More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / defxx.c
bloba80315d2cd2ef1294eded827b6c071801ad79a7b
1 /*
2 * File Name:
3 * defxx.c
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 General Public License, incorporated herein by reference.
11 * Abstract:
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)
18 * Maintainers:
19 * LVS Lawrence V. Stefani
21 * Contact:
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
28 * 550 King Street
29 * M/S: LKG1-3/M07
30 * Littleton, MA 01460
32 * Credits:
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
44 * driver.
46 * Adapter Probe -
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.
61 * Driver Open/Close -
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
68 * example:
69 * ifconfig fddi0 up
70 * ifconfig fddi0 down
71 * ifconfig fddi0 up
73 * Driver Shutdown -
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.
123 * Receive Path -
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
138 * some point.
140 * Transmit Path -
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,
155 * sets these bytes.
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
190 * override support.
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
198 * Feb 2001 Skb allocation fixes
199 * Feb 2001 davej PCI enable cleanups.
202 #error Please convert me to Documentation/DMA-mapping.txt
204 /* Include files */
206 #include <linux/module.h>
207 #include <linux/kernel.h>
208 #include <linux/string.h>
209 #include <linux/errno.h>
210 #include <linux/ioport.h>
211 #include <linux/slab.h>
212 #include <linux/interrupt.h>
213 #include <linux/pci.h>
214 #include <linux/delay.h>
215 #include <linux/init.h>
216 #include <linux/netdevice.h>
217 #include <linux/fddidevice.h>
218 #include <linux/skbuff.h>
220 #include <asm/byteorder.h>
221 #include <asm/bitops.h>
222 #include <asm/io.h>
224 #include "defxx.h"
226 /* Version information string - should be updated prior to each new release!!! */
228 static char version[] __devinitdata =
229 "defxx.c:v1.05e 2001/02/03 Lawrence V. Stefani and others\n";
231 #define DYNAMIC_BUFFERS 1
233 #define SKBUFF_RX_COPYBREAK 200
235 * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
236 * alignment for compatibility with old EISA boards.
238 #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
240 /* Define module-wide (static) routines */
242 static void dfx_bus_init(struct net_device *dev);
243 static void dfx_bus_config_check(DFX_board_t *bp);
245 static int dfx_driver_init(struct net_device *dev);
246 static int dfx_adap_init(DFX_board_t *bp, int get_buffers);
248 static int dfx_open(struct net_device *dev);
249 static int dfx_close(struct net_device *dev);
251 static void dfx_int_pr_halt_id(DFX_board_t *bp);
252 static void dfx_int_type_0_process(DFX_board_t *bp);
253 static void dfx_int_common(struct net_device *dev);
254 static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs);
256 static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
257 static void dfx_ctl_set_multicast_list(struct net_device *dev);
258 static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
259 static int dfx_ctl_update_cam(DFX_board_t *bp);
260 static int dfx_ctl_update_filters(DFX_board_t *bp);
262 static int dfx_hw_dma_cmd_req(DFX_board_t *bp);
263 static int dfx_hw_port_ctrl_req(DFX_board_t *bp, PI_UINT32 command, PI_UINT32 data_a, PI_UINT32 data_b, PI_UINT32 *host_data);
264 static void dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
265 static int dfx_hw_adap_state_rd(DFX_board_t *bp);
266 static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
268 static int dfx_rcv_init(DFX_board_t *bp, int get_buffers);
269 static void dfx_rcv_queue_process(DFX_board_t *bp);
270 static void dfx_rcv_flush(DFX_board_t *bp);
272 static int dfx_xmt_queue_pkt(struct sk_buff *skb, struct net_device *dev);
273 static int dfx_xmt_done(DFX_board_t *bp);
274 static void dfx_xmt_flush(DFX_board_t *bp);
276 /* Define module-wide (static) variables */
278 static struct net_device *root_dfx_eisa_dev;
282 * =======================
283 * = dfx_port_write_byte =
284 * = dfx_port_read_byte =
285 * = dfx_port_write_long =
286 * = dfx_port_read_long =
287 * =======================
289 * Overview:
290 * Routines for reading and writing values from/to adapter
292 * Returns:
293 * None
295 * Arguments:
296 * bp - pointer to board information
297 * offset - register offset from base I/O address
298 * data - for dfx_port_write_byte and dfx_port_write_long, this
299 * is a value to write.
300 * for dfx_port_read_byte and dfx_port_read_byte, this
301 * is a pointer to store the read value.
303 * Functional Description:
304 * These routines perform the correct operation to read or write
305 * the adapter register.
307 * EISA port block base addresses are based on the slot number in which the
308 * controller is installed. For example, if the EISA controller is installed
309 * in slot 4, the port block base address is 0x4000. If the controller is
310 * installed in slot 2, the port block base address is 0x2000, and so on.
311 * This port block can be used to access PDQ, ESIC, and DEFEA on-board
312 * registers using the register offsets defined in DEFXX.H.
314 * PCI port block base addresses are assigned by the PCI BIOS or system
315 * firmware. There is one 128 byte port block which can be accessed. It
316 * allows for I/O mapping of both PDQ and PFI registers using the register
317 * offsets defined in DEFXX.H.
319 * Return Codes:
320 * None
322 * Assumptions:
323 * bp->base_addr is a valid base I/O address for this adapter.
324 * offset is a valid register offset for this adapter.
326 * Side Effects:
327 * Rather than produce macros for these functions, these routines
328 * are defined using "inline" to ensure that the compiler will
329 * generate inline code and not waste a procedure call and return.
330 * This provides all the benefits of macros, but with the
331 * advantage of strict data type checking.
334 static inline void dfx_port_write_byte(
335 DFX_board_t *bp,
336 int offset,
337 u8 data
341 u16 port = bp->base_addr + offset;
343 outb(data, port);
346 static inline void dfx_port_read_byte(
347 DFX_board_t *bp,
348 int offset,
349 u8 *data
353 u16 port = bp->base_addr + offset;
355 *data = inb(port);
358 static inline void dfx_port_write_long(
359 DFX_board_t *bp,
360 int offset,
361 u32 data
365 u16 port = bp->base_addr + offset;
367 outl(data, port);
370 static inline void dfx_port_read_long(
371 DFX_board_t *bp,
372 int offset,
373 u32 *data
377 u16 port = bp->base_addr + offset;
379 *data = inl(port);
384 * =============
385 * = dfx_init_one_pci_or_eisa =
386 * =============
388 * Overview:
389 * Initializes a supported FDDI EISA or PCI controller
391 * Returns:
392 * Condition code
394 * Arguments:
395 * pdev - pointer to pci device information (NULL for EISA)
396 * ioaddr - pointer to port (NULL for PCI)
398 * Functional Description:
400 * Return Codes:
401 * 0 - This device (fddi0, fddi1, etc) configured successfully
402 * -EBUSY - Failed to get resources, or dfx_driver_init failed.
404 * Assumptions:
405 * It compiles so it should work :-( (PCI cards do :-)
407 * Side Effects:
408 * Device structures for FDDI adapters (fddi0, fddi1, etc) are
409 * initialized and the board resources are read and stored in
410 * the device structure.
412 static int __devinit dfx_init_one_pci_or_eisa(struct pci_dev *pdev, long ioaddr)
414 struct net_device *dev;
415 DFX_board_t *bp; /* board pointer */
416 int err;
418 #ifndef MODULE
419 static int version_disp;
421 if (!version_disp) /* display version info if adapter is found */
423 version_disp = 1; /* set display flag to TRUE so that */
424 printk(version); /* we only display this string ONCE */
426 #endif
428 dev = alloc_fddidev(sizeof(*bp));
429 if (!dev) {
430 printk (KERN_ERR "defxx: unable to allocate fddidev, aborting\n");
431 return -ENOMEM;
434 /* Enable PCI device. */
435 if (pdev != NULL) {
436 err = pci_enable_device (pdev);
437 if (err) goto err_out;
438 ioaddr = pci_resource_start (pdev, 1);
441 SET_MODULE_OWNER(dev);
442 SET_NETDEV_DEV(dev, &pdev->dev);
444 bp = dev->priv;
446 if (!request_region (ioaddr, pdev ? PFI_K_CSR_IO_LEN : PI_ESIC_K_CSR_IO_LEN, dev->name)) {
447 printk (KERN_ERR "%s: Cannot reserve I/O resource 0x%x @ 0x%lx, aborting\n",
448 dev->name, PFI_K_CSR_IO_LEN, ioaddr);
449 err = -EBUSY;
450 goto err_out;
453 /* Initialize new device structure */
455 dev->base_addr = ioaddr; /* save port (I/O) base address */
457 dev->get_stats = dfx_ctl_get_stats;
458 dev->open = dfx_open;
459 dev->stop = dfx_close;
460 dev->hard_start_xmit = dfx_xmt_queue_pkt;
461 dev->set_multicast_list = dfx_ctl_set_multicast_list;
462 dev->set_mac_address = dfx_ctl_set_mac_address;
464 if (pdev == NULL) {
465 /* EISA board */
466 bp->bus_type = DFX_BUS_TYPE_EISA;
467 bp->next = root_dfx_eisa_dev;
468 root_dfx_eisa_dev = dev;
469 } else {
470 /* PCI board */
471 bp->bus_type = DFX_BUS_TYPE_PCI;
472 bp->pci_dev = pdev;
473 pci_set_drvdata (pdev, dev);
474 pci_set_master (pdev);
477 if (dfx_driver_init(dev) != DFX_K_SUCCESS) {
478 err = -ENODEV;
479 goto err_out_region;
482 err = register_netdev(dev);
483 if (err)
484 goto err_out_kfree;
486 return 0;
488 err_out_kfree:
489 if (bp->kmalloced) kfree(bp->kmalloced);
490 err_out_region:
491 release_region(ioaddr, pdev ? PFI_K_CSR_IO_LEN : PI_ESIC_K_CSR_IO_LEN);
492 err_out:
493 kfree(dev);
494 return err;
497 static int __devinit dfx_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
499 return dfx_init_one_pci_or_eisa(pdev, 0);
502 static int __init dfx_eisa_init(void)
504 int rc = -ENODEV;
505 int i; /* used in for loops */
506 u16 port; /* temporary I/O (port) address */
507 u32 slot_id; /* EISA hardware (slot) ID read from adapter */
509 DBG_printk("In dfx_eisa_init...\n");
511 /* Scan for FDDI EISA controllers */
513 for (i=0; i < DFX_MAX_EISA_SLOTS; i++) /* only scan for up to 16 EISA slots */
515 port = (i << 12) + PI_ESIC_K_SLOT_ID; /* port = I/O address for reading slot ID */
516 slot_id = inl(port); /* read EISA HW (slot) ID */
517 if ((slot_id & 0xF0FFFFFF) == DEFEA_PRODUCT_ID)
519 port = (i << 12); /* recalc base addr */
521 if (dfx_init_one_pci_or_eisa(NULL, port) == 0) rc = 0;
524 return rc;
528 * ================
529 * = dfx_bus_init =
530 * ================
532 * Overview:
533 * Initializes EISA and PCI controller bus-specific logic.
535 * Returns:
536 * None
538 * Arguments:
539 * dev - pointer to device information
541 * Functional Description:
542 * Determine and save adapter IRQ in device table,
543 * then perform bus-specific logic initialization.
545 * Return Codes:
546 * None
548 * Assumptions:
549 * dev->base_addr has already been set with the proper
550 * base I/O address for this device.
552 * Side Effects:
553 * Interrupts are enabled at the adapter bus-specific logic.
554 * Note: Interrupts at the DMA engine (PDQ chip) are not
555 * enabled yet.
558 static void __devinit dfx_bus_init(struct net_device *dev)
560 DFX_board_t *bp = dev->priv;
561 u8 val; /* used for I/O read/writes */
563 DBG_printk("In dfx_bus_init...\n");
566 * Initialize base I/O address field in bp structure
568 * Note: bp->base_addr is the same as dev->base_addr.
569 * It's useful because often we'll need to read
570 * or write registers where we already have the
571 * bp pointer instead of the dev pointer. Having
572 * the base address in the bp structure will
573 * save a pointer dereference.
575 * IMPORTANT!! This field must be defined before
576 * any of the dfx_port_* inline functions are
577 * called.
580 bp->base_addr = dev->base_addr;
582 /* And a pointer back to the net_device struct */
583 bp->dev = dev;
585 /* Initialize adapter based on bus type */
587 if (bp->bus_type == DFX_BUS_TYPE_EISA)
589 /* Get the interrupt level from the ESIC chip */
591 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &val);
592 switch ((val & PI_CONFIG_STAT_0_M_IRQ) >> PI_CONFIG_STAT_0_V_IRQ)
594 case PI_CONFIG_STAT_0_IRQ_K_9:
595 dev->irq = 9;
596 break;
598 case PI_CONFIG_STAT_0_IRQ_K_10:
599 dev->irq = 10;
600 break;
602 case PI_CONFIG_STAT_0_IRQ_K_11:
603 dev->irq = 11;
604 break;
606 case PI_CONFIG_STAT_0_IRQ_K_15:
607 dev->irq = 15;
608 break;
611 /* Enable access to I/O on the board by writing 0x03 to Function Control Register */
613 dfx_port_write_byte(bp, PI_ESIC_K_FUNCTION_CNTRL, PI_ESIC_K_FUNCTION_CNTRL_IO_ENB);
615 /* Set the I/O decode range of the board */
617 val = ((dev->base_addr >> 12) << PI_IO_CMP_V_SLOT);
618 dfx_port_write_byte(bp, PI_ESIC_K_IO_CMP_0_1, val);
619 dfx_port_write_byte(bp, PI_ESIC_K_IO_CMP_1_1, val);
621 /* Enable access to rest of module (including PDQ and packet memory) */
623 dfx_port_write_byte(bp, PI_ESIC_K_SLOT_CNTRL, PI_SLOT_CNTRL_M_ENB);
626 * Map PDQ registers into I/O space. This is done by clearing a bit
627 * in Burst Holdoff register.
630 dfx_port_read_byte(bp, PI_ESIC_K_BURST_HOLDOFF, &val);
631 dfx_port_write_byte(bp, PI_ESIC_K_BURST_HOLDOFF, (val & ~PI_BURST_HOLDOFF_M_MEM_MAP));
633 /* Enable interrupts at EISA bus interface chip (ESIC) */
635 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &val);
636 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, (val | PI_CONFIG_STAT_0_M_INT_ENB));
638 else
640 struct pci_dev *pdev = bp->pci_dev;
642 /* Get the interrupt level from the PCI Configuration Table */
644 dev->irq = pdev->irq;
646 /* Check Latency Timer and set if less than minimal */
648 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
649 if (val < PFI_K_LAT_TIMER_MIN) /* if less than min, override with default */
651 val = PFI_K_LAT_TIMER_DEF;
652 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
655 /* Enable interrupts at PCI bus interface chip (PFI) */
657 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, (PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB));
663 * ========================
664 * = dfx_bus_config_check =
665 * ========================
667 * Overview:
668 * Checks the configuration (burst size, full-duplex, etc.) If any parameters
669 * are illegal, then this routine will set new defaults.
671 * Returns:
672 * None
674 * Arguments:
675 * bp - pointer to board information
677 * Functional Description:
678 * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
679 * PDQ, and all FDDI PCI controllers, all values are legal.
681 * Return Codes:
682 * None
684 * Assumptions:
685 * dfx_adap_init has NOT been called yet so burst size and other items have
686 * not been set.
688 * Side Effects:
689 * None
692 static void __devinit dfx_bus_config_check(DFX_board_t *bp)
694 int status; /* return code from adapter port control call */
695 u32 slot_id; /* EISA-bus hardware id (DEC3001, DEC3002,...) */
696 u32 host_data; /* LW data returned from port control call */
698 DBG_printk("In dfx_bus_config_check...\n");
700 /* Configuration check only valid for EISA adapter */
702 if (bp->bus_type == DFX_BUS_TYPE_EISA)
704 dfx_port_read_long(bp, PI_ESIC_K_SLOT_ID, &slot_id);
707 * First check if revision 2 EISA controller. Rev. 1 cards used
708 * PDQ revision B, so no workaround needed in this case. Rev. 3
709 * cards used PDQ revision E, so no workaround needed in this
710 * case, either. Only Rev. 2 cards used either Rev. D or E
711 * chips, so we must verify the chip revision on Rev. 2 cards.
714 if (slot_id == DEFEA_PROD_ID_2)
717 * Revision 2 FDDI EISA controller found, so let's check PDQ
718 * revision of adapter.
721 status = dfx_hw_port_ctrl_req(bp,
722 PI_PCTRL_M_SUB_CMD,
723 PI_SUB_CMD_K_PDQ_REV_GET,
725 &host_data);
726 if ((status != DFX_K_SUCCESS) || (host_data == 2))
729 * Either we couldn't determine the PDQ revision, or
730 * we determined that it is at revision D. In either case,
731 * we need to implement the workaround.
734 /* Ensure that the burst size is set to 8 longwords or less */
736 switch (bp->burst_size)
738 case PI_PDATA_B_DMA_BURST_SIZE_32:
739 case PI_PDATA_B_DMA_BURST_SIZE_16:
740 bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
741 break;
743 default:
744 break;
747 /* Ensure that full-duplex mode is not enabled */
749 bp->full_duplex_enb = PI_SNMP_K_FALSE;
757 * ===================
758 * = dfx_driver_init =
759 * ===================
761 * Overview:
762 * Initializes remaining adapter board structure information
763 * and makes sure adapter is in a safe state prior to dfx_open().
765 * Returns:
766 * Condition code
768 * Arguments:
769 * dev - pointer to device information
771 * Functional Description:
772 * This function allocates additional resources such as the host memory
773 * blocks needed by the adapter (eg. descriptor and consumer blocks).
774 * Remaining bus initialization steps are also completed. The adapter
775 * is also reset so that it is in the DMA_UNAVAILABLE state. The OS
776 * must call dfx_open() to open the adapter and bring it on-line.
778 * Return Codes:
779 * DFX_K_SUCCESS - initialization succeeded
780 * DFX_K_FAILURE - initialization failed - could not allocate memory
781 * or read adapter MAC address
783 * Assumptions:
784 * Memory allocated from kmalloc() call is physically contiguous, locked
785 * memory whose physical address equals its virtual address.
787 * Side Effects:
788 * Adapter is reset and should be in DMA_UNAVAILABLE state before
789 * returning from this routine.
792 static int __devinit dfx_driver_init(struct net_device *dev)
794 DFX_board_t *bp = dev->priv;
795 int alloc_size; /* total buffer size needed */
796 char *top_v, *curr_v; /* virtual addrs into memory block */
797 u32 top_p, curr_p; /* physical addrs into memory block */
798 u32 data; /* host data register value */
800 DBG_printk("In dfx_driver_init...\n");
802 /* Initialize bus-specific hardware registers */
804 dfx_bus_init(dev);
807 * Initialize default values for configurable parameters
809 * Note: All of these parameters are ones that a user may
810 * want to customize. It'd be nice to break these
811 * out into Space.c or someplace else that's more
812 * accessible/understandable than this file.
815 bp->full_duplex_enb = PI_SNMP_K_FALSE;
816 bp->req_ttrt = 8 * 12500; /* 8ms in 80 nanosec units */
817 bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_DEF;
818 bp->rcv_bufs_to_post = RCV_BUFS_DEF;
821 * Ensure that HW configuration is OK
823 * Note: Depending on the hardware revision, we may need to modify
824 * some of the configurable parameters to workaround hardware
825 * limitations. We'll perform this configuration check AFTER
826 * setting the parameters to their default values.
829 dfx_bus_config_check(bp);
831 /* Disable PDQ interrupts first */
833 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
835 /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
837 (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
839 /* Read the factory MAC address from the adapter then save it */
841 if (dfx_hw_port_ctrl_req(bp,
842 PI_PCTRL_M_MLA,
843 PI_PDATA_A_MLA_K_LO,
845 &data) != DFX_K_SUCCESS)
847 printk("%s: Could not read adapter factory MAC address!\n", dev->name);
848 return(DFX_K_FAILURE);
850 memcpy(&bp->factory_mac_addr[0], &data, sizeof(u32));
852 if (dfx_hw_port_ctrl_req(bp,
853 PI_PCTRL_M_MLA,
854 PI_PDATA_A_MLA_K_HI,
856 &data) != DFX_K_SUCCESS)
858 printk("%s: Could not read adapter factory MAC address!\n", dev->name);
859 return(DFX_K_FAILURE);
861 memcpy(&bp->factory_mac_addr[4], &data, sizeof(u16));
864 * Set current address to factory address
866 * Note: Node address override support is handled through
867 * dfx_ctl_set_mac_address.
870 memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
871 if (bp->bus_type == DFX_BUS_TYPE_EISA)
872 printk("%s: DEFEA at I/O addr = 0x%lX, IRQ = %d, Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n",
873 dev->name,
874 dev->base_addr,
875 dev->irq,
876 dev->dev_addr[0],
877 dev->dev_addr[1],
878 dev->dev_addr[2],
879 dev->dev_addr[3],
880 dev->dev_addr[4],
881 dev->dev_addr[5]);
882 else
883 printk("%s: DEFPA at I/O addr = 0x%lX, IRQ = %d, Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n",
884 dev->name,
885 dev->base_addr,
886 dev->irq,
887 dev->dev_addr[0],
888 dev->dev_addr[1],
889 dev->dev_addr[2],
890 dev->dev_addr[3],
891 dev->dev_addr[4],
892 dev->dev_addr[5]);
895 * Get memory for descriptor block, consumer block, and other buffers
896 * that need to be DMA read or written to by the adapter.
899 alloc_size = sizeof(PI_DESCR_BLOCK) +
900 PI_CMD_REQ_K_SIZE_MAX +
901 PI_CMD_RSP_K_SIZE_MAX +
902 #ifndef DYNAMIC_BUFFERS
903 (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
904 #endif
905 sizeof(PI_CONSUMER_BLOCK) +
906 (PI_ALIGN_K_DESC_BLK - 1);
907 bp->kmalloced = top_v = (char *) kmalloc(alloc_size, GFP_KERNEL);
908 if (top_v == NULL)
910 printk("%s: Could not allocate memory for host buffers and structures!\n", dev->name);
911 return(DFX_K_FAILURE);
913 memset(top_v, 0, alloc_size); /* zero out memory before continuing */
914 top_p = virt_to_bus(top_v); /* get physical address of buffer */
917 * To guarantee the 8K alignment required for the descriptor block, 8K - 1
918 * plus the amount of memory needed was allocated. The physical address
919 * is now 8K aligned. By carving up the memory in a specific order,
920 * we'll guarantee the alignment requirements for all other structures.
922 * Note: If the assumptions change regarding the non-paged, non-cached,
923 * physically contiguous nature of the memory block or the address
924 * alignments, then we'll need to implement a different algorithm
925 * for allocating the needed memory.
928 curr_p = (u32) (ALIGN(top_p, PI_ALIGN_K_DESC_BLK));
929 curr_v = top_v + (curr_p - top_p);
931 /* Reserve space for descriptor block */
933 bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
934 bp->descr_block_phys = curr_p;
935 curr_v += sizeof(PI_DESCR_BLOCK);
936 curr_p += sizeof(PI_DESCR_BLOCK);
938 /* Reserve space for command request buffer */
940 bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
941 bp->cmd_req_phys = curr_p;
942 curr_v += PI_CMD_REQ_K_SIZE_MAX;
943 curr_p += PI_CMD_REQ_K_SIZE_MAX;
945 /* Reserve space for command response buffer */
947 bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
948 bp->cmd_rsp_phys = curr_p;
949 curr_v += PI_CMD_RSP_K_SIZE_MAX;
950 curr_p += PI_CMD_RSP_K_SIZE_MAX;
952 /* Reserve space for the LLC host receive queue buffers */
954 bp->rcv_block_virt = curr_v;
955 bp->rcv_block_phys = curr_p;
957 #ifndef DYNAMIC_BUFFERS
958 curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
959 curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
960 #endif
962 /* Reserve space for the consumer block */
964 bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
965 bp->cons_block_phys = curr_p;
967 /* Display virtual and physical addresses if debug driver */
969 DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X\n", dev->name, (long)bp->descr_block_virt, bp->descr_block_phys);
970 DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X\n", dev->name, (long)bp->cmd_req_virt, bp->cmd_req_phys);
971 DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X\n", dev->name, (long)bp->cmd_rsp_virt, bp->cmd_rsp_phys);
972 DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X\n", dev->name, (long)bp->rcv_block_virt, bp->rcv_block_phys);
973 DBG_printk("%s: Consumer block virt = %0lX, phys = %0X\n", dev->name, (long)bp->cons_block_virt, bp->cons_block_phys);
975 return(DFX_K_SUCCESS);
980 * =================
981 * = dfx_adap_init =
982 * =================
984 * Overview:
985 * Brings the adapter to the link avail/link unavailable state.
987 * Returns:
988 * Condition code
990 * Arguments:
991 * bp - pointer to board information
992 * get_buffers - non-zero if buffers to be allocated
994 * Functional Description:
995 * Issues the low-level firmware/hardware calls necessary to bring
996 * the adapter up, or to properly reset and restore adapter during
997 * run-time.
999 * Return Codes:
1000 * DFX_K_SUCCESS - Adapter brought up successfully
1001 * DFX_K_FAILURE - Adapter initialization failed
1003 * Assumptions:
1004 * bp->reset_type should be set to a valid reset type value before
1005 * calling this routine.
1007 * Side Effects:
1008 * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
1009 * upon a successful return of this routine.
1012 static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
1014 DBG_printk("In dfx_adap_init...\n");
1016 /* Disable PDQ interrupts first */
1018 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1020 /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1022 if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
1024 printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
1025 return(DFX_K_FAILURE);
1029 * When the PDQ is reset, some false Type 0 interrupts may be pending,
1030 * so we'll acknowledge all Type 0 interrupts now before continuing.
1033 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
1036 * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
1038 * Note: We only need to clear host copies of these registers. The PDQ reset
1039 * takes care of the on-board register values.
1042 bp->cmd_req_reg.lword = 0;
1043 bp->cmd_rsp_reg.lword = 0;
1044 bp->rcv_xmt_reg.lword = 0;
1046 /* Clear consumer block before going to DMA_AVAILABLE state */
1048 memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
1050 /* Initialize the DMA Burst Size */
1052 if (dfx_hw_port_ctrl_req(bp,
1053 PI_PCTRL_M_SUB_CMD,
1054 PI_SUB_CMD_K_BURST_SIZE_SET,
1055 bp->burst_size,
1056 NULL) != DFX_K_SUCCESS)
1058 printk("%s: Could not set adapter burst size!\n", bp->dev->name);
1059 return(DFX_K_FAILURE);
1063 * Set base address of Consumer Block
1065 * Assumption: 32-bit physical address of consumer block is 64 byte
1066 * aligned. That is, bits 0-5 of the address must be zero.
1069 if (dfx_hw_port_ctrl_req(bp,
1070 PI_PCTRL_M_CONS_BLOCK,
1071 bp->cons_block_phys,
1073 NULL) != DFX_K_SUCCESS)
1075 printk("%s: Could not set consumer block address!\n", bp->dev->name);
1076 return(DFX_K_FAILURE);
1080 * Set base address of Descriptor Block and bring adapter to DMA_AVAILABLE state
1082 * Note: We also set the literal and data swapping requirements in this
1083 * command. Since this driver presently runs on Intel platforms
1084 * which are Little Endian, we'll tell the adapter to byte swap
1085 * data only. This code will need to change when we support
1086 * Big Endian systems (eg. PowerPC).
1088 * Assumption: 32-bit physical address of descriptor block is 8Kbyte
1089 * aligned. That is, bits 0-12 of the address must be zero.
1092 if (dfx_hw_port_ctrl_req(bp,
1093 PI_PCTRL_M_INIT,
1094 (u32) (bp->descr_block_phys | PI_PDATA_A_INIT_M_BSWAP_DATA),
1096 NULL) != DFX_K_SUCCESS)
1098 printk("%s: Could not set descriptor block address!\n", bp->dev->name);
1099 return(DFX_K_FAILURE);
1102 /* Set transmit flush timeout value */
1104 bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
1105 bp->cmd_req_virt->char_set.item[0].item_code = PI_ITEM_K_FLUSH_TIME;
1106 bp->cmd_req_virt->char_set.item[0].value = 3; /* 3 seconds */
1107 bp->cmd_req_virt->char_set.item[0].item_index = 0;
1108 bp->cmd_req_virt->char_set.item[1].item_code = PI_ITEM_K_EOL;
1109 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1111 printk("%s: DMA command request failed!\n", bp->dev->name);
1112 return(DFX_K_FAILURE);
1115 /* Set the initial values for eFDXEnable and MACTReq MIB objects */
1117 bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
1118 bp->cmd_req_virt->snmp_set.item[0].item_code = PI_ITEM_K_FDX_ENB_DIS;
1119 bp->cmd_req_virt->snmp_set.item[0].value = bp->full_duplex_enb;
1120 bp->cmd_req_virt->snmp_set.item[0].item_index = 0;
1121 bp->cmd_req_virt->snmp_set.item[1].item_code = PI_ITEM_K_MAC_T_REQ;
1122 bp->cmd_req_virt->snmp_set.item[1].value = bp->req_ttrt;
1123 bp->cmd_req_virt->snmp_set.item[1].item_index = 0;
1124 bp->cmd_req_virt->snmp_set.item[2].item_code = PI_ITEM_K_EOL;
1125 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1127 printk("%s: DMA command request failed!\n", bp->dev->name);
1128 return(DFX_K_FAILURE);
1131 /* Initialize adapter CAM */
1133 if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
1135 printk("%s: Adapter CAM update failed!\n", bp->dev->name);
1136 return(DFX_K_FAILURE);
1139 /* Initialize adapter filters */
1141 if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
1143 printk("%s: Adapter filters update failed!\n", bp->dev->name);
1144 return(DFX_K_FAILURE);
1148 * Remove any existing dynamic buffers (i.e. if the adapter is being
1149 * reinitialized)
1152 if (get_buffers)
1153 dfx_rcv_flush(bp);
1155 /* Initialize receive descriptor block and produce buffers */
1157 if (dfx_rcv_init(bp, get_buffers))
1159 printk("%s: Receive buffer allocation failed\n", bp->dev->name);
1160 if (get_buffers)
1161 dfx_rcv_flush(bp);
1162 return(DFX_K_FAILURE);
1165 /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
1167 bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
1168 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1170 printk("%s: Start command failed\n", bp->dev->name);
1171 if (get_buffers)
1172 dfx_rcv_flush(bp);
1173 return(DFX_K_FAILURE);
1176 /* Initialization succeeded, reenable PDQ interrupts */
1178 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
1179 return(DFX_K_SUCCESS);
1184 * ============
1185 * = dfx_open =
1186 * ============
1188 * Overview:
1189 * Opens the adapter
1191 * Returns:
1192 * Condition code
1194 * Arguments:
1195 * dev - pointer to device information
1197 * Functional Description:
1198 * This function brings the adapter to an operational state.
1200 * Return Codes:
1201 * 0 - Adapter was successfully opened
1202 * -EAGAIN - Could not register IRQ or adapter initialization failed
1204 * Assumptions:
1205 * This routine should only be called for a device that was
1206 * initialized successfully.
1208 * Side Effects:
1209 * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
1210 * if the open is successful.
1213 static int dfx_open(struct net_device *dev)
1215 int ret;
1216 DFX_board_t *bp = dev->priv;
1218 DBG_printk("In dfx_open...\n");
1220 /* Register IRQ - support shared interrupts by passing device ptr */
1222 ret = request_irq(dev->irq, (void *)dfx_interrupt, SA_SHIRQ, dev->name, dev);
1223 if (ret) {
1224 printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
1225 return ret;
1229 * Set current address to factory MAC address
1231 * Note: We've already done this step in dfx_driver_init.
1232 * However, it's possible that a user has set a node
1233 * address override, then closed and reopened the
1234 * adapter. Unless we reset the device address field
1235 * now, we'll continue to use the existing modified
1236 * address.
1239 memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
1241 /* Clear local unicast/multicast address tables and counts */
1243 memset(bp->uc_table, 0, sizeof(bp->uc_table));
1244 memset(bp->mc_table, 0, sizeof(bp->mc_table));
1245 bp->uc_count = 0;
1246 bp->mc_count = 0;
1248 /* Disable promiscuous filter settings */
1250 bp->ind_group_prom = PI_FSTATE_K_BLOCK;
1251 bp->group_prom = PI_FSTATE_K_BLOCK;
1253 spin_lock_init(&bp->lock);
1255 /* Reset and initialize adapter */
1257 bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST; /* skip self-test */
1258 if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
1260 printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
1261 free_irq(dev->irq, dev);
1262 return -EAGAIN;
1265 /* Set device structure info */
1266 netif_start_queue(dev);
1267 return(0);
1272 * =============
1273 * = dfx_close =
1274 * =============
1276 * Overview:
1277 * Closes the device/module.
1279 * Returns:
1280 * Condition code
1282 * Arguments:
1283 * dev - pointer to device information
1285 * Functional Description:
1286 * This routine closes the adapter and brings it to a safe state.
1287 * The interrupt service routine is deregistered with the OS.
1288 * The adapter can be opened again with another call to dfx_open().
1290 * Return Codes:
1291 * Always return 0.
1293 * Assumptions:
1294 * No further requests for this adapter are made after this routine is
1295 * called. dfx_open() can be called to reset and reinitialize the
1296 * adapter.
1298 * Side Effects:
1299 * Adapter should be in DMA_UNAVAILABLE state upon completion of this
1300 * routine.
1303 static int dfx_close(struct net_device *dev)
1305 DFX_board_t *bp = dev->priv;
1307 DBG_printk("In dfx_close...\n");
1309 /* Disable PDQ interrupts first */
1311 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1313 /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1315 (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
1318 * Flush any pending transmit buffers
1320 * Note: It's important that we flush the transmit buffers
1321 * BEFORE we clear our copy of the Type 2 register.
1322 * Otherwise, we'll have no idea how many buffers
1323 * we need to free.
1326 dfx_xmt_flush(bp);
1329 * Clear Type 1 and Type 2 registers after adapter reset
1331 * Note: Even though we're closing the adapter, it's
1332 * possible that an interrupt will occur after
1333 * dfx_close is called. Without some assurance to
1334 * the contrary we want to make sure that we don't
1335 * process receive and transmit LLC frames and update
1336 * the Type 2 register with bad information.
1339 bp->cmd_req_reg.lword = 0;
1340 bp->cmd_rsp_reg.lword = 0;
1341 bp->rcv_xmt_reg.lword = 0;
1343 /* Clear consumer block for the same reason given above */
1345 memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
1347 /* Release all dynamically allocate skb in the receive ring. */
1349 dfx_rcv_flush(bp);
1351 /* Clear device structure flags */
1353 netif_stop_queue(dev);
1355 /* Deregister (free) IRQ */
1357 free_irq(dev->irq, dev);
1359 return(0);
1364 * ======================
1365 * = dfx_int_pr_halt_id =
1366 * ======================
1368 * Overview:
1369 * Displays halt id's in string form.
1371 * Returns:
1372 * None
1374 * Arguments:
1375 * bp - pointer to board information
1377 * Functional Description:
1378 * Determine current halt id and display appropriate string.
1380 * Return Codes:
1381 * None
1383 * Assumptions:
1384 * None
1386 * Side Effects:
1387 * None
1390 static void dfx_int_pr_halt_id(DFX_board_t *bp)
1392 PI_UINT32 port_status; /* PDQ port status register value */
1393 PI_UINT32 halt_id; /* PDQ port status halt ID */
1395 /* Read the latest port status */
1397 dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
1399 /* Display halt state transition information */
1401 halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
1402 switch (halt_id)
1404 case PI_HALT_ID_K_SELFTEST_TIMEOUT:
1405 printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
1406 break;
1408 case PI_HALT_ID_K_PARITY_ERROR:
1409 printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
1410 break;
1412 case PI_HALT_ID_K_HOST_DIR_HALT:
1413 printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
1414 break;
1416 case PI_HALT_ID_K_SW_FAULT:
1417 printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
1418 break;
1420 case PI_HALT_ID_K_HW_FAULT:
1421 printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
1422 break;
1424 case PI_HALT_ID_K_PC_TRACE:
1425 printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
1426 break;
1428 case PI_HALT_ID_K_DMA_ERROR:
1429 printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
1430 break;
1432 case PI_HALT_ID_K_IMAGE_CRC_ERROR:
1433 printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
1434 break;
1436 case PI_HALT_ID_K_BUS_EXCEPTION:
1437 printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
1438 break;
1440 default:
1441 printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
1442 break;
1448 * ==========================
1449 * = dfx_int_type_0_process =
1450 * ==========================
1452 * Overview:
1453 * Processes Type 0 interrupts.
1455 * Returns:
1456 * None
1458 * Arguments:
1459 * bp - pointer to board information
1461 * Functional Description:
1462 * Processes all enabled Type 0 interrupts. If the reason for the interrupt
1463 * is a serious fault on the adapter, then an error message is displayed
1464 * and the adapter is reset.
1466 * One tricky potential timing window is the rapid succession of "link avail"
1467 * "link unavail" state change interrupts. The acknowledgement of the Type 0
1468 * interrupt must be done before reading the state from the Port Status
1469 * register. This is true because a state change could occur after reading
1470 * the data, but before acknowledging the interrupt. If this state change
1471 * does happen, it would be lost because the driver is using the old state,
1472 * and it will never know about the new state because it subsequently
1473 * acknowledges the state change interrupt.
1475 * INCORRECT CORRECT
1476 * read type 0 int reasons read type 0 int reasons
1477 * read adapter state ack type 0 interrupts
1478 * ack type 0 interrupts read adapter state
1479 * ... process interrupt ... ... process interrupt ...
1481 * Return Codes:
1482 * None
1484 * Assumptions:
1485 * None
1487 * Side Effects:
1488 * An adapter reset may occur if the adapter has any Type 0 error interrupts
1489 * or if the port status indicates that the adapter is halted. The driver
1490 * is responsible for reinitializing the adapter with the current CAM
1491 * contents and adapter filter settings.
1494 static void dfx_int_type_0_process(DFX_board_t *bp)
1497 PI_UINT32 type_0_status; /* Host Interrupt Type 0 register */
1498 PI_UINT32 state; /* current adap state (from port status) */
1501 * Read host interrupt Type 0 register to determine which Type 0
1502 * interrupts are pending. Immediately write it back out to clear
1503 * those interrupts.
1506 dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
1507 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
1509 /* Check for Type 0 error interrupts */
1511 if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
1512 PI_TYPE_0_STAT_M_PM_PAR_ERR |
1513 PI_TYPE_0_STAT_M_BUS_PAR_ERR))
1515 /* Check for Non-Existent Memory error */
1517 if (type_0_status & PI_TYPE_0_STAT_M_NXM)
1518 printk("%s: Non-Existent Memory Access Error\n", bp->dev->name);
1520 /* Check for Packet Memory Parity error */
1522 if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
1523 printk("%s: Packet Memory Parity Error\n", bp->dev->name);
1525 /* Check for Host Bus Parity error */
1527 if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
1528 printk("%s: Host Bus Parity Error\n", bp->dev->name);
1530 /* Reset adapter and bring it back on-line */
1532 bp->link_available = PI_K_FALSE; /* link is no longer available */
1533 bp->reset_type = 0; /* rerun on-board diagnostics */
1534 printk("%s: Resetting adapter...\n", bp->dev->name);
1535 if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
1537 printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
1538 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1539 return;
1541 printk("%s: Adapter reset successful!\n", bp->dev->name);
1542 return;
1545 /* Check for transmit flush interrupt */
1547 if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
1549 /* Flush any pending xmt's and acknowledge the flush interrupt */
1551 bp->link_available = PI_K_FALSE; /* link is no longer available */
1552 dfx_xmt_flush(bp); /* flush any outstanding packets */
1553 (void) dfx_hw_port_ctrl_req(bp,
1554 PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
1557 NULL);
1560 /* Check for adapter state change */
1562 if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
1564 /* Get latest adapter state */
1566 state = dfx_hw_adap_state_rd(bp); /* get adapter state */
1567 if (state == PI_STATE_K_HALTED)
1570 * Adapter has transitioned to HALTED state, try to reset
1571 * adapter to bring it back on-line. If reset fails,
1572 * leave the adapter in the broken state.
1575 printk("%s: Controller has transitioned to HALTED state!\n", bp->dev->name);
1576 dfx_int_pr_halt_id(bp); /* display halt id as string */
1578 /* Reset adapter and bring it back on-line */
1580 bp->link_available = PI_K_FALSE; /* link is no longer available */
1581 bp->reset_type = 0; /* rerun on-board diagnostics */
1582 printk("%s: Resetting adapter...\n", bp->dev->name);
1583 if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
1585 printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
1586 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1587 return;
1589 printk("%s: Adapter reset successful!\n", bp->dev->name);
1591 else if (state == PI_STATE_K_LINK_AVAIL)
1593 bp->link_available = PI_K_TRUE; /* set link available flag */
1600 * ==================
1601 * = dfx_int_common =
1602 * ==================
1604 * Overview:
1605 * Interrupt service routine (ISR)
1607 * Returns:
1608 * None
1610 * Arguments:
1611 * bp - pointer to board information
1613 * Functional Description:
1614 * This is the ISR which processes incoming adapter interrupts.
1616 * Return Codes:
1617 * None
1619 * Assumptions:
1620 * This routine assumes PDQ interrupts have not been disabled.
1621 * When interrupts are disabled at the PDQ, the Port Status register
1622 * is automatically cleared. This routine uses the Port Status
1623 * register value to determine whether a Type 0 interrupt occurred,
1624 * so it's important that adapter interrupts are not normally
1625 * enabled/disabled at the PDQ.
1627 * It's vital that this routine is NOT reentered for the
1628 * same board and that the OS is not in another section of
1629 * code (eg. dfx_xmt_queue_pkt) for the same board on a
1630 * different thread.
1632 * Side Effects:
1633 * Pending interrupts are serviced. Depending on the type of
1634 * interrupt, acknowledging and clearing the interrupt at the
1635 * PDQ involves writing a register to clear the interrupt bit
1636 * or updating completion indices.
1639 static void dfx_int_common(struct net_device *dev)
1641 DFX_board_t *bp = dev->priv;
1642 PI_UINT32 port_status; /* Port Status register */
1644 /* Process xmt interrupts - frequent case, so always call this routine */
1646 if(dfx_xmt_done(bp)) /* free consumed xmt packets */
1647 netif_wake_queue(dev);
1649 /* Process rcv interrupts - frequent case, so always call this routine */
1651 dfx_rcv_queue_process(bp); /* service received LLC frames */
1654 * Transmit and receive producer and completion indices are updated on the
1655 * adapter by writing to the Type 2 Producer register. Since the frequent
1656 * case is that we'll be processing either LLC transmit or receive buffers,
1657 * we'll optimize I/O writes by doing a single register write here.
1660 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
1662 /* Read PDQ Port Status register to find out which interrupts need processing */
1664 dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
1666 /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
1668 if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
1669 dfx_int_type_0_process(bp); /* process Type 0 interrupts */
1674 * =================
1675 * = dfx_interrupt =
1676 * =================
1678 * Overview:
1679 * Interrupt processing routine
1681 * Returns:
1682 * None
1684 * Arguments:
1685 * irq - interrupt vector
1686 * dev_id - pointer to device information
1687 * regs - pointer to registers structure
1689 * Functional Description:
1690 * This routine calls the interrupt processing routine for this adapter. It
1691 * disables and reenables adapter interrupts, as appropriate. We can support
1692 * shared interrupts since the incoming dev_id pointer provides our device
1693 * structure context.
1695 * Return Codes:
1696 * None
1698 * Assumptions:
1699 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
1700 * on Intel-based systems) is done by the operating system outside this
1701 * routine.
1703 * System interrupts are enabled through this call.
1705 * Side Effects:
1706 * Interrupts are disabled, then reenabled at the adapter.
1709 static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1711 struct net_device *dev = dev_id;
1712 DFX_board_t *bp; /* private board structure pointer */
1713 u8 tmp; /* used for disabling/enabling ints */
1715 /* Get board pointer only if device structure is valid */
1717 bp = dev->priv;
1719 spin_lock(&bp->lock);
1721 /* See if we're already servicing an interrupt */
1723 /* Service adapter interrupts */
1725 if (bp->bus_type == DFX_BUS_TYPE_PCI)
1727 /* Disable PDQ-PFI interrupts at PFI */
1729 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, PFI_MODE_M_DMA_ENB);
1731 /* Call interrupt service routine for this adapter */
1733 dfx_int_common(dev);
1735 /* Clear PDQ interrupt status bit and reenable interrupts */
1737 dfx_port_write_long(bp, PFI_K_REG_STATUS, PFI_STATUS_M_PDQ_INT);
1738 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1739 (PFI_MODE_M_PDQ_INT_ENB + PFI_MODE_M_DMA_ENB));
1741 else
1743 /* Disable interrupts at the ESIC */
1745 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp);
1746 tmp &= ~PI_CONFIG_STAT_0_M_INT_ENB;
1747 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp);
1749 /* Call interrupt service routine for this adapter */
1751 dfx_int_common(dev);
1753 /* Reenable interrupts at the ESIC */
1755 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp);
1756 tmp |= PI_CONFIG_STAT_0_M_INT_ENB;
1757 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp);
1760 spin_unlock(&bp->lock);
1765 * =====================
1766 * = dfx_ctl_get_stats =
1767 * =====================
1769 * Overview:
1770 * Get statistics for FDDI adapter
1772 * Returns:
1773 * Pointer to FDDI statistics structure
1775 * Arguments:
1776 * dev - pointer to device information
1778 * Functional Description:
1779 * Gets current MIB objects from adapter, then
1780 * returns FDDI statistics structure as defined
1781 * in if_fddi.h.
1783 * Note: Since the FDDI statistics structure is
1784 * still new and the device structure doesn't
1785 * have an FDDI-specific get statistics handler,
1786 * we'll return the FDDI statistics structure as
1787 * a pointer to an Ethernet statistics structure.
1788 * That way, at least the first part of the statistics
1789 * structure can be decoded properly, and it allows
1790 * "smart" applications to perform a second cast to
1791 * decode the FDDI-specific statistics.
1793 * We'll have to pay attention to this routine as the
1794 * device structure becomes more mature and LAN media
1795 * independent.
1797 * Return Codes:
1798 * None
1800 * Assumptions:
1801 * None
1803 * Side Effects:
1804 * None
1807 static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
1809 DFX_board_t *bp = dev->priv;
1811 /* Fill the bp->stats structure with driver-maintained counters */
1813 bp->stats.rx_packets = bp->rcv_total_frames;
1814 bp->stats.tx_packets = bp->xmt_total_frames;
1815 bp->stats.rx_bytes = bp->rcv_total_bytes;
1816 bp->stats.tx_bytes = bp->xmt_total_bytes;
1817 bp->stats.rx_errors = (u32)(bp->rcv_crc_errors + bp->rcv_frame_status_errors + bp->rcv_length_errors);
1818 bp->stats.tx_errors = bp->xmt_length_errors;
1819 bp->stats.rx_dropped = bp->rcv_discards;
1820 bp->stats.tx_dropped = bp->xmt_discards;
1821 bp->stats.multicast = bp->rcv_multicast_frames;
1822 bp->stats.transmit_collision = 0; /* always zero (0) for FDDI */
1824 /* Get FDDI SMT MIB objects */
1826 bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
1827 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1828 return((struct net_device_stats *) &bp->stats);
1830 /* Fill the bp->stats structure with the SMT MIB object values */
1832 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));
1833 bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
1834 bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
1835 bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
1836 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));
1837 bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
1838 bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
1839 bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
1840 bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
1841 bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
1842 bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
1843 bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
1844 bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
1845 bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
1846 bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
1847 bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
1848 bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
1849 bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
1850 bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
1851 bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
1852 bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
1853 bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
1854 bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
1855 bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
1856 bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
1857 bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
1858 bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
1859 bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
1860 bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
1861 memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
1862 memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
1863 memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
1864 memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
1865 bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
1866 bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
1867 bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
1868 memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
1869 bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
1870 bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
1871 bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
1872 bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
1873 bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
1874 bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
1875 bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
1876 bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
1877 bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
1878 bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
1879 bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
1880 bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
1881 bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
1882 bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
1883 bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
1884 bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
1885 memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
1886 bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
1887 bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
1888 bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
1889 bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
1890 bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
1891 bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
1892 bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
1893 bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
1894 bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
1895 bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
1896 memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
1897 memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
1898 bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
1899 bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
1900 bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
1901 bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
1902 bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
1903 bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
1904 bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
1905 bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
1906 bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
1907 bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
1908 bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
1909 bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
1910 bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
1911 bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
1912 bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
1913 bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
1914 bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
1915 bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
1916 bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
1917 bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
1918 bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
1919 bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
1920 bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
1921 bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
1922 bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
1923 bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
1925 /* Get FDDI counters */
1927 bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
1928 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1929 return((struct net_device_stats *) &bp->stats);
1931 /* Fill the bp->stats structure with the FDDI counter values */
1933 bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
1934 bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
1935 bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
1936 bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
1937 bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
1938 bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
1939 bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
1940 bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
1941 bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
1942 bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
1943 bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
1945 return((struct net_device_stats *) &bp->stats);
1950 * ==============================
1951 * = dfx_ctl_set_multicast_list =
1952 * ==============================
1954 * Overview:
1955 * Enable/Disable LLC frame promiscuous mode reception
1956 * on the adapter and/or update multicast address table.
1958 * Returns:
1959 * None
1961 * Arguments:
1962 * dev - pointer to device information
1964 * Functional Description:
1965 * This routine follows a fairly simple algorithm for setting the
1966 * adapter filters and CAM:
1968 * if IFF_PROMISC flag is set
1969 * enable LLC individual/group promiscuous mode
1970 * else
1971 * disable LLC individual/group promiscuous mode
1972 * if number of incoming multicast addresses >
1973 * (CAM max size - number of unicast addresses in CAM)
1974 * enable LLC group promiscuous mode
1975 * set driver-maintained multicast address count to zero
1976 * else
1977 * disable LLC group promiscuous mode
1978 * set driver-maintained multicast address count to incoming count
1979 * update adapter CAM
1980 * update adapter filters
1982 * Return Codes:
1983 * None
1985 * Assumptions:
1986 * Multicast addresses are presented in canonical (LSB) format.
1988 * Side Effects:
1989 * On-board adapter CAM and filters are updated.
1992 static void dfx_ctl_set_multicast_list(struct net_device *dev)
1994 DFX_board_t *bp = dev->priv;
1995 int i; /* used as index in for loop */
1996 struct dev_mc_list *dmi; /* ptr to multicast addr entry */
1998 /* Enable LLC frame promiscuous mode, if necessary */
2000 if (dev->flags & IFF_PROMISC)
2001 bp->ind_group_prom = PI_FSTATE_K_PASS; /* Enable LLC ind/group prom mode */
2003 /* Else, update multicast address table */
2005 else
2007 bp->ind_group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC ind/group prom mode */
2009 * Check whether incoming multicast address count exceeds table size
2011 * Note: The adapters utilize an on-board 64 entry CAM for
2012 * supporting perfect filtering of multicast packets
2013 * and bridge functions when adding unicast addresses.
2014 * There is no hash function available. To support
2015 * additional multicast addresses, the all multicast
2016 * filter (LLC group promiscuous mode) must be enabled.
2018 * The firmware reserves two CAM entries for SMT-related
2019 * multicast addresses, which leaves 62 entries available.
2020 * The following code ensures that we're not being asked
2021 * to add more than 62 addresses to the CAM. If we are,
2022 * the driver will enable the all multicast filter.
2023 * Should the number of multicast addresses drop below
2024 * the high water mark, the filter will be disabled and
2025 * perfect filtering will be used.
2028 if (dev->mc_count > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
2030 bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
2031 bp->mc_count = 0; /* Don't add mc addrs to CAM */
2033 else
2035 bp->group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC group prom mode */
2036 bp->mc_count = dev->mc_count; /* Add mc addrs to CAM */
2039 /* Copy addresses to multicast address table, then update adapter CAM */
2041 dmi = dev->mc_list; /* point to first multicast addr */
2042 for (i=0; i < bp->mc_count; i++)
2044 memcpy(&bp->mc_table[i*FDDI_K_ALEN], dmi->dmi_addr, FDDI_K_ALEN);
2045 dmi = dmi->next; /* point to next multicast addr */
2047 if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
2049 DBG_printk("%s: Could not update multicast address table!\n", dev->name);
2051 else
2053 DBG_printk("%s: Multicast address table updated! Added %d addresses.\n", dev->name, bp->mc_count);
2057 /* Update adapter filters */
2059 if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
2061 DBG_printk("%s: Could not update adapter filters!\n", dev->name);
2063 else
2065 DBG_printk("%s: Adapter filters updated!\n", dev->name);
2071 * ===========================
2072 * = dfx_ctl_set_mac_address =
2073 * ===========================
2075 * Overview:
2076 * Add node address override (unicast address) to adapter
2077 * CAM and update dev_addr field in device table.
2079 * Returns:
2080 * None
2082 * Arguments:
2083 * dev - pointer to device information
2084 * addr - pointer to sockaddr structure containing unicast address to add
2086 * Functional Description:
2087 * The adapter supports node address overrides by adding one or more
2088 * unicast addresses to the adapter CAM. This is similar to adding
2089 * multicast addresses. In this routine we'll update the driver and
2090 * device structures with the new address, then update the adapter CAM
2091 * to ensure that the adapter will copy and strip frames destined and
2092 * sourced by that address.
2094 * Return Codes:
2095 * Always returns zero.
2097 * Assumptions:
2098 * The address pointed to by addr->sa_data is a valid unicast
2099 * address and is presented in canonical (LSB) format.
2101 * Side Effects:
2102 * On-board adapter CAM is updated. On-board adapter filters
2103 * may be updated.
2106 static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
2108 DFX_board_t *bp = dev->priv;
2109 struct sockaddr *p_sockaddr = (struct sockaddr *)addr;
2111 /* Copy unicast address to driver-maintained structs and update count */
2113 memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN); /* update device struct */
2114 memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN); /* update driver struct */
2115 bp->uc_count = 1;
2118 * Verify we're not exceeding the CAM size by adding unicast address
2120 * Note: It's possible that before entering this routine we've
2121 * already filled the CAM with 62 multicast addresses.
2122 * Since we need to place the node address override into
2123 * the CAM, we have to check to see that we're not
2124 * exceeding the CAM size. If we are, we have to enable
2125 * the LLC group (multicast) promiscuous mode filter as
2126 * in dfx_ctl_set_multicast_list.
2129 if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
2131 bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
2132 bp->mc_count = 0; /* Don't add mc addrs to CAM */
2134 /* Update adapter filters */
2136 if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
2138 DBG_printk("%s: Could not update adapter filters!\n", dev->name);
2140 else
2142 DBG_printk("%s: Adapter filters updated!\n", dev->name);
2146 /* Update adapter CAM with new unicast address */
2148 if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
2150 DBG_printk("%s: Could not set new MAC address!\n", dev->name);
2152 else
2154 DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev->name);
2156 return(0); /* always return zero */
2161 * ======================
2162 * = dfx_ctl_update_cam =
2163 * ======================
2165 * Overview:
2166 * Procedure to update adapter CAM (Content Addressable Memory)
2167 * with desired unicast and multicast address entries.
2169 * Returns:
2170 * Condition code
2172 * Arguments:
2173 * bp - pointer to board information
2175 * Functional Description:
2176 * Updates adapter CAM with current contents of board structure
2177 * unicast and multicast address tables. Since there are only 62
2178 * free entries in CAM, this routine ensures that the command
2179 * request buffer is not overrun.
2181 * Return Codes:
2182 * DFX_K_SUCCESS - Request succeeded
2183 * DFX_K_FAILURE - Request failed
2185 * Assumptions:
2186 * All addresses being added (unicast and multicast) are in canonical
2187 * order.
2189 * Side Effects:
2190 * On-board adapter CAM is updated.
2193 static int dfx_ctl_update_cam(DFX_board_t *bp)
2195 int i; /* used as index */
2196 PI_LAN_ADDR *p_addr; /* pointer to CAM entry */
2199 * Fill in command request information
2201 * Note: Even though both the unicast and multicast address
2202 * table entries are stored as contiguous 6 byte entries,
2203 * the firmware address filter set command expects each
2204 * entry to be two longwords (8 bytes total). We must be
2205 * careful to only copy the six bytes of each unicast and
2206 * multicast table entry into each command entry. This
2207 * is also why we must first clear the entire command
2208 * request buffer.
2211 memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX); /* first clear buffer */
2212 bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
2213 p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
2215 /* Now add unicast addresses to command request buffer, if any */
2217 for (i=0; i < (int)bp->uc_count; i++)
2219 if (i < PI_CMD_ADDR_FILTER_K_SIZE)
2221 memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
2222 p_addr++; /* point to next command entry */
2226 /* Now add multicast addresses to command request buffer, if any */
2228 for (i=0; i < (int)bp->mc_count; i++)
2230 if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
2232 memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
2233 p_addr++; /* point to next command entry */
2237 /* Issue command to update adapter CAM, then return */
2239 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2240 return(DFX_K_FAILURE);
2241 return(DFX_K_SUCCESS);
2246 * ==========================
2247 * = dfx_ctl_update_filters =
2248 * ==========================
2250 * Overview:
2251 * Procedure to update adapter filters with desired
2252 * filter settings.
2254 * Returns:
2255 * Condition code
2257 * Arguments:
2258 * bp - pointer to board information
2260 * Functional Description:
2261 * Enables or disables filter using current filter settings.
2263 * Return Codes:
2264 * DFX_K_SUCCESS - Request succeeded.
2265 * DFX_K_FAILURE - Request failed.
2267 * Assumptions:
2268 * We must always pass up packets destined to the broadcast
2269 * address (FF-FF-FF-FF-FF-FF), so we'll always keep the
2270 * broadcast filter enabled.
2272 * Side Effects:
2273 * On-board adapter filters are updated.
2276 static int dfx_ctl_update_filters(DFX_board_t *bp)
2278 int i = 0; /* used as index */
2280 /* Fill in command request information */
2282 bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
2284 /* Initialize Broadcast filter - * ALWAYS ENABLED * */
2286 bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_BROADCAST;
2287 bp->cmd_req_virt->filter_set.item[i++].value = PI_FSTATE_K_PASS;
2289 /* Initialize LLC Individual/Group Promiscuous filter */
2291 bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_IND_GROUP_PROM;
2292 bp->cmd_req_virt->filter_set.item[i++].value = bp->ind_group_prom;
2294 /* Initialize LLC Group Promiscuous filter */
2296 bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_GROUP_PROM;
2297 bp->cmd_req_virt->filter_set.item[i++].value = bp->group_prom;
2299 /* Terminate the item code list */
2301 bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_EOL;
2303 /* Issue command to update adapter filters, then return */
2305 if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2306 return(DFX_K_FAILURE);
2307 return(DFX_K_SUCCESS);
2312 * ======================
2313 * = dfx_hw_dma_cmd_req =
2314 * ======================
2316 * Overview:
2317 * Sends PDQ DMA command to adapter firmware
2319 * Returns:
2320 * Condition code
2322 * Arguments:
2323 * bp - pointer to board information
2325 * Functional Description:
2326 * The command request and response buffers are posted to the adapter in the manner
2327 * described in the PDQ Port Specification:
2329 * 1. Command Response Buffer is posted to adapter.
2330 * 2. Command Request Buffer is posted to adapter.
2331 * 3. Command Request consumer index is polled until it indicates that request
2332 * buffer has been DMA'd to adapter.
2333 * 4. Command Response consumer index is polled until it indicates that response
2334 * buffer has been DMA'd from adapter.
2336 * This ordering ensures that a response buffer is already available for the firmware
2337 * to use once it's done processing the request buffer.
2339 * Return Codes:
2340 * DFX_K_SUCCESS - DMA command succeeded
2341 * DFX_K_OUTSTATE - Adapter is NOT in proper state
2342 * DFX_K_HW_TIMEOUT - DMA command timed out
2344 * Assumptions:
2345 * Command request buffer has already been filled with desired DMA command.
2347 * Side Effects:
2348 * None
2351 static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
2353 int status; /* adapter status */
2354 int timeout_cnt; /* used in for loops */
2356 /* Make sure the adapter is in a state that we can issue the DMA command in */
2358 status = dfx_hw_adap_state_rd(bp);
2359 if ((status == PI_STATE_K_RESET) ||
2360 (status == PI_STATE_K_HALTED) ||
2361 (status == PI_STATE_K_DMA_UNAVAIL) ||
2362 (status == PI_STATE_K_UPGRADE))
2363 return(DFX_K_OUTSTATE);
2365 /* Put response buffer on the command response queue */
2367 bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2368 ((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2369 bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
2371 /* Bump (and wrap) the producer index and write out to register */
2373 bp->cmd_rsp_reg.index.prod += 1;
2374 bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
2375 dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
2377 /* Put request buffer on the command request queue */
2379 bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
2380 PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
2381 bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
2383 /* Bump (and wrap) the producer index and write out to register */
2385 bp->cmd_req_reg.index.prod += 1;
2386 bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
2387 dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
2390 * Here we wait for the command request consumer index to be equal
2391 * to the producer, indicating that the adapter has DMAed the request.
2394 for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
2396 if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
2397 break;
2398 udelay(100); /* wait for 100 microseconds */
2400 if (timeout_cnt == 0)
2401 return(DFX_K_HW_TIMEOUT);
2403 /* Bump (and wrap) the completion index and write out to register */
2405 bp->cmd_req_reg.index.comp += 1;
2406 bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
2407 dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
2410 * Here we wait for the command response consumer index to be equal
2411 * to the producer, indicating that the adapter has DMAed the response.
2414 for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
2416 if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
2417 break;
2418 udelay(100); /* wait for 100 microseconds */
2420 if (timeout_cnt == 0)
2421 return(DFX_K_HW_TIMEOUT);
2423 /* Bump (and wrap) the completion index and write out to register */
2425 bp->cmd_rsp_reg.index.comp += 1;
2426 bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
2427 dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
2428 return(DFX_K_SUCCESS);
2433 * ========================
2434 * = dfx_hw_port_ctrl_req =
2435 * ========================
2437 * Overview:
2438 * Sends PDQ port control command to adapter firmware
2440 * Returns:
2441 * Host data register value in host_data if ptr is not NULL
2443 * Arguments:
2444 * bp - pointer to board information
2445 * command - port control command
2446 * data_a - port data A register value
2447 * data_b - port data B register value
2448 * host_data - ptr to host data register value
2450 * Functional Description:
2451 * Send generic port control command to adapter by writing
2452 * to various PDQ port registers, then polling for completion.
2454 * Return Codes:
2455 * DFX_K_SUCCESS - port control command succeeded
2456 * DFX_K_HW_TIMEOUT - port control command timed out
2458 * Assumptions:
2459 * None
2461 * Side Effects:
2462 * None
2465 static int dfx_hw_port_ctrl_req(
2466 DFX_board_t *bp,
2467 PI_UINT32 command,
2468 PI_UINT32 data_a,
2469 PI_UINT32 data_b,
2470 PI_UINT32 *host_data
2474 PI_UINT32 port_cmd; /* Port Control command register value */
2475 int timeout_cnt; /* used in for loops */
2477 /* Set Command Error bit in command longword */
2479 port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
2481 /* Issue port command to the adapter */
2483 dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
2484 dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
2485 dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
2487 /* Now wait for command to complete */
2489 if (command == PI_PCTRL_M_BLAST_FLASH)
2490 timeout_cnt = 600000; /* set command timeout count to 60 seconds */
2491 else
2492 timeout_cnt = 20000; /* set command timeout count to 2 seconds */
2494 for (; timeout_cnt > 0; timeout_cnt--)
2496 dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
2497 if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
2498 break;
2499 udelay(100); /* wait for 100 microseconds */
2501 if (timeout_cnt == 0)
2502 return(DFX_K_HW_TIMEOUT);
2505 * If the address of host_data is non-zero, assume caller has supplied a
2506 * non NULL pointer, and return the contents of the HOST_DATA register in
2507 * it.
2510 if (host_data != NULL)
2511 dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
2512 return(DFX_K_SUCCESS);
2517 * =====================
2518 * = dfx_hw_adap_reset =
2519 * =====================
2521 * Overview:
2522 * Resets adapter
2524 * Returns:
2525 * None
2527 * Arguments:
2528 * bp - pointer to board information
2529 * type - type of reset to perform
2531 * Functional Description:
2532 * Issue soft reset to adapter by writing to PDQ Port Reset
2533 * register. Use incoming reset type to tell adapter what
2534 * kind of reset operation to perform.
2536 * Return Codes:
2537 * None
2539 * Assumptions:
2540 * This routine merely issues a soft reset to the adapter.
2541 * It is expected that after this routine returns, the caller
2542 * will appropriately poll the Port Status register for the
2543 * adapter to enter the proper state.
2545 * Side Effects:
2546 * Internal adapter registers are cleared.
2549 static void dfx_hw_adap_reset(
2550 DFX_board_t *bp,
2551 PI_UINT32 type
2555 /* Set Reset type and assert reset */
2557 dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type); /* tell adapter type of reset */
2558 dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
2560 /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
2562 udelay(20);
2564 /* Deassert reset */
2566 dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
2571 * ========================
2572 * = dfx_hw_adap_state_rd =
2573 * ========================
2575 * Overview:
2576 * Returns current adapter state
2578 * Returns:
2579 * Adapter state per PDQ Port Specification
2581 * Arguments:
2582 * bp - pointer to board information
2584 * Functional Description:
2585 * Reads PDQ Port Status register and returns adapter state.
2587 * Return Codes:
2588 * None
2590 * Assumptions:
2591 * None
2593 * Side Effects:
2594 * None
2597 static int dfx_hw_adap_state_rd(DFX_board_t *bp)
2599 PI_UINT32 port_status; /* Port Status register value */
2601 dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
2602 return((port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE);
2607 * =====================
2608 * = dfx_hw_dma_uninit =
2609 * =====================
2611 * Overview:
2612 * Brings adapter to DMA_UNAVAILABLE state
2614 * Returns:
2615 * Condition code
2617 * Arguments:
2618 * bp - pointer to board information
2619 * type - type of reset to perform
2621 * Functional Description:
2622 * Bring adapter to DMA_UNAVAILABLE state by performing the following:
2623 * 1. Set reset type bit in Port Data A Register then reset adapter.
2624 * 2. Check that adapter is in DMA_UNAVAILABLE state.
2626 * Return Codes:
2627 * DFX_K_SUCCESS - adapter is in DMA_UNAVAILABLE state
2628 * DFX_K_HW_TIMEOUT - adapter did not reset properly
2630 * Assumptions:
2631 * None
2633 * Side Effects:
2634 * Internal adapter registers are cleared.
2637 static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
2639 int timeout_cnt; /* used in for loops */
2641 /* Set reset type bit and reset adapter */
2643 dfx_hw_adap_reset(bp, type);
2645 /* Now wait for adapter to enter DMA_UNAVAILABLE state */
2647 for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
2649 if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
2650 break;
2651 udelay(100); /* wait for 100 microseconds */
2653 if (timeout_cnt == 0)
2654 return(DFX_K_HW_TIMEOUT);
2655 return(DFX_K_SUCCESS);
2659 * Align an sk_buff to a boundary power of 2
2663 static void my_skb_align(struct sk_buff *skb, int n)
2665 u32 x=(u32)skb->data; /* We only want the low bits .. */
2666 u32 v;
2668 v=(x+n-1)&~(n-1); /* Where we want to be */
2670 skb_reserve(skb, v-x);
2675 * ================
2676 * = dfx_rcv_init =
2677 * ================
2679 * Overview:
2680 * Produces buffers to adapter LLC Host receive descriptor block
2682 * Returns:
2683 * None
2685 * Arguments:
2686 * bp - pointer to board information
2687 * get_buffers - non-zero if buffers to be allocated
2689 * Functional Description:
2690 * This routine can be called during dfx_adap_init() or during an adapter
2691 * reset. It initializes the descriptor block and produces all allocated
2692 * LLC Host queue receive buffers.
2694 * Return Codes:
2695 * Return 0 on success or -ENOMEM if buffer allocation failed (when using
2696 * dynamic buffer allocation). If the buffer allocation failed, the
2697 * already allocated buffers will not be released and the caller should do
2698 * this.
2700 * Assumptions:
2701 * The PDQ has been reset and the adapter and driver maintained Type 2
2702 * register indices are cleared.
2704 * Side Effects:
2705 * Receive buffers are posted to the adapter LLC queue and the adapter
2706 * is notified.
2709 static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
2711 int i, j; /* used in for loop */
2714 * Since each receive buffer is a single fragment of same length, initialize
2715 * first longword in each receive descriptor for entire LLC Host descriptor
2716 * block. Also initialize second longword in each receive descriptor with
2717 * physical address of receive buffer. We'll always allocate receive
2718 * buffers in powers of 2 so that we can easily fill the 256 entry descriptor
2719 * block and produce new receive buffers by simply updating the receive
2720 * producer index.
2722 * Assumptions:
2723 * To support all shipping versions of PDQ, the receive buffer size
2724 * must be mod 128 in length and the physical address must be 128 byte
2725 * aligned. In other words, bits 0-6 of the length and address must
2726 * be zero for the following descriptor field entries to be correct on
2727 * all PDQ-based boards. We guaranteed both requirements during
2728 * driver initialization when we allocated memory for the receive buffers.
2731 if (get_buffers) {
2732 #ifdef DYNAMIC_BUFFERS
2733 for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
2734 for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
2736 struct sk_buff *newskb = __dev_alloc_skb(NEW_SKB_SIZE, GFP_NOIO);
2737 if (!newskb)
2738 return -ENOMEM;
2739 bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2740 ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2742 * align to 128 bytes for compatibility with
2743 * the old EISA boards.
2746 my_skb_align(newskb, 128);
2747 bp->descr_block_virt->rcv_data[i+j].long_1 = virt_to_bus(newskb->data);
2749 * p_rcv_buff_va is only used inside the
2750 * kernel so we put the skb pointer here.
2752 bp->p_rcv_buff_va[i+j] = (char *) newskb;
2754 #else
2755 for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
2756 for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
2758 bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2759 ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2760 bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
2761 bp->p_rcv_buff_va[i+j] = (char *) (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
2763 #endif
2766 /* Update receive producer and Type 2 register */
2768 bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
2769 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
2770 return 0;
2775 * =========================
2776 * = dfx_rcv_queue_process =
2777 * =========================
2779 * Overview:
2780 * Process received LLC frames.
2782 * Returns:
2783 * None
2785 * Arguments:
2786 * bp - pointer to board information
2788 * Functional Description:
2789 * Received LLC frames are processed until there are no more consumed frames.
2790 * Once all frames are processed, the receive buffers are returned to the
2791 * adapter. Note that this algorithm fixes the length of time that can be spent
2792 * in this routine, because there are a fixed number of receive buffers to
2793 * process and buffers are not produced until this routine exits and returns
2794 * to the ISR.
2796 * Return Codes:
2797 * None
2799 * Assumptions:
2800 * None
2802 * Side Effects:
2803 * None
2806 static void dfx_rcv_queue_process(
2807 DFX_board_t *bp
2811 PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
2812 char *p_buff; /* ptr to start of packet receive buffer (FMC descriptor) */
2813 u32 descr, pkt_len; /* FMC descriptor field and packet length */
2814 struct sk_buff *skb; /* pointer to a sk_buff to hold incoming packet data */
2816 /* Service all consumed LLC receive frames */
2818 p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
2819 while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
2821 /* Process any errors */
2823 int entry;
2825 entry = bp->rcv_xmt_reg.index.rcv_comp;
2826 #ifdef DYNAMIC_BUFFERS
2827 p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
2828 #else
2829 p_buff = (char *) bp->p_rcv_buff_va[entry];
2830 #endif
2831 memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
2833 if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
2835 if (descr & PI_FMC_DESCR_M_RCC_CRC)
2836 bp->rcv_crc_errors++;
2837 else
2838 bp->rcv_frame_status_errors++;
2840 else
2842 int rx_in_place = 0;
2844 /* The frame was received without errors - verify packet length */
2846 pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
2847 pkt_len -= 4; /* subtract 4 byte CRC */
2848 if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
2849 bp->rcv_length_errors++;
2850 else{
2851 #ifdef DYNAMIC_BUFFERS
2852 if (pkt_len > SKBUFF_RX_COPYBREAK) {
2853 struct sk_buff *newskb;
2855 newskb = dev_alloc_skb(NEW_SKB_SIZE);
2856 if (newskb){
2857 rx_in_place = 1;
2859 my_skb_align(newskb, 128);
2860 skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
2861 skb_reserve(skb, RCV_BUFF_K_PADDING);
2862 bp->p_rcv_buff_va[entry] = (char *)newskb;
2863 bp->descr_block_virt->rcv_data[entry].long_1 = virt_to_bus(newskb->data);
2864 } else
2865 skb = NULL;
2866 } else
2867 #endif
2868 skb = dev_alloc_skb(pkt_len+3); /* alloc new buffer to pass up, add room for PRH */
2869 if (skb == NULL)
2871 printk("%s: Could not allocate receive buffer. Dropping packet.\n", bp->dev->name);
2872 bp->rcv_discards++;
2873 break;
2875 else {
2876 #ifndef DYNAMIC_BUFFERS
2877 if (! rx_in_place)
2878 #endif
2880 /* Receive buffer allocated, pass receive packet up */
2882 memcpy(skb->data, p_buff + RCV_BUFF_K_PADDING, pkt_len+3);
2885 skb_reserve(skb,3); /* adjust data field so that it points to FC byte */
2886 skb_put(skb, pkt_len); /* pass up packet length, NOT including CRC */
2887 skb->dev = bp->dev; /* pass up device pointer */
2889 skb->protocol = fddi_type_trans(skb, bp->dev);
2890 bp->rcv_total_bytes += skb->len;
2891 netif_rx(skb);
2893 /* Update the rcv counters */
2894 bp->dev->last_rx = jiffies;
2895 bp->rcv_total_frames++;
2896 if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
2897 bp->rcv_multicast_frames++;
2903 * Advance the producer (for recycling) and advance the completion
2904 * (for servicing received frames). Note that it is okay to
2905 * advance the producer without checking that it passes the
2906 * completion index because they are both advanced at the same
2907 * rate.
2910 bp->rcv_xmt_reg.index.rcv_prod += 1;
2911 bp->rcv_xmt_reg.index.rcv_comp += 1;
2917 * =====================
2918 * = dfx_xmt_queue_pkt =
2919 * =====================
2921 * Overview:
2922 * Queues packets for transmission
2924 * Returns:
2925 * Condition code
2927 * Arguments:
2928 * skb - pointer to sk_buff to queue for transmission
2929 * dev - pointer to device information
2931 * Functional Description:
2932 * Here we assume that an incoming skb transmit request
2933 * is contained in a single physically contiguous buffer
2934 * in which the virtual address of the start of packet
2935 * (skb->data) can be converted to a physical address
2936 * by using virt_to_bus().
2938 * Since the adapter architecture requires a three byte
2939 * packet request header to prepend the start of packet,
2940 * we'll write the three byte field immediately prior to
2941 * the FC byte. This assumption is valid because we've
2942 * ensured that dev->hard_header_len includes three pad
2943 * bytes. By posting a single fragment to the adapter,
2944 * we'll reduce the number of descriptor fetches and
2945 * bus traffic needed to send the request.
2947 * Also, we can't free the skb until after it's been DMA'd
2948 * out by the adapter, so we'll queue it in the driver and
2949 * return it in dfx_xmt_done.
2951 * Return Codes:
2952 * 0 - driver queued packet, link is unavailable, or skbuff was bad
2953 * 1 - caller should requeue the sk_buff for later transmission
2955 * Assumptions:
2956 * First and foremost, we assume the incoming skb pointer
2957 * is NOT NULL and is pointing to a valid sk_buff structure.
2959 * The outgoing packet is complete, starting with the
2960 * frame control byte including the last byte of data,
2961 * but NOT including the 4 byte CRC. We'll let the
2962 * adapter hardware generate and append the CRC.
2964 * The entire packet is stored in one physically
2965 * contiguous buffer which is not cached and whose
2966 * 32-bit physical address can be determined.
2968 * It's vital that this routine is NOT reentered for the
2969 * same board and that the OS is not in another section of
2970 * code (eg. dfx_int_common) for the same board on a
2971 * different thread.
2973 * Side Effects:
2974 * None
2977 static int dfx_xmt_queue_pkt(
2978 struct sk_buff *skb,
2979 struct net_device *dev
2983 DFX_board_t *bp = dev->priv;
2984 u8 prod; /* local transmit producer index */
2985 PI_XMT_DESCR *p_xmt_descr; /* ptr to transmit descriptor block entry */
2986 XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
2987 unsigned long flags;
2989 netif_stop_queue(dev);
2992 * Verify that incoming transmit request is OK
2994 * Note: The packet size check is consistent with other
2995 * Linux device drivers, although the correct packet
2996 * size should be verified before calling the
2997 * transmit routine.
3000 if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
3002 printk("%s: Invalid packet length - %u bytes\n",
3003 dev->name, skb->len);
3004 bp->xmt_length_errors++; /* bump error counter */
3005 netif_wake_queue(dev);
3006 dev_kfree_skb(skb);
3007 return(0); /* return "success" */
3010 * See if adapter link is available, if not, free buffer
3012 * Note: If the link isn't available, free buffer and return 0
3013 * rather than tell the upper layer to requeue the packet.
3014 * The methodology here is that by the time the link
3015 * becomes available, the packet to be sent will be
3016 * fairly stale. By simply dropping the packet, the
3017 * higher layer protocols will eventually time out
3018 * waiting for response packets which it won't receive.
3021 if (bp->link_available == PI_K_FALSE)
3023 if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL) /* is link really available? */
3024 bp->link_available = PI_K_TRUE; /* if so, set flag and continue */
3025 else
3027 bp->xmt_discards++; /* bump error counter */
3028 dev_kfree_skb(skb); /* free sk_buff now */
3029 netif_wake_queue(dev);
3030 return(0); /* return "success" */
3034 spin_lock_irqsave(&bp->lock, flags);
3036 /* Get the current producer and the next free xmt data descriptor */
3038 prod = bp->rcv_xmt_reg.index.xmt_prod;
3039 p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
3042 * Get pointer to auxiliary queue entry to contain information
3043 * for this packet.
3045 * Note: The current xmt producer index will become the
3046 * current xmt completion index when we complete this
3047 * packet later on. So, we'll get the pointer to the
3048 * next auxiliary queue entry now before we bump the
3049 * producer index.
3052 p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]); /* also bump producer index */
3054 /* Write the three PRH bytes immediately before the FC byte */
3056 skb_push(skb,3);
3057 skb->data[0] = DFX_PRH0_BYTE; /* these byte values are defined */
3058 skb->data[1] = DFX_PRH1_BYTE; /* in the Motorola FDDI MAC chip */
3059 skb->data[2] = DFX_PRH2_BYTE; /* specification */
3062 * Write the descriptor with buffer info and bump producer
3064 * Note: Since we need to start DMA from the packet request
3065 * header, we'll add 3 bytes to the DMA buffer length,
3066 * and we'll determine the physical address of the
3067 * buffer from the PRH, not skb->data.
3069 * Assumptions:
3070 * 1. Packet starts with the frame control (FC) byte
3071 * at skb->data.
3072 * 2. The 4-byte CRC is not appended to the buffer or
3073 * included in the length.
3074 * 3. Packet length (skb->len) is from FC to end of
3075 * data, inclusive.
3076 * 4. The packet length does not exceed the maximum
3077 * FDDI LLC frame length of 4491 bytes.
3078 * 5. The entire packet is contained in a physically
3079 * contiguous, non-cached, locked memory space
3080 * comprised of a single buffer pointed to by
3081 * skb->data.
3082 * 6. The physical address of the start of packet
3083 * can be determined from the virtual address
3084 * by using virt_to_bus() and is only 32-bits
3085 * wide.
3088 p_xmt_descr->long_0 = (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
3089 p_xmt_descr->long_1 = (u32) virt_to_bus(skb->data);
3092 * Verify that descriptor is actually available
3094 * Note: If descriptor isn't available, return 1 which tells
3095 * the upper layer to requeue the packet for later
3096 * transmission.
3098 * We need to ensure that the producer never reaches the
3099 * completion, except to indicate that the queue is empty.
3102 if (prod == bp->rcv_xmt_reg.index.xmt_comp)
3104 skb_pull(skb,3);
3105 spin_unlock_irqrestore(&bp->lock, flags);
3106 return(1); /* requeue packet for later */
3110 * Save info for this packet for xmt done indication routine
3112 * Normally, we'd save the producer index in the p_xmt_drv_descr
3113 * structure so that we'd have it handy when we complete this
3114 * packet later (in dfx_xmt_done). However, since the current
3115 * transmit architecture guarantees a single fragment for the
3116 * entire packet, we can simply bump the completion index by
3117 * one (1) for each completed packet.
3119 * Note: If this assumption changes and we're presented with
3120 * an inconsistent number of transmit fragments for packet
3121 * data, we'll need to modify this code to save the current
3122 * transmit producer index.
3125 p_xmt_drv_descr->p_skb = skb;
3127 /* Update Type 2 register */
3129 bp->rcv_xmt_reg.index.xmt_prod = prod;
3130 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
3131 spin_unlock_irqrestore(&bp->lock, flags);
3132 netif_wake_queue(dev);
3133 return(0); /* packet queued to adapter */
3138 * ================
3139 * = dfx_xmt_done =
3140 * ================
3142 * Overview:
3143 * Processes all frames that have been transmitted.
3145 * Returns:
3146 * None
3148 * Arguments:
3149 * bp - pointer to board information
3151 * Functional Description:
3152 * For all consumed transmit descriptors that have not
3153 * yet been completed, we'll free the skb we were holding
3154 * onto using dev_kfree_skb and bump the appropriate
3155 * counters.
3157 * Return Codes:
3158 * None
3160 * Assumptions:
3161 * The Type 2 register is not updated in this routine. It is
3162 * assumed that it will be updated in the ISR when dfx_xmt_done
3163 * returns.
3165 * Side Effects:
3166 * None
3169 static int dfx_xmt_done(DFX_board_t *bp)
3171 XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
3172 PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
3173 int freed = 0; /* buffers freed */
3175 /* Service all consumed transmit frames */
3177 p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
3178 while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
3180 /* Get pointer to the transmit driver descriptor block information */
3182 p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
3184 /* Increment transmit counters */
3186 bp->xmt_total_frames++;
3187 bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
3189 /* Return skb to operating system */
3191 dev_kfree_skb_irq(p_xmt_drv_descr->p_skb);
3194 * Move to start of next packet by updating completion index
3196 * Here we assume that a transmit packet request is always
3197 * serviced by posting one fragment. We can therefore
3198 * simplify the completion code by incrementing the
3199 * completion index by one. This code will need to be
3200 * modified if this assumption changes. See comments
3201 * in dfx_xmt_queue_pkt for more details.
3204 bp->rcv_xmt_reg.index.xmt_comp += 1;
3205 freed++;
3207 return freed;
3212 * =================
3213 * = dfx_rcv_flush =
3214 * =================
3216 * Overview:
3217 * Remove all skb's in the receive ring.
3219 * Returns:
3220 * None
3222 * Arguments:
3223 * bp - pointer to board information
3225 * Functional Description:
3226 * Free's all the dynamically allocated skb's that are
3227 * currently attached to the device receive ring. This
3228 * function is typically only used when the device is
3229 * initialized or reinitialized.
3231 * Return Codes:
3232 * None
3234 * Side Effects:
3235 * None
3237 #ifdef DYNAMIC_BUFFERS
3238 static void dfx_rcv_flush( DFX_board_t *bp )
3240 int i, j;
3242 for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
3243 for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
3245 struct sk_buff *skb;
3246 skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
3247 if (skb)
3248 dev_kfree_skb(skb);
3249 bp->p_rcv_buff_va[i+j] = NULL;
3253 #else
3254 static inline void dfx_rcv_flush( DFX_board_t *bp )
3257 #endif /* DYNAMIC_BUFFERS */
3260 * =================
3261 * = dfx_xmt_flush =
3262 * =================
3264 * Overview:
3265 * Processes all frames whether they've been transmitted
3266 * or not.
3268 * Returns:
3269 * None
3271 * Arguments:
3272 * bp - pointer to board information
3274 * Functional Description:
3275 * For all produced transmit descriptors that have not
3276 * yet been completed, we'll free the skb we were holding
3277 * onto using dev_kfree_skb and bump the appropriate
3278 * counters. Of course, it's possible that some of
3279 * these transmit requests actually did go out, but we
3280 * won't make that distinction here. Finally, we'll
3281 * update the consumer index to match the producer.
3283 * Return Codes:
3284 * None
3286 * Assumptions:
3287 * This routine does NOT update the Type 2 register. It
3288 * is assumed that this routine is being called during a
3289 * transmit flush interrupt, or a shutdown or close routine.
3291 * Side Effects:
3292 * None
3295 static void dfx_xmt_flush( DFX_board_t *bp )
3297 u32 prod_cons; /* rcv/xmt consumer block longword */
3298 XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
3300 /* Flush all outstanding transmit frames */
3302 while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
3304 /* Get pointer to the transmit driver descriptor block information */
3306 p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
3308 /* Return skb to operating system */
3310 dev_kfree_skb(p_xmt_drv_descr->p_skb);
3312 /* Increment transmit error counter */
3314 bp->xmt_discards++;
3317 * Move to start of next packet by updating completion index
3319 * Here we assume that a transmit packet request is always
3320 * serviced by posting one fragment. We can therefore
3321 * simplify the completion code by incrementing the
3322 * completion index by one. This code will need to be
3323 * modified if this assumption changes. See comments
3324 * in dfx_xmt_queue_pkt for more details.
3327 bp->rcv_xmt_reg.index.xmt_comp += 1;
3330 /* Update the transmit consumer index in the consumer block */
3332 prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
3333 prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
3334 bp->cons_block_virt->xmt_rcv_data = prod_cons;
3337 static void __devexit dfx_remove_one_pci_or_eisa(struct pci_dev *pdev, struct net_device *dev)
3339 DFX_board_t *bp = dev->priv;
3341 unregister_netdev(dev);
3342 release_region(dev->base_addr, pdev ? PFI_K_CSR_IO_LEN : PI_ESIC_K_CSR_IO_LEN );
3343 if (bp->kmalloced) kfree(bp->kmalloced);
3344 kfree(dev);
3347 static void __devexit dfx_remove_one (struct pci_dev *pdev)
3349 struct net_device *dev = pci_get_drvdata(pdev);
3351 dfx_remove_one_pci_or_eisa(pdev, dev);
3352 pci_set_drvdata(pdev, NULL);
3355 static struct pci_device_id dfx_pci_tbl[] __devinitdata = {
3356 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI, PCI_ANY_ID, PCI_ANY_ID, },
3357 { 0, }
3359 MODULE_DEVICE_TABLE(pci, dfx_pci_tbl);
3361 static struct pci_driver dfx_driver = {
3362 .name = "defxx",
3363 .probe = dfx_init_one,
3364 .remove = __devexit_p(dfx_remove_one),
3365 .id_table = dfx_pci_tbl,
3368 static int dfx_have_pci;
3369 static int dfx_have_eisa;
3372 static void __exit dfx_eisa_cleanup(void)
3374 struct net_device *dev = root_dfx_eisa_dev;
3376 while (dev)
3378 struct net_device *tmp;
3379 DFX_board_t *bp;
3381 bp = (DFX_board_t*)dev->priv;
3382 tmp = bp->next;
3383 dfx_remove_one_pci_or_eisa(NULL, dev);
3384 dev = tmp;
3388 static int __init dfx_init(void)
3390 int rc_pci, rc_eisa;
3392 /* when a module, this is printed whether or not devices are found in probe */
3393 #ifdef MODULE
3394 printk(version);
3395 #endif
3397 rc_pci = pci_module_init(&dfx_driver);
3398 if (rc_pci >= 0) dfx_have_pci = 1;
3400 rc_eisa = dfx_eisa_init();
3401 if (rc_eisa >= 0) dfx_have_eisa = 1;
3403 return ((rc_eisa < 0) ? 0 : rc_eisa) + ((rc_pci < 0) ? 0 : rc_pci);
3406 static void __exit dfx_cleanup(void)
3408 if (dfx_have_pci)
3409 pci_unregister_driver(&dfx_driver);
3410 if (dfx_have_eisa)
3411 dfx_eisa_cleanup();
3415 module_init(dfx_init);
3416 module_exit(dfx_cleanup);
3417 MODULE_LICENSE("GPL");
3421 * Local variables:
3422 * 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"
3423 * End: