5 * Copyright Information:
6 * Copyright SysKonnect 1998,1999.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The information in this file is provided "AS IS" without warranty.
16 * A Linux device driver supporting the SysKonnect FDDI PCI controller
20 * CG Christoph Goos (cgoos@syskonnect.de)
25 * Address all question to:
28 * The technical manual for the adapters is available from SysKonnect's
29 * web pages: www.syskonnect.com
30 * Goto "Support" and search Knowledge Base for "manual".
32 * Driver Architecture:
33 * The driver architecture is based on the DEC FDDI driver by
34 * Lawrence V. Stefani and several ethernet drivers.
35 * I also used an existing Windows NT miniport driver.
36 * All hardware dependent fuctions are handled by the SysKonnect
38 * The only headerfiles that are directly related to this source
39 * are skfddi.c, h/types.h, h/osdef1st.h, h/targetos.h.
40 * The others belong to the SysKonnect FDDI Hardware Module and
41 * should better not be changed.
43 * Modification History:
44 * Date Name Description
45 * 02-Mar-98 CG Created.
47 * 10-Mar-99 CG Support for 2.2.x added.
48 * 25-Mar-99 CG Corrected IRQ routing for SMP (APIC)
49 * 26-Oct-99 CG Fixed compilation error on 2.2.13
50 * 12-Nov-99 CG Source code release
51 * 22-Nov-99 CG Included in kernel source.
52 * 07-May-00 DM 64 bit fixes, new dma interface
53 * 31-Jul-03 DB Audit copy_*_user in skfp_ioctl
54 * Daniele Bellucci <bellucda@tiscali.it>
55 * 03-Dec-03 SH Convert to PCI device model
57 * Compilation options (-Dxxx):
58 * DRIVERDEBUG print lots of messages to log file
59 * DUMPPACKETS print received/transmitted packets to logfile
61 * Tested cpu architectures:
66 /* Version information string - should be updated prior to */
67 /* each new release!!! */
68 #define VERSION "2.07"
70 static 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)";
76 #include <linux/module.h>
77 #include <linux/kernel.h>
78 #include <linux/errno.h>
79 #include <linux/ioport.h>
80 #include <linux/slab.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>
88 #include <asm/byteorder.h>
90 #include <asm/uaccess.h>
93 #undef ADDR // undo Linux definition
97 #include "h/smtstate.h"
100 // Define module-wide (static) routines
101 static int skfp_driver_init(struct net_device *dev);
102 static int skfp_open(struct net_device *dev);
103 static int skfp_close(struct net_device *dev);
104 static irqreturn_t skfp_interrupt(int irq, void *dev_id);
105 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
106 static void skfp_ctl_set_multicast_list(struct net_device *dev);
107 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
108 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
109 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
110 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev);
111 static void send_queued_packets(struct s_smc *smc);
112 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
113 static void ResetAdapter(struct s_smc *smc);
116 // Functions needed by the hardware module
117 void *mac_drv_get_space(struct s_smc *smc, u_int size);
118 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
119 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
120 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
121 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
123 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
124 void llc_restart_tx(struct s_smc *smc);
125 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
126 int frag_count, int len);
127 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
129 void mac_drv_fill_rxd(struct s_smc *smc);
130 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
132 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
134 void dump_data(unsigned char *Data, int length);
136 // External functions from the hardware module
137 extern u_int mac_drv_check_space(void);
138 extern void read_address(struct s_smc *smc, u_char * mac_addr);
139 extern void card_stop(struct s_smc *smc);
140 extern int mac_drv_init(struct s_smc *smc);
141 extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
142 int len, int frame_status);
143 extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
144 int frame_len, int frame_status);
145 extern int init_smt(struct s_smc *smc, u_char * mac_addr);
146 extern void fddi_isr(struct s_smc *smc);
147 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
148 int len, int frame_status);
149 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
150 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
151 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
153 static struct pci_device_id skfddi_pci_tbl[] = {
154 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
155 { } /* Terminating entry */
157 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
158 MODULE_LICENSE("GPL");
159 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
161 // Define module-wide (static) variables
163 static int num_boards; /* total number of adapters configured */
166 #define PRINTK(s, args...) printk(s, ## args)
168 #define PRINTK(s, args...)
169 #endif // DRIVERDEBUG
177 * Probes for supported FDDI PCI controllers
183 * pdev - pointer to PCI device information
185 * Functional Description:
186 * This is now called by PCI driver registration process
187 * for each board found.
190 * 0 - This device (fddi0, fddi1, etc) configured successfully
191 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
192 * present for this device name
196 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
197 * initialized and the board resources are read and stored in
198 * the device structure.
200 static int skfp_init_one(struct pci_dev *pdev,
201 const struct pci_device_id *ent)
203 struct net_device *dev;
204 struct s_smc *smc; /* board pointer */
208 PRINTK(KERN_INFO "entering skfp_init_one\n");
211 printk("%s\n", boot_msg);
213 err = pci_enable_device(pdev);
217 err = pci_request_regions(pdev, "skfddi");
221 pci_set_master(pdev);
224 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
225 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
230 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
232 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
233 printk(KERN_ERR "skfp: region is not PIO resource\n");
238 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
241 printk(KERN_ERR "skfp: Unable to map register, "
242 "FDDI adapter will be disabled.\n");
247 dev = alloc_fddidev(sizeof(struct s_smc));
249 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
250 "FDDI adapter will be disabled.\n");
255 dev->irq = pdev->irq;
256 dev->get_stats = &skfp_ctl_get_stats;
257 dev->open = &skfp_open;
258 dev->stop = &skfp_close;
259 dev->hard_start_xmit = &skfp_send_pkt;
260 dev->set_multicast_list = &skfp_ctl_set_multicast_list;
261 dev->set_mac_address = &skfp_ctl_set_mac_address;
262 dev->do_ioctl = &skfp_ioctl;
263 dev->header_cache_update = NULL; /* not supported */
265 SET_NETDEV_DEV(dev, &pdev->dev);
267 /* Initialize board structure with bus-specific info */
268 smc = netdev_priv(dev);
270 smc->os.bus_type = SK_BUS_TYPE_PCI;
271 smc->os.pdev = *pdev;
272 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
273 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
277 smc->os.ResetRequested = FALSE;
278 skb_queue_head_init(&smc->os.SendSkbQueue);
280 dev->base_addr = (unsigned long)mem;
282 err = skfp_driver_init(dev);
286 err = register_netdev(dev);
291 pci_set_drvdata(pdev, dev);
293 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
294 (pdev->subsystem_device & 0xff00) == 0x5800)
295 printk("%s: SysKonnect FDDI PCI adapter"
296 " found (SK-%04X)\n", dev->name,
297 pdev->subsystem_device);
299 printk("%s: FDDI PCI adapter found\n", dev->name);
303 if (smc->os.SharedMemAddr)
304 pci_free_consistent(pdev, smc->os.SharedMemSize,
305 smc->os.SharedMemAddr,
306 smc->os.SharedMemDMA);
307 pci_free_consistent(pdev, MAX_FRAME_SIZE,
308 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
318 pci_release_regions(pdev);
320 pci_disable_device(pdev);
325 * Called for each adapter board from pci_unregister_driver
327 static void __devexit skfp_remove_one(struct pci_dev *pdev)
329 struct net_device *p = pci_get_drvdata(pdev);
330 struct s_smc *lp = netdev_priv(p);
332 unregister_netdev(p);
334 if (lp->os.SharedMemAddr) {
335 pci_free_consistent(&lp->os.pdev,
336 lp->os.SharedMemSize,
337 lp->os.SharedMemAddr,
338 lp->os.SharedMemDMA);
339 lp->os.SharedMemAddr = NULL;
341 if (lp->os.LocalRxBuffer) {
342 pci_free_consistent(&lp->os.pdev,
344 lp->os.LocalRxBuffer,
345 lp->os.LocalRxBufferDMA);
346 lp->os.LocalRxBuffer = NULL;
351 ioport_unmap(lp->hw.iop);
353 pci_release_regions(pdev);
356 pci_disable_device(pdev);
357 pci_set_drvdata(pdev, NULL);
361 * ====================
362 * = skfp_driver_init =
363 * ====================
366 * Initializes remaining adapter board structure information
367 * and makes sure adapter is in a safe state prior to skfp_open().
373 * dev - pointer to device information
375 * Functional Description:
376 * This function allocates additional resources such as the host memory
377 * blocks needed by the adapter.
378 * The adapter is also reset. The OS must call skfp_open() to open
379 * the adapter and bring it on-line.
382 * 0 - initialization succeeded
383 * -1 - initialization failed
385 static int skfp_driver_init(struct net_device *dev)
387 struct s_smc *smc = netdev_priv(dev);
388 skfddi_priv *bp = &smc->os;
391 PRINTK(KERN_INFO "entering skfp_driver_init\n");
393 // set the io address in private structures
394 bp->base_addr = dev->base_addr;
396 // Get the interrupt level from the PCI Configuration Table
397 smc->hw.irq = dev->irq;
399 spin_lock_init(&bp->DriverLock);
401 // Allocate invalid frame
402 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
403 if (!bp->LocalRxBuffer) {
404 printk("could not allocate mem for ");
405 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
409 // Determine the required size of the 'shared' memory area.
410 bp->SharedMemSize = mac_drv_check_space();
411 PRINTK(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize);
412 if (bp->SharedMemSize > 0) {
413 bp->SharedMemSize += 16; // for descriptor alignment
415 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
418 if (!bp->SharedMemSize) {
419 printk("could not allocate mem for ");
420 printk("hardware module: %ld byte\n",
424 bp->SharedMemHeap = 0; // Nothing used yet.
427 bp->SharedMemAddr = NULL;
428 bp->SharedMemHeap = 0;
429 } // SharedMemSize > 0
431 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
433 card_stop(smc); // Reset adapter.
435 PRINTK(KERN_INFO "mac_drv_init()..\n");
436 if (mac_drv_init(smc) != 0) {
437 PRINTK(KERN_INFO "mac_drv_init() failed.\n");
440 read_address(smc, NULL);
441 PRINTK(KERN_INFO "HW-Addr: %02x %02x %02x %02x %02x %02x\n",
442 smc->hw.fddi_canon_addr.a[0],
443 smc->hw.fddi_canon_addr.a[1],
444 smc->hw.fddi_canon_addr.a[2],
445 smc->hw.fddi_canon_addr.a[3],
446 smc->hw.fddi_canon_addr.a[4],
447 smc->hw.fddi_canon_addr.a[5]);
448 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
450 smt_reset_defaults(smc, 0);
455 if (bp->SharedMemAddr) {
456 pci_free_consistent(&bp->pdev,
460 bp->SharedMemAddr = NULL;
462 if (bp->LocalRxBuffer) {
463 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
464 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
465 bp->LocalRxBuffer = NULL;
468 } // skfp_driver_init
483 * dev - pointer to device information
485 * Functional Description:
486 * This function brings the adapter to an operational state.
489 * 0 - Adapter was successfully opened
490 * -EAGAIN - Could not register IRQ
492 static int skfp_open(struct net_device *dev)
494 struct s_smc *smc = netdev_priv(dev);
497 PRINTK(KERN_INFO "entering skfp_open\n");
498 /* Register IRQ - support shared interrupts by passing device ptr */
499 err = request_irq(dev->irq, (void *) skfp_interrupt, IRQF_SHARED,
505 * Set current address to factory MAC address
507 * Note: We've already done this step in skfp_driver_init.
508 * However, it's possible that a user has set a node
509 * address override, then closed and reopened the
510 * adapter. Unless we reset the device address field
511 * now, we'll continue to use the existing modified
514 read_address(smc, NULL);
515 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
521 /* Clear local multicast address tables */
522 mac_clear_multicast(smc);
524 /* Disable promiscuous filter settings */
525 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
527 netif_start_queue(dev);
538 * Closes the device/module.
544 * dev - pointer to device information
546 * Functional Description:
547 * This routine closes the adapter and brings it to a safe state.
548 * The interrupt service routine is deregistered with the OS.
549 * The adapter can be opened again with another call to skfp_open().
555 * No further requests for this adapter are made after this routine is
556 * called. skfp_open() can be called to reset and reinitialize the
559 static int skfp_close(struct net_device *dev)
561 struct s_smc *smc = netdev_priv(dev);
562 skfddi_priv *bp = &smc->os;
565 smt_reset_defaults(smc, 1);
567 mac_drv_clear_tx_queue(smc);
568 mac_drv_clear_rx_queue(smc);
570 netif_stop_queue(dev);
571 /* Deregister (free) IRQ */
572 free_irq(dev->irq, dev);
574 skb_queue_purge(&bp->SendSkbQueue);
575 bp->QueueSkb = MAX_TX_QUEUE_LEN;
587 * Interrupt processing routine
593 * irq - interrupt vector
594 * dev_id - pointer to device information
596 * Functional Description:
597 * This routine calls the interrupt processing routine for this adapter. It
598 * disables and reenables adapter interrupts, as appropriate. We can support
599 * shared interrupts since the incoming dev_id pointer provides our device
600 * structure context. All the real work is done in the hardware module.
606 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
607 * on Intel-based systems) is done by the operating system outside this
610 * System interrupts are enabled through this call.
613 * Interrupts are disabled, then reenabled at the adapter.
616 irqreturn_t skfp_interrupt(int irq, void *dev_id)
618 struct net_device *dev = dev_id;
619 struct s_smc *smc; /* private board structure pointer */
622 smc = netdev_priv(dev);
625 // IRQs enabled or disabled ?
626 if (inpd(ADDR(B0_IMSK)) == 0) {
627 // IRQs are disabled: must be shared interrupt
630 // Note: At this point, IRQs are enabled.
631 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
632 // Adapter did not issue an IRQ: must be shared interrupt
635 CLI_FBI(); // Disable IRQs from our adapter.
636 spin_lock(&bp->DriverLock);
638 // Call interrupt handler in hardware module (HWM).
641 if (smc->os.ResetRequested) {
643 smc->os.ResetRequested = FALSE;
645 spin_unlock(&bp->DriverLock);
646 STI_FBI(); // Enable IRQs from our adapter.
653 * ======================
654 * = skfp_ctl_get_stats =
655 * ======================
658 * Get statistics for FDDI adapter
661 * Pointer to FDDI statistics structure
664 * dev - pointer to device information
666 * Functional Description:
667 * Gets current MIB objects from adapter, then
668 * returns FDDI statistics structure as defined
671 * Note: Since the FDDI statistics structure is
672 * still new and the device structure doesn't
673 * have an FDDI-specific get statistics handler,
674 * we'll return the FDDI statistics structure as
675 * a pointer to an Ethernet statistics structure.
676 * That way, at least the first part of the statistics
677 * structure can be decoded properly.
678 * We'll have to pay attention to this routine as the
679 * device structure becomes more mature and LAN media
683 struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
685 struct s_smc *bp = netdev_priv(dev);
687 /* Fill the bp->stats structure with driver-maintained counters */
689 bp->os.MacStat.port_bs_flag[0] = 0x1234;
690 bp->os.MacStat.port_bs_flag[1] = 0x5678;
691 // goos: need to fill out fddi statistic
693 /* Get FDDI SMT MIB objects */
695 /* Fill the bp->stats structure with the SMT MIB object values */
697 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));
698 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
699 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
700 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
701 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));
702 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
703 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
704 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
705 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
706 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
707 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
708 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
709 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
710 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
711 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
712 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
713 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
714 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
715 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
716 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
717 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
718 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
719 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
720 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
721 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
722 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
723 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
724 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
725 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
726 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
727 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
728 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
729 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
730 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
731 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
732 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
733 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
734 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
735 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
736 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
737 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
738 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
739 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
740 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
741 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
742 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
743 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
744 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
745 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
746 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
747 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
748 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
749 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
750 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
751 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
752 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
753 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
754 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
755 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
756 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
757 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
758 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
759 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
760 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
761 memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
762 memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
763 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
764 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
765 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
766 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
767 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
768 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
769 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
770 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
771 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
772 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
773 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
774 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
775 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
776 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
777 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
778 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
779 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
780 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
781 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
782 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
783 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
784 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
785 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
786 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
787 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
788 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
791 /* Fill the bp->stats structure with the FDDI counter values */
793 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
794 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
795 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
796 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
797 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
798 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
799 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
800 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
801 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
802 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
803 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
806 return ((struct net_device_stats *) &bp->os.MacStat);
811 * ==============================
812 * = skfp_ctl_set_multicast_list =
813 * ==============================
816 * Enable/Disable LLC frame promiscuous mode reception
817 * on the adapter and/or update multicast address table.
823 * dev - pointer to device information
825 * Functional Description:
826 * This function acquires the driver lock and only calls
827 * skfp_ctl_set_multicast_list_wo_lock then.
828 * This routine follows a fairly simple algorithm for setting the
829 * adapter filters and CAM:
831 * if IFF_PROMISC flag is set
832 * enable promiscuous mode
834 * disable promiscuous mode
835 * if number of multicast addresses <= max. multicast number
836 * add mc addresses to adapter table
838 * enable promiscuous mode
839 * update adapter filters
842 * Multicast addresses are presented in canonical (LSB) format.
845 * On-board adapter filters are updated.
847 static void skfp_ctl_set_multicast_list(struct net_device *dev)
849 struct s_smc *smc = netdev_priv(dev);
850 skfddi_priv *bp = &smc->os;
853 spin_lock_irqsave(&bp->DriverLock, Flags);
854 skfp_ctl_set_multicast_list_wo_lock(dev);
855 spin_unlock_irqrestore(&bp->DriverLock, Flags);
857 } // skfp_ctl_set_multicast_list
861 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
863 struct s_smc *smc = netdev_priv(dev);
864 struct dev_mc_list *dmi; /* ptr to multicast addr entry */
867 /* Enable promiscuous mode, if necessary */
868 if (dev->flags & IFF_PROMISC) {
869 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
870 PRINTK(KERN_INFO "PROMISCUOUS MODE ENABLED\n");
872 /* Else, update multicast address table */
874 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
875 PRINTK(KERN_INFO "PROMISCUOUS MODE DISABLED\n");
877 // Reset all MC addresses
878 mac_clear_multicast(smc);
879 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
881 if (dev->flags & IFF_ALLMULTI) {
882 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
883 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
884 } else if (dev->mc_count > 0) {
885 if (dev->mc_count <= FPMAX_MULTICAST) {
886 /* use exact filtering */
888 // point to first multicast addr
891 for (i = 0; i < dev->mc_count; i++) {
892 mac_add_multicast(smc,
893 (struct fddi_addr *)dmi->dmi_addr,
896 PRINTK(KERN_INFO "ENABLE MC ADDRESS:");
897 PRINTK(" %02x %02x %02x ",
901 PRINTK("%02x %02x %02x\n",
908 } else { // more MC addresses than HW supports
910 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
911 PRINTK(KERN_INFO "ENABLE ALL MC ADDRESSES\n");
913 } else { // no MC addresses
915 PRINTK(KERN_INFO "DISABLE ALL MC ADDRESSES\n");
918 /* Update adapter filters */
919 mac_update_multicast(smc);
922 } // skfp_ctl_set_multicast_list_wo_lock
926 * ===========================
927 * = skfp_ctl_set_mac_address =
928 * ===========================
931 * set new mac address on adapter and update dev_addr field in device table.
937 * dev - pointer to device information
938 * addr - pointer to sockaddr structure containing unicast address to set
941 * The address pointed to by addr->sa_data is a valid unicast
942 * address and is presented in canonical (LSB) format.
944 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
946 struct s_smc *smc = netdev_priv(dev);
947 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
948 skfddi_priv *bp = &smc->os;
952 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
953 spin_lock_irqsave(&bp->DriverLock, Flags);
955 spin_unlock_irqrestore(&bp->DriverLock, Flags);
957 return (0); /* always return zero */
958 } // skfp_ctl_set_mac_address
968 * Perform IOCTL call functions here. Some are privileged operations and the
969 * effective uid is checked in those cases.
977 * dev - pointer to device information
978 * rq - pointer to ioctl request structure
984 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
986 struct s_smc *smc = netdev_priv(dev);
987 skfddi_priv *lp = &smc->os;
988 struct s_skfp_ioctl ioc;
991 if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
995 case SKFP_GET_STATS: /* Get the driver statistics */
996 ioc.len = sizeof(lp->MacStat);
997 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
1000 case SKFP_CLR_STATS: /* Zero out the driver statistics */
1001 if (!capable(CAP_NET_ADMIN)) {
1002 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
1008 printk("ioctl for %s: unknow cmd: %04x\n", dev->name, ioc.cmd);
1009 status = -EOPNOTSUPP;
1018 * =====================
1020 * =====================
1023 * Queues a packet for transmission and try to transmit it.
1029 * skb - pointer to sk_buff to queue for transmission
1030 * dev - pointer to device information
1032 * Functional Description:
1033 * Here we assume that an incoming skb transmit request
1034 * is contained in a single physically contiguous buffer
1035 * in which the virtual address of the start of packet
1036 * (skb->data) can be converted to a physical address
1037 * by using pci_map_single().
1039 * We have an internal queue for packets we can not send
1040 * immediately. Packets in this queue can be given to the
1041 * adapter if transmit buffers are freed.
1043 * We can't free the skb until after it's been DMA'd
1044 * out by the adapter, so we'll keep it in the driver and
1045 * return it in mac_drv_tx_complete.
1048 * 0 - driver has queued and/or sent packet
1049 * 1 - caller should requeue the sk_buff for later transmission
1052 * The entire packet is stored in one physically
1053 * contiguous buffer which is not cached and whose
1054 * 32-bit physical address can be determined.
1056 * It's vital that this routine is NOT reentered for the
1057 * same board and that the OS is not in another section of
1058 * code (eg. skfp_interrupt) for the same board on a
1064 static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
1066 struct s_smc *smc = netdev_priv(dev);
1067 skfddi_priv *bp = &smc->os;
1069 PRINTK(KERN_INFO "skfp_send_pkt\n");
1072 * Verify that incoming transmit request is OK
1074 * Note: The packet size check is consistent with other
1075 * Linux device drivers, although the correct packet
1076 * size should be verified before calling the
1080 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1081 bp->MacStat.gen.tx_errors++; /* bump error counter */
1082 // dequeue packets from xmt queue and send them
1083 netif_start_queue(dev);
1085 return (0); /* return "success" */
1087 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1089 netif_stop_queue(dev);
1093 skb_queue_tail(&bp->SendSkbQueue, skb);
1094 send_queued_packets(netdev_priv(dev));
1095 if (bp->QueueSkb == 0) {
1096 netif_stop_queue(dev);
1098 dev->trans_start = jiffies;
1105 * =======================
1106 * = send_queued_packets =
1107 * =======================
1110 * Send packets from the driver queue as long as there are some and
1111 * transmit resources are available.
1117 * smc - pointer to smc (adapter) structure
1119 * Functional Description:
1120 * Take a packet from queue if there is any. If not, then we are done.
1121 * Check if there are resources to send the packet. If not, requeue it
1123 * Set packet descriptor flags and give packet to adapter.
1124 * Check if any send resources can be freed (we do not use the
1125 * transmit complete interrupt).
1127 static void send_queued_packets(struct s_smc *smc)
1129 skfddi_priv *bp = &smc->os;
1130 struct sk_buff *skb;
1133 struct s_smt_fp_txd *txd; // Current TxD.
1134 dma_addr_t dma_address;
1135 unsigned long Flags;
1137 int frame_status; // HWM tx frame status.
1139 PRINTK(KERN_INFO "send queued packets\n");
1141 // send first buffer from queue
1142 skb = skb_dequeue(&bp->SendSkbQueue);
1145 PRINTK(KERN_INFO "queue empty\n");
1149 spin_lock_irqsave(&bp->DriverLock, Flags);
1151 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1153 // Check if the frame may/must be sent as a synchronous frame.
1155 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1156 // It's an LLC frame.
1157 if (!smc->ess.sync_bw_available)
1158 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1160 else { // Bandwidth is available.
1162 if (smc->mib.fddiESSSynchTxMode) {
1163 // Send as sync. frame.
1169 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1171 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1172 // Unable to send the frame.
1174 if ((frame_status & RING_DOWN) != 0) {
1176 PRINTK("Tx attempt while ring down.\n");
1177 } else if ((frame_status & OUT_OF_TXD) != 0) {
1178 PRINTK("%s: out of TXDs.\n", bp->dev->name);
1180 PRINTK("%s: out of transmit resources",
1184 // Note: We will retry the operation as soon as
1185 // transmit resources become available.
1186 skb_queue_head(&bp->SendSkbQueue, skb);
1187 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1188 return; // Packet has been queued.
1190 } // if (unable to send frame)
1192 bp->QueueSkb++; // one packet less in local queue
1194 // source address in packet ?
1195 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1197 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1199 dma_address = pci_map_single(&bp->pdev, skb->data,
1200 skb->len, PCI_DMA_TODEVICE);
1201 if (frame_status & LAN_TX) {
1202 txd->txd_os.skb = skb; // save skb
1203 txd->txd_os.dma_addr = dma_address; // save dma mapping
1205 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1206 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1208 if (!(frame_status & LAN_TX)) { // local only frame
1209 pci_unmap_single(&bp->pdev, dma_address,
1210 skb->len, PCI_DMA_TODEVICE);
1211 dev_kfree_skb_irq(skb);
1213 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1216 return; // never reached
1218 } // send_queued_packets
1221 /************************
1223 * CheckSourceAddress
1225 * Verify if the source address is set. Insert it if necessary.
1227 ************************/
1228 void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1230 unsigned char SRBit;
1232 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1235 if ((unsigned short) frame[1 + 10] != 0)
1237 SRBit = frame[1 + 6] & 0x01;
1238 memcpy(&frame[1 + 6], hw_addr, 6);
1240 } // CheckSourceAddress
1243 /************************
1247 * Reset the adapter and bring it back to operational mode.
1249 * smc - A pointer to the SMT context struct.
1253 ************************/
1254 static void ResetAdapter(struct s_smc *smc)
1257 PRINTK(KERN_INFO "[fddi: ResetAdapter]\n");
1259 // Stop the adapter.
1261 card_stop(smc); // Stop all activity.
1263 // Clear the transmit and receive descriptor queues.
1264 mac_drv_clear_tx_queue(smc);
1265 mac_drv_clear_rx_queue(smc);
1267 // Restart the adapter.
1269 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1271 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1273 smt_online(smc, 1); // Insert into the ring again.
1276 // Restore original receive mode (multicasts, promiscuous, etc.).
1277 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1281 //--------------- functions called by hardware module ----------------
1283 /************************
1287 * The hardware driver calls this routine when the transmit complete
1288 * interrupt bits (end of frame) for the synchronous or asynchronous
1291 * NOTE The hardware driver calls this function also if no packets are queued.
1292 * The routine must be able to handle this case.
1294 * smc - A pointer to the SMT context struct.
1298 ************************/
1299 void llc_restart_tx(struct s_smc *smc)
1301 skfddi_priv *bp = &smc->os;
1303 PRINTK(KERN_INFO "[llc_restart_tx]\n");
1305 // Try to send queued packets
1306 spin_unlock(&bp->DriverLock);
1307 send_queued_packets(smc);
1308 spin_lock(&bp->DriverLock);
1309 netif_start_queue(bp->dev);// system may send again if it was blocked
1314 /************************
1318 * The hardware module calls this function to allocate the memory
1319 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1321 * smc - A pointer to the SMT context struct.
1323 * size - Size of memory in bytes to allocate.
1325 * != 0 A pointer to the virtual address of the allocated memory.
1326 * == 0 Allocation error.
1328 ************************/
1329 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1333 PRINTK(KERN_INFO "mac_drv_get_space (%d bytes), ", size);
1334 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1336 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1337 printk("Unexpected SMT memory size requested: %d\n", size);
1340 smc->os.SharedMemHeap += size; // Move heap pointer.
1342 PRINTK(KERN_INFO "mac_drv_get_space end\n");
1343 PRINTK(KERN_INFO "virt addr: %lx\n", (ulong) virt);
1344 PRINTK(KERN_INFO "bus addr: %lx\n", (ulong)
1345 (smc->os.SharedMemDMA +
1346 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1348 } // mac_drv_get_space
1351 /************************
1353 * mac_drv_get_desc_mem
1355 * This function is called by the hardware dependent module.
1356 * It allocates the memory for the RxD and TxD descriptors.
1358 * This memory must be non-cached, non-movable and non-swappable.
1359 * This memory should start at a physical page boundary.
1361 * smc - A pointer to the SMT context struct.
1363 * size - Size of memory in bytes to allocate.
1365 * != 0 A pointer to the virtual address of the allocated memory.
1366 * == 0 Allocation error.
1368 ************************/
1369 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1374 PRINTK(KERN_INFO "mac_drv_get_desc_mem\n");
1376 // Descriptor memory must be aligned on 16-byte boundary.
1378 virt = mac_drv_get_space(smc, size);
1380 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1383 PRINTK("Allocate %u bytes alignment gap ", size);
1384 PRINTK("for descriptor memory.\n");
1386 if (!mac_drv_get_space(smc, size)) {
1387 printk("fddi: Unable to align descriptor memory.\n");
1390 return (virt + size);
1391 } // mac_drv_get_desc_mem
1394 /************************
1398 * Get the physical address of a given virtual address.
1400 * smc - A pointer to the SMT context struct.
1402 * virt - A (virtual) pointer into our 'shared' memory area.
1404 * Physical address of the given virtual address.
1406 ************************/
1407 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1409 return (smc->os.SharedMemDMA +
1410 ((char *) virt - (char *)smc->os.SharedMemAddr));
1411 } // mac_drv_virt2phys
1414 /************************
1418 * The HWM calls this function, when the driver leads through a DMA
1419 * transfer. If the OS-specific module must prepare the system hardware
1420 * for the DMA transfer, it should do it in this function.
1422 * The hardware module calls this dma_master if it wants to send an SMT
1423 * frame. This means that the virt address passed in here is part of
1424 * the 'shared' memory area.
1426 * smc - A pointer to the SMT context struct.
1428 * virt - The virtual address of the data.
1430 * len - The length in bytes of the data.
1432 * flag - Indicates the transmit direction and the buffer type:
1433 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1434 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1435 * SMT_BUF (0x80) SMT buffer
1437 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1439 * Returns the pyhsical address for the DMA transfer.
1441 ************************/
1442 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1444 return (smc->os.SharedMemDMA +
1445 ((char *) virt - (char *)smc->os.SharedMemAddr));
1449 /************************
1453 * The hardware module calls this routine when it has completed a DMA
1454 * transfer. If the operating system dependent module has set up the DMA
1455 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1458 * smc - A pointer to the SMT context struct.
1460 * descr - A pointer to a TxD or RxD, respectively.
1462 * flag - Indicates the DMA transfer direction / SMT buffer:
1463 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1464 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1465 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1469 ************************/
1470 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1472 /* For TX buffers, there are two cases. If it is an SMT transmit
1473 * buffer, there is nothing to do since we use consistent memory
1474 * for the 'shared' memory area. The other case is for normal
1475 * transmit packets given to us by the networking stack, and in
1476 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1479 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1480 * because the hardware module is about to potentially look at
1481 * the contents of the buffer. If we did not call the PCI DMA
1482 * unmap first, the hardware module could read inconsistent data.
1484 if (flag & DMA_WR) {
1485 skfddi_priv *bp = &smc->os;
1486 volatile struct s_smt_fp_rxd *r = &descr->r;
1488 /* If SKB is NULL, we used the local buffer. */
1489 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1490 int MaxFrameSize = bp->MaxFrameSize;
1492 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1493 MaxFrameSize, PCI_DMA_FROMDEVICE);
1494 r->rxd_os.dma_addr = 0;
1500 /************************
1502 * mac_drv_tx_complete
1504 * Transmit of a packet is complete. Release the tx staging buffer.
1507 * smc - A pointer to the SMT context struct.
1509 * txd - A pointer to the last TxD which is used by the frame.
1513 ************************/
1514 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1516 struct sk_buff *skb;
1518 PRINTK(KERN_INFO "entering mac_drv_tx_complete\n");
1519 // Check if this TxD points to a skb
1521 if (!(skb = txd->txd_os.skb)) {
1522 PRINTK("TXD with no skb assigned.\n");
1525 txd->txd_os.skb = NULL;
1527 // release the DMA mapping
1528 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1529 skb->len, PCI_DMA_TODEVICE);
1530 txd->txd_os.dma_addr = 0;
1532 smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
1533 smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1536 dev_kfree_skb_irq(skb);
1538 PRINTK(KERN_INFO "leaving mac_drv_tx_complete\n");
1539 } // mac_drv_tx_complete
1542 /************************
1544 * dump packets to logfile
1546 ************************/
1548 void dump_data(unsigned char *Data, int length)
1551 unsigned char s[255], sh[10];
1555 printk(KERN_INFO "---Packet start---\n");
1556 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1557 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1558 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1559 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1561 for (i = 0; i < length % 8; i++) {
1562 sprintf(sh, "%02x ", Data[j + i]);
1565 printk(KERN_INFO "%s\n", s);
1566 printk(KERN_INFO "------------------\n");
1569 #define dump_data(data,len)
1570 #endif // DUMPPACKETS
1572 /************************
1574 * mac_drv_rx_complete
1576 * The hardware module calls this function if an LLC frame is received
1577 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1578 * from the network will be passed to the LLC layer by this function
1579 * if passing is enabled.
1581 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1582 * be received. It also fills the RxD ring with new receive buffers if
1583 * some can be queued.
1585 * smc - A pointer to the SMT context struct.
1587 * rxd - A pointer to the first RxD which is used by the receive frame.
1589 * frag_count - Count of RxDs used by the received frame.
1591 * len - Frame length.
1595 ************************/
1596 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1597 int frag_count, int len)
1599 skfddi_priv *bp = &smc->os;
1600 struct sk_buff *skb;
1601 unsigned char *virt, *cp;
1605 PRINTK(KERN_INFO "entering mac_drv_rx_complete (len=%d)\n", len);
1606 if (frag_count != 1) { // This is not allowed to happen.
1608 printk("fddi: Multi-fragment receive!\n");
1609 goto RequeueRxd; // Re-use the given RXD(s).
1612 skb = rxd->rxd_os.skb;
1614 PRINTK(KERN_INFO "No skb in rxd\n");
1615 smc->os.MacStat.gen.rx_errors++;
1620 // The DMA mapping was released in dma_complete above.
1622 dump_data(skb->data, len);
1625 * FDDI Frame format:
1626 * +-------+-------+-------+------------+--------+------------+
1627 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1628 * +-------+-------+-------+------------+--------+------------+
1630 * FC = Frame Control
1631 * DA = Destination Address
1632 * SA = Source Address
1633 * RIF = Routing Information Field
1634 * LLC = Logical Link Control
1637 // Remove Routing Information Field (RIF), if present.
1639 if ((virt[1 + 6] & FDDI_RII) == 0)
1643 // goos: RIF removal has still to be tested
1644 PRINTK(KERN_INFO "RIF found\n");
1645 // Get RIF length from Routing Control (RC) field.
1646 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1648 ri = ntohs(*((unsigned short *) cp));
1649 RifLength = ri & FDDI_RCF_LEN_MASK;
1650 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1651 printk("fddi: Invalid RIF.\n");
1652 goto RequeueRxd; // Discard the frame.
1655 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1658 virt = cp + RifLength;
1659 for (n = FDDI_MAC_HDR_LEN; n; n--)
1661 // adjust sbd->data pointer
1662 skb_pull(skb, RifLength);
1667 // Count statistics.
1668 smc->os.MacStat.gen.rx_packets++; // Count indicated receive
1670 smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
1672 // virt points to header again
1673 if (virt[1] & 0x01) { // Check group (multicast) bit.
1675 smc->os.MacStat.gen.multicast++;
1678 // deliver frame to system
1679 rxd->rxd_os.skb = NULL;
1681 skb->protocol = fddi_type_trans(skb, bp->dev);
1684 bp->dev->last_rx = jiffies;
1686 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1690 PRINTK(KERN_INFO "Rx: re-queue RXD.\n");
1691 mac_drv_requeue_rxd(smc, rxd, frag_count);
1692 smc->os.MacStat.gen.rx_errors++; // Count receive packets
1695 } // mac_drv_rx_complete
1698 /************************
1700 * mac_drv_requeue_rxd
1702 * The hardware module calls this function to request the OS-specific
1703 * module to queue the receive buffer(s) represented by the pointer
1704 * to the RxD and the frag_count into the receive queue again. This
1705 * buffer was filled with an invalid frame or an SMT frame.
1707 * smc - A pointer to the SMT context struct.
1709 * rxd - A pointer to the first RxD which is used by the receive frame.
1711 * frag_count - Count of RxDs used by the received frame.
1715 ************************/
1716 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1719 volatile struct s_smt_fp_rxd *next_rxd;
1720 volatile struct s_smt_fp_rxd *src_rxd;
1721 struct sk_buff *skb;
1723 unsigned char *v_addr;
1726 if (frag_count != 1) // This is not allowed to happen.
1728 printk("fddi: Multi-fragment requeue!\n");
1730 MaxFrameSize = smc->os.MaxFrameSize;
1732 for (; frag_count > 0; frag_count--) {
1733 next_rxd = src_rxd->rxd_next;
1734 rxd = HWM_GET_CURR_RXD(smc);
1736 skb = src_rxd->rxd_os.skb;
1737 if (skb == NULL) { // this should not happen
1739 PRINTK("Requeue with no skb in rxd!\n");
1740 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1743 rxd->rxd_os.skb = skb;
1744 skb_reserve(skb, 3);
1745 skb_put(skb, MaxFrameSize);
1747 b_addr = pci_map_single(&smc->os.pdev,
1750 PCI_DMA_FROMDEVICE);
1751 rxd->rxd_os.dma_addr = b_addr;
1753 // no skb available, use local buffer
1754 PRINTK("Queueing invalid buffer!\n");
1755 rxd->rxd_os.skb = NULL;
1756 v_addr = smc->os.LocalRxBuffer;
1757 b_addr = smc->os.LocalRxBufferDMA;
1760 // we use skb from old rxd
1761 rxd->rxd_os.skb = skb;
1763 b_addr = pci_map_single(&smc->os.pdev,
1766 PCI_DMA_FROMDEVICE);
1767 rxd->rxd_os.dma_addr = b_addr;
1769 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1770 FIRST_FRAG | LAST_FRAG);
1774 } // mac_drv_requeue_rxd
1777 /************************
1781 * The hardware module calls this function at initialization time
1782 * to fill the RxD ring with receive buffers. It is also called by
1783 * mac_drv_rx_complete if rx_free is large enough to queue some new
1784 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
1785 * receive buffers as long as enough RxDs and receive buffers are
1788 * smc - A pointer to the SMT context struct.
1792 ************************/
1793 void mac_drv_fill_rxd(struct s_smc *smc)
1796 unsigned char *v_addr;
1797 unsigned long b_addr;
1798 struct sk_buff *skb;
1799 volatile struct s_smt_fp_rxd *rxd;
1801 PRINTK(KERN_INFO "entering mac_drv_fill_rxd\n");
1803 // Walk through the list of free receive buffers, passing receive
1804 // buffers to the HWM as long as RXDs are available.
1806 MaxFrameSize = smc->os.MaxFrameSize;
1807 // Check if there is any RXD left.
1808 while (HWM_GET_RX_FREE(smc) > 0) {
1809 PRINTK(KERN_INFO ".\n");
1811 rxd = HWM_GET_CURR_RXD(smc);
1812 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1815 skb_reserve(skb, 3);
1816 skb_put(skb, MaxFrameSize);
1818 b_addr = pci_map_single(&smc->os.pdev,
1821 PCI_DMA_FROMDEVICE);
1822 rxd->rxd_os.dma_addr = b_addr;
1824 // no skb available, use local buffer
1825 // System has run out of buffer memory, but we want to
1826 // keep the receiver running in hope of better times.
1827 // Multiple descriptors may point to this local buffer,
1828 // so data in it must be considered invalid.
1829 PRINTK("Queueing invalid buffer!\n");
1830 v_addr = smc->os.LocalRxBuffer;
1831 b_addr = smc->os.LocalRxBufferDMA;
1834 rxd->rxd_os.skb = skb;
1836 // Pass receive buffer to HWM.
1837 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1838 FIRST_FRAG | LAST_FRAG);
1840 PRINTK(KERN_INFO "leaving mac_drv_fill_rxd\n");
1841 } // mac_drv_fill_rxd
1844 /************************
1848 * The hardware module calls this function to release unused
1851 * smc - A pointer to the SMT context struct.
1853 * rxd - A pointer to the first RxD which is used by the receive buffer.
1855 * frag_count - Count of RxDs used by the receive buffer.
1859 ************************/
1860 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1864 struct sk_buff *skb;
1866 PRINTK("entering mac_drv_clear_rxd\n");
1868 if (frag_count != 1) // This is not allowed to happen.
1870 printk("fddi: Multi-fragment clear!\n");
1872 for (; frag_count > 0; frag_count--) {
1873 skb = rxd->rxd_os.skb;
1875 skfddi_priv *bp = &smc->os;
1876 int MaxFrameSize = bp->MaxFrameSize;
1878 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
1879 MaxFrameSize, PCI_DMA_FROMDEVICE);
1882 rxd->rxd_os.skb = NULL;
1884 rxd = rxd->rxd_next; // Next RXD.
1887 } // mac_drv_clear_rxd
1890 /************************
1894 * The hardware module calls this routine when an SMT or NSA frame of the
1895 * local SMT should be delivered to the LLC layer.
1897 * It is necessary to have this function, because there is no other way to
1898 * copy the contents of SMT MBufs into receive buffers.
1900 * mac_drv_rx_init allocates the required target memory for this frame,
1901 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
1903 * smc - A pointer to the SMT context struct.
1905 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1907 * fc - The Frame Control field of the received frame.
1909 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
1911 * la_len - The length of the lookahead data stored in the lookahead
1912 * buffer (may be zero).
1914 * Always returns zero (0).
1916 ************************/
1917 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1918 char *look_ahead, int la_len)
1920 struct sk_buff *skb;
1922 PRINTK("entering mac_drv_rx_init(len=%d)\n", len);
1924 // "Received" a SMT or NSA frame of the local SMT.
1926 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1927 PRINTK("fddi: Discard invalid local SMT frame\n");
1928 PRINTK(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1929 len, la_len, (unsigned long) look_ahead);
1932 skb = alloc_skb(len + 3, GFP_ATOMIC);
1934 PRINTK("fddi: Local SMT: skb memory exhausted.\n");
1937 skb_reserve(skb, 3);
1939 skb_copy_to_linear_data(skb, look_ahead, len);
1941 // deliver frame to system
1942 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1943 skb->dev->last_rx = jiffies;
1947 } // mac_drv_rx_init
1950 /************************
1954 * This routine is called periodically by the SMT module to clean up the
1957 * Return any queued frames back to the upper protocol layers if the ring
1960 * smc - A pointer to the SMT context struct.
1964 ************************/
1965 void smt_timer_poll(struct s_smc *smc)
1970 /************************
1972 * ring_status_indication
1974 * This function indicates a change of the ring state.
1976 * smc - A pointer to the SMT context struct.
1978 * status - The current ring status.
1982 ************************/
1983 void ring_status_indication(struct s_smc *smc, u_long status)
1985 PRINTK("ring_status_indication( ");
1986 if (status & RS_RES15)
1987 PRINTK("RS_RES15 ");
1988 if (status & RS_HARDERROR)
1989 PRINTK("RS_HARDERROR ");
1990 if (status & RS_SOFTERROR)
1991 PRINTK("RS_SOFTERROR ");
1992 if (status & RS_BEACON)
1993 PRINTK("RS_BEACON ");
1994 if (status & RS_PATHTEST)
1995 PRINTK("RS_PATHTEST ");
1996 if (status & RS_SELFTEST)
1997 PRINTK("RS_SELFTEST ");
1998 if (status & RS_RES9)
2000 if (status & RS_DISCONNECT)
2001 PRINTK("RS_DISCONNECT ");
2002 if (status & RS_RES7)
2004 if (status & RS_DUPADDR)
2005 PRINTK("RS_DUPADDR ");
2006 if (status & RS_NORINGOP)
2007 PRINTK("RS_NORINGOP ");
2008 if (status & RS_VERSION)
2009 PRINTK("RS_VERSION ");
2010 if (status & RS_STUCKBYPASSS)
2011 PRINTK("RS_STUCKBYPASSS ");
2012 if (status & RS_EVENT)
2013 PRINTK("RS_EVENT ");
2014 if (status & RS_RINGOPCHANGE)
2015 PRINTK("RS_RINGOPCHANGE ");
2016 if (status & RS_RES0)
2019 } // ring_status_indication
2022 /************************
2026 * Gets the current time from the system.
2030 * The current time in TICKS_PER_SECOND.
2032 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
2033 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
2034 * to the time returned by smt_get_time().
2036 ************************/
2037 unsigned long smt_get_time(void)
2043 /************************
2047 * Status counter update (ring_op, fifo full).
2049 * smc - A pointer to the SMT context struct.
2051 * stat - = 0: A ring operational change occurred.
2052 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2056 ************************/
2057 void smt_stat_counter(struct s_smc *smc, int stat)
2059 // BOOLEAN RingIsUp ;
2061 PRINTK(KERN_INFO "smt_stat_counter\n");
2064 PRINTK(KERN_INFO "Ring operational change.\n");
2067 PRINTK(KERN_INFO "Receive fifo overflow.\n");
2068 smc->os.MacStat.gen.rx_errors++;
2071 PRINTK(KERN_INFO "Unknown status (%d).\n", stat);
2074 } // smt_stat_counter
2077 /************************
2081 * Sets CFM state in custom statistics.
2083 * smc - A pointer to the SMT context struct.
2085 * c_state - Possible values are:
2087 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2088 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2092 ************************/
2093 void cfm_state_change(struct s_smc *smc, int c_state)
2121 s = "SC10_C_WRAP_B";
2124 s = "SC11_C_WRAP_S";
2127 PRINTK(KERN_INFO "cfm_state_change: unknown %d\n", c_state);
2130 PRINTK(KERN_INFO "cfm_state_change: %s\n", s);
2131 #endif // DRIVERDEBUG
2132 } // cfm_state_change
2135 /************************
2139 * Sets ECM state in custom statistics.
2141 * smc - A pointer to the SMT context struct.
2143 * e_state - Possible values are:
2145 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2146 * SC5_THRU_B (7), SC7_WRAP_S (8)
2150 ************************/
2151 void ecm_state_change(struct s_smc *smc, int e_state)
2170 s = "EC4_PATH_TEST";
2185 PRINTK(KERN_INFO "ecm_state_change: %s\n", s);
2186 #endif //DRIVERDEBUG
2187 } // ecm_state_change
2190 /************************
2194 * Sets RMT state in custom statistics.
2196 * smc - A pointer to the SMT context struct.
2198 * r_state - Possible values are:
2200 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2201 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2205 ************************/
2206 void rmt_state_change(struct s_smc *smc, int r_state)
2216 s = "RM1_NON_OP - not operational";
2219 s = "RM2_RING_OP - ring operational";
2222 s = "RM3_DETECT - detect dupl addresses";
2224 case RM4_NON_OP_DUP:
2225 s = "RM4_NON_OP_DUP - dupl. addr detected";
2227 case RM5_RING_OP_DUP:
2228 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2231 s = "RM6_DIRECTED - sending directed beacons";
2234 s = "RM7_TRACE - trace initiated";
2240 PRINTK(KERN_INFO "[rmt_state_change: %s]\n", s);
2241 #endif // DRIVERDEBUG
2242 } // rmt_state_change
2245 /************************
2247 * drv_reset_indication
2249 * This function is called by the SMT when it has detected a severe
2250 * hardware problem. The driver should perform a reset on the adapter
2251 * as soon as possible, but not from within this function.
2253 * smc - A pointer to the SMT context struct.
2257 ************************/
2258 void drv_reset_indication(struct s_smc *smc)
2260 PRINTK(KERN_INFO "entering drv_reset_indication\n");
2262 smc->os.ResetRequested = TRUE; // Set flag.
2264 } // drv_reset_indication
2266 static struct pci_driver skfddi_pci_driver = {
2268 .id_table = skfddi_pci_tbl,
2269 .probe = skfp_init_one,
2270 .remove = __devexit_p(skfp_remove_one),
2273 static int __init skfd_init(void)
2275 return pci_register_driver(&skfddi_pci_driver);
2278 static void __exit skfd_exit(void)
2280 pci_unregister_driver(&skfddi_pci_driver);
2283 module_init(skfd_init);
2284 module_exit(skfd_exit);