Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sgiseeq.c: Seeq8003 ethernet driver for SGI machines. |
| 3 | * |
| 4 | * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com) |
| 5 | */ |
Ralf Baechle | a4d4d51 | 2006-03-08 11:49:31 +0000 | [diff] [blame] | 6 | |
| 7 | #undef DEBUG |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/string.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/netdevice.h> |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
| 20 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/sgi/hpc3.h> |
| 23 | #include <asm/sgi/ip22.h> |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 24 | #include <asm/sgi/seeq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "sgiseeq.h" |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static char *sgiseeqstr = "SGI Seeq8003"; |
| 29 | |
| 30 | /* |
| 31 | * If you want speed, you do something silly, it always has worked for me. So, |
| 32 | * with that in mind, I've decided to make this driver look completely like a |
| 33 | * stupid Lance from a driver architecture perspective. Only difference is that |
| 34 | * here our "ring buffer" looks and acts like a real Lance one does but is |
| 35 | * layed out like how the HPC DMA and the Seeq want it to. You'd be surprised |
| 36 | * how a stupid idea like this can pay off in performance, not to mention |
| 37 | * making this driver 2,000 times easier to write. ;-) |
| 38 | */ |
| 39 | |
| 40 | /* Tune these if we tend to run out often etc. */ |
| 41 | #define SEEQ_RX_BUFFERS 16 |
| 42 | #define SEEQ_TX_BUFFERS 16 |
| 43 | |
| 44 | #define PKT_BUF_SZ 1584 |
| 45 | |
| 46 | #define NEXT_RX(i) (((i) + 1) & (SEEQ_RX_BUFFERS - 1)) |
| 47 | #define NEXT_TX(i) (((i) + 1) & (SEEQ_TX_BUFFERS - 1)) |
| 48 | #define PREV_RX(i) (((i) - 1) & (SEEQ_RX_BUFFERS - 1)) |
| 49 | #define PREV_TX(i) (((i) - 1) & (SEEQ_TX_BUFFERS - 1)) |
| 50 | |
| 51 | #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \ |
| 52 | sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \ |
| 53 | sp->tx_old - sp->tx_new - 1) |
| 54 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 55 | #define VIRT_TO_DMA(sp, v) ((sp)->srings_dma + \ |
| 56 | (dma_addr_t)((unsigned long)(v) - \ |
| 57 | (unsigned long)((sp)->rx_desc))) |
| 58 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 59 | /* Copy frames shorter than rx_copybreak, otherwise pass on up in |
| 60 | * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha). |
| 61 | */ |
| 62 | static int rx_copybreak = 100; |
| 63 | |
| 64 | #define PAD_SIZE (128 - sizeof(struct hpc_dma_desc) - sizeof(void *)) |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | struct sgiseeq_rx_desc { |
| 67 | volatile struct hpc_dma_desc rdma; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 68 | u8 padding[PAD_SIZE]; |
| 69 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct sgiseeq_tx_desc { |
| 73 | volatile struct hpc_dma_desc tdma; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 74 | u8 padding[PAD_SIZE]; |
| 75 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* |
| 79 | * Warning: This structure is layed out in a certain way because HPC dma |
| 80 | * descriptors must be 8-byte aligned. So don't touch this without |
| 81 | * some care. |
| 82 | */ |
| 83 | struct sgiseeq_init_block { /* Note the name ;-) */ |
| 84 | struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS]; |
| 85 | struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS]; |
| 86 | }; |
| 87 | |
| 88 | struct sgiseeq_private { |
| 89 | struct sgiseeq_init_block *srings; |
Ralf Baechle | 99cd149 | 2007-09-04 14:41:01 +0100 | [diff] [blame] | 90 | dma_addr_t srings_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* Ptrs to the descriptors in uncached space. */ |
| 93 | struct sgiseeq_rx_desc *rx_desc; |
| 94 | struct sgiseeq_tx_desc *tx_desc; |
| 95 | |
| 96 | char *name; |
| 97 | struct hpc3_ethregs *hregs; |
| 98 | struct sgiseeq_regs *sregs; |
| 99 | |
| 100 | /* Ring entry counters. */ |
| 101 | unsigned int rx_new, tx_new; |
| 102 | unsigned int rx_old, tx_old; |
| 103 | |
| 104 | int is_edlc; |
| 105 | unsigned char control; |
| 106 | unsigned char mode; |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | spinlock_t tx_lock; |
| 109 | }; |
| 110 | |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 111 | static inline void dma_sync_desc_cpu(struct net_device *dev, void *addr) |
| 112 | { |
| 113 | dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc), |
| 114 | DMA_FROM_DEVICE); |
| 115 | } |
| 116 | |
| 117 | static inline void dma_sync_desc_dev(struct net_device *dev, void *addr) |
| 118 | { |
| 119 | dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc), |
| 120 | DMA_TO_DEVICE); |
| 121 | } |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs) |
| 124 | { |
Ralf Baechle | 302a5c4b | 2005-10-10 14:50:56 +0100 | [diff] [blame] | 125 | hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | udelay(20); |
Ralf Baechle | 302a5c4b | 2005-10-10 14:50:56 +0100 | [diff] [blame] | 127 | hregs->reset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs, |
| 131 | struct sgiseeq_regs *sregs) |
| 132 | { |
| 133 | hregs->rx_ctrl = hregs->tx_ctrl = 0; |
| 134 | hpc3_eth_reset(hregs); |
| 135 | } |
| 136 | |
| 137 | #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \ |
| 138 | SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC) |
| 139 | |
| 140 | static inline void seeq_go(struct sgiseeq_private *sp, |
| 141 | struct hpc3_ethregs *hregs, |
| 142 | struct sgiseeq_regs *sregs) |
| 143 | { |
| 144 | sregs->rstat = sp->mode | RSTAT_GO_BITS; |
| 145 | hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE; |
| 146 | } |
| 147 | |
| 148 | static inline void __sgiseeq_set_mac_address(struct net_device *dev) |
| 149 | { |
| 150 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 151 | struct sgiseeq_regs *sregs = sp->sregs; |
| 152 | int i; |
| 153 | |
| 154 | sregs->tstat = SEEQ_TCMD_RB0; |
| 155 | for (i = 0; i < 6; i++) |
| 156 | sregs->rw.eth_addr[i] = dev->dev_addr[i]; |
| 157 | } |
| 158 | |
| 159 | static int sgiseeq_set_mac_address(struct net_device *dev, void *addr) |
| 160 | { |
| 161 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 162 | struct sockaddr *sa = addr; |
| 163 | |
| 164 | memcpy(dev->dev_addr, sa->sa_data, dev->addr_len); |
| 165 | |
| 166 | spin_lock_irq(&sp->tx_lock); |
| 167 | __sgiseeq_set_mac_address(dev); |
| 168 | spin_unlock_irq(&sp->tx_lock); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD) |
| 174 | #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE) |
| 175 | #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT)) |
| 176 | |
| 177 | static int seeq_init_ring(struct net_device *dev) |
| 178 | { |
| 179 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 180 | int i; |
| 181 | |
| 182 | netif_stop_queue(dev); |
| 183 | sp->rx_new = sp->tx_new = 0; |
| 184 | sp->rx_old = sp->tx_old = 0; |
| 185 | |
| 186 | __sgiseeq_set_mac_address(dev); |
| 187 | |
| 188 | /* Setup tx ring. */ |
| 189 | for(i = 0; i < SEEQ_TX_BUFFERS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | sp->tx_desc[i].tdma.cntinfo = TCNTINFO_INIT; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 191 | dma_sync_desc_dev(dev, &sp->tx_desc[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* And now the rx ring. */ |
| 195 | for (i = 0; i < SEEQ_RX_BUFFERS; i++) { |
Thomas Bogendoerfer | a24a789 | 2008-01-13 00:08:47 +0100 | [diff] [blame] | 196 | if (!sp->rx_desc[i].skb) { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 197 | dma_addr_t dma_addr; |
| 198 | struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 200 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | return -ENOMEM; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 202 | skb_reserve(skb, 2); |
| 203 | dma_addr = dma_map_single(dev->dev.parent, |
| 204 | skb->data - 2, |
| 205 | PKT_BUF_SZ, DMA_FROM_DEVICE); |
| 206 | sp->rx_desc[i].skb = skb; |
| 207 | sp->rx_desc[i].rdma.pbuf = dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | sp->rx_desc[i].rdma.cntinfo = RCNTINFO_INIT; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 210 | dma_sync_desc_dev(dev, &sp->rx_desc[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | sp->rx_desc[i - 1].rdma.cntinfo |= HPCDMA_EOR; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 213 | dma_sync_desc_dev(dev, &sp->rx_desc[i - 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 217 | static void seeq_purge_ring(struct net_device *dev) |
| 218 | { |
| 219 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 220 | int i; |
| 221 | |
| 222 | /* clear tx ring. */ |
| 223 | for (i = 0; i < SEEQ_TX_BUFFERS; i++) { |
| 224 | if (sp->tx_desc[i].skb) { |
| 225 | dev_kfree_skb(sp->tx_desc[i].skb); |
| 226 | sp->tx_desc[i].skb = NULL; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* And now the rx ring. */ |
| 231 | for (i = 0; i < SEEQ_RX_BUFFERS; i++) { |
| 232 | if (sp->rx_desc[i].skb) { |
| 233 | dev_kfree_skb(sp->rx_desc[i].skb); |
| 234 | sp->rx_desc[i].skb = NULL; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | #ifdef DEBUG |
| 240 | static struct sgiseeq_private *gpriv; |
| 241 | static struct net_device *gdev; |
| 242 | |
Ralf Baechle | a4d4d51 | 2006-03-08 11:49:31 +0000 | [diff] [blame] | 243 | static void sgiseeq_dump_rings(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | static int once; |
| 246 | struct sgiseeq_rx_desc *r = gpriv->rx_desc; |
| 247 | struct sgiseeq_tx_desc *t = gpriv->tx_desc; |
| 248 | struct hpc3_ethregs *hregs = gpriv->hregs; |
| 249 | int i; |
| 250 | |
| 251 | if (once) |
| 252 | return; |
| 253 | once++; |
| 254 | printk("RING DUMP:\n"); |
| 255 | for (i = 0; i < SEEQ_RX_BUFFERS; i++) { |
| 256 | printk("RX [%d]: @(%p) [%08x,%08x,%08x] ", |
| 257 | i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo, |
| 258 | r[i].rdma.pnext); |
| 259 | i += 1; |
| 260 | printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n", |
| 261 | i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo, |
| 262 | r[i].rdma.pnext); |
| 263 | } |
| 264 | for (i = 0; i < SEEQ_TX_BUFFERS; i++) { |
| 265 | printk("TX [%d]: @(%p) [%08x,%08x,%08x] ", |
| 266 | i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo, |
| 267 | t[i].tdma.pnext); |
| 268 | i += 1; |
| 269 | printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n", |
| 270 | i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo, |
| 271 | t[i].tdma.pnext); |
| 272 | } |
| 273 | printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n", |
| 274 | gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old); |
| 275 | printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n", |
| 276 | hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl); |
| 277 | printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n", |
| 278 | hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl); |
| 279 | } |
| 280 | #endif |
| 281 | |
| 282 | #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF) |
| 283 | #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp, |
| 286 | struct sgiseeq_regs *sregs) |
| 287 | { |
| 288 | struct hpc3_ethregs *hregs = sp->hregs; |
| 289 | int err; |
| 290 | |
| 291 | reset_hpc3_and_seeq(hregs, sregs); |
| 292 | err = seeq_init_ring(dev); |
| 293 | if (err) |
| 294 | return err; |
| 295 | |
| 296 | /* Setup to field the proper interrupt types. */ |
| 297 | if (sp->is_edlc) { |
| 298 | sregs->tstat = TSTAT_INIT_EDLC; |
| 299 | sregs->rw.wregs.control = sp->control; |
| 300 | sregs->rw.wregs.frame_gap = 0; |
| 301 | } else { |
| 302 | sregs->tstat = TSTAT_INIT_SEEQ; |
| 303 | } |
| 304 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 305 | hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc); |
| 306 | hregs->tx_ndptr = VIRT_TO_DMA(sp, sp->tx_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | seeq_go(sp, hregs, sregs); |
| 309 | return 0; |
| 310 | } |
| 311 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 312 | static void record_rx_errors(struct net_device *dev, unsigned char status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
| 314 | if (status & SEEQ_RSTAT_OVERF || |
| 315 | status & SEEQ_RSTAT_SFRAME) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 316 | dev->stats.rx_over_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (status & SEEQ_RSTAT_CERROR) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 318 | dev->stats.rx_crc_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (status & SEEQ_RSTAT_DERROR) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 320 | dev->stats.rx_frame_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | if (status & SEEQ_RSTAT_REOF) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 322 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static inline void rx_maybe_restart(struct sgiseeq_private *sp, |
| 326 | struct hpc3_ethregs *hregs, |
| 327 | struct sgiseeq_regs *sregs) |
| 328 | { |
| 329 | if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 330 | hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc + sp->rx_new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | seeq_go(sp, hregs, sregs); |
| 332 | } |
| 333 | } |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp, |
| 336 | struct hpc3_ethregs *hregs, |
| 337 | struct sgiseeq_regs *sregs) |
| 338 | { |
| 339 | struct sgiseeq_rx_desc *rd; |
Ralf Baechle | a4d4d51 | 2006-03-08 11:49:31 +0000 | [diff] [blame] | 340 | struct sk_buff *skb = NULL; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 341 | struct sk_buff *newskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | unsigned char pkt_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | int len = 0; |
| 344 | unsigned int orig_end = PREV_RX(sp->rx_new); |
| 345 | |
| 346 | /* Service every received packet. */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 347 | rd = &sp->rx_desc[sp->rx_new]; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 348 | dma_sync_desc_cpu(dev, rd); |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 349 | while (!(rd->rdma.cntinfo & HPCDMA_OWN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | len = PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 351 | dma_unmap_single(dev->dev.parent, rd->rdma.pbuf, |
| 352 | PKT_BUF_SZ, DMA_FROM_DEVICE); |
| 353 | pkt_status = rd->skb->data[len]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (pkt_status & SEEQ_RSTAT_FIG) { |
| 355 | /* Packet is OK. */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 356 | /* We don't want to receive our own packets */ |
| 357 | if (memcmp(rd->skb->data + 6, dev->dev_addr, ETH_ALEN)) { |
| 358 | if (len > rx_copybreak) { |
| 359 | skb = rd->skb; |
| 360 | newskb = netdev_alloc_skb(dev, PKT_BUF_SZ); |
| 361 | if (!newskb) { |
| 362 | newskb = skb; |
| 363 | skb = NULL; |
| 364 | goto memory_squeeze; |
| 365 | } |
| 366 | skb_reserve(newskb, 2); |
| 367 | } else { |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 368 | skb = netdev_alloc_skb_ip_align(dev, len); |
| 369 | if (skb) |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 370 | skb_copy_to_linear_data(skb, rd->skb->data, len); |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 371 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 372 | newskb = rd->skb; |
| 373 | } |
| 374 | memory_squeeze: |
| 375 | if (skb) { |
| 376 | skb_put(skb, len); |
| 377 | skb->protocol = eth_type_trans(skb, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | netif_rx(skb); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 379 | dev->stats.rx_packets++; |
| 380 | dev->stats.rx_bytes += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } else { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 382 | printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n", |
| 383 | dev->name); |
| 384 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | } else { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 387 | /* Silently drop my own packets */ |
| 388 | newskb = rd->skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | } else { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 391 | record_rx_errors(dev, pkt_status); |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 392 | newskb = rd->skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 394 | rd->skb = newskb; |
| 395 | rd->rdma.pbuf = dma_map_single(dev->dev.parent, |
| 396 | newskb->data - 2, |
| 397 | PKT_BUF_SZ, DMA_FROM_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | /* Return the entry to the ring pool. */ |
| 400 | rd->rdma.cntinfo = RCNTINFO_INIT; |
| 401 | sp->rx_new = NEXT_RX(sp->rx_new); |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 402 | dma_sync_desc_dev(dev, rd); |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 403 | rd = &sp->rx_desc[sp->rx_new]; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 404 | dma_sync_desc_cpu(dev, rd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 406 | dma_sync_desc_cpu(dev, &sp->rx_desc[orig_end]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR); |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 408 | dma_sync_desc_dev(dev, &sp->rx_desc[orig_end]); |
| 409 | dma_sync_desc_cpu(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 411 | dma_sync_desc_dev(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | rx_maybe_restart(sp, hregs, sregs); |
| 413 | } |
| 414 | |
| 415 | static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp, |
| 416 | struct sgiseeq_regs *sregs) |
| 417 | { |
| 418 | if (sp->is_edlc) { |
| 419 | sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT); |
| 420 | sregs->rw.wregs.control = sp->control; |
| 421 | } |
| 422 | } |
| 423 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 424 | static inline void kick_tx(struct net_device *dev, |
| 425 | struct sgiseeq_private *sp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | struct hpc3_ethregs *hregs) |
| 427 | { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 428 | struct sgiseeq_tx_desc *td; |
| 429 | int i = sp->tx_old; |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* If the HPC aint doin nothin, and there are more packets |
| 432 | * with ETXD cleared and XIU set we must make very certain |
| 433 | * that we restart the HPC else we risk locking up the |
| 434 | * adapter. The following code is only safe iff the HPCDMA |
| 435 | * is not active! |
| 436 | */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 437 | td = &sp->tx_desc[i]; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 438 | dma_sync_desc_cpu(dev, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) == |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 440 | (HPCDMA_XIU | HPCDMA_ETXD)) { |
| 441 | i = NEXT_TX(i); |
| 442 | td = &sp->tx_desc[i]; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 443 | dma_sync_desc_cpu(dev, td); |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | if (td->tdma.cntinfo & HPCDMA_XIU) { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 446 | hregs->tx_ndptr = VIRT_TO_DMA(sp, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp, |
| 452 | struct hpc3_ethregs *hregs, |
| 453 | struct sgiseeq_regs *sregs) |
| 454 | { |
| 455 | struct sgiseeq_tx_desc *td; |
| 456 | unsigned long status = hregs->tx_ctrl; |
| 457 | int j; |
| 458 | |
| 459 | tx_maybe_reset_collisions(sp, sregs); |
| 460 | |
| 461 | if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) { |
| 462 | /* Oops, HPC detected some sort of error. */ |
| 463 | if (status & SEEQ_TSTAT_R16) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 464 | dev->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if (status & SEEQ_TSTAT_UFLOW) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 466 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | if (status & SEEQ_TSTAT_LCLS) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 468 | dev->stats.collisions++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /* Ack 'em... */ |
| 472 | for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) { |
| 473 | td = &sp->tx_desc[j]; |
| 474 | |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 475 | dma_sync_desc_cpu(dev, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | if (!(td->tdma.cntinfo & (HPCDMA_XIU))) |
| 477 | break; |
| 478 | if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) { |
| 479 | if (!(status & HPC3_ETXCTRL_ACTIVE)) { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 480 | hregs->tx_ndptr = VIRT_TO_DMA(sp, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE; |
| 482 | } |
| 483 | break; |
| 484 | } |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 485 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | sp->tx_old = NEXT_TX(sp->tx_old); |
| 487 | td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE); |
| 488 | td->tdma.cntinfo |= HPCDMA_EOX; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 489 | if (td->skb) { |
| 490 | dev_kfree_skb_any(td->skb); |
| 491 | td->skb = NULL; |
| 492 | } |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 493 | dma_sync_desc_dev(dev, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 497 | static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
| 499 | struct net_device *dev = (struct net_device *) dev_id; |
| 500 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 501 | struct hpc3_ethregs *hregs = sp->hregs; |
| 502 | struct sgiseeq_regs *sregs = sp->sregs; |
| 503 | |
| 504 | spin_lock(&sp->tx_lock); |
| 505 | |
| 506 | /* Ack the IRQ and set software state. */ |
Ralf Baechle | 302a5c4b | 2005-10-10 14:50:56 +0100 | [diff] [blame] | 507 | hregs->reset = HPC3_ERST_CLRIRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | /* Always check for received packets. */ |
| 510 | sgiseeq_rx(dev, sp, hregs, sregs); |
| 511 | |
| 512 | /* Only check for tx acks if we have something queued. */ |
| 513 | if (sp->tx_old != sp->tx_new) |
| 514 | sgiseeq_tx(dev, sp, hregs, sregs); |
| 515 | |
| 516 | if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) { |
| 517 | netif_wake_queue(dev); |
| 518 | } |
| 519 | spin_unlock(&sp->tx_lock); |
| 520 | |
| 521 | return IRQ_HANDLED; |
| 522 | } |
| 523 | |
| 524 | static int sgiseeq_open(struct net_device *dev) |
| 525 | { |
| 526 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 527 | struct sgiseeq_regs *sregs = sp->sregs; |
| 528 | unsigned int irq = dev->irq; |
| 529 | int err; |
| 530 | |
| 531 | if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) { |
| 532 | printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq); |
| 533 | err = -EAGAIN; |
| 534 | } |
| 535 | |
| 536 | err = init_seeq(dev, sp, sregs); |
| 537 | if (err) |
| 538 | goto out_free_irq; |
| 539 | |
| 540 | netif_start_queue(dev); |
| 541 | |
| 542 | return 0; |
| 543 | |
| 544 | out_free_irq: |
| 545 | free_irq(irq, dev); |
| 546 | |
| 547 | return err; |
| 548 | } |
| 549 | |
| 550 | static int sgiseeq_close(struct net_device *dev) |
| 551 | { |
| 552 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 553 | struct sgiseeq_regs *sregs = sp->sregs; |
Ralf Baechle | 2891439 | 2005-10-10 14:50:51 +0100 | [diff] [blame] | 554 | unsigned int irq = dev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | netif_stop_queue(dev); |
| 557 | |
| 558 | /* Shutdown the Seeq. */ |
| 559 | reset_hpc3_and_seeq(sp->hregs, sregs); |
Ralf Baechle | 2891439 | 2005-10-10 14:50:51 +0100 | [diff] [blame] | 560 | free_irq(irq, dev); |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 561 | seeq_purge_ring(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static inline int sgiseeq_reset(struct net_device *dev) |
| 567 | { |
| 568 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 569 | struct sgiseeq_regs *sregs = sp->sregs; |
| 570 | int err; |
| 571 | |
| 572 | err = init_seeq(dev, sp, sregs); |
| 573 | if (err) |
| 574 | return err; |
| 575 | |
| 576 | dev->trans_start = jiffies; |
| 577 | netif_wake_queue(dev); |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 583 | { |
| 584 | struct sgiseeq_private *sp = netdev_priv(dev); |
| 585 | struct hpc3_ethregs *hregs = sp->hregs; |
| 586 | unsigned long flags; |
| 587 | struct sgiseeq_tx_desc *td; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 588 | int len, entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
| 590 | spin_lock_irqsave(&sp->tx_lock, flags); |
| 591 | |
| 592 | /* Setup... */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 593 | len = skb->len; |
| 594 | if (len < ETH_ZLEN) { |
| 595 | if (skb_padto(skb, ETH_ZLEN)) |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 596 | return NETDEV_TX_OK; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 597 | len = ETH_ZLEN; |
| 598 | } |
| 599 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 600 | dev->stats.tx_bytes += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | entry = sp->tx_new; |
| 602 | td = &sp->tx_desc[entry]; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 603 | dma_sync_desc_cpu(dev, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | /* Create entry. There are so many races with adding a new |
| 606 | * descriptor to the chain: |
| 607 | * 1) Assume that the HPC is off processing a DMA chain while |
| 608 | * we are changing all of the following. |
| 609 | * 2) Do no allow the HPC to look at a new descriptor until |
| 610 | * we have completely set up it's state. This means, do |
| 611 | * not clear HPCDMA_EOX in the current last descritptor |
| 612 | * until the one we are adding looks consistent and could |
| 613 | * be processes right now. |
| 614 | * 3) The tx interrupt code must notice when we've added a new |
| 615 | * entry and the HPC got to the end of the chain before we |
| 616 | * added this new entry and restarted it. |
| 617 | */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 618 | td->skb = skb; |
| 619 | td->tdma.pbuf = dma_map_single(dev->dev.parent, skb->data, |
| 620 | len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | td->tdma.cntinfo = (len & HPCDMA_BCNT) | |
| 622 | HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 623 | dma_sync_desc_dev(dev, td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | if (sp->tx_old != sp->tx_new) { |
| 625 | struct sgiseeq_tx_desc *backend; |
| 626 | |
| 627 | backend = &sp->tx_desc[PREV_TX(sp->tx_new)]; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 628 | dma_sync_desc_cpu(dev, backend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | backend->tdma.cntinfo &= ~HPCDMA_EOX; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 630 | dma_sync_desc_dev(dev, backend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */ |
| 633 | |
| 634 | /* Maybe kick the HPC back into motion. */ |
| 635 | if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE)) |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 636 | kick_tx(dev, sp, hregs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
| 638 | dev->trans_start = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | if (!TX_BUFFS_AVAIL(sp)) |
| 641 | netif_stop_queue(dev); |
| 642 | spin_unlock_irqrestore(&sp->tx_lock, flags); |
| 643 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 644 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void timeout(struct net_device *dev) |
| 648 | { |
| 649 | printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name); |
| 650 | sgiseeq_reset(dev); |
| 651 | |
| 652 | dev->trans_start = jiffies; |
| 653 | netif_wake_queue(dev); |
| 654 | } |
| 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | static void sgiseeq_set_multicast(struct net_device *dev) |
| 657 | { |
Wang Chen | 8f15ea4 | 2008-11-12 23:38:36 -0800 | [diff] [blame] | 658 | struct sgiseeq_private *sp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | unsigned char oldmode = sp->mode; |
| 660 | |
| 661 | if(dev->flags & IFF_PROMISC) |
| 662 | sp->mode = SEEQ_RCMD_RANY; |
| 663 | else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count) |
| 664 | sp->mode = SEEQ_RCMD_RBMCAST; |
| 665 | else |
| 666 | sp->mode = SEEQ_RCMD_RBCAST; |
| 667 | |
| 668 | /* XXX I know this sucks, but is there a better way to reprogram |
| 669 | * XXX the receiver? At least, this shouldn't happen too often. |
| 670 | */ |
| 671 | |
| 672 | if (oldmode != sp->mode) |
| 673 | sgiseeq_reset(dev); |
| 674 | } |
| 675 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 676 | static inline void setup_tx_ring(struct net_device *dev, |
| 677 | struct sgiseeq_tx_desc *buf, |
| 678 | int nbufs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 680 | struct sgiseeq_private *sp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | int i = 0; |
| 682 | |
| 683 | while (i < (nbufs - 1)) { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 684 | buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf + i + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | buf[i].tdma.pbuf = 0; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 686 | dma_sync_desc_dev(dev, &buf[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | i++; |
| 688 | } |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 689 | buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf); |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 690 | dma_sync_desc_dev(dev, &buf[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 693 | static inline void setup_rx_ring(struct net_device *dev, |
| 694 | struct sgiseeq_rx_desc *buf, |
| 695 | int nbufs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 697 | struct sgiseeq_private *sp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | int i = 0; |
| 699 | |
| 700 | while (i < (nbufs - 1)) { |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 701 | buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf + i + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | buf[i].rdma.pbuf = 0; |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 703 | dma_sync_desc_dev(dev, &buf[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | i++; |
| 705 | } |
| 706 | buf[i].rdma.pbuf = 0; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 707 | buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf); |
Thomas Bogendoerfer | 49b11bc | 2007-12-19 13:42:36 +0100 | [diff] [blame] | 708 | dma_sync_desc_dev(dev, &buf[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Alexander Beregalov | 8c2c6be | 2009-04-15 12:52:58 +0000 | [diff] [blame] | 711 | static const struct net_device_ops sgiseeq_netdev_ops = { |
| 712 | .ndo_open = sgiseeq_open, |
| 713 | .ndo_stop = sgiseeq_close, |
| 714 | .ndo_start_xmit = sgiseeq_start_xmit, |
| 715 | .ndo_tx_timeout = timeout, |
| 716 | .ndo_set_multicast_list = sgiseeq_set_multicast, |
| 717 | .ndo_set_mac_address = sgiseeq_set_mac_address, |
| 718 | .ndo_change_mtu = eth_change_mtu, |
| 719 | .ndo_validate_addr = eth_validate_addr, |
| 720 | }; |
| 721 | |
Uwe Kleine-König | a65a688 | 2009-07-21 11:25:26 +0000 | [diff] [blame] | 722 | static int __devinit sgiseeq_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 724 | struct sgiseeq_platform_data *pd = pdev->dev.platform_data; |
| 725 | struct hpc3_regs *hpcregs = pd->hpc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | struct sgiseeq_init_block *sr; |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 727 | unsigned int irq = pd->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | struct sgiseeq_private *sp; |
| 729 | struct net_device *dev; |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 730 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
| 732 | dev = alloc_etherdev(sizeof (struct sgiseeq_private)); |
| 733 | if (!dev) { |
| 734 | printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n"); |
| 735 | err = -ENOMEM; |
| 736 | goto err_out; |
| 737 | } |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 738 | |
| 739 | platform_set_drvdata(pdev, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | sp = netdev_priv(dev); |
| 741 | |
| 742 | /* Make private data page aligned */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 743 | sr = dma_alloc_noncoherent(&pdev->dev, sizeof(*sp->srings), |
Ralf Baechle | 99cd149 | 2007-09-04 14:41:01 +0100 | [diff] [blame] | 744 | &sp->srings_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | if (!sr) { |
| 746 | printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n"); |
| 747 | err = -ENOMEM; |
| 748 | goto err_out_free_dev; |
| 749 | } |
| 750 | sp->srings = sr; |
Ralf Baechle | 99cd149 | 2007-09-04 14:41:01 +0100 | [diff] [blame] | 751 | sp->rx_desc = sp->srings->rxvector; |
| 752 | sp->tx_desc = sp->srings->txvector; |
| 753 | |
| 754 | /* A couple calculations now, saves many cycles later. */ |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 755 | setup_rx_ring(dev, sp->rx_desc, SEEQ_RX_BUFFERS); |
| 756 | setup_tx_ring(dev, sp->tx_desc, SEEQ_TX_BUFFERS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 758 | memcpy(dev->dev_addr, pd->mac, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | #ifdef DEBUG |
| 761 | gpriv = sp; |
| 762 | gdev = dev; |
| 763 | #endif |
Ralf Baechle | 302a5c4b | 2005-10-10 14:50:56 +0100 | [diff] [blame] | 764 | sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0]; |
| 765 | sp->hregs = &hpcregs->ethregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | sp->name = sgiseeqstr; |
| 767 | sp->mode = SEEQ_RCMD_RBCAST; |
| 768 | |
Ralf Baechle | 302a5c4b | 2005-10-10 14:50:56 +0100 | [diff] [blame] | 769 | /* Setup PIO and DMA transfer timing */ |
| 770 | sp->hregs->pconfig = 0x161; |
| 771 | sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP | |
| 772 | HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026; |
| 773 | |
Ladislav Michl | 78ee5b3 | 2007-02-28 01:18:35 +0000 | [diff] [blame] | 774 | /* Setup PIO and DMA transfer timing */ |
| 775 | sp->hregs->pconfig = 0x161; |
| 776 | sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP | |
| 777 | HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026; |
| 778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | /* Reset the chip. */ |
| 780 | hpc3_eth_reset(sp->hregs); |
| 781 | |
| 782 | sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff); |
| 783 | if (sp->is_edlc) |
| 784 | sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT | |
| 785 | SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT | |
| 786 | SEEQ_CTRL_ENCARR; |
| 787 | |
Alexander Beregalov | 8c2c6be | 2009-04-15 12:52:58 +0000 | [diff] [blame] | 788 | dev->netdev_ops = &sgiseeq_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | dev->watchdog_timeo = (200 * HZ) / 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | dev->irq = irq; |
| 791 | |
| 792 | if (register_netdev(dev)) { |
| 793 | printk(KERN_ERR "Sgiseeq: Cannot register net device, " |
| 794 | "aborting.\n"); |
| 795 | err = -ENODEV; |
| 796 | goto err_out_free_page; |
| 797 | } |
| 798 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 799 | printk(KERN_INFO "%s: %s %pM\n", dev->name, sgiseeqstr, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | return 0; |
| 802 | |
| 803 | err_out_free_page: |
Ralf Baechle | 2891439 | 2005-10-10 14:50:51 +0100 | [diff] [blame] | 804 | free_page((unsigned long) sp->srings); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | err_out_free_dev: |
| 806 | kfree(dev); |
| 807 | |
| 808 | err_out: |
| 809 | return err; |
| 810 | } |
| 811 | |
Ralf Baechle | e3efb05 | 2007-08-22 16:03:52 +0100 | [diff] [blame] | 812 | static int __exit sgiseeq_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | { |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 814 | struct net_device *dev = platform_get_drvdata(pdev); |
| 815 | struct sgiseeq_private *sp = netdev_priv(dev); |
Ladislav Michl | 78ee5b3 | 2007-02-28 01:18:35 +0000 | [diff] [blame] | 816 | |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 817 | unregister_netdev(dev); |
Thomas Bogendoerfer | 43831b1 | 2007-11-24 13:29:19 +0100 | [diff] [blame] | 818 | dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings, |
| 819 | sp->srings_dma); |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 820 | free_netdev(dev); |
| 821 | platform_set_drvdata(pdev, NULL); |
Ralf Baechle | e3efb05 | 2007-08-22 16:03:52 +0100 | [diff] [blame] | 822 | |
| 823 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 826 | static struct platform_driver sgiseeq_driver = { |
| 827 | .probe = sgiseeq_probe, |
Uwe Kleine-König | fb74c2f | 2009-09-30 22:28:26 +0000 | [diff] [blame] | 828 | .remove = __exit_p(sgiseeq_remove), |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 829 | .driver = { |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 830 | .name = "sgiseeq", |
| 831 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 833 | }; |
| 834 | |
| 835 | static int __init sgiseeq_module_init(void) |
| 836 | { |
| 837 | if (platform_driver_register(&sgiseeq_driver)) { |
| 838 | printk(KERN_ERR "Driver registration failed\n"); |
| 839 | return -ENODEV; |
| 840 | } |
| 841 | |
| 842 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Ralf Baechle | df9f540 | 2007-05-11 15:48:58 +0100 | [diff] [blame] | 845 | static void __exit sgiseeq_module_exit(void) |
| 846 | { |
| 847 | platform_driver_unregister(&sgiseeq_driver); |
| 848 | } |
| 849 | |
| 850 | module_init(sgiseeq_module_init); |
| 851 | module_exit(sgiseeq_module_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Ralf Baechle | 302a5c4b | 2005-10-10 14:50:56 +0100 | [diff] [blame] | 853 | MODULE_DESCRIPTION("SGI Seeq 8003 driver"); |
| 854 | MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | MODULE_LICENSE("GPL"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 856 | MODULE_ALIAS("platform:sgiseeq"); |