rionet.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * rionet - Ethernet driver over RapidIO messaging services
  3. *
  4. * Copyright 2005 MontaVista Software, Inc.
  5. * Matt Porter <mporter@kernel.crashing.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/delay.h>
  16. #include <linux/rio.h>
  17. #include <linux/rio_drv.h>
  18. #include <linux/slab.h>
  19. #include <linux/rio_ids.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/crc32.h>
  24. #include <linux/ethtool.h>
  25. #define DRV_NAME "rionet"
  26. #define DRV_VERSION "0.3"
  27. #define DRV_AUTHOR "Matt Porter <mporter@kernel.crashing.org>"
  28. #define DRV_DESC "Ethernet over RapidIO"
  29. MODULE_AUTHOR(DRV_AUTHOR);
  30. MODULE_DESCRIPTION(DRV_DESC);
  31. MODULE_LICENSE("GPL");
  32. #define RIONET_DEFAULT_MSGLEVEL \
  33. (NETIF_MSG_DRV | \
  34. NETIF_MSG_LINK | \
  35. NETIF_MSG_RX_ERR | \
  36. NETIF_MSG_TX_ERR)
  37. #define RIONET_DOORBELL_JOIN 0x1000
  38. #define RIONET_DOORBELL_LEAVE 0x1001
  39. #define RIONET_MAILBOX 0
  40. #define RIONET_TX_RING_SIZE CONFIG_RIONET_TX_SIZE
  41. #define RIONET_RX_RING_SIZE CONFIG_RIONET_RX_SIZE
  42. #define RIONET_MAX_NETS 8
  43. struct rionet_private {
  44. struct rio_mport *mport;
  45. struct sk_buff *rx_skb[RIONET_RX_RING_SIZE];
  46. struct sk_buff *tx_skb[RIONET_TX_RING_SIZE];
  47. int rx_slot;
  48. int tx_slot;
  49. int tx_cnt;
  50. int ack_slot;
  51. spinlock_t lock;
  52. spinlock_t tx_lock;
  53. u32 msg_enable;
  54. };
  55. struct rionet_peer {
  56. struct list_head node;
  57. struct rio_dev *rdev;
  58. struct resource *res;
  59. };
  60. struct rionet_net {
  61. struct net_device *ndev;
  62. struct list_head peers;
  63. struct rio_dev **active;
  64. int nact; /* number of active peers */
  65. };
  66. static struct rionet_net nets[RIONET_MAX_NETS];
  67. #define is_rionet_capable(src_ops, dst_ops) \
  68. ((src_ops & RIO_SRC_OPS_DATA_MSG) && \
  69. (dst_ops & RIO_DST_OPS_DATA_MSG) && \
  70. (src_ops & RIO_SRC_OPS_DOORBELL) && \
  71. (dst_ops & RIO_DST_OPS_DOORBELL))
  72. #define dev_rionet_capable(dev) \
  73. is_rionet_capable(dev->src_ops, dev->dst_ops)
  74. #define RIONET_MAC_MATCH(x) (!memcmp((x), "\00\01\00\01", 4))
  75. #define RIONET_GET_DESTID(x) ((*((u8 *)x + 4) << 8) | *((u8 *)x + 5))
  76. static int rionet_rx_clean(struct net_device *ndev)
  77. {
  78. int i;
  79. int error = 0;
  80. struct rionet_private *rnet = netdev_priv(ndev);
  81. void *data;
  82. i = rnet->rx_slot;
  83. do {
  84. if (!rnet->rx_skb[i])
  85. continue;
  86. if (!(data = rio_get_inb_message(rnet->mport, RIONET_MAILBOX)))
  87. break;
  88. rnet->rx_skb[i]->data = data;
  89. skb_put(rnet->rx_skb[i], RIO_MAX_MSG_SIZE);
  90. rnet->rx_skb[i]->protocol =
  91. eth_type_trans(rnet->rx_skb[i], ndev);
  92. error = netif_rx(rnet->rx_skb[i]);
  93. if (error == NET_RX_DROP) {
  94. ndev->stats.rx_dropped++;
  95. } else {
  96. ndev->stats.rx_packets++;
  97. ndev->stats.rx_bytes += RIO_MAX_MSG_SIZE;
  98. }
  99. } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != rnet->rx_slot);
  100. return i;
  101. }
  102. static void rionet_rx_fill(struct net_device *ndev, int end)
  103. {
  104. int i;
  105. struct rionet_private *rnet = netdev_priv(ndev);
  106. i = rnet->rx_slot;
  107. do {
  108. rnet->rx_skb[i] = dev_alloc_skb(RIO_MAX_MSG_SIZE);
  109. if (!rnet->rx_skb[i])
  110. break;
  111. rio_add_inb_buffer(rnet->mport, RIONET_MAILBOX,
  112. rnet->rx_skb[i]->data);
  113. } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != end);
  114. rnet->rx_slot = i;
  115. }
  116. static int rionet_queue_tx_msg(struct sk_buff *skb, struct net_device *ndev,
  117. struct rio_dev *rdev)
  118. {
  119. struct rionet_private *rnet = netdev_priv(ndev);
  120. rio_add_outb_message(rnet->mport, rdev, 0, skb->data, skb->len);
  121. rnet->tx_skb[rnet->tx_slot] = skb;
  122. ndev->stats.tx_packets++;
  123. ndev->stats.tx_bytes += skb->len;
  124. if (++rnet->tx_cnt == RIONET_TX_RING_SIZE)
  125. netif_stop_queue(ndev);
  126. ++rnet->tx_slot;
  127. rnet->tx_slot &= (RIONET_TX_RING_SIZE - 1);
  128. if (netif_msg_tx_queued(rnet))
  129. printk(KERN_INFO "%s: queued skb len %8.8x\n", DRV_NAME,
  130. skb->len);
  131. return 0;
  132. }
  133. static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  134. {
  135. int i;
  136. struct rionet_private *rnet = netdev_priv(ndev);
  137. struct ethhdr *eth = (struct ethhdr *)skb->data;
  138. u16 destid;
  139. unsigned long flags;
  140. int add_num = 1;
  141. local_irq_save(flags);
  142. if (!spin_trylock(&rnet->tx_lock)) {
  143. local_irq_restore(flags);
  144. return NETDEV_TX_LOCKED;
  145. }
  146. if (is_multicast_ether_addr(eth->h_dest))
  147. add_num = nets[rnet->mport->id].nact;
  148. if ((rnet->tx_cnt + add_num) > RIONET_TX_RING_SIZE) {
  149. netif_stop_queue(ndev);
  150. spin_unlock_irqrestore(&rnet->tx_lock, flags);
  151. printk(KERN_ERR "%s: BUG! Tx Ring full when queue awake!\n",
  152. ndev->name);
  153. return NETDEV_TX_BUSY;
  154. }
  155. if (is_multicast_ether_addr(eth->h_dest)) {
  156. int count = 0;
  157. for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size);
  158. i++)
  159. if (nets[rnet->mport->id].active[i]) {
  160. rionet_queue_tx_msg(skb, ndev,
  161. nets[rnet->mport->id].active[i]);
  162. if (count)
  163. atomic_inc(&skb->users);
  164. count++;
  165. }
  166. } else if (RIONET_MAC_MATCH(eth->h_dest)) {
  167. destid = RIONET_GET_DESTID(eth->h_dest);
  168. if (nets[rnet->mport->id].active[destid])
  169. rionet_queue_tx_msg(skb, ndev,
  170. nets[rnet->mport->id].active[destid]);
  171. else {
  172. /*
  173. * If the target device was removed from the list of
  174. * active peers but we still have TX packets targeting
  175. * it just report sending a packet to the target
  176. * (without actual packet transfer).
  177. */
  178. ndev->stats.tx_packets++;
  179. ndev->stats.tx_bytes += skb->len;
  180. dev_kfree_skb_any(skb);
  181. }
  182. }
  183. spin_unlock_irqrestore(&rnet->tx_lock, flags);
  184. return NETDEV_TX_OK;
  185. }
  186. static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u16 tid,
  187. u16 info)
  188. {
  189. struct net_device *ndev = dev_id;
  190. struct rionet_private *rnet = netdev_priv(ndev);
  191. struct rionet_peer *peer;
  192. if (netif_msg_intr(rnet))
  193. printk(KERN_INFO "%s: doorbell sid %4.4x tid %4.4x info %4.4x",
  194. DRV_NAME, sid, tid, info);
  195. if (info == RIONET_DOORBELL_JOIN) {
  196. if (!nets[rnet->mport->id].active[sid]) {
  197. list_for_each_entry(peer,
  198. &nets[rnet->mport->id].peers, node) {
  199. if (peer->rdev->destid == sid) {
  200. nets[rnet->mport->id].active[sid] =
  201. peer->rdev;
  202. nets[rnet->mport->id].nact++;
  203. }
  204. }
  205. rio_mport_send_doorbell(mport, sid,
  206. RIONET_DOORBELL_JOIN);
  207. }
  208. } else if (info == RIONET_DOORBELL_LEAVE) {
  209. nets[rnet->mport->id].active[sid] = NULL;
  210. nets[rnet->mport->id].nact--;
  211. } else {
  212. if (netif_msg_intr(rnet))
  213. printk(KERN_WARNING "%s: unhandled doorbell\n",
  214. DRV_NAME);
  215. }
  216. }
  217. static void rionet_inb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot)
  218. {
  219. int n;
  220. struct net_device *ndev = dev_id;
  221. struct rionet_private *rnet = netdev_priv(ndev);
  222. if (netif_msg_intr(rnet))
  223. printk(KERN_INFO "%s: inbound message event, mbox %d slot %d\n",
  224. DRV_NAME, mbox, slot);
  225. spin_lock(&rnet->lock);
  226. if ((n = rionet_rx_clean(ndev)) != rnet->rx_slot)
  227. rionet_rx_fill(ndev, n);
  228. spin_unlock(&rnet->lock);
  229. }
  230. static void rionet_outb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot)
  231. {
  232. struct net_device *ndev = dev_id;
  233. struct rionet_private *rnet = netdev_priv(ndev);
  234. spin_lock(&rnet->tx_lock);
  235. if (netif_msg_intr(rnet))
  236. printk(KERN_INFO
  237. "%s: outbound message event, mbox %d slot %d\n",
  238. DRV_NAME, mbox, slot);
  239. while (rnet->tx_cnt && (rnet->ack_slot != slot)) {
  240. /* dma unmap single */
  241. dev_kfree_skb_irq(rnet->tx_skb[rnet->ack_slot]);
  242. rnet->tx_skb[rnet->ack_slot] = NULL;
  243. ++rnet->ack_slot;
  244. rnet->ack_slot &= (RIONET_TX_RING_SIZE - 1);
  245. rnet->tx_cnt--;
  246. }
  247. if (rnet->tx_cnt < RIONET_TX_RING_SIZE)
  248. netif_wake_queue(ndev);
  249. spin_unlock(&rnet->tx_lock);
  250. }
  251. static int rionet_open(struct net_device *ndev)
  252. {
  253. int i, rc = 0;
  254. struct rionet_peer *peer, *tmp;
  255. struct rionet_private *rnet = netdev_priv(ndev);
  256. if (netif_msg_ifup(rnet))
  257. printk(KERN_INFO "%s: open\n", DRV_NAME);
  258. if ((rc = rio_request_inb_dbell(rnet->mport,
  259. (void *)ndev,
  260. RIONET_DOORBELL_JOIN,
  261. RIONET_DOORBELL_LEAVE,
  262. rionet_dbell_event)) < 0)
  263. goto out;
  264. if ((rc = rio_request_inb_mbox(rnet->mport,
  265. (void *)ndev,
  266. RIONET_MAILBOX,
  267. RIONET_RX_RING_SIZE,
  268. rionet_inb_msg_event)) < 0)
  269. goto out;
  270. if ((rc = rio_request_outb_mbox(rnet->mport,
  271. (void *)ndev,
  272. RIONET_MAILBOX,
  273. RIONET_TX_RING_SIZE,
  274. rionet_outb_msg_event)) < 0)
  275. goto out;
  276. /* Initialize inbound message ring */
  277. for (i = 0; i < RIONET_RX_RING_SIZE; i++)
  278. rnet->rx_skb[i] = NULL;
  279. rnet->rx_slot = 0;
  280. rionet_rx_fill(ndev, 0);
  281. rnet->tx_slot = 0;
  282. rnet->tx_cnt = 0;
  283. rnet->ack_slot = 0;
  284. netif_carrier_on(ndev);
  285. netif_start_queue(ndev);
  286. list_for_each_entry_safe(peer, tmp,
  287. &nets[rnet->mport->id].peers, node) {
  288. if (!(peer->res = rio_request_outb_dbell(peer->rdev,
  289. RIONET_DOORBELL_JOIN,
  290. RIONET_DOORBELL_LEAVE)))
  291. {
  292. printk(KERN_ERR "%s: error requesting doorbells\n",
  293. DRV_NAME);
  294. continue;
  295. }
  296. /* Send a join message */
  297. rio_send_doorbell(peer->rdev, RIONET_DOORBELL_JOIN);
  298. }
  299. out:
  300. return rc;
  301. }
  302. static int rionet_close(struct net_device *ndev)
  303. {
  304. struct rionet_private *rnet = netdev_priv(ndev);
  305. struct rionet_peer *peer, *tmp;
  306. int i;
  307. if (netif_msg_ifup(rnet))
  308. printk(KERN_INFO "%s: close %s\n", DRV_NAME, ndev->name);
  309. netif_stop_queue(ndev);
  310. netif_carrier_off(ndev);
  311. for (i = 0; i < RIONET_RX_RING_SIZE; i++)
  312. kfree_skb(rnet->rx_skb[i]);
  313. list_for_each_entry_safe(peer, tmp,
  314. &nets[rnet->mport->id].peers, node) {
  315. if (nets[rnet->mport->id].active[peer->rdev->destid]) {
  316. rio_send_doorbell(peer->rdev, RIONET_DOORBELL_LEAVE);
  317. nets[rnet->mport->id].active[peer->rdev->destid] = NULL;
  318. }
  319. rio_release_outb_dbell(peer->rdev, peer->res);
  320. }
  321. rio_release_inb_dbell(rnet->mport, RIONET_DOORBELL_JOIN,
  322. RIONET_DOORBELL_LEAVE);
  323. rio_release_inb_mbox(rnet->mport, RIONET_MAILBOX);
  324. rio_release_outb_mbox(rnet->mport, RIONET_MAILBOX);
  325. return 0;
  326. }
  327. static void rionet_remove_dev(struct device *dev, struct subsys_interface *sif)
  328. {
  329. struct rio_dev *rdev = to_rio_dev(dev);
  330. unsigned char netid = rdev->net->hport->id;
  331. struct rionet_peer *peer, *tmp;
  332. if (dev_rionet_capable(rdev)) {
  333. list_for_each_entry_safe(peer, tmp, &nets[netid].peers, node) {
  334. if (peer->rdev == rdev) {
  335. if (nets[netid].active[rdev->destid]) {
  336. nets[netid].active[rdev->destid] = NULL;
  337. nets[netid].nact--;
  338. }
  339. list_del(&peer->node);
  340. kfree(peer);
  341. break;
  342. }
  343. }
  344. }
  345. }
  346. static void rionet_get_drvinfo(struct net_device *ndev,
  347. struct ethtool_drvinfo *info)
  348. {
  349. struct rionet_private *rnet = netdev_priv(ndev);
  350. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  351. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  352. strlcpy(info->fw_version, "n/a", sizeof(info->fw_version));
  353. strlcpy(info->bus_info, rnet->mport->name, sizeof(info->bus_info));
  354. }
  355. static u32 rionet_get_msglevel(struct net_device *ndev)
  356. {
  357. struct rionet_private *rnet = netdev_priv(ndev);
  358. return rnet->msg_enable;
  359. }
  360. static void rionet_set_msglevel(struct net_device *ndev, u32 value)
  361. {
  362. struct rionet_private *rnet = netdev_priv(ndev);
  363. rnet->msg_enable = value;
  364. }
  365. static const struct ethtool_ops rionet_ethtool_ops = {
  366. .get_drvinfo = rionet_get_drvinfo,
  367. .get_msglevel = rionet_get_msglevel,
  368. .set_msglevel = rionet_set_msglevel,
  369. .get_link = ethtool_op_get_link,
  370. };
  371. static const struct net_device_ops rionet_netdev_ops = {
  372. .ndo_open = rionet_open,
  373. .ndo_stop = rionet_close,
  374. .ndo_start_xmit = rionet_start_xmit,
  375. .ndo_change_mtu = eth_change_mtu,
  376. .ndo_validate_addr = eth_validate_addr,
  377. .ndo_set_mac_address = eth_mac_addr,
  378. };
  379. static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
  380. {
  381. int rc = 0;
  382. struct rionet_private *rnet;
  383. u16 device_id;
  384. const size_t rionet_active_bytes = sizeof(void *) *
  385. RIO_MAX_ROUTE_ENTRIES(mport->sys_size);
  386. nets[mport->id].active = (struct rio_dev **)__get_free_pages(GFP_KERNEL,
  387. get_order(rionet_active_bytes));
  388. if (!nets[mport->id].active) {
  389. rc = -ENOMEM;
  390. goto out;
  391. }
  392. memset((void *)nets[mport->id].active, 0, rionet_active_bytes);
  393. /* Set up private area */
  394. rnet = netdev_priv(ndev);
  395. rnet->mport = mport;
  396. /* Set the default MAC address */
  397. device_id = rio_local_get_device_id(mport);
  398. ndev->dev_addr[0] = 0x00;
  399. ndev->dev_addr[1] = 0x01;
  400. ndev->dev_addr[2] = 0x00;
  401. ndev->dev_addr[3] = 0x01;
  402. ndev->dev_addr[4] = device_id >> 8;
  403. ndev->dev_addr[5] = device_id & 0xff;
  404. ndev->netdev_ops = &rionet_netdev_ops;
  405. ndev->mtu = RIO_MAX_MSG_SIZE - 14;
  406. ndev->features = NETIF_F_LLTX;
  407. SET_NETDEV_DEV(ndev, &mport->dev);
  408. ndev->ethtool_ops = &rionet_ethtool_ops;
  409. spin_lock_init(&rnet->lock);
  410. spin_lock_init(&rnet->tx_lock);
  411. rnet->msg_enable = RIONET_DEFAULT_MSGLEVEL;
  412. rc = register_netdev(ndev);
  413. if (rc != 0)
  414. goto out;
  415. printk(KERN_INFO "%s: %s %s Version %s, MAC %pM, %s\n",
  416. ndev->name,
  417. DRV_NAME,
  418. DRV_DESC,
  419. DRV_VERSION,
  420. ndev->dev_addr,
  421. mport->name);
  422. out:
  423. return rc;
  424. }
  425. static unsigned long net_table[RIONET_MAX_NETS/sizeof(unsigned long) + 1];
  426. static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
  427. {
  428. int rc = -ENODEV;
  429. u32 lsrc_ops, ldst_ops;
  430. struct rionet_peer *peer;
  431. struct net_device *ndev = NULL;
  432. struct rio_dev *rdev = to_rio_dev(dev);
  433. unsigned char netid = rdev->net->hport->id;
  434. int oldnet;
  435. if (netid >= RIONET_MAX_NETS)
  436. return rc;
  437. oldnet = test_and_set_bit(netid, net_table);
  438. /*
  439. * If first time through this net, make sure local device is rionet
  440. * capable and setup netdev (this step will be skipped in later probes
  441. * on the same net).
  442. */
  443. if (!oldnet) {
  444. rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR,
  445. &lsrc_ops);
  446. rio_local_read_config_32(rdev->net->hport, RIO_DST_OPS_CAR,
  447. &ldst_ops);
  448. if (!is_rionet_capable(lsrc_ops, ldst_ops)) {
  449. printk(KERN_ERR
  450. "%s: local device %s is not network capable\n",
  451. DRV_NAME, rdev->net->hport->name);
  452. goto out;
  453. }
  454. /* Allocate our net_device structure */
  455. ndev = alloc_etherdev(sizeof(struct rionet_private));
  456. if (ndev == NULL) {
  457. rc = -ENOMEM;
  458. goto out;
  459. }
  460. nets[netid].ndev = ndev;
  461. rc = rionet_setup_netdev(rdev->net->hport, ndev);
  462. if (rc) {
  463. printk(KERN_ERR "%s: failed to setup netdev (rc=%d)\n",
  464. DRV_NAME, rc);
  465. goto out;
  466. }
  467. INIT_LIST_HEAD(&nets[netid].peers);
  468. nets[netid].nact = 0;
  469. } else if (nets[netid].ndev == NULL)
  470. goto out;
  471. /*
  472. * If the remote device has mailbox/doorbell capabilities,
  473. * add it to the peer list.
  474. */
  475. if (dev_rionet_capable(rdev)) {
  476. if (!(peer = kmalloc(sizeof(struct rionet_peer), GFP_KERNEL))) {
  477. rc = -ENOMEM;
  478. goto out;
  479. }
  480. peer->rdev = rdev;
  481. list_add_tail(&peer->node, &nets[netid].peers);
  482. }
  483. return 0;
  484. out:
  485. return rc;
  486. }
  487. #ifdef MODULE
  488. static struct rio_device_id rionet_id_table[] = {
  489. {RIO_DEVICE(RIO_ANY_ID, RIO_ANY_ID)},
  490. { 0, } /* terminate list */
  491. };
  492. MODULE_DEVICE_TABLE(rapidio, rionet_id_table);
  493. #endif
  494. static struct subsys_interface rionet_interface = {
  495. .name = "rionet",
  496. .subsys = &rio_bus_type,
  497. .add_dev = rionet_add_dev,
  498. .remove_dev = rionet_remove_dev,
  499. };
  500. static int __init rionet_init(void)
  501. {
  502. return subsys_interface_register(&rionet_interface);
  503. }
  504. static void __exit rionet_exit(void)
  505. {
  506. struct rionet_private *rnet;
  507. struct net_device *ndev;
  508. struct rionet_peer *peer, *tmp;
  509. int i;
  510. for (i = 0; i < RIONET_MAX_NETS; i++) {
  511. if (nets[i].ndev != NULL) {
  512. ndev = nets[i].ndev;
  513. rnet = netdev_priv(ndev);
  514. unregister_netdev(ndev);
  515. list_for_each_entry_safe(peer,
  516. tmp, &nets[i].peers, node) {
  517. list_del(&peer->node);
  518. kfree(peer);
  519. }
  520. free_pages((unsigned long)nets[i].active,
  521. get_order(sizeof(void *) *
  522. RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size)));
  523. nets[i].active = NULL;
  524. free_netdev(ndev);
  525. }
  526. }
  527. subsys_interface_unregister(&rionet_interface);
  528. }
  529. late_initcall(rionet_init);
  530. module_exit(rionet_exit);