]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/fddi/defxx.c
netpoll: use DEFINE_STATIC_SRCU() to define netpoll_srcu
[karo-tx-linux.git] / drivers / net / fddi / defxx.c
1 /*
2  * File Name:
3  *   defxx.c
4  *
5  * Copyright Information:
6  *   Copyright Digital Equipment Corporation 1996.
7  *
8  *   This software may be used and distributed according to the terms of
9  *   the GNU General Public License, incorporated herein by reference.
10  *
11  * Abstract:
12  *   A Linux device driver supporting the Digital Equipment Corporation
13  *   FDDI TURBOchannel, EISA and PCI controller families.  Supported
14  *   adapters include:
15  *
16  *              DEC FDDIcontroller/TURBOchannel (DEFTA)
17  *              DEC FDDIcontroller/EISA         (DEFEA)
18  *              DEC FDDIcontroller/PCI          (DEFPA)
19  *
20  * The original author:
21  *   LVS        Lawrence V. Stefani <lstefani@yahoo.com>
22  *
23  * Maintainers:
24  *   macro      Maciej W. Rozycki <macro@linux-mips.org>
25  *
26  * Credits:
27  *   I'd like to thank Patricia Cross for helping me get started with
28  *   Linux, David Davies for a lot of help upgrading and configuring
29  *   my development system and for answering many OS and driver
30  *   development questions, and Alan Cox for recommendations and
31  *   integration help on getting FDDI support into Linux.  LVS
32  *
33  * Driver Architecture:
34  *   The driver architecture is largely based on previous driver work
35  *   for other operating systems.  The upper edge interface and
36  *   functions were largely taken from existing Linux device drivers
37  *   such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
38  *   driver.
39  *
40  *   Adapter Probe -
41  *              The driver scans for supported EISA adapters by reading the
42  *              SLOT ID register for each EISA slot and making a match
43  *              against the expected value.
44  *
45  *   Bus-Specific Initialization -
46  *              This driver currently supports both EISA and PCI controller
47  *              families.  While the custom DMA chip and FDDI logic is similar
48  *              or identical, the bus logic is very different.  After
49  *              initialization, the     only bus-specific differences is in how the
50  *              driver enables and disables interrupts.  Other than that, the
51  *              run-time critical code behaves the same on both families.
52  *              It's important to note that both adapter families are configured
53  *              to I/O map, rather than memory map, the adapter registers.
54  *
55  *   Driver Open/Close -
56  *              In the driver open routine, the driver ISR (interrupt service
57  *              routine) is registered and the adapter is brought to an
58  *              operational state.  In the driver close routine, the opposite
59  *              occurs; the driver ISR is deregistered and the adapter is
60  *              brought to a safe, but closed state.  Users may use consecutive
61  *              commands to bring the adapter up and down as in the following
62  *              example:
63  *                                      ifconfig fddi0 up
64  *                                      ifconfig fddi0 down
65  *                                      ifconfig fddi0 up
66  *
67  *   Driver Shutdown -
68  *              Apparently, there is no shutdown or halt routine support under
69  *              Linux.  This routine would be called during "reboot" or
70  *              "shutdown" to allow the driver to place the adapter in a safe
71  *              state before a warm reboot occurs.  To be really safe, the user
72  *              should close the adapter before shutdown (eg. ifconfig fddi0 down)
73  *              to ensure that the adapter DMA engine is taken off-line.  However,
74  *              the current driver code anticipates this problem and always issues
75  *              a soft reset of the adapter     at the beginning of driver initialization.
76  *              A future driver enhancement in this area may occur in 2.1.X where
77  *              Alan indicated that a shutdown handler may be implemented.
78  *
79  *   Interrupt Service Routine -
80  *              The driver supports shared interrupts, so the ISR is registered for
81  *              each board with the appropriate flag and the pointer to that board's
82  *              device structure.  This provides the context during interrupt
83  *              processing to support shared interrupts and multiple boards.
84  *
85  *              Interrupt enabling/disabling can occur at many levels.  At the host
86  *              end, you can disable system interrupts, or disable interrupts at the
87  *              PIC (on Intel systems).  Across the bus, both EISA and PCI adapters
88  *              have a bus-logic chip interrupt enable/disable as well as a DMA
89  *              controller interrupt enable/disable.
90  *
91  *              The driver currently enables and disables adapter interrupts at the
92  *              bus-logic chip and assumes that Linux will take care of clearing or
93  *              acknowledging any host-based interrupt chips.
94  *
95  *   Control Functions -
96  *              Control functions are those used to support functions such as adding
97  *              or deleting multicast addresses, enabling or disabling packet
98  *              reception filters, or other custom/proprietary commands.  Presently,
99  *              the driver supports the "get statistics", "set multicast list", and
100  *              "set mac address" functions defined by Linux.  A list of possible
101  *              enhancements include:
102  *
103  *                              - Custom ioctl interface for executing port interface commands
104  *                              - Custom ioctl interface for adding unicast addresses to
105  *                                adapter CAM (to support bridge functions).
106  *                              - Custom ioctl interface for supporting firmware upgrades.
107  *
108  *   Hardware (port interface) Support Routines -
109  *              The driver function names that start with "dfx_hw_" represent
110  *              low-level port interface routines that are called frequently.  They
111  *              include issuing a DMA or port control command to the adapter,
112  *              resetting the adapter, or reading the adapter state.  Since the
113  *              driver initialization and run-time code must make calls into the
114  *              port interface, these routines were written to be as generic and
115  *              usable as possible.
116  *
117  *   Receive Path -
118  *              The adapter DMA engine supports a 256 entry receive descriptor block
119  *              of which up to 255 entries can be used at any given time.  The
120  *              architecture is a standard producer, consumer, completion model in
121  *              which the driver "produces" receive buffers to the adapter, the
122  *              adapter "consumes" the receive buffers by DMAing incoming packet data,
123  *              and the driver "completes" the receive buffers by servicing the
124  *              incoming packet, then "produces" a new buffer and starts the cycle
125  *              again.  Receive buffers can be fragmented in up to 16 fragments
126  *              (descriptor     entries).  For simplicity, this driver posts
127  *              single-fragment receive buffers of 4608 bytes, then allocates a
128  *              sk_buff, copies the data, then reposts the buffer.  To reduce CPU
129  *              utilization, a better approach would be to pass up the receive
130  *              buffer (no extra copy) then allocate and post a replacement buffer.
131  *              This is a performance enhancement that should be looked into at
132  *              some point.
133  *
134  *   Transmit Path -
135  *              Like the receive path, the adapter DMA engine supports a 256 entry
136  *              transmit descriptor block of which up to 255 entries can be used at
137  *              any     given time.  Transmit buffers can be fragmented in up to 255
138  *              fragments (descriptor entries).  This driver always posts one
139  *              fragment per transmit packet request.
140  *
141  *              The fragment contains the entire packet from FC to end of data.
142  *              Before posting the buffer to the adapter, the driver sets a three-byte
143  *              packet request header (PRH) which is required by the Motorola MAC chip
144  *              used on the adapters.  The PRH tells the MAC the type of token to
145  *              receive/send, whether or not to generate and append the CRC, whether
146  *              synchronous or asynchronous framing is used, etc.  Since the PRH
147  *              definition is not necessarily consistent across all FDDI chipsets,
148  *              the driver, rather than the common FDDI packet handler routines,
149  *              sets these bytes.
150  *
151  *              To reduce the amount of descriptor fetches needed per transmit request,
152  *              the driver takes advantage of the fact that there are at least three
153  *              bytes available before the skb->data field on the outgoing transmit
154  *              request.  This is guaranteed by having fddi_setup() in net_init.c set
155  *              dev->hard_header_len to 24 bytes.  21 bytes accounts for the largest
156  *              header in an 802.2 SNAP frame.  The other 3 bytes are the extra "pad"
157  *              bytes which we'll use to store the PRH.
158  *
159  *              There's a subtle advantage to adding these pad bytes to the
160  *              hard_header_len, it ensures that the data portion of the packet for
161  *              an 802.2 SNAP frame is longword aligned.  Other FDDI driver
162  *              implementations may not need the extra padding and can start copying
163  *              or DMAing directly from the FC byte which starts at skb->data.  Should
164  *              another driver implementation need ADDITIONAL padding, the net_init.c
165  *              module should be updated and dev->hard_header_len should be increased.
166  *              NOTE: To maintain the alignment on the data portion of the packet,
167  *              dev->hard_header_len should always be evenly divisible by 4 and at
168  *              least 24 bytes in size.
169  *
170  * Modification History:
171  *              Date            Name    Description
172  *              16-Aug-96       LVS             Created.
173  *              20-Aug-96       LVS             Updated dfx_probe so that version information
174  *                                                      string is only displayed if 1 or more cards are
175  *                                                      found.  Changed dfx_rcv_queue_process to copy
176  *                                                      3 NULL bytes before FC to ensure that data is
177  *                                                      longword aligned in receive buffer.
178  *              09-Sep-96       LVS             Updated dfx_ctl_set_multicast_list to enable
179  *                                                      LLC group promiscuous mode if multicast list
180  *                                                      is too large.  LLC individual/group promiscuous
181  *                                                      mode is now disabled if IFF_PROMISC flag not set.
182  *                                                      dfx_xmt_queue_pkt no longer checks for NULL skb
183  *                                                      on Alan Cox recommendation.  Added node address
184  *                                                      override support.
185  *              12-Sep-96       LVS             Reset current address to factory address during
186  *                                                      device open.  Updated transmit path to post a
187  *                                                      single fragment which includes PRH->end of data.
188  *              Mar 2000        AC              Did various cleanups for 2.3.x
189  *              Jun 2000        jgarzik         PCI and resource alloc cleanups
190  *              Jul 2000        tjeerd          Much cleanup and some bug fixes
191  *              Sep 2000        tjeerd          Fix leak on unload, cosmetic code cleanup
192  *              Feb 2001                        Skb allocation fixes
193  *              Feb 2001        davej           PCI enable cleanups.
194  *              04 Aug 2003     macro           Converted to the DMA API.
195  *              14 Aug 2004     macro           Fix device names reported.
196  *              14 Jun 2005     macro           Use irqreturn_t.
197  *              23 Oct 2006     macro           Big-endian host support.
198  *              14 Dec 2006     macro           TURBOchannel support.
199  */
200
201 /* Include files */
202 #include <linux/bitops.h>
203 #include <linux/compiler.h>
204 #include <linux/delay.h>
205 #include <linux/dma-mapping.h>
206 #include <linux/eisa.h>
207 #include <linux/errno.h>
208 #include <linux/fddidevice.h>
209 #include <linux/init.h>
210 #include <linux/interrupt.h>
211 #include <linux/ioport.h>
212 #include <linux/kernel.h>
213 #include <linux/module.h>
214 #include <linux/netdevice.h>
215 #include <linux/pci.h>
216 #include <linux/skbuff.h>
217 #include <linux/slab.h>
218 #include <linux/string.h>
219 #include <linux/tc.h>
220
221 #include <asm/byteorder.h>
222 #include <asm/io.h>
223
224 #include "defxx.h"
225
226 /* Version information string should be updated prior to each new release!  */
227 #define DRV_NAME "defxx"
228 #define DRV_VERSION "v1.10"
229 #define DRV_RELDATE "2006/12/14"
230
231 static char version[] =
232         DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
233         "  Lawrence V. Stefani and others\n";
234
235 #define DYNAMIC_BUFFERS 1
236
237 #define SKBUFF_RX_COPYBREAK 200
238 /*
239  * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
240  * alignment for compatibility with old EISA boards.
241  */
242 #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
243
244 #ifdef CONFIG_PCI
245 #define DFX_BUS_PCI(dev) (dev->bus == &pci_bus_type)
246 #else
247 #define DFX_BUS_PCI(dev) 0
248 #endif
249
250 #ifdef CONFIG_EISA
251 #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
252 #else
253 #define DFX_BUS_EISA(dev) 0
254 #endif
255
256 #ifdef CONFIG_TC
257 #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
258 #else
259 #define DFX_BUS_TC(dev) 0
260 #endif
261
262 #ifdef CONFIG_DEFXX_MMIO
263 #define DFX_MMIO 1
264 #else
265 #define DFX_MMIO 0
266 #endif
267
268 /* Define module-wide (static) routines */
269
270 static void             dfx_bus_init(struct net_device *dev);
271 static void             dfx_bus_uninit(struct net_device *dev);
272 static void             dfx_bus_config_check(DFX_board_t *bp);
273
274 static int              dfx_driver_init(struct net_device *dev,
275                                         const char *print_name,
276                                         resource_size_t bar_start);
277 static int              dfx_adap_init(DFX_board_t *bp, int get_buffers);
278
279 static int              dfx_open(struct net_device *dev);
280 static int              dfx_close(struct net_device *dev);
281
282 static void             dfx_int_pr_halt_id(DFX_board_t *bp);
283 static void             dfx_int_type_0_process(DFX_board_t *bp);
284 static void             dfx_int_common(struct net_device *dev);
285 static irqreturn_t      dfx_interrupt(int irq, void *dev_id);
286
287 static struct           net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
288 static void             dfx_ctl_set_multicast_list(struct net_device *dev);
289 static int              dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
290 static int              dfx_ctl_update_cam(DFX_board_t *bp);
291 static int              dfx_ctl_update_filters(DFX_board_t *bp);
292
293 static int              dfx_hw_dma_cmd_req(DFX_board_t *bp);
294 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);
295 static void             dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
296 static int              dfx_hw_adap_state_rd(DFX_board_t *bp);
297 static int              dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
298
299 static int              dfx_rcv_init(DFX_board_t *bp, int get_buffers);
300 static void             dfx_rcv_queue_process(DFX_board_t *bp);
301 static void             dfx_rcv_flush(DFX_board_t *bp);
302
303 static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
304                                      struct net_device *dev);
305 static int              dfx_xmt_done(DFX_board_t *bp);
306 static void             dfx_xmt_flush(DFX_board_t *bp);
307
308 /* Define module-wide (static) variables */
309
310 static struct pci_driver dfx_pci_driver;
311 static struct eisa_driver dfx_eisa_driver;
312 static struct tc_driver dfx_tc_driver;
313
314
315 /*
316  * =======================
317  * = dfx_port_write_long =
318  * = dfx_port_read_long  =
319  * =======================
320  *
321  * Overview:
322  *   Routines for reading and writing values from/to adapter
323  *
324  * Returns:
325  *   None
326  *
327  * Arguments:
328  *   bp         - pointer to board information
329  *   offset     - register offset from base I/O address
330  *   data       - for dfx_port_write_long, this is a value to write;
331  *                for dfx_port_read_long, this is a pointer to store
332  *                the read value
333  *
334  * Functional Description:
335  *   These routines perform the correct operation to read or write
336  *   the adapter register.
337  *
338  *   EISA port block base addresses are based on the slot number in which the
339  *   controller is installed.  For example, if the EISA controller is installed
340  *   in slot 4, the port block base address is 0x4000.  If the controller is
341  *   installed in slot 2, the port block base address is 0x2000, and so on.
342  *   This port block can be used to access PDQ, ESIC, and DEFEA on-board
343  *   registers using the register offsets defined in DEFXX.H.
344  *
345  *   PCI port block base addresses are assigned by the PCI BIOS or system
346  *   firmware.  There is one 128 byte port block which can be accessed.  It
347  *   allows for I/O mapping of both PDQ and PFI registers using the register
348  *   offsets defined in DEFXX.H.
349  *
350  * Return Codes:
351  *   None
352  *
353  * Assumptions:
354  *   bp->base is a valid base I/O address for this adapter.
355  *   offset is a valid register offset for this adapter.
356  *
357  * Side Effects:
358  *   Rather than produce macros for these functions, these routines
359  *   are defined using "inline" to ensure that the compiler will
360  *   generate inline code and not waste a procedure call and return.
361  *   This provides all the benefits of macros, but with the
362  *   advantage of strict data type checking.
363  */
364
365 static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
366 {
367         writel(data, bp->base.mem + offset);
368         mb();
369 }
370
371 static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
372 {
373         outl(data, bp->base.port + offset);
374 }
375
376 static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
377 {
378         struct device __maybe_unused *bdev = bp->bus_dev;
379         int dfx_bus_tc = DFX_BUS_TC(bdev);
380         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
381
382         if (dfx_use_mmio)
383                 dfx_writel(bp, offset, data);
384         else
385                 dfx_outl(bp, offset, data);
386 }
387
388
389 static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
390 {
391         mb();
392         *data = readl(bp->base.mem + offset);
393 }
394
395 static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
396 {
397         *data = inl(bp->base.port + offset);
398 }
399
400 static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
401 {
402         struct device __maybe_unused *bdev = bp->bus_dev;
403         int dfx_bus_tc = DFX_BUS_TC(bdev);
404         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
405
406         if (dfx_use_mmio)
407                 dfx_readl(bp, offset, data);
408         else
409                 dfx_inl(bp, offset, data);
410 }
411
412
413 /*
414  * ================
415  * = dfx_get_bars =
416  * ================
417  *
418  * Overview:
419  *   Retrieves the address range used to access control and status
420  *   registers.
421  *
422  * Returns:
423  *   None
424  *
425  * Arguments:
426  *   bdev       - pointer to device information
427  *   bar_start  - pointer to store the start address
428  *   bar_len    - pointer to store the length of the area
429  *
430  * Assumptions:
431  *   I am sure there are some.
432  *
433  * Side Effects:
434  *   None
435  */
436 static void dfx_get_bars(struct device *bdev,
437                          resource_size_t *bar_start, resource_size_t *bar_len)
438 {
439         int dfx_bus_pci = DFX_BUS_PCI(bdev);
440         int dfx_bus_eisa = DFX_BUS_EISA(bdev);
441         int dfx_bus_tc = DFX_BUS_TC(bdev);
442         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
443
444         if (dfx_bus_pci) {
445                 int num = dfx_use_mmio ? 0 : 1;
446
447                 *bar_start = pci_resource_start(to_pci_dev(bdev), num);
448                 *bar_len = pci_resource_len(to_pci_dev(bdev), num);
449         }
450         if (dfx_bus_eisa) {
451                 unsigned long base_addr = to_eisa_device(bdev)->base_addr;
452                 resource_size_t bar;
453
454                 if (dfx_use_mmio) {
455                         bar = inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_2);
456                         bar <<= 8;
457                         bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_1);
458                         bar <<= 8;
459                         bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_0);
460                         bar <<= 16;
461                         *bar_start = bar;
462                         bar = inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_2);
463                         bar <<= 8;
464                         bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_1);
465                         bar <<= 8;
466                         bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_0);
467                         bar <<= 16;
468                         *bar_len = (bar | PI_MEM_ADD_MASK_M) + 1;
469                 } else {
470                         *bar_start = base_addr;
471                         *bar_len = PI_ESIC_K_CSR_IO_LEN;
472                 }
473         }
474         if (dfx_bus_tc) {
475                 *bar_start = to_tc_dev(bdev)->resource.start +
476                              PI_TC_K_CSR_OFFSET;
477                 *bar_len = PI_TC_K_CSR_LEN;
478         }
479 }
480
481 static const struct net_device_ops dfx_netdev_ops = {
482         .ndo_open               = dfx_open,
483         .ndo_stop               = dfx_close,
484         .ndo_start_xmit         = dfx_xmt_queue_pkt,
485         .ndo_get_stats          = dfx_ctl_get_stats,
486         .ndo_set_rx_mode        = dfx_ctl_set_multicast_list,
487         .ndo_set_mac_address    = dfx_ctl_set_mac_address,
488 };
489
490 /*
491  * ================
492  * = dfx_register =
493  * ================
494  *
495  * Overview:
496  *   Initializes a supported FDDI controller
497  *
498  * Returns:
499  *   Condition code
500  *
501  * Arguments:
502  *   bdev - pointer to device information
503  *
504  * Functional Description:
505  *
506  * Return Codes:
507  *   0           - This device (fddi0, fddi1, etc) configured successfully
508  *   -EBUSY      - Failed to get resources, or dfx_driver_init failed.
509  *
510  * Assumptions:
511  *   It compiles so it should work :-( (PCI cards do :-)
512  *
513  * Side Effects:
514  *   Device structures for FDDI adapters (fddi0, fddi1, etc) are
515  *   initialized and the board resources are read and stored in
516  *   the device structure.
517  */
518 static int dfx_register(struct device *bdev)
519 {
520         static int version_disp;
521         int dfx_bus_pci = DFX_BUS_PCI(bdev);
522         int dfx_bus_tc = DFX_BUS_TC(bdev);
523         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
524         const char *print_name = dev_name(bdev);
525         struct net_device *dev;
526         DFX_board_t       *bp;                  /* board pointer */
527         resource_size_t bar_start = 0;          /* pointer to port */
528         resource_size_t bar_len = 0;            /* resource length */
529         int alloc_size;                         /* total buffer size used */
530         struct resource *region;
531         int err = 0;
532
533         if (!version_disp) {    /* display version info if adapter is found */
534                 version_disp = 1;       /* set display flag to TRUE so that */
535                 printk(version);        /* we only display this string ONCE */
536         }
537
538         dev = alloc_fddidev(sizeof(*bp));
539         if (!dev) {
540                 printk(KERN_ERR "%s: Unable to allocate fddidev, aborting\n",
541                        print_name);
542                 return -ENOMEM;
543         }
544
545         /* Enable PCI device. */
546         if (dfx_bus_pci && pci_enable_device(to_pci_dev(bdev))) {
547                 printk(KERN_ERR "%s: Cannot enable PCI device, aborting\n",
548                        print_name);
549                 goto err_out;
550         }
551
552         SET_NETDEV_DEV(dev, bdev);
553
554         bp = netdev_priv(dev);
555         bp->bus_dev = bdev;
556         dev_set_drvdata(bdev, dev);
557
558         dfx_get_bars(bdev, &bar_start, &bar_len);
559
560         if (dfx_use_mmio)
561                 region = request_mem_region(bar_start, bar_len, print_name);
562         else
563                 region = request_region(bar_start, bar_len, print_name);
564         if (!region) {
565                 printk(KERN_ERR "%s: Cannot reserve I/O resource "
566                        "0x%lx @ 0x%lx, aborting\n",
567                        print_name, (long)bar_len, (long)bar_start);
568                 err = -EBUSY;
569                 goto err_out_disable;
570         }
571
572         /* Set up I/O base address. */
573         if (dfx_use_mmio) {
574                 bp->base.mem = ioremap_nocache(bar_start, bar_len);
575                 if (!bp->base.mem) {
576                         printk(KERN_ERR "%s: Cannot map MMIO\n", print_name);
577                         err = -ENOMEM;
578                         goto err_out_region;
579                 }
580         } else {
581                 bp->base.port = bar_start;
582                 dev->base_addr = bar_start;
583         }
584
585         /* Initialize new device structure */
586         dev->netdev_ops                 = &dfx_netdev_ops;
587
588         if (dfx_bus_pci)
589                 pci_set_master(to_pci_dev(bdev));
590
591         if (dfx_driver_init(dev, print_name, bar_start) != DFX_K_SUCCESS) {
592                 err = -ENODEV;
593                 goto err_out_unmap;
594         }
595
596         err = register_netdev(dev);
597         if (err)
598                 goto err_out_kfree;
599
600         printk("%s: registered as %s\n", print_name, dev->name);
601         return 0;
602
603 err_out_kfree:
604         alloc_size = sizeof(PI_DESCR_BLOCK) +
605                      PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
606 #ifndef DYNAMIC_BUFFERS
607                      (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
608 #endif
609                      sizeof(PI_CONSUMER_BLOCK) +
610                      (PI_ALIGN_K_DESC_BLK - 1);
611         if (bp->kmalloced)
612                 dma_free_coherent(bdev, alloc_size,
613                                   bp->kmalloced, bp->kmalloced_dma);
614
615 err_out_unmap:
616         if (dfx_use_mmio)
617                 iounmap(bp->base.mem);
618
619 err_out_region:
620         if (dfx_use_mmio)
621                 release_mem_region(bar_start, bar_len);
622         else
623                 release_region(bar_start, bar_len);
624
625 err_out_disable:
626         if (dfx_bus_pci)
627                 pci_disable_device(to_pci_dev(bdev));
628
629 err_out:
630         free_netdev(dev);
631         return err;
632 }
633
634
635 /*
636  * ================
637  * = dfx_bus_init =
638  * ================
639  *
640  * Overview:
641  *   Initializes the bus-specific controller logic.
642  *
643  * Returns:
644  *   None
645  *
646  * Arguments:
647  *   dev - pointer to device information
648  *
649  * Functional Description:
650  *   Determine and save adapter IRQ in device table,
651  *   then perform bus-specific logic initialization.
652  *
653  * Return Codes:
654  *   None
655  *
656  * Assumptions:
657  *   bp->base has already been set with the proper
658  *       base I/O address for this device.
659  *
660  * Side Effects:
661  *   Interrupts are enabled at the adapter bus-specific logic.
662  *   Note:  Interrupts at the DMA engine (PDQ chip) are not
663  *   enabled yet.
664  */
665
666 static void dfx_bus_init(struct net_device *dev)
667 {
668         DFX_board_t *bp = netdev_priv(dev);
669         struct device *bdev = bp->bus_dev;
670         int dfx_bus_pci = DFX_BUS_PCI(bdev);
671         int dfx_bus_eisa = DFX_BUS_EISA(bdev);
672         int dfx_bus_tc = DFX_BUS_TC(bdev);
673         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
674         u8 val;
675
676         DBG_printk("In dfx_bus_init...\n");
677
678         /* Initialize a pointer back to the net_device struct */
679         bp->dev = dev;
680
681         /* Initialize adapter based on bus type */
682
683         if (dfx_bus_tc)
684                 dev->irq = to_tc_dev(bdev)->interrupt;
685         if (dfx_bus_eisa) {
686                 unsigned long base_addr = to_eisa_device(bdev)->base_addr;
687
688                 /* Get the interrupt level from the ESIC chip.  */
689                 val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
690                 val &= PI_CONFIG_STAT_0_M_IRQ;
691                 val >>= PI_CONFIG_STAT_0_V_IRQ;
692
693                 switch (val) {
694                 case PI_CONFIG_STAT_0_IRQ_K_9:
695                         dev->irq = 9;
696                         break;
697
698                 case PI_CONFIG_STAT_0_IRQ_K_10:
699                         dev->irq = 10;
700                         break;
701
702                 case PI_CONFIG_STAT_0_IRQ_K_11:
703                         dev->irq = 11;
704                         break;
705
706                 case PI_CONFIG_STAT_0_IRQ_K_15:
707                         dev->irq = 15;
708                         break;
709                 }
710
711                 /*
712                  * Enable memory decoding (MEMCS0) and/or port decoding
713                  * (IOCS1/IOCS0) as appropriate in Function Control
714                  * Register.  One of the port chip selects seems to be
715                  * used for the Burst Holdoff register, but this bit of
716                  * documentation is missing and as yet it has not been
717                  * determined which of the two.  This is also the reason
718                  * the size of the decoded port range is twice as large
719                  * as one required by the PDQ.
720                  */
721
722                 /* Set the decode range of the board.  */
723                 val = ((bp->base.port >> 12) << PI_IO_CMP_V_SLOT);
724                 outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_1, val);
725                 outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_0, 0);
726                 outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_1, val);
727                 outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_0, 0);
728                 val = PI_ESIC_K_CSR_IO_LEN - 1;
729                 outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_1, (val >> 8) & 0xff);
730                 outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_0, val & 0xff);
731                 outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_1, (val >> 8) & 0xff);
732                 outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_0, val & 0xff);
733
734                 /* Enable the decoders.  */
735                 val = PI_FUNCTION_CNTRL_M_IOCS1 | PI_FUNCTION_CNTRL_M_IOCS0;
736                 if (dfx_use_mmio)
737                         val |= PI_FUNCTION_CNTRL_M_MEMCS0;
738                 outb(base_addr + PI_ESIC_K_FUNCTION_CNTRL, val);
739
740                 /*
741                  * Enable access to the rest of the module
742                  * (including PDQ and packet memory).
743                  */
744                 val = PI_SLOT_CNTRL_M_ENB;
745                 outb(base_addr + PI_ESIC_K_SLOT_CNTRL, val);
746
747                 /*
748                  * Map PDQ registers into memory or port space.  This is
749                  * done with a bit in the Burst Holdoff register.
750                  */
751                 val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
752                 if (dfx_use_mmio)
753                         val |= PI_BURST_HOLDOFF_V_MEM_MAP;
754                 else
755                         val &= ~PI_BURST_HOLDOFF_V_MEM_MAP;
756                 outb(base_addr + PI_DEFEA_K_BURST_HOLDOFF, val);
757
758                 /* Enable interrupts at EISA bus interface chip (ESIC) */
759                 val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
760                 val |= PI_CONFIG_STAT_0_M_INT_ENB;
761                 outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
762         }
763         if (dfx_bus_pci) {
764                 struct pci_dev *pdev = to_pci_dev(bdev);
765
766                 /* Get the interrupt level from the PCI Configuration Table */
767
768                 dev->irq = pdev->irq;
769
770                 /* Check Latency Timer and set if less than minimal */
771
772                 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
773                 if (val < PFI_K_LAT_TIMER_MIN) {
774                         val = PFI_K_LAT_TIMER_DEF;
775                         pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
776                 }
777
778                 /* Enable interrupts at PCI bus interface chip (PFI) */
779                 val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
780                 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
781         }
782 }
783
784 /*
785  * ==================
786  * = dfx_bus_uninit =
787  * ==================
788  *
789  * Overview:
790  *   Uninitializes the bus-specific controller logic.
791  *
792  * Returns:
793  *   None
794  *
795  * Arguments:
796  *   dev - pointer to device information
797  *
798  * Functional Description:
799  *   Perform bus-specific logic uninitialization.
800  *
801  * Return Codes:
802  *   None
803  *
804  * Assumptions:
805  *   bp->base has already been set with the proper
806  *       base I/O address for this device.
807  *
808  * Side Effects:
809  *   Interrupts are disabled at the adapter bus-specific logic.
810  */
811
812 static void dfx_bus_uninit(struct net_device *dev)
813 {
814         DFX_board_t *bp = netdev_priv(dev);
815         struct device *bdev = bp->bus_dev;
816         int dfx_bus_pci = DFX_BUS_PCI(bdev);
817         int dfx_bus_eisa = DFX_BUS_EISA(bdev);
818         u8 val;
819
820         DBG_printk("In dfx_bus_uninit...\n");
821
822         /* Uninitialize adapter based on bus type */
823
824         if (dfx_bus_eisa) {
825                 unsigned long base_addr = to_eisa_device(bdev)->base_addr;
826
827                 /* Disable interrupts at EISA bus interface chip (ESIC) */
828                 val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
829                 val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
830                 outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
831         }
832         if (dfx_bus_pci) {
833                 /* Disable interrupts at PCI bus interface chip (PFI) */
834                 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
835         }
836 }
837
838
839 /*
840  * ========================
841  * = dfx_bus_config_check =
842  * ========================
843  *
844  * Overview:
845  *   Checks the configuration (burst size, full-duplex, etc.)  If any parameters
846  *   are illegal, then this routine will set new defaults.
847  *
848  * Returns:
849  *   None
850  *
851  * Arguments:
852  *   bp - pointer to board information
853  *
854  * Functional Description:
855  *   For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
856  *   PDQ, and all FDDI PCI controllers, all values are legal.
857  *
858  * Return Codes:
859  *   None
860  *
861  * Assumptions:
862  *   dfx_adap_init has NOT been called yet so burst size and other items have
863  *   not been set.
864  *
865  * Side Effects:
866  *   None
867  */
868
869 static void dfx_bus_config_check(DFX_board_t *bp)
870 {
871         struct device __maybe_unused *bdev = bp->bus_dev;
872         int dfx_bus_eisa = DFX_BUS_EISA(bdev);
873         int     status;                         /* return code from adapter port control call */
874         u32     host_data;                      /* LW data returned from port control call */
875
876         DBG_printk("In dfx_bus_config_check...\n");
877
878         /* Configuration check only valid for EISA adapter */
879
880         if (dfx_bus_eisa) {
881                 /*
882                  * First check if revision 2 EISA controller.  Rev. 1 cards used
883                  * PDQ revision B, so no workaround needed in this case.  Rev. 3
884                  * cards used PDQ revision E, so no workaround needed in this
885                  * case, either.  Only Rev. 2 cards used either Rev. D or E
886                  * chips, so we must verify the chip revision on Rev. 2 cards.
887                  */
888                 if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
889                         /*
890                          * Revision 2 FDDI EISA controller found,
891                          * so let's check PDQ revision of adapter.
892                          */
893                         status = dfx_hw_port_ctrl_req(bp,
894                                                                                         PI_PCTRL_M_SUB_CMD,
895                                                                                         PI_SUB_CMD_K_PDQ_REV_GET,
896                                                                                         0,
897                                                                                         &host_data);
898                         if ((status != DFX_K_SUCCESS) || (host_data == 2))
899                                 {
900                                 /*
901                                  * Either we couldn't determine the PDQ revision, or
902                                  * we determined that it is at revision D.  In either case,
903                                  * we need to implement the workaround.
904                                  */
905
906                                 /* Ensure that the burst size is set to 8 longwords or less */
907
908                                 switch (bp->burst_size)
909                                         {
910                                         case PI_PDATA_B_DMA_BURST_SIZE_32:
911                                         case PI_PDATA_B_DMA_BURST_SIZE_16:
912                                                 bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
913                                                 break;
914
915                                         default:
916                                                 break;
917                                         }
918
919                                 /* Ensure that full-duplex mode is not enabled */
920
921                                 bp->full_duplex_enb = PI_SNMP_K_FALSE;
922                                 }
923                         }
924                 }
925         }
926
927
928 /*
929  * ===================
930  * = dfx_driver_init =
931  * ===================
932  *
933  * Overview:
934  *   Initializes remaining adapter board structure information
935  *   and makes sure adapter is in a safe state prior to dfx_open().
936  *
937  * Returns:
938  *   Condition code
939  *
940  * Arguments:
941  *   dev - pointer to device information
942  *   print_name - printable device name
943  *
944  * Functional Description:
945  *   This function allocates additional resources such as the host memory
946  *   blocks needed by the adapter (eg. descriptor and consumer blocks).
947  *       Remaining bus initialization steps are also completed.  The adapter
948  *   is also reset so that it is in the DMA_UNAVAILABLE state.  The OS
949  *   must call dfx_open() to open the adapter and bring it on-line.
950  *
951  * Return Codes:
952  *   DFX_K_SUCCESS      - initialization succeeded
953  *   DFX_K_FAILURE      - initialization failed - could not allocate memory
954  *                                              or read adapter MAC address
955  *
956  * Assumptions:
957  *   Memory allocated from pci_alloc_consistent() call is physically
958  *   contiguous, locked memory.
959  *
960  * Side Effects:
961  *   Adapter is reset and should be in DMA_UNAVAILABLE state before
962  *   returning from this routine.
963  */
964
965 static int dfx_driver_init(struct net_device *dev, const char *print_name,
966                            resource_size_t bar_start)
967 {
968         DFX_board_t *bp = netdev_priv(dev);
969         struct device *bdev = bp->bus_dev;
970         int dfx_bus_pci = DFX_BUS_PCI(bdev);
971         int dfx_bus_eisa = DFX_BUS_EISA(bdev);
972         int dfx_bus_tc = DFX_BUS_TC(bdev);
973         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
974         int alloc_size;                 /* total buffer size needed */
975         char *top_v, *curr_v;           /* virtual addrs into memory block */
976         dma_addr_t top_p, curr_p;       /* physical addrs into memory block */
977         u32 data;                       /* host data register value */
978         __le32 le32;
979         char *board_name = NULL;
980
981         DBG_printk("In dfx_driver_init...\n");
982
983         /* Initialize bus-specific hardware registers */
984
985         dfx_bus_init(dev);
986
987         /*
988          * Initialize default values for configurable parameters
989          *
990          * Note: All of these parameters are ones that a user may
991          *       want to customize.  It'd be nice to break these
992          *               out into Space.c or someplace else that's more
993          *               accessible/understandable than this file.
994          */
995
996         bp->full_duplex_enb             = PI_SNMP_K_FALSE;
997         bp->req_ttrt                    = 8 * 12500;            /* 8ms in 80 nanosec units */
998         bp->burst_size                  = PI_PDATA_B_DMA_BURST_SIZE_DEF;
999         bp->rcv_bufs_to_post    = RCV_BUFS_DEF;
1000
1001         /*
1002          * Ensure that HW configuration is OK
1003          *
1004          * Note: Depending on the hardware revision, we may need to modify
1005          *       some of the configurable parameters to workaround hardware
1006          *       limitations.  We'll perform this configuration check AFTER
1007          *       setting the parameters to their default values.
1008          */
1009
1010         dfx_bus_config_check(bp);
1011
1012         /* Disable PDQ interrupts first */
1013
1014         dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1015
1016         /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1017
1018         (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
1019
1020         /*  Read the factory MAC address from the adapter then save it */
1021
1022         if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
1023                                  &data) != DFX_K_SUCCESS) {
1024                 printk("%s: Could not read adapter factory MAC address!\n",
1025                        print_name);
1026                 return DFX_K_FAILURE;
1027         }
1028         le32 = cpu_to_le32(data);
1029         memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
1030
1031         if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
1032                                  &data) != DFX_K_SUCCESS) {
1033                 printk("%s: Could not read adapter factory MAC address!\n",
1034                        print_name);
1035                 return DFX_K_FAILURE;
1036         }
1037         le32 = cpu_to_le32(data);
1038         memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
1039
1040         /*
1041          * Set current address to factory address
1042          *
1043          * Note: Node address override support is handled through
1044          *       dfx_ctl_set_mac_address.
1045          */
1046
1047         memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
1048         if (dfx_bus_tc)
1049                 board_name = "DEFTA";
1050         if (dfx_bus_eisa)
1051                 board_name = "DEFEA";
1052         if (dfx_bus_pci)
1053                 board_name = "DEFPA";
1054         pr_info("%s: %s at %saddr = 0x%llx, IRQ = %d, Hardware addr = %pMF\n",
1055                 print_name, board_name, dfx_use_mmio ? "" : "I/O ",
1056                 (long long)bar_start, dev->irq, dev->dev_addr);
1057
1058         /*
1059          * Get memory for descriptor block, consumer block, and other buffers
1060          * that need to be DMA read or written to by the adapter.
1061          */
1062
1063         alloc_size = sizeof(PI_DESCR_BLOCK) +
1064                                         PI_CMD_REQ_K_SIZE_MAX +
1065                                         PI_CMD_RSP_K_SIZE_MAX +
1066 #ifndef DYNAMIC_BUFFERS
1067                                         (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
1068 #endif
1069                                         sizeof(PI_CONSUMER_BLOCK) +
1070                                         (PI_ALIGN_K_DESC_BLK - 1);
1071         bp->kmalloced = top_v = dma_alloc_coherent(bp->bus_dev, alloc_size,
1072                                                    &bp->kmalloced_dma,
1073                                                    GFP_ATOMIC);
1074         if (top_v == NULL)
1075                 return DFX_K_FAILURE;
1076
1077         memset(top_v, 0, alloc_size);   /* zero out memory before continuing */
1078         top_p = bp->kmalloced_dma;      /* get physical address of buffer */
1079
1080         /*
1081          *  To guarantee the 8K alignment required for the descriptor block, 8K - 1
1082          *  plus the amount of memory needed was allocated.  The physical address
1083          *      is now 8K aligned.  By carving up the memory in a specific order,
1084          *  we'll guarantee the alignment requirements for all other structures.
1085          *
1086          *  Note: If the assumptions change regarding the non-paged, non-cached,
1087          *                physically contiguous nature of the memory block or the address
1088          *                alignments, then we'll need to implement a different algorithm
1089          *                for allocating the needed memory.
1090          */
1091
1092         curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
1093         curr_v = top_v + (curr_p - top_p);
1094
1095         /* Reserve space for descriptor block */
1096
1097         bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
1098         bp->descr_block_phys = curr_p;
1099         curr_v += sizeof(PI_DESCR_BLOCK);
1100         curr_p += sizeof(PI_DESCR_BLOCK);
1101
1102         /* Reserve space for command request buffer */
1103
1104         bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
1105         bp->cmd_req_phys = curr_p;
1106         curr_v += PI_CMD_REQ_K_SIZE_MAX;
1107         curr_p += PI_CMD_REQ_K_SIZE_MAX;
1108
1109         /* Reserve space for command response buffer */
1110
1111         bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
1112         bp->cmd_rsp_phys = curr_p;
1113         curr_v += PI_CMD_RSP_K_SIZE_MAX;
1114         curr_p += PI_CMD_RSP_K_SIZE_MAX;
1115
1116         /* Reserve space for the LLC host receive queue buffers */
1117
1118         bp->rcv_block_virt = curr_v;
1119         bp->rcv_block_phys = curr_p;
1120
1121 #ifndef DYNAMIC_BUFFERS
1122         curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
1123         curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
1124 #endif
1125
1126         /* Reserve space for the consumer block */
1127
1128         bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
1129         bp->cons_block_phys = curr_p;
1130
1131         /* Display virtual and physical addresses if debug driver */
1132
1133         DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X\n",
1134                    print_name,
1135                    (long)bp->descr_block_virt, bp->descr_block_phys);
1136         DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X\n",
1137                    print_name, (long)bp->cmd_req_virt, bp->cmd_req_phys);
1138         DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X\n",
1139                    print_name, (long)bp->cmd_rsp_virt, bp->cmd_rsp_phys);
1140         DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X\n",
1141                    print_name, (long)bp->rcv_block_virt, bp->rcv_block_phys);
1142         DBG_printk("%s: Consumer block virt = %0lX, phys = %0X\n",
1143                    print_name, (long)bp->cons_block_virt, bp->cons_block_phys);
1144
1145         return DFX_K_SUCCESS;
1146 }
1147
1148
1149 /*
1150  * =================
1151  * = dfx_adap_init =
1152  * =================
1153  *
1154  * Overview:
1155  *   Brings the adapter to the link avail/link unavailable state.
1156  *
1157  * Returns:
1158  *   Condition code
1159  *
1160  * Arguments:
1161  *   bp - pointer to board information
1162  *   get_buffers - non-zero if buffers to be allocated
1163  *
1164  * Functional Description:
1165  *   Issues the low-level firmware/hardware calls necessary to bring
1166  *   the adapter up, or to properly reset and restore adapter during
1167  *   run-time.
1168  *
1169  * Return Codes:
1170  *   DFX_K_SUCCESS - Adapter brought up successfully
1171  *   DFX_K_FAILURE - Adapter initialization failed
1172  *
1173  * Assumptions:
1174  *   bp->reset_type should be set to a valid reset type value before
1175  *   calling this routine.
1176  *
1177  * Side Effects:
1178  *   Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
1179  *   upon a successful return of this routine.
1180  */
1181
1182 static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
1183         {
1184         DBG_printk("In dfx_adap_init...\n");
1185
1186         /* Disable PDQ interrupts first */
1187
1188         dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1189
1190         /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1191
1192         if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
1193                 {
1194                 printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
1195                 return DFX_K_FAILURE;
1196                 }
1197
1198         /*
1199          * When the PDQ is reset, some false Type 0 interrupts may be pending,
1200          * so we'll acknowledge all Type 0 interrupts now before continuing.
1201          */
1202
1203         dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
1204
1205         /*
1206          * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
1207          *
1208          * Note: We only need to clear host copies of these registers.  The PDQ reset
1209          *       takes care of the on-board register values.
1210          */
1211
1212         bp->cmd_req_reg.lword   = 0;
1213         bp->cmd_rsp_reg.lword   = 0;
1214         bp->rcv_xmt_reg.lword   = 0;
1215
1216         /* Clear consumer block before going to DMA_AVAILABLE state */
1217
1218         memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
1219
1220         /* Initialize the DMA Burst Size */
1221
1222         if (dfx_hw_port_ctrl_req(bp,
1223                                                         PI_PCTRL_M_SUB_CMD,
1224                                                         PI_SUB_CMD_K_BURST_SIZE_SET,
1225                                                         bp->burst_size,
1226                                                         NULL) != DFX_K_SUCCESS)
1227                 {
1228                 printk("%s: Could not set adapter burst size!\n", bp->dev->name);
1229                 return DFX_K_FAILURE;
1230                 }
1231
1232         /*
1233          * Set base address of Consumer Block
1234          *
1235          * Assumption: 32-bit physical address of consumer block is 64 byte
1236          *                         aligned.  That is, bits 0-5 of the address must be zero.
1237          */
1238
1239         if (dfx_hw_port_ctrl_req(bp,
1240                                                         PI_PCTRL_M_CONS_BLOCK,
1241                                                         bp->cons_block_phys,
1242                                                         0,
1243                                                         NULL) != DFX_K_SUCCESS)
1244                 {
1245                 printk("%s: Could not set consumer block address!\n", bp->dev->name);
1246                 return DFX_K_FAILURE;
1247                 }
1248
1249         /*
1250          * Set the base address of Descriptor Block and bring adapter
1251          * to DMA_AVAILABLE state.
1252          *
1253          * Note: We also set the literal and data swapping requirements
1254          *       in this command.
1255          *
1256          * Assumption: 32-bit physical address of descriptor block
1257          *       is 8Kbyte aligned.
1258          */
1259         if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
1260                                  (u32)(bp->descr_block_phys |
1261                                        PI_PDATA_A_INIT_M_BSWAP_INIT),
1262                                  0, NULL) != DFX_K_SUCCESS) {
1263                 printk("%s: Could not set descriptor block address!\n",
1264                        bp->dev->name);
1265                 return DFX_K_FAILURE;
1266         }
1267
1268         /* Set transmit flush timeout value */
1269
1270         bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
1271         bp->cmd_req_virt->char_set.item[0].item_code    = PI_ITEM_K_FLUSH_TIME;
1272         bp->cmd_req_virt->char_set.item[0].value                = 3;    /* 3 seconds */
1273         bp->cmd_req_virt->char_set.item[0].item_index   = 0;
1274         bp->cmd_req_virt->char_set.item[1].item_code    = PI_ITEM_K_EOL;
1275         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1276                 {
1277                 printk("%s: DMA command request failed!\n", bp->dev->name);
1278                 return DFX_K_FAILURE;
1279                 }
1280
1281         /* Set the initial values for eFDXEnable and MACTReq MIB objects */
1282
1283         bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
1284         bp->cmd_req_virt->snmp_set.item[0].item_code    = PI_ITEM_K_FDX_ENB_DIS;
1285         bp->cmd_req_virt->snmp_set.item[0].value                = bp->full_duplex_enb;
1286         bp->cmd_req_virt->snmp_set.item[0].item_index   = 0;
1287         bp->cmd_req_virt->snmp_set.item[1].item_code    = PI_ITEM_K_MAC_T_REQ;
1288         bp->cmd_req_virt->snmp_set.item[1].value                = bp->req_ttrt;
1289         bp->cmd_req_virt->snmp_set.item[1].item_index   = 0;
1290         bp->cmd_req_virt->snmp_set.item[2].item_code    = PI_ITEM_K_EOL;
1291         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1292                 {
1293                 printk("%s: DMA command request failed!\n", bp->dev->name);
1294                 return DFX_K_FAILURE;
1295                 }
1296
1297         /* Initialize adapter CAM */
1298
1299         if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
1300                 {
1301                 printk("%s: Adapter CAM update failed!\n", bp->dev->name);
1302                 return DFX_K_FAILURE;
1303                 }
1304
1305         /* Initialize adapter filters */
1306
1307         if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
1308                 {
1309                 printk("%s: Adapter filters update failed!\n", bp->dev->name);
1310                 return DFX_K_FAILURE;
1311                 }
1312
1313         /*
1314          * Remove any existing dynamic buffers (i.e. if the adapter is being
1315          * reinitialized)
1316          */
1317
1318         if (get_buffers)
1319                 dfx_rcv_flush(bp);
1320
1321         /* Initialize receive descriptor block and produce buffers */
1322
1323         if (dfx_rcv_init(bp, get_buffers))
1324                 {
1325                 printk("%s: Receive buffer allocation failed\n", bp->dev->name);
1326                 if (get_buffers)
1327                         dfx_rcv_flush(bp);
1328                 return DFX_K_FAILURE;
1329                 }
1330
1331         /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
1332
1333         bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
1334         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1335                 {
1336                 printk("%s: Start command failed\n", bp->dev->name);
1337                 if (get_buffers)
1338                         dfx_rcv_flush(bp);
1339                 return DFX_K_FAILURE;
1340                 }
1341
1342         /* Initialization succeeded, reenable PDQ interrupts */
1343
1344         dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
1345         return DFX_K_SUCCESS;
1346         }
1347
1348
1349 /*
1350  * ============
1351  * = dfx_open =
1352  * ============
1353  *
1354  * Overview:
1355  *   Opens the adapter
1356  *
1357  * Returns:
1358  *   Condition code
1359  *
1360  * Arguments:
1361  *   dev - pointer to device information
1362  *
1363  * Functional Description:
1364  *   This function brings the adapter to an operational state.
1365  *
1366  * Return Codes:
1367  *   0           - Adapter was successfully opened
1368  *   -EAGAIN - Could not register IRQ or adapter initialization failed
1369  *
1370  * Assumptions:
1371  *   This routine should only be called for a device that was
1372  *   initialized successfully.
1373  *
1374  * Side Effects:
1375  *   Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
1376  *   if the open is successful.
1377  */
1378
1379 static int dfx_open(struct net_device *dev)
1380 {
1381         DFX_board_t *bp = netdev_priv(dev);
1382         int ret;
1383
1384         DBG_printk("In dfx_open...\n");
1385
1386         /* Register IRQ - support shared interrupts by passing device ptr */
1387
1388         ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
1389                           dev);
1390         if (ret) {
1391                 printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
1392                 return ret;
1393         }
1394
1395         /*
1396          * Set current address to factory MAC address
1397          *
1398          * Note: We've already done this step in dfx_driver_init.
1399          *       However, it's possible that a user has set a node
1400          *               address override, then closed and reopened the
1401          *               adapter.  Unless we reset the device address field
1402          *               now, we'll continue to use the existing modified
1403          *               address.
1404          */
1405
1406         memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
1407
1408         /* Clear local unicast/multicast address tables and counts */
1409
1410         memset(bp->uc_table, 0, sizeof(bp->uc_table));
1411         memset(bp->mc_table, 0, sizeof(bp->mc_table));
1412         bp->uc_count = 0;
1413         bp->mc_count = 0;
1414
1415         /* Disable promiscuous filter settings */
1416
1417         bp->ind_group_prom      = PI_FSTATE_K_BLOCK;
1418         bp->group_prom          = PI_FSTATE_K_BLOCK;
1419
1420         spin_lock_init(&bp->lock);
1421
1422         /* Reset and initialize adapter */
1423
1424         bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST;    /* skip self-test */
1425         if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
1426         {
1427                 printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
1428                 free_irq(dev->irq, dev);
1429                 return -EAGAIN;
1430         }
1431
1432         /* Set device structure info */
1433         netif_start_queue(dev);
1434         return 0;
1435 }
1436
1437
1438 /*
1439  * =============
1440  * = dfx_close =
1441  * =============
1442  *
1443  * Overview:
1444  *   Closes the device/module.
1445  *
1446  * Returns:
1447  *   Condition code
1448  *
1449  * Arguments:
1450  *   dev - pointer to device information
1451  *
1452  * Functional Description:
1453  *   This routine closes the adapter and brings it to a safe state.
1454  *   The interrupt service routine is deregistered with the OS.
1455  *   The adapter can be opened again with another call to dfx_open().
1456  *
1457  * Return Codes:
1458  *   Always return 0.
1459  *
1460  * Assumptions:
1461  *   No further requests for this adapter are made after this routine is
1462  *   called.  dfx_open() can be called to reset and reinitialize the
1463  *   adapter.
1464  *
1465  * Side Effects:
1466  *   Adapter should be in DMA_UNAVAILABLE state upon completion of this
1467  *   routine.
1468  */
1469
1470 static int dfx_close(struct net_device *dev)
1471 {
1472         DFX_board_t *bp = netdev_priv(dev);
1473
1474         DBG_printk("In dfx_close...\n");
1475
1476         /* Disable PDQ interrupts first */
1477
1478         dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1479
1480         /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1481
1482         (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
1483
1484         /*
1485          * Flush any pending transmit buffers
1486          *
1487          * Note: It's important that we flush the transmit buffers
1488          *               BEFORE we clear our copy of the Type 2 register.
1489          *               Otherwise, we'll have no idea how many buffers
1490          *               we need to free.
1491          */
1492
1493         dfx_xmt_flush(bp);
1494
1495         /*
1496          * Clear Type 1 and Type 2 registers after adapter reset
1497          *
1498          * Note: Even though we're closing the adapter, it's
1499          *       possible that an interrupt will occur after
1500          *               dfx_close is called.  Without some assurance to
1501          *               the contrary we want to make sure that we don't
1502          *               process receive and transmit LLC frames and update
1503          *               the Type 2 register with bad information.
1504          */
1505
1506         bp->cmd_req_reg.lword   = 0;
1507         bp->cmd_rsp_reg.lword   = 0;
1508         bp->rcv_xmt_reg.lword   = 0;
1509
1510         /* Clear consumer block for the same reason given above */
1511
1512         memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
1513
1514         /* Release all dynamically allocate skb in the receive ring. */
1515
1516         dfx_rcv_flush(bp);
1517
1518         /* Clear device structure flags */
1519
1520         netif_stop_queue(dev);
1521
1522         /* Deregister (free) IRQ */
1523
1524         free_irq(dev->irq, dev);
1525
1526         return 0;
1527 }
1528
1529
1530 /*
1531  * ======================
1532  * = dfx_int_pr_halt_id =
1533  * ======================
1534  *
1535  * Overview:
1536  *   Displays halt id's in string form.
1537  *
1538  * Returns:
1539  *   None
1540  *
1541  * Arguments:
1542  *   bp - pointer to board information
1543  *
1544  * Functional Description:
1545  *   Determine current halt id and display appropriate string.
1546  *
1547  * Return Codes:
1548  *   None
1549  *
1550  * Assumptions:
1551  *   None
1552  *
1553  * Side Effects:
1554  *   None
1555  */
1556
1557 static void dfx_int_pr_halt_id(DFX_board_t      *bp)
1558         {
1559         PI_UINT32       port_status;                    /* PDQ port status register value */
1560         PI_UINT32       halt_id;                                /* PDQ port status halt ID */
1561
1562         /* Read the latest port status */
1563
1564         dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
1565
1566         /* Display halt state transition information */
1567
1568         halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
1569         switch (halt_id)
1570                 {
1571                 case PI_HALT_ID_K_SELFTEST_TIMEOUT:
1572                         printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
1573                         break;
1574
1575                 case PI_HALT_ID_K_PARITY_ERROR:
1576                         printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
1577                         break;
1578
1579                 case PI_HALT_ID_K_HOST_DIR_HALT:
1580                         printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
1581                         break;
1582
1583                 case PI_HALT_ID_K_SW_FAULT:
1584                         printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
1585                         break;
1586
1587                 case PI_HALT_ID_K_HW_FAULT:
1588                         printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
1589                         break;
1590
1591                 case PI_HALT_ID_K_PC_TRACE:
1592                         printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
1593                         break;
1594
1595                 case PI_HALT_ID_K_DMA_ERROR:
1596                         printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
1597                         break;
1598
1599                 case PI_HALT_ID_K_IMAGE_CRC_ERROR:
1600                         printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
1601                         break;
1602
1603                 case PI_HALT_ID_K_BUS_EXCEPTION:
1604                         printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
1605                         break;
1606
1607                 default:
1608                         printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
1609                         break;
1610                 }
1611         }
1612
1613
1614 /*
1615  * ==========================
1616  * = dfx_int_type_0_process =
1617  * ==========================
1618  *
1619  * Overview:
1620  *   Processes Type 0 interrupts.
1621  *
1622  * Returns:
1623  *   None
1624  *
1625  * Arguments:
1626  *   bp - pointer to board information
1627  *
1628  * Functional Description:
1629  *   Processes all enabled Type 0 interrupts.  If the reason for the interrupt
1630  *   is a serious fault on the adapter, then an error message is displayed
1631  *   and the adapter is reset.
1632  *
1633  *   One tricky potential timing window is the rapid succession of "link avail"
1634  *   "link unavail" state change interrupts.  The acknowledgement of the Type 0
1635  *   interrupt must be done before reading the state from the Port Status
1636  *   register.  This is true because a state change could occur after reading
1637  *   the data, but before acknowledging the interrupt.  If this state change
1638  *   does happen, it would be lost because the driver is using the old state,
1639  *   and it will never know about the new state because it subsequently
1640  *   acknowledges the state change interrupt.
1641  *
1642  *          INCORRECT                                      CORRECT
1643  *      read type 0 int reasons                   read type 0 int reasons
1644  *      read adapter state                        ack type 0 interrupts
1645  *      ack type 0 interrupts                     read adapter state
1646  *      ... process interrupt ...                 ... process interrupt ...
1647  *
1648  * Return Codes:
1649  *   None
1650  *
1651  * Assumptions:
1652  *   None
1653  *
1654  * Side Effects:
1655  *   An adapter reset may occur if the adapter has any Type 0 error interrupts
1656  *   or if the port status indicates that the adapter is halted.  The driver
1657  *   is responsible for reinitializing the adapter with the current CAM
1658  *   contents and adapter filter settings.
1659  */
1660
1661 static void dfx_int_type_0_process(DFX_board_t  *bp)
1662
1663         {
1664         PI_UINT32       type_0_status;          /* Host Interrupt Type 0 register */
1665         PI_UINT32       state;                          /* current adap state (from port status) */
1666
1667         /*
1668          * Read host interrupt Type 0 register to determine which Type 0
1669          * interrupts are pending.  Immediately write it back out to clear
1670          * those interrupts.
1671          */
1672
1673         dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
1674         dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
1675
1676         /* Check for Type 0 error interrupts */
1677
1678         if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
1679                                                         PI_TYPE_0_STAT_M_PM_PAR_ERR |
1680                                                         PI_TYPE_0_STAT_M_BUS_PAR_ERR))
1681                 {
1682                 /* Check for Non-Existent Memory error */
1683
1684                 if (type_0_status & PI_TYPE_0_STAT_M_NXM)
1685                         printk("%s: Non-Existent Memory Access Error\n", bp->dev->name);
1686
1687                 /* Check for Packet Memory Parity error */
1688
1689                 if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
1690                         printk("%s: Packet Memory Parity Error\n", bp->dev->name);
1691
1692                 /* Check for Host Bus Parity error */
1693
1694                 if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
1695                         printk("%s: Host Bus Parity Error\n", bp->dev->name);
1696
1697                 /* Reset adapter and bring it back on-line */
1698
1699                 bp->link_available = PI_K_FALSE;        /* link is no longer available */
1700                 bp->reset_type = 0;                                     /* rerun on-board diagnostics */
1701                 printk("%s: Resetting adapter...\n", bp->dev->name);
1702                 if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
1703                         {
1704                         printk("%s: Adapter reset failed!  Disabling adapter interrupts.\n", bp->dev->name);
1705                         dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1706                         return;
1707                         }
1708                 printk("%s: Adapter reset successful!\n", bp->dev->name);
1709                 return;
1710                 }
1711
1712         /* Check for transmit flush interrupt */
1713
1714         if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
1715                 {
1716                 /* Flush any pending xmt's and acknowledge the flush interrupt */
1717
1718                 bp->link_available = PI_K_FALSE;                /* link is no longer available */
1719                 dfx_xmt_flush(bp);                                              /* flush any outstanding packets */
1720                 (void) dfx_hw_port_ctrl_req(bp,
1721                                                                         PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
1722                                                                         0,
1723                                                                         0,
1724                                                                         NULL);
1725                 }
1726
1727         /* Check for adapter state change */
1728
1729         if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
1730                 {
1731                 /* Get latest adapter state */
1732
1733                 state = dfx_hw_adap_state_rd(bp);       /* get adapter state */
1734                 if (state == PI_STATE_K_HALTED)
1735                         {
1736                         /*
1737                          * Adapter has transitioned to HALTED state, try to reset
1738                          * adapter to bring it back on-line.  If reset fails,
1739                          * leave the adapter in the broken state.
1740                          */
1741
1742                         printk("%s: Controller has transitioned to HALTED state!\n", bp->dev->name);
1743                         dfx_int_pr_halt_id(bp);                 /* display halt id as string */
1744
1745                         /* Reset adapter and bring it back on-line */
1746
1747                         bp->link_available = PI_K_FALSE;        /* link is no longer available */
1748                         bp->reset_type = 0;                                     /* rerun on-board diagnostics */
1749                         printk("%s: Resetting adapter...\n", bp->dev->name);
1750                         if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
1751                                 {
1752                                 printk("%s: Adapter reset failed!  Disabling adapter interrupts.\n", bp->dev->name);
1753                                 dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1754                                 return;
1755                                 }
1756                         printk("%s: Adapter reset successful!\n", bp->dev->name);
1757                         }
1758                 else if (state == PI_STATE_K_LINK_AVAIL)
1759                         {
1760                         bp->link_available = PI_K_TRUE;         /* set link available flag */
1761                         }
1762                 }
1763         }
1764
1765
1766 /*
1767  * ==================
1768  * = dfx_int_common =
1769  * ==================
1770  *
1771  * Overview:
1772  *   Interrupt service routine (ISR)
1773  *
1774  * Returns:
1775  *   None
1776  *
1777  * Arguments:
1778  *   bp - pointer to board information
1779  *
1780  * Functional Description:
1781  *   This is the ISR which processes incoming adapter interrupts.
1782  *
1783  * Return Codes:
1784  *   None
1785  *
1786  * Assumptions:
1787  *   This routine assumes PDQ interrupts have not been disabled.
1788  *   When interrupts are disabled at the PDQ, the Port Status register
1789  *   is automatically cleared.  This routine uses the Port Status
1790  *   register value to determine whether a Type 0 interrupt occurred,
1791  *   so it's important that adapter interrupts are not normally
1792  *   enabled/disabled at the PDQ.
1793  *
1794  *   It's vital that this routine is NOT reentered for the
1795  *   same board and that the OS is not in another section of
1796  *   code (eg. dfx_xmt_queue_pkt) for the same board on a
1797  *   different thread.
1798  *
1799  * Side Effects:
1800  *   Pending interrupts are serviced.  Depending on the type of
1801  *   interrupt, acknowledging and clearing the interrupt at the
1802  *   PDQ involves writing a register to clear the interrupt bit
1803  *   or updating completion indices.
1804  */
1805
1806 static void dfx_int_common(struct net_device *dev)
1807 {
1808         DFX_board_t *bp = netdev_priv(dev);
1809         PI_UINT32       port_status;            /* Port Status register */
1810
1811         /* Process xmt interrupts - frequent case, so always call this routine */
1812
1813         if(dfx_xmt_done(bp))                            /* free consumed xmt packets */
1814                 netif_wake_queue(dev);
1815
1816         /* Process rcv interrupts - frequent case, so always call this routine */
1817
1818         dfx_rcv_queue_process(bp);              /* service received LLC frames */
1819
1820         /*
1821          * Transmit and receive producer and completion indices are updated on the
1822          * adapter by writing to the Type 2 Producer register.  Since the frequent
1823          * case is that we'll be processing either LLC transmit or receive buffers,
1824          * we'll optimize I/O writes by doing a single register write here.
1825          */
1826
1827         dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
1828
1829         /* Read PDQ Port Status register to find out which interrupts need processing */
1830
1831         dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
1832
1833         /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
1834
1835         if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
1836                 dfx_int_type_0_process(bp);     /* process Type 0 interrupts */
1837         }
1838
1839
1840 /*
1841  * =================
1842  * = dfx_interrupt =
1843  * =================
1844  *
1845  * Overview:
1846  *   Interrupt processing routine
1847  *
1848  * Returns:
1849  *   Whether a valid interrupt was seen.
1850  *
1851  * Arguments:
1852  *   irq        - interrupt vector
1853  *   dev_id     - pointer to device information
1854  *
1855  * Functional Description:
1856  *   This routine calls the interrupt processing routine for this adapter.  It
1857  *   disables and reenables adapter interrupts, as appropriate.  We can support
1858  *   shared interrupts since the incoming dev_id pointer provides our device
1859  *   structure context.
1860  *
1861  * Return Codes:
1862  *   IRQ_HANDLED - an IRQ was handled.
1863  *   IRQ_NONE    - no IRQ was handled.
1864  *
1865  * Assumptions:
1866  *   The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
1867  *   on Intel-based systems) is done by the operating system outside this
1868  *   routine.
1869  *
1870  *       System interrupts are enabled through this call.
1871  *
1872  * Side Effects:
1873  *   Interrupts are disabled, then reenabled at the adapter.
1874  */
1875
1876 static irqreturn_t dfx_interrupt(int irq, void *dev_id)
1877 {
1878         struct net_device *dev = dev_id;
1879         DFX_board_t *bp = netdev_priv(dev);
1880         struct device *bdev = bp->bus_dev;
1881         int dfx_bus_pci = DFX_BUS_PCI(bdev);
1882         int dfx_bus_eisa = DFX_BUS_EISA(bdev);
1883         int dfx_bus_tc = DFX_BUS_TC(bdev);
1884
1885         /* Service adapter interrupts */
1886
1887         if (dfx_bus_pci) {
1888                 u32 status;
1889
1890                 dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
1891                 if (!(status & PFI_STATUS_M_PDQ_INT))
1892                         return IRQ_NONE;
1893
1894                 spin_lock(&bp->lock);
1895
1896                 /* Disable PDQ-PFI interrupts at PFI */
1897                 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1898                                     PFI_MODE_M_DMA_ENB);
1899
1900                 /* Call interrupt service routine for this adapter */
1901                 dfx_int_common(dev);
1902
1903                 /* Clear PDQ interrupt status bit and reenable interrupts */
1904                 dfx_port_write_long(bp, PFI_K_REG_STATUS,
1905                                     PFI_STATUS_M_PDQ_INT);
1906                 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1907                                     (PFI_MODE_M_PDQ_INT_ENB |
1908                                      PFI_MODE_M_DMA_ENB));
1909
1910                 spin_unlock(&bp->lock);
1911         }
1912         if (dfx_bus_eisa) {
1913                 unsigned long base_addr = to_eisa_device(bdev)->base_addr;
1914                 u8 status;
1915
1916                 status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
1917                 if (!(status & PI_CONFIG_STAT_0_M_PEND))
1918                         return IRQ_NONE;
1919
1920                 spin_lock(&bp->lock);
1921
1922                 /* Disable interrupts at the ESIC */
1923                 status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
1924                 outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, status);
1925
1926                 /* Call interrupt service routine for this adapter */
1927                 dfx_int_common(dev);
1928
1929                 /* Reenable interrupts at the ESIC */
1930                 status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
1931                 status |= PI_CONFIG_STAT_0_M_INT_ENB;
1932                 outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, status);
1933
1934                 spin_unlock(&bp->lock);
1935         }
1936         if (dfx_bus_tc) {
1937                 u32 status;
1938
1939                 dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &status);
1940                 if (!(status & (PI_PSTATUS_M_RCV_DATA_PENDING |
1941                                 PI_PSTATUS_M_XMT_DATA_PENDING |
1942                                 PI_PSTATUS_M_SMT_HOST_PENDING |
1943                                 PI_PSTATUS_M_UNSOL_PENDING |
1944                                 PI_PSTATUS_M_CMD_RSP_PENDING |
1945                                 PI_PSTATUS_M_CMD_REQ_PENDING |
1946                                 PI_PSTATUS_M_TYPE_0_PENDING)))
1947                         return IRQ_NONE;
1948
1949                 spin_lock(&bp->lock);
1950
1951                 /* Call interrupt service routine for this adapter */
1952                 dfx_int_common(dev);
1953
1954                 spin_unlock(&bp->lock);
1955         }
1956
1957         return IRQ_HANDLED;
1958 }
1959
1960
1961 /*
1962  * =====================
1963  * = dfx_ctl_get_stats =
1964  * =====================
1965  *
1966  * Overview:
1967  *   Get statistics for FDDI adapter
1968  *
1969  * Returns:
1970  *   Pointer to FDDI statistics structure
1971  *
1972  * Arguments:
1973  *   dev - pointer to device information
1974  *
1975  * Functional Description:
1976  *   Gets current MIB objects from adapter, then
1977  *   returns FDDI statistics structure as defined
1978  *   in if_fddi.h.
1979  *
1980  *   Note: Since the FDDI statistics structure is
1981  *   still new and the device structure doesn't
1982  *   have an FDDI-specific get statistics handler,
1983  *   we'll return the FDDI statistics structure as
1984  *   a pointer to an Ethernet statistics structure.
1985  *   That way, at least the first part of the statistics
1986  *   structure can be decoded properly, and it allows
1987  *   "smart" applications to perform a second cast to
1988  *   decode the FDDI-specific statistics.
1989  *
1990  *   We'll have to pay attention to this routine as the
1991  *   device structure becomes more mature and LAN media
1992  *   independent.
1993  *
1994  * Return Codes:
1995  *   None
1996  *
1997  * Assumptions:
1998  *   None
1999  *
2000  * Side Effects:
2001  *   None
2002  */
2003
2004 static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
2005         {
2006         DFX_board_t *bp = netdev_priv(dev);
2007
2008         /* Fill the bp->stats structure with driver-maintained counters */
2009
2010         bp->stats.gen.rx_packets = bp->rcv_total_frames;
2011         bp->stats.gen.tx_packets = bp->xmt_total_frames;
2012         bp->stats.gen.rx_bytes   = bp->rcv_total_bytes;
2013         bp->stats.gen.tx_bytes   = bp->xmt_total_bytes;
2014         bp->stats.gen.rx_errors  = bp->rcv_crc_errors +
2015                                    bp->rcv_frame_status_errors +
2016                                    bp->rcv_length_errors;
2017         bp->stats.gen.tx_errors  = bp->xmt_length_errors;
2018         bp->stats.gen.rx_dropped = bp->rcv_discards;
2019         bp->stats.gen.tx_dropped = bp->xmt_discards;
2020         bp->stats.gen.multicast  = bp->rcv_multicast_frames;
2021         bp->stats.gen.collisions = 0;           /* always zero (0) for FDDI */
2022
2023         /* Get FDDI SMT MIB objects */
2024
2025         bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
2026         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2027                 return (struct net_device_stats *)&bp->stats;
2028
2029         /* Fill the bp->stats structure with the SMT MIB object values */
2030
2031         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));
2032         bp->stats.smt_op_version_id                                     = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
2033         bp->stats.smt_hi_version_id                                     = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
2034         bp->stats.smt_lo_version_id                                     = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
2035         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));
2036         bp->stats.smt_mib_version_id                            = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
2037         bp->stats.smt_mac_cts                                           = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
2038         bp->stats.smt_non_master_cts                            = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
2039         bp->stats.smt_master_cts                                        = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
2040         bp->stats.smt_available_paths                           = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
2041         bp->stats.smt_config_capabilities                       = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
2042         bp->stats.smt_config_policy                                     = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
2043         bp->stats.smt_connection_policy                         = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
2044         bp->stats.smt_t_notify                                          = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
2045         bp->stats.smt_stat_rpt_policy                           = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
2046         bp->stats.smt_trace_max_expiration                      = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
2047         bp->stats.smt_bypass_present                            = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
2048         bp->stats.smt_ecm_state                                         = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
2049         bp->stats.smt_cf_state                                          = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
2050         bp->stats.smt_remote_disconnect_flag            = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
2051         bp->stats.smt_station_status                            = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
2052         bp->stats.smt_peer_wrap_flag                            = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
2053         bp->stats.smt_time_stamp                                        = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
2054         bp->stats.smt_transition_time_stamp                     = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
2055         bp->stats.mac_frame_status_functions            = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
2056         bp->stats.mac_t_max_capability                          = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
2057         bp->stats.mac_tvx_capability                            = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
2058         bp->stats.mac_available_paths                           = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
2059         bp->stats.mac_current_path                                      = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
2060         memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
2061         memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
2062         memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
2063         memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
2064         bp->stats.mac_dup_address_test                          = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
2065         bp->stats.mac_requested_paths                           = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
2066         bp->stats.mac_downstream_port_type                      = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
2067         memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
2068         bp->stats.mac_t_req                                                     = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
2069         bp->stats.mac_t_neg                                                     = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
2070         bp->stats.mac_t_max                                                     = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
2071         bp->stats.mac_tvx_value                                         = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
2072         bp->stats.mac_frame_error_threshold                     = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
2073         bp->stats.mac_frame_error_ratio                         = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
2074         bp->stats.mac_rmt_state                                         = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
2075         bp->stats.mac_da_flag                                           = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
2076         bp->stats.mac_una_da_flag                                       = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
2077         bp->stats.mac_frame_error_flag                          = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
2078         bp->stats.mac_ma_unitdata_available                     = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
2079         bp->stats.mac_hardware_present                          = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
2080         bp->stats.mac_ma_unitdata_enable                        = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
2081         bp->stats.path_tvx_lower_bound                          = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
2082         bp->stats.path_t_max_lower_bound                        = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
2083         bp->stats.path_max_t_req                                        = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
2084         memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
2085         bp->stats.port_my_type[0]                                       = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
2086         bp->stats.port_my_type[1]                                       = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
2087         bp->stats.port_neighbor_type[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
2088         bp->stats.port_neighbor_type[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
2089         bp->stats.port_connection_policies[0]           = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
2090         bp->stats.port_connection_policies[1]           = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
2091         bp->stats.port_mac_indicated[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
2092         bp->stats.port_mac_indicated[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
2093         bp->stats.port_current_path[0]                          = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
2094         bp->stats.port_current_path[1]                          = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
2095         memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
2096         memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
2097         bp->stats.port_mac_placement[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
2098         bp->stats.port_mac_placement[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
2099         bp->stats.port_available_paths[0]                       = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
2100         bp->stats.port_available_paths[1]                       = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
2101         bp->stats.port_pmd_class[0]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
2102         bp->stats.port_pmd_class[1]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
2103         bp->stats.port_connection_capabilities[0]       = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
2104         bp->stats.port_connection_capabilities[1]       = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
2105         bp->stats.port_bs_flag[0]                                       = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
2106         bp->stats.port_bs_flag[1]                                       = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
2107         bp->stats.port_ler_estimate[0]                          = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
2108         bp->stats.port_ler_estimate[1]                          = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
2109         bp->stats.port_ler_cutoff[0]                            = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
2110         bp->stats.port_ler_cutoff[1]                            = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
2111         bp->stats.port_ler_alarm[0]                                     = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
2112         bp->stats.port_ler_alarm[1]                                     = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
2113         bp->stats.port_connect_state[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
2114         bp->stats.port_connect_state[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
2115         bp->stats.port_pcm_state[0]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
2116         bp->stats.port_pcm_state[1]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
2117         bp->stats.port_pc_withhold[0]                           = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
2118         bp->stats.port_pc_withhold[1]                           = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
2119         bp->stats.port_ler_flag[0]                                      = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
2120         bp->stats.port_ler_flag[1]                                      = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
2121         bp->stats.port_hardware_present[0]                      = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
2122         bp->stats.port_hardware_present[1]                      = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
2123
2124         /* Get FDDI counters */
2125
2126         bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
2127         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2128                 return (struct net_device_stats *)&bp->stats;
2129
2130         /* Fill the bp->stats structure with the FDDI counter values */
2131
2132         bp->stats.mac_frame_cts                         = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
2133         bp->stats.mac_copied_cts                        = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
2134         bp->stats.mac_transmit_cts                      = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
2135         bp->stats.mac_error_cts                         = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
2136         bp->stats.mac_lost_cts                          = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
2137         bp->stats.port_lct_fail_cts[0]          = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
2138         bp->stats.port_lct_fail_cts[1]          = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
2139         bp->stats.port_lem_reject_cts[0]        = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
2140         bp->stats.port_lem_reject_cts[1]        = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
2141         bp->stats.port_lem_cts[0]                       = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
2142         bp->stats.port_lem_cts[1]                       = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
2143
2144         return (struct net_device_stats *)&bp->stats;
2145         }
2146
2147
2148 /*
2149  * ==============================
2150  * = dfx_ctl_set_multicast_list =
2151  * ==============================
2152  *
2153  * Overview:
2154  *   Enable/Disable LLC frame promiscuous mode reception
2155  *   on the adapter and/or update multicast address table.
2156  *
2157  * Returns:
2158  *   None
2159  *
2160  * Arguments:
2161  *   dev - pointer to device information
2162  *
2163  * Functional Description:
2164  *   This routine follows a fairly simple algorithm for setting the
2165  *   adapter filters and CAM:
2166  *
2167  *              if IFF_PROMISC flag is set
2168  *                      enable LLC individual/group promiscuous mode
2169  *              else
2170  *                      disable LLC individual/group promiscuous mode
2171  *                      if number of incoming multicast addresses >
2172  *                                      (CAM max size - number of unicast addresses in CAM)
2173  *                              enable LLC group promiscuous mode
2174  *                              set driver-maintained multicast address count to zero
2175  *                      else
2176  *                              disable LLC group promiscuous mode
2177  *                              set driver-maintained multicast address count to incoming count
2178  *                      update adapter CAM
2179  *              update adapter filters
2180  *
2181  * Return Codes:
2182  *   None
2183  *
2184  * Assumptions:
2185  *   Multicast addresses are presented in canonical (LSB) format.
2186  *
2187  * Side Effects:
2188  *   On-board adapter CAM and filters are updated.
2189  */
2190
2191 static void dfx_ctl_set_multicast_list(struct net_device *dev)
2192 {
2193         DFX_board_t *bp = netdev_priv(dev);
2194         int                                     i;                      /* used as index in for loop */
2195         struct netdev_hw_addr *ha;
2196
2197         /* Enable LLC frame promiscuous mode, if necessary */
2198
2199         if (dev->flags & IFF_PROMISC)
2200                 bp->ind_group_prom = PI_FSTATE_K_PASS;          /* Enable LLC ind/group prom mode */
2201
2202         /* Else, update multicast address table */
2203
2204         else
2205                 {
2206                 bp->ind_group_prom = PI_FSTATE_K_BLOCK;         /* Disable LLC ind/group prom mode */
2207                 /*
2208                  * Check whether incoming multicast address count exceeds table size
2209                  *
2210                  * Note: The adapters utilize an on-board 64 entry CAM for
2211                  *       supporting perfect filtering of multicast packets
2212                  *               and bridge functions when adding unicast addresses.
2213                  *               There is no hash function available.  To support
2214                  *               additional multicast addresses, the all multicast
2215                  *               filter (LLC group promiscuous mode) must be enabled.
2216                  *
2217                  *               The firmware reserves two CAM entries for SMT-related
2218                  *               multicast addresses, which leaves 62 entries available.
2219                  *               The following code ensures that we're not being asked
2220                  *               to add more than 62 addresses to the CAM.  If we are,
2221                  *               the driver will enable the all multicast filter.
2222                  *               Should the number of multicast addresses drop below
2223                  *               the high water mark, the filter will be disabled and
2224                  *               perfect filtering will be used.
2225                  */
2226
2227                 if (netdev_mc_count(dev) > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
2228                         {
2229                         bp->group_prom  = PI_FSTATE_K_PASS;             /* Enable LLC group prom mode */
2230                         bp->mc_count    = 0;                                    /* Don't add mc addrs to CAM */
2231                         }
2232                 else
2233                         {
2234                         bp->group_prom  = PI_FSTATE_K_BLOCK;    /* Disable LLC group prom mode */
2235                         bp->mc_count    = netdev_mc_count(dev);         /* Add mc addrs to CAM */
2236                         }
2237
2238                 /* Copy addresses to multicast address table, then update adapter CAM */
2239
2240                 i = 0;
2241                 netdev_for_each_mc_addr(ha, dev)
2242                         memcpy(&bp->mc_table[i++ * FDDI_K_ALEN],
2243                                ha->addr, FDDI_K_ALEN);
2244
2245                 if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
2246                         {
2247                         DBG_printk("%s: Could not update multicast address table!\n", dev->name);
2248                         }
2249                 else
2250                         {
2251                         DBG_printk("%s: Multicast address table updated!  Added %d addresses.\n", dev->name, bp->mc_count);
2252                         }
2253                 }
2254
2255         /* Update adapter filters */
2256
2257         if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
2258                 {
2259                 DBG_printk("%s: Could not update adapter filters!\n", dev->name);
2260                 }
2261         else
2262                 {
2263                 DBG_printk("%s: Adapter filters updated!\n", dev->name);
2264                 }
2265         }
2266
2267
2268 /*
2269  * ===========================
2270  * = dfx_ctl_set_mac_address =
2271  * ===========================
2272  *
2273  * Overview:
2274  *   Add node address override (unicast address) to adapter
2275  *   CAM and update dev_addr field in device table.
2276  *
2277  * Returns:
2278  *   None
2279  *
2280  * Arguments:
2281  *   dev  - pointer to device information
2282  *   addr - pointer to sockaddr structure containing unicast address to add
2283  *
2284  * Functional Description:
2285  *   The adapter supports node address overrides by adding one or more
2286  *   unicast addresses to the adapter CAM.  This is similar to adding
2287  *   multicast addresses.  In this routine we'll update the driver and
2288  *   device structures with the new address, then update the adapter CAM
2289  *   to ensure that the adapter will copy and strip frames destined and
2290  *   sourced by that address.
2291  *
2292  * Return Codes:
2293  *   Always returns zero.
2294  *
2295  * Assumptions:
2296  *   The address pointed to by addr->sa_data is a valid unicast
2297  *   address and is presented in canonical (LSB) format.
2298  *
2299  * Side Effects:
2300  *   On-board adapter CAM is updated.  On-board adapter filters
2301  *   may be updated.
2302  */
2303
2304 static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
2305         {
2306         struct sockaddr *p_sockaddr = (struct sockaddr *)addr;
2307         DFX_board_t *bp = netdev_priv(dev);
2308
2309         /* Copy unicast address to driver-maintained structs and update count */
2310
2311         memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);        /* update device struct */
2312         memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN);     /* update driver struct */
2313         bp->uc_count = 1;
2314
2315         /*
2316          * Verify we're not exceeding the CAM size by adding unicast address
2317          *
2318          * Note: It's possible that before entering this routine we've
2319          *       already filled the CAM with 62 multicast addresses.
2320          *               Since we need to place the node address override into
2321          *               the CAM, we have to check to see that we're not
2322          *               exceeding the CAM size.  If we are, we have to enable
2323          *               the LLC group (multicast) promiscuous mode filter as
2324          *               in dfx_ctl_set_multicast_list.
2325          */
2326
2327         if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
2328                 {
2329                 bp->group_prom  = PI_FSTATE_K_PASS;             /* Enable LLC group prom mode */
2330                 bp->mc_count    = 0;                                    /* Don't add mc addrs to CAM */
2331
2332                 /* Update adapter filters */
2333
2334                 if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
2335                         {
2336                         DBG_printk("%s: Could not update adapter filters!\n", dev->name);
2337                         }
2338                 else
2339                         {
2340                         DBG_printk("%s: Adapter filters updated!\n", dev->name);
2341                         }
2342                 }
2343
2344         /* Update adapter CAM with new unicast address */
2345
2346         if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
2347                 {
2348                 DBG_printk("%s: Could not set new MAC address!\n", dev->name);
2349                 }
2350         else
2351                 {
2352                 DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev->name);
2353                 }
2354         return 0;                       /* always return zero */
2355         }
2356
2357
2358 /*
2359  * ======================
2360  * = dfx_ctl_update_cam =
2361  * ======================
2362  *
2363  * Overview:
2364  *   Procedure to update adapter CAM (Content Addressable Memory)
2365  *   with desired unicast and multicast address entries.
2366  *
2367  * Returns:
2368  *   Condition code
2369  *
2370  * Arguments:
2371  *   bp - pointer to board information
2372  *
2373  * Functional Description:
2374  *   Updates adapter CAM with current contents of board structure
2375  *   unicast and multicast address tables.  Since there are only 62
2376  *   free entries in CAM, this routine ensures that the command
2377  *   request buffer is not overrun.
2378  *
2379  * Return Codes:
2380  *   DFX_K_SUCCESS - Request succeeded
2381  *   DFX_K_FAILURE - Request failed
2382  *
2383  * Assumptions:
2384  *   All addresses being added (unicast and multicast) are in canonical
2385  *   order.
2386  *
2387  * Side Effects:
2388  *   On-board adapter CAM is updated.
2389  */
2390
2391 static int dfx_ctl_update_cam(DFX_board_t *bp)
2392         {
2393         int                     i;                              /* used as index */
2394         PI_LAN_ADDR     *p_addr;                /* pointer to CAM entry */
2395
2396         /*
2397          * Fill in command request information
2398          *
2399          * Note: Even though both the unicast and multicast address
2400          *       table entries are stored as contiguous 6 byte entries,
2401          *               the firmware address filter set command expects each
2402          *               entry to be two longwords (8 bytes total).  We must be
2403          *               careful to only copy the six bytes of each unicast and
2404          *               multicast table entry into each command entry.  This
2405          *               is also why we must first clear the entire command
2406          *               request buffer.
2407          */
2408
2409         memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX);     /* first clear buffer */
2410         bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
2411         p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
2412
2413         /* Now add unicast addresses to command request buffer, if any */
2414
2415         for (i=0; i < (int)bp->uc_count; i++)
2416                 {
2417                 if (i < PI_CMD_ADDR_FILTER_K_SIZE)
2418                         {
2419                         memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
2420                         p_addr++;                       /* point to next command entry */
2421                         }
2422                 }
2423
2424         /* Now add multicast addresses to command request buffer, if any */
2425
2426         for (i=0; i < (int)bp->mc_count; i++)
2427                 {
2428                 if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
2429                         {
2430                         memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
2431                         p_addr++;                       /* point to next command entry */
2432                         }
2433                 }
2434
2435         /* Issue command to update adapter CAM, then return */
2436
2437         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2438                 return DFX_K_FAILURE;
2439         return DFX_K_SUCCESS;
2440         }
2441
2442
2443 /*
2444  * ==========================
2445  * = dfx_ctl_update_filters =
2446  * ==========================
2447  *
2448  * Overview:
2449  *   Procedure to update adapter filters with desired
2450  *   filter settings.
2451  *
2452  * Returns:
2453  *   Condition code
2454  *
2455  * Arguments:
2456  *   bp - pointer to board information
2457  *
2458  * Functional Description:
2459  *   Enables or disables filter using current filter settings.
2460  *
2461  * Return Codes:
2462  *   DFX_K_SUCCESS - Request succeeded.
2463  *   DFX_K_FAILURE - Request failed.
2464  *
2465  * Assumptions:
2466  *   We must always pass up packets destined to the broadcast
2467  *   address (FF-FF-FF-FF-FF-FF), so we'll always keep the
2468  *   broadcast filter enabled.
2469  *
2470  * Side Effects:
2471  *   On-board adapter filters are updated.
2472  */
2473
2474 static int dfx_ctl_update_filters(DFX_board_t *bp)
2475         {
2476         int     i = 0;                                  /* used as index */
2477
2478         /* Fill in command request information */
2479
2480         bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
2481
2482         /* Initialize Broadcast filter - * ALWAYS ENABLED * */
2483
2484         bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_BROADCAST;
2485         bp->cmd_req_virt->filter_set.item[i++].value    = PI_FSTATE_K_PASS;
2486
2487         /* Initialize LLC Individual/Group Promiscuous filter */
2488
2489         bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_IND_GROUP_PROM;
2490         bp->cmd_req_virt->filter_set.item[i++].value    = bp->ind_group_prom;
2491
2492         /* Initialize LLC Group Promiscuous filter */
2493
2494         bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_GROUP_PROM;
2495         bp->cmd_req_virt->filter_set.item[i++].value    = bp->group_prom;
2496
2497         /* Terminate the item code list */
2498
2499         bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_EOL;
2500
2501         /* Issue command to update adapter filters, then return */
2502
2503         if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2504                 return DFX_K_FAILURE;
2505         return DFX_K_SUCCESS;
2506         }
2507
2508
2509 /*
2510  * ======================
2511  * = dfx_hw_dma_cmd_req =
2512  * ======================
2513  *
2514  * Overview:
2515  *   Sends PDQ DMA command to adapter firmware
2516  *
2517  * Returns:
2518  *   Condition code
2519  *
2520  * Arguments:
2521  *   bp - pointer to board information
2522  *
2523  * Functional Description:
2524  *   The command request and response buffers are posted to the adapter in the manner
2525  *   described in the PDQ Port Specification:
2526  *
2527  *              1. Command Response Buffer is posted to adapter.
2528  *              2. Command Request Buffer is posted to adapter.
2529  *              3. Command Request consumer index is polled until it indicates that request
2530  *         buffer has been DMA'd to adapter.
2531  *              4. Command Response consumer index is polled until it indicates that response
2532  *         buffer has been DMA'd from adapter.
2533  *
2534  *   This ordering ensures that a response buffer is already available for the firmware
2535  *   to use once it's done processing the request buffer.
2536  *
2537  * Return Codes:
2538  *   DFX_K_SUCCESS        - DMA command succeeded
2539  *       DFX_K_OUTSTATE   - Adapter is NOT in proper state
2540  *   DFX_K_HW_TIMEOUT - DMA command timed out
2541  *
2542  * Assumptions:
2543  *   Command request buffer has already been filled with desired DMA command.
2544  *
2545  * Side Effects:
2546  *   None
2547  */
2548
2549 static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
2550         {
2551         int status;                     /* adapter status */
2552         int timeout_cnt;        /* used in for loops */
2553
2554         /* Make sure the adapter is in a state that we can issue the DMA command in */
2555
2556         status = dfx_hw_adap_state_rd(bp);
2557         if ((status == PI_STATE_K_RESET)                ||
2558                 (status == PI_STATE_K_HALTED)           ||
2559                 (status == PI_STATE_K_DMA_UNAVAIL)      ||
2560                 (status == PI_STATE_K_UPGRADE))
2561                 return DFX_K_OUTSTATE;
2562
2563         /* Put response buffer on the command response queue */
2564
2565         bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2566                         ((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2567         bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
2568
2569         /* Bump (and wrap) the producer index and write out to register */
2570
2571         bp->cmd_rsp_reg.index.prod += 1;
2572         bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
2573         dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
2574
2575         /* Put request buffer on the command request queue */
2576
2577         bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
2578                         PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
2579         bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
2580
2581         /* Bump (and wrap) the producer index and write out to register */
2582
2583         bp->cmd_req_reg.index.prod += 1;
2584         bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
2585         dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
2586
2587         /*
2588          * Here we wait for the command request consumer index to be equal
2589          * to the producer, indicating that the adapter has DMAed the request.
2590          */
2591
2592         for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
2593                 {
2594                 if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
2595                         break;
2596                 udelay(100);                    /* wait for 100 microseconds */
2597                 }
2598         if (timeout_cnt == 0)
2599                 return DFX_K_HW_TIMEOUT;
2600
2601         /* Bump (and wrap) the completion index and write out to register */
2602
2603         bp->cmd_req_reg.index.comp += 1;
2604         bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
2605         dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
2606
2607         /*
2608          * Here we wait for the command response consumer index to be equal
2609          * to the producer, indicating that the adapter has DMAed the response.
2610          */
2611
2612         for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
2613                 {
2614                 if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
2615                         break;
2616                 udelay(100);                    /* wait for 100 microseconds */
2617                 }
2618         if (timeout_cnt == 0)
2619                 return DFX_K_HW_TIMEOUT;
2620
2621         /* Bump (and wrap) the completion index and write out to register */
2622
2623         bp->cmd_rsp_reg.index.comp += 1;
2624         bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
2625         dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
2626         return DFX_K_SUCCESS;
2627         }
2628
2629
2630 /*
2631  * ========================
2632  * = dfx_hw_port_ctrl_req =
2633  * ========================
2634  *
2635  * Overview:
2636  *   Sends PDQ port control command to adapter firmware
2637  *
2638  * Returns:
2639  *   Host data register value in host_data if ptr is not NULL
2640  *
2641  * Arguments:
2642  *   bp                 - pointer to board information
2643  *       command        - port control command
2644  *       data_a         - port data A register value
2645  *       data_b         - port data B register value
2646  *       host_data      - ptr to host data register value
2647  *
2648  * Functional Description:
2649  *   Send generic port control command to adapter by writing
2650  *   to various PDQ port registers, then polling for completion.
2651  *
2652  * Return Codes:
2653  *   DFX_K_SUCCESS        - port control command succeeded
2654  *   DFX_K_HW_TIMEOUT - port control command timed out
2655  *
2656  * Assumptions:
2657  *   None
2658  *
2659  * Side Effects:
2660  *   None
2661  */
2662
2663 static int dfx_hw_port_ctrl_req(
2664         DFX_board_t     *bp,
2665         PI_UINT32       command,
2666         PI_UINT32       data_a,
2667         PI_UINT32       data_b,
2668         PI_UINT32       *host_data
2669         )
2670
2671         {
2672         PI_UINT32       port_cmd;               /* Port Control command register value */
2673         int                     timeout_cnt;    /* used in for loops */
2674
2675         /* Set Command Error bit in command longword */
2676
2677         port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
2678
2679         /* Issue port command to the adapter */
2680
2681         dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
2682         dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
2683         dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
2684
2685         /* Now wait for command to complete */
2686
2687         if (command == PI_PCTRL_M_BLAST_FLASH)
2688                 timeout_cnt = 600000;   /* set command timeout count to 60 seconds */
2689         else
2690                 timeout_cnt = 20000;    /* set command timeout count to 2 seconds */
2691
2692         for (; timeout_cnt > 0; timeout_cnt--)
2693                 {
2694                 dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
2695                 if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
2696                         break;
2697                 udelay(100);                    /* wait for 100 microseconds */
2698                 }
2699         if (timeout_cnt == 0)
2700                 return DFX_K_HW_TIMEOUT;
2701
2702         /*
2703          * If the address of host_data is non-zero, assume caller has supplied a
2704          * non NULL pointer, and return the contents of the HOST_DATA register in
2705          * it.
2706          */
2707
2708         if (host_data != NULL)
2709                 dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
2710         return DFX_K_SUCCESS;
2711         }
2712
2713
2714 /*
2715  * =====================
2716  * = dfx_hw_adap_reset =
2717  * =====================
2718  *
2719  * Overview:
2720  *   Resets adapter
2721  *
2722  * Returns:
2723  *   None
2724  *
2725  * Arguments:
2726  *   bp   - pointer to board information
2727  *   type - type of reset to perform
2728  *
2729  * Functional Description:
2730  *   Issue soft reset to adapter by writing to PDQ Port Reset
2731  *   register.  Use incoming reset type to tell adapter what
2732  *   kind of reset operation to perform.
2733  *
2734  * Return Codes:
2735  *   None
2736  *
2737  * Assumptions:
2738  *   This routine merely issues a soft reset to the adapter.
2739  *   It is expected that after this routine returns, the caller
2740  *   will appropriately poll the Port Status register for the
2741  *   adapter to enter the proper state.
2742  *
2743  * Side Effects:
2744  *   Internal adapter registers are cleared.
2745  */
2746
2747 static void dfx_hw_adap_reset(
2748         DFX_board_t     *bp,
2749         PI_UINT32       type
2750         )
2751
2752         {
2753         /* Set Reset type and assert reset */
2754
2755         dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type);        /* tell adapter type of reset */
2756         dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
2757
2758         /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
2759
2760         udelay(20);
2761
2762         /* Deassert reset */
2763
2764         dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
2765         }
2766
2767
2768 /*
2769  * ========================
2770  * = dfx_hw_adap_state_rd =
2771  * ========================
2772  *
2773  * Overview:
2774  *   Returns current adapter state
2775  *
2776  * Returns:
2777  *   Adapter state per PDQ Port Specification
2778  *
2779  * Arguments:
2780  *   bp - pointer to board information
2781  *
2782  * Functional Description:
2783  *   Reads PDQ Port Status register and returns adapter state.
2784  *
2785  * Return Codes:
2786  *   None
2787  *
2788  * Assumptions:
2789  *   None
2790  *
2791  * Side Effects:
2792  *   None
2793  */
2794
2795 static int dfx_hw_adap_state_rd(DFX_board_t *bp)
2796         {
2797         PI_UINT32 port_status;          /* Port Status register value */
2798
2799         dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
2800         return (port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE;
2801         }
2802
2803
2804 /*
2805  * =====================
2806  * = dfx_hw_dma_uninit =
2807  * =====================
2808  *
2809  * Overview:
2810  *   Brings adapter to DMA_UNAVAILABLE state
2811  *
2812  * Returns:
2813  *   Condition code
2814  *
2815  * Arguments:
2816  *   bp   - pointer to board information
2817  *   type - type of reset to perform
2818  *
2819  * Functional Description:
2820  *   Bring adapter to DMA_UNAVAILABLE state by performing the following:
2821  *              1. Set reset type bit in Port Data A Register then reset adapter.
2822  *              2. Check that adapter is in DMA_UNAVAILABLE state.
2823  *
2824  * Return Codes:
2825  *   DFX_K_SUCCESS        - adapter is in DMA_UNAVAILABLE state
2826  *   DFX_K_HW_TIMEOUT - adapter did not reset properly
2827  *
2828  * Assumptions:
2829  *   None
2830  *
2831  * Side Effects:
2832  *   Internal adapter registers are cleared.
2833  */
2834
2835 static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
2836         {
2837         int timeout_cnt;        /* used in for loops */
2838
2839         /* Set reset type bit and reset adapter */
2840
2841         dfx_hw_adap_reset(bp, type);
2842
2843         /* Now wait for adapter to enter DMA_UNAVAILABLE state */
2844
2845         for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
2846                 {
2847                 if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
2848                         break;
2849                 udelay(100);                                    /* wait for 100 microseconds */
2850                 }
2851         if (timeout_cnt == 0)
2852                 return DFX_K_HW_TIMEOUT;
2853         return DFX_K_SUCCESS;
2854         }
2855
2856 /*
2857  *      Align an sk_buff to a boundary power of 2
2858  *
2859  */
2860
2861 static void my_skb_align(struct sk_buff *skb, int n)
2862 {
2863         unsigned long x = (unsigned long)skb->data;
2864         unsigned long v;
2865
2866         v = ALIGN(x, n);        /* Where we want to be */
2867
2868         skb_reserve(skb, v - x);
2869 }
2870
2871
2872 /*
2873  * ================
2874  * = dfx_rcv_init =
2875  * ================
2876  *
2877  * Overview:
2878  *   Produces buffers to adapter LLC Host receive descriptor block
2879  *
2880  * Returns:
2881  *   None
2882  *
2883  * Arguments:
2884  *   bp - pointer to board information
2885  *   get_buffers - non-zero if buffers to be allocated
2886  *
2887  * Functional Description:
2888  *   This routine can be called during dfx_adap_init() or during an adapter
2889  *       reset.  It initializes the descriptor block and produces all allocated
2890  *   LLC Host queue receive buffers.
2891  *
2892  * Return Codes:
2893  *   Return 0 on success or -ENOMEM if buffer allocation failed (when using
2894  *   dynamic buffer allocation). If the buffer allocation failed, the
2895  *   already allocated buffers will not be released and the caller should do
2896  *   this.
2897  *
2898  * Assumptions:
2899  *   The PDQ has been reset and the adapter and driver maintained Type 2
2900  *   register indices are cleared.
2901  *
2902  * Side Effects:
2903  *   Receive buffers are posted to the adapter LLC queue and the adapter
2904  *   is notified.
2905  */
2906
2907 static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
2908         {
2909         int     i, j;                                   /* used in for loop */
2910
2911         /*
2912          *  Since each receive buffer is a single fragment of same length, initialize
2913          *  first longword in each receive descriptor for entire LLC Host descriptor
2914          *  block.  Also initialize second longword in each receive descriptor with
2915          *  physical address of receive buffer.  We'll always allocate receive
2916          *  buffers in powers of 2 so that we can easily fill the 256 entry descriptor
2917          *  block and produce new receive buffers by simply updating the receive
2918          *  producer index.
2919          *
2920          *      Assumptions:
2921          *              To support all shipping versions of PDQ, the receive buffer size
2922          *              must be mod 128 in length and the physical address must be 128 byte
2923          *              aligned.  In other words, bits 0-6 of the length and address must
2924          *              be zero for the following descriptor field entries to be correct on
2925          *              all PDQ-based boards.  We guaranteed both requirements during
2926          *              driver initialization when we allocated memory for the receive buffers.
2927          */
2928
2929         if (get_buffers) {
2930 #ifdef DYNAMIC_BUFFERS
2931         for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
2932                 for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
2933                 {
2934                         struct sk_buff *newskb = __netdev_alloc_skb(bp->dev, NEW_SKB_SIZE, GFP_NOIO);
2935                         if (!newskb)
2936                                 return -ENOMEM;
2937                         bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2938                                 ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2939                         /*
2940                          * align to 128 bytes for compatibility with
2941                          * the old EISA boards.
2942                          */
2943
2944                         my_skb_align(newskb, 128);
2945                         bp->descr_block_virt->rcv_data[i + j].long_1 =
2946                                 (u32)dma_map_single(bp->bus_dev, newskb->data,
2947                                                     NEW_SKB_SIZE,
2948                                                     DMA_FROM_DEVICE);
2949                         /*
2950                          * p_rcv_buff_va is only used inside the
2951                          * kernel so we put the skb pointer here.
2952                          */
2953                         bp->p_rcv_buff_va[i+j] = (char *) newskb;
2954                 }
2955 #else
2956         for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
2957                 for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
2958                         {
2959                         bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2960                                 ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2961                         bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
2962                         bp->p_rcv_buff_va[i+j] = (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
2963                         }
2964 #endif
2965         }
2966
2967         /* Update receive producer and Type 2 register */
2968
2969         bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
2970         dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
2971         return 0;
2972         }
2973
2974
2975 /*
2976  * =========================
2977  * = dfx_rcv_queue_process =
2978  * =========================
2979  *
2980  * Overview:
2981  *   Process received LLC frames.
2982  *
2983  * Returns:
2984  *   None
2985  *
2986  * Arguments:
2987  *   bp - pointer to board information
2988  *
2989  * Functional Description:
2990  *   Received LLC frames are processed until there are no more consumed frames.
2991  *   Once all frames are processed, the receive buffers are returned to the
2992  *   adapter.  Note that this algorithm fixes the length of time that can be spent
2993  *   in this routine, because there are a fixed number of receive buffers to
2994  *   process and buffers are not produced until this routine exits and returns
2995  *   to the ISR.
2996  *
2997  * Return Codes:
2998  *   None
2999  *
3000  * Assumptions:
3001  *   None
3002  *
3003  * Side Effects:
3004  *   None
3005  */
3006
3007 static void dfx_rcv_queue_process(
3008         DFX_board_t *bp
3009         )
3010
3011         {
3012         PI_TYPE_2_CONSUMER      *p_type_2_cons;         /* ptr to rcv/xmt consumer block register */
3013         char                            *p_buff;                        /* ptr to start of packet receive buffer (FMC descriptor) */
3014         u32                                     descr, pkt_len;         /* FMC descriptor field and packet length */
3015         struct sk_buff          *skb;                           /* pointer to a sk_buff to hold incoming packet data */
3016
3017         /* Service all consumed LLC receive frames */
3018
3019         p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
3020         while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
3021                 {
3022                 /* Process any errors */
3023
3024                 int entry;
3025
3026                 entry = bp->rcv_xmt_reg.index.rcv_comp;
3027 #ifdef DYNAMIC_BUFFERS
3028                 p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
3029 #else
3030                 p_buff = bp->p_rcv_buff_va[entry];
3031 #endif
3032                 memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
3033
3034                 if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
3035                         {
3036                         if (descr & PI_FMC_DESCR_M_RCC_CRC)
3037                                 bp->rcv_crc_errors++;
3038                         else
3039                                 bp->rcv_frame_status_errors++;
3040                         }
3041                 else
3042                 {
3043                         int rx_in_place = 0;
3044
3045                         /* The frame was received without errors - verify packet length */
3046
3047                         pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
3048                         pkt_len -= 4;                           /* subtract 4 byte CRC */
3049                         if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
3050                                 bp->rcv_length_errors++;
3051                         else{
3052 #ifdef DYNAMIC_BUFFERS
3053                                 if (pkt_len > SKBUFF_RX_COPYBREAK) {
3054                                         struct sk_buff *newskb;
3055
3056                                         newskb = dev_alloc_skb(NEW_SKB_SIZE);
3057                                         if (newskb){
3058                                                 rx_in_place = 1;
3059
3060                                                 my_skb_align(newskb, 128);
3061                                                 skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
3062                                                 dma_unmap_single(bp->bus_dev,
3063                                                         bp->descr_block_virt->rcv_data[entry].long_1,
3064                                                         NEW_SKB_SIZE,
3065                                                         DMA_FROM_DEVICE);
3066                                                 skb_reserve(skb, RCV_BUFF_K_PADDING);
3067                                                 bp->p_rcv_buff_va[entry] = (char *)newskb;
3068                                                 bp->descr_block_virt->rcv_data[entry].long_1 =
3069                                                         (u32)dma_map_single(bp->bus_dev,
3070                                                                 newskb->data,
3071                                                                 NEW_SKB_SIZE,
3072                                                                 DMA_FROM_DEVICE);
3073                                         } else
3074                                                 skb = NULL;
3075                                 } else
3076 #endif
3077                                         skb = dev_alloc_skb(pkt_len+3); /* alloc new buffer to pass up, add room for PRH */
3078                                 if (skb == NULL)
3079                                         {
3080                                         printk("%s: Could not allocate receive buffer.  Dropping packet.\n", bp->dev->name);
3081                                         bp->rcv_discards++;
3082                                         break;
3083                                         }
3084                                 else {
3085 #ifndef DYNAMIC_BUFFERS
3086                                         if (! rx_in_place)
3087 #endif
3088                                         {
3089                                                 /* Receive buffer allocated, pass receive packet up */
3090
3091                                                 skb_copy_to_linear_data(skb,
3092                                                                p_buff + RCV_BUFF_K_PADDING,
3093                                                                pkt_len + 3);
3094                                         }
3095
3096                                         skb_reserve(skb,3);             /* adjust data field so that it points to FC byte */
3097                                         skb_put(skb, pkt_len);          /* pass up packet length, NOT including CRC */
3098                                         skb->protocol = fddi_type_trans(skb, bp->dev);
3099                                         bp->rcv_total_bytes += skb->len;
3100                                         netif_rx(skb);
3101
3102                                         /* Update the rcv counters */
3103                                         bp->rcv_total_frames++;
3104                                         if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
3105                                                 bp->rcv_multicast_frames++;
3106                                 }
3107                         }
3108                         }
3109
3110                 /*
3111                  * Advance the producer (for recycling) and advance the completion
3112                  * (for servicing received frames).  Note that it is okay to
3113                  * advance the producer without checking that it passes the
3114                  * completion index because they are both advanced at the same
3115                  * rate.
3116                  */
3117
3118                 bp->rcv_xmt_reg.index.rcv_prod += 1;
3119                 bp->rcv_xmt_reg.index.rcv_comp += 1;
3120                 }
3121         }
3122
3123
3124 /*
3125  * =====================
3126  * = dfx_xmt_queue_pkt =
3127  * =====================
3128  *
3129  * Overview:
3130  *   Queues packets for transmission
3131  *
3132  * Returns:
3133  *   Condition code
3134  *
3135  * Arguments:
3136  *   skb - pointer to sk_buff to queue for transmission
3137  *   dev - pointer to device information
3138  *
3139  * Functional Description:
3140  *   Here we assume that an incoming skb transmit request
3141  *   is contained in a single physically contiguous buffer
3142  *   in which the virtual address of the start of packet
3143  *   (skb->data) can be converted to a physical address
3144  *   by using pci_map_single().
3145  *
3146  *   Since the adapter architecture requires a three byte
3147  *   packet request header to prepend the start of packet,
3148  *   we'll write the three byte field immediately prior to
3149  *   the FC byte.  This assumption is valid because we've
3150  *   ensured that dev->hard_header_len includes three pad
3151  *   bytes.  By posting a single fragment to the adapter,
3152  *   we'll reduce the number of descriptor fetches and
3153  *   bus traffic needed to send the request.
3154  *
3155  *   Also, we can't free the skb until after it's been DMA'd
3156  *   out by the adapter, so we'll queue it in the driver and
3157  *   return it in dfx_xmt_done.
3158  *
3159  * Return Codes:
3160  *   0 - driver queued packet, link is unavailable, or skbuff was bad
3161  *       1 - caller should requeue the sk_buff for later transmission
3162  *
3163  * Assumptions:
3164  *       First and foremost, we assume the incoming skb pointer
3165  *   is NOT NULL and is pointing to a valid sk_buff structure.
3166  *
3167  *   The outgoing packet is complete, starting with the
3168  *   frame control byte including the last byte of data,
3169  *   but NOT including the 4 byte CRC.  We'll let the
3170  *   adapter hardware generate and append the CRC.
3171  *
3172  *   The entire packet is stored in one physically
3173  *   contiguous buffer which is not cached and whose
3174  *   32-bit physical address can be determined.
3175  *
3176  *   It's vital that this routine is NOT reentered for the
3177  *   same board and that the OS is not in another section of
3178  *   code (eg. dfx_int_common) for the same board on a
3179  *   different thread.
3180  *
3181  * Side Effects:
3182  *   None
3183  */
3184
3185 static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
3186                                      struct net_device *dev)
3187         {
3188         DFX_board_t             *bp = netdev_priv(dev);
3189         u8                      prod;                           /* local transmit producer index */
3190         PI_XMT_DESCR            *p_xmt_descr;           /* ptr to transmit descriptor block entry */
3191         XMT_DRIVER_DESCR        *p_xmt_drv_descr;       /* ptr to transmit driver descriptor */
3192         unsigned long           flags;
3193
3194         netif_stop_queue(dev);
3195
3196         /*
3197          * Verify that incoming transmit request is OK
3198          *
3199          * Note: The packet size check is consistent with other
3200          *               Linux device drivers, although the correct packet
3201          *               size should be verified before calling the
3202          *               transmit routine.
3203          */
3204
3205         if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
3206         {
3207                 printk("%s: Invalid packet length - %u bytes\n",
3208                         dev->name, skb->len);
3209                 bp->xmt_length_errors++;                /* bump error counter */
3210                 netif_wake_queue(dev);
3211                 dev_kfree_skb(skb);
3212                 return NETDEV_TX_OK;                    /* return "success" */
3213         }
3214         /*
3215          * See if adapter link is available, if not, free buffer
3216          *
3217          * Note: If the link isn't available, free buffer and return 0
3218          *               rather than tell the upper layer to requeue the packet.
3219          *               The methodology here is that by the time the link
3220          *               becomes available, the packet to be sent will be
3221          *               fairly stale.  By simply dropping the packet, the
3222          *               higher layer protocols will eventually time out
3223          *               waiting for response packets which it won't receive.
3224          */
3225
3226         if (bp->link_available == PI_K_FALSE)
3227                 {
3228                 if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL)  /* is link really available? */
3229                         bp->link_available = PI_K_TRUE;         /* if so, set flag and continue */
3230                 else
3231                         {
3232                         bp->xmt_discards++;                                     /* bump error counter */
3233                         dev_kfree_skb(skb);             /* free sk_buff now */
3234                         netif_wake_queue(dev);
3235                         return NETDEV_TX_OK;            /* return "success" */
3236                         }
3237                 }
3238
3239         spin_lock_irqsave(&bp->lock, flags);
3240
3241         /* Get the current producer and the next free xmt data descriptor */
3242
3243         prod            = bp->rcv_xmt_reg.index.xmt_prod;
3244         p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
3245
3246         /*
3247          * Get pointer to auxiliary queue entry to contain information
3248          * for this packet.
3249          *
3250          * Note: The current xmt producer index will become the
3251          *       current xmt completion index when we complete this
3252          *       packet later on.  So, we'll get the pointer to the
3253          *       next auxiliary queue entry now before we bump the
3254          *       producer index.
3255          */
3256
3257         p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]);     /* also bump producer index */
3258
3259         /* Write the three PRH bytes immediately before the FC byte */
3260
3261         skb_push(skb,3);
3262         skb->data[0] = DFX_PRH0_BYTE;   /* these byte values are defined */
3263         skb->data[1] = DFX_PRH1_BYTE;   /* in the Motorola FDDI MAC chip */
3264         skb->data[2] = DFX_PRH2_BYTE;   /* specification */
3265
3266         /*
3267          * Write the descriptor with buffer info and bump producer
3268          *
3269          * Note: Since we need to start DMA from the packet request
3270          *               header, we'll add 3 bytes to the DMA buffer length,
3271          *               and we'll determine the physical address of the
3272          *               buffer from the PRH, not skb->data.
3273          *
3274          * Assumptions:
3275          *               1. Packet starts with the frame control (FC) byte
3276          *                  at skb->data.
3277          *               2. The 4-byte CRC is not appended to the buffer or
3278          *                      included in the length.
3279          *               3. Packet length (skb->len) is from FC to end of
3280          *                      data, inclusive.
3281          *               4. The packet length does not exceed the maximum
3282          *                      FDDI LLC frame length of 4491 bytes.
3283          *               5. The entire packet is contained in a physically
3284          *                      contiguous, non-cached, locked memory space
3285          *                      comprised of a single buffer pointed to by
3286          *                      skb->data.
3287          *               6. The physical address of the start of packet
3288          *                      can be determined from the virtual address
3289          *                      by using pci_map_single() and is only 32-bits
3290          *                      wide.
3291          */
3292
3293         p_xmt_descr->long_0     = (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
3294         p_xmt_descr->long_1 = (u32)dma_map_single(bp->bus_dev, skb->data,
3295                                                   skb->len, DMA_TO_DEVICE);
3296
3297         /*
3298          * Verify that descriptor is actually available
3299          *
3300          * Note: If descriptor isn't available, return 1 which tells
3301          *       the upper layer to requeue the packet for later
3302          *       transmission.
3303          *
3304          *       We need to ensure that the producer never reaches the
3305          *       completion, except to indicate that the queue is empty.
3306          */
3307
3308         if (prod == bp->rcv_xmt_reg.index.xmt_comp)
3309         {
3310                 skb_pull(skb,3);
3311                 spin_unlock_irqrestore(&bp->lock, flags);
3312                 return NETDEV_TX_BUSY;  /* requeue packet for later */
3313         }
3314
3315         /*
3316          * Save info for this packet for xmt done indication routine
3317          *
3318          * Normally, we'd save the producer index in the p_xmt_drv_descr
3319          * structure so that we'd have it handy when we complete this
3320          * packet later (in dfx_xmt_done).  However, since the current
3321          * transmit architecture guarantees a single fragment for the
3322          * entire packet, we can simply bump the completion index by
3323          * one (1) for each completed packet.
3324          *
3325          * Note: If this assumption changes and we're presented with
3326          *       an inconsistent number of transmit fragments for packet
3327          *       data, we'll need to modify this code to save the current
3328          *       transmit producer index.
3329          */
3330
3331         p_xmt_drv_descr->p_skb = skb;
3332
3333         /* Update Type 2 register */
3334
3335         bp->rcv_xmt_reg.index.xmt_prod = prod;
3336         dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
3337         spin_unlock_irqrestore(&bp->lock, flags);
3338         netif_wake_queue(dev);
3339         return NETDEV_TX_OK;    /* packet queued to adapter */
3340         }
3341
3342
3343 /*
3344  * ================
3345  * = dfx_xmt_done =
3346  * ================
3347  *
3348  * Overview:
3349  *   Processes all frames that have been transmitted.
3350  *
3351  * Returns:
3352  *   None
3353  *
3354  * Arguments:
3355  *   bp - pointer to board information
3356  *
3357  * Functional Description:
3358  *   For all consumed transmit descriptors that have not
3359  *   yet been completed, we'll free the skb we were holding
3360  *   onto using dev_kfree_skb and bump the appropriate
3361  *   counters.
3362  *
3363  * Return Codes:
3364  *   None
3365  *
3366  * Assumptions:
3367  *   The Type 2 register is not updated in this routine.  It is
3368  *   assumed that it will be updated in the ISR when dfx_xmt_done
3369  *   returns.
3370  *
3371  * Side Effects:
3372  *   None
3373  */
3374
3375 static int dfx_xmt_done(DFX_board_t *bp)
3376         {
3377         XMT_DRIVER_DESCR        *p_xmt_drv_descr;       /* ptr to transmit driver descriptor */
3378         PI_TYPE_2_CONSUMER      *p_type_2_cons;         /* ptr to rcv/xmt consumer block register */
3379         u8                      comp;                   /* local transmit completion index */
3380         int                     freed = 0;              /* buffers freed */
3381
3382         /* Service all consumed transmit frames */
3383
3384         p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
3385         while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
3386                 {
3387                 /* Get pointer to the transmit driver descriptor block information */
3388
3389                 p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
3390
3391                 /* Increment transmit counters */
3392
3393                 bp->xmt_total_frames++;
3394                 bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
3395
3396                 /* Return skb to operating system */
3397                 comp = bp->rcv_xmt_reg.index.xmt_comp;
3398                 dma_unmap_single(bp->bus_dev,
3399                                  bp->descr_block_virt->xmt_data[comp].long_1,
3400                                  p_xmt_drv_descr->p_skb->len,
3401                                  DMA_TO_DEVICE);
3402                 dev_kfree_skb_irq(p_xmt_drv_descr->p_skb);
3403
3404                 /*
3405                  * Move to start of next packet by updating completion index
3406                  *
3407                  * Here we assume that a transmit packet request is always
3408                  * serviced by posting one fragment.  We can therefore
3409                  * simplify the completion code by incrementing the
3410                  * completion index by one.  This code will need to be
3411                  * modified if this assumption changes.  See comments
3412                  * in dfx_xmt_queue_pkt for more details.
3413                  */
3414
3415                 bp->rcv_xmt_reg.index.xmt_comp += 1;
3416                 freed++;
3417                 }
3418         return freed;
3419         }
3420
3421
3422 /*
3423  * =================
3424  * = dfx_rcv_flush =
3425  * =================
3426  *
3427  * Overview:
3428  *   Remove all skb's in the receive ring.
3429  *
3430  * Returns:
3431  *   None
3432  *
3433  * Arguments:
3434  *   bp - pointer to board information
3435  *
3436  * Functional Description:
3437  *   Free's all the dynamically allocated skb's that are
3438  *   currently attached to the device receive ring. This
3439  *   function is typically only used when the device is
3440  *   initialized or reinitialized.
3441  *
3442  * Return Codes:
3443  *   None
3444  *
3445  * Side Effects:
3446  *   None
3447  */
3448 #ifdef DYNAMIC_BUFFERS
3449 static void dfx_rcv_flush( DFX_board_t *bp )
3450         {
3451         int i, j;
3452
3453         for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
3454                 for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
3455                 {
3456                         struct sk_buff *skb;
3457                         skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
3458                         if (skb)
3459                                 dev_kfree_skb(skb);
3460                         bp->p_rcv_buff_va[i+j] = NULL;
3461                 }
3462
3463         }
3464 #else
3465 static inline void dfx_rcv_flush( DFX_board_t *bp )
3466 {
3467 }
3468 #endif /* DYNAMIC_BUFFERS */
3469
3470 /*
3471  * =================
3472  * = dfx_xmt_flush =
3473  * =================
3474  *
3475  * Overview:
3476  *   Processes all frames whether they've been transmitted
3477  *   or not.
3478  *
3479  * Returns:
3480  *   None
3481  *
3482  * Arguments:
3483  *   bp - pointer to board information
3484  *
3485  * Functional Description:
3486  *   For all produced transmit descriptors that have not
3487  *   yet been completed, we'll free the skb we were holding
3488  *   onto using dev_kfree_skb and bump the appropriate
3489  *   counters.  Of course, it's possible that some of
3490  *   these transmit requests actually did go out, but we
3491  *   won't make that distinction here.  Finally, we'll
3492  *   update the consumer index to match the producer.
3493  *
3494  * Return Codes:
3495  *   None
3496  *
3497  * Assumptions:
3498  *   This routine does NOT update the Type 2 register.  It
3499  *   is assumed that this routine is being called during a
3500  *   transmit flush interrupt, or a shutdown or close routine.
3501  *
3502  * Side Effects:
3503  *   None
3504  */
3505
3506 static void dfx_xmt_flush( DFX_board_t *bp )
3507         {
3508         u32                     prod_cons;              /* rcv/xmt consumer block longword */
3509         XMT_DRIVER_DESCR        *p_xmt_drv_descr;       /* ptr to transmit driver descriptor */
3510         u8                      comp;                   /* local transmit completion index */
3511
3512         /* Flush all outstanding transmit frames */
3513
3514         while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
3515                 {
3516                 /* Get pointer to the transmit driver descriptor block information */
3517
3518                 p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
3519
3520                 /* Return skb to operating system */
3521                 comp = bp->rcv_xmt_reg.index.xmt_comp;
3522                 dma_unmap_single(bp->bus_dev,
3523                                  bp->descr_block_virt->xmt_data[comp].long_1,
3524                                  p_xmt_drv_descr->p_skb->len,
3525                                  DMA_TO_DEVICE);
3526                 dev_kfree_skb(p_xmt_drv_descr->p_skb);
3527
3528                 /* Increment transmit error counter */
3529
3530                 bp->xmt_discards++;
3531
3532                 /*
3533                  * Move to start of next packet by updating completion index
3534                  *
3535                  * Here we assume that a transmit packet request is always
3536                  * serviced by posting one fragment.  We can therefore
3537                  * simplify the completion code by incrementing the
3538                  * completion index by one.  This code will need to be
3539                  * modified if this assumption changes.  See comments
3540                  * in dfx_xmt_queue_pkt for more details.
3541                  */
3542
3543                 bp->rcv_xmt_reg.index.xmt_comp += 1;
3544                 }
3545
3546         /* Update the transmit consumer index in the consumer block */
3547
3548         prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
3549         prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
3550         bp->cons_block_virt->xmt_rcv_data = prod_cons;
3551         }
3552
3553 /*
3554  * ==================
3555  * = dfx_unregister =
3556  * ==================
3557  *
3558  * Overview:
3559  *   Shuts down an FDDI controller
3560  *
3561  * Returns:
3562  *   Condition code
3563  *
3564  * Arguments:
3565  *   bdev - pointer to device information
3566  *
3567  * Functional Description:
3568  *
3569  * Return Codes:
3570  *   None
3571  *
3572  * Assumptions:
3573  *   It compiles so it should work :-( (PCI cards do :-)
3574  *
3575  * Side Effects:
3576  *   Device structures for FDDI adapters (fddi0, fddi1, etc) are
3577  *   freed.
3578  */
3579 static void dfx_unregister(struct device *bdev)
3580 {
3581         struct net_device *dev = dev_get_drvdata(bdev);
3582         DFX_board_t *bp = netdev_priv(dev);
3583         int dfx_bus_pci = DFX_BUS_PCI(bdev);
3584         int dfx_bus_tc = DFX_BUS_TC(bdev);
3585         int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
3586         resource_size_t bar_start = 0;          /* pointer to port */
3587         resource_size_t bar_len = 0;            /* resource length */
3588         int             alloc_size;             /* total buffer size used */
3589
3590         unregister_netdev(dev);
3591
3592         alloc_size = sizeof(PI_DESCR_BLOCK) +
3593                      PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
3594 #ifndef DYNAMIC_BUFFERS
3595                      (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
3596 #endif
3597                      sizeof(PI_CONSUMER_BLOCK) +
3598                      (PI_ALIGN_K_DESC_BLK - 1);
3599         if (bp->kmalloced)
3600                 dma_free_coherent(bdev, alloc_size,
3601                                   bp->kmalloced, bp->kmalloced_dma);
3602
3603         dfx_bus_uninit(dev);
3604
3605         dfx_get_bars(bdev, &bar_start, &bar_len);
3606         if (dfx_use_mmio) {
3607                 iounmap(bp->base.mem);
3608                 release_mem_region(bar_start, bar_len);
3609         } else
3610                 release_region(bar_start, bar_len);
3611
3612         if (dfx_bus_pci)
3613                 pci_disable_device(to_pci_dev(bdev));
3614
3615         free_netdev(dev);
3616 }
3617
3618
3619 static int __maybe_unused dfx_dev_register(struct device *);
3620 static int __maybe_unused dfx_dev_unregister(struct device *);
3621
3622 #ifdef CONFIG_PCI
3623 static int dfx_pci_register(struct pci_dev *, const struct pci_device_id *);
3624 static void dfx_pci_unregister(struct pci_dev *);
3625
3626 static DEFINE_PCI_DEVICE_TABLE(dfx_pci_table) = {
3627         { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI) },
3628         { }
3629 };
3630 MODULE_DEVICE_TABLE(pci, dfx_pci_table);
3631
3632 static struct pci_driver dfx_pci_driver = {
3633         .name           = "defxx",
3634         .id_table       = dfx_pci_table,
3635         .probe          = dfx_pci_register,
3636         .remove         = dfx_pci_unregister,
3637 };
3638
3639 static int dfx_pci_register(struct pci_dev *pdev,
3640                             const struct pci_device_id *ent)
3641 {
3642         return dfx_register(&pdev->dev);
3643 }
3644
3645 static void dfx_pci_unregister(struct pci_dev *pdev)
3646 {
3647         dfx_unregister(&pdev->dev);
3648 }
3649 #endif /* CONFIG_PCI */
3650
3651 #ifdef CONFIG_EISA
3652 static struct eisa_device_id dfx_eisa_table[] = {
3653         { "DEC3001", DEFEA_PROD_ID_1 },
3654         { "DEC3002", DEFEA_PROD_ID_2 },
3655         { "DEC3003", DEFEA_PROD_ID_3 },
3656         { "DEC3004", DEFEA_PROD_ID_4 },
3657         { }
3658 };
3659 MODULE_DEVICE_TABLE(eisa, dfx_eisa_table);
3660
3661 static struct eisa_driver dfx_eisa_driver = {
3662         .id_table       = dfx_eisa_table,
3663         .driver         = {
3664                 .name   = "defxx",
3665                 .bus    = &eisa_bus_type,
3666                 .probe  = dfx_dev_register,
3667                 .remove = dfx_dev_unregister,
3668         },
3669 };
3670 #endif /* CONFIG_EISA */
3671
3672 #ifdef CONFIG_TC
3673 static struct tc_device_id const dfx_tc_table[] = {
3674         { "DEC     ", "PMAF-FA " },
3675         { "DEC     ", "PMAF-FD " },
3676         { "DEC     ", "PMAF-FS " },
3677         { "DEC     ", "PMAF-FU " },
3678         { }
3679 };
3680 MODULE_DEVICE_TABLE(tc, dfx_tc_table);
3681
3682 static struct tc_driver dfx_tc_driver = {
3683         .id_table       = dfx_tc_table,
3684         .driver         = {
3685                 .name   = "defxx",
3686                 .bus    = &tc_bus_type,
3687                 .probe  = dfx_dev_register,
3688                 .remove = dfx_dev_unregister,
3689         },
3690 };
3691 #endif /* CONFIG_TC */
3692
3693 static int __maybe_unused dfx_dev_register(struct device *dev)
3694 {
3695         int status;
3696
3697         status = dfx_register(dev);
3698         if (!status)
3699                 get_device(dev);
3700         return status;
3701 }
3702
3703 static int __maybe_unused dfx_dev_unregister(struct device *dev)
3704 {
3705         put_device(dev);
3706         dfx_unregister(dev);
3707         return 0;
3708 }
3709
3710
3711 static int dfx_init(void)
3712 {
3713         int status;
3714
3715         status = pci_register_driver(&dfx_pci_driver);
3716         if (!status)
3717                 status = eisa_driver_register(&dfx_eisa_driver);
3718         if (!status)
3719                 status = tc_register_driver(&dfx_tc_driver);
3720         return status;
3721 }
3722
3723 static void dfx_cleanup(void)
3724 {
3725         tc_unregister_driver(&dfx_tc_driver);
3726         eisa_driver_unregister(&dfx_eisa_driver);
3727         pci_unregister_driver(&dfx_pci_driver);
3728 }
3729
3730 module_init(dfx_init);
3731 module_exit(dfx_cleanup);
3732 MODULE_AUTHOR("Lawrence V. Stefani");
3733 MODULE_DESCRIPTION("DEC FDDIcontroller TC/EISA/PCI (DEFTA/DEFEA/DEFPA) driver "
3734                    DRV_VERSION " " DRV_RELDATE);
3735 MODULE_LICENSE("GPL");