Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * File Name:
0004  *   skfddi.c
0005  *
0006  * Copyright Information:
0007  *   Copyright SysKonnect 1998,1999.
0008  *
0009  * The information in this file is provided "AS IS" without warranty.
0010  *
0011  * Abstract:
0012  *   A Linux device driver supporting the SysKonnect FDDI PCI controller
0013  *   familie.
0014  *
0015  * Maintainers:
0016  *   CG    Christoph Goos (cgoos@syskonnect.de)
0017  *
0018  * Contributors:
0019  *   DM    David S. Miller
0020  *
0021  * Address all question to:
0022  *   linux@syskonnect.de
0023  *
0024  * The technical manual for the adapters is available from SysKonnect's
0025  * web pages: www.syskonnect.com
0026  * Goto "Support" and search Knowledge Base for "manual".
0027  *
0028  * Driver Architecture:
0029  *   The driver architecture is based on the DEC FDDI driver by
0030  *   Lawrence V. Stefani and several ethernet drivers.
0031  *   I also used an existing Windows NT miniport driver.
0032  *   All hardware dependent functions are handled by the SysKonnect
0033  *   Hardware Module.
0034  *   The only headerfiles that are directly related to this source
0035  *   are skfddi.c, h/types.h, h/osdef1st.h, h/targetos.h.
0036  *   The others belong to the SysKonnect FDDI Hardware Module and
0037  *   should better not be changed.
0038  *
0039  * Modification History:
0040  *              Date            Name    Description
0041  *              02-Mar-98       CG  Created.
0042  *
0043  *      10-Mar-99   CG  Support for 2.2.x added.
0044  *      25-Mar-99   CG  Corrected IRQ routing for SMP (APIC)
0045  *      26-Oct-99   CG  Fixed compilation error on 2.2.13
0046  *      12-Nov-99   CG  Source code release
0047  *      22-Nov-99   CG  Included in kernel source.
0048  *      07-May-00   DM  64 bit fixes, new dma interface
0049  *      31-Jul-03   DB  Audit copy_*_user in skfp_ioctl
0050  *                    Daniele Bellucci <bellucda@tiscali.it>
0051  *      03-Dec-03   SH  Convert to PCI device model
0052  *
0053  * Compilation options (-Dxxx):
0054  *              DRIVERDEBUG     print lots of messages to log file
0055  *              DUMPPACKETS     print received/transmitted packets to logfile
0056  * 
0057  * Tested cpu architectures:
0058  *  - i386
0059  *  - sparc64
0060  */
0061 
0062 /* Version information string - should be updated prior to */
0063 /* each new release!!! */
0064 #define VERSION     "2.07"
0065 
0066 static const char * const boot_msg = 
0067     "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n"
0068     "  SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)";
0069 
0070 /* Include files */
0071 
0072 #include <linux/capability.h>
0073 #include <linux/compat.h>
0074 #include <linux/module.h>
0075 #include <linux/kernel.h>
0076 #include <linux/errno.h>
0077 #include <linux/ioport.h>
0078 #include <linux/interrupt.h>
0079 #include <linux/pci.h>
0080 #include <linux/netdevice.h>
0081 #include <linux/etherdevice.h>
0082 #include <linux/fddidevice.h>
0083 #include <linux/skbuff.h>
0084 #include <linux/bitops.h>
0085 #include <linux/gfp.h>
0086 
0087 #include <asm/byteorder.h>
0088 #include <asm/io.h>
0089 #include <linux/uaccess.h>
0090 
0091 #include    "h/types.h"
0092 #undef ADDR         // undo Linux definition
0093 #include    "h/skfbi.h"
0094 #include    "h/fddi.h"
0095 #include    "h/smc.h"
0096 #include    "h/smtstate.h"
0097 
0098 
0099 // Define module-wide (static) routines
0100 static int skfp_driver_init(struct net_device *dev);
0101 static int skfp_open(struct net_device *dev);
0102 static int skfp_close(struct net_device *dev);
0103 static irqreturn_t skfp_interrupt(int irq, void *dev_id);
0104 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
0105 static void skfp_ctl_set_multicast_list(struct net_device *dev);
0106 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
0107 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
0108 static int skfp_siocdevprivate(struct net_device *dev, struct ifreq *rq,
0109                    void __user *data, int cmd);
0110 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
0111                        struct net_device *dev);
0112 static void send_queued_packets(struct s_smc *smc);
0113 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
0114 static void ResetAdapter(struct s_smc *smc);
0115 
0116 
0117 // Functions needed by the hardware module
0118 void *mac_drv_get_space(struct s_smc *smc, u_int size);
0119 void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
0120 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
0121 unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
0122 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
0123           int flag);
0124 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
0125 void llc_restart_tx(struct s_smc *smc);
0126 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
0127              int frag_count, int len);
0128 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
0129              int frag_count);
0130 void mac_drv_fill_rxd(struct s_smc *smc);
0131 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
0132                int frag_count);
0133 int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
0134             int la_len);
0135 void dump_data(unsigned char *Data, int length);
0136 
0137 // External functions from the hardware module
0138 extern u_int mac_drv_check_space(void);
0139 extern int mac_drv_init(struct s_smc *smc);
0140 extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
0141             int len, int frame_status);
0142 extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
0143                int frame_len, int frame_status);
0144 extern void fddi_isr(struct s_smc *smc);
0145 extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
0146             int len, int frame_status);
0147 extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
0148 extern void mac_drv_clear_rx_queue(struct s_smc *smc);
0149 extern void enable_tx_irq(struct s_smc *smc, u_short queue);
0150 
0151 static const struct pci_device_id skfddi_pci_tbl[] = {
0152     { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
0153     { }         /* Terminating entry */
0154 };
0155 MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
0156 MODULE_LICENSE("GPL");
0157 MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
0158 
0159 // Define module-wide (static) variables
0160 
0161 static int num_boards;  /* total number of adapters configured */
0162 
0163 static const struct net_device_ops skfp_netdev_ops = {
0164     .ndo_open       = skfp_open,
0165     .ndo_stop       = skfp_close,
0166     .ndo_start_xmit     = skfp_send_pkt,
0167     .ndo_get_stats      = skfp_ctl_get_stats,
0168     .ndo_set_rx_mode    = skfp_ctl_set_multicast_list,
0169     .ndo_set_mac_address    = skfp_ctl_set_mac_address,
0170     .ndo_siocdevprivate = skfp_siocdevprivate,
0171 };
0172 
0173 /*
0174  * =================
0175  * = skfp_init_one =
0176  * =================
0177  *   
0178  * Overview:
0179  *   Probes for supported FDDI PCI controllers
0180  *  
0181  * Returns:
0182  *   Condition code
0183  *       
0184  * Arguments:
0185  *   pdev - pointer to PCI device information
0186  *
0187  * Functional Description:
0188  *   This is now called by PCI driver registration process
0189  *   for each board found.
0190  *   
0191  * Return Codes:
0192  *   0           - This device (fddi0, fddi1, etc) configured successfully
0193  *   -ENODEV - No devices present, or no SysKonnect FDDI PCI device
0194  *                         present for this device name
0195  *
0196  *
0197  * Side Effects:
0198  *   Device structures for FDDI adapters (fddi0, fddi1, etc) are
0199  *   initialized and the board resources are read and stored in
0200  *   the device structure.
0201  */
0202 static int skfp_init_one(struct pci_dev *pdev,
0203                 const struct pci_device_id *ent)
0204 {
0205     struct net_device *dev;
0206     struct s_smc *smc;  /* board pointer */
0207     void __iomem *mem;
0208     int err;
0209 
0210     pr_debug("entering skfp_init_one\n");
0211 
0212     if (num_boards == 0) 
0213         printk("%s\n", boot_msg);
0214 
0215     err = pci_enable_device(pdev);
0216     if (err)
0217         return err;
0218 
0219     err = pci_request_regions(pdev, "skfddi");
0220     if (err)
0221         goto err_out1;
0222 
0223     pci_set_master(pdev);
0224 
0225 #ifdef MEM_MAPPED_IO
0226     if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
0227         printk(KERN_ERR "skfp: region is not an MMIO resource\n");
0228         err = -EIO;
0229         goto err_out2;
0230     }
0231 
0232     mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
0233 #else
0234     if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
0235         printk(KERN_ERR "skfp: region is not PIO resource\n");
0236         err = -EIO;
0237         goto err_out2;
0238     }
0239 
0240     mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
0241 #endif
0242     if (!mem) {
0243         printk(KERN_ERR "skfp:  Unable to map register, "
0244                 "FDDI adapter will be disabled.\n");
0245         err = -EIO;
0246         goto err_out2;
0247     }
0248 
0249     dev = alloc_fddidev(sizeof(struct s_smc));
0250     if (!dev) {
0251         printk(KERN_ERR "skfp: Unable to allocate fddi device, "
0252                 "FDDI adapter will be disabled.\n");
0253         err = -ENOMEM;
0254         goto err_out3;
0255     }
0256 
0257     dev->irq = pdev->irq;
0258     dev->netdev_ops = &skfp_netdev_ops;
0259 
0260     SET_NETDEV_DEV(dev, &pdev->dev);
0261 
0262     /* Initialize board structure with bus-specific info */
0263     smc = netdev_priv(dev);
0264     smc->os.dev = dev;
0265     smc->os.bus_type = SK_BUS_TYPE_PCI;
0266     smc->os.pdev = *pdev;
0267     smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
0268     smc->os.MaxFrameSize = MAX_FRAME_SIZE;
0269     smc->os.dev = dev;
0270     smc->hw.slot = -1;
0271     smc->hw.iop = mem;
0272     smc->os.ResetRequested = FALSE;
0273     skb_queue_head_init(&smc->os.SendSkbQueue);
0274 
0275     dev->base_addr = (unsigned long)mem;
0276 
0277     err = skfp_driver_init(dev);
0278     if (err)
0279         goto err_out4;
0280 
0281     err = register_netdev(dev);
0282     if (err)
0283         goto err_out5;
0284 
0285     ++num_boards;
0286     pci_set_drvdata(pdev, dev);
0287 
0288     if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
0289         (pdev->subsystem_device & 0xff00) == 0x5800) 
0290         printk("%s: SysKonnect FDDI PCI adapter"
0291                " found (SK-%04X)\n", dev->name, 
0292                pdev->subsystem_device);
0293     else
0294         printk("%s: FDDI PCI adapter found\n", dev->name);
0295 
0296     return 0;
0297 err_out5:
0298     if (smc->os.SharedMemAddr) 
0299         dma_free_coherent(&pdev->dev, smc->os.SharedMemSize,
0300                   smc->os.SharedMemAddr,
0301                   smc->os.SharedMemDMA);
0302     dma_free_coherent(&pdev->dev, MAX_FRAME_SIZE,
0303               smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
0304 err_out4:
0305     free_netdev(dev);
0306 err_out3:
0307 #ifdef MEM_MAPPED_IO
0308     iounmap(mem);
0309 #else
0310     ioport_unmap(mem);
0311 #endif
0312 err_out2:
0313     pci_release_regions(pdev);
0314 err_out1:
0315     pci_disable_device(pdev);
0316     return err;
0317 }
0318 
0319 /*
0320  * Called for each adapter board from pci_unregister_driver
0321  */
0322 static void skfp_remove_one(struct pci_dev *pdev)
0323 {
0324     struct net_device *p = pci_get_drvdata(pdev);
0325     struct s_smc *lp = netdev_priv(p);
0326 
0327     unregister_netdev(p);
0328 
0329     if (lp->os.SharedMemAddr) {
0330         dma_free_coherent(&pdev->dev,
0331                   lp->os.SharedMemSize,
0332                   lp->os.SharedMemAddr,
0333                   lp->os.SharedMemDMA);
0334         lp->os.SharedMemAddr = NULL;
0335     }
0336     if (lp->os.LocalRxBuffer) {
0337         dma_free_coherent(&pdev->dev,
0338                   MAX_FRAME_SIZE,
0339                   lp->os.LocalRxBuffer,
0340                   lp->os.LocalRxBufferDMA);
0341         lp->os.LocalRxBuffer = NULL;
0342     }
0343 #ifdef MEM_MAPPED_IO
0344     iounmap(lp->hw.iop);
0345 #else
0346     ioport_unmap(lp->hw.iop);
0347 #endif
0348     pci_release_regions(pdev);
0349     free_netdev(p);
0350 
0351     pci_disable_device(pdev);
0352 }
0353 
0354 /*
0355  * ====================
0356  * = skfp_driver_init =
0357  * ====================
0358  *   
0359  * Overview:
0360  *   Initializes remaining adapter board structure information
0361  *   and makes sure adapter is in a safe state prior to skfp_open().
0362  *  
0363  * Returns:
0364  *   Condition code
0365  *       
0366  * Arguments:
0367  *   dev - pointer to device information
0368  *
0369  * Functional Description:
0370  *   This function allocates additional resources such as the host memory
0371  *   blocks needed by the adapter.
0372  *   The adapter is also reset. The OS must call skfp_open() to open 
0373  *   the adapter and bring it on-line.
0374  *
0375  * Return Codes:
0376  *    0 - initialization succeeded
0377  *   -1 - initialization failed
0378  */
0379 static  int skfp_driver_init(struct net_device *dev)
0380 {
0381     struct s_smc *smc = netdev_priv(dev);
0382     skfddi_priv *bp = &smc->os;
0383     int err = -EIO;
0384 
0385     pr_debug("entering skfp_driver_init\n");
0386 
0387     // set the io address in private structures
0388     bp->base_addr = dev->base_addr;
0389 
0390     // Get the interrupt level from the PCI Configuration Table
0391     smc->hw.irq = dev->irq;
0392 
0393     spin_lock_init(&bp->DriverLock);
0394     
0395     // Allocate invalid frame
0396     bp->LocalRxBuffer = dma_alloc_coherent(&bp->pdev.dev, MAX_FRAME_SIZE,
0397                            &bp->LocalRxBufferDMA,
0398                            GFP_ATOMIC);
0399     if (!bp->LocalRxBuffer) {
0400         printk("could not allocate mem for ");
0401         printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
0402         goto fail;
0403     }
0404 
0405     // Determine the required size of the 'shared' memory area.
0406     bp->SharedMemSize = mac_drv_check_space();
0407     pr_debug("Memory for HWM: %ld\n", bp->SharedMemSize);
0408     if (bp->SharedMemSize > 0) {
0409         bp->SharedMemSize += 16;    // for descriptor alignment
0410 
0411         bp->SharedMemAddr = dma_alloc_coherent(&bp->pdev.dev,
0412                                bp->SharedMemSize,
0413                                &bp->SharedMemDMA,
0414                                GFP_ATOMIC);
0415         if (!bp->SharedMemAddr) {
0416             printk("could not allocate mem for ");
0417             printk("hardware module: %ld byte\n",
0418                    bp->SharedMemSize);
0419             goto fail;
0420         }
0421 
0422     } else {
0423         bp->SharedMemAddr = NULL;
0424     }
0425 
0426     bp->SharedMemHeap = 0;
0427 
0428     card_stop(smc);     // Reset adapter.
0429 
0430     pr_debug("mac_drv_init()..\n");
0431     if (mac_drv_init(smc) != 0) {
0432         pr_debug("mac_drv_init() failed\n");
0433         goto fail;
0434     }
0435     read_address(smc, NULL);
0436     pr_debug("HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
0437     eth_hw_addr_set(dev, smc->hw.fddi_canon_addr.a);
0438 
0439     smt_reset_defaults(smc, 0);
0440 
0441     return 0;
0442 
0443 fail:
0444     if (bp->SharedMemAddr) {
0445         dma_free_coherent(&bp->pdev.dev,
0446                   bp->SharedMemSize,
0447                   bp->SharedMemAddr,
0448                   bp->SharedMemDMA);
0449         bp->SharedMemAddr = NULL;
0450     }
0451     if (bp->LocalRxBuffer) {
0452         dma_free_coherent(&bp->pdev.dev, MAX_FRAME_SIZE,
0453                   bp->LocalRxBuffer, bp->LocalRxBufferDMA);
0454         bp->LocalRxBuffer = NULL;
0455     }
0456     return err;
0457 }               // skfp_driver_init
0458 
0459 
0460 /*
0461  * =============
0462  * = skfp_open =
0463  * =============
0464  *   
0465  * Overview:
0466  *   Opens the adapter
0467  *  
0468  * Returns:
0469  *   Condition code
0470  *       
0471  * Arguments:
0472  *   dev - pointer to device information
0473  *
0474  * Functional Description:
0475  *   This function brings the adapter to an operational state.
0476  *
0477  * Return Codes:
0478  *   0           - Adapter was successfully opened
0479  *   -EAGAIN - Could not register IRQ
0480  */
0481 static int skfp_open(struct net_device *dev)
0482 {
0483     struct s_smc *smc = netdev_priv(dev);
0484     int err;
0485 
0486     pr_debug("entering skfp_open\n");
0487     /* Register IRQ - support shared interrupts by passing device ptr */
0488     err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
0489               dev->name, dev);
0490     if (err)
0491         return err;
0492 
0493     /*
0494      * Set current address to factory MAC address
0495      *
0496      * Note: We've already done this step in skfp_driver_init.
0497      *       However, it's possible that a user has set a node
0498      *               address override, then closed and reopened the
0499      *               adapter.  Unless we reset the device address field
0500      *               now, we'll continue to use the existing modified
0501      *               address.
0502      */
0503     read_address(smc, NULL);
0504     eth_hw_addr_set(dev, smc->hw.fddi_canon_addr.a);
0505 
0506     init_smt(smc, NULL);
0507     smt_online(smc, 1);
0508     STI_FBI();
0509 
0510     /* Clear local multicast address tables */
0511     mac_clear_multicast(smc);
0512 
0513     /* Disable promiscuous filter settings */
0514     mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
0515 
0516     netif_start_queue(dev);
0517     return 0;
0518 }               // skfp_open
0519 
0520 
0521 /*
0522  * ==============
0523  * = skfp_close =
0524  * ==============
0525  *   
0526  * Overview:
0527  *   Closes the device/module.
0528  *  
0529  * Returns:
0530  *   Condition code
0531  *       
0532  * Arguments:
0533  *   dev - pointer to device information
0534  *
0535  * Functional Description:
0536  *   This routine closes the adapter and brings it to a safe state.
0537  *   The interrupt service routine is deregistered with the OS.
0538  *   The adapter can be opened again with another call to skfp_open().
0539  *
0540  * Return Codes:
0541  *   Always return 0.
0542  *
0543  * Assumptions:
0544  *   No further requests for this adapter are made after this routine is
0545  *   called.  skfp_open() can be called to reset and reinitialize the
0546  *   adapter.
0547  */
0548 static int skfp_close(struct net_device *dev)
0549 {
0550     struct s_smc *smc = netdev_priv(dev);
0551     skfddi_priv *bp = &smc->os;
0552 
0553     CLI_FBI();
0554     smt_reset_defaults(smc, 1);
0555     card_stop(smc);
0556     mac_drv_clear_tx_queue(smc);
0557     mac_drv_clear_rx_queue(smc);
0558 
0559     netif_stop_queue(dev);
0560     /* Deregister (free) IRQ */
0561     free_irq(dev->irq, dev);
0562 
0563     skb_queue_purge(&bp->SendSkbQueue);
0564     bp->QueueSkb = MAX_TX_QUEUE_LEN;
0565 
0566     return 0;
0567 }               // skfp_close
0568 
0569 
0570 /*
0571  * ==================
0572  * = skfp_interrupt =
0573  * ==================
0574  *   
0575  * Overview:
0576  *   Interrupt processing routine
0577  *  
0578  * Returns:
0579  *   None
0580  *       
0581  * Arguments:
0582  *   irq        - interrupt vector
0583  *   dev_id     - pointer to device information
0584  *
0585  * Functional Description:
0586  *   This routine calls the interrupt processing routine for this adapter.  It
0587  *   disables and reenables adapter interrupts, as appropriate.  We can support
0588  *   shared interrupts since the incoming dev_id pointer provides our device
0589  *   structure context. All the real work is done in the hardware module.
0590  *
0591  * Return Codes:
0592  *   None
0593  *
0594  * Assumptions:
0595  *   The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
0596  *   on Intel-based systems) is done by the operating system outside this
0597  *   routine.
0598  *
0599  *       System interrupts are enabled through this call.
0600  *
0601  * Side Effects:
0602  *   Interrupts are disabled, then reenabled at the adapter.
0603  */
0604 
0605 static irqreturn_t skfp_interrupt(int irq, void *dev_id)
0606 {
0607     struct net_device *dev = dev_id;
0608     struct s_smc *smc;  /* private board structure pointer */
0609     skfddi_priv *bp;
0610 
0611     smc = netdev_priv(dev);
0612     bp = &smc->os;
0613 
0614     // IRQs enabled or disabled ?
0615     if (inpd(ADDR(B0_IMSK)) == 0) {
0616         // IRQs are disabled: must be shared interrupt
0617         return IRQ_NONE;
0618     }
0619     // Note: At this point, IRQs are enabled.
0620     if ((inpd(ISR_A) & smc->hw.is_imask) == 0) {    // IRQ?
0621         // Adapter did not issue an IRQ: must be shared interrupt
0622         return IRQ_NONE;
0623     }
0624     CLI_FBI();      // Disable IRQs from our adapter.
0625     spin_lock(&bp->DriverLock);
0626 
0627     // Call interrupt handler in hardware module (HWM).
0628     fddi_isr(smc);
0629 
0630     if (smc->os.ResetRequested) {
0631         ResetAdapter(smc);
0632         smc->os.ResetRequested = FALSE;
0633     }
0634     spin_unlock(&bp->DriverLock);
0635     STI_FBI();      // Enable IRQs from our adapter.
0636 
0637     return IRQ_HANDLED;
0638 }               // skfp_interrupt
0639 
0640 
0641 /*
0642  * ======================
0643  * = skfp_ctl_get_stats =
0644  * ======================
0645  *   
0646  * Overview:
0647  *   Get statistics for FDDI adapter
0648  *  
0649  * Returns:
0650  *   Pointer to FDDI statistics structure
0651  *       
0652  * Arguments:
0653  *   dev - pointer to device information
0654  *
0655  * Functional Description:
0656  *   Gets current MIB objects from adapter, then
0657  *   returns FDDI statistics structure as defined
0658  *   in if_fddi.h.
0659  *
0660  *   Note: Since the FDDI statistics structure is
0661  *   still new and the device structure doesn't
0662  *   have an FDDI-specific get statistics handler,
0663  *   we'll return the FDDI statistics structure as
0664  *   a pointer to an Ethernet statistics structure.
0665  *   That way, at least the first part of the statistics
0666  *   structure can be decoded properly.
0667  *   We'll have to pay attention to this routine as the
0668  *   device structure becomes more mature and LAN media
0669  *   independent.
0670  *
0671  */
0672 static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
0673 {
0674     struct s_smc *bp = netdev_priv(dev);
0675 
0676     /* Fill the bp->stats structure with driver-maintained counters */
0677 
0678     bp->os.MacStat.port_bs_flag[0] = 0x1234;
0679     bp->os.MacStat.port_bs_flag[1] = 0x5678;
0680 // goos: need to fill out fddi statistic
0681 #if 0
0682     /* Get FDDI SMT MIB objects */
0683 
0684 /* Fill the bp->stats structure with the SMT MIB object values */
0685 
0686     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));
0687     bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
0688     bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
0689     bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
0690     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));
0691     bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
0692     bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
0693     bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
0694     bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
0695     bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
0696     bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
0697     bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
0698     bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
0699     bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
0700     bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
0701     bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
0702     bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
0703     bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
0704     bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
0705     bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
0706     bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
0707     bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
0708     bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
0709     bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
0710     bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
0711     bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
0712     bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
0713     bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
0714     bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
0715     memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
0716     memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
0717     memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
0718     memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
0719     bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
0720     bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
0721     bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
0722     memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
0723     bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
0724     bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
0725     bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
0726     bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
0727     bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
0728     bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
0729     bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
0730     bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
0731     bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
0732     bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
0733     bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
0734     bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
0735     bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
0736     bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
0737     bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
0738     bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
0739     memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
0740     bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
0741     bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
0742     bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
0743     bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
0744     bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
0745     bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
0746     bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
0747     bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
0748     bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
0749     bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
0750     memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
0751     memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
0752     bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
0753     bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
0754     bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
0755     bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
0756     bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
0757     bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
0758     bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
0759     bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
0760     bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
0761     bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
0762     bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
0763     bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
0764     bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
0765     bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
0766     bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
0767     bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
0768     bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
0769     bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
0770     bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
0771     bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
0772     bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
0773     bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
0774     bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
0775     bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
0776     bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
0777     bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
0778 
0779 
0780     /* Fill the bp->stats structure with the FDDI counter values */
0781 
0782     bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
0783     bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
0784     bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
0785     bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
0786     bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
0787     bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
0788     bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
0789     bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
0790     bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
0791     bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
0792     bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
0793 
0794 #endif
0795     return (struct net_device_stats *)&bp->os.MacStat;
0796 }               // ctl_get_stat
0797 
0798 
0799 /*
0800  * ==============================
0801  * = skfp_ctl_set_multicast_list =
0802  * ==============================
0803  *   
0804  * Overview:
0805  *   Enable/Disable LLC frame promiscuous mode reception
0806  *   on the adapter and/or update multicast address table.
0807  *  
0808  * Returns:
0809  *   None
0810  *       
0811  * Arguments:
0812  *   dev - pointer to device information
0813  *
0814  * Functional Description:
0815  *   This function acquires the driver lock and only calls
0816  *   skfp_ctl_set_multicast_list_wo_lock then.
0817  *   This routine follows a fairly simple algorithm for setting the
0818  *   adapter filters and CAM:
0819  *
0820  *      if IFF_PROMISC flag is set
0821  *              enable promiscuous mode
0822  *      else
0823  *              disable promiscuous mode
0824  *              if number of multicast addresses <= max. multicast number
0825  *                      add mc addresses to adapter table
0826  *              else
0827  *                      enable promiscuous mode
0828  *              update adapter filters
0829  *
0830  * Assumptions:
0831  *   Multicast addresses are presented in canonical (LSB) format.
0832  *
0833  * Side Effects:
0834  *   On-board adapter filters are updated.
0835  */
0836 static void skfp_ctl_set_multicast_list(struct net_device *dev)
0837 {
0838     struct s_smc *smc = netdev_priv(dev);
0839     skfddi_priv *bp = &smc->os;
0840     unsigned long Flags;
0841 
0842     spin_lock_irqsave(&bp->DriverLock, Flags);
0843     skfp_ctl_set_multicast_list_wo_lock(dev);
0844     spin_unlock_irqrestore(&bp->DriverLock, Flags);
0845 }               // skfp_ctl_set_multicast_list
0846 
0847 
0848 
0849 static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
0850 {
0851     struct s_smc *smc = netdev_priv(dev);
0852     struct netdev_hw_addr *ha;
0853 
0854     /* Enable promiscuous mode, if necessary */
0855     if (dev->flags & IFF_PROMISC) {
0856         mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
0857         pr_debug("PROMISCUOUS MODE ENABLED\n");
0858     }
0859     /* Else, update multicast address table */
0860     else {
0861         mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
0862         pr_debug("PROMISCUOUS MODE DISABLED\n");
0863 
0864         // Reset all MC addresses
0865         mac_clear_multicast(smc);
0866         mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
0867 
0868         if (dev->flags & IFF_ALLMULTI) {
0869             mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
0870             pr_debug("ENABLE ALL MC ADDRESSES\n");
0871         } else if (!netdev_mc_empty(dev)) {
0872             if (netdev_mc_count(dev) <= FPMAX_MULTICAST) {
0873                 /* use exact filtering */
0874 
0875                 // point to first multicast addr
0876                 netdev_for_each_mc_addr(ha, dev) {
0877                     mac_add_multicast(smc,
0878                         (struct fddi_addr *)ha->addr,
0879                         1);
0880 
0881                     pr_debug("ENABLE MC ADDRESS: %pMF\n",
0882                          ha->addr);
0883                 }
0884 
0885             } else {    // more MC addresses than HW supports
0886 
0887                 mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
0888                 pr_debug("ENABLE ALL MC ADDRESSES\n");
0889             }
0890         } else {    // no MC addresses
0891 
0892             pr_debug("DISABLE ALL MC ADDRESSES\n");
0893         }
0894 
0895         /* Update adapter filters */
0896         mac_update_multicast(smc);
0897     }
0898 }               // skfp_ctl_set_multicast_list_wo_lock
0899 
0900 
0901 /*
0902  * ===========================
0903  * = skfp_ctl_set_mac_address =
0904  * ===========================
0905  *   
0906  * Overview:
0907  *   set new mac address on adapter and update dev_addr field in device table.
0908  *  
0909  * Returns:
0910  *   None
0911  *       
0912  * Arguments:
0913  *   dev  - pointer to device information
0914  *   addr - pointer to sockaddr structure containing unicast address to set
0915  *
0916  * Assumptions:
0917  *   The address pointed to by addr->sa_data is a valid unicast
0918  *   address and is presented in canonical (LSB) format.
0919  */
0920 static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
0921 {
0922     struct s_smc *smc = netdev_priv(dev);
0923     struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
0924     skfddi_priv *bp = &smc->os;
0925     unsigned long Flags;
0926 
0927 
0928     dev_addr_set(dev, p_sockaddr->sa_data);
0929     spin_lock_irqsave(&bp->DriverLock, Flags);
0930     ResetAdapter(smc);
0931     spin_unlock_irqrestore(&bp->DriverLock, Flags);
0932 
0933     return 0;       /* always return zero */
0934 }               // skfp_ctl_set_mac_address
0935 
0936 
0937 /*
0938  * =======================
0939  * = skfp_siocdevprivate =
0940  * =======================
0941  *   
0942  * Overview:
0943  *
0944  * Perform IOCTL call functions here. Some are privileged operations and the
0945  * effective uid is checked in those cases.
0946  *  
0947  * Returns:
0948  *   status value
0949  *   0 - success
0950  *   other - failure
0951  *       
0952  * Arguments:
0953  *   dev  - pointer to device information
0954  *   rq - pointer to ioctl request structure
0955  *   cmd - ?
0956  *
0957  */
0958 
0959 
0960 static int skfp_siocdevprivate(struct net_device *dev, struct ifreq *rq, void __user *data, int cmd)
0961 {
0962     struct s_smc *smc = netdev_priv(dev);
0963     skfddi_priv *lp = &smc->os;
0964     struct s_skfp_ioctl ioc;
0965     int status = 0;
0966 
0967     if (copy_from_user(&ioc, data, sizeof(struct s_skfp_ioctl)))
0968         return -EFAULT;
0969 
0970     if (in_compat_syscall())
0971         return -EOPNOTSUPP;
0972 
0973     switch (ioc.cmd) {
0974     case SKFP_GET_STATS:    /* Get the driver statistics */
0975         ioc.len = sizeof(lp->MacStat);
0976         status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
0977                 ? -EFAULT : 0;
0978         break;
0979     case SKFP_CLR_STATS:    /* Zero out the driver statistics */
0980         if (!capable(CAP_NET_ADMIN)) {
0981             status = -EPERM;
0982         } else {
0983             memset(&lp->MacStat, 0, sizeof(lp->MacStat));
0984         }
0985         break;
0986     default:
0987         printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd);
0988         status = -EOPNOTSUPP;
0989 
0990     }           // switch
0991 
0992     return status;
0993 }               // skfp_ioctl
0994 
0995 
0996 /*
0997  * =====================
0998  * = skfp_send_pkt     =
0999  * =====================
1000  *   
1001  * Overview:
1002  *   Queues a packet for transmission and try to transmit it.
1003  *  
1004  * Returns:
1005  *   Condition code
1006  *       
1007  * Arguments:
1008  *   skb - pointer to sk_buff to queue for transmission
1009  *   dev - pointer to device information
1010  *
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().
1017  *
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.
1021  *
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.
1025  *
1026  * Return Codes:
1027  *   0 - driver has queued and/or sent packet
1028  *       1 - caller should requeue the sk_buff for later transmission
1029  *
1030  * Assumptions:
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.
1034  *
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
1038  *   different thread.
1039  *
1040  * Side Effects:
1041  *   None
1042  */
1043 static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
1044                        struct net_device *dev)
1045 {
1046     struct s_smc *smc = netdev_priv(dev);
1047     skfddi_priv *bp = &smc->os;
1048 
1049     pr_debug("skfp_send_pkt\n");
1050 
1051     /*
1052      * Verify that incoming transmit request is OK
1053      *
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
1057      *               transmit routine.
1058      */
1059 
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);
1064         dev_kfree_skb(skb);
1065         return NETDEV_TX_OK;    /* return "success" */
1066     }
1067     if (bp->QueueSkb == 0) {    // return with tbusy set: queue full
1068 
1069         netif_stop_queue(dev);
1070         return NETDEV_TX_BUSY;
1071     }
1072     bp->QueueSkb--;
1073     skb_queue_tail(&bp->SendSkbQueue, skb);
1074     send_queued_packets(netdev_priv(dev));
1075     if (bp->QueueSkb == 0) {
1076         netif_stop_queue(dev);
1077     }
1078     return NETDEV_TX_OK;
1079 
1080 }               // skfp_send_pkt
1081 
1082 
1083 /*
1084  * =======================
1085  * = send_queued_packets =
1086  * =======================
1087  *   
1088  * Overview:
1089  *   Send packets from the driver queue as long as there are some and
1090  *   transmit resources are available.
1091  *  
1092  * Returns:
1093  *   None
1094  *       
1095  * Arguments:
1096  *   smc - pointer to smc (adapter) structure
1097  *
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
1101  *   and exit. 
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).
1105  */
1106 static void send_queued_packets(struct s_smc *smc)
1107 {
1108     skfddi_priv *bp = &smc->os;
1109     struct sk_buff *skb;
1110     unsigned char fc;
1111     int queue;
1112     struct s_smt_fp_txd *txd;   // Current TxD.
1113     dma_addr_t dma_address;
1114     unsigned long Flags;
1115 
1116     int frame_status;   // HWM tx frame status.
1117 
1118     pr_debug("send queued packets\n");
1119     for (;;) {
1120         // send first buffer from queue
1121         skb = skb_dequeue(&bp->SendSkbQueue);
1122 
1123         if (!skb) {
1124             pr_debug("queue empty\n");
1125             return;
1126         }       // queue empty !
1127 
1128         spin_lock_irqsave(&bp->DriverLock, Flags);
1129         fc = skb->data[0];
1130         queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
1131 #ifdef ESS
1132         // Check if the frame may/must be sent as a synchronous frame.
1133 
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.
1138 
1139             else {  // Bandwidth is available.
1140 
1141                 if (smc->mib.fddiESSSynchTxMode) {
1142                     // Send as sync. frame.
1143                     fc |= FC_SYNC_BIT;
1144                 }
1145             }
1146         }
1147 #endif              // ESS
1148         frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
1149 
1150         if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
1151             // Unable to send the frame.
1152 
1153             if ((frame_status & RING_DOWN) != 0) {
1154                 // Ring is down.
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);
1158             } else {
1159                 pr_debug("%s: out of transmit resources",
1160                     bp->dev->name);
1161             }
1162 
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.
1168 
1169         }       // if (unable to send frame)
1170 
1171         bp->QueueSkb++; // one packet less in local queue
1172 
1173         // source address in packet ?
1174         CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
1175 
1176         txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
1177 
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
1183         }
1184         hwm_tx_frag(smc, skb->data, dma_address, skb->len,
1185                       frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
1186 
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);
1191         }
1192         spin_unlock_irqrestore(&bp->DriverLock, Flags);
1193     }           // for
1194 
1195     return;         // never reached
1196 
1197 }               // send_queued_packets
1198 
1199 
1200 /************************
1201  * 
1202  * CheckSourceAddress
1203  *
1204  * Verify if the source address is set. Insert it if necessary.
1205  *
1206  ************************/
1207 static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
1208 {
1209     unsigned char SRBit;
1210 
1211     if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
1212 
1213         return;
1214     if ((unsigned short) frame[1 + 10] != 0)
1215         return;
1216     SRBit = frame[1 + 6] & 0x01;
1217     memcpy(&frame[1 + 6], hw_addr, ETH_ALEN);
1218     frame[8] |= SRBit;
1219 }               // CheckSourceAddress
1220 
1221 
1222 /************************
1223  *
1224  *  ResetAdapter
1225  *
1226  *  Reset the adapter and bring it back to operational mode.
1227  * Args
1228  *  smc - A pointer to the SMT context struct.
1229  * Out
1230  *  Nothing.
1231  *
1232  ************************/
1233 static void ResetAdapter(struct s_smc *smc)
1234 {
1235 
1236     pr_debug("[fddi: ResetAdapter]\n");
1237 
1238     // Stop the adapter.
1239 
1240     card_stop(smc);     // Stop all activity.
1241 
1242     // Clear the transmit and receive descriptor queues.
1243     mac_drv_clear_tx_queue(smc);
1244     mac_drv_clear_rx_queue(smc);
1245 
1246     // Restart the adapter.
1247 
1248     smt_reset_defaults(smc, 1); // Initialize the SMT module.
1249 
1250     init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
1251 
1252     smt_online(smc, 1); // Insert into the ring again.
1253     STI_FBI();
1254 
1255     // Restore original receive mode (multicasts, promiscuous, etc.).
1256     skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
1257 }               // ResetAdapter
1258 
1259 
1260 //--------------- functions called by hardware module ----------------
1261 
1262 /************************
1263  *
1264  *  llc_restart_tx
1265  *
1266  *  The hardware driver calls this routine when the transmit complete
1267  *  interrupt bits (end of frame) for the synchronous or asynchronous
1268  *  queue is set.
1269  *
1270  * NOTE The hardware driver calls this function also if no packets are queued.
1271  *  The routine must be able to handle this case.
1272  * Args
1273  *  smc - A pointer to the SMT context struct.
1274  * Out
1275  *  Nothing.
1276  *
1277  ************************/
1278 void llc_restart_tx(struct s_smc *smc)
1279 {
1280     skfddi_priv *bp = &smc->os;
1281 
1282     pr_debug("[llc_restart_tx]\n");
1283 
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
1289 
1290 }               // llc_restart_tx
1291 
1292 
1293 /************************
1294  *
1295  *  mac_drv_get_space
1296  *
1297  *  The hardware module calls this function to allocate the memory
1298  *  for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
1299  * Args
1300  *  smc - A pointer to the SMT context struct.
1301  *
1302  *  size - Size of memory in bytes to allocate.
1303  * Out
1304  *  != 0    A pointer to the virtual address of the allocated memory.
1305  *  == 0    Allocation error.
1306  *
1307  ************************/
1308 void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
1309 {
1310     void *virt;
1311 
1312     pr_debug("mac_drv_get_space (%d bytes), ", size);
1313     virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
1314 
1315     if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
1316         printk("Unexpected SMT memory size requested: %d\n", size);
1317         return NULL;
1318     }
1319     smc->os.SharedMemHeap += size;  // Move heap pointer.
1320 
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)));
1326     return virt;
1327 }               // mac_drv_get_space
1328 
1329 
1330 /************************
1331  *
1332  *  mac_drv_get_desc_mem
1333  *
1334  *  This function is called by the hardware dependent module.
1335  *  It allocates the memory for the RxD and TxD descriptors.
1336  *
1337  *  This memory must be non-cached, non-movable and non-swappable.
1338  *  This memory should start at a physical page boundary.
1339  * Args
1340  *  smc - A pointer to the SMT context struct.
1341  *
1342  *  size - Size of memory in bytes to allocate.
1343  * Out
1344  *  != 0    A pointer to the virtual address of the allocated memory.
1345  *  == 0    Allocation error.
1346  *
1347  ************************/
1348 void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
1349 {
1350 
1351     char *virt;
1352 
1353     pr_debug("mac_drv_get_desc_mem\n");
1354 
1355     // Descriptor memory must be aligned on 16-byte boundary.
1356 
1357     virt = mac_drv_get_space(smc, size);
1358 
1359     size = (u_int) (16 - (((unsigned long) virt) & 15UL));
1360     size = size % 16;
1361 
1362     pr_debug("Allocate %u bytes alignment gap ", size);
1363     pr_debug("for descriptor memory.\n");
1364 
1365     if (!mac_drv_get_space(smc, size)) {
1366         printk("fddi: Unable to align descriptor memory.\n");
1367         return NULL;
1368     }
1369     return virt + size;
1370 }               // mac_drv_get_desc_mem
1371 
1372 
1373 /************************
1374  *
1375  *  mac_drv_virt2phys
1376  *
1377  *  Get the physical address of a given virtual address.
1378  * Args
1379  *  smc - A pointer to the SMT context struct.
1380  *
1381  *  virt - A (virtual) pointer into our 'shared' memory area.
1382  * Out
1383  *  Physical address of the given virtual address.
1384  *
1385  ************************/
1386 unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
1387 {
1388     return smc->os.SharedMemDMA +
1389         ((char *) virt - (char *)smc->os.SharedMemAddr);
1390 }               // mac_drv_virt2phys
1391 
1392 
1393 /************************
1394  *
1395  *  dma_master
1396  *
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.
1400  *
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.
1404  * Args
1405  *  smc - A pointer to the SMT context struct.
1406  *
1407  *  virt - The virtual address of the data.
1408  *
1409  *  len - The length in bytes of the data.
1410  *
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
1415  *
1416  *  >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
1417  * Out
1418  *  Returns the pyhsical address for the DMA transfer.
1419  *
1420  ************************/
1421 u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
1422 {
1423     return smc->os.SharedMemDMA +
1424         ((char *) virt - (char *)smc->os.SharedMemAddr);
1425 }               // dma_master
1426 
1427 
1428 /************************
1429  *
1430  *  dma_complete
1431  *
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
1435  *  the DMA channel.
1436  * Args
1437  *  smc - A pointer to the SMT context struct.
1438  *
1439  *  descr - A pointer to a TxD or RxD, respectively.
1440  *
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)
1445  * Out
1446  *  Nothing.
1447  *
1448  ************************/
1449 void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
1450 {
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
1456      * below.
1457      *
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.
1462      */
1463     if (flag & DMA_WR) {
1464         skfddi_priv *bp = &smc->os;
1465         volatile struct s_smt_fp_rxd *r = &descr->r;
1466 
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;
1470 
1471             dma_unmap_single(&(&bp->pdev)->dev,
1472                      r->rxd_os.dma_addr, MaxFrameSize,
1473                      DMA_FROM_DEVICE);
1474             r->rxd_os.dma_addr = 0;
1475         }
1476     }
1477 }               // dma_complete
1478 
1479 
1480 /************************
1481  *
1482  *  mac_drv_tx_complete
1483  *
1484  *  Transmit of a packet is complete. Release the tx staging buffer.
1485  *
1486  * Args
1487  *  smc - A pointer to the SMT context struct.
1488  *
1489  *  txd - A pointer to the last TxD which is used by the frame.
1490  * Out
1491  *  Returns nothing.
1492  *
1493  ************************/
1494 void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
1495 {
1496     struct sk_buff *skb;
1497 
1498     pr_debug("entering mac_drv_tx_complete\n");
1499     // Check if this TxD points to a skb
1500 
1501     if (!(skb = txd->txd_os.skb)) {
1502         pr_debug("TXD with no skb assigned.\n");
1503         return;
1504     }
1505     txd->txd_os.skb = NULL;
1506 
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;
1511 
1512     smc->os.MacStat.gen.tx_packets++;   // Count transmitted packets.
1513     smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
1514 
1515     // free the skb
1516     dev_kfree_skb_irq(skb);
1517 
1518     pr_debug("leaving mac_drv_tx_complete\n");
1519 }               // mac_drv_tx_complete
1520 
1521 
1522 /************************
1523  *
1524  * dump packets to logfile
1525  *
1526  ************************/
1527 #ifdef DUMPPACKETS
1528 void dump_data(unsigned char *Data, int length)
1529 {
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");
1533 }               // dump_data
1534 #else
1535 #define dump_data(data,len)
1536 #endif              // DUMPPACKETS
1537 
1538 /************************
1539  *
1540  *  mac_drv_rx_complete
1541  *
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.
1546  *
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.
1550  * Args
1551  *  smc - A pointer to the SMT context struct.
1552  *
1553  *  rxd - A pointer to the first RxD which is used by the receive frame.
1554  *
1555  *  frag_count - Count of RxDs used by the received frame.
1556  *
1557  *  len - Frame length.
1558  * Out
1559  *  Nothing.
1560  *
1561  ************************/
1562 void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1563              int frag_count, int len)
1564 {
1565     skfddi_priv *bp = &smc->os;
1566     struct sk_buff *skb;
1567     unsigned char *virt, *cp;
1568     unsigned short ri;
1569     u_int RifLength;
1570 
1571     pr_debug("entering mac_drv_rx_complete (len=%d)\n", len);
1572     if (frag_count != 1) {  // This is not allowed to happen.
1573 
1574         printk("fddi: Multi-fragment receive!\n");
1575         goto RequeueRxd;    // Re-use the given RXD(s).
1576 
1577     }
1578     skb = rxd->rxd_os.skb;
1579     if (!skb) {
1580         pr_debug("No skb in rxd\n");
1581         smc->os.MacStat.gen.rx_errors++;
1582         goto RequeueRxd;
1583     }
1584     virt = skb->data;
1585 
1586     // The DMA mapping was released in dma_complete above.
1587 
1588     dump_data(skb->data, len);
1589 
1590     /*
1591      * FDDI Frame format:
1592      * +-------+-------+-------+------------+--------+------------+
1593      * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
1594      * +-------+-------+-------+------------+--------+------------+
1595      *
1596      * FC = Frame Control
1597      * DA = Destination Address
1598      * SA = Source Address
1599      * RIF = Routing Information Field
1600      * LLC = Logical Link Control
1601      */
1602 
1603     // Remove Routing Information Field (RIF), if present.
1604 
1605     if ((virt[1 + 6] & FDDI_RII) == 0)
1606         RifLength = 0;
1607     else {
1608         int n;
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.
1613 
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.
1619 
1620         }
1621         virt[1 + 6] &= ~FDDI_RII;   // Clear RII bit.
1622         // regions overlap
1623 
1624         virt = cp + RifLength;
1625         for (n = FDDI_MAC_HDR_LEN; n; n--)
1626             *--virt = *--cp;
1627         // adjust sbd->data pointer
1628         skb_pull(skb, RifLength);
1629         len -= RifLength;
1630         RifLength = 0;
1631     }
1632 
1633     // Count statistics.
1634     smc->os.MacStat.gen.rx_packets++;   // Count indicated receive
1635                         // packets.
1636     smc->os.MacStat.gen.rx_bytes+=len;  // Count bytes.
1637 
1638     // virt points to header again
1639     if (virt[1] & 0x01) {   // Check group (multicast) bit.
1640 
1641         smc->os.MacStat.gen.multicast++;
1642     }
1643 
1644     // deliver frame to system
1645     rxd->rxd_os.skb = NULL;
1646     skb_trim(skb, len);
1647     skb->protocol = fddi_type_trans(skb, bp->dev);
1648 
1649     netif_rx(skb);
1650 
1651     HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
1652     return;
1653 
1654       RequeueRxd:
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
1658                         // not indicated.
1659 
1660 }               // mac_drv_rx_complete
1661 
1662 
1663 /************************
1664  *
1665  *  mac_drv_requeue_rxd
1666  *
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.
1671  * Args
1672  *  smc - A pointer to the SMT context struct.
1673  *
1674  *  rxd - A pointer to the first RxD which is used by the receive frame.
1675  *
1676  *  frag_count - Count of RxDs used by the received frame.
1677  * Out
1678  *  Nothing.
1679  *
1680  ************************/
1681 void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1682              int frag_count)
1683 {
1684     volatile struct s_smt_fp_rxd *next_rxd;
1685     volatile struct s_smt_fp_rxd *src_rxd;
1686     struct sk_buff *skb;
1687     int MaxFrameSize;
1688     unsigned char *v_addr;
1689     dma_addr_t b_addr;
1690 
1691     if (frag_count != 1)    // This is not allowed to happen.
1692 
1693         printk("fddi: Multi-fragment requeue!\n");
1694 
1695     MaxFrameSize = smc->os.MaxFrameSize;
1696     src_rxd = rxd;
1697     for (; frag_count > 0; frag_count--) {
1698         next_rxd = src_rxd->rxd_next;
1699         rxd = HWM_GET_CURR_RXD(smc);
1700 
1701         skb = src_rxd->rxd_os.skb;
1702         if (skb == NULL) {  // this should not happen
1703 
1704             pr_debug("Requeue with no skb in rxd!\n");
1705             skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1706             if (skb) {
1707                 // we got a skb
1708                 rxd->rxd_os.skb = skb;
1709                 skb_reserve(skb, 3);
1710                 skb_put(skb, MaxFrameSize);
1711                 v_addr = skb->data;
1712                 b_addr = dma_map_single(&(&smc->os.pdev)->dev,
1713                             v_addr, MaxFrameSize,
1714                             DMA_FROM_DEVICE);
1715                 rxd->rxd_os.dma_addr = b_addr;
1716             } else {
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;
1722             }
1723         } else {
1724             // we use skb from old rxd
1725             rxd->rxd_os.skb = skb;
1726             v_addr = skb->data;
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;
1730         }
1731         hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1732                 FIRST_FRAG | LAST_FRAG);
1733 
1734         src_rxd = next_rxd;
1735     }
1736 }               // mac_drv_requeue_rxd
1737 
1738 
1739 /************************
1740  *
1741  *  mac_drv_fill_rxd
1742  *
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
1748  *  available.
1749  * Args
1750  *  smc - A pointer to the SMT context struct.
1751  * Out
1752  *  Nothing.
1753  *
1754  ************************/
1755 void mac_drv_fill_rxd(struct s_smc *smc)
1756 {
1757     int MaxFrameSize;
1758     unsigned char *v_addr;
1759     unsigned long b_addr;
1760     struct sk_buff *skb;
1761     volatile struct s_smt_fp_rxd *rxd;
1762 
1763     pr_debug("entering mac_drv_fill_rxd\n");
1764 
1765     // Walk through the list of free receive buffers, passing receive
1766     // buffers to the HWM as long as RXDs are available.
1767 
1768     MaxFrameSize = smc->os.MaxFrameSize;
1769     // Check if there is any RXD left.
1770     while (HWM_GET_RX_FREE(smc) > 0) {
1771         pr_debug(".\n");
1772 
1773         rxd = HWM_GET_CURR_RXD(smc);
1774         skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
1775         if (skb) {
1776             // we got a skb
1777             skb_reserve(skb, 3);
1778             skb_put(skb, MaxFrameSize);
1779             v_addr = skb->data;
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;
1783         } else {
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;
1792         }
1793 
1794         rxd->rxd_os.skb = skb;
1795 
1796         // Pass receive buffer to HWM.
1797         hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
1798                 FIRST_FRAG | LAST_FRAG);
1799     }
1800     pr_debug("leaving mac_drv_fill_rxd\n");
1801 }               // mac_drv_fill_rxd
1802 
1803 
1804 /************************
1805  *
1806  *  mac_drv_clear_rxd
1807  *
1808  *  The hardware module calls this function to release unused
1809  *  receive buffers.
1810  * Args
1811  *  smc - A pointer to the SMT context struct.
1812  *
1813  *  rxd - A pointer to the first RxD which is used by the receive buffer.
1814  *
1815  *  frag_count - Count of RxDs used by the receive buffer.
1816  * Out
1817  *  Nothing.
1818  *
1819  ************************/
1820 void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
1821                int frag_count)
1822 {
1823 
1824     struct sk_buff *skb;
1825 
1826     pr_debug("entering mac_drv_clear_rxd\n");
1827 
1828     if (frag_count != 1)    // This is not allowed to happen.
1829 
1830         printk("fddi: Multi-fragment clear!\n");
1831 
1832     for (; frag_count > 0; frag_count--) {
1833         skb = rxd->rxd_os.skb;
1834         if (skb != NULL) {
1835             skfddi_priv *bp = &smc->os;
1836             int MaxFrameSize = bp->MaxFrameSize;
1837 
1838             dma_unmap_single(&(&bp->pdev)->dev,
1839                      rxd->rxd_os.dma_addr, MaxFrameSize,
1840                      DMA_FROM_DEVICE);
1841 
1842             dev_kfree_skb(skb);
1843             rxd->rxd_os.skb = NULL;
1844         }
1845         rxd = rxd->rxd_next;    // Next RXD.
1846 
1847     }
1848 }               // mac_drv_clear_rxd
1849 
1850 
1851 /************************
1852  *
1853  *  mac_drv_rx_init
1854  *
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.
1857  *
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.
1860  *
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.
1863  * Args
1864  *  smc - A pointer to the SMT context struct.
1865  *
1866  *  len - The length (in bytes) of the received frame (FC, DA, SA, Data).
1867  *
1868  *  fc - The Frame Control field of the received frame.
1869  *
1870  *  look_ahead - A pointer to the lookahead data buffer (may be NULL).
1871  *
1872  *  la_len - The length of the lookahead data stored in the lookahead
1873  *  buffer (may be zero).
1874  * Out
1875  *  Always returns zero (0).
1876  *
1877  ************************/
1878 int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
1879             char *look_ahead, int la_len)
1880 {
1881     struct sk_buff *skb;
1882 
1883     pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
1884 
1885     // "Received" a SMT or NSA frame of the local SMT.
1886 
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);
1891         return 0;
1892     }
1893     skb = alloc_skb(len + 3, GFP_ATOMIC);
1894     if (!skb) {
1895         pr_debug("fddi: Local SMT: skb memory exhausted.\n");
1896         return 0;
1897     }
1898     skb_reserve(skb, 3);
1899     skb_put(skb, len);
1900     skb_copy_to_linear_data(skb, look_ahead, len);
1901 
1902     // deliver frame to system
1903     skb->protocol = fddi_type_trans(skb, smc->os.dev);
1904     netif_rx(skb);
1905 
1906     return 0;
1907 }               // mac_drv_rx_init
1908 
1909 
1910 /************************
1911  *
1912  *  smt_timer_poll
1913  *
1914  *  This routine is called periodically by the SMT module to clean up the
1915  *  driver.
1916  *
1917  *  Return any queued frames back to the upper protocol layers if the ring
1918  *  is down.
1919  * Args
1920  *  smc - A pointer to the SMT context struct.
1921  * Out
1922  *  Nothing.
1923  *
1924  ************************/
1925 void smt_timer_poll(struct s_smc *smc)
1926 {
1927 }               // smt_timer_poll
1928 
1929 
1930 /************************
1931  *
1932  *  ring_status_indication
1933  *
1934  *  This function indicates a change of the ring state.
1935  * Args
1936  *  smc - A pointer to the SMT context struct.
1937  *
1938  *  status - The current ring status.
1939  * Out
1940  *  Nothing.
1941  *
1942  ************************/
1943 void ring_status_indication(struct s_smc *smc, u_long status)
1944 {
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 ");
1978     pr_debug("]\n");
1979 }               // ring_status_indication
1980 
1981 
1982 /************************
1983  *
1984  *  smt_get_time
1985  *
1986  *  Gets the current time from the system.
1987  * Args
1988  *  None.
1989  * Out
1990  *  The current time in TICKS_PER_SECOND.
1991  *
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().
1995  *
1996  ************************/
1997 unsigned long smt_get_time(void)
1998 {
1999     return jiffies;
2000 }               // smt_get_time
2001 
2002 
2003 /************************
2004  *
2005  *  smt_stat_counter
2006  *
2007  *  Status counter update (ring_op, fifo full).
2008  * Args
2009  *  smc - A pointer to the SMT context struct.
2010  *
2011  *  stat -  = 0: A ring operational change occurred.
2012  *      = 1: The FORMAC FIFO buffer is full / FIFO overflow.
2013  * Out
2014  *  Nothing.
2015  *
2016  ************************/
2017 void smt_stat_counter(struct s_smc *smc, int stat)
2018 {
2019 //      BOOLEAN RingIsUp ;
2020 
2021     pr_debug("smt_stat_counter\n");
2022     switch (stat) {
2023     case 0:
2024         pr_debug("Ring operational change.\n");
2025         break;
2026     case 1:
2027         pr_debug("Receive fifo overflow.\n");
2028         smc->os.MacStat.gen.rx_errors++;
2029         break;
2030     default:
2031         pr_debug("Unknown status (%d).\n", stat);
2032         break;
2033     }
2034 }               // smt_stat_counter
2035 
2036 
2037 /************************
2038  *
2039  *  cfm_state_change
2040  *
2041  *  Sets CFM state in custom statistics.
2042  * Args
2043  *  smc - A pointer to the SMT context struct.
2044  *
2045  *  c_state - Possible values are:
2046  *
2047  *      EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
2048  *      EC5_INSERT, EC6_CHECK, EC7_DEINSERT
2049  * Out
2050  *  Nothing.
2051  *
2052  ************************/
2053 void cfm_state_change(struct s_smc *smc, int c_state)
2054 {
2055 #ifdef DRIVERDEBUG
2056     char *s;
2057 
2058     switch (c_state) {
2059     case SC0_ISOLATED:
2060         s = "SC0_ISOLATED";
2061         break;
2062     case SC1_WRAP_A:
2063         s = "SC1_WRAP_A";
2064         break;
2065     case SC2_WRAP_B:
2066         s = "SC2_WRAP_B";
2067         break;
2068     case SC4_THRU_A:
2069         s = "SC4_THRU_A";
2070         break;
2071     case SC5_THRU_B:
2072         s = "SC5_THRU_B";
2073         break;
2074     case SC7_WRAP_S:
2075         s = "SC7_WRAP_S";
2076         break;
2077     case SC9_C_WRAP_A:
2078         s = "SC9_C_WRAP_A";
2079         break;
2080     case SC10_C_WRAP_B:
2081         s = "SC10_C_WRAP_B";
2082         break;
2083     case SC11_C_WRAP_S:
2084         s = "SC11_C_WRAP_S";
2085         break;
2086     default:
2087         pr_debug("cfm_state_change: unknown %d\n", c_state);
2088         return;
2089     }
2090     pr_debug("cfm_state_change: %s\n", s);
2091 #endif              // DRIVERDEBUG
2092 }               // cfm_state_change
2093 
2094 
2095 /************************
2096  *
2097  *  ecm_state_change
2098  *
2099  *  Sets ECM state in custom statistics.
2100  * Args
2101  *  smc - A pointer to the SMT context struct.
2102  *
2103  *  e_state - Possible values are:
2104  *
2105  *      SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
2106  *      SC5_THRU_B (7), SC7_WRAP_S (8)
2107  * Out
2108  *  Nothing.
2109  *
2110  ************************/
2111 void ecm_state_change(struct s_smc *smc, int e_state)
2112 {
2113 #ifdef DRIVERDEBUG
2114     char *s;
2115 
2116     switch (e_state) {
2117     case EC0_OUT:
2118         s = "EC0_OUT";
2119         break;
2120     case EC1_IN:
2121         s = "EC1_IN";
2122         break;
2123     case EC2_TRACE:
2124         s = "EC2_TRACE";
2125         break;
2126     case EC3_LEAVE:
2127         s = "EC3_LEAVE";
2128         break;
2129     case EC4_PATH_TEST:
2130         s = "EC4_PATH_TEST";
2131         break;
2132     case EC5_INSERT:
2133         s = "EC5_INSERT";
2134         break;
2135     case EC6_CHECK:
2136         s = "EC6_CHECK";
2137         break;
2138     case EC7_DEINSERT:
2139         s = "EC7_DEINSERT";
2140         break;
2141     default:
2142         s = "unknown";
2143         break;
2144     }
2145     pr_debug("ecm_state_change: %s\n", s);
2146 #endif              //DRIVERDEBUG
2147 }               // ecm_state_change
2148 
2149 
2150 /************************
2151  *
2152  *  rmt_state_change
2153  *
2154  *  Sets RMT state in custom statistics.
2155  * Args
2156  *  smc - A pointer to the SMT context struct.
2157  *
2158  *  r_state - Possible values are:
2159  *
2160  *      RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
2161  *      RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
2162  * Out
2163  *  Nothing.
2164  *
2165  ************************/
2166 void rmt_state_change(struct s_smc *smc, int r_state)
2167 {
2168 #ifdef DRIVERDEBUG
2169     char *s;
2170 
2171     switch (r_state) {
2172     case RM0_ISOLATED:
2173         s = "RM0_ISOLATED";
2174         break;
2175     case RM1_NON_OP:
2176         s = "RM1_NON_OP - not operational";
2177         break;
2178     case RM2_RING_OP:
2179         s = "RM2_RING_OP - ring operational";
2180         break;
2181     case RM3_DETECT:
2182         s = "RM3_DETECT - detect dupl addresses";
2183         break;
2184     case RM4_NON_OP_DUP:
2185         s = "RM4_NON_OP_DUP - dupl. addr detected";
2186         break;
2187     case RM5_RING_OP_DUP:
2188         s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
2189         break;
2190     case RM6_DIRECTED:
2191         s = "RM6_DIRECTED - sending directed beacons";
2192         break;
2193     case RM7_TRACE:
2194         s = "RM7_TRACE - trace initiated";
2195         break;
2196     default:
2197         s = "unknown";
2198         break;
2199     }
2200     pr_debug("[rmt_state_change: %s]\n", s);
2201 #endif              // DRIVERDEBUG
2202 }               // rmt_state_change
2203 
2204 
2205 /************************
2206  *
2207  *  drv_reset_indication
2208  *
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.
2212  * Args
2213  *  smc - A pointer to the SMT context struct.
2214  * Out
2215  *  Nothing.
2216  *
2217  ************************/
2218 void drv_reset_indication(struct s_smc *smc)
2219 {
2220     pr_debug("entering drv_reset_indication\n");
2221 
2222     smc->os.ResetRequested = TRUE;  // Set flag.
2223 
2224 }               // drv_reset_indication
2225 
2226 static struct pci_driver skfddi_pci_driver = {
2227     .name       = "skfddi",
2228     .id_table   = skfddi_pci_tbl,
2229     .probe      = skfp_init_one,
2230     .remove     = skfp_remove_one,
2231 };
2232 
2233 module_pci_driver(skfddi_pci_driver);