Import 2.3.18pre1
[davej-history.git] / drivers / net / rcpci45.c
blob1b7b2d61817db3ddb86fc1cb94081011fdc67c47
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(struct net_device *dev);
162 static int RCfound_device(struct net_device *, int, int, int, int, int, int);
164 static int RCopen(struct net_device *);
165 static int RC_xmit_packet(struct sk_buff *, struct net_device *);
166 static void RCinterrupt(int, void *, struct pt_regs *);
167 static int RCclose(struct net_device *dev);
168 static struct enet_statistics *RCget_stats(struct net_device *);
169 static int RCioctl(struct net_device *, struct ifreq *, int);
170 static int RCconfig(struct net_device *, struct ifmap *);
171 static void RCxmit_callback(U32, U16, PU32, U16);
172 static void RCrecv_callback(U32, U8, U32, PU32, U16);
173 static void RCreset_callback(U32, U32, U32, U16);
174 static void RCreboot_callback(U32, U32, U32, U16);
175 static int RC_allocate_and_post_buffers(struct net_device *, int);
178 /* A list of all installed RC devices, for removing the driver module. */
179 static struct net_device *root_RCdev = NULL;
181 #ifdef MODULE
182 int init_module(void)
183 #else
184 int rcpci_probe(struct net_device *dev)
185 #endif
187 int cards_found;
189 #ifdef MODULE
190 cards_found = RCscan(NULL);
191 #else
192 cards_found = RCscan(dev);
193 #endif
194 if (cards_found)
195 printk(version);
196 return cards_found ? 0 : -ENODEV;
199 static int RCscan(struct net_device *dev)
201 int cards_found = 0;
202 static int pci_index = 0;
204 if (!pcibios_present())
205 return cards_found;
207 for (;pci_index < 0x8; pci_index++)
209 unsigned char pci_bus, pci_device_fn;
210 int scan_status;
211 int board_index = 0;
212 unsigned char pci_irq_line;
213 unsigned int pci_ioaddr;
214 struct pci_dev *pdev;
216 scan_status =
217 (pcibios_find_device (RC_PCI45_VENDOR_ID,
218 RC_PCI45_DEVICE_ID,
219 pci_index,
220 &pci_bus,
221 &pci_device_fn));
222 #ifdef RCDEBUG
223 printk("rc scan_status = 0x%X\n", scan_status);
224 #endif
225 if (scan_status != PCIBIOS_SUCCESSFUL ||
226 !((pdev = pci_find_slot(pci_bus, pci_device_fn))))
227 break;
228 pci_irq_line = pdev->irq;
229 pci_ioaddr = pdev->resource[0].start;
231 #ifdef RCDEBUG
232 printk("rc: Found RedCreek PCI adapter\n");
233 printk("rc: pci_bus = %d, pci_device_fn = %d\n", pci_bus, pci_device_fn);
234 printk("rc: pci_irq_line = 0x%x \n", pci_irq_line);
235 printk("rc: pci_ioaddr = 0x%x\n", pci_ioaddr);
236 #endif
238 pci_set_master(pdev);
240 if (!RCfound_device(dev, pci_ioaddr, pci_irq_line,
241 pci_bus, pci_device_fn,
242 board_index++, cards_found))
244 dev = 0;
245 cards_found++;
248 #ifdef RCDEBUG
249 printk("rc: found %d cards \n", cards_found);
250 #endif
251 return cards_found;
254 static int RCinit(struct net_device *dev)
256 dev->open = &RCopen;
257 dev->hard_start_xmit = &RC_xmit_packet;
258 dev->stop = &RCclose;
259 dev->get_stats = &RCget_stats;
260 dev->do_ioctl = &RCioctl;
261 dev->set_config = &RCconfig;
262 return 0;
265 static int
266 RCfound_device(struct net_device *dev, int memaddr, int irq,
267 int bus, int function, int product_index, int card_idx)
269 int dev_size = 32768;
270 unsigned long *vaddr=0;
271 PDPA pDpa;
272 int init_status;
275 * Allocate and fill new device structure.
276 * We need enough for struct net_device plus DPA plus the LAN API private
277 * area, which requires a minimum of 16KB. The top of the allocated
278 * area will be assigned to struct net_device; the next chunk will be
279 * assigned to DPA; and finally, the rest will be assigned to the
280 * the LAN API layer.
283 #ifdef MODULE
284 dev = (struct net_device *) kmalloc(dev_size, GFP_DMA | GFP_KERNEL |GFP_ATOMIC);
285 if (!dev)
287 printk("rc: unable to kmalloc dev\n");
288 return 1;
290 memset(dev, 0, dev_size);
292 * dev->priv will point to the start of DPA.
294 dev->priv = (void *)(((long)dev + sizeof(struct net_device) + 15) & ~15);
295 #else
296 dev->priv = 0;
297 dev->priv = (struct net_device *) kmalloc(dev_size, GFP_DMA | GFP_KERNEL |GFP_ATOMIC);
298 if (!dev->priv)
300 printk("rc: unable to kmalloc private area\n");
301 return 1;
303 memset(dev->priv, 0, dev_size);
304 #endif
306 #ifdef RCDEBUG
307 printk("rc: dev = 0x%x, dev->priv = 0x%x\n", (uint)dev, (uint)dev->priv);
308 #endif
310 pDpa = dev->priv;
311 if (!dev->name)
312 dev->name = pDpa->devname;
314 pDpa->dev = dev; /* this is just for easy reference */
315 pDpa->function = function;
316 pDpa->bus = bus;
317 pDpa->id = card_idx; /* the device number */
318 pDpa->pci_addr = memaddr;
319 PCIAdapters[card_idx] = pDpa;
320 #ifdef RCDEBUG
321 printk("rc: pDpa = 0x%x, id = %d \n", (uint)pDpa, (uint)pDpa->id);
322 #endif
325 * Save the starting address of the LAN API private area. We'll
326 * pass that to RCInitI2OMsgLayer().
328 pDpa->PLanApiPA = (void *)(((long)pDpa + sizeof(DPA) + 0xff) & ~0xff);
329 #ifdef RCDEBUG
330 printk("rc: pDpa->PLanApiPA = 0x%x\n", (uint)pDpa->PLanApiPA);
331 #endif
333 /* The adapter is accessable through memory-access read/write, not
334 * I/O read/write. Thus, we need to map it to some virtual address
335 * area in order to access the registers are normal memory.
337 vaddr = (ulong *) ioremap (memaddr, 2*32768);
338 #ifdef RCDEBUG
339 printk("rc: RCfound_device: 0x%x, priv = 0x%x, vaddr = 0x%x\n",
340 (uint)dev, (uint)dev->priv, (uint)vaddr);
341 #endif
342 dev->base_addr = (unsigned long)vaddr;
343 dev->irq = irq;
344 dev->interrupt = 0;
347 * Request a shared interrupt line.
349 if ( request_irq(dev->irq, (void *)RCinterrupt,
350 SA_INTERRUPT|SA_SHIRQ, "RedCreek VPN Adapter", dev) )
352 printk( "RC PCI 45: %s: unable to get IRQ %d\n", (PU8)dev->name, (uint)dev->irq );
353 iounmap(vaddr);
354 kfree(dev);
355 return 1;
358 init_status = RCInitI2OMsgLayer(pDpa->id, dev->base_addr,
359 pDpa->PLanApiPA, (PU8)virt_to_bus((void *)pDpa->PLanApiPA),
360 (PFNTXCALLBACK)RCxmit_callback,
361 (PFNRXCALLBACK)RCrecv_callback,
362 (PFNCALLBACK)RCreboot_callback);
363 if (init_status)
365 printk("rc: Unable to initialize msg layer\n");
366 free_irq(dev->irq, dev);
367 iounmap(vaddr);
368 kfree(dev);
369 return 1;
371 if (RCGetMAC(pDpa->id, dev->dev_addr, NULL))
373 printk("rc: Unable to get adapter MAC\n");
374 free_irq(dev->irq, dev);
375 iounmap(vaddr);
376 kfree(dev);
377 return 1;
380 DriverControlWord |= WARM_REBOOT_CAPABLE;
381 RCReportDriverCapability(pDpa->id, DriverControlWord);
383 dev->init = &RCinit;
384 ether_setup(dev); /* linux kernel interface */
386 pDpa->next = root_RCdev;
387 root_RCdev = dev;
389 #ifdef MODULE
390 if (register_netdev(dev) != 0) /* linux kernel interface */
392 printk("rc: unable to register device \n");
393 free_irq(dev->irq, dev);
394 iounmap(vaddr);
395 kfree(dev);
396 return 1;
398 #else
399 RCinit(dev);
400 #endif
401 printk("%s: RedCreek Communications IPSEC VPN adapter\n",
402 dev->name);
404 return 0; /* success */
407 static int
408 RCopen(struct net_device *dev)
410 int post_buffers = MAX_NMBR_RCV_BUFFERS;
411 PDPA pDpa = (PDPA) dev->priv;
412 int count = 0;
413 int requested = 0;
415 #ifdef RCDEBUG
416 printk("rc: RCopen\n");
417 #endif
418 RCEnableI2OInterrupts(pDpa->id);
420 if (pDpa->nexus)
422 /* This is not the first time RCopen is called. Thus,
423 * the interface was previously opened and later closed
424 * by RCclose(). RCclose() does a Shutdown; to wake up
425 * the adapter, a reset is mandatory before we can post
426 * receive buffers. However, if the adapter initiated
427 * a reboot while the interface was closed -- and interrupts
428 * were turned off -- we need will need to reinitialize
429 * the adapter, rather than simply waking it up.
431 printk("rc: Waking up adapter...\n");
432 RCResetLANCard(pDpa->id,0,0,0);
434 else
436 pDpa->nexus = 1;
439 while(post_buffers)
441 if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
442 requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
443 else
444 requested = post_buffers;
445 count = RC_allocate_and_post_buffers(dev, requested);
447 if ( count < requested )
450 * Check to see if we were able to post any buffers at all.
452 if (post_buffers == MAX_NMBR_RCV_BUFFERS)
454 printk("rc: Error RCopen: not able to allocate any buffers\r\n");
455 return(-ENOMEM);
457 printk("rc: Warning RCopen: not able to allocate all requested buffers\r\n");
458 break; /* we'll try to post more buffers later */
460 else
461 post_buffers -= count;
463 pDpa->numOutRcvBuffers = MAX_NMBR_RCV_BUFFERS - post_buffers;
464 pDpa->shutdown = 0; /* just in case */
465 #ifdef RCDEBUG
466 printk("rc: RCopen: posted %d buffers\n", (uint)pDpa->numOutRcvBuffers);
467 #endif
468 MOD_INC_USE_COUNT;
469 return 0;
472 static int
473 RC_xmit_packet(struct sk_buff *skb, struct net_device *dev)
476 PDPA pDpa = (PDPA) dev->priv;
477 singleTCB tcb;
478 psingleTCB ptcb = &tcb;
479 RC_RETURN status = 0;
481 if (dev->tbusy || pDpa->shutdown || pDpa->reboot)
483 #ifdef RCDEBUG
484 printk("rc: RC_xmit_packet: tbusy!\n");
485 #endif
486 dev->tbusy = 1;
487 return 1;
490 if ( skb->len <= 0 )
492 printk("RC_xmit_packet: skb->len less than 0!\n");
493 return 0;
497 * The user is free to reuse the TCB after RCI2OSendPacket() returns, since
498 * the function copies the necessary info into its own private space. Thus,
499 * our TCB can be a local structure. The skb, on the other hand, will be
500 * freed up in our interrupt handler.
502 ptcb->bcount = 1;
504 * we'll get the context when the adapter interrupts us to tell us that
505 * the transmision is done. At that time, we can free skb.
507 ptcb->b.context = (U32)skb;
508 ptcb->b.scount = 1;
509 ptcb->b.size = skb->len;
510 ptcb->b.addr = virt_to_bus((void *)skb->data);
512 #ifdef RCDEBUG
513 printk("rc: RC xmit: skb = 0x%x, pDpa = 0x%x, id = %d, ptcb = 0x%x\n",
514 (uint)skb, (uint)pDpa, (uint)pDpa->id, (uint)ptcb);
515 #endif
516 if ( (status = RCI2OSendPacket(pDpa->id, (U32)NULL, (PRCTCB)ptcb))
517 != RC_RTN_NO_ERROR)
519 #ifdef RCDEBUG
520 printk("rc: RC send error 0x%x\n", (uint)status);
521 #endif
522 dev->tbusy = 1;
523 return 1;
525 else
527 dev->trans_start = jiffies;
528 // dev->tbusy = 0;
531 * That's it!
533 return 0;
537 * RCxmit_callback()
539 * The transmit callback routine. It's called by RCProcI2OMsgQ()
540 * because the adapter is done with one or more transmit buffers and
541 * it's returning them to us, or we asked the adapter to return the
542 * outstanding transmit buffers by calling RCResetLANCard() with
543 * RC_RESOURCE_RETURN_PEND_TX_BUFFERS flag.
544 * All we need to do is free the buffers.
546 static void
547 RCxmit_callback(U32 Status,
548 U16 PcktCount,
549 PU32 BufferContext,
550 U16 AdapterID)
552 struct sk_buff *skb;
553 PDPA pDpa;
554 struct net_device *dev;
556 pDpa = PCIAdapters[AdapterID];
557 if (!pDpa)
559 printk("rc: Fatal error: xmit callback, !pDpa\n");
560 return;
562 dev = pDpa->dev;
564 // printk("xmit_callback: Status = 0x%x\n", (uint)Status);
565 if (Status != I2O_REPLY_STATUS_SUCCESS)
567 printk("rc: xmit_callback: Status = 0x%x\n", (uint)Status);
569 #ifdef RCDEBUG
570 if (pDpa->shutdown || pDpa->reboot)
571 printk("rc: xmit callback: shutdown||reboot\n");
572 #endif
574 #ifdef RCDEBUG
575 printk("rc: xmit_callback: PcktCount = %d, BC = 0x%x\n",
576 (uint)PcktCount, (uint)BufferContext);
577 #endif
578 while (PcktCount--)
580 skb = (struct sk_buff *)(BufferContext[0]);
581 #ifdef RCDEBUG
582 printk("rc: skb = 0x%x\n", (uint)skb);
583 #endif
584 BufferContext++;
585 #ifdef LINUX_2_1
586 dev_kfree_skb (skb);
587 #else
588 dev_kfree_skb (skb, FREE_WRITE);
589 #endif
591 dev->tbusy = 0;
595 static void
596 RCreset_callback(U32 Status, U32 p1, U32 p2, U16 AdapterID)
598 PDPA pDpa;
599 struct net_device *dev;
601 pDpa = PCIAdapters[AdapterID];
602 dev = pDpa->dev;
603 #ifdef RCDEBUG
604 printk("rc: RCreset_callback Status 0x%x\n", (uint)Status);
605 #endif
607 * Check to see why we were called.
609 if (pDpa->shutdown)
611 printk("rc: Shutting down interface\n");
612 pDpa->shutdown = 0;
613 pDpa->reboot = 0;
614 MOD_DEC_USE_COUNT;
616 else if (pDpa->reboot)
618 printk("rc: reboot, shutdown adapter\n");
620 * We don't set any of the flags in RCShutdownLANCard()
621 * and we don't pass a callback routine to it.
622 * The adapter will have already initiated the reboot by
623 * the time the function returns.
625 RCDisableI2OInterrupts(pDpa->id);
626 RCShutdownLANCard(pDpa->id,0,0,0);
627 printk("rc: scheduling timer...\n");
628 init_timer(&pDpa->timer);
629 pDpa->timer.expires = RUN_AT((40*HZ)/10); /* 4 sec. */
630 pDpa->timer.data = (unsigned long)dev;
631 pDpa->timer.function = &rc_timer; /* timer handler */
632 add_timer(&pDpa->timer);
639 static void
640 RCreboot_callback(U32 Status, U32 p1, U32 p2, U16 AdapterID)
642 PDPA pDpa;
644 pDpa = PCIAdapters[AdapterID];
645 #ifdef RCDEBUG
646 printk("rc: RCreboot: rcv buffers outstanding = %d\n",
647 (uint)pDpa->numOutRcvBuffers);
648 #endif
649 if (pDpa->shutdown)
651 printk("rc: skipping reboot sequence -- shutdown already initiated\n");
652 return;
654 pDpa->reboot = 1;
656 * OK, we reset the adapter and ask it to return all
657 * outstanding transmit buffers as well as the posted
658 * receive buffers. When the adapter is done returning
659 * those buffers, it will call our RCreset_callback()
660 * routine. In that routine, we'll call RCShutdownLANCard()
661 * to tell the adapter that it's OK to start the reboot and
662 * schedule a timer callback routine to execute 3 seconds
663 * later; this routine will reinitialize the adapter at that time.
665 RCResetLANCard(pDpa->id,
666 RC_RESOURCE_RETURN_POSTED_RX_BUCKETS |
667 RC_RESOURCE_RETURN_PEND_TX_BUFFERS,0,
668 (PFNCALLBACK)RCreset_callback);
672 int broadcast_packet(unsigned char * address)
674 int i;
675 for (i=0; i<6; i++)
676 if (address[i] != 0xff) return 0;
678 return 1;
682 * RCrecv_callback()
684 * The receive packet callback routine. This is called by
685 * RCProcI2OMsgQ() after the adapter posts buffers which have been
686 * filled (one ethernet packet per buffer).
688 static void
689 RCrecv_callback(U32 Status,
690 U8 PktCount,
691 U32 BucketsRemain,
692 PU32 PacketDescBlock,
693 U16 AdapterID)
696 U32 len, count;
697 PDPA pDpa;
698 struct sk_buff *skb;
699 struct net_device *dev;
700 singleTCB tcb;
701 psingleTCB ptcb = &tcb;
704 pDpa = PCIAdapters[AdapterID];
705 dev = pDpa->dev;
707 ptcb->bcount = 1;
709 #ifdef RCDEBUG
710 printk("rc: RCrecv_callback: 0x%x, 0x%x, 0x%x\n",
711 (uint)PktCount, (uint)BucketsRemain, (uint)PacketDescBlock);
712 #endif
714 #ifdef RCDEBUG
715 if ((pDpa->shutdown || pDpa->reboot) && !Status)
716 printk("shutdown||reboot && !Status: PktCount = %d\n",PktCount);
717 #endif
719 if ( (Status != I2O_REPLY_STATUS_SUCCESS) || pDpa->shutdown)
722 * Free whatever buffers the adapter returned, but don't
723 * pass them to the kernel.
726 if (!pDpa->shutdown && !pDpa->reboot)
727 printk("rc: RCrecv error: status = 0x%x\n", (uint)Status);
728 #ifdef RCDEBUG
729 else
730 printk("rc: Returning %d buffers, status = 0x%x\n",
731 PktCount, (uint)Status);
732 #endif
734 * TO DO: check the nature of the failure and put the adapter in
735 * failed mode if it's a hard failure. Send a reset to the adapter
736 * and free all outstanding memory.
738 if (Status == I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER)
740 #ifdef RCDEBUG
741 printk("RCrecv status ABORT NO DATA TRANSFER\n");
742 #endif
744 /* check for reset status: I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER */
745 if (PacketDescBlock)
747 while(PktCount--)
749 skb = (struct sk_buff *)PacketDescBlock[0];
750 #ifndef LINUX_2_1
751 skb->free = 1;
752 skb->lock = 0;
753 #endif
754 #ifdef RCDEBUG
755 printk("free skb 0x%p\n", skb);
756 #endif
757 #ifdef LINUX_2_1
758 dev_kfree_skb (skb);
759 #else
760 dev_kfree_skb(skb, FREE_READ);
761 #endif
762 pDpa->numOutRcvBuffers--;
763 PacketDescBlock += BD_SIZE; /* point to next context field */
766 return;
768 else
770 while(PktCount--)
772 skb = (struct sk_buff *)PacketDescBlock[0];
773 #ifdef RCDEBUG
774 if (pDpa->shutdown)
775 printk("shutdown: skb=0x%x\n", (uint)skb);
777 printk("skb = 0x%x: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", (uint)skb,
778 (uint)skb->data[0], (uint)skb->data[1], (uint)skb->data[2],
779 (uint)skb->data[3], (uint)skb->data[4], (uint)skb->data[5]);
780 #endif
782 #ifdef PROMISCUOUS_BY_DEFAULT /* early 2.x firmware */
783 if ( (memcmp(dev->dev_addr, skb->data, 6)) &&
784 (!broadcast_packet(skb->data)))
787 * Re-post the buffer to the adapter. Since the adapter usually
788 * return 1 to 2 receive buffers at a time, it's not too inefficient
789 * post one buffer at a time but ... may be that should be
790 * optimized at some point.
792 ptcb->b.context = (U32)skb;
793 ptcb->b.scount = 1;
794 ptcb->b.size = MAX_ETHER_SIZE;
795 ptcb->b.addr = virt_to_bus((void *)skb->data);
797 if ( RCPostRecvBuffers(pDpa->id, (PRCTCB)ptcb ) != RC_RTN_NO_ERROR)
799 printk("rc: RCrecv_callback: post buffer failed!\n");
800 #ifdef LINUX_2_1
801 dev_kfree_skb (skb);
802 #else
803 skb->free = 1;
804 dev_kfree_skb(skb, FREE_READ);
805 #endif
807 else
809 pDpa->numOutRcvBuffers++;
812 else
813 #endif /* PROMISCUOUS_BY_DEFAULT */
815 len = PacketDescBlock[2];
816 skb->dev = dev;
817 skb_put( skb, len ); /* adjust length and tail */
818 skb->protocol = eth_type_trans(skb, dev);
819 netif_rx(skb); /* send the packet to the kernel */
820 dev->last_rx = jiffies;
822 pDpa->numOutRcvBuffers--;
823 PacketDescBlock += BD_SIZE; /* point to next context field */
828 * Replenish the posted receive buffers.
829 * DO NOT replenish buffers if the driver has already
830 * initiated a reboot or shutdown!
833 if (!pDpa->shutdown && !pDpa->reboot)
835 count = RC_allocate_and_post_buffers(dev,
836 MAX_NMBR_RCV_BUFFERS-pDpa->numOutRcvBuffers);
837 pDpa->numOutRcvBuffers += count;
843 * RCinterrupt()
845 * Interrupt handler.
846 * This routine sets up a couple of pointers and calls
847 * RCProcI2OMsgQ(), which in turn process the message and
848 * calls one of our callback functions.
850 static void
851 RCinterrupt(int irq, void *dev_id, struct pt_regs *regs)
854 PDPA pDpa;
855 struct net_device *dev = (struct net_device *)(dev_id);
857 pDpa = (PDPA) (dev->priv);
859 #ifdef RCDEBUG
860 if (pDpa->shutdown)
861 printk("rc: shutdown: service irq\n");
863 printk("RC irq: pDpa = 0x%x, dev = 0x%x, id = %d\n",
864 (uint)pDpa, (uint)dev, (uint)pDpa->id);
865 printk("dev = 0x%x\n", (uint)dev);
866 #endif
867 if (dev->interrupt)
868 printk("%s: Re-entering the interrupt handler.\n", dev->name);
869 dev->interrupt = 1;
871 RCProcI2OMsgQ(pDpa->id);
872 dev->interrupt = 0;
874 return;
878 #define REBOOT_REINIT_RETRY_LIMIT 4
879 static void rc_timer(unsigned long data)
881 struct net_device *dev = (struct net_device *)data;
882 PDPA pDpa = (PDPA) (dev->priv);
883 int init_status;
884 static int retry = 0;
885 int post_buffers = MAX_NMBR_RCV_BUFFERS;
886 int count = 0;
887 int requested = 0;
889 if (pDpa->reboot)
891 init_status = RCInitI2OMsgLayer(pDpa->id, dev->base_addr,
892 pDpa->PLanApiPA,
893 (PU8)virt_to_bus((void *)pDpa->PLanApiPA),
894 (PFNTXCALLBACK)RCxmit_callback,
895 (PFNRXCALLBACK)RCrecv_callback,
896 (PFNCALLBACK)RCreboot_callback);
898 switch(init_status)
900 case RC_RTN_NO_ERROR:
902 pDpa->reboot = 0;
903 pDpa->shutdown = 0; /* just in case */
904 RCReportDriverCapability(pDpa->id, DriverControlWord);
905 RCEnableI2OInterrupts(pDpa->id);
907 if (dev->flags & IFF_UP)
909 while(post_buffers)
911 if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
912 requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
913 else
914 requested = post_buffers;
915 count = RC_allocate_and_post_buffers(dev, requested);
916 post_buffers -= count;
917 if ( count < requested )
918 break;
920 pDpa->numOutRcvBuffers =
921 MAX_NMBR_RCV_BUFFERS - post_buffers;
922 printk("rc: posted %d buffers \r\n",
923 (uint)pDpa->numOutRcvBuffers);
925 printk("rc: Initialization done.\n");
926 dev->tbusy=0;
927 retry=0;
928 return;
929 case RC_RTN_FREE_Q_EMPTY:
930 retry++;
931 printk("rc: inbound free q empty\n");
932 break;
933 default:
934 retry++;
935 printk("rc: bad status after reboot: %d\n", init_status);
936 break;
939 if (retry > REBOOT_REINIT_RETRY_LIMIT)
941 printk("rc: unable to reinitialize adapter after reboot\n");
942 printk("rc: decrementing driver and closing interface\n");
943 RCDisableI2OInterrupts(pDpa->id);
944 dev->flags &= ~IFF_UP;
945 MOD_DEC_USE_COUNT;
947 else
949 printk("rc: rescheduling timer...\n");
950 init_timer(&pDpa->timer);
951 pDpa->timer.expires = RUN_AT((40*HZ)/10); /* 3 sec. */
952 pDpa->timer.data = (unsigned long)dev;
953 pDpa->timer.function = &rc_timer; /* timer handler */
954 add_timer(&pDpa->timer);
957 else
959 printk("rc: timer??\n");
963 static int
964 RCclose(struct net_device *dev)
967 PDPA pDpa = (PDPA) dev->priv;
969 #ifdef RCDEBUG
970 printk("rc: RCclose\r\n");
971 #endif
972 if (pDpa->reboot)
974 printk("rc: skipping reset -- adapter already in reboot mode\n");
975 dev->flags &= ~IFF_UP;
976 pDpa->shutdown = 1;
977 return 0;
979 #ifdef RCDEBUG
980 printk("rc: receive buffers outstanding: %d\n",
981 (uint)pDpa->numOutRcvBuffers);
982 #endif
984 pDpa->shutdown = 1;
987 * We can't allow the driver to be unloaded until the adapter returns
988 * all posted receive buffers. It doesn't hurt to tell the adapter
989 * to return all posted receive buffers and outstanding xmit buffers,
990 * even if there are none.
993 RCShutdownLANCard(pDpa->id,
994 RC_RESOURCE_RETURN_POSTED_RX_BUCKETS |
995 RC_RESOURCE_RETURN_PEND_TX_BUFFERS,0,
996 (PFNCALLBACK)RCreset_callback);
998 dev->flags &= ~IFF_UP;
999 return 0;
1002 static struct enet_statistics *
1003 RCget_stats(struct net_device *dev)
1005 RCLINKSTATS RCstats;
1007 PDPA pDpa = dev->priv;
1009 if (!pDpa)
1011 printk("rc: RCget_stats: !pDpa\n");
1012 return 0;
1014 else if (!(dev->flags & IFF_UP))
1016 #ifdef RCDEBUG
1017 printk("rc: RCget_stats: device down\n");
1018 #endif
1019 return 0;
1022 memset(&RCstats, 0, sizeof(RCLINKSTATS));
1023 if ( (RCGetLinkStatistics(pDpa->id, &RCstats, (void *)0)) == RC_RTN_NO_ERROR )
1025 #ifdef RCDEBUG
1026 printk("rc: TX_good 0x%x\n", (uint)RCstats.TX_good);
1027 printk("rc: TX_maxcol 0x%x\n", (uint)RCstats.TX_maxcol);
1028 printk("rc: TX_latecol 0x%x\n", (uint)RCstats.TX_latecol);
1029 printk("rc: TX_urun 0x%x\n", (uint)RCstats.TX_urun);
1030 printk("rc: TX_crs 0x%x\n", (uint)RCstats.TX_crs);
1031 printk("rc: TX_def 0x%x\n", (uint)RCstats.TX_def);
1032 printk("rc: TX_singlecol 0x%x\n", (uint)RCstats.TX_singlecol);
1033 printk("rc: TX_multcol 0x%x\n", (uint)RCstats.TX_multcol);
1034 printk("rc: TX_totcol 0x%x\n", (uint)RCstats.TX_totcol);
1036 printk("rc: Rcv_good 0x%x\n", (uint)RCstats.Rcv_good);
1037 printk("rc: Rcv_CRCerr 0x%x\n", (uint)RCstats.Rcv_CRCerr);
1038 printk("rc: Rcv_alignerr 0x%x\n", (uint)RCstats.Rcv_alignerr);
1039 printk("rc: Rcv_reserr 0x%x\n", (uint)RCstats.Rcv_reserr);
1040 printk("rc: Rcv_orun 0x%x\n", (uint)RCstats.Rcv_orun);
1041 printk("rc: Rcv_cdt 0x%x\n", (uint)RCstats.Rcv_cdt);
1042 printk("rc: Rcv_runt 0x%x\n", (uint)RCstats.Rcv_runt);
1043 #endif
1045 pDpa->stats.rx_packets = RCstats.Rcv_good; /* total packets received */
1046 pDpa->stats.tx_packets = RCstats.TX_good; /* total packets transmitted */
1048 pDpa->stats.rx_errors =
1049 RCstats.Rcv_CRCerr +
1050 RCstats.Rcv_alignerr +
1051 RCstats.Rcv_reserr +
1052 RCstats.Rcv_orun +
1053 RCstats.Rcv_cdt +
1054 RCstats.Rcv_runt; /* bad packets received */
1056 pDpa->stats.tx_errors =
1057 RCstats.TX_urun +
1058 RCstats.TX_crs +
1059 RCstats.TX_def +
1060 RCstats.TX_totcol; /* packet transmit problems */
1063 * This needs improvement.
1065 pDpa->stats.rx_dropped = 0; /* no space in linux buffers */
1066 pDpa->stats.tx_dropped = 0; /* no space available in linux */
1067 pDpa->stats.multicast = 0; /* multicast packets received */
1068 pDpa->stats.collisions = RCstats.TX_totcol;
1070 /* detailed rx_errors: */
1071 pDpa->stats.rx_length_errors = 0;
1072 pDpa->stats.rx_over_errors = RCstats.Rcv_orun; /* receiver ring buff overflow */
1073 pDpa->stats.rx_crc_errors = RCstats.Rcv_CRCerr; /* recved pkt with crc error */
1074 pDpa->stats.rx_frame_errors = 0; /* recv'd frame alignment error */
1075 pDpa->stats.rx_fifo_errors = 0; /* recv'r fifo overrun */
1076 pDpa->stats.rx_missed_errors = 0; /* receiver missed packet */
1078 /* detailed tx_errors */
1079 pDpa->stats.tx_aborted_errors = 0;
1080 pDpa->stats.tx_carrier_errors = 0;
1081 pDpa->stats.tx_fifo_errors = 0;
1082 pDpa->stats.tx_heartbeat_errors = 0;
1083 pDpa->stats.tx_window_errors = 0;
1085 return ((struct enet_statistics *)&(pDpa->stats));
1087 return 0;
1090 static int RCioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1092 RCuser_struct RCuser;
1093 PDPA pDpa = dev->priv;
1095 #if RCDEBUG
1096 printk("RCioctl: cmd = 0x%x\n", cmd);
1097 #endif
1099 switch (cmd) {
1101 case RCU_PROTOCOL_REV:
1103 * Assign user protocol revision, to tell user-level
1104 * controller program whether or not it's in sync.
1106 rq->ifr_ifru.ifru_data = (caddr_t) USER_PROTOCOL_REV;
1107 break;
1110 case RCU_COMMAND:
1112 #ifdef LINUX_2_1
1113 if(copy_from_user(&RCuser, rq->ifr_data, sizeof(RCuser)))
1114 return -EFAULT;
1115 #else
1116 int error;
1117 error=verify_area(VERIFY_WRITE, rq->ifr_data, sizeof(RCuser));
1118 if (error) {
1119 return error;
1121 memcpy_fromfs(&RCuser, rq->ifr_data, sizeof(RCuser));
1122 #endif
1124 #ifdef RCDEBUG
1125 printk("RCioctl: RCuser_cmd = 0x%x\n", RCuser.cmd);
1126 #endif
1128 switch(RCuser.cmd)
1130 case RCUC_GETFWVER:
1131 printk("RC GETFWVER\n");
1132 RCUD_GETFWVER = &RCuser.RCUS_GETFWVER;
1133 RCGetFirmwareVer(pDpa->id, (PU8) &RCUD_GETFWVER->FirmString, NULL);
1134 break;
1135 case RCUC_GETINFO:
1136 printk("RC GETINFO\n");
1137 RCUD_GETINFO = &RCuser.RCUS_GETINFO;
1138 RCUD_GETINFO -> mem_start = dev->base_addr;
1139 RCUD_GETINFO -> mem_end = dev->base_addr + 2*32768;
1140 RCUD_GETINFO -> base_addr = pDpa->pci_addr;
1141 RCUD_GETINFO -> irq = dev->irq;
1142 break;
1143 case RCUC_GETIPANDMASK:
1144 printk("RC GETIPANDMASK\n");
1145 RCUD_GETIPANDMASK = &RCuser.RCUS_GETIPANDMASK;
1146 RCGetRavlinIPandMask(pDpa->id, (PU32) &RCUD_GETIPANDMASK->IpAddr,
1147 (PU32) &RCUD_GETIPANDMASK->NetMask, NULL);
1148 break;
1149 case RCUC_GETLINKSTATISTICS:
1150 printk("RC GETLINKSTATISTICS\n");
1151 RCUD_GETLINKSTATISTICS = &RCuser.RCUS_GETLINKSTATISTICS;
1152 RCGetLinkStatistics(pDpa->id, (P_RCLINKSTATS) &RCUD_GETLINKSTATISTICS->StatsReturn, NULL);
1153 break;
1154 case RCUC_GETLINKSTATUS:
1155 printk("RC GETLINKSTATUS\n");
1156 RCUD_GETLINKSTATUS = &RCuser.RCUS_GETLINKSTATUS;
1157 RCGetLinkStatus(pDpa->id, (PU32) &RCUD_GETLINKSTATUS->ReturnStatus, NULL);
1158 break;
1159 case RCUC_GETMAC:
1160 printk("RC GETMAC\n");
1161 RCUD_GETMAC = &RCuser.RCUS_GETMAC;
1162 RCGetMAC(pDpa->id, (PU8) &RCUD_GETMAC->mac, NULL);
1163 break;
1164 case RCUC_GETPROM:
1165 printk("RC GETPROM\n");
1166 RCUD_GETPROM = &RCuser.RCUS_GETPROM;
1167 RCGetPromiscuousMode(pDpa->id, (PU32) &RCUD_GETPROM->PromMode, NULL);
1168 break;
1169 case RCUC_GETBROADCAST:
1170 printk("RC GETBROADCAST\n");
1171 RCUD_GETBROADCAST = &RCuser.RCUS_GETBROADCAST;
1172 RCGetBroadcastMode(pDpa->id, (PU32) &RCUD_GETBROADCAST->BroadcastMode, NULL);
1173 break;
1174 case RCUC_GETSPEED:
1175 printk("RC GETSPEED\n");
1176 if (!(dev->flags & IFF_UP))
1178 printk("RCioctl, GETSPEED error: interface down\n");
1179 return -ENODATA;
1181 RCUD_GETSPEED = &RCuser.RCUS_GETSPEED;
1182 RCGetLinkSpeed(pDpa->id, (PU32) &RCUD_GETSPEED->LinkSpeedCode, NULL);
1183 printk("RC speed = 0x%ld\n", RCUD_GETSPEED->LinkSpeedCode);
1184 break;
1185 case RCUC_SETIPANDMASK:
1186 printk("RC SETIPANDMASK\n");
1187 RCUD_SETIPANDMASK = &RCuser.RCUS_SETIPANDMASK;
1188 printk ("RC New IP Addr = %d.%d.%d.%d, ", (U8) ((RCUD_SETIPANDMASK->IpAddr) & 0xff),
1189 (U8) ((RCUD_SETIPANDMASK->IpAddr >> 8) & 0xff),
1190 (U8) ((RCUD_SETIPANDMASK->IpAddr >> 16) & 0xff),
1191 (U8) ((RCUD_SETIPANDMASK->IpAddr >> 24) & 0xff));
1192 printk ("RC New Mask = %d.%d.%d.%d\n", (U8) ((RCUD_SETIPANDMASK->NetMask) & 0xff),
1193 (U8) ((RCUD_SETIPANDMASK->NetMask >> 8) & 0xff),
1194 (U8) ((RCUD_SETIPANDMASK->NetMask >> 16) & 0xff),
1195 (U8) ((RCUD_SETIPANDMASK->NetMask >> 24) & 0xff));
1196 RCSetRavlinIPandMask(pDpa->id, (U32) RCUD_SETIPANDMASK->IpAddr,
1197 (U32) RCUD_SETIPANDMASK->NetMask);
1198 break;
1199 case RCUC_SETMAC:
1200 printk("RC SETMAC\n");
1201 RCUD_SETMAC = &RCuser.RCUS_SETMAC;
1202 printk ("RC New MAC addr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1203 (U8) (RCUD_SETMAC->mac[0]), (U8) (RCUD_SETMAC->mac[1]), (U8) (RCUD_SETMAC->mac[2]),
1204 (U8) (RCUD_SETMAC->mac[3]), (U8) (RCUD_SETMAC->mac[4]), (U8) (RCUD_SETMAC->mac[5]));
1205 RCSetMAC(pDpa->id, (PU8) &RCUD_SETMAC->mac);
1206 break;
1207 case RCUC_SETSPEED:
1208 printk("RC SETSPEED\n");
1209 RCUD_SETSPEED = &RCuser.RCUS_SETSPEED;
1210 RCSetLinkSpeed(pDpa->id, (U16) RCUD_SETSPEED->LinkSpeedCode);
1211 printk("RC New speed = 0x%d\n", RCUD_SETSPEED->LinkSpeedCode);
1212 break;
1213 case RCUC_SETPROM:
1214 printk("RC SETPROM\n");
1215 RCUD_SETPROM = &RCuser.RCUS_SETPROM;
1216 RCSetPromiscuousMode(pDpa->id,(U16)RCUD_SETPROM->PromMode);
1217 printk("RC New prom mode = 0x%d\n", RCUD_SETPROM->PromMode);
1218 break;
1219 case RCUC_SETBROADCAST:
1220 printk("RC SETBROADCAST\n");
1221 RCUD_SETBROADCAST = &RCuser.RCUS_SETBROADCAST;
1222 RCSetBroadcastMode(pDpa->id,(U16)RCUD_SETBROADCAST->BroadcastMode);
1223 printk("RC New broadcast mode = 0x%d\n", RCUD_SETBROADCAST->BroadcastMode);
1224 break;
1225 default:
1226 printk("RC command default\n");
1227 RCUD_DEFAULT = &RCuser.RCUS_DEFAULT;
1228 RCUD_DEFAULT -> rc = 0x11223344;
1229 break;
1231 #ifdef LINUX_2_1
1232 copy_to_user(rq->ifr_data, &RCuser, sizeof(RCuser));
1233 #else
1234 memcpy_tofs(rq->ifr_data, &RCuser, sizeof(RCuser));
1235 #endif
1236 break;
1237 } /* RCU_COMMAND */
1239 default:
1240 printk("RC default\n");
1241 rq->ifr_ifru.ifru_data = (caddr_t) 0x12345678;
1242 break;
1244 return 0;
1247 static int RCconfig(struct net_device *dev, struct ifmap *map)
1250 * To be completed ...
1252 printk("rc: RCconfig\n");
1253 return 0;
1254 if (dev->flags & IFF_UP) /* can't act on a running interface */
1255 return -EBUSY;
1257 /* Don't allow changing the I/O address */
1258 if (map->base_addr != dev->base_addr) {
1259 printk(KERN_WARNING "RC pci45: Change I/O address not implemented\n");
1260 return -EOPNOTSUPP;
1262 return 0;
1266 #ifdef MODULE
1267 void
1268 cleanup_module(void)
1270 PDPA pDpa;
1271 struct net_device *next;
1274 #ifdef RCDEBUG
1275 printk("rc: RC cleanup_module\n");
1276 printk("rc: root_RCdev = 0x%x\n", (uint)root_RCdev);
1277 #endif
1280 while (root_RCdev)
1282 pDpa = (PDPA) root_RCdev->priv;
1283 #ifdef RCDEBUG
1284 printk("rc: cleanup 0x%08X\n", (uint)root_RCdev);
1285 #endif
1286 printk("IOP reset: 0x%x\n", RCResetIOP(pDpa->id));
1287 unregister_netdev(root_RCdev);
1288 next = pDpa->next;
1290 iounmap((unsigned long *)root_RCdev->base_addr);
1291 free_irq( root_RCdev->irq, root_RCdev );
1292 kfree(root_RCdev);
1293 root_RCdev = next;
1296 #endif
1299 static int
1300 RC_allocate_and_post_buffers(struct net_device *dev, int numBuffers)
1303 int i;
1304 PDPA pDpa = (PDPA)dev->priv;
1305 PU32 p;
1306 psingleB pB;
1307 struct sk_buff *skb;
1308 RC_RETURN status;
1310 if (!numBuffers)
1311 return 0;
1312 else if (numBuffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
1314 #ifdef RCDEBUG
1315 printk("rc: Too many buffers requested!\n");
1316 printk("rc: attempting to allocate only 32 buffers\n");
1317 #endif
1318 numBuffers = 32;
1321 p = (PU32) kmalloc(sizeof(U32) + numBuffers*sizeof(singleB), GFP_ATOMIC);
1323 #ifdef RCDEBUG
1324 printk("rc: TCB = 0x%x\n", (uint)p);
1325 #endif
1327 if (!p)
1329 printk("rc: RCopen: unable to allocate TCB\n");
1330 return 0;
1333 p[0] = 0; /* Buffer Count */
1334 pB = (psingleB)((U32)p + sizeof(U32)); /* point to the first buffer */
1336 #ifdef RCDEBUG
1337 printk("rc: p[0] = 0x%x, p = 0x%x, pB = 0x%x\n", (uint)p[0], (uint)p, (uint)pB);
1338 printk("rc: pB = 0x%x\n", (uint)pB);
1339 #endif
1341 for (i=0; i<numBuffers; i++)
1343 skb = dev_alloc_skb(MAX_ETHER_SIZE+2);
1344 if (!skb)
1346 printk("rc: Doh! RCopen: unable to allocate enough skbs!\n");
1347 if (*p != 0) /* did we allocate any buffers at all? */
1349 #ifdef RCDEBUG
1350 printk("rc: will post only %d buffers \n", (uint)(*p));
1351 #endif
1352 break;
1354 else
1356 kfree(p); /* Free the TCB */
1357 return 0;
1360 #ifdef RCDEBUG
1361 printk("post 0x%x\n", (uint)skb);
1362 #endif
1363 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1364 pB->context = (U32)skb;
1365 pB->scount = 1; /* segment count */
1366 pB->size = MAX_ETHER_SIZE;
1367 pB->addr = virt_to_bus((void *)skb->data);
1368 p[0]++;
1369 pB++;
1372 if ( (status = RCPostRecvBuffers(pDpa->id, (PRCTCB)p )) != RC_RTN_NO_ERROR)
1374 printk("rc: Post buffer failed with error code 0x%x!\n", status);
1375 pB = (psingleB)((U32)p + sizeof(U32)); /* point to the first buffer */
1376 while(p[0])
1378 skb = (struct sk_buff *)pB->context;
1379 #ifndef LINUX_2_1
1380 skb->free = 1;
1381 #endif
1382 #ifdef RCDEBUG
1383 printk("rc: freeing 0x%x\n", (uint)skb);
1384 #endif
1385 #ifdef LINUX_2_1
1386 dev_kfree_skb (skb);
1387 #else
1388 dev_kfree_skb(skb, FREE_READ);
1389 #endif
1390 p[0]--;
1391 pB++;
1393 #ifdef RCDEBUG
1394 printk("rc: freed all buffers, p[0] = %ld\n", p[0]);
1395 #endif
1397 kfree(p);
1398 return(p[0]); /* return the number of posted buffers */