OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [sgiseeq.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.