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(void);
162 static int RCfound_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(void)
189 cards_found
= RCscan();
192 return cards_found
? 0 : -ENODEV
;
195 static int RCscan(void)
198 static int pci_index
= 0;
200 if (!pcibios_present())
203 for (;pci_index
< 0x8; pci_index
++)
205 unsigned char pci_bus
, pci_device_fn
;
208 unsigned char pci_irq_line
;
209 unsigned int pci_ioaddr
;
210 struct pci_dev
*pdev
;
213 (pcibios_find_device (RC_PCI45_VENDOR_ID
,
219 printk("rc scan_status = 0x%X\n", scan_status
);
221 if (scan_status
!= PCIBIOS_SUCCESSFUL
||
222 !((pdev
= pci_find_slot(pci_bus
, pci_device_fn
))))
224 pci_irq_line
= pdev
->irq
;
225 pci_ioaddr
= pdev
->resource
[0].start
;
228 printk("rc: Found RedCreek PCI adapter\n");
229 printk("rc: pci_bus = %d, pci_device_fn = %d\n", pci_bus
, pci_device_fn
);
230 printk("rc: pci_irq_line = 0x%x \n", pci_irq_line
);
231 printk("rc: pci_ioaddr = 0x%x\n", pci_ioaddr
);
234 pci_set_master(pdev
);
236 if (!RCfound_device(pci_ioaddr
, pci_irq_line
,
237 pci_bus
, pci_device_fn
,
238 board_index
++, cards_found
))
242 printk("rc: found %d cards \n", cards_found
);
247 static int RCinit(struct net_device
*dev
)
250 dev
->hard_start_xmit
= &RC_xmit_packet
;
251 dev
->stop
= &RCclose
;
252 dev
->get_stats
= &RCget_stats
;
253 dev
->do_ioctl
= &RCioctl
;
254 dev
->set_config
= &RCconfig
;
259 RCfound_device(int memaddr
, int irq
,
260 int bus
, int function
, int product_index
, int card_idx
)
262 int dev_size
= 32768;
263 unsigned long *vaddr
=0;
267 struct net_device
*dev
;
270 * Allocate and fill new device structure.
271 * We need enough for struct net_device plus DPA plus the LAN API private
272 * area, which requires a minimum of 16KB. The top of the allocated
273 * area will be assigned to struct net_device; the next chunk will be
274 * assigned to DPA; and finally, the rest will be assigned to the
278 dev
= (struct net_device
*) kmalloc(dev_size
, GFP_DMA
| GFP_KERNEL
|GFP_ATOMIC
);
281 printk("rc: unable to kmalloc dev\n");
284 memset(dev
, 0, dev_size
);
286 * dev->priv will point to the start of DPA.
288 dev
->priv
= (void *)(((long)dev
+ sizeof(struct net_device
) + 15) & ~15);
291 printk("rc: dev = 0x%x, dev->priv = 0x%x\n", (uint
)dev
, (uint
)dev
->priv
);
296 dev
->name
= pDpa
->devname
;
298 pDpa
->dev
= dev
; /* this is just for easy reference */
299 pDpa
->function
= function
;
301 pDpa
->id
= card_idx
; /* the device number */
302 pDpa
->pci_addr
= memaddr
;
303 PCIAdapters
[card_idx
] = pDpa
;
305 printk("rc: pDpa = 0x%x, id = %d \n", (uint
)pDpa
, (uint
)pDpa
->id
);
309 * Save the starting address of the LAN API private area. We'll
310 * pass that to RCInitI2OMsgLayer().
312 pDpa
->PLanApiPA
= (void *)(((long)pDpa
+ sizeof(DPA
) + 0xff) & ~0xff);
314 printk("rc: pDpa->PLanApiPA = 0x%x\n", (uint
)pDpa
->PLanApiPA
);
317 /* The adapter is accessable through memory-access read/write, not
318 * I/O read/write. Thus, we need to map it to some virtual address
319 * area in order to access the registers are normal memory.
321 vaddr
= (ulong
*) ioremap (memaddr
, 2*32768);
323 printk("rc: RCfound_device: 0x%x, priv = 0x%x, vaddr = 0x%x\n",
324 (uint
)dev
, (uint
)dev
->priv
, (uint
)vaddr
);
326 dev
->base_addr
= (unsigned long)vaddr
;
331 * Request a shared interrupt line.
333 if ( request_irq(dev
->irq
, (void *)RCinterrupt
,
334 SA_INTERRUPT
|SA_SHIRQ
, "RedCreek VPN Adapter", dev
) )
336 printk( "RC PCI 45: %s: unable to get IRQ %d\n", (PU8
)dev
->name
, (uint
)dev
->irq
);
342 init_status
= RCInitI2OMsgLayer(pDpa
->id
, dev
->base_addr
,
343 pDpa
->PLanApiPA
, (PU8
)virt_to_bus((void *)pDpa
->PLanApiPA
),
344 (PFNTXCALLBACK
)RCxmit_callback
,
345 (PFNRXCALLBACK
)RCrecv_callback
,
346 (PFNCALLBACK
)RCreboot_callback
);
349 printk("rc: Unable to initialize msg layer\n");
350 free_irq(dev
->irq
, dev
);
355 if (RCGetMAC(pDpa
->id
, dev
->dev_addr
, NULL
))
357 printk("rc: Unable to get adapter MAC\n");
358 free_irq(dev
->irq
, dev
);
364 DriverControlWord
|= WARM_REBOOT_CAPABLE
;
365 RCReportDriverCapability(pDpa
->id
, DriverControlWord
);
368 ether_setup(dev
); /* linux kernel interface */
370 pDpa
->next
= root_RCdev
;
373 if (register_netdev(dev
) != 0) /* linux kernel interface */
375 printk("rc: unable to register device \n");
376 free_irq(dev
->irq
, dev
);
381 printk("%s: RedCreek Communications IPSEC VPN adapter\n",
384 return 0; /* success */
388 RCopen(struct net_device
*dev
)
390 int post_buffers
= MAX_NMBR_RCV_BUFFERS
;
391 PDPA pDpa
= (PDPA
) dev
->priv
;
396 printk("rc: RCopen\n");
398 RCEnableI2OInterrupts(pDpa
->id
);
402 /* This is not the first time RCopen is called. Thus,
403 * the interface was previously opened and later closed
404 * by RCclose(). RCclose() does a Shutdown; to wake up
405 * the adapter, a reset is mandatory before we can post
406 * receive buffers. However, if the adapter initiated
407 * a reboot while the interface was closed -- and interrupts
408 * were turned off -- we need will need to reinitialize
409 * the adapter, rather than simply waking it up.
411 printk("rc: Waking up adapter...\n");
412 RCResetLANCard(pDpa
->id
,0,0,0);
421 if (post_buffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
422 requested
= MAX_NMBR_POST_BUFFERS_PER_MSG
;
424 requested
= post_buffers
;
425 count
= RC_allocate_and_post_buffers(dev
, requested
);
427 if ( count
< requested
)
430 * Check to see if we were able to post any buffers at all.
432 if (post_buffers
== MAX_NMBR_RCV_BUFFERS
)
434 printk("rc: Error RCopen: not able to allocate any buffers\r\n");
437 printk("rc: Warning RCopen: not able to allocate all requested buffers\r\n");
438 break; /* we'll try to post more buffers later */
441 post_buffers
-= count
;
443 pDpa
->numOutRcvBuffers
= MAX_NMBR_RCV_BUFFERS
- post_buffers
;
444 pDpa
->shutdown
= 0; /* just in case */
446 printk("rc: RCopen: posted %d buffers\n", (uint
)pDpa
->numOutRcvBuffers
);
453 RC_xmit_packet(struct sk_buff
*skb
, struct net_device
*dev
)
456 PDPA pDpa
= (PDPA
) dev
->priv
;
458 psingleTCB ptcb
= &tcb
;
459 RC_RETURN status
= 0;
461 if (dev
->tbusy
|| pDpa
->shutdown
|| pDpa
->reboot
)
464 printk("rc: RC_xmit_packet: tbusy!\n");
472 printk("RC_xmit_packet: skb->len less than 0!\n");
477 * The user is free to reuse the TCB after RCI2OSendPacket() returns, since
478 * the function copies the necessary info into its own private space. Thus,
479 * our TCB can be a local structure. The skb, on the other hand, will be
480 * freed up in our interrupt handler.
484 * we'll get the context when the adapter interrupts us to tell us that
485 * the transmision is done. At that time, we can free skb.
487 ptcb
->b
.context
= (U32
)skb
;
489 ptcb
->b
.size
= skb
->len
;
490 ptcb
->b
.addr
= virt_to_bus((void *)skb
->data
);
493 printk("rc: RC xmit: skb = 0x%x, pDpa = 0x%x, id = %d, ptcb = 0x%x\n",
494 (uint
)skb
, (uint
)pDpa
, (uint
)pDpa
->id
, (uint
)ptcb
);
496 if ( (status
= RCI2OSendPacket(pDpa
->id
, (U32
)NULL
, (PRCTCB
)ptcb
))
500 printk("rc: RC send error 0x%x\n", (uint
)status
);
507 dev
->trans_start
= jiffies
;
519 * The transmit callback routine. It's called by RCProcI2OMsgQ()
520 * because the adapter is done with one or more transmit buffers and
521 * it's returning them to us, or we asked the adapter to return the
522 * outstanding transmit buffers by calling RCResetLANCard() with
523 * RC_RESOURCE_RETURN_PEND_TX_BUFFERS flag.
524 * All we need to do is free the buffers.
527 RCxmit_callback(U32 Status
,
534 struct net_device
*dev
;
536 pDpa
= PCIAdapters
[AdapterID
];
539 printk("rc: Fatal error: xmit callback, !pDpa\n");
544 // printk("xmit_callback: Status = 0x%x\n", (uint)Status);
545 if (Status
!= I2O_REPLY_STATUS_SUCCESS
)
547 printk("rc: xmit_callback: Status = 0x%x\n", (uint
)Status
);
550 if (pDpa
->shutdown
|| pDpa
->reboot
)
551 printk("rc: xmit callback: shutdown||reboot\n");
555 printk("rc: xmit_callback: PcktCount = %d, BC = 0x%x\n",
556 (uint
)PcktCount
, (uint
)BufferContext
);
560 skb
= (struct sk_buff
*)(BufferContext
[0]);
562 printk("rc: skb = 0x%x\n", (uint
)skb
);
568 dev_kfree_skb (skb
, FREE_WRITE
);
576 RCreset_callback(U32 Status
, U32 p1
, U32 p2
, U16 AdapterID
)
579 struct net_device
*dev
;
581 pDpa
= PCIAdapters
[AdapterID
];
584 printk("rc: RCreset_callback Status 0x%x\n", (uint
)Status
);
587 * Check to see why we were called.
591 printk("rc: Shutting down interface\n");
596 else if (pDpa
->reboot
)
598 printk("rc: reboot, shutdown adapter\n");
600 * We don't set any of the flags in RCShutdownLANCard()
601 * and we don't pass a callback routine to it.
602 * The adapter will have already initiated the reboot by
603 * the time the function returns.
605 RCDisableI2OInterrupts(pDpa
->id
);
606 RCShutdownLANCard(pDpa
->id
,0,0,0);
607 printk("rc: scheduling timer...\n");
608 init_timer(&pDpa
->timer
);
609 pDpa
->timer
.expires
= RUN_AT((40*HZ
)/10); /* 4 sec. */
610 pDpa
->timer
.data
= (unsigned long)dev
;
611 pDpa
->timer
.function
= &rc_timer
; /* timer handler */
612 add_timer(&pDpa
->timer
);
620 RCreboot_callback(U32 Status
, U32 p1
, U32 p2
, U16 AdapterID
)
624 pDpa
= PCIAdapters
[AdapterID
];
626 printk("rc: RCreboot: rcv buffers outstanding = %d\n",
627 (uint
)pDpa
->numOutRcvBuffers
);
631 printk("rc: skipping reboot sequence -- shutdown already initiated\n");
636 * OK, we reset the adapter and ask it to return all
637 * outstanding transmit buffers as well as the posted
638 * receive buffers. When the adapter is done returning
639 * those buffers, it will call our RCreset_callback()
640 * routine. In that routine, we'll call RCShutdownLANCard()
641 * to tell the adapter that it's OK to start the reboot and
642 * schedule a timer callback routine to execute 3 seconds
643 * later; this routine will reinitialize the adapter at that time.
645 RCResetLANCard(pDpa
->id
,
646 RC_RESOURCE_RETURN_POSTED_RX_BUCKETS
|
647 RC_RESOURCE_RETURN_PEND_TX_BUFFERS
,0,
648 (PFNCALLBACK
)RCreset_callback
);
652 int broadcast_packet(unsigned char * address
)
656 if (address
[i
] != 0xff) return 0;
664 * The receive packet callback routine. This is called by
665 * RCProcI2OMsgQ() after the adapter posts buffers which have been
666 * filled (one ethernet packet per buffer).
669 RCrecv_callback(U32 Status
,
672 PU32 PacketDescBlock
,
679 struct net_device
*dev
;
681 psingleTCB ptcb
= &tcb
;
684 pDpa
= PCIAdapters
[AdapterID
];
690 printk("rc: RCrecv_callback: 0x%x, 0x%x, 0x%x\n",
691 (uint
)PktCount
, (uint
)BucketsRemain
, (uint
)PacketDescBlock
);
695 if ((pDpa
->shutdown
|| pDpa
->reboot
) && !Status
)
696 printk("shutdown||reboot && !Status: PktCount = %d\n",PktCount
);
699 if ( (Status
!= I2O_REPLY_STATUS_SUCCESS
) || pDpa
->shutdown
)
702 * Free whatever buffers the adapter returned, but don't
703 * pass them to the kernel.
706 if (!pDpa
->shutdown
&& !pDpa
->reboot
)
707 printk("rc: RCrecv error: status = 0x%x\n", (uint
)Status
);
710 printk("rc: Returning %d buffers, status = 0x%x\n",
711 PktCount
, (uint
)Status
);
714 * TO DO: check the nature of the failure and put the adapter in
715 * failed mode if it's a hard failure. Send a reset to the adapter
716 * and free all outstanding memory.
718 if (Status
== I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER
)
721 printk("RCrecv status ABORT NO DATA TRANSFER\n");
724 /* check for reset status: I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER */
729 skb
= (struct sk_buff
*)PacketDescBlock
[0];
735 printk("free skb 0x%p\n", skb
);
740 dev_kfree_skb(skb
, FREE_READ
);
742 pDpa
->numOutRcvBuffers
--;
743 PacketDescBlock
+= BD_SIZE
; /* point to next context field */
752 skb
= (struct sk_buff
*)PacketDescBlock
[0];
755 printk("shutdown: skb=0x%x\n", (uint
)skb
);
757 printk("skb = 0x%x: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", (uint
)skb
,
758 (uint
)skb
->data
[0], (uint
)skb
->data
[1], (uint
)skb
->data
[2],
759 (uint
)skb
->data
[3], (uint
)skb
->data
[4], (uint
)skb
->data
[5]);
762 #ifdef PROMISCUOUS_BY_DEFAULT /* early 2.x firmware */
763 if ( (memcmp(dev
->dev_addr
, skb
->data
, 6)) &&
764 (!broadcast_packet(skb
->data
)))
767 * Re-post the buffer to the adapter. Since the adapter usually
768 * return 1 to 2 receive buffers at a time, it's not too inefficient
769 * post one buffer at a time but ... may be that should be
770 * optimized at some point.
772 ptcb
->b
.context
= (U32
)skb
;
774 ptcb
->b
.size
= MAX_ETHER_SIZE
;
775 ptcb
->b
.addr
= virt_to_bus((void *)skb
->data
);
777 if ( RCPostRecvBuffers(pDpa
->id
, (PRCTCB
)ptcb
) != RC_RTN_NO_ERROR
)
779 printk("rc: RCrecv_callback: post buffer failed!\n");
784 dev_kfree_skb(skb
, FREE_READ
);
789 pDpa
->numOutRcvBuffers
++;
793 #endif /* PROMISCUOUS_BY_DEFAULT */
795 len
= PacketDescBlock
[2];
797 skb_put( skb
, len
); /* adjust length and tail */
798 skb
->protocol
= eth_type_trans(skb
, dev
);
799 netif_rx(skb
); /* send the packet to the kernel */
800 dev
->last_rx
= jiffies
;
802 pDpa
->numOutRcvBuffers
--;
803 PacketDescBlock
+= BD_SIZE
; /* point to next context field */
808 * Replenish the posted receive buffers.
809 * DO NOT replenish buffers if the driver has already
810 * initiated a reboot or shutdown!
813 if (!pDpa
->shutdown
&& !pDpa
->reboot
)
815 count
= RC_allocate_and_post_buffers(dev
,
816 MAX_NMBR_RCV_BUFFERS
-pDpa
->numOutRcvBuffers
);
817 pDpa
->numOutRcvBuffers
+= count
;
826 * This routine sets up a couple of pointers and calls
827 * RCProcI2OMsgQ(), which in turn process the message and
828 * calls one of our callback functions.
831 RCinterrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
835 struct net_device
*dev
= (struct net_device
*)(dev_id
);
837 pDpa
= (PDPA
) (dev
->priv
);
841 printk("rc: shutdown: service irq\n");
843 printk("RC irq: pDpa = 0x%x, dev = 0x%x, id = %d\n",
844 (uint
)pDpa
, (uint
)dev
, (uint
)pDpa
->id
);
845 printk("dev = 0x%x\n", (uint
)dev
);
848 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
851 RCProcI2OMsgQ(pDpa
->id
);
858 #define REBOOT_REINIT_RETRY_LIMIT 4
859 static void rc_timer(unsigned long data
)
861 struct net_device
*dev
= (struct net_device
*)data
;
862 PDPA pDpa
= (PDPA
) (dev
->priv
);
864 static int retry
= 0;
865 int post_buffers
= MAX_NMBR_RCV_BUFFERS
;
871 init_status
= RCInitI2OMsgLayer(pDpa
->id
, dev
->base_addr
,
873 (PU8
)virt_to_bus((void *)pDpa
->PLanApiPA
),
874 (PFNTXCALLBACK
)RCxmit_callback
,
875 (PFNRXCALLBACK
)RCrecv_callback
,
876 (PFNCALLBACK
)RCreboot_callback
);
880 case RC_RTN_NO_ERROR
:
883 pDpa
->shutdown
= 0; /* just in case */
884 RCReportDriverCapability(pDpa
->id
, DriverControlWord
);
885 RCEnableI2OInterrupts(pDpa
->id
);
887 if (dev
->flags
& IFF_UP
)
891 if (post_buffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
892 requested
= MAX_NMBR_POST_BUFFERS_PER_MSG
;
894 requested
= post_buffers
;
895 count
= RC_allocate_and_post_buffers(dev
, requested
);
896 post_buffers
-= count
;
897 if ( count
< requested
)
900 pDpa
->numOutRcvBuffers
=
901 MAX_NMBR_RCV_BUFFERS
- post_buffers
;
902 printk("rc: posted %d buffers \r\n",
903 (uint
)pDpa
->numOutRcvBuffers
);
905 printk("rc: Initialization done.\n");
909 case RC_RTN_FREE_Q_EMPTY
:
911 printk("rc: inbound free q empty\n");
915 printk("rc: bad status after reboot: %d\n", init_status
);
919 if (retry
> REBOOT_REINIT_RETRY_LIMIT
)
921 printk("rc: unable to reinitialize adapter after reboot\n");
922 printk("rc: decrementing driver and closing interface\n");
923 RCDisableI2OInterrupts(pDpa
->id
);
924 dev
->flags
&= ~IFF_UP
;
929 printk("rc: rescheduling timer...\n");
930 init_timer(&pDpa
->timer
);
931 pDpa
->timer
.expires
= RUN_AT((40*HZ
)/10); /* 3 sec. */
932 pDpa
->timer
.data
= (unsigned long)dev
;
933 pDpa
->timer
.function
= &rc_timer
; /* timer handler */
934 add_timer(&pDpa
->timer
);
939 printk("rc: timer??\n");
944 RCclose(struct net_device
*dev
)
947 PDPA pDpa
= (PDPA
) dev
->priv
;
950 printk("rc: RCclose\r\n");
954 printk("rc: skipping reset -- adapter already in reboot mode\n");
955 dev
->flags
&= ~IFF_UP
;
960 printk("rc: receive buffers outstanding: %d\n",
961 (uint
)pDpa
->numOutRcvBuffers
);
967 * We can't allow the driver to be unloaded until the adapter returns
968 * all posted receive buffers. It doesn't hurt to tell the adapter
969 * to return all posted receive buffers and outstanding xmit buffers,
970 * even if there are none.
973 RCShutdownLANCard(pDpa
->id
,
974 RC_RESOURCE_RETURN_POSTED_RX_BUCKETS
|
975 RC_RESOURCE_RETURN_PEND_TX_BUFFERS
,0,
976 (PFNCALLBACK
)RCreset_callback
);
978 dev
->flags
&= ~IFF_UP
;
982 static struct enet_statistics
*
983 RCget_stats(struct net_device
*dev
)
987 PDPA pDpa
= dev
->priv
;
991 printk("rc: RCget_stats: !pDpa\n");
994 else if (!(dev
->flags
& IFF_UP
))
997 printk("rc: RCget_stats: device down\n");
1002 memset(&RCstats
, 0, sizeof(RCLINKSTATS
));
1003 if ( (RCGetLinkStatistics(pDpa
->id
, &RCstats
, (void *)0)) == RC_RTN_NO_ERROR
)
1006 printk("rc: TX_good 0x%x\n", (uint
)RCstats
.TX_good
);
1007 printk("rc: TX_maxcol 0x%x\n", (uint
)RCstats
.TX_maxcol
);
1008 printk("rc: TX_latecol 0x%x\n", (uint
)RCstats
.TX_latecol
);
1009 printk("rc: TX_urun 0x%x\n", (uint
)RCstats
.TX_urun
);
1010 printk("rc: TX_crs 0x%x\n", (uint
)RCstats
.TX_crs
);
1011 printk("rc: TX_def 0x%x\n", (uint
)RCstats
.TX_def
);
1012 printk("rc: TX_singlecol 0x%x\n", (uint
)RCstats
.TX_singlecol
);
1013 printk("rc: TX_multcol 0x%x\n", (uint
)RCstats
.TX_multcol
);
1014 printk("rc: TX_totcol 0x%x\n", (uint
)RCstats
.TX_totcol
);
1016 printk("rc: Rcv_good 0x%x\n", (uint
)RCstats
.Rcv_good
);
1017 printk("rc: Rcv_CRCerr 0x%x\n", (uint
)RCstats
.Rcv_CRCerr
);
1018 printk("rc: Rcv_alignerr 0x%x\n", (uint
)RCstats
.Rcv_alignerr
);
1019 printk("rc: Rcv_reserr 0x%x\n", (uint
)RCstats
.Rcv_reserr
);
1020 printk("rc: Rcv_orun 0x%x\n", (uint
)RCstats
.Rcv_orun
);
1021 printk("rc: Rcv_cdt 0x%x\n", (uint
)RCstats
.Rcv_cdt
);
1022 printk("rc: Rcv_runt 0x%x\n", (uint
)RCstats
.Rcv_runt
);
1025 pDpa
->stats
.rx_packets
= RCstats
.Rcv_good
; /* total packets received */
1026 pDpa
->stats
.tx_packets
= RCstats
.TX_good
; /* total packets transmitted */
1028 pDpa
->stats
.rx_errors
=
1029 RCstats
.Rcv_CRCerr
+
1030 RCstats
.Rcv_alignerr
+
1031 RCstats
.Rcv_reserr
+
1034 RCstats
.Rcv_runt
; /* bad packets received */
1036 pDpa
->stats
.tx_errors
=
1040 RCstats
.TX_totcol
; /* packet transmit problems */
1043 * This needs improvement.
1045 pDpa
->stats
.rx_dropped
= 0; /* no space in linux buffers */
1046 pDpa
->stats
.tx_dropped
= 0; /* no space available in linux */
1047 pDpa
->stats
.multicast
= 0; /* multicast packets received */
1048 pDpa
->stats
.collisions
= RCstats
.TX_totcol
;
1050 /* detailed rx_errors: */
1051 pDpa
->stats
.rx_length_errors
= 0;
1052 pDpa
->stats
.rx_over_errors
= RCstats
.Rcv_orun
; /* receiver ring buff overflow */
1053 pDpa
->stats
.rx_crc_errors
= RCstats
.Rcv_CRCerr
; /* recved pkt with crc error */
1054 pDpa
->stats
.rx_frame_errors
= 0; /* recv'd frame alignment error */
1055 pDpa
->stats
.rx_fifo_errors
= 0; /* recv'r fifo overrun */
1056 pDpa
->stats
.rx_missed_errors
= 0; /* receiver missed packet */
1058 /* detailed tx_errors */
1059 pDpa
->stats
.tx_aborted_errors
= 0;
1060 pDpa
->stats
.tx_carrier_errors
= 0;
1061 pDpa
->stats
.tx_fifo_errors
= 0;
1062 pDpa
->stats
.tx_heartbeat_errors
= 0;
1063 pDpa
->stats
.tx_window_errors
= 0;
1065 return ((struct enet_statistics
*)&(pDpa
->stats
));
1070 static int RCioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1072 RCuser_struct RCuser
;
1073 PDPA pDpa
= dev
->priv
;
1076 printk("RCioctl: cmd = 0x%x\n", cmd
);
1081 case RCU_PROTOCOL_REV
:
1083 * Assign user protocol revision, to tell user-level
1084 * controller program whether or not it's in sync.
1086 rq
->ifr_ifru
.ifru_data
= (caddr_t
) USER_PROTOCOL_REV
;
1093 if(copy_from_user(&RCuser
, rq
->ifr_data
, sizeof(RCuser
)))
1097 error
=verify_area(VERIFY_WRITE
, rq
->ifr_data
, sizeof(RCuser
));
1101 memcpy_fromfs(&RCuser
, rq
->ifr_data
, sizeof(RCuser
));
1105 printk("RCioctl: RCuser_cmd = 0x%x\n", RCuser
.cmd
);
1111 printk("RC GETFWVER\n");
1112 RCUD_GETFWVER
= &RCuser
.RCUS_GETFWVER
;
1113 RCGetFirmwareVer(pDpa
->id
, (PU8
) &RCUD_GETFWVER
->FirmString
, NULL
);
1116 printk("RC GETINFO\n");
1117 RCUD_GETINFO
= &RCuser
.RCUS_GETINFO
;
1118 RCUD_GETINFO
-> mem_start
= dev
->base_addr
;
1119 RCUD_GETINFO
-> mem_end
= dev
->base_addr
+ 2*32768;
1120 RCUD_GETINFO
-> base_addr
= pDpa
->pci_addr
;
1121 RCUD_GETINFO
-> irq
= dev
->irq
;
1123 case RCUC_GETIPANDMASK
:
1124 printk("RC GETIPANDMASK\n");
1125 RCUD_GETIPANDMASK
= &RCuser
.RCUS_GETIPANDMASK
;
1126 RCGetRavlinIPandMask(pDpa
->id
, (PU32
) &RCUD_GETIPANDMASK
->IpAddr
,
1127 (PU32
) &RCUD_GETIPANDMASK
->NetMask
, NULL
);
1129 case RCUC_GETLINKSTATISTICS
:
1130 printk("RC GETLINKSTATISTICS\n");
1131 RCUD_GETLINKSTATISTICS
= &RCuser
.RCUS_GETLINKSTATISTICS
;
1132 RCGetLinkStatistics(pDpa
->id
, (P_RCLINKSTATS
) &RCUD_GETLINKSTATISTICS
->StatsReturn
, NULL
);
1134 case RCUC_GETLINKSTATUS
:
1135 printk("RC GETLINKSTATUS\n");
1136 RCUD_GETLINKSTATUS
= &RCuser
.RCUS_GETLINKSTATUS
;
1137 RCGetLinkStatus(pDpa
->id
, (PU32
) &RCUD_GETLINKSTATUS
->ReturnStatus
, NULL
);
1140 printk("RC GETMAC\n");
1141 RCUD_GETMAC
= &RCuser
.RCUS_GETMAC
;
1142 RCGetMAC(pDpa
->id
, (PU8
) &RCUD_GETMAC
->mac
, NULL
);
1145 printk("RC GETPROM\n");
1146 RCUD_GETPROM
= &RCuser
.RCUS_GETPROM
;
1147 RCGetPromiscuousMode(pDpa
->id
, (PU32
) &RCUD_GETPROM
->PromMode
, NULL
);
1149 case RCUC_GETBROADCAST
:
1150 printk("RC GETBROADCAST\n");
1151 RCUD_GETBROADCAST
= &RCuser
.RCUS_GETBROADCAST
;
1152 RCGetBroadcastMode(pDpa
->id
, (PU32
) &RCUD_GETBROADCAST
->BroadcastMode
, NULL
);
1155 printk("RC GETSPEED\n");
1156 if (!(dev
->flags
& IFF_UP
))
1158 printk("RCioctl, GETSPEED error: interface down\n");
1161 RCUD_GETSPEED
= &RCuser
.RCUS_GETSPEED
;
1162 RCGetLinkSpeed(pDpa
->id
, (PU32
) &RCUD_GETSPEED
->LinkSpeedCode
, NULL
);
1163 printk("RC speed = 0x%ld\n", RCUD_GETSPEED
->LinkSpeedCode
);
1165 case RCUC_SETIPANDMASK
:
1166 printk("RC SETIPANDMASK\n");
1167 RCUD_SETIPANDMASK
= &RCuser
.RCUS_SETIPANDMASK
;
1168 printk ("RC New IP Addr = %d.%d.%d.%d, ", (U8
) ((RCUD_SETIPANDMASK
->IpAddr
) & 0xff),
1169 (U8
) ((RCUD_SETIPANDMASK
->IpAddr
>> 8) & 0xff),
1170 (U8
) ((RCUD_SETIPANDMASK
->IpAddr
>> 16) & 0xff),
1171 (U8
) ((RCUD_SETIPANDMASK
->IpAddr
>> 24) & 0xff));
1172 printk ("RC New Mask = %d.%d.%d.%d\n", (U8
) ((RCUD_SETIPANDMASK
->NetMask
) & 0xff),
1173 (U8
) ((RCUD_SETIPANDMASK
->NetMask
>> 8) & 0xff),
1174 (U8
) ((RCUD_SETIPANDMASK
->NetMask
>> 16) & 0xff),
1175 (U8
) ((RCUD_SETIPANDMASK
->NetMask
>> 24) & 0xff));
1176 RCSetRavlinIPandMask(pDpa
->id
, (U32
) RCUD_SETIPANDMASK
->IpAddr
,
1177 (U32
) RCUD_SETIPANDMASK
->NetMask
);
1180 printk("RC SETMAC\n");
1181 RCUD_SETMAC
= &RCuser
.RCUS_SETMAC
;
1182 printk ("RC New MAC addr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1183 (U8
) (RCUD_SETMAC
->mac
[0]), (U8
) (RCUD_SETMAC
->mac
[1]), (U8
) (RCUD_SETMAC
->mac
[2]),
1184 (U8
) (RCUD_SETMAC
->mac
[3]), (U8
) (RCUD_SETMAC
->mac
[4]), (U8
) (RCUD_SETMAC
->mac
[5]));
1185 RCSetMAC(pDpa
->id
, (PU8
) &RCUD_SETMAC
->mac
);
1188 printk("RC SETSPEED\n");
1189 RCUD_SETSPEED
= &RCuser
.RCUS_SETSPEED
;
1190 RCSetLinkSpeed(pDpa
->id
, (U16
) RCUD_SETSPEED
->LinkSpeedCode
);
1191 printk("RC New speed = 0x%d\n", RCUD_SETSPEED
->LinkSpeedCode
);
1194 printk("RC SETPROM\n");
1195 RCUD_SETPROM
= &RCuser
.RCUS_SETPROM
;
1196 RCSetPromiscuousMode(pDpa
->id
,(U16
)RCUD_SETPROM
->PromMode
);
1197 printk("RC New prom mode = 0x%d\n", RCUD_SETPROM
->PromMode
);
1199 case RCUC_SETBROADCAST
:
1200 printk("RC SETBROADCAST\n");
1201 RCUD_SETBROADCAST
= &RCuser
.RCUS_SETBROADCAST
;
1202 RCSetBroadcastMode(pDpa
->id
,(U16
)RCUD_SETBROADCAST
->BroadcastMode
);
1203 printk("RC New broadcast mode = 0x%d\n", RCUD_SETBROADCAST
->BroadcastMode
);
1206 printk("RC command default\n");
1207 RCUD_DEFAULT
= &RCuser
.RCUS_DEFAULT
;
1208 RCUD_DEFAULT
-> rc
= 0x11223344;
1212 copy_to_user(rq
->ifr_data
, &RCuser
, sizeof(RCuser
));
1214 memcpy_tofs(rq
->ifr_data
, &RCuser
, sizeof(RCuser
));
1220 printk("RC default\n");
1221 rq
->ifr_ifru
.ifru_data
= (caddr_t
) 0x12345678;
1227 static int RCconfig(struct net_device
*dev
, struct ifmap
*map
)
1230 * To be completed ...
1232 printk("rc: RCconfig\n");
1234 if (dev
->flags
& IFF_UP
) /* can't act on a running interface */
1237 /* Don't allow changing the I/O address */
1238 if (map
->base_addr
!= dev
->base_addr
) {
1239 printk(KERN_WARNING
"RC pci45: Change I/O address not implemented\n");
1248 cleanup_module(void)
1251 struct net_device
*next
;
1255 printk("rc: RC cleanup_module\n");
1256 printk("rc: root_RCdev = 0x%x\n", (uint
)root_RCdev
);
1262 pDpa
= (PDPA
) root_RCdev
->priv
;
1264 printk("rc: cleanup 0x%08X\n", (uint
)root_RCdev
);
1266 printk("IOP reset: 0x%x\n", RCResetIOP(pDpa
->id
));
1267 unregister_netdev(root_RCdev
);
1270 iounmap((unsigned long *)root_RCdev
->base_addr
);
1271 free_irq( root_RCdev
->irq
, root_RCdev
);
1280 RC_allocate_and_post_buffers(struct net_device
*dev
, int numBuffers
)
1284 PDPA pDpa
= (PDPA
)dev
->priv
;
1287 struct sk_buff
*skb
;
1292 else if (numBuffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
1295 printk("rc: Too many buffers requested!\n");
1296 printk("rc: attempting to allocate only 32 buffers\n");
1301 p
= (PU32
) kmalloc(sizeof(U32
) + numBuffers
*sizeof(singleB
), GFP_ATOMIC
);
1304 printk("rc: TCB = 0x%x\n", (uint
)p
);
1309 printk("rc: RCopen: unable to allocate TCB\n");
1313 p
[0] = 0; /* Buffer Count */
1314 pB
= (psingleB
)((U32
)p
+ sizeof(U32
)); /* point to the first buffer */
1317 printk("rc: p[0] = 0x%x, p = 0x%x, pB = 0x%x\n", (uint
)p
[0], (uint
)p
, (uint
)pB
);
1318 printk("rc: pB = 0x%x\n", (uint
)pB
);
1321 for (i
=0; i
<numBuffers
; i
++)
1323 skb
= dev_alloc_skb(MAX_ETHER_SIZE
+2);
1326 printk("rc: Doh! RCopen: unable to allocate enough skbs!\n");
1327 if (*p
!= 0) /* did we allocate any buffers at all? */
1330 printk("rc: will post only %d buffers \n", (uint
)(*p
));
1336 kfree(p
); /* Free the TCB */
1341 printk("post 0x%x\n", (uint
)skb
);
1343 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1344 pB
->context
= (U32
)skb
;
1345 pB
->scount
= 1; /* segment count */
1346 pB
->size
= MAX_ETHER_SIZE
;
1347 pB
->addr
= virt_to_bus((void *)skb
->data
);
1352 if ( (status
= RCPostRecvBuffers(pDpa
->id
, (PRCTCB
)p
)) != RC_RTN_NO_ERROR
)
1354 printk("rc: Post buffer failed with error code 0x%x!\n", status
);
1355 pB
= (psingleB
)((U32
)p
+ sizeof(U32
)); /* point to the first buffer */
1358 skb
= (struct sk_buff
*)pB
->context
;
1363 printk("rc: freeing 0x%x\n", (uint
)skb
);
1366 dev_kfree_skb (skb
);
1368 dev_kfree_skb(skb
, FREE_READ
);
1374 printk("rc: freed all buffers, p[0] = %ld\n", p
[0]);
1378 return(p
[0]); /* return the number of posted buffers */