1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#include <linux/module.h>
51#include <linux/kernel.h>
52#include <linux/sched.h>
53#include <linux/string.h>
54#include <linux/ptrace.h>
55#include <linux/errno.h>
56#include <linux/in.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>
63#include <asm/irq.h>
64#include <asm/bitops.h>
65#include <asm/uaccess.h>
66
67static char version[] __initdata =
68 "RedCreek Communications PCI linux driver version 2.20\n";
69
70#define RC_LINUX_MODULE
71#include "rclanmtl.h"
72#include "rcif.h"
73
74#define RUN_AT(x) (jiffies + (x))
75
76#define NEW_MULTICAST
77
78#define MAX_ETHER_SIZE 1520
79#define MAX_NMBR_RCV_BUFFERS 96
80#define RC_POSTED_BUFFERS_LOW_MARK MAX_NMBR_RCV_BUFFERS-16
81#define BD_SIZE 3
82#define BD_LEN_OFFSET 2
83
84
85#define RC_LAN_TARGET_ID 0x10
86
87#define DEFAULT_RECV_INIT_CONTEXT 0xA17
88
89
90
91
92
93
94
95#define MSG_BUF_SIZE 16384
96
97static U32 DriverControlWord;
98
99static void rc_timer (unsigned long);
100
101static int RCopen (struct net_device *);
102static int RC_xmit_packet (struct sk_buff *, struct net_device *);
103static void RCinterrupt (int, void *, struct pt_regs *);
104static int RCclose (struct net_device *dev);
105static struct net_device_stats *RCget_stats (struct net_device *);
106static int RCioctl (struct net_device *, struct ifreq *, int);
107static int RCconfig (struct net_device *, struct ifmap *);
108static void RCxmit_callback (U32, U16, PU32, struct net_device *);
109static void RCrecv_callback (U32, U8, U32, PU32, struct net_device *);
110static void RCreset_callback (U32, U32, U32, struct net_device *);
111static void RCreboot_callback (U32, U32, U32, struct net_device *);
112static int RC_allocate_and_post_buffers (struct net_device *, int);
113
114static struct pci_device_id rcpci45_pci_table[] __devinitdata = {
115 { PCI_VENDOR_ID_REDCREEK, PCI_DEVICE_ID_RC45, PCI_ANY_ID, PCI_ANY_ID,},
116 {}
117};
118MODULE_DEVICE_TABLE (pci, rcpci45_pci_table);
119MODULE_LICENSE("GPL");
120
121static void __devexit
122rcpci45_remove_one (struct pci_dev *pdev)
123{
124 struct net_device *dev = pci_get_drvdata (pdev);
125 PDPA pDpa = dev->priv;
126
127 if (!dev) {
128 printk (KERN_ERR "%s: remove non-existent device\n",
129 dev->name);
130 return;
131 }
132
133 RCResetIOP (dev);
134 unregister_netdev (dev);
135 free_irq (dev->irq, dev);
136 iounmap ((void *) dev->base_addr);
137 pci_release_regions (pdev);
138 if (pDpa->msgbuf)
139 kfree (pDpa->msgbuf);
140 if (pDpa->pPab)
141 kfree (pDpa->pPab);
142 kfree (dev);
143 pci_set_drvdata (pdev, NULL);
144}
145
146static int
147rcpci45_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
148{
149 unsigned long *vaddr;
150 PDPA pDpa;
151 int error;
152 static int card_idx = -1;
153 struct net_device *dev;
154 unsigned long pci_start, pci_len;
155
156 card_idx++;
157
158
159
160
161
162
163
164
165
166
167 dev = init_etherdev (NULL, sizeof (*pDpa));
168 if (!dev) {
169 printk (KERN_ERR
170 "(rcpci45 driver:) init_etherdev alloc failed\n");
171 error = -ENOMEM;
172 goto err_out;
173 }
174
175 error = pci_enable_device (pdev);
176 if (error) {
177 printk (KERN_ERR
178 "(rcpci45 driver:) %d: pci enable device error\n",
179 card_idx);
180 goto err_out;
181 }
182 error = -ENOMEM;
183 pci_start = pci_resource_start (pdev, 0);
184 pci_len = pci_resource_len (pdev, 0);
185 printk("pci_start %lx pci_len %lx\n", pci_start, pci_len);
186
187 pci_set_drvdata (pdev, dev);
188
189 pDpa = dev->priv;
190 pDpa->id = card_idx;
191 pDpa->pci_addr = pci_start;
192
193 if (!pci_start || !(pci_resource_flags (pdev, 0) & IORESOURCE_MEM)) {
194 printk (KERN_ERR
195 "(rcpci45 driver:) No PCI mem resources! Aborting\n");
196 error = -EBUSY;
197 goto err_out_free_dev;
198 }
199
200
201
202
203
204
205 pDpa->msgbuf = kmalloc (MSG_BUF_SIZE, GFP_DMA | GFP_KERNEL);
206 if (!pDpa->msgbuf) {
207 printk (KERN_ERR "(rcpci45 driver:) \
208 Could not allocate %d byte memory for the \
209 private msgbuf!\n", MSG_BUF_SIZE);
210 goto err_out_free_dev;
211 }
212
213
214
215
216
217
218 pDpa->PLanApiPA = (void *) (((long) pDpa->msgbuf + 0xff) & ~0xff);
219
220
221
222
223
224 error = pci_request_regions (pdev, dev->name);
225 if (error)
226 goto err_out_free_msgbuf;
227
228 vaddr = (ulong *) ioremap (pci_start, pci_len);
229 if (!vaddr) {
230 printk (KERN_ERR
231 "(rcpci45 driver:) \
232 Unable to remap address range from %lu to %lu\n",
233 pci_start, pci_start + pci_len);
234 goto err_out_free_region;
235 }
236
237 dev->base_addr = (unsigned long) vaddr;
238 dev->irq = pdev->irq;
239 dev->open = &RCopen;
240 dev->hard_start_xmit = &RC_xmit_packet;
241 dev->stop = &RCclose;
242 dev->get_stats = &RCget_stats;
243 dev->do_ioctl = &RCioctl;
244 dev->set_config = &RCconfig;
245
246 return 0;
247
248err_out_free_region:
249 pci_release_regions (pdev);
250err_out_free_msgbuf:
251 kfree (pDpa->msgbuf);
252err_out_free_dev:
253 unregister_netdev (dev);
254 kfree (dev);
255err_out:
256 card_idx--;
257 return -ENODEV;
258}
259
260static struct pci_driver rcpci45_driver = {
261 name: "rcpci45",
262 id_table: rcpci45_pci_table,
263 probe: rcpci45_init_one,
264 remove: __devexit_p(rcpci45_remove_one),
265};
266
267static int __init
268rcpci_init_module (void)
269{
270 int rc = pci_module_init (&rcpci45_driver);
271 if (!rc)
272 printk (KERN_ERR "%s", version);
273 return rc;
274}
275
276static int
277RCopen (struct net_device *dev)
278{
279 int post_buffers = MAX_NMBR_RCV_BUFFERS;
280 PDPA pDpa = dev->priv;
281 int count = 0;
282 int requested = 0;
283 int error;
284
285 MOD_INC_USE_COUNT;
286 if (pDpa->nexus) {
287
288
289
290
291
292
293
294
295
296 printk (KERN_INFO "Waking up adapter...\n");
297 RCResetLANCard (dev, 0, 0, 0);
298 } else {
299 pDpa->nexus = 1;
300
301
302
303
304 error = RCInitI2OMsgLayer (dev, (PFNTXCALLBACK) RCxmit_callback,
305 (PFNRXCALLBACK) RCrecv_callback,
306 (PFNCALLBACK) RCreboot_callback);
307 if (error) {
308 printk (KERN_ERR "%s: Unable to init msg layer (%x)\n",
309 dev->name, error);
310 goto err_out;
311 }
312 if ((error = RCGetMAC (dev, NULL))) {
313 printk (KERN_ERR "%s: Unable to get adapter MAC\n",
314 dev->name);
315 goto err_out;
316 }
317 }
318
319
320 error = request_irq (dev->irq, RCinterrupt, SA_SHIRQ, dev->name, dev);
321 if (error) {
322 printk (KERN_ERR "%s: unable to get IRQ %d\n",
323 dev->name, dev->irq);
324 goto err_out;
325 }
326
327 DriverControlWord |= WARM_REBOOT_CAPABLE;
328 RCReportDriverCapability (dev, DriverControlWord);
329
330 printk (KERN_INFO "%s: RedCreek Communications IPSEC VPN adapter\n",
331 dev->name);
332
333 RCEnableI2OInterrupts (dev);
334
335 while (post_buffers) {
336 if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)
337 requested = MAX_NMBR_POST_BUFFERS_PER_MSG;
338 else
339 requested = post_buffers;
340 count = RC_allocate_and_post_buffers (dev, requested);
341
342 if (count < requested) {
343
344
345
346
347 if (post_buffers == MAX_NMBR_RCV_BUFFERS) {
348 printk (KERN_ERR "%s: \
349 unable to allocate any buffers\n",
350 dev->name);
351 goto err_out_free_irq;
352 }
353 printk (KERN_WARNING "%s: \
354 unable to allocate all requested buffers\n", dev->name);
355 break;
356 } else
357 post_buffers -= count;
358 }
359 pDpa->numOutRcvBuffers = MAX_NMBR_RCV_BUFFERS - post_buffers;
360 pDpa->shutdown = 0;
361 netif_start_queue (dev);
362 return 0;
363
364err_out_free_irq:
365 free_irq (dev->irq, dev);
366err_out:
367 MOD_DEC_USE_COUNT;
368 return error;
369}
370
371static int
372RC_xmit_packet (struct sk_buff *skb, struct net_device *dev)
373{
374
375 PDPA pDpa = dev->priv;
376 singleTCB tcb;
377 psingleTCB ptcb = &tcb;
378 RC_RETURN status = 0;
379
380 netif_stop_queue (dev);
381
382 if (pDpa->shutdown || pDpa->reboot) {
383 printk ("RC_xmit_packet: tbusy!\n");
384 return 1;
385 }
386
387
388
389
390
391
392
393
394
395 ptcb->bcount = 1;
396
397
398
399
400
401 ptcb->b.context = (U32) skb;
402 ptcb->b.scount = 1;
403 ptcb->b.size = skb->len;
404 ptcb->b.addr = virt_to_bus ((void *) skb->data);
405
406 if ((status = RCI2OSendPacket (dev, (U32) NULL, (PRCTCB) ptcb))
407 != RC_RTN_NO_ERROR) {
408 printk ("%s: send error 0x%x\n", dev->name, (uint) status);
409 return 1;
410 } else {
411 dev->trans_start = jiffies;
412 netif_wake_queue (dev);
413 }
414
415
416
417 return 0;
418}
419
420
421
422
423
424
425
426
427
428
429
430static void
431RCxmit_callback (U32 Status,
432 U16 PcktCount, PU32 BufferContext, struct net_device *dev)
433{
434 struct sk_buff *skb;
435 PDPA pDpa = dev->priv;
436
437 if (!pDpa) {
438 printk (KERN_ERR "%s: Fatal Error in xmit callback, !pDpa\n",
439 dev->name);
440 return;
441 }
442
443 if (Status != I2O_REPLY_STATUS_SUCCESS)
444 printk (KERN_INFO "%s: xmit_callback: Status = 0x%x\n",
445 dev->name, (uint) Status);
446 if (pDpa->shutdown || pDpa->reboot)
447 printk (KERN_INFO "%s: xmit callback: shutdown||reboot\n",
448 dev->name);
449
450 while (PcktCount--) {
451 skb = (struct sk_buff *) (BufferContext[0]);
452 BufferContext++;
453 dev_kfree_skb_irq (skb);
454 }
455 netif_wake_queue (dev);
456}
457
458static void
459RCreset_callback (U32 Status, U32 p1, U32 p2, struct net_device *dev)
460{
461 PDPA pDpa = dev->priv;
462
463 printk ("RCreset_callback Status 0x%x\n", (uint) Status);
464
465
466
467 if (pDpa->shutdown) {
468 printk (KERN_INFO "%s: shutting down interface\n",
469 dev->name);
470 pDpa->shutdown = 0;
471 pDpa->reboot = 0;
472 } else if (pDpa->reboot) {
473 printk (KERN_INFO "%s: reboot, shutdown adapter\n",
474 dev->name);
475
476
477
478
479
480
481 RCDisableI2OInterrupts (dev);
482 RCShutdownLANCard (dev, 0, 0, 0);
483 printk (KERN_INFO "%s: scheduling timer...\n", dev->name);
484 init_timer (&pDpa->timer);
485 pDpa->timer.expires = RUN_AT ((40 * HZ) / 10);
486 pDpa->timer.data = (unsigned long) dev;
487 pDpa->timer.function = &rc_timer;
488 add_timer (&pDpa->timer);
489 }
490}
491
492static void
493RCreboot_callback (U32 Status, U32 p1, U32 p2, struct net_device *dev)
494{
495 PDPA pDpa = dev->priv;
496
497 printk (KERN_INFO "%s: reboot: rcv buffers outstanding = %d\n",
498 dev->name, (uint) pDpa->numOutRcvBuffers);
499
500 if (pDpa->shutdown) {
501 printk (KERN_INFO "%s: skip reboot, shutdown initiated\n",
502 dev->name);
503 return;
504 }
505 pDpa->reboot = 1;
506
507
508
509
510
511
512
513
514
515
516 RCResetLANCard (dev, RC_RESOURCE_RETURN_POSTED_RX_BUCKETS |
517 RC_RESOURCE_RETURN_PEND_TX_BUFFERS, 0,
518 (PFNCALLBACK) RCreset_callback);
519}
520
521int
522broadcast_packet (unsigned char *address)
523{
524 int i;
525 for (i = 0; i < 6; i++)
526 if (address[i] != 0xff)
527 return 0;
528
529 return 1;
530}
531
532
533
534
535
536
537
538
539static void
540RCrecv_callback (U32 Status,
541 U8 PktCount,
542 U32 BucketsRemain,
543 PU32 PacketDescBlock, struct net_device *dev)
544{
545
546 U32 len, count;
547 PDPA pDpa = dev->priv;
548 struct sk_buff *skb;
549 singleTCB tcb;
550 psingleTCB ptcb = &tcb;
551
552 ptcb->bcount = 1;
553
554 if ((pDpa->shutdown || pDpa->reboot) && !Status)
555 printk (KERN_INFO "%s: shutdown||reboot && !Status (%d)\n",
556 dev->name, PktCount);
557
558 if ((Status != I2O_REPLY_STATUS_SUCCESS) || pDpa->shutdown) {
559
560
561
562
563
564 if (!pDpa->shutdown && !pDpa->reboot)
565 printk (KERN_INFO "%s: recv error status = 0x%x\n",
566 dev->name, (uint) Status);
567 else
568 printk (KERN_DEBUG "%s: Returning %d buffs stat 0x%x\n",
569 dev->name, PktCount, (uint) Status);
570
571
572
573
574
575 if (PacketDescBlock) {
576 while (PktCount--) {
577 skb = (struct sk_buff *) PacketDescBlock[0];
578 dev_kfree_skb (skb);
579 pDpa->numOutRcvBuffers--;
580
581 PacketDescBlock += BD_SIZE;
582 }
583 }
584 return;
585 } else {
586 while (PktCount--) {
587 skb = (struct sk_buff *) PacketDescBlock[0];
588 len = PacketDescBlock[2];
589 skb->dev = dev;
590 skb_put (skb, len);
591 skb->protocol = eth_type_trans (skb, dev);
592 netif_rx (skb);
593 dev->last_rx = jiffies;
594 pDpa->numOutRcvBuffers--;
595
596 PacketDescBlock += BD_SIZE;
597 }
598 }
599
600
601
602
603
604
605
606 if (!pDpa->shutdown && !pDpa->reboot) {
607 count = RC_allocate_and_post_buffers (dev,
608 MAX_NMBR_RCV_BUFFERS -
609 pDpa->numOutRcvBuffers);
610 pDpa->numOutRcvBuffers += count;
611 }
612
613}
614
615
616
617
618
619
620
621
622
623static void
624RCinterrupt (int irq, void *dev_id, struct pt_regs *regs)
625{
626
627 PDPA pDpa;
628 struct net_device *dev = dev_id;
629
630 pDpa = dev->priv;
631
632 if (pDpa->shutdown)
633 printk (KERN_DEBUG "%s: shutdown, service irq\n",
634 dev->name);
635
636 RCProcI2OMsgQ (dev);
637}
638
639#define REBOOT_REINIT_RETRY_LIMIT 4
640static void
641rc_timer (unsigned long data)
642{
643 struct net_device *dev = (struct net_device *) data;
644 PDPA pDpa = dev->priv;
645 int init_status;
646 static int retry;
647 int post_buffers = MAX_NMBR_RCV_BUFFERS;
648 int count = 0;
649 int requested = 0;
650
651 if (pDpa->reboot) {
652 init_status =
653 RCInitI2OMsgLayer (dev, (PFNTXCALLBACK) RCxmit_callback,
654 (PFNRXCALLBACK) RCrecv_callback,
655 (PFNCALLBACK) RCreboot_callback);
656
657 switch (init_status) {
658 case RC_RTN_NO_ERROR:
659
660 pDpa->reboot = 0;
661 pDpa->shutdown = 0;
662 RCReportDriverCapability (dev, DriverControlWord);
663 RCEnableI2OInterrupts (dev);
664
665
666 if (!(dev->flags & IFF_UP)) {
667 retry = 0;
668 return;
669 }
670 while (post_buffers) {
671 if (post_buffers >
672 MAX_NMBR_POST_BUFFERS_PER_MSG)
673 requested =
674 MAX_NMBR_POST_BUFFERS_PER_MSG;
675 else
676 requested = post_buffers;
677 count =
678 RC_allocate_and_post_buffers (dev,
679 requested);
680 post_buffers -= count;
681 if (count < requested)
682 break;
683 }
684 pDpa->numOutRcvBuffers =
685 MAX_NMBR_RCV_BUFFERS - post_buffers;
686 printk ("Initialization done.\n");
687 netif_wake_queue (dev);
688 retry = 0;
689 return;
690 case RC_RTN_FREE_Q_EMPTY:
691 retry++;
692 printk (KERN_WARNING "%s inbound free q empty\n",
693 dev->name);
694 break;
695 default:
696 retry++;
697 printk (KERN_WARNING "%s bad stat after reboot: %d\n",
698 dev->name, init_status);
699 break;
700 }
701
702 if (retry > REBOOT_REINIT_RETRY_LIMIT) {
703 printk (KERN_WARNING "%s unable to reinitialize adapter after reboot\n", dev->name);
704 printk (KERN_WARNING "%s decrementing driver and closing interface\n", dev->name);
705 RCDisableI2OInterrupts (dev);
706 dev->flags &= ~IFF_UP;
707 MOD_DEC_USE_COUNT;
708 } else {
709 printk (KERN_INFO "%s: rescheduling timer...\n",
710 dev->name);
711 init_timer (&pDpa->timer);
712 pDpa->timer.expires = RUN_AT ((40 * HZ) / 10);
713 pDpa->timer.data = (unsigned long) dev;
714 pDpa->timer.function = &rc_timer;
715 add_timer (&pDpa->timer);
716 }
717 } else
718 printk (KERN_WARNING "%s: unexpected timer irq\n", dev->name);
719}
720
721static int
722RCclose (struct net_device *dev)
723{
724 PDPA pDpa = dev->priv;
725
726 printk("RCclose\n");
727 netif_stop_queue (dev);
728
729 if (pDpa->reboot) {
730 printk (KERN_INFO "%s skipping reset -- adapter already in reboot mode\n", dev->name);
731 dev->flags &= ~IFF_UP;
732 pDpa->shutdown = 1;
733 MOD_DEC_USE_COUNT;
734 return 0;
735 }
736
737 pDpa->shutdown = 1;
738
739
740
741
742
743
744
745
746 RCShutdownLANCard (dev, RC_RESOURCE_RETURN_POSTED_RX_BUCKETS |
747 RC_RESOURCE_RETURN_PEND_TX_BUFFERS, 0,
748 (PFNCALLBACK) RCreset_callback);
749
750 dev->flags &= ~IFF_UP;
751 MOD_DEC_USE_COUNT;
752 return 0;
753}
754
755static struct net_device_stats *
756RCget_stats (struct net_device *dev)
757{
758 RCLINKSTATS RCstats;
759
760 PDPA pDpa = dev->priv;
761
762 if (!pDpa) {
763 return 0;
764 } else if (!(dev->flags & IFF_UP)) {
765 return 0;
766 }
767
768 memset (&RCstats, 0, sizeof (RCLINKSTATS));
769 if ((RCGetLinkStatistics (dev, &RCstats, (void *) 0)) ==
770 RC_RTN_NO_ERROR) {
771
772
773 pDpa->stats.rx_packets = RCstats.Rcv_good
774 ;
775 pDpa->stats.tx_packets = RCstats.TX_good;
776
777 pDpa->stats.rx_errors = RCstats.Rcv_CRCerr +
778 RCstats.Rcv_alignerr + RCstats.Rcv_reserr +
779 RCstats.Rcv_orun + RCstats.Rcv_cdt + RCstats.Rcv_runt;
780
781 pDpa->stats.tx_errors = RCstats.TX_urun + RCstats.TX_crs +
782 RCstats.TX_def + RCstats.TX_totcol;
783
784
785
786
787 pDpa->stats.rx_dropped = 0;
788 pDpa->stats.tx_dropped = 0;
789 pDpa->stats.multicast = 0;
790 pDpa->stats.collisions = RCstats.TX_totcol;
791
792
793 pDpa->stats.rx_length_errors = 0;
794 pDpa->stats.rx_over_errors = RCstats.Rcv_orun;
795 pDpa->stats.rx_crc_errors = RCstats.Rcv_CRCerr;
796 pDpa->stats.rx_frame_errors = 0;
797 pDpa->stats.rx_fifo_errors = 0;
798 pDpa->stats.rx_missed_errors = 0;
799
800
801 pDpa->stats.tx_aborted_errors = 0;
802 pDpa->stats.tx_carrier_errors = 0;
803 pDpa->stats.tx_fifo_errors = 0;
804 pDpa->stats.tx_heartbeat_errors = 0;
805 pDpa->stats.tx_window_errors = 0;
806
807 return ((struct net_device_stats *) &(pDpa->stats));
808 }
809 return 0;
810}
811
812static int
813RCioctl (struct net_device *dev, struct ifreq *rq, int cmd)
814{
815 RCuser_struct RCuser;
816 PDPA pDpa = dev->priv;
817
818 if (!capable (CAP_NET_ADMIN))
819 return -EPERM;
820
821 switch (cmd) {
822
823 case RCU_PROTOCOL_REV:
824
825
826
827
828 rq->ifr_ifru.ifru_data = (caddr_t) USER_PROTOCOL_REV;
829 break;
830
831 case RCU_COMMAND:
832 {
833 if (copy_from_user
834 (&RCuser, rq->ifr_data, sizeof (RCuser)))
835 return -EFAULT;
836
837 dprintk ("RCioctl: RCuser_cmd = 0x%x\n", RCuser.cmd);
838
839 switch (RCuser.cmd) {
840 case RCUC_GETFWVER:
841 RCUD_GETFWVER = &RCuser.RCUS_GETFWVER;
842 RCGetFirmwareVer (dev,
843 (PU8) & RCUD_GETFWVER->
844 FirmString, NULL);
845 break;
846 case RCUC_GETINFO:
847 RCUD_GETINFO = &RCuser.RCUS_GETINFO;
848 RCUD_GETINFO->mem_start = dev->base_addr;
849 RCUD_GETINFO->mem_end =
850 dev->base_addr + pDpa->pci_addr_len;
851 RCUD_GETINFO->base_addr = pDpa->pci_addr;
852 RCUD_GETINFO->irq = dev->irq;
853 break;
854 case RCUC_GETIPANDMASK:
855 RCUD_GETIPANDMASK = &RCuser.RCUS_GETIPANDMASK;
856 RCGetRavlinIPandMask (dev,
857 (PU32) &
858 RCUD_GETIPANDMASK->IpAddr,
859 (PU32) &
860 RCUD_GETIPANDMASK->
861 NetMask, NULL);
862 break;
863 case RCUC_GETLINKSTATISTICS:
864 RCUD_GETLINKSTATISTICS =
865 &RCuser.RCUS_GETLINKSTATISTICS;
866 RCGetLinkStatistics (dev,
867 (P_RCLINKSTATS) &
868 RCUD_GETLINKSTATISTICS->
869 StatsReturn, NULL);
870 break;
871 case RCUC_GETLINKSTATUS:
872 RCUD_GETLINKSTATUS = &RCuser.RCUS_GETLINKSTATUS;
873 RCGetLinkStatus (dev,
874 (PU32) & RCUD_GETLINKSTATUS->
875 ReturnStatus, NULL);
876 break;
877 case RCUC_GETMAC:
878 RCUD_GETMAC = &RCuser.RCUS_GETMAC;
879 RCGetMAC (dev, NULL);
880 memcpy(RCUD_GETMAC, dev->dev_addr, 8);
881 break;
882 case RCUC_GETPROM:
883 RCUD_GETPROM = &RCuser.RCUS_GETPROM;
884 RCGetPromiscuousMode (dev,
885 (PU32) & RCUD_GETPROM->
886 PromMode, NULL);
887 break;
888 case RCUC_GETBROADCAST:
889 RCUD_GETBROADCAST = &RCuser.RCUS_GETBROADCAST;
890 RCGetBroadcastMode (dev,
891 (PU32) & RCUD_GETBROADCAST->
892 BroadcastMode, NULL);
893 break;
894 case RCUC_GETSPEED:
895 if (!(dev->flags & IFF_UP)) {
896 return -ENODATA;
897 }
898 RCUD_GETSPEED = &RCuser.RCUS_GETSPEED;
899 RCGetLinkSpeed (dev,
900 (PU32) & RCUD_GETSPEED->
901 LinkSpeedCode, NULL);
902 break;
903 case RCUC_SETIPANDMASK:
904 RCUD_SETIPANDMASK = &RCuser.RCUS_SETIPANDMASK;
905 RCSetRavlinIPandMask (dev,
906 (U32) RCUD_SETIPANDMASK->
907 IpAddr,
908 (U32) RCUD_SETIPANDMASK->
909 NetMask);
910 break;
911 case RCUC_SETMAC:
912 RCSetMAC (dev, (PU8) & RCUD_SETMAC->mac);
913 break;
914 case RCUC_SETSPEED:
915 RCUD_SETSPEED = &RCuser.RCUS_SETSPEED;
916 RCSetLinkSpeed (dev,
917 (U16) RCUD_SETSPEED->
918 LinkSpeedCode);
919 break;
920 case RCUC_SETPROM:
921 RCUD_SETPROM = &RCuser.RCUS_SETPROM;
922 RCSetPromiscuousMode (dev,
923 (U16) RCUD_SETPROM->
924 PromMode);
925 break;
926 case RCUC_SETBROADCAST:
927 RCUD_SETBROADCAST = &RCuser.RCUS_SETBROADCAST;
928 RCSetBroadcastMode (dev,
929 (U16) RCUD_SETBROADCAST->
930 BroadcastMode);
931 break;
932 default:
933 RCUD_DEFAULT = &RCuser.RCUS_DEFAULT;
934 RCUD_DEFAULT->rc = 0x11223344;
935 break;
936 }
937 if (copy_to_user (rq->ifr_data, &RCuser,
938 sizeof (RCuser)))
939 return -EFAULT;
940 break;
941 }
942
943 default:
944 rq->ifr_ifru.ifru_data = (caddr_t) 0x12345678;
945 return -EINVAL;
946 }
947 return 0;
948}
949
950static int
951RCconfig (struct net_device *dev, struct ifmap *map)
952{
953
954
955
956 return 0;
957 if (dev->flags & IFF_UP)
958 return -EBUSY;
959
960
961 if (map->base_addr != dev->base_addr) {
962 printk (KERN_WARNING "%s Change I/O address not implemented\n",
963 dev->name);
964 return -EOPNOTSUPP;
965 }
966 return 0;
967}
968
969static void __exit
970rcpci_cleanup_module (void)
971{
972 pci_unregister_driver (&rcpci45_driver);
973}
974
975module_init (rcpci_init_module);
976module_exit (rcpci_cleanup_module);
977
978static int
979RC_allocate_and_post_buffers (struct net_device *dev, int numBuffers)
980{
981
982 int i;
983 PU32 p;
984 psingleB pB;
985 struct sk_buff *skb;
986 RC_RETURN status;
987 U32 res;
988
989 if (!numBuffers)
990 return 0;
991 else if (numBuffers > MAX_NMBR_POST_BUFFERS_PER_MSG) {
992 printk (KERN_ERR "%s: Too many buffers requested!\n",
993 dev->name);
994 numBuffers = 32;
995 }
996
997 p = (PU32) kmalloc (sizeof (U32) + numBuffers * sizeof (singleB),
998 GFP_DMA | GFP_ATOMIC);
999
1000 if (!p) {
1001 printk (KERN_WARNING "%s unable to allocate TCB\n",
1002 dev->name);
1003 return 0;
1004 }
1005
1006 p[0] = 0;
1007 pB = (psingleB) ((U32) p + sizeof (U32));
1008
1009 for (i = 0; i < numBuffers; i++) {
1010 skb = dev_alloc_skb (MAX_ETHER_SIZE + 2);
1011 if (!skb) {
1012 printk (KERN_WARNING
1013 "%s: unable to allocate enough skbs!\n",
1014 dev->name);
1015 if (*p != 0) {
1016 break;
1017 } else {
1018 kfree (p);
1019 return 0;
1020 }
1021 }
1022 skb_reserve (skb, 2);
1023 pB->context = (U32) skb;
1024 pB->scount = 1;
1025 pB->size = MAX_ETHER_SIZE;
1026 pB->addr = virt_to_bus ((void *) skb->data);
1027 p[0]++;
1028 pB++;
1029 }
1030
1031 if ((status = RCPostRecvBuffers (dev, (PRCTCB) p)) != RC_RTN_NO_ERROR) {
1032 printk (KERN_WARNING "%s: Post buffer failed, error 0x%x\n",
1033 dev->name, status);
1034
1035 pB = (psingleB) ((U32) p + sizeof (U32));
1036 while (p[0]) {
1037 skb = (struct sk_buff *) pB->context;
1038 dev_kfree_skb (skb);
1039 p[0]--;
1040 pB++;
1041 }
1042 }
1043 res = p[0];
1044 kfree (p);
1045 return (res);
1046}
1047