Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File Name: |
| 3 | * skfddi.c |
| 4 | * |
| 5 | * Copyright Information: |
| 6 | * Copyright SysKonnect 1998,1999. |
| 7 | * |
| 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. |
| 12 | * |
| 13 | * The information in this file is provided "AS IS" without warranty. |
| 14 | * |
| 15 | * Abstract: |
| 16 | * A Linux device driver supporting the SysKonnect FDDI PCI controller |
| 17 | * familie. |
| 18 | * |
| 19 | * Maintainers: |
| 20 | * CG Christoph Goos (cgoos@syskonnect.de) |
| 21 | * |
| 22 | * Contributors: |
| 23 | * DM David S. Miller |
| 24 | * |
| 25 | * Address all question to: |
| 26 | * linux@syskonnect.de |
| 27 | * |
| 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". |
| 31 | * |
| 32 | * Driver Architecture: |
| 33 | * The driver architecture is based on the DEC FDDI driver by |
| 34 | * Lawrence V. Stefani and several ethernet drivers. |
| 35 | * I also used an existing Windows NT miniport driver. |
| 36 | * All hardware dependent fuctions are handled by the SysKonnect |
| 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. |
| 42 | * |
| 43 | * Modification History: |
| 44 | * Date Name Description |
| 45 | * 02-Mar-98 CG Created. |
| 46 | * |
| 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 |
| 56 | * |
| 57 | * Compilation options (-Dxxx): |
| 58 | * DRIVERDEBUG print lots of messages to log file |
| 59 | * DUMPPACKETS print received/transmitted packets to logfile |
| 60 | * |
| 61 | * Tested cpu architectures: |
| 62 | * - i386 |
| 63 | * - sparc64 |
| 64 | */ |
| 65 | |
| 66 | /* Version information string - should be updated prior to */ |
| 67 | /* each new release!!! */ |
| 68 | #define VERSION "2.07" |
| 69 | |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 70 | static const char * const boot_msg = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n" |
| 72 | " SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)"; |
| 73 | |
| 74 | /* Include files */ |
| 75 | |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 76 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #include <linux/module.h> |
| 78 | #include <linux/kernel.h> |
| 79 | #include <linux/errno.h> |
| 80 | #include <linux/ioport.h> |
| 81 | #include <linux/slab.h> |
| 82 | #include <linux/interrupt.h> |
| 83 | #include <linux/pci.h> |
| 84 | #include <linux/netdevice.h> |
| 85 | #include <linux/fddidevice.h> |
| 86 | #include <linux/skbuff.h> |
| 87 | #include <linux/bitops.h> |
| 88 | |
| 89 | #include <asm/byteorder.h> |
| 90 | #include <asm/io.h> |
| 91 | #include <asm/uaccess.h> |
| 92 | |
| 93 | #include "h/types.h" |
| 94 | #undef ADDR // undo Linux definition |
| 95 | #include "h/skfbi.h" |
| 96 | #include "h/fddi.h" |
| 97 | #include "h/smc.h" |
| 98 | #include "h/smtstate.h" |
| 99 | |
| 100 | |
| 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); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 105 | static irqreturn_t skfp_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 111 | static netdev_tx_t skfp_send_pkt(struct sk_buff *skb, |
| 112 | struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 116 | |
| 117 | |
| 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); |
| 137 | |
| 138 | // External functions from the hardware module |
| 139 | extern u_int mac_drv_check_space(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 152 | static DEFINE_PCI_DEVICE_TABLE(skfddi_pci_tbl) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, }, |
| 154 | { } /* Terminating entry */ |
| 155 | }; |
| 156 | MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl); |
| 157 | MODULE_LICENSE("GPL"); |
| 158 | MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>"); |
| 159 | |
| 160 | // Define module-wide (static) variables |
| 161 | |
| 162 | static int num_boards; /* total number of adapters configured */ |
| 163 | |
Stephen Hemminger | 145186a | 2008-11-20 20:29:48 -0800 | [diff] [blame] | 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_change_mtu = fddi_change_mtu, |
| 170 | .ndo_set_multicast_list = skfp_ctl_set_multicast_list, |
| 171 | .ndo_set_mac_address = skfp_ctl_set_mac_address, |
| 172 | .ndo_do_ioctl = skfp_ioctl, |
| 173 | }; |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /* |
| 176 | * ================= |
| 177 | * = skfp_init_one = |
| 178 | * ================= |
| 179 | * |
| 180 | * Overview: |
| 181 | * Probes for supported FDDI PCI controllers |
| 182 | * |
| 183 | * Returns: |
| 184 | * Condition code |
| 185 | * |
| 186 | * Arguments: |
| 187 | * pdev - pointer to PCI device information |
| 188 | * |
| 189 | * Functional Description: |
| 190 | * This is now called by PCI driver registration process |
| 191 | * for each board found. |
| 192 | * |
| 193 | * Return Codes: |
| 194 | * 0 - This device (fddi0, fddi1, etc) configured successfully |
| 195 | * -ENODEV - No devices present, or no SysKonnect FDDI PCI device |
| 196 | * present for this device name |
| 197 | * |
| 198 | * |
| 199 | * Side Effects: |
| 200 | * Device structures for FDDI adapters (fddi0, fddi1, etc) are |
| 201 | * initialized and the board resources are read and stored in |
| 202 | * the device structure. |
| 203 | */ |
| 204 | static int skfp_init_one(struct pci_dev *pdev, |
| 205 | const struct pci_device_id *ent) |
| 206 | { |
| 207 | struct net_device *dev; |
| 208 | struct s_smc *smc; /* board pointer */ |
| 209 | void __iomem *mem; |
| 210 | int err; |
| 211 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 212 | pr_debug(KERN_INFO "entering skfp_init_one\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | if (num_boards == 0) |
| 215 | printk("%s\n", boot_msg); |
| 216 | |
| 217 | err = pci_enable_device(pdev); |
| 218 | if (err) |
| 219 | return err; |
| 220 | |
| 221 | err = pci_request_regions(pdev, "skfddi"); |
| 222 | if (err) |
| 223 | goto err_out1; |
| 224 | |
| 225 | pci_set_master(pdev); |
| 226 | |
| 227 | #ifdef MEM_MAPPED_IO |
| 228 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 229 | printk(KERN_ERR "skfp: region is not an MMIO resource\n"); |
| 230 | err = -EIO; |
| 231 | goto err_out2; |
| 232 | } |
| 233 | |
| 234 | mem = ioremap(pci_resource_start(pdev, 0), 0x4000); |
| 235 | #else |
| 236 | if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) { |
| 237 | printk(KERN_ERR "skfp: region is not PIO resource\n"); |
| 238 | err = -EIO; |
| 239 | goto err_out2; |
| 240 | } |
| 241 | |
| 242 | mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN); |
| 243 | #endif |
| 244 | if (!mem) { |
| 245 | printk(KERN_ERR "skfp: Unable to map register, " |
| 246 | "FDDI adapter will be disabled.\n"); |
| 247 | err = -EIO; |
| 248 | goto err_out2; |
| 249 | } |
| 250 | |
| 251 | dev = alloc_fddidev(sizeof(struct s_smc)); |
| 252 | if (!dev) { |
| 253 | printk(KERN_ERR "skfp: Unable to allocate fddi device, " |
| 254 | "FDDI adapter will be disabled.\n"); |
| 255 | err = -ENOMEM; |
| 256 | goto err_out3; |
| 257 | } |
| 258 | |
| 259 | dev->irq = pdev->irq; |
Stephen Hemminger | 145186a | 2008-11-20 20:29:48 -0800 | [diff] [blame] | 260 | dev->netdev_ops = &skfp_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 263 | |
| 264 | /* Initialize board structure with bus-specific info */ |
| 265 | smc = netdev_priv(dev); |
| 266 | smc->os.dev = dev; |
| 267 | smc->os.bus_type = SK_BUS_TYPE_PCI; |
| 268 | smc->os.pdev = *pdev; |
| 269 | smc->os.QueueSkb = MAX_TX_QUEUE_LEN; |
| 270 | smc->os.MaxFrameSize = MAX_FRAME_SIZE; |
| 271 | smc->os.dev = dev; |
| 272 | smc->hw.slot = -1; |
| 273 | smc->hw.iop = mem; |
| 274 | smc->os.ResetRequested = FALSE; |
| 275 | skb_queue_head_init(&smc->os.SendSkbQueue); |
| 276 | |
| 277 | dev->base_addr = (unsigned long)mem; |
| 278 | |
| 279 | err = skfp_driver_init(dev); |
| 280 | if (err) |
| 281 | goto err_out4; |
| 282 | |
| 283 | err = register_netdev(dev); |
| 284 | if (err) |
| 285 | goto err_out5; |
| 286 | |
| 287 | ++num_boards; |
| 288 | pci_set_drvdata(pdev, dev); |
| 289 | |
| 290 | if ((pdev->subsystem_device & 0xff00) == 0x5500 || |
| 291 | (pdev->subsystem_device & 0xff00) == 0x5800) |
| 292 | printk("%s: SysKonnect FDDI PCI adapter" |
| 293 | " found (SK-%04X)\n", dev->name, |
| 294 | pdev->subsystem_device); |
| 295 | else |
| 296 | printk("%s: FDDI PCI adapter found\n", dev->name); |
| 297 | |
| 298 | return 0; |
| 299 | err_out5: |
| 300 | if (smc->os.SharedMemAddr) |
| 301 | pci_free_consistent(pdev, smc->os.SharedMemSize, |
| 302 | smc->os.SharedMemAddr, |
| 303 | smc->os.SharedMemDMA); |
| 304 | pci_free_consistent(pdev, MAX_FRAME_SIZE, |
| 305 | smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA); |
| 306 | err_out4: |
| 307 | free_netdev(dev); |
| 308 | err_out3: |
| 309 | #ifdef MEM_MAPPED_IO |
| 310 | iounmap(mem); |
| 311 | #else |
| 312 | ioport_unmap(mem); |
| 313 | #endif |
| 314 | err_out2: |
| 315 | pci_release_regions(pdev); |
| 316 | err_out1: |
| 317 | pci_disable_device(pdev); |
| 318 | return err; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * Called for each adapter board from pci_unregister_driver |
| 323 | */ |
| 324 | static void __devexit skfp_remove_one(struct pci_dev *pdev) |
| 325 | { |
| 326 | struct net_device *p = pci_get_drvdata(pdev); |
| 327 | struct s_smc *lp = netdev_priv(p); |
| 328 | |
| 329 | unregister_netdev(p); |
| 330 | |
| 331 | if (lp->os.SharedMemAddr) { |
| 332 | pci_free_consistent(&lp->os.pdev, |
| 333 | lp->os.SharedMemSize, |
| 334 | lp->os.SharedMemAddr, |
| 335 | lp->os.SharedMemDMA); |
| 336 | lp->os.SharedMemAddr = NULL; |
| 337 | } |
| 338 | if (lp->os.LocalRxBuffer) { |
| 339 | pci_free_consistent(&lp->os.pdev, |
| 340 | MAX_FRAME_SIZE, |
| 341 | lp->os.LocalRxBuffer, |
| 342 | lp->os.LocalRxBufferDMA); |
| 343 | lp->os.LocalRxBuffer = NULL; |
| 344 | } |
| 345 | #ifdef MEM_MAPPED_IO |
| 346 | iounmap(lp->hw.iop); |
| 347 | #else |
| 348 | ioport_unmap(lp->hw.iop); |
| 349 | #endif |
| 350 | pci_release_regions(pdev); |
| 351 | free_netdev(p); |
| 352 | |
| 353 | pci_disable_device(pdev); |
| 354 | pci_set_drvdata(pdev, NULL); |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * ==================== |
| 359 | * = skfp_driver_init = |
| 360 | * ==================== |
| 361 | * |
| 362 | * Overview: |
| 363 | * Initializes remaining adapter board structure information |
| 364 | * and makes sure adapter is in a safe state prior to skfp_open(). |
| 365 | * |
| 366 | * Returns: |
| 367 | * Condition code |
| 368 | * |
| 369 | * Arguments: |
| 370 | * dev - pointer to device information |
| 371 | * |
| 372 | * Functional Description: |
| 373 | * This function allocates additional resources such as the host memory |
| 374 | * blocks needed by the adapter. |
| 375 | * The adapter is also reset. The OS must call skfp_open() to open |
| 376 | * the adapter and bring it on-line. |
| 377 | * |
| 378 | * Return Codes: |
| 379 | * 0 - initialization succeeded |
| 380 | * -1 - initialization failed |
| 381 | */ |
| 382 | static int skfp_driver_init(struct net_device *dev) |
| 383 | { |
| 384 | struct s_smc *smc = netdev_priv(dev); |
| 385 | skfddi_priv *bp = &smc->os; |
| 386 | int err = -EIO; |
| 387 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 388 | pr_debug(KERN_INFO "entering skfp_driver_init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | // set the io address in private structures |
| 391 | bp->base_addr = dev->base_addr; |
| 392 | |
| 393 | // Get the interrupt level from the PCI Configuration Table |
| 394 | smc->hw.irq = dev->irq; |
| 395 | |
| 396 | spin_lock_init(&bp->DriverLock); |
| 397 | |
| 398 | // Allocate invalid frame |
| 399 | bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA); |
| 400 | if (!bp->LocalRxBuffer) { |
| 401 | printk("could not allocate mem for "); |
| 402 | printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE); |
| 403 | goto fail; |
| 404 | } |
| 405 | |
| 406 | // Determine the required size of the 'shared' memory area. |
| 407 | bp->SharedMemSize = mac_drv_check_space(); |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 408 | pr_debug(KERN_INFO "Memory for HWM: %ld\n", bp->SharedMemSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | if (bp->SharedMemSize > 0) { |
| 410 | bp->SharedMemSize += 16; // for descriptor alignment |
| 411 | |
| 412 | bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev, |
| 413 | bp->SharedMemSize, |
| 414 | &bp->SharedMemDMA); |
| 415 | if (!bp->SharedMemSize) { |
| 416 | printk("could not allocate mem for "); |
| 417 | printk("hardware module: %ld byte\n", |
| 418 | bp->SharedMemSize); |
| 419 | goto fail; |
| 420 | } |
| 421 | bp->SharedMemHeap = 0; // Nothing used yet. |
| 422 | |
| 423 | } else { |
| 424 | bp->SharedMemAddr = NULL; |
| 425 | bp->SharedMemHeap = 0; |
| 426 | } // SharedMemSize > 0 |
| 427 | |
| 428 | memset(bp->SharedMemAddr, 0, bp->SharedMemSize); |
| 429 | |
| 430 | card_stop(smc); // Reset adapter. |
| 431 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 432 | pr_debug(KERN_INFO "mac_drv_init()..\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if (mac_drv_init(smc) != 0) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 434 | pr_debug(KERN_INFO "mac_drv_init() failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | goto fail; |
| 436 | } |
| 437 | read_address(smc, NULL); |
hartleys | 596a530 | 2010-01-07 13:27:46 +0000 | [diff] [blame] | 438 | pr_debug(KERN_INFO "HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6); |
| 440 | |
| 441 | smt_reset_defaults(smc, 0); |
| 442 | |
| 443 | return (0); |
| 444 | |
| 445 | fail: |
| 446 | if (bp->SharedMemAddr) { |
| 447 | pci_free_consistent(&bp->pdev, |
| 448 | bp->SharedMemSize, |
| 449 | bp->SharedMemAddr, |
| 450 | bp->SharedMemDMA); |
| 451 | bp->SharedMemAddr = NULL; |
| 452 | } |
| 453 | if (bp->LocalRxBuffer) { |
| 454 | pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE, |
| 455 | bp->LocalRxBuffer, bp->LocalRxBufferDMA); |
| 456 | bp->LocalRxBuffer = NULL; |
| 457 | } |
| 458 | return err; |
| 459 | } // skfp_driver_init |
| 460 | |
| 461 | |
| 462 | /* |
| 463 | * ============= |
| 464 | * = skfp_open = |
| 465 | * ============= |
| 466 | * |
| 467 | * Overview: |
| 468 | * Opens the adapter |
| 469 | * |
| 470 | * Returns: |
| 471 | * Condition code |
| 472 | * |
| 473 | * Arguments: |
| 474 | * dev - pointer to device information |
| 475 | * |
| 476 | * Functional Description: |
| 477 | * This function brings the adapter to an operational state. |
| 478 | * |
| 479 | * Return Codes: |
| 480 | * 0 - Adapter was successfully opened |
| 481 | * -EAGAIN - Could not register IRQ |
| 482 | */ |
| 483 | static int skfp_open(struct net_device *dev) |
| 484 | { |
| 485 | struct s_smc *smc = netdev_priv(dev); |
| 486 | int err; |
| 487 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 488 | pr_debug(KERN_INFO "entering skfp_open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* Register IRQ - support shared interrupts by passing device ptr */ |
Al Viro | 2f220e3 | 2008-03-16 22:22:24 +0000 | [diff] [blame] | 490 | err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | dev->name, dev); |
| 492 | if (err) |
| 493 | return err; |
| 494 | |
| 495 | /* |
| 496 | * Set current address to factory MAC address |
| 497 | * |
| 498 | * Note: We've already done this step in skfp_driver_init. |
| 499 | * However, it's possible that a user has set a node |
| 500 | * address override, then closed and reopened the |
| 501 | * adapter. Unless we reset the device address field |
| 502 | * now, we'll continue to use the existing modified |
| 503 | * address. |
| 504 | */ |
| 505 | read_address(smc, NULL); |
| 506 | memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6); |
| 507 | |
| 508 | init_smt(smc, NULL); |
| 509 | smt_online(smc, 1); |
| 510 | STI_FBI(); |
| 511 | |
| 512 | /* Clear local multicast address tables */ |
| 513 | mac_clear_multicast(smc); |
| 514 | |
| 515 | /* Disable promiscuous filter settings */ |
| 516 | mac_drv_rx_mode(smc, RX_DISABLE_PROMISC); |
| 517 | |
| 518 | netif_start_queue(dev); |
| 519 | return (0); |
| 520 | } // skfp_open |
| 521 | |
| 522 | |
| 523 | /* |
| 524 | * ============== |
| 525 | * = skfp_close = |
| 526 | * ============== |
| 527 | * |
| 528 | * Overview: |
| 529 | * Closes the device/module. |
| 530 | * |
| 531 | * Returns: |
| 532 | * Condition code |
| 533 | * |
| 534 | * Arguments: |
| 535 | * dev - pointer to device information |
| 536 | * |
| 537 | * Functional Description: |
| 538 | * This routine closes the adapter and brings it to a safe state. |
| 539 | * The interrupt service routine is deregistered with the OS. |
| 540 | * The adapter can be opened again with another call to skfp_open(). |
| 541 | * |
| 542 | * Return Codes: |
| 543 | * Always return 0. |
| 544 | * |
| 545 | * Assumptions: |
| 546 | * No further requests for this adapter are made after this routine is |
| 547 | * called. skfp_open() can be called to reset and reinitialize the |
| 548 | * adapter. |
| 549 | */ |
| 550 | static int skfp_close(struct net_device *dev) |
| 551 | { |
| 552 | struct s_smc *smc = netdev_priv(dev); |
| 553 | skfddi_priv *bp = &smc->os; |
| 554 | |
| 555 | CLI_FBI(); |
| 556 | smt_reset_defaults(smc, 1); |
| 557 | card_stop(smc); |
| 558 | mac_drv_clear_tx_queue(smc); |
| 559 | mac_drv_clear_rx_queue(smc); |
| 560 | |
| 561 | netif_stop_queue(dev); |
| 562 | /* Deregister (free) IRQ */ |
| 563 | free_irq(dev->irq, dev); |
| 564 | |
| 565 | skb_queue_purge(&bp->SendSkbQueue); |
| 566 | bp->QueueSkb = MAX_TX_QUEUE_LEN; |
| 567 | |
| 568 | return (0); |
| 569 | } // skfp_close |
| 570 | |
| 571 | |
| 572 | /* |
| 573 | * ================== |
| 574 | * = skfp_interrupt = |
| 575 | * ================== |
| 576 | * |
| 577 | * Overview: |
| 578 | * Interrupt processing routine |
| 579 | * |
| 580 | * Returns: |
| 581 | * None |
| 582 | * |
| 583 | * Arguments: |
| 584 | * irq - interrupt vector |
| 585 | * dev_id - pointer to device information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | * |
| 587 | * Functional Description: |
| 588 | * This routine calls the interrupt processing routine for this adapter. It |
| 589 | * disables and reenables adapter interrupts, as appropriate. We can support |
| 590 | * shared interrupts since the incoming dev_id pointer provides our device |
| 591 | * structure context. All the real work is done in the hardware module. |
| 592 | * |
| 593 | * Return Codes: |
| 594 | * None |
| 595 | * |
| 596 | * Assumptions: |
| 597 | * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC |
| 598 | * on Intel-based systems) is done by the operating system outside this |
| 599 | * routine. |
| 600 | * |
| 601 | * System interrupts are enabled through this call. |
| 602 | * |
| 603 | * Side Effects: |
| 604 | * Interrupts are disabled, then reenabled at the adapter. |
| 605 | */ |
| 606 | |
Hannes Eder | 409b204 | 2008-12-26 00:06:28 -0800 | [diff] [blame] | 607 | static irqreturn_t skfp_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
Jeff Garzik | c31f28e | 2006-10-06 14:56:04 -0400 | [diff] [blame] | 609 | struct net_device *dev = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | struct s_smc *smc; /* private board structure pointer */ |
| 611 | skfddi_priv *bp; |
| 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | smc = netdev_priv(dev); |
| 614 | bp = &smc->os; |
| 615 | |
| 616 | // IRQs enabled or disabled ? |
| 617 | if (inpd(ADDR(B0_IMSK)) == 0) { |
| 618 | // IRQs are disabled: must be shared interrupt |
| 619 | return IRQ_NONE; |
| 620 | } |
| 621 | // Note: At this point, IRQs are enabled. |
| 622 | if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ? |
| 623 | // Adapter did not issue an IRQ: must be shared interrupt |
| 624 | return IRQ_NONE; |
| 625 | } |
| 626 | CLI_FBI(); // Disable IRQs from our adapter. |
| 627 | spin_lock(&bp->DriverLock); |
| 628 | |
| 629 | // Call interrupt handler in hardware module (HWM). |
| 630 | fddi_isr(smc); |
| 631 | |
| 632 | if (smc->os.ResetRequested) { |
| 633 | ResetAdapter(smc); |
| 634 | smc->os.ResetRequested = FALSE; |
| 635 | } |
| 636 | spin_unlock(&bp->DriverLock); |
| 637 | STI_FBI(); // Enable IRQs from our adapter. |
| 638 | |
| 639 | return IRQ_HANDLED; |
| 640 | } // skfp_interrupt |
| 641 | |
| 642 | |
| 643 | /* |
| 644 | * ====================== |
| 645 | * = skfp_ctl_get_stats = |
| 646 | * ====================== |
| 647 | * |
| 648 | * Overview: |
| 649 | * Get statistics for FDDI adapter |
| 650 | * |
| 651 | * Returns: |
| 652 | * Pointer to FDDI statistics structure |
| 653 | * |
| 654 | * Arguments: |
| 655 | * dev - pointer to device information |
| 656 | * |
| 657 | * Functional Description: |
| 658 | * Gets current MIB objects from adapter, then |
| 659 | * returns FDDI statistics structure as defined |
| 660 | * in if_fddi.h. |
| 661 | * |
| 662 | * Note: Since the FDDI statistics structure is |
| 663 | * still new and the device structure doesn't |
| 664 | * have an FDDI-specific get statistics handler, |
| 665 | * we'll return the FDDI statistics structure as |
| 666 | * a pointer to an Ethernet statistics structure. |
| 667 | * That way, at least the first part of the statistics |
| 668 | * structure can be decoded properly. |
| 669 | * We'll have to pay attention to this routine as the |
| 670 | * device structure becomes more mature and LAN media |
| 671 | * independent. |
| 672 | * |
| 673 | */ |
Hannes Eder | 409b204 | 2008-12-26 00:06:28 -0800 | [diff] [blame] | 674 | static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
| 676 | struct s_smc *bp = netdev_priv(dev); |
| 677 | |
| 678 | /* Fill the bp->stats structure with driver-maintained counters */ |
| 679 | |
| 680 | bp->os.MacStat.port_bs_flag[0] = 0x1234; |
| 681 | bp->os.MacStat.port_bs_flag[1] = 0x5678; |
| 682 | // goos: need to fill out fddi statistic |
| 683 | #if 0 |
| 684 | /* Get FDDI SMT MIB objects */ |
| 685 | |
| 686 | /* Fill the bp->stats structure with the SMT MIB object values */ |
| 687 | |
| 688 | memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id)); |
| 689 | bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id; |
| 690 | bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id; |
| 691 | bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id; |
| 692 | memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data)); |
| 693 | bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id; |
| 694 | bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct; |
| 695 | bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct; |
| 696 | bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct; |
| 697 | bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths; |
| 698 | bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities; |
| 699 | bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy; |
| 700 | bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy; |
| 701 | bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify; |
| 702 | bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy; |
| 703 | bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration; |
| 704 | bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present; |
| 705 | bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state; |
| 706 | bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state; |
| 707 | bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag; |
| 708 | bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status; |
| 709 | bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag; |
| 710 | bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls; |
| 711 | bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls; |
| 712 | bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions; |
| 713 | bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability; |
| 714 | bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability; |
| 715 | bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths; |
| 716 | bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path; |
| 717 | memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN); |
| 718 | memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN); |
| 719 | memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN); |
| 720 | memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN); |
| 721 | bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test; |
| 722 | bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths; |
| 723 | bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type; |
| 724 | memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN); |
| 725 | bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req; |
| 726 | bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg; |
| 727 | bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max; |
| 728 | bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value; |
| 729 | bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold; |
| 730 | bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio; |
| 731 | bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state; |
| 732 | bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag; |
| 733 | bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag; |
| 734 | bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag; |
| 735 | bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available; |
| 736 | bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present; |
| 737 | bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable; |
| 738 | bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound; |
| 739 | bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound; |
| 740 | bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req; |
| 741 | memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration)); |
| 742 | bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0]; |
| 743 | bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1]; |
| 744 | bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0]; |
| 745 | bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1]; |
| 746 | bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0]; |
| 747 | bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1]; |
| 748 | bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0]; |
| 749 | bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1]; |
| 750 | bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0]; |
| 751 | bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1]; |
| 752 | memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3); |
| 753 | memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3); |
| 754 | bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0]; |
| 755 | bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1]; |
| 756 | bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0]; |
| 757 | bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1]; |
| 758 | bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0]; |
| 759 | bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1]; |
| 760 | bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0]; |
| 761 | bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1]; |
| 762 | bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0]; |
| 763 | bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1]; |
| 764 | bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0]; |
| 765 | bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1]; |
| 766 | bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0]; |
| 767 | bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1]; |
| 768 | bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0]; |
| 769 | bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1]; |
| 770 | bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0]; |
| 771 | bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1]; |
| 772 | bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0]; |
| 773 | bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1]; |
| 774 | bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0]; |
| 775 | bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1]; |
| 776 | bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0]; |
| 777 | bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1]; |
| 778 | bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0]; |
| 779 | bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1]; |
| 780 | |
| 781 | |
| 782 | /* Fill the bp->stats structure with the FDDI counter values */ |
| 783 | |
| 784 | bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls; |
| 785 | bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls; |
| 786 | bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls; |
| 787 | bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls; |
| 788 | bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls; |
| 789 | bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls; |
| 790 | bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls; |
| 791 | bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls; |
| 792 | bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls; |
| 793 | bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls; |
| 794 | bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls; |
| 795 | |
| 796 | #endif |
| 797 | return ((struct net_device_stats *) &bp->os.MacStat); |
| 798 | } // ctl_get_stat |
| 799 | |
| 800 | |
| 801 | /* |
| 802 | * ============================== |
| 803 | * = skfp_ctl_set_multicast_list = |
| 804 | * ============================== |
| 805 | * |
| 806 | * Overview: |
| 807 | * Enable/Disable LLC frame promiscuous mode reception |
| 808 | * on the adapter and/or update multicast address table. |
| 809 | * |
| 810 | * Returns: |
| 811 | * None |
| 812 | * |
| 813 | * Arguments: |
| 814 | * dev - pointer to device information |
| 815 | * |
| 816 | * Functional Description: |
| 817 | * This function acquires the driver lock and only calls |
| 818 | * skfp_ctl_set_multicast_list_wo_lock then. |
| 819 | * This routine follows a fairly simple algorithm for setting the |
| 820 | * adapter filters and CAM: |
| 821 | * |
| 822 | * if IFF_PROMISC flag is set |
| 823 | * enable promiscuous mode |
| 824 | * else |
| 825 | * disable promiscuous mode |
| 826 | * if number of multicast addresses <= max. multicast number |
| 827 | * add mc addresses to adapter table |
| 828 | * else |
| 829 | * enable promiscuous mode |
| 830 | * update adapter filters |
| 831 | * |
| 832 | * Assumptions: |
| 833 | * Multicast addresses are presented in canonical (LSB) format. |
| 834 | * |
| 835 | * Side Effects: |
| 836 | * On-board adapter filters are updated. |
| 837 | */ |
| 838 | static void skfp_ctl_set_multicast_list(struct net_device *dev) |
| 839 | { |
| 840 | struct s_smc *smc = netdev_priv(dev); |
| 841 | skfddi_priv *bp = &smc->os; |
| 842 | unsigned long Flags; |
| 843 | |
| 844 | spin_lock_irqsave(&bp->DriverLock, Flags); |
| 845 | skfp_ctl_set_multicast_list_wo_lock(dev); |
| 846 | spin_unlock_irqrestore(&bp->DriverLock, Flags); |
| 847 | return; |
| 848 | } // skfp_ctl_set_multicast_list |
| 849 | |
| 850 | |
| 851 | |
| 852 | static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev) |
| 853 | { |
| 854 | struct s_smc *smc = netdev_priv(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame^] | 855 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | /* Enable promiscuous mode, if necessary */ |
| 858 | if (dev->flags & IFF_PROMISC) { |
| 859 | mac_drv_rx_mode(smc, RX_ENABLE_PROMISC); |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 860 | pr_debug(KERN_INFO "PROMISCUOUS MODE ENABLED\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | } |
| 862 | /* Else, update multicast address table */ |
| 863 | else { |
| 864 | mac_drv_rx_mode(smc, RX_DISABLE_PROMISC); |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 865 | pr_debug(KERN_INFO "PROMISCUOUS MODE DISABLED\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
| 867 | // Reset all MC addresses |
| 868 | mac_clear_multicast(smc); |
| 869 | mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI); |
| 870 | |
| 871 | if (dev->flags & IFF_ALLMULTI) { |
| 872 | mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI); |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 873 | pr_debug(KERN_INFO "ENABLE ALL MC ADDRESSES\n"); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 874 | } else if (!netdev_mc_empty(dev)) { |
| 875 | if (netdev_mc_count(dev) <= FPMAX_MULTICAST) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | /* use exact filtering */ |
| 877 | |
| 878 | // point to first multicast addr |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame^] | 879 | netdev_for_each_mc_addr(ha, dev) { |
| 880 | mac_add_multicast(smc, |
| 881 | (struct fddi_addr *)ha->addr, |
| 882 | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
hartleys | 596a530 | 2010-01-07 13:27:46 +0000 | [diff] [blame] | 884 | pr_debug(KERN_INFO "ENABLE MC ADDRESS: %pMF\n", |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame^] | 885 | ha->addr); |
Jiri Pirko | 5508590 | 2010-02-18 00:42:54 +0000 | [diff] [blame] | 886 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
| 888 | } else { // more MC addresses than HW supports |
| 889 | |
| 890 | mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI); |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 891 | pr_debug(KERN_INFO "ENABLE ALL MC ADDRESSES\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | } else { // no MC addresses |
| 894 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 895 | pr_debug(KERN_INFO "DISABLE ALL MC ADDRESSES\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /* Update adapter filters */ |
| 899 | mac_update_multicast(smc); |
| 900 | } |
| 901 | return; |
| 902 | } // skfp_ctl_set_multicast_list_wo_lock |
| 903 | |
| 904 | |
| 905 | /* |
| 906 | * =========================== |
| 907 | * = skfp_ctl_set_mac_address = |
| 908 | * =========================== |
| 909 | * |
| 910 | * Overview: |
| 911 | * set new mac address on adapter and update dev_addr field in device table. |
| 912 | * |
| 913 | * Returns: |
| 914 | * None |
| 915 | * |
| 916 | * Arguments: |
| 917 | * dev - pointer to device information |
| 918 | * addr - pointer to sockaddr structure containing unicast address to set |
| 919 | * |
| 920 | * Assumptions: |
| 921 | * The address pointed to by addr->sa_data is a valid unicast |
| 922 | * address and is presented in canonical (LSB) format. |
| 923 | */ |
| 924 | static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr) |
| 925 | { |
| 926 | struct s_smc *smc = netdev_priv(dev); |
| 927 | struct sockaddr *p_sockaddr = (struct sockaddr *) addr; |
| 928 | skfddi_priv *bp = &smc->os; |
| 929 | unsigned long Flags; |
| 930 | |
| 931 | |
| 932 | memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN); |
| 933 | spin_lock_irqsave(&bp->DriverLock, Flags); |
| 934 | ResetAdapter(smc); |
| 935 | spin_unlock_irqrestore(&bp->DriverLock, Flags); |
| 936 | |
| 937 | return (0); /* always return zero */ |
| 938 | } // skfp_ctl_set_mac_address |
| 939 | |
| 940 | |
| 941 | /* |
| 942 | * ============== |
| 943 | * = skfp_ioctl = |
| 944 | * ============== |
| 945 | * |
| 946 | * Overview: |
| 947 | * |
| 948 | * Perform IOCTL call functions here. Some are privileged operations and the |
| 949 | * effective uid is checked in those cases. |
| 950 | * |
| 951 | * Returns: |
| 952 | * status value |
| 953 | * 0 - success |
| 954 | * other - failure |
| 955 | * |
| 956 | * Arguments: |
| 957 | * dev - pointer to device information |
| 958 | * rq - pointer to ioctl request structure |
| 959 | * cmd - ? |
| 960 | * |
| 961 | */ |
| 962 | |
| 963 | |
| 964 | static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 965 | { |
| 966 | struct s_smc *smc = netdev_priv(dev); |
| 967 | skfddi_priv *lp = &smc->os; |
| 968 | struct s_skfp_ioctl ioc; |
| 969 | int status = 0; |
| 970 | |
| 971 | if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl))) |
| 972 | return -EFAULT; |
| 973 | |
| 974 | switch (ioc.cmd) { |
| 975 | case SKFP_GET_STATS: /* Get the driver statistics */ |
| 976 | ioc.len = sizeof(lp->MacStat); |
| 977 | status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len) |
| 978 | ? -EFAULT : 0; |
| 979 | break; |
| 980 | case SKFP_CLR_STATS: /* Zero out the driver statistics */ |
| 981 | if (!capable(CAP_NET_ADMIN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | status = -EPERM; |
Roel Kluin | c25b9ab | 2009-01-29 17:32:20 -0800 | [diff] [blame] | 983 | } else { |
| 984 | memset(&lp->MacStat, 0, sizeof(lp->MacStat)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | } |
| 986 | break; |
| 987 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 988 | printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | status = -EOPNOTSUPP; |
| 990 | |
| 991 | } // switch |
| 992 | |
| 993 | return status; |
| 994 | } // skfp_ioctl |
| 995 | |
| 996 | |
| 997 | /* |
| 998 | * ===================== |
| 999 | * = skfp_send_pkt = |
| 1000 | * ===================== |
| 1001 | * |
| 1002 | * Overview: |
| 1003 | * Queues a packet for transmission and try to transmit it. |
| 1004 | * |
| 1005 | * Returns: |
| 1006 | * Condition code |
| 1007 | * |
| 1008 | * Arguments: |
| 1009 | * skb - pointer to sk_buff to queue for transmission |
| 1010 | * dev - pointer to device information |
| 1011 | * |
| 1012 | * Functional Description: |
| 1013 | * Here we assume that an incoming skb transmit request |
| 1014 | * is contained in a single physically contiguous buffer |
| 1015 | * in which the virtual address of the start of packet |
| 1016 | * (skb->data) can be converted to a physical address |
| 1017 | * by using pci_map_single(). |
| 1018 | * |
| 1019 | * We have an internal queue for packets we can not send |
| 1020 | * immediately. Packets in this queue can be given to the |
| 1021 | * adapter if transmit buffers are freed. |
| 1022 | * |
| 1023 | * We can't free the skb until after it's been DMA'd |
| 1024 | * out by the adapter, so we'll keep it in the driver and |
| 1025 | * return it in mac_drv_tx_complete. |
| 1026 | * |
| 1027 | * Return Codes: |
| 1028 | * 0 - driver has queued and/or sent packet |
| 1029 | * 1 - caller should requeue the sk_buff for later transmission |
| 1030 | * |
| 1031 | * Assumptions: |
| 1032 | * The entire packet is stored in one physically |
| 1033 | * contiguous buffer which is not cached and whose |
| 1034 | * 32-bit physical address can be determined. |
| 1035 | * |
| 1036 | * It's vital that this routine is NOT reentered for the |
| 1037 | * same board and that the OS is not in another section of |
| 1038 | * code (eg. skfp_interrupt) for the same board on a |
| 1039 | * different thread. |
| 1040 | * |
| 1041 | * Side Effects: |
| 1042 | * None |
| 1043 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 1044 | static netdev_tx_t skfp_send_pkt(struct sk_buff *skb, |
| 1045 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | { |
| 1047 | struct s_smc *smc = netdev_priv(dev); |
| 1048 | skfddi_priv *bp = &smc->os; |
| 1049 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1050 | pr_debug(KERN_INFO "skfp_send_pkt\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
| 1052 | /* |
| 1053 | * Verify that incoming transmit request is OK |
| 1054 | * |
| 1055 | * Note: The packet size check is consistent with other |
| 1056 | * Linux device drivers, although the correct packet |
| 1057 | * size should be verified before calling the |
| 1058 | * transmit routine. |
| 1059 | */ |
| 1060 | |
| 1061 | if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) { |
| 1062 | bp->MacStat.gen.tx_errors++; /* bump error counter */ |
| 1063 | // dequeue packets from xmt queue and send them |
| 1064 | netif_start_queue(dev); |
| 1065 | dev_kfree_skb(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1066 | return NETDEV_TX_OK; /* return "success" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
| 1068 | if (bp->QueueSkb == 0) { // return with tbusy set: queue full |
| 1069 | |
| 1070 | netif_stop_queue(dev); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1071 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | } |
| 1073 | bp->QueueSkb--; |
| 1074 | skb_queue_tail(&bp->SendSkbQueue, skb); |
| 1075 | send_queued_packets(netdev_priv(dev)); |
| 1076 | if (bp->QueueSkb == 0) { |
| 1077 | netif_stop_queue(dev); |
| 1078 | } |
| 1079 | dev->trans_start = jiffies; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1080 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| 1082 | } // skfp_send_pkt |
| 1083 | |
| 1084 | |
| 1085 | /* |
| 1086 | * ======================= |
| 1087 | * = send_queued_packets = |
| 1088 | * ======================= |
| 1089 | * |
| 1090 | * Overview: |
| 1091 | * Send packets from the driver queue as long as there are some and |
| 1092 | * transmit resources are available. |
| 1093 | * |
| 1094 | * Returns: |
| 1095 | * None |
| 1096 | * |
| 1097 | * Arguments: |
| 1098 | * smc - pointer to smc (adapter) structure |
| 1099 | * |
| 1100 | * Functional Description: |
| 1101 | * Take a packet from queue if there is any. If not, then we are done. |
| 1102 | * Check if there are resources to send the packet. If not, requeue it |
| 1103 | * and exit. |
| 1104 | * Set packet descriptor flags and give packet to adapter. |
| 1105 | * Check if any send resources can be freed (we do not use the |
| 1106 | * transmit complete interrupt). |
| 1107 | */ |
| 1108 | static void send_queued_packets(struct s_smc *smc) |
| 1109 | { |
| 1110 | skfddi_priv *bp = &smc->os; |
| 1111 | struct sk_buff *skb; |
| 1112 | unsigned char fc; |
| 1113 | int queue; |
| 1114 | struct s_smt_fp_txd *txd; // Current TxD. |
| 1115 | dma_addr_t dma_address; |
| 1116 | unsigned long Flags; |
| 1117 | |
| 1118 | int frame_status; // HWM tx frame status. |
| 1119 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1120 | pr_debug(KERN_INFO "send queued packets\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | for (;;) { |
| 1122 | // send first buffer from queue |
| 1123 | skb = skb_dequeue(&bp->SendSkbQueue); |
| 1124 | |
| 1125 | if (!skb) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1126 | pr_debug(KERN_INFO "queue empty\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | return; |
| 1128 | } // queue empty ! |
| 1129 | |
| 1130 | spin_lock_irqsave(&bp->DriverLock, Flags); |
| 1131 | fc = skb->data[0]; |
| 1132 | queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0; |
| 1133 | #ifdef ESS |
| 1134 | // Check if the frame may/must be sent as a synchronous frame. |
| 1135 | |
| 1136 | if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) { |
| 1137 | // It's an LLC frame. |
| 1138 | if (!smc->ess.sync_bw_available) |
| 1139 | fc &= ~FC_SYNC_BIT; // No bandwidth available. |
| 1140 | |
| 1141 | else { // Bandwidth is available. |
| 1142 | |
| 1143 | if (smc->mib.fddiESSSynchTxMode) { |
| 1144 | // Send as sync. frame. |
| 1145 | fc |= FC_SYNC_BIT; |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | #endif // ESS |
| 1150 | frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue); |
| 1151 | |
| 1152 | if ((frame_status & (LOC_TX | LAN_TX)) == 0) { |
| 1153 | // Unable to send the frame. |
| 1154 | |
| 1155 | if ((frame_status & RING_DOWN) != 0) { |
| 1156 | // Ring is down. |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1157 | pr_debug("Tx attempt while ring down.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } else if ((frame_status & OUT_OF_TXD) != 0) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1159 | pr_debug("%s: out of TXDs.\n", bp->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } else { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1161 | pr_debug("%s: out of transmit resources", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | bp->dev->name); |
| 1163 | } |
| 1164 | |
| 1165 | // Note: We will retry the operation as soon as |
| 1166 | // transmit resources become available. |
| 1167 | skb_queue_head(&bp->SendSkbQueue, skb); |
| 1168 | spin_unlock_irqrestore(&bp->DriverLock, Flags); |
| 1169 | return; // Packet has been queued. |
| 1170 | |
| 1171 | } // if (unable to send frame) |
| 1172 | |
| 1173 | bp->QueueSkb++; // one packet less in local queue |
| 1174 | |
| 1175 | // source address in packet ? |
| 1176 | CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a); |
| 1177 | |
| 1178 | txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue); |
| 1179 | |
| 1180 | dma_address = pci_map_single(&bp->pdev, skb->data, |
| 1181 | skb->len, PCI_DMA_TODEVICE); |
| 1182 | if (frame_status & LAN_TX) { |
| 1183 | txd->txd_os.skb = skb; // save skb |
| 1184 | txd->txd_os.dma_addr = dma_address; // save dma mapping |
| 1185 | } |
| 1186 | hwm_tx_frag(smc, skb->data, dma_address, skb->len, |
| 1187 | frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF); |
| 1188 | |
| 1189 | if (!(frame_status & LAN_TX)) { // local only frame |
| 1190 | pci_unmap_single(&bp->pdev, dma_address, |
| 1191 | skb->len, PCI_DMA_TODEVICE); |
| 1192 | dev_kfree_skb_irq(skb); |
| 1193 | } |
| 1194 | spin_unlock_irqrestore(&bp->DriverLock, Flags); |
| 1195 | } // for |
| 1196 | |
| 1197 | return; // never reached |
| 1198 | |
| 1199 | } // send_queued_packets |
| 1200 | |
| 1201 | |
| 1202 | /************************ |
| 1203 | * |
| 1204 | * CheckSourceAddress |
| 1205 | * |
| 1206 | * Verify if the source address is set. Insert it if necessary. |
| 1207 | * |
| 1208 | ************************/ |
Hannes Eder | 409b204 | 2008-12-26 00:06:28 -0800 | [diff] [blame] | 1209 | static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | { |
| 1211 | unsigned char SRBit; |
| 1212 | |
| 1213 | if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit |
| 1214 | |
| 1215 | return; |
| 1216 | if ((unsigned short) frame[1 + 10] != 0) |
| 1217 | return; |
| 1218 | SRBit = frame[1 + 6] & 0x01; |
| 1219 | memcpy(&frame[1 + 6], hw_addr, 6); |
| 1220 | frame[8] |= SRBit; |
| 1221 | } // CheckSourceAddress |
| 1222 | |
| 1223 | |
| 1224 | /************************ |
| 1225 | * |
| 1226 | * ResetAdapter |
| 1227 | * |
| 1228 | * Reset the adapter and bring it back to operational mode. |
| 1229 | * Args |
| 1230 | * smc - A pointer to the SMT context struct. |
| 1231 | * Out |
| 1232 | * Nothing. |
| 1233 | * |
| 1234 | ************************/ |
| 1235 | static void ResetAdapter(struct s_smc *smc) |
| 1236 | { |
| 1237 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1238 | pr_debug(KERN_INFO "[fddi: ResetAdapter]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | // Stop the adapter. |
| 1241 | |
| 1242 | card_stop(smc); // Stop all activity. |
| 1243 | |
| 1244 | // Clear the transmit and receive descriptor queues. |
| 1245 | mac_drv_clear_tx_queue(smc); |
| 1246 | mac_drv_clear_rx_queue(smc); |
| 1247 | |
| 1248 | // Restart the adapter. |
| 1249 | |
| 1250 | smt_reset_defaults(smc, 1); // Initialize the SMT module. |
| 1251 | |
| 1252 | init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware. |
| 1253 | |
| 1254 | smt_online(smc, 1); // Insert into the ring again. |
| 1255 | STI_FBI(); |
| 1256 | |
| 1257 | // Restore original receive mode (multicasts, promiscuous, etc.). |
| 1258 | skfp_ctl_set_multicast_list_wo_lock(smc->os.dev); |
| 1259 | } // ResetAdapter |
| 1260 | |
| 1261 | |
| 1262 | //--------------- functions called by hardware module ---------------- |
| 1263 | |
| 1264 | /************************ |
| 1265 | * |
| 1266 | * llc_restart_tx |
| 1267 | * |
| 1268 | * The hardware driver calls this routine when the transmit complete |
| 1269 | * interrupt bits (end of frame) for the synchronous or asynchronous |
| 1270 | * queue is set. |
| 1271 | * |
| 1272 | * NOTE The hardware driver calls this function also if no packets are queued. |
| 1273 | * The routine must be able to handle this case. |
| 1274 | * Args |
| 1275 | * smc - A pointer to the SMT context struct. |
| 1276 | * Out |
| 1277 | * Nothing. |
| 1278 | * |
| 1279 | ************************/ |
| 1280 | void llc_restart_tx(struct s_smc *smc) |
| 1281 | { |
| 1282 | skfddi_priv *bp = &smc->os; |
| 1283 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1284 | pr_debug(KERN_INFO "[llc_restart_tx]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
| 1286 | // Try to send queued packets |
| 1287 | spin_unlock(&bp->DriverLock); |
| 1288 | send_queued_packets(smc); |
| 1289 | spin_lock(&bp->DriverLock); |
| 1290 | netif_start_queue(bp->dev);// system may send again if it was blocked |
| 1291 | |
| 1292 | } // llc_restart_tx |
| 1293 | |
| 1294 | |
| 1295 | /************************ |
| 1296 | * |
| 1297 | * mac_drv_get_space |
| 1298 | * |
| 1299 | * The hardware module calls this function to allocate the memory |
| 1300 | * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified. |
| 1301 | * Args |
| 1302 | * smc - A pointer to the SMT context struct. |
| 1303 | * |
| 1304 | * size - Size of memory in bytes to allocate. |
| 1305 | * Out |
| 1306 | * != 0 A pointer to the virtual address of the allocated memory. |
| 1307 | * == 0 Allocation error. |
| 1308 | * |
| 1309 | ************************/ |
| 1310 | void *mac_drv_get_space(struct s_smc *smc, unsigned int size) |
| 1311 | { |
| 1312 | void *virt; |
| 1313 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1314 | pr_debug(KERN_INFO "mac_drv_get_space (%d bytes), ", size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap); |
| 1316 | |
| 1317 | if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) { |
| 1318 | printk("Unexpected SMT memory size requested: %d\n", size); |
| 1319 | return (NULL); |
| 1320 | } |
| 1321 | smc->os.SharedMemHeap += size; // Move heap pointer. |
| 1322 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1323 | pr_debug(KERN_INFO "mac_drv_get_space end\n"); |
| 1324 | pr_debug(KERN_INFO "virt addr: %lx\n", (ulong) virt); |
| 1325 | pr_debug(KERN_INFO "bus addr: %lx\n", (ulong) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | (smc->os.SharedMemDMA + |
| 1327 | ((char *) virt - (char *)smc->os.SharedMemAddr))); |
| 1328 | return (virt); |
| 1329 | } // mac_drv_get_space |
| 1330 | |
| 1331 | |
| 1332 | /************************ |
| 1333 | * |
| 1334 | * mac_drv_get_desc_mem |
| 1335 | * |
| 1336 | * This function is called by the hardware dependent module. |
| 1337 | * It allocates the memory for the RxD and TxD descriptors. |
| 1338 | * |
| 1339 | * This memory must be non-cached, non-movable and non-swappable. |
| 1340 | * This memory should start at a physical page boundary. |
| 1341 | * Args |
| 1342 | * smc - A pointer to the SMT context struct. |
| 1343 | * |
| 1344 | * size - Size of memory in bytes to allocate. |
| 1345 | * Out |
| 1346 | * != 0 A pointer to the virtual address of the allocated memory. |
| 1347 | * == 0 Allocation error. |
| 1348 | * |
| 1349 | ************************/ |
| 1350 | void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size) |
| 1351 | { |
| 1352 | |
| 1353 | char *virt; |
| 1354 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1355 | pr_debug(KERN_INFO "mac_drv_get_desc_mem\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
| 1357 | // Descriptor memory must be aligned on 16-byte boundary. |
| 1358 | |
| 1359 | virt = mac_drv_get_space(smc, size); |
| 1360 | |
| 1361 | size = (u_int) (16 - (((unsigned long) virt) & 15UL)); |
| 1362 | size = size % 16; |
| 1363 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1364 | pr_debug("Allocate %u bytes alignment gap ", size); |
| 1365 | pr_debug("for descriptor memory.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
| 1367 | if (!mac_drv_get_space(smc, size)) { |
| 1368 | printk("fddi: Unable to align descriptor memory.\n"); |
| 1369 | return (NULL); |
| 1370 | } |
| 1371 | return (virt + size); |
| 1372 | } // mac_drv_get_desc_mem |
| 1373 | |
| 1374 | |
| 1375 | /************************ |
| 1376 | * |
| 1377 | * mac_drv_virt2phys |
| 1378 | * |
| 1379 | * Get the physical address of a given virtual address. |
| 1380 | * Args |
| 1381 | * smc - A pointer to the SMT context struct. |
| 1382 | * |
| 1383 | * virt - A (virtual) pointer into our 'shared' memory area. |
| 1384 | * Out |
| 1385 | * Physical address of the given virtual address. |
| 1386 | * |
| 1387 | ************************/ |
| 1388 | unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt) |
| 1389 | { |
| 1390 | return (smc->os.SharedMemDMA + |
| 1391 | ((char *) virt - (char *)smc->os.SharedMemAddr)); |
| 1392 | } // mac_drv_virt2phys |
| 1393 | |
| 1394 | |
| 1395 | /************************ |
| 1396 | * |
| 1397 | * dma_master |
| 1398 | * |
| 1399 | * The HWM calls this function, when the driver leads through a DMA |
| 1400 | * transfer. If the OS-specific module must prepare the system hardware |
| 1401 | * for the DMA transfer, it should do it in this function. |
| 1402 | * |
| 1403 | * The hardware module calls this dma_master if it wants to send an SMT |
| 1404 | * frame. This means that the virt address passed in here is part of |
| 1405 | * the 'shared' memory area. |
| 1406 | * Args |
| 1407 | * smc - A pointer to the SMT context struct. |
| 1408 | * |
| 1409 | * virt - The virtual address of the data. |
| 1410 | * |
| 1411 | * len - The length in bytes of the data. |
| 1412 | * |
| 1413 | * flag - Indicates the transmit direction and the buffer type: |
| 1414 | * DMA_RD (0x01) system RAM ==> adapter buffer memory |
| 1415 | * DMA_WR (0x02) adapter buffer memory ==> system RAM |
| 1416 | * SMT_BUF (0x80) SMT buffer |
| 1417 | * |
| 1418 | * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. << |
| 1419 | * Out |
| 1420 | * Returns the pyhsical address for the DMA transfer. |
| 1421 | * |
| 1422 | ************************/ |
| 1423 | u_long dma_master(struct s_smc * smc, void *virt, int len, int flag) |
| 1424 | { |
| 1425 | return (smc->os.SharedMemDMA + |
| 1426 | ((char *) virt - (char *)smc->os.SharedMemAddr)); |
| 1427 | } // dma_master |
| 1428 | |
| 1429 | |
| 1430 | /************************ |
| 1431 | * |
| 1432 | * dma_complete |
| 1433 | * |
| 1434 | * The hardware module calls this routine when it has completed a DMA |
| 1435 | * transfer. If the operating system dependent module has set up the DMA |
| 1436 | * channel via dma_master() (e.g. Windows NT or AIX) it should clean up |
| 1437 | * the DMA channel. |
| 1438 | * Args |
| 1439 | * smc - A pointer to the SMT context struct. |
| 1440 | * |
| 1441 | * descr - A pointer to a TxD or RxD, respectively. |
| 1442 | * |
| 1443 | * flag - Indicates the DMA transfer direction / SMT buffer: |
| 1444 | * DMA_RD (0x01) system RAM ==> adapter buffer memory |
| 1445 | * DMA_WR (0x02) adapter buffer memory ==> system RAM |
| 1446 | * SMT_BUF (0x80) SMT buffer (managed by HWM) |
| 1447 | * Out |
| 1448 | * Nothing. |
| 1449 | * |
| 1450 | ************************/ |
| 1451 | void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag) |
| 1452 | { |
| 1453 | /* For TX buffers, there are two cases. If it is an SMT transmit |
| 1454 | * buffer, there is nothing to do since we use consistent memory |
| 1455 | * for the 'shared' memory area. The other case is for normal |
| 1456 | * transmit packets given to us by the networking stack, and in |
| 1457 | * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete |
| 1458 | * below. |
| 1459 | * |
| 1460 | * For RX buffers, we have to unmap dynamic PCI DMA mappings here |
| 1461 | * because the hardware module is about to potentially look at |
| 1462 | * the contents of the buffer. If we did not call the PCI DMA |
| 1463 | * unmap first, the hardware module could read inconsistent data. |
| 1464 | */ |
| 1465 | if (flag & DMA_WR) { |
| 1466 | skfddi_priv *bp = &smc->os; |
| 1467 | volatile struct s_smt_fp_rxd *r = &descr->r; |
| 1468 | |
| 1469 | /* If SKB is NULL, we used the local buffer. */ |
| 1470 | if (r->rxd_os.skb && r->rxd_os.dma_addr) { |
| 1471 | int MaxFrameSize = bp->MaxFrameSize; |
| 1472 | |
| 1473 | pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr, |
| 1474 | MaxFrameSize, PCI_DMA_FROMDEVICE); |
| 1475 | r->rxd_os.dma_addr = 0; |
| 1476 | } |
| 1477 | } |
| 1478 | } // dma_complete |
| 1479 | |
| 1480 | |
| 1481 | /************************ |
| 1482 | * |
| 1483 | * mac_drv_tx_complete |
| 1484 | * |
| 1485 | * Transmit of a packet is complete. Release the tx staging buffer. |
| 1486 | * |
| 1487 | * Args |
| 1488 | * smc - A pointer to the SMT context struct. |
| 1489 | * |
| 1490 | * txd - A pointer to the last TxD which is used by the frame. |
| 1491 | * Out |
| 1492 | * Returns nothing. |
| 1493 | * |
| 1494 | ************************/ |
| 1495 | void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd) |
| 1496 | { |
| 1497 | struct sk_buff *skb; |
| 1498 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1499 | pr_debug(KERN_INFO "entering mac_drv_tx_complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | // Check if this TxD points to a skb |
| 1501 | |
| 1502 | if (!(skb = txd->txd_os.skb)) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1503 | pr_debug("TXD with no skb assigned.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | return; |
| 1505 | } |
| 1506 | txd->txd_os.skb = NULL; |
| 1507 | |
| 1508 | // release the DMA mapping |
| 1509 | pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr, |
| 1510 | skb->len, PCI_DMA_TODEVICE); |
| 1511 | txd->txd_os.dma_addr = 0; |
| 1512 | |
| 1513 | smc->os.MacStat.gen.tx_packets++; // Count transmitted packets. |
| 1514 | smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes |
| 1515 | |
| 1516 | // free the skb |
| 1517 | dev_kfree_skb_irq(skb); |
| 1518 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1519 | pr_debug(KERN_INFO "leaving mac_drv_tx_complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | } // mac_drv_tx_complete |
| 1521 | |
| 1522 | |
| 1523 | /************************ |
| 1524 | * |
| 1525 | * dump packets to logfile |
| 1526 | * |
| 1527 | ************************/ |
| 1528 | #ifdef DUMPPACKETS |
| 1529 | void dump_data(unsigned char *Data, int length) |
| 1530 | { |
| 1531 | int i, j; |
| 1532 | unsigned char s[255], sh[10]; |
| 1533 | if (length > 64) { |
| 1534 | length = 64; |
| 1535 | } |
| 1536 | printk(KERN_INFO "---Packet start---\n"); |
| 1537 | for (i = 0, j = 0; i < length / 8; i++, j += 8) |
| 1538 | printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 1539 | Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3], |
| 1540 | Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]); |
| 1541 | strcpy(s, ""); |
| 1542 | for (i = 0; i < length % 8; i++) { |
| 1543 | sprintf(sh, "%02x ", Data[j + i]); |
| 1544 | strcat(s, sh); |
| 1545 | } |
| 1546 | printk(KERN_INFO "%s\n", s); |
| 1547 | printk(KERN_INFO "------------------\n"); |
| 1548 | } // dump_data |
| 1549 | #else |
| 1550 | #define dump_data(data,len) |
| 1551 | #endif // DUMPPACKETS |
| 1552 | |
| 1553 | /************************ |
| 1554 | * |
| 1555 | * mac_drv_rx_complete |
| 1556 | * |
| 1557 | * The hardware module calls this function if an LLC frame is received |
| 1558 | * in a receive buffer. Also the SMT, NSA, and directed beacon frames |
| 1559 | * from the network will be passed to the LLC layer by this function |
| 1560 | * if passing is enabled. |
| 1561 | * |
| 1562 | * mac_drv_rx_complete forwards the frame to the LLC layer if it should |
| 1563 | * be received. It also fills the RxD ring with new receive buffers if |
| 1564 | * some can be queued. |
| 1565 | * Args |
| 1566 | * smc - A pointer to the SMT context struct. |
| 1567 | * |
| 1568 | * rxd - A pointer to the first RxD which is used by the receive frame. |
| 1569 | * |
| 1570 | * frag_count - Count of RxDs used by the received frame. |
| 1571 | * |
| 1572 | * len - Frame length. |
| 1573 | * Out |
| 1574 | * Nothing. |
| 1575 | * |
| 1576 | ************************/ |
| 1577 | void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd, |
| 1578 | int frag_count, int len) |
| 1579 | { |
| 1580 | skfddi_priv *bp = &smc->os; |
| 1581 | struct sk_buff *skb; |
| 1582 | unsigned char *virt, *cp; |
| 1583 | unsigned short ri; |
| 1584 | u_int RifLength; |
| 1585 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1586 | pr_debug(KERN_INFO "entering mac_drv_rx_complete (len=%d)\n", len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | if (frag_count != 1) { // This is not allowed to happen. |
| 1588 | |
| 1589 | printk("fddi: Multi-fragment receive!\n"); |
| 1590 | goto RequeueRxd; // Re-use the given RXD(s). |
| 1591 | |
| 1592 | } |
| 1593 | skb = rxd->rxd_os.skb; |
| 1594 | if (!skb) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1595 | pr_debug(KERN_INFO "No skb in rxd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | smc->os.MacStat.gen.rx_errors++; |
| 1597 | goto RequeueRxd; |
| 1598 | } |
| 1599 | virt = skb->data; |
| 1600 | |
| 1601 | // The DMA mapping was released in dma_complete above. |
| 1602 | |
| 1603 | dump_data(skb->data, len); |
| 1604 | |
| 1605 | /* |
| 1606 | * FDDI Frame format: |
| 1607 | * +-------+-------+-------+------------+--------+------------+ |
| 1608 | * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] | |
| 1609 | * +-------+-------+-------+------------+--------+------------+ |
| 1610 | * |
| 1611 | * FC = Frame Control |
| 1612 | * DA = Destination Address |
| 1613 | * SA = Source Address |
| 1614 | * RIF = Routing Information Field |
| 1615 | * LLC = Logical Link Control |
| 1616 | */ |
| 1617 | |
| 1618 | // Remove Routing Information Field (RIF), if present. |
| 1619 | |
| 1620 | if ((virt[1 + 6] & FDDI_RII) == 0) |
| 1621 | RifLength = 0; |
| 1622 | else { |
| 1623 | int n; |
| 1624 | // goos: RIF removal has still to be tested |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1625 | pr_debug(KERN_INFO "RIF found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | // Get RIF length from Routing Control (RC) field. |
| 1627 | cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header. |
| 1628 | |
Al Viro | 2f220e3 | 2008-03-16 22:22:24 +0000 | [diff] [blame] | 1629 | ri = ntohs(*((__be16 *) cp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | RifLength = ri & FDDI_RCF_LEN_MASK; |
| 1631 | if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) { |
| 1632 | printk("fddi: Invalid RIF.\n"); |
| 1633 | goto RequeueRxd; // Discard the frame. |
| 1634 | |
| 1635 | } |
| 1636 | virt[1 + 6] &= ~FDDI_RII; // Clear RII bit. |
| 1637 | // regions overlap |
| 1638 | |
| 1639 | virt = cp + RifLength; |
| 1640 | for (n = FDDI_MAC_HDR_LEN; n; n--) |
| 1641 | *--virt = *--cp; |
| 1642 | // adjust sbd->data pointer |
| 1643 | skb_pull(skb, RifLength); |
| 1644 | len -= RifLength; |
| 1645 | RifLength = 0; |
| 1646 | } |
| 1647 | |
| 1648 | // Count statistics. |
| 1649 | smc->os.MacStat.gen.rx_packets++; // Count indicated receive |
| 1650 | // packets. |
| 1651 | smc->os.MacStat.gen.rx_bytes+=len; // Count bytes. |
| 1652 | |
| 1653 | // virt points to header again |
| 1654 | if (virt[1] & 0x01) { // Check group (multicast) bit. |
| 1655 | |
| 1656 | smc->os.MacStat.gen.multicast++; |
| 1657 | } |
| 1658 | |
| 1659 | // deliver frame to system |
| 1660 | rxd->rxd_os.skb = NULL; |
| 1661 | skb_trim(skb, len); |
| 1662 | skb->protocol = fddi_type_trans(skb, bp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
| 1664 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
| 1666 | HWM_RX_CHECK(smc, RX_LOW_WATERMARK); |
| 1667 | return; |
| 1668 | |
| 1669 | RequeueRxd: |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1670 | pr_debug(KERN_INFO "Rx: re-queue RXD.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | mac_drv_requeue_rxd(smc, rxd, frag_count); |
| 1672 | smc->os.MacStat.gen.rx_errors++; // Count receive packets |
| 1673 | // not indicated. |
| 1674 | |
| 1675 | } // mac_drv_rx_complete |
| 1676 | |
| 1677 | |
| 1678 | /************************ |
| 1679 | * |
| 1680 | * mac_drv_requeue_rxd |
| 1681 | * |
| 1682 | * The hardware module calls this function to request the OS-specific |
| 1683 | * module to queue the receive buffer(s) represented by the pointer |
| 1684 | * to the RxD and the frag_count into the receive queue again. This |
| 1685 | * buffer was filled with an invalid frame or an SMT frame. |
| 1686 | * Args |
| 1687 | * smc - A pointer to the SMT context struct. |
| 1688 | * |
| 1689 | * rxd - A pointer to the first RxD which is used by the receive frame. |
| 1690 | * |
| 1691 | * frag_count - Count of RxDs used by the received frame. |
| 1692 | * Out |
| 1693 | * Nothing. |
| 1694 | * |
| 1695 | ************************/ |
| 1696 | void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd, |
| 1697 | int frag_count) |
| 1698 | { |
| 1699 | volatile struct s_smt_fp_rxd *next_rxd; |
| 1700 | volatile struct s_smt_fp_rxd *src_rxd; |
| 1701 | struct sk_buff *skb; |
| 1702 | int MaxFrameSize; |
| 1703 | unsigned char *v_addr; |
| 1704 | dma_addr_t b_addr; |
| 1705 | |
| 1706 | if (frag_count != 1) // This is not allowed to happen. |
| 1707 | |
| 1708 | printk("fddi: Multi-fragment requeue!\n"); |
| 1709 | |
| 1710 | MaxFrameSize = smc->os.MaxFrameSize; |
| 1711 | src_rxd = rxd; |
| 1712 | for (; frag_count > 0; frag_count--) { |
| 1713 | next_rxd = src_rxd->rxd_next; |
| 1714 | rxd = HWM_GET_CURR_RXD(smc); |
| 1715 | |
| 1716 | skb = src_rxd->rxd_os.skb; |
| 1717 | if (skb == NULL) { // this should not happen |
| 1718 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1719 | pr_debug("Requeue with no skb in rxd!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC); |
| 1721 | if (skb) { |
| 1722 | // we got a skb |
| 1723 | rxd->rxd_os.skb = skb; |
| 1724 | skb_reserve(skb, 3); |
| 1725 | skb_put(skb, MaxFrameSize); |
| 1726 | v_addr = skb->data; |
| 1727 | b_addr = pci_map_single(&smc->os.pdev, |
| 1728 | v_addr, |
| 1729 | MaxFrameSize, |
| 1730 | PCI_DMA_FROMDEVICE); |
| 1731 | rxd->rxd_os.dma_addr = b_addr; |
| 1732 | } else { |
| 1733 | // no skb available, use local buffer |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1734 | pr_debug("Queueing invalid buffer!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | rxd->rxd_os.skb = NULL; |
| 1736 | v_addr = smc->os.LocalRxBuffer; |
| 1737 | b_addr = smc->os.LocalRxBufferDMA; |
| 1738 | } |
| 1739 | } else { |
| 1740 | // we use skb from old rxd |
| 1741 | rxd->rxd_os.skb = skb; |
| 1742 | v_addr = skb->data; |
| 1743 | b_addr = pci_map_single(&smc->os.pdev, |
| 1744 | v_addr, |
| 1745 | MaxFrameSize, |
| 1746 | PCI_DMA_FROMDEVICE); |
| 1747 | rxd->rxd_os.dma_addr = b_addr; |
| 1748 | } |
| 1749 | hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize, |
| 1750 | FIRST_FRAG | LAST_FRAG); |
| 1751 | |
| 1752 | src_rxd = next_rxd; |
| 1753 | } |
| 1754 | } // mac_drv_requeue_rxd |
| 1755 | |
| 1756 | |
| 1757 | /************************ |
| 1758 | * |
| 1759 | * mac_drv_fill_rxd |
| 1760 | * |
| 1761 | * The hardware module calls this function at initialization time |
| 1762 | * to fill the RxD ring with receive buffers. It is also called by |
| 1763 | * mac_drv_rx_complete if rx_free is large enough to queue some new |
| 1764 | * receive buffers into the RxD ring. mac_drv_fill_rxd queues new |
| 1765 | * receive buffers as long as enough RxDs and receive buffers are |
| 1766 | * available. |
| 1767 | * Args |
| 1768 | * smc - A pointer to the SMT context struct. |
| 1769 | * Out |
| 1770 | * Nothing. |
| 1771 | * |
| 1772 | ************************/ |
| 1773 | void mac_drv_fill_rxd(struct s_smc *smc) |
| 1774 | { |
| 1775 | int MaxFrameSize; |
| 1776 | unsigned char *v_addr; |
| 1777 | unsigned long b_addr; |
| 1778 | struct sk_buff *skb; |
| 1779 | volatile struct s_smt_fp_rxd *rxd; |
| 1780 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1781 | pr_debug(KERN_INFO "entering mac_drv_fill_rxd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | |
| 1783 | // Walk through the list of free receive buffers, passing receive |
| 1784 | // buffers to the HWM as long as RXDs are available. |
| 1785 | |
| 1786 | MaxFrameSize = smc->os.MaxFrameSize; |
| 1787 | // Check if there is any RXD left. |
| 1788 | while (HWM_GET_RX_FREE(smc) > 0) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1789 | pr_debug(KERN_INFO ".\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
| 1791 | rxd = HWM_GET_CURR_RXD(smc); |
| 1792 | skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC); |
| 1793 | if (skb) { |
| 1794 | // we got a skb |
| 1795 | skb_reserve(skb, 3); |
| 1796 | skb_put(skb, MaxFrameSize); |
| 1797 | v_addr = skb->data; |
| 1798 | b_addr = pci_map_single(&smc->os.pdev, |
| 1799 | v_addr, |
| 1800 | MaxFrameSize, |
| 1801 | PCI_DMA_FROMDEVICE); |
| 1802 | rxd->rxd_os.dma_addr = b_addr; |
| 1803 | } else { |
| 1804 | // no skb available, use local buffer |
| 1805 | // System has run out of buffer memory, but we want to |
| 1806 | // keep the receiver running in hope of better times. |
| 1807 | // Multiple descriptors may point to this local buffer, |
| 1808 | // so data in it must be considered invalid. |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1809 | pr_debug("Queueing invalid buffer!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | v_addr = smc->os.LocalRxBuffer; |
| 1811 | b_addr = smc->os.LocalRxBufferDMA; |
| 1812 | } |
| 1813 | |
| 1814 | rxd->rxd_os.skb = skb; |
| 1815 | |
| 1816 | // Pass receive buffer to HWM. |
| 1817 | hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize, |
| 1818 | FIRST_FRAG | LAST_FRAG); |
| 1819 | } |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1820 | pr_debug(KERN_INFO "leaving mac_drv_fill_rxd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | } // mac_drv_fill_rxd |
| 1822 | |
| 1823 | |
| 1824 | /************************ |
| 1825 | * |
| 1826 | * mac_drv_clear_rxd |
| 1827 | * |
| 1828 | * The hardware module calls this function to release unused |
| 1829 | * receive buffers. |
| 1830 | * Args |
| 1831 | * smc - A pointer to the SMT context struct. |
| 1832 | * |
| 1833 | * rxd - A pointer to the first RxD which is used by the receive buffer. |
| 1834 | * |
| 1835 | * frag_count - Count of RxDs used by the receive buffer. |
| 1836 | * Out |
| 1837 | * Nothing. |
| 1838 | * |
| 1839 | ************************/ |
| 1840 | void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd, |
| 1841 | int frag_count) |
| 1842 | { |
| 1843 | |
| 1844 | struct sk_buff *skb; |
| 1845 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1846 | pr_debug("entering mac_drv_clear_rxd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
| 1848 | if (frag_count != 1) // This is not allowed to happen. |
| 1849 | |
| 1850 | printk("fddi: Multi-fragment clear!\n"); |
| 1851 | |
| 1852 | for (; frag_count > 0; frag_count--) { |
| 1853 | skb = rxd->rxd_os.skb; |
| 1854 | if (skb != NULL) { |
| 1855 | skfddi_priv *bp = &smc->os; |
| 1856 | int MaxFrameSize = bp->MaxFrameSize; |
| 1857 | |
| 1858 | pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr, |
| 1859 | MaxFrameSize, PCI_DMA_FROMDEVICE); |
| 1860 | |
| 1861 | dev_kfree_skb(skb); |
| 1862 | rxd->rxd_os.skb = NULL; |
| 1863 | } |
| 1864 | rxd = rxd->rxd_next; // Next RXD. |
| 1865 | |
| 1866 | } |
| 1867 | } // mac_drv_clear_rxd |
| 1868 | |
| 1869 | |
| 1870 | /************************ |
| 1871 | * |
| 1872 | * mac_drv_rx_init |
| 1873 | * |
| 1874 | * The hardware module calls this routine when an SMT or NSA frame of the |
| 1875 | * local SMT should be delivered to the LLC layer. |
| 1876 | * |
| 1877 | * It is necessary to have this function, because there is no other way to |
| 1878 | * copy the contents of SMT MBufs into receive buffers. |
| 1879 | * |
| 1880 | * mac_drv_rx_init allocates the required target memory for this frame, |
| 1881 | * and receives the frame fragment by fragment by calling mac_drv_rx_frag. |
| 1882 | * Args |
| 1883 | * smc - A pointer to the SMT context struct. |
| 1884 | * |
| 1885 | * len - The length (in bytes) of the received frame (FC, DA, SA, Data). |
| 1886 | * |
| 1887 | * fc - The Frame Control field of the received frame. |
| 1888 | * |
| 1889 | * look_ahead - A pointer to the lookahead data buffer (may be NULL). |
| 1890 | * |
| 1891 | * la_len - The length of the lookahead data stored in the lookahead |
| 1892 | * buffer (may be zero). |
| 1893 | * Out |
| 1894 | * Always returns zero (0). |
| 1895 | * |
| 1896 | ************************/ |
| 1897 | int mac_drv_rx_init(struct s_smc *smc, int len, int fc, |
| 1898 | char *look_ahead, int la_len) |
| 1899 | { |
| 1900 | struct sk_buff *skb; |
| 1901 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1902 | pr_debug("entering mac_drv_rx_init(len=%d)\n", len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
| 1904 | // "Received" a SMT or NSA frame of the local SMT. |
| 1905 | |
| 1906 | if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1907 | pr_debug("fddi: Discard invalid local SMT frame\n"); |
| 1908 | pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | len, la_len, (unsigned long) look_ahead); |
| 1910 | return (0); |
| 1911 | } |
| 1912 | skb = alloc_skb(len + 3, GFP_ATOMIC); |
| 1913 | if (!skb) { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1914 | pr_debug("fddi: Local SMT: skb memory exhausted.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | return (0); |
| 1916 | } |
| 1917 | skb_reserve(skb, 3); |
| 1918 | skb_put(skb, len); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1919 | skb_copy_to_linear_data(skb, look_ahead, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
| 1921 | // deliver frame to system |
| 1922 | skb->protocol = fddi_type_trans(skb, smc->os.dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | netif_rx(skb); |
| 1924 | |
| 1925 | return (0); |
| 1926 | } // mac_drv_rx_init |
| 1927 | |
| 1928 | |
| 1929 | /************************ |
| 1930 | * |
| 1931 | * smt_timer_poll |
| 1932 | * |
| 1933 | * This routine is called periodically by the SMT module to clean up the |
| 1934 | * driver. |
| 1935 | * |
| 1936 | * Return any queued frames back to the upper protocol layers if the ring |
| 1937 | * is down. |
| 1938 | * Args |
| 1939 | * smc - A pointer to the SMT context struct. |
| 1940 | * Out |
| 1941 | * Nothing. |
| 1942 | * |
| 1943 | ************************/ |
| 1944 | void smt_timer_poll(struct s_smc *smc) |
| 1945 | { |
| 1946 | } // smt_timer_poll |
| 1947 | |
| 1948 | |
| 1949 | /************************ |
| 1950 | * |
| 1951 | * ring_status_indication |
| 1952 | * |
| 1953 | * This function indicates a change of the ring state. |
| 1954 | * Args |
| 1955 | * smc - A pointer to the SMT context struct. |
| 1956 | * |
| 1957 | * status - The current ring status. |
| 1958 | * Out |
| 1959 | * Nothing. |
| 1960 | * |
| 1961 | ************************/ |
| 1962 | void ring_status_indication(struct s_smc *smc, u_long status) |
| 1963 | { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1964 | pr_debug("ring_status_indication( "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | if (status & RS_RES15) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1966 | pr_debug("RS_RES15 "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | if (status & RS_HARDERROR) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1968 | pr_debug("RS_HARDERROR "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | if (status & RS_SOFTERROR) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1970 | pr_debug("RS_SOFTERROR "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | if (status & RS_BEACON) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1972 | pr_debug("RS_BEACON "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | if (status & RS_PATHTEST) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1974 | pr_debug("RS_PATHTEST "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | if (status & RS_SELFTEST) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1976 | pr_debug("RS_SELFTEST "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | if (status & RS_RES9) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1978 | pr_debug("RS_RES9 "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | if (status & RS_DISCONNECT) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1980 | pr_debug("RS_DISCONNECT "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | if (status & RS_RES7) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1982 | pr_debug("RS_RES7 "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | if (status & RS_DUPADDR) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1984 | pr_debug("RS_DUPADDR "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | if (status & RS_NORINGOP) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1986 | pr_debug("RS_NORINGOP "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | if (status & RS_VERSION) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1988 | pr_debug("RS_VERSION "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | if (status & RS_STUCKBYPASSS) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1990 | pr_debug("RS_STUCKBYPASSS "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if (status & RS_EVENT) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1992 | pr_debug("RS_EVENT "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | if (status & RS_RINGOPCHANGE) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1994 | pr_debug("RS_RINGOPCHANGE "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | if (status & RS_RES0) |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 1996 | pr_debug("RS_RES0 "); |
| 1997 | pr_debug("]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } // ring_status_indication |
| 1999 | |
| 2000 | |
| 2001 | /************************ |
| 2002 | * |
| 2003 | * smt_get_time |
| 2004 | * |
| 2005 | * Gets the current time from the system. |
| 2006 | * Args |
| 2007 | * None. |
| 2008 | * Out |
| 2009 | * The current time in TICKS_PER_SECOND. |
| 2010 | * |
| 2011 | * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is |
| 2012 | * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply |
| 2013 | * to the time returned by smt_get_time(). |
| 2014 | * |
| 2015 | ************************/ |
| 2016 | unsigned long smt_get_time(void) |
| 2017 | { |
| 2018 | return jiffies; |
| 2019 | } // smt_get_time |
| 2020 | |
| 2021 | |
| 2022 | /************************ |
| 2023 | * |
| 2024 | * smt_stat_counter |
| 2025 | * |
| 2026 | * Status counter update (ring_op, fifo full). |
| 2027 | * Args |
| 2028 | * smc - A pointer to the SMT context struct. |
| 2029 | * |
| 2030 | * stat - = 0: A ring operational change occurred. |
| 2031 | * = 1: The FORMAC FIFO buffer is full / FIFO overflow. |
| 2032 | * Out |
| 2033 | * Nothing. |
| 2034 | * |
| 2035 | ************************/ |
| 2036 | void smt_stat_counter(struct s_smc *smc, int stat) |
| 2037 | { |
| 2038 | // BOOLEAN RingIsUp ; |
| 2039 | |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2040 | pr_debug(KERN_INFO "smt_stat_counter\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | switch (stat) { |
| 2042 | case 0: |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2043 | pr_debug(KERN_INFO "Ring operational change.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | break; |
| 2045 | case 1: |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2046 | pr_debug(KERN_INFO "Receive fifo overflow.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | smc->os.MacStat.gen.rx_errors++; |
| 2048 | break; |
| 2049 | default: |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2050 | pr_debug(KERN_INFO "Unknown status (%d).\n", stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | break; |
| 2052 | } |
| 2053 | } // smt_stat_counter |
| 2054 | |
| 2055 | |
| 2056 | /************************ |
| 2057 | * |
| 2058 | * cfm_state_change |
| 2059 | * |
| 2060 | * Sets CFM state in custom statistics. |
| 2061 | * Args |
| 2062 | * smc - A pointer to the SMT context struct. |
| 2063 | * |
| 2064 | * c_state - Possible values are: |
| 2065 | * |
| 2066 | * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST, |
| 2067 | * EC5_INSERT, EC6_CHECK, EC7_DEINSERT |
| 2068 | * Out |
| 2069 | * Nothing. |
| 2070 | * |
| 2071 | ************************/ |
| 2072 | void cfm_state_change(struct s_smc *smc, int c_state) |
| 2073 | { |
| 2074 | #ifdef DRIVERDEBUG |
| 2075 | char *s; |
| 2076 | |
| 2077 | switch (c_state) { |
| 2078 | case SC0_ISOLATED: |
| 2079 | s = "SC0_ISOLATED"; |
| 2080 | break; |
| 2081 | case SC1_WRAP_A: |
| 2082 | s = "SC1_WRAP_A"; |
| 2083 | break; |
| 2084 | case SC2_WRAP_B: |
| 2085 | s = "SC2_WRAP_B"; |
| 2086 | break; |
| 2087 | case SC4_THRU_A: |
| 2088 | s = "SC4_THRU_A"; |
| 2089 | break; |
| 2090 | case SC5_THRU_B: |
| 2091 | s = "SC5_THRU_B"; |
| 2092 | break; |
| 2093 | case SC7_WRAP_S: |
| 2094 | s = "SC7_WRAP_S"; |
| 2095 | break; |
| 2096 | case SC9_C_WRAP_A: |
| 2097 | s = "SC9_C_WRAP_A"; |
| 2098 | break; |
| 2099 | case SC10_C_WRAP_B: |
| 2100 | s = "SC10_C_WRAP_B"; |
| 2101 | break; |
| 2102 | case SC11_C_WRAP_S: |
| 2103 | s = "SC11_C_WRAP_S"; |
| 2104 | break; |
| 2105 | default: |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2106 | pr_debug(KERN_INFO "cfm_state_change: unknown %d\n", c_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | return; |
| 2108 | } |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2109 | pr_debug(KERN_INFO "cfm_state_change: %s\n", s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | #endif // DRIVERDEBUG |
| 2111 | } // cfm_state_change |
| 2112 | |
| 2113 | |
| 2114 | /************************ |
| 2115 | * |
| 2116 | * ecm_state_change |
| 2117 | * |
| 2118 | * Sets ECM state in custom statistics. |
| 2119 | * Args |
| 2120 | * smc - A pointer to the SMT context struct. |
| 2121 | * |
| 2122 | * e_state - Possible values are: |
| 2123 | * |
| 2124 | * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12), |
| 2125 | * SC5_THRU_B (7), SC7_WRAP_S (8) |
| 2126 | * Out |
| 2127 | * Nothing. |
| 2128 | * |
| 2129 | ************************/ |
| 2130 | void ecm_state_change(struct s_smc *smc, int e_state) |
| 2131 | { |
| 2132 | #ifdef DRIVERDEBUG |
| 2133 | char *s; |
| 2134 | |
| 2135 | switch (e_state) { |
| 2136 | case EC0_OUT: |
| 2137 | s = "EC0_OUT"; |
| 2138 | break; |
| 2139 | case EC1_IN: |
| 2140 | s = "EC1_IN"; |
| 2141 | break; |
| 2142 | case EC2_TRACE: |
| 2143 | s = "EC2_TRACE"; |
| 2144 | break; |
| 2145 | case EC3_LEAVE: |
| 2146 | s = "EC3_LEAVE"; |
| 2147 | break; |
| 2148 | case EC4_PATH_TEST: |
| 2149 | s = "EC4_PATH_TEST"; |
| 2150 | break; |
| 2151 | case EC5_INSERT: |
| 2152 | s = "EC5_INSERT"; |
| 2153 | break; |
| 2154 | case EC6_CHECK: |
| 2155 | s = "EC6_CHECK"; |
| 2156 | break; |
| 2157 | case EC7_DEINSERT: |
| 2158 | s = "EC7_DEINSERT"; |
| 2159 | break; |
| 2160 | default: |
| 2161 | s = "unknown"; |
| 2162 | break; |
| 2163 | } |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2164 | pr_debug(KERN_INFO "ecm_state_change: %s\n", s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | #endif //DRIVERDEBUG |
| 2166 | } // ecm_state_change |
| 2167 | |
| 2168 | |
| 2169 | /************************ |
| 2170 | * |
| 2171 | * rmt_state_change |
| 2172 | * |
| 2173 | * Sets RMT state in custom statistics. |
| 2174 | * Args |
| 2175 | * smc - A pointer to the SMT context struct. |
| 2176 | * |
| 2177 | * r_state - Possible values are: |
| 2178 | * |
| 2179 | * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT, |
| 2180 | * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE |
| 2181 | * Out |
| 2182 | * Nothing. |
| 2183 | * |
| 2184 | ************************/ |
| 2185 | void rmt_state_change(struct s_smc *smc, int r_state) |
| 2186 | { |
| 2187 | #ifdef DRIVERDEBUG |
| 2188 | char *s; |
| 2189 | |
| 2190 | switch (r_state) { |
| 2191 | case RM0_ISOLATED: |
| 2192 | s = "RM0_ISOLATED"; |
| 2193 | break; |
| 2194 | case RM1_NON_OP: |
| 2195 | s = "RM1_NON_OP - not operational"; |
| 2196 | break; |
| 2197 | case RM2_RING_OP: |
| 2198 | s = "RM2_RING_OP - ring operational"; |
| 2199 | break; |
| 2200 | case RM3_DETECT: |
| 2201 | s = "RM3_DETECT - detect dupl addresses"; |
| 2202 | break; |
| 2203 | case RM4_NON_OP_DUP: |
| 2204 | s = "RM4_NON_OP_DUP - dupl. addr detected"; |
| 2205 | break; |
| 2206 | case RM5_RING_OP_DUP: |
| 2207 | s = "RM5_RING_OP_DUP - ring oper. with dupl. addr"; |
| 2208 | break; |
| 2209 | case RM6_DIRECTED: |
| 2210 | s = "RM6_DIRECTED - sending directed beacons"; |
| 2211 | break; |
| 2212 | case RM7_TRACE: |
| 2213 | s = "RM7_TRACE - trace initiated"; |
| 2214 | break; |
| 2215 | default: |
| 2216 | s = "unknown"; |
| 2217 | break; |
| 2218 | } |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2219 | pr_debug(KERN_INFO "[rmt_state_change: %s]\n", s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | #endif // DRIVERDEBUG |
| 2221 | } // rmt_state_change |
| 2222 | |
| 2223 | |
| 2224 | /************************ |
| 2225 | * |
| 2226 | * drv_reset_indication |
| 2227 | * |
| 2228 | * This function is called by the SMT when it has detected a severe |
| 2229 | * hardware problem. The driver should perform a reset on the adapter |
| 2230 | * as soon as possible, but not from within this function. |
| 2231 | * Args |
| 2232 | * smc - A pointer to the SMT context struct. |
| 2233 | * Out |
| 2234 | * Nothing. |
| 2235 | * |
| 2236 | ************************/ |
| 2237 | void drv_reset_indication(struct s_smc *smc) |
| 2238 | { |
Alexander Beregalov | ebc06ee | 2009-05-15 10:22:42 +0000 | [diff] [blame] | 2239 | pr_debug(KERN_INFO "entering drv_reset_indication\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | |
| 2241 | smc->os.ResetRequested = TRUE; // Set flag. |
| 2242 | |
| 2243 | } // drv_reset_indication |
| 2244 | |
| 2245 | static struct pci_driver skfddi_pci_driver = { |
| 2246 | .name = "skfddi", |
| 2247 | .id_table = skfddi_pci_tbl, |
| 2248 | .probe = skfp_init_one, |
| 2249 | .remove = __devexit_p(skfp_remove_one), |
| 2250 | }; |
| 2251 | |
| 2252 | static int __init skfd_init(void) |
| 2253 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 2254 | return pci_register_driver(&skfddi_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | static void __exit skfd_exit(void) |
| 2258 | { |
| 2259 | pci_unregister_driver(&skfddi_pci_driver); |
| 2260 | } |
| 2261 | |
| 2262 | module_init(skfd_init); |
| 2263 | module_exit(skfd_exit); |