Import 2.3.27pre3
[davej-history.git] / drivers / net / rcpci45.c
blob746455bf0b591fa622284eb93fed8e3f1589ec8c
1 /*
2 **
3 ** RCpci45.c
4 **
5 **
6 **
7 ** ---------------------------------------------------------------------
8 ** --- Copyright (c) 1998, 1999, RedCreek Communications Inc. ---
9 ** --- All rights reserved. ---
10 ** ---------------------------------------------------------------------
12 ** Written by Pete Popov and Brian Moyle.
14 ** Known Problems
15 **
16 ** None known at this time.
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.
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.
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.
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>
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/timer.h>
67 #include <asm/irq.h> /* For NR_IRQS only. */
68 #include <asm/bitops.h>
69 #include <asm/io.h>
71 #if LINUX_VERSION_CODE >= 0x020100
72 #define LINUX_2_1
73 #endif
75 #ifdef LINUX_2_1
76 #include <asm/uaccess.h>
77 #endif
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
86 #include "rclanmtl.h"
87 #include "rcif.h"
89 #define RUN_AT(x) (jiffies + (x))
91 #define NEW_MULTICAST
92 #include <linux/delay.h>
94 #ifndef LINUX_2_1
95 #define ioremap vremap
96 #define iounmap vfree
97 #endif
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.
123 typedef struct
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 */
135 U32 bus;
136 U32 function;
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;
143 unsigned char nexus;
144 PU8 PLanApiPA; /* Pointer to Lan Api Private Area */
147 DPA, *PDPA;
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;
181 #ifdef MODULE
182 int init_module(void)
183 #else
184 int rcpci_probe(void)
185 #endif
187 int cards_found;
189 cards_found = RCscan();
190 if (cards_found)
191 printk(version);
192 return cards_found ? 0 : -ENODEV;
195 static int RCscan(void)
197 int cards_found = 0;
198 static int pci_index = 0;
200 if (!pcibios_present())
201 return cards_found;
203 for (;pci_index < 0x8; pci_index++)
205 unsigned char pci_bus, pci_device_fn;
206 int scan_status;
207 int board_index = 0;
208 unsigned char pci_irq_line;
209 unsigned int pci_ioaddr;
210 struct pci_dev *pdev;
212 scan_status =
213 (pcibios_find_device (RC_PCI45_VENDOR_ID,
214 RC_PCI45_DEVICE_ID,
215 pci_index,
216 &pci_bus,
217 &pci_device_fn));
218 #ifdef RCDEBUG
219 printk("rc scan_status = 0x%X\n", scan_status);
220 #endif
221 if (scan_status != PCIBIOS_SUCCESSFUL ||
222 !((pdev = pci_find_slot(pci_bus, pci_device_fn))))
223 break;
224 pci_irq_line = pdev->irq;
225 pci_ioaddr = pdev->resource[0].start;
227 #ifdef RCDEBUG
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);
232 #endif
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))
239 cards_found++;
241 #ifdef RCDEBUG
242 printk("rc: found %d cards \n", cards_found);
243 #endif
244 return cards_found;
247 static int RCinit(struct net_device *dev)
249 dev->open = &RCopen;
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;
255 return 0;
258 static int
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;
264 PDPA pDpa;
265 int init_status;
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
275 * the LAN API layer.
278 dev = (struct net_device *) kmalloc(dev_size, GFP_DMA | GFP_KERNEL |GFP_ATOMIC);
279 if (!dev)
281 printk("rc: unable to kmalloc dev\n");
282 return 1;
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);
290 #ifdef RCDEBUG
291 printk("rc: dev = 0x%x, dev->priv = 0x%x\n", (uint)dev, (uint)dev->priv);
292 #endif
294 pDpa = dev->priv;
295 if (!dev->name)
296 dev->name = pDpa->devname;
298 pDpa->dev = dev; /* this is just for easy reference */
299 pDpa->function = function;
300 pDpa->bus = bus;
301 pDpa->id = card_idx; /* the device number */
302 pDpa->pci_addr = memaddr;
303 PCIAdapters[card_idx] = pDpa;
304 #ifdef RCDEBUG
305 printk("rc: pDpa = 0x%x, id = %d \n", (uint)pDpa, (uint)pDpa->id);
306 #endif
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);
313 #ifdef RCDEBUG
314 printk("rc: pDpa->PLanApiPA = 0x%x\n", (uint)pDpa->PLanApiPA);
315 #endif
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);
322 #ifdef RCDEBUG
323 printk("rc: RCfound_device: 0x%x, priv = 0x%x, vaddr = 0x%x\n",
324 (uint)dev, (uint)dev->priv, (uint)vaddr);
325 #endif
326 dev->base_addr = (unsigned long)vaddr;
327 dev->irq = irq;
328 dev->interrupt = 0;
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 );
337 iounmap(vaddr);
338 kfree(dev);
339 return 1;
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);
347 if (init_status)
349 printk("rc: Unable to initialize msg layer\n");
350 free_irq(dev->irq, dev);
351 iounmap(vaddr);
352 kfree(dev);
353 return 1;
355 if (RCGetMAC(pDpa->id, dev->dev_addr, NULL))
357 printk("rc: Unable to get adapter MAC\n");
358 free_irq(dev->irq, dev);
359 iounmap(vaddr);
360 kfree(dev);
361 return 1;
364 DriverControlWord |= WARM_REBOOT_CAPABLE;
365 RCReportDriverCapability(pDpa->id, DriverControlWord);
367 dev->init = &RCinit;
368 ether_setup(dev); /* linux kernel interface */
370 pDpa->next = root_RCdev;
371 root_RCdev = dev;
373 if (register_netdev(dev) != 0) /* linux kernel interface */
375 printk("rc: unable to register device \n");
376 free_irq(dev->irq, dev);
377 iounmap(vaddr);
378 kfree(dev);
379 return 1;
381 printk("%s: RedCreek Communications IPSEC VPN adapter\n",
382 dev->name);
384 return 0; /* success */
387 static int
388 RCopen(struct net_device *dev)
390 int post_buffers = MAX_NMBR_RCV_BUFFERS;
391 PDPA pDpa = (PDPA) dev->priv;
392 int count = 0;
393 int requested = 0;
395 #ifdef RCDEBUG
396 printk("rc: RCopen\n");
397 #endif
398 RCEnableI2OInterrupts(pDpa->id);
400 if (pDpa->nexus)
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);
414 else
416 pDpa->nexus = 1;
419 while(post_buffers)
421 if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
422 requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
423 else
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");
435 return(-ENOMEM);
437 printk("rc: Warning RCopen: not able to allocate all requested buffers\r\n");
438 break; /* we'll try to post more buffers later */
440 else
441 post_buffers -= count;
443 pDpa->numOutRcvBuffers = MAX_NMBR_RCV_BUFFERS - post_buffers;
444 pDpa->shutdown = 0; /* just in case */
445 #ifdef RCDEBUG
446 printk("rc: RCopen: posted %d buffers\n", (uint)pDpa->numOutRcvBuffers);
447 #endif
448 MOD_INC_USE_COUNT;
449 return 0;
452 static int
453 RC_xmit_packet(struct sk_buff *skb, struct net_device *dev)
456 PDPA pDpa = (PDPA) dev->priv;
457 singleTCB tcb;
458 psingleTCB ptcb = &tcb;
459 RC_RETURN status = 0;
461 if (dev->tbusy || pDpa->shutdown || pDpa->reboot)
463 #ifdef RCDEBUG
464 printk("rc: RC_xmit_packet: tbusy!\n");
465 #endif
466 dev->tbusy = 1;
467 return 1;
470 if ( skb->len <= 0 )
472 printk("RC_xmit_packet: skb->len less than 0!\n");
473 return 0;
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.
482 ptcb->bcount = 1;
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;
488 ptcb->b.scount = 1;
489 ptcb->b.size = skb->len;
490 ptcb->b.addr = virt_to_bus((void *)skb->data);
492 #ifdef RCDEBUG
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);
495 #endif
496 if ( (status = RCI2OSendPacket(pDpa->id, (U32)NULL, (PRCTCB)ptcb))
497 != RC_RTN_NO_ERROR)
499 #ifdef RCDEBUG
500 printk("rc: RC send error 0x%x\n", (uint)status);
501 #endif
502 dev->tbusy = 1;
503 return 1;
505 else
507 dev->trans_start = jiffies;
508 // dev->tbusy = 0;
511 * That's it!
513 return 0;
517 * RCxmit_callback()
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.
526 static void
527 RCxmit_callback(U32 Status,
528 U16 PcktCount,
529 PU32 BufferContext,
530 U16 AdapterID)
532 struct sk_buff *skb;
533 PDPA pDpa;
534 struct net_device *dev;
536 pDpa = PCIAdapters[AdapterID];
537 if (!pDpa)
539 printk("rc: Fatal error: xmit callback, !pDpa\n");
540 return;
542 dev = pDpa->dev;
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);
549 #ifdef RCDEBUG
550 if (pDpa->shutdown || pDpa->reboot)
551 printk("rc: xmit callback: shutdown||reboot\n");
552 #endif
554 #ifdef RCDEBUG
555 printk("rc: xmit_callback: PcktCount = %d, BC = 0x%x\n",
556 (uint)PcktCount, (uint)BufferContext);
557 #endif
558 while (PcktCount--)
560 skb = (struct sk_buff *)(BufferContext[0]);
561 #ifdef RCDEBUG
562 printk("rc: skb = 0x%x\n", (uint)skb);
563 #endif
564 BufferContext++;
565 #ifdef LINUX_2_1
566 dev_kfree_skb (skb);
567 #else
568 dev_kfree_skb (skb, FREE_WRITE);
569 #endif
571 dev->tbusy = 0;
575 static void
576 RCreset_callback(U32 Status, U32 p1, U32 p2, U16 AdapterID)
578 PDPA pDpa;
579 struct net_device *dev;
581 pDpa = PCIAdapters[AdapterID];
582 dev = pDpa->dev;
583 #ifdef RCDEBUG
584 printk("rc: RCreset_callback Status 0x%x\n", (uint)Status);
585 #endif
587 * Check to see why we were called.
589 if (pDpa->shutdown)
591 printk("rc: Shutting down interface\n");
592 pDpa->shutdown = 0;
593 pDpa->reboot = 0;
594 MOD_DEC_USE_COUNT;
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);
619 static void
620 RCreboot_callback(U32 Status, U32 p1, U32 p2, U16 AdapterID)
622 PDPA pDpa;
624 pDpa = PCIAdapters[AdapterID];
625 #ifdef RCDEBUG
626 printk("rc: RCreboot: rcv buffers outstanding = %d\n",
627 (uint)pDpa->numOutRcvBuffers);
628 #endif
629 if (pDpa->shutdown)
631 printk("rc: skipping reboot sequence -- shutdown already initiated\n");
632 return;
634 pDpa->reboot = 1;
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)
654 int i;
655 for (i=0; i<6; i++)
656 if (address[i] != 0xff) return 0;
658 return 1;
662 * RCrecv_callback()
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).
668 static void
669 RCrecv_callback(U32 Status,
670 U8 PktCount,
671 U32 BucketsRemain,
672 PU32 PacketDescBlock,
673 U16 AdapterID)
676 U32 len, count;
677 PDPA pDpa;
678 struct sk_buff *skb;
679 struct net_device *dev;
680 singleTCB tcb;
681 psingleTCB ptcb = &tcb;
684 pDpa = PCIAdapters[AdapterID];
685 dev = pDpa->dev;
687 ptcb->bcount = 1;
689 #ifdef RCDEBUG
690 printk("rc: RCrecv_callback: 0x%x, 0x%x, 0x%x\n",
691 (uint)PktCount, (uint)BucketsRemain, (uint)PacketDescBlock);
692 #endif
694 #ifdef RCDEBUG
695 if ((pDpa->shutdown || pDpa->reboot) && !Status)
696 printk("shutdown||reboot && !Status: PktCount = %d\n",PktCount);
697 #endif
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);
708 #ifdef RCDEBUG
709 else
710 printk("rc: Returning %d buffers, status = 0x%x\n",
711 PktCount, (uint)Status);
712 #endif
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)
720 #ifdef RCDEBUG
721 printk("RCrecv status ABORT NO DATA TRANSFER\n");
722 #endif
724 /* check for reset status: I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER */
725 if (PacketDescBlock)
727 while(PktCount--)
729 skb = (struct sk_buff *)PacketDescBlock[0];
730 #ifndef LINUX_2_1
731 skb->free = 1;
732 skb->lock = 0;
733 #endif
734 #ifdef RCDEBUG
735 printk("free skb 0x%p\n", skb);
736 #endif
737 #ifdef LINUX_2_1
738 dev_kfree_skb (skb);
739 #else
740 dev_kfree_skb(skb, FREE_READ);
741 #endif
742 pDpa->numOutRcvBuffers--;
743 PacketDescBlock += BD_SIZE; /* point to next context field */
746 return;
748 else
750 while(PktCount--)
752 skb = (struct sk_buff *)PacketDescBlock[0];
753 #ifdef RCDEBUG
754 if (pDpa->shutdown)
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]);
760 #endif
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;
773 ptcb->b.scount = 1;
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");
780 #ifdef LINUX_2_1
781 dev_kfree_skb (skb);
782 #else
783 skb->free = 1;
784 dev_kfree_skb(skb, FREE_READ);
785 #endif
787 else
789 pDpa->numOutRcvBuffers++;
792 else
793 #endif /* PROMISCUOUS_BY_DEFAULT */
795 len = PacketDescBlock[2];
796 skb->dev = dev;
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;
823 * RCinterrupt()
825 * Interrupt handler.
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.
830 static void
831 RCinterrupt(int irq, void *dev_id, struct pt_regs *regs)
834 PDPA pDpa;
835 struct net_device *dev = (struct net_device *)(dev_id);
837 pDpa = (PDPA) (dev->priv);
839 #ifdef RCDEBUG
840 if (pDpa->shutdown)
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);
846 #endif
847 if (dev->interrupt)
848 printk("%s: Re-entering the interrupt handler.\n", dev->name);
849 dev->interrupt = 1;
851 RCProcI2OMsgQ(pDpa->id);
852 dev->interrupt = 0;
854 return;
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);
863 int init_status;
864 static int retry = 0;
865 int post_buffers = MAX_NMBR_RCV_BUFFERS;
866 int count = 0;
867 int requested = 0;
869 if (pDpa->reboot)
871 init_status = RCInitI2OMsgLayer(pDpa->id, dev->base_addr,
872 pDpa->PLanApiPA,
873 (PU8)virt_to_bus((void *)pDpa->PLanApiPA),
874 (PFNTXCALLBACK)RCxmit_callback,
875 (PFNRXCALLBACK)RCrecv_callback,
876 (PFNCALLBACK)RCreboot_callback);
878 switch(init_status)
880 case RC_RTN_NO_ERROR:
882 pDpa->reboot = 0;
883 pDpa->shutdown = 0; /* just in case */
884 RCReportDriverCapability(pDpa->id, DriverControlWord);
885 RCEnableI2OInterrupts(pDpa->id);
887 if (dev->flags & IFF_UP)
889 while(post_buffers)
891 if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
892 requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
893 else
894 requested = post_buffers;
895 count = RC_allocate_and_post_buffers(dev, requested);
896 post_buffers -= count;
897 if ( count < requested )
898 break;
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");
906 dev->tbusy=0;
907 retry=0;
908 return;
909 case RC_RTN_FREE_Q_EMPTY:
910 retry++;
911 printk("rc: inbound free q empty\n");
912 break;
913 default:
914 retry++;
915 printk("rc: bad status after reboot: %d\n", init_status);
916 break;
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;
925 MOD_DEC_USE_COUNT;
927 else
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);
937 else
939 printk("rc: timer??\n");
943 static int
944 RCclose(struct net_device *dev)
947 PDPA pDpa = (PDPA) dev->priv;
949 #ifdef RCDEBUG
950 printk("rc: RCclose\r\n");
951 #endif
952 if (pDpa->reboot)
954 printk("rc: skipping reset -- adapter already in reboot mode\n");
955 dev->flags &= ~IFF_UP;
956 pDpa->shutdown = 1;
957 return 0;
959 #ifdef RCDEBUG
960 printk("rc: receive buffers outstanding: %d\n",
961 (uint)pDpa->numOutRcvBuffers);
962 #endif
964 pDpa->shutdown = 1;
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;
979 return 0;
982 static struct enet_statistics *
983 RCget_stats(struct net_device *dev)
985 RCLINKSTATS RCstats;
987 PDPA pDpa = dev->priv;
989 if (!pDpa)
991 printk("rc: RCget_stats: !pDpa\n");
992 return 0;
994 else if (!(dev->flags & IFF_UP))
996 #ifdef RCDEBUG
997 printk("rc: RCget_stats: device down\n");
998 #endif
999 return 0;
1002 memset(&RCstats, 0, sizeof(RCLINKSTATS));
1003 if ( (RCGetLinkStatistics(pDpa->id, &RCstats, (void *)0)) == RC_RTN_NO_ERROR )
1005 #ifdef RCDEBUG
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);
1023 #endif
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 +
1032 RCstats.Rcv_orun +
1033 RCstats.Rcv_cdt +
1034 RCstats.Rcv_runt; /* bad packets received */
1036 pDpa->stats.tx_errors =
1037 RCstats.TX_urun +
1038 RCstats.TX_crs +
1039 RCstats.TX_def +
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));
1067 return 0;
1070 static int RCioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1072 RCuser_struct RCuser;
1073 PDPA pDpa = dev->priv;
1075 #if RCDEBUG
1076 printk("RCioctl: cmd = 0x%x\n", cmd);
1077 #endif
1079 switch (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;
1087 break;
1090 case RCU_COMMAND:
1092 #ifdef LINUX_2_1
1093 if(copy_from_user(&RCuser, rq->ifr_data, sizeof(RCuser)))
1094 return -EFAULT;
1095 #else
1096 int error;
1097 error=verify_area(VERIFY_WRITE, rq->ifr_data, sizeof(RCuser));
1098 if (error) {
1099 return error;
1101 memcpy_fromfs(&RCuser, rq->ifr_data, sizeof(RCuser));
1102 #endif
1104 #ifdef RCDEBUG
1105 printk("RCioctl: RCuser_cmd = 0x%x\n", RCuser.cmd);
1106 #endif
1108 switch(RCuser.cmd)
1110 case RCUC_GETFWVER:
1111 printk("RC GETFWVER\n");
1112 RCUD_GETFWVER = &RCuser.RCUS_GETFWVER;
1113 RCGetFirmwareVer(pDpa->id, (PU8) &RCUD_GETFWVER->FirmString, NULL);
1114 break;
1115 case RCUC_GETINFO:
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;
1122 break;
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);
1128 break;
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);
1133 break;
1134 case RCUC_GETLINKSTATUS:
1135 printk("RC GETLINKSTATUS\n");
1136 RCUD_GETLINKSTATUS = &RCuser.RCUS_GETLINKSTATUS;
1137 RCGetLinkStatus(pDpa->id, (PU32) &RCUD_GETLINKSTATUS->ReturnStatus, NULL);
1138 break;
1139 case RCUC_GETMAC:
1140 printk("RC GETMAC\n");
1141 RCUD_GETMAC = &RCuser.RCUS_GETMAC;
1142 RCGetMAC(pDpa->id, (PU8) &RCUD_GETMAC->mac, NULL);
1143 break;
1144 case RCUC_GETPROM:
1145 printk("RC GETPROM\n");
1146 RCUD_GETPROM = &RCuser.RCUS_GETPROM;
1147 RCGetPromiscuousMode(pDpa->id, (PU32) &RCUD_GETPROM->PromMode, NULL);
1148 break;
1149 case RCUC_GETBROADCAST:
1150 printk("RC GETBROADCAST\n");
1151 RCUD_GETBROADCAST = &RCuser.RCUS_GETBROADCAST;
1152 RCGetBroadcastMode(pDpa->id, (PU32) &RCUD_GETBROADCAST->BroadcastMode, NULL);
1153 break;
1154 case RCUC_GETSPEED:
1155 printk("RC GETSPEED\n");
1156 if (!(dev->flags & IFF_UP))
1158 printk("RCioctl, GETSPEED error: interface down\n");
1159 return -ENODATA;
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);
1164 break;
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);
1178 break;
1179 case RCUC_SETMAC:
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);
1186 break;
1187 case RCUC_SETSPEED:
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);
1192 break;
1193 case RCUC_SETPROM:
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);
1198 break;
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);
1204 break;
1205 default:
1206 printk("RC command default\n");
1207 RCUD_DEFAULT = &RCuser.RCUS_DEFAULT;
1208 RCUD_DEFAULT -> rc = 0x11223344;
1209 break;
1211 #ifdef LINUX_2_1
1212 copy_to_user(rq->ifr_data, &RCuser, sizeof(RCuser));
1213 #else
1214 memcpy_tofs(rq->ifr_data, &RCuser, sizeof(RCuser));
1215 #endif
1216 break;
1217 } /* RCU_COMMAND */
1219 default:
1220 printk("RC default\n");
1221 rq->ifr_ifru.ifru_data = (caddr_t) 0x12345678;
1222 break;
1224 return 0;
1227 static int RCconfig(struct net_device *dev, struct ifmap *map)
1230 * To be completed ...
1232 printk("rc: RCconfig\n");
1233 return 0;
1234 if (dev->flags & IFF_UP) /* can't act on a running interface */
1235 return -EBUSY;
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");
1240 return -EOPNOTSUPP;
1242 return 0;
1246 #ifdef MODULE
1247 void
1248 cleanup_module(void)
1250 PDPA pDpa;
1251 struct net_device *next;
1254 #ifdef RCDEBUG
1255 printk("rc: RC cleanup_module\n");
1256 printk("rc: root_RCdev = 0x%x\n", (uint)root_RCdev);
1257 #endif
1260 while (root_RCdev)
1262 pDpa = (PDPA) root_RCdev->priv;
1263 #ifdef RCDEBUG
1264 printk("rc: cleanup 0x%08X\n", (uint)root_RCdev);
1265 #endif
1266 printk("IOP reset: 0x%x\n", RCResetIOP(pDpa->id));
1267 unregister_netdev(root_RCdev);
1268 next = pDpa->next;
1270 iounmap((unsigned long *)root_RCdev->base_addr);
1271 free_irq( root_RCdev->irq, root_RCdev );
1272 kfree(root_RCdev);
1273 root_RCdev = next;
1276 #endif
1279 static int
1280 RC_allocate_and_post_buffers(struct net_device *dev, int numBuffers)
1283 int i;
1284 PDPA pDpa = (PDPA)dev->priv;
1285 PU32 p;
1286 psingleB pB;
1287 struct sk_buff *skb;
1288 RC_RETURN status;
1290 if (!numBuffers)
1291 return 0;
1292 else if (numBuffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
1294 #ifdef RCDEBUG
1295 printk("rc: Too many buffers requested!\n");
1296 printk("rc: attempting to allocate only 32 buffers\n");
1297 #endif
1298 numBuffers = 32;
1301 p = (PU32) kmalloc(sizeof(U32) + numBuffers*sizeof(singleB), GFP_ATOMIC);
1303 #ifdef RCDEBUG
1304 printk("rc: TCB = 0x%x\n", (uint)p);
1305 #endif
1307 if (!p)
1309 printk("rc: RCopen: unable to allocate TCB\n");
1310 return 0;
1313 p[0] = 0; /* Buffer Count */
1314 pB = (psingleB)((U32)p + sizeof(U32)); /* point to the first buffer */
1316 #ifdef RCDEBUG
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);
1319 #endif
1321 for (i=0; i<numBuffers; i++)
1323 skb = dev_alloc_skb(MAX_ETHER_SIZE+2);
1324 if (!skb)
1326 printk("rc: Doh! RCopen: unable to allocate enough skbs!\n");
1327 if (*p != 0) /* did we allocate any buffers at all? */
1329 #ifdef RCDEBUG
1330 printk("rc: will post only %d buffers \n", (uint)(*p));
1331 #endif
1332 break;
1334 else
1336 kfree(p); /* Free the TCB */
1337 return 0;
1340 #ifdef RCDEBUG
1341 printk("post 0x%x\n", (uint)skb);
1342 #endif
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);
1348 p[0]++;
1349 pB++;
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 */
1356 while(p[0])
1358 skb = (struct sk_buff *)pB->context;
1359 #ifndef LINUX_2_1
1360 skb->free = 1;
1361 #endif
1362 #ifdef RCDEBUG
1363 printk("rc: freeing 0x%x\n", (uint)skb);
1364 #endif
1365 #ifdef LINUX_2_1
1366 dev_kfree_skb (skb);
1367 #else
1368 dev_kfree_skb(skb, FREE_READ);
1369 #endif
1370 p[0]--;
1371 pB++;
1373 #ifdef RCDEBUG
1374 printk("rc: freed all buffers, p[0] = %ld\n", p[0]);
1375 #endif
1377 kfree(p);
1378 return(p[0]); /* return the number of posted buffers */