10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/errno.h>
15 #include <linux/types.h>
17 #include <linux/string.h>
19 #include <linux/netdevice.h>
30 static char *sgiseeqstr =
"SGI Seeq8003";
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)))
64 static int rx_copybreak = 100;
66 #define PAD_SIZE (128 - sizeof(struct hpc_dma_desc) - sizeof(void *))
125 static inline void hpc3_eth_reset(
struct hpc3_ethregs *hregs)
132 static inline void reset_hpc3_and_seeq(
struct hpc3_ethregs *hregs,
136 hpc3_eth_reset(hregs);
139 #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
140 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
150 static inline void __sgiseeq_set_mac_address(
struct net_device *
dev)
157 for (i = 0; i < 6; i++)
161 static int sgiseeq_set_mac_address(
struct net_device *dev,
void *
addr)
169 __sgiseeq_set_mac_address(dev);
175 #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
176 #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
177 #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
179 static int seeq_init_ring(
struct net_device *dev)
184 netif_stop_queue(dev);
188 __sgiseeq_set_mac_address(dev);
193 dma_sync_desc_dev(dev, &sp->
tx_desc[i]);
212 dma_sync_desc_dev(dev, &sp->
rx_desc[i]);
215 dma_sync_desc_dev(dev, &sp->
rx_desc[i - 1]);
219 static void seeq_purge_ring(
struct net_device *dev)
227 dev_kfree_skb(sp->
tx_desc[i].skb);
235 dev_kfree_skb(sp->
rx_desc[i].skb);
245 static void sgiseeq_dump_rings(
void)
258 printk(
"RX [%d]: @(%p) [%08x,%08x,%08x] ",
259 i, (&r[i]), r[i].rdma.pbuf, r[i].
rdma.cntinfo,
262 printk(
"-- [%d]: @(%p) [%08x,%08x,%08x]\n",
263 i, (&r[i]), r[i].rdma.pbuf, r[i].
rdma.cntinfo,
267 printk(
"TX [%d]: @(%p) [%08x,%08x,%08x] ",
268 i, (&t[i]), t[i].tdma.pbuf, t[i].
tdma.cntinfo,
271 printk(
"-- [%d]: @(%p) [%08x,%08x,%08x]\n",
272 i, (&t[i]), t[i].tdma.pbuf, t[i].
tdma.cntinfo,
275 printk(
"INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
277 printk(
"RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
279 printk(
"TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
284 #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
285 #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
293 reset_hpc3_and_seeq(hregs, sregs);
294 err = seeq_init_ring(dev);
310 seeq_go(sp, hregs, sregs);
318 dev->
stats.rx_over_errors++;
320 dev->
stats.rx_crc_errors++;
322 dev->
stats.rx_frame_errors++;
324 dev->
stats.rx_errors++;
333 seeq_go(sp, hregs, sregs);
344 unsigned char pkt_status;
350 dma_sync_desc_cpu(dev, rd);
355 pkt_status = rd->
skb->data[
len];
360 if (len > rx_copybreak) {
368 skb_reserve(newskb, 2);
370 skb = netdev_alloc_skb_ip_align(dev, len);
372 skb_copy_to_linear_data(skb, rd->
skb->data, len);
381 dev->
stats.rx_packets++;
386 dev->
stats.rx_dropped++;
393 record_rx_errors(dev, pkt_status);
404 dma_sync_desc_dev(dev, rd);
406 dma_sync_desc_cpu(dev, rd);
408 dma_sync_desc_cpu(dev, &sp->
rx_desc[orig_end]);
410 dma_sync_desc_dev(dev, &sp->
rx_desc[orig_end]);
414 rx_maybe_restart(sp, hregs, sregs);
417 static inline void tx_maybe_reset_collisions(
struct sgiseeq_private *sp,
426 static inline void kick_tx(
struct net_device *dev,
440 dma_sync_desc_cpu(dev, td);
445 dma_sync_desc_cpu(dev, td);
458 unsigned long status = hregs->
tx_ctrl;
461 tx_maybe_reset_collisions(sp, sregs);
466 dev->
stats.tx_aborted_errors++;
468 dev->
stats.tx_fifo_errors++;
470 dev->
stats.collisions++;
477 dma_sync_desc_cpu(dev, td);
487 dev->
stats.tx_packets++;
495 dma_sync_desc_dev(dev, td);
512 sgiseeq_rx(dev, sp, hregs, sregs);
516 sgiseeq_tx(dev, sp, hregs, sregs);
519 netif_wake_queue(dev);
526 static int sgiseeq_open(
struct net_device *dev)
530 unsigned int irq = dev->
irq;
533 if (
request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
538 err = init_seeq(dev, sp, sregs);
542 netif_start_queue(dev);
552 static int sgiseeq_close(
struct net_device *dev)
556 unsigned int irq = dev->
irq;
558 netif_stop_queue(dev);
561 reset_hpc3_and_seeq(sp->
hregs, sregs);
563 seeq_purge_ring(dev);
568 static inline int sgiseeq_reset(
struct net_device *dev)
574 err = init_seeq(dev, sp, sregs);
579 netif_wake_queue(dev);
598 spin_unlock_irqrestore(&sp->
tx_lock, flags);
604 dev->
stats.tx_bytes += len;
607 dma_sync_desc_cpu(dev, td);
627 dma_sync_desc_dev(dev, td);
632 dma_sync_desc_cpu(dev, backend);
634 dma_sync_desc_dev(dev, backend);
640 kick_tx(dev, sp, hregs);
643 netif_stop_queue(dev);
644 spin_unlock_irqrestore(&sp->
tx_lock, flags);
655 netif_wake_queue(dev);
658 static void sgiseeq_set_multicast(
struct net_device *dev)
661 unsigned char oldmode = sp->
mode;
674 if (oldmode != sp->
mode)
678 static inline void setup_tx_ring(
struct net_device *dev,
685 while (i < (nbufs - 1)) {
687 buf[
i].
tdma.pbuf = 0;
688 dma_sync_desc_dev(dev, &buf[i]);
692 dma_sync_desc_dev(dev, &buf[i]);
695 static inline void setup_rx_ring(
struct net_device *dev,
702 while (i < (nbufs - 1)) {
704 buf[
i].
rdma.pbuf = 0;
705 dma_sync_desc_dev(dev, &buf[i]);
708 buf[
i].
rdma.pbuf = 0;
710 dma_sync_desc_dev(dev, &buf[i]);
714 .ndo_open = sgiseeq_open,
715 .ndo_stop = sgiseeq_close,
716 .ndo_start_xmit = sgiseeq_start_xmit,
718 .ndo_set_rx_mode = sgiseeq_set_multicast,
719 .ndo_set_mac_address = sgiseeq_set_mac_address,
729 unsigned int irq = pd->
irq;
740 platform_set_drvdata(pdev, dev);
741 sp = netdev_priv(dev);
749 goto err_out_free_dev;
757 setup_rx_ring(dev, sp->
rx_desc, SEEQ_RX_BUFFERS);
758 setup_tx_ring(dev, sp->
tx_desc, SEEQ_TX_BUFFERS);
768 sp->
name = sgiseeqstr;
772 sp->
hregs->pconfig = 0x161;
777 sp->
hregs->pconfig = 0x161;
782 hpc3_eth_reset(sp->
hregs);
784 sp->
is_edlc = !(sp->
sregs->rw.rregs.collision_tx[0] & 0xff);
798 goto err_out_free_page;
816 struct net_device *dev = platform_get_drvdata(pdev);
823 platform_set_drvdata(pdev,
NULL);
829 .probe = sgiseeq_probe,