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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68#define VERSION "2.07"
69
70static const char * const boot_msg =
71 "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n"
72 " SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)";
73
74
75
76#include <linux/capability.h>
77#include <linux/module.h>
78#include <linux/kernel.h>
79#include <linux/errno.h>
80#include <linux/ioport.h>
81#include <linux/interrupt.h>
82#include <linux/pci.h>
83#include <linux/netdevice.h>
84#include <linux/fddidevice.h>
85#include <linux/skbuff.h>
86#include <linux/bitops.h>
87#include <linux/gfp.h>
88
89#include <asm/byteorder.h>
90#include <asm/io.h>
91#include <asm/uaccess.h>
92
93#include "h/types.h"
94#undef ADDR
95#include "h/skfbi.h"
96#include "h/fddi.h"
97#include "h/smc.h"
98#include "h/smtstate.h"
99
100
101
102static int skfp_driver_init(struct net_device *dev);
103static int skfp_open(struct net_device *dev);
104static int skfp_close(struct net_device *dev);
105static irqreturn_t skfp_interrupt(int irq, void *dev_id);
106static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
107static void skfp_ctl_set_multicast_list(struct net_device *dev);
108static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
109static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
110static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
111static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
112 struct net_device *dev);
113static void send_queued_packets(struct s_smc *smc);
114static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
115static void ResetAdapter(struct s_smc *smc);
116
117
118
119void *mac_drv_get_space(struct s_smc *smc, u_int size);
120void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
121unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
122unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
123void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
124 int flag);
125void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
126void llc_restart_tx(struct s_smc *smc);
127void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
128 int frag_count, int len);
129void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
130 int frag_count);
131void mac_drv_fill_rxd(struct s_smc *smc);
132void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
133 int frag_count);
134int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
135 int la_len);
136void dump_data(unsigned char *Data, int length);
137
138
139extern u_int mac_drv_check_space(void);
140extern int mac_drv_init(struct s_smc *smc);
141extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
142 int len, int frame_status);
143extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
144 int frame_len, int frame_status);
145extern void fddi_isr(struct s_smc *smc);
146extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
147 int len, int frame_status);
148extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
149extern void mac_drv_clear_rx_queue(struct s_smc *smc);
150extern void enable_tx_irq(struct s_smc *smc, u_short queue);
151
152static DEFINE_PCI_DEVICE_TABLE(skfddi_pci_tbl) = {
153 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
154 { }
155};
156MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
157MODULE_LICENSE("GPL");
158MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
159
160
161
162static int num_boards;
163
164static const struct net_device_ops skfp_netdev_ops = {
165 .ndo_open = skfp_open,
166 .ndo_stop = skfp_close,
167 .ndo_start_xmit = skfp_send_pkt,
168 .ndo_get_stats = skfp_ctl_get_stats,
169 .ndo_change_mtu = fddi_change_mtu,
170 .ndo_set_rx_mode = skfp_ctl_set_multicast_list,
171 .ndo_set_mac_address = skfp_ctl_set_mac_address,
172 .ndo_do_ioctl = skfp_ioctl,
173};
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204static int skfp_init_one(struct pci_dev *pdev,
205 const struct pci_device_id *ent)
206{
207 struct net_device *dev;
208 struct s_smc *smc;
209 void __iomem *mem;
210 int err;
211
212 pr_debug("entering skfp_init_one\n");
213
214 if (num_boards == 0)
215 printk("%s\n", boot_msg);
216
217 err = pci_enable_device(pdev);
218 if (err)
219 return err;
220
221 err = pci_request_regions(pdev, "skfddi");
222 if (err)
223 goto err_out1;
224
225 pci_set_master(pdev);
226
227#ifdef MEM_MAPPED_IO
228 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
229 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
230 err = -EIO;
231 goto err_out2;
232 }
233
234 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
235#else
236 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
237 printk(KERN_ERR "skfp: region is not PIO resource\n");
238 err = -EIO;
239 goto err_out2;
240 }
241
242 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
243#endif
244 if (!mem) {
245 printk(KERN_ERR "skfp: Unable to map register, "
246 "FDDI adapter will be disabled.\n");
247 err = -EIO;
248 goto err_out2;
249 }
250
251 dev = alloc_fddidev(sizeof(struct s_smc));
252 if (!dev) {
253 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
254 "FDDI adapter will be disabled.\n");
255 err = -ENOMEM;
256 goto err_out3;
257 }
258
259 dev->irq = pdev->irq;
260 dev->netdev_ops = &skfp_netdev_ops;
261
262 SET_NETDEV_DEV(dev, &pdev->dev);
263
264
265 smc = netdev_priv(dev);
266 smc->os.dev = dev;
267 smc->os.bus_type = SK_BUS_TYPE_PCI;
268 smc->os.pdev = *pdev;
269 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
270 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
271 smc->os.dev = dev;
272 smc->hw.slot = -1;
273 smc->hw.iop = mem;
274 smc->os.ResetRequested = FALSE;
275 skb_queue_head_init(&smc->os.SendSkbQueue);
276
277 dev->base_addr = (unsigned long)mem;
278
279 err = skfp_driver_init(dev);
280 if (err)
281 goto err_out4;
282
283 err = register_netdev(dev);
284 if (err)
285 goto err_out5;
286
287 ++num_boards;
288 pci_set_drvdata(pdev, dev);
289
290 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
291 (pdev->subsystem_device & 0xff00) == 0x5800)
292 printk("%s: SysKonnect FDDI PCI adapter"
293 " found (SK-%04X)\n", dev->name,
294 pdev->subsystem_device);
295 else
296 printk("%s: FDDI PCI adapter found\n", dev->name);
297
298 return 0;
299err_out5:
300 if (smc->os.SharedMemAddr)
301 pci_free_consistent(pdev, smc->os.SharedMemSize,
302 smc->os.SharedMemAddr,
303 smc->os.SharedMemDMA);
304 pci_free_consistent(pdev, MAX_FRAME_SIZE,
305 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
306err_out4:
307 free_netdev(dev);
308err_out3:
309#ifdef MEM_MAPPED_IO
310 iounmap(mem);
311#else
312 ioport_unmap(mem);
313#endif
314err_out2:
315 pci_release_regions(pdev);
316err_out1:
317 pci_disable_device(pdev);
318 return err;
319}
320
321
322
323
324static void __devexit skfp_remove_one(struct pci_dev *pdev)
325{
326 struct net_device *p = pci_get_drvdata(pdev);
327 struct s_smc *lp = netdev_priv(p);
328
329 unregister_netdev(p);
330
331 if (lp->os.SharedMemAddr) {
332 pci_free_consistent(&lp->os.pdev,
333 lp->os.SharedMemSize,
334 lp->os.SharedMemAddr,
335 lp->os.SharedMemDMA);
336 lp->os.SharedMemAddr = NULL;
337 }
338 if (lp->os.LocalRxBuffer) {
339 pci_free_consistent(&lp->os.pdev,
340 MAX_FRAME_SIZE,
341 lp->os.LocalRxBuffer,
342 lp->os.LocalRxBufferDMA);
343 lp->os.LocalRxBuffer = NULL;
344 }
345#ifdef MEM_MAPPED_IO
346 iounmap(lp->hw.iop);
347#else
348 ioport_unmap(lp->hw.iop);
349#endif
350 pci_release_regions(pdev);
351 free_netdev(p);
352
353 pci_disable_device(pdev);
354 pci_set_drvdata(pdev, NULL);
355}
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382static int skfp_driver_init(struct net_device *dev)
383{
384 struct s_smc *smc = netdev_priv(dev);
385 skfddi_priv *bp = &smc->os;
386 int err = -EIO;
387
388 pr_debug("entering skfp_driver_init\n");
389
390
391 bp->base_addr = dev->base_addr;
392
393
394 smc->hw.irq = dev->irq;
395
396 spin_lock_init(&bp->DriverLock);
397
398
399 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
400 if (!bp->LocalRxBuffer) {
401 printk("could not allocate mem for ");
402 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
403 goto fail;
404 }
405
406
407 bp->SharedMemSize = mac_drv_check_space();
408 pr_debug("Memory for HWM: %ld\n", bp->SharedMemSize);
409 if (bp->SharedMemSize > 0) {
410 bp->SharedMemSize += 16;
411
412 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
413 bp->SharedMemSize,
414 &bp->SharedMemDMA);
415 if (!bp->SharedMemAddr) {
416 printk("could not allocate mem for ");
417 printk("hardware module: %ld byte\n",
418 bp->SharedMemSize);
419 goto fail;
420 }
421 bp->SharedMemHeap = 0;
422
423 } else {
424 bp->SharedMemAddr = NULL;
425 bp->SharedMemHeap = 0;
426 }
427
428 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
429
430 card_stop(smc);
431
432 pr_debug("mac_drv_init()..\n");
433 if (mac_drv_init(smc) != 0) {
434 pr_debug("mac_drv_init() failed\n");
435 goto fail;
436 }
437 read_address(smc, NULL);
438 pr_debug("HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
439 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
440
441 smt_reset_defaults(smc, 0);
442
443 return 0;
444
445fail:
446 if (bp->SharedMemAddr) {
447 pci_free_consistent(&bp->pdev,
448 bp->SharedMemSize,
449 bp->SharedMemAddr,
450 bp->SharedMemDMA);
451 bp->SharedMemAddr = NULL;
452 }
453 if (bp->LocalRxBuffer) {
454 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
455 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
456 bp->LocalRxBuffer = NULL;
457 }
458 return err;
459}
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483static int skfp_open(struct net_device *dev)
484{
485 struct s_smc *smc = netdev_priv(dev);
486 int err;
487
488 pr_debug("entering skfp_open\n");
489
490 err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
491 dev->name, dev);
492 if (err)
493 return err;
494
495
496
497
498
499
500
501
502
503
504
505 read_address(smc, NULL);
506 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
507
508 init_smt(smc, NULL);
509 smt_online(smc, 1);
510 STI_FBI();
511
512
513 mac_clear_multicast(smc);
514
515
516 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
517
518 netif_start_queue(dev);
519 return 0;
520}
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550static int skfp_close(struct net_device *dev)
551{
552 struct s_smc *smc = netdev_priv(dev);
553 skfddi_priv *bp = &smc->os;
554
555 CLI_FBI();
556 smt_reset_defaults(smc, 1);
557 card_stop(smc);
558 mac_drv_clear_tx_queue(smc);
559 mac_drv_clear_rx_queue(smc);
560
561 netif_stop_queue(dev);
562
563 free_irq(dev->irq, dev);
564
565 skb_queue_purge(&bp->SendSkbQueue);
566 bp->QueueSkb = MAX_TX_QUEUE_LEN;
567
568 return 0;
569}
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607static irqreturn_t skfp_interrupt(int irq, void *dev_id)
608{
609 struct net_device *dev = dev_id;
610 struct s_smc *smc;
611 skfddi_priv *bp;
612
613 smc = netdev_priv(dev);
614 bp = &smc->os;
615
616
617 if (inpd(ADDR(B0_IMSK)) == 0) {
618
619 return IRQ_NONE;
620 }
621
622 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) {
623
624 return IRQ_NONE;
625 }
626 CLI_FBI();
627 spin_lock(&bp->DriverLock);
628
629
630 fddi_isr(smc);
631
632 if (smc->os.ResetRequested) {
633 ResetAdapter(smc);
634 smc->os.ResetRequested = FALSE;
635 }
636 spin_unlock(&bp->DriverLock);
637 STI_FBI();
638
639 return IRQ_HANDLED;
640}
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
675{
676 struct s_smc *bp = netdev_priv(dev);
677
678
679
680 bp->os.MacStat.port_bs_flag[0] = 0x1234;
681 bp->os.MacStat.port_bs_flag[1] = 0x5678;
682
683#if 0
684
685
686
687
688 memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id));
689 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
690 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
691 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
692 memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data));
693 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
694 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
695 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
696 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
697 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
698 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
699 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
700 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
701 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
702 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
703 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
704 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
705 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
706 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
707 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
708 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
709 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
710 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
711 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
712 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
713 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
714 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
715 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
716 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
717 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
718 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
719 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
720 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
721 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
722 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
723 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
724 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
725 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
726 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
727 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
728 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
729 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
730 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
731 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
732 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
733 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
734 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
735 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
736 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
737 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
738 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
739 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
740 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
741 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
742 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
743 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
744 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
745 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
746 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
747 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
748 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
749 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
750 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
751 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
752 memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
753 memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
754 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
755 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
756 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
757 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
758 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
759 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
760 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
761 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
762 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
763 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
764 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
765 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
766 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
767 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
768 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
769 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
770 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
771 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
772 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
773 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
774 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
775 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
776 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
777 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
778 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
779 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
780
781
782
783
784 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
785 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
786 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
787 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
788 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
789 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
790 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
791 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
792 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
793 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
794 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
795
796#endif
797 return (struct net_device_stats *)&bp->os.MacStat;
798}
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838static void skfp_ctl_set_multicast_list(struct net_device *dev)
839{
840 struct s_smc *smc = netdev_priv(dev);
841 skfddi_priv *bp = &smc->os;
842 unsigned long Flags;
843
844 spin_lock_irqsave(&bp->DriverLock, Flags);
845 skfp_ctl_set_multicast_list_wo_lock(dev);
846 spin_unlock_irqrestore(&bp->DriverLock, Flags);
847}
848
849
850
851static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
852{
853 struct s_smc *smc = netdev_priv(dev);
854 struct netdev_hw_addr *ha;
855
856
857 if (dev->flags & IFF_PROMISC) {
858 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
859 pr_debug("PROMISCUOUS MODE ENABLED\n");
860 }
861
862 else {
863 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
864 pr_debug("PROMISCUOUS MODE DISABLED\n");
865
866
867 mac_clear_multicast(smc);
868 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
869
870 if (dev->flags & IFF_ALLMULTI) {
871 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
872 pr_debug("ENABLE ALL MC ADDRESSES\n");
873 } else if (!netdev_mc_empty(dev)) {
874 if (netdev_mc_count(dev) <= FPMAX_MULTICAST) {
875
876
877
878 netdev_for_each_mc_addr(ha, dev) {
879 mac_add_multicast(smc,
880 (struct fddi_addr *)ha->addr,
881 1);
882
883 pr_debug("ENABLE MC ADDRESS: %pMF\n",
884 ha->addr);
885 }
886
887 } else {
888
889 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
890 pr_debug("ENABLE ALL MC ADDRESSES\n");
891 }
892 } else {
893
894 pr_debug("DISABLE ALL MC ADDRESSES\n");
895 }
896
897
898 mac_update_multicast(smc);
899 }
900}
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
923{
924 struct s_smc *smc = netdev_priv(dev);
925 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
926 skfddi_priv *bp = &smc->os;
927 unsigned long Flags;
928
929
930 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
931 spin_lock_irqsave(&bp->DriverLock, Flags);
932 ResetAdapter(smc);
933 spin_unlock_irqrestore(&bp->DriverLock, Flags);
934
935 return 0;
936}
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
963{
964 struct s_smc *smc = netdev_priv(dev);
965 skfddi_priv *lp = &smc->os;
966 struct s_skfp_ioctl ioc;
967 int status = 0;
968
969 if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
970 return -EFAULT;
971
972 switch (ioc.cmd) {
973 case SKFP_GET_STATS:
974 ioc.len = sizeof(lp->MacStat);
975 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
976 ? -EFAULT : 0;
977 break;
978 case SKFP_CLR_STATS:
979 if (!capable(CAP_NET_ADMIN)) {
980 status = -EPERM;
981 } else {
982 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
983 }
984 break;
985 default:
986 printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd);
987 status = -EOPNOTSUPP;
988
989 }
990
991 return status;
992}
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
1043 struct net_device *dev)
1044{
1045 struct s_smc *smc = netdev_priv(dev);
1046 skfddi_priv *bp = &smc->os;
1047
1048 pr_debug("skfp_send_pkt\n");
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1060 bp->MacStat.gen.tx_errors++;
1061
1062 netif_start_queue(dev);
1063 dev_kfree_skb(skb);
1064 return NETDEV_TX_OK;
1065 }
1066 if (bp->QueueSkb == 0) {
1067
1068 netif_stop_queue(dev);
1069 return NETDEV_TX_BUSY;
1070 }
1071 bp->QueueSkb--;
1072 skb_queue_tail(&bp->SendSkbQueue, skb);
1073 send_queued_packets(netdev_priv(dev));
1074 if (bp->QueueSkb == 0) {
1075 netif_stop_queue(dev);
1076 }
1077 return NETDEV_TX_OK;
1078
1079}
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105static void send_queued_packets(struct s_smc *smc)
1106{
1107 skfddi_priv *bp = &smc->os;
1108 struct sk_buff *skb;
1109 unsigned char fc;
1110 int queue;
1111 struct s_smt_fp_txd *txd;
1112 dma_addr_t dma_address;
1113 unsigned long Flags;
1114
1115 int frame_status;
1116
1117 pr_debug("send queued packets\n");
1118 for (;;) {
1119
1120 skb = skb_dequeue(&bp->SendSkbQueue);
1121
1122 if (!skb) {
1123 pr_debug("queue empty\n");
1124 return;
1125 }
1126
1127 spin_lock_irqsave(&bp->DriverLock, Flags);
1128 fc = skb->data[0];
1129 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1130#ifdef ESS
1131
1132
1133 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1134
1135 if (!smc->ess.sync_bw_available)
1136 fc &= ~FC_SYNC_BIT;
1137
1138 else {
1139
1140 if (smc->mib.fddiESSSynchTxMode) {
1141
1142 fc |= FC_SYNC_BIT;
1143 }
1144 }
1145 }
1146#endif
1147 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1148
1149 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1150
1151
1152 if ((frame_status & RING_DOWN) != 0) {
1153
1154 pr_debug("Tx attempt while ring down.\n");
1155 } else if ((frame_status & OUT_OF_TXD) != 0) {
1156 pr_debug("%s: out of TXDs.\n", bp->dev->name);
1157 } else {
1158 pr_debug("%s: out of transmit resources",
1159 bp->dev->name);
1160 }
1161
1162
1163
1164 skb_queue_head(&bp->SendSkbQueue, skb);
1165 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1166 return;
1167
1168 }
1169
1170 bp->QueueSkb++;
1171
1172
1173 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1174
1175 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1176
1177 dma_address = pci_map_single(&bp->pdev, skb->data,
1178 skb->len, PCI_DMA_TODEVICE);
1179 if (frame_status & LAN_TX) {
1180 txd->txd_os.skb = skb;
1181 txd->txd_os.dma_addr = dma_address;
1182 }
1183 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1184 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1185
1186 if (!(frame_status & LAN_TX)) {
1187 pci_unmap_single(&bp->pdev, dma_address,
1188 skb->len, PCI_DMA_TODEVICE);
1189 dev_kfree_skb_irq(skb);
1190 }
1191 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1192 }
1193
1194 return;
1195
1196}
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1207{
1208 unsigned char SRBit;
1209
1210 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0)
1211
1212 return;
1213 if ((unsigned short) frame[1 + 10] != 0)
1214 return;
1215 SRBit = frame[1 + 6] & 0x01;
1216 memcpy(&frame[1 + 6], hw_addr, 6);
1217 frame[8] |= SRBit;
1218}
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232static void ResetAdapter(struct s_smc *smc)
1233{
1234
1235 pr_debug("[fddi: ResetAdapter]\n");
1236
1237
1238
1239 card_stop(smc);
1240
1241
1242 mac_drv_clear_tx_queue(smc);
1243 mac_drv_clear_rx_queue(smc);
1244
1245
1246
1247 smt_reset_defaults(smc, 1);
1248
1249 init_smt(smc, (smc->os.dev)->dev_addr);
1250
1251 smt_online(smc, 1);
1252 STI_FBI();
1253
1254
1255 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1256}
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277void llc_restart_tx(struct s_smc *smc)
1278{
1279 skfddi_priv *bp = &smc->os;
1280
1281 pr_debug("[llc_restart_tx]\n");
1282
1283
1284 spin_unlock(&bp->DriverLock);
1285 send_queued_packets(smc);
1286 spin_lock(&bp->DriverLock);
1287 netif_start_queue(bp->dev);
1288
1289}
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1308{
1309 void *virt;
1310
1311 pr_debug("mac_drv_get_space (%d bytes), ", size);
1312 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1313
1314 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1315 printk("Unexpected SMT memory size requested: %d\n", size);
1316 return NULL;
1317 }
1318 smc->os.SharedMemHeap += size;
1319
1320 pr_debug("mac_drv_get_space end\n");
1321 pr_debug("virt addr: %lx\n", (ulong) virt);
1322 pr_debug("bus addr: %lx\n", (ulong)
1323 (smc->os.SharedMemDMA +
1324 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1325 return virt;
1326}
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1348{
1349
1350 char *virt;
1351
1352 pr_debug("mac_drv_get_desc_mem\n");
1353
1354
1355
1356 virt = mac_drv_get_space(smc, size);
1357
1358 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1359 size = size % 16;
1360
1361 pr_debug("Allocate %u bytes alignment gap ", size);
1362 pr_debug("for descriptor memory.\n");
1363
1364 if (!mac_drv_get_space(smc, size)) {
1365 printk("fddi: Unable to align descriptor memory.\n");
1366 return NULL;
1367 }
1368 return virt + size;
1369}
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1386{
1387 return smc->os.SharedMemDMA +
1388 ((char *) virt - (char *)smc->os.SharedMemAddr);
1389}
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1421{
1422 return smc->os.SharedMemDMA +
1423 ((char *) virt - (char *)smc->os.SharedMemAddr);
1424}
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1449{
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462 if (flag & DMA_WR) {
1463 skfddi_priv *bp = &smc->os;
1464 volatile struct s_smt_fp_rxd *r = &descr->r;
1465
1466
1467 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1468 int MaxFrameSize = bp->MaxFrameSize;
1469
1470 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1471 MaxFrameSize, PCI_DMA_FROMDEVICE);
1472 r->rxd_os.dma_addr = 0;
1473 }
1474 }
1475}
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1493{
1494 struct sk_buff *skb;
1495
1496 pr_debug("entering mac_drv_tx_complete\n");
1497
1498
1499 if (!(skb = txd->txd_os.skb)) {
1500 pr_debug("TXD with no skb assigned.\n");
1501 return;
1502 }
1503 txd->txd_os.skb = NULL;
1504
1505
1506 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1507 skb->len, PCI_DMA_TODEVICE);
1508 txd->txd_os.dma_addr = 0;
1509
1510 smc->os.MacStat.gen.tx_packets++;
1511 smc->os.MacStat.gen.tx_bytes+=skb->len;
1512
1513
1514 dev_kfree_skb_irq(skb);
1515
1516 pr_debug("leaving mac_drv_tx_complete\n");
1517}
1518
1519
1520
1521
1522
1523
1524
1525#ifdef DUMPPACKETS
1526void dump_data(unsigned char *Data, int length)
1527{
1528 int i, j;
1529 unsigned char s[255], sh[10];
1530 if (length > 64) {
1531 length = 64;
1532 }
1533 printk(KERN_INFO "---Packet start---\n");
1534 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1535 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1536 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1537 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1538 strcpy(s, "");
1539 for (i = 0; i < length % 8; i++) {
1540 sprintf(sh, "%02x ", Data[j + i]);
1541 strcat(s, sh);
1542 }
1543 printk(KERN_INFO "%s\n", s);
1544 printk(KERN_INFO "------------------\n");
1545}
1546#else
1547#define dump_data(data,len)
1548#endif
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1575 int frag_count, int len)
1576{
1577 skfddi_priv *bp = &smc->os;
1578 struct sk_buff *skb;
1579 unsigned char *virt, *cp;
1580 unsigned short ri;
1581 u_int RifLength;
1582
1583 pr_debug("entering mac_drv_rx_complete (len=%d)\n", len);
1584 if (frag_count != 1) {
1585
1586 printk("fddi: Multi-fragment receive!\n");
1587 goto RequeueRxd;
1588
1589 }
1590 skb = rxd->rxd_os.skb;
1591 if (!skb) {
1592 pr_debug("No skb in rxd\n");
1593 smc->os.MacStat.gen.rx_errors++;
1594 goto RequeueRxd;
1595 }
1596 virt = skb->data;
1597
1598
1599
1600 dump_data(skb->data, len);
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617 if ((virt[1 + 6] & FDDI_RII) == 0)
1618 RifLength = 0;
1619 else {
1620 int n;
1621
1622 pr_debug("RIF found\n");
1623
1624 cp = virt + FDDI_MAC_HDR_LEN;
1625
1626 ri = ntohs(*((__be16 *) cp));
1627 RifLength = ri & FDDI_RCF_LEN_MASK;
1628 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1629 printk("fddi: Invalid RIF.\n");
1630 goto RequeueRxd;
1631
1632 }
1633 virt[1 + 6] &= ~FDDI_RII;
1634
1635
1636 virt = cp + RifLength;
1637 for (n = FDDI_MAC_HDR_LEN; n; n--)
1638 *--virt = *--cp;
1639
1640 skb_pull(skb, RifLength);
1641 len -= RifLength;
1642 RifLength = 0;
1643 }
1644
1645
1646 smc->os.MacStat.gen.rx_packets++;
1647
1648 smc->os.MacStat.gen.rx_bytes+=len;
1649
1650
1651 if (virt[1] & 0x01) {
1652
1653 smc->os.MacStat.gen.multicast++;
1654 }
1655
1656
1657 rxd->rxd_os.skb = NULL;
1658 skb_trim(skb, len);
1659 skb->protocol = fddi_type_trans(skb, bp->dev);
1660
1661 netif_rx(skb);
1662
1663 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1664 return;
1665
1666 RequeueRxd:
1667 pr_debug("Rx: re-queue RXD.\n");
1668 mac_drv_requeue_rxd(smc, rxd, frag_count);
1669 smc->os.MacStat.gen.rx_errors++;
1670
1671
1672}
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1694 int frag_count)
1695{
1696 volatile struct s_smt_fp_rxd *next_rxd;
1697 volatile struct s_smt_fp_rxd *src_rxd;
1698 struct sk_buff *skb;
1699 int MaxFrameSize;
1700 unsigned char *v_addr;
1701 dma_addr_t b_addr;
1702
1703 if (frag_count != 1)
1704
1705 printk("fddi: Multi-fragment requeue!\n");
1706
1707 MaxFrameSize = smc->os.MaxFrameSize;
1708 src_rxd = rxd;
1709 for (; frag_count > 0; frag_count--) {
1710 next_rxd = src_rxd->rxd_next;
1711 rxd = HWM_GET_CURR_RXD(smc);
1712
1713 skb = src_rxd->rxd_os.skb;
1714 if (skb == NULL) {
1715
1716 pr_debug("Requeue with no skb in rxd!\n");
1717 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1718 if (skb) {
1719
1720 rxd->rxd_os.skb = skb;
1721 skb_reserve(skb, 3);
1722 skb_put(skb, MaxFrameSize);
1723 v_addr = skb->data;
1724 b_addr = pci_map_single(&smc->os.pdev,
1725 v_addr,
1726 MaxFrameSize,
1727 PCI_DMA_FROMDEVICE);
1728 rxd->rxd_os.dma_addr = b_addr;
1729 } else {
1730
1731 pr_debug("Queueing invalid buffer!\n");
1732 rxd->rxd_os.skb = NULL;
1733 v_addr = smc->os.LocalRxBuffer;
1734 b_addr = smc->os.LocalRxBufferDMA;
1735 }
1736 } else {
1737
1738 rxd->rxd_os.skb = skb;
1739 v_addr = skb->data;
1740 b_addr = pci_map_single(&smc->os.pdev,
1741 v_addr,
1742 MaxFrameSize,
1743 PCI_DMA_FROMDEVICE);
1744 rxd->rxd_os.dma_addr = b_addr;
1745 }
1746 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1747 FIRST_FRAG | LAST_FRAG);
1748
1749 src_rxd = next_rxd;
1750 }
1751}
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770void mac_drv_fill_rxd(struct s_smc *smc)
1771{
1772 int MaxFrameSize;
1773 unsigned char *v_addr;
1774 unsigned long b_addr;
1775 struct sk_buff *skb;
1776 volatile struct s_smt_fp_rxd *rxd;
1777
1778 pr_debug("entering mac_drv_fill_rxd\n");
1779
1780
1781
1782
1783 MaxFrameSize = smc->os.MaxFrameSize;
1784
1785 while (HWM_GET_RX_FREE(smc) > 0) {
1786 pr_debug(".\n");
1787
1788 rxd = HWM_GET_CURR_RXD(smc);
1789 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1790 if (skb) {
1791
1792 skb_reserve(skb, 3);
1793 skb_put(skb, MaxFrameSize);
1794 v_addr = skb->data;
1795 b_addr = pci_map_single(&smc->os.pdev,
1796 v_addr,
1797 MaxFrameSize,
1798 PCI_DMA_FROMDEVICE);
1799 rxd->rxd_os.dma_addr = b_addr;
1800 } else {
1801
1802
1803
1804
1805
1806 pr_debug("Queueing invalid buffer!\n");
1807 v_addr = smc->os.LocalRxBuffer;
1808 b_addr = smc->os.LocalRxBufferDMA;
1809 }
1810
1811 rxd->rxd_os.skb = skb;
1812
1813
1814 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1815 FIRST_FRAG | LAST_FRAG);
1816 }
1817 pr_debug("leaving mac_drv_fill_rxd\n");
1818}
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1838 int frag_count)
1839{
1840
1841 struct sk_buff *skb;
1842
1843 pr_debug("entering mac_drv_clear_rxd\n");
1844
1845 if (frag_count != 1)
1846
1847 printk("fddi: Multi-fragment clear!\n");
1848
1849 for (; frag_count > 0; frag_count--) {
1850 skb = rxd->rxd_os.skb;
1851 if (skb != NULL) {
1852 skfddi_priv *bp = &smc->os;
1853 int MaxFrameSize = bp->MaxFrameSize;
1854
1855 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
1856 MaxFrameSize, PCI_DMA_FROMDEVICE);
1857
1858 dev_kfree_skb(skb);
1859 rxd->rxd_os.skb = NULL;
1860 }
1861 rxd = rxd->rxd_next;
1862
1863 }
1864}
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1895 char *look_ahead, int la_len)
1896{
1897 struct sk_buff *skb;
1898
1899 pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
1900
1901
1902
1903 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1904 pr_debug("fddi: Discard invalid local SMT frame\n");
1905 pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1906 len, la_len, (unsigned long) look_ahead);
1907 return 0;
1908 }
1909 skb = alloc_skb(len + 3, GFP_ATOMIC);
1910 if (!skb) {
1911 pr_debug("fddi: Local SMT: skb memory exhausted.\n");
1912 return 0;
1913 }
1914 skb_reserve(skb, 3);
1915 skb_put(skb, len);
1916 skb_copy_to_linear_data(skb, look_ahead, len);
1917
1918
1919 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1920 netif_rx(skb);
1921
1922 return 0;
1923}
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941void smt_timer_poll(struct s_smc *smc)
1942{
1943}
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959void ring_status_indication(struct s_smc *smc, u_long status)
1960{
1961 pr_debug("ring_status_indication( ");
1962 if (status & RS_RES15)
1963 pr_debug("RS_RES15 ");
1964 if (status & RS_HARDERROR)
1965 pr_debug("RS_HARDERROR ");
1966 if (status & RS_SOFTERROR)
1967 pr_debug("RS_SOFTERROR ");
1968 if (status & RS_BEACON)
1969 pr_debug("RS_BEACON ");
1970 if (status & RS_PATHTEST)
1971 pr_debug("RS_PATHTEST ");
1972 if (status & RS_SELFTEST)
1973 pr_debug("RS_SELFTEST ");
1974 if (status & RS_RES9)
1975 pr_debug("RS_RES9 ");
1976 if (status & RS_DISCONNECT)
1977 pr_debug("RS_DISCONNECT ");
1978 if (status & RS_RES7)
1979 pr_debug("RS_RES7 ");
1980 if (status & RS_DUPADDR)
1981 pr_debug("RS_DUPADDR ");
1982 if (status & RS_NORINGOP)
1983 pr_debug("RS_NORINGOP ");
1984 if (status & RS_VERSION)
1985 pr_debug("RS_VERSION ");
1986 if (status & RS_STUCKBYPASSS)
1987 pr_debug("RS_STUCKBYPASSS ");
1988 if (status & RS_EVENT)
1989 pr_debug("RS_EVENT ");
1990 if (status & RS_RINGOPCHANGE)
1991 pr_debug("RS_RINGOPCHANGE ");
1992 if (status & RS_RES0)
1993 pr_debug("RS_RES0 ");
1994 pr_debug("]\n");
1995}
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013unsigned long smt_get_time(void)
2014{
2015 return jiffies;
2016}
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033void smt_stat_counter(struct s_smc *smc, int stat)
2034{
2035
2036
2037 pr_debug("smt_stat_counter\n");
2038 switch (stat) {
2039 case 0:
2040 pr_debug("Ring operational change.\n");
2041 break;
2042 case 1:
2043 pr_debug("Receive fifo overflow.\n");
2044 smc->os.MacStat.gen.rx_errors++;
2045 break;
2046 default:
2047 pr_debug("Unknown status (%d).\n", stat);
2048 break;
2049 }
2050}
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069void cfm_state_change(struct s_smc *smc, int c_state)
2070{
2071#ifdef DRIVERDEBUG
2072 char *s;
2073
2074 switch (c_state) {
2075 case SC0_ISOLATED:
2076 s = "SC0_ISOLATED";
2077 break;
2078 case SC1_WRAP_A:
2079 s = "SC1_WRAP_A";
2080 break;
2081 case SC2_WRAP_B:
2082 s = "SC2_WRAP_B";
2083 break;
2084 case SC4_THRU_A:
2085 s = "SC4_THRU_A";
2086 break;
2087 case SC5_THRU_B:
2088 s = "SC5_THRU_B";
2089 break;
2090 case SC7_WRAP_S:
2091 s = "SC7_WRAP_S";
2092 break;
2093 case SC9_C_WRAP_A:
2094 s = "SC9_C_WRAP_A";
2095 break;
2096 case SC10_C_WRAP_B:
2097 s = "SC10_C_WRAP_B";
2098 break;
2099 case SC11_C_WRAP_S:
2100 s = "SC11_C_WRAP_S";
2101 break;
2102 default:
2103 pr_debug("cfm_state_change: unknown %d\n", c_state);
2104 return;
2105 }
2106 pr_debug("cfm_state_change: %s\n", s);
2107#endif
2108}
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127void ecm_state_change(struct s_smc *smc, int e_state)
2128{
2129#ifdef DRIVERDEBUG
2130 char *s;
2131
2132 switch (e_state) {
2133 case EC0_OUT:
2134 s = "EC0_OUT";
2135 break;
2136 case EC1_IN:
2137 s = "EC1_IN";
2138 break;
2139 case EC2_TRACE:
2140 s = "EC2_TRACE";
2141 break;
2142 case EC3_LEAVE:
2143 s = "EC3_LEAVE";
2144 break;
2145 case EC4_PATH_TEST:
2146 s = "EC4_PATH_TEST";
2147 break;
2148 case EC5_INSERT:
2149 s = "EC5_INSERT";
2150 break;
2151 case EC6_CHECK:
2152 s = "EC6_CHECK";
2153 break;
2154 case EC7_DEINSERT:
2155 s = "EC7_DEINSERT";
2156 break;
2157 default:
2158 s = "unknown";
2159 break;
2160 }
2161 pr_debug("ecm_state_change: %s\n", s);
2162#endif
2163}
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182void rmt_state_change(struct s_smc *smc, int r_state)
2183{
2184#ifdef DRIVERDEBUG
2185 char *s;
2186
2187 switch (r_state) {
2188 case RM0_ISOLATED:
2189 s = "RM0_ISOLATED";
2190 break;
2191 case RM1_NON_OP:
2192 s = "RM1_NON_OP - not operational";
2193 break;
2194 case RM2_RING_OP:
2195 s = "RM2_RING_OP - ring operational";
2196 break;
2197 case RM3_DETECT:
2198 s = "RM3_DETECT - detect dupl addresses";
2199 break;
2200 case RM4_NON_OP_DUP:
2201 s = "RM4_NON_OP_DUP - dupl. addr detected";
2202 break;
2203 case RM5_RING_OP_DUP:
2204 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2205 break;
2206 case RM6_DIRECTED:
2207 s = "RM6_DIRECTED - sending directed beacons";
2208 break;
2209 case RM7_TRACE:
2210 s = "RM7_TRACE - trace initiated";
2211 break;
2212 default:
2213 s = "unknown";
2214 break;
2215 }
2216 pr_debug("[rmt_state_change: %s]\n", s);
2217#endif
2218}
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234void drv_reset_indication(struct s_smc *smc)
2235{
2236 pr_debug("entering drv_reset_indication\n");
2237
2238 smc->os.ResetRequested = TRUE;
2239
2240}
2241
2242static struct pci_driver skfddi_pci_driver = {
2243 .name = "skfddi",
2244 .id_table = skfddi_pci_tbl,
2245 .probe = skfp_init_one,
2246 .remove = __devexit_p(skfp_remove_one),
2247};
2248
2249static int __init skfd_init(void)
2250{
2251 return pci_register_driver(&skfddi_pci_driver);
2252}
2253
2254static void __exit skfd_exit(void)
2255{
2256 pci_unregister_driver(&skfddi_pci_driver);
2257}
2258
2259module_init(skfd_init);
2260module_exit(skfd_exit);
2261