1 // SPDX-License-Identifier: GPL-2.0-only
3 * sgiseeq.c: Seeq8003 ethernet driver for SGI machines.
10 #include <linux/dma-mapping.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/errno.h>
15 #include <linux/types.h>
16 #include <linux/interrupt.h>
17 #include <linux/string.h>
18 #include <linux/delay.h>
19 #include <linux/netdevice.h>
20 #include <linux/platform_device.h>
21 #include <linux/etherdevice.h>
22 #include <linux/skbuff.h>
24 #include <asm/sgi/hpc3.h>
25 #include <asm/sgi/ip22.h>
26 #include <asm/sgi/seeq.h>
30 static char *sgiseeqstr = "SGI Seeq8003";
33 * If you want speed, you do something silly, it always has worked for me. So,
34 * with that in mind, I've decided to make this driver look completely like a
35 * stupid Lance from a driver architecture perspective. Only difference is that
36 * here our "ring buffer" looks and acts like a real Lance one does but is
37 * laid out like how the HPC DMA and the Seeq want it to. You'd be surprised
38 * how a stupid idea like this can pay off in performance, not to mention
39 * making this driver 2,000 times easier to write. ;-)
42 /* Tune these if we tend to run out often etc. */
43 #define SEEQ_RX_BUFFERS 16
44 #define SEEQ_TX_BUFFERS 16
46 #define PKT_BUF_SZ 1584
48 #define NEXT_RX(i) (((i) + 1) & (SEEQ_RX_BUFFERS - 1))
49 #define NEXT_TX(i) (((i) + 1) & (SEEQ_TX_BUFFERS - 1))
50 #define PREV_RX(i) (((i) - 1) & (SEEQ_RX_BUFFERS - 1))
51 #define PREV_TX(i) (((i) - 1) & (SEEQ_TX_BUFFERS - 1))
53 #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \
54 sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \
55 sp->tx_old - sp->tx_new - 1)
57 #define VIRT_TO_DMA(sp, v) ((sp)->srings_dma + \
58 (dma_addr_t)((unsigned long)(v) - \
59 (unsigned long)((sp)->rx_desc)))
61 /* Copy frames shorter than rx_copybreak, otherwise pass on up in
62 * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
64 static int rx_copybreak = 100;
66 #define PAD_SIZE (128 - sizeof(struct hpc_dma_desc) - sizeof(void *))
68 struct sgiseeq_rx_desc {
69 volatile struct hpc_dma_desc rdma;
74 struct sgiseeq_tx_desc {
75 volatile struct hpc_dma_desc tdma;
81 * Warning: This structure is laid out in a certain way because HPC dma
82 * descriptors must be 8-byte aligned. So don't touch this without
85 struct sgiseeq_init_block { /* Note the name ;-) */
86 struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS];
87 struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS];
90 struct sgiseeq_private {
91 struct sgiseeq_init_block *srings;
92 dma_addr_t srings_dma;
94 /* Ptrs to the descriptors in uncached space. */
95 struct sgiseeq_rx_desc *rx_desc;
96 struct sgiseeq_tx_desc *tx_desc;
99 struct hpc3_ethregs *hregs;
100 struct sgiseeq_regs *sregs;
102 /* Ring entry counters. */
103 unsigned int rx_new, tx_new;
104 unsigned int rx_old, tx_old;
107 unsigned char control;
113 static inline void dma_sync_desc_cpu(struct net_device *dev, void *addr)
115 struct sgiseeq_private *sp = netdev_priv(dev);
117 dma_sync_single_for_cpu(dev->dev.parent, VIRT_TO_DMA(sp, addr),
118 sizeof(struct sgiseeq_rx_desc), DMA_BIDIRECTIONAL);
121 static inline void dma_sync_desc_dev(struct net_device *dev, void *addr)
123 struct sgiseeq_private *sp = netdev_priv(dev);
125 dma_sync_single_for_device(dev->dev.parent, VIRT_TO_DMA(sp, addr),
126 sizeof(struct sgiseeq_rx_desc), DMA_BIDIRECTIONAL);
129 static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
131 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
136 static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
137 struct sgiseeq_regs *sregs)
139 hregs->rx_ctrl = hregs->tx_ctrl = 0;
140 hpc3_eth_reset(hregs);
143 #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
144 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
146 static inline void seeq_go(struct sgiseeq_private *sp,
147 struct hpc3_ethregs *hregs,
148 struct sgiseeq_regs *sregs)
150 sregs->rstat = sp->mode | RSTAT_GO_BITS;
151 hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
154 static inline void __sgiseeq_set_mac_address(struct net_device *dev)
156 struct sgiseeq_private *sp = netdev_priv(dev);
157 struct sgiseeq_regs *sregs = sp->sregs;
160 sregs->tstat = SEEQ_TCMD_RB0;
161 for (i = 0; i < 6; i++)
162 sregs->rw.eth_addr[i] = dev->dev_addr[i];
165 static int sgiseeq_set_mac_address(struct net_device *dev, void *addr)
167 struct sgiseeq_private *sp = netdev_priv(dev);
168 struct sockaddr *sa = addr;
170 eth_hw_addr_set(dev, sa->sa_data);
172 spin_lock_irq(&sp->tx_lock);
173 __sgiseeq_set_mac_address(dev);
174 spin_unlock_irq(&sp->tx_lock);
179 #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
180 #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
181 #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
183 static int seeq_init_ring(struct net_device *dev)
185 struct sgiseeq_private *sp = netdev_priv(dev);
188 netif_stop_queue(dev);
189 sp->rx_new = sp->tx_new = 0;
190 sp->rx_old = sp->tx_old = 0;
192 __sgiseeq_set_mac_address(dev);
195 for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
196 sp->tx_desc[i].tdma.cntinfo = TCNTINFO_INIT;
197 dma_sync_desc_dev(dev, &sp->tx_desc[i]);
200 /* And now the rx ring. */
201 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
202 if (!sp->rx_desc[i].skb) {
204 struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ);
209 dma_addr = dma_map_single(dev->dev.parent,
211 PKT_BUF_SZ, DMA_FROM_DEVICE);
212 sp->rx_desc[i].skb = skb;
213 sp->rx_desc[i].rdma.pbuf = dma_addr;
215 sp->rx_desc[i].rdma.cntinfo = RCNTINFO_INIT;
216 dma_sync_desc_dev(dev, &sp->rx_desc[i]);
218 sp->rx_desc[i - 1].rdma.cntinfo |= HPCDMA_EOR;
219 dma_sync_desc_dev(dev, &sp->rx_desc[i - 1]);
223 static void seeq_purge_ring(struct net_device *dev)
225 struct sgiseeq_private *sp = netdev_priv(dev);
229 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
230 if (sp->tx_desc[i].skb) {
231 dev_kfree_skb(sp->tx_desc[i].skb);
232 sp->tx_desc[i].skb = NULL;
236 /* And now the rx ring. */
237 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
238 if (sp->rx_desc[i].skb) {
239 dev_kfree_skb(sp->rx_desc[i].skb);
240 sp->rx_desc[i].skb = NULL;
246 static struct sgiseeq_private *gpriv;
247 static struct net_device *gdev;
249 static void sgiseeq_dump_rings(void)
252 struct sgiseeq_rx_desc *r = gpriv->rx_desc;
253 struct sgiseeq_tx_desc *t = gpriv->tx_desc;
254 struct hpc3_ethregs *hregs = gpriv->hregs;
260 printk("RING DUMP:\n");
261 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
262 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
263 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
266 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
267 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
270 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
271 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
272 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
275 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
276 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
279 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
280 gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
281 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
282 hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
283 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
284 hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
288 #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
289 #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
291 static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
292 struct sgiseeq_regs *sregs)
294 struct hpc3_ethregs *hregs = sp->hregs;
297 reset_hpc3_and_seeq(hregs, sregs);
298 err = seeq_init_ring(dev);
302 /* Setup to field the proper interrupt types. */
304 sregs->tstat = TSTAT_INIT_EDLC;
305 sregs->rw.wregs.control = sp->control;
306 sregs->rw.wregs.frame_gap = 0;
308 sregs->tstat = TSTAT_INIT_SEEQ;
311 hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc);
312 hregs->tx_ndptr = VIRT_TO_DMA(sp, sp->tx_desc);
314 seeq_go(sp, hregs, sregs);
318 static void record_rx_errors(struct net_device *dev, unsigned char status)
320 if (status & SEEQ_RSTAT_OVERF ||
321 status & SEEQ_RSTAT_SFRAME)
322 dev->stats.rx_over_errors++;
323 if (status & SEEQ_RSTAT_CERROR)
324 dev->stats.rx_crc_errors++;
325 if (status & SEEQ_RSTAT_DERROR)
326 dev->stats.rx_frame_errors++;
327 if (status & SEEQ_RSTAT_REOF)
328 dev->stats.rx_errors++;
331 static inline void rx_maybe_restart(struct sgiseeq_private *sp,
332 struct hpc3_ethregs *hregs,
333 struct sgiseeq_regs *sregs)
335 if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
336 hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc + sp->rx_new);
337 seeq_go(sp, hregs, sregs);
341 static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
342 struct hpc3_ethregs *hregs,
343 struct sgiseeq_regs *sregs)
345 struct sgiseeq_rx_desc *rd;
346 struct sk_buff *skb = NULL;
347 struct sk_buff *newskb;
348 unsigned char pkt_status;
350 unsigned int orig_end = PREV_RX(sp->rx_new);
352 /* Service every received packet. */
353 rd = &sp->rx_desc[sp->rx_new];
354 dma_sync_desc_cpu(dev, rd);
355 while (!(rd->rdma.cntinfo & HPCDMA_OWN)) {
356 len = PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3;
357 dma_unmap_single(dev->dev.parent, rd->rdma.pbuf,
358 PKT_BUF_SZ, DMA_FROM_DEVICE);
359 pkt_status = rd->skb->data[len];
360 if (pkt_status & SEEQ_RSTAT_FIG) {
362 /* We don't want to receive our own packets */
363 if (!ether_addr_equal(rd->skb->data + 6, dev->dev_addr)) {
364 if (len > rx_copybreak) {
366 newskb = netdev_alloc_skb(dev, PKT_BUF_SZ);
372 skb_reserve(newskb, 2);
374 skb = netdev_alloc_skb_ip_align(dev, len);
376 skb_copy_to_linear_data(skb, rd->skb->data, len);
383 skb->protocol = eth_type_trans(skb, dev);
385 dev->stats.rx_packets++;
386 dev->stats.rx_bytes += len;
388 dev->stats.rx_dropped++;
391 /* Silently drop my own packets */
395 record_rx_errors(dev, pkt_status);
399 rd->rdma.pbuf = dma_map_single(dev->dev.parent,
401 PKT_BUF_SZ, DMA_FROM_DEVICE);
403 /* Return the entry to the ring pool. */
404 rd->rdma.cntinfo = RCNTINFO_INIT;
405 sp->rx_new = NEXT_RX(sp->rx_new);
406 dma_sync_desc_dev(dev, rd);
407 rd = &sp->rx_desc[sp->rx_new];
408 dma_sync_desc_cpu(dev, rd);
410 dma_sync_desc_dev(dev, rd);
412 dma_sync_desc_cpu(dev, &sp->rx_desc[orig_end]);
413 sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
414 dma_sync_desc_dev(dev, &sp->rx_desc[orig_end]);
415 dma_sync_desc_cpu(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]);
416 sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
417 dma_sync_desc_dev(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]);
418 rx_maybe_restart(sp, hregs, sregs);
421 static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
422 struct sgiseeq_regs *sregs)
425 sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
426 sregs->rw.wregs.control = sp->control;
430 static inline void kick_tx(struct net_device *dev,
431 struct sgiseeq_private *sp,
432 struct hpc3_ethregs *hregs)
434 struct sgiseeq_tx_desc *td;
437 /* If the HPC aint doin nothin, and there are more packets
438 * with ETXD cleared and XIU set we must make very certain
439 * that we restart the HPC else we risk locking up the
440 * adapter. The following code is only safe iff the HPCDMA
443 td = &sp->tx_desc[i];
444 dma_sync_desc_cpu(dev, td);
445 while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
446 (HPCDMA_XIU | HPCDMA_ETXD)) {
448 td = &sp->tx_desc[i];
449 dma_sync_desc_cpu(dev, td);
451 if (td->tdma.cntinfo & HPCDMA_XIU) {
452 dma_sync_desc_dev(dev, td);
453 hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
454 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
458 static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
459 struct hpc3_ethregs *hregs,
460 struct sgiseeq_regs *sregs)
462 struct sgiseeq_tx_desc *td;
463 unsigned long status = hregs->tx_ctrl;
466 tx_maybe_reset_collisions(sp, sregs);
468 if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
469 /* Oops, HPC detected some sort of error. */
470 if (status & SEEQ_TSTAT_R16)
471 dev->stats.tx_aborted_errors++;
472 if (status & SEEQ_TSTAT_UFLOW)
473 dev->stats.tx_fifo_errors++;
474 if (status & SEEQ_TSTAT_LCLS)
475 dev->stats.collisions++;
479 for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
480 td = &sp->tx_desc[j];
482 dma_sync_desc_cpu(dev, td);
483 if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
485 if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
486 dma_sync_desc_dev(dev, td);
487 if (!(status & HPC3_ETXCTRL_ACTIVE)) {
488 hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
489 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
493 dev->stats.tx_packets++;
494 sp->tx_old = NEXT_TX(sp->tx_old);
495 td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
496 td->tdma.cntinfo |= HPCDMA_EOX;
498 dev_kfree_skb_any(td->skb);
501 dma_sync_desc_dev(dev, td);
505 static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id)
507 struct net_device *dev = (struct net_device *) dev_id;
508 struct sgiseeq_private *sp = netdev_priv(dev);
509 struct hpc3_ethregs *hregs = sp->hregs;
510 struct sgiseeq_regs *sregs = sp->sregs;
512 spin_lock(&sp->tx_lock);
514 /* Ack the IRQ and set software state. */
515 hregs->reset = HPC3_ERST_CLRIRQ;
517 /* Always check for received packets. */
518 sgiseeq_rx(dev, sp, hregs, sregs);
520 /* Only check for tx acks if we have something queued. */
521 if (sp->tx_old != sp->tx_new)
522 sgiseeq_tx(dev, sp, hregs, sregs);
524 if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
525 netif_wake_queue(dev);
527 spin_unlock(&sp->tx_lock);
532 static int sgiseeq_open(struct net_device *dev)
534 struct sgiseeq_private *sp = netdev_priv(dev);
535 struct sgiseeq_regs *sregs = sp->sregs;
536 unsigned int irq = dev->irq;
539 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
540 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
544 err = init_seeq(dev, sp, sregs);
548 netif_start_queue(dev);
558 static int sgiseeq_close(struct net_device *dev)
560 struct sgiseeq_private *sp = netdev_priv(dev);
561 struct sgiseeq_regs *sregs = sp->sregs;
562 unsigned int irq = dev->irq;
564 netif_stop_queue(dev);
566 /* Shutdown the Seeq. */
567 reset_hpc3_and_seeq(sp->hregs, sregs);
569 seeq_purge_ring(dev);
574 static inline int sgiseeq_reset(struct net_device *dev)
576 struct sgiseeq_private *sp = netdev_priv(dev);
577 struct sgiseeq_regs *sregs = sp->sregs;
580 err = init_seeq(dev, sp, sregs);
584 netif_trans_update(dev); /* prevent tx timeout */
585 netif_wake_queue(dev);
591 sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
593 struct sgiseeq_private *sp = netdev_priv(dev);
594 struct hpc3_ethregs *hregs = sp->hregs;
596 struct sgiseeq_tx_desc *td;
599 spin_lock_irqsave(&sp->tx_lock, flags);
603 if (len < ETH_ZLEN) {
604 if (skb_padto(skb, ETH_ZLEN)) {
605 spin_unlock_irqrestore(&sp->tx_lock, flags);
611 dev->stats.tx_bytes += len;
613 td = &sp->tx_desc[entry];
614 dma_sync_desc_cpu(dev, td);
616 /* Create entry. There are so many races with adding a new
617 * descriptor to the chain:
618 * 1) Assume that the HPC is off processing a DMA chain while
619 * we are changing all of the following.
620 * 2) Do no allow the HPC to look at a new descriptor until
621 * we have completely set up it's state. This means, do
622 * not clear HPCDMA_EOX in the current last descritptor
623 * until the one we are adding looks consistent and could
624 * be processes right now.
625 * 3) The tx interrupt code must notice when we've added a new
626 * entry and the HPC got to the end of the chain before we
627 * added this new entry and restarted it.
630 td->tdma.pbuf = dma_map_single(dev->dev.parent, skb->data,
632 td->tdma.cntinfo = (len & HPCDMA_BCNT) |
633 HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX;
634 dma_sync_desc_dev(dev, td);
635 if (sp->tx_old != sp->tx_new) {
636 struct sgiseeq_tx_desc *backend;
638 backend = &sp->tx_desc[PREV_TX(sp->tx_new)];
639 dma_sync_desc_cpu(dev, backend);
640 backend->tdma.cntinfo &= ~HPCDMA_EOX;
641 dma_sync_desc_dev(dev, backend);
643 sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
645 /* Maybe kick the HPC back into motion. */
646 if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
647 kick_tx(dev, sp, hregs);
649 if (!TX_BUFFS_AVAIL(sp))
650 netif_stop_queue(dev);
651 spin_unlock_irqrestore(&sp->tx_lock, flags);
656 static void timeout(struct net_device *dev, unsigned int txqueue)
658 printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
661 netif_trans_update(dev); /* prevent tx timeout */
662 netif_wake_queue(dev);
665 static void sgiseeq_set_multicast(struct net_device *dev)
667 struct sgiseeq_private *sp = netdev_priv(dev);
668 unsigned char oldmode = sp->mode;
670 if(dev->flags & IFF_PROMISC)
671 sp->mode = SEEQ_RCMD_RANY;
672 else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev))
673 sp->mode = SEEQ_RCMD_RBMCAST;
675 sp->mode = SEEQ_RCMD_RBCAST;
677 /* XXX I know this sucks, but is there a better way to reprogram
678 * XXX the receiver? At least, this shouldn't happen too often.
681 if (oldmode != sp->mode)
685 static inline void setup_tx_ring(struct net_device *dev,
686 struct sgiseeq_tx_desc *buf,
689 struct sgiseeq_private *sp = netdev_priv(dev);
692 while (i < (nbufs - 1)) {
693 buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf + i + 1);
694 buf[i].tdma.pbuf = 0;
695 dma_sync_desc_dev(dev, &buf[i]);
698 buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf);
699 dma_sync_desc_dev(dev, &buf[i]);
702 static inline void setup_rx_ring(struct net_device *dev,
703 struct sgiseeq_rx_desc *buf,
706 struct sgiseeq_private *sp = netdev_priv(dev);
709 while (i < (nbufs - 1)) {
710 buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf + i + 1);
711 buf[i].rdma.pbuf = 0;
712 dma_sync_desc_dev(dev, &buf[i]);
715 buf[i].rdma.pbuf = 0;
716 buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf);
717 dma_sync_desc_dev(dev, &buf[i]);
720 static const struct net_device_ops sgiseeq_netdev_ops = {
721 .ndo_open = sgiseeq_open,
722 .ndo_stop = sgiseeq_close,
723 .ndo_start_xmit = sgiseeq_start_xmit,
724 .ndo_tx_timeout = timeout,
725 .ndo_set_rx_mode = sgiseeq_set_multicast,
726 .ndo_set_mac_address = sgiseeq_set_mac_address,
727 .ndo_validate_addr = eth_validate_addr,
730 static int sgiseeq_probe(struct platform_device *pdev)
732 struct sgiseeq_platform_data *pd = dev_get_platdata(&pdev->dev);
733 struct hpc3_regs *hpcregs = pd->hpc;
734 struct sgiseeq_init_block *sr;
735 unsigned int irq = pd->irq;
736 struct sgiseeq_private *sp;
737 struct net_device *dev;
740 dev = alloc_etherdev(sizeof (struct sgiseeq_private));
746 platform_set_drvdata(pdev, dev);
747 SET_NETDEV_DEV(dev, &pdev->dev);
748 sp = netdev_priv(dev);
750 /* Make private data page aligned */
751 sr = dma_alloc_noncoherent(&pdev->dev, sizeof(*sp->srings),
752 &sp->srings_dma, DMA_BIDIRECTIONAL, GFP_KERNEL);
754 printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
756 goto err_out_free_dev;
759 sp->rx_desc = sp->srings->rxvector;
760 sp->tx_desc = sp->srings->txvector;
761 spin_lock_init(&sp->tx_lock);
763 /* A couple calculations now, saves many cycles later. */
764 setup_rx_ring(dev, sp->rx_desc, SEEQ_RX_BUFFERS);
765 setup_tx_ring(dev, sp->tx_desc, SEEQ_TX_BUFFERS);
767 eth_hw_addr_set(dev, pd->mac);
773 sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
774 sp->hregs = &hpcregs->ethregs;
775 sp->name = sgiseeqstr;
776 sp->mode = SEEQ_RCMD_RBCAST;
778 /* Setup PIO and DMA transfer timing */
779 sp->hregs->pconfig = 0x161;
780 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
781 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
783 /* Setup PIO and DMA transfer timing */
784 sp->hregs->pconfig = 0x161;
785 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
786 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
788 /* Reset the chip. */
789 hpc3_eth_reset(sp->hregs);
791 sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
793 sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
794 SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
797 dev->netdev_ops = &sgiseeq_netdev_ops;
798 dev->watchdog_timeo = (200 * HZ) / 1000;
801 if (register_netdev(dev)) {
802 printk(KERN_ERR "Sgiseeq: Cannot register net device, "
805 goto err_out_free_attrs;
808 printk(KERN_INFO "%s: %s %pM\n", dev->name, sgiseeqstr, dev->dev_addr);
813 dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
814 sp->srings_dma, DMA_BIDIRECTIONAL);
822 static int sgiseeq_remove(struct platform_device *pdev)
824 struct net_device *dev = platform_get_drvdata(pdev);
825 struct sgiseeq_private *sp = netdev_priv(dev);
827 unregister_netdev(dev);
828 dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
829 sp->srings_dma, DMA_BIDIRECTIONAL);
835 static struct platform_driver sgiseeq_driver = {
836 .probe = sgiseeq_probe,
837 .remove = sgiseeq_remove,
843 module_platform_driver(sgiseeq_driver);
845 MODULE_DESCRIPTION("SGI Seeq 8003 driver");
847 MODULE_LICENSE("GPL");
848 MODULE_ALIAS("platform:sgiseeq");