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.
18 ** This program is free software; you can redistribute it and/or modify
19 ** it under the terms of the GNU General Public License as published by
20 ** the Free Software Foundation; either version 2 of the License, or
21 ** (at your option) any later version.
23 ** This program is distributed in the hope that it will be useful,
24 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ** GNU General Public License for more details.
28 ** You should have received a copy of the GNU General Public License
29 ** along with this program; if not, write to the Free Software
30 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 ** Francois Romieu, Apr 2003: Converted to pci DMA mapping API.
34 ** Pete Popov, Oct 2001: Fixed a few bugs to make the driver functional
35 ** again. Note that this card is not supported or manufactured by
38 ** Rasmus Andersen, December 2000: Converted to new PCI API and general
41 ** Pete Popov, January 11,99: Fixed a couple of 2.1.x problems
42 ** (virt_to_bus() not called), tested it under 2.2pre5 (as a module), and
43 ** added a #define(s) to enable the use of the same file for both, the 2.0.x
44 ** kernels as well as the 2.1.x.
46 ** Ported to 2.1.x by Alan Cox 1998/12/9.
48 ** Sometime in mid 1998, written by Pete Popov and Brian Moyle.
50 ***************************************************************************/
52 #include <linux/module.h>
53 #include <linux/kernel.h>
54 #include <linux/string.h>
55 #include <linux/errno.h>
57 #include <linux/init.h>
58 #include <linux/ioport.h>
59 #include <linux/slab.h>
60 #include <linux/interrupt.h>
61 #include <linux/pci.h>
62 #include <linux/timer.h>
64 #include <asm/irq.h> /* For NR_IRQS only. */
65 #include <asm/bitops.h>
66 #include <asm/uaccess.h>
68 static char version
[] __initdata
=
69 "RedCreek Communications PCI linux driver version 2.21\n";
71 #define RC_LINUX_MODULE
75 #define RUN_AT(x) (jiffies + (x))
79 #define MAX_ETHER_SIZE 1520
80 #define MAX_NMBR_RCV_BUFFERS 96
81 #define RC_POSTED_BUFFERS_LOW_MARK MAX_NMBR_RCV_BUFFERS-16
82 #define BD_SIZE 3 /* Bucket Descriptor size */
83 #define BD_LEN_OFFSET 2 /* Bucket Descriptor offset to length field */
85 /* RedCreek LAN device Target ID */
86 #define RC_LAN_TARGET_ID 0x10
87 /* RedCreek's OSM default LAN receive Initiator */
88 #define DEFAULT_RECV_INIT_CONTEXT 0xA17
90 /* minimum msg buffer size needed by the card
91 * Note that the size of this buffer is hard code in the
92 * ipsec card's firmware. Thus, the size MUST be a minimum
93 * of 16K. Otherwise the card will end up using memory
94 * that does not belong to it.
96 #define MSG_BUF_SIZE 16384
98 /* 2003/04/20: I don't know about the hardware ability but the driver won't
99 * play safe with 64 bit addressing and DAC without NETIF_F_HIGHDMA doesn't
100 * really make sense anyway. Let's play safe - romieu.
102 #define RCPCI45_DMA_MASK ((u64) 0xffffffff)
104 static U32 DriverControlWord
;
106 static void rc_timer (unsigned long);
108 static int RCopen (struct net_device
*);
109 static int RC_xmit_packet (struct sk_buff
*, struct net_device
*);
110 static irqreturn_t
RCinterrupt (int, void *, struct pt_regs
*);
111 static int RCclose (struct net_device
*dev
);
112 static struct net_device_stats
*RCget_stats (struct net_device
*);
113 static int RCioctl (struct net_device
*, struct ifreq
*, int);
114 static int RCconfig (struct net_device
*, struct ifmap
*);
115 static void RCxmit_callback (U32
, U16
, PU32
, struct net_device
*);
116 static void RCrecv_callback (U32
, U8
, U32
, PU32
, struct net_device
*);
117 static void RCreset_callback (U32
, U32
, U32
, struct net_device
*);
118 static void RCreboot_callback (U32
, U32
, U32
, struct net_device
*);
119 static int RC_allocate_and_post_buffers (struct net_device
*, int);
121 static struct pci_device_id rcpci45_pci_table
[] __devinitdata
= {
122 { PCI_VENDOR_ID_REDCREEK
, PCI_DEVICE_ID_RC45
, PCI_ANY_ID
, PCI_ANY_ID
,},
125 MODULE_DEVICE_TABLE (pci
, rcpci45_pci_table
);
126 MODULE_LICENSE("GPL");
128 static void __devexit
129 rcpci45_remove_one (struct pci_dev
*pdev
)
131 struct net_device
*dev
= pci_get_drvdata (pdev
);
132 PDPA pDpa
= dev
->priv
;
135 printk (KERN_ERR
"%s: remove non-existent device\n",
141 unregister_netdev (dev
);
142 free_irq (dev
->irq
, dev
);
143 iounmap ((void *) dev
->base_addr
);
144 pci_release_regions (pdev
);
145 pci_free_consistent (pdev
, MSG_BUF_SIZE
, pDpa
->msgbuf
,
150 pci_set_drvdata (pdev
, NULL
);
154 rcpci45_init_one (struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
156 unsigned long *vaddr
;
159 static int card_idx
= -1;
160 struct net_device
*dev
;
161 unsigned long pci_start
, pci_len
;
166 * Allocate and fill new device structure.
167 * We need enough for struct net_device plus DPA plus the LAN
168 * API private area, which requires a minimum of 16KB. The top
169 * of the allocated area will be assigned to struct net_device;
170 * the next chunk will be assigned to DPA; and finally, the rest
171 * will be assigned to the LAN API layer.
174 dev
= alloc_etherdev(sizeof(*pDpa
));
177 "(rcpci45 driver:) alloc_etherdev alloc failed\n");
182 SET_MODULE_OWNER(dev
);
183 SET_NETDEV_DEV(dev
, &pdev
->dev
);
185 error
= pci_enable_device (pdev
);
188 "(rcpci45 driver:) %d: pci enable device error\n",
192 pci_start
= pci_resource_start (pdev
, 0);
193 pci_len
= pci_resource_len (pdev
, 0);
194 printk("pci_start %lx pci_len %lx\n", pci_start
, pci_len
);
196 pci_set_drvdata (pdev
, dev
);
200 pDpa
->pci_dev
= pdev
;
201 pDpa
->pci_addr
= pci_start
;
203 if (!pci_start
|| !(pci_resource_flags (pdev
, 0) & IORESOURCE_MEM
)) {
205 "(rcpci45 driver:) No PCI mem resources! Aborting\n");
207 goto err_out_free_dev
;
211 * pDpa->msgbuf is where the card will dma the I2O
212 * messages. Thus, we need contiguous physical pages of memory.
213 * 2003/04/20: pci_alloc_consistent() provides well over the needed
214 * alignment on a 256 bytes boundary for the LAN API private area.
215 * Thus it isn't needed anymore to align it by hand.
217 pDpa
->msgbuf
= pci_alloc_consistent (pdev
, MSG_BUF_SIZE
,
220 printk (KERN_ERR
"(rcpci45 driver:) \
221 Could not allocate %d byte memory for the \
222 private msgbuf!\n", MSG_BUF_SIZE
);
224 goto err_out_free_dev
;
227 /* The adapter is accessible through memory-access read/write, not
228 * I/O read/write. Thus, we need to map it to some virtual address
229 * area in order to access the registers as normal memory.
231 error
= pci_request_regions (pdev
, dev
->name
);
233 goto err_out_free_msgbuf
;
235 error
= pci_set_dma_mask (pdev
, RCPCI45_DMA_MASK
);
238 "(rcpci45 driver:) pci_set_dma_mask failed!\n");
239 goto err_out_free_region
;
242 vaddr
= (ulong
*) ioremap (pci_start
, pci_len
);
246 Unable to remap address range from %lu to %lu\n",
247 pci_start
, pci_start
+ pci_len
);
249 goto err_out_free_region
;
252 dev
->base_addr
= (unsigned long) vaddr
;
253 dev
->irq
= pdev
->irq
;
255 dev
->hard_start_xmit
= &RC_xmit_packet
;
256 dev
->stop
= &RCclose
;
257 dev
->get_stats
= &RCget_stats
;
258 dev
->do_ioctl
= &RCioctl
;
259 dev
->set_config
= &RCconfig
;
261 if ((error
= register_netdev(dev
)))
262 goto err_out_free_region
;
264 return 0; /* success */
267 pci_release_regions (pdev
);
269 pci_free_consistent (pdev
, MSG_BUF_SIZE
, pDpa
->msgbuf
,
278 static struct pci_driver rcpci45_driver
= {
280 .id_table
= rcpci45_pci_table
,
281 .probe
= rcpci45_init_one
,
282 .remove
= __devexit_p(rcpci45_remove_one
),
286 rcpci_init_module (void)
288 int rc
= pci_module_init (&rcpci45_driver
);
290 printk (KERN_ERR
"%s", version
);
295 RCopen (struct net_device
*dev
)
297 int post_buffers
= MAX_NMBR_RCV_BUFFERS
;
298 PDPA pDpa
= dev
->priv
;
304 /* This is not the first time RCopen is called. Thus,
305 * the interface was previously opened and later closed
306 * by RCclose(). RCclose() does a Shutdown; to wake up
307 * the adapter, a reset is mandatory before we can post
308 * receive buffers. However, if the adapter initiated
309 * a reboot while the interface was closed -- and interrupts
310 * were turned off -- we need will need to reinitialize
311 * the adapter, rather than simply waking it up.
313 printk (KERN_INFO
"Waking up adapter...\n");
314 RCResetLANCard (dev
, 0, 0, 0);
318 * RCInitI2OMsgLayer is done only once, unless the
319 * adapter was sent a warm reboot
321 error
= RCInitI2OMsgLayer (dev
, (PFNTXCALLBACK
) RCxmit_callback
,
322 (PFNRXCALLBACK
) RCrecv_callback
,
323 (PFNCALLBACK
) RCreboot_callback
);
325 printk (KERN_ERR
"%s: Unable to init msg layer (%x)\n",
329 if ((error
= RCGetMAC (dev
, NULL
))) {
330 printk (KERN_ERR
"%s: Unable to get adapter MAC\n",
336 /* Request a shared interrupt line. */
337 error
= request_irq (dev
->irq
, RCinterrupt
, SA_SHIRQ
, dev
->name
, dev
);
339 printk (KERN_ERR
"%s: unable to get IRQ %d\n",
340 dev
->name
, dev
->irq
);
344 DriverControlWord
|= WARM_REBOOT_CAPABLE
;
345 RCReportDriverCapability (dev
, DriverControlWord
);
347 printk (KERN_INFO
"%s: RedCreek Communications IPSEC VPN adapter\n",
350 RCEnableI2OInterrupts (dev
);
352 while (post_buffers
) {
353 if (post_buffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
)
354 requested
= MAX_NMBR_POST_BUFFERS_PER_MSG
;
356 requested
= post_buffers
;
357 count
= RC_allocate_and_post_buffers (dev
, requested
);
359 if (count
< requested
) {
361 * Check to see if we were able to post
362 * any buffers at all.
364 if (post_buffers
== MAX_NMBR_RCV_BUFFERS
) {
365 printk (KERN_ERR
"%s: \
366 unable to allocate any buffers\n",
368 goto err_out_free_irq
;
370 printk (KERN_WARNING
"%s: \
371 unable to allocate all requested buffers\n", dev
->name
);
372 break; /* we'll try to post more buffers later */
374 post_buffers
-= count
;
376 pDpa
->numOutRcvBuffers
= MAX_NMBR_RCV_BUFFERS
- post_buffers
;
377 pDpa
->shutdown
= 0; /* just in case */
378 netif_start_queue (dev
);
382 free_irq (dev
->irq
, dev
);
388 RC_xmit_packet (struct sk_buff
*skb
, struct net_device
*dev
)
391 PDPA pDpa
= dev
->priv
;
393 psingleTCB ptcb
= &tcb
;
394 RC_RETURN status
= 0;
396 netif_stop_queue (dev
);
398 if (pDpa
->shutdown
|| pDpa
->reboot
) {
399 printk ("RC_xmit_packet: tbusy!\n");
404 * The user is free to reuse the TCB after RCI2OSendPacket()
405 * returns, since the function copies the necessary info into its
406 * own private space. Thus, our TCB can be a local structure.
407 * The skb, on the other hand, will be freed up in our interrupt
414 * we'll get the context when the adapter interrupts us to tell us that
415 * the transmission is done. At that time, we can free skb.
417 ptcb
->b
.context
= (U32
) skb
;
419 ptcb
->b
.size
= skb
->len
;
420 ptcb
->b
.addr
= pci_map_single(pDpa
->pci_dev
, skb
->data
, skb
->len
,
423 if ((status
= RCI2OSendPacket (dev
, (U32
) NULL
, (PRCTCB
) ptcb
))
424 != RC_RTN_NO_ERROR
) {
425 printk ("%s: send error 0x%x\n", dev
->name
, (uint
) status
);
428 dev
->trans_start
= jiffies
;
429 netif_wake_queue (dev
);
440 * The transmit callback routine. It's called by RCProcI2OMsgQ()
441 * because the adapter is done with one or more transmit buffers and
442 * it's returning them to us, or we asked the adapter to return the
443 * outstanding transmit buffers by calling RCResetLANCard() with
444 * RC_RESOURCE_RETURN_PEND_TX_BUFFERS flag.
445 * All we need to do is free the buffers.
448 RCxmit_callback (U32 Status
,
449 U16 PcktCount
, PU32 BufferContext
, struct net_device
*dev
)
452 PDPA pDpa
= dev
->priv
;
455 printk (KERN_ERR
"%s: Fatal Error in xmit callback, !pDpa\n",
460 if (Status
!= I2O_REPLY_STATUS_SUCCESS
)
461 printk (KERN_INFO
"%s: xmit_callback: Status = 0x%x\n",
462 dev
->name
, (uint
) Status
);
463 if (pDpa
->shutdown
|| pDpa
->reboot
)
464 printk (KERN_INFO
"%s: xmit callback: shutdown||reboot\n",
467 while (PcktCount
--) {
468 skb
= (struct sk_buff
*) (BufferContext
[0]);
470 pci_unmap_single(pDpa
->pci_dev
, BufferContext
[1], skb
->len
,
472 dev_kfree_skb_irq (skb
);
474 netif_wake_queue (dev
);
478 RCreset_callback (U32 Status
, U32 p1
, U32 p2
, struct net_device
*dev
)
480 PDPA pDpa
= dev
->priv
;
482 printk ("RCreset_callback Status 0x%x\n", (uint
) Status
);
484 * Check to see why we were called.
486 if (pDpa
->shutdown
) {
487 printk (KERN_INFO
"%s: shutting down interface\n",
491 } else if (pDpa
->reboot
) {
492 printk (KERN_INFO
"%s: reboot, shutdown adapter\n",
495 * We don't set any of the flags in RCShutdownLANCard()
496 * and we don't pass a callback routine to it.
497 * The adapter will have already initiated the reboot by
498 * the time the function returns.
500 RCDisableI2OInterrupts (dev
);
501 RCShutdownLANCard (dev
, 0, 0, 0);
502 printk (KERN_INFO
"%s: scheduling timer...\n", dev
->name
);
503 init_timer (&pDpa
->timer
);
504 pDpa
->timer
.expires
= RUN_AT ((40 * HZ
) / 10); /* 4 sec. */
505 pDpa
->timer
.data
= (unsigned long) dev
;
506 pDpa
->timer
.function
= &rc_timer
; /* timer handler */
507 add_timer (&pDpa
->timer
);
512 RCreboot_callback (U32 Status
, U32 p1
, U32 p2
, struct net_device
*dev
)
514 PDPA pDpa
= dev
->priv
;
516 printk (KERN_INFO
"%s: reboot: rcv buffers outstanding = %d\n",
517 dev
->name
, (uint
) pDpa
->numOutRcvBuffers
);
519 if (pDpa
->shutdown
) {
520 printk (KERN_INFO
"%s: skip reboot, shutdown initiated\n",
526 * OK, we reset the adapter and ask it to return all
527 * outstanding transmit buffers as well as the posted
528 * receive buffers. When the adapter is done returning
529 * those buffers, it will call our RCreset_callback()
530 * routine. In that routine, we'll call RCShutdownLANCard()
531 * to tell the adapter that it's OK to start the reboot and
532 * schedule a timer callback routine to execute 3 seconds
533 * later; this routine will reinitialize the adapter at that time.
535 RCResetLANCard (dev
, RC_RESOURCE_RETURN_POSTED_RX_BUCKETS
|
536 RC_RESOURCE_RETURN_PEND_TX_BUFFERS
, 0,
537 (PFNCALLBACK
) RCreset_callback
);
543 * The receive packet callback routine. This is called by
544 * RCProcI2OMsgQ() after the adapter posts buffers which have been
545 * filled (one ethernet packet per buffer).
548 RCrecv_callback (U32 Status
,
551 PU32 PacketDescBlock
, struct net_device
*dev
)
555 PDPA pDpa
= dev
->priv
;
558 psingleTCB ptcb
= &tcb
;
562 if ((pDpa
->shutdown
|| pDpa
->reboot
) && !Status
)
563 printk (KERN_INFO
"%s: shutdown||reboot && !Status (%d)\n",
564 dev
->name
, PktCount
);
566 if ((Status
!= I2O_REPLY_STATUS_SUCCESS
) || pDpa
->shutdown
) {
568 * Free whatever buffers the adapter returned, but don't
569 * pass them to the kernel.
572 if (!pDpa
->shutdown
&& !pDpa
->reboot
)
573 printk (KERN_INFO
"%s: recv error status = 0x%x\n",
574 dev
->name
, (uint
) Status
);
576 printk (KERN_DEBUG
"%s: Returning %d buffs stat 0x%x\n",
577 dev
->name
, PktCount
, (uint
) Status
);
579 * TO DO: check the nature of the failure and put the
580 * adapter in failed mode if it's a hard failure.
581 * Send a reset to the adapter and free all outstanding memory.
583 if (PacketDescBlock
) {
585 skb
= (struct sk_buff
*) PacketDescBlock
[0];
587 pDpa
->numOutRcvBuffers
--;
588 /* point to next context field */
589 PacketDescBlock
+= BD_SIZE
;
595 skb
= (struct sk_buff
*) PacketDescBlock
[0];
596 len
= PacketDescBlock
[2];
598 skb_put (skb
, len
); /* adjust length and tail */
599 skb
->protocol
= eth_type_trans (skb
, dev
);
600 netif_rx (skb
); /* send the packet to the kernel */
601 dev
->last_rx
= jiffies
;
602 pDpa
->numOutRcvBuffers
--;
603 /* point to next context field */
604 PacketDescBlock
+= BD_SIZE
;
609 * Replenish the posted receive buffers.
610 * DO NOT replenish buffers if the driver has already
611 * initiated a reboot or shutdown!
614 if (!pDpa
->shutdown
&& !pDpa
->reboot
) {
615 count
= RC_allocate_and_post_buffers (dev
,
616 MAX_NMBR_RCV_BUFFERS
-
617 pDpa
->numOutRcvBuffers
);
618 pDpa
->numOutRcvBuffers
+= count
;
627 * This routine sets up a couple of pointers and calls
628 * RCProcI2OMsgQ(), which in turn process the message and
629 * calls one of our callback functions.
632 RCinterrupt (int irq
, void *dev_id
, struct pt_regs
*regs
)
636 struct net_device
*dev
= dev_id
;
641 printk (KERN_DEBUG
"%s: shutdown, service irq\n",
644 return RCProcI2OMsgQ (dev
);
647 #define REBOOT_REINIT_RETRY_LIMIT 4
649 rc_timer (unsigned long data
)
651 struct net_device
*dev
= (struct net_device
*) data
;
652 PDPA pDpa
= dev
->priv
;
655 int post_buffers
= MAX_NMBR_RCV_BUFFERS
;
661 RCInitI2OMsgLayer (dev
, (PFNTXCALLBACK
) RCxmit_callback
,
662 (PFNRXCALLBACK
) RCrecv_callback
,
663 (PFNCALLBACK
) RCreboot_callback
);
665 switch (init_status
) {
666 case RC_RTN_NO_ERROR
:
669 pDpa
->shutdown
= 0; /* just in case */
670 RCReportDriverCapability (dev
, DriverControlWord
);
671 RCEnableI2OInterrupts (dev
);
674 if (!(dev
->flags
& IFF_UP
)) {
678 while (post_buffers
) {
680 MAX_NMBR_POST_BUFFERS_PER_MSG
)
682 MAX_NMBR_POST_BUFFERS_PER_MSG
;
684 requested
= post_buffers
;
686 RC_allocate_and_post_buffers (dev
,
688 post_buffers
-= count
;
689 if (count
< requested
)
692 pDpa
->numOutRcvBuffers
=
693 MAX_NMBR_RCV_BUFFERS
- post_buffers
;
694 printk ("Initialization done.\n");
695 netif_wake_queue (dev
);
698 case RC_RTN_FREE_Q_EMPTY
:
700 printk (KERN_WARNING
"%s inbound free q empty\n",
705 printk (KERN_WARNING
"%s bad stat after reboot: %d\n",
706 dev
->name
, init_status
);
710 if (retry
> REBOOT_REINIT_RETRY_LIMIT
) {
711 printk (KERN_WARNING
"%s unable to reinitialize adapter after reboot\n", dev
->name
);
712 printk (KERN_WARNING
"%s shutting down interface\n", dev
->name
);
713 RCDisableI2OInterrupts (dev
);
714 dev
->flags
&= ~IFF_UP
;
716 printk (KERN_INFO
"%s: rescheduling timer...\n",
718 init_timer (&pDpa
->timer
);
719 pDpa
->timer
.expires
= RUN_AT ((40 * HZ
) / 10);
720 pDpa
->timer
.data
= (unsigned long) dev
;
721 pDpa
->timer
.function
= &rc_timer
;
722 add_timer (&pDpa
->timer
);
725 printk (KERN_WARNING
"%s: unexpected timer irq\n", dev
->name
);
729 RCclose (struct net_device
*dev
)
731 PDPA pDpa
= dev
->priv
;
734 netif_stop_queue (dev
);
737 printk (KERN_INFO
"%s skipping reset -- adapter already in reboot mode\n", dev
->name
);
738 dev
->flags
&= ~IFF_UP
;
746 * We can't allow the driver to be unloaded until the adapter returns
747 * all posted receive buffers. It doesn't hurt to tell the adapter
748 * to return all posted receive buffers and outstanding xmit buffers,
749 * even if there are none.
752 RCShutdownLANCard (dev
, RC_RESOURCE_RETURN_POSTED_RX_BUCKETS
|
753 RC_RESOURCE_RETURN_PEND_TX_BUFFERS
, 0,
754 (PFNCALLBACK
) RCreset_callback
);
756 dev
->flags
&= ~IFF_UP
;
760 static struct net_device_stats
*
761 RCget_stats (struct net_device
*dev
)
765 PDPA pDpa
= dev
->priv
;
769 } else if (!(dev
->flags
& IFF_UP
)) {
773 memset (&RCstats
, 0, sizeof (RCLINKSTATS
));
774 if ((RCGetLinkStatistics (dev
, &RCstats
, (void *) 0)) ==
777 /* total packets received */
778 pDpa
->stats
.rx_packets
= RCstats
.Rcv_good
779 /* total packets transmitted */;
780 pDpa
->stats
.tx_packets
= RCstats
.TX_good
;
782 pDpa
->stats
.rx_errors
= RCstats
.Rcv_CRCerr
+
783 RCstats
.Rcv_alignerr
+ RCstats
.Rcv_reserr
+
784 RCstats
.Rcv_orun
+ RCstats
.Rcv_cdt
+ RCstats
.Rcv_runt
;
786 pDpa
->stats
.tx_errors
= RCstats
.TX_urun
+ RCstats
.TX_crs
+
787 RCstats
.TX_def
+ RCstats
.TX_totcol
;
790 * This needs improvement.
792 pDpa
->stats
.rx_dropped
= 0; /* no space in linux buffers */
793 pDpa
->stats
.tx_dropped
= 0; /* no space available in linux */
794 pDpa
->stats
.multicast
= 0; /* multicast packets received */
795 pDpa
->stats
.collisions
= RCstats
.TX_totcol
;
797 /* detailed rx_errors: */
798 pDpa
->stats
.rx_length_errors
= 0;
799 pDpa
->stats
.rx_over_errors
= RCstats
.Rcv_orun
;
800 pDpa
->stats
.rx_crc_errors
= RCstats
.Rcv_CRCerr
;
801 pDpa
->stats
.rx_frame_errors
= 0;
802 pDpa
->stats
.rx_fifo_errors
= 0;
803 pDpa
->stats
.rx_missed_errors
= 0;
805 /* detailed tx_errors */
806 pDpa
->stats
.tx_aborted_errors
= 0;
807 pDpa
->stats
.tx_carrier_errors
= 0;
808 pDpa
->stats
.tx_fifo_errors
= 0;
809 pDpa
->stats
.tx_heartbeat_errors
= 0;
810 pDpa
->stats
.tx_window_errors
= 0;
812 return ((struct net_device_stats
*) &(pDpa
->stats
));
818 RCioctl (struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
820 RCuser_struct RCuser
;
821 PDPA pDpa
= dev
->priv
;
823 if (!capable (CAP_NET_ADMIN
))
828 case RCU_PROTOCOL_REV
:
830 * Assign user protocol revision, to tell user-level
831 * controller program whether or not it's in sync.
833 rq
->ifr_ifru
.ifru_data
= (caddr_t
) USER_PROTOCOL_REV
;
839 (&RCuser
, rq
->ifr_data
, sizeof (RCuser
)))
842 dprintk ("RCioctl: RCuser_cmd = 0x%x\n", RCuser
.cmd
);
844 switch (RCuser
.cmd
) {
846 RCUD_GETFWVER
= &RCuser
.RCUS_GETFWVER
;
847 RCGetFirmwareVer (dev
,
848 (PU8
) & RCUD_GETFWVER
->
852 RCUD_GETINFO
= &RCuser
.RCUS_GETINFO
;
853 RCUD_GETINFO
->mem_start
= dev
->base_addr
;
854 RCUD_GETINFO
->mem_end
=
855 dev
->base_addr
+ pDpa
->pci_addr_len
;
856 RCUD_GETINFO
->base_addr
= pDpa
->pci_addr
;
857 RCUD_GETINFO
->irq
= dev
->irq
;
859 case RCUC_GETIPANDMASK
:
860 RCUD_GETIPANDMASK
= &RCuser
.RCUS_GETIPANDMASK
;
861 RCGetRavlinIPandMask (dev
,
863 RCUD_GETIPANDMASK
->IpAddr
,
868 case RCUC_GETLINKSTATISTICS
:
869 RCUD_GETLINKSTATISTICS
=
870 &RCuser
.RCUS_GETLINKSTATISTICS
;
871 RCGetLinkStatistics (dev
,
873 RCUD_GETLINKSTATISTICS
->
876 case RCUC_GETLINKSTATUS
:
877 RCUD_GETLINKSTATUS
= &RCuser
.RCUS_GETLINKSTATUS
;
878 RCGetLinkStatus (dev
,
879 (PU32
) & RCUD_GETLINKSTATUS
->
883 RCUD_GETMAC
= &RCuser
.RCUS_GETMAC
;
884 RCGetMAC (dev
, NULL
);
885 memcpy(RCUD_GETMAC
, dev
->dev_addr
, 8);
888 RCUD_GETPROM
= &RCuser
.RCUS_GETPROM
;
889 RCGetPromiscuousMode (dev
,
890 (PU32
) & RCUD_GETPROM
->
893 case RCUC_GETBROADCAST
:
894 RCUD_GETBROADCAST
= &RCuser
.RCUS_GETBROADCAST
;
895 RCGetBroadcastMode (dev
,
896 (PU32
) & RCUD_GETBROADCAST
->
897 BroadcastMode
, NULL
);
900 if (!(dev
->flags
& IFF_UP
)) {
903 RCUD_GETSPEED
= &RCuser
.RCUS_GETSPEED
;
905 (PU32
) & RCUD_GETSPEED
->
906 LinkSpeedCode
, NULL
);
908 case RCUC_SETIPANDMASK
:
909 RCUD_SETIPANDMASK
= &RCuser
.RCUS_SETIPANDMASK
;
910 RCSetRavlinIPandMask (dev
,
911 (U32
) RCUD_SETIPANDMASK
->
913 (U32
) RCUD_SETIPANDMASK
->
917 RCSetMAC (dev
, (PU8
) & RCUD_SETMAC
->mac
);
920 RCUD_SETSPEED
= &RCuser
.RCUS_SETSPEED
;
922 (U16
) RCUD_SETSPEED
->
926 RCUD_SETPROM
= &RCuser
.RCUS_SETPROM
;
927 RCSetPromiscuousMode (dev
,
931 case RCUC_SETBROADCAST
:
932 RCUD_SETBROADCAST
= &RCuser
.RCUS_SETBROADCAST
;
933 RCSetBroadcastMode (dev
,
934 (U16
) RCUD_SETBROADCAST
->
938 RCUD_DEFAULT
= &RCuser
.RCUS_DEFAULT
;
939 RCUD_DEFAULT
->rc
= 0x11223344;
942 if (copy_to_user (rq
->ifr_data
, &RCuser
,
949 rq
->ifr_ifru
.ifru_data
= (caddr_t
) 0x12345678;
956 RCconfig (struct net_device
*dev
, struct ifmap
*map
)
959 * To be completed ...
962 if (dev
->flags
& IFF_UP
) /* can't act on a running interface */
965 /* Don't allow changing the I/O address */
966 if (map
->base_addr
!= dev
->base_addr
) {
967 printk (KERN_WARNING
"%s Change I/O address not implemented\n",
975 rcpci_cleanup_module (void)
977 pci_unregister_driver (&rcpci45_driver
);
980 module_init (rcpci_init_module
);
981 module_exit (rcpci_cleanup_module
);
984 RC_allocate_and_post_buffers (struct net_device
*dev
, int numBuffers
)
991 PDPA pDpa
= dev
->priv
;
997 else if (numBuffers
> MAX_NMBR_POST_BUFFERS_PER_MSG
) {
998 printk (KERN_ERR
"%s: Too many buffers requested!\n",
1003 p
= (PU32
) kmalloc (sizeof (U32
) + numBuffers
* sizeof (singleB
),
1004 GFP_DMA
| GFP_ATOMIC
);
1007 printk (KERN_WARNING
"%s unable to allocate TCB\n",
1012 p
[0] = 0; /* Buffer Count */
1013 pB
= (psingleB
) ((U32
) p
+ sizeof (U32
));/* point to the first buffer */
1015 for (i
= 0; i
< numBuffers
; i
++) {
1016 skb
= dev_alloc_skb (MAX_ETHER_SIZE
+ 2);
1018 printk (KERN_WARNING
1019 "%s: unable to allocate enough skbs!\n",
1023 skb_reserve (skb
, 2); /* Align IP on 16 byte boundaries */
1024 pB
->context
= (U32
) skb
;
1025 pB
->scount
= 1; /* segment count */
1026 pB
->size
= MAX_ETHER_SIZE
;
1027 pB
->addr
= pci_map_single(pDpa
->pci_dev
, skb
->data
,
1028 MAX_ETHER_SIZE
, PCI_DMA_FROMDEVICE
);
1033 if ((status
= RCPostRecvBuffers (dev
, (PRCTCB
) p
)) != RC_RTN_NO_ERROR
) {
1034 printk (KERN_WARNING
"%s: Post buffer failed, error 0x%x\n",
1042 return (res
); /* return the number of posted buffers */
1045 for (; p
[0] > 0; p
[0]--) {
1047 skb
= (struct sk_buff
*) pB
->context
;
1048 pci_unmap_single(pDpa
->pci_dev
, pB
->addr
, MAX_ETHER_SIZE
,
1049 PCI_DMA_FROMDEVICE
);
1050 dev_kfree_skb (skb
);