Linux 4.16.11
[linux/fpc-iii.git] / drivers / net / fddi / skfp / skfddi.c
blob2414f1dc8ddd8e10a36f8f279bca0a64bb24acf8
1 /*
2 * File Name:
3 * skfddi.c
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.
15 * Abstract:
16 * A Linux device driver supporting the SysKonnect FDDI PCI controller
17 * familie.
19 * Maintainers:
20 * CG Christoph Goos (cgoos@syskonnect.de)
22 * Contributors:
23 * DM David S. Miller
25 * Address all question to:
26 * linux@syskonnect.de
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 functions are handled by the SysKonnect
37 * Hardware Module.
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:
62 * - i386
63 * - sparc64
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)";
74 /* Include files */
76 #include <linux/capability.h>
77 #include <linux/module.h>
78 #include <linux/kernel.h>
79 #include <linux/errno.h>
80 #include <linux/ioport.h>
81 #include <linux/interrupt.h>
82 #include <linux/pci.h>
83 #include <linux/netdevice.h>
84 #include <linux/fddidevice.h>
85 #include <linux/skbuff.h>
86 #include <linux/bitops.h>
87 #include <linux/gfp.h>
89 #include <asm/byteorder.h>
90 #include <asm/io.h>
91 #include <linux/uaccess.h>
93 #include "h/types.h"
94 #undef ADDR // undo Linux definition
95 #include "h/skfbi.h"
96 #include "h/fddi.h"
97 #include "h/smc.h"
98 #include "h/smtstate.h"
101 // Define module-wide (static) routines
102 static int skfp_driver_init(struct net_device *dev);
103 static int skfp_open(struct net_device *dev);
104 static int skfp_close(struct net_device *dev);
105 static irqreturn_t skfp_interrupt(int irq, void *dev_id);
106 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
107 static void skfp_ctl_set_multicast_list(struct net_device *dev);
108 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
109 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
110 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
111 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
112 struct net_device *dev);
113 static void send_queued_packets(struct s_smc *smc);
114 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
115 static void ResetAdapter(struct s_smc *smc);
118 // Functions needed by the hardware module
119 void *mac_drv_get_space(struct s_smc *smc, u_int size);
120 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
121 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
122 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
123 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
124 int flag);
125 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
126 void llc_restart_tx(struct s_smc *smc);
127 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
128 int frag_count, int len);
129 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
130 int frag_count);
131 void mac_drv_fill_rxd(struct s_smc *smc);
132 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
133 int frag_count);
134 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
135 int la_len);
136 void dump_data(unsigned char *Data, int length);
138 // External functions from the hardware module
139 extern u_int mac_drv_check_space(void);
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 void fddi_isr(struct s_smc *smc);
146 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
147 int len, int frame_status);
148 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
149 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
150 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
152 static const struct pci_device_id skfddi_pci_tbl[] = {
153 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
154 { } /* Terminating entry */
156 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
157 MODULE_LICENSE("GPL");
158 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
160 // Define module-wide (static) variables
162 static int num_boards; /* total number of adapters configured */
164 static const struct net_device_ops skfp_netdev_ops = {
165 .ndo_open = skfp_open,
166 .ndo_stop = skfp_close,
167 .ndo_start_xmit = skfp_send_pkt,
168 .ndo_get_stats = skfp_ctl_get_stats,
169 .ndo_set_rx_mode = skfp_ctl_set_multicast_list,
170 .ndo_set_mac_address = skfp_ctl_set_mac_address,
171 .ndo_do_ioctl = skfp_ioctl,
175 * =================
176 * = skfp_init_one =
177 * =================
179 * Overview:
180 * Probes for supported FDDI PCI controllers
182 * Returns:
183 * Condition code
185 * Arguments:
186 * pdev - pointer to PCI device information
188 * Functional Description:
189 * This is now called by PCI driver registration process
190 * for each board found.
192 * Return Codes:
193 * 0 - This device (fddi0, fddi1, etc) configured successfully
194 * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
195 * present for this device name
198 * Side Effects:
199 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
200 * initialized and the board resources are read and stored in
201 * the device structure.
203 static int skfp_init_one(struct pci_dev *pdev,
204 const struct pci_device_id *ent)
206 struct net_device *dev;
207 struct s_smc *smc; /* board pointer */
208 void __iomem *mem;
209 int err;
211 pr_debug("entering skfp_init_one\n");
213 if (num_boards == 0)
214 printk("%s\n", boot_msg);
216 err = pci_enable_device(pdev);
217 if (err)
218 return err;
220 err = pci_request_regions(pdev, "skfddi");
221 if (err)
222 goto err_out1;
224 pci_set_master(pdev);
226 #ifdef MEM_MAPPED_IO
227 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
228 printk(KERN_ERR "skfp: region is not an MMIO resource\n");
229 err = -EIO;
230 goto err_out2;
233 mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
234 #else
235 if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
236 printk(KERN_ERR "skfp: region is not PIO resource\n");
237 err = -EIO;
238 goto err_out2;
241 mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
242 #endif
243 if (!mem) {
244 printk(KERN_ERR "skfp: Unable to map register, "
245 "FDDI adapter will be disabled.\n");
246 err = -EIO;
247 goto err_out2;
250 dev = alloc_fddidev(sizeof(struct s_smc));
251 if (!dev) {
252 printk(KERN_ERR "skfp: Unable to allocate fddi device, "
253 "FDDI adapter will be disabled.\n");
254 err = -ENOMEM;
255 goto err_out3;
258 dev->irq = pdev->irq;
259 dev->netdev_ops = &skfp_netdev_ops;
261 SET_NETDEV_DEV(dev, &pdev->dev);
263 /* Initialize board structure with bus-specific info */
264 smc = netdev_priv(dev);
265 smc->os.dev = dev;
266 smc->os.bus_type = SK_BUS_TYPE_PCI;
267 smc->os.pdev = *pdev;
268 smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
269 smc->os.MaxFrameSize = MAX_FRAME_SIZE;
270 smc->os.dev = dev;
271 smc->hw.slot = -1;
272 smc->hw.iop = mem;
273 smc->os.ResetRequested = FALSE;
274 skb_queue_head_init(&smc->os.SendSkbQueue);
276 dev->base_addr = (unsigned long)mem;
278 err = skfp_driver_init(dev);
279 if (err)
280 goto err_out4;
282 err = register_netdev(dev);
283 if (err)
284 goto err_out5;
286 ++num_boards;
287 pci_set_drvdata(pdev, dev);
289 if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
290 (pdev->subsystem_device & 0xff00) == 0x5800)
291 printk("%s: SysKonnect FDDI PCI adapter"
292 " found (SK-%04X)\n", dev->name,
293 pdev->subsystem_device);
294 else
295 printk("%s: FDDI PCI adapter found\n", dev->name);
297 return 0;
298 err_out5:
299 if (smc->os.SharedMemAddr)
300 pci_free_consistent(pdev, smc->os.SharedMemSize,
301 smc->os.SharedMemAddr,
302 smc->os.SharedMemDMA);
303 pci_free_consistent(pdev, MAX_FRAME_SIZE,
304 smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
305 err_out4:
306 free_netdev(dev);
307 err_out3:
308 #ifdef MEM_MAPPED_IO
309 iounmap(mem);
310 #else
311 ioport_unmap(mem);
312 #endif
313 err_out2:
314 pci_release_regions(pdev);
315 err_out1:
316 pci_disable_device(pdev);
317 return err;
321 * Called for each adapter board from pci_unregister_driver
323 static void skfp_remove_one(struct pci_dev *pdev)
325 struct net_device *p = pci_get_drvdata(pdev);
326 struct s_smc *lp = netdev_priv(p);
328 unregister_netdev(p);
330 if (lp->os.SharedMemAddr) {
331 pci_free_consistent(&lp->os.pdev,
332 lp->os.SharedMemSize,
333 lp->os.SharedMemAddr,
334 lp->os.SharedMemDMA);
335 lp->os.SharedMemAddr = NULL;
337 if (lp->os.LocalRxBuffer) {
338 pci_free_consistent(&lp->os.pdev,
339 MAX_FRAME_SIZE,
340 lp->os.LocalRxBuffer,
341 lp->os.LocalRxBufferDMA);
342 lp->os.LocalRxBuffer = NULL;
344 #ifdef MEM_MAPPED_IO
345 iounmap(lp->hw.iop);
346 #else
347 ioport_unmap(lp->hw.iop);
348 #endif
349 pci_release_regions(pdev);
350 free_netdev(p);
352 pci_disable_device(pdev);
356 * ====================
357 * = skfp_driver_init =
358 * ====================
360 * Overview:
361 * Initializes remaining adapter board structure information
362 * and makes sure adapter is in a safe state prior to skfp_open().
364 * Returns:
365 * Condition code
367 * Arguments:
368 * dev - pointer to device information
370 * Functional Description:
371 * This function allocates additional resources such as the host memory
372 * blocks needed by the adapter.
373 * The adapter is also reset. The OS must call skfp_open() to open
374 * the adapter and bring it on-line.
376 * Return Codes:
377 * 0 - initialization succeeded
378 * -1 - initialization failed
380 static int skfp_driver_init(struct net_device *dev)
382 struct s_smc *smc = netdev_priv(dev);
383 skfddi_priv *bp = &smc->os;
384 int err = -EIO;
386 pr_debug("entering skfp_driver_init\n");
388 // set the io address in private structures
389 bp->base_addr = dev->base_addr;
391 // Get the interrupt level from the PCI Configuration Table
392 smc->hw.irq = dev->irq;
394 spin_lock_init(&bp->DriverLock);
396 // Allocate invalid frame
397 bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
398 if (!bp->LocalRxBuffer) {
399 printk("could not allocate mem for ");
400 printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
401 goto fail;
404 // Determine the required size of the 'shared' memory area.
405 bp->SharedMemSize = mac_drv_check_space();
406 pr_debug("Memory for HWM: %ld\n", bp->SharedMemSize);
407 if (bp->SharedMemSize > 0) {
408 bp->SharedMemSize += 16; // for descriptor alignment
410 bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
411 bp->SharedMemSize,
412 &bp->SharedMemDMA);
413 if (!bp->SharedMemAddr) {
414 printk("could not allocate mem for ");
415 printk("hardware module: %ld byte\n",
416 bp->SharedMemSize);
417 goto fail;
419 bp->SharedMemHeap = 0; // Nothing used yet.
421 } else {
422 bp->SharedMemAddr = NULL;
423 bp->SharedMemHeap = 0;
424 } // SharedMemSize > 0
426 memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
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");
433 goto fail;
435 read_address(smc, NULL);
436 pr_debug("HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
437 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, ETH_ALEN);
439 smt_reset_defaults(smc, 0);
441 return 0;
443 fail:
444 if (bp->SharedMemAddr) {
445 pci_free_consistent(&bp->pdev,
446 bp->SharedMemSize,
447 bp->SharedMemAddr,
448 bp->SharedMemDMA);
449 bp->SharedMemAddr = NULL;
451 if (bp->LocalRxBuffer) {
452 pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
453 bp->LocalRxBuffer, bp->LocalRxBufferDMA);
454 bp->LocalRxBuffer = NULL;
456 return err;
457 } // skfp_driver_init
461 * =============
462 * = skfp_open =
463 * =============
465 * Overview:
466 * Opens the adapter
468 * Returns:
469 * Condition code
471 * Arguments:
472 * dev - pointer to device information
474 * Functional Description:
475 * This function brings the adapter to an operational state.
477 * Return Codes:
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);
484 int err;
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,
489 dev->name, dev);
490 if (err)
491 return err;
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
501 * address.
503 read_address(smc, NULL);
504 memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, ETH_ALEN);
506 init_smt(smc, NULL);
507 smt_online(smc, 1);
508 STI_FBI();
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);
517 return 0;
518 } // skfp_open
522 * ==============
523 * = skfp_close =
524 * ==============
526 * Overview:
527 * Closes the device/module.
529 * Returns:
530 * Condition code
532 * Arguments:
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().
540 * Return Codes:
541 * Always return 0.
543 * Assumptions:
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
546 * adapter.
548 static int skfp_close(struct net_device *dev)
550 struct s_smc *smc = netdev_priv(dev);
551 skfddi_priv *bp = &smc->os;
553 CLI_FBI();
554 smt_reset_defaults(smc, 1);
555 card_stop(smc);
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;
566 return 0;
567 } // skfp_close
571 * ==================
572 * = skfp_interrupt =
573 * ==================
575 * Overview:
576 * Interrupt processing routine
578 * Returns:
579 * None
581 * Arguments:
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.
591 * Return Codes:
592 * None
594 * Assumptions:
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
597 * routine.
599 * System interrupts are enabled through this call.
601 * Side Effects:
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 */
609 skfddi_priv *bp;
611 smc = netdev_priv(dev);
612 bp = &smc->os;
614 // IRQs enabled or disabled ?
615 if (inpd(ADDR(B0_IMSK)) == 0) {
616 // IRQs are disabled: must be shared interrupt
617 return IRQ_NONE;
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
622 return IRQ_NONE;
624 CLI_FBI(); // Disable IRQs from our adapter.
625 spin_lock(&bp->DriverLock);
627 // Call interrupt handler in hardware module (HWM).
628 fddi_isr(smc);
630 if (smc->os.ResetRequested) {
631 ResetAdapter(smc);
632 smc->os.ResetRequested = FALSE;
634 spin_unlock(&bp->DriverLock);
635 STI_FBI(); // Enable IRQs from our adapter.
637 return IRQ_HANDLED;
638 } // skfp_interrupt
642 * ======================
643 * = skfp_ctl_get_stats =
644 * ======================
646 * Overview:
647 * Get statistics for FDDI adapter
649 * Returns:
650 * Pointer to FDDI statistics structure
652 * Arguments:
653 * dev - pointer to device information
655 * Functional Description:
656 * Gets current MIB objects from adapter, then
657 * returns FDDI statistics structure as defined
658 * in if_fddi.h.
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
669 * independent.
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
681 #if 0
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;
794 #endif
795 return (struct net_device_stats *)&bp->os.MacStat;
796 } // ctl_get_stat
800 * ==============================
801 * = skfp_ctl_set_multicast_list =
802 * ==============================
804 * Overview:
805 * Enable/Disable LLC frame promiscuous mode reception
806 * on the adapter and/or update multicast address table.
808 * Returns:
809 * None
811 * Arguments:
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
822 * else
823 * disable promiscuous mode
824 * if number of multicast addresses <= max. multicast number
825 * add mc addresses to adapter table
826 * else
827 * enable promiscuous mode
828 * update adapter filters
830 * Assumptions:
831 * Multicast addresses are presented in canonical (LSB) format.
833 * Side Effects:
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;
840 unsigned long Flags;
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 */
860 else {
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",
882 ha->addr);
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 * ===========================
906 * Overview:
907 * set new mac address on adapter and update dev_addr field in device table.
909 * Returns:
910 * None
912 * Arguments:
913 * dev - pointer to device information
914 * addr - pointer to sockaddr structure containing unicast address to set
916 * Assumptions:
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;
925 unsigned long Flags;
928 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
929 spin_lock_irqsave(&bp->DriverLock, Flags);
930 ResetAdapter(smc);
931 spin_unlock_irqrestore(&bp->DriverLock, Flags);
933 return 0; /* always return zero */
934 } // skfp_ctl_set_mac_address
938 * ==============
939 * = skfp_ioctl =
940 * ==============
942 * Overview:
944 * Perform IOCTL call functions here. Some are privileged operations and the
945 * effective uid is checked in those cases.
947 * Returns:
948 * status value
949 * 0 - success
950 * other - failure
952 * Arguments:
953 * dev - pointer to device information
954 * rq - pointer to ioctl request structure
955 * cmd - ?
960 static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
962 struct s_smc *smc = netdev_priv(dev);
963 skfddi_priv *lp = &smc->os;
964 struct s_skfp_ioctl ioc;
965 int status = 0;
967 if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
968 return -EFAULT;
970 switch (ioc.cmd) {
971 case SKFP_GET_STATS: /* Get the driver statistics */
972 ioc.len = sizeof(lp->MacStat);
973 status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
974 ? -EFAULT : 0;
975 break;
976 case SKFP_CLR_STATS: /* Zero out the driver statistics */
977 if (!capable(CAP_NET_ADMIN)) {
978 status = -EPERM;
979 } else {
980 memset(&lp->MacStat, 0, sizeof(lp->MacStat));
982 break;
983 default:
984 printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd);
985 status = -EOPNOTSUPP;
987 } // switch
989 return status;
990 } // skfp_ioctl
994 * =====================
995 * = skfp_send_pkt =
996 * =====================
998 * Overview:
999 * Queues a packet for transmission and try to transmit it.
1001 * Returns:
1002 * Condition code
1004 * Arguments:
1005 * skb - pointer to sk_buff to queue for transmission
1006 * dev - pointer to device information
1008 * Functional Description:
1009 * Here we assume that an incoming skb transmit request
1010 * is contained in a single physically contiguous buffer
1011 * in which the virtual address of the start of packet
1012 * (skb->data) can be converted to a physical address
1013 * by using pci_map_single().
1015 * We have an internal queue for packets we can not send
1016 * immediately. Packets in this queue can be given to the
1017 * adapter if transmit buffers are freed.
1019 * We can't free the skb until after it's been DMA'd
1020 * out by the adapter, so we'll keep it in the driver and
1021 * return it in mac_drv_tx_complete.
1023 * Return Codes:
1024 * 0 - driver has queued and/or sent packet
1025 * 1 - caller should requeue the sk_buff for later transmission
1027 * Assumptions:
1028 * The entire packet is stored in one physically
1029 * contiguous buffer which is not cached and whose
1030 * 32-bit physical address can be determined.
1032 * It's vital that this routine is NOT reentered for the
1033 * same board and that the OS is not in another section of
1034 * code (eg. skfp_interrupt) for the same board on a
1035 * different thread.
1037 * Side Effects:
1038 * None
1040 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
1041 struct net_device *dev)
1043 struct s_smc *smc = netdev_priv(dev);
1044 skfddi_priv *bp = &smc->os;
1046 pr_debug("skfp_send_pkt\n");
1049 * Verify that incoming transmit request is OK
1051 * Note: The packet size check is consistent with other
1052 * Linux device drivers, although the correct packet
1053 * size should be verified before calling the
1054 * transmit routine.
1057 if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
1058 bp->MacStat.gen.tx_errors++; /* bump error counter */
1059 // dequeue packets from xmt queue and send them
1060 netif_start_queue(dev);
1061 dev_kfree_skb(skb);
1062 return NETDEV_TX_OK; /* return "success" */
1064 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1066 netif_stop_queue(dev);
1067 return NETDEV_TX_BUSY;
1069 bp->QueueSkb--;
1070 skb_queue_tail(&bp->SendSkbQueue, skb);
1071 send_queued_packets(netdev_priv(dev));
1072 if (bp->QueueSkb == 0) {
1073 netif_stop_queue(dev);
1075 return NETDEV_TX_OK;
1077 } // skfp_send_pkt
1081 * =======================
1082 * = send_queued_packets =
1083 * =======================
1085 * Overview:
1086 * Send packets from the driver queue as long as there are some and
1087 * transmit resources are available.
1089 * Returns:
1090 * None
1092 * Arguments:
1093 * smc - pointer to smc (adapter) structure
1095 * Functional Description:
1096 * Take a packet from queue if there is any. If not, then we are done.
1097 * Check if there are resources to send the packet. If not, requeue it
1098 * and exit.
1099 * Set packet descriptor flags and give packet to adapter.
1100 * Check if any send resources can be freed (we do not use the
1101 * transmit complete interrupt).
1103 static void send_queued_packets(struct s_smc *smc)
1105 skfddi_priv *bp = &smc->os;
1106 struct sk_buff *skb;
1107 unsigned char fc;
1108 int queue;
1109 struct s_smt_fp_txd *txd; // Current TxD.
1110 dma_addr_t dma_address;
1111 unsigned long Flags;
1113 int frame_status; // HWM tx frame status.
1115 pr_debug("send queued packets\n");
1116 for (;;) {
1117 // send first buffer from queue
1118 skb = skb_dequeue(&bp->SendSkbQueue);
1120 if (!skb) {
1121 pr_debug("queue empty\n");
1122 return;
1123 } // queue empty !
1125 spin_lock_irqsave(&bp->DriverLock, Flags);
1126 fc = skb->data[0];
1127 queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1128 #ifdef ESS
1129 // Check if the frame may/must be sent as a synchronous frame.
1131 if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
1132 // It's an LLC frame.
1133 if (!smc->ess.sync_bw_available)
1134 fc &= ~FC_SYNC_BIT; // No bandwidth available.
1136 else { // Bandwidth is available.
1138 if (smc->mib.fddiESSSynchTxMode) {
1139 // Send as sync. frame.
1140 fc |= FC_SYNC_BIT;
1144 #endif // ESS
1145 frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1147 if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1148 // Unable to send the frame.
1150 if ((frame_status & RING_DOWN) != 0) {
1151 // Ring is down.
1152 pr_debug("Tx attempt while ring down.\n");
1153 } else if ((frame_status & OUT_OF_TXD) != 0) {
1154 pr_debug("%s: out of TXDs.\n", bp->dev->name);
1155 } else {
1156 pr_debug("%s: out of transmit resources",
1157 bp->dev->name);
1160 // Note: We will retry the operation as soon as
1161 // transmit resources become available.
1162 skb_queue_head(&bp->SendSkbQueue, skb);
1163 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1164 return; // Packet has been queued.
1166 } // if (unable to send frame)
1168 bp->QueueSkb++; // one packet less in local queue
1170 // source address in packet ?
1171 CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1173 txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1175 dma_address = pci_map_single(&bp->pdev, skb->data,
1176 skb->len, PCI_DMA_TODEVICE);
1177 if (frame_status & LAN_TX) {
1178 txd->txd_os.skb = skb; // save skb
1179 txd->txd_os.dma_addr = dma_address; // save dma mapping
1181 hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1182 frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1184 if (!(frame_status & LAN_TX)) { // local only frame
1185 pci_unmap_single(&bp->pdev, dma_address,
1186 skb->len, PCI_DMA_TODEVICE);
1187 dev_kfree_skb_irq(skb);
1189 spin_unlock_irqrestore(&bp->DriverLock, Flags);
1190 } // for
1192 return; // never reached
1194 } // send_queued_packets
1197 /************************
1199 * CheckSourceAddress
1201 * Verify if the source address is set. Insert it if necessary.
1203 ************************/
1204 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1206 unsigned char SRBit;
1208 if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1210 return;
1211 if ((unsigned short) frame[1 + 10] != 0)
1212 return;
1213 SRBit = frame[1 + 6] & 0x01;
1214 memcpy(&frame[1 + 6], hw_addr, ETH_ALEN);
1215 frame[8] |= SRBit;
1216 } // CheckSourceAddress
1219 /************************
1221 * ResetAdapter
1223 * Reset the adapter and bring it back to operational mode.
1224 * Args
1225 * smc - A pointer to the SMT context struct.
1226 * Out
1227 * Nothing.
1229 ************************/
1230 static void ResetAdapter(struct s_smc *smc)
1233 pr_debug("[fddi: ResetAdapter]\n");
1235 // Stop the adapter.
1237 card_stop(smc); // Stop all activity.
1239 // Clear the transmit and receive descriptor queues.
1240 mac_drv_clear_tx_queue(smc);
1241 mac_drv_clear_rx_queue(smc);
1243 // Restart the adapter.
1245 smt_reset_defaults(smc, 1); // Initialize the SMT module.
1247 init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1249 smt_online(smc, 1); // Insert into the ring again.
1250 STI_FBI();
1252 // Restore original receive mode (multicasts, promiscuous, etc.).
1253 skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1254 } // ResetAdapter
1257 //--------------- functions called by hardware module ----------------
1259 /************************
1261 * llc_restart_tx
1263 * The hardware driver calls this routine when the transmit complete
1264 * interrupt bits (end of frame) for the synchronous or asynchronous
1265 * queue is set.
1267 * NOTE The hardware driver calls this function also if no packets are queued.
1268 * The routine must be able to handle this case.
1269 * Args
1270 * smc - A pointer to the SMT context struct.
1271 * Out
1272 * Nothing.
1274 ************************/
1275 void llc_restart_tx(struct s_smc *smc)
1277 skfddi_priv *bp = &smc->os;
1279 pr_debug("[llc_restart_tx]\n");
1281 // Try to send queued packets
1282 spin_unlock(&bp->DriverLock);
1283 send_queued_packets(smc);
1284 spin_lock(&bp->DriverLock);
1285 netif_start_queue(bp->dev);// system may send again if it was blocked
1287 } // llc_restart_tx
1290 /************************
1292 * mac_drv_get_space
1294 * The hardware module calls this function to allocate the memory
1295 * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1296 * Args
1297 * smc - A pointer to the SMT context struct.
1299 * size - Size of memory in bytes to allocate.
1300 * Out
1301 * != 0 A pointer to the virtual address of the allocated memory.
1302 * == 0 Allocation error.
1304 ************************/
1305 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1307 void *virt;
1309 pr_debug("mac_drv_get_space (%d bytes), ", size);
1310 virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1312 if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1313 printk("Unexpected SMT memory size requested: %d\n", size);
1314 return NULL;
1316 smc->os.SharedMemHeap += size; // Move heap pointer.
1318 pr_debug("mac_drv_get_space end\n");
1319 pr_debug("virt addr: %lx\n", (ulong) virt);
1320 pr_debug("bus addr: %lx\n", (ulong)
1321 (smc->os.SharedMemDMA +
1322 ((char *) virt - (char *)smc->os.SharedMemAddr)));
1323 return virt;
1324 } // mac_drv_get_space
1327 /************************
1329 * mac_drv_get_desc_mem
1331 * This function is called by the hardware dependent module.
1332 * It allocates the memory for the RxD and TxD descriptors.
1334 * This memory must be non-cached, non-movable and non-swappable.
1335 * This memory should start at a physical page boundary.
1336 * Args
1337 * smc - A pointer to the SMT context struct.
1339 * size - Size of memory in bytes to allocate.
1340 * Out
1341 * != 0 A pointer to the virtual address of the allocated memory.
1342 * == 0 Allocation error.
1344 ************************/
1345 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1348 char *virt;
1350 pr_debug("mac_drv_get_desc_mem\n");
1352 // Descriptor memory must be aligned on 16-byte boundary.
1354 virt = mac_drv_get_space(smc, size);
1356 size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1357 size = size % 16;
1359 pr_debug("Allocate %u bytes alignment gap ", size);
1360 pr_debug("for descriptor memory.\n");
1362 if (!mac_drv_get_space(smc, size)) {
1363 printk("fddi: Unable to align descriptor memory.\n");
1364 return NULL;
1366 return virt + size;
1367 } // mac_drv_get_desc_mem
1370 /************************
1372 * mac_drv_virt2phys
1374 * Get the physical address of a given virtual address.
1375 * Args
1376 * smc - A pointer to the SMT context struct.
1378 * virt - A (virtual) pointer into our 'shared' memory area.
1379 * Out
1380 * Physical address of the given virtual address.
1382 ************************/
1383 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1385 return smc->os.SharedMemDMA +
1386 ((char *) virt - (char *)smc->os.SharedMemAddr);
1387 } // mac_drv_virt2phys
1390 /************************
1392 * dma_master
1394 * The HWM calls this function, when the driver leads through a DMA
1395 * transfer. If the OS-specific module must prepare the system hardware
1396 * for the DMA transfer, it should do it in this function.
1398 * The hardware module calls this dma_master if it wants to send an SMT
1399 * frame. This means that the virt address passed in here is part of
1400 * the 'shared' memory area.
1401 * Args
1402 * smc - A pointer to the SMT context struct.
1404 * virt - The virtual address of the data.
1406 * len - The length in bytes of the data.
1408 * flag - Indicates the transmit direction and the buffer type:
1409 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1410 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1411 * SMT_BUF (0x80) SMT buffer
1413 * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1414 * Out
1415 * Returns the pyhsical address for the DMA transfer.
1417 ************************/
1418 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1420 return smc->os.SharedMemDMA +
1421 ((char *) virt - (char *)smc->os.SharedMemAddr);
1422 } // dma_master
1425 /************************
1427 * dma_complete
1429 * The hardware module calls this routine when it has completed a DMA
1430 * transfer. If the operating system dependent module has set up the DMA
1431 * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
1432 * the DMA channel.
1433 * Args
1434 * smc - A pointer to the SMT context struct.
1436 * descr - A pointer to a TxD or RxD, respectively.
1438 * flag - Indicates the DMA transfer direction / SMT buffer:
1439 * DMA_RD (0x01) system RAM ==> adapter buffer memory
1440 * DMA_WR (0x02) adapter buffer memory ==> system RAM
1441 * SMT_BUF (0x80) SMT buffer (managed by HWM)
1442 * Out
1443 * Nothing.
1445 ************************/
1446 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1448 /* For TX buffers, there are two cases. If it is an SMT transmit
1449 * buffer, there is nothing to do since we use consistent memory
1450 * for the 'shared' memory area. The other case is for normal
1451 * transmit packets given to us by the networking stack, and in
1452 * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
1453 * below.
1455 * For RX buffers, we have to unmap dynamic PCI DMA mappings here
1456 * because the hardware module is about to potentially look at
1457 * the contents of the buffer. If we did not call the PCI DMA
1458 * unmap first, the hardware module could read inconsistent data.
1460 if (flag & DMA_WR) {
1461 skfddi_priv *bp = &smc->os;
1462 volatile struct s_smt_fp_rxd *r = &descr->r;
1464 /* If SKB is NULL, we used the local buffer. */
1465 if (r->rxd_os.skb && r->rxd_os.dma_addr) {
1466 int MaxFrameSize = bp->MaxFrameSize;
1468 pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
1469 MaxFrameSize, PCI_DMA_FROMDEVICE);
1470 r->rxd_os.dma_addr = 0;
1473 } // dma_complete
1476 /************************
1478 * mac_drv_tx_complete
1480 * Transmit of a packet is complete. Release the tx staging buffer.
1482 * Args
1483 * smc - A pointer to the SMT context struct.
1485 * txd - A pointer to the last TxD which is used by the frame.
1486 * Out
1487 * Returns nothing.
1489 ************************/
1490 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1492 struct sk_buff *skb;
1494 pr_debug("entering mac_drv_tx_complete\n");
1495 // Check if this TxD points to a skb
1497 if (!(skb = txd->txd_os.skb)) {
1498 pr_debug("TXD with no skb assigned.\n");
1499 return;
1501 txd->txd_os.skb = NULL;
1503 // release the DMA mapping
1504 pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
1505 skb->len, PCI_DMA_TODEVICE);
1506 txd->txd_os.dma_addr = 0;
1508 smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
1509 smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1511 // free the skb
1512 dev_kfree_skb_irq(skb);
1514 pr_debug("leaving mac_drv_tx_complete\n");
1515 } // mac_drv_tx_complete
1518 /************************
1520 * dump packets to logfile
1522 ************************/
1523 #ifdef DUMPPACKETS
1524 void dump_data(unsigned char *Data, int length)
1526 int i, j;
1527 unsigned char s[255], sh[10];
1528 if (length > 64) {
1529 length = 64;
1531 printk(KERN_INFO "---Packet start---\n");
1532 for (i = 0, j = 0; i < length / 8; i++, j += 8)
1533 printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
1534 Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
1535 Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
1536 strcpy(s, "");
1537 for (i = 0; i < length % 8; i++) {
1538 sprintf(sh, "%02x ", Data[j + i]);
1539 strcat(s, sh);
1541 printk(KERN_INFO "%s\n", s);
1542 printk(KERN_INFO "------------------\n");
1543 } // dump_data
1544 #else
1545 #define dump_data(data,len)
1546 #endif // DUMPPACKETS
1548 /************************
1550 * mac_drv_rx_complete
1552 * The hardware module calls this function if an LLC frame is received
1553 * in a receive buffer. Also the SMT, NSA, and directed beacon frames
1554 * from the network will be passed to the LLC layer by this function
1555 * if passing is enabled.
1557 * mac_drv_rx_complete forwards the frame to the LLC layer if it should
1558 * be received. It also fills the RxD ring with new receive buffers if
1559 * some can be queued.
1560 * Args
1561 * smc - A pointer to the SMT context struct.
1563 * rxd - A pointer to the first RxD which is used by the receive frame.
1565 * frag_count - Count of RxDs used by the received frame.
1567 * len - Frame length.
1568 * Out
1569 * Nothing.
1571 ************************/
1572 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1573 int frag_count, int len)
1575 skfddi_priv *bp = &smc->os;
1576 struct sk_buff *skb;
1577 unsigned char *virt, *cp;
1578 unsigned short ri;
1579 u_int RifLength;
1581 pr_debug("entering mac_drv_rx_complete (len=%d)\n", len);
1582 if (frag_count != 1) { // This is not allowed to happen.
1584 printk("fddi: Multi-fragment receive!\n");
1585 goto RequeueRxd; // Re-use the given RXD(s).
1588 skb = rxd->rxd_os.skb;
1589 if (!skb) {
1590 pr_debug("No skb in rxd\n");
1591 smc->os.MacStat.gen.rx_errors++;
1592 goto RequeueRxd;
1594 virt = skb->data;
1596 // The DMA mapping was released in dma_complete above.
1598 dump_data(skb->data, len);
1601 * FDDI Frame format:
1602 * +-------+-------+-------+------------+--------+------------+
1603 * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1604 * +-------+-------+-------+------------+--------+------------+
1606 * FC = Frame Control
1607 * DA = Destination Address
1608 * SA = Source Address
1609 * RIF = Routing Information Field
1610 * LLC = Logical Link Control
1613 // Remove Routing Information Field (RIF), if present.
1615 if ((virt[1 + 6] & FDDI_RII) == 0)
1616 RifLength = 0;
1617 else {
1618 int n;
1619 // goos: RIF removal has still to be tested
1620 pr_debug("RIF found\n");
1621 // Get RIF length from Routing Control (RC) field.
1622 cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
1624 ri = ntohs(*((__be16 *) cp));
1625 RifLength = ri & FDDI_RCF_LEN_MASK;
1626 if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
1627 printk("fddi: Invalid RIF.\n");
1628 goto RequeueRxd; // Discard the frame.
1631 virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
1632 // regions overlap
1634 virt = cp + RifLength;
1635 for (n = FDDI_MAC_HDR_LEN; n; n--)
1636 *--virt = *--cp;
1637 // adjust sbd->data pointer
1638 skb_pull(skb, RifLength);
1639 len -= RifLength;
1640 RifLength = 0;
1643 // Count statistics.
1644 smc->os.MacStat.gen.rx_packets++; // Count indicated receive
1645 // packets.
1646 smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
1648 // virt points to header again
1649 if (virt[1] & 0x01) { // Check group (multicast) bit.
1651 smc->os.MacStat.gen.multicast++;
1654 // deliver frame to system
1655 rxd->rxd_os.skb = NULL;
1656 skb_trim(skb, len);
1657 skb->protocol = fddi_type_trans(skb, bp->dev);
1659 netif_rx(skb);
1661 HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1662 return;
1664 RequeueRxd:
1665 pr_debug("Rx: re-queue RXD.\n");
1666 mac_drv_requeue_rxd(smc, rxd, frag_count);
1667 smc->os.MacStat.gen.rx_errors++; // Count receive packets
1668 // not indicated.
1670 } // mac_drv_rx_complete
1673 /************************
1675 * mac_drv_requeue_rxd
1677 * The hardware module calls this function to request the OS-specific
1678 * module to queue the receive buffer(s) represented by the pointer
1679 * to the RxD and the frag_count into the receive queue again. This
1680 * buffer was filled with an invalid frame or an SMT frame.
1681 * Args
1682 * smc - A pointer to the SMT context struct.
1684 * rxd - A pointer to the first RxD which is used by the receive frame.
1686 * frag_count - Count of RxDs used by the received frame.
1687 * Out
1688 * Nothing.
1690 ************************/
1691 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1692 int frag_count)
1694 volatile struct s_smt_fp_rxd *next_rxd;
1695 volatile struct s_smt_fp_rxd *src_rxd;
1696 struct sk_buff *skb;
1697 int MaxFrameSize;
1698 unsigned char *v_addr;
1699 dma_addr_t b_addr;
1701 if (frag_count != 1) // This is not allowed to happen.
1703 printk("fddi: Multi-fragment requeue!\n");
1705 MaxFrameSize = smc->os.MaxFrameSize;
1706 src_rxd = rxd;
1707 for (; frag_count > 0; frag_count--) {
1708 next_rxd = src_rxd->rxd_next;
1709 rxd = HWM_GET_CURR_RXD(smc);
1711 skb = src_rxd->rxd_os.skb;
1712 if (skb == NULL) { // this should not happen
1714 pr_debug("Requeue with no skb in rxd!\n");
1715 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1716 if (skb) {
1717 // we got a skb
1718 rxd->rxd_os.skb = skb;
1719 skb_reserve(skb, 3);
1720 skb_put(skb, MaxFrameSize);
1721 v_addr = skb->data;
1722 b_addr = pci_map_single(&smc->os.pdev,
1723 v_addr,
1724 MaxFrameSize,
1725 PCI_DMA_FROMDEVICE);
1726 rxd->rxd_os.dma_addr = b_addr;
1727 } else {
1728 // no skb available, use local buffer
1729 pr_debug("Queueing invalid buffer!\n");
1730 rxd->rxd_os.skb = NULL;
1731 v_addr = smc->os.LocalRxBuffer;
1732 b_addr = smc->os.LocalRxBufferDMA;
1734 } else {
1735 // we use skb from old rxd
1736 rxd->rxd_os.skb = skb;
1737 v_addr = skb->data;
1738 b_addr = pci_map_single(&smc->os.pdev,
1739 v_addr,
1740 MaxFrameSize,
1741 PCI_DMA_FROMDEVICE);
1742 rxd->rxd_os.dma_addr = b_addr;
1744 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1745 FIRST_FRAG | LAST_FRAG);
1747 src_rxd = next_rxd;
1749 } // mac_drv_requeue_rxd
1752 /************************
1754 * mac_drv_fill_rxd
1756 * The hardware module calls this function at initialization time
1757 * to fill the RxD ring with receive buffers. It is also called by
1758 * mac_drv_rx_complete if rx_free is large enough to queue some new
1759 * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
1760 * receive buffers as long as enough RxDs and receive buffers are
1761 * available.
1762 * Args
1763 * smc - A pointer to the SMT context struct.
1764 * Out
1765 * Nothing.
1767 ************************/
1768 void mac_drv_fill_rxd(struct s_smc *smc)
1770 int MaxFrameSize;
1771 unsigned char *v_addr;
1772 unsigned long b_addr;
1773 struct sk_buff *skb;
1774 volatile struct s_smt_fp_rxd *rxd;
1776 pr_debug("entering mac_drv_fill_rxd\n");
1778 // Walk through the list of free receive buffers, passing receive
1779 // buffers to the HWM as long as RXDs are available.
1781 MaxFrameSize = smc->os.MaxFrameSize;
1782 // Check if there is any RXD left.
1783 while (HWM_GET_RX_FREE(smc) > 0) {
1784 pr_debug(".\n");
1786 rxd = HWM_GET_CURR_RXD(smc);
1787 skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1788 if (skb) {
1789 // we got a skb
1790 skb_reserve(skb, 3);
1791 skb_put(skb, MaxFrameSize);
1792 v_addr = skb->data;
1793 b_addr = pci_map_single(&smc->os.pdev,
1794 v_addr,
1795 MaxFrameSize,
1796 PCI_DMA_FROMDEVICE);
1797 rxd->rxd_os.dma_addr = b_addr;
1798 } else {
1799 // no skb available, use local buffer
1800 // System has run out of buffer memory, but we want to
1801 // keep the receiver running in hope of better times.
1802 // Multiple descriptors may point to this local buffer,
1803 // so data in it must be considered invalid.
1804 pr_debug("Queueing invalid buffer!\n");
1805 v_addr = smc->os.LocalRxBuffer;
1806 b_addr = smc->os.LocalRxBufferDMA;
1809 rxd->rxd_os.skb = skb;
1811 // Pass receive buffer to HWM.
1812 hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1813 FIRST_FRAG | LAST_FRAG);
1815 pr_debug("leaving mac_drv_fill_rxd\n");
1816 } // mac_drv_fill_rxd
1819 /************************
1821 * mac_drv_clear_rxd
1823 * The hardware module calls this function to release unused
1824 * receive buffers.
1825 * Args
1826 * smc - A pointer to the SMT context struct.
1828 * rxd - A pointer to the first RxD which is used by the receive buffer.
1830 * frag_count - Count of RxDs used by the receive buffer.
1831 * Out
1832 * Nothing.
1834 ************************/
1835 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1836 int frag_count)
1839 struct sk_buff *skb;
1841 pr_debug("entering mac_drv_clear_rxd\n");
1843 if (frag_count != 1) // This is not allowed to happen.
1845 printk("fddi: Multi-fragment clear!\n");
1847 for (; frag_count > 0; frag_count--) {
1848 skb = rxd->rxd_os.skb;
1849 if (skb != NULL) {
1850 skfddi_priv *bp = &smc->os;
1851 int MaxFrameSize = bp->MaxFrameSize;
1853 pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
1854 MaxFrameSize, PCI_DMA_FROMDEVICE);
1856 dev_kfree_skb(skb);
1857 rxd->rxd_os.skb = NULL;
1859 rxd = rxd->rxd_next; // Next RXD.
1862 } // mac_drv_clear_rxd
1865 /************************
1867 * mac_drv_rx_init
1869 * The hardware module calls this routine when an SMT or NSA frame of the
1870 * local SMT should be delivered to the LLC layer.
1872 * It is necessary to have this function, because there is no other way to
1873 * copy the contents of SMT MBufs into receive buffers.
1875 * mac_drv_rx_init allocates the required target memory for this frame,
1876 * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
1877 * Args
1878 * smc - A pointer to the SMT context struct.
1880 * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1882 * fc - The Frame Control field of the received frame.
1884 * look_ahead - A pointer to the lookahead data buffer (may be NULL).
1886 * la_len - The length of the lookahead data stored in the lookahead
1887 * buffer (may be zero).
1888 * Out
1889 * Always returns zero (0).
1891 ************************/
1892 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1893 char *look_ahead, int la_len)
1895 struct sk_buff *skb;
1897 pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
1899 // "Received" a SMT or NSA frame of the local SMT.
1901 if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
1902 pr_debug("fddi: Discard invalid local SMT frame\n");
1903 pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
1904 len, la_len, (unsigned long) look_ahead);
1905 return 0;
1907 skb = alloc_skb(len + 3, GFP_ATOMIC);
1908 if (!skb) {
1909 pr_debug("fddi: Local SMT: skb memory exhausted.\n");
1910 return 0;
1912 skb_reserve(skb, 3);
1913 skb_put(skb, len);
1914 skb_copy_to_linear_data(skb, look_ahead, len);
1916 // deliver frame to system
1917 skb->protocol = fddi_type_trans(skb, smc->os.dev);
1918 netif_rx(skb);
1920 return 0;
1921 } // mac_drv_rx_init
1924 /************************
1926 * smt_timer_poll
1928 * This routine is called periodically by the SMT module to clean up the
1929 * driver.
1931 * Return any queued frames back to the upper protocol layers if the ring
1932 * is down.
1933 * Args
1934 * smc - A pointer to the SMT context struct.
1935 * Out
1936 * Nothing.
1938 ************************/
1939 void smt_timer_poll(struct s_smc *smc)
1941 } // smt_timer_poll
1944 /************************
1946 * ring_status_indication
1948 * This function indicates a change of the ring state.
1949 * Args
1950 * smc - A pointer to the SMT context struct.
1952 * status - The current ring status.
1953 * Out
1954 * Nothing.
1956 ************************/
1957 void ring_status_indication(struct s_smc *smc, u_long status)
1959 pr_debug("ring_status_indication( ");
1960 if (status & RS_RES15)
1961 pr_debug("RS_RES15 ");
1962 if (status & RS_HARDERROR)
1963 pr_debug("RS_HARDERROR ");
1964 if (status & RS_SOFTERROR)
1965 pr_debug("RS_SOFTERROR ");
1966 if (status & RS_BEACON)
1967 pr_debug("RS_BEACON ");
1968 if (status & RS_PATHTEST)
1969 pr_debug("RS_PATHTEST ");
1970 if (status & RS_SELFTEST)
1971 pr_debug("RS_SELFTEST ");
1972 if (status & RS_RES9)
1973 pr_debug("RS_RES9 ");
1974 if (status & RS_DISCONNECT)
1975 pr_debug("RS_DISCONNECT ");
1976 if (status & RS_RES7)
1977 pr_debug("RS_RES7 ");
1978 if (status & RS_DUPADDR)
1979 pr_debug("RS_DUPADDR ");
1980 if (status & RS_NORINGOP)
1981 pr_debug("RS_NORINGOP ");
1982 if (status & RS_VERSION)
1983 pr_debug("RS_VERSION ");
1984 if (status & RS_STUCKBYPASSS)
1985 pr_debug("RS_STUCKBYPASSS ");
1986 if (status & RS_EVENT)
1987 pr_debug("RS_EVENT ");
1988 if (status & RS_RINGOPCHANGE)
1989 pr_debug("RS_RINGOPCHANGE ");
1990 if (status & RS_RES0)
1991 pr_debug("RS_RES0 ");
1992 pr_debug("]\n");
1993 } // ring_status_indication
1996 /************************
1998 * smt_get_time
2000 * Gets the current time from the system.
2001 * Args
2002 * None.
2003 * Out
2004 * The current time in TICKS_PER_SECOND.
2006 * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
2007 * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
2008 * to the time returned by smt_get_time().
2010 ************************/
2011 unsigned long smt_get_time(void)
2013 return jiffies;
2014 } // smt_get_time
2017 /************************
2019 * smt_stat_counter
2021 * Status counter update (ring_op, fifo full).
2022 * Args
2023 * smc - A pointer to the SMT context struct.
2025 * stat - = 0: A ring operational change occurred.
2026 * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2027 * Out
2028 * Nothing.
2030 ************************/
2031 void smt_stat_counter(struct s_smc *smc, int stat)
2033 // BOOLEAN RingIsUp ;
2035 pr_debug("smt_stat_counter\n");
2036 switch (stat) {
2037 case 0:
2038 pr_debug("Ring operational change.\n");
2039 break;
2040 case 1:
2041 pr_debug("Receive fifo overflow.\n");
2042 smc->os.MacStat.gen.rx_errors++;
2043 break;
2044 default:
2045 pr_debug("Unknown status (%d).\n", stat);
2046 break;
2048 } // smt_stat_counter
2051 /************************
2053 * cfm_state_change
2055 * Sets CFM state in custom statistics.
2056 * Args
2057 * smc - A pointer to the SMT context struct.
2059 * c_state - Possible values are:
2061 * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2062 * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2063 * Out
2064 * Nothing.
2066 ************************/
2067 void cfm_state_change(struct s_smc *smc, int c_state)
2069 #ifdef DRIVERDEBUG
2070 char *s;
2072 switch (c_state) {
2073 case SC0_ISOLATED:
2074 s = "SC0_ISOLATED";
2075 break;
2076 case SC1_WRAP_A:
2077 s = "SC1_WRAP_A";
2078 break;
2079 case SC2_WRAP_B:
2080 s = "SC2_WRAP_B";
2081 break;
2082 case SC4_THRU_A:
2083 s = "SC4_THRU_A";
2084 break;
2085 case SC5_THRU_B:
2086 s = "SC5_THRU_B";
2087 break;
2088 case SC7_WRAP_S:
2089 s = "SC7_WRAP_S";
2090 break;
2091 case SC9_C_WRAP_A:
2092 s = "SC9_C_WRAP_A";
2093 break;
2094 case SC10_C_WRAP_B:
2095 s = "SC10_C_WRAP_B";
2096 break;
2097 case SC11_C_WRAP_S:
2098 s = "SC11_C_WRAP_S";
2099 break;
2100 default:
2101 pr_debug("cfm_state_change: unknown %d\n", c_state);
2102 return;
2104 pr_debug("cfm_state_change: %s\n", s);
2105 #endif // DRIVERDEBUG
2106 } // cfm_state_change
2109 /************************
2111 * ecm_state_change
2113 * Sets ECM state in custom statistics.
2114 * Args
2115 * smc - A pointer to the SMT context struct.
2117 * e_state - Possible values are:
2119 * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2120 * SC5_THRU_B (7), SC7_WRAP_S (8)
2121 * Out
2122 * Nothing.
2124 ************************/
2125 void ecm_state_change(struct s_smc *smc, int e_state)
2127 #ifdef DRIVERDEBUG
2128 char *s;
2130 switch (e_state) {
2131 case EC0_OUT:
2132 s = "EC0_OUT";
2133 break;
2134 case EC1_IN:
2135 s = "EC1_IN";
2136 break;
2137 case EC2_TRACE:
2138 s = "EC2_TRACE";
2139 break;
2140 case EC3_LEAVE:
2141 s = "EC3_LEAVE";
2142 break;
2143 case EC4_PATH_TEST:
2144 s = "EC4_PATH_TEST";
2145 break;
2146 case EC5_INSERT:
2147 s = "EC5_INSERT";
2148 break;
2149 case EC6_CHECK:
2150 s = "EC6_CHECK";
2151 break;
2152 case EC7_DEINSERT:
2153 s = "EC7_DEINSERT";
2154 break;
2155 default:
2156 s = "unknown";
2157 break;
2159 pr_debug("ecm_state_change: %s\n", s);
2160 #endif //DRIVERDEBUG
2161 } // ecm_state_change
2164 /************************
2166 * rmt_state_change
2168 * Sets RMT state in custom statistics.
2169 * Args
2170 * smc - A pointer to the SMT context struct.
2172 * r_state - Possible values are:
2174 * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2175 * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2176 * Out
2177 * Nothing.
2179 ************************/
2180 void rmt_state_change(struct s_smc *smc, int r_state)
2182 #ifdef DRIVERDEBUG
2183 char *s;
2185 switch (r_state) {
2186 case RM0_ISOLATED:
2187 s = "RM0_ISOLATED";
2188 break;
2189 case RM1_NON_OP:
2190 s = "RM1_NON_OP - not operational";
2191 break;
2192 case RM2_RING_OP:
2193 s = "RM2_RING_OP - ring operational";
2194 break;
2195 case RM3_DETECT:
2196 s = "RM3_DETECT - detect dupl addresses";
2197 break;
2198 case RM4_NON_OP_DUP:
2199 s = "RM4_NON_OP_DUP - dupl. addr detected";
2200 break;
2201 case RM5_RING_OP_DUP:
2202 s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2203 break;
2204 case RM6_DIRECTED:
2205 s = "RM6_DIRECTED - sending directed beacons";
2206 break;
2207 case RM7_TRACE:
2208 s = "RM7_TRACE - trace initiated";
2209 break;
2210 default:
2211 s = "unknown";
2212 break;
2214 pr_debug("[rmt_state_change: %s]\n", s);
2215 #endif // DRIVERDEBUG
2216 } // rmt_state_change
2219 /************************
2221 * drv_reset_indication
2223 * This function is called by the SMT when it has detected a severe
2224 * hardware problem. The driver should perform a reset on the adapter
2225 * as soon as possible, but not from within this function.
2226 * Args
2227 * smc - A pointer to the SMT context struct.
2228 * Out
2229 * Nothing.
2231 ************************/
2232 void drv_reset_indication(struct s_smc *smc)
2234 pr_debug("entering drv_reset_indication\n");
2236 smc->os.ResetRequested = TRUE; // Set flag.
2238 } // drv_reset_indication
2240 static struct pci_driver skfddi_pci_driver = {
2241 .name = "skfddi",
2242 .id_table = skfddi_pci_tbl,
2243 .probe = skfp_init_one,
2244 .remove = skfp_remove_one,
2247 module_pci_driver(skfddi_pci_driver);