Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 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 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/dma-mapping.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/rio.h> |
| 18 | #include <linux/rio_drv.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 20 | #include <linux/rio_ids.h> |
| 21 | |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/etherdevice.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/crc32.h> |
| 26 | #include <linux/ethtool.h> |
Alexandre Bounine | f41e247 | 2016-03-22 14:26:11 -0700 | [diff] [blame] | 27 | #include <linux/reboot.h> |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 28 | |
| 29 | #define DRV_NAME "rionet" |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 30 | #define DRV_VERSION "0.3" |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 31 | #define DRV_AUTHOR "Matt Porter <mporter@kernel.crashing.org>" |
| 32 | #define DRV_DESC "Ethernet over RapidIO" |
| 33 | |
| 34 | MODULE_AUTHOR(DRV_AUTHOR); |
| 35 | MODULE_DESCRIPTION(DRV_DESC); |
| 36 | MODULE_LICENSE("GPL"); |
| 37 | |
| 38 | #define RIONET_DEFAULT_MSGLEVEL \ |
| 39 | (NETIF_MSG_DRV | \ |
| 40 | NETIF_MSG_LINK | \ |
| 41 | NETIF_MSG_RX_ERR | \ |
| 42 | NETIF_MSG_TX_ERR) |
| 43 | |
| 44 | #define RIONET_DOORBELL_JOIN 0x1000 |
| 45 | #define RIONET_DOORBELL_LEAVE 0x1001 |
| 46 | |
| 47 | #define RIONET_MAILBOX 0 |
| 48 | |
| 49 | #define RIONET_TX_RING_SIZE CONFIG_RIONET_TX_SIZE |
| 50 | #define RIONET_RX_RING_SIZE CONFIG_RIONET_RX_SIZE |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 51 | #define RIONET_MAX_NETS 8 |
Aurelien Jacquiot | 92444bb | 2016-03-22 14:25:45 -0700 | [diff] [blame] | 52 | #define RIONET_MSG_SIZE RIO_MAX_MSG_SIZE |
| 53 | #define RIONET_MAX_MTU (RIONET_MSG_SIZE - ETH_HLEN) |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 54 | |
| 55 | struct rionet_private { |
| 56 | struct rio_mport *mport; |
| 57 | struct sk_buff *rx_skb[RIONET_RX_RING_SIZE]; |
| 58 | struct sk_buff *tx_skb[RIONET_TX_RING_SIZE]; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 59 | int rx_slot; |
| 60 | int tx_slot; |
| 61 | int tx_cnt; |
| 62 | int ack_slot; |
| 63 | spinlock_t lock; |
| 64 | spinlock_t tx_lock; |
| 65 | u32 msg_enable; |
| 66 | }; |
| 67 | |
| 68 | struct rionet_peer { |
| 69 | struct list_head node; |
| 70 | struct rio_dev *rdev; |
| 71 | struct resource *res; |
| 72 | }; |
| 73 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 74 | struct rionet_net { |
| 75 | struct net_device *ndev; |
| 76 | struct list_head peers; |
| 77 | struct rio_dev **active; |
| 78 | int nact; /* number of active peers */ |
| 79 | }; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 80 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 81 | static struct rionet_net nets[RIONET_MAX_NETS]; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 82 | |
Alexandre Bounine | 284fb68 | 2011-08-25 15:59:13 -0700 | [diff] [blame] | 83 | #define is_rionet_capable(src_ops, dst_ops) \ |
| 84 | ((src_ops & RIO_SRC_OPS_DATA_MSG) && \ |
| 85 | (dst_ops & RIO_DST_OPS_DATA_MSG) && \ |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 86 | (src_ops & RIO_SRC_OPS_DOORBELL) && \ |
| 87 | (dst_ops & RIO_DST_OPS_DOORBELL)) |
| 88 | #define dev_rionet_capable(dev) \ |
Alexandre Bounine | 284fb68 | 2011-08-25 15:59:13 -0700 | [diff] [blame] | 89 | is_rionet_capable(dev->src_ops, dev->dst_ops) |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 90 | |
Alexandre Bounine | e0c87bd | 2011-11-02 13:39:15 -0700 | [diff] [blame] | 91 | #define RIONET_MAC_MATCH(x) (!memcmp((x), "\00\01\00\01", 4)) |
| 92 | #define RIONET_GET_DESTID(x) ((*((u8 *)x + 4) << 8) | *((u8 *)x + 5)) |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 93 | |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 94 | static int rionet_rx_clean(struct net_device *ndev) |
| 95 | { |
| 96 | int i; |
| 97 | int error = 0; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 98 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 99 | void *data; |
| 100 | |
| 101 | i = rnet->rx_slot; |
| 102 | |
| 103 | do { |
| 104 | if (!rnet->rx_skb[i]) |
| 105 | continue; |
| 106 | |
| 107 | if (!(data = rio_get_inb_message(rnet->mport, RIONET_MAILBOX))) |
| 108 | break; |
| 109 | |
| 110 | rnet->rx_skb[i]->data = data; |
| 111 | skb_put(rnet->rx_skb[i], RIO_MAX_MSG_SIZE); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 112 | rnet->rx_skb[i]->protocol = |
| 113 | eth_type_trans(rnet->rx_skb[i], ndev); |
| 114 | error = netif_rx(rnet->rx_skb[i]); |
| 115 | |
| 116 | if (error == NET_RX_DROP) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 117 | ndev->stats.rx_dropped++; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 118 | } else { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 119 | ndev->stats.rx_packets++; |
| 120 | ndev->stats.rx_bytes += RIO_MAX_MSG_SIZE; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != rnet->rx_slot); |
| 124 | |
| 125 | return i; |
| 126 | } |
| 127 | |
| 128 | static void rionet_rx_fill(struct net_device *ndev, int end) |
| 129 | { |
| 130 | int i; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 131 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 132 | |
| 133 | i = rnet->rx_slot; |
| 134 | do { |
| 135 | rnet->rx_skb[i] = dev_alloc_skb(RIO_MAX_MSG_SIZE); |
| 136 | |
| 137 | if (!rnet->rx_skb[i]) |
| 138 | break; |
| 139 | |
| 140 | rio_add_inb_buffer(rnet->mport, RIONET_MAILBOX, |
| 141 | rnet->rx_skb[i]->data); |
| 142 | } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != end); |
| 143 | |
| 144 | rnet->rx_slot = i; |
| 145 | } |
| 146 | |
| 147 | static int rionet_queue_tx_msg(struct sk_buff *skb, struct net_device *ndev, |
| 148 | struct rio_dev *rdev) |
| 149 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 150 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 151 | |
| 152 | rio_add_outb_message(rnet->mport, rdev, 0, skb->data, skb->len); |
| 153 | rnet->tx_skb[rnet->tx_slot] = skb; |
| 154 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 155 | ndev->stats.tx_packets++; |
| 156 | ndev->stats.tx_bytes += skb->len; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 157 | |
| 158 | if (++rnet->tx_cnt == RIONET_TX_RING_SIZE) |
| 159 | netif_stop_queue(ndev); |
| 160 | |
| 161 | ++rnet->tx_slot; |
| 162 | rnet->tx_slot &= (RIONET_TX_RING_SIZE - 1); |
| 163 | |
| 164 | if (netif_msg_tx_queued(rnet)) |
David S. Miller | 8df8a47 | 2011-05-22 20:35:54 -0400 | [diff] [blame] | 165 | printk(KERN_INFO "%s: queued skb len %8.8x\n", DRV_NAME, |
| 166 | skb->len); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 172 | { |
| 173 | int i; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 174 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 175 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 176 | u16 destid; |
| 177 | unsigned long flags; |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 178 | int add_num = 1; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 179 | |
| 180 | local_irq_save(flags); |
| 181 | if (!spin_trylock(&rnet->tx_lock)) { |
| 182 | local_irq_restore(flags); |
| 183 | return NETDEV_TX_LOCKED; |
| 184 | } |
| 185 | |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 186 | if (is_multicast_ether_addr(eth->h_dest)) |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 187 | add_num = nets[rnet->mport->id].nact; |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 188 | |
| 189 | if ((rnet->tx_cnt + add_num) > RIONET_TX_RING_SIZE) { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 190 | netif_stop_queue(ndev); |
| 191 | spin_unlock_irqrestore(&rnet->tx_lock, flags); |
| 192 | printk(KERN_ERR "%s: BUG! Tx Ring full when queue awake!\n", |
| 193 | ndev->name); |
| 194 | return NETDEV_TX_BUSY; |
| 195 | } |
| 196 | |
Tobias Klauser | abfc89c | 2011-07-03 23:54:54 +0000 | [diff] [blame] | 197 | if (is_multicast_ether_addr(eth->h_dest)) { |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 198 | int count = 0; |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 199 | |
Zhang Wei | e042323 | 2008-04-18 13:33:42 -0700 | [diff] [blame] | 200 | for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size); |
| 201 | i++) |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 202 | if (nets[rnet->mport->id].active[i]) { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 203 | rionet_queue_tx_msg(skb, ndev, |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 204 | nets[rnet->mport->id].active[i]); |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 205 | if (count) |
| 206 | atomic_inc(&skb->users); |
| 207 | count++; |
| 208 | } |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 209 | } else if (RIONET_MAC_MATCH(eth->h_dest)) { |
| 210 | destid = RIONET_GET_DESTID(eth->h_dest); |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 211 | if (nets[rnet->mport->id].active[destid]) |
| 212 | rionet_queue_tx_msg(skb, ndev, |
| 213 | nets[rnet->mport->id].active[destid]); |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 214 | else { |
| 215 | /* |
| 216 | * If the target device was removed from the list of |
| 217 | * active peers but we still have TX packets targeting |
| 218 | * it just report sending a packet to the target |
| 219 | * (without actual packet transfer). |
| 220 | */ |
| 221 | dev_kfree_skb_any(skb); |
| 222 | ndev->stats.tx_packets++; |
| 223 | ndev->stats.tx_bytes += skb->len; |
| 224 | } |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | spin_unlock_irqrestore(&rnet->tx_lock, flags); |
| 228 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 229 | return NETDEV_TX_OK; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u16 tid, |
| 233 | u16 info) |
| 234 | { |
| 235 | struct net_device *ndev = dev_id; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 236 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 237 | struct rionet_peer *peer; |
| 238 | |
| 239 | if (netif_msg_intr(rnet)) |
| 240 | printk(KERN_INFO "%s: doorbell sid %4.4x tid %4.4x info %4.4x", |
| 241 | DRV_NAME, sid, tid, info); |
| 242 | if (info == RIONET_DOORBELL_JOIN) { |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 243 | if (!nets[rnet->mport->id].active[sid]) { |
| 244 | list_for_each_entry(peer, |
| 245 | &nets[rnet->mport->id].peers, node) { |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 246 | if (peer->rdev->destid == sid) { |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 247 | nets[rnet->mport->id].active[sid] = |
| 248 | peer->rdev; |
| 249 | nets[rnet->mport->id].nact++; |
Alexandre Bounine | 7c4a610 | 2012-10-04 17:15:48 -0700 | [diff] [blame] | 250 | } |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 251 | } |
| 252 | rio_mport_send_doorbell(mport, sid, |
| 253 | RIONET_DOORBELL_JOIN); |
| 254 | } |
| 255 | } else if (info == RIONET_DOORBELL_LEAVE) { |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 256 | nets[rnet->mport->id].active[sid] = NULL; |
| 257 | nets[rnet->mport->id].nact--; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 258 | } else { |
| 259 | if (netif_msg_intr(rnet)) |
| 260 | printk(KERN_WARNING "%s: unhandled doorbell\n", |
| 261 | DRV_NAME); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | static void rionet_inb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot) |
| 266 | { |
| 267 | int n; |
| 268 | struct net_device *ndev = dev_id; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 269 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 270 | |
| 271 | if (netif_msg_intr(rnet)) |
| 272 | printk(KERN_INFO "%s: inbound message event, mbox %d slot %d\n", |
| 273 | DRV_NAME, mbox, slot); |
| 274 | |
| 275 | spin_lock(&rnet->lock); |
| 276 | if ((n = rionet_rx_clean(ndev)) != rnet->rx_slot) |
| 277 | rionet_rx_fill(ndev, n); |
| 278 | spin_unlock(&rnet->lock); |
| 279 | } |
| 280 | |
| 281 | static void rionet_outb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot) |
| 282 | { |
| 283 | struct net_device *ndev = dev_id; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 284 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 285 | |
Aurelien Jacquiot | 3691597 | 2016-03-22 14:25:42 -0700 | [diff] [blame] | 286 | spin_lock(&rnet->tx_lock); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 287 | |
| 288 | if (netif_msg_intr(rnet)) |
| 289 | printk(KERN_INFO |
| 290 | "%s: outbound message event, mbox %d slot %d\n", |
| 291 | DRV_NAME, mbox, slot); |
| 292 | |
| 293 | while (rnet->tx_cnt && (rnet->ack_slot != slot)) { |
| 294 | /* dma unmap single */ |
| 295 | dev_kfree_skb_irq(rnet->tx_skb[rnet->ack_slot]); |
| 296 | rnet->tx_skb[rnet->ack_slot] = NULL; |
| 297 | ++rnet->ack_slot; |
| 298 | rnet->ack_slot &= (RIONET_TX_RING_SIZE - 1); |
| 299 | rnet->tx_cnt--; |
| 300 | } |
| 301 | |
| 302 | if (rnet->tx_cnt < RIONET_TX_RING_SIZE) |
| 303 | netif_wake_queue(ndev); |
| 304 | |
Aurelien Jacquiot | 3691597 | 2016-03-22 14:25:42 -0700 | [diff] [blame] | 305 | spin_unlock(&rnet->tx_lock); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static int rionet_open(struct net_device *ndev) |
| 309 | { |
| 310 | int i, rc = 0; |
| 311 | struct rionet_peer *peer, *tmp; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 312 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 313 | |
| 314 | if (netif_msg_ifup(rnet)) |
| 315 | printk(KERN_INFO "%s: open\n", DRV_NAME); |
| 316 | |
| 317 | if ((rc = rio_request_inb_dbell(rnet->mport, |
| 318 | (void *)ndev, |
| 319 | RIONET_DOORBELL_JOIN, |
| 320 | RIONET_DOORBELL_LEAVE, |
| 321 | rionet_dbell_event)) < 0) |
| 322 | goto out; |
| 323 | |
| 324 | if ((rc = rio_request_inb_mbox(rnet->mport, |
| 325 | (void *)ndev, |
| 326 | RIONET_MAILBOX, |
| 327 | RIONET_RX_RING_SIZE, |
| 328 | rionet_inb_msg_event)) < 0) |
| 329 | goto out; |
| 330 | |
| 331 | if ((rc = rio_request_outb_mbox(rnet->mport, |
| 332 | (void *)ndev, |
| 333 | RIONET_MAILBOX, |
| 334 | RIONET_TX_RING_SIZE, |
| 335 | rionet_outb_msg_event)) < 0) |
| 336 | goto out; |
| 337 | |
| 338 | /* Initialize inbound message ring */ |
| 339 | for (i = 0; i < RIONET_RX_RING_SIZE; i++) |
| 340 | rnet->rx_skb[i] = NULL; |
| 341 | rnet->rx_slot = 0; |
| 342 | rionet_rx_fill(ndev, 0); |
| 343 | |
| 344 | rnet->tx_slot = 0; |
| 345 | rnet->tx_cnt = 0; |
| 346 | rnet->ack_slot = 0; |
| 347 | |
| 348 | netif_carrier_on(ndev); |
| 349 | netif_start_queue(ndev); |
| 350 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 351 | list_for_each_entry_safe(peer, tmp, |
| 352 | &nets[rnet->mport->id].peers, node) { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 353 | if (!(peer->res = rio_request_outb_dbell(peer->rdev, |
| 354 | RIONET_DOORBELL_JOIN, |
| 355 | RIONET_DOORBELL_LEAVE))) |
| 356 | { |
| 357 | printk(KERN_ERR "%s: error requesting doorbells\n", |
| 358 | DRV_NAME); |
| 359 | continue; |
| 360 | } |
| 361 | |
Alexandre Bounine | 284fb68 | 2011-08-25 15:59:13 -0700 | [diff] [blame] | 362 | /* Send a join message */ |
| 363 | rio_send_doorbell(peer->rdev, RIONET_DOORBELL_JOIN); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | out: |
| 367 | return rc; |
| 368 | } |
| 369 | |
| 370 | static int rionet_close(struct net_device *ndev) |
| 371 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 372 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 373 | struct rionet_peer *peer, *tmp; |
| 374 | int i; |
| 375 | |
| 376 | if (netif_msg_ifup(rnet)) |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 377 | printk(KERN_INFO "%s: close %s\n", DRV_NAME, ndev->name); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 378 | |
| 379 | netif_stop_queue(ndev); |
| 380 | netif_carrier_off(ndev); |
| 381 | |
| 382 | for (i = 0; i < RIONET_RX_RING_SIZE; i++) |
Wei Yongjun | aaff1e1 | 2009-02-25 00:18:12 +0000 | [diff] [blame] | 383 | kfree_skb(rnet->rx_skb[i]); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 384 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 385 | list_for_each_entry_safe(peer, tmp, |
| 386 | &nets[rnet->mport->id].peers, node) { |
| 387 | if (nets[rnet->mport->id].active[peer->rdev->destid]) { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 388 | rio_send_doorbell(peer->rdev, RIONET_DOORBELL_LEAVE); |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 389 | nets[rnet->mport->id].active[peer->rdev->destid] = NULL; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 390 | } |
| 391 | rio_release_outb_dbell(peer->rdev, peer->res); |
| 392 | } |
| 393 | |
| 394 | rio_release_inb_dbell(rnet->mport, RIONET_DOORBELL_JOIN, |
| 395 | RIONET_DOORBELL_LEAVE); |
| 396 | rio_release_inb_mbox(rnet->mport, RIONET_MAILBOX); |
| 397 | rio_release_outb_mbox(rnet->mport, RIONET_MAILBOX); |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Viresh Kumar | 71db87b | 2015-07-30 15:04:01 +0530 | [diff] [blame] | 402 | static void rionet_remove_dev(struct device *dev, struct subsys_interface *sif) |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 403 | { |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 404 | struct rio_dev *rdev = to_rio_dev(dev); |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 405 | unsigned char netid = rdev->net->hport->id; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 406 | struct rionet_peer *peer, *tmp; |
| 407 | |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 408 | if (dev_rionet_capable(rdev)) { |
| 409 | list_for_each_entry_safe(peer, tmp, &nets[netid].peers, node) { |
| 410 | if (peer->rdev == rdev) { |
| 411 | if (nets[netid].active[rdev->destid]) { |
| 412 | nets[netid].active[rdev->destid] = NULL; |
| 413 | nets[netid].nact--; |
| 414 | } |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 415 | |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 416 | list_del(&peer->node); |
| 417 | kfree(peer); |
| 418 | break; |
| 419 | } |
| 420 | } |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
| 424 | static void rionet_get_drvinfo(struct net_device *ndev, |
| 425 | struct ethtool_drvinfo *info) |
| 426 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 427 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 428 | |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 429 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
| 430 | strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
| 431 | strlcpy(info->fw_version, "n/a", sizeof(info->fw_version)); |
| 432 | strlcpy(info->bus_info, rnet->mport->name, sizeof(info->bus_info)); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static u32 rionet_get_msglevel(struct net_device *ndev) |
| 436 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 437 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 438 | |
| 439 | return rnet->msg_enable; |
| 440 | } |
| 441 | |
| 442 | static void rionet_set_msglevel(struct net_device *ndev, u32 value) |
| 443 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 444 | struct rionet_private *rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 445 | |
| 446 | rnet->msg_enable = value; |
| 447 | } |
| 448 | |
Aurelien Jacquiot | 92444bb | 2016-03-22 14:25:45 -0700 | [diff] [blame] | 449 | static int rionet_change_mtu(struct net_device *ndev, int new_mtu) |
| 450 | { |
| 451 | if ((new_mtu < 68) || (new_mtu > RIONET_MAX_MTU)) { |
| 452 | printk(KERN_ERR "%s: Invalid MTU size %d\n", |
| 453 | ndev->name, new_mtu); |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | ndev->mtu = new_mtu; |
| 457 | return 0; |
| 458 | } |
| 459 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 460 | static const struct ethtool_ops rionet_ethtool_ops = { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 461 | .get_drvinfo = rionet_get_drvinfo, |
| 462 | .get_msglevel = rionet_get_msglevel, |
| 463 | .set_msglevel = rionet_set_msglevel, |
| 464 | .get_link = ethtool_op_get_link, |
| 465 | }; |
| 466 | |
Alexander Beregalov | a33a2bb | 2009-04-15 12:52:56 +0000 | [diff] [blame] | 467 | static const struct net_device_ops rionet_netdev_ops = { |
| 468 | .ndo_open = rionet_open, |
| 469 | .ndo_stop = rionet_close, |
| 470 | .ndo_start_xmit = rionet_start_xmit, |
Aurelien Jacquiot | 92444bb | 2016-03-22 14:25:45 -0700 | [diff] [blame] | 471 | .ndo_change_mtu = rionet_change_mtu, |
Alexander Beregalov | a33a2bb | 2009-04-15 12:52:56 +0000 | [diff] [blame] | 472 | .ndo_validate_addr = eth_validate_addr, |
| 473 | .ndo_set_mac_address = eth_mac_addr, |
| 474 | }; |
| 475 | |
Yinglin Luan | 55caa92 | 2011-06-25 18:12:12 +0000 | [diff] [blame] | 476 | static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev) |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 477 | { |
| 478 | int rc = 0; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 479 | struct rionet_private *rnet; |
| 480 | u16 device_id; |
Akinobu Mita | acc6563 | 2012-03-30 01:01:46 +0000 | [diff] [blame] | 481 | const size_t rionet_active_bytes = sizeof(void *) * |
| 482 | RIO_MAX_ROUTE_ENTRIES(mport->sys_size); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 483 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 484 | nets[mport->id].active = (struct rio_dev **)__get_free_pages(GFP_KERNEL, |
| 485 | get_order(rionet_active_bytes)); |
| 486 | if (!nets[mport->id].active) { |
Zhang Wei | e042323 | 2008-04-18 13:33:42 -0700 | [diff] [blame] | 487 | rc = -ENOMEM; |
| 488 | goto out; |
| 489 | } |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 490 | memset((void *)nets[mport->id].active, 0, rionet_active_bytes); |
Zhang Wei | e042323 | 2008-04-18 13:33:42 -0700 | [diff] [blame] | 491 | |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 492 | /* Set up private area */ |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 493 | rnet = netdev_priv(ndev); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 494 | rnet->mport = mport; |
| 495 | |
| 496 | /* Set the default MAC address */ |
| 497 | device_id = rio_local_get_device_id(mport); |
| 498 | ndev->dev_addr[0] = 0x00; |
| 499 | ndev->dev_addr[1] = 0x01; |
| 500 | ndev->dev_addr[2] = 0x00; |
| 501 | ndev->dev_addr[3] = 0x01; |
| 502 | ndev->dev_addr[4] = device_id >> 8; |
| 503 | ndev->dev_addr[5] = device_id & 0xff; |
| 504 | |
Alexander Beregalov | a33a2bb | 2009-04-15 12:52:56 +0000 | [diff] [blame] | 505 | ndev->netdev_ops = &rionet_netdev_ops; |
Aurelien Jacquiot | 92444bb | 2016-03-22 14:25:45 -0700 | [diff] [blame] | 506 | ndev->mtu = RIONET_MAX_MTU; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 507 | ndev->features = NETIF_F_LLTX; |
Alexandre Bounine | 2aaf308 | 2014-04-07 15:38:56 -0700 | [diff] [blame] | 508 | SET_NETDEV_DEV(ndev, &mport->dev); |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 509 | ndev->ethtool_ops = &rionet_ethtool_ops; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 510 | |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 511 | spin_lock_init(&rnet->lock); |
| 512 | spin_lock_init(&rnet->tx_lock); |
| 513 | |
| 514 | rnet->msg_enable = RIONET_DEFAULT_MSGLEVEL; |
| 515 | |
| 516 | rc = register_netdev(ndev); |
| 517 | if (rc != 0) |
| 518 | goto out; |
| 519 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 520 | printk(KERN_INFO "%s: %s %s Version %s, MAC %pM, %s\n", |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 521 | ndev->name, |
| 522 | DRV_NAME, |
| 523 | DRV_DESC, |
| 524 | DRV_VERSION, |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 525 | ndev->dev_addr, |
| 526 | mport->name); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 527 | |
| 528 | out: |
| 529 | return rc; |
| 530 | } |
| 531 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 532 | static unsigned long net_table[RIONET_MAX_NETS/sizeof(unsigned long) + 1]; |
| 533 | |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 534 | static int rionet_add_dev(struct device *dev, struct subsys_interface *sif) |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 535 | { |
| 536 | int rc = -ENODEV; |
Alexandre Bounine | 284fb68 | 2011-08-25 15:59:13 -0700 | [diff] [blame] | 537 | u32 lsrc_ops, ldst_ops; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 538 | struct rionet_peer *peer; |
Yinglin Luan | 55caa92 | 2011-06-25 18:12:12 +0000 | [diff] [blame] | 539 | struct net_device *ndev = NULL; |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 540 | struct rio_dev *rdev = to_rio_dev(dev); |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 541 | unsigned char netid = rdev->net->hport->id; |
| 542 | int oldnet; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 543 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 544 | if (netid >= RIONET_MAX_NETS) |
| 545 | return rc; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 546 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 547 | oldnet = test_and_set_bit(netid, net_table); |
Yinglin Luan | 55caa92 | 2011-06-25 18:12:12 +0000 | [diff] [blame] | 548 | |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 549 | /* |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 550 | * If first time through this net, make sure local device is rionet |
| 551 | * capable and setup netdev (this step will be skipped in later probes |
| 552 | * on the same net). |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 553 | */ |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 554 | if (!oldnet) { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 555 | rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR, |
| 556 | &lsrc_ops); |
| 557 | rio_local_read_config_32(rdev->net->hport, RIO_DST_OPS_CAR, |
| 558 | &ldst_ops); |
Alexandre Bounine | 284fb68 | 2011-08-25 15:59:13 -0700 | [diff] [blame] | 559 | if (!is_rionet_capable(lsrc_ops, ldst_ops)) { |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 560 | printk(KERN_ERR |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 561 | "%s: local device %s is not network capable\n", |
| 562 | DRV_NAME, rdev->net->hport->name); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 563 | goto out; |
| 564 | } |
| 565 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 566 | /* Allocate our net_device structure */ |
| 567 | ndev = alloc_etherdev(sizeof(struct rionet_private)); |
| 568 | if (ndev == NULL) { |
| 569 | rc = -ENOMEM; |
| 570 | goto out; |
| 571 | } |
| 572 | nets[netid].ndev = ndev; |
Yinglin Luan | 55caa92 | 2011-06-25 18:12:12 +0000 | [diff] [blame] | 573 | rc = rionet_setup_netdev(rdev->net->hport, ndev); |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 574 | if (rc) { |
| 575 | printk(KERN_ERR "%s: failed to setup netdev (rc=%d)\n", |
| 576 | DRV_NAME, rc); |
| 577 | goto out; |
| 578 | } |
| 579 | |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 580 | INIT_LIST_HEAD(&nets[netid].peers); |
| 581 | nets[netid].nact = 0; |
| 582 | } else if (nets[netid].ndev == NULL) |
| 583 | goto out; |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 584 | |
| 585 | /* |
| 586 | * If the remote device has mailbox/doorbell capabilities, |
| 587 | * add it to the peer list. |
| 588 | */ |
| 589 | if (dev_rionet_capable(rdev)) { |
| 590 | if (!(peer = kmalloc(sizeof(struct rionet_peer), GFP_KERNEL))) { |
| 591 | rc = -ENOMEM; |
| 592 | goto out; |
| 593 | } |
| 594 | peer->rdev = rdev; |
Alexandre Bounine | 2fb717e | 2012-10-04 17:16:11 -0700 | [diff] [blame] | 595 | list_add_tail(&peer->node, &nets[netid].peers); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 598 | return 0; |
| 599 | out: |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 600 | return rc; |
| 601 | } |
| 602 | |
Alexandre Bounine | f41e247 | 2016-03-22 14:26:11 -0700 | [diff] [blame] | 603 | static int rionet_shutdown(struct notifier_block *nb, unsigned long code, |
| 604 | void *unused) |
| 605 | { |
| 606 | struct rionet_peer *peer, *tmp; |
| 607 | int i; |
| 608 | |
| 609 | pr_debug("%s: %s\n", DRV_NAME, __func__); |
| 610 | |
| 611 | for (i = 0; i < RIONET_MAX_NETS; i++) { |
| 612 | if (!nets[i].ndev) |
| 613 | continue; |
| 614 | |
| 615 | list_for_each_entry_safe(peer, tmp, &nets[i].peers, node) { |
| 616 | if (nets[i].active[peer->rdev->destid]) { |
| 617 | rio_send_doorbell(peer->rdev, |
| 618 | RIONET_DOORBELL_LEAVE); |
| 619 | nets[i].active[peer->rdev->destid] = NULL; |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | return NOTIFY_DONE; |
| 625 | } |
| 626 | |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 627 | #ifdef MODULE |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 628 | static struct rio_device_id rionet_id_table[] = { |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 629 | {RIO_DEVICE(RIO_ANY_ID, RIO_ANY_ID)}, |
| 630 | { 0, } /* terminate list */ |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 631 | }; |
| 632 | |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 633 | MODULE_DEVICE_TABLE(rapidio, rionet_id_table); |
| 634 | #endif |
| 635 | |
| 636 | static struct subsys_interface rionet_interface = { |
| 637 | .name = "rionet", |
| 638 | .subsys = &rio_bus_type, |
| 639 | .add_dev = rionet_add_dev, |
| 640 | .remove_dev = rionet_remove_dev, |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 641 | }; |
| 642 | |
Alexandre Bounine | f41e247 | 2016-03-22 14:26:11 -0700 | [diff] [blame] | 643 | static struct notifier_block rionet_notifier = { |
| 644 | .notifier_call = rionet_shutdown, |
| 645 | }; |
| 646 | |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 647 | static int __init rionet_init(void) |
| 648 | { |
Alexandre Bounine | f41e247 | 2016-03-22 14:26:11 -0700 | [diff] [blame] | 649 | int ret; |
| 650 | |
| 651 | ret = register_reboot_notifier(&rionet_notifier); |
| 652 | if (ret) { |
| 653 | pr_err("%s: failed to register reboot notifier (err=%d)\n", |
| 654 | DRV_NAME, ret); |
| 655 | return ret; |
| 656 | } |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 657 | return subsys_interface_register(&rionet_interface); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static void __exit rionet_exit(void) |
| 661 | { |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 662 | struct rionet_private *rnet; |
| 663 | struct net_device *ndev; |
| 664 | struct rionet_peer *peer, *tmp; |
| 665 | int i; |
| 666 | |
| 667 | for (i = 0; i < RIONET_MAX_NETS; i++) { |
| 668 | if (nets[i].ndev != NULL) { |
| 669 | ndev = nets[i].ndev; |
| 670 | rnet = netdev_priv(ndev); |
| 671 | unregister_netdev(ndev); |
| 672 | |
| 673 | list_for_each_entry_safe(peer, |
| 674 | tmp, &nets[i].peers, node) { |
| 675 | list_del(&peer->node); |
| 676 | kfree(peer); |
| 677 | } |
| 678 | |
| 679 | free_pages((unsigned long)nets[i].active, |
| 680 | get_order(sizeof(void *) * |
| 681 | RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size))); |
| 682 | nets[i].active = NULL; |
| 683 | |
| 684 | free_netdev(ndev); |
| 685 | } |
| 686 | } |
| 687 | |
Alexandre Bounine | f41e247 | 2016-03-22 14:26:11 -0700 | [diff] [blame] | 688 | unregister_reboot_notifier(&rionet_notifier); |
Alexandre Bounine | e6161d6 | 2013-07-03 15:08:52 -0700 | [diff] [blame] | 689 | subsys_interface_unregister(&rionet_interface); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Alexandre Bounine | 2f80998 | 2011-03-23 16:43:04 -0700 | [diff] [blame] | 692 | late_initcall(rionet_init); |
Matt Porter | f89efd5 | 2005-09-09 12:10:10 -0700 | [diff] [blame] | 693 | module_exit(rionet_exit); |