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