OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [defxx.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.