Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * IXP2000 MSF network device driver |
| 3 | * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org> |
| 4 | * Dedicated to Marija Kulikova. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/etherdevice.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/moduleparam.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/gfp.h> |
Lennert Buytenhek | 18ec5c7 | 2006-03-20 17:10:17 +0000 | [diff] [blame] | 19 | #include <asm/hardware/uengine.h> |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 20 | #include <asm/io.h> |
| 21 | #include "ixp2400_rx.ucode" |
| 22 | #include "ixp2400_tx.ucode" |
| 23 | #include "ixpdev_priv.h" |
| 24 | #include "ixpdev.h" |
Vincent Sanders | b9696ea | 2009-10-13 00:03:11 -0700 | [diff] [blame] | 25 | #include "pm3386.h" |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 26 | |
Lennert Buytenhek | 1274778 | 2005-11-23 12:50:08 +0100 | [diff] [blame] | 27 | #define DRV_MODULE_VERSION "0.2" |
| 28 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 29 | static int nds_count; |
| 30 | static struct net_device **nds; |
| 31 | static int nds_open; |
| 32 | static void (*set_port_admin_status)(int port, int up); |
| 33 | |
| 34 | static struct ixpdev_rx_desc * const rx_desc = |
| 35 | (struct ixpdev_rx_desc *)(IXP2000_SRAM0_VIRT_BASE + RX_BUF_DESC_BASE); |
| 36 | static struct ixpdev_tx_desc * const tx_desc = |
| 37 | (struct ixpdev_tx_desc *)(IXP2000_SRAM0_VIRT_BASE + TX_BUF_DESC_BASE); |
| 38 | static int tx_pointer; |
| 39 | |
| 40 | |
| 41 | static int ixpdev_xmit(struct sk_buff *skb, struct net_device *dev) |
| 42 | { |
| 43 | struct ixpdev_priv *ip = netdev_priv(dev); |
| 44 | struct ixpdev_tx_desc *desc; |
| 45 | int entry; |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 46 | unsigned long flags; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 47 | |
| 48 | if (unlikely(skb->len > PAGE_SIZE)) { |
| 49 | /* @@@ Count drops. */ |
| 50 | dev_kfree_skb(skb); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 51 | return NETDEV_TX_OK; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | entry = tx_pointer; |
| 55 | tx_pointer = (tx_pointer + 1) % TX_BUF_COUNT; |
| 56 | |
| 57 | desc = tx_desc + entry; |
| 58 | desc->pkt_length = skb->len; |
| 59 | desc->channel = ip->channel; |
| 60 | |
| 61 | skb_copy_and_csum_dev(skb, phys_to_virt(desc->buf_addr)); |
| 62 | dev_kfree_skb(skb); |
| 63 | |
| 64 | ixp2000_reg_write(RING_TX_PENDING, |
| 65 | TX_BUF_DESC_BASE + (entry * sizeof(struct ixpdev_tx_desc))); |
| 66 | |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 67 | local_irq_save(flags); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 68 | ip->tx_queue_entries++; |
| 69 | if (ip->tx_queue_entries == TX_BUF_COUNT_PER_CHAN) |
| 70 | netif_stop_queue(dev); |
Dongdong Deng | 4871953 | 2009-08-23 19:49:07 -0700 | [diff] [blame] | 71 | local_irq_restore(flags); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 72 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 73 | return NETDEV_TX_OK; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 77 | static int ixpdev_rx(struct net_device *dev, int processed, int budget) |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 78 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 79 | while (processed < budget) { |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 80 | struct ixpdev_rx_desc *desc; |
| 81 | struct sk_buff *skb; |
| 82 | void *buf; |
| 83 | u32 _desc; |
| 84 | |
| 85 | _desc = ixp2000_reg_read(RING_RX_DONE); |
| 86 | if (_desc == 0) |
| 87 | return 0; |
| 88 | |
| 89 | desc = rx_desc + |
| 90 | ((_desc - RX_BUF_DESC_BASE) / sizeof(struct ixpdev_rx_desc)); |
| 91 | buf = phys_to_virt(desc->buf_addr); |
| 92 | |
| 93 | if (desc->pkt_length < 4 || desc->pkt_length > PAGE_SIZE) { |
| 94 | printk(KERN_ERR "ixp2000: rx err, length %d\n", |
| 95 | desc->pkt_length); |
| 96 | goto err; |
| 97 | } |
| 98 | |
| 99 | if (desc->channel < 0 || desc->channel >= nds_count) { |
| 100 | printk(KERN_ERR "ixp2000: rx err, channel %d\n", |
| 101 | desc->channel); |
| 102 | goto err; |
| 103 | } |
| 104 | |
| 105 | /* @@@ Make FCS stripping configurable. */ |
| 106 | desc->pkt_length -= 4; |
| 107 | |
| 108 | if (unlikely(!netif_running(nds[desc->channel]))) |
| 109 | goto err; |
| 110 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 111 | skb = netdev_alloc_skb_ip_align(dev, desc->pkt_length); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 112 | if (likely(skb != NULL)) { |
David S. Miller | 8c7b7fa | 2007-07-10 22:08:12 -0700 | [diff] [blame] | 113 | skb_copy_to_linear_data(skb, buf, desc->pkt_length); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 114 | skb_put(skb, desc->pkt_length); |
Arnaldo Carvalho de Melo | 4c13eb6 | 2007-04-25 17:40:23 -0700 | [diff] [blame] | 115 | skb->protocol = eth_type_trans(skb, nds[desc->channel]); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 116 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 117 | netif_receive_skb(skb); |
| 118 | } |
| 119 | |
| 120 | err: |
| 121 | ixp2000_reg_write(RING_RX_PENDING, _desc); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 122 | processed++; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 125 | return processed; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* dev always points to nds[0]. */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 129 | static int ixpdev_poll(struct napi_struct *napi, int budget) |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 130 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 131 | struct ixpdev_priv *ip = container_of(napi, struct ixpdev_priv, napi); |
| 132 | struct net_device *dev = ip->dev; |
| 133 | int rx; |
| 134 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 135 | rx = 0; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 136 | do { |
| 137 | ixp2000_reg_write(IXP2000_IRQ_THD_RAW_STATUS_A_0, 0x00ff); |
| 138 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 139 | rx = ixpdev_rx(dev, rx, budget); |
| 140 | if (rx >= budget) |
| 141 | break; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 142 | } while (ixp2000_reg_read(IXP2000_IRQ_THD_RAW_STATUS_A_0) & 0x00ff); |
| 143 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 144 | napi_complete(napi); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 145 | ixp2000_reg_write(IXP2000_IRQ_THD_ENABLE_SET_A_0, 0x00ff); |
| 146 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 147 | return rx; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 150 | static void ixpdev_tx_complete(void) |
| 151 | { |
| 152 | int channel; |
| 153 | u32 wake; |
| 154 | |
| 155 | wake = 0; |
| 156 | while (1) { |
| 157 | struct ixpdev_priv *ip; |
| 158 | u32 desc; |
| 159 | int entry; |
| 160 | |
| 161 | desc = ixp2000_reg_read(RING_TX_DONE); |
| 162 | if (desc == 0) |
| 163 | break; |
| 164 | |
| 165 | /* @@@ Check whether entries come back in order. */ |
| 166 | entry = (desc - TX_BUF_DESC_BASE) / sizeof(struct ixpdev_tx_desc); |
| 167 | channel = tx_desc[entry].channel; |
| 168 | |
| 169 | if (channel < 0 || channel >= nds_count) { |
| 170 | printk(KERN_ERR "ixp2000: txcomp channel index " |
| 171 | "out of bounds (%d, %.8i, %d)\n", |
| 172 | channel, (unsigned int)desc, entry); |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | ip = netdev_priv(nds[channel]); |
| 177 | if (ip->tx_queue_entries == TX_BUF_COUNT_PER_CHAN) |
| 178 | wake |= 1 << channel; |
| 179 | ip->tx_queue_entries--; |
| 180 | } |
| 181 | |
| 182 | for (channel = 0; wake != 0; channel++) { |
| 183 | if (wake & (1 << channel)) { |
| 184 | netif_wake_queue(nds[channel]); |
| 185 | wake &= ~(1 << channel); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 190 | static irqreturn_t ixpdev_interrupt(int irq, void *dev_id) |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 191 | { |
| 192 | u32 status; |
| 193 | |
| 194 | status = ixp2000_reg_read(IXP2000_IRQ_THD_STATUS_A_0); |
| 195 | if (status == 0) |
| 196 | return IRQ_NONE; |
| 197 | |
| 198 | /* |
| 199 | * Any of the eight receive units signaled RX? |
| 200 | */ |
| 201 | if (status & 0x00ff) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 202 | struct net_device *dev = nds[0]; |
| 203 | struct ixpdev_priv *ip = netdev_priv(dev); |
| 204 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 205 | ixp2000_reg_wrb(IXP2000_IRQ_THD_ENABLE_CLEAR_A_0, 0x00ff); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 206 | if (likely(napi_schedule_prep(&ip->napi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 207 | __napi_schedule(&ip->napi); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 208 | } else { |
| 209 | printk(KERN_CRIT "ixp2000: irq while polling!!\n"); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Any of the eight transmit units signaled TXdone? |
| 215 | */ |
| 216 | if (status & 0xff00) { |
| 217 | ixp2000_reg_wrb(IXP2000_IRQ_THD_RAW_STATUS_A_0, 0xff00); |
| 218 | ixpdev_tx_complete(); |
| 219 | } |
| 220 | |
| 221 | return IRQ_HANDLED; |
| 222 | } |
| 223 | |
Lennert Buytenhek | 8ce51d6 | 2005-11-23 12:50:04 +0100 | [diff] [blame] | 224 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 225 | static void ixpdev_poll_controller(struct net_device *dev) |
| 226 | { |
| 227 | disable_irq(IRQ_IXP2000_THDA0); |
Yoann Padioleau | 0da2f0f | 2007-07-06 02:39:56 -0700 | [diff] [blame] | 228 | ixpdev_interrupt(IRQ_IXP2000_THDA0, dev); |
Lennert Buytenhek | 8ce51d6 | 2005-11-23 12:50:04 +0100 | [diff] [blame] | 229 | enable_irq(IRQ_IXP2000_THDA0); |
| 230 | } |
| 231 | #endif |
| 232 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 233 | static int ixpdev_open(struct net_device *dev) |
| 234 | { |
| 235 | struct ixpdev_priv *ip = netdev_priv(dev); |
| 236 | int err; |
| 237 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 238 | napi_enable(&ip->napi); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 239 | if (!nds_open++) { |
| 240 | err = request_irq(IRQ_IXP2000_THDA0, ixpdev_interrupt, |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 241 | IRQF_SHARED, "ixp2000_eth", nds); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 242 | if (err) { |
| 243 | nds_open--; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 244 | napi_disable(&ip->napi); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 245 | return err; |
| 246 | } |
| 247 | |
| 248 | ixp2000_reg_write(IXP2000_IRQ_THD_ENABLE_SET_A_0, 0xffff); |
| 249 | } |
| 250 | |
| 251 | set_port_admin_status(ip->channel, 1); |
| 252 | netif_start_queue(dev); |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int ixpdev_close(struct net_device *dev) |
| 258 | { |
| 259 | struct ixpdev_priv *ip = netdev_priv(dev); |
| 260 | |
| 261 | netif_stop_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 262 | napi_disable(&ip->napi); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 263 | set_port_admin_status(ip->channel, 0); |
| 264 | |
| 265 | if (!--nds_open) { |
| 266 | ixp2000_reg_write(IXP2000_IRQ_THD_ENABLE_CLEAR_A_0, 0xffff); |
| 267 | free_irq(IRQ_IXP2000_THDA0, nds); |
| 268 | } |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Vincent Sanders | b9696ea | 2009-10-13 00:03:11 -0700 | [diff] [blame] | 273 | static struct net_device_stats *ixpdev_get_stats(struct net_device *dev) |
| 274 | { |
| 275 | struct ixpdev_priv *ip = netdev_priv(dev); |
| 276 | |
| 277 | pm3386_get_stats(ip->channel, &(dev->stats)); |
| 278 | |
| 279 | return &(dev->stats); |
| 280 | } |
| 281 | |
Alexander Beregalov | e7090e3 | 2009-04-15 12:52:44 +0000 | [diff] [blame] | 282 | static const struct net_device_ops ixpdev_netdev_ops = { |
| 283 | .ndo_open = ixpdev_open, |
| 284 | .ndo_stop = ixpdev_close, |
| 285 | .ndo_start_xmit = ixpdev_xmit, |
| 286 | .ndo_change_mtu = eth_change_mtu, |
| 287 | .ndo_validate_addr = eth_validate_addr, |
| 288 | .ndo_set_mac_address = eth_mac_addr, |
Vincent Sanders | b9696ea | 2009-10-13 00:03:11 -0700 | [diff] [blame] | 289 | .ndo_get_stats = ixpdev_get_stats, |
Alexander Beregalov | e7090e3 | 2009-04-15 12:52:44 +0000 | [diff] [blame] | 290 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 291 | .ndo_poll_controller = ixpdev_poll_controller, |
| 292 | #endif |
| 293 | }; |
| 294 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 295 | struct net_device *ixpdev_alloc(int channel, int sizeof_priv) |
| 296 | { |
| 297 | struct net_device *dev; |
| 298 | struct ixpdev_priv *ip; |
| 299 | |
| 300 | dev = alloc_etherdev(sizeof_priv); |
| 301 | if (dev == NULL) |
| 302 | return NULL; |
| 303 | |
Alexander Beregalov | e7090e3 | 2009-04-15 12:52:44 +0000 | [diff] [blame] | 304 | dev->netdev_ops = &ixpdev_netdev_ops; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 305 | |
| 306 | dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 307 | |
| 308 | ip = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 309 | ip->dev = dev; |
| 310 | netif_napi_add(dev, &ip->napi, ixpdev_poll, 64); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 311 | ip->channel = channel; |
| 312 | ip->tx_queue_entries = 0; |
| 313 | |
| 314 | return dev; |
| 315 | } |
| 316 | |
| 317 | int ixpdev_init(int __nds_count, struct net_device **__nds, |
| 318 | void (*__set_port_admin_status)(int port, int up)) |
| 319 | { |
| 320 | int i; |
| 321 | int err; |
| 322 | |
Lennert Buytenhek | 5d4fe2c | 2006-03-29 15:12:44 +0200 | [diff] [blame] | 323 | BUILD_BUG_ON(RX_BUF_COUNT > 192 || TX_BUF_COUNT > 192); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 324 | |
Lennert Buytenhek | 1274778 | 2005-11-23 12:50:08 +0100 | [diff] [blame] | 325 | printk(KERN_INFO "IXP2000 MSF ethernet driver %s\n", DRV_MODULE_VERSION); |
| 326 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 327 | nds_count = __nds_count; |
| 328 | nds = __nds; |
| 329 | set_port_admin_status = __set_port_admin_status; |
| 330 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 331 | for (i = 0; i < RX_BUF_COUNT; i++) { |
| 332 | void *buf; |
| 333 | |
| 334 | buf = (void *)get_zeroed_page(GFP_KERNEL); |
| 335 | if (buf == NULL) { |
| 336 | err = -ENOMEM; |
| 337 | while (--i >= 0) |
| 338 | free_page((unsigned long)phys_to_virt(rx_desc[i].buf_addr)); |
Lennert Buytenhek | 0c49919 | 2005-11-23 12:49:05 +0100 | [diff] [blame] | 339 | goto err_out; |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 340 | } |
| 341 | rx_desc[i].buf_addr = virt_to_phys(buf); |
| 342 | rx_desc[i].buf_length = PAGE_SIZE; |
| 343 | } |
| 344 | |
| 345 | /* @@@ Maybe we shouldn't be preallocating TX buffers. */ |
| 346 | for (i = 0; i < TX_BUF_COUNT; i++) { |
| 347 | void *buf; |
| 348 | |
| 349 | buf = (void *)get_zeroed_page(GFP_KERNEL); |
| 350 | if (buf == NULL) { |
| 351 | err = -ENOMEM; |
| 352 | while (--i >= 0) |
| 353 | free_page((unsigned long)phys_to_virt(tx_desc[i].buf_addr)); |
| 354 | goto err_free_rx; |
| 355 | } |
| 356 | tx_desc[i].buf_addr = virt_to_phys(buf); |
| 357 | } |
| 358 | |
| 359 | /* 256 entries, ring status set means 'empty', base address 0x0000. */ |
| 360 | ixp2000_reg_write(RING_RX_PENDING_BASE, 0x44000000); |
| 361 | ixp2000_reg_write(RING_RX_PENDING_HEAD, 0x00000000); |
| 362 | ixp2000_reg_write(RING_RX_PENDING_TAIL, 0x00000000); |
| 363 | |
| 364 | /* 256 entries, ring status set means 'full', base address 0x0400. */ |
| 365 | ixp2000_reg_write(RING_RX_DONE_BASE, 0x40000400); |
| 366 | ixp2000_reg_write(RING_RX_DONE_HEAD, 0x00000000); |
| 367 | ixp2000_reg_write(RING_RX_DONE_TAIL, 0x00000000); |
| 368 | |
| 369 | for (i = 0; i < RX_BUF_COUNT; i++) { |
| 370 | ixp2000_reg_write(RING_RX_PENDING, |
| 371 | RX_BUF_DESC_BASE + (i * sizeof(struct ixpdev_rx_desc))); |
| 372 | } |
| 373 | |
| 374 | ixp2000_uengine_load(0, &ixp2400_rx); |
| 375 | ixp2000_uengine_start_contexts(0, 0xff); |
| 376 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 377 | /* 256 entries, ring status set means 'empty', base address 0x0800. */ |
| 378 | ixp2000_reg_write(RING_TX_PENDING_BASE, 0x44000800); |
| 379 | ixp2000_reg_write(RING_TX_PENDING_HEAD, 0x00000000); |
| 380 | ixp2000_reg_write(RING_TX_PENDING_TAIL, 0x00000000); |
| 381 | |
| 382 | /* 256 entries, ring status set means 'full', base address 0x0c00. */ |
| 383 | ixp2000_reg_write(RING_TX_DONE_BASE, 0x40000c00); |
| 384 | ixp2000_reg_write(RING_TX_DONE_HEAD, 0x00000000); |
| 385 | ixp2000_reg_write(RING_TX_DONE_TAIL, 0x00000000); |
| 386 | |
| 387 | ixp2000_uengine_load(1, &ixp2400_tx); |
| 388 | ixp2000_uengine_start_contexts(1, 0xff); |
| 389 | |
Lennert Buytenhek | 0c49919 | 2005-11-23 12:49:05 +0100 | [diff] [blame] | 390 | for (i = 0; i < nds_count; i++) { |
| 391 | err = register_netdev(nds[i]); |
| 392 | if (err) { |
| 393 | while (--i >= 0) |
| 394 | unregister_netdev(nds[i]); |
| 395 | goto err_free_tx; |
| 396 | } |
| 397 | } |
| 398 | |
Lennert Buytenhek | 7ed98bf | 2005-11-23 12:49:43 +0100 | [diff] [blame] | 399 | for (i = 0; i < nds_count; i++) { |
| 400 | printk(KERN_INFO "%s: IXP2000 MSF ethernet (port %d), " |
| 401 | "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x.\n", nds[i]->name, i, |
| 402 | nds[i]->dev_addr[0], nds[i]->dev_addr[1], |
| 403 | nds[i]->dev_addr[2], nds[i]->dev_addr[3], |
| 404 | nds[i]->dev_addr[4], nds[i]->dev_addr[5]); |
| 405 | } |
| 406 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 407 | return 0; |
| 408 | |
Lennert Buytenhek | 0c49919 | 2005-11-23 12:49:05 +0100 | [diff] [blame] | 409 | err_free_tx: |
| 410 | for (i = 0; i < TX_BUF_COUNT; i++) |
| 411 | free_page((unsigned long)phys_to_virt(tx_desc[i].buf_addr)); |
| 412 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 413 | err_free_rx: |
| 414 | for (i = 0; i < RX_BUF_COUNT; i++) |
| 415 | free_page((unsigned long)phys_to_virt(rx_desc[i].buf_addr)); |
| 416 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 417 | err_out: |
| 418 | return err; |
| 419 | } |
| 420 | |
| 421 | void ixpdev_deinit(void) |
| 422 | { |
| 423 | int i; |
| 424 | |
| 425 | /* @@@ Flush out pending packets. */ |
| 426 | |
Lennert Buytenhek | 0c49919 | 2005-11-23 12:49:05 +0100 | [diff] [blame] | 427 | for (i = 0; i < nds_count; i++) |
| 428 | unregister_netdev(nds[i]); |
| 429 | |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 430 | ixp2000_uengine_stop_contexts(1, 0xff); |
| 431 | ixp2000_uengine_stop_contexts(0, 0xff); |
| 432 | ixp2000_uengine_reset(0x3); |
| 433 | |
| 434 | for (i = 0; i < TX_BUF_COUNT; i++) |
| 435 | free_page((unsigned long)phys_to_virt(tx_desc[i].buf_addr)); |
| 436 | |
| 437 | for (i = 0; i < RX_BUF_COUNT; i++) |
| 438 | free_page((unsigned long)phys_to_virt(rx_desc[i].buf_addr)); |
Lennert Buytenhek | 15d014d | 2005-11-11 18:23:13 +0100 | [diff] [blame] | 439 | } |