network.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. *
  3. * arch/xtensa/platforms/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. #include <linux/list.h>
  19. #include <linux/irq.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/slab.h>
  22. #include <linux/timer.h>
  23. #include <linux/if_ether.h>
  24. #include <linux/inetdevice.h>
  25. #include <linux/init.h>
  26. #include <linux/if_tun.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/ioctl.h>
  30. #include <linux/bootmem.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/rtnetlink.h>
  33. #include <linux/platform_device.h>
  34. #include <platform/simcall.h>
  35. #define DRIVER_NAME "iss-netdev"
  36. #define ETH_MAX_PACKET 1500
  37. #define ETH_HEADER_OTHER 14
  38. #define ISS_NET_TIMER_VALUE (2 * HZ)
  39. static DEFINE_SPINLOCK(opened_lock);
  40. static LIST_HEAD(opened);
  41. static DEFINE_SPINLOCK(devices_lock);
  42. static LIST_HEAD(devices);
  43. /* ------------------------------------------------------------------------- */
  44. /* We currently only support the TUNTAP transport protocol. */
  45. #define TRANSPORT_TUNTAP_NAME "tuntap"
  46. #define TRANSPORT_TUNTAP_MTU ETH_MAX_PACKET
  47. struct tuntap_info {
  48. char dev_name[IFNAMSIZ];
  49. int fixed_config;
  50. unsigned char gw[ETH_ALEN];
  51. int fd;
  52. };
  53. /* ------------------------------------------------------------------------- */
  54. /* This structure contains out private information for the driver. */
  55. struct iss_net_private {
  56. struct list_head device_list;
  57. struct list_head opened_list;
  58. spinlock_t lock;
  59. struct net_device *dev;
  60. struct platform_device pdev;
  61. struct timer_list tl;
  62. struct net_device_stats stats;
  63. struct timer_list timer;
  64. unsigned int timer_val;
  65. int index;
  66. int mtu;
  67. unsigned char mac[ETH_ALEN];
  68. int have_mac;
  69. struct {
  70. union {
  71. struct tuntap_info tuntap;
  72. } info;
  73. int (*open)(struct iss_net_private *lp);
  74. void (*close)(struct iss_net_private *lp);
  75. int (*read)(struct iss_net_private *lp, struct sk_buff **skb);
  76. int (*write)(struct iss_net_private *lp, struct sk_buff **skb);
  77. unsigned short (*protocol)(struct sk_buff *skb);
  78. int (*poll)(struct iss_net_private *lp);
  79. } tp;
  80. };
  81. /* ================================ HELPERS ================================ */
  82. static char *split_if_spec(char *str, ...)
  83. {
  84. char **arg, *end;
  85. va_list ap;
  86. va_start(ap, str);
  87. while ((arg = va_arg(ap, char**)) != NULL) {
  88. if (*str == '\0')
  89. return NULL;
  90. end = strchr(str, ',');
  91. if (end != str)
  92. *arg = str;
  93. if (end == NULL)
  94. return NULL;
  95. *end ++ = '\0';
  96. str = end;
  97. }
  98. va_end(ap);
  99. return str;
  100. }
  101. #if 0
  102. /* Adjust SKB. */
  103. struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
  104. {
  105. if ((skb != NULL) && (skb_tailroom(skb) < extra)) {
  106. struct sk_buff *skb2;
  107. skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
  108. dev_kfree_skb(skb);
  109. skb = skb2;
  110. }
  111. if (skb != NULL)
  112. skb_put(skb, extra);
  113. return skb;
  114. }
  115. #endif
  116. /* Return the IP address as a string for a given device. */
  117. static void dev_ip_addr(void *d, char *buf, char *bin_buf)
  118. {
  119. struct net_device *dev = d;
  120. struct in_device *ip = dev->ip_ptr;
  121. struct in_ifaddr *in;
  122. __be32 addr;
  123. if ((ip == NULL) || ((in = ip->ifa_list) == NULL)) {
  124. printk(KERN_WARNING "Device not assigned an IP address!\n");
  125. return;
  126. }
  127. addr = in->ifa_address;
  128. sprintf(buf, "%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff,
  129. (addr >> 16) & 0xff, addr >> 24);
  130. if (bin_buf) {
  131. bin_buf[0] = addr & 0xff;
  132. bin_buf[1] = (addr >> 8) & 0xff;
  133. bin_buf[2] = (addr >> 16) & 0xff;
  134. bin_buf[3] = addr >> 24;
  135. }
  136. }
  137. /* Set Ethernet address of the specified device. */
  138. static void inline set_ether_mac(void *d, unsigned char *addr)
  139. {
  140. struct net_device *dev = d;
  141. memcpy(dev->dev_addr, addr, ETH_ALEN);
  142. }
  143. /* ======================= TUNTAP TRANSPORT INTERFACE ====================== */
  144. static int tuntap_open(struct iss_net_private *lp)
  145. {
  146. struct ifreq ifr;
  147. char *dev_name = lp->tp.info.tuntap.dev_name;
  148. int err = -EINVAL;
  149. int fd;
  150. /* We currently only support a fixed configuration. */
  151. if (!lp->tp.info.tuntap.fixed_config)
  152. return -EINVAL;
  153. if ((fd = simc_open("/dev/net/tun", 02, 0)) < 0) { /* O_RDWR */
  154. printk("Failed to open /dev/net/tun, returned %d "
  155. "(errno = %d)\n", fd, errno);
  156. return fd;
  157. }
  158. memset(&ifr, 0, sizeof ifr);
  159. ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
  160. strlcpy(ifr.ifr_name, dev_name, sizeof ifr.ifr_name);
  161. if ((err = simc_ioctl(fd, TUNSETIFF, (void*) &ifr)) < 0) {
  162. printk("Failed to set interface, returned %d "
  163. "(errno = %d)\n", err, errno);
  164. simc_close(fd);
  165. return err;
  166. }
  167. lp->tp.info.tuntap.fd = fd;
  168. return err;
  169. }
  170. static void tuntap_close(struct iss_net_private *lp)
  171. {
  172. #if 0
  173. if (lp->tp.info.tuntap.fixed_config)
  174. iter_addresses(lp->tp.info.tuntap.dev, close_addr, lp->host.dev_name);
  175. #endif
  176. simc_close(lp->tp.info.tuntap.fd);
  177. lp->tp.info.tuntap.fd = -1;
  178. }
  179. static int tuntap_read (struct iss_net_private *lp, struct sk_buff **skb)
  180. {
  181. #if 0
  182. *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
  183. if (*skb == NULL)
  184. return -ENOMEM;
  185. #endif
  186. return simc_read(lp->tp.info.tuntap.fd,
  187. (*skb)->data, (*skb)->dev->mtu + ETH_HEADER_OTHER);
  188. }
  189. static int tuntap_write (struct iss_net_private *lp, struct sk_buff **skb)
  190. {
  191. return simc_write(lp->tp.info.tuntap.fd, (*skb)->data, (*skb)->len);
  192. }
  193. unsigned short tuntap_protocol(struct sk_buff *skb)
  194. {
  195. return eth_type_trans(skb, skb->dev);
  196. }
  197. static int tuntap_poll(struct iss_net_private *lp)
  198. {
  199. return simc_poll(lp->tp.info.tuntap.fd);
  200. }
  201. /*
  202. * Currently only a device name is supported.
  203. * ethX=tuntap[,[mac address][,[device name]]]
  204. */
  205. static int tuntap_probe(struct iss_net_private *lp, int index, char *init)
  206. {
  207. const int len = strlen(TRANSPORT_TUNTAP_NAME);
  208. char *dev_name = NULL, *mac_str = NULL, *rem = NULL;
  209. /* Transport should be 'tuntap': ethX=tuntap,mac,dev_name */
  210. if (strncmp(init, TRANSPORT_TUNTAP_NAME, len))
  211. return 0;
  212. if (*(init += strlen(TRANSPORT_TUNTAP_NAME)) == ',') {
  213. if ((rem=split_if_spec(init+1, &mac_str, &dev_name)) != NULL) {
  214. printk("Extra garbage on specification : '%s'\n", rem);
  215. return 0;
  216. }
  217. } else if (*init != '\0') {
  218. printk("Invalid argument: %s. Skipping device!\n", init);
  219. return 0;
  220. }
  221. if (dev_name) {
  222. strncpy(lp->tp.info.tuntap.dev_name, dev_name,
  223. sizeof lp->tp.info.tuntap.dev_name);
  224. lp->tp.info.tuntap.fixed_config = 1;
  225. } else
  226. strcpy(lp->tp.info.tuntap.dev_name, TRANSPORT_TUNTAP_NAME);
  227. #if 0
  228. if (setup_etheraddr(mac_str, lp->mac))
  229. lp->have_mac = 1;
  230. #endif
  231. lp->mtu = TRANSPORT_TUNTAP_MTU;
  232. //lp->info.tuntap.gate_addr = gate_addr;
  233. lp->tp.info.tuntap.fd = -1;
  234. lp->tp.open = tuntap_open;
  235. lp->tp.close = tuntap_close;
  236. lp->tp.read = tuntap_read;
  237. lp->tp.write = tuntap_write;
  238. lp->tp.protocol = tuntap_protocol;
  239. lp->tp.poll = tuntap_poll;
  240. printk("TUN/TAP backend - ");
  241. #if 0
  242. if (lp->host.gate_addr != NULL)
  243. printk("IP = %s", lp->host.gate_addr);
  244. #endif
  245. printk("\n");
  246. return 1;
  247. }
  248. /* ================================ ISS NET ================================ */
  249. static int iss_net_rx(struct net_device *dev)
  250. {
  251. struct iss_net_private *lp = netdev_priv(dev);
  252. int pkt_len;
  253. struct sk_buff *skb;
  254. /* Check if there is any new data. */
  255. if (lp->tp.poll(lp) == 0)
  256. return 0;
  257. /* Try to allocate memory, if it fails, try again next round. */
  258. if ((skb = dev_alloc_skb(dev->mtu + 2 + ETH_HEADER_OTHER)) == NULL) {
  259. lp->stats.rx_dropped++;
  260. return 0;
  261. }
  262. skb_reserve(skb, 2);
  263. /* Setup skb */
  264. skb->dev = dev;
  265. skb_reset_mac_header(skb);
  266. pkt_len = lp->tp.read(lp, &skb);
  267. skb_put(skb, pkt_len);
  268. if (pkt_len > 0) {
  269. skb_trim(skb, pkt_len);
  270. skb->protocol = lp->tp.protocol(skb);
  271. lp->stats.rx_bytes += skb->len;
  272. lp->stats.rx_packets++;
  273. // netif_rx(skb);
  274. netif_rx_ni(skb);
  275. return pkt_len;
  276. }
  277. kfree_skb(skb);
  278. return pkt_len;
  279. }
  280. static int iss_net_poll(void)
  281. {
  282. struct list_head *ele;
  283. int err, ret = 0;
  284. spin_lock(&opened_lock);
  285. list_for_each(ele, &opened) {
  286. struct iss_net_private *lp;
  287. lp = list_entry(ele, struct iss_net_private, opened_list);
  288. if (!netif_running(lp->dev))
  289. break;
  290. spin_lock(&lp->lock);
  291. while ((err = iss_net_rx(lp->dev)) > 0)
  292. ret++;
  293. spin_unlock(&lp->lock);
  294. if (err < 0) {
  295. printk(KERN_ERR "Device '%s' read returned %d, "
  296. "shutting it down\n", lp->dev->name, err);
  297. dev_close(lp->dev);
  298. } else {
  299. // FIXME reactivate_fd(lp->fd, ISS_ETH_IRQ);
  300. }
  301. }
  302. spin_unlock(&opened_lock);
  303. return ret;
  304. }
  305. static void iss_net_timer(unsigned long priv)
  306. {
  307. struct iss_net_private* lp = (struct iss_net_private*) priv;
  308. spin_lock(&lp->lock);
  309. iss_net_poll();
  310. mod_timer(&lp->timer, jiffies + lp->timer_val);
  311. spin_unlock(&lp->lock);
  312. }
  313. static int iss_net_open(struct net_device *dev)
  314. {
  315. struct iss_net_private *lp = netdev_priv(dev);
  316. char addr[sizeof "255.255.255.255\0"];
  317. int err;
  318. spin_lock(&lp->lock);
  319. if ((err = lp->tp.open(lp)) < 0)
  320. goto out;
  321. if (!lp->have_mac) {
  322. dev_ip_addr(dev, addr, &lp->mac[2]);
  323. set_ether_mac(dev, lp->mac);
  324. }
  325. netif_start_queue(dev);
  326. /* clear buffer - it can happen that the host side of the interface
  327. * is full when we get here. In this case, new data is never queued,
  328. * SIGIOs never arrive, and the net never works.
  329. */
  330. while ((err = iss_net_rx(dev)) > 0)
  331. ;
  332. spin_lock(&opened_lock);
  333. list_add(&lp->opened_list, &opened);
  334. spin_unlock(&opened_lock);
  335. init_timer(&lp->timer);
  336. lp->timer_val = ISS_NET_TIMER_VALUE;
  337. lp->timer.data = (unsigned long) lp;
  338. lp->timer.function = iss_net_timer;
  339. mod_timer(&lp->timer, jiffies + lp->timer_val);
  340. out:
  341. spin_unlock(&lp->lock);
  342. return err;
  343. }
  344. static int iss_net_close(struct net_device *dev)
  345. {
  346. struct iss_net_private *lp = netdev_priv(dev);
  347. printk("iss_net_close!\n");
  348. netif_stop_queue(dev);
  349. spin_lock(&lp->lock);
  350. spin_lock(&opened_lock);
  351. list_del(&opened);
  352. spin_unlock(&opened_lock);
  353. del_timer_sync(&lp->timer);
  354. lp->tp.close(lp);
  355. spin_unlock(&lp->lock);
  356. return 0;
  357. }
  358. static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
  359. {
  360. struct iss_net_private *lp = netdev_priv(dev);
  361. unsigned long flags;
  362. int len;
  363. netif_stop_queue(dev);
  364. spin_lock_irqsave(&lp->lock, flags);
  365. len = lp->tp.write(lp, &skb);
  366. if (len == skb->len) {
  367. lp->stats.tx_packets++;
  368. lp->stats.tx_bytes += skb->len;
  369. dev->trans_start = jiffies;
  370. netif_start_queue(dev);
  371. /* this is normally done in the interrupt when tx finishes */
  372. netif_wake_queue(dev);
  373. } else if (len == 0) {
  374. netif_start_queue(dev);
  375. lp->stats.tx_dropped++;
  376. } else {
  377. netif_start_queue(dev);
  378. printk(KERN_ERR "iss_net_start_xmit: failed(%d)\n", len);
  379. }
  380. spin_unlock_irqrestore(&lp->lock, flags);
  381. dev_kfree_skb(skb);
  382. return NETDEV_TX_OK;
  383. }
  384. static struct net_device_stats *iss_net_get_stats(struct net_device *dev)
  385. {
  386. struct iss_net_private *lp = netdev_priv(dev);
  387. return &lp->stats;
  388. }
  389. static void iss_net_set_multicast_list(struct net_device *dev)
  390. {
  391. #if 0
  392. if (dev->flags & IFF_PROMISC)
  393. return;
  394. else if (!netdev_mc_empty(dev))
  395. dev->flags |= IFF_ALLMULTI;
  396. else
  397. dev->flags &= ~IFF_ALLMULTI;
  398. #endif
  399. }
  400. static void iss_net_tx_timeout(struct net_device *dev)
  401. {
  402. #if 0
  403. dev->trans_start = jiffies;
  404. netif_wake_queue(dev);
  405. #endif
  406. }
  407. static int iss_net_set_mac(struct net_device *dev, void *addr)
  408. {
  409. #if 0
  410. struct iss_net_private *lp = netdev_priv(dev);
  411. struct sockaddr *hwaddr = addr;
  412. spin_lock(&lp->lock);
  413. memcpy(dev->dev_addr, hwaddr->sa_data, ETH_ALEN);
  414. spin_unlock(&lp->lock);
  415. #endif
  416. return 0;
  417. }
  418. static int iss_net_change_mtu(struct net_device *dev, int new_mtu)
  419. {
  420. #if 0
  421. struct iss_net_private *lp = netdev_priv(dev);
  422. int err = 0;
  423. spin_lock(&lp->lock);
  424. // FIXME not needed new_mtu = transport_set_mtu(new_mtu, &lp->user);
  425. if (new_mtu < 0)
  426. err = new_mtu;
  427. else
  428. dev->mtu = new_mtu;
  429. spin_unlock(&lp->lock);
  430. return err;
  431. #endif
  432. return -EINVAL;
  433. }
  434. void iss_net_user_timer_expire(unsigned long _conn)
  435. {
  436. }
  437. static struct platform_driver iss_net_driver = {
  438. .driver = {
  439. .name = DRIVER_NAME,
  440. },
  441. };
  442. static int driver_registered;
  443. static const struct net_device_ops iss_netdev_ops = {
  444. .ndo_open = iss_net_open,
  445. .ndo_stop = iss_net_close,
  446. .ndo_get_stats = iss_net_get_stats,
  447. .ndo_start_xmit = iss_net_start_xmit,
  448. .ndo_validate_addr = eth_validate_addr,
  449. .ndo_change_mtu = iss_net_change_mtu,
  450. .ndo_set_mac_address = iss_net_set_mac,
  451. //.ndo_do_ioctl = iss_net_ioctl,
  452. .ndo_tx_timeout = iss_net_tx_timeout,
  453. .ndo_set_rx_mode = iss_net_set_multicast_list,
  454. };
  455. static int iss_net_configure(int index, char *init)
  456. {
  457. struct net_device *dev;
  458. struct iss_net_private *lp;
  459. int err;
  460. if ((dev = alloc_etherdev(sizeof *lp)) == NULL) {
  461. printk(KERN_ERR "eth_configure: failed to allocate device\n");
  462. return 1;
  463. }
  464. /* Initialize private element. */
  465. lp = netdev_priv(dev);
  466. *lp = ((struct iss_net_private) {
  467. .device_list = LIST_HEAD_INIT(lp->device_list),
  468. .opened_list = LIST_HEAD_INIT(lp->opened_list),
  469. .lock = __SPIN_LOCK_UNLOCKED(lp.lock),
  470. .dev = dev,
  471. .index = index,
  472. //.fd = -1,
  473. .mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0 },
  474. .have_mac = 0,
  475. });
  476. /*
  477. * Try all transport protocols.
  478. * Note: more protocols can be added by adding '&& !X_init(lp, eth)'.
  479. */
  480. if (!tuntap_probe(lp, index, init)) {
  481. printk("Invalid arguments. Skipping device!\n");
  482. goto errout;
  483. }
  484. printk(KERN_INFO "Netdevice %d ", index);
  485. if (lp->have_mac)
  486. printk("(%pM) ", lp->mac);
  487. printk(": ");
  488. /* sysfs register */
  489. if (!driver_registered) {
  490. platform_driver_register(&iss_net_driver);
  491. driver_registered = 1;
  492. }
  493. spin_lock(&devices_lock);
  494. list_add(&lp->device_list, &devices);
  495. spin_unlock(&devices_lock);
  496. lp->pdev.id = index;
  497. lp->pdev.name = DRIVER_NAME;
  498. platform_device_register(&lp->pdev);
  499. SET_NETDEV_DEV(dev,&lp->pdev.dev);
  500. /*
  501. * If this name ends up conflicting with an existing registered
  502. * netdevice, that is OK, register_netdev{,ice}() will notice this
  503. * and fail.
  504. */
  505. snprintf(dev->name, sizeof dev->name, "eth%d", index);
  506. dev->netdev_ops = &iss_netdev_ops;
  507. dev->mtu = lp->mtu;
  508. dev->watchdog_timeo = (HZ >> 1);
  509. dev->irq = -1;
  510. rtnl_lock();
  511. err = register_netdevice(dev);
  512. rtnl_unlock();
  513. if (err) {
  514. printk("Error registering net device!\n");
  515. /* XXX: should we call ->remove() here? */
  516. free_netdev(dev);
  517. return 1;
  518. }
  519. init_timer(&lp->tl);
  520. lp->tl.function = iss_net_user_timer_expire;
  521. #if 0
  522. if (lp->have_mac)
  523. set_ether_mac(dev, lp->mac);
  524. #endif
  525. return 0;
  526. errout:
  527. // FIXME: unregister; free, etc..
  528. return -EIO;
  529. }
  530. /* ------------------------------------------------------------------------- */
  531. /* Filled in during early boot */
  532. struct list_head eth_cmd_line = LIST_HEAD_INIT(eth_cmd_line);
  533. struct iss_net_init {
  534. struct list_head list;
  535. char *init; /* init string */
  536. int index;
  537. };
  538. /*
  539. * Parse the command line and look for 'ethX=...' fields, and register all
  540. * those fields. They will be later initialized in iss_net_init.
  541. */
  542. #define ERR KERN_ERR "iss_net_setup: "
  543. static int iss_net_setup(char *str)
  544. {
  545. struct iss_net_private *device = NULL;
  546. struct iss_net_init *new;
  547. struct list_head *ele;
  548. char *end;
  549. int n;
  550. n = simple_strtoul(str, &end, 0);
  551. if (end == str) {
  552. printk(ERR "Failed to parse '%s'\n", str);
  553. return 1;
  554. }
  555. if (n < 0) {
  556. printk(ERR "Device %d is negative\n", n);
  557. return 1;
  558. }
  559. if (*(str = end) != '=') {
  560. printk(ERR "Expected '=' after device number\n");
  561. return 1;
  562. }
  563. spin_lock(&devices_lock);
  564. list_for_each(ele, &devices) {
  565. device = list_entry(ele, struct iss_net_private, device_list);
  566. if (device->index == n)
  567. break;
  568. }
  569. spin_unlock(&devices_lock);
  570. if (device && device->index == n) {
  571. printk(ERR "Device %d already configured\n", n);
  572. return 1;
  573. }
  574. if ((new = alloc_bootmem(sizeof new)) == NULL) {
  575. printk("Alloc_bootmem failed\n");
  576. return 1;
  577. }
  578. INIT_LIST_HEAD(&new->list);
  579. new->index = n;
  580. new->init = str + 1;
  581. list_add_tail(&new->list, &eth_cmd_line);
  582. return 1;
  583. }
  584. #undef ERR
  585. __setup("eth=", iss_net_setup);
  586. /*
  587. * Initialize all ISS Ethernet devices previously registered in iss_net_setup.
  588. */
  589. static int iss_net_init(void)
  590. {
  591. struct list_head *ele, *next;
  592. /* Walk through all Ethernet devices specified in the command line. */
  593. list_for_each_safe(ele, next, &eth_cmd_line) {
  594. struct iss_net_init *eth;
  595. eth = list_entry(ele, struct iss_net_init, list);
  596. iss_net_configure(eth->index, eth->init);
  597. }
  598. return 1;
  599. }
  600. module_init(iss_net_init);