1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright Information:
7 * Copyright SysKonnect 1998,1999.
9 * The information in this file is provided "AS IS" without warranty.
12 * A Linux device driver supporting the SysKonnect FDDI PCI controller
16 * CG Christoph Goos (cgoos@syskonnect.de)
21 * Address all question to:
24 * The technical manual for the adapters is available from SysKonnect's
25 * web pages: www.syskonnect.com
26 * Goto "Support" and search Knowledge Base for "manual".
28 * Driver Architecture:
29 * The driver architecture is based on the DEC FDDI driver by
30 * Lawrence V. Stefani and several ethernet drivers.
31 * I also used an existing Windows NT miniport driver.
32 * All hardware dependent functions are handled by the SysKonnect
34 * The only headerfiles that are directly related to this source
35 * are skfddi.c, h/types.h, h/osdef1st.h, h/targetos.h.
36 * The others belong to the SysKonnect FDDI Hardware Module and
37 * should better not be changed.
39 * Modification History:
40 * Date Name Description
41 * 02-Mar-98 CG Created.
43 * 10-Mar-99 CG Support for 2.2.x added.
44 * 25-Mar-99 CG Corrected IRQ routing for SMP (APIC)
45 * 26-Oct-99 CG Fixed compilation error on 2.2.13
46 * 12-Nov-99 CG Source code release
47 * 22-Nov-99 CG Included in kernel source.
48 * 07-May-00 DM 64 bit fixes, new dma interface
49 * 31-Jul-03 DB Audit copy_*_user in skfp_ioctl
50 * Daniele Bellucci <bellucda@tiscali.it>
51 * 03-Dec-03 SH Convert to PCI device model
53 * Compilation options (-Dxxx):
54 * DRIVERDEBUG print lots of messages to log file
55 * DUMPPACKETS print received/transmitted packets to logfile
57 * Tested cpu architectures:
62 /* Version information string - should be updated prior to */
63 /* each new release!!! */
64 #define VERSION "2.07"
66 static const char * const boot_msg =
67 "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n"
68 " SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)";
72 #include <linux/capability.h>
73 #include <linux/compat.h>
74 #include <linux/module.h>
75 #include <linux/kernel.h>
76 #include <linux/errno.h>
77 #include <linux/ioport.h>
78 #include <linux/interrupt.h>
79 #include <linux/pci.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/fddidevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/bitops.h>
85 #include <linux/gfp.h>
87 #include <asm/byteorder.h>
89 #include <linux/uaccess.h>
92 #undef ADDR // undo Linux definition
96 #include "h/smtstate.h"
99 // Define module-wide (static) routines
100 static int skfp_driver_init(struct net_device *dev);
101 static int skfp_open(struct net_device *dev);
102 static int skfp_close(struct net_device *dev);
103 static irqreturn_t skfp_interrupt(int irq, void *dev_id);
104 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
105 static void skfp_ctl_set_multicast_list(struct net_device *dev);
106 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
107 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
108 static int skfp_siocdevprivate(struct net_device *dev, struct ifreq *rq,
109 void __user *data, int cmd);
110 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
111 struct net_device *dev);
112 static void send_queued_packets(struct s_smc *smc);
113 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
114 static void ResetAdapter(struct s_smc *smc);
117 // Functions needed by the hardware module
118 void *mac_drv_get_space(struct s_smc *smc, u_int size);
119 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
120 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
121 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
122 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
124 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
125 void llc_restart_tx(struct s_smc *smc);
126 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
127 int frag_count, int len);
128 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
130 void mac_drv_fill_rxd(struct s_smc *smc);
131 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
133 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
135 void dump_data(unsigned char *Data, int length);
137 // External functions from the hardware module
138 extern u_int mac_drv_check_space(void);
139 extern int mac_drv_init(struct s_smc *smc);
140 extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
141 int len, int frame_status);
142 extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
143 int frame_len, int frame_status);
144 extern void fddi_isr(struct s_smc *smc);
145 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
146 int len, int frame_status);
147 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
148 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
149 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
151 static const struct pci_device_id skfddi_pci_tbl[] = {
152 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
153 { } /* Terminating entry */
155 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
156 MODULE_LICENSE("GPL");
157 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
159 // Define module-wide (static) variables
161 static int num_boards; /* total number of adapters configured */
163 static const struct net_device_ops skfp_netdev_ops = {
164 .ndo_open = skfp_open,
165 .ndo_stop = skfp_close,
166 .ndo_start_xmit = skfp_send_pkt,
167 .ndo_get_stats = skfp_ctl_get_stats,
168 .ndo_set_rx_mode = skfp_ctl_set_multicast_list,
169 .ndo_set_mac_address = skfp_ctl_set_mac_address,
170 .ndo_siocdevprivate = skfp_siocdevprivate,
179 * Probes for supported FDDI PCI controllers
185 * pdev - pointer to PCI device information
187 * Functional Description:
188 * This is now called by PCI driver registration process
189 * for each board found.
192 * 0 - This device (fddi0, fddi1, etc) configured successfully
193 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
194 * present for this device name
198 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
199 * initialized and the board resources are read and stored in
200 * the device structure.
202 static int skfp_init_one(struct pci_dev *pdev,
203 const struct pci_device_id *ent)
205 struct net_device *dev;
206 struct s_smc *smc; /* board pointer */
210 pr_debug("entering skfp_init_one\n");
213 printk("%s\n", boot_msg);
215 err = pci_enable_device(pdev);
219 err = pci_request_regions(pdev, "skfddi");
223 pci_set_master(pdev);
226 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
227 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
232 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
234 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
235 printk(KERN_ERR "skfp: region is not PIO resource\n");
240 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
243 printk(KERN_ERR "skfp: Unable to map register, "
244 "FDDI adapter will be disabled.\n");
249 dev = alloc_fddidev(sizeof(struct s_smc));
251 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
252 "FDDI adapter will be disabled.\n");
257 dev->irq = pdev->irq;
258 dev->netdev_ops = &skfp_netdev_ops;
260 SET_NETDEV_DEV(dev, &pdev->dev);
262 /* Initialize board structure with bus-specific info */
263 smc = netdev_priv(dev);
265 smc->os.bus_type = SK_BUS_TYPE_PCI;
266 smc->os.pdev = *pdev;
267 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
268 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
272 smc->os.ResetRequested = FALSE;
273 skb_queue_head_init(&smc->os.SendSkbQueue);
275 dev->base_addr = (unsigned long)mem;
277 err = skfp_driver_init(dev);
281 err = register_netdev(dev);
286 pci_set_drvdata(pdev, dev);
288 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
289 (pdev->subsystem_device & 0xff00) == 0x5800)
290 printk("%s: SysKonnect FDDI PCI adapter"
291 " found (SK-%04X)\n", dev->name,
292 pdev->subsystem_device);
294 printk("%s: FDDI PCI adapter found\n", dev->name);
298 if (smc->os.SharedMemAddr)
299 dma_free_coherent(&pdev->dev, smc->os.SharedMemSize,
300 smc->os.SharedMemAddr,
301 smc->os.SharedMemDMA);
302 dma_free_coherent(&pdev->dev, MAX_FRAME_SIZE,
303 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
313 pci_release_regions(pdev);
315 pci_disable_device(pdev);
320 * Called for each adapter board from pci_unregister_driver
322 static void skfp_remove_one(struct pci_dev *pdev)
324 struct net_device *p = pci_get_drvdata(pdev);
325 struct s_smc *lp = netdev_priv(p);
327 unregister_netdev(p);
329 if (lp->os.SharedMemAddr) {
330 dma_free_coherent(&pdev->dev,
331 lp->os.SharedMemSize,
332 lp->os.SharedMemAddr,
333 lp->os.SharedMemDMA);
334 lp->os.SharedMemAddr = NULL;
336 if (lp->os.LocalRxBuffer) {
337 dma_free_coherent(&pdev->dev,
339 lp->os.LocalRxBuffer,
340 lp->os.LocalRxBufferDMA);
341 lp->os.LocalRxBuffer = NULL;
346 ioport_unmap(lp->hw.iop);
348 pci_release_regions(pdev);
351 pci_disable_device(pdev);
355 * ====================
356 * = skfp_driver_init =
357 * ====================
360 * Initializes remaining adapter board structure information
361 * and makes sure adapter is in a safe state prior to skfp_open().
367 * dev - pointer to device information
369 * Functional Description:
370 * This function allocates additional resources such as the host memory
371 * blocks needed by the adapter.
372 * The adapter is also reset. The OS must call skfp_open() to open
373 * the adapter and bring it on-line.
376 * 0 - initialization succeeded
377 * -1 - initialization failed
379 static int skfp_driver_init(struct net_device *dev)
381 struct s_smc *smc = netdev_priv(dev);
382 skfddi_priv *bp = &smc->os;
385 pr_debug("entering skfp_driver_init\n");
387 // set the io address in private structures
388 bp->base_addr = dev->base_addr;
390 // Get the interrupt level from the PCI Configuration Table
391 smc->hw.irq = dev->irq;
393 spin_lock_init(&bp->DriverLock);
395 // Allocate invalid frame
396 bp->LocalRxBuffer = dma_alloc_coherent(&bp->pdev.dev, MAX_FRAME_SIZE,
397 &bp->LocalRxBufferDMA,
399 if (!bp->LocalRxBuffer) {
400 printk("could not allocate mem for ");
401 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
405 // Determine the required size of the 'shared' memory area.
406 bp->SharedMemSize = mac_drv_check_space();
407 pr_debug("Memory for HWM: %ld\n", bp->SharedMemSize);
408 if (bp->SharedMemSize > 0) {
409 bp->SharedMemSize += 16; // for descriptor alignment
411 bp->SharedMemAddr = dma_alloc_coherent(&bp->pdev.dev,
415 if (!bp->SharedMemAddr) {
416 printk("could not allocate mem for ");
417 printk("hardware module: %ld byte\n",
423 bp->SharedMemAddr = NULL;
426 bp->SharedMemHeap = 0;
428 card_stop(smc); // Reset adapter.
430 pr_debug("mac_drv_init()..\n");
431 if (mac_drv_init(smc) != 0) {
432 pr_debug("mac_drv_init() failed\n");
435 read_address(smc, NULL);
436 pr_debug("HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
437 eth_hw_addr_set(dev, smc->hw.fddi_canon_addr.a);
439 smt_reset_defaults(smc, 0);
444 if (bp->SharedMemAddr) {
445 dma_free_coherent(&bp->pdev.dev,
449 bp->SharedMemAddr = NULL;
451 if (bp->LocalRxBuffer) {
452 dma_free_coherent(&bp->pdev.dev, MAX_FRAME_SIZE,
453 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
454 bp->LocalRxBuffer = NULL;
457 } // skfp_driver_init
472 * dev - pointer to device information
474 * Functional Description:
475 * This function brings the adapter to an operational state.
478 * 0 - Adapter was successfully opened
479 * -EAGAIN - Could not register IRQ
481 static int skfp_open(struct net_device *dev)
483 struct s_smc *smc = netdev_priv(dev);
486 pr_debug("entering skfp_open\n");
487 /* Register IRQ - support shared interrupts by passing device ptr */
488 err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
494 * Set current address to factory MAC address
496 * Note: We've already done this step in skfp_driver_init.
497 * However, it's possible that a user has set a node
498 * address override, then closed and reopened the
499 * adapter. Unless we reset the device address field
500 * now, we'll continue to use the existing modified
503 read_address(smc, NULL);
504 eth_hw_addr_set(dev, smc->hw.fddi_canon_addr.a);
510 /* Clear local multicast address tables */
511 mac_clear_multicast(smc);
513 /* Disable promiscuous filter settings */
514 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
516 netif_start_queue(dev);
527 * Closes the device/module.
533 * dev - pointer to device information
535 * Functional Description:
536 * This routine closes the adapter and brings it to a safe state.
537 * The interrupt service routine is deregistered with the OS.
538 * The adapter can be opened again with another call to skfp_open().
544 * No further requests for this adapter are made after this routine is
545 * called. skfp_open() can be called to reset and reinitialize the
548 static int skfp_close(struct net_device *dev)
550 struct s_smc *smc = netdev_priv(dev);
551 skfddi_priv *bp = &smc->os;
554 smt_reset_defaults(smc, 1);
556 mac_drv_clear_tx_queue(smc);
557 mac_drv_clear_rx_queue(smc);
559 netif_stop_queue(dev);
560 /* Deregister (free) IRQ */
561 free_irq(dev->irq, dev);
563 skb_queue_purge(&bp->SendSkbQueue);
564 bp->QueueSkb = MAX_TX_QUEUE_LEN;
576 * Interrupt processing routine
582 * irq - interrupt vector
583 * dev_id - pointer to device information
585 * Functional Description:
586 * This routine calls the interrupt processing routine for this adapter. It
587 * disables and reenables adapter interrupts, as appropriate. We can support
588 * shared interrupts since the incoming dev_id pointer provides our device
589 * structure context. All the real work is done in the hardware module.
595 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
596 * on Intel-based systems) is done by the operating system outside this
599 * System interrupts are enabled through this call.
602 * Interrupts are disabled, then reenabled at the adapter.
605 static irqreturn_t skfp_interrupt(int irq, void *dev_id)
607 struct net_device *dev = dev_id;
608 struct s_smc *smc; /* private board structure pointer */
611 smc = netdev_priv(dev);
614 // IRQs enabled or disabled ?
615 if (inpd(ADDR(B0_IMSK)) == 0) {
616 // IRQs are disabled: must be shared interrupt
619 // Note: At this point, IRQs are enabled.
620 if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
621 // Adapter did not issue an IRQ: must be shared interrupt
624 CLI_FBI(); // Disable IRQs from our adapter.
625 spin_lock(&bp->DriverLock);
627 // Call interrupt handler in hardware module (HWM).
630 if (smc->os.ResetRequested) {
632 smc->os.ResetRequested = FALSE;
634 spin_unlock(&bp->DriverLock);
635 STI_FBI(); // Enable IRQs from our adapter.
642 * ======================
643 * = skfp_ctl_get_stats =
644 * ======================
647 * Get statistics for FDDI adapter
650 * Pointer to FDDI statistics structure
653 * dev - pointer to device information
655 * Functional Description:
656 * Gets current MIB objects from adapter, then
657 * returns FDDI statistics structure as defined
660 * Note: Since the FDDI statistics structure is
661 * still new and the device structure doesn't
662 * have an FDDI-specific get statistics handler,
663 * we'll return the FDDI statistics structure as
664 * a pointer to an Ethernet statistics structure.
665 * That way, at least the first part of the statistics
666 * structure can be decoded properly.
667 * We'll have to pay attention to this routine as the
668 * device structure becomes more mature and LAN media
672 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
674 struct s_smc *bp = netdev_priv(dev);
676 /* Fill the bp->stats structure with driver-maintained counters */
678 bp->os.MacStat.port_bs_flag[0] = 0x1234;
679 bp->os.MacStat.port_bs_flag[1] = 0x5678;
680 // goos: need to fill out fddi statistic
682 /* Get FDDI SMT MIB objects */
684 /* Fill the bp->stats structure with the SMT MIB object values */
686 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));
687 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
688 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
689 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
690 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));
691 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
692 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
693 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
694 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
695 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
696 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
697 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
698 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
699 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
700 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
701 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
702 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
703 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
704 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
705 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
706 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
707 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
708 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
709 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
710 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
711 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
712 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
713 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
714 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
715 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
716 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
717 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
718 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
719 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
720 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
721 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
722 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
723 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
724 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
725 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
726 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
727 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
728 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
729 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
730 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
731 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
732 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
733 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
734 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
735 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
736 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
737 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
738 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
739 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
740 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
741 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
742 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
743 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
744 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
745 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
746 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
747 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
748 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
749 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
750 memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
751 memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
752 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
753 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
754 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
755 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
756 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
757 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
758 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
759 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
760 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
761 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
762 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
763 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
764 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
765 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
766 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
767 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
768 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
769 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
770 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
771 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
772 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
773 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
774 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
775 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
776 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
777 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
780 /* Fill the bp->stats structure with the FDDI counter values */
782 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
783 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
784 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
785 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
786 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
787 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
788 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
789 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
790 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
791 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
792 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
795 return (struct net_device_stats *)&bp->os.MacStat;
800 * ==============================
801 * = skfp_ctl_set_multicast_list =
802 * ==============================
805 * Enable/Disable LLC frame promiscuous mode reception
806 * on the adapter and/or update multicast address table.
812 * dev - pointer to device information
814 * Functional Description:
815 * This function acquires the driver lock and only calls
816 * skfp_ctl_set_multicast_list_wo_lock then.
817 * This routine follows a fairly simple algorithm for setting the
818 * adapter filters and CAM:
820 * if IFF_PROMISC flag is set
821 * enable promiscuous mode
823 * disable promiscuous mode
824 * if number of multicast addresses <= max. multicast number
825 * add mc addresses to adapter table
827 * enable promiscuous mode
828 * update adapter filters
831 * Multicast addresses are presented in canonical (LSB) format.
834 * On-board adapter filters are updated.
836 static void skfp_ctl_set_multicast_list(struct net_device *dev)
838 struct s_smc *smc = netdev_priv(dev);
839 skfddi_priv *bp = &smc->os;
842 spin_lock_irqsave(&bp->DriverLock, Flags);
843 skfp_ctl_set_multicast_list_wo_lock(dev);
844 spin_unlock_irqrestore(&bp->DriverLock, Flags);
845 } // skfp_ctl_set_multicast_list
849 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
851 struct s_smc *smc = netdev_priv(dev);
852 struct netdev_hw_addr *ha;
854 /* Enable promiscuous mode, if necessary */
855 if (dev->flags & IFF_PROMISC) {
856 mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
857 pr_debug("PROMISCUOUS MODE ENABLED\n");
859 /* Else, update multicast address table */
861 mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
862 pr_debug("PROMISCUOUS MODE DISABLED\n");
864 // Reset all MC addresses
865 mac_clear_multicast(smc);
866 mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
868 if (dev->flags & IFF_ALLMULTI) {
869 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
870 pr_debug("ENABLE ALL MC ADDRESSES\n");
871 } else if (!netdev_mc_empty(dev)) {
872 if (netdev_mc_count(dev) <= FPMAX_MULTICAST) {
873 /* use exact filtering */
875 // point to first multicast addr
876 netdev_for_each_mc_addr(ha, dev) {
877 mac_add_multicast(smc,
878 (struct fddi_addr *)ha->addr,
881 pr_debug("ENABLE MC ADDRESS: %pMF\n",
885 } else { // more MC addresses than HW supports
887 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
888 pr_debug("ENABLE ALL MC ADDRESSES\n");
890 } else { // no MC addresses
892 pr_debug("DISABLE ALL MC ADDRESSES\n");
895 /* Update adapter filters */
896 mac_update_multicast(smc);
898 } // skfp_ctl_set_multicast_list_wo_lock
902 * ===========================
903 * = skfp_ctl_set_mac_address =
904 * ===========================
907 * set new mac address on adapter and update dev_addr field in device table.
913 * dev - pointer to device information
914 * addr - pointer to sockaddr structure containing unicast address to set
917 * The address pointed to by addr->sa_data is a valid unicast
918 * address and is presented in canonical (LSB) format.
920 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
922 struct s_smc *smc = netdev_priv(dev);
923 struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
924 skfddi_priv *bp = &smc->os;
928 dev_addr_set(dev, p_sockaddr->sa_data);
929 spin_lock_irqsave(&bp->DriverLock, Flags);
931 spin_unlock_irqrestore(&bp->DriverLock, Flags);
933 return 0; /* always return zero */
934 } // skfp_ctl_set_mac_address
938 * =======================
939 * = skfp_siocdevprivate =
940 * =======================
944 * Perform IOCTL call functions here. Some are privileged operations and the
945 * effective uid is checked in those cases.
953 * dev - pointer to device information
954 * rq - pointer to ioctl request structure
960 static int skfp_siocdevprivate(struct net_device *dev, struct ifreq *rq, void __user *data, int cmd)
962 struct s_smc *smc = netdev_priv(dev);
963 skfddi_priv *lp = &smc->os;
964 struct s_skfp_ioctl ioc;
967 if (copy_from_user(&ioc, data, sizeof(struct s_skfp_ioctl)))
970 if (in_compat_syscall())
974 case SKFP_GET_STATS: /* Get the driver statistics */
975 ioc.len = sizeof(lp->MacStat);
976 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
979 case SKFP_CLR_STATS: /* Zero out the driver statistics */
980 if (!capable(CAP_NET_ADMIN)) {
983 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
987 printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd);
988 status = -EOPNOTSUPP;
997 * =====================
999 * =====================
1002 * Queues a packet for transmission and try to transmit it.
1008 * skb - pointer to sk_buff to queue for transmission
1009 * dev - pointer to device information
1011 * Functional Description:
1012 * Here we assume that an incoming skb transmit request
1013 * is contained in a single physically contiguous buffer
1014 * in which the virtual address of the start of packet
1015 * (skb->data) can be converted to a physical address
1016 * by using dma_map_single().
1018 * We have an internal queue for packets we can not send
1019 * immediately. Packets in this queue can be given to the
1020 * adapter if transmit buffers are freed.
1022 * We can't free the skb until after it's been DMA'd
1023 * out by the adapter, so we'll keep it in the driver and
1024 * return it in mac_drv_tx_complete.
1027 * 0 - driver has queued and/or sent packet
1028 * 1 - caller should requeue the sk_buff for later transmission
1031 * The entire packet is stored in one physically
1032 * contiguous buffer which is not cached and whose
1033 * 32-bit physical address can be determined.
1035 * It's vital that this routine is NOT reentered for the
1036 * same board and that the OS is not in another section of
1037 * code (eg. skfp_interrupt) for the same board on a
1043 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
1044 struct net_device *dev)
1046 struct s_smc *smc = netdev_priv(dev);
1047 skfddi_priv *bp = &smc->os;
1049 pr_debug("skfp_send_pkt\n");
1052 * Verify that incoming transmit request is OK
1054 * Note: The packet size check is consistent with other
1055 * Linux device drivers, although the correct packet
1056 * size should be verified before calling the
1060 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1061 bp->MacStat.gen.tx_errors++; /* bump error counter */
1062 // dequeue packets from xmt queue and send them
1063 netif_start_queue(dev);
1065 return NETDEV_TX_OK; /* return "success" */
1067 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1069 netif_stop_queue(dev);
1070 return NETDEV_TX_BUSY;
1073 skb_queue_tail(&bp->SendSkbQueue, skb);
1074 send_queued_packets(netdev_priv(dev));
1075 if (bp->QueueSkb == 0) {
1076 netif_stop_queue(dev);
1078 return NETDEV_TX_OK;
1084 * =======================
1085 * = send_queued_packets =
1086 * =======================
1089 * Send packets from the driver queue as long as there are some and
1090 * transmit resources are available.
1096 * smc - pointer to smc (adapter) structure
1098 * Functional Description:
1099 * Take a packet from queue if there is any. If not, then we are done.
1100 * Check if there are resources to send the packet. If not, requeue it
1102 * Set packet descriptor flags and give packet to adapter.
1103 * Check if any send resources can be freed (we do not use the
1104 * transmit complete interrupt).
1106 static void send_queued_packets(struct s_smc *smc)
1108 skfddi_priv *bp = &smc->os;
1109 struct sk_buff *skb;
1112 struct s_smt_fp_txd *txd; // Current TxD.
1113 dma_addr_t dma_address;
1114 unsigned long Flags;
1116 int frame_status; // HWM tx frame status.
1118 pr_debug("send queued packets\n");
1120 // send first buffer from queue
1121 skb = skb_dequeue(&bp->SendSkbQueue);
1124 pr_debug("queue empty\n");
1128 spin_lock_irqsave(&bp->DriverLock, Flags);
1130 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1132 // Check if the frame may/must be sent as a synchronous frame.
1134 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1135 // It's an LLC frame.
1136 if (!smc->ess.sync_bw_available)
1137 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1139 else { // Bandwidth is available.
1141 if (smc->mib.fddiESSSynchTxMode) {
1142 // Send as sync. frame.
1148 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1150 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1151 // Unable to send the frame.
1153 if ((frame_status & RING_DOWN) != 0) {
1155 pr_debug("Tx attempt while ring down.\n");
1156 } else if ((frame_status & OUT_OF_TXD) != 0) {
1157 pr_debug("%s: out of TXDs.\n", bp->dev->name);
1159 pr_debug("%s: out of transmit resources",
1163 // Note: We will retry the operation as soon as
1164 // transmit resources become available.
1165 skb_queue_head(&bp->SendSkbQueue, skb);
1166 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1167 return; // Packet has been queued.
1169 } // if (unable to send frame)
1171 bp->QueueSkb++; // one packet less in local queue
1173 // source address in packet ?
1174 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1176 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1178 dma_address = dma_map_single(&(&bp->pdev)->dev, skb->data,
1179 skb->len, DMA_TO_DEVICE);
1180 if (frame_status & LAN_TX) {
1181 txd->txd_os.skb = skb; // save skb
1182 txd->txd_os.dma_addr = dma_address; // save dma mapping
1184 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1185 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1187 if (!(frame_status & LAN_TX)) { // local only frame
1188 dma_unmap_single(&(&bp->pdev)->dev, dma_address,
1189 skb->len, DMA_TO_DEVICE);
1190 dev_kfree_skb_irq(skb);
1192 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1195 return; // never reached
1197 } // send_queued_packets
1200 /************************
1202 * CheckSourceAddress
1204 * Verify if the source address is set. Insert it if necessary.
1206 ************************/
1207 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1209 unsigned char SRBit;
1211 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1214 if ((unsigned short) frame[1 + 10] != 0)
1216 SRBit = frame[1 + 6] & 0x01;
1217 memcpy(&frame[1 + 6], hw_addr, ETH_ALEN);
1219 } // CheckSourceAddress
1222 /************************
1226 * Reset the adapter and bring it back to operational mode.
1228 * smc - A pointer to the SMT context struct.
1232 ************************/
1233 static void ResetAdapter(struct s_smc *smc)
1236 pr_debug("[fddi: ResetAdapter]\n");
1238 // Stop the adapter.
1240 card_stop(smc); // Stop all activity.
1242 // Clear the transmit and receive descriptor queues.
1243 mac_drv_clear_tx_queue(smc);
1244 mac_drv_clear_rx_queue(smc);
1246 // Restart the adapter.
1248 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1250 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1252 smt_online(smc, 1); // Insert into the ring again.
1255 // Restore original receive mode (multicasts, promiscuous, etc.).
1256 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1260 //--------------- functions called by hardware module ----------------
1262 /************************
1266 * The hardware driver calls this routine when the transmit complete
1267 * interrupt bits (end of frame) for the synchronous or asynchronous
1270 * NOTE The hardware driver calls this function also if no packets are queued.
1271 * The routine must be able to handle this case.
1273 * smc - A pointer to the SMT context struct.
1277 ************************/
1278 void llc_restart_tx(struct s_smc *smc)
1280 skfddi_priv *bp = &smc->os;
1282 pr_debug("[llc_restart_tx]\n");
1284 // Try to send queued packets
1285 spin_unlock(&bp->DriverLock);
1286 send_queued_packets(smc);
1287 spin_lock(&bp->DriverLock);
1288 netif_start_queue(bp->dev);// system may send again if it was blocked
1293 /************************
1297 * The hardware module calls this function to allocate the memory
1298 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1300 * smc - A pointer to the SMT context struct.
1302 * size - Size of memory in bytes to allocate.
1304 * != 0 A pointer to the virtual address of the allocated memory.
1305 * == 0 Allocation error.
1307 ************************/
1308 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1312 pr_debug("mac_drv_get_space (%d bytes), ", size);
1313 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1315 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1316 printk("Unexpected SMT memory size requested: %d\n", size);
1319 smc->os.SharedMemHeap += size; // Move heap pointer.
1321 pr_debug("mac_drv_get_space end\n");
1322 pr_debug("virt addr: %lx\n", (ulong) virt);
1323 pr_debug("bus addr: %lx\n", (ulong)
1324 (smc->os.SharedMemDMA +
1325 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1327 } // mac_drv_get_space
1330 /************************
1332 * mac_drv_get_desc_mem
1334 * This function is called by the hardware dependent module.
1335 * It allocates the memory for the RxD and TxD descriptors.
1337 * This memory must be non-cached, non-movable and non-swappable.
1338 * This memory should start at a physical page boundary.
1340 * smc - A pointer to the SMT context struct.
1342 * size - Size of memory in bytes to allocate.
1344 * != 0 A pointer to the virtual address of the allocated memory.
1345 * == 0 Allocation error.
1347 ************************/
1348 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1353 pr_debug("mac_drv_get_desc_mem\n");
1355 // Descriptor memory must be aligned on 16-byte boundary.
1357 virt = mac_drv_get_space(smc, size);
1359 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1362 pr_debug("Allocate %u bytes alignment gap ", size);
1363 pr_debug("for descriptor memory.\n");
1365 if (!mac_drv_get_space(smc, size)) {
1366 printk("fddi: Unable to align descriptor memory.\n");
1370 } // mac_drv_get_desc_mem
1373 /************************
1377 * Get the physical address of a given virtual address.
1379 * smc - A pointer to the SMT context struct.
1381 * virt - A (virtual) pointer into our 'shared' memory area.
1383 * Physical address of the given virtual address.
1385 ************************/
1386 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1388 return smc->os.SharedMemDMA +
1389 ((char *) virt - (char *)smc->os.SharedMemAddr);
1390 } // mac_drv_virt2phys
1393 /************************
1397 * The HWM calls this function, when the driver leads through a DMA
1398 * transfer. If the OS-specific module must prepare the system hardware
1399 * for the DMA transfer, it should do it in this function.
1401 * The hardware module calls this dma_master if it wants to send an SMT
1402 * frame. This means that the virt address passed in here is part of
1403 * the 'shared' memory area.
1405 * smc - A pointer to the SMT context struct.
1407 * virt - The virtual address of the data.
1409 * len - The length in bytes of the data.
1411 * flag - Indicates the transmit direction and the buffer type:
1412 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1413 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1414 * SMT_BUF (0x80) SMT buffer
1416 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1418 * Returns the pyhsical address for the DMA transfer.
1420 ************************/
1421 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1423 return smc->os.SharedMemDMA +
1424 ((char *) virt - (char *)smc->os.SharedMemAddr);
1428 /************************
1432 * The hardware module calls this routine when it has completed a DMA
1433 * transfer. If the operating system dependent module has set up the DMA
1434 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1437 * smc - A pointer to the SMT context struct.
1439 * descr - A pointer to a TxD or RxD, respectively.
1441 * flag - Indicates the DMA transfer direction / SMT buffer:
1442 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1443 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1444 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1448 ************************/
1449 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1451 /* For TX buffers, there are two cases. If it is an SMT transmit
1452 * buffer, there is nothing to do since we use consistent memory
1453 * for the 'shared' memory area. The other case is for normal
1454 * transmit packets given to us by the networking stack, and in
1455 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1458 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1459 * because the hardware module is about to potentially look at
1460 * the contents of the buffer. If we did not call the PCI DMA
1461 * unmap first, the hardware module could read inconsistent data.
1463 if (flag & DMA_WR) {
1464 skfddi_priv *bp = &smc->os;
1465 volatile struct s_smt_fp_rxd *r = &descr->r;
1467 /* If SKB is NULL, we used the local buffer. */
1468 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1469 int MaxFrameSize = bp->MaxFrameSize;
1471 dma_unmap_single(&(&bp->pdev)->dev,
1472 r->rxd_os.dma_addr, MaxFrameSize,
1474 r->rxd_os.dma_addr = 0;
1480 /************************
1482 * mac_drv_tx_complete
1484 * Transmit of a packet is complete. Release the tx staging buffer.
1487 * smc - A pointer to the SMT context struct.
1489 * txd - A pointer to the last TxD which is used by the frame.
1493 ************************/
1494 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1496 struct sk_buff *skb;
1498 pr_debug("entering mac_drv_tx_complete\n");
1499 // Check if this TxD points to a skb
1501 if (!(skb = txd->txd_os.skb)) {
1502 pr_debug("TXD with no skb assigned.\n");
1505 txd->txd_os.skb = NULL;
1507 // release the DMA mapping
1508 dma_unmap_single(&(&smc->os.pdev)->dev, txd->txd_os.dma_addr,
1509 skb->len, DMA_TO_DEVICE);
1510 txd->txd_os.dma_addr = 0;
1512 smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
1513 smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1516 dev_kfree_skb_irq(skb);
1518 pr_debug("leaving mac_drv_tx_complete\n");
1519 } // mac_drv_tx_complete
1522 /************************
1524 * dump packets to logfile
1526 ************************/
1528 void dump_data(unsigned char *Data, int length)
1530 printk(KERN_INFO "---Packet start---\n");
1531 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, Data, min_t(size_t, length, 64), false);
1532 printk(KERN_INFO "------------------\n");
1535 #define dump_data(data,len)
1536 #endif // DUMPPACKETS
1538 /************************
1540 * mac_drv_rx_complete
1542 * The hardware module calls this function if an LLC frame is received
1543 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1544 * from the network will be passed to the LLC layer by this function
1545 * if passing is enabled.
1547 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1548 * be received. It also fills the RxD ring with new receive buffers if
1549 * some can be queued.
1551 * smc - A pointer to the SMT context struct.
1553 * rxd - A pointer to the first RxD which is used by the receive frame.
1555 * frag_count - Count of RxDs used by the received frame.
1557 * len - Frame length.
1561 ************************/
1562 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1563 int frag_count, int len)
1565 skfddi_priv *bp = &smc->os;
1566 struct sk_buff *skb;
1567 unsigned char *virt, *cp;
1571 pr_debug("entering mac_drv_rx_complete (len=%d)\n", len);
1572 if (frag_count != 1) { // This is not allowed to happen.
1574 printk("fddi: Multi-fragment receive!\n");
1575 goto RequeueRxd; // Re-use the given RXD(s).
1578 skb = rxd->rxd_os.skb;
1580 pr_debug("No skb in rxd\n");
1581 smc->os.MacStat.gen.rx_errors++;
1586 // The DMA mapping was released in dma_complete above.
1588 dump_data(skb->data, len);
1591 * FDDI Frame format:
1592 * +-------+-------+-------+------------+--------+------------+
1593 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1594 * +-------+-------+-------+------------+--------+------------+
1596 * FC = Frame Control
1597 * DA = Destination Address
1598 * SA = Source Address
1599 * RIF = Routing Information Field
1600 * LLC = Logical Link Control
1603 // Remove Routing Information Field (RIF), if present.
1605 if ((virt[1 + 6] & FDDI_RII) == 0)
1609 // goos: RIF removal has still to be tested
1610 pr_debug("RIF found\n");
1611 // Get RIF length from Routing Control (RC) field.
1612 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1614 ri = ntohs(*((__be16 *) cp));
1615 RifLength = ri & FDDI_RCF_LEN_MASK;
1616 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1617 printk("fddi: Invalid RIF.\n");
1618 goto RequeueRxd; // Discard the frame.
1621 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1624 virt = cp + RifLength;
1625 for (n = FDDI_MAC_HDR_LEN; n; n--)
1627 // adjust sbd->data pointer
1628 skb_pull(skb, RifLength);
1633 // Count statistics.
1634 smc->os.MacStat.gen.rx_packets++; // Count indicated receive
1636 smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
1638 // virt points to header again
1639 if (virt[1] & 0x01) { // Check group (multicast) bit.
1641 smc->os.MacStat.gen.multicast++;
1644 // deliver frame to system
1645 rxd->rxd_os.skb = NULL;
1647 skb->protocol = fddi_type_trans(skb, bp->dev);
1651 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1655 pr_debug("Rx: re-queue RXD.\n");
1656 mac_drv_requeue_rxd(smc, rxd, frag_count);
1657 smc->os.MacStat.gen.rx_errors++; // Count receive packets
1660 } // mac_drv_rx_complete
1663 /************************
1665 * mac_drv_requeue_rxd
1667 * The hardware module calls this function to request the OS-specific
1668 * module to queue the receive buffer(s) represented by the pointer
1669 * to the RxD and the frag_count into the receive queue again. This
1670 * buffer was filled with an invalid frame or an SMT frame.
1672 * smc - A pointer to the SMT context struct.
1674 * rxd - A pointer to the first RxD which is used by the receive frame.
1676 * frag_count - Count of RxDs used by the received frame.
1680 ************************/
1681 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1684 volatile struct s_smt_fp_rxd *next_rxd;
1685 volatile struct s_smt_fp_rxd *src_rxd;
1686 struct sk_buff *skb;
1688 unsigned char *v_addr;
1691 if (frag_count != 1) // This is not allowed to happen.
1693 printk("fddi: Multi-fragment requeue!\n");
1695 MaxFrameSize = smc->os.MaxFrameSize;
1697 for (; frag_count > 0; frag_count--) {
1698 next_rxd = src_rxd->rxd_next;
1699 rxd = HWM_GET_CURR_RXD(smc);
1701 skb = src_rxd->rxd_os.skb;
1702 if (skb == NULL) { // this should not happen
1704 pr_debug("Requeue with no skb in rxd!\n");
1705 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1708 rxd->rxd_os.skb = skb;
1709 skb_reserve(skb, 3);
1710 skb_put(skb, MaxFrameSize);
1712 b_addr = dma_map_single(&(&smc->os.pdev)->dev,
1713 v_addr, MaxFrameSize,
1715 rxd->rxd_os.dma_addr = b_addr;
1717 // no skb available, use local buffer
1718 pr_debug("Queueing invalid buffer!\n");
1719 rxd->rxd_os.skb = NULL;
1720 v_addr = smc->os.LocalRxBuffer;
1721 b_addr = smc->os.LocalRxBufferDMA;
1724 // we use skb from old rxd
1725 rxd->rxd_os.skb = skb;
1727 b_addr = dma_map_single(&(&smc->os.pdev)->dev, v_addr,
1728 MaxFrameSize, DMA_FROM_DEVICE);
1729 rxd->rxd_os.dma_addr = b_addr;
1731 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1732 FIRST_FRAG | LAST_FRAG);
1736 } // mac_drv_requeue_rxd
1739 /************************
1743 * The hardware module calls this function at initialization time
1744 * to fill the RxD ring with receive buffers. It is also called by
1745 * mac_drv_rx_complete if rx_free is large enough to queue some new
1746 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
1747 * receive buffers as long as enough RxDs and receive buffers are
1750 * smc - A pointer to the SMT context struct.
1754 ************************/
1755 void mac_drv_fill_rxd(struct s_smc *smc)
1758 unsigned char *v_addr;
1759 unsigned long b_addr;
1760 struct sk_buff *skb;
1761 volatile struct s_smt_fp_rxd *rxd;
1763 pr_debug("entering mac_drv_fill_rxd\n");
1765 // Walk through the list of free receive buffers, passing receive
1766 // buffers to the HWM as long as RXDs are available.
1768 MaxFrameSize = smc->os.MaxFrameSize;
1769 // Check if there is any RXD left.
1770 while (HWM_GET_RX_FREE(smc) > 0) {
1773 rxd = HWM_GET_CURR_RXD(smc);
1774 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1777 skb_reserve(skb, 3);
1778 skb_put(skb, MaxFrameSize);
1780 b_addr = dma_map_single(&(&smc->os.pdev)->dev, v_addr,
1781 MaxFrameSize, DMA_FROM_DEVICE);
1782 rxd->rxd_os.dma_addr = b_addr;
1784 // no skb available, use local buffer
1785 // System has run out of buffer memory, but we want to
1786 // keep the receiver running in hope of better times.
1787 // Multiple descriptors may point to this local buffer,
1788 // so data in it must be considered invalid.
1789 pr_debug("Queueing invalid buffer!\n");
1790 v_addr = smc->os.LocalRxBuffer;
1791 b_addr = smc->os.LocalRxBufferDMA;
1794 rxd->rxd_os.skb = skb;
1796 // Pass receive buffer to HWM.
1797 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1798 FIRST_FRAG | LAST_FRAG);
1800 pr_debug("leaving mac_drv_fill_rxd\n");
1801 } // mac_drv_fill_rxd
1804 /************************
1808 * The hardware module calls this function to release unused
1811 * smc - A pointer to the SMT context struct.
1813 * rxd - A pointer to the first RxD which is used by the receive buffer.
1815 * frag_count - Count of RxDs used by the receive buffer.
1819 ************************/
1820 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1824 struct sk_buff *skb;
1826 pr_debug("entering mac_drv_clear_rxd\n");
1828 if (frag_count != 1) // This is not allowed to happen.
1830 printk("fddi: Multi-fragment clear!\n");
1832 for (; frag_count > 0; frag_count--) {
1833 skb = rxd->rxd_os.skb;
1835 skfddi_priv *bp = &smc->os;
1836 int MaxFrameSize = bp->MaxFrameSize;
1838 dma_unmap_single(&(&bp->pdev)->dev,
1839 rxd->rxd_os.dma_addr, MaxFrameSize,
1843 rxd->rxd_os.skb = NULL;
1845 rxd = rxd->rxd_next; // Next RXD.
1848 } // mac_drv_clear_rxd
1851 /************************
1855 * The hardware module calls this routine when an SMT or NSA frame of the
1856 * local SMT should be delivered to the LLC layer.
1858 * It is necessary to have this function, because there is no other way to
1859 * copy the contents of SMT MBufs into receive buffers.
1861 * mac_drv_rx_init allocates the required target memory for this frame,
1862 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
1864 * smc - A pointer to the SMT context struct.
1866 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1868 * fc - The Frame Control field of the received frame.
1870 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
1872 * la_len - The length of the lookahead data stored in the lookahead
1873 * buffer (may be zero).
1875 * Always returns zero (0).
1877 ************************/
1878 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1879 char *look_ahead, int la_len)
1881 struct sk_buff *skb;
1883 pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
1885 // "Received" a SMT or NSA frame of the local SMT.
1887 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1888 pr_debug("fddi: Discard invalid local SMT frame\n");
1889 pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1890 len, la_len, (unsigned long) look_ahead);
1893 skb = alloc_skb(len + 3, GFP_ATOMIC);
1895 pr_debug("fddi: Local SMT: skb memory exhausted.\n");
1898 skb_reserve(skb, 3);
1900 skb_copy_to_linear_data(skb, look_ahead, len);
1902 // deliver frame to system
1903 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1907 } // mac_drv_rx_init
1910 /************************
1914 * This routine is called periodically by the SMT module to clean up the
1917 * Return any queued frames back to the upper protocol layers if the ring
1920 * smc - A pointer to the SMT context struct.
1924 ************************/
1925 void smt_timer_poll(struct s_smc *smc)
1930 /************************
1932 * ring_status_indication
1934 * This function indicates a change of the ring state.
1936 * smc - A pointer to the SMT context struct.
1938 * status - The current ring status.
1942 ************************/
1943 void ring_status_indication(struct s_smc *smc, u_long status)
1945 pr_debug("ring_status_indication( ");
1946 if (status & RS_RES15)
1947 pr_debug("RS_RES15 ");
1948 if (status & RS_HARDERROR)
1949 pr_debug("RS_HARDERROR ");
1950 if (status & RS_SOFTERROR)
1951 pr_debug("RS_SOFTERROR ");
1952 if (status & RS_BEACON)
1953 pr_debug("RS_BEACON ");
1954 if (status & RS_PATHTEST)
1955 pr_debug("RS_PATHTEST ");
1956 if (status & RS_SELFTEST)
1957 pr_debug("RS_SELFTEST ");
1958 if (status & RS_RES9)
1959 pr_debug("RS_RES9 ");
1960 if (status & RS_DISCONNECT)
1961 pr_debug("RS_DISCONNECT ");
1962 if (status & RS_RES7)
1963 pr_debug("RS_RES7 ");
1964 if (status & RS_DUPADDR)
1965 pr_debug("RS_DUPADDR ");
1966 if (status & RS_NORINGOP)
1967 pr_debug("RS_NORINGOP ");
1968 if (status & RS_VERSION)
1969 pr_debug("RS_VERSION ");
1970 if (status & RS_STUCKBYPASSS)
1971 pr_debug("RS_STUCKBYPASSS ");
1972 if (status & RS_EVENT)
1973 pr_debug("RS_EVENT ");
1974 if (status & RS_RINGOPCHANGE)
1975 pr_debug("RS_RINGOPCHANGE ");
1976 if (status & RS_RES0)
1977 pr_debug("RS_RES0 ");
1979 } // ring_status_indication
1982 /************************
1986 * Gets the current time from the system.
1990 * The current time in TICKS_PER_SECOND.
1992 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
1993 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
1994 * to the time returned by smt_get_time().
1996 ************************/
1997 unsigned long smt_get_time(void)
2003 /************************
2007 * Status counter update (ring_op, fifo full).
2009 * smc - A pointer to the SMT context struct.
2011 * stat - = 0: A ring operational change occurred.
2012 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2016 ************************/
2017 void smt_stat_counter(struct s_smc *smc, int stat)
2019 // BOOLEAN RingIsUp ;
2021 pr_debug("smt_stat_counter\n");
2024 pr_debug("Ring operational change.\n");
2027 pr_debug("Receive fifo overflow.\n");
2028 smc->os.MacStat.gen.rx_errors++;
2031 pr_debug("Unknown status (%d).\n", stat);
2034 } // smt_stat_counter
2037 /************************
2041 * Sets CFM state in custom statistics.
2043 * smc - A pointer to the SMT context struct.
2045 * c_state - Possible values are:
2047 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2048 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2052 ************************/
2053 void cfm_state_change(struct s_smc *smc, int c_state)
2081 s = "SC10_C_WRAP_B";
2084 s = "SC11_C_WRAP_S";
2087 pr_debug("cfm_state_change: unknown %d\n", c_state);
2090 pr_debug("cfm_state_change: %s\n", s);
2091 #endif // DRIVERDEBUG
2092 } // cfm_state_change
2095 /************************
2099 * Sets ECM state in custom statistics.
2101 * smc - A pointer to the SMT context struct.
2103 * e_state - Possible values are:
2105 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2106 * SC5_THRU_B (7), SC7_WRAP_S (8)
2110 ************************/
2111 void ecm_state_change(struct s_smc *smc, int e_state)
2130 s = "EC4_PATH_TEST";
2145 pr_debug("ecm_state_change: %s\n", s);
2146 #endif //DRIVERDEBUG
2147 } // ecm_state_change
2150 /************************
2154 * Sets RMT state in custom statistics.
2156 * smc - A pointer to the SMT context struct.
2158 * r_state - Possible values are:
2160 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2161 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2165 ************************/
2166 void rmt_state_change(struct s_smc *smc, int r_state)
2176 s = "RM1_NON_OP - not operational";
2179 s = "RM2_RING_OP - ring operational";
2182 s = "RM3_DETECT - detect dupl addresses";
2184 case RM4_NON_OP_DUP:
2185 s = "RM4_NON_OP_DUP - dupl. addr detected";
2187 case RM5_RING_OP_DUP:
2188 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2191 s = "RM6_DIRECTED - sending directed beacons";
2194 s = "RM7_TRACE - trace initiated";
2200 pr_debug("[rmt_state_change: %s]\n", s);
2201 #endif // DRIVERDEBUG
2202 } // rmt_state_change
2205 /************************
2207 * drv_reset_indication
2209 * This function is called by the SMT when it has detected a severe
2210 * hardware problem. The driver should perform a reset on the adapter
2211 * as soon as possible, but not from within this function.
2213 * smc - A pointer to the SMT context struct.
2217 ************************/
2218 void drv_reset_indication(struct s_smc *smc)
2220 pr_debug("entering drv_reset_indication\n");
2222 smc->os.ResetRequested = TRUE; // Set flag.
2224 } // drv_reset_indication
2226 static struct pci_driver skfddi_pci_driver = {
2228 .id_table = skfddi_pci_tbl,
2229 .probe = skfp_init_one,
2230 .remove = skfp_remove_one,
2233 module_pci_driver(skfddi_pci_driver);