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