]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/xtensa/platform-iss/network.c
0682ffd38175edd2da90dd10da2e71c8bc6d6906
[karo-tx-linux.git] / arch / xtensa / platform-iss / network.c
1 /*
2  *
3  * arch/xtensa/platform-iss/network.c
4  *
5  * Platform specific initialization.
6  *
7  * Authors: Chris Zankel <chris@zankel.net>
8  * Based on work form the UML team.
9  *
10  * Copyright 2005 Tensilica Inc.
11  *
12  * This program is free software; you can redistribute  it and/or modify it
13  * under  the terms of  the GNU General  Public License as published by the
14  * Free Software Foundation;  either version 2 of the  License, or (at your
15  * option) any later version.
16  *
17  */
18
19 #include <linux/config.h>
20 #include <linux/list.h>
21 #include <linux/irq.h>
22 #include <linux/spinlock.h>
23 #include <linux/slab.h>
24 #include <linux/timer.h>
25 #include <linux/if_ether.h>
26 #include <linux/inetdevice.h>
27 #include <linux/init.h>
28 #include <linux/if_tun.h>
29 #include <linux/etherdevice.h>
30 #include <linux/interrupt.h>
31 #include <linux/ioctl.h>
32 #include <linux/bootmem.h>
33 #include <linux/ethtool.h>
34 #include <linux/rtnetlink.h>
35 #include <linux/timer.h>
36 #include <linux/platform_device.h>
37
38 #include <xtensa/simcall.h>
39
40 #define DRIVER_NAME "iss-netdev"
41 #define ETH_MAX_PACKET 1500
42 #define ETH_HEADER_OTHER 14
43 #define ISS_NET_TIMER_VALUE (2 * HZ)
44
45
46 static DEFINE_SPINLOCK(opened_lock);
47 static LIST_HEAD(opened);
48
49 static DEFINE_SPINLOCK(devices_lock);
50 static LIST_HEAD(devices);
51
52 /* ------------------------------------------------------------------------- */
53
54 /* We currently only support the TUNTAP transport protocol. */
55
56 #define TRANSPORT_TUNTAP_NAME "tuntap"
57 #define TRANSPORT_TUNTAP_MTU ETH_MAX_PACKET
58
59 struct tuntap_info {
60         char dev_name[IFNAMSIZ];
61         int fixed_config;
62         unsigned char gw[ETH_ALEN];
63         int fd;
64 };
65
66 /* ------------------------------------------------------------------------- */
67
68
69 /* This structure contains out private information for the driver. */
70
71 struct iss_net_private {
72
73         struct list_head device_list;
74         struct list_head opened_list;
75
76         spinlock_t lock;
77         struct net_device *dev;
78         struct platform_device pdev;
79         struct timer_list tl;
80         struct net_device_stats stats;
81
82         struct timer_list timer;
83         unsigned int timer_val;
84
85         int index;
86         int mtu;
87
88         unsigned char mac[ETH_ALEN];
89         int have_mac;
90
91         struct {
92                 union {
93                         struct tuntap_info tuntap;
94                 } info;
95
96                 int (*open)(struct iss_net_private *lp);
97                 void (*close)(struct iss_net_private *lp);
98                 int (*read)(struct iss_net_private *lp, struct sk_buff **skb);
99                 int (*write)(struct iss_net_private *lp, struct sk_buff **skb);
100                 unsigned short (*protocol)(struct sk_buff *skb);
101                 int (*poll)(struct iss_net_private *lp);
102         } tp;
103
104 };
105
106 /* ======================= ISS SIMCALL INTERFACE =========================== */
107
108 /* Note: __simc must _not_ be declared inline! */
109
110 static int errno;
111
112 static int __simc (int a, int b, int c, int d, int e, int f)
113 {
114         int ret;
115         __asm__ __volatile__ ("simcall\n"
116                               "mov %0, a2\n"
117                               "mov %1, a3\n" : "=a" (ret), "=a" (errno)
118                               : : "a2", "a3");
119         return ret;
120 }
121
122 static int inline simc_open(char *file, int flags, int mode)
123 {
124         return __simc(SYS_open, (int) file, flags, mode, 0, 0);
125 }
126
127 static int inline simc_close(int fd)
128 {
129         return __simc(SYS_close, fd, 0, 0, 0, 0);
130 }
131
132 static int inline simc_ioctl(int fd, int request, void *arg)
133 {
134         return __simc(SYS_ioctl, fd, request, (int) arg, 0, 0);
135 }
136
137 static int inline simc_read(int fd, void *buf, size_t count)
138 {
139         return __simc(SYS_read, fd, (int) buf, count, 0, 0);
140 }
141
142 static int inline simc_write(int fd, void *buf, size_t count)
143 {
144         return __simc(SYS_write, fd, (int) buf, count, 0, 0);
145 }
146
147 static int inline simc_poll(int fd)
148 {
149         struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
150
151         return __simc(SYS_select_one, fd, XTISS_SELECT_ONE_READ, (int)&tv,0,0);
152 }
153
154 /* ================================ HELPERS ================================ */
155
156
157 static char *split_if_spec(char *str, ...)
158 {
159         char **arg, *end;
160         va_list ap;
161
162         va_start(ap, str);
163         while ((arg = va_arg(ap, char**)) != NULL) {
164                 if (*str == '\0')
165                         return NULL;
166                 end = strchr(str, ',');
167                 if (end != str)
168                         *arg = str;
169                 if (end == NULL)
170                         return NULL;
171                 *end ++ = '\0';
172                 str = end;
173         }
174         va_end(ap);
175         return str;
176 }
177
178
179 #if 0
180 /* Adjust SKB. */
181
182 struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
183 {
184         if ((skb != NULL) && (skb_tailroom(skb) < extra)) {
185                 struct sk_buff *skb2;
186
187                 skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
188                 dev_kfree_skb(skb);
189                 skb = skb2;
190         }
191         if (skb != NULL)
192                 skb_put(skb, extra);
193
194         return skb;
195 }
196 #endif
197
198 /* Return the IP address as a string for a given device. */
199
200 static void dev_ip_addr(void *d, char *buf, char *bin_buf)
201 {
202         struct net_device *dev = d;
203         struct in_device *ip = dev->ip_ptr;
204         struct in_ifaddr *in;
205         u32 addr;
206
207         if ((ip == NULL) || ((in = ip->ifa_list) == NULL)) {
208                 printk(KERN_WARNING "Device not assigned an IP address!\n");
209                 return;
210         }
211
212         addr = in->ifa_address;
213         sprintf(buf, "%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff,
214                 (addr >> 16) & 0xff, addr >> 24);
215
216         if (bin_buf) {
217                 bin_buf[0] = addr & 0xff;
218                 bin_buf[1] = (addr >> 8) & 0xff;
219                 bin_buf[2] = (addr >> 16) & 0xff;
220                 bin_buf[3] = addr >> 24;
221         }
222 }
223
224 /* Set Ethernet address of the specified device. */
225
226 static void inline set_ether_mac(void *d, unsigned char *addr)
227 {
228         struct net_device *dev = d;
229         memcpy(dev->dev_addr, addr, ETH_ALEN);
230 }
231
232
233 /* ======================= TUNTAP TRANSPORT INTERFACE ====================== */
234
235 static int tuntap_open(struct iss_net_private *lp)
236 {
237         struct ifreq ifr;
238         char *dev_name = lp->tp.info.tuntap.dev_name;
239         int err = -EINVAL;
240         int fd;
241
242         /* We currently only support a fixed configuration. */
243
244         if (!lp->tp.info.tuntap.fixed_config)
245                 return -EINVAL;
246
247         if ((fd = simc_open("/dev/net/tun", 02, 0)) < 0) {      /* O_RDWR */
248                 printk("Failed to open /dev/net/tun, returned %d "
249                        "(errno = %d)\n", fd, errno);
250                 return fd;
251         }
252
253         memset(&ifr, 0, sizeof ifr);
254         ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
255         strlcpy(ifr.ifr_name, dev_name, sizeof ifr.ifr_name - 1);
256
257         if ((err = simc_ioctl(fd, TUNSETIFF, (void*) &ifr)) < 0) {
258                 printk("Failed to set interface, returned %d "
259                        "(errno = %d)\n", err, errno);
260                 simc_close(fd);
261                 return err;
262         }
263
264         lp->tp.info.tuntap.fd = fd;
265         return err;
266 }
267
268 static void tuntap_close(struct iss_net_private *lp)
269 {
270 #if 0
271         if (lp->tp.info.tuntap.fixed_config)
272                 iter_addresses(lp->tp.info.tuntap.dev, close_addr, lp->host.dev_name);
273 #endif
274         simc_close(lp->tp.info.tuntap.fd);
275         lp->tp.info.tuntap.fd = -1;
276 }
277
278 static int tuntap_read (struct iss_net_private *lp, struct sk_buff **skb)
279 {
280 #if 0
281         *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
282         if (*skb == NULL)
283                 return -ENOMEM;
284 #endif
285
286         return simc_read(lp->tp.info.tuntap.fd,
287                         (*skb)->data, (*skb)->dev->mtu + ETH_HEADER_OTHER);
288 }
289
290 static int tuntap_write (struct iss_net_private *lp, struct sk_buff **skb)
291 {
292         return simc_write(lp->tp.info.tuntap.fd, (*skb)->data, (*skb)->len);
293 }
294
295 unsigned short tuntap_protocol(struct sk_buff *skb)
296 {
297         return eth_type_trans(skb, skb->dev);
298 }
299
300 static int tuntap_poll(struct iss_net_private *lp)
301 {
302         return simc_poll(lp->tp.info.tuntap.fd);
303 }
304
305 /*
306  * Currently only a device name is supported.
307  * ethX=tuntap[,[mac address][,[device name]]]
308  */
309
310 static int tuntap_probe(struct iss_net_private *lp, int index, char *init)
311 {
312         const int len = strlen(TRANSPORT_TUNTAP_NAME);
313         char *dev_name = NULL, *mac_str = NULL, *rem = NULL;
314
315         /* Transport should be 'tuntap': ethX=tuntap,mac,dev_name */
316
317         if (strncmp(init, TRANSPORT_TUNTAP_NAME, len))
318                 return 0;
319
320         if (*(init += strlen(TRANSPORT_TUNTAP_NAME)) == ',') {
321                 if ((rem=split_if_spec(init+1, &mac_str, &dev_name)) != NULL) {
322                         printk("Extra garbage on specification : '%s'\n", rem);
323                         return 0;
324                 }
325         } else if (*init != '\0') {
326                 printk("Invalid argument: %s. Skipping device!\n", init);
327                 return 0;
328         }
329
330         if (dev_name) {
331                 strncpy(lp->tp.info.tuntap.dev_name, dev_name,
332                          sizeof lp->tp.info.tuntap.dev_name);
333                 lp->tp.info.tuntap.fixed_config = 1;
334         } else
335                 strcpy(lp->tp.info.tuntap.dev_name, TRANSPORT_TUNTAP_NAME);
336
337
338 #if 0
339         if (setup_etheraddr(mac_str, lp->mac))
340                 lp->have_mac = 1;
341 #endif
342         lp->mtu = TRANSPORT_TUNTAP_MTU;
343
344         //lp->info.tuntap.gate_addr = gate_addr;
345
346         lp->tp.info.tuntap.fd = -1;
347
348         lp->tp.open = tuntap_open;
349         lp->tp.close = tuntap_close;
350         lp->tp.read = tuntap_read;
351         lp->tp.write = tuntap_write;
352         lp->tp.protocol = tuntap_protocol;
353         lp->tp.poll = tuntap_poll;
354
355         printk("TUN/TAP backend - ");
356 #if 0
357         if (lp->host.gate_addr != NULL)
358                 printk("IP = %s", lp->host.gate_addr);
359 #endif
360         printk("\n");
361
362         return 1;
363 }
364
365 /* ================================ ISS NET ================================ */
366
367 static int iss_net_rx(struct net_device *dev)
368 {
369         struct iss_net_private *lp = dev->priv;
370         int pkt_len;
371         struct sk_buff *skb;
372
373         /* Check if there is any new data. */
374
375         if (lp->tp.poll(lp) == 0)
376                 return 0;
377
378         /* Try to allocate memory, if it fails, try again next round. */
379
380         if ((skb = dev_alloc_skb(dev->mtu + 2 + ETH_HEADER_OTHER)) == NULL) {
381                 lp->stats.rx_dropped++;
382                 return 0;
383         }
384
385         skb_reserve(skb, 2);
386
387         /* Setup skb */
388
389         skb->dev = dev;
390         skb->mac.raw = skb->data;
391         pkt_len = lp->tp.read(lp, &skb);
392         skb_put(skb, pkt_len);
393
394         if (pkt_len > 0) {
395                 skb_trim(skb, pkt_len);
396                 skb->protocol = lp->tp.protocol(skb);
397         //      netif_rx(skb);
398                 netif_rx_ni(skb);
399
400                 lp->stats.rx_bytes += skb->len;
401                 lp->stats.rx_packets++;
402                 return pkt_len;
403         }
404         kfree_skb(skb);
405         return pkt_len;
406 }
407
408 static int iss_net_poll(void)
409 {
410         struct list_head *ele;
411         int err, ret = 0;
412
413         spin_lock(&opened_lock);
414
415         list_for_each(ele, &opened) {
416                 struct iss_net_private *lp;
417
418                 lp = list_entry(ele, struct iss_net_private, opened_list);
419
420                 if (!netif_running(lp->dev))
421                         break;
422
423                 spin_lock(&lp->lock);
424
425                 while ((err = iss_net_rx(lp->dev)) > 0)
426                         ret++;
427
428                 spin_unlock(&lp->lock);
429
430                 if (err < 0) {
431                         printk(KERN_ERR "Device '%s' read returned %d, "
432                                "shutting it down\n", lp->dev->name, err);
433                         dev_close(lp->dev);
434                 } else {
435                         // FIXME reactivate_fd(lp->fd, ISS_ETH_IRQ);
436                 }
437         }
438
439         spin_unlock(&opened_lock);
440         return ret;
441 }
442
443
444 static void iss_net_timer(unsigned long priv)
445 {
446         struct iss_net_private* lp = (struct iss_net_private*) priv;
447
448         spin_lock(&lp->lock);
449
450         iss_net_poll();
451
452         mod_timer(&lp->timer, jiffies + lp->timer_val);
453
454         spin_unlock(&lp->lock);
455 }
456
457
458 static int iss_net_open(struct net_device *dev)
459 {
460         struct iss_net_private *lp = dev->priv;
461         char addr[sizeof "255.255.255.255\0"];
462         int err;
463
464         spin_lock(&lp->lock);
465
466         if ((err = lp->tp.open(lp)) < 0)
467                 goto out;
468
469         if (!lp->have_mac) {
470                 dev_ip_addr(dev, addr, &lp->mac[2]);
471                 set_ether_mac(dev, lp->mac);
472         }
473
474         netif_start_queue(dev);
475
476         /* clear buffer - it can happen that the host side of the interface
477          * is full when we gethere. In this case, new data is never queued,
478          * SIGIOs never arrive, and the net never works.
479          */
480         while ((err = iss_net_rx(dev)) > 0)
481                 ;
482
483         spin_lock(&opened_lock);
484         list_add(&lp->opened_list, &opened);
485         spin_unlock(&opened_lock);
486
487         init_timer(&lp->timer);
488         lp->timer_val = ISS_NET_TIMER_VALUE;
489         lp->timer.data = (unsigned long) lp;
490         lp->timer.function = iss_net_timer;
491         mod_timer(&lp->timer, jiffies + lp->timer_val);
492
493 out:
494         spin_unlock(&lp->lock);
495         return err;
496 }
497
498 static int iss_net_close(struct net_device *dev)
499 {
500         struct iss_net_private *lp = dev->priv;
501 printk("iss_net_close!\n");
502         netif_stop_queue(dev);
503         spin_lock(&lp->lock);
504
505         spin_lock(&opened_lock);
506         list_del(&opened);
507         spin_unlock(&opened_lock);
508
509         del_timer_sync(&lp->timer);
510
511         lp->tp.close(lp);
512
513         spin_unlock(&lp->lock);
514         return 0;
515 }
516
517 static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
518 {
519         struct iss_net_private *lp = dev->priv;
520         unsigned long flags;
521         int len;
522
523         netif_stop_queue(dev);
524         spin_lock_irqsave(&lp->lock, flags);
525
526         len = lp->tp.write(lp, &skb);
527
528         if (len == skb->len) {
529                 lp->stats.tx_packets++;
530                 lp->stats.tx_bytes += skb->len;
531                 dev->trans_start = jiffies;
532                 netif_start_queue(dev);
533
534                 /* this is normally done in the interrupt when tx finishes */
535                 netif_wake_queue(dev);
536
537         } else if (len == 0) {
538                 netif_start_queue(dev);
539                 lp->stats.tx_dropped++;
540
541         } else {
542                 netif_start_queue(dev);
543                 printk(KERN_ERR "iss_net_start_xmit: failed(%d)\n", len);
544         }
545
546         spin_unlock_irqrestore(&lp->lock, flags);
547
548         dev_kfree_skb(skb);
549         return 0;
550 }
551
552
553 static struct net_device_stats *iss_net_get_stats(struct net_device *dev)
554 {
555         struct iss_net_private *lp = dev->priv;
556         return &lp->stats;
557 }
558
559 static void iss_net_set_multicast_list(struct net_device *dev)
560 {
561 #if 0
562         if (dev->flags & IFF_PROMISC)
563                 return;
564         else if (dev->mc_count)
565                 dev->flags |= IFF_ALLMULTI;
566         else
567                 dev->flags &= ~IFF_ALLMULTI;
568 #endif
569 }
570
571 static void iss_net_tx_timeout(struct net_device *dev)
572 {
573 #if 0
574         dev->trans_start = jiffies;
575         netif_wake_queue(dev);
576 #endif
577 }
578
579 static int iss_net_set_mac(struct net_device *dev, void *addr)
580 {
581 #if 0
582         struct iss_net_private *lp = dev->priv;
583         struct sockaddr *hwaddr = addr;
584
585         spin_lock(&lp->lock);
586         memcpy(dev->dev_addr, hwaddr->sa_data, ETH_ALEN);
587         spin_unlock(&lp->lock);
588 #endif
589
590         return 0;
591 }
592
593 static int iss_net_change_mtu(struct net_device *dev, int new_mtu)
594 {
595 #if 0
596         struct iss_net_private *lp = dev->priv;
597         int err = 0;
598
599         spin_lock(&lp->lock);
600
601         // FIXME not needed new_mtu = transport_set_mtu(new_mtu, &lp->user);
602
603         if (new_mtu < 0)
604                 err = new_mtu;
605         else
606                 dev->mtu = new_mtu;
607
608         spin_unlock(&lp->lock);
609         return err;
610 #endif
611         return -EINVAL;
612 }
613
614 static int iss_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
615 {
616 #if 0
617         static const struct ethtool_drvinfo info = {
618                 .cmd     = ETHTOOL_GDRVINFO,
619                 .driver  = DRIVER_NAME,
620                 .version = "42",
621         };
622         void *useraddr;
623         u32 ethcmd;
624
625         switch (cmd) {
626         case SIOCETHTOOL:
627                 useraddr = ifr->ifr_data;
628                 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
629                         return -EFAULT;
630
631                 switch (ethcmd) {
632                         case ETHTOOL_GDRVINFO:
633                                 if (copy_to_user(useraddr, &info, sizeof(info)))
634                                         return -EFAULT;
635                                 return 0;
636                         default:
637                                 return -EOPNOTSUPP;
638                 }
639         default:
640                 return -EINVAL;
641         }
642 #endif
643         return -EINVAL;
644 }
645
646 void iss_net_user_timer_expire(unsigned long _conn)
647 {
648 }
649
650
651 static struct device_driver iss_net_driver = {
652         .name  = DRIVER_NAME,
653         .bus   = &platform_bus_type,
654 };
655
656 static int driver_registered;
657
658 static int iss_net_configure(int index, char *init)
659 {
660         struct net_device *dev;
661         struct iss_net_private *lp;
662         int err;
663
664         if ((dev = alloc_etherdev(sizeof *lp)) == NULL) {
665                 printk(KERN_ERR "eth_configure: failed to allocate device\n");
666                 return 1;
667         }
668
669         /* Initialize private element. */
670
671         lp = dev->priv;
672         *lp = ((struct iss_net_private) {
673                 .device_list            = LIST_HEAD_INIT(lp->device_list),
674                 .opened_list            = LIST_HEAD_INIT(lp->opened_list),
675                 .lock                   = SPIN_LOCK_UNLOCKED,
676                 .dev                    = dev,
677                 .index                  = index,
678                 //.fd                   = -1,
679                 .mac                    = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0 },
680                 .have_mac               = 0,
681                 });
682
683         /*
684          * Try all transport protocols.
685          * Note: more protocols can be added by adding '&& !X_init(lp, eth)'.
686          */
687
688         if (!tuntap_probe(lp, index, init)) {
689                 printk("Invalid arguments. Skipping device!\n");
690                 goto errout;
691         }
692
693         printk(KERN_INFO "Netdevice %d ", index);
694         if (lp->have_mac)
695                 printk("(%02x:%02x:%02x:%02x:%02x:%02x) ",
696                                 lp->mac[0], lp->mac[1],
697                                 lp->mac[2], lp->mac[3],
698                                 lp->mac[4], lp->mac[5]);
699         printk(": ");
700
701         /* sysfs register */
702
703         if (!driver_registered) {
704                 driver_register(&iss_net_driver);
705                 driver_registered = 1;
706         }
707
708         spin_lock(&devices_lock);
709         list_add(&lp->device_list, &devices);
710         spin_unlock(&devices_lock);
711
712         lp->pdev.id = index;
713         lp->pdev.name = DRIVER_NAME;
714         platform_device_register(&lp->pdev);
715         SET_NETDEV_DEV(dev,&lp->pdev.dev);
716
717         /*
718          * If this name ends up conflicting with an existing registered
719          * netdevice, that is OK, register_netdev{,ice}() will notice this
720          * and fail.
721          */
722         snprintf(dev->name, sizeof dev->name, "eth%d", index);
723
724         dev->mtu = lp->mtu;
725         dev->open = iss_net_open;
726         dev->hard_start_xmit = iss_net_start_xmit;
727         dev->stop = iss_net_close;
728         dev->get_stats = iss_net_get_stats;
729         dev->set_multicast_list = iss_net_set_multicast_list;
730         dev->tx_timeout = iss_net_tx_timeout;
731         dev->set_mac_address = iss_net_set_mac;
732         dev->change_mtu = iss_net_change_mtu;
733         dev->do_ioctl = iss_net_ioctl;
734         dev->watchdog_timeo = (HZ >> 1);
735         dev->irq = -1;
736
737         rtnl_lock();
738         err = register_netdevice(dev);
739         rtnl_unlock();
740
741         if (err) {
742                 printk("Error registering net device!\n");
743                 /* XXX: should we call ->remove() here? */
744                 free_netdev(dev);
745                 return 1;
746         }
747
748         init_timer(&lp->tl);
749         lp->tl.function = iss_net_user_timer_expire;
750
751 #if 0
752         if (lp->have_mac)
753                 set_ether_mac(dev, lp->mac);
754 #endif
755         return 0;
756
757 errout:
758         // FIXME: unregister; free, etc..
759         return -EIO;
760
761 }
762
763 /* ------------------------------------------------------------------------- */
764
765 /* Filled in during early boot */
766
767 struct list_head eth_cmd_line = LIST_HEAD_INIT(eth_cmd_line);
768
769 struct iss_net_init {
770         struct list_head list;
771         char *init;             /* init string */
772         int index;
773 };
774
775 /*
776  * Parse the command line and look for 'ethX=...' fields, and register all
777  * those fields. They will be later initialized in iss_net_init.
778  */
779
780 #define ERR KERN_ERR "iss_net_setup: "
781
782 static int iss_net_setup(char *str)
783 {
784         struct iss_net_private *device = NULL;
785         struct iss_net_init *new;
786         struct list_head *ele;
787         char *end;
788         int n;
789
790         n = simple_strtoul(str, &end, 0);
791         if (end == str) {
792                 printk(ERR "Failed to parse '%s'\n", str);
793                 return 1;
794         }
795         if (n < 0) {
796                 printk(ERR "Device %d is negative\n", n);
797                 return 1;
798         }
799         if (*(str = end) != '=') {
800                 printk(ERR "Expected '=' after device number\n");
801                 return 1;
802         }
803
804         spin_lock(&devices_lock);
805
806         list_for_each(ele, &devices) {
807                 device = list_entry(ele, struct iss_net_private, device_list);
808                 if (device->index == n)
809                         break;
810         }
811
812         spin_unlock(&devices_lock);
813
814         if (device && device->index == n) {
815                 printk(ERR "Device %d already configured\n", n);
816                 return 1;
817         }
818
819         if ((new = alloc_bootmem(sizeof new)) == NULL) {
820                 printk("Alloc_bootmem failed\n");
821                 return 1;
822         }
823
824         INIT_LIST_HEAD(&new->list);
825         new->index = n;
826         new->init = str + 1;
827
828         list_add_tail(&new->list, &eth_cmd_line);
829         return 1;
830 }
831
832 #undef ERR
833
834 __setup("eth", iss_net_setup);
835
836 /*
837  * Initialize all ISS Ethernet devices previously registered in iss_net_setup.
838  */
839
840 static int iss_net_init(void)
841 {
842         struct list_head *ele, *next;
843
844         /* Walk through all Ethernet devices specified in the command line. */
845
846         list_for_each_safe(ele, next, &eth_cmd_line) {
847                 struct iss_net_init *eth;
848                 eth = list_entry(ele, struct iss_net_init, list);
849                 iss_net_configure(eth->index, eth->init);
850         }
851
852         return 1;
853 }
854
855 module_init(iss_net_init);
856