Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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