7 ** ---------------------------------------------------------------------
8 ** --- Copyright (c) 1998, 1999, RedCreek Communications Inc. ---
9 ** --- All rights reserved. ---
10 ** ---------------------------------------------------------------------
12 ** Written by Pete Popov and Brian Moyle.
16 ** None known at this time.
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.
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.
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.
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.
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.
44 ** Ported to 2.1.x by Alan Cox 1998/12/9.
46 ** Sometime in mid 1998, written by Pete Popov and Brian Moyle.
48 ***************************************************************************/
50 static char *version
=
51 "RedCreek Communications PCI linux driver version 2.02\n";
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>
62 #include <linux/ioport.h>
63 #include <linux/malloc.h>
64 #include <linux/interrupt.h>
65 #include <linux/pci.h>
66 #include <linux/timer.h>
67 #include <asm/irq.h> /* For NR_IRQS only. */
68 #include <asm/bitops.h>
71 #if LINUX_VERSION_CODE >= 0x020100
76 #include <asm/uaccess.h>
79 #include <linux/if_ether.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
85 #define RC_LINUX_MODULE
89 #define RUN_AT(x) (jiffies + (x))
92 #include <linux/delay.h>
95 #define ioremap vremap
99 /* PCI/45 Configuration space values */
100 #define RC_PCI45_VENDOR_ID 0x4916
101 #define RC_PCI45_DEVICE_ID 0x1960
103 #define MAX_ETHER_SIZE 1520
104 #define MAX_NMBR_RCV_BUFFERS 96
105 #define RC_POSTED_BUFFERS_LOW_MARK MAX_NMBR_RCV_BUFFERS-16
106 #define BD_SIZE 3 /* Bucket Descriptor size */
107 #define BD_LEN_OFFSET 2 /* Bucket Descriptor offset to length field */
110 /* RedCreek LAN device Target ID */
111 #define RC_LAN_TARGET_ID 0x10
112 /* RedCreek's OSM default LAN receive Initiator */
113 #define DEFAULT_RECV_INIT_CONTEXT 0xA17
116 static U32 DriverControlWord
= 0;
118 static void rc_timer(unsigned long);
121 * Driver Private Area, DPA.
127 * pointer to the device structure which is part
128 * of the interface to the Linux kernel.
130 struct net_device
*dev
;
132 char devname
[8]; /* "ethN" string */
133 U8 id
; /* the AdapterID */
134 U32 pci_addr
; /* the pci address of the adapter */
137 struct timer_list timer
; /* timer */
138 struct enet_statistics stats
; /* the statistics structure */
139 struct net_device
*next
; /* points to the next RC adapter */
140 unsigned long numOutRcvBuffers
;/* number of outstanding receive buffers*/
141 unsigned char shutdown
;
142 unsigned char reboot
;
144 PU8 PLanApiPA
; /* Pointer to Lan Api Private Area */
149 #define MAX_ADAPTERS 32
151 static PDPA PCIAdapters
[MAX_ADAPTERS
] =
153 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
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
160 static int RCinit(struct net_device
*dev
);
161 static int RCscan(struct net_device
*dev
);
162 static int RCfound_device(struct net_device
*, int, int, int, int, int, int);
164 static int RCopen(struct net_device
*);
165 static int RC_xmit_packet(struct sk_buff
*, struct net_device
*);
166 static void RCinterrupt(int, void *, struct pt_regs
*);
167 static int RCclose(struct net_device
*dev
);
168 static struct enet_statistics
*RCget_stats(struct net_device
*);
169 static int RCioctl(struct net_device
*, struct ifreq
*, int);
170 static int RCconfig(struct net_device
*, struct ifmap
*);
171 static void RCxmit_callback(U32
, U16
, PU32
, U16
);
172 static void RCrecv_callback(U32
, U8
, U32
, PU32
, U16
);
173 static void RCreset_callback(U32
, U32
, U32
, U16
);
174 static void RCreboot_callback(U32
, U32
, U32
, U16
);
175 static int RC_allocate_and_post_buffers(struct net_device
*, int);
178 /* A list of all installed RC devices, for removing the driver module. */
179 static struct net_device
*root_RCdev
= NULL
;
182 int init_module(void)
184 int rcpci_probe(struct net_device
*dev
)
190 cards_found
= RCscan(NULL
);
192 cards_found
= RCscan(dev
);
196 return cards_found
? 0 : -ENODEV
;
199 static int RCscan(struct net_device
*dev
)
202 static int pci_index
= 0;
204 if (!pcibios_present())
207 for (;pci_index
< 0x8; pci_index
++)
209 unsigned char pci_bus
, pci_device_fn
;
212 unsigned char pci_irq_line
;
213 unsigned int pci_ioaddr
;
214 struct pci_dev
*pdev
;
217 (pcibios_find_device (RC_PCI45_VENDOR_ID
,
223 printk("rc scan_status = 0x%X\n", scan_status
);
225 if (scan_status
!= PCIBIOS_SUCCESSFUL
||
226 !((pdev
= pci_find_slot(pci_bus
, pci_device_fn
))))
228 pci_irq_line
= pdev
->irq
;
229 pci_ioaddr
= pdev
->resource
[0].start
;
232 printk("rc: Found RedCreek PCI adapter\n");
233 printk("rc: pci_bus = %d, pci_device_fn = %d\n", pci_bus
, pci_device_fn
);
234 printk("rc: pci_irq_line = 0x%x \n", pci_irq_line
);
235 printk("rc: pci_ioaddr = 0x%x\n", pci_ioaddr
);
238 pci_set_master(pdev
);
240 if (!RCfound_device(dev
, pci_ioaddr
, pci_irq_line
,
241 pci_bus
, pci_device_fn
,
242 board_index
++, cards_found
))
249 printk("rc: found %d cards \n", cards_found
);
254 static int RCinit(struct net_device
*dev
)
257 dev
->hard_start_xmit
= &RC_xmit_packet
;
258 dev
->stop
= &RCclose
;
259 dev
->get_stats
= &RCget_stats
;
260 dev
->do_ioctl
= &RCioctl
;
261 dev
->set_config
= &RCconfig
;
266 RCfound_device(struct net_device
*dev
, int memaddr
, int irq
,
267 int bus
, int function
, int product_index
, int card_idx
)
269 int dev_size
= 32768;
270 unsigned long *vaddr
=0;
275 * Allocate and fill new device structure.
276 * We need enough for struct net_device plus DPA plus the LAN API private
277 * area, which requires a minimum of 16KB. The top of the allocated
278 * area will be assigned to struct net_device; the next chunk will be
279 * assigned to DPA; and finally, the rest will be assigned to the
284 dev
= (struct net_device
*) kmalloc(dev_size
, GFP_DMA
| GFP_KERNEL
|GFP_ATOMIC
);
287 printk("rc: unable to kmalloc dev\n");
290 memset(dev
, 0, dev_size
);
292 * dev->priv will point to the start of DPA.
294 dev
->priv
= (void *)(((long)dev
+ sizeof(struct net_device
) + 15) & ~15);
297 dev
->priv
= (struct net_device
*) kmalloc(dev_size
, GFP_DMA
| GFP_KERNEL
|GFP_ATOMIC
);
300 printk("rc: unable to kmalloc private area\n");
303 memset(dev
->priv
, 0, dev_size
);
307 printk("rc: dev = 0x%x, dev->priv = 0x%x\n", (uint
)dev
, (uint
)dev
->priv
);
312 dev
->name
= pDpa
->devname
;
314 pDpa
->dev
= dev
; /* this is just for easy reference */
315 pDpa
->function
= function
;
317 pDpa
->id
= card_idx
; /* the device number */
318 pDpa
->pci_addr
= memaddr
;
319 PCIAdapters
[card_idx
] = pDpa
;
321 printk("rc: pDpa = 0x%x, id = %d \n", (uint
)pDpa
, (uint
)pDpa
->id
);
325 * Save the starting address of the LAN API private area. We'll
326 * pass that to RCInitI2OMsgLayer().
328 pDpa
->PLanApiPA
= (void *)(((long)pDpa
+ sizeof(DPA
) + 0xff) & ~0xff);
330 printk("rc: pDpa->PLanApiPA = 0x%x\n", (uint
)pDpa
->PLanApiPA
);
333 /* The adapter is accessable through memory-access read/write, not
334 * I/O read/write. Thus, we need to map it to some virtual address
335 * area in order to access the registers are normal memory.
337 vaddr
= (ulong
*) ioremap (memaddr
, 2*32768);
339 printk("rc: RCfound_device: 0x%x, priv = 0x%x, vaddr = 0x%x\n",
340 (uint
)dev
, (uint
)dev
->priv
, (uint
)vaddr
);
342 dev
->base_addr
= (unsigned long)vaddr
;
347 * Request a shared interrupt line.
349 if ( request_irq(dev
->irq
, (void *)RCinterrupt
,
350 SA_INTERRUPT
|SA_SHIRQ
, "RedCreek VPN Adapter", dev
) )
352 printk( "RC PCI 45: %s: unable to get IRQ %d\n", (PU8
)dev
->name
, (uint
)dev
->irq
);
358 init_status
= RCInitI2OMsgLayer(pDpa
->id
, dev
->base_addr
,
359 pDpa
->PLanApiPA
, (PU8
)virt_to_bus((void *)pDpa
->PLanApiPA
),
360 (PFNTXCALLBACK
)RCxmit_callback
,
361 (PFNRXCALLBACK
)RCrecv_callback
,
362 (PFNCALLBACK
)RCreboot_callback
);
365 printk("rc: Unable to initialize msg layer\n");
366 free_irq(dev
->irq
, dev
);
371 if (RCGetMAC(pDpa
->id
, dev
->dev_addr
, NULL
))
373 printk("rc: Unable to get adapter MAC\n");
374 free_irq(dev
->irq
, dev
);
380 DriverControlWord
|= WARM_REBOOT_CAPABLE
;
381 RCReportDriverCapability(pDpa
->id
, DriverControlWord
);
384 ether_setup(dev
); /* linux kernel interface */
386 pDpa
->next
= root_RCdev
;
390 if (register_netdev(dev
) != 0) /* linux kernel interface */
392 printk("rc: unable to register device \n");
393 free_irq(dev
->irq
, dev
);
401 printk("%s: RedCreek Communications IPSEC VPN adapter\n",
404 return 0; /* success */
408 RCopen(struct net_device
*dev
)
410 int post_buffers
= MAX_NMBR_RCV_BUFFERS
;
411 PDPA pDpa
= (PDPA
) dev
->priv
;
416 printk("rc: RCopen\n");
418 RCEnableI2OInterrupts(pDpa
->id
);
422 /* This is not the first time RCopen is called. Thus,
423 * the interface was previously opened and later closed
424 * by RCclose(). RCclose() does a Shutdown; to wake up
425 * the adapter, a reset is mandatory before we can post
426 * receive buffers. However, if the adapter initiated
427 * a reboot while the interface was closed -- and interrupts
428 * were turned off -- we need will need to reinitialize
429 * the adapter, rather than simply waking it up.
431 printk("rc: Waking up adapter...\n");
432 RCResetLANCard(pDpa
->id
,0,0,0);
441 if (post_buffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
442 requested
= MAX_NMBR_POST_BUFFERS_PER_MSG
;
444 requested
= post_buffers
;
445 count
= RC_allocate_and_post_buffers(dev
, requested
);
447 if ( count
< requested
)
450 * Check to see if we were able to post any buffers at all.
452 if (post_buffers
== MAX_NMBR_RCV_BUFFERS
)
454 printk("rc: Error RCopen: not able to allocate any buffers\r\n");
457 printk("rc: Warning RCopen: not able to allocate all requested buffers\r\n");
458 break; /* we'll try to post more buffers later */
461 post_buffers
-= count
;
463 pDpa
->numOutRcvBuffers
= MAX_NMBR_RCV_BUFFERS
- post_buffers
;
464 pDpa
->shutdown
= 0; /* just in case */
466 printk("rc: RCopen: posted %d buffers\n", (uint
)pDpa
->numOutRcvBuffers
);
473 RC_xmit_packet(struct sk_buff
*skb
, struct net_device
*dev
)
476 PDPA pDpa
= (PDPA
) dev
->priv
;
478 psingleTCB ptcb
= &tcb
;
479 RC_RETURN status
= 0;
481 if (dev
->tbusy
|| pDpa
->shutdown
|| pDpa
->reboot
)
484 printk("rc: RC_xmit_packet: tbusy!\n");
492 printk("RC_xmit_packet: skb->len less than 0!\n");
497 * The user is free to reuse the TCB after RCI2OSendPacket() returns, since
498 * the function copies the necessary info into its own private space. Thus,
499 * our TCB can be a local structure. The skb, on the other hand, will be
500 * freed up in our interrupt handler.
504 * we'll get the context when the adapter interrupts us to tell us that
505 * the transmision is done. At that time, we can free skb.
507 ptcb
->b
.context
= (U32
)skb
;
509 ptcb
->b
.size
= skb
->len
;
510 ptcb
->b
.addr
= virt_to_bus((void *)skb
->data
);
513 printk("rc: RC xmit: skb = 0x%x, pDpa = 0x%x, id = %d, ptcb = 0x%x\n",
514 (uint
)skb
, (uint
)pDpa
, (uint
)pDpa
->id
, (uint
)ptcb
);
516 if ( (status
= RCI2OSendPacket(pDpa
->id
, (U32
)NULL
, (PRCTCB
)ptcb
))
520 printk("rc: RC send error 0x%x\n", (uint
)status
);
527 dev
->trans_start
= jiffies
;
539 * The transmit callback routine. It's called by RCProcI2OMsgQ()
540 * because the adapter is done with one or more transmit buffers and
541 * it's returning them to us, or we asked the adapter to return the
542 * outstanding transmit buffers by calling RCResetLANCard() with
543 * RC_RESOURCE_RETURN_PEND_TX_BUFFERS flag.
544 * All we need to do is free the buffers.
547 RCxmit_callback(U32 Status
,
554 struct net_device
*dev
;
556 pDpa
= PCIAdapters
[AdapterID
];
559 printk("rc: Fatal error: xmit callback, !pDpa\n");
564 // printk("xmit_callback: Status = 0x%x\n", (uint)Status);
565 if (Status
!= I2O_REPLY_STATUS_SUCCESS
)
567 printk("rc: xmit_callback: Status = 0x%x\n", (uint
)Status
);
570 if (pDpa
->shutdown
|| pDpa
->reboot
)
571 printk("rc: xmit callback: shutdown||reboot\n");
575 printk("rc: xmit_callback: PcktCount = %d, BC = 0x%x\n",
576 (uint
)PcktCount
, (uint
)BufferContext
);
580 skb
= (struct sk_buff
*)(BufferContext
[0]);
582 printk("rc: skb = 0x%x\n", (uint
)skb
);
588 dev_kfree_skb (skb
, FREE_WRITE
);
596 RCreset_callback(U32 Status
, U32 p1
, U32 p2
, U16 AdapterID
)
599 struct net_device
*dev
;
601 pDpa
= PCIAdapters
[AdapterID
];
604 printk("rc: RCreset_callback Status 0x%x\n", (uint
)Status
);
607 * Check to see why we were called.
611 printk("rc: Shutting down interface\n");
616 else if (pDpa
->reboot
)
618 printk("rc: reboot, shutdown adapter\n");
620 * We don't set any of the flags in RCShutdownLANCard()
621 * and we don't pass a callback routine to it.
622 * The adapter will have already initiated the reboot by
623 * the time the function returns.
625 RCDisableI2OInterrupts(pDpa
->id
);
626 RCShutdownLANCard(pDpa
->id
,0,0,0);
627 printk("rc: scheduling timer...\n");
628 init_timer(&pDpa
->timer
);
629 pDpa
->timer
.expires
= RUN_AT((40*HZ
)/10); /* 4 sec. */
630 pDpa
->timer
.data
= (unsigned long)dev
;
631 pDpa
->timer
.function
= &rc_timer
; /* timer handler */
632 add_timer(&pDpa
->timer
);
640 RCreboot_callback(U32 Status
, U32 p1
, U32 p2
, U16 AdapterID
)
644 pDpa
= PCIAdapters
[AdapterID
];
646 printk("rc: RCreboot: rcv buffers outstanding = %d\n",
647 (uint
)pDpa
->numOutRcvBuffers
);
651 printk("rc: skipping reboot sequence -- shutdown already initiated\n");
656 * OK, we reset the adapter and ask it to return all
657 * outstanding transmit buffers as well as the posted
658 * receive buffers. When the adapter is done returning
659 * those buffers, it will call our RCreset_callback()
660 * routine. In that routine, we'll call RCShutdownLANCard()
661 * to tell the adapter that it's OK to start the reboot and
662 * schedule a timer callback routine to execute 3 seconds
663 * later; this routine will reinitialize the adapter at that time.
665 RCResetLANCard(pDpa
->id
,
666 RC_RESOURCE_RETURN_POSTED_RX_BUCKETS
|
667 RC_RESOURCE_RETURN_PEND_TX_BUFFERS
,0,
668 (PFNCALLBACK
)RCreset_callback
);
672 int broadcast_packet(unsigned char * address
)
676 if (address
[i
] != 0xff) return 0;
684 * The receive packet callback routine. This is called by
685 * RCProcI2OMsgQ() after the adapter posts buffers which have been
686 * filled (one ethernet packet per buffer).
689 RCrecv_callback(U32 Status
,
692 PU32 PacketDescBlock
,
699 struct net_device
*dev
;
701 psingleTCB ptcb
= &tcb
;
704 pDpa
= PCIAdapters
[AdapterID
];
710 printk("rc: RCrecv_callback: 0x%x, 0x%x, 0x%x\n",
711 (uint
)PktCount
, (uint
)BucketsRemain
, (uint
)PacketDescBlock
);
715 if ((pDpa
->shutdown
|| pDpa
->reboot
) && !Status
)
716 printk("shutdown||reboot && !Status: PktCount = %d\n",PktCount
);
719 if ( (Status
!= I2O_REPLY_STATUS_SUCCESS
) || pDpa
->shutdown
)
722 * Free whatever buffers the adapter returned, but don't
723 * pass them to the kernel.
726 if (!pDpa
->shutdown
&& !pDpa
->reboot
)
727 printk("rc: RCrecv error: status = 0x%x\n", (uint
)Status
);
730 printk("rc: Returning %d buffers, status = 0x%x\n",
731 PktCount
, (uint
)Status
);
734 * TO DO: check the nature of the failure and put the adapter in
735 * failed mode if it's a hard failure. Send a reset to the adapter
736 * and free all outstanding memory.
738 if (Status
== I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER
)
741 printk("RCrecv status ABORT NO DATA TRANSFER\n");
744 /* check for reset status: I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER */
749 skb
= (struct sk_buff
*)PacketDescBlock
[0];
755 printk("free skb 0x%p\n", skb
);
760 dev_kfree_skb(skb
, FREE_READ
);
762 pDpa
->numOutRcvBuffers
--;
763 PacketDescBlock
+= BD_SIZE
; /* point to next context field */
772 skb
= (struct sk_buff
*)PacketDescBlock
[0];
775 printk("shutdown: skb=0x%x\n", (uint
)skb
);
777 printk("skb = 0x%x: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", (uint
)skb
,
778 (uint
)skb
->data
[0], (uint
)skb
->data
[1], (uint
)skb
->data
[2],
779 (uint
)skb
->data
[3], (uint
)skb
->data
[4], (uint
)skb
->data
[5]);
782 #ifdef PROMISCUOUS_BY_DEFAULT /* early 2.x firmware */
783 if ( (memcmp(dev
->dev_addr
, skb
->data
, 6)) &&
784 (!broadcast_packet(skb
->data
)))
787 * Re-post the buffer to the adapter. Since the adapter usually
788 * return 1 to 2 receive buffers at a time, it's not too inefficient
789 * post one buffer at a time but ... may be that should be
790 * optimized at some point.
792 ptcb
->b
.context
= (U32
)skb
;
794 ptcb
->b
.size
= MAX_ETHER_SIZE
;
795 ptcb
->b
.addr
= virt_to_bus((void *)skb
->data
);
797 if ( RCPostRecvBuffers(pDpa
->id
, (PRCTCB
)ptcb
) != RC_RTN_NO_ERROR
)
799 printk("rc: RCrecv_callback: post buffer failed!\n");
804 dev_kfree_skb(skb
, FREE_READ
);
809 pDpa
->numOutRcvBuffers
++;
813 #endif /* PROMISCUOUS_BY_DEFAULT */
815 len
= PacketDescBlock
[2];
817 skb_put( skb
, len
); /* adjust length and tail */
818 skb
->protocol
= eth_type_trans(skb
, dev
);
819 netif_rx(skb
); /* send the packet to the kernel */
820 dev
->last_rx
= jiffies
;
822 pDpa
->numOutRcvBuffers
--;
823 PacketDescBlock
+= BD_SIZE
; /* point to next context field */
828 * Replenish the posted receive buffers.
829 * DO NOT replenish buffers if the driver has already
830 * initiated a reboot or shutdown!
833 if (!pDpa
->shutdown
&& !pDpa
->reboot
)
835 count
= RC_allocate_and_post_buffers(dev
,
836 MAX_NMBR_RCV_BUFFERS
-pDpa
->numOutRcvBuffers
);
837 pDpa
->numOutRcvBuffers
+= count
;
846 * This routine sets up a couple of pointers and calls
847 * RCProcI2OMsgQ(), which in turn process the message and
848 * calls one of our callback functions.
851 RCinterrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
855 struct net_device
*dev
= (struct net_device
*)(dev_id
);
857 pDpa
= (PDPA
) (dev
->priv
);
861 printk("rc: shutdown: service irq\n");
863 printk("RC irq: pDpa = 0x%x, dev = 0x%x, id = %d\n",
864 (uint
)pDpa
, (uint
)dev
, (uint
)pDpa
->id
);
865 printk("dev = 0x%x\n", (uint
)dev
);
868 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
871 RCProcI2OMsgQ(pDpa
->id
);
878 #define REBOOT_REINIT_RETRY_LIMIT 4
879 static void rc_timer(unsigned long data
)
881 struct net_device
*dev
= (struct net_device
*)data
;
882 PDPA pDpa
= (PDPA
) (dev
->priv
);
884 static int retry
= 0;
885 int post_buffers
= MAX_NMBR_RCV_BUFFERS
;
891 init_status
= RCInitI2OMsgLayer(pDpa
->id
, dev
->base_addr
,
893 (PU8
)virt_to_bus((void *)pDpa
->PLanApiPA
),
894 (PFNTXCALLBACK
)RCxmit_callback
,
895 (PFNRXCALLBACK
)RCrecv_callback
,
896 (PFNCALLBACK
)RCreboot_callback
);
900 case RC_RTN_NO_ERROR
:
903 pDpa
->shutdown
= 0; /* just in case */
904 RCReportDriverCapability(pDpa
->id
, DriverControlWord
);
905 RCEnableI2OInterrupts(pDpa
->id
);
907 if (dev
->flags
& IFF_UP
)
911 if (post_buffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
912 requested
= MAX_NMBR_POST_BUFFERS_PER_MSG
;
914 requested
= post_buffers
;
915 count
= RC_allocate_and_post_buffers(dev
, requested
);
916 post_buffers
-= count
;
917 if ( count
< requested
)
920 pDpa
->numOutRcvBuffers
=
921 MAX_NMBR_RCV_BUFFERS
- post_buffers
;
922 printk("rc: posted %d buffers \r\n",
923 (uint
)pDpa
->numOutRcvBuffers
);
925 printk("rc: Initialization done.\n");
929 case RC_RTN_FREE_Q_EMPTY
:
931 printk("rc: inbound free q empty\n");
935 printk("rc: bad status after reboot: %d\n", init_status
);
939 if (retry
> REBOOT_REINIT_RETRY_LIMIT
)
941 printk("rc: unable to reinitialize adapter after reboot\n");
942 printk("rc: decrementing driver and closing interface\n");
943 RCDisableI2OInterrupts(pDpa
->id
);
944 dev
->flags
&= ~IFF_UP
;
949 printk("rc: rescheduling timer...\n");
950 init_timer(&pDpa
->timer
);
951 pDpa
->timer
.expires
= RUN_AT((40*HZ
)/10); /* 3 sec. */
952 pDpa
->timer
.data
= (unsigned long)dev
;
953 pDpa
->timer
.function
= &rc_timer
; /* timer handler */
954 add_timer(&pDpa
->timer
);
959 printk("rc: timer??\n");
964 RCclose(struct net_device
*dev
)
967 PDPA pDpa
= (PDPA
) dev
->priv
;
970 printk("rc: RCclose\r\n");
974 printk("rc: skipping reset -- adapter already in reboot mode\n");
975 dev
->flags
&= ~IFF_UP
;
980 printk("rc: receive buffers outstanding: %d\n",
981 (uint
)pDpa
->numOutRcvBuffers
);
987 * We can't allow the driver to be unloaded until the adapter returns
988 * all posted receive buffers. It doesn't hurt to tell the adapter
989 * to return all posted receive buffers and outstanding xmit buffers,
990 * even if there are none.
993 RCShutdownLANCard(pDpa
->id
,
994 RC_RESOURCE_RETURN_POSTED_RX_BUCKETS
|
995 RC_RESOURCE_RETURN_PEND_TX_BUFFERS
,0,
996 (PFNCALLBACK
)RCreset_callback
);
998 dev
->flags
&= ~IFF_UP
;
1002 static struct enet_statistics
*
1003 RCget_stats(struct net_device
*dev
)
1005 RCLINKSTATS RCstats
;
1007 PDPA pDpa
= dev
->priv
;
1011 printk("rc: RCget_stats: !pDpa\n");
1014 else if (!(dev
->flags
& IFF_UP
))
1017 printk("rc: RCget_stats: device down\n");
1022 memset(&RCstats
, 0, sizeof(RCLINKSTATS
));
1023 if ( (RCGetLinkStatistics(pDpa
->id
, &RCstats
, (void *)0)) == RC_RTN_NO_ERROR
)
1026 printk("rc: TX_good 0x%x\n", (uint
)RCstats
.TX_good
);
1027 printk("rc: TX_maxcol 0x%x\n", (uint
)RCstats
.TX_maxcol
);
1028 printk("rc: TX_latecol 0x%x\n", (uint
)RCstats
.TX_latecol
);
1029 printk("rc: TX_urun 0x%x\n", (uint
)RCstats
.TX_urun
);
1030 printk("rc: TX_crs 0x%x\n", (uint
)RCstats
.TX_crs
);
1031 printk("rc: TX_def 0x%x\n", (uint
)RCstats
.TX_def
);
1032 printk("rc: TX_singlecol 0x%x\n", (uint
)RCstats
.TX_singlecol
);
1033 printk("rc: TX_multcol 0x%x\n", (uint
)RCstats
.TX_multcol
);
1034 printk("rc: TX_totcol 0x%x\n", (uint
)RCstats
.TX_totcol
);
1036 printk("rc: Rcv_good 0x%x\n", (uint
)RCstats
.Rcv_good
);
1037 printk("rc: Rcv_CRCerr 0x%x\n", (uint
)RCstats
.Rcv_CRCerr
);
1038 printk("rc: Rcv_alignerr 0x%x\n", (uint
)RCstats
.Rcv_alignerr
);
1039 printk("rc: Rcv_reserr 0x%x\n", (uint
)RCstats
.Rcv_reserr
);
1040 printk("rc: Rcv_orun 0x%x\n", (uint
)RCstats
.Rcv_orun
);
1041 printk("rc: Rcv_cdt 0x%x\n", (uint
)RCstats
.Rcv_cdt
);
1042 printk("rc: Rcv_runt 0x%x\n", (uint
)RCstats
.Rcv_runt
);
1045 pDpa
->stats
.rx_packets
= RCstats
.Rcv_good
; /* total packets received */
1046 pDpa
->stats
.tx_packets
= RCstats
.TX_good
; /* total packets transmitted */
1048 pDpa
->stats
.rx_errors
=
1049 RCstats
.Rcv_CRCerr
+
1050 RCstats
.Rcv_alignerr
+
1051 RCstats
.Rcv_reserr
+
1054 RCstats
.Rcv_runt
; /* bad packets received */
1056 pDpa
->stats
.tx_errors
=
1060 RCstats
.TX_totcol
; /* packet transmit problems */
1063 * This needs improvement.
1065 pDpa
->stats
.rx_dropped
= 0; /* no space in linux buffers */
1066 pDpa
->stats
.tx_dropped
= 0; /* no space available in linux */
1067 pDpa
->stats
.multicast
= 0; /* multicast packets received */
1068 pDpa
->stats
.collisions
= RCstats
.TX_totcol
;
1070 /* detailed rx_errors: */
1071 pDpa
->stats
.rx_length_errors
= 0;
1072 pDpa
->stats
.rx_over_errors
= RCstats
.Rcv_orun
; /* receiver ring buff overflow */
1073 pDpa
->stats
.rx_crc_errors
= RCstats
.Rcv_CRCerr
; /* recved pkt with crc error */
1074 pDpa
->stats
.rx_frame_errors
= 0; /* recv'd frame alignment error */
1075 pDpa
->stats
.rx_fifo_errors
= 0; /* recv'r fifo overrun */
1076 pDpa
->stats
.rx_missed_errors
= 0; /* receiver missed packet */
1078 /* detailed tx_errors */
1079 pDpa
->stats
.tx_aborted_errors
= 0;
1080 pDpa
->stats
.tx_carrier_errors
= 0;
1081 pDpa
->stats
.tx_fifo_errors
= 0;
1082 pDpa
->stats
.tx_heartbeat_errors
= 0;
1083 pDpa
->stats
.tx_window_errors
= 0;
1085 return ((struct enet_statistics
*)&(pDpa
->stats
));
1090 static int RCioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1092 RCuser_struct RCuser
;
1093 PDPA pDpa
= dev
->priv
;
1096 printk("RCioctl: cmd = 0x%x\n", cmd
);
1101 case RCU_PROTOCOL_REV
:
1103 * Assign user protocol revision, to tell user-level
1104 * controller program whether or not it's in sync.
1106 rq
->ifr_ifru
.ifru_data
= (caddr_t
) USER_PROTOCOL_REV
;
1113 if(copy_from_user(&RCuser
, rq
->ifr_data
, sizeof(RCuser
)))
1117 error
=verify_area(VERIFY_WRITE
, rq
->ifr_data
, sizeof(RCuser
));
1121 memcpy_fromfs(&RCuser
, rq
->ifr_data
, sizeof(RCuser
));
1125 printk("RCioctl: RCuser_cmd = 0x%x\n", RCuser
.cmd
);
1131 printk("RC GETFWVER\n");
1132 RCUD_GETFWVER
= &RCuser
.RCUS_GETFWVER
;
1133 RCGetFirmwareVer(pDpa
->id
, (PU8
) &RCUD_GETFWVER
->FirmString
, NULL
);
1136 printk("RC GETINFO\n");
1137 RCUD_GETINFO
= &RCuser
.RCUS_GETINFO
;
1138 RCUD_GETINFO
-> mem_start
= dev
->base_addr
;
1139 RCUD_GETINFO
-> mem_end
= dev
->base_addr
+ 2*32768;
1140 RCUD_GETINFO
-> base_addr
= pDpa
->pci_addr
;
1141 RCUD_GETINFO
-> irq
= dev
->irq
;
1143 case RCUC_GETIPANDMASK
:
1144 printk("RC GETIPANDMASK\n");
1145 RCUD_GETIPANDMASK
= &RCuser
.RCUS_GETIPANDMASK
;
1146 RCGetRavlinIPandMask(pDpa
->id
, (PU32
) &RCUD_GETIPANDMASK
->IpAddr
,
1147 (PU32
) &RCUD_GETIPANDMASK
->NetMask
, NULL
);
1149 case RCUC_GETLINKSTATISTICS
:
1150 printk("RC GETLINKSTATISTICS\n");
1151 RCUD_GETLINKSTATISTICS
= &RCuser
.RCUS_GETLINKSTATISTICS
;
1152 RCGetLinkStatistics(pDpa
->id
, (P_RCLINKSTATS
) &RCUD_GETLINKSTATISTICS
->StatsReturn
, NULL
);
1154 case RCUC_GETLINKSTATUS
:
1155 printk("RC GETLINKSTATUS\n");
1156 RCUD_GETLINKSTATUS
= &RCuser
.RCUS_GETLINKSTATUS
;
1157 RCGetLinkStatus(pDpa
->id
, (PU32
) &RCUD_GETLINKSTATUS
->ReturnStatus
, NULL
);
1160 printk("RC GETMAC\n");
1161 RCUD_GETMAC
= &RCuser
.RCUS_GETMAC
;
1162 RCGetMAC(pDpa
->id
, (PU8
) &RCUD_GETMAC
->mac
, NULL
);
1165 printk("RC GETPROM\n");
1166 RCUD_GETPROM
= &RCuser
.RCUS_GETPROM
;
1167 RCGetPromiscuousMode(pDpa
->id
, (PU32
) &RCUD_GETPROM
->PromMode
, NULL
);
1169 case RCUC_GETBROADCAST
:
1170 printk("RC GETBROADCAST\n");
1171 RCUD_GETBROADCAST
= &RCuser
.RCUS_GETBROADCAST
;
1172 RCGetBroadcastMode(pDpa
->id
, (PU32
) &RCUD_GETBROADCAST
->BroadcastMode
, NULL
);
1175 printk("RC GETSPEED\n");
1176 if (!(dev
->flags
& IFF_UP
))
1178 printk("RCioctl, GETSPEED error: interface down\n");
1181 RCUD_GETSPEED
= &RCuser
.RCUS_GETSPEED
;
1182 RCGetLinkSpeed(pDpa
->id
, (PU32
) &RCUD_GETSPEED
->LinkSpeedCode
, NULL
);
1183 printk("RC speed = 0x%ld\n", RCUD_GETSPEED
->LinkSpeedCode
);
1185 case RCUC_SETIPANDMASK
:
1186 printk("RC SETIPANDMASK\n");
1187 RCUD_SETIPANDMASK
= &RCuser
.RCUS_SETIPANDMASK
;
1188 printk ("RC New IP Addr = %d.%d.%d.%d, ", (U8
) ((RCUD_SETIPANDMASK
->IpAddr
) & 0xff),
1189 (U8
) ((RCUD_SETIPANDMASK
->IpAddr
>> 8) & 0xff),
1190 (U8
) ((RCUD_SETIPANDMASK
->IpAddr
>> 16) & 0xff),
1191 (U8
) ((RCUD_SETIPANDMASK
->IpAddr
>> 24) & 0xff));
1192 printk ("RC New Mask = %d.%d.%d.%d\n", (U8
) ((RCUD_SETIPANDMASK
->NetMask
) & 0xff),
1193 (U8
) ((RCUD_SETIPANDMASK
->NetMask
>> 8) & 0xff),
1194 (U8
) ((RCUD_SETIPANDMASK
->NetMask
>> 16) & 0xff),
1195 (U8
) ((RCUD_SETIPANDMASK
->NetMask
>> 24) & 0xff));
1196 RCSetRavlinIPandMask(pDpa
->id
, (U32
) RCUD_SETIPANDMASK
->IpAddr
,
1197 (U32
) RCUD_SETIPANDMASK
->NetMask
);
1200 printk("RC SETMAC\n");
1201 RCUD_SETMAC
= &RCuser
.RCUS_SETMAC
;
1202 printk ("RC New MAC addr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1203 (U8
) (RCUD_SETMAC
->mac
[0]), (U8
) (RCUD_SETMAC
->mac
[1]), (U8
) (RCUD_SETMAC
->mac
[2]),
1204 (U8
) (RCUD_SETMAC
->mac
[3]), (U8
) (RCUD_SETMAC
->mac
[4]), (U8
) (RCUD_SETMAC
->mac
[5]));
1205 RCSetMAC(pDpa
->id
, (PU8
) &RCUD_SETMAC
->mac
);
1208 printk("RC SETSPEED\n");
1209 RCUD_SETSPEED
= &RCuser
.RCUS_SETSPEED
;
1210 RCSetLinkSpeed(pDpa
->id
, (U16
) RCUD_SETSPEED
->LinkSpeedCode
);
1211 printk("RC New speed = 0x%d\n", RCUD_SETSPEED
->LinkSpeedCode
);
1214 printk("RC SETPROM\n");
1215 RCUD_SETPROM
= &RCuser
.RCUS_SETPROM
;
1216 RCSetPromiscuousMode(pDpa
->id
,(U16
)RCUD_SETPROM
->PromMode
);
1217 printk("RC New prom mode = 0x%d\n", RCUD_SETPROM
->PromMode
);
1219 case RCUC_SETBROADCAST
:
1220 printk("RC SETBROADCAST\n");
1221 RCUD_SETBROADCAST
= &RCuser
.RCUS_SETBROADCAST
;
1222 RCSetBroadcastMode(pDpa
->id
,(U16
)RCUD_SETBROADCAST
->BroadcastMode
);
1223 printk("RC New broadcast mode = 0x%d\n", RCUD_SETBROADCAST
->BroadcastMode
);
1226 printk("RC command default\n");
1227 RCUD_DEFAULT
= &RCuser
.RCUS_DEFAULT
;
1228 RCUD_DEFAULT
-> rc
= 0x11223344;
1232 copy_to_user(rq
->ifr_data
, &RCuser
, sizeof(RCuser
));
1234 memcpy_tofs(rq
->ifr_data
, &RCuser
, sizeof(RCuser
));
1240 printk("RC default\n");
1241 rq
->ifr_ifru
.ifru_data
= (caddr_t
) 0x12345678;
1247 static int RCconfig(struct net_device
*dev
, struct ifmap
*map
)
1250 * To be completed ...
1252 printk("rc: RCconfig\n");
1254 if (dev
->flags
& IFF_UP
) /* can't act on a running interface */
1257 /* Don't allow changing the I/O address */
1258 if (map
->base_addr
!= dev
->base_addr
) {
1259 printk(KERN_WARNING
"RC pci45: Change I/O address not implemented\n");
1268 cleanup_module(void)
1271 struct net_device
*next
;
1275 printk("rc: RC cleanup_module\n");
1276 printk("rc: root_RCdev = 0x%x\n", (uint
)root_RCdev
);
1282 pDpa
= (PDPA
) root_RCdev
->priv
;
1284 printk("rc: cleanup 0x%08X\n", (uint
)root_RCdev
);
1286 printk("IOP reset: 0x%x\n", RCResetIOP(pDpa
->id
));
1287 unregister_netdev(root_RCdev
);
1290 iounmap((unsigned long *)root_RCdev
->base_addr
);
1291 free_irq( root_RCdev
->irq
, root_RCdev
);
1300 RC_allocate_and_post_buffers(struct net_device
*dev
, int numBuffers
)
1304 PDPA pDpa
= (PDPA
)dev
->priv
;
1307 struct sk_buff
*skb
;
1312 else if (numBuffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
1315 printk("rc: Too many buffers requested!\n");
1316 printk("rc: attempting to allocate only 32 buffers\n");
1321 p
= (PU32
) kmalloc(sizeof(U32
) + numBuffers
*sizeof(singleB
), GFP_ATOMIC
);
1324 printk("rc: TCB = 0x%x\n", (uint
)p
);
1329 printk("rc: RCopen: unable to allocate TCB\n");
1333 p
[0] = 0; /* Buffer Count */
1334 pB
= (psingleB
)((U32
)p
+ sizeof(U32
)); /* point to the first buffer */
1337 printk("rc: p[0] = 0x%x, p = 0x%x, pB = 0x%x\n", (uint
)p
[0], (uint
)p
, (uint
)pB
);
1338 printk("rc: pB = 0x%x\n", (uint
)pB
);
1341 for (i
=0; i
<numBuffers
; i
++)
1343 skb
= dev_alloc_skb(MAX_ETHER_SIZE
+2);
1346 printk("rc: Doh! RCopen: unable to allocate enough skbs!\n");
1347 if (*p
!= 0) /* did we allocate any buffers at all? */
1350 printk("rc: will post only %d buffers \n", (uint
)(*p
));
1356 kfree(p
); /* Free the TCB */
1361 printk("post 0x%x\n", (uint
)skb
);
1363 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1364 pB
->context
= (U32
)skb
;
1365 pB
->scount
= 1; /* segment count */
1366 pB
->size
= MAX_ETHER_SIZE
;
1367 pB
->addr
= virt_to_bus((void *)skb
->data
);
1372 if ( (status
= RCPostRecvBuffers(pDpa
->id
, (PRCTCB
)p
)) != RC_RTN_NO_ERROR
)
1374 printk("rc: Post buffer failed with error code 0x%x!\n", status
);
1375 pB
= (psingleB
)((U32
)p
+ sizeof(U32
)); /* point to the first buffer */
1378 skb
= (struct sk_buff
*)pB
->context
;
1383 printk("rc: freeing 0x%x\n", (uint
)skb
);
1386 dev_kfree_skb (skb
);
1388 dev_kfree_skb(skb
, FREE_READ
);
1394 printk("rc: freed all buffers, p[0] = %ld\n", p
[0]);
1398 return(p
[0]); /* return the number of posted buffers */