]> rtime.felk.cvut.cz Git - linux-lin.git/blob - sllin/sllin.c
Added basic speed change.
[linux-lin.git] / sllin / sllin.c
1 /*
2  * sllin.c - serial line LIN interface driver (using tty line discipline)
3  *
4  * This file is derived from linux/drivers/net/slip.c
5  *
6  * slip.c Authors  : Laurence Culhane <loz@holmes.demon.co.uk>
7  *                   Fred N. van Kempen <waltje@uwalt.nl.mugnet.org>
8  * sllin.c Author  : Oliver Hartkopp <socketcan@hartkopp.net>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by the
12  * Free Software Foundation; either version 2 of the License, or (at your
13  * option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 59 Temple Place, Suite 330, Boston, MA 02111-1307. You can also get it
23  * at http://www.gnu.org/licenses/gpl.html
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
36  * DAMAGE.
37  *
38  * Send feedback to <socketcan-users@lists.berlios.de>
39  *
40  */
41
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44
45 #include <asm/system.h>
46 #include <linux/uaccess.h>
47 #include <linux/bitops.h>
48 #include <linux/string.h>
49 #include <linux/tty.h>
50 #include <linux/errno.h>
51 #include <linux/netdevice.h>
52 #include <linux/skbuff.h>
53 #include <linux/rtnetlink.h>
54 #include <linux/if_arp.h>
55 #include <linux/if_ether.h>
56 #include <linux/sched.h>
57 #include <linux/delay.h>
58 #include <linux/init.h>
59 #include <linux/can.h>
60
61 /* Should be in include/linux/tty.h */
62 #define N_SLLIN         25
63
64
65 static __initdata const char banner[] =
66         KERN_INFO "sllin: serial line LIN interface driver\n";
67
68 MODULE_ALIAS_LDISC(N_SLLIN);
69 MODULE_DESCRIPTION("serial line LIN interface");
70 MODULE_LICENSE("GPL");
71 MODULE_AUTHOR("Oliver Hartkopp <socketcan@hartkopp.net>");
72
73 #define SLLIN_MAGIC 0x53CA
74
75 static int maxdev = 10;         /* MAX number of SLLIN channels;
76                                    This can be overridden with
77                                    insmod sllin.ko maxdev=nnn   */
78 module_param(maxdev, int, 0);
79 MODULE_PARM_DESC(maxdev, "Maximum number of sllin interfaces");
80
81 /* maximum rx buffer len: extended CAN frame with timestamp */
82 #define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
83
84 struct sllin {
85         int                     magic;
86
87         /* Various fields. */
88         struct tty_struct       *tty;           /* ptr to TTY structure      */
89         struct net_device       *dev;           /* easy for intr handling    */
90         spinlock_t              lock;
91
92         /* These are pointers to the malloc()ed frame buffers. */
93         unsigned char           rbuff[SLC_MTU]; /* receiver buffer           */
94         int                     rcount;         /* received chars counter    */
95         unsigned char           xbuff[SLC_MTU]; /* transmitter buffer        */
96         unsigned char           *xhead;         /* pointer to next XMIT byte */
97         int                     xleft;          /* bytes left in XMIT queue  */
98
99         unsigned long           flags;          /* Flag values/ mode etc     */
100 #define SLF_INUSE               0               /* Channel in use            */
101 #define SLF_ERROR               1               /* Parity, etc. error        */
102
103         unsigned char           leased;
104         dev_t                   line;
105         pid_t                   pid;
106 };
107
108 static struct net_device **sllin_devs;
109
110
111 static int sltty_change_speed(struct tty_struct *tty, unsigned speed)
112 {
113         struct ktermios old_termios;
114         int cflag;
115
116         mutex_lock(&tty->termios_mutex);
117         old_termios = *(tty->termios);
118         cflag = tty->termios->c_cflag;
119         tty_encode_baud_rate(tty, speed, speed);
120         if (tty->ops->set_termios)
121                 tty->ops->set_termios(tty, &old_termios);
122         //priv->io.speed = speed;
123         mutex_unlock(&tty->termios_mutex);
124
125         return 0;
126 }
127
128
129 /* Send one completely decapsulated can_frame to the network layer */
130 static void sll_bump(struct sllin *sl)
131 {
132 //      struct sk_buff *skb;
133 //      struct can_frame cf;
134 //      int i, dlc_pos, tmp;
135 //      unsigned long ultmp;
136 //      char cmd = sl->rbuff[0];
137 //
138 //      if ((cmd != 't') && (cmd != 'T') && (cmd != 'r') && (cmd != 'R'))
139 //              return;
140 //
141 //      if (cmd & 0x20) /* tiny chars 'r' 't' => standard frame format */
142 //              dlc_pos = 4; /* dlc position tiiid */
143 //      else
144 //              dlc_pos = 9; /* dlc position Tiiiiiiiid */
145 //
146 //      if (!((sl->rbuff[dlc_pos] >= '0') && (sl->rbuff[dlc_pos] < '9')))
147 //              return;
148 //
149 //      cf.can_dlc = sl->rbuff[dlc_pos] - '0'; /* get can_dlc from ASCII val */
150 //
151 //      sl->rbuff[dlc_pos] = 0; /* terminate can_id string */
152 //
153 //      if (strict_strtoul(sl->rbuff+1, 16, &ultmp))
154 //              return;
155 //
156 //      cf.can_id = ultmp;
157 //
158 //      if (!(cmd & 0x20)) /* NO tiny chars => extended frame format */
159 //              cf.can_id |= CAN_EFF_FLAG;
160 //
161 //      if ((cmd | 0x20) == 'r') /* RTR frame */
162 //              cf.can_id |= CAN_RTR_FLAG;
163 //
164 //      *(u64 *) (&cf.data) = 0; /* clear payload */
165 //
166 //      for (i = 0, dlc_pos++; i < cf.can_dlc; i++) {
167 //
168 //              tmp = asc2nibble(sl->rbuff[dlc_pos++]);
169 //              if (tmp > 0x0F)
170 //                      return;
171 //              cf.data[i] = (tmp << 4);
172 //              tmp = asc2nibble(sl->rbuff[dlc_pos++]);
173 //              if (tmp > 0x0F)
174 //                      return;
175 //              cf.data[i] |= tmp;
176 //      }
177 //
178 //
179 //      skb = dev_alloc_skb(sizeof(struct can_frame));
180 //      if (!skb)
181 //              return;
182 //
183 //      skb->dev = sl->dev;
184 //      skb->protocol = htons(ETH_P_CAN);
185 //      skb->pkt_type = PACKET_BROADCAST;
186 //      skb->ip_summed = CHECKSUM_UNNECESSARY;
187 //      memcpy(skb_put(skb, sizeof(struct can_frame)),
188 //             &cf, sizeof(struct can_frame));
189 //      netif_rx(skb);
190 //
191 //      sl->dev->stats.rx_packets++;
192 //      sl->dev->stats.rx_bytes += cf.can_dlc;
193 }
194
195 /* parse tty input stream */
196 static void sllin_unesc(struct sllin *sl, unsigned char s)
197 {
198
199         if ((s == '\r') || (s == '\a')) { /* CR or BEL ends the pdu */
200                 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
201                     (sl->rcount > 4))  {
202                         sll_bump(sl);
203                 }
204                 sl->rcount = 0;
205         } else {
206                 if (!test_bit(SLF_ERROR, &sl->flags))  {
207                         if (sl->rcount < SLC_MTU)  {
208                                 sl->rbuff[sl->rcount++] = s;
209                                 return;
210                         } else {
211                                 sl->dev->stats.rx_over_errors++;
212                                 set_bit(SLF_ERROR, &sl->flags);
213                         }
214                 }
215         }
216 }
217
218  /************************************************************************
219   *                     STANDARD SLLIN ENCAPSULATION                     *
220   ************************************************************************/
221
222 /* Convert particular CAN frame into LIN frame and send it to TTY queue. */
223 static void sll_encaps(struct sllin *sl, struct can_frame *cf)
224 {
225         int actual, idx, i;
226         char lframe[16] = {0x00, 0x55}; /* Fake break, Sync byte */
227         struct tty_struct *tty = sl->tty;
228
229         /* We do care only about SFF frames */
230         if (cf->can_id & CAN_EFF_FLAG)
231                 return;
232
233         /* Send only header */
234         if (cf->can_id & CAN_RTR_FLAG) {
235                 lframe[2] = (u8)cf->can_id; /* Get one byte LIN ID */
236
237                 sltty_change_speed(tty, 1200);
238                 tty->ops->write(tty, &lframe[0], 1);
239                 sltty_change_speed(tty, 2400);
240                 tty->ops->write(tty, &lframe[1], 1);
241                 tty->ops->write(tty, &lframe[2], 1);
242         } else {
243                 /*      idx = strlen(sl->xbuff);
244
245                         for (i = 0; i < cf->can_dlc; i++)
246                         sprintf(&sl->xbuff[idx + 2*i], "%02X", cf->data[i]);
247
248                  * Order of next two lines is *very* important.
249                  * When we are sending a little amount of data,
250                  * the transfer may be completed inside the ops->write()
251                  * routine, because it's running with interrupts enabled.
252                  * In this case we *never* got WRITE_WAKEUP event,
253                  * if we did not request it before write operation.
254                  *       14 Oct 1994  Dmitry Gorodchanin.
255
256                  set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
257                  actual = sl->tty->ops->write(sl->tty, sl->xbuff, strlen(sl->xbuff));
258                  sl->xleft = strlen(sl->xbuff) - actual;
259                  sl->xhead = sl->xbuff + actual;
260                  sl->dev->stats.tx_bytes += cf->can_dlc;
261                  */
262         }
263
264 }
265
266 /*
267  * Called by the driver when there's room for more data.  If we have
268  * more packets to send, we send them here.
269  */
270 static void sllin_write_wakeup(struct tty_struct *tty)
271 {
272         int actual;
273         struct sllin *sl = (struct sllin *) tty->disc_data;
274
275         /* First make sure we're connected. */
276         if (!sl || sl->magic != SLLIN_MAGIC || !netif_running(sl->dev))
277                 return;
278
279         if (sl->xleft <= 0)  {
280                 /* Now serial buffer is almost free & we can start
281                  * transmission of another packet */
282                 sl->dev->stats.tx_packets++;
283                 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
284                 netif_wake_queue(sl->dev);
285                 return;
286         }
287
288         actual = tty->ops->write(tty, sl->xhead, sl->xleft);
289         sl->xleft -= actual;
290         sl->xhead += actual;
291 }
292
293 /* Send a can_frame to a TTY queue. */
294 static netdev_tx_t sll_xmit(struct sk_buff *skb, struct net_device *dev)
295 {
296         struct sllin *sl = netdev_priv(dev);
297
298         if (skb->len != sizeof(struct can_frame))
299                 goto out;
300
301         spin_lock(&sl->lock);
302         if (!netif_running(dev))  {
303                 spin_unlock(&sl->lock);
304                 printk(KERN_WARNING "%s: xmit: iface is down\n", dev->name);
305                 goto out;
306         }
307         if (sl->tty == NULL) {
308                 spin_unlock(&sl->lock);
309                 goto out;
310         }
311
312         netif_stop_queue(sl->dev);
313         sll_encaps(sl, (struct can_frame *) skb->data); /* encaps & send */
314         spin_unlock(&sl->lock);
315
316 out:
317         kfree_skb(skb);
318         return NETDEV_TX_OK;
319 }
320
321
322 /******************************************
323  *   Routines looking at netdevice side.
324  ******************************************/
325
326 /* Netdevice UP -> DOWN routine */
327 static int sll_close(struct net_device *dev)
328 {
329         struct sllin *sl = netdev_priv(dev);
330
331         spin_lock_bh(&sl->lock);
332         if (sl->tty) {
333                 /* TTY discipline is running. */
334                 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
335         }
336         netif_stop_queue(dev);
337         sl->rcount   = 0;
338         sl->xleft    = 0;
339         spin_unlock_bh(&sl->lock);
340
341         return 0;
342 }
343
344 /* Netdevice DOWN -> UP routine */
345 static int sll_open(struct net_device *dev)
346 {
347         struct sllin *sl = netdev_priv(dev);
348
349         if (sl->tty == NULL)
350                 return -ENODEV;
351
352         sl->flags &= (1 << SLF_INUSE);
353         netif_start_queue(dev);
354         return 0;
355 }
356
357 /* Hook the destructor so we can free sllin devs at the right point in time */
358 static void sll_free_netdev(struct net_device *dev)
359 {
360         int i = dev->base_addr;
361         free_netdev(dev);
362         sllin_devs[i] = NULL;
363 }
364
365 static const struct net_device_ops sll_netdev_ops = {
366         .ndo_open               = sll_open,
367         .ndo_stop               = sll_close,
368         .ndo_start_xmit         = sll_xmit,
369 };
370
371 static void sll_setup(struct net_device *dev)
372 {
373         dev->netdev_ops         = &sll_netdev_ops;
374         dev->destructor         = sll_free_netdev;
375
376         dev->hard_header_len    = 0;
377         dev->addr_len           = 0;
378         dev->tx_queue_len       = 10;
379
380         dev->mtu                = sizeof(struct can_frame);
381         dev->type               = ARPHRD_CAN;
382
383         /* New-style flags. */
384         dev->flags              = IFF_NOARP;
385         dev->features           = NETIF_F_NO_CSUM;
386 }
387
388 /******************************************
389   Routines looking at TTY side.
390  ******************************************/
391
392 /*
393  * Handle the 'receiver data ready' interrupt.
394  * This function is called by the 'tty_io' module in the kernel when
395  * a block of SLLIN data has been received, which can now be decapsulated
396  * and sent on to some IP layer for further processing. This will not
397  * be re-entered while running but other ldisc functions may be called
398  * in parallel
399  */
400
401 static void sllin_receive_buf(struct tty_struct *tty,
402                               const unsigned char *cp, char *fp, int count)
403 {
404         struct sllin *sl = (struct sllin *) tty->disc_data;
405
406         if (!sl || sl->magic != SLLIN_MAGIC || !netif_running(sl->dev))
407                 return;
408
409         /* Read the characters out of the buffer */
410         while (count--) {
411                 if (fp && *fp++) {
412                         if (!test_and_set_bit(SLF_ERROR, &sl->flags))
413                                 sl->dev->stats.rx_errors++;
414                         cp++;
415                         continue;
416                 }
417                 sllin_unesc(sl, *cp++);
418         }
419 }
420
421 /************************************
422  *  sllin_open helper routines.
423  ************************************/
424
425 /* Collect hanged up channels */
426 static void sll_sync(void)
427 {
428         int i;
429         struct net_device *dev;
430         struct sllin      *sl;
431
432         for (i = 0; i < maxdev; i++) {
433                 dev = sllin_devs[i];
434                 if (dev == NULL)
435                         break;
436
437                 sl = netdev_priv(dev);
438                 if (sl->tty || sl->leased)
439                         continue;
440                 if (dev->flags & IFF_UP)
441                         dev_close(dev);
442         }
443 }
444
445 /* Find a free SLLIN channel, and link in this `tty' line. */
446 static struct sllin *sll_alloc(dev_t line)
447 {
448         int i;
449         struct net_device *dev = NULL;
450         struct sllin       *sl;
451
452         if (sllin_devs == NULL)
453                 return NULL;    /* Master array missing ! */
454
455         for (i = 0; i < maxdev; i++) {
456                 dev = sllin_devs[i];
457                 if (dev == NULL)
458                         break;
459
460         }
461
462         /* Sorry, too many, all slots in use */
463         if (i >= maxdev)
464                 return NULL;
465
466         if (dev) {
467                 sl = netdev_priv(dev);
468                 if (test_bit(SLF_INUSE, &sl->flags)) {
469                         unregister_netdevice(dev);
470                         dev = NULL;
471                         sllin_devs[i] = NULL;
472                 }
473         }
474
475         if (!dev) {
476                 char name[IFNAMSIZ];
477                 sprintf(name, "sllin%d", i);
478
479                 dev = alloc_netdev(sizeof(*sl), name, sll_setup);
480                 if (!dev)
481                         return NULL;
482                 dev->base_addr  = i;
483         }
484
485         sl = netdev_priv(dev);
486
487         /* Initialize channel control data */
488         sl->magic = SLLIN_MAGIC;
489         sl->dev = dev;
490         spin_lock_init(&sl->lock);
491         sllin_devs[i] = dev;
492
493         return sl;
494 }
495
496 /*
497  * Open the high-level part of the SLLIN channel.
498  * This function is called by the TTY module when the
499  * SLLIN line discipline is called for.  Because we are
500  * sure the tty line exists, we only have to link it to
501  * a free SLLIN channel...
502  *
503  * Called in process context serialized from other ldisc calls.
504  */
505
506 static int sllin_open(struct tty_struct *tty)
507 {
508         struct sllin *sl;
509         int err;
510
511         if (!capable(CAP_NET_ADMIN))
512                 return -EPERM;
513
514         if (tty->ops->write == NULL)
515                 return -EOPNOTSUPP;
516
517         /* RTnetlink lock is misused here to serialize concurrent
518            opens of sllin channels. There are better ways, but it is
519            the simplest one.
520          */
521         rtnl_lock();
522
523         /* Collect hanged up channels. */
524         sll_sync();
525
526         sl = tty->disc_data;
527
528         err = -EEXIST;
529         /* First make sure we're not already connected. */
530         if (sl && sl->magic == SLLIN_MAGIC)
531                 goto err_exit;
532
533         /* OK.  Find a free SLLIN channel to use. */
534         err = -ENFILE;
535         sl = sll_alloc(tty_devnum(tty));
536         if (sl == NULL)
537                 goto err_exit;
538
539         sl->tty = tty;
540         tty->disc_data = sl;
541         sl->line = tty_devnum(tty);
542         sl->pid = current->pid;
543
544         if (!test_bit(SLF_INUSE, &sl->flags)) {
545                 /* Perform the low-level SLLIN initialization. */
546                 sl->rcount   = 0;
547                 sl->xleft    = 0;
548
549                 set_bit(SLF_INUSE, &sl->flags);
550
551                 err = register_netdevice(sl->dev);
552                 if (err)
553                         goto err_free_chan;
554         }
555
556         /* Done.  We have linked the TTY line to a channel. */
557         rtnl_unlock();
558         tty->receive_room = 65536;      /* We don't flow control */
559
560         /* TTY layer expects 0 on success */
561         return 0;
562
563 err_free_chan:
564         sl->tty = NULL;
565         tty->disc_data = NULL;
566         clear_bit(SLF_INUSE, &sl->flags);
567
568 err_exit:
569         rtnl_unlock();
570
571         /* Count references from TTY module */
572         return err;
573 }
574
575 /*
576  * Close down a SLLIN channel.
577  * This means flushing out any pending queues, and then returning. This
578  * call is serialized against other ldisc functions.
579  *
580  * We also use this method for a hangup event.
581  */
582
583 static void sllin_close(struct tty_struct *tty)
584 {
585         struct sllin *sl = (struct sllin *) tty->disc_data;
586
587         /* First make sure we're connected. */
588         if (!sl || sl->magic != SLLIN_MAGIC || sl->tty != tty)
589                 return;
590
591         tty->disc_data = NULL;
592         sl->tty = NULL;
593         if (!sl->leased)
594                 sl->line = 0;
595
596         /* Flush network side */
597         unregister_netdev(sl->dev);
598         /* This will complete via sl_free_netdev */
599 }
600
601 static int sllin_hangup(struct tty_struct *tty)
602 {
603         sllin_close(tty);
604         return 0;
605 }
606
607 /* Perform I/O control on an active SLLIN channel. */
608 static int sllin_ioctl(struct tty_struct *tty, struct file *file,
609                        unsigned int cmd, unsigned long arg)
610 {
611         struct sllin *sl = (struct sllin *) tty->disc_data;
612         unsigned int tmp;
613
614         /* First make sure we're connected. */
615         if (!sl || sl->magic != SLLIN_MAGIC)
616                 return -EINVAL;
617
618         switch (cmd) {
619         case SIOCGIFNAME:
620                 tmp = strlen(sl->dev->name) + 1;
621                 if (copy_to_user((void __user *)arg, sl->dev->name, tmp))
622                         return -EFAULT;
623                 return 0;
624
625         case SIOCSIFHWADDR:
626                 return -EINVAL;
627
628         default:
629                 return tty_mode_ioctl(tty, file, cmd, arg);
630         }
631 }
632
633 static struct tty_ldisc_ops sll_ldisc = {
634         .owner          = THIS_MODULE,
635         .magic          = TTY_LDISC_MAGIC,
636         .name           = "sllin",
637         .open           = sllin_open,
638         .close          = sllin_close,
639         .hangup         = sllin_hangup,
640         .ioctl          = sllin_ioctl,
641         .receive_buf    = sllin_receive_buf,
642         .write_wakeup   = sllin_write_wakeup,
643 };
644
645 static int __init sllin_init(void)
646 {
647         int status;
648
649         if (maxdev < 4)
650                 maxdev = 4; /* Sanity */
651
652         printk(banner);
653         printk(KERN_INFO "sllin: %d dynamic interface channels.\n", maxdev);
654
655         sllin_devs = kzalloc(sizeof(struct net_device *)*maxdev, GFP_KERNEL);
656         if (!sllin_devs) {
657                 printk(KERN_ERR "sllin: can't allocate sllin device array!\n");
658                 return -ENOMEM;
659         }
660
661         /* Fill in our line protocol discipline, and register it */
662         status = tty_register_ldisc(N_SLLIN, &sll_ldisc);
663         if (status)  {
664                 printk(KERN_ERR "sllin: can't register line discipline\n");
665                 kfree(sllin_devs);
666         }
667         return status;
668 }
669
670 static void __exit sllin_exit(void)
671 {
672         int i;
673         struct net_device *dev;
674         struct sllin *sl;
675         unsigned long timeout = jiffies + HZ;
676         int busy = 0;
677
678         if (sllin_devs == NULL)
679                 return;
680
681         /* First of all: check for active disciplines and hangup them.
682          */
683         do {
684                 if (busy)
685                         msleep_interruptible(100);
686
687                 busy = 0;
688                 for (i = 0; i < maxdev; i++) {
689                         dev = sllin_devs[i];
690                         if (!dev)
691                                 continue;
692                         sl = netdev_priv(dev);
693                         spin_lock_bh(&sl->lock);
694                         if (sl->tty) {
695                                 busy++;
696                                 tty_hangup(sl->tty);
697                         }
698                         spin_unlock_bh(&sl->lock);
699                 }
700         } while (busy && time_before(jiffies, timeout));
701
702         /* FIXME: hangup is async so we should wait when doing this second
703            phase */
704
705         for (i = 0; i < maxdev; i++) {
706                 dev = sllin_devs[i];
707                 if (!dev)
708                         continue;
709                 sllin_devs[i] = NULL;
710
711                 sl = netdev_priv(dev);
712                 if (sl->tty) {
713                         printk(KERN_ERR "%s: tty discipline still running\n",
714                                dev->name);
715                         /* Intentionally leak the control block. */
716                         dev->destructor = NULL;
717                 }
718
719                 unregister_netdev(dev);
720         }
721
722         kfree(sllin_devs);
723         sllin_devs = NULL;
724
725         i = tty_unregister_ldisc(N_SLLIN);
726         if (i)
727                 printk(KERN_ERR "sllin: can't unregister ldisc (err %d)\n", i);
728 }
729
730 module_init(sllin_init);
731 module_exit(sllin_exit);