5 * Copyright Information: 6 * Copyright Digital Equipment Corporation 1996. 8 * This software may be used and distributed according to the terms of 9 * the GNU Public License, incorporated herein by reference. 12 * A Linux device driver supporting the Digital Equipment Corporation 13 * FDDI EISA and PCI controller families. Supported adapters include: 15 * DEC FDDIcontroller/EISA (DEFEA) 16 * DEC FDDIcontroller/PCI (DEFPA) 19 * LVS Lawrence V. Stefani 22 * The author may be reached at: 24 * Inet: stefani@lkg.dec.com 25 * (NOTE! this address no longer works -jgarzik) 27 * Mail: Digital Equipment Corporation 33 * I'd like to thank Patricia Cross for helping me get started with 34 * Linux, David Davies for a lot of help upgrading and configuring 35 * my development system and for answering many OS and driver 36 * development questions, and Alan Cox for recommendations and 37 * integration help on getting FDDI support into Linux. LVS 39 * Driver Architecture: 40 * The driver architecture is largely based on previous driver work 41 * for other operating systems. The upper edge interface and 42 * functions were largely taken from existing Linux device drivers 43 * such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C 47 * The driver scans for supported EISA adapters by reading the 48 * SLOT ID register for each EISA slot and making a match 49 * against the expected value. 51 * Bus-Specific Initialization - 52 * This driver currently supports both EISA and PCI controller 53 * families. While the custom DMA chip and FDDI logic is similar 54 * or identical, the bus logic is very different. After 55 * initialization, the only bus-specific differences is in how the 56 * driver enables and disables interrupts. Other than that, the 57 * run-time critical code behaves the same on both families. 58 * It's important to note that both adapter families are configured 59 * to I/O map, rather than memory map, the adapter registers. 62 * In the driver open routine, the driver ISR (interrupt service 63 * routine) is registered and the adapter is brought to an 64 * operational state. In the driver close routine, the opposite 65 * occurs; the driver ISR is deregistered and the adapter is 66 * brought to a safe, but closed state. Users may use consecutive 67 * commands to bring the adapter up and down as in the following 74 * Apparently, there is no shutdown or halt routine support under 75 * Linux. This routine would be called during "reboot" or 76 * "shutdown" to allow the driver to place the adapter in a safe 77 * state before a warm reboot occurs. To be really safe, the user 78 * should close the adapter before shutdown (eg. ifconfig fddi0 down) 79 * to ensure that the adapter DMA engine is taken off-line. However, 80 * the current driver code anticipates this problem and always issues 81 * a soft reset of the adapter at the beginning of driver initialization. 82 * A future driver enhancement in this area may occur in 2.1.X where 83 * Alan indicated that a shutdown handler may be implemented. 85 * Interrupt Service Routine - 86 * The driver supports shared interrupts, so the ISR is registered for 87 * each board with the appropriate flag and the pointer to that board's 88 * device structure. This provides the context during interrupt 89 * processing to support shared interrupts and multiple boards. 91 * Interrupt enabling/disabling can occur at many levels. At the host 92 * end, you can disable system interrupts, or disable interrupts at the 93 * PIC (on Intel systems). Across the bus, both EISA and PCI adapters 94 * have a bus-logic chip interrupt enable/disable as well as a DMA 95 * controller interrupt enable/disable. 97 * The driver currently enables and disables adapter interrupts at the 98 * bus-logic chip and assumes that Linux will take care of clearing or 99 * acknowledging any host-based interrupt chips. 101 * Control Functions - 102 * Control functions are those used to support functions such as adding 103 * or deleting multicast addresses, enabling or disabling packet 104 * reception filters, or other custom/proprietary commands. Presently, 105 * the driver supports the "get statistics", "set multicast list", and 106 * "set mac address" functions defined by Linux. A list of possible 107 * enhancements include: 109 * - Custom ioctl interface for executing port interface commands 110 * - Custom ioctl interface for adding unicast addresses to 111 * adapter CAM (to support bridge functions). 112 * - Custom ioctl interface for supporting firmware upgrades. 114 * Hardware (port interface) Support Routines - 115 * The driver function names that start with "dfx_hw_" represent 116 * low-level port interface routines that are called frequently. They 117 * include issuing a DMA or port control command to the adapter, 118 * resetting the adapter, or reading the adapter state. Since the 119 * driver initialization and run-time code must make calls into the 120 * port interface, these routines were written to be as generic and 121 * usable as possible. 124 * The adapter DMA engine supports a 256 entry receive descriptor block 125 * of which up to 255 entries can be used at any given time. The 126 * architecture is a standard producer, consumer, completion model in 127 * which the driver "produces" receive buffers to the adapter, the 128 * adapter "consumes" the receive buffers by DMAing incoming packet data, 129 * and the driver "completes" the receive buffers by servicing the 130 * incoming packet, then "produces" a new buffer and starts the cycle 131 * again. Receive buffers can be fragmented in up to 16 fragments 132 * (descriptor entries). For simplicity, this driver posts 133 * single-fragment receive buffers of 4608 bytes, then allocates a 134 * sk_buff, copies the data, then reposts the buffer. To reduce CPU 135 * utilization, a better approach would be to pass up the receive 136 * buffer (no extra copy) then allocate and post a replacement buffer. 137 * This is a performance enhancement that should be looked into at 141 * Like the receive path, the adapter DMA engine supports a 256 entry 142 * transmit descriptor block of which up to 255 entries can be used at 143 * any given time. Transmit buffers can be fragmented in up to 255 144 * fragments (descriptor entries). This driver always posts one 145 * fragment per transmit packet request. 147 * The fragment contains the entire packet from FC to end of data. 148 * Before posting the buffer to the adapter, the driver sets a three-byte 149 * packet request header (PRH) which is required by the Motorola MAC chip 150 * used on the adapters. The PRH tells the MAC the type of token to 151 * receive/send, whether or not to generate and append the CRC, whether 152 * synchronous or asynchronous framing is used, etc. Since the PRH 153 * definition is not necessarily consistent across all FDDI chipsets, 154 * the driver, rather than the common FDDI packet handler routines, 157 * To reduce the amount of descriptor fetches needed per transmit request, 158 * the driver takes advantage of the fact that there are at least three 159 * bytes available before the skb->data field on the outgoing transmit 160 * request. This is guaranteed by having fddi_setup() in net_init.c set 161 * dev->hard_header_len to 24 bytes. 21 bytes accounts for the largest 162 * header in an 802.2 SNAP frame. The other 3 bytes are the extra "pad" 163 * bytes which we'll use to store the PRH. 165 * There's a subtle advantage to adding these pad bytes to the 166 * hard_header_len, it ensures that the data portion of the packet for 167 * an 802.2 SNAP frame is longword aligned. Other FDDI driver 168 * implementations may not need the extra padding and can start copying 169 * or DMAing directly from the FC byte which starts at skb->data. Should 170 * another driver implementation need ADDITIONAL padding, the net_init.c 171 * module should be updated and dev->hard_header_len should be increased. 172 * NOTE: To maintain the alignment on the data portion of the packet, 173 * dev->hard_header_len should always be evenly divisible by 4 and at 174 * least 24 bytes in size. 176 * Modification History: 177 * Date Name Description 178 * 16-Aug-96 LVS Created. 179 * 20-Aug-96 LVS Updated dfx_probe so that version information 180 * string is only displayed if 1 or more cards are 181 * found. Changed dfx_rcv_queue_process to copy 182 * 3 NULL bytes before FC to ensure that data is 183 * longword aligned in receive buffer. 184 * 09-Sep-96 LVS Updated dfx_ctl_set_multicast_list to enable 185 * LLC group promiscuous mode if multicast list 186 * is too large. LLC individual/group promiscuous 187 * mode is now disabled if IFF_PROMISC flag not set. 188 * dfx_xmt_queue_pkt no longer checks for NULL skb 189 * on Alan Cox recommendation. Added node address 191 * 12-Sep-96 LVS Reset current address to factory address during 192 * device open. Updated transmit path to post a 193 * single fragment which includes PRH->end of data. 194 * Mar 2000 AC Did various cleanups for 2.3.x 195 * Jun 2000 jgarzik PCI and resource alloc cleanups 196 * Jul 2000 tjeerd Much cleanup and some bug fixes 197 * Sep 2000 tjeerd Fix leak on unload, cosmetic code cleanup 202 #include <linux/module.h> 204 #include <linux/kernel.h> 205 #include <linux/sched.h> 206 #include <linux/string.h> 207 #include <linux/ptrace.h> 208 #include <linux/errno.h> 209 #include <linux/ioport.h> 210 #include <linux/malloc.h> 211 #include <linux/interrupt.h> 212 #include <linux/pci.h> 213 #include <linux/delay.h> 214 #include <linux/init.h> 215 #include <linux/netdevice.h> 216 #include <asm/byteorder.h> 217 #include <asm/bitops.h> 220 #include <linux/fddidevice.h> 221 #include <linux/skbuff.h> 225 /* Version information string - should be updated prior to each new release!!! */ 227 static char version
[] __devinitdata
= 228 "defxx.c:v1.05d 2000/09/05 Lawrence V. Stefani and others\n"; 230 #define DYNAMIC_BUFFERS 1 232 #define SKBUFF_RX_COPYBREAK 200 234 * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte 235 * alignment for compatibility with old EISA boards. 237 #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128) 239 /* Define module-wide (static) routines */ 241 static voiddfx_bus_init(struct net_device
*dev
); 242 static voiddfx_bus_config_check(DFX_board_t
*bp
); 244 static intdfx_driver_init(struct net_device
*dev
); 245 static intdfx_adap_init(DFX_board_t
*bp
); 247 static intdfx_open(struct net_device
*dev
); 248 static intdfx_close(struct net_device
*dev
); 250 static voiddfx_int_pr_halt_id(DFX_board_t
*bp
); 251 static voiddfx_int_type_0_process(DFX_board_t
*bp
); 252 static voiddfx_int_common(struct net_device
*dev
); 253 static voiddfx_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
); 255 static struct net_device_stats
*dfx_ctl_get_stats(struct net_device
*dev
); 256 static voiddfx_ctl_set_multicast_list(struct net_device
*dev
); 257 static intdfx_ctl_set_mac_address(struct net_device
*dev
,void*addr
); 258 static intdfx_ctl_update_cam(DFX_board_t
*bp
); 259 static intdfx_ctl_update_filters(DFX_board_t
*bp
); 261 static intdfx_hw_dma_cmd_req(DFX_board_t
*bp
); 262 static intdfx_hw_port_ctrl_req(DFX_board_t
*bp
, PI_UINT32 command
, PI_UINT32 data_a
, PI_UINT32 data_b
, PI_UINT32
*host_data
); 263 static voiddfx_hw_adap_reset(DFX_board_t
*bp
, PI_UINT32 type
); 264 static intdfx_hw_adap_state_rd(DFX_board_t
*bp
); 265 static intdfx_hw_dma_uninit(DFX_board_t
*bp
, PI_UINT32 type
); 267 static voiddfx_rcv_init(DFX_board_t
*bp
); 268 static voiddfx_rcv_queue_process(DFX_board_t
*bp
); 270 static intdfx_xmt_queue_pkt(struct sk_buff
*skb
,struct net_device
*dev
); 271 static intdfx_xmt_done(DFX_board_t
*bp
); 272 static voiddfx_xmt_flush(DFX_board_t
*bp
); 274 /* Define module-wide (static) variables */ 276 static struct net_device
*root_dfx_eisa_dev
; 280 * ======================= 281 * = dfx_port_write_byte = 282 * = dfx_port_read_byte = 283 * = dfx_port_write_long = 284 * = dfx_port_read_long = 285 * ======================= 288 * Routines for reading and writing values from/to adapter 294 * bp - pointer to board information 295 * offset - register offset from base I/O address 296 * data - for dfx_port_write_byte and dfx_port_write_long, this 297 * is a value to write. 298 * for dfx_port_read_byte and dfx_port_read_byte, this 299 * is a pointer to store the read value. 301 * Functional Description: 302 * These routines perform the correct operation to read or write 303 * the adapter register. 305 * EISA port block base addresses are based on the slot number in which the 306 * controller is installed. For example, if the EISA controller is installed 307 * in slot 4, the port block base address is 0x4000. If the controller is 308 * installed in slot 2, the port block base address is 0x2000, and so on. 309 * This port block can be used to access PDQ, ESIC, and DEFEA on-board 310 * registers using the register offsets defined in DEFXX.H. 312 * PCI port block base addresses are assigned by the PCI BIOS or system 313 * firmware. There is one 128 byte port block which can be accessed. It 314 * allows for I/O mapping of both PDQ and PFI registers using the register 315 * offsets defined in DEFXX.H. 321 * bp->base_addr is a valid base I/O address for this adapter. 322 * offset is a valid register offset for this adapter. 325 * Rather than produce macros for these functions, these routines 326 * are defined using "inline" to ensure that the compiler will 327 * generate inline code and not waste a procedure call and return. 328 * This provides all the benefits of macros, but with the 329 * advantage of strict data type checking. 332 staticinlinevoiddfx_port_write_byte( 339 u16 port
= bp
->base_addr
+ offset
; 345 staticinlinevoiddfx_port_read_byte( 352 u16 port
= bp
->base_addr
+ offset
; 358 staticinlinevoiddfx_port_write_long( 365 u16 port
= bp
->base_addr
+ offset
; 371 staticinlinevoiddfx_port_read_long( 378 u16 port
= bp
->base_addr
+ offset
; 387 * = dfx_init_one_pci_or_eisa = 391 * Initializes a supported FDDI EISA or PCI controller 397 * pdev - pointer to pci device information (NULL for EISA) 399 * Functional Description: 402 * 0 - This device (fddi0, fddi1, etc) configured successfully 403 * -EBUSY - Failed to get resources, or dfx_driver_init failed. 406 * It compiles so it should work :-( (PCI cards do :-) 409 * Device structures for FDDI adapters (fddi0, fddi1, etc) are 410 * initialized and the board resources are read and stored in 411 * the device structure. 413 static int __devinit
dfx_init_one_pci_or_eisa(struct pci_dev
*pdev
,long ioaddr
) 415 struct net_device
*dev
; 416 DFX_board_t
*bp
;/* board pointer */ 417 static int version_disp
; 419 if(!version_disp
)/* display version info if adapter is found */ 421 version_disp
=1;/* set display flag to TRUE so that */ 422 printk(version
);/* we only display this string ONCE */ 426 * init_fddidev() allocates a device structure with private data, clears the device structure and private data, 427 * and calls fddi_setup() and register_netdev(). Not much left to do for us here. 429 dev
=init_fddidev( NULL
,sizeof(*bp
)); 432 printk(KERN_ERR
"defxx: unable to allocate fddidev, aborting\n"); 436 bp
= (DFX_board_t
*)dev
->priv
; 438 if(!request_region(ioaddr
, pdev
? PFI_K_CSR_IO_LEN
: PI_ESIC_K_CSR_IO_LEN
, dev
->name
)) { 439 printk(KERN_ERR
"%s: Cannot reserve I/O resource 0x%x @ 0x%lx, aborting\n", 440 dev
->name
, PFI_K_CSR_IO_LEN
, ioaddr
); 444 /* Initialize new device structure */ 446 dev
->base_addr
= ioaddr
;/* save port (I/O) base address */ 448 dev
->get_stats
= dfx_ctl_get_stats
; 449 dev
->open
= dfx_open
; 450 dev
->stop
= dfx_close
; 451 dev
->hard_start_xmit
= dfx_xmt_queue_pkt
; 452 dev
->set_multicast_list
= dfx_ctl_set_multicast_list
; 453 dev
->set_mac_address
= dfx_ctl_set_mac_address
; 457 bp
->bus_type
= DFX_BUS_TYPE_EISA
; 458 bp
->next
= root_dfx_eisa_dev
; 459 root_dfx_eisa_dev
= dev
; 462 bp
->bus_type
= DFX_BUS_TYPE_PCI
; 464 pdev
->driver_data
= dev
; 465 if(pci_enable_device(pdev
)) 467 pci_set_master(pdev
); 470 if(dfx_driver_init(dev
) != DFX_K_SUCCESS
) 476 release_region(ioaddr
, pdev
? PFI_K_CSR_IO_LEN
: PI_ESIC_K_CSR_IO_LEN
); 478 unregister_netdev(dev
); 483 static int __devinit
dfx_init_one(struct pci_dev
*pdev
,const struct pci_device_id
*ent
) 485 returndfx_init_one_pci_or_eisa(pdev
,pci_resource_start(pdev
,1)); 488 static int __init
dfx_eisa_init(void) 491 int i
;/* used in for loops */ 492 u16 port
;/* temporary I/O (port) address */ 493 u32 slot_id
;/* EISA hardware (slot) ID read from adapter */ 495 DBG_printk("In dfx_eisa_init...\n"); 497 /* Scan for FDDI EISA controllers */ 499 for(i
=0; i
< DFX_MAX_EISA_SLOTS
; i
++)/* only scan for up to 16 EISA slots */ 501 port
= (i
<<12) + PI_ESIC_K_SLOT_ID
;/* port = I/O address for reading slot ID */ 502 slot_id
=inl(port
);/* read EISA HW (slot) ID */ 503 if((slot_id
&0xF0FFFFFF) == DEFEA_PRODUCT_ID
) 505 port
= (i
<<12);/* recalc base addr */ 507 if(dfx_init_one_pci_or_eisa(NULL
, port
) ==0) rc
=0; 519 * Initializes EISA and PCI controller bus-specific logic. 525 * dev - pointer to device information 527 * Functional Description: 528 * Determine and save adapter IRQ in device table, 529 * then perform bus-specific logic initialization. 535 * dev->base_addr has already been set with the proper 536 * base I/O address for this device. 539 * Interrupts are enabled at the adapter bus-specific logic. 540 * Note: Interrupts at the DMA engine (PDQ chip) are not 544 static void __devinit
dfx_bus_init(struct net_device
*dev
) 546 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 547 u8 val
;/* used for I/O read/writes */ 549 DBG_printk("In dfx_bus_init...\n"); 552 * Initialize base I/O address field in bp structure 554 * Note: bp->base_addr is the same as dev->base_addr. 555 * It's useful because often we'll need to read 556 * or write registers where we already have the 557 * bp pointer instead of the dev pointer. Having 558 * the base address in the bp structure will 559 * save a pointer dereference. 561 * IMPORTANT!! This field must be defined before 562 * any of the dfx_port_* inline functions are 566 bp
->base_addr
= dev
->base_addr
; 568 /* And a pointer back to the net_device struct */ 571 /* Initialize adapter based on bus type */ 573 if(bp
->bus_type
== DFX_BUS_TYPE_EISA
) 575 /* Get the interrupt level from the ESIC chip */ 577 dfx_port_read_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, &val
); 578 switch((val
& PI_CONFIG_STAT_0_M_IRQ
) >> PI_CONFIG_STAT_0_V_IRQ
) 580 case PI_CONFIG_STAT_0_IRQ_K_9
: 584 case PI_CONFIG_STAT_0_IRQ_K_10
: 588 case PI_CONFIG_STAT_0_IRQ_K_11
: 592 case PI_CONFIG_STAT_0_IRQ_K_15
: 597 /* Enable access to I/O on the board by writing 0x03 to Function Control Register */ 599 dfx_port_write_byte(bp
, PI_ESIC_K_FUNCTION_CNTRL
, PI_ESIC_K_FUNCTION_CNTRL_IO_ENB
); 601 /* Set the I/O decode range of the board */ 603 val
= ((dev
->base_addr
>>12) << PI_IO_CMP_V_SLOT
); 604 dfx_port_write_byte(bp
, PI_ESIC_K_IO_CMP_0_1
, val
); 605 dfx_port_write_byte(bp
, PI_ESIC_K_IO_CMP_1_1
, val
); 607 /* Enable access to rest of module (including PDQ and packet memory) */ 609 dfx_port_write_byte(bp
, PI_ESIC_K_SLOT_CNTRL
, PI_SLOT_CNTRL_M_ENB
); 612 * Map PDQ registers into I/O space. This is done by clearing a bit 613 * in Burst Holdoff register. 616 dfx_port_read_byte(bp
, PI_ESIC_K_BURST_HOLDOFF
, &val
); 617 dfx_port_write_byte(bp
, PI_ESIC_K_BURST_HOLDOFF
, (val
& ~PI_BURST_HOLDOFF_M_MEM_MAP
)); 619 /* Enable interrupts at EISA bus interface chip (ESIC) */ 621 dfx_port_read_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, &val
); 622 dfx_port_write_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, (val
| PI_CONFIG_STAT_0_M_INT_ENB
)); 626 struct pci_dev
*pdev
= bp
->pci_dev
; 628 /* Get the interrupt level from the PCI Configuration Table */ 630 dev
->irq
= pdev
->irq
; 632 /* Check Latency Timer and set if less than minimal */ 634 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &val
); 635 if(val
< PFI_K_LAT_TIMER_MIN
)/* if less than min, override with default */ 637 val
= PFI_K_LAT_TIMER_DEF
; 638 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, val
); 641 /* Enable interrupts at PCI bus interface chip (PFI) */ 643 dfx_port_write_long(bp
, PFI_K_REG_MODE_CTRL
, (PFI_MODE_M_PDQ_INT_ENB
| PFI_MODE_M_DMA_ENB
)); 650 * ======================== 651 * = dfx_bus_config_check = 652 * ======================== 655 * Checks the configuration (burst size, full-duplex, etc.) If any parameters 656 * are illegal, then this routine will set new defaults. 662 * bp - pointer to board information 664 * Functional Description: 665 * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later 666 * PDQ, and all FDDI PCI controllers, all values are legal. 672 * dfx_adap_init has NOT been called yet so burst size and other items have 679 static void __devinit
dfx_bus_config_check(DFX_board_t
*bp
) 681 int status
;/* return code from adapter port control call */ 682 u32 slot_id
;/* EISA-bus hardware id (DEC3001, DEC3002,...) */ 683 u32 host_data
;/* LW data returned from port control call */ 685 DBG_printk("In dfx_bus_config_check...\n"); 687 /* Configuration check only valid for EISA adapter */ 689 if(bp
->bus_type
== DFX_BUS_TYPE_EISA
) 691 dfx_port_read_long(bp
, PI_ESIC_K_SLOT_ID
, &slot_id
); 694 * First check if revision 2 EISA controller. Rev. 1 cards used 695 * PDQ revision B, so no workaround needed in this case. Rev. 3 696 * cards used PDQ revision E, so no workaround needed in this 697 * case, either. Only Rev. 2 cards used either Rev. D or E 698 * chips, so we must verify the chip revision on Rev. 2 cards. 701 if(slot_id
== DEFEA_PROD_ID_2
) 704 * Revision 2 FDDI EISA controller found, so let's check PDQ 705 * revision of adapter. 708 status
=dfx_hw_port_ctrl_req(bp
, 710 PI_SUB_CMD_K_PDQ_REV_GET
, 713 if((status
!= DFX_K_SUCCESS
) || (host_data
==2)) 716 * Either we couldn't determine the PDQ revision, or 717 * we determined that it is at revision D. In either case, 718 * we need to implement the workaround. 721 /* Ensure that the burst size is set to 8 longwords or less */ 723 switch(bp
->burst_size
) 725 case PI_PDATA_B_DMA_BURST_SIZE_32
: 726 case PI_PDATA_B_DMA_BURST_SIZE_16
: 727 bp
->burst_size
= PI_PDATA_B_DMA_BURST_SIZE_8
; 734 /* Ensure that full-duplex mode is not enabled */ 736 bp
->full_duplex_enb
= PI_SNMP_K_FALSE
; 745 * =================== 746 * = dfx_driver_init = 747 * =================== 750 * Initializes remaining adapter board structure information 751 * and makes sure adapter is in a safe state prior to dfx_open(). 757 * dev - pointer to device information 759 * Functional Description: 760 * This function allocates additional resources such as the host memory 761 * blocks needed by the adapter (eg. descriptor and consumer blocks). 762 * Remaining bus initialization steps are also completed. The adapter 763 * is also reset so that it is in the DMA_UNAVAILABLE state. The OS 764 * must call dfx_open() to open the adapter and bring it on-line. 767 * DFX_K_SUCCESS - initialization succeeded 768 * DFX_K_FAILURE - initialization failed - could not allocate memory 769 * or read adapter MAC address 772 * Memory allocated from kmalloc() call is physically contiguous, locked 773 * memory whose physical address equals its virtual address. 776 * Adapter is reset and should be in DMA_UNAVAILABLE state before 777 * returning from this routine. 780 static int __devinit
dfx_driver_init(struct net_device
*dev
) 782 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 783 int alloc_size
;/* total buffer size needed */ 784 char*top_v
, *curr_v
;/* virtual addrs into memory block */ 785 u32 top_p
, curr_p
;/* physical addrs into memory block */ 786 u32 data
;/* host data register value */ 788 DBG_printk("In dfx_driver_init...\n"); 790 /* Initialize bus-specific hardware registers */ 795 * Initialize default values for configurable parameters 797 * Note: All of these parameters are ones that a user may 798 * want to customize. It'd be nice to break these 799 * out into Space.c or someplace else that's more 800 * accessible/understandable than this file. 803 bp
->full_duplex_enb
= PI_SNMP_K_FALSE
; 804 bp
->req_ttrt
=8*12500;/* 8ms in 80 nanosec units */ 805 bp
->burst_size
= PI_PDATA_B_DMA_BURST_SIZE_DEF
; 806 bp
->rcv_bufs_to_post
= RCV_BUFS_DEF
; 809 * Ensure that HW configuration is OK 811 * Note: Depending on the hardware revision, we may need to modify 812 * some of the configurable parameters to workaround hardware 813 * limitations. We'll perform this configuration check AFTER 814 * setting the parameters to their default values. 817 dfx_bus_config_check(bp
); 819 /* Disable PDQ interrupts first */ 821 dfx_port_write_long(bp
, PI_PDQ_K_REG_HOST_INT_ENB
, PI_HOST_INT_K_DISABLE_ALL_INTS
); 823 /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */ 825 (void)dfx_hw_dma_uninit(bp
, PI_PDATA_A_RESET_M_SKIP_ST
); 827 /* Read the factory MAC address from the adapter then save it */ 829 if(dfx_hw_port_ctrl_req(bp
, 833 &data
) != DFX_K_SUCCESS
) 835 printk("%s: Could not read adapter factory MAC address!\n", dev
->name
); 836 return(DFX_K_FAILURE
); 838 memcpy(&bp
->factory_mac_addr
[0], &data
,sizeof(u32
)); 840 if(dfx_hw_port_ctrl_req(bp
, 844 &data
) != DFX_K_SUCCESS
) 846 printk("%s: Could not read adapter factory MAC address!\n", dev
->name
); 847 return(DFX_K_FAILURE
); 849 memcpy(&bp
->factory_mac_addr
[4], &data
,sizeof(u16
)); 852 * Set current address to factory address 854 * Note: Node address override support is handled through 855 * dfx_ctl_set_mac_address. 858 memcpy(dev
->dev_addr
, bp
->factory_mac_addr
, FDDI_K_ALEN
); 859 if(bp
->bus_type
== DFX_BUS_TYPE_EISA
) 860 printk("%s: DEFEA at I/O addr = 0x%lX, IRQ = %d, Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n", 871 printk("%s: DEFPA at I/O addr = 0x%lX, IRQ = %d, Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n", 883 * Get memory for descriptor block, consumer block, and other buffers 884 * that need to be DMA read or written to by the adapter. 887 alloc_size
=sizeof(PI_DESCR_BLOCK
) + 888 PI_CMD_REQ_K_SIZE_MAX
+ 889 PI_CMD_RSP_K_SIZE_MAX
+ 890 #ifndef DYNAMIC_BUFFERS 891 (bp
->rcv_bufs_to_post
* PI_RCV_DATA_K_SIZE_MAX
) + 893 sizeof(PI_CONSUMER_BLOCK
) + 894 (PI_ALIGN_K_DESC_BLK
-1); 895 bp
->kmalloced
= top_v
= (char*)kmalloc(alloc_size
, GFP_KERNEL
); 898 printk("%s: Could not allocate memory for host buffers and structures!\n", dev
->name
); 899 return(DFX_K_FAILURE
); 901 memset(top_v
,0, alloc_size
);/* zero out memory before continuing */ 902 top_p
=virt_to_bus(top_v
);/* get physical address of buffer */ 905 * To guarantee the 8K alignment required for the descriptor block, 8K - 1 906 * plus the amount of memory needed was allocated. The physical address 907 * is now 8K aligned. By carving up the memory in a specific order, 908 * we'll guarantee the alignment requirements for all other structures. 910 * Note: If the assumptions change regarding the non-paged, non-cached, 911 * physically contiguous nature of the memory block or the address 912 * alignments, then we'll need to implement a different algorithm 913 * for allocating the needed memory. 916 curr_p
= (u32
) (ALIGN(top_p
, PI_ALIGN_K_DESC_BLK
)); 917 curr_v
= top_v
+ (curr_p
- top_p
); 919 /* Reserve space for descriptor block */ 921 bp
->descr_block_virt
= (PI_DESCR_BLOCK
*) curr_v
; 922 bp
->descr_block_phys
= curr_p
; 923 curr_v
+=sizeof(PI_DESCR_BLOCK
); 924 curr_p
+=sizeof(PI_DESCR_BLOCK
); 926 /* Reserve space for command request buffer */ 928 bp
->cmd_req_virt
= (PI_DMA_CMD_REQ
*) curr_v
; 929 bp
->cmd_req_phys
= curr_p
; 930 curr_v
+= PI_CMD_REQ_K_SIZE_MAX
; 931 curr_p
+= PI_CMD_REQ_K_SIZE_MAX
; 933 /* Reserve space for command response buffer */ 935 bp
->cmd_rsp_virt
= (PI_DMA_CMD_RSP
*) curr_v
; 936 bp
->cmd_rsp_phys
= curr_p
; 937 curr_v
+= PI_CMD_RSP_K_SIZE_MAX
; 938 curr_p
+= PI_CMD_RSP_K_SIZE_MAX
; 940 /* Reserve space for the LLC host receive queue buffers */ 942 bp
->rcv_block_virt
= curr_v
; 943 bp
->rcv_block_phys
= curr_p
; 945 #ifndef DYNAMIC_BUFFERS 946 curr_v
+= (bp
->rcv_bufs_to_post
* PI_RCV_DATA_K_SIZE_MAX
); 947 curr_p
+= (bp
->rcv_bufs_to_post
* PI_RCV_DATA_K_SIZE_MAX
); 950 /* Reserve space for the consumer block */ 952 bp
->cons_block_virt
= (PI_CONSUMER_BLOCK
*) curr_v
; 953 bp
->cons_block_phys
= curr_p
; 955 /* Display virtual and physical addresses if debug driver */ 957 DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X\n", dev
->name
, (long)bp
->descr_block_virt
, bp
->descr_block_phys
); 958 DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X\n", dev
->name
, (long)bp
->cmd_req_virt
, bp
->cmd_req_phys
); 959 DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X\n", dev
->name
, (long)bp
->cmd_rsp_virt
, bp
->cmd_rsp_phys
); 960 DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X\n", dev
->name
, (long)bp
->rcv_block_virt
, bp
->rcv_block_phys
); 961 DBG_printk("%s: Consumer block virt = %0lX, phys = %0X\n", dev
->name
, (long)bp
->cons_block_virt
, bp
->cons_block_phys
); 963 return(DFX_K_SUCCESS
); 973 * Brings the adapter to the link avail/link unavailable state. 979 * bp - pointer to board information 981 * Functional Description: 982 * Issues the low-level firmware/hardware calls necessary to bring 983 * the adapter up, or to properly reset and restore adapter during 987 * DFX_K_SUCCESS - Adapter brought up successfully 988 * DFX_K_FAILURE - Adapter initialization failed 991 * bp->reset_type should be set to a valid reset type value before 992 * calling this routine. 995 * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state 996 * upon a successful return of this routine. 999 static intdfx_adap_init(DFX_board_t
*bp
) 1001 DBG_printk("In dfx_adap_init...\n"); 1003 /* Disable PDQ interrupts first */ 1005 dfx_port_write_long(bp
, PI_PDQ_K_REG_HOST_INT_ENB
, PI_HOST_INT_K_DISABLE_ALL_INTS
); 1007 /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */ 1009 if(dfx_hw_dma_uninit(bp
, bp
->reset_type
) != DFX_K_SUCCESS
) 1011 printk("%s: Could not uninitialize/reset adapter!\n", bp
->dev
->name
); 1012 return(DFX_K_FAILURE
); 1016 * When the PDQ is reset, some false Type 0 interrupts may be pending, 1017 * so we'll acknowledge all Type 0 interrupts now before continuing. 1020 dfx_port_write_long(bp
, PI_PDQ_K_REG_TYPE_0_STATUS
, PI_HOST_INT_K_ACK_ALL_TYPE_0
); 1023 * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state 1025 * Note: We only need to clear host copies of these registers. The PDQ reset 1026 * takes care of the on-board register values. 1029 bp
->cmd_req_reg
.lword
=0; 1030 bp
->cmd_rsp_reg
.lword
=0; 1031 bp
->rcv_xmt_reg
.lword
=0; 1033 /* Clear consumer block before going to DMA_AVAILABLE state */ 1035 memset(bp
->cons_block_virt
,0,sizeof(PI_CONSUMER_BLOCK
)); 1037 /* Initialize the DMA Burst Size */ 1039 if(dfx_hw_port_ctrl_req(bp
, 1041 PI_SUB_CMD_K_BURST_SIZE_SET
, 1043 NULL
) != DFX_K_SUCCESS
) 1045 printk("%s: Could not set adapter burst size!\n", bp
->dev
->name
); 1046 return(DFX_K_FAILURE
); 1050 * Set base address of Consumer Block 1052 * Assumption: 32-bit physical address of consumer block is 64 byte 1053 * aligned. That is, bits 0-5 of the address must be zero. 1056 if(dfx_hw_port_ctrl_req(bp
, 1057 PI_PCTRL_M_CONS_BLOCK
, 1058 bp
->cons_block_phys
, 1060 NULL
) != DFX_K_SUCCESS
) 1062 printk("%s: Could not set consumer block address!\n", bp
->dev
->name
); 1063 return(DFX_K_FAILURE
); 1067 * Set base address of Descriptor Block and bring adapter to DMA_AVAILABLE state 1069 * Note: We also set the literal and data swapping requirements in this 1070 * command. Since this driver presently runs on Intel platforms 1071 * which are Little Endian, we'll tell the adapter to byte swap 1072 * data only. This code will need to change when we support 1073 * Big Endian systems (eg. PowerPC). 1075 * Assumption: 32-bit physical address of descriptor block is 8Kbyte 1076 * aligned. That is, bits 0-12 of the address must be zero. 1079 if(dfx_hw_port_ctrl_req(bp
, 1081 (u32
) (bp
->descr_block_phys
| PI_PDATA_A_INIT_M_BSWAP_DATA
), 1083 NULL
) != DFX_K_SUCCESS
) 1085 printk("%s: Could not set descriptor block address!\n", bp
->dev
->name
); 1086 return(DFX_K_FAILURE
); 1089 /* Set transmit flush timeout value */ 1091 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_CHARS_SET
; 1092 bp
->cmd_req_virt
->char_set
.item
[0].item_code
= PI_ITEM_K_FLUSH_TIME
; 1093 bp
->cmd_req_virt
->char_set
.item
[0].value
=3;/* 3 seconds */ 1094 bp
->cmd_req_virt
->char_set
.item
[0].item_index
=0; 1095 bp
->cmd_req_virt
->char_set
.item
[1].item_code
= PI_ITEM_K_EOL
; 1096 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 1098 printk("%s: DMA command request failed!\n", bp
->dev
->name
); 1099 return(DFX_K_FAILURE
); 1102 /* Set the initial values for eFDXEnable and MACTReq MIB objects */ 1104 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_SNMP_SET
; 1105 bp
->cmd_req_virt
->snmp_set
.item
[0].item_code
= PI_ITEM_K_FDX_ENB_DIS
; 1106 bp
->cmd_req_virt
->snmp_set
.item
[0].value
= bp
->full_duplex_enb
; 1107 bp
->cmd_req_virt
->snmp_set
.item
[0].item_index
=0; 1108 bp
->cmd_req_virt
->snmp_set
.item
[1].item_code
= PI_ITEM_K_MAC_T_REQ
; 1109 bp
->cmd_req_virt
->snmp_set
.item
[1].value
= bp
->req_ttrt
; 1110 bp
->cmd_req_virt
->snmp_set
.item
[1].item_index
=0; 1111 bp
->cmd_req_virt
->snmp_set
.item
[2].item_code
= PI_ITEM_K_EOL
; 1112 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 1114 printk("%s: DMA command request failed!\n", bp
->dev
->name
); 1115 return(DFX_K_FAILURE
); 1118 /* Initialize adapter CAM */ 1120 if(dfx_ctl_update_cam(bp
) != DFX_K_SUCCESS
) 1122 printk("%s: Adapter CAM update failed!\n", bp
->dev
->name
); 1123 return(DFX_K_FAILURE
); 1126 /* Initialize adapter filters */ 1128 if(dfx_ctl_update_filters(bp
) != DFX_K_SUCCESS
) 1130 printk("%s: Adapter filters update failed!\n", bp
->dev
->name
); 1131 return(DFX_K_FAILURE
); 1134 /* Initialize receive descriptor block and produce buffers */ 1138 /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */ 1140 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_START
; 1141 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 1143 printk("%s: Start command failed\n", bp
->dev
->name
); 1144 return(DFX_K_FAILURE
); 1147 /* Initialization succeeded, reenable PDQ interrupts */ 1149 dfx_port_write_long(bp
, PI_PDQ_K_REG_HOST_INT_ENB
, PI_HOST_INT_K_ENABLE_DEF_INTS
); 1150 return(DFX_K_SUCCESS
); 1166 * dev - pointer to device information 1168 * Functional Description: 1169 * This function brings the adapter to an operational state. 1172 * 0 - Adapter was successfully opened 1173 * -EAGAIN - Could not register IRQ or adapter initialization failed 1176 * This routine should only be called for a device that was 1177 * initialized successfully. 1180 * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state 1181 * if the open is successful. 1184 static intdfx_open(struct net_device
*dev
) 1186 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 1188 DBG_printk("In dfx_open...\n"); 1192 /* Register IRQ - support shared interrupts by passing device ptr */ 1194 if(request_irq(dev
->irq
, (void*)dfx_interrupt
, SA_SHIRQ
, dev
->name
, dev
)) 1196 printk(KERN_ERR
"%s: Requested IRQ %d is busy\n", dev
->name
, dev
->irq
); 1202 * Set current address to factory MAC address 1204 * Note: We've already done this step in dfx_driver_init. 1205 * However, it's possible that a user has set a node 1206 * address override, then closed and reopened the 1207 * adapter. Unless we reset the device address field 1208 * now, we'll continue to use the existing modified 1212 memcpy(dev
->dev_addr
, bp
->factory_mac_addr
, FDDI_K_ALEN
); 1214 /* Clear local unicast/multicast address tables and counts */ 1216 memset(bp
->uc_table
,0,sizeof(bp
->uc_table
)); 1217 memset(bp
->mc_table
,0,sizeof(bp
->mc_table
)); 1221 /* Disable promiscuous filter settings */ 1223 bp
->ind_group_prom
= PI_FSTATE_K_BLOCK
; 1224 bp
->group_prom
= PI_FSTATE_K_BLOCK
; 1226 spin_lock_init(&bp
->lock
); 1228 /* Reset and initialize adapter */ 1230 bp
->reset_type
= PI_PDATA_A_RESET_M_SKIP_ST
;/* skip self-test */ 1231 if(dfx_adap_init(bp
) != DFX_K_SUCCESS
) 1233 printk(KERN_ERR
"%s: Adapter open failed!\n", dev
->name
); 1234 free_irq(dev
->irq
, dev
); 1239 /* Set device structure info */ 1240 netif_start_queue(dev
); 1251 * Closes the device/module. 1257 * dev - pointer to device information 1259 * Functional Description: 1260 * This routine closes the adapter and brings it to a safe state. 1261 * The interrupt service routine is deregistered with the OS. 1262 * The adapter can be opened again with another call to dfx_open(). 1268 * No further requests for this adapter are made after this routine is 1269 * called. dfx_open() can be called to reset and reinitialize the 1273 * Adapter should be in DMA_UNAVAILABLE state upon completion of this 1277 static intdfx_close(struct net_device
*dev
) 1279 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 1281 DBG_printk("In dfx_close...\n"); 1283 /* Disable PDQ interrupts first */ 1285 dfx_port_write_long(bp
, PI_PDQ_K_REG_HOST_INT_ENB
, PI_HOST_INT_K_DISABLE_ALL_INTS
); 1287 /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */ 1289 (void)dfx_hw_dma_uninit(bp
, PI_PDATA_A_RESET_M_SKIP_ST
); 1292 * Flush any pending transmit buffers 1294 * Note: It's important that we flush the transmit buffers 1295 * BEFORE we clear our copy of the Type 2 register. 1296 * Otherwise, we'll have no idea how many buffers 1303 * Clear Type 1 and Type 2 registers after adapter reset 1305 * Note: Even though we're closing the adapter, it's 1306 * possible that an interrupt will occur after 1307 * dfx_close is called. Without some assurance to 1308 * the contrary we want to make sure that we don't 1309 * process receive and transmit LLC frames and update 1310 * the Type 2 register with bad information. 1313 bp
->cmd_req_reg
.lword
=0; 1314 bp
->cmd_rsp_reg
.lword
=0; 1315 bp
->rcv_xmt_reg
.lword
=0; 1317 /* Clear consumer block for the same reason given above */ 1319 memset(bp
->cons_block_virt
,0,sizeof(PI_CONSUMER_BLOCK
)); 1321 /* Clear device structure flags */ 1323 netif_stop_queue(dev
); 1325 /* Deregister (free) IRQ */ 1327 free_irq(dev
->irq
, dev
); 1335 * ====================== 1336 * = dfx_int_pr_halt_id = 1337 * ====================== 1340 * Displays halt id's in string form. 1346 * bp - pointer to board information 1348 * Functional Description: 1349 * Determine current halt id and display appropriate string. 1361 static voiddfx_int_pr_halt_id(DFX_board_t
*bp
) 1363 PI_UINT32 port_status
;/* PDQ port status register value */ 1364 PI_UINT32 halt_id
;/* PDQ port status halt ID */ 1366 /* Read the latest port status */ 1368 dfx_port_read_long(bp
, PI_PDQ_K_REG_PORT_STATUS
, &port_status
); 1370 /* Display halt state transition information */ 1372 halt_id
= (port_status
& PI_PSTATUS_M_HALT_ID
) >> PI_PSTATUS_V_HALT_ID
; 1375 case PI_HALT_ID_K_SELFTEST_TIMEOUT
: 1376 printk("%s: Halt ID: Selftest Timeout\n", bp
->dev
->name
); 1379 case PI_HALT_ID_K_PARITY_ERROR
: 1380 printk("%s: Halt ID: Host Bus Parity Error\n", bp
->dev
->name
); 1383 case PI_HALT_ID_K_HOST_DIR_HALT
: 1384 printk("%s: Halt ID: Host-Directed Halt\n", bp
->dev
->name
); 1387 case PI_HALT_ID_K_SW_FAULT
: 1388 printk("%s: Halt ID: Adapter Software Fault\n", bp
->dev
->name
); 1391 case PI_HALT_ID_K_HW_FAULT
: 1392 printk("%s: Halt ID: Adapter Hardware Fault\n", bp
->dev
->name
); 1395 case PI_HALT_ID_K_PC_TRACE
: 1396 printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp
->dev
->name
); 1399 case PI_HALT_ID_K_DMA_ERROR
: 1400 printk("%s: Halt ID: Adapter DMA Error\n", bp
->dev
->name
); 1403 case PI_HALT_ID_K_IMAGE_CRC_ERROR
: 1404 printk("%s: Halt ID: Firmware Image CRC Error\n", bp
->dev
->name
); 1407 case PI_HALT_ID_K_BUS_EXCEPTION
: 1408 printk("%s: Halt ID: 68000 Bus Exception\n", bp
->dev
->name
); 1412 printk("%s: Halt ID: Unknown (code = %X)\n", bp
->dev
->name
, halt_id
); 1420 * ========================== 1421 * = dfx_int_type_0_process = 1422 * ========================== 1425 * Processes Type 0 interrupts. 1431 * bp - pointer to board information 1433 * Functional Description: 1434 * Processes all enabled Type 0 interrupts. If the reason for the interrupt 1435 * is a serious fault on the adapter, then an error message is displayed 1436 * and the adapter is reset. 1438 * One tricky potential timing window is the rapid succession of "link avail" 1439 * "link unavail" state change interrupts. The acknowledgement of the Type 0 1440 * interrupt must be done before reading the state from the Port Status 1441 * register. This is true because a state change could occur after reading 1442 * the data, but before acknowledging the interrupt. If this state change 1443 * does happen, it would be lost because the driver is using the old state, 1444 * and it will never know about the new state because it subsequently 1445 * acknowledges the state change interrupt. 1448 * read type 0 int reasons read type 0 int reasons 1449 * read adapter state ack type 0 interrupts 1450 * ack type 0 interrupts read adapter state 1451 * ... process interrupt ... ... process interrupt ... 1460 * An adapter reset may occur if the adapter has any Type 0 error interrupts 1461 * or if the port status indicates that the adapter is halted. The driver 1462 * is responsible for reinitializing the adapter with the current CAM 1463 * contents and adapter filter settings. 1466 static voiddfx_int_type_0_process(DFX_board_t
*bp
) 1469 PI_UINT32 type_0_status
;/* Host Interrupt Type 0 register */ 1470 PI_UINT32 state
;/* current adap state (from port status) */ 1473 * Read host interrupt Type 0 register to determine which Type 0 1474 * interrupts are pending. Immediately write it back out to clear 1478 dfx_port_read_long(bp
, PI_PDQ_K_REG_TYPE_0_STATUS
, &type_0_status
); 1479 dfx_port_write_long(bp
, PI_PDQ_K_REG_TYPE_0_STATUS
, type_0_status
); 1481 /* Check for Type 0 error interrupts */ 1483 if(type_0_status
& (PI_TYPE_0_STAT_M_NXM
| 1484 PI_TYPE_0_STAT_M_PM_PAR_ERR
| 1485 PI_TYPE_0_STAT_M_BUS_PAR_ERR
)) 1487 /* Check for Non-Existent Memory error */ 1489 if(type_0_status
& PI_TYPE_0_STAT_M_NXM
) 1490 printk("%s: Non-Existent Memory Access Error\n", bp
->dev
->name
); 1492 /* Check for Packet Memory Parity error */ 1494 if(type_0_status
& PI_TYPE_0_STAT_M_PM_PAR_ERR
) 1495 printk("%s: Packet Memory Parity Error\n", bp
->dev
->name
); 1497 /* Check for Host Bus Parity error */ 1499 if(type_0_status
& PI_TYPE_0_STAT_M_BUS_PAR_ERR
) 1500 printk("%s: Host Bus Parity Error\n", bp
->dev
->name
); 1502 /* Reset adapter and bring it back on-line */ 1504 bp
->link_available
= PI_K_FALSE
;/* link is no longer available */ 1505 bp
->reset_type
=0;/* rerun on-board diagnostics */ 1506 printk("%s: Resetting adapter...\n", bp
->dev
->name
); 1507 if(dfx_adap_init(bp
) != DFX_K_SUCCESS
) 1509 printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp
->dev
->name
); 1510 dfx_port_write_long(bp
, PI_PDQ_K_REG_HOST_INT_ENB
, PI_HOST_INT_K_DISABLE_ALL_INTS
); 1513 printk("%s: Adapter reset successful!\n", bp
->dev
->name
); 1517 /* Check for transmit flush interrupt */ 1519 if(type_0_status
& PI_TYPE_0_STAT_M_XMT_FLUSH
) 1521 /* Flush any pending xmt's and acknowledge the flush interrupt */ 1523 bp
->link_available
= PI_K_FALSE
;/* link is no longer available */ 1524 dfx_xmt_flush(bp
);/* flush any outstanding packets */ 1525 (void)dfx_hw_port_ctrl_req(bp
, 1526 PI_PCTRL_M_XMT_DATA_FLUSH_DONE
, 1532 /* Check for adapter state change */ 1534 if(type_0_status
& PI_TYPE_0_STAT_M_STATE_CHANGE
) 1536 /* Get latest adapter state */ 1538 state
=dfx_hw_adap_state_rd(bp
);/* get adapter state */ 1539 if(state
== PI_STATE_K_HALTED
) 1542 * Adapter has transitioned to HALTED state, try to reset 1543 * adapter to bring it back on-line. If reset fails, 1544 * leave the adapter in the broken state. 1547 printk("%s: Controller has transitioned to HALTED state!\n", bp
->dev
->name
); 1548 dfx_int_pr_halt_id(bp
);/* display halt id as string */ 1550 /* Reset adapter and bring it back on-line */ 1552 bp
->link_available
= PI_K_FALSE
;/* link is no longer available */ 1553 bp
->reset_type
=0;/* rerun on-board diagnostics */ 1554 printk("%s: Resetting adapter...\n", bp
->dev
->name
); 1555 if(dfx_adap_init(bp
) != DFX_K_SUCCESS
) 1557 printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp
->dev
->name
); 1558 dfx_port_write_long(bp
, PI_PDQ_K_REG_HOST_INT_ENB
, PI_HOST_INT_K_DISABLE_ALL_INTS
); 1561 printk("%s: Adapter reset successful!\n", bp
->dev
->name
); 1563 else if(state
== PI_STATE_K_LINK_AVAIL
) 1565 bp
->link_available
= PI_K_TRUE
;/* set link available flag */ 1573 * ================== 1574 * = dfx_int_common = 1575 * ================== 1578 * Interrupt service routine (ISR) 1584 * bp - pointer to board information 1586 * Functional Description: 1587 * This is the ISR which processes incoming adapter interrupts. 1593 * This routine assumes PDQ interrupts have not been disabled. 1594 * When interrupts are disabled at the PDQ, the Port Status register 1595 * is automatically cleared. This routine uses the Port Status 1596 * register value to determine whether a Type 0 interrupt occurred, 1597 * so it's important that adapter interrupts are not normally 1598 * enabled/disabled at the PDQ. 1600 * It's vital that this routine is NOT reentered for the 1601 * same board and that the OS is not in another section of 1602 * code (eg. dfx_xmt_queue_pkt) for the same board on a 1606 * Pending interrupts are serviced. Depending on the type of 1607 * interrupt, acknowledging and clearing the interrupt at the 1608 * PDQ involves writing a register to clear the interrupt bit 1609 * or updating completion indices. 1612 static voiddfx_int_common(struct net_device
*dev
) 1614 DFX_board_t
*bp
= (DFX_board_t
*) dev
->priv
; 1615 PI_UINT32 port_status
;/* Port Status register */ 1617 /* Process xmt interrupts - frequent case, so always call this routine */ 1619 if(dfx_xmt_done(bp
))/* free consumed xmt packets */ 1620 netif_wake_queue(dev
); 1622 /* Process rcv interrupts - frequent case, so always call this routine */ 1624 dfx_rcv_queue_process(bp
);/* service received LLC frames */ 1627 * Transmit and receive producer and completion indices are updated on the 1628 * adapter by writing to the Type 2 Producer register. Since the frequent 1629 * case is that we'll be processing either LLC transmit or receive buffers, 1630 * we'll optimize I/O writes by doing a single register write here. 1633 dfx_port_write_long(bp
, PI_PDQ_K_REG_TYPE_2_PROD
, bp
->rcv_xmt_reg
.lword
); 1635 /* Read PDQ Port Status register to find out which interrupts need processing */ 1637 dfx_port_read_long(bp
, PI_PDQ_K_REG_PORT_STATUS
, &port_status
); 1639 /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */ 1641 if(port_status
& PI_PSTATUS_M_TYPE_0_PENDING
) 1642 dfx_int_type_0_process(bp
);/* process Type 0 interrupts */ 1653 * Interrupt processing routine 1659 * irq - interrupt vector 1660 * dev_id - pointer to device information 1661 * regs - pointer to registers structure 1663 * Functional Description: 1664 * This routine calls the interrupt processing routine for this adapter. It 1665 * disables and reenables adapter interrupts, as appropriate. We can support 1666 * shared interrupts since the incoming dev_id pointer provides our device 1667 * structure context. 1673 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC 1674 * on Intel-based systems) is done by the operating system outside this 1677 * System interrupts are enabled through this call. 1680 * Interrupts are disabled, then reenabled at the adapter. 1683 static voiddfx_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
) 1685 struct net_device
*dev
= (struct net_device
*) dev_id
; 1686 DFX_board_t
*bp
;/* private board structure pointer */ 1687 u8 tmp
;/* used for disabling/enabling ints */ 1689 /* Get board pointer only if device structure is valid */ 1691 bp
= (DFX_board_t
*) dev
->priv
; 1693 spin_lock(&bp
->lock
); 1695 /* See if we're already servicing an interrupt */ 1697 /* Service adapter interrupts */ 1699 if(bp
->bus_type
== DFX_BUS_TYPE_PCI
) 1701 /* Disable PDQ-PFI interrupts at PFI */ 1703 dfx_port_write_long(bp
, PFI_K_REG_MODE_CTRL
, PFI_MODE_M_DMA_ENB
); 1705 /* Call interrupt service routine for this adapter */ 1707 dfx_int_common(dev
); 1709 /* Clear PDQ interrupt status bit and reenable interrupts */ 1711 dfx_port_write_long(bp
, PFI_K_REG_STATUS
, PFI_STATUS_M_PDQ_INT
); 1712 dfx_port_write_long(bp
, PFI_K_REG_MODE_CTRL
, 1713 (PFI_MODE_M_PDQ_INT_ENB
+ PFI_MODE_M_DMA_ENB
)); 1717 /* Disable interrupts at the ESIC */ 1719 dfx_port_read_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, &tmp
); 1720 tmp
&= ~PI_CONFIG_STAT_0_M_INT_ENB
; 1721 dfx_port_write_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, tmp
); 1723 /* Call interrupt service routine for this adapter */ 1725 dfx_int_common(dev
); 1727 /* Reenable interrupts at the ESIC */ 1729 dfx_port_read_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, &tmp
); 1730 tmp
|= PI_CONFIG_STAT_0_M_INT_ENB
; 1731 dfx_port_write_byte(bp
, PI_ESIC_K_IO_CONFIG_STAT_0
, tmp
); 1734 spin_unlock(&bp
->lock
); 1740 * ===================== 1741 * = dfx_ctl_get_stats = 1742 * ===================== 1745 * Get statistics for FDDI adapter 1748 * Pointer to FDDI statistics structure 1751 * dev - pointer to device information 1753 * Functional Description: 1754 * Gets current MIB objects from adapter, then 1755 * returns FDDI statistics structure as defined 1758 * Note: Since the FDDI statistics structure is 1759 * still new and the device structure doesn't 1760 * have an FDDI-specific get statistics handler, 1761 * we'll return the FDDI statistics structure as 1762 * a pointer to an Ethernet statistics structure. 1763 * That way, at least the first part of the statistics 1764 * structure can be decoded properly, and it allows 1765 * "smart" applications to perform a second cast to 1766 * decode the FDDI-specific statistics. 1768 * We'll have to pay attention to this routine as the 1769 * device structure becomes more mature and LAN media 1782 static struct net_device_stats
*dfx_ctl_get_stats(struct net_device
*dev
) 1784 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 1786 /* Fill the bp->stats structure with driver-maintained counters */ 1788 bp
->stats
.rx_packets
= bp
->rcv_total_frames
; 1789 bp
->stats
.tx_packets
= bp
->xmt_total_frames
; 1790 bp
->stats
.rx_bytes
= bp
->rcv_total_bytes
; 1791 bp
->stats
.tx_bytes
= bp
->xmt_total_bytes
; 1792 bp
->stats
.rx_errors
= (u32
)(bp
->rcv_crc_errors
+ bp
->rcv_frame_status_errors
+ bp
->rcv_length_errors
); 1793 bp
->stats
.tx_errors
= bp
->xmt_length_errors
; 1794 bp
->stats
.rx_dropped
= bp
->rcv_discards
; 1795 bp
->stats
.tx_dropped
= bp
->xmt_discards
; 1796 bp
->stats
.multicast
= bp
->rcv_multicast_frames
; 1797 bp
->stats
.transmit_collision
=0;/* always zero (0) for FDDI */ 1799 /* Get FDDI SMT MIB objects */ 1801 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_SMT_MIB_GET
; 1802 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 1803 return((struct net_device_stats
*) &bp
->stats
); 1805 /* Fill the bp->stats structure with the SMT MIB object values */ 1807 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
)); 1808 bp
->stats
.smt_op_version_id
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_op_version_id
; 1809 bp
->stats
.smt_hi_version_id
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_hi_version_id
; 1810 bp
->stats
.smt_lo_version_id
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_lo_version_id
; 1811 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
)); 1812 bp
->stats
.smt_mib_version_id
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_mib_version_id
; 1813 bp
->stats
.smt_mac_cts
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_mac_ct
; 1814 bp
->stats
.smt_non_master_cts
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_non_master_ct
; 1815 bp
->stats
.smt_master_cts
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_master_ct
; 1816 bp
->stats
.smt_available_paths
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_available_paths
; 1817 bp
->stats
.smt_config_capabilities
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_config_capabilities
; 1818 bp
->stats
.smt_config_policy
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_config_policy
; 1819 bp
->stats
.smt_connection_policy
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_connection_policy
; 1820 bp
->stats
.smt_t_notify
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_t_notify
; 1821 bp
->stats
.smt_stat_rpt_policy
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_stat_rpt_policy
; 1822 bp
->stats
.smt_trace_max_expiration
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_trace_max_expiration
; 1823 bp
->stats
.smt_bypass_present
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_bypass_present
; 1824 bp
->stats
.smt_ecm_state
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_ecm_state
; 1825 bp
->stats
.smt_cf_state
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_cf_state
; 1826 bp
->stats
.smt_remote_disconnect_flag
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_remote_disconnect_flag
; 1827 bp
->stats
.smt_station_status
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_station_status
; 1828 bp
->stats
.smt_peer_wrap_flag
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_peer_wrap_flag
; 1829 bp
->stats
.smt_time_stamp
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_msg_time_stamp
.ls
; 1830 bp
->stats
.smt_transition_time_stamp
= bp
->cmd_rsp_virt
->smt_mib_get
.smt_transition_time_stamp
.ls
; 1831 bp
->stats
.mac_frame_status_functions
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_frame_status_functions
; 1832 bp
->stats
.mac_t_max_capability
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_t_max_capability
; 1833 bp
->stats
.mac_tvx_capability
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_tvx_capability
; 1834 bp
->stats
.mac_available_paths
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_available_paths
; 1835 bp
->stats
.mac_current_path
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_current_path
; 1836 memcpy(bp
->stats
.mac_upstream_nbr
, &bp
->cmd_rsp_virt
->smt_mib_get
.mac_upstream_nbr
, FDDI_K_ALEN
); 1837 memcpy(bp
->stats
.mac_downstream_nbr
, &bp
->cmd_rsp_virt
->smt_mib_get
.mac_downstream_nbr
, FDDI_K_ALEN
); 1838 memcpy(bp
->stats
.mac_old_upstream_nbr
, &bp
->cmd_rsp_virt
->smt_mib_get
.mac_old_upstream_nbr
, FDDI_K_ALEN
); 1839 memcpy(bp
->stats
.mac_old_downstream_nbr
, &bp
->cmd_rsp_virt
->smt_mib_get
.mac_old_downstream_nbr
, FDDI_K_ALEN
); 1840 bp
->stats
.mac_dup_address_test
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_dup_address_test
; 1841 bp
->stats
.mac_requested_paths
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_requested_paths
; 1842 bp
->stats
.mac_downstream_port_type
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_downstream_port_type
; 1843 memcpy(bp
->stats
.mac_smt_address
, &bp
->cmd_rsp_virt
->smt_mib_get
.mac_smt_address
, FDDI_K_ALEN
); 1844 bp
->stats
.mac_t_req
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_t_req
; 1845 bp
->stats
.mac_t_neg
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_t_neg
; 1846 bp
->stats
.mac_t_max
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_t_max
; 1847 bp
->stats
.mac_tvx_value
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_tvx_value
; 1848 bp
->stats
.mac_frame_error_threshold
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_frame_error_threshold
; 1849 bp
->stats
.mac_frame_error_ratio
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_frame_error_ratio
; 1850 bp
->stats
.mac_rmt_state
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_rmt_state
; 1851 bp
->stats
.mac_da_flag
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_da_flag
; 1852 bp
->stats
.mac_una_da_flag
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_unda_flag
; 1853 bp
->stats
.mac_frame_error_flag
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_frame_error_flag
; 1854 bp
->stats
.mac_ma_unitdata_available
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_ma_unitdata_available
; 1855 bp
->stats
.mac_hardware_present
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_hardware_present
; 1856 bp
->stats
.mac_ma_unitdata_enable
= bp
->cmd_rsp_virt
->smt_mib_get
.mac_ma_unitdata_enable
; 1857 bp
->stats
.path_tvx_lower_bound
= bp
->cmd_rsp_virt
->smt_mib_get
.path_tvx_lower_bound
; 1858 bp
->stats
.path_t_max_lower_bound
= bp
->cmd_rsp_virt
->smt_mib_get
.path_t_max_lower_bound
; 1859 bp
->stats
.path_max_t_req
= bp
->cmd_rsp_virt
->smt_mib_get
.path_max_t_req
; 1860 memcpy(bp
->stats
.path_configuration
, &bp
->cmd_rsp_virt
->smt_mib_get
.path_configuration
,sizeof(bp
->cmd_rsp_virt
->smt_mib_get
.path_configuration
)); 1861 bp
->stats
.port_my_type
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_my_type
[0]; 1862 bp
->stats
.port_my_type
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_my_type
[1]; 1863 bp
->stats
.port_neighbor_type
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_neighbor_type
[0]; 1864 bp
->stats
.port_neighbor_type
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_neighbor_type
[1]; 1865 bp
->stats
.port_connection_policies
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_connection_policies
[0]; 1866 bp
->stats
.port_connection_policies
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_connection_policies
[1]; 1867 bp
->stats
.port_mac_indicated
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_mac_indicated
[0]; 1868 bp
->stats
.port_mac_indicated
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_mac_indicated
[1]; 1869 bp
->stats
.port_current_path
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_current_path
[0]; 1870 bp
->stats
.port_current_path
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_current_path
[1]; 1871 memcpy(&bp
->stats
.port_requested_paths
[0*3], &bp
->cmd_rsp_virt
->smt_mib_get
.port_requested_paths
[0],3); 1872 memcpy(&bp
->stats
.port_requested_paths
[1*3], &bp
->cmd_rsp_virt
->smt_mib_get
.port_requested_paths
[1],3); 1873 bp
->stats
.port_mac_placement
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_mac_placement
[0]; 1874 bp
->stats
.port_mac_placement
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_mac_placement
[1]; 1875 bp
->stats
.port_available_paths
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_available_paths
[0]; 1876 bp
->stats
.port_available_paths
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_available_paths
[1]; 1877 bp
->stats
.port_pmd_class
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_pmd_class
[0]; 1878 bp
->stats
.port_pmd_class
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_pmd_class
[1]; 1879 bp
->stats
.port_connection_capabilities
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_connection_capabilities
[0]; 1880 bp
->stats
.port_connection_capabilities
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_connection_capabilities
[1]; 1881 bp
->stats
.port_bs_flag
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_bs_flag
[0]; 1882 bp
->stats
.port_bs_flag
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_bs_flag
[1]; 1883 bp
->stats
.port_ler_estimate
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_estimate
[0]; 1884 bp
->stats
.port_ler_estimate
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_estimate
[1]; 1885 bp
->stats
.port_ler_cutoff
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_cutoff
[0]; 1886 bp
->stats
.port_ler_cutoff
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_cutoff
[1]; 1887 bp
->stats
.port_ler_alarm
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_alarm
[0]; 1888 bp
->stats
.port_ler_alarm
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_alarm
[1]; 1889 bp
->stats
.port_connect_state
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_connect_state
[0]; 1890 bp
->stats
.port_connect_state
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_connect_state
[1]; 1891 bp
->stats
.port_pcm_state
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_pcm_state
[0]; 1892 bp
->stats
.port_pcm_state
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_pcm_state
[1]; 1893 bp
->stats
.port_pc_withhold
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_pc_withhold
[0]; 1894 bp
->stats
.port_pc_withhold
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_pc_withhold
[1]; 1895 bp
->stats
.port_ler_flag
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_flag
[0]; 1896 bp
->stats
.port_ler_flag
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_ler_flag
[1]; 1897 bp
->stats
.port_hardware_present
[0] = bp
->cmd_rsp_virt
->smt_mib_get
.port_hardware_present
[0]; 1898 bp
->stats
.port_hardware_present
[1] = bp
->cmd_rsp_virt
->smt_mib_get
.port_hardware_present
[1]; 1900 /* Get FDDI counters */ 1902 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_CNTRS_GET
; 1903 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 1904 return((struct net_device_stats
*) &bp
->stats
); 1906 /* Fill the bp->stats structure with the FDDI counter values */ 1908 bp
->stats
.mac_frame_cts
= bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.frame_cnt
.ls
; 1909 bp
->stats
.mac_copied_cts
= bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.copied_cnt
.ls
; 1910 bp
->stats
.mac_transmit_cts
= bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.transmit_cnt
.ls
; 1911 bp
->stats
.mac_error_cts
= bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.error_cnt
.ls
; 1912 bp
->stats
.mac_lost_cts
= bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.lost_cnt
.ls
; 1913 bp
->stats
.port_lct_fail_cts
[0] = bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.lct_rejects
[0].ls
; 1914 bp
->stats
.port_lct_fail_cts
[1] = bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.lct_rejects
[1].ls
; 1915 bp
->stats
.port_lem_reject_cts
[0] = bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.lem_rejects
[0].ls
; 1916 bp
->stats
.port_lem_reject_cts
[1] = bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.lem_rejects
[1].ls
; 1917 bp
->stats
.port_lem_cts
[0] = bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.link_errors
[0].ls
; 1918 bp
->stats
.port_lem_cts
[1] = bp
->cmd_rsp_virt
->cntrs_get
.cntrs
.link_errors
[1].ls
; 1920 return((struct net_device_stats
*) &bp
->stats
); 1925 * ============================== 1926 * = dfx_ctl_set_multicast_list = 1927 * ============================== 1930 * Enable/Disable LLC frame promiscuous mode reception 1931 * on the adapter and/or update multicast address table. 1937 * dev - pointer to device information 1939 * Functional Description: 1940 * This routine follows a fairly simple algorithm for setting the 1941 * adapter filters and CAM: 1943 * if IFF_PROMISC flag is set 1944 * enable LLC individual/group promiscuous mode 1946 * disable LLC individual/group promiscuous mode 1947 * if number of incoming multicast addresses > 1948 * (CAM max size - number of unicast addresses in CAM) 1949 * enable LLC group promiscuous mode 1950 * set driver-maintained multicast address count to zero 1952 * disable LLC group promiscuous mode 1953 * set driver-maintained multicast address count to incoming count 1954 * update adapter CAM 1955 * update adapter filters 1961 * Multicast addresses are presented in canonical (LSB) format. 1964 * On-board adapter CAM and filters are updated. 1967 static voiddfx_ctl_set_multicast_list(struct net_device
*dev
) 1969 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 1970 int i
;/* used as index in for loop */ 1971 struct dev_mc_list
*dmi
;/* ptr to multicast addr entry */ 1973 /* Enable LLC frame promiscuous mode, if necessary */ 1975 if(dev
->flags
& IFF_PROMISC
) 1976 bp
->ind_group_prom
= PI_FSTATE_K_PASS
;/* Enable LLC ind/group prom mode */ 1978 /* Else, update multicast address table */ 1982 bp
->ind_group_prom
= PI_FSTATE_K_BLOCK
;/* Disable LLC ind/group prom mode */ 1984 * Check whether incoming multicast address count exceeds table size 1986 * Note: The adapters utilize an on-board 64 entry CAM for 1987 * supporting perfect filtering of multicast packets 1988 * and bridge functions when adding unicast addresses. 1989 * There is no hash function available. To support 1990 * additional multicast addresses, the all multicast 1991 * filter (LLC group promiscuous mode) must be enabled. 1993 * The firmware reserves two CAM entries for SMT-related 1994 * multicast addresses, which leaves 62 entries available. 1995 * The following code ensures that we're not being asked 1996 * to add more than 62 addresses to the CAM. If we are, 1997 * the driver will enable the all multicast filter. 1998 * Should the number of multicast addresses drop below 1999 * the high water mark, the filter will be disabled and 2000 * perfect filtering will be used. 2003 if(dev
->mc_count
> (PI_CMD_ADDR_FILTER_K_SIZE
- bp
->uc_count
)) 2005 bp
->group_prom
= PI_FSTATE_K_PASS
;/* Enable LLC group prom mode */ 2006 bp
->mc_count
=0;/* Don't add mc addrs to CAM */ 2010 bp
->group_prom
= PI_FSTATE_K_BLOCK
;/* Disable LLC group prom mode */ 2011 bp
->mc_count
= dev
->mc_count
;/* Add mc addrs to CAM */ 2014 /* Copy addresses to multicast address table, then update adapter CAM */ 2016 dmi
= dev
->mc_list
;/* point to first multicast addr */ 2017 for(i
=0; i
< bp
->mc_count
; i
++) 2019 memcpy(&bp
->mc_table
[i
*FDDI_K_ALEN
], dmi
->dmi_addr
, FDDI_K_ALEN
); 2020 dmi
= dmi
->next
;/* point to next multicast addr */ 2022 if(dfx_ctl_update_cam(bp
) != DFX_K_SUCCESS
) 2024 DBG_printk("%s: Could not update multicast address table!\n", dev
->name
); 2028 DBG_printk("%s: Multicast address table updated! Added %d addresses.\n", dev
->name
, bp
->mc_count
); 2032 /* Update adapter filters */ 2034 if(dfx_ctl_update_filters(bp
) != DFX_K_SUCCESS
) 2036 DBG_printk("%s: Could not update adapter filters!\n", dev
->name
); 2040 DBG_printk("%s: Adapter filters updated!\n", dev
->name
); 2047 * =========================== 2048 * = dfx_ctl_set_mac_address = 2049 * =========================== 2052 * Add node address override (unicast address) to adapter 2053 * CAM and update dev_addr field in device table. 2059 * dev - pointer to device information 2060 * addr - pointer to sockaddr structure containing unicast address to add 2062 * Functional Description: 2063 * The adapter supports node address overrides by adding one or more 2064 * unicast addresses to the adapter CAM. This is similar to adding 2065 * multicast addresses. In this routine we'll update the driver and 2066 * device structures with the new address, then update the adapter CAM 2067 * to ensure that the adapter will copy and strip frames destined and 2068 * sourced by that address. 2071 * Always returns zero. 2074 * The address pointed to by addr->sa_data is a valid unicast 2075 * address and is presented in canonical (LSB) format. 2078 * On-board adapter CAM is updated. On-board adapter filters 2082 static intdfx_ctl_set_mac_address(struct net_device
*dev
,void*addr
) 2084 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 2085 struct sockaddr
*p_sockaddr
= (struct sockaddr
*)addr
; 2087 /* Copy unicast address to driver-maintained structs and update count */ 2089 memcpy(dev
->dev_addr
, p_sockaddr
->sa_data
, FDDI_K_ALEN
);/* update device struct */ 2090 memcpy(&bp
->uc_table
[0], p_sockaddr
->sa_data
, FDDI_K_ALEN
);/* update driver struct */ 2094 * Verify we're not exceeding the CAM size by adding unicast address 2096 * Note: It's possible that before entering this routine we've 2097 * already filled the CAM with 62 multicast addresses. 2098 * Since we need to place the node address override into 2099 * the CAM, we have to check to see that we're not 2100 * exceeding the CAM size. If we are, we have to enable 2101 * the LLC group (multicast) promiscuous mode filter as 2102 * in dfx_ctl_set_multicast_list. 2105 if((bp
->uc_count
+ bp
->mc_count
) > PI_CMD_ADDR_FILTER_K_SIZE
) 2107 bp
->group_prom
= PI_FSTATE_K_PASS
;/* Enable LLC group prom mode */ 2108 bp
->mc_count
=0;/* Don't add mc addrs to CAM */ 2110 /* Update adapter filters */ 2112 if(dfx_ctl_update_filters(bp
) != DFX_K_SUCCESS
) 2114 DBG_printk("%s: Could not update adapter filters!\n", dev
->name
); 2118 DBG_printk("%s: Adapter filters updated!\n", dev
->name
); 2122 /* Update adapter CAM with new unicast address */ 2124 if(dfx_ctl_update_cam(bp
) != DFX_K_SUCCESS
) 2126 DBG_printk("%s: Could not set new MAC address!\n", dev
->name
); 2130 DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev
->name
); 2132 return(0);/* always return zero */ 2137 * ====================== 2138 * = dfx_ctl_update_cam = 2139 * ====================== 2142 * Procedure to update adapter CAM (Content Addressable Memory) 2143 * with desired unicast and multicast address entries. 2149 * bp - pointer to board information 2151 * Functional Description: 2152 * Updates adapter CAM with current contents of board structure 2153 * unicast and multicast address tables. Since there are only 62 2154 * free entries in CAM, this routine ensures that the command 2155 * request buffer is not overrun. 2158 * DFX_K_SUCCESS - Request succeeded 2159 * DFX_K_FAILURE - Request failed 2162 * All addresses being added (unicast and multicast) are in canonical 2166 * On-board adapter CAM is updated. 2169 static intdfx_ctl_update_cam(DFX_board_t
*bp
) 2171 int i
;/* used as index */ 2172 PI_LAN_ADDR
*p_addr
;/* pointer to CAM entry */ 2175 * Fill in command request information 2177 * Note: Even though both the unicast and multicast address 2178 * table entries are stored as contiguous 6 byte entries, 2179 * the firmware address filter set command expects each 2180 * entry to be two longwords (8 bytes total). We must be 2181 * careful to only copy the six bytes of each unicast and 2182 * multicast table entry into each command entry. This 2183 * is also why we must first clear the entire command 2187 memset(bp
->cmd_req_virt
,0, PI_CMD_REQ_K_SIZE_MAX
);/* first clear buffer */ 2188 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_ADDR_FILTER_SET
; 2189 p_addr
= &bp
->cmd_req_virt
->addr_filter_set
.entry
[0]; 2191 /* Now add unicast addresses to command request buffer, if any */ 2193 for(i
=0; i
< (int)bp
->uc_count
; i
++) 2195 if(i
< PI_CMD_ADDR_FILTER_K_SIZE
) 2197 memcpy(p_addr
, &bp
->uc_table
[i
*FDDI_K_ALEN
], FDDI_K_ALEN
); 2198 p_addr
++;/* point to next command entry */ 2202 /* Now add multicast addresses to command request buffer, if any */ 2204 for(i
=0; i
< (int)bp
->mc_count
; i
++) 2206 if((i
+ bp
->uc_count
) < PI_CMD_ADDR_FILTER_K_SIZE
) 2208 memcpy(p_addr
, &bp
->mc_table
[i
*FDDI_K_ALEN
], FDDI_K_ALEN
); 2209 p_addr
++;/* point to next command entry */ 2213 /* Issue command to update adapter CAM, then return */ 2215 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 2216 return(DFX_K_FAILURE
); 2217 return(DFX_K_SUCCESS
); 2222 * ========================== 2223 * = dfx_ctl_update_filters = 2224 * ========================== 2227 * Procedure to update adapter filters with desired 2234 * bp - pointer to board information 2236 * Functional Description: 2237 * Enables or disables filter using current filter settings. 2240 * DFX_K_SUCCESS - Request succeeded. 2241 * DFX_K_FAILURE - Request failed. 2244 * We must always pass up packets destined to the broadcast 2245 * address (FF-FF-FF-FF-FF-FF), so we'll always keep the 2246 * broadcast filter enabled. 2249 * On-board adapter filters are updated. 2252 static intdfx_ctl_update_filters(DFX_board_t
*bp
) 2254 int i
=0;/* used as index */ 2256 /* Fill in command request information */ 2258 bp
->cmd_req_virt
->cmd_type
= PI_CMD_K_FILTERS_SET
; 2260 /* Initialize Broadcast filter - * ALWAYS ENABLED * */ 2262 bp
->cmd_req_virt
->filter_set
.item
[i
].item_code
= PI_ITEM_K_BROADCAST
; 2263 bp
->cmd_req_virt
->filter_set
.item
[i
++].value
= PI_FSTATE_K_PASS
; 2265 /* Initialize LLC Individual/Group Promiscuous filter */ 2267 bp
->cmd_req_virt
->filter_set
.item
[i
].item_code
= PI_ITEM_K_IND_GROUP_PROM
; 2268 bp
->cmd_req_virt
->filter_set
.item
[i
++].value
= bp
->ind_group_prom
; 2270 /* Initialize LLC Group Promiscuous filter */ 2272 bp
->cmd_req_virt
->filter_set
.item
[i
].item_code
= PI_ITEM_K_GROUP_PROM
; 2273 bp
->cmd_req_virt
->filter_set
.item
[i
++].value
= bp
->group_prom
; 2275 /* Terminate the item code list */ 2277 bp
->cmd_req_virt
->filter_set
.item
[i
].item_code
= PI_ITEM_K_EOL
; 2279 /* Issue command to update adapter filters, then return */ 2281 if(dfx_hw_dma_cmd_req(bp
) != DFX_K_SUCCESS
) 2282 return(DFX_K_FAILURE
); 2283 return(DFX_K_SUCCESS
); 2288 * ====================== 2289 * = dfx_hw_dma_cmd_req = 2290 * ====================== 2293 * Sends PDQ DMA command to adapter firmware 2299 * bp - pointer to board information 2301 * Functional Description: 2302 * The command request and response buffers are posted to the adapter in the manner 2303 * described in the PDQ Port Specification: 2305 * 1. Command Response Buffer is posted to adapter. 2306 * 2. Command Request Buffer is posted to adapter. 2307 * 3. Command Request consumer index is polled until it indicates that request 2308 * buffer has been DMA'd to adapter. 2309 * 4. Command Response consumer index is polled until it indicates that response 2310 * buffer has been DMA'd from adapter. 2312 * This ordering ensures that a response buffer is already available for the firmware 2313 * to use once it's done processing the request buffer. 2316 * DFX_K_SUCCESS - DMA command succeeded 2317 * DFX_K_OUTSTATE - Adapter is NOT in proper state 2318 * DFX_K_HW_TIMEOUT - DMA command timed out 2321 * Command request buffer has already been filled with desired DMA command. 2327 static intdfx_hw_dma_cmd_req(DFX_board_t
*bp
) 2329 int status
;/* adapter status */ 2330 int timeout_cnt
;/* used in for loops */ 2332 /* Make sure the adapter is in a state that we can issue the DMA command in */ 2334 status
=dfx_hw_adap_state_rd(bp
); 2335 if((status
== PI_STATE_K_RESET
) || 2336 (status
== PI_STATE_K_HALTED
) || 2337 (status
== PI_STATE_K_DMA_UNAVAIL
) || 2338 (status
== PI_STATE_K_UPGRADE
)) 2339 return(DFX_K_OUTSTATE
); 2341 /* Put response buffer on the command response queue */ 2343 bp
->descr_block_virt
->cmd_rsp
[bp
->cmd_rsp_reg
.index
.prod
].long_0
= (u32
) (PI_RCV_DESCR_M_SOP
| 2344 ((PI_CMD_RSP_K_SIZE_MAX
/ PI_ALIGN_K_CMD_RSP_BUFF
) << PI_RCV_DESCR_V_SEG_LEN
)); 2345 bp
->descr_block_virt
->cmd_rsp
[bp
->cmd_rsp_reg
.index
.prod
].long_1
= bp
->cmd_rsp_phys
; 2347 /* Bump (and wrap) the producer index and write out to register */ 2349 bp
->cmd_rsp_reg
.index
.prod
+=1; 2350 bp
->cmd_rsp_reg
.index
.prod
&= PI_CMD_RSP_K_NUM_ENTRIES
-1; 2351 dfx_port_write_long(bp
, PI_PDQ_K_REG_CMD_RSP_PROD
, bp
->cmd_rsp_reg
.lword
); 2353 /* Put request buffer on the command request queue */ 2355 bp
->descr_block_virt
->cmd_req
[bp
->cmd_req_reg
.index
.prod
].long_0
= (u32
) (PI_XMT_DESCR_M_SOP
| 2356 PI_XMT_DESCR_M_EOP
| (PI_CMD_REQ_K_SIZE_MAX
<< PI_XMT_DESCR_V_SEG_LEN
)); 2357 bp
->descr_block_virt
->cmd_req
[bp
->cmd_req_reg
.index
.prod
].long_1
= bp
->cmd_req_phys
; 2359 /* Bump (and wrap) the producer index and write out to register */ 2361 bp
->cmd_req_reg
.index
.prod
+=1; 2362 bp
->cmd_req_reg
.index
.prod
&= PI_CMD_REQ_K_NUM_ENTRIES
-1; 2363 dfx_port_write_long(bp
, PI_PDQ_K_REG_CMD_REQ_PROD
, bp
->cmd_req_reg
.lword
); 2366 * Here we wait for the command request consumer index to be equal 2367 * to the producer, indicating that the adapter has DMAed the request. 2370 for(timeout_cnt
=20000; timeout_cnt
>0; timeout_cnt
--) 2372 if(bp
->cmd_req_reg
.index
.prod
== (u8
)(bp
->cons_block_virt
->cmd_req
)) 2374 udelay(100);/* wait for 100 microseconds */ 2377 return(DFX_K_HW_TIMEOUT
); 2379 /* Bump (and wrap) the completion index and write out to register */ 2381 bp
->cmd_req_reg
.index
.comp
+=1; 2382 bp
->cmd_req_reg
.index
.comp
&= PI_CMD_REQ_K_NUM_ENTRIES
-1; 2383 dfx_port_write_long(bp
, PI_PDQ_K_REG_CMD_REQ_PROD
, bp
->cmd_req_reg
.lword
); 2386 * Here we wait for the command response consumer index to be equal 2387 * to the producer, indicating that the adapter has DMAed the response. 2390 for(timeout_cnt
=20000; timeout_cnt
>0; timeout_cnt
--) 2392 if(bp
->cmd_rsp_reg
.index
.prod
== (u8
)(bp
->cons_block_virt
->cmd_rsp
)) 2394 udelay(100);/* wait for 100 microseconds */ 2397 return(DFX_K_HW_TIMEOUT
); 2399 /* Bump (and wrap) the completion index and write out to register */ 2401 bp
->cmd_rsp_reg
.index
.comp
+=1; 2402 bp
->cmd_rsp_reg
.index
.comp
&= PI_CMD_RSP_K_NUM_ENTRIES
-1; 2403 dfx_port_write_long(bp
, PI_PDQ_K_REG_CMD_RSP_PROD
, bp
->cmd_rsp_reg
.lword
); 2404 return(DFX_K_SUCCESS
); 2409 * ======================== 2410 * = dfx_hw_port_ctrl_req = 2411 * ======================== 2414 * Sends PDQ port control command to adapter firmware 2417 * Host data register value in host_data if ptr is not NULL 2420 * bp - pointer to board information 2421 * command - port control command 2422 * data_a - port data A register value 2423 * data_b - port data B register value 2424 * host_data - ptr to host data register value 2426 * Functional Description: 2427 * Send generic port control command to adapter by writing 2428 * to various PDQ port registers, then polling for completion. 2431 * DFX_K_SUCCESS - port control command succeeded 2432 * DFX_K_HW_TIMEOUT - port control command timed out 2441 static intdfx_hw_port_ctrl_req( 2446 PI_UINT32
*host_data
2450 PI_UINT32 port_cmd
;/* Port Control command register value */ 2451 int timeout_cnt
;/* used in for loops */ 2453 /* Set Command Error bit in command longword */ 2455 port_cmd
= (PI_UINT32
) (command
| PI_PCTRL_M_CMD_ERROR
); 2457 /* Issue port command to the adapter */ 2459 dfx_port_write_long(bp
, PI_PDQ_K_REG_PORT_DATA_A
, data_a
); 2460 dfx_port_write_long(bp
, PI_PDQ_K_REG_PORT_DATA_B
, data_b
); 2461 dfx_port_write_long(bp
, PI_PDQ_K_REG_PORT_CTRL
, port_cmd
); 2463 /* Now wait for command to complete */ 2465 if(command
== PI_PCTRL_M_BLAST_FLASH
) 2466 timeout_cnt
=600000;/* set command timeout count to 60 seconds */ 2468 timeout_cnt
=20000;/* set command timeout count to 2 seconds */ 2470 for(; timeout_cnt
>0; timeout_cnt
--) 2472 dfx_port_read_long(bp
, PI_PDQ_K_REG_PORT_CTRL
, &port_cmd
); 2473 if(!(port_cmd
& PI_PCTRL_M_CMD_ERROR
)) 2475 udelay(100);/* wait for 100 microseconds */ 2478 return(DFX_K_HW_TIMEOUT
); 2481 * If the address of host_data is non-zero, assume caller has supplied a 2482 * non NULL pointer, and return the contents of the HOST_DATA register in 2486 if(host_data
!= NULL
) 2487 dfx_port_read_long(bp
, PI_PDQ_K_REG_HOST_DATA
, host_data
); 2488 return(DFX_K_SUCCESS
); 2493 * ===================== 2494 * = dfx_hw_adap_reset = 2495 * ===================== 2504 * bp - pointer to board information 2505 * type - type of reset to perform 2507 * Functional Description: 2508 * Issue soft reset to adapter by writing to PDQ Port Reset 2509 * register. Use incoming reset type to tell adapter what 2510 * kind of reset operation to perform. 2516 * This routine merely issues a soft reset to the adapter. 2517 * It is expected that after this routine returns, the caller 2518 * will appropriately poll the Port Status register for the 2519 * adapter to enter the proper state. 2522 * Internal adapter registers are cleared. 2525 static voiddfx_hw_adap_reset( 2531 /* Set Reset type and assert reset */ 2533 dfx_port_write_long(bp
, PI_PDQ_K_REG_PORT_DATA_A
, type
);/* tell adapter type of reset */ 2534 dfx_port_write_long(bp
, PI_PDQ_K_REG_PORT_RESET
, PI_RESET_M_ASSERT_RESET
); 2536 /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */ 2540 /* Deassert reset */ 2542 dfx_port_write_long(bp
, PI_PDQ_K_REG_PORT_RESET
,0); 2548 * ======================== 2549 * = dfx_hw_adap_state_rd = 2550 * ======================== 2553 * Returns current adapter state 2556 * Adapter state per PDQ Port Specification 2559 * bp - pointer to board information 2561 * Functional Description: 2562 * Reads PDQ Port Status register and returns adapter state. 2574 static intdfx_hw_adap_state_rd(DFX_board_t
*bp
) 2576 PI_UINT32 port_status
;/* Port Status register value */ 2578 dfx_port_read_long(bp
, PI_PDQ_K_REG_PORT_STATUS
, &port_status
); 2579 return((port_status
& PI_PSTATUS_M_STATE
) >> PI_PSTATUS_V_STATE
); 2584 * ===================== 2585 * = dfx_hw_dma_uninit = 2586 * ===================== 2589 * Brings adapter to DMA_UNAVAILABLE state 2595 * bp - pointer to board information 2596 * type - type of reset to perform 2598 * Functional Description: 2599 * Bring adapter to DMA_UNAVAILABLE state by performing the following: 2600 * 1. Set reset type bit in Port Data A Register then reset adapter. 2601 * 2. Check that adapter is in DMA_UNAVAILABLE state. 2604 * DFX_K_SUCCESS - adapter is in DMA_UNAVAILABLE state 2605 * DFX_K_HW_TIMEOUT - adapter did not reset properly 2611 * Internal adapter registers are cleared. 2614 static intdfx_hw_dma_uninit(DFX_board_t
*bp
, PI_UINT32 type
) 2616 int timeout_cnt
;/* used in for loops */ 2618 /* Set reset type bit and reset adapter */ 2620 dfx_hw_adap_reset(bp
, type
); 2622 /* Now wait for adapter to enter DMA_UNAVAILABLE state */ 2624 for(timeout_cnt
=100000; timeout_cnt
>0; timeout_cnt
--) 2626 if(dfx_hw_adap_state_rd(bp
) == PI_STATE_K_DMA_UNAVAIL
) 2628 udelay(100);/* wait for 100 microseconds */ 2631 return(DFX_K_HW_TIMEOUT
); 2632 return(DFX_K_SUCCESS
); 2637 * Align an sk_buff to a boundary power of 2 2641 static voidmy_skb_align(struct sk_buff
*skb
,int n
) 2643 u32 x
=(u32
)skb
->data
;/* We only want the low bits .. */ 2646 v
=(x
+n
-1)&~(n
-1);/* Where we want to be */ 2648 skb_reserve(skb
, v
-x
); 2658 * Produces buffers to adapter LLC Host receive descriptor block 2664 * bp - pointer to board information 2666 * Functional Description: 2667 * This routine can be called during dfx_adap_init() or during an adapter 2668 * reset. It initializes the descriptor block and produces all allocated 2669 * LLC Host queue receive buffers. 2675 * The PDQ has been reset and the adapter and driver maintained Type 2 2676 * register indices are cleared. 2679 * Receive buffers are posted to the adapter LLC queue and the adapter 2683 static voiddfx_rcv_init(DFX_board_t
*bp
) 2685 int i
, j
;/* used in for loop */ 2688 * Since each receive buffer is a single fragment of same length, initialize 2689 * first longword in each receive descriptor for entire LLC Host descriptor 2690 * block. Also initialize second longword in each receive descriptor with 2691 * physical address of receive buffer. We'll always allocate receive 2692 * buffers in powers of 2 so that we can easily fill the 256 entry descriptor 2693 * block and produce new receive buffers by simply updating the receive 2697 * To support all shipping versions of PDQ, the receive buffer size 2698 * must be mod 128 in length and the physical address must be 128 byte 2699 * aligned. In other words, bits 0-6 of the length and address must 2700 * be zero for the following descriptor field entries to be correct on 2701 * all PDQ-based boards. We guaranteed both requirements during 2702 * driver initialization when we allocated memory for the receive buffers. 2705 #ifdef DYNAMIC_BUFFERS 2706 for(i
=0; i
< (int)(bp
->rcv_bufs_to_post
); i
++) 2707 for(j
=0; (i
+ j
) < (int)PI_RCV_DATA_K_NUM_ENTRIES
; j
+= bp
->rcv_bufs_to_post
) 2709 struct sk_buff
*newskb
; 2710 bp
->descr_block_virt
->rcv_data
[i
+j
].long_0
= (u32
) (PI_RCV_DESCR_M_SOP
| 2711 ((PI_RCV_DATA_K_SIZE_MAX
/ PI_ALIGN_K_RCV_DATA_BUFF
) << PI_RCV_DESCR_V_SEG_LEN
)); 2712 newskb
=dev_alloc_skb(NEW_SKB_SIZE
); 2714 * align to 128 bytes for compatibility with 2715 * the old EISA boards. 2718 my_skb_align(newskb
,128); 2719 bp
->descr_block_virt
->rcv_data
[i
+j
].long_1
=virt_to_bus(newskb
->data
); 2721 * p_rcv_buff_va is only used inside the 2722 * kernel so we put the skb pointer here. 2724 bp
->p_rcv_buff_va
[i
+j
] = (char*) newskb
; 2727 for(i
=0; i
< (int)(bp
->rcv_bufs_to_post
); i
++) 2728 for(j
=0; (i
+ j
) < (int)PI_RCV_DATA_K_NUM_ENTRIES
; j
+= bp
->rcv_bufs_to_post
) 2730 bp
->descr_block_virt
->rcv_data
[i
+j
].long_0
= (u32
) (PI_RCV_DESCR_M_SOP
| 2731 ((PI_RCV_DATA_K_SIZE_MAX
/ PI_ALIGN_K_RCV_DATA_BUFF
) << PI_RCV_DESCR_V_SEG_LEN
)); 2732 bp
->descr_block_virt
->rcv_data
[i
+j
].long_1
= (u32
) (bp
->rcv_block_phys
+ (i
* PI_RCV_DATA_K_SIZE_MAX
)); 2733 bp
->p_rcv_buff_va
[i
+j
] = (char*) (bp
->rcv_block_virt
+ (i
* PI_RCV_DATA_K_SIZE_MAX
)); 2737 /* Update receive producer and Type 2 register */ 2739 bp
->rcv_xmt_reg
.index
.rcv_prod
= bp
->rcv_bufs_to_post
; 2740 dfx_port_write_long(bp
, PI_PDQ_K_REG_TYPE_2_PROD
, bp
->rcv_xmt_reg
.lword
); 2746 * ========================= 2747 * = dfx_rcv_queue_process = 2748 * ========================= 2751 * Process received LLC frames. 2757 * bp - pointer to board information 2759 * Functional Description: 2760 * Received LLC frames are processed until there are no more consumed frames. 2761 * Once all frames are processed, the receive buffers are returned to the 2762 * adapter. Note that this algorithm fixes the length of time that can be spent 2763 * in this routine, because there are a fixed number of receive buffers to 2764 * process and buffers are not produced until this routine exits and returns 2777 static voiddfx_rcv_queue_process( 2782 PI_TYPE_2_CONSUMER
*p_type_2_cons
;/* ptr to rcv/xmt consumer block register */ 2783 char*p_buff
;/* ptr to start of packet receive buffer (FMC descriptor) */ 2784 u32 descr
, pkt_len
;/* FMC descriptor field and packet length */ 2785 struct sk_buff
*skb
;/* pointer to a sk_buff to hold incoming packet data */ 2787 /* Service all consumed LLC receive frames */ 2789 p_type_2_cons
= (PI_TYPE_2_CONSUMER
*)(&bp
->cons_block_virt
->xmt_rcv_data
); 2790 while(bp
->rcv_xmt_reg
.index
.rcv_comp
!= p_type_2_cons
->index
.rcv_cons
) 2792 /* Process any errors */ 2796 entry
= bp
->rcv_xmt_reg
.index
.rcv_comp
; 2797 #ifdef DYNAMIC_BUFFERS 2798 p_buff
= (char*) (((struct sk_buff
*)bp
->p_rcv_buff_va
[entry
])->data
); 2800 p_buff
= (char*) bp
->p_rcv_buff_va
[entry
]; 2802 memcpy(&descr
, p_buff
+ RCV_BUFF_K_DESCR
,sizeof(u32
)); 2804 if(descr
& PI_FMC_DESCR_M_RCC_FLUSH
) 2806 if(descr
& PI_FMC_DESCR_M_RCC_CRC
) 2807 bp
->rcv_crc_errors
++; 2809 bp
->rcv_frame_status_errors
++; 2815 /* The frame was received without errors - verify packet length */ 2817 pkt_len
= (u32
)((descr
& PI_FMC_DESCR_M_LEN
) >> PI_FMC_DESCR_V_LEN
); 2818 pkt_len
-=4;/* subtract 4 byte CRC */ 2819 if(!IN_RANGE(pkt_len
, FDDI_K_LLC_ZLEN
, FDDI_K_LLC_LEN
)) 2820 bp
->rcv_length_errors
++; 2822 #ifdef DYNAMIC_BUFFERS 2823 if(pkt_len
> SKBUFF_RX_COPYBREAK
) { 2824 struct sk_buff
*newskb
; 2826 newskb
=dev_alloc_skb(NEW_SKB_SIZE
); 2830 my_skb_align(newskb
,128); 2831 skb
= (struct sk_buff
*)bp
->p_rcv_buff_va
[entry
]; 2832 skb_reserve(skb
, RCV_BUFF_K_PADDING
); 2833 bp
->p_rcv_buff_va
[entry
] = (char*)newskb
; 2834 bp
->descr_block_virt
->rcv_data
[entry
].long_1
=virt_to_bus(newskb
->data
); 2839 skb
=dev_alloc_skb(pkt_len
+3);/* alloc new buffer to pass up, add room for PRH */ 2842 printk("%s: Could not allocate receive buffer. Dropping packet.\n", bp
->dev
->name
); 2847 #ifndef DYNAMIC_BUFFERS 2851 /* Receive buffer allocated, pass receive packet up */ 2853 memcpy(skb
->data
, p_buff
+ RCV_BUFF_K_PADDING
, pkt_len
+3); 2856 skb_reserve(skb
,3);/* adjust data field so that it points to FC byte */ 2857 skb_put(skb
, pkt_len
);/* pass up packet length, NOT including CRC */ 2858 skb
->dev
= bp
->dev
;/* pass up device pointer */ 2860 skb
->protocol
=fddi_type_trans(skb
, bp
->dev
); 2863 /* Update the rcv counters */ 2865 bp
->rcv_total_frames
++; 2866 if(*(p_buff
+ RCV_BUFF_K_DA
) &0x01) 2867 bp
->rcv_multicast_frames
++; 2869 bp
->rcv_total_bytes
+= skb
->len
; 2875 * Advance the producer (for recycling) and advance the completion 2876 * (for servicing received frames). Note that it is okay to 2877 * advance the producer without checking that it passes the 2878 * completion index because they are both advanced at the same 2882 bp
->rcv_xmt_reg
.index
.rcv_prod
+=1; 2883 bp
->rcv_xmt_reg
.index
.rcv_comp
+=1; 2890 * ===================== 2891 * = dfx_xmt_queue_pkt = 2892 * ===================== 2895 * Queues packets for transmission 2901 * skb - pointer to sk_buff to queue for transmission 2902 * dev - pointer to device information 2904 * Functional Description: 2905 * Here we assume that an incoming skb transmit request 2906 * is contained in a single physically contiguous buffer 2907 * in which the virtual address of the start of packet 2908 * (skb->data) can be converted to a physical address 2909 * by using virt_to_bus(). 2911 * Since the adapter architecture requires a three byte 2912 * packet request header to prepend the start of packet, 2913 * we'll write the three byte field immediately prior to 2914 * the FC byte. This assumption is valid because we've 2915 * ensured that dev->hard_header_len includes three pad 2916 * bytes. By posting a single fragment to the adapter, 2917 * we'll reduce the number of descriptor fetches and 2918 * bus traffic needed to send the request. 2920 * Also, we can't free the skb until after it's been DMA'd 2921 * out by the adapter, so we'll queue it in the driver and 2922 * return it in dfx_xmt_done. 2925 * 0 - driver queued packet, link is unavailable, or skbuff was bad 2926 * 1 - caller should requeue the sk_buff for later transmission 2929 * First and foremost, we assume the incoming skb pointer 2930 * is NOT NULL and is pointing to a valid sk_buff structure. 2932 * The outgoing packet is complete, starting with the 2933 * frame control byte including the last byte of data, 2934 * but NOT including the 4 byte CRC. We'll let the 2935 * adapter hardware generate and append the CRC. 2937 * The entire packet is stored in one physically 2938 * contiguous buffer which is not cached and whose 2939 * 32-bit physical address can be determined. 2941 * It's vital that this routine is NOT reentered for the 2942 * same board and that the OS is not in another section of 2943 * code (eg. dfx_int_common) for the same board on a 2950 static intdfx_xmt_queue_pkt( 2951 struct sk_buff
*skb
, 2952 struct net_device
*dev
2956 DFX_board_t
*bp
= (DFX_board_t
*) dev
->priv
; 2957 u8 prod
;/* local transmit producer index */ 2958 PI_XMT_DESCR
*p_xmt_descr
;/* ptr to transmit descriptor block entry */ 2959 XMT_DRIVER_DESCR
*p_xmt_drv_descr
;/* ptr to transmit driver descriptor */ 2960 unsigned long flags
; 2962 netif_stop_queue(dev
); 2965 * Verify that incoming transmit request is OK 2967 * Note: The packet size check is consistent with other 2968 * Linux device drivers, although the correct packet 2969 * size should be verified before calling the 2973 if(!IN_RANGE(skb
->len
, FDDI_K_LLC_ZLEN
, FDDI_K_LLC_LEN
)) 2975 printk("%s: Invalid packet length - %u bytes\n", 2976 dev
->name
, skb
->len
); 2977 bp
->xmt_length_errors
++;/* bump error counter */ 2978 netif_wake_queue(dev
); 2980 return(0);/* return "success" */ 2983 * See if adapter link is available, if not, free buffer 2985 * Note: If the link isn't available, free buffer and return 0 2986 * rather than tell the upper layer to requeue the packet. 2987 * The methodology here is that by the time the link 2988 * becomes available, the packet to be sent will be 2989 * fairly stale. By simply dropping the packet, the 2990 * higher layer protocols will eventually time out 2991 * waiting for response packets which it won't receive. 2994 if(bp
->link_available
== PI_K_FALSE
) 2996 if(dfx_hw_adap_state_rd(bp
) == PI_STATE_K_LINK_AVAIL
)/* is link really available? */ 2997 bp
->link_available
= PI_K_TRUE
;/* if so, set flag and continue */ 3000 bp
->xmt_discards
++;/* bump error counter */ 3001 dev_kfree_skb(skb
);/* free sk_buff now */ 3002 netif_wake_queue(dev
); 3003 return(0);/* return "success" */ 3007 spin_lock_irqsave(&bp
->lock
, flags
); 3009 /* Get the current producer and the next free xmt data descriptor */ 3011 prod
= bp
->rcv_xmt_reg
.index
.xmt_prod
; 3012 p_xmt_descr
= &(bp
->descr_block_virt
->xmt_data
[prod
]); 3015 * Get pointer to auxiliary queue entry to contain information 3018 * Note: The current xmt producer index will become the 3019 * current xmt completion index when we complete this 3020 * packet later on. So, we'll get the pointer to the 3021 * next auxiliary queue entry now before we bump the 3025 p_xmt_drv_descr
= &(bp
->xmt_drv_descr_blk
[prod
++]);/* also bump producer index */ 3027 /* Write the three PRH bytes immediately before the FC byte */ 3030 skb
->data
[0] = DFX_PRH0_BYTE
;/* these byte values are defined */ 3031 skb
->data
[1] = DFX_PRH1_BYTE
;/* in the Motorola FDDI MAC chip */ 3032 skb
->data
[2] = DFX_PRH2_BYTE
;/* specification */ 3035 * Write the descriptor with buffer info and bump producer 3037 * Note: Since we need to start DMA from the packet request 3038 * header, we'll add 3 bytes to the DMA buffer length, 3039 * and we'll determine the physical address of the 3040 * buffer from the PRH, not skb->data. 3043 * 1. Packet starts with the frame control (FC) byte 3045 * 2. The 4-byte CRC is not appended to the buffer or 3046 * included in the length. 3047 * 3. Packet length (skb->len) is from FC to end of 3049 * 4. The packet length does not exceed the maximum 3050 * FDDI LLC frame length of 4491 bytes. 3051 * 5. The entire packet is contained in a physically 3052 * contiguous, non-cached, locked memory space 3053 * comprised of a single buffer pointed to by 3055 * 6. The physical address of the start of packet 3056 * can be determined from the virtual address 3057 * by using virt_to_bus() and is only 32-bits 3061 p_xmt_descr
->long_0
= (u32
) (PI_XMT_DESCR_M_SOP
| PI_XMT_DESCR_M_EOP
| ((skb
->len
) << PI_XMT_DESCR_V_SEG_LEN
)); 3062 p_xmt_descr
->long_1
= (u32
)virt_to_bus(skb
->data
); 3065 * Verify that descriptor is actually available 3067 * Note: If descriptor isn't available, return 1 which tells 3068 * the upper layer to requeue the packet for later 3071 * We need to ensure that the producer never reaches the 3072 * completion, except to indicate that the queue is empty. 3075 if(prod
== bp
->rcv_xmt_reg
.index
.xmt_comp
) 3078 spin_unlock_irqrestore(&bp
->lock
, flags
); 3079 return(1);/* requeue packet for later */ 3083 * Save info for this packet for xmt done indication routine 3085 * Normally, we'd save the producer index in the p_xmt_drv_descr 3086 * structure so that we'd have it handy when we complete this 3087 * packet later (in dfx_xmt_done). However, since the current 3088 * transmit architecture guarantees a single fragment for the 3089 * entire packet, we can simply bump the completion index by 3090 * one (1) for each completed packet. 3092 * Note: If this assumption changes and we're presented with 3093 * an inconsistent number of transmit fragments for packet 3094 * data, we'll need to modify this code to save the current 3095 * transmit producer index. 3098 p_xmt_drv_descr
->p_skb
= skb
; 3100 /* Update Type 2 register */ 3102 bp
->rcv_xmt_reg
.index
.xmt_prod
= prod
; 3103 dfx_port_write_long(bp
, PI_PDQ_K_REG_TYPE_2_PROD
, bp
->rcv_xmt_reg
.lword
); 3104 spin_unlock_irqrestore(&bp
->lock
, flags
); 3105 netif_wake_queue(dev
); 3106 return(0);/* packet queued to adapter */ 3116 * Processes all frames that have been transmitted. 3122 * bp - pointer to board information 3124 * Functional Description: 3125 * For all consumed transmit descriptors that have not 3126 * yet been completed, we'll free the skb we were holding 3127 * onto using dev_kfree_skb and bump the appropriate 3134 * The Type 2 register is not updated in this routine. It is 3135 * assumed that it will be updated in the ISR when dfx_xmt_done 3142 static intdfx_xmt_done(DFX_board_t
*bp
) 3144 XMT_DRIVER_DESCR
*p_xmt_drv_descr
;/* ptr to transmit driver descriptor */ 3145 PI_TYPE_2_CONSUMER
*p_type_2_cons
;/* ptr to rcv/xmt consumer block register */ 3146 int freed
=0;/* buffers freed */ 3148 /* Service all consumed transmit frames */ 3150 p_type_2_cons
= (PI_TYPE_2_CONSUMER
*)(&bp
->cons_block_virt
->xmt_rcv_data
); 3151 while(bp
->rcv_xmt_reg
.index
.xmt_comp
!= p_type_2_cons
->index
.xmt_cons
) 3153 /* Get pointer to the transmit driver descriptor block information */ 3155 p_xmt_drv_descr
= &(bp
->xmt_drv_descr_blk
[bp
->rcv_xmt_reg
.index
.xmt_comp
]); 3157 /* Increment transmit counters */ 3159 bp
->xmt_total_frames
++; 3160 bp
->xmt_total_bytes
+= p_xmt_drv_descr
->p_skb
->len
; 3162 /* Return skb to operating system */ 3164 dev_kfree_skb_irq(p_xmt_drv_descr
->p_skb
); 3167 * Move to start of next packet by updating completion index 3169 * Here we assume that a transmit packet request is always 3170 * serviced by posting one fragment. We can therefore 3171 * simplify the completion code by incrementing the 3172 * completion index by one. This code will need to be 3173 * modified if this assumption changes. See comments 3174 * in dfx_xmt_queue_pkt for more details. 3177 bp
->rcv_xmt_reg
.index
.xmt_comp
+=1; 3190 * Processes all frames whether they've been transmitted 3197 * bp - pointer to board information 3199 * Functional Description: 3200 * For all produced transmit descriptors that have not 3201 * yet been completed, we'll free the skb we were holding 3202 * onto using dev_kfree_skb and bump the appropriate 3203 * counters. Of course, it's possible that some of 3204 * these transmit requests actually did go out, but we 3205 * won't make that distinction here. Finally, we'll 3206 * update the consumer index to match the producer. 3212 * This routine does NOT update the Type 2 register. It 3213 * is assumed that this routine is being called during a 3214 * transmit flush interrupt, or a shutdown or close routine. 3220 static voiddfx_xmt_flush( DFX_board_t
*bp
) 3222 u32 prod_cons
;/* rcv/xmt consumer block longword */ 3223 XMT_DRIVER_DESCR
*p_xmt_drv_descr
;/* ptr to transmit driver descriptor */ 3225 /* Flush all outstanding transmit frames */ 3227 while(bp
->rcv_xmt_reg
.index
.xmt_comp
!= bp
->rcv_xmt_reg
.index
.xmt_prod
) 3229 /* Get pointer to the transmit driver descriptor block information */ 3231 p_xmt_drv_descr
= &(bp
->xmt_drv_descr_blk
[bp
->rcv_xmt_reg
.index
.xmt_comp
]); 3233 /* Return skb to operating system */ 3235 dev_kfree_skb(p_xmt_drv_descr
->p_skb
); 3237 /* Increment transmit error counter */ 3242 * Move to start of next packet by updating completion index 3244 * Here we assume that a transmit packet request is always 3245 * serviced by posting one fragment. We can therefore 3246 * simplify the completion code by incrementing the 3247 * completion index by one. This code will need to be 3248 * modified if this assumption changes. See comments 3249 * in dfx_xmt_queue_pkt for more details. 3252 bp
->rcv_xmt_reg
.index
.xmt_comp
+=1; 3255 /* Update the transmit consumer index in the consumer block */ 3257 prod_cons
= (u32
)(bp
->cons_block_virt
->xmt_rcv_data
& ~PI_CONS_M_XMT_INDEX
); 3258 prod_cons
|= (u32
)(bp
->rcv_xmt_reg
.index
.xmt_prod
<< PI_CONS_V_XMT_INDEX
); 3259 bp
->cons_block_virt
->xmt_rcv_data
= prod_cons
; 3263 static void __devexit
dfx_remove_one_pci_or_eisa(struct pci_dev
*pdev
,struct net_device
*dev
) 3265 DFX_board_t
*bp
= (DFX_board_t
*)dev
->priv
; 3267 unregister_netdev(dev
); 3268 release_region(dev
->base_addr
, pdev
? PFI_K_CSR_IO_LEN
: PI_ESIC_K_CSR_IO_LEN
); 3269 if(bp
->kmalloced
)kfree(bp
->kmalloced
); 3273 static void __devexit
dfx_remove_one(struct pci_dev
*pdev
) 3275 struct net_device
*dev
= pdev
->driver_data
; 3277 dfx_remove_one_pci_or_eisa(pdev
, dev
); 3280 static struct pci_device_id dfx_pci_tbl
[] __devinitdata
= { 3281 { PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_FDDI
, PCI_ANY_ID
, PCI_ANY_ID
, }, 3284 MODULE_DEVICE_TABLE(pci
, dfx_pci_tbl
); 3286 static struct pci_driver dfx_driver
= { 3288 probe
: dfx_init_one
, 3289 remove
: dfx_remove_one
, 3290 id_table
: dfx_pci_tbl
, 3293 static int dfx_have_pci
; 3294 static int dfx_have_eisa
; 3297 static void __exit
dfx_eisa_cleanup(void) 3299 struct net_device
*dev
= root_dfx_eisa_dev
; 3303 struct net_device
*tmp
; 3306 bp
= (DFX_board_t
*)dev
->priv
; 3308 dfx_remove_one_pci_or_eisa(NULL
, dev
); 3313 static int __init
dfx_init(void) 3315 int rc_pci
, rc_eisa
; 3317 rc_pci
=pci_module_init(&dfx_driver
); 3318 if(rc_pci
>=0) dfx_have_pci
=1; 3320 rc_eisa
=dfx_eisa_init(); 3321 if(rc_eisa
>=0) dfx_have_eisa
=1; 3323 return((rc_eisa
<0) ?0: rc_eisa
) + ((rc_pci
<0) ?0: rc_pci
); 3326 static void __exit
dfx_cleanup(void) 3329 pci_unregister_driver(&dfx_driver
); 3335 module_init(dfx_init
); 3336 module_exit(dfx_cleanup
); 3341 * kernel-compile-command: "gcc -D__KERNEL__ -I/root/linux/include -Wall -Wstrict-prototypes -O2 -pipe -fomit-frame-pointer -fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -c defxx.c"