network.c 17 KB

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