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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [rcpci45.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
**
3
**  RCpci45.c
4
**
5
**
6
**
7
**  ---------------------------------------------------------------------
8
**  ---     Copyright (c) 1998, 1999, RedCreek Communications Inc.    ---
9
**  ---                   All rights reserved.                        ---
10
**  ---------------------------------------------------------------------
11
**
12
** Written by Pete Popov and Brian Moyle.
13
**
14
** Known Problems
15
**
16
** None known at this time.
17
**
18
**  TODO:
19
**      -Get rid of the wait loops in the API and replace them
20
**       with system independent delays ...something like
21
**       "delayms(2)".  However, under normal circumstances, the
22
**       delays are very short so they're not a problem.
23
**
24
**  This program is free software; you can redistribute it and/or modify
25
**  it under the terms of the GNU General Public License as published by
26
**  the Free Software Foundation; either version 2 of the License, or
27
**  (at your option) any later version.
28
 
29
**  This program is distributed in the hope that it will be useful,
30
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
31
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
**  GNU General Public License for more details.
33
 
34
**  You should have received a copy of the GNU General Public License
35
**  along with this program; if not, write to the Free Software
36
**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37
**
38
**
39
**  Pete Popov, January 11,99: Fixed a couple of 2.1.x problems
40
**  (virt_to_bus() not called), tested it under 2.2pre5 (as a module), and
41
**  added a #define(s) to enable the use of the same file for both, the 2.0.x
42
**  kernels as well as the 2.1.x.
43
**
44
**  Ported to 2.1.x by Alan Cox 1998/12/9.
45
**
46
**  Sometime in mid 1998, written by Pete Popov and Brian Moyle.
47
**
48
***************************************************************************/
49
 
50
static char *version =
51
"RedCreek Communications PCI linux driver version 2.02\n";
52
 
53
 
54
#include <linux/module.h>
55
#include <linux/version.h>
56
#include <linux/kernel.h>
57
#include <linux/sched.h>
58
#include <linux/string.h>
59
#include <linux/ptrace.h>
60
#include <linux/errno.h>
61
#include <linux/in.h>
62
#include <linux/ioport.h>
63
#include <linux/malloc.h>
64
#include <linux/interrupt.h>
65
#include <linux/pci.h>
66
#include <linux/bios32.h>
67
#include <linux/timer.h>
68
#include <asm/irq.h>            /* For NR_IRQS only. */
69
#include <asm/bitops.h>
70
#include <asm/io.h>
71
 
72
#if LINUX_VERSION_CODE >= 0x020100
73
#define LINUX_2_1
74
#endif
75
 
76
#ifdef LINUX_2_1
77
#include <asm/uaccess.h>
78
#endif
79
 
80
#include <linux/if_ether.h>
81
#include <linux/netdevice.h>
82
#include <linux/etherdevice.h>
83
#include <linux/skbuff.h>
84
 
85
 
86
#define RC_LINUX_MODULE
87
#include "rclanmtl.h"
88
#include "rcif.h"
89
 
90
#define RUN_AT(x) (jiffies + (x))
91
 
92
#define NEW_MULTICAST
93
#include <linux/delay.h>
94
 
95
#ifndef LINUX_2_1
96
#define ioremap vremap
97
#define iounmap vfree
98
#endif
99
 
100
/* PCI/45 Configuration space values */
101
#define RC_PCI45_VENDOR_ID  0x4916
102
#define RC_PCI45_DEVICE_ID  0x1960
103
 
104
#define MAX_ETHER_SIZE        1520  
105
#define MAX_NMBR_RCV_BUFFERS    96
106
#define RC_POSTED_BUFFERS_LOW_MARK MAX_NMBR_RCV_BUFFERS-16
107
#define BD_SIZE 3           /* Bucket Descriptor size */
108
#define BD_LEN_OFFSET 2     /* Bucket Descriptor offset to length field */
109
 
110
 
111
/* RedCreek LAN device Target ID */
112
#define RC_LAN_TARGET_ID  0x10 
113
/* RedCreek's OSM default LAN receive Initiator */
114
#define DEFAULT_RECV_INIT_CONTEXT  0xA17  
115
 
116
 
117
static U32 DriverControlWord =  0;
118
 
119
static void rc_timer(unsigned long);
120
 
121
/*
122
 * Driver Private Area, DPA.
123
 */
124
typedef struct
125
{
126
 
127
    /*
128
     *    pointer to the device structure which is part
129
     * of the interface to the Linux kernel.
130
     */
131
    struct device *dev;
132
 
133
    char devname[8];                /* "ethN" string */
134
    U8     id;                        /* the AdapterID */
135
    U32    pci_addr;               /* the pci address of the adapter */
136
    U32    bus;
137
    U32    function;
138
    struct timer_list timer;        /*  timer */
139
    struct enet_statistics  stats; /* the statistics structure */
140
    struct device *next;            /* points to the next RC adapter */
141
    unsigned long numOutRcvBuffers;/* number of outstanding receive buffers*/
142
    unsigned char shutdown;
143
    unsigned char reboot;
144
    unsigned char nexus;
145
    PU8    PLanApiPA;             /* Pointer to Lan Api Private Area */
146
 
147
}
148
DPA, *PDPA;
149
 
150
#define MAX_ADAPTERS 32
151
 
152
static PDPA  PCIAdapters[MAX_ADAPTERS] =
153
{
154
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
155
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
156
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
157
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
158
};
159
 
160
 
161
static int RCinit(struct device *dev);
162
static int RCscan(struct device *dev);
163
static int RCfound_device(struct device *, int, int, int, int, int, int);
164
 
165
static int RCopen(struct device *);
166
static int RC_xmit_packet(struct sk_buff *, struct device *);
167
static void RCinterrupt(int, void *, struct pt_regs *);
168
static int RCclose(struct device *dev);
169
static struct enet_statistics *RCget_stats(struct device *);
170
static int RCioctl(struct device *, struct ifreq *, int);
171
static int RCconfig(struct device *, struct ifmap *);
172
static void RCxmit_callback(U32, U16, PU32, U16);
173
static void RCrecv_callback(U32, U8, U32, PU32, U16);
174
static void RCreset_callback(U32, U32, U32, U16);
175
static void RCreboot_callback(U32, U32, U32, U16);
176
static int RC_allocate_and_post_buffers(struct device *, int);
177
 
178
 
179
/* A list of all installed RC devices, for removing the driver module. */
180
static struct device *root_RCdev = NULL;
181
 
182
#ifdef MODULE
183
int init_module(void)
184
#else
185
int rcpci_probe(struct device *dev)
186
#endif
187
{
188
    int cards_found;
189
 
190
#ifdef MODULE
191
    cards_found = RCscan(NULL);
192
#else
193
    cards_found = RCscan(dev);
194
#endif
195
    if (cards_found)
196
        printk(version);
197
    return cards_found ? 0 : -ENODEV;
198
}
199
 
200
static int RCscan(struct device *dev)
201
{
202
    int cards_found = 0;
203
    static int pci_index = 0;
204
 
205
    if (!pcibios_present())
206
        return cards_found;
207
 
208
    for (;pci_index < 0x8; pci_index++)
209
    {
210
        unsigned char pci_bus, pci_device_fn;
211
        int scan_status;
212
        int board_index = 0;
213
        unsigned char pci_irq_line;
214
        unsigned short pci_command, vendor, device, class;
215
        unsigned int pci_ioaddr;
216
 
217
 
218
        scan_status =
219
            (pcibios_find_device (RC_PCI45_VENDOR_ID,
220
                                  RC_PCI45_DEVICE_ID,
221
                                  pci_index,
222
                                  &pci_bus,
223
                                  &pci_device_fn));
224
#ifdef RCDEBUG
225
        printk("rc scan_status = 0x%X\n", scan_status);
226
#endif
227
        if (scan_status != PCIBIOS_SUCCESSFUL)
228
            break;
229
        pcibios_read_config_word(pci_bus,
230
                                 pci_device_fn,
231
                                 PCI_VENDOR_ID, &vendor);
232
        pcibios_read_config_word(pci_bus,
233
                                 pci_device_fn,
234
                                 PCI_DEVICE_ID, &device);
235
        pcibios_read_config_byte(pci_bus,
236
                                 pci_device_fn,
237
                                 PCI_INTERRUPT_LINE, &pci_irq_line);
238
        pcibios_read_config_dword(pci_bus,
239
                                  pci_device_fn,
240
                                  PCI_BASE_ADDRESS_0, &pci_ioaddr);
241
        pcibios_read_config_word(pci_bus,
242
                                 pci_device_fn,
243
                                 PCI_CLASS_DEVICE, &class);
244
 
245
        pci_ioaddr &= ~0xf;
246
 
247
#ifdef RCDEBUG
248
        printk("rc: Found RedCreek PCI adapter\n");
249
        printk("rc: pci class = 0x%x  0x%x \n", class, class>>8);
250
        printk("rc: pci_bus = %d,  pci_device_fn = %d\n", pci_bus, pci_device_fn);
251
        printk("rc: pci_irq_line = 0x%x \n", pci_irq_line);
252
        printk("rc: pci_ioaddr = 0x%x\n", pci_ioaddr);
253
#endif
254
 
255
        if (check_region(pci_ioaddr, 2*32768))
256
        {
257
            printk("rc: check_region failed\n");
258
            continue;
259
        }
260
#ifdef RCDEBUG
261
        else
262
        {
263
            printk("rc: check_region passed\n");
264
        }
265
#endif
266
 
267
        /*
268
         * Get and check the bus-master and latency values.
269
         * Some PCI BIOSes fail to set the master-enable bit.
270
         */
271
 
272
        pcibios_read_config_word(pci_bus,
273
                                 pci_device_fn,
274
                                 PCI_COMMAND,
275
                                 &pci_command);
276
        if ( ! (pci_command & PCI_COMMAND_MASTER)) {
277
            printk("rc: PCI Master Bit has not been set!\n");
278
 
279
            pci_command |= PCI_COMMAND_MASTER;
280
            pcibios_write_config_word(pci_bus,
281
                                      pci_device_fn,
282
                                      PCI_COMMAND,
283
                                      pci_command);
284
        }
285
        if ( ! (pci_command & PCI_COMMAND_MEMORY)) {
286
            /*
287
             * If the BIOS did not set the memory enable bit, what else
288
             * did it not initialize?  Skip this adapter.
289
             */
290
            printk("rc: Adapter %d, PCI Memory Bit has not been set!\n",
291
                   cards_found);
292
            printk("rc: Bios problem? \n");
293
            continue;
294
        }
295
 
296
        if (!RCfound_device(dev, pci_ioaddr, pci_irq_line,
297
                          pci_bus, pci_device_fn,
298
                          board_index++, cards_found))
299
        {
300
            dev = 0;
301
            cards_found++;
302
        }
303
    }
304
#ifdef RCDEBUG
305
    printk("rc: found %d cards \n", cards_found);
306
#endif
307
    return cards_found;
308
}
309
 
310
static int RCinit(struct device *dev)
311
{
312
    dev->open = &RCopen;
313
    dev->hard_start_xmit = &RC_xmit_packet;
314
    dev->stop = &RCclose;
315
    dev->get_stats = &RCget_stats;
316
    dev->do_ioctl = &RCioctl;
317
    dev->set_config = &RCconfig;
318
    return 0;
319
}
320
 
321
static int
322
RCfound_device(struct device *dev, int memaddr, int irq,
323
               int bus, int function, int product_index, int card_idx)
324
{
325
    int dev_size = 32768;
326
    unsigned long *vaddr=0;
327
    PDPA pDpa;
328
    int init_status;
329
 
330
    /*
331
     * Allocate and fill new device structure.
332
     * We need enough for struct device plus DPA plus the LAN API private
333
     * area, which requires a minimum of 16KB.  The top of the allocated
334
     * area will be assigned to struct device; the next chunk will be
335
     * assigned to DPA; and finally, the rest will be assigned to the
336
     * the LAN API layer.
337
     */
338
 
339
#ifdef MODULE
340
    dev = (struct device *) kmalloc(dev_size, GFP_DMA | GFP_KERNEL |GFP_ATOMIC);
341
    if (!dev)
342
    {
343
        printk("rc: unable to kmalloc dev\n");
344
        return 1;
345
    }
346
    memset(dev, 0, dev_size);
347
    /*
348
     * dev->priv will point to the start of DPA.
349
     */
350
    dev->priv = (void *)(((long)dev + sizeof(struct device) + 15) & ~15);
351
#else
352
    dev->priv = 0;
353
    dev->priv = (struct device *) kmalloc(dev_size, GFP_DMA | GFP_KERNEL |GFP_ATOMIC);
354
    if (!dev->priv)
355
    {
356
        printk("rc: unable to kmalloc private area\n");
357
        return 1;
358
    }
359
    memset(dev->priv, 0, dev_size);
360
#endif
361
 
362
#ifdef RCDEBUG
363
    printk("rc: dev = 0x%x, dev->priv = 0x%x\n", (uint)dev, (uint)dev->priv);
364
#endif
365
 
366
    pDpa = dev->priv;
367
    if (!dev->name)
368
        dev->name = pDpa->devname;
369
 
370
    pDpa->dev = dev;            /* this is just for easy reference */
371
    pDpa->function = function;
372
    pDpa->bus = bus;
373
    pDpa->id = card_idx;        /* the device number */
374
    pDpa->pci_addr = memaddr;
375
    PCIAdapters[card_idx] = pDpa;
376
#ifdef RCDEBUG
377
    printk("rc: pDpa = 0x%x, id = %d \n", (uint)pDpa, (uint)pDpa->id);
378
#endif
379
 
380
    /*
381
     * Save the starting address of the LAN API private area.  We'll
382
     * pass that to RCInitI2OMsgLayer().
383
     */
384
    pDpa->PLanApiPA = (void *)(((long)pDpa + sizeof(DPA) + 0xff) & ~0xff);
385
#ifdef RCDEBUG
386
    printk("rc: pDpa->PLanApiPA = 0x%x\n", (uint)pDpa->PLanApiPA);
387
#endif
388
 
389
    /* The adapter is accessable through memory-access read/write, not
390
     * I/O read/write.  Thus, we need to map it to some virtual address
391
     * area in order to access the registers are normal memory.
392
     */
393
    vaddr = (ulong *) ioremap (memaddr, 2*32768);
394
#ifdef RCDEBUG
395
    printk("rc: RCfound_device: 0x%x, priv = 0x%x, vaddr = 0x%x\n",
396
           (uint)dev, (uint)dev->priv, (uint)vaddr);
397
#endif
398
    dev->base_addr = (unsigned long)vaddr;
399
    dev->irq = irq;
400
    dev->interrupt = 0;
401
 
402
    /*
403
     * Request a shared interrupt line.
404
     */
405
    if ( request_irq(dev->irq, (void *)RCinterrupt,
406
                     SA_INTERRUPT|SA_SHIRQ, "RedCreek VPN Adapter", dev) )
407
    {
408
        printk( "RC PCI 45: %s: unable to get IRQ %d\n", (PU8)dev->name, (uint)dev->irq );
409
        iounmap(vaddr);
410
        kfree(dev);
411
        return 1;
412
    }
413
 
414
    init_status = RCInitI2OMsgLayer(pDpa->id, dev->base_addr,
415
                  pDpa->PLanApiPA, (PU8)virt_to_bus((void *)pDpa->PLanApiPA),
416
                  (PFNTXCALLBACK)RCxmit_callback,
417
                  (PFNRXCALLBACK)RCrecv_callback,
418
                  (PFNCALLBACK)RCreboot_callback);
419
    if (init_status)
420
    {
421
        printk("rc: Unable to initialize msg layer\n");
422
        free_irq(dev->irq, dev);
423
        iounmap(vaddr);
424
        kfree(dev);
425
        return 1;
426
    }
427
    if (RCGetMAC(pDpa->id, dev->dev_addr, NULL))
428
    {
429
        printk("rc: Unable to get adapter MAC\n");
430
        free_irq(dev->irq, dev);
431
        iounmap(vaddr);
432
        kfree(dev);
433
        return 1;
434
    }
435
 
436
    DriverControlWord |= WARM_REBOOT_CAPABLE;
437
    RCReportDriverCapability(pDpa->id, DriverControlWord);
438
 
439
    dev->init = &RCinit;
440
    ether_setup(dev);            /* linux kernel interface */
441
 
442
    pDpa->next = root_RCdev;
443
    root_RCdev = dev;
444
 
445
#ifdef MODULE
446
    if (register_netdev(dev) != 0) /* linux kernel interface */
447
    {
448
        printk("rc: unable to register device \n");
449
        free_irq(dev->irq, dev);
450
        iounmap(vaddr);
451
        kfree(dev);
452
        return 1;
453
    }
454
#else
455
    RCinit(dev);
456
#endif
457
    printk("%s: RedCreek Communications IPSEC VPN adapter\n",
458
        dev->name);
459
 
460
    return 0; /* success */
461
}
462
 
463
static int
464
RCopen(struct device *dev)
465
{
466
    int post_buffers = MAX_NMBR_RCV_BUFFERS;
467
    PDPA pDpa = (PDPA) dev->priv;
468
    int count = 0;
469
    int requested = 0;
470
 
471
#ifdef RCDEBUG
472
    printk("rc: RCopen\n");
473
#endif
474
    RCEnableI2OInterrupts(pDpa->id);
475
 
476
    if (pDpa->nexus)
477
    {
478
        /* This is not the first time RCopen is called.  Thus,
479
         * the interface was previously opened and later closed
480
         * by RCclose().  RCclose() does a Shutdown; to wake up
481
         * the adapter, a reset is mandatory before we can post
482
         * receive buffers.  However, if the adapter initiated
483
         * a reboot while the interface was closed -- and interrupts
484
         * were turned off -- we need will need to reinitialize
485
         * the adapter, rather than simply waking it up.
486
         */
487
        printk("rc: Waking up adapter...\n");
488
        RCResetLANCard(pDpa->id,0,0,0);
489
    }
490
    else
491
    {
492
        pDpa->nexus = 1;
493
    }
494
 
495
    while(post_buffers)
496
    {
497
        if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
498
            requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
499
        else
500
            requested = post_buffers;
501
        count = RC_allocate_and_post_buffers(dev, requested);
502
 
503
        if ( count < requested )
504
        {
505
            /*
506
             * Check to see if we were able to post any buffers at all.
507
             */
508
            if (post_buffers == MAX_NMBR_RCV_BUFFERS)
509
            {
510
                printk("rc: Error RCopen: not able to allocate any buffers\r\n");
511
                return(-ENOMEM);
512
            }
513
            printk("rc: Warning RCopen: not able to allocate all requested buffers\r\n");
514
            break;            /* we'll try to post more buffers later */
515
        }
516
        else
517
            post_buffers -= count;
518
    }
519
    pDpa->numOutRcvBuffers = MAX_NMBR_RCV_BUFFERS - post_buffers;
520
    pDpa->shutdown = 0;        /* just in case */
521
#ifdef RCDEBUG
522
    printk("rc: RCopen: posted %d buffers\n", (uint)pDpa->numOutRcvBuffers);
523
#endif
524
    MOD_INC_USE_COUNT;
525
    return 0;
526
}
527
 
528
static int
529
RC_xmit_packet(struct sk_buff *skb, struct device *dev)
530
{
531
 
532
    PDPA pDpa = (PDPA) dev->priv;
533
    singleTCB tcb;
534
    psingleTCB ptcb = &tcb;
535
    RC_RETURN status = 0;
536
 
537
        if (dev->tbusy || pDpa->shutdown || pDpa->reboot)
538
        {
539
#ifdef RCDEBUG
540
            printk("rc: RC_xmit_packet: tbusy!\n");
541
#endif
542
            dev->tbusy = 1;
543
            return 1;
544
        }
545
 
546
    if ( skb->len <= 0 )
547
    {
548
        printk("RC_xmit_packet: skb->len less than 0!\n");
549
        return 0;
550
    }
551
 
552
    /*
553
     * The user is free to reuse the TCB after RCI2OSendPacket() returns, since
554
     * the function copies the necessary info into its own private space.  Thus,
555
     * our TCB can be a local structure.  The skb, on the other hand, will be
556
     * freed up in our interrupt handler.
557
     */
558
    ptcb->bcount = 1;
559
    /*
560
     * we'll get the context when the adapter interrupts us to tell us that
561
     * the transmision is done. At that time, we can free skb.
562
     */
563
    ptcb->b.context = (U32)skb;
564
    ptcb->b.scount = 1;
565
    ptcb->b.size = skb->len;
566
    ptcb->b.addr = virt_to_bus((void *)skb->data);
567
 
568
#ifdef RCDEBUG
569
    printk("rc: RC xmit: skb = 0x%x, pDpa = 0x%x, id = %d, ptcb = 0x%x\n",
570
           (uint)skb, (uint)pDpa, (uint)pDpa->id, (uint)ptcb);
571
#endif
572
    if ( (status = RCI2OSendPacket(pDpa->id, (U32)NULL, (PRCTCB)ptcb))
573
         != RC_RTN_NO_ERROR)
574
    {
575
#ifdef RCDEBUG
576
        printk("rc: RC send error 0x%x\n", (uint)status);
577
#endif
578
        dev->tbusy = 1;
579
        return 1;
580
    }
581
    else
582
    {
583
        dev->trans_start = jiffies;
584
        //       dev->tbusy = 0;
585
    }
586
    /*
587
     * That's it!
588
     */
589
    return 0;
590
}
591
 
592
/*
593
 * RCxmit_callback()
594
 *
595
 * The transmit callback routine. It's called by RCProcI2OMsgQ()
596
 * because the adapter is done with one or more transmit buffers and
597
 * it's returning them to us, or we asked the adapter to return the
598
 * outstanding transmit buffers by calling RCResetLANCard() with
599
 * RC_RESOURCE_RETURN_PEND_TX_BUFFERS flag.
600
 * All we need to do is free the buffers.
601
 */
602
static void
603
RCxmit_callback(U32 Status,
604
                U16 PcktCount,
605
                PU32 BufferContext,
606
                U16 AdapterID)
607
{
608
    struct sk_buff *skb;
609
    PDPA pDpa;
610
    struct device *dev;
611
 
612
        pDpa = PCIAdapters[AdapterID];
613
        if (!pDpa)
614
        {
615
            printk("rc: Fatal error: xmit callback, !pDpa\n");
616
            return;
617
        }
618
        dev = pDpa->dev;
619
 
620
        // printk("xmit_callback: Status = 0x%x\n", (uint)Status);
621
        if (Status != I2O_REPLY_STATUS_SUCCESS)
622
        {
623
            printk("rc: xmit_callback: Status = 0x%x\n", (uint)Status);
624
        }
625
#ifdef RCDEBUG
626
        if (pDpa->shutdown || pDpa->reboot)
627
            printk("rc: xmit callback: shutdown||reboot\n");
628
#endif
629
 
630
#ifdef RCDEBUG     
631
        printk("rc: xmit_callback: PcktCount = %d, BC = 0x%x\n",
632
               (uint)PcktCount, (uint)BufferContext);
633
#endif
634
        while (PcktCount--)
635
        {
636
            skb = (struct sk_buff *)(BufferContext[0]);
637
#ifdef RCDEBUG
638
            printk("rc: skb = 0x%x\n", (uint)skb);
639
#endif
640
            BufferContext++;
641
#ifdef LINUX_2_1
642
            dev_kfree_skb (skb);
643
#else
644
            dev_kfree_skb (skb, FREE_WRITE);
645
#endif
646
        }
647
        dev->tbusy = 0;
648
 
649
}
650
 
651
static void
652
RCreset_callback(U32 Status, U32 p1, U32 p2, U16 AdapterID)
653
{
654
    PDPA pDpa;
655
    struct device *dev;
656
 
657
    pDpa = PCIAdapters[AdapterID];
658
    dev = pDpa->dev;
659
#ifdef RCDEBUG
660
    printk("rc: RCreset_callback Status 0x%x\n", (uint)Status);
661
#endif
662
    /*
663
     * Check to see why we were called.
664
     */
665
    if (pDpa->shutdown)
666
    {
667
        printk("rc: Shutting down interface\n");
668
        pDpa->shutdown = 0;
669
        pDpa->reboot = 0;
670
        MOD_DEC_USE_COUNT;
671
    }
672
    else if (pDpa->reboot)
673
    {
674
        printk("rc: reboot, shutdown adapter\n");
675
        /*
676
         * We don't set any of the flags in RCShutdownLANCard()
677
         * and we don't pass a callback routine to it.
678
         * The adapter will have already initiated the reboot by
679
         * the time the function returns.
680
         */
681
        RCDisableI2OInterrupts(pDpa->id);
682
        RCShutdownLANCard(pDpa->id,0,0,0);
683
        printk("rc: scheduling timer...\n");
684
        init_timer(&pDpa->timer);
685
        pDpa->timer.expires = RUN_AT((40*HZ)/10); /* 4 sec. */
686
        pDpa->timer.data = (unsigned long)dev;
687
        pDpa->timer.function = &rc_timer;    /* timer handler */
688
        add_timer(&pDpa->timer);
689
    }
690
 
691
 
692
 
693
}
694
 
695
static void
696
RCreboot_callback(U32 Status, U32 p1, U32 p2, U16 AdapterID)
697
{
698
    PDPA pDpa;
699
 
700
    pDpa = PCIAdapters[AdapterID];
701
#ifdef RCDEBUG
702
    printk("rc: RCreboot: rcv buffers outstanding = %d\n",
703
           (uint)pDpa->numOutRcvBuffers);
704
#endif
705
    if (pDpa->shutdown)
706
    {
707
        printk("rc: skipping reboot sequence -- shutdown already initiated\n");
708
        return;
709
    }
710
    pDpa->reboot = 1;
711
    /*
712
     * OK, we reset the adapter and ask it to return all
713
     * outstanding transmit buffers as well as the posted
714
     * receive buffers.  When the adapter is done returning
715
     * those buffers, it will call our RCreset_callback()
716
     * routine.  In that routine, we'll call RCShutdownLANCard()
717
     * to tell the adapter that it's OK to start the reboot and
718
     * schedule a timer callback routine to execute 3 seconds
719
     * later; this routine will reinitialize the adapter at that time.
720
     */
721
    RCResetLANCard(pDpa->id,
722
                   RC_RESOURCE_RETURN_POSTED_RX_BUCKETS |
723
                   RC_RESOURCE_RETURN_PEND_TX_BUFFERS,0,
724
                   (PFNCALLBACK)RCreset_callback);
725
}
726
 
727
 
728
int broadcast_packet(unsigned char * address)
729
{
730
    int i;
731
    for (i=0; i<6; i++)
732
        if (address[i] != 0xff) return 0;
733
 
734
    return 1;
735
}
736
 
737
/*
738
 * RCrecv_callback()
739
 *
740
 * The receive packet callback routine.  This is called by
741
 * RCProcI2OMsgQ() after the adapter posts buffers which have been
742
 * filled (one ethernet packet per buffer).
743
 */
744
static void
745
RCrecv_callback(U32  Status,
746
                U8   PktCount,
747
                U32  BucketsRemain,
748
                PU32 PacketDescBlock,
749
                U16  AdapterID)
750
{
751
 
752
    U32 len, count;
753
    PDPA pDpa;
754
    struct sk_buff *skb;
755
    struct device *dev;
756
    singleTCB tcb;
757
    psingleTCB ptcb = &tcb;
758
 
759
 
760
        pDpa = PCIAdapters[AdapterID];
761
        dev = pDpa->dev;
762
 
763
        ptcb->bcount = 1;
764
 
765
#ifdef RCDEBUG
766
        printk("rc: RCrecv_callback: 0x%x, 0x%x, 0x%x\n",
767
               (uint)PktCount, (uint)BucketsRemain, (uint)PacketDescBlock);
768
#endif
769
 
770
#ifdef RCDEBUG
771
        if ((pDpa->shutdown || pDpa->reboot) && !Status)
772
            printk("shutdown||reboot && !Status: PktCount = %d\n",PktCount);
773
#endif
774
 
775
        if ( (Status != I2O_REPLY_STATUS_SUCCESS) || pDpa->shutdown)
776
        {
777
            /*
778
             * Free whatever buffers the adapter returned, but don't
779
             * pass them to the kernel.
780
             */
781
 
782
                if (!pDpa->shutdown && !pDpa->reboot)
783
                    printk("rc: RCrecv error: status = 0x%x\n", (uint)Status);
784
#ifdef RCDEBUG
785
                else
786
                    printk("rc: Returning %d buffers, status = 0x%x\n",
787
                           PktCount, (uint)Status);
788
#endif
789
            /*
790
             * TO DO: check the nature of the failure and put the adapter in
791
             * failed mode if it's a hard failure.  Send a reset to the adapter
792
             * and free all outstanding memory.
793
             */
794
            if (Status == I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER)
795
            {
796
#ifdef RCDEBUG
797
                printk("RCrecv status ABORT NO DATA TRANSFER\n");
798
#endif
799
            }
800
            /* check for reset status: I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER */
801
            if (PacketDescBlock)
802
            {
803
                while(PktCount--)
804
                {
805
                    skb = (struct sk_buff *)PacketDescBlock[0];
806
#ifndef LINUX_2_1
807
                    skb->free = 1;
808
                    skb->lock = 0;
809
#endif
810
#ifdef RCDEBUG
811
                    printk("free skb 0x%p\n", skb);
812
#endif
813
#ifdef LINUX_2_1
814
                    dev_kfree_skb (skb);
815
#else
816
                    dev_kfree_skb(skb, FREE_READ);
817
#endif
818
                    pDpa->numOutRcvBuffers--;
819
                    PacketDescBlock += BD_SIZE; /* point to next context field */
820
                }
821
            }
822
            return;
823
        }
824
        else
825
        {
826
            while(PktCount--)
827
            {
828
                skb = (struct sk_buff *)PacketDescBlock[0];
829
#ifdef RCDEBUG
830
                if (pDpa->shutdown)
831
                    printk("shutdown: skb=0x%x\n", (uint)skb);
832
 
833
                printk("skb = 0x%x: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", (uint)skb,
834
                       (uint)skb->data[0], (uint)skb->data[1], (uint)skb->data[2],
835
                       (uint)skb->data[3], (uint)skb->data[4], (uint)skb->data[5]);
836
#endif
837
 
838
#ifdef PROMISCUOUS_BY_DEFAULT   /* early 2.x firmware */
839
                if ( (memcmp(dev->dev_addr, skb->data, 6)) &&
840
                     (!broadcast_packet(skb->data)))
841
                {
842
                    /*
843
                     * Re-post the buffer to the adapter.  Since the adapter usually
844
                     * return 1 to 2 receive buffers at a time, it's not too inefficient
845
                     * post one buffer at a time but ... may be that should be
846
                     * optimized at some point.
847
                     */
848
                    ptcb->b.context = (U32)skb;
849
                    ptcb->b.scount = 1;
850
                    ptcb->b.size = MAX_ETHER_SIZE;
851
                    ptcb->b.addr = virt_to_bus((void *)skb->data);
852
 
853
                    if ( RCPostRecvBuffers(pDpa->id, (PRCTCB)ptcb ) != RC_RTN_NO_ERROR)
854
                    {
855
                        printk("rc: RCrecv_callback: post buffer failed!\n");
856
#ifdef LINUX_2_1
857
                        dev_kfree_skb (skb);
858
#else
859
                        skb->free = 1;
860
                        dev_kfree_skb(skb, FREE_READ);
861
#endif
862
                    }
863
                    else
864
                    {
865
                        pDpa->numOutRcvBuffers++;
866
                    }
867
                }
868
                else
869
#endif /* PROMISCUOUS_BY_DEFAULT */
870
                {
871
                    len = PacketDescBlock[2];
872
                    skb->dev = dev;
873
                    skb_put( skb, len ); /* adjust length and tail */
874
                    skb->protocol = eth_type_trans(skb, dev);
875
                    netif_rx(skb);    /* send the packet to the kernel */
876
                    dev->last_rx = jiffies;
877
                }
878
                pDpa->numOutRcvBuffers--;
879
                PacketDescBlock += BD_SIZE; /* point to next context field */
880
            }
881
        }
882
 
883
        /*
884
         * Replenish the posted receive buffers.
885
         * DO NOT replenish buffers if the driver has already
886
         * initiated a reboot or shutdown!
887
         */
888
 
889
        if (!pDpa->shutdown && !pDpa->reboot)
890
        {
891
            count = RC_allocate_and_post_buffers(dev,
892
                                                 MAX_NMBR_RCV_BUFFERS-pDpa->numOutRcvBuffers);
893
            pDpa->numOutRcvBuffers += count;
894
        }
895
 
896
}
897
 
898
/*
899
 * RCinterrupt()
900
 *
901
 * Interrupt handler.
902
 * This routine sets up a couple of pointers and calls
903
 * RCProcI2OMsgQ(), which in turn process the message and
904
 * calls one of our callback functions.
905
 */
906
static void
907
RCinterrupt(int irq, void *dev_id, struct pt_regs *regs)
908
{
909
 
910
    PDPA pDpa;
911
    struct device *dev = (struct device *)(dev_id);
912
 
913
    pDpa = (PDPA) (dev->priv);
914
 
915
#ifdef RCDEBUG
916
    if (pDpa->shutdown)
917
        printk("rc: shutdown: service irq\n");
918
 
919
    printk("RC irq: pDpa = 0x%x, dev = 0x%x, id = %d\n",
920
           (uint)pDpa, (uint)dev, (uint)pDpa->id);
921
    printk("dev = 0x%x\n", (uint)dev);
922
#endif
923
    if (dev->interrupt)
924
        printk("%s: Re-entering the interrupt handler.\n", dev->name);
925
    dev->interrupt = 1;
926
 
927
    RCProcI2OMsgQ(pDpa->id);
928
    dev->interrupt = 0;
929
 
930
    return;
931
}
932
 
933
 
934
#define REBOOT_REINIT_RETRY_LIMIT 4
935
static void rc_timer(unsigned long data)
936
{
937
    struct device *dev = (struct device *)data;
938
    PDPA pDpa = (PDPA) (dev->priv);
939
    int init_status;
940
    static int retry = 0;
941
    int post_buffers = MAX_NMBR_RCV_BUFFERS;
942
    int count = 0;
943
    int requested = 0;
944
 
945
    if (pDpa->reboot)
946
    {
947
        init_status = RCInitI2OMsgLayer(pDpa->id, dev->base_addr,
948
                                    pDpa->PLanApiPA,
949
                                    (PU8)virt_to_bus((void *)pDpa->PLanApiPA),
950
                                    (PFNTXCALLBACK)RCxmit_callback,
951
                                    (PFNRXCALLBACK)RCrecv_callback,
952
                                    (PFNCALLBACK)RCreboot_callback);
953
 
954
        switch(init_status)
955
        {
956
        case RC_RTN_NO_ERROR:
957
 
958
            pDpa->reboot = 0;
959
            pDpa->shutdown = 0;        /* just in case */
960
            RCReportDriverCapability(pDpa->id, DriverControlWord);
961
            RCEnableI2OInterrupts(pDpa->id);
962
 
963
            if (dev->flags & IFF_UP)
964
            {
965
                while(post_buffers)
966
                {
967
                    if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
968
                        requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
969
                    else
970
                        requested = post_buffers;
971
                    count = RC_allocate_and_post_buffers(dev, requested);
972
                    post_buffers -= count;
973
                    if ( count < requested )
974
                        break;
975
                }
976
                pDpa->numOutRcvBuffers =
977
                    MAX_NMBR_RCV_BUFFERS - post_buffers;
978
                printk("rc: posted %d buffers \r\n",
979
                       (uint)pDpa->numOutRcvBuffers);
980
            }
981
            printk("rc: Initialization done.\n");
982
            dev->tbusy=0;
983
            retry=0;
984
            return;
985
        case RC_RTN_FREE_Q_EMPTY:
986
            retry++;
987
            printk("rc: inbound free q empty\n");
988
            break;
989
        default:
990
            retry++;
991
            printk("rc: bad status after reboot: %d\n", init_status);
992
            break;
993
        }
994
 
995
        if (retry > REBOOT_REINIT_RETRY_LIMIT)
996
        {
997
            printk("rc: unable to reinitialize adapter after reboot\n");
998
            printk("rc: decrementing driver and closing interface\n");
999
            RCDisableI2OInterrupts(pDpa->id);
1000
            dev->flags &= ~IFF_UP;
1001
            MOD_DEC_USE_COUNT;
1002
        }
1003
        else
1004
        {
1005
            printk("rc: rescheduling timer...\n");
1006
            init_timer(&pDpa->timer);
1007
            pDpa->timer.expires = RUN_AT((40*HZ)/10); /* 3 sec. */
1008
            pDpa->timer.data = (unsigned long)dev;
1009
            pDpa->timer.function = &rc_timer;    /* timer handler */
1010
            add_timer(&pDpa->timer);
1011
        }
1012
    }
1013
    else
1014
    {
1015
        printk("rc: timer??\n");
1016
    }
1017
}
1018
 
1019
static int
1020
RCclose(struct device *dev)
1021
{
1022
 
1023
    PDPA pDpa = (PDPA) dev->priv;
1024
 
1025
#ifdef RCDEBUG
1026
    printk("rc: RCclose\r\n");
1027
#endif
1028
    if (pDpa->reboot)
1029
    {
1030
        printk("rc: skipping reset -- adapter already in reboot mode\n");
1031
        dev->flags &= ~IFF_UP;
1032
        pDpa->shutdown = 1;
1033
        return 0;
1034
    }
1035
#ifdef RCDEBUG
1036
    printk("rc: receive buffers outstanding: %d\n",
1037
           (uint)pDpa->numOutRcvBuffers);
1038
#endif
1039
 
1040
    pDpa->shutdown = 1;
1041
 
1042
    /*
1043
     * We can't allow the driver to be unloaded until the adapter returns
1044
     * all posted receive buffers.  It doesn't hurt to tell the adapter
1045
     * to return all posted receive buffers and outstanding xmit buffers,
1046
     * even if there are none.
1047
     */
1048
 
1049
    RCShutdownLANCard(pDpa->id,
1050
                      RC_RESOURCE_RETURN_POSTED_RX_BUCKETS |
1051
                      RC_RESOURCE_RETURN_PEND_TX_BUFFERS,0,
1052
                      (PFNCALLBACK)RCreset_callback);
1053
 
1054
        dev->flags &= ~IFF_UP;
1055
    return 0;
1056
}
1057
 
1058
static struct enet_statistics *
1059
RCget_stats(struct device *dev)
1060
{
1061
    RCLINKSTATS    RCstats;
1062
 
1063
    PDPA pDpa = dev->priv;
1064
 
1065
    if (!pDpa)
1066
    {
1067
        printk("rc: RCget_stats: !pDpa\n");
1068
        return 0;
1069
    }
1070
    else if (!(dev->flags & IFF_UP))
1071
    {
1072
#ifdef RCDEBUG
1073
        printk("rc: RCget_stats: device down\n");
1074
#endif
1075
        return 0;
1076
    }
1077
 
1078
    memset(&RCstats, 0, sizeof(RCLINKSTATS));
1079
    if ( (RCGetLinkStatistics(pDpa->id, &RCstats, (void *)0)) == RC_RTN_NO_ERROR )
1080
    {
1081
#ifdef RCDEBUG
1082
        printk("rc: TX_good 0x%x\n", (uint)RCstats.TX_good);
1083
        printk("rc: TX_maxcol 0x%x\n", (uint)RCstats.TX_maxcol);
1084
        printk("rc: TX_latecol 0x%x\n", (uint)RCstats.TX_latecol);
1085
        printk("rc: TX_urun 0x%x\n", (uint)RCstats.TX_urun);
1086
        printk("rc: TX_crs 0x%x\n", (uint)RCstats.TX_crs);
1087
        printk("rc: TX_def 0x%x\n", (uint)RCstats.TX_def);
1088
        printk("rc: TX_singlecol 0x%x\n", (uint)RCstats.TX_singlecol);
1089
        printk("rc: TX_multcol 0x%x\n", (uint)RCstats.TX_multcol);
1090
        printk("rc: TX_totcol 0x%x\n", (uint)RCstats.TX_totcol);
1091
 
1092
        printk("rc: Rcv_good 0x%x\n", (uint)RCstats.Rcv_good);
1093
        printk("rc: Rcv_CRCerr 0x%x\n", (uint)RCstats.Rcv_CRCerr);
1094
        printk("rc: Rcv_alignerr 0x%x\n", (uint)RCstats.Rcv_alignerr);
1095
        printk("rc: Rcv_reserr 0x%x\n", (uint)RCstats.Rcv_reserr);
1096
        printk("rc: Rcv_orun 0x%x\n", (uint)RCstats.Rcv_orun);
1097
        printk("rc: Rcv_cdt 0x%x\n", (uint)RCstats.Rcv_cdt);
1098
        printk("rc: Rcv_runt 0x%x\n", (uint)RCstats.Rcv_runt);
1099
#endif
1100
 
1101
        pDpa->stats.rx_packets = RCstats.Rcv_good; /* total packets received    */
1102
        pDpa->stats.tx_packets = RCstats.TX_good; /* total packets transmitted    */
1103
 
1104
        pDpa->stats.rx_errors =
1105
            RCstats.Rcv_CRCerr +
1106
            RCstats.Rcv_alignerr +
1107
            RCstats.Rcv_reserr +
1108
            RCstats.Rcv_orun +
1109
            RCstats.Rcv_cdt +
1110
            RCstats.Rcv_runt; /* bad packets received        */
1111
 
1112
        pDpa->stats.tx_errors =
1113
            RCstats.TX_urun +
1114
            RCstats.TX_crs +
1115
            RCstats.TX_def +
1116
            RCstats.TX_totcol; /* packet transmit problems    */
1117
 
1118
        /*
1119
         * This needs improvement.
1120
         */
1121
        pDpa->stats.rx_dropped = 0;        /* no space in linux buffers    */
1122
        pDpa->stats.tx_dropped = 0;        /* no space available in linux    */
1123
        pDpa->stats.multicast = 0;        /* multicast packets received    */
1124
        pDpa->stats.collisions = RCstats.TX_totcol;
1125
 
1126
        /* detailed rx_errors: */
1127
        pDpa->stats.rx_length_errors = 0;
1128
        pDpa->stats.rx_over_errors = RCstats.Rcv_orun; /* receiver ring buff overflow    */
1129
        pDpa->stats.rx_crc_errors = RCstats.Rcv_CRCerr;    /* recved pkt with crc error    */
1130
        pDpa->stats.rx_frame_errors = 0; /* recv'd frame alignment error */
1131
        pDpa->stats.rx_fifo_errors = 0; /* recv'r fifo overrun        */
1132
        pDpa->stats.rx_missed_errors = 0; /* receiver missed packet    */
1133
 
1134
        /* detailed tx_errors */
1135
        pDpa->stats.tx_aborted_errors = 0;
1136
        pDpa->stats.tx_carrier_errors = 0;
1137
        pDpa->stats.tx_fifo_errors = 0;
1138
        pDpa->stats.tx_heartbeat_errors = 0;
1139
        pDpa->stats.tx_window_errors = 0;
1140
 
1141
        return ((struct enet_statistics *)&(pDpa->stats));
1142
    }
1143
    return 0;
1144
}
1145
 
1146
static int RCioctl(struct device *dev, struct ifreq *rq, int cmd)
1147
{
1148
    RCuser_struct RCuser;
1149
    PDPA pDpa = dev->priv;
1150
 
1151
#if RCDEBUG
1152
    printk("RCioctl: cmd = 0x%x\n", cmd);
1153
#endif
1154
 
1155
    switch (cmd)  {
1156
 
1157
    case RCU_PROTOCOL_REV:
1158
        /*
1159
         * Assign user protocol revision, to tell user-level
1160
         * controller program whether or not it's in sync.
1161
         */
1162
        rq->ifr_ifru.ifru_data = (caddr_t) USER_PROTOCOL_REV;
1163
        break;
1164
 
1165
 
1166
    case RCU_COMMAND:
1167
    {
1168
#ifdef LINUX_2_1
1169
        if(copy_from_user(&RCuser, rq->ifr_data, sizeof(RCuser)))
1170
             return -EFAULT;
1171
#else
1172
        int error;
1173
        error=verify_area(VERIFY_WRITE, rq->ifr_data, sizeof(RCuser));
1174
        if (error)  {
1175
            return error;
1176
        }
1177
        memcpy_fromfs(&RCuser, rq->ifr_data, sizeof(RCuser));
1178
#endif
1179
 
1180
#ifdef RCDEBUG
1181
        printk("RCioctl: RCuser_cmd = 0x%x\n", RCuser.cmd);
1182
#endif
1183
 
1184
        switch(RCuser.cmd)
1185
        {
1186
        case RCUC_GETFWVER:
1187
            printk("RC GETFWVER\n");
1188
            RCUD_GETFWVER = &RCuser.RCUS_GETFWVER;
1189
            RCGetFirmwareVer(pDpa->id, (PU8) &RCUD_GETFWVER->FirmString, NULL);
1190
            break;
1191
        case RCUC_GETINFO:
1192
            printk("RC GETINFO\n");
1193
            RCUD_GETINFO = &RCuser.RCUS_GETINFO;
1194
            RCUD_GETINFO -> mem_start = dev->base_addr;
1195
            RCUD_GETINFO -> mem_end = dev->base_addr + 2*32768;
1196
            RCUD_GETINFO -> base_addr = pDpa->pci_addr;
1197
            RCUD_GETINFO -> irq = dev->irq;
1198
            break;
1199
        case RCUC_GETIPANDMASK:
1200
            printk("RC GETIPANDMASK\n");
1201
            RCUD_GETIPANDMASK = &RCuser.RCUS_GETIPANDMASK;
1202
            RCGetRavlinIPandMask(pDpa->id, (PU32) &RCUD_GETIPANDMASK->IpAddr,
1203
                                 (PU32) &RCUD_GETIPANDMASK->NetMask, NULL);
1204
            break;
1205
        case RCUC_GETLINKSTATISTICS:
1206
            printk("RC GETLINKSTATISTICS\n");
1207
            RCUD_GETLINKSTATISTICS = &RCuser.RCUS_GETLINKSTATISTICS;
1208
            RCGetLinkStatistics(pDpa->id, (P_RCLINKSTATS) &RCUD_GETLINKSTATISTICS->StatsReturn, NULL);
1209
            break;
1210
        case RCUC_GETLINKSTATUS:
1211
            printk("RC GETLINKSTATUS\n");
1212
            RCUD_GETLINKSTATUS = &RCuser.RCUS_GETLINKSTATUS;
1213
            RCGetLinkStatus(pDpa->id, (PU32) &RCUD_GETLINKSTATUS->ReturnStatus, NULL);
1214
            break;
1215
        case RCUC_GETMAC:
1216
            printk("RC GETMAC\n");
1217
            RCUD_GETMAC = &RCuser.RCUS_GETMAC;
1218
            RCGetMAC(pDpa->id, (PU8) &RCUD_GETMAC->mac, NULL);
1219
            break;
1220
        case RCUC_GETPROM:
1221
            printk("RC GETPROM\n");
1222
            RCUD_GETPROM = &RCuser.RCUS_GETPROM;
1223
            RCGetPromiscuousMode(pDpa->id, (PU32) &RCUD_GETPROM->PromMode, NULL);
1224
            break;
1225
        case RCUC_GETBROADCAST:
1226
            printk("RC GETBROADCAST\n");
1227
            RCUD_GETBROADCAST = &RCuser.RCUS_GETBROADCAST;
1228
            RCGetBroadcastMode(pDpa->id, (PU32) &RCUD_GETBROADCAST->BroadcastMode, NULL);
1229
            break;
1230
        case RCUC_GETSPEED:
1231
            printk("RC GETSPEED\n");
1232
            if (!(dev->flags & IFF_UP))
1233
            {
1234
                printk("RCioctl, GETSPEED error: interface down\n");
1235
                return -ENODATA;
1236
            }
1237
            RCUD_GETSPEED = &RCuser.RCUS_GETSPEED;
1238
            RCGetLinkSpeed(pDpa->id, (PU32) &RCUD_GETSPEED->LinkSpeedCode, NULL);
1239
            printk("RC speed = 0x%ld\n", RCUD_GETSPEED->LinkSpeedCode);
1240
            break;
1241
        case RCUC_SETIPANDMASK:
1242
            printk("RC SETIPANDMASK\n");
1243
            RCUD_SETIPANDMASK = &RCuser.RCUS_SETIPANDMASK;
1244
            printk ("RC New IP Addr = %d.%d.%d.%d, ", (U8) ((RCUD_SETIPANDMASK->IpAddr) & 0xff),
1245
                    (U8) ((RCUD_SETIPANDMASK->IpAddr >>  8) & 0xff),
1246
                    (U8) ((RCUD_SETIPANDMASK->IpAddr >> 16) & 0xff),
1247
                    (U8) ((RCUD_SETIPANDMASK->IpAddr >> 24) & 0xff));
1248
            printk ("RC New Mask = %d.%d.%d.%d\n", (U8) ((RCUD_SETIPANDMASK->NetMask) & 0xff),
1249
                    (U8) ((RCUD_SETIPANDMASK->NetMask >>  8) & 0xff),
1250
                    (U8) ((RCUD_SETIPANDMASK->NetMask >> 16) & 0xff),
1251
                    (U8) ((RCUD_SETIPANDMASK->NetMask >> 24) & 0xff));
1252
            RCSetRavlinIPandMask(pDpa->id, (U32) RCUD_SETIPANDMASK->IpAddr,
1253
                                 (U32) RCUD_SETIPANDMASK->NetMask);
1254
            break;
1255
        case RCUC_SETMAC:
1256
            printk("RC SETMAC\n");
1257
            RCUD_SETMAC = &RCuser.RCUS_SETMAC;
1258
            printk ("RC New MAC addr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1259
                    (U8) (RCUD_SETMAC->mac[0]), (U8) (RCUD_SETMAC->mac[1]), (U8) (RCUD_SETMAC->mac[2]),
1260
                    (U8) (RCUD_SETMAC->mac[3]), (U8) (RCUD_SETMAC->mac[4]), (U8) (RCUD_SETMAC->mac[5]));
1261
            RCSetMAC(pDpa->id, (PU8) &RCUD_SETMAC->mac);
1262
            break;
1263
        case RCUC_SETSPEED:
1264
            printk("RC SETSPEED\n");
1265
            RCUD_SETSPEED = &RCuser.RCUS_SETSPEED;
1266
            RCSetLinkSpeed(pDpa->id, (U16) RCUD_SETSPEED->LinkSpeedCode);
1267
            printk("RC New speed = 0x%d\n", RCUD_SETSPEED->LinkSpeedCode);
1268
            break;
1269
        case RCUC_SETPROM:
1270
            printk("RC SETPROM\n");
1271
            RCUD_SETPROM = &RCuser.RCUS_SETPROM;
1272
            RCSetPromiscuousMode(pDpa->id,(U16)RCUD_SETPROM->PromMode);
1273
            printk("RC New prom mode = 0x%d\n", RCUD_SETPROM->PromMode);
1274
            break;
1275
        case RCUC_SETBROADCAST:
1276
            printk("RC SETBROADCAST\n");
1277
            RCUD_SETBROADCAST = &RCuser.RCUS_SETBROADCAST;
1278
            RCSetBroadcastMode(pDpa->id,(U16)RCUD_SETBROADCAST->BroadcastMode);
1279
            printk("RC New broadcast mode = 0x%d\n", RCUD_SETBROADCAST->BroadcastMode);
1280
            break;
1281
        default:
1282
            printk("RC command default\n");
1283
            RCUD_DEFAULT = &RCuser.RCUS_DEFAULT;
1284
            RCUD_DEFAULT -> rc = 0x11223344;
1285
            break;
1286
        }
1287
#ifdef LINUX_2_1
1288
        copy_to_user(rq->ifr_data, &RCuser, sizeof(RCuser));
1289
#else
1290
        memcpy_tofs(rq->ifr_data, &RCuser, sizeof(RCuser));
1291
#endif
1292
        break;
1293
    }   /* RCU_COMMAND */
1294
 
1295
    default:
1296
        printk("RC default\n");
1297
        rq->ifr_ifru.ifru_data = (caddr_t) 0x12345678;
1298
        break;
1299
    }
1300
    return 0;
1301
}
1302
 
1303
static int RCconfig(struct device *dev, struct ifmap *map)
1304
{
1305
    /*
1306
     * To be completed ...
1307
      */
1308
    printk("rc: RCconfig\n");
1309
    return 0;
1310
    if (dev->flags & IFF_UP)    /* can't act on a running interface */
1311
        return -EBUSY;
1312
 
1313
     /* Don't allow changing the I/O address */
1314
    if (map->base_addr != dev->base_addr) {
1315
        printk(KERN_WARNING "RC pci45: Change I/O address not implemented\n");
1316
        return -EOPNOTSUPP;
1317
    }
1318
    return 0;
1319
}
1320
 
1321
 
1322
#ifdef MODULE
1323
void
1324
cleanup_module(void)
1325
{
1326
    PDPA pDpa;
1327
    struct device *next;
1328
 
1329
 
1330
#ifdef RCDEBUG
1331
    printk("rc: RC cleanup_module\n");
1332
    printk("rc: root_RCdev = 0x%x\n", (uint)root_RCdev);
1333
#endif
1334
 
1335
 
1336
    while (root_RCdev)
1337
    {
1338
        pDpa = (PDPA) root_RCdev->priv;
1339
#ifdef RCDEBUG
1340
        printk("rc: cleanup 0x%08X\n", (uint)root_RCdev);
1341
#endif
1342
        printk("IOP reset: 0x%x\n", RCResetIOP(pDpa->id));
1343
        unregister_netdev(root_RCdev);
1344
        next = pDpa->next;
1345
 
1346
        iounmap((unsigned long *)root_RCdev->base_addr);
1347
        free_irq( root_RCdev->irq, root_RCdev );
1348
        kfree(root_RCdev);
1349
        root_RCdev = next;
1350
    }
1351
}
1352
#endif
1353
 
1354
 
1355
static int
1356
RC_allocate_and_post_buffers(struct device *dev, int numBuffers)
1357
{
1358
 
1359
    int i;
1360
    PDPA pDpa = (PDPA)dev->priv;
1361
    PU32 p;
1362
    psingleB pB;
1363
    struct sk_buff *skb;
1364
    RC_RETURN status;
1365
 
1366
    if (!numBuffers)
1367
        return 0;
1368
    else if (numBuffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
1369
    {
1370
#ifdef RCDEBUG
1371
        printk("rc: Too many buffers requested!\n");
1372
        printk("rc: attempting to allocate only 32 buffers\n");
1373
#endif
1374
        numBuffers = 32;
1375
    }
1376
 
1377
    p = (PU32) kmalloc(sizeof(U32) + numBuffers*sizeof(singleB), GFP_ATOMIC);
1378
 
1379
#ifdef RCDEBUG
1380
    printk("rc: TCB = 0x%x\n", (uint)p);
1381
#endif
1382
 
1383
    if (!p)
1384
    {
1385
        printk("rc: RCopen: unable to allocate TCB\n");
1386
        return 0;
1387
    }
1388
 
1389
    p[0] = 0;                              /* Buffer Count */
1390
    pB = (psingleB)((U32)p + sizeof(U32)); /* point to the first buffer */
1391
 
1392
#ifdef RCDEBUG
1393
    printk("rc: p[0] = 0x%x, p = 0x%x, pB = 0x%x\n", (uint)p[0], (uint)p, (uint)pB);
1394
    printk("rc: pB = 0x%x\n", (uint)pB);
1395
#endif
1396
 
1397
    for (i=0; i<numBuffers; i++)
1398
    {
1399
        skb = dev_alloc_skb(MAX_ETHER_SIZE+2);
1400
        if (!skb)
1401
        {
1402
            printk("rc: Doh! RCopen: unable to allocate enough skbs!\n");
1403
            if (*p != 0)        /* did we allocate any buffers at all? */
1404
            {
1405
#ifdef RCDEBUG
1406
                printk("rc: will post only %d buffers \n", (uint)(*p));
1407
#endif
1408
                break;
1409
            }
1410
            else
1411
            {
1412
                kfree(p);    /* Free the TCB */
1413
                return 0;
1414
            }
1415
        }
1416
#ifdef RCDEBUG
1417
        printk("post 0x%x\n", (uint)skb);
1418
#endif
1419
        skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
1420
        pB->context = (U32)skb;
1421
        pB->scount = 1;        /* segment count */
1422
        pB->size = MAX_ETHER_SIZE;
1423
        pB->addr = virt_to_bus((void *)skb->data);
1424
        p[0]++;
1425
        pB++;
1426
    }
1427
 
1428
    if ( (status = RCPostRecvBuffers(pDpa->id, (PRCTCB)p )) != RC_RTN_NO_ERROR)
1429
    {
1430
        printk("rc: Post buffer failed with error code 0x%x!\n", status);
1431
        pB = (psingleB)((U32)p + sizeof(U32)); /* point to the first buffer */
1432
        while(p[0])
1433
        {
1434
            skb = (struct sk_buff *)pB->context;
1435
#ifndef LINUX_2_1
1436
            skb->free = 1;
1437
#endif
1438
#ifdef RCDEBUG
1439
            printk("rc: freeing 0x%x\n", (uint)skb);
1440
#endif
1441
#ifdef LINUX_2_1
1442
            dev_kfree_skb (skb);
1443
#else
1444
            dev_kfree_skb(skb, FREE_READ);
1445
#endif
1446
            p[0]--;
1447
            pB++;
1448
        }
1449
#ifdef RCDEBUG
1450
        printk("rc: freed all buffers, p[0] = %ld\n", p[0]);
1451
#endif
1452
    }
1453
    kfree(p);
1454
    return(p[0]);                /* return the number of posted buffers */
1455
}

powered by: WebSVN 2.1.0

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