blob: 52fb7ed9f3654bc272dbf6a824e26d3f860841ff [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>
14#include <linux/init.h>
15#include <linux/types.h>
16#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/string.h>
18#include <linux/delay.h>
19#include <linux/netdevice.h>
Ralf Baechledf9f5402007-05-11 15:48:58 +010020#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/etherdevice.h>
22#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/sgi/hpc3.h>
25#include <asm/sgi/ip22.h>
Ralf Baechledf9f5402007-05-11 15:48:58 +010026#include <asm/sgi/seeq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include "sgiseeq.h"
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static char *sgiseeqstr = "SGI Seeq8003";
31
32/*
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
Lucas De Marchi25985ed2011-03-30 22:57:33 -030037 * laid out like how the HPC DMA and the Seeq want it to. You'd be surprised
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * how a stupid idea like this can pay off in performance, not to mention
39 * making this driver 2,000 times easier to write. ;-)
40 */
41
42/* Tune these if we tend to run out often etc. */
43#define SEEQ_RX_BUFFERS 16
44#define SEEQ_TX_BUFFERS 16
45
46#define PKT_BUF_SZ 1584
47
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))
52
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)
56
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010057#define VIRT_TO_DMA(sp, v) ((sp)->srings_dma + \
58 (dma_addr_t)((unsigned long)(v) - \
59 (unsigned long)((sp)->rx_desc)))
60
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010061/* 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).
63 */
64static int rx_copybreak = 100;
65
66#define PAD_SIZE (128 - sizeof(struct hpc_dma_desc) - sizeof(void *))
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068struct sgiseeq_rx_desc {
69 volatile struct hpc_dma_desc rdma;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010070 u8 padding[PAD_SIZE];
71 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
73
74struct sgiseeq_tx_desc {
75 volatile struct hpc_dma_desc tdma;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +010076 u8 padding[PAD_SIZE];
77 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -030081 * Warning: This structure is laid out in a certain way because HPC dma
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * descriptors must be 8-byte aligned. So don't touch this without
83 * some care.
84 */
85struct sgiseeq_init_block { /* Note the name ;-) */
86 struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS];
87 struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS];
88};
89
90struct sgiseeq_private {
91 struct sgiseeq_init_block *srings;
Ralf Baechle99cd1492007-09-04 14:41:01 +010092 dma_addr_t srings_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 /* Ptrs to the descriptors in uncached space. */
95 struct sgiseeq_rx_desc *rx_desc;
96 struct sgiseeq_tx_desc *tx_desc;
97
98 char *name;
99 struct hpc3_ethregs *hregs;
100 struct sgiseeq_regs *sregs;
101
102 /* Ring entry counters. */
103 unsigned int rx_new, tx_new;
104 unsigned int rx_old, tx_old;
105
106 int is_edlc;
107 unsigned char control;
108 unsigned char mode;
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 spinlock_t tx_lock;
111};
112
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100113static inline void dma_sync_desc_cpu(struct net_device *dev, void *addr)
114{
115 dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc),
116 DMA_FROM_DEVICE);
117}
118
119static inline void dma_sync_desc_dev(struct net_device *dev, void *addr)
120{
121 dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc),
122 DMA_TO_DEVICE);
123}
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
126{
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100127 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 udelay(20);
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100129 hregs->reset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
133 struct sgiseeq_regs *sregs)
134{
135 hregs->rx_ctrl = hregs->tx_ctrl = 0;
136 hpc3_eth_reset(hregs);
137}
138
139#define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
140 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
141
142static inline void seeq_go(struct sgiseeq_private *sp,
143 struct hpc3_ethregs *hregs,
144 struct sgiseeq_regs *sregs)
145{
146 sregs->rstat = sp->mode | RSTAT_GO_BITS;
147 hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
148}
149
150static inline void __sgiseeq_set_mac_address(struct net_device *dev)
151{
152 struct sgiseeq_private *sp = netdev_priv(dev);
153 struct sgiseeq_regs *sregs = sp->sregs;
154 int i;
155
156 sregs->tstat = SEEQ_TCMD_RB0;
157 for (i = 0; i < 6; i++)
158 sregs->rw.eth_addr[i] = dev->dev_addr[i];
159}
160
161static int sgiseeq_set_mac_address(struct net_device *dev, void *addr)
162{
163 struct sgiseeq_private *sp = netdev_priv(dev);
164 struct sockaddr *sa = addr;
165
166 memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
167
168 spin_lock_irq(&sp->tx_lock);
169 __sgiseeq_set_mac_address(dev);
170 spin_unlock_irq(&sp->tx_lock);
171
172 return 0;
173}
174
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))
178
179static int seeq_init_ring(struct net_device *dev)
180{
181 struct sgiseeq_private *sp = netdev_priv(dev);
182 int i;
183
184 netif_stop_queue(dev);
185 sp->rx_new = sp->tx_new = 0;
186 sp->rx_old = sp->tx_old = 0;
187
188 __sgiseeq_set_mac_address(dev);
189
190 /* Setup tx ring. */
191 for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 sp->tx_desc[i].tdma.cntinfo = TCNTINFO_INIT;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100193 dma_sync_desc_dev(dev, &sp->tx_desc[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195
196 /* And now the rx ring. */
197 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
Thomas Bogendoerfera24a7892008-01-13 00:08:47 +0100198 if (!sp->rx_desc[i].skb) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100199 dma_addr_t dma_addr;
200 struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100202 if (skb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return -ENOMEM;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100204 skb_reserve(skb, 2);
205 dma_addr = dma_map_single(dev->dev.parent,
206 skb->data - 2,
207 PKT_BUF_SZ, DMA_FROM_DEVICE);
208 sp->rx_desc[i].skb = skb;
209 sp->rx_desc[i].rdma.pbuf = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211 sp->rx_desc[i].rdma.cntinfo = RCNTINFO_INIT;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100212 dma_sync_desc_dev(dev, &sp->rx_desc[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214 sp->rx_desc[i - 1].rdma.cntinfo |= HPCDMA_EOR;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100215 dma_sync_desc_dev(dev, &sp->rx_desc[i - 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return 0;
217}
218
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100219static void seeq_purge_ring(struct net_device *dev)
220{
221 struct sgiseeq_private *sp = netdev_priv(dev);
222 int i;
223
224 /* clear tx ring. */
225 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
226 if (sp->tx_desc[i].skb) {
227 dev_kfree_skb(sp->tx_desc[i].skb);
228 sp->tx_desc[i].skb = NULL;
229 }
230 }
231
232 /* And now the rx ring. */
233 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
234 if (sp->rx_desc[i].skb) {
235 dev_kfree_skb(sp->rx_desc[i].skb);
236 sp->rx_desc[i].skb = NULL;
237 }
238 }
239}
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#ifdef DEBUG
242static struct sgiseeq_private *gpriv;
243static struct net_device *gdev;
244
Ralf Baechlea4d4d512006-03-08 11:49:31 +0000245static void sgiseeq_dump_rings(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 static int once;
248 struct sgiseeq_rx_desc *r = gpriv->rx_desc;
249 struct sgiseeq_tx_desc *t = gpriv->tx_desc;
250 struct hpc3_ethregs *hregs = gpriv->hregs;
251 int i;
252
253 if (once)
254 return;
255 once++;
256 printk("RING DUMP:\n");
257 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
258 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
259 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
260 r[i].rdma.pnext);
261 i += 1;
262 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
263 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
264 r[i].rdma.pnext);
265 }
266 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
267 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
268 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
269 t[i].tdma.pnext);
270 i += 1;
271 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
272 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
273 t[i].tdma.pnext);
274 }
275 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
276 gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
277 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
278 hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
279 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
280 hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
281}
282#endif
283
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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
288 struct sgiseeq_regs *sregs)
289{
290 struct hpc3_ethregs *hregs = sp->hregs;
291 int err;
292
293 reset_hpc3_and_seeq(hregs, sregs);
294 err = seeq_init_ring(dev);
295 if (err)
296 return err;
297
298 /* Setup to field the proper interrupt types. */
299 if (sp->is_edlc) {
300 sregs->tstat = TSTAT_INIT_EDLC;
301 sregs->rw.wregs.control = sp->control;
302 sregs->rw.wregs.frame_gap = 0;
303 } else {
304 sregs->tstat = TSTAT_INIT_SEEQ;
305 }
306
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100307 hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc);
308 hregs->tx_ndptr = VIRT_TO_DMA(sp, sp->tx_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 seeq_go(sp, hregs, sregs);
311 return 0;
312}
313
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700314static void record_rx_errors(struct net_device *dev, unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 if (status & SEEQ_RSTAT_OVERF ||
317 status & SEEQ_RSTAT_SFRAME)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700318 dev->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (status & SEEQ_RSTAT_CERROR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700320 dev->stats.rx_crc_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (status & SEEQ_RSTAT_DERROR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700322 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (status & SEEQ_RSTAT_REOF)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700324 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327static inline void rx_maybe_restart(struct sgiseeq_private *sp,
328 struct hpc3_ethregs *hregs,
329 struct sgiseeq_regs *sregs)
330{
331 if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100332 hregs->rx_ndptr = VIRT_TO_DMA(sp, sp->rx_desc + sp->rx_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 seeq_go(sp, hregs, sregs);
334 }
335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
338 struct hpc3_ethregs *hregs,
339 struct sgiseeq_regs *sregs)
340{
341 struct sgiseeq_rx_desc *rd;
Ralf Baechlea4d4d512006-03-08 11:49:31 +0000342 struct sk_buff *skb = NULL;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100343 struct sk_buff *newskb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 unsigned char pkt_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 int len = 0;
346 unsigned int orig_end = PREV_RX(sp->rx_new);
347
348 /* Service every received packet. */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100349 rd = &sp->rx_desc[sp->rx_new];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100350 dma_sync_desc_cpu(dev, rd);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100351 while (!(rd->rdma.cntinfo & HPCDMA_OWN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 len = PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100353 dma_unmap_single(dev->dev.parent, rd->rdma.pbuf,
354 PKT_BUF_SZ, DMA_FROM_DEVICE);
355 pkt_status = rd->skb->data[len];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (pkt_status & SEEQ_RSTAT_FIG) {
357 /* Packet is OK. */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100358 /* We don't want to receive our own packets */
359 if (memcmp(rd->skb->data + 6, dev->dev_addr, ETH_ALEN)) {
360 if (len > rx_copybreak) {
361 skb = rd->skb;
362 newskb = netdev_alloc_skb(dev, PKT_BUF_SZ);
363 if (!newskb) {
364 newskb = skb;
365 skb = NULL;
366 goto memory_squeeze;
367 }
368 skb_reserve(newskb, 2);
369 } else {
Eric Dumazet89d71a62009-10-13 05:34:20 +0000370 skb = netdev_alloc_skb_ip_align(dev, len);
371 if (skb)
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100372 skb_copy_to_linear_data(skb, rd->skb->data, len);
Eric Dumazet89d71a62009-10-13 05:34:20 +0000373
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100374 newskb = rd->skb;
375 }
376memory_squeeze:
377 if (skb) {
378 skb_put(skb, len);
379 skb->protocol = eth_type_trans(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 netif_rx(skb);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700381 dev->stats.rx_packets++;
382 dev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 } else {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100384 printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n",
385 dev->name);
386 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388 } else {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100389 /* Silently drop my own packets */
390 newskb = rd->skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
392 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700393 record_rx_errors(dev, pkt_status);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100394 newskb = rd->skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100396 rd->skb = newskb;
397 rd->rdma.pbuf = dma_map_single(dev->dev.parent,
398 newskb->data - 2,
399 PKT_BUF_SZ, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /* Return the entry to the ring pool. */
402 rd->rdma.cntinfo = RCNTINFO_INIT;
403 sp->rx_new = NEXT_RX(sp->rx_new);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100404 dma_sync_desc_dev(dev, rd);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100405 rd = &sp->rx_desc[sp->rx_new];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100406 dma_sync_desc_cpu(dev, rd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100408 dma_sync_desc_cpu(dev, &sp->rx_desc[orig_end]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100410 dma_sync_desc_dev(dev, &sp->rx_desc[orig_end]);
411 dma_sync_desc_cpu(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100413 dma_sync_desc_dev(dev, &sp->rx_desc[PREV_RX(sp->rx_new)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 rx_maybe_restart(sp, hregs, sregs);
415}
416
417static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
418 struct sgiseeq_regs *sregs)
419{
420 if (sp->is_edlc) {
421 sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
422 sregs->rw.wregs.control = sp->control;
423 }
424}
425
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100426static inline void kick_tx(struct net_device *dev,
427 struct sgiseeq_private *sp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 struct hpc3_ethregs *hregs)
429{
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100430 struct sgiseeq_tx_desc *td;
431 int i = sp->tx_old;
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 /* If the HPC aint doin nothin, and there are more packets
434 * with ETXD cleared and XIU set we must make very certain
435 * that we restart the HPC else we risk locking up the
436 * adapter. The following code is only safe iff the HPCDMA
437 * is not active!
438 */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100439 td = &sp->tx_desc[i];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100440 dma_sync_desc_cpu(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100442 (HPCDMA_XIU | HPCDMA_ETXD)) {
443 i = NEXT_TX(i);
444 td = &sp->tx_desc[i];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100445 dma_sync_desc_cpu(dev, td);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 if (td->tdma.cntinfo & HPCDMA_XIU) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100448 hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
450 }
451}
452
453static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
454 struct hpc3_ethregs *hregs,
455 struct sgiseeq_regs *sregs)
456{
457 struct sgiseeq_tx_desc *td;
458 unsigned long status = hregs->tx_ctrl;
459 int j;
460
461 tx_maybe_reset_collisions(sp, sregs);
462
463 if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
464 /* Oops, HPC detected some sort of error. */
465 if (status & SEEQ_TSTAT_R16)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700466 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (status & SEEQ_TSTAT_UFLOW)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700468 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (status & SEEQ_TSTAT_LCLS)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700470 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
473 /* Ack 'em... */
474 for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
475 td = &sp->tx_desc[j];
476
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100477 dma_sync_desc_cpu(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
479 break;
480 if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
481 if (!(status & HPC3_ETXCTRL_ACTIVE)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100482 hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
484 }
485 break;
486 }
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700487 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 sp->tx_old = NEXT_TX(sp->tx_old);
489 td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
490 td->tdma.cntinfo |= HPCDMA_EOX;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100491 if (td->skb) {
492 dev_kfree_skb_any(td->skb);
493 td->skb = NULL;
494 }
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100495 dma_sync_desc_dev(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497}
498
David Howells7d12e782006-10-05 14:55:46 +0100499static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 struct net_device *dev = (struct net_device *) dev_id;
502 struct sgiseeq_private *sp = netdev_priv(dev);
503 struct hpc3_ethregs *hregs = sp->hregs;
504 struct sgiseeq_regs *sregs = sp->sregs;
505
506 spin_lock(&sp->tx_lock);
507
508 /* Ack the IRQ and set software state. */
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100509 hregs->reset = HPC3_ERST_CLRIRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 /* Always check for received packets. */
512 sgiseeq_rx(dev, sp, hregs, sregs);
513
514 /* Only check for tx acks if we have something queued. */
515 if (sp->tx_old != sp->tx_new)
516 sgiseeq_tx(dev, sp, hregs, sregs);
517
518 if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
519 netif_wake_queue(dev);
520 }
521 spin_unlock(&sp->tx_lock);
522
523 return IRQ_HANDLED;
524}
525
526static int sgiseeq_open(struct net_device *dev)
527{
528 struct sgiseeq_private *sp = netdev_priv(dev);
529 struct sgiseeq_regs *sregs = sp->sregs;
530 unsigned int irq = dev->irq;
531 int err;
532
533 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
534 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
Nicolas Kaiser06d6e6d2010-10-26 10:02:13 -0700535 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
537
538 err = init_seeq(dev, sp, sregs);
539 if (err)
540 goto out_free_irq;
541
542 netif_start_queue(dev);
543
544 return 0;
545
546out_free_irq:
547 free_irq(irq, dev);
548
549 return err;
550}
551
552static int sgiseeq_close(struct net_device *dev)
553{
554 struct sgiseeq_private *sp = netdev_priv(dev);
555 struct sgiseeq_regs *sregs = sp->sregs;
Ralf Baechle28914392005-10-10 14:50:51 +0100556 unsigned int irq = dev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 netif_stop_queue(dev);
559
560 /* Shutdown the Seeq. */
561 reset_hpc3_and_seeq(sp->hregs, sregs);
Ralf Baechle28914392005-10-10 14:50:51 +0100562 free_irq(irq, dev);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100563 seeq_purge_ring(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 return 0;
566}
567
568static inline int sgiseeq_reset(struct net_device *dev)
569{
570 struct sgiseeq_private *sp = netdev_priv(dev);
571 struct sgiseeq_regs *sregs = sp->sregs;
572 int err;
573
574 err = init_seeq(dev, sp, sregs);
575 if (err)
576 return err;
577
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700578 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 netif_wake_queue(dev);
580
581 return 0;
582}
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
585{
586 struct sgiseeq_private *sp = netdev_priv(dev);
587 struct hpc3_ethregs *hregs = sp->hregs;
588 unsigned long flags;
589 struct sgiseeq_tx_desc *td;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100590 int len, entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 spin_lock_irqsave(&sp->tx_lock, flags);
593
594 /* Setup... */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100595 len = skb->len;
596 if (len < ETH_ZLEN) {
Julia Lawallce6fbde2010-03-29 05:35:05 +0000597 if (skb_padto(skb, ETH_ZLEN)) {
598 spin_unlock_irqrestore(&sp->tx_lock, flags);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000599 return NETDEV_TX_OK;
Julia Lawallce6fbde2010-03-29 05:35:05 +0000600 }
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100601 len = ETH_ZLEN;
602 }
603
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700604 dev->stats.tx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 entry = sp->tx_new;
606 td = &sp->tx_desc[entry];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100607 dma_sync_desc_cpu(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 /* Create entry. There are so many races with adding a new
610 * descriptor to the chain:
611 * 1) Assume that the HPC is off processing a DMA chain while
612 * we are changing all of the following.
613 * 2) Do no allow the HPC to look at a new descriptor until
614 * we have completely set up it's state. This means, do
615 * not clear HPCDMA_EOX in the current last descritptor
616 * until the one we are adding looks consistent and could
617 * be processes right now.
618 * 3) The tx interrupt code must notice when we've added a new
619 * entry and the HPC got to the end of the chain before we
620 * added this new entry and restarted it.
621 */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100622 td->skb = skb;
623 td->tdma.pbuf = dma_map_single(dev->dev.parent, skb->data,
624 len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 td->tdma.cntinfo = (len & HPCDMA_BCNT) |
626 HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100627 dma_sync_desc_dev(dev, td);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (sp->tx_old != sp->tx_new) {
629 struct sgiseeq_tx_desc *backend;
630
631 backend = &sp->tx_desc[PREV_TX(sp->tx_new)];
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100632 dma_sync_desc_cpu(dev, backend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 backend->tdma.cntinfo &= ~HPCDMA_EOX;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100634 dma_sync_desc_dev(dev, backend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636 sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
637
638 /* Maybe kick the HPC back into motion. */
639 if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100640 kick_tx(dev, sp, hregs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (!TX_BUFFS_AVAIL(sp))
643 netif_stop_queue(dev);
644 spin_unlock_irqrestore(&sp->tx_lock, flags);
645
Patrick McHardy6ed10652009-06-23 06:03:08 +0000646 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
649static void timeout(struct net_device *dev)
650{
651 printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
652 sgiseeq_reset(dev);
653
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700654 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 netif_wake_queue(dev);
656}
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658static void sgiseeq_set_multicast(struct net_device *dev)
659{
Wang Chen8f15ea42008-11-12 23:38:36 -0800660 struct sgiseeq_private *sp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 unsigned char oldmode = sp->mode;
662
663 if(dev->flags & IFF_PROMISC)
664 sp->mode = SEEQ_RCMD_RANY;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000665 else if ((dev->flags & IFF_ALLMULTI) || !netdev_mc_empty(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 sp->mode = SEEQ_RCMD_RBMCAST;
667 else
668 sp->mode = SEEQ_RCMD_RBCAST;
669
670 /* XXX I know this sucks, but is there a better way to reprogram
671 * XXX the receiver? At least, this shouldn't happen too often.
672 */
673
674 if (oldmode != sp->mode)
675 sgiseeq_reset(dev);
676}
677
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100678static inline void setup_tx_ring(struct net_device *dev,
679 struct sgiseeq_tx_desc *buf,
680 int nbufs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100682 struct sgiseeq_private *sp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 int i = 0;
684
685 while (i < (nbufs - 1)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100686 buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf + i + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 buf[i].tdma.pbuf = 0;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100688 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 i++;
690 }
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100691 buf[i].tdma.pnext = VIRT_TO_DMA(sp, buf);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100692 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100695static inline void setup_rx_ring(struct net_device *dev,
696 struct sgiseeq_rx_desc *buf,
697 int nbufs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100699 struct sgiseeq_private *sp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 int i = 0;
701
702 while (i < (nbufs - 1)) {
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100703 buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf + i + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 buf[i].rdma.pbuf = 0;
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100705 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 i++;
707 }
708 buf[i].rdma.pbuf = 0;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100709 buf[i].rdma.pnext = VIRT_TO_DMA(sp, buf);
Thomas Bogendoerfer49b11bc2007-12-19 13:42:36 +0100710 dma_sync_desc_dev(dev, &buf[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
Alexander Beregalov8c2c6be2009-04-15 12:52:58 +0000713static const struct net_device_ops sgiseeq_netdev_ops = {
714 .ndo_open = sgiseeq_open,
715 .ndo_stop = sgiseeq_close,
716 .ndo_start_xmit = sgiseeq_start_xmit,
717 .ndo_tx_timeout = timeout,
718 .ndo_set_multicast_list = sgiseeq_set_multicast,
719 .ndo_set_mac_address = sgiseeq_set_mac_address,
720 .ndo_change_mtu = eth_change_mtu,
721 .ndo_validate_addr = eth_validate_addr,
722};
723
Uwe Kleine-Königa65a6882009-07-21 11:25:26 +0000724static int __devinit sgiseeq_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Ralf Baechledf9f5402007-05-11 15:48:58 +0100726 struct sgiseeq_platform_data *pd = pdev->dev.platform_data;
727 struct hpc3_regs *hpcregs = pd->hpc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 struct sgiseeq_init_block *sr;
Ralf Baechledf9f5402007-05-11 15:48:58 +0100729 unsigned int irq = pd->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 struct sgiseeq_private *sp;
731 struct net_device *dev;
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100732 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 dev = alloc_etherdev(sizeof (struct sgiseeq_private));
735 if (!dev) {
736 printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n");
737 err = -ENOMEM;
738 goto err_out;
739 }
Ralf Baechledf9f5402007-05-11 15:48:58 +0100740
741 platform_set_drvdata(pdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 sp = netdev_priv(dev);
743
744 /* Make private data page aligned */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100745 sr = dma_alloc_noncoherent(&pdev->dev, sizeof(*sp->srings),
Ralf Baechle99cd1492007-09-04 14:41:01 +0100746 &sp->srings_dma, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 if (!sr) {
748 printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
749 err = -ENOMEM;
750 goto err_out_free_dev;
751 }
752 sp->srings = sr;
Ralf Baechle99cd1492007-09-04 14:41:01 +0100753 sp->rx_desc = sp->srings->rxvector;
754 sp->tx_desc = sp->srings->txvector;
755
756 /* A couple calculations now, saves many cycles later. */
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100757 setup_rx_ring(dev, sp->rx_desc, SEEQ_RX_BUFFERS);
758 setup_tx_ring(dev, sp->tx_desc, SEEQ_TX_BUFFERS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Ralf Baechledf9f5402007-05-11 15:48:58 +0100760 memcpy(dev->dev_addr, pd->mac, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762#ifdef DEBUG
763 gpriv = sp;
764 gdev = dev;
765#endif
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100766 sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
767 sp->hregs = &hpcregs->ethregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 sp->name = sgiseeqstr;
769 sp->mode = SEEQ_RCMD_RBCAST;
770
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100771 /* Setup PIO and DMA transfer timing */
772 sp->hregs->pconfig = 0x161;
773 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
774 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
775
Ladislav Michl78ee5b32007-02-28 01:18:35 +0000776 /* Setup PIO and DMA transfer timing */
777 sp->hregs->pconfig = 0x161;
778 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
779 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 /* Reset the chip. */
782 hpc3_eth_reset(sp->hregs);
783
784 sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
785 if (sp->is_edlc)
786 sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
787 SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
788 SEEQ_CTRL_ENCARR;
789
Alexander Beregalov8c2c6be2009-04-15 12:52:58 +0000790 dev->netdev_ops = &sgiseeq_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 dev->watchdog_timeo = (200 * HZ) / 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 dev->irq = irq;
793
794 if (register_netdev(dev)) {
795 printk(KERN_ERR "Sgiseeq: Cannot register net device, "
796 "aborting.\n");
797 err = -ENODEV;
798 goto err_out_free_page;
799 }
800
Johannes Berge1749612008-10-27 15:59:26 -0700801 printk(KERN_INFO "%s: %s %pM\n", dev->name, sgiseeqstr, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return 0;
804
805err_out_free_page:
Ralf Baechle28914392005-10-10 14:50:51 +0100806 free_page((unsigned long) sp->srings);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807err_out_free_dev:
Kulikov Vasiliy8d879de2010-09-25 23:58:06 +0000808 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810err_out:
811 return err;
812}
813
Ralf Baechlee3efb052007-08-22 16:03:52 +0100814static int __exit sgiseeq_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Ralf Baechledf9f5402007-05-11 15:48:58 +0100816 struct net_device *dev = platform_get_drvdata(pdev);
817 struct sgiseeq_private *sp = netdev_priv(dev);
Ladislav Michl78ee5b32007-02-28 01:18:35 +0000818
Ralf Baechledf9f5402007-05-11 15:48:58 +0100819 unregister_netdev(dev);
Thomas Bogendoerfer43831b12007-11-24 13:29:19 +0100820 dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
821 sp->srings_dma);
Ralf Baechledf9f5402007-05-11 15:48:58 +0100822 free_netdev(dev);
823 platform_set_drvdata(pdev, NULL);
Ralf Baechlee3efb052007-08-22 16:03:52 +0100824
825 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
Ralf Baechledf9f5402007-05-11 15:48:58 +0100828static struct platform_driver sgiseeq_driver = {
829 .probe = sgiseeq_probe,
Uwe Kleine-Königfb74c2f2009-09-30 22:28:26 +0000830 .remove = __exit_p(sgiseeq_remove),
Ralf Baechledf9f5402007-05-11 15:48:58 +0100831 .driver = {
Kay Sievers72abb462008-04-18 13:50:44 -0700832 .name = "sgiseeq",
833 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
Ralf Baechledf9f5402007-05-11 15:48:58 +0100835};
836
837static int __init sgiseeq_module_init(void)
838{
839 if (platform_driver_register(&sgiseeq_driver)) {
840 printk(KERN_ERR "Driver registration failed\n");
841 return -ENODEV;
842 }
843
844 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
Ralf Baechledf9f5402007-05-11 15:48:58 +0100847static void __exit sgiseeq_module_exit(void)
848{
849 platform_driver_unregister(&sgiseeq_driver);
850}
851
852module_init(sgiseeq_module_init);
853module_exit(sgiseeq_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Ralf Baechle302a5c4b2005-10-10 14:50:56 +0100855MODULE_DESCRIPTION("SGI Seeq 8003 driver");
856MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857MODULE_LICENSE("GPL");
Kay Sievers72abb462008-04-18 13:50:44 -0700858MODULE_ALIAS("platform:sgiseeq");