blob: ca73366057486a4bc753e7fb00740cec5e748221 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sgiseeq.c: Seeq8003 ethernet driver for SGI machines.
3 *
Justin P. Mattock79add622011-04-04 14:15:29 -07004 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Ralf Baechlea4d4d512006-03-08 11:49:31 +00006
7#undef DEBUG
8
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +00009#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/string.h>
17#include <linux/delay.h>
18#include <linux/netdevice.h>
Ralf Baechledf9f54082007-05-11 15:48:58 +010019#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/etherdevice.h>
21#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/sgi/hpc3.h>
24#include <asm/sgi/ip22.h>
Ralf Baechledf9f54082007-05-11 15:48:58 +010025#include <asm/sgi/seeq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include "sgiseeq.h"
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static 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
Lucas De Marchi25985ed2011-03-30 22:57:33 -030036 * laid out like how the HPC DMA and the Seeq want it to. You'd be surprised
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 * 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
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010056#define VIRT_TO_DMA(sp, v) ((sp)->srings_dma + \
57 (dma_addr_t)((unsigned long)(v) - \
58 (unsigned long)((sp)->rx_desc)))
59
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010060/* Copy frames shorter than rx_copybreak, otherwise pass on up in
61 * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
62 */
63static int rx_copybreak = 100;
64
65#define PAD_SIZE (128 - sizeof(struct hpc_dma_desc) - sizeof(void *))
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067struct sgiseeq_rx_desc {
68 volatile struct hpc_dma_desc rdma;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010069 u8 padding[PAD_SIZE];
70 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
73struct sgiseeq_tx_desc {
74 volatile struct hpc_dma_desc tdma;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010075 u8 padding[PAD_SIZE];
76 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
79/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -030080 * Warning: This structure is laid out in a certain way because HPC dma
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 * descriptors must be 8-byte aligned. So don't touch this without
82 * some care.
83 */
84struct sgiseeq_init_block { /* Note the name ;-) */
85 struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS];
86 struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS];
87};
88
89struct sgiseeq_private {
90 struct sgiseeq_init_block *srings;
Ralf Baechle99cd1492007-09-04 14:41:01 +010091 dma_addr_t srings_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 /* Ptrs to the descriptors in uncached space. */
94 struct sgiseeq_rx_desc *rx_desc;
95 struct sgiseeq_tx_desc *tx_desc;
96
97 char *name;
98 struct hpc3_ethregs *hregs;
99 struct sgiseeq_regs *sregs;
100
101 /* Ring entry counters. */
102 unsigned int rx_new, tx_new;
103 unsigned int rx_old, tx_old;
104
105 int is_edlc;
106 unsigned char control;
107 unsigned char mode;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 spinlock_t tx_lock;
110};
111
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100112static inline void dma_sync_desc_cpu(struct net_device *dev, void *addr)
113{
114 dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc),
115 DMA_FROM_DEVICE);
116}
117
118static inline void dma_sync_desc_dev(struct net_device *dev, void *addr)
119{
120 dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc),
121 DMA_TO_DEVICE);
122}
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
125{
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100126 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 udelay(20);
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100128 hregs->reset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
132 struct sgiseeq_regs *sregs)
133{
134 hregs->rx_ctrl = hregs->tx_ctrl = 0;
135 hpc3_eth_reset(hregs);
136}
137
138#define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
139 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
140
141static inline void seeq_go(struct sgiseeq_private *sp,
142 struct hpc3_ethregs *hregs,
143 struct sgiseeq_regs *sregs)
144{
145 sregs->rstat = sp->mode | RSTAT_GO_BITS;
146 hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
147}
148
149static inline void __sgiseeq_set_mac_address(struct net_device *dev)
150{
151 struct sgiseeq_private *sp = netdev_priv(dev);
152 struct sgiseeq_regs *sregs = sp->sregs;
153 int i;
154
155 sregs->tstat = SEEQ_TCMD_RB0;
156 for (i = 0; i < 6; i++)
157 sregs->rw.eth_addr[i] = dev->dev_addr[i];
158}
159
160static int sgiseeq_set_mac_address(struct net_device *dev, void *addr)
161{
162 struct sgiseeq_private *sp = netdev_priv(dev);
163 struct sockaddr *sa = addr;
164
165 memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
166
167 spin_lock_irq(&sp->tx_lock);
168 __sgiseeq_set_mac_address(dev);
169 spin_unlock_irq(&sp->tx_lock);
170
171 return 0;
172}
173
174#define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
175#define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
176#define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
177
178static int seeq_init_ring(struct net_device *dev)
179{
180 struct sgiseeq_private *sp = netdev_priv(dev);
181 int i;
182
183 netif_stop_queue(dev);
184 sp->rx_new = sp->tx_new = 0;
185 sp->rx_old = sp->tx_old = 0;
186
187 __sgiseeq_set_mac_address(dev);
188
189 /* Setup tx ring. */
190 for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 sp->tx_desc[i].tdma.cntinfo = TCNTINFO_INIT;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100192 dma_sync_desc_dev(dev, &sp->tx_desc[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
195 /* And now the rx ring. */
196 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
Thomas Bogendoerfera24a7892008-01-13 00:08:47 +0100197 if (!sp->rx_desc[i].skb) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100198 dma_addr_t dma_addr;
199 struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100201 if (skb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return -ENOMEM;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100203 skb_reserve(skb, 2);
204 dma_addr = dma_map_single(dev->dev.parent,
205 skb->data - 2,
206 PKT_BUF_SZ, DMA_FROM_DEVICE);
207 sp->rx_desc[i].skb = skb;
208 sp->rx_desc[i].rdma.pbuf = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210 sp->rx_desc[i].rdma.cntinfo = RCNTINFO_INIT;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100211 dma_sync_desc_dev(dev, &sp->rx_desc[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
213 sp->rx_desc[i - 1].rdma.cntinfo |= HPCDMA_EOR;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100214 dma_sync_desc_dev(dev, &sp->rx_desc[i - 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return 0;
216}
217
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100218static void seeq_purge_ring(struct net_device *dev)
219{
220 struct sgiseeq_private *sp = netdev_priv(dev);
221 int i;
222
223 /* clear tx ring. */
224 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
225 if (sp->tx_desc[i].skb) {
226 dev_kfree_skb(sp->tx_desc[i].skb);
227 sp->tx_desc[i].skb = NULL;
228 }
229 }
230
231 /* And now the rx ring. */
232 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
233 if (sp->rx_desc[i].skb) {
234 dev_kfree_skb(sp->rx_desc[i].skb);
235 sp->rx_desc[i].skb = NULL;
236 }
237 }
238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#ifdef DEBUG
241static struct sgiseeq_private *gpriv;
242static struct net_device *gdev;
243
Ralf Baechlea4d4d512006-03-08 11:49:31 +0000244static void sgiseeq_dump_rings(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 static int once;
247 struct sgiseeq_rx_desc *r = gpriv->rx_desc;
248 struct sgiseeq_tx_desc *t = gpriv->tx_desc;
249 struct hpc3_ethregs *hregs = gpriv->hregs;
250 int i;
251
252 if (once)
253 return;
254 once++;
255 printk("RING DUMP:\n");
256 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
257 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
258 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
259 r[i].rdma.pnext);
260 i += 1;
261 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
262 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
263 r[i].rdma.pnext);
264 }
265 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
266 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
267 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
268 t[i].tdma.pnext);
269 i += 1;
270 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
271 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
272 t[i].tdma.pnext);
273 }
274 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
275 gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
276 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
277 hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
278 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
279 hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
280}
281#endif
282
283#define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
284#define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
287 struct sgiseeq_regs *sregs)
288{
289 struct hpc3_ethregs *hregs = sp->hregs;
290 int err;
291
292 reset_hpc3_and_seeq(hregs, sregs);
293 err = seeq_init_ring(dev);
294 if (err)
295 return err;
296
297 /* Setup to field the proper interrupt types. */
298 if (sp->is_edlc) {
299 sregs->tstat = TSTAT_INIT_EDLC;
300 sregs->rw.wregs.control = sp->control;
301 sregs->rw.wregs.frame_gap = 0;
302 } else {
303 sregs->tstat = TSTAT_INIT_SEEQ;
304 }
305
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100306 hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc);
307 hregs->tx_ndptr = VIRT_TO_DMA(sp, sp->tx_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 seeq_go(sp, hregs, sregs);
310 return 0;
311}
312
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700313static void record_rx_errors(struct net_device *dev, unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 if (status & SEEQ_RSTAT_OVERF ||
316 status & SEEQ_RSTAT_SFRAME)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700317 dev->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (status & SEEQ_RSTAT_CERROR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700319 dev->stats.rx_crc_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (status & SEEQ_RSTAT_DERROR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700321 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (status & SEEQ_RSTAT_REOF)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700323 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326static inline void rx_maybe_restart(struct sgiseeq_private *sp,
327 struct hpc3_ethregs *hregs,
328 struct sgiseeq_regs *sregs)
329{
330 if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100331 hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc + sp->rx_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 seeq_go(sp, hregs, sregs);
333 }
334}
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
337 struct hpc3_ethregs *hregs,
338 struct sgiseeq_regs *sregs)
339{
340 struct sgiseeq_rx_desc *rd;
Ralf Baechlea4d4d512006-03-08 11:49:31 +0000341 struct sk_buff *skb = NULL;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100342 struct sk_buff *newskb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 unsigned char pkt_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 int len = 0;
345 unsigned int orig_end = PREV_RX(sp->rx_new);
346
347 /* Service every received packet. */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100348 rd = &sp->rx_desc[sp->rx_new];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100349 dma_sync_desc_cpu(dev, rd);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100350 while (!(rd->rdma.cntinfo & HPCDMA_OWN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 len = PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100352 dma_unmap_single(dev->dev.parent, rd->rdma.pbuf,
353 PKT_BUF_SZ, DMA_FROM_DEVICE);
354 pkt_status = rd->skb->data[len];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (pkt_status & SEEQ_RSTAT_FIG) {
356 /* Packet is OK. */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100357 /* We don't want to receive our own packets */
dingtianhong9116d7b2013-12-30 15:41:21 +0800358 if (!ether_addr_equal(rd->skb->data + 6, dev->dev_addr)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100359 if (len > rx_copybreak) {
360 skb = rd->skb;
361 newskb = netdev_alloc_skb(dev, PKT_BUF_SZ);
362 if (!newskb) {
363 newskb = skb;
364 skb = NULL;
365 goto memory_squeeze;
366 }
367 skb_reserve(newskb, 2);
368 } else {
Eric Dumazet89d71a62009-10-13 05:34:20 +0000369 skb = netdev_alloc_skb_ip_align(dev, len);
370 if (skb)
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100371 skb_copy_to_linear_data(skb, rd->skb->data, len);
Eric Dumazet89d71a62009-10-13 05:34:20 +0000372
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100373 newskb = rd->skb;
374 }
375memory_squeeze:
376 if (skb) {
377 skb_put(skb, len);
378 skb->protocol = eth_type_trans(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 netif_rx(skb);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700380 dev->stats.rx_packets++;
381 dev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 } else {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100383 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385 } else {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100386 /* Silently drop my own packets */
387 newskb = rd->skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700390 record_rx_errors(dev, pkt_status);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100391 newskb = rd->skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100393 rd->skb = newskb;
394 rd->rdma.pbuf = dma_map_single(dev->dev.parent,
395 newskb->data - 2,
396 PKT_BUF_SZ, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 /* Return the entry to the ring pool. */
399 rd->rdma.cntinfo = RCNTINFO_INIT;
400 sp->rx_new = NEXT_RX(sp->rx_new);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100401 dma_sync_desc_dev(dev, rd);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100402 rd = &sp->rx_desc[sp->rx_new];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100403 dma_sync_desc_cpu(dev, rd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100405 dma_sync_desc_cpu(dev, &sp->rx_desc[orig_end]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100407 dma_sync_desc_dev(dev, &sp->rx_desc[orig_end]);
408 dma_sync_desc_cpu(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100410 dma_sync_desc_dev(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 rx_maybe_restart(sp, hregs, sregs);
412}
413
414static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
415 struct sgiseeq_regs *sregs)
416{
417 if (sp->is_edlc) {
418 sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
419 sregs->rw.wregs.control = sp->control;
420 }
421}
422
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100423static inline void kick_tx(struct net_device *dev,
424 struct sgiseeq_private *sp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 struct hpc3_ethregs *hregs)
426{
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100427 struct sgiseeq_tx_desc *td;
428 int i = sp->tx_old;
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 /* If the HPC aint doin nothin, and there are more packets
431 * with ETXD cleared and XIU set we must make very certain
432 * that we restart the HPC else we risk locking up the
433 * adapter. The following code is only safe iff the HPCDMA
434 * is not active!
435 */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100436 td = &sp->tx_desc[i];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100437 dma_sync_desc_cpu(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100439 (HPCDMA_XIU | HPCDMA_ETXD)) {
440 i = NEXT_TX(i);
441 td = &sp->tx_desc[i];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100442 dma_sync_desc_cpu(dev, td);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (td->tdma.cntinfo & HPCDMA_XIU) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100445 hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
447 }
448}
449
450static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
451 struct hpc3_ethregs *hregs,
452 struct sgiseeq_regs *sregs)
453{
454 struct sgiseeq_tx_desc *td;
455 unsigned long status = hregs->tx_ctrl;
456 int j;
457
458 tx_maybe_reset_collisions(sp, sregs);
459
460 if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
461 /* Oops, HPC detected some sort of error. */
462 if (status & SEEQ_TSTAT_R16)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700463 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (status & SEEQ_TSTAT_UFLOW)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700465 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (status & SEEQ_TSTAT_LCLS)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700467 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469
470 /* Ack 'em... */
471 for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
472 td = &sp->tx_desc[j];
473
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100474 dma_sync_desc_cpu(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
476 break;
477 if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
478 if (!(status & HPC3_ETXCTRL_ACTIVE)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100479 hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
481 }
482 break;
483 }
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700484 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 sp->tx_old = NEXT_TX(sp->tx_old);
486 td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
487 td->tdma.cntinfo |= HPCDMA_EOX;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100488 if (td->skb) {
489 dev_kfree_skb_any(td->skb);
490 td->skb = NULL;
491 }
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100492 dma_sync_desc_dev(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494}
495
David Howells7d12e782006-10-05 14:55:46 +0100496static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 struct net_device *dev = (struct net_device *) dev_id;
499 struct sgiseeq_private *sp = netdev_priv(dev);
500 struct hpc3_ethregs *hregs = sp->hregs;
501 struct sgiseeq_regs *sregs = sp->sregs;
502
503 spin_lock(&sp->tx_lock);
504
505 /* Ack the IRQ and set software state. */
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100506 hregs->reset = HPC3_ERST_CLRIRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 /* Always check for received packets. */
509 sgiseeq_rx(dev, sp, hregs, sregs);
510
511 /* Only check for tx acks if we have something queued. */
512 if (sp->tx_old != sp->tx_new)
513 sgiseeq_tx(dev, sp, hregs, sregs);
514
515 if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
516 netif_wake_queue(dev);
517 }
518 spin_unlock(&sp->tx_lock);
519
520 return IRQ_HANDLED;
521}
522
523static int sgiseeq_open(struct net_device *dev)
524{
525 struct sgiseeq_private *sp = netdev_priv(dev);
526 struct sgiseeq_regs *sregs = sp->sregs;
527 unsigned int irq = dev->irq;
528 int err;
529
530 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
531 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
Nicolas Kaiser06d6e6d2010-10-26 10:02:13 -0700532 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534
535 err = init_seeq(dev, sp, sregs);
536 if (err)
537 goto out_free_irq;
538
539 netif_start_queue(dev);
540
541 return 0;
542
543out_free_irq:
544 free_irq(irq, dev);
545
546 return err;
547}
548
549static int sgiseeq_close(struct net_device *dev)
550{
551 struct sgiseeq_private *sp = netdev_priv(dev);
552 struct sgiseeq_regs *sregs = sp->sregs;
Ralf Baechle28914392005-10-10 14:50:51 +0100553 unsigned int irq = dev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 netif_stop_queue(dev);
556
557 /* Shutdown the Seeq. */
558 reset_hpc3_and_seeq(sp->hregs, sregs);
Ralf Baechle28914392005-10-10 14:50:51 +0100559 free_irq(irq, dev);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100560 seeq_purge_ring(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 return 0;
563}
564
565static inline int sgiseeq_reset(struct net_device *dev)
566{
567 struct sgiseeq_private *sp = netdev_priv(dev);
568 struct sgiseeq_regs *sregs = sp->sregs;
569 int err;
570
571 err = init_seeq(dev, sp, sregs);
572 if (err)
573 return err;
574
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700575 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 netif_wake_queue(dev);
577
578 return 0;
579}
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
582{
583 struct sgiseeq_private *sp = netdev_priv(dev);
584 struct hpc3_ethregs *hregs = sp->hregs;
585 unsigned long flags;
586 struct sgiseeq_tx_desc *td;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100587 int len, entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 spin_lock_irqsave(&sp->tx_lock, flags);
590
591 /* Setup... */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100592 len = skb->len;
593 if (len < ETH_ZLEN) {
Julia Lawallce6fbde2010-03-29 05:35:05 +0000594 if (skb_padto(skb, ETH_ZLEN)) {
595 spin_unlock_irqrestore(&sp->tx_lock, flags);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000596 return NETDEV_TX_OK;
Julia Lawallce6fbde2010-03-29 05:35:05 +0000597 }
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100598 len = ETH_ZLEN;
599 }
600
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700601 dev->stats.tx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 entry = sp->tx_new;
603 td = &sp->tx_desc[entry];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100604 dma_sync_desc_cpu(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 /* Create entry. There are so many races with adding a new
607 * descriptor to the chain:
608 * 1) Assume that the HPC is off processing a DMA chain while
609 * we are changing all of the following.
610 * 2) Do no allow the HPC to look at a new descriptor until
611 * we have completely set up it's state. This means, do
612 * not clear HPCDMA_EOX in the current last descritptor
613 * until the one we are adding looks consistent and could
614 * be processes right now.
615 * 3) The tx interrupt code must notice when we've added a new
616 * entry and the HPC got to the end of the chain before we
617 * added this new entry and restarted it.
618 */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100619 td->skb = skb;
620 td->tdma.pbuf = dma_map_single(dev->dev.parent, skb->data,
621 len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 td->tdma.cntinfo = (len & HPCDMA_BCNT) |
623 HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100624 dma_sync_desc_dev(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (sp->tx_old != sp->tx_new) {
626 struct sgiseeq_tx_desc *backend;
627
628 backend = &sp->tx_desc[PREV_TX(sp->tx_new)];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100629 dma_sync_desc_cpu(dev, backend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 backend->tdma.cntinfo &= ~HPCDMA_EOX;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100631 dma_sync_desc_dev(dev, backend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633 sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
634
635 /* Maybe kick the HPC back into motion. */
636 if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100637 kick_tx(dev, sp, hregs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (!TX_BUFFS_AVAIL(sp))
640 netif_stop_queue(dev);
641 spin_unlock_irqrestore(&sp->tx_lock, flags);
642
Patrick McHardy6ed10652009-06-23 06:03:08 +0000643 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644}
645
646static void timeout(struct net_device *dev)
647{
648 printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
649 sgiseeq_reset(dev);
650
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700651 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 netif_wake_queue(dev);
653}
654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655static void sgiseeq_set_multicast(struct net_device *dev)
656{
Wang Chen8f15ea42008-11-12 23:38:36 -0800657 struct sgiseeq_private *sp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 unsigned char oldmode = sp->mode;
659
660 if(dev->flags & IFF_PROMISC)
661 sp->mode = SEEQ_RCMD_RANY;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000662 else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 sp->mode = SEEQ_RCMD_RBMCAST;
664 else
665 sp->mode = SEEQ_RCMD_RBCAST;
666
667 /* XXX I know this sucks, but is there a better way to reprogram
668 * XXX the receiver? At least, this shouldn't happen too often.
669 */
670
671 if (oldmode != sp->mode)
672 sgiseeq_reset(dev);
673}
674
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100675static inline void setup_tx_ring(struct net_device *dev,
676 struct sgiseeq_tx_desc *buf,
677 int nbufs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100679 struct sgiseeq_private *sp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 int i = 0;
681
682 while (i < (nbufs - 1)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100683 buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf + i + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 buf[i].tdma.pbuf = 0;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100685 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 i++;
687 }
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100688 buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100689 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100692static inline void setup_rx_ring(struct net_device *dev,
693 struct sgiseeq_rx_desc *buf,
694 int nbufs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100696 struct sgiseeq_private *sp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 int i = 0;
698
699 while (i < (nbufs - 1)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100700 buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf + i + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 buf[i].rdma.pbuf = 0;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100702 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 i++;
704 }
705 buf[i].rdma.pbuf = 0;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100706 buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100707 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
Alexander Beregalov8c2c6be2009-04-15 12:52:58 +0000710static const struct net_device_ops sgiseeq_netdev_ops = {
711 .ndo_open = sgiseeq_open,
712 .ndo_stop = sgiseeq_close,
713 .ndo_start_xmit = sgiseeq_start_xmit,
714 .ndo_tx_timeout = timeout,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000715 .ndo_set_rx_mode = sgiseeq_set_multicast,
Alexander Beregalov8c2c6be2009-04-15 12:52:58 +0000716 .ndo_set_mac_address = sgiseeq_set_mac_address,
717 .ndo_change_mtu = eth_change_mtu,
718 .ndo_validate_addr = eth_validate_addr,
719};
720
Bill Pemberton5911ce02012-12-03 09:23:31 -0500721static int sgiseeq_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
Jingoo Hand7765422013-08-30 14:00:45 +0900723 struct sgiseeq_platform_data *pd = dev_get_platdata(&pdev->dev);
Ralf Baechledf9f54082007-05-11 15:48:58 +0100724 struct hpc3_regs *hpcregs = pd->hpc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 struct sgiseeq_init_block *sr;
Ralf Baechledf9f54082007-05-11 15:48:58 +0100726 unsigned int irq = pd->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 struct sgiseeq_private *sp;
728 struct net_device *dev;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100729 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 dev = alloc_etherdev(sizeof (struct sgiseeq_private));
732 if (!dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 err = -ENOMEM;
734 goto err_out;
735 }
Ralf Baechledf9f54082007-05-11 15:48:58 +0100736
737 platform_set_drvdata(pdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 sp = netdev_priv(dev);
739
740 /* Make private data page aligned */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100741 sr = dma_alloc_noncoherent(&pdev->dev, sizeof(*sp->srings),
Ralf Baechle99cd1492007-09-04 14:41:01 +0100742 &sp->srings_dma, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 if (!sr) {
744 printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
745 err = -ENOMEM;
746 goto err_out_free_dev;
747 }
748 sp->srings = sr;
Ralf Baechle99cd1492007-09-04 14:41:01 +0100749 sp->rx_desc = sp->srings->rxvector;
750 sp->tx_desc = sp->srings->txvector;
Jean Delvareb8dfc6a2012-09-06 00:47:05 +0000751 spin_lock_init(&sp->tx_lock);
Ralf Baechle99cd1492007-09-04 14:41:01 +0100752
753 /* A couple calculations now, saves many cycles later. */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100754 setup_rx_ring(dev, sp->rx_desc, SEEQ_RX_BUFFERS);
755 setup_tx_ring(dev, sp->tx_desc, SEEQ_TX_BUFFERS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Ralf Baechledf9f54082007-05-11 15:48:58 +0100757 memcpy(dev->dev_addr, pd->mac, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759#ifdef DEBUG
760 gpriv = sp;
761 gdev = dev;
762#endif
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100763 sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
764 sp->hregs = &hpcregs->ethregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 sp->name = sgiseeqstr;
766 sp->mode = SEEQ_RCMD_RBCAST;
767
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100768 /* Setup PIO and DMA transfer timing */
769 sp->hregs->pconfig = 0x161;
770 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
771 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
772
Ladislav Michl78ee5b32007-02-28 01:18:35 +0000773 /* Setup PIO and DMA transfer timing */
774 sp->hregs->pconfig = 0x161;
775 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
776 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 /* Reset the chip. */
779 hpc3_eth_reset(sp->hregs);
780
781 sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
782 if (sp->is_edlc)
783 sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
784 SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
785 SEEQ_CTRL_ENCARR;
786
Alexander Beregalov8c2c6be2009-04-15 12:52:58 +0000787 dev->netdev_ops = &sgiseeq_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 dev->watchdog_timeo = (200 * HZ) / 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 dev->irq = irq;
790
791 if (register_netdev(dev)) {
792 printk(KERN_ERR "Sgiseeq: Cannot register net device, "
793 "aborting.\n");
794 err = -ENODEV;
795 goto err_out_free_page;
796 }
797
Johannes Berge1749612008-10-27 15:59:26 -0700798 printk(KERN_INFO "%s: %s %pM\n", dev->name, sgiseeqstr, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return 0;
801
802err_out_free_page:
Ralf Baechle28914392005-10-10 14:50:51 +0100803 free_page((unsigned long) sp->srings);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804err_out_free_dev:
Kulikov Vasiliy8d879de2010-09-25 23:58:06 +0000805 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807err_out:
808 return err;
809}
810
Ralf Baechlee3efb052007-08-22 16:03:52 +0100811static int __exit sgiseeq_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
Ralf Baechledf9f54082007-05-11 15:48:58 +0100813 struct net_device *dev = platform_get_drvdata(pdev);
814 struct sgiseeq_private *sp = netdev_priv(dev);
Ladislav Michl78ee5b32007-02-28 01:18:35 +0000815
Ralf Baechledf9f54082007-05-11 15:48:58 +0100816 unregister_netdev(dev);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100817 dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
818 sp->srings_dma);
Ralf Baechledf9f54082007-05-11 15:48:58 +0100819 free_netdev(dev);
Ralf Baechlee3efb052007-08-22 16:03:52 +0100820
821 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822}
823
Ralf Baechledf9f54082007-05-11 15:48:58 +0100824static struct platform_driver sgiseeq_driver = {
825 .probe = sgiseeq_probe,
Uwe Kleine-Königfb74c2f2009-09-30 22:28:26 +0000826 .remove = __exit_p(sgiseeq_remove),
Ralf Baechledf9f54082007-05-11 15:48:58 +0100827 .driver = {
Kay Sievers72abb462008-04-18 13:50:44 -0700828 .name = "sgiseeq",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 }
Ralf Baechledf9f54082007-05-11 15:48:58 +0100830};
831
Axel Lindb62f682011-11-27 16:44:17 +0000832module_platform_driver(sgiseeq_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100834MODULE_DESCRIPTION("SGI Seeq 8003 driver");
835MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836MODULE_LICENSE("GPL");
Kay Sievers72abb462008-04-18 13:50:44 -0700837MODULE_ALIAS("platform:sgiseeq");