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