133f810b2SJeff Kirsher /*
233f810b2SJeff Kirsher * File Name:
333f810b2SJeff Kirsher * defxx.c
433f810b2SJeff Kirsher *
533f810b2SJeff Kirsher * Copyright Information:
633f810b2SJeff Kirsher * Copyright Digital Equipment Corporation 1996.
733f810b2SJeff Kirsher *
833f810b2SJeff Kirsher * This software may be used and distributed according to the terms of
933f810b2SJeff Kirsher * the GNU General Public License, incorporated herein by reference.
1033f810b2SJeff Kirsher *
1133f810b2SJeff Kirsher * Abstract:
1233f810b2SJeff Kirsher * A Linux device driver supporting the Digital Equipment Corporation
1333f810b2SJeff Kirsher * FDDI TURBOchannel, EISA and PCI controller families. Supported
1433f810b2SJeff Kirsher * adapters include:
1533f810b2SJeff Kirsher *
1633f810b2SJeff Kirsher * DEC FDDIcontroller/TURBOchannel (DEFTA)
1733f810b2SJeff Kirsher * DEC FDDIcontroller/EISA (DEFEA)
1833f810b2SJeff Kirsher * DEC FDDIcontroller/PCI (DEFPA)
1933f810b2SJeff Kirsher *
2033f810b2SJeff Kirsher * The original author:
2133f810b2SJeff Kirsher * LVS Lawrence V. Stefani <lstefani@yahoo.com>
2233f810b2SJeff Kirsher *
2333f810b2SJeff Kirsher * Maintainers:
244d248c0dSMaciej W. Rozycki * macro Maciej W. Rozycki <macro@orcam.me.uk>
2533f810b2SJeff Kirsher *
2633f810b2SJeff Kirsher * Credits:
2733f810b2SJeff Kirsher * I'd like to thank Patricia Cross for helping me get started with
2833f810b2SJeff Kirsher * Linux, David Davies for a lot of help upgrading and configuring
2933f810b2SJeff Kirsher * my development system and for answering many OS and driver
3033f810b2SJeff Kirsher * development questions, and Alan Cox for recommendations and
3133f810b2SJeff Kirsher * integration help on getting FDDI support into Linux. LVS
3233f810b2SJeff Kirsher *
3333f810b2SJeff Kirsher * Driver Architecture:
3433f810b2SJeff Kirsher * The driver architecture is largely based on previous driver work
3533f810b2SJeff Kirsher * for other operating systems. The upper edge interface and
3633f810b2SJeff Kirsher * functions were largely taken from existing Linux device drivers
3733f810b2SJeff Kirsher * such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
3833f810b2SJeff Kirsher * driver.
3933f810b2SJeff Kirsher *
4033f810b2SJeff Kirsher * Adapter Probe -
4133f810b2SJeff Kirsher * The driver scans for supported EISA adapters by reading the
4233f810b2SJeff Kirsher * SLOT ID register for each EISA slot and making a match
4333f810b2SJeff Kirsher * against the expected value.
4433f810b2SJeff Kirsher *
4533f810b2SJeff Kirsher * Bus-Specific Initialization -
4633f810b2SJeff Kirsher * This driver currently supports both EISA and PCI controller
4733f810b2SJeff Kirsher * families. While the custom DMA chip and FDDI logic is similar
4833f810b2SJeff Kirsher * or identical, the bus logic is very different. After
4933f810b2SJeff Kirsher * initialization, the only bus-specific differences is in how the
5033f810b2SJeff Kirsher * driver enables and disables interrupts. Other than that, the
5133f810b2SJeff Kirsher * run-time critical code behaves the same on both families.
5233f810b2SJeff Kirsher * It's important to note that both adapter families are configured
5333f810b2SJeff Kirsher * to I/O map, rather than memory map, the adapter registers.
5433f810b2SJeff Kirsher *
5533f810b2SJeff Kirsher * Driver Open/Close -
5633f810b2SJeff Kirsher * In the driver open routine, the driver ISR (interrupt service
5733f810b2SJeff Kirsher * routine) is registered and the adapter is brought to an
5833f810b2SJeff Kirsher * operational state. In the driver close routine, the opposite
5933f810b2SJeff Kirsher * occurs; the driver ISR is deregistered and the adapter is
6033f810b2SJeff Kirsher * brought to a safe, but closed state. Users may use consecutive
6133f810b2SJeff Kirsher * commands to bring the adapter up and down as in the following
6233f810b2SJeff Kirsher * example:
6333f810b2SJeff Kirsher * ifconfig fddi0 up
6433f810b2SJeff Kirsher * ifconfig fddi0 down
6533f810b2SJeff Kirsher * ifconfig fddi0 up
6633f810b2SJeff Kirsher *
6733f810b2SJeff Kirsher * Driver Shutdown -
6833f810b2SJeff Kirsher * Apparently, there is no shutdown or halt routine support under
6933f810b2SJeff Kirsher * Linux. This routine would be called during "reboot" or
7033f810b2SJeff Kirsher * "shutdown" to allow the driver to place the adapter in a safe
7133f810b2SJeff Kirsher * state before a warm reboot occurs. To be really safe, the user
7233f810b2SJeff Kirsher * should close the adapter before shutdown (eg. ifconfig fddi0 down)
7333f810b2SJeff Kirsher * to ensure that the adapter DMA engine is taken off-line. However,
7433f810b2SJeff Kirsher * the current driver code anticipates this problem and always issues
7533f810b2SJeff Kirsher * a soft reset of the adapter at the beginning of driver initialization.
7633f810b2SJeff Kirsher * A future driver enhancement in this area may occur in 2.1.X where
7733f810b2SJeff Kirsher * Alan indicated that a shutdown handler may be implemented.
7833f810b2SJeff Kirsher *
7933f810b2SJeff Kirsher * Interrupt Service Routine -
8033f810b2SJeff Kirsher * The driver supports shared interrupts, so the ISR is registered for
8133f810b2SJeff Kirsher * each board with the appropriate flag and the pointer to that board's
8233f810b2SJeff Kirsher * device structure. This provides the context during interrupt
8333f810b2SJeff Kirsher * processing to support shared interrupts and multiple boards.
8433f810b2SJeff Kirsher *
8533f810b2SJeff Kirsher * Interrupt enabling/disabling can occur at many levels. At the host
8633f810b2SJeff Kirsher * end, you can disable system interrupts, or disable interrupts at the
8733f810b2SJeff Kirsher * PIC (on Intel systems). Across the bus, both EISA and PCI adapters
8833f810b2SJeff Kirsher * have a bus-logic chip interrupt enable/disable as well as a DMA
8933f810b2SJeff Kirsher * controller interrupt enable/disable.
9033f810b2SJeff Kirsher *
9133f810b2SJeff Kirsher * The driver currently enables and disables adapter interrupts at the
9233f810b2SJeff Kirsher * bus-logic chip and assumes that Linux will take care of clearing or
9333f810b2SJeff Kirsher * acknowledging any host-based interrupt chips.
9433f810b2SJeff Kirsher *
9533f810b2SJeff Kirsher * Control Functions -
9633f810b2SJeff Kirsher * Control functions are those used to support functions such as adding
9733f810b2SJeff Kirsher * or deleting multicast addresses, enabling or disabling packet
9833f810b2SJeff Kirsher * reception filters, or other custom/proprietary commands. Presently,
9933f810b2SJeff Kirsher * the driver supports the "get statistics", "set multicast list", and
10033f810b2SJeff Kirsher * "set mac address" functions defined by Linux. A list of possible
10133f810b2SJeff Kirsher * enhancements include:
10233f810b2SJeff Kirsher *
10333f810b2SJeff Kirsher * - Custom ioctl interface for executing port interface commands
10433f810b2SJeff Kirsher * - Custom ioctl interface for adding unicast addresses to
10533f810b2SJeff Kirsher * adapter CAM (to support bridge functions).
10633f810b2SJeff Kirsher * - Custom ioctl interface for supporting firmware upgrades.
10733f810b2SJeff Kirsher *
10833f810b2SJeff Kirsher * Hardware (port interface) Support Routines -
10933f810b2SJeff Kirsher * The driver function names that start with "dfx_hw_" represent
11033f810b2SJeff Kirsher * low-level port interface routines that are called frequently. They
11133f810b2SJeff Kirsher * include issuing a DMA or port control command to the adapter,
11233f810b2SJeff Kirsher * resetting the adapter, or reading the adapter state. Since the
11333f810b2SJeff Kirsher * driver initialization and run-time code must make calls into the
11433f810b2SJeff Kirsher * port interface, these routines were written to be as generic and
11533f810b2SJeff Kirsher * usable as possible.
11633f810b2SJeff Kirsher *
11733f810b2SJeff Kirsher * Receive Path -
11833f810b2SJeff Kirsher * The adapter DMA engine supports a 256 entry receive descriptor block
11933f810b2SJeff Kirsher * of which up to 255 entries can be used at any given time. The
12033f810b2SJeff Kirsher * architecture is a standard producer, consumer, completion model in
12133f810b2SJeff Kirsher * which the driver "produces" receive buffers to the adapter, the
12233f810b2SJeff Kirsher * adapter "consumes" the receive buffers by DMAing incoming packet data,
12333f810b2SJeff Kirsher * and the driver "completes" the receive buffers by servicing the
12433f810b2SJeff Kirsher * incoming packet, then "produces" a new buffer and starts the cycle
12533f810b2SJeff Kirsher * again. Receive buffers can be fragmented in up to 16 fragments
12633f810b2SJeff Kirsher * (descriptor entries). For simplicity, this driver posts
12733f810b2SJeff Kirsher * single-fragment receive buffers of 4608 bytes, then allocates a
12833f810b2SJeff Kirsher * sk_buff, copies the data, then reposts the buffer. To reduce CPU
12933f810b2SJeff Kirsher * utilization, a better approach would be to pass up the receive
13033f810b2SJeff Kirsher * buffer (no extra copy) then allocate and post a replacement buffer.
13133f810b2SJeff Kirsher * This is a performance enhancement that should be looked into at
13233f810b2SJeff Kirsher * some point.
13333f810b2SJeff Kirsher *
13433f810b2SJeff Kirsher * Transmit Path -
13533f810b2SJeff Kirsher * Like the receive path, the adapter DMA engine supports a 256 entry
13633f810b2SJeff Kirsher * transmit descriptor block of which up to 255 entries can be used at
13733f810b2SJeff Kirsher * any given time. Transmit buffers can be fragmented in up to 255
13833f810b2SJeff Kirsher * fragments (descriptor entries). This driver always posts one
13933f810b2SJeff Kirsher * fragment per transmit packet request.
14033f810b2SJeff Kirsher *
14133f810b2SJeff Kirsher * The fragment contains the entire packet from FC to end of data.
14233f810b2SJeff Kirsher * Before posting the buffer to the adapter, the driver sets a three-byte
14333f810b2SJeff Kirsher * packet request header (PRH) which is required by the Motorola MAC chip
14433f810b2SJeff Kirsher * used on the adapters. The PRH tells the MAC the type of token to
14533f810b2SJeff Kirsher * receive/send, whether or not to generate and append the CRC, whether
14633f810b2SJeff Kirsher * synchronous or asynchronous framing is used, etc. Since the PRH
14733f810b2SJeff Kirsher * definition is not necessarily consistent across all FDDI chipsets,
14833f810b2SJeff Kirsher * the driver, rather than the common FDDI packet handler routines,
14933f810b2SJeff Kirsher * sets these bytes.
15033f810b2SJeff Kirsher *
15133f810b2SJeff Kirsher * To reduce the amount of descriptor fetches needed per transmit request,
15233f810b2SJeff Kirsher * the driver takes advantage of the fact that there are at least three
15333f810b2SJeff Kirsher * bytes available before the skb->data field on the outgoing transmit
15433f810b2SJeff Kirsher * request. This is guaranteed by having fddi_setup() in net_init.c set
15533f810b2SJeff Kirsher * dev->hard_header_len to 24 bytes. 21 bytes accounts for the largest
15633f810b2SJeff Kirsher * header in an 802.2 SNAP frame. The other 3 bytes are the extra "pad"
15733f810b2SJeff Kirsher * bytes which we'll use to store the PRH.
15833f810b2SJeff Kirsher *
15933f810b2SJeff Kirsher * There's a subtle advantage to adding these pad bytes to the
16033f810b2SJeff Kirsher * hard_header_len, it ensures that the data portion of the packet for
16133f810b2SJeff Kirsher * an 802.2 SNAP frame is longword aligned. Other FDDI driver
16233f810b2SJeff Kirsher * implementations may not need the extra padding and can start copying
16333f810b2SJeff Kirsher * or DMAing directly from the FC byte which starts at skb->data. Should
16433f810b2SJeff Kirsher * another driver implementation need ADDITIONAL padding, the net_init.c
16533f810b2SJeff Kirsher * module should be updated and dev->hard_header_len should be increased.
16633f810b2SJeff Kirsher * NOTE: To maintain the alignment on the data portion of the packet,
16733f810b2SJeff Kirsher * dev->hard_header_len should always be evenly divisible by 4 and at
16833f810b2SJeff Kirsher * least 24 bytes in size.
16933f810b2SJeff Kirsher *
17033f810b2SJeff Kirsher * Modification History:
17133f810b2SJeff Kirsher * Date Name Description
17233f810b2SJeff Kirsher * 16-Aug-96 LVS Created.
17333f810b2SJeff Kirsher * 20-Aug-96 LVS Updated dfx_probe so that version information
17433f810b2SJeff Kirsher * string is only displayed if 1 or more cards are
17533f810b2SJeff Kirsher * found. Changed dfx_rcv_queue_process to copy
17633f810b2SJeff Kirsher * 3 NULL bytes before FC to ensure that data is
17733f810b2SJeff Kirsher * longword aligned in receive buffer.
17833f810b2SJeff Kirsher * 09-Sep-96 LVS Updated dfx_ctl_set_multicast_list to enable
17933f810b2SJeff Kirsher * LLC group promiscuous mode if multicast list
18033f810b2SJeff Kirsher * is too large. LLC individual/group promiscuous
18133f810b2SJeff Kirsher * mode is now disabled if IFF_PROMISC flag not set.
18233f810b2SJeff Kirsher * dfx_xmt_queue_pkt no longer checks for NULL skb
18333f810b2SJeff Kirsher * on Alan Cox recommendation. Added node address
18433f810b2SJeff Kirsher * override support.
18533f810b2SJeff Kirsher * 12-Sep-96 LVS Reset current address to factory address during
18633f810b2SJeff Kirsher * device open. Updated transmit path to post a
18733f810b2SJeff Kirsher * single fragment which includes PRH->end of data.
18833f810b2SJeff Kirsher * Mar 2000 AC Did various cleanups for 2.3.x
18933f810b2SJeff Kirsher * Jun 2000 jgarzik PCI and resource alloc cleanups
19033f810b2SJeff Kirsher * Jul 2000 tjeerd Much cleanup and some bug fixes
19133f810b2SJeff Kirsher * Sep 2000 tjeerd Fix leak on unload, cosmetic code cleanup
19233f810b2SJeff Kirsher * Feb 2001 Skb allocation fixes
19333f810b2SJeff Kirsher * Feb 2001 davej PCI enable cleanups.
19433f810b2SJeff Kirsher * 04 Aug 2003 macro Converted to the DMA API.
19533f810b2SJeff Kirsher * 14 Aug 2004 macro Fix device names reported.
19633f810b2SJeff Kirsher * 14 Jun 2005 macro Use irqreturn_t.
19733f810b2SJeff Kirsher * 23 Oct 2006 macro Big-endian host support.
19833f810b2SJeff Kirsher * 14 Dec 2006 macro TURBOchannel support.
1998848761fSMaciej W. Rozycki * 01 Jul 2014 macro Fixes for DMA on 64-bit hosts.
200795e272eSMaciej W. Rozycki * 10 Mar 2021 macro Dynamic MMIO vs port I/O.
20133f810b2SJeff Kirsher */
20233f810b2SJeff Kirsher
20333f810b2SJeff Kirsher /* Include files */
20433f810b2SJeff Kirsher #include <linux/bitops.h>
20533f810b2SJeff Kirsher #include <linux/compiler.h>
20633f810b2SJeff Kirsher #include <linux/delay.h>
20733f810b2SJeff Kirsher #include <linux/dma-mapping.h>
20833f810b2SJeff Kirsher #include <linux/eisa.h>
20933f810b2SJeff Kirsher #include <linux/errno.h>
21033f810b2SJeff Kirsher #include <linux/fddidevice.h>
21133f810b2SJeff Kirsher #include <linux/interrupt.h>
21233f810b2SJeff Kirsher #include <linux/ioport.h>
21333f810b2SJeff Kirsher #include <linux/kernel.h>
21433f810b2SJeff Kirsher #include <linux/module.h>
21533f810b2SJeff Kirsher #include <linux/netdevice.h>
21633f810b2SJeff Kirsher #include <linux/pci.h>
21733f810b2SJeff Kirsher #include <linux/skbuff.h>
21833f810b2SJeff Kirsher #include <linux/slab.h>
21933f810b2SJeff Kirsher #include <linux/string.h>
22033f810b2SJeff Kirsher #include <linux/tc.h>
22133f810b2SJeff Kirsher
22233f810b2SJeff Kirsher #include <asm/byteorder.h>
22333f810b2SJeff Kirsher #include <asm/io.h>
22433f810b2SJeff Kirsher
22533f810b2SJeff Kirsher #include "defxx.h"
22633f810b2SJeff Kirsher
22733f810b2SJeff Kirsher /* Version information string should be updated prior to each new release! */
22833f810b2SJeff Kirsher #define DRV_NAME "defxx"
229795e272eSMaciej W. Rozycki #define DRV_VERSION "v1.12"
230795e272eSMaciej W. Rozycki #define DRV_RELDATE "2021/03/10"
23133f810b2SJeff Kirsher
23206324664SKees Cook static const char version[] =
23333f810b2SJeff Kirsher DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
23433f810b2SJeff Kirsher " Lawrence V. Stefani and others\n";
23533f810b2SJeff Kirsher
23633f810b2SJeff Kirsher #define DYNAMIC_BUFFERS 1
23733f810b2SJeff Kirsher
23833f810b2SJeff Kirsher #define SKBUFF_RX_COPYBREAK 200
23933f810b2SJeff Kirsher /*
24033f810b2SJeff Kirsher * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
24133f810b2SJeff Kirsher * alignment for compatibility with old EISA boards.
24233f810b2SJeff Kirsher */
24333f810b2SJeff Kirsher #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
24433f810b2SJeff Kirsher
24533f810b2SJeff Kirsher #ifdef CONFIG_EISA
24633f810b2SJeff Kirsher #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
24733f810b2SJeff Kirsher #else
24833f810b2SJeff Kirsher #define DFX_BUS_EISA(dev) 0
24933f810b2SJeff Kirsher #endif
25033f810b2SJeff Kirsher
25133f810b2SJeff Kirsher #ifdef CONFIG_TC
25233f810b2SJeff Kirsher #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
25333f810b2SJeff Kirsher #else
25433f810b2SJeff Kirsher #define DFX_BUS_TC(dev) 0
25533f810b2SJeff Kirsher #endif
25633f810b2SJeff Kirsher
257795e272eSMaciej W. Rozycki #if defined(CONFIG_EISA) || defined(CONFIG_PCI)
258795e272eSMaciej W. Rozycki #define dfx_use_mmio bp->mmio
25933f810b2SJeff Kirsher #else
260795e272eSMaciej W. Rozycki #define dfx_use_mmio true
26133f810b2SJeff Kirsher #endif
26233f810b2SJeff Kirsher
26333f810b2SJeff Kirsher /* Define module-wide (static) routines */
26433f810b2SJeff Kirsher
26533f810b2SJeff Kirsher static void dfx_bus_init(struct net_device *dev);
26633f810b2SJeff Kirsher static void dfx_bus_uninit(struct net_device *dev);
26733f810b2SJeff Kirsher static void dfx_bus_config_check(DFX_board_t *bp);
26833f810b2SJeff Kirsher
26933f810b2SJeff Kirsher static int dfx_driver_init(struct net_device *dev,
27033f810b2SJeff Kirsher const char *print_name,
27133f810b2SJeff Kirsher resource_size_t bar_start);
27233f810b2SJeff Kirsher static int dfx_adap_init(DFX_board_t *bp, int get_buffers);
27333f810b2SJeff Kirsher
27433f810b2SJeff Kirsher static int dfx_open(struct net_device *dev);
27533f810b2SJeff Kirsher static int dfx_close(struct net_device *dev);
27633f810b2SJeff Kirsher
27733f810b2SJeff Kirsher static void dfx_int_pr_halt_id(DFX_board_t *bp);
27833f810b2SJeff Kirsher static void dfx_int_type_0_process(DFX_board_t *bp);
27933f810b2SJeff Kirsher static void dfx_int_common(struct net_device *dev);
28033f810b2SJeff Kirsher static irqreturn_t dfx_interrupt(int irq, void *dev_id);
28133f810b2SJeff Kirsher
28233f810b2SJeff Kirsher static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
28333f810b2SJeff Kirsher static void dfx_ctl_set_multicast_list(struct net_device *dev);
28433f810b2SJeff Kirsher static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
28533f810b2SJeff Kirsher static int dfx_ctl_update_cam(DFX_board_t *bp);
28633f810b2SJeff Kirsher static int dfx_ctl_update_filters(DFX_board_t *bp);
28733f810b2SJeff Kirsher
28833f810b2SJeff Kirsher static int dfx_hw_dma_cmd_req(DFX_board_t *bp);
28933f810b2SJeff Kirsher 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);
29033f810b2SJeff Kirsher static void dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
29133f810b2SJeff Kirsher static int dfx_hw_adap_state_rd(DFX_board_t *bp);
29233f810b2SJeff Kirsher static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
29333f810b2SJeff Kirsher
29433f810b2SJeff Kirsher static int dfx_rcv_init(DFX_board_t *bp, int get_buffers);
29533f810b2SJeff Kirsher static void dfx_rcv_queue_process(DFX_board_t *bp);
2961b037474SMaciej W. Rozycki #ifdef DYNAMIC_BUFFERS
29733f810b2SJeff Kirsher static void dfx_rcv_flush(DFX_board_t *bp);
2981b037474SMaciej W. Rozycki #else
dfx_rcv_flush(DFX_board_t * bp)2991b037474SMaciej W. Rozycki static inline void dfx_rcv_flush(DFX_board_t *bp) {}
3001b037474SMaciej W. Rozycki #endif
30133f810b2SJeff Kirsher
30233f810b2SJeff Kirsher static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
30333f810b2SJeff Kirsher struct net_device *dev);
30433f810b2SJeff Kirsher static int dfx_xmt_done(DFX_board_t *bp);
30533f810b2SJeff Kirsher static void dfx_xmt_flush(DFX_board_t *bp);
30633f810b2SJeff Kirsher
30733f810b2SJeff Kirsher /* Define module-wide (static) variables */
30833f810b2SJeff Kirsher
30933f810b2SJeff Kirsher static struct pci_driver dfx_pci_driver;
31033f810b2SJeff Kirsher static struct eisa_driver dfx_eisa_driver;
31133f810b2SJeff Kirsher static struct tc_driver dfx_tc_driver;
31233f810b2SJeff Kirsher
31333f810b2SJeff Kirsher
31433f810b2SJeff Kirsher /*
31533f810b2SJeff Kirsher * =======================
31633f810b2SJeff Kirsher * = dfx_port_write_long =
31733f810b2SJeff Kirsher * = dfx_port_read_long =
31833f810b2SJeff Kirsher * =======================
31933f810b2SJeff Kirsher *
32033f810b2SJeff Kirsher * Overview:
32133f810b2SJeff Kirsher * Routines for reading and writing values from/to adapter
32233f810b2SJeff Kirsher *
32333f810b2SJeff Kirsher * Returns:
32433f810b2SJeff Kirsher * None
32533f810b2SJeff Kirsher *
32633f810b2SJeff Kirsher * Arguments:
32733f810b2SJeff Kirsher * bp - pointer to board information
32833f810b2SJeff Kirsher * offset - register offset from base I/O address
32933f810b2SJeff Kirsher * data - for dfx_port_write_long, this is a value to write;
33033f810b2SJeff Kirsher * for dfx_port_read_long, this is a pointer to store
33133f810b2SJeff Kirsher * the read value
33233f810b2SJeff Kirsher *
33333f810b2SJeff Kirsher * Functional Description:
33433f810b2SJeff Kirsher * These routines perform the correct operation to read or write
33533f810b2SJeff Kirsher * the adapter register.
33633f810b2SJeff Kirsher *
33733f810b2SJeff Kirsher * EISA port block base addresses are based on the slot number in which the
33833f810b2SJeff Kirsher * controller is installed. For example, if the EISA controller is installed
33933f810b2SJeff Kirsher * in slot 4, the port block base address is 0x4000. If the controller is
34033f810b2SJeff Kirsher * installed in slot 2, the port block base address is 0x2000, and so on.
34133f810b2SJeff Kirsher * This port block can be used to access PDQ, ESIC, and DEFEA on-board
34233f810b2SJeff Kirsher * registers using the register offsets defined in DEFXX.H.
34333f810b2SJeff Kirsher *
34433f810b2SJeff Kirsher * PCI port block base addresses are assigned by the PCI BIOS or system
34533f810b2SJeff Kirsher * firmware. There is one 128 byte port block which can be accessed. It
34633f810b2SJeff Kirsher * allows for I/O mapping of both PDQ and PFI registers using the register
34733f810b2SJeff Kirsher * offsets defined in DEFXX.H.
34833f810b2SJeff Kirsher *
34933f810b2SJeff Kirsher * Return Codes:
35033f810b2SJeff Kirsher * None
35133f810b2SJeff Kirsher *
35233f810b2SJeff Kirsher * Assumptions:
35333f810b2SJeff Kirsher * bp->base is a valid base I/O address for this adapter.
35433f810b2SJeff Kirsher * offset is a valid register offset for this adapter.
35533f810b2SJeff Kirsher *
35633f810b2SJeff Kirsher * Side Effects:
35733f810b2SJeff Kirsher * Rather than produce macros for these functions, these routines
35833f810b2SJeff Kirsher * are defined using "inline" to ensure that the compiler will
35933f810b2SJeff Kirsher * generate inline code and not waste a procedure call and return.
36033f810b2SJeff Kirsher * This provides all the benefits of macros, but with the
36133f810b2SJeff Kirsher * advantage of strict data type checking.
36233f810b2SJeff Kirsher */
36333f810b2SJeff Kirsher
dfx_writel(DFX_board_t * bp,int offset,u32 data)36433f810b2SJeff Kirsher static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
36533f810b2SJeff Kirsher {
36633f810b2SJeff Kirsher writel(data, bp->base.mem + offset);
36733f810b2SJeff Kirsher mb();
36833f810b2SJeff Kirsher }
36933f810b2SJeff Kirsher
dfx_outl(DFX_board_t * bp,int offset,u32 data)37033f810b2SJeff Kirsher static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
37133f810b2SJeff Kirsher {
37233f810b2SJeff Kirsher outl(data, bp->base.port + offset);
37333f810b2SJeff Kirsher }
37433f810b2SJeff Kirsher
dfx_port_write_long(DFX_board_t * bp,int offset,u32 data)37533f810b2SJeff Kirsher static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
37633f810b2SJeff Kirsher {
37733f810b2SJeff Kirsher struct device __maybe_unused *bdev = bp->bus_dev;
37833f810b2SJeff Kirsher
37933f810b2SJeff Kirsher if (dfx_use_mmio)
38033f810b2SJeff Kirsher dfx_writel(bp, offset, data);
38133f810b2SJeff Kirsher else
38233f810b2SJeff Kirsher dfx_outl(bp, offset, data);
38333f810b2SJeff Kirsher }
38433f810b2SJeff Kirsher
38533f810b2SJeff Kirsher
dfx_readl(DFX_board_t * bp,int offset,u32 * data)38633f810b2SJeff Kirsher static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
38733f810b2SJeff Kirsher {
38833f810b2SJeff Kirsher mb();
38933f810b2SJeff Kirsher *data = readl(bp->base.mem + offset);
39033f810b2SJeff Kirsher }
39133f810b2SJeff Kirsher
dfx_inl(DFX_board_t * bp,int offset,u32 * data)39233f810b2SJeff Kirsher static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
39333f810b2SJeff Kirsher {
39433f810b2SJeff Kirsher *data = inl(bp->base.port + offset);
39533f810b2SJeff Kirsher }
39633f810b2SJeff Kirsher
dfx_port_read_long(DFX_board_t * bp,int offset,u32 * data)39733f810b2SJeff Kirsher static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
39833f810b2SJeff Kirsher {
39933f810b2SJeff Kirsher struct device __maybe_unused *bdev = bp->bus_dev;
40033f810b2SJeff Kirsher
40133f810b2SJeff Kirsher if (dfx_use_mmio)
40233f810b2SJeff Kirsher dfx_readl(bp, offset, data);
40333f810b2SJeff Kirsher else
40433f810b2SJeff Kirsher dfx_inl(bp, offset, data);
40533f810b2SJeff Kirsher }
40633f810b2SJeff Kirsher
40733f810b2SJeff Kirsher
40833f810b2SJeff Kirsher /*
40933f810b2SJeff Kirsher * ================
41033f810b2SJeff Kirsher * = dfx_get_bars =
41133f810b2SJeff Kirsher * ================
41233f810b2SJeff Kirsher *
41333f810b2SJeff Kirsher * Overview:
4144d0438e5SMaciej W. Rozycki * Retrieves the address ranges used to access control and status
41533f810b2SJeff Kirsher * registers.
41633f810b2SJeff Kirsher *
41733f810b2SJeff Kirsher * Returns:
41833f810b2SJeff Kirsher * None
41933f810b2SJeff Kirsher *
42033f810b2SJeff Kirsher * Arguments:
421795e272eSMaciej W. Rozycki * bp - pointer to board information
4224d0438e5SMaciej W. Rozycki * bar_start - pointer to store the start addresses
4234d0438e5SMaciej W. Rozycki * bar_len - pointer to store the lengths of the areas
42433f810b2SJeff Kirsher *
42533f810b2SJeff Kirsher * Assumptions:
42633f810b2SJeff Kirsher * I am sure there are some.
42733f810b2SJeff Kirsher *
42833f810b2SJeff Kirsher * Side Effects:
42933f810b2SJeff Kirsher * None
43033f810b2SJeff Kirsher */
dfx_get_bars(DFX_board_t * bp,resource_size_t * bar_start,resource_size_t * bar_len)431795e272eSMaciej W. Rozycki static void dfx_get_bars(DFX_board_t *bp,
43233f810b2SJeff Kirsher resource_size_t *bar_start, resource_size_t *bar_len)
43333f810b2SJeff Kirsher {
434795e272eSMaciej W. Rozycki struct device *bdev = bp->bus_dev;
4355349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
43633f810b2SJeff Kirsher int dfx_bus_eisa = DFX_BUS_EISA(bdev);
43733f810b2SJeff Kirsher int dfx_bus_tc = DFX_BUS_TC(bdev);
43833f810b2SJeff Kirsher
43933f810b2SJeff Kirsher if (dfx_bus_pci) {
44033f810b2SJeff Kirsher int num = dfx_use_mmio ? 0 : 1;
44133f810b2SJeff Kirsher
4424d0438e5SMaciej W. Rozycki bar_start[0] = pci_resource_start(to_pci_dev(bdev), num);
4434d0438e5SMaciej W. Rozycki bar_len[0] = pci_resource_len(to_pci_dev(bdev), num);
4444d0438e5SMaciej W. Rozycki bar_start[2] = bar_start[1] = 0;
4454d0438e5SMaciej W. Rozycki bar_len[2] = bar_len[1] = 0;
44633f810b2SJeff Kirsher }
44733f810b2SJeff Kirsher if (dfx_bus_eisa) {
44833f810b2SJeff Kirsher unsigned long base_addr = to_eisa_device(bdev)->base_addr;
449fef85fc4SMaciej W. Rozycki resource_size_t bar_lo;
450fef85fc4SMaciej W. Rozycki resource_size_t bar_hi;
45133f810b2SJeff Kirsher
45233f810b2SJeff Kirsher if (dfx_use_mmio) {
453fef85fc4SMaciej W. Rozycki bar_lo = inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_2);
454fef85fc4SMaciej W. Rozycki bar_lo <<= 8;
455fef85fc4SMaciej W. Rozycki bar_lo |= inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_1);
456fef85fc4SMaciej W. Rozycki bar_lo <<= 8;
457fef85fc4SMaciej W. Rozycki bar_lo |= inb(base_addr + PI_ESIC_K_MEM_ADD_LO_CMP_0);
458fef85fc4SMaciej W. Rozycki bar_lo <<= 8;
4594d0438e5SMaciej W. Rozycki bar_start[0] = bar_lo;
460fef85fc4SMaciej W. Rozycki bar_hi = inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_2);
461fef85fc4SMaciej W. Rozycki bar_hi <<= 8;
462fef85fc4SMaciej W. Rozycki bar_hi |= inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_1);
463fef85fc4SMaciej W. Rozycki bar_hi <<= 8;
464fef85fc4SMaciej W. Rozycki bar_hi |= inb(base_addr + PI_ESIC_K_MEM_ADD_HI_CMP_0);
465fef85fc4SMaciej W. Rozycki bar_hi <<= 8;
4664d0438e5SMaciej W. Rozycki bar_len[0] = ((bar_hi - bar_lo) | PI_MEM_ADD_MASK_M) +
4674d0438e5SMaciej W. Rozycki 1;
46833f810b2SJeff Kirsher } else {
4694d0438e5SMaciej W. Rozycki bar_start[0] = base_addr;
4704d0438e5SMaciej W. Rozycki bar_len[0] = PI_ESIC_K_CSR_IO_LEN;
47133f810b2SJeff Kirsher }
4724d0438e5SMaciej W. Rozycki bar_start[1] = base_addr + PI_DEFEA_K_BURST_HOLDOFF;
4734d0438e5SMaciej W. Rozycki bar_len[1] = PI_ESIC_K_BURST_HOLDOFF_LEN;
4744d0438e5SMaciej W. Rozycki bar_start[2] = base_addr + PI_ESIC_K_ESIC_CSR;
4754d0438e5SMaciej W. Rozycki bar_len[2] = PI_ESIC_K_ESIC_CSR_LEN;
47633f810b2SJeff Kirsher }
47733f810b2SJeff Kirsher if (dfx_bus_tc) {
4784d0438e5SMaciej W. Rozycki bar_start[0] = to_tc_dev(bdev)->resource.start +
47933f810b2SJeff Kirsher PI_TC_K_CSR_OFFSET;
4804d0438e5SMaciej W. Rozycki bar_len[0] = PI_TC_K_CSR_LEN;
4814d0438e5SMaciej W. Rozycki bar_start[2] = bar_start[1] = 0;
4824d0438e5SMaciej W. Rozycki bar_len[2] = bar_len[1] = 0;
48333f810b2SJeff Kirsher }
48433f810b2SJeff Kirsher }
48533f810b2SJeff Kirsher
48633f810b2SJeff Kirsher static const struct net_device_ops dfx_netdev_ops = {
48733f810b2SJeff Kirsher .ndo_open = dfx_open,
48833f810b2SJeff Kirsher .ndo_stop = dfx_close,
48933f810b2SJeff Kirsher .ndo_start_xmit = dfx_xmt_queue_pkt,
49033f810b2SJeff Kirsher .ndo_get_stats = dfx_ctl_get_stats,
49133f810b2SJeff Kirsher .ndo_set_rx_mode = dfx_ctl_set_multicast_list,
49233f810b2SJeff Kirsher .ndo_set_mac_address = dfx_ctl_set_mac_address,
49333f810b2SJeff Kirsher };
49433f810b2SJeff Kirsher
dfx_register_res_err(const char * print_name,bool mmio,unsigned long start,unsigned long len)495f626ca68SMaciej W. Rozycki static void dfx_register_res_err(const char *print_name, bool mmio,
496f626ca68SMaciej W. Rozycki unsigned long start, unsigned long len)
497f626ca68SMaciej W. Rozycki {
498f626ca68SMaciej W. Rozycki pr_err("%s: Cannot reserve %s resource 0x%lx @ 0x%lx, aborting\n",
499f626ca68SMaciej W. Rozycki print_name, mmio ? "MMIO" : "I/O", len, start);
500f626ca68SMaciej W. Rozycki }
501f626ca68SMaciej W. Rozycki
50233f810b2SJeff Kirsher /*
50333f810b2SJeff Kirsher * ================
50433f810b2SJeff Kirsher * = dfx_register =
50533f810b2SJeff Kirsher * ================
50633f810b2SJeff Kirsher *
50733f810b2SJeff Kirsher * Overview:
50833f810b2SJeff Kirsher * Initializes a supported FDDI controller
50933f810b2SJeff Kirsher *
51033f810b2SJeff Kirsher * Returns:
51133f810b2SJeff Kirsher * Condition code
51233f810b2SJeff Kirsher *
51333f810b2SJeff Kirsher * Arguments:
51433f810b2SJeff Kirsher * bdev - pointer to device information
51533f810b2SJeff Kirsher *
51633f810b2SJeff Kirsher * Functional Description:
51733f810b2SJeff Kirsher *
51833f810b2SJeff Kirsher * Return Codes:
51933f810b2SJeff Kirsher * 0 - This device (fddi0, fddi1, etc) configured successfully
52033f810b2SJeff Kirsher * -EBUSY - Failed to get resources, or dfx_driver_init failed.
52133f810b2SJeff Kirsher *
52233f810b2SJeff Kirsher * Assumptions:
52333f810b2SJeff Kirsher * It compiles so it should work :-( (PCI cards do :-)
52433f810b2SJeff Kirsher *
52533f810b2SJeff Kirsher * Side Effects:
52633f810b2SJeff Kirsher * Device structures for FDDI adapters (fddi0, fddi1, etc) are
52733f810b2SJeff Kirsher * initialized and the board resources are read and stored in
52833f810b2SJeff Kirsher * the device structure.
52933f810b2SJeff Kirsher */
dfx_register(struct device * bdev)530c354dfc3SBill Pemberton static int dfx_register(struct device *bdev)
53133f810b2SJeff Kirsher {
53233f810b2SJeff Kirsher static int version_disp;
5335349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
534fef85fc4SMaciej W. Rozycki int dfx_bus_eisa = DFX_BUS_EISA(bdev);
53533f810b2SJeff Kirsher const char *print_name = dev_name(bdev);
53633f810b2SJeff Kirsher struct net_device *dev;
53733f810b2SJeff Kirsher DFX_board_t *bp; /* board pointer */
53862f2aaabSSudip Mukherjee resource_size_t bar_start[3] = {0}; /* pointers to ports */
53962f2aaabSSudip Mukherjee resource_size_t bar_len[3] = {0}; /* resource length */
54033f810b2SJeff Kirsher int alloc_size; /* total buffer size used */
54133f810b2SJeff Kirsher struct resource *region;
54233f810b2SJeff Kirsher int err = 0;
54333f810b2SJeff Kirsher
54433f810b2SJeff Kirsher if (!version_disp) { /* display version info if adapter is found */
54533f810b2SJeff Kirsher version_disp = 1; /* set display flag to TRUE so that */
54633f810b2SJeff Kirsher printk(version); /* we only display this string ONCE */
54733f810b2SJeff Kirsher }
54833f810b2SJeff Kirsher
54933f810b2SJeff Kirsher dev = alloc_fddidev(sizeof(*bp));
55033f810b2SJeff Kirsher if (!dev) {
55133f810b2SJeff Kirsher printk(KERN_ERR "%s: Unable to allocate fddidev, aborting\n",
55233f810b2SJeff Kirsher print_name);
55333f810b2SJeff Kirsher return -ENOMEM;
55433f810b2SJeff Kirsher }
55533f810b2SJeff Kirsher
55633f810b2SJeff Kirsher /* Enable PCI device. */
557a65da0c3SMaciej W. Rozycki if (dfx_bus_pci) {
558a65da0c3SMaciej W. Rozycki err = pci_enable_device(to_pci_dev(bdev));
559a65da0c3SMaciej W. Rozycki if (err) {
560a65da0c3SMaciej W. Rozycki pr_err("%s: Cannot enable PCI device, aborting\n",
56133f810b2SJeff Kirsher print_name);
56233f810b2SJeff Kirsher goto err_out;
56333f810b2SJeff Kirsher }
564a65da0c3SMaciej W. Rozycki }
56533f810b2SJeff Kirsher
56633f810b2SJeff Kirsher SET_NETDEV_DEV(dev, bdev);
56733f810b2SJeff Kirsher
56833f810b2SJeff Kirsher bp = netdev_priv(dev);
56933f810b2SJeff Kirsher bp->bus_dev = bdev;
57033f810b2SJeff Kirsher dev_set_drvdata(bdev, dev);
57133f810b2SJeff Kirsher
572795e272eSMaciej W. Rozycki bp->mmio = true;
573795e272eSMaciej W. Rozycki
574795e272eSMaciej W. Rozycki dfx_get_bars(bp, bar_start, bar_len);
575f626ca68SMaciej W. Rozycki if (bar_len[0] == 0 ||
576f626ca68SMaciej W. Rozycki (dfx_bus_eisa && dfx_use_mmio && bar_start[0] == 0)) {
577795e272eSMaciej W. Rozycki bp->mmio = false;
578795e272eSMaciej W. Rozycki dfx_get_bars(bp, bar_start, bar_len);
579fef85fc4SMaciej W. Rozycki }
58033f810b2SJeff Kirsher
581795e272eSMaciej W. Rozycki if (dfx_use_mmio) {
5824d0438e5SMaciej W. Rozycki region = request_mem_region(bar_start[0], bar_len[0],
5834e052626SMaciej W. Rozycki bdev->driver->name);
584795e272eSMaciej W. Rozycki if (!region && (dfx_bus_eisa || dfx_bus_pci)) {
585795e272eSMaciej W. Rozycki bp->mmio = false;
586795e272eSMaciej W. Rozycki dfx_get_bars(bp, bar_start, bar_len);
587795e272eSMaciej W. Rozycki }
588795e272eSMaciej W. Rozycki }
589795e272eSMaciej W. Rozycki if (!dfx_use_mmio)
5904e052626SMaciej W. Rozycki region = request_region(bar_start[0], bar_len[0],
5914e052626SMaciej W. Rozycki bdev->driver->name);
59233f810b2SJeff Kirsher if (!region) {
593f626ca68SMaciej W. Rozycki dfx_register_res_err(print_name, dfx_use_mmio,
594f626ca68SMaciej W. Rozycki bar_start[0], bar_len[0]);
59533f810b2SJeff Kirsher err = -EBUSY;
59633f810b2SJeff Kirsher goto err_out_disable;
59733f810b2SJeff Kirsher }
5984d0438e5SMaciej W. Rozycki if (bar_start[1] != 0) {
5994e052626SMaciej W. Rozycki region = request_region(bar_start[1], bar_len[1],
6004e052626SMaciej W. Rozycki bdev->driver->name);
6014d0438e5SMaciej W. Rozycki if (!region) {
602f626ca68SMaciej W. Rozycki dfx_register_res_err(print_name, 0,
603f626ca68SMaciej W. Rozycki bar_start[1], bar_len[1]);
6044d0438e5SMaciej W. Rozycki err = -EBUSY;
6054d0438e5SMaciej W. Rozycki goto err_out_csr_region;
6064d0438e5SMaciej W. Rozycki }
6074d0438e5SMaciej W. Rozycki }
6084d0438e5SMaciej W. Rozycki if (bar_start[2] != 0) {
6094e052626SMaciej W. Rozycki region = request_region(bar_start[2], bar_len[2],
6104e052626SMaciej W. Rozycki bdev->driver->name);
6114d0438e5SMaciej W. Rozycki if (!region) {
612f626ca68SMaciej W. Rozycki dfx_register_res_err(print_name, 0,
613f626ca68SMaciej W. Rozycki bar_start[2], bar_len[2]);
6144d0438e5SMaciej W. Rozycki err = -EBUSY;
6154d0438e5SMaciej W. Rozycki goto err_out_bh_region;
6164d0438e5SMaciej W. Rozycki }
6174d0438e5SMaciej W. Rozycki }
61833f810b2SJeff Kirsher
61933f810b2SJeff Kirsher /* Set up I/O base address. */
62033f810b2SJeff Kirsher if (dfx_use_mmio) {
6214bdc0d67SChristoph Hellwig bp->base.mem = ioremap(bar_start[0], bar_len[0]);
62233f810b2SJeff Kirsher if (!bp->base.mem) {
62333f810b2SJeff Kirsher printk(KERN_ERR "%s: Cannot map MMIO\n", print_name);
62433f810b2SJeff Kirsher err = -ENOMEM;
6254d0438e5SMaciej W. Rozycki goto err_out_esic_region;
62633f810b2SJeff Kirsher }
62733f810b2SJeff Kirsher } else {
6284d0438e5SMaciej W. Rozycki bp->base.port = bar_start[0];
6294d0438e5SMaciej W. Rozycki dev->base_addr = bar_start[0];
63033f810b2SJeff Kirsher }
63133f810b2SJeff Kirsher
63233f810b2SJeff Kirsher /* Initialize new device structure */
63333f810b2SJeff Kirsher dev->netdev_ops = &dfx_netdev_ops;
63433f810b2SJeff Kirsher
63533f810b2SJeff Kirsher if (dfx_bus_pci)
63633f810b2SJeff Kirsher pci_set_master(to_pci_dev(bdev));
63733f810b2SJeff Kirsher
6384d0438e5SMaciej W. Rozycki if (dfx_driver_init(dev, print_name, bar_start[0]) != DFX_K_SUCCESS) {
63933f810b2SJeff Kirsher err = -ENODEV;
64033f810b2SJeff Kirsher goto err_out_unmap;
64133f810b2SJeff Kirsher }
64233f810b2SJeff Kirsher
64333f810b2SJeff Kirsher err = register_netdev(dev);
64433f810b2SJeff Kirsher if (err)
64533f810b2SJeff Kirsher goto err_out_kfree;
64633f810b2SJeff Kirsher
64733f810b2SJeff Kirsher printk("%s: registered as %s\n", print_name, dev->name);
64833f810b2SJeff Kirsher return 0;
64933f810b2SJeff Kirsher
65033f810b2SJeff Kirsher err_out_kfree:
65133f810b2SJeff Kirsher alloc_size = sizeof(PI_DESCR_BLOCK) +
65233f810b2SJeff Kirsher PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
65333f810b2SJeff Kirsher #ifndef DYNAMIC_BUFFERS
65433f810b2SJeff Kirsher (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
65533f810b2SJeff Kirsher #endif
65633f810b2SJeff Kirsher sizeof(PI_CONSUMER_BLOCK) +
65733f810b2SJeff Kirsher (PI_ALIGN_K_DESC_BLK - 1);
65833f810b2SJeff Kirsher if (bp->kmalloced)
65933f810b2SJeff Kirsher dma_free_coherent(bdev, alloc_size,
66033f810b2SJeff Kirsher bp->kmalloced, bp->kmalloced_dma);
66133f810b2SJeff Kirsher
66233f810b2SJeff Kirsher err_out_unmap:
66333f810b2SJeff Kirsher if (dfx_use_mmio)
66433f810b2SJeff Kirsher iounmap(bp->base.mem);
66533f810b2SJeff Kirsher
6664d0438e5SMaciej W. Rozycki err_out_esic_region:
6674d0438e5SMaciej W. Rozycki if (bar_start[2] != 0)
6684d0438e5SMaciej W. Rozycki release_region(bar_start[2], bar_len[2]);
6694d0438e5SMaciej W. Rozycki
6704d0438e5SMaciej W. Rozycki err_out_bh_region:
6714d0438e5SMaciej W. Rozycki if (bar_start[1] != 0)
6724d0438e5SMaciej W. Rozycki release_region(bar_start[1], bar_len[1]);
6734d0438e5SMaciej W. Rozycki
6744d0438e5SMaciej W. Rozycki err_out_csr_region:
67533f810b2SJeff Kirsher if (dfx_use_mmio)
6764d0438e5SMaciej W. Rozycki release_mem_region(bar_start[0], bar_len[0]);
67733f810b2SJeff Kirsher else
6784d0438e5SMaciej W. Rozycki release_region(bar_start[0], bar_len[0]);
67933f810b2SJeff Kirsher
68033f810b2SJeff Kirsher err_out_disable:
68133f810b2SJeff Kirsher if (dfx_bus_pci)
68233f810b2SJeff Kirsher pci_disable_device(to_pci_dev(bdev));
68333f810b2SJeff Kirsher
68433f810b2SJeff Kirsher err_out:
68533f810b2SJeff Kirsher free_netdev(dev);
68633f810b2SJeff Kirsher return err;
68733f810b2SJeff Kirsher }
68833f810b2SJeff Kirsher
68933f810b2SJeff Kirsher
69033f810b2SJeff Kirsher /*
69133f810b2SJeff Kirsher * ================
69233f810b2SJeff Kirsher * = dfx_bus_init =
69333f810b2SJeff Kirsher * ================
69433f810b2SJeff Kirsher *
69533f810b2SJeff Kirsher * Overview:
69633f810b2SJeff Kirsher * Initializes the bus-specific controller logic.
69733f810b2SJeff Kirsher *
69833f810b2SJeff Kirsher * Returns:
69933f810b2SJeff Kirsher * None
70033f810b2SJeff Kirsher *
70133f810b2SJeff Kirsher * Arguments:
70233f810b2SJeff Kirsher * dev - pointer to device information
70333f810b2SJeff Kirsher *
70433f810b2SJeff Kirsher * Functional Description:
70533f810b2SJeff Kirsher * Determine and save adapter IRQ in device table,
70633f810b2SJeff Kirsher * then perform bus-specific logic initialization.
70733f810b2SJeff Kirsher *
70833f810b2SJeff Kirsher * Return Codes:
70933f810b2SJeff Kirsher * None
71033f810b2SJeff Kirsher *
71133f810b2SJeff Kirsher * Assumptions:
71233f810b2SJeff Kirsher * bp->base has already been set with the proper
71333f810b2SJeff Kirsher * base I/O address for this device.
71433f810b2SJeff Kirsher *
71533f810b2SJeff Kirsher * Side Effects:
71633f810b2SJeff Kirsher * Interrupts are enabled at the adapter bus-specific logic.
71733f810b2SJeff Kirsher * Note: Interrupts at the DMA engine (PDQ chip) are not
71833f810b2SJeff Kirsher * enabled yet.
71933f810b2SJeff Kirsher */
72033f810b2SJeff Kirsher
dfx_bus_init(struct net_device * dev)721c354dfc3SBill Pemberton static void dfx_bus_init(struct net_device *dev)
72233f810b2SJeff Kirsher {
72333f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
72433f810b2SJeff Kirsher struct device *bdev = bp->bus_dev;
7255349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
72633f810b2SJeff Kirsher int dfx_bus_eisa = DFX_BUS_EISA(bdev);
72733f810b2SJeff Kirsher int dfx_bus_tc = DFX_BUS_TC(bdev);
72833f810b2SJeff Kirsher u8 val;
72933f810b2SJeff Kirsher
73033f810b2SJeff Kirsher DBG_printk("In dfx_bus_init...\n");
73133f810b2SJeff Kirsher
73233f810b2SJeff Kirsher /* Initialize a pointer back to the net_device struct */
73333f810b2SJeff Kirsher bp->dev = dev;
73433f810b2SJeff Kirsher
73533f810b2SJeff Kirsher /* Initialize adapter based on bus type */
73633f810b2SJeff Kirsher
73733f810b2SJeff Kirsher if (dfx_bus_tc)
73833f810b2SJeff Kirsher dev->irq = to_tc_dev(bdev)->interrupt;
73933f810b2SJeff Kirsher if (dfx_bus_eisa) {
74033f810b2SJeff Kirsher unsigned long base_addr = to_eisa_device(bdev)->base_addr;
74133f810b2SJeff Kirsher
742b98dfaf2SMaciej W. Rozycki /* Disable the board before fiddling with the decoders. */
743b98dfaf2SMaciej W. Rozycki outb(0, base_addr + PI_ESIC_K_SLOT_CNTRL);
744b98dfaf2SMaciej W. Rozycki
74533f810b2SJeff Kirsher /* Get the interrupt level from the ESIC chip. */
74633f810b2SJeff Kirsher val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
74733f810b2SJeff Kirsher val &= PI_CONFIG_STAT_0_M_IRQ;
74833f810b2SJeff Kirsher val >>= PI_CONFIG_STAT_0_V_IRQ;
74933f810b2SJeff Kirsher
75033f810b2SJeff Kirsher switch (val) {
75133f810b2SJeff Kirsher case PI_CONFIG_STAT_0_IRQ_K_9:
75233f810b2SJeff Kirsher dev->irq = 9;
75333f810b2SJeff Kirsher break;
75433f810b2SJeff Kirsher
75533f810b2SJeff Kirsher case PI_CONFIG_STAT_0_IRQ_K_10:
75633f810b2SJeff Kirsher dev->irq = 10;
75733f810b2SJeff Kirsher break;
75833f810b2SJeff Kirsher
75933f810b2SJeff Kirsher case PI_CONFIG_STAT_0_IRQ_K_11:
76033f810b2SJeff Kirsher dev->irq = 11;
76133f810b2SJeff Kirsher break;
76233f810b2SJeff Kirsher
76333f810b2SJeff Kirsher case PI_CONFIG_STAT_0_IRQ_K_15:
76433f810b2SJeff Kirsher dev->irq = 15;
76533f810b2SJeff Kirsher break;
76633f810b2SJeff Kirsher }
76733f810b2SJeff Kirsher
76833f810b2SJeff Kirsher /*
769fef85fc4SMaciej W. Rozycki * Enable memory decoding (MEMCS1) and/or port decoding
77033f810b2SJeff Kirsher * (IOCS1/IOCS0) as appropriate in Function Control
771fef85fc4SMaciej W. Rozycki * Register. MEMCS1 or IOCS0 is used for PDQ registers,
772fef85fc4SMaciej W. Rozycki * taking 16 32-bit words, while IOCS1 is used for the
773fef85fc4SMaciej W. Rozycki * Burst Holdoff register, taking a single 32-bit word
774fef85fc4SMaciej W. Rozycki * only. We use the slot-specific I/O range as per the
775fef85fc4SMaciej W. Rozycki * ESIC spec, that is set bits 15:12 in the mask registers
776fef85fc4SMaciej W. Rozycki * to mask them out.
77733f810b2SJeff Kirsher */
77833f810b2SJeff Kirsher
77933f810b2SJeff Kirsher /* Set the decode range of the board. */
780b98dfaf2SMaciej W. Rozycki val = 0;
7818a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_0_1);
782b98dfaf2SMaciej W. Rozycki val = PI_DEFEA_K_CSR_IO;
783b98dfaf2SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_0_0);
784b98dfaf2SMaciej W. Rozycki
785b98dfaf2SMaciej W. Rozycki val = PI_IO_CMP_M_SLOT;
7868a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_0_1);
787b98dfaf2SMaciej W. Rozycki val = (PI_ESIC_K_CSR_IO_LEN - 1) & ~3;
788b98dfaf2SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_0_0);
789b98dfaf2SMaciej W. Rozycki
790b98dfaf2SMaciej W. Rozycki val = 0;
791b98dfaf2SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_1_1);
792b98dfaf2SMaciej W. Rozycki val = PI_DEFEA_K_BURST_HOLDOFF;
793b98dfaf2SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_CMP_1_0);
794b98dfaf2SMaciej W. Rozycki
795b98dfaf2SMaciej W. Rozycki val = PI_IO_CMP_M_SLOT;
7968a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_1_1);
797b98dfaf2SMaciej W. Rozycki val = (PI_ESIC_K_BURST_HOLDOFF_LEN - 1) & ~3;
798b98dfaf2SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_ADD_MASK_1_0);
79933f810b2SJeff Kirsher
80033f810b2SJeff Kirsher /* Enable the decoders. */
801fef85fc4SMaciej W. Rozycki val = PI_FUNCTION_CNTRL_M_IOCS1;
80233f810b2SJeff Kirsher if (dfx_use_mmio)
803fef85fc4SMaciej W. Rozycki val |= PI_FUNCTION_CNTRL_M_MEMCS1;
804fef85fc4SMaciej W. Rozycki else
805fef85fc4SMaciej W. Rozycki val |= PI_FUNCTION_CNTRL_M_IOCS0;
8068a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_FUNCTION_CNTRL);
80733f810b2SJeff Kirsher
80833f810b2SJeff Kirsher /*
80933f810b2SJeff Kirsher * Enable access to the rest of the module
81033f810b2SJeff Kirsher * (including PDQ and packet memory).
81133f810b2SJeff Kirsher */
81233f810b2SJeff Kirsher val = PI_SLOT_CNTRL_M_ENB;
8138a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_SLOT_CNTRL);
81433f810b2SJeff Kirsher
81533f810b2SJeff Kirsher /*
81633f810b2SJeff Kirsher * Map PDQ registers into memory or port space. This is
81733f810b2SJeff Kirsher * done with a bit in the Burst Holdoff register.
81833f810b2SJeff Kirsher */
81933f810b2SJeff Kirsher val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
82033f810b2SJeff Kirsher if (dfx_use_mmio)
821b1a6d3ecSMaciej W. Rozycki val |= PI_BURST_HOLDOFF_M_MEM_MAP;
82233f810b2SJeff Kirsher else
823b1a6d3ecSMaciej W. Rozycki val &= ~PI_BURST_HOLDOFF_M_MEM_MAP;
8248a189f12SMaciej W. Rozycki outb(val, base_addr + PI_DEFEA_K_BURST_HOLDOFF);
82533f810b2SJeff Kirsher
82633f810b2SJeff Kirsher /* Enable interrupts at EISA bus interface chip (ESIC) */
82733f810b2SJeff Kirsher val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
82833f810b2SJeff Kirsher val |= PI_CONFIG_STAT_0_M_INT_ENB;
8298a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
83033f810b2SJeff Kirsher }
83133f810b2SJeff Kirsher if (dfx_bus_pci) {
83233f810b2SJeff Kirsher struct pci_dev *pdev = to_pci_dev(bdev);
83333f810b2SJeff Kirsher
83433f810b2SJeff Kirsher /* Get the interrupt level from the PCI Configuration Table */
83533f810b2SJeff Kirsher
83633f810b2SJeff Kirsher dev->irq = pdev->irq;
83733f810b2SJeff Kirsher
83833f810b2SJeff Kirsher /* Check Latency Timer and set if less than minimal */
83933f810b2SJeff Kirsher
84033f810b2SJeff Kirsher pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
84133f810b2SJeff Kirsher if (val < PFI_K_LAT_TIMER_MIN) {
84233f810b2SJeff Kirsher val = PFI_K_LAT_TIMER_DEF;
84333f810b2SJeff Kirsher pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
84433f810b2SJeff Kirsher }
84533f810b2SJeff Kirsher
84633f810b2SJeff Kirsher /* Enable interrupts at PCI bus interface chip (PFI) */
84733f810b2SJeff Kirsher val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
84833f810b2SJeff Kirsher dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
84933f810b2SJeff Kirsher }
85033f810b2SJeff Kirsher }
85133f810b2SJeff Kirsher
85233f810b2SJeff Kirsher /*
85333f810b2SJeff Kirsher * ==================
85433f810b2SJeff Kirsher * = dfx_bus_uninit =
85533f810b2SJeff Kirsher * ==================
85633f810b2SJeff Kirsher *
85733f810b2SJeff Kirsher * Overview:
85833f810b2SJeff Kirsher * Uninitializes the bus-specific controller logic.
85933f810b2SJeff Kirsher *
86033f810b2SJeff Kirsher * Returns:
86133f810b2SJeff Kirsher * None
86233f810b2SJeff Kirsher *
86333f810b2SJeff Kirsher * Arguments:
86433f810b2SJeff Kirsher * dev - pointer to device information
86533f810b2SJeff Kirsher *
86633f810b2SJeff Kirsher * Functional Description:
86733f810b2SJeff Kirsher * Perform bus-specific logic uninitialization.
86833f810b2SJeff Kirsher *
86933f810b2SJeff Kirsher * Return Codes:
87033f810b2SJeff Kirsher * None
87133f810b2SJeff Kirsher *
87233f810b2SJeff Kirsher * Assumptions:
87333f810b2SJeff Kirsher * bp->base has already been set with the proper
87433f810b2SJeff Kirsher * base I/O address for this device.
87533f810b2SJeff Kirsher *
87633f810b2SJeff Kirsher * Side Effects:
87733f810b2SJeff Kirsher * Interrupts are disabled at the adapter bus-specific logic.
87833f810b2SJeff Kirsher */
87933f810b2SJeff Kirsher
dfx_bus_uninit(struct net_device * dev)880c354dfc3SBill Pemberton static void dfx_bus_uninit(struct net_device *dev)
88133f810b2SJeff Kirsher {
88233f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
88333f810b2SJeff Kirsher struct device *bdev = bp->bus_dev;
8845349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
88533f810b2SJeff Kirsher int dfx_bus_eisa = DFX_BUS_EISA(bdev);
88633f810b2SJeff Kirsher u8 val;
88733f810b2SJeff Kirsher
88833f810b2SJeff Kirsher DBG_printk("In dfx_bus_uninit...\n");
88933f810b2SJeff Kirsher
89033f810b2SJeff Kirsher /* Uninitialize adapter based on bus type */
89133f810b2SJeff Kirsher
89233f810b2SJeff Kirsher if (dfx_bus_eisa) {
89333f810b2SJeff Kirsher unsigned long base_addr = to_eisa_device(bdev)->base_addr;
89433f810b2SJeff Kirsher
89533f810b2SJeff Kirsher /* Disable interrupts at EISA bus interface chip (ESIC) */
89633f810b2SJeff Kirsher val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
89733f810b2SJeff Kirsher val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
8988a189f12SMaciej W. Rozycki outb(val, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
8996a931423SMaciej W. Rozycki
9006a931423SMaciej W. Rozycki /* Disable the board. */
9016a931423SMaciej W. Rozycki outb(0, base_addr + PI_ESIC_K_SLOT_CNTRL);
9026a931423SMaciej W. Rozycki
9036a931423SMaciej W. Rozycki /* Disable memory and port decoders. */
9046a931423SMaciej W. Rozycki outb(0, base_addr + PI_ESIC_K_FUNCTION_CNTRL);
90533f810b2SJeff Kirsher }
90633f810b2SJeff Kirsher if (dfx_bus_pci) {
90733f810b2SJeff Kirsher /* Disable interrupts at PCI bus interface chip (PFI) */
90833f810b2SJeff Kirsher dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
90933f810b2SJeff Kirsher }
91033f810b2SJeff Kirsher }
91133f810b2SJeff Kirsher
91233f810b2SJeff Kirsher
91333f810b2SJeff Kirsher /*
91433f810b2SJeff Kirsher * ========================
91533f810b2SJeff Kirsher * = dfx_bus_config_check =
91633f810b2SJeff Kirsher * ========================
91733f810b2SJeff Kirsher *
91833f810b2SJeff Kirsher * Overview:
91933f810b2SJeff Kirsher * Checks the configuration (burst size, full-duplex, etc.) If any parameters
92033f810b2SJeff Kirsher * are illegal, then this routine will set new defaults.
92133f810b2SJeff Kirsher *
92233f810b2SJeff Kirsher * Returns:
92333f810b2SJeff Kirsher * None
92433f810b2SJeff Kirsher *
92533f810b2SJeff Kirsher * Arguments:
92633f810b2SJeff Kirsher * bp - pointer to board information
92733f810b2SJeff Kirsher *
92833f810b2SJeff Kirsher * Functional Description:
92933f810b2SJeff Kirsher * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
93033f810b2SJeff Kirsher * PDQ, and all FDDI PCI controllers, all values are legal.
93133f810b2SJeff Kirsher *
93233f810b2SJeff Kirsher * Return Codes:
93333f810b2SJeff Kirsher * None
93433f810b2SJeff Kirsher *
93533f810b2SJeff Kirsher * Assumptions:
93633f810b2SJeff Kirsher * dfx_adap_init has NOT been called yet so burst size and other items have
93733f810b2SJeff Kirsher * not been set.
93833f810b2SJeff Kirsher *
93933f810b2SJeff Kirsher * Side Effects:
94033f810b2SJeff Kirsher * None
94133f810b2SJeff Kirsher */
94233f810b2SJeff Kirsher
dfx_bus_config_check(DFX_board_t * bp)943c354dfc3SBill Pemberton static void dfx_bus_config_check(DFX_board_t *bp)
94433f810b2SJeff Kirsher {
94533f810b2SJeff Kirsher struct device __maybe_unused *bdev = bp->bus_dev;
94633f810b2SJeff Kirsher int dfx_bus_eisa = DFX_BUS_EISA(bdev);
94733f810b2SJeff Kirsher int status; /* return code from adapter port control call */
94833f810b2SJeff Kirsher u32 host_data; /* LW data returned from port control call */
94933f810b2SJeff Kirsher
95033f810b2SJeff Kirsher DBG_printk("In dfx_bus_config_check...\n");
95133f810b2SJeff Kirsher
95233f810b2SJeff Kirsher /* Configuration check only valid for EISA adapter */
95333f810b2SJeff Kirsher
95433f810b2SJeff Kirsher if (dfx_bus_eisa) {
95533f810b2SJeff Kirsher /*
95633f810b2SJeff Kirsher * First check if revision 2 EISA controller. Rev. 1 cards used
95733f810b2SJeff Kirsher * PDQ revision B, so no workaround needed in this case. Rev. 3
95833f810b2SJeff Kirsher * cards used PDQ revision E, so no workaround needed in this
95933f810b2SJeff Kirsher * case, either. Only Rev. 2 cards used either Rev. D or E
96033f810b2SJeff Kirsher * chips, so we must verify the chip revision on Rev. 2 cards.
96133f810b2SJeff Kirsher */
96233f810b2SJeff Kirsher if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
96333f810b2SJeff Kirsher /*
96433f810b2SJeff Kirsher * Revision 2 FDDI EISA controller found,
96533f810b2SJeff Kirsher * so let's check PDQ revision of adapter.
96633f810b2SJeff Kirsher */
96733f810b2SJeff Kirsher status = dfx_hw_port_ctrl_req(bp,
96833f810b2SJeff Kirsher PI_PCTRL_M_SUB_CMD,
96933f810b2SJeff Kirsher PI_SUB_CMD_K_PDQ_REV_GET,
97033f810b2SJeff Kirsher 0,
97133f810b2SJeff Kirsher &host_data);
97233f810b2SJeff Kirsher if ((status != DFX_K_SUCCESS) || (host_data == 2))
97333f810b2SJeff Kirsher {
97433f810b2SJeff Kirsher /*
97533f810b2SJeff Kirsher * Either we couldn't determine the PDQ revision, or
97633f810b2SJeff Kirsher * we determined that it is at revision D. In either case,
97733f810b2SJeff Kirsher * we need to implement the workaround.
97833f810b2SJeff Kirsher */
97933f810b2SJeff Kirsher
98033f810b2SJeff Kirsher /* Ensure that the burst size is set to 8 longwords or less */
98133f810b2SJeff Kirsher
98233f810b2SJeff Kirsher switch (bp->burst_size)
98333f810b2SJeff Kirsher {
98433f810b2SJeff Kirsher case PI_PDATA_B_DMA_BURST_SIZE_32:
98533f810b2SJeff Kirsher case PI_PDATA_B_DMA_BURST_SIZE_16:
98633f810b2SJeff Kirsher bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
98733f810b2SJeff Kirsher break;
98833f810b2SJeff Kirsher
98933f810b2SJeff Kirsher default:
99033f810b2SJeff Kirsher break;
99133f810b2SJeff Kirsher }
99233f810b2SJeff Kirsher
99333f810b2SJeff Kirsher /* Ensure that full-duplex mode is not enabled */
99433f810b2SJeff Kirsher
99533f810b2SJeff Kirsher bp->full_duplex_enb = PI_SNMP_K_FALSE;
99633f810b2SJeff Kirsher }
99733f810b2SJeff Kirsher }
99833f810b2SJeff Kirsher }
99933f810b2SJeff Kirsher }
100033f810b2SJeff Kirsher
100133f810b2SJeff Kirsher
100233f810b2SJeff Kirsher /*
100333f810b2SJeff Kirsher * ===================
100433f810b2SJeff Kirsher * = dfx_driver_init =
100533f810b2SJeff Kirsher * ===================
100633f810b2SJeff Kirsher *
100733f810b2SJeff Kirsher * Overview:
100833f810b2SJeff Kirsher * Initializes remaining adapter board structure information
100933f810b2SJeff Kirsher * and makes sure adapter is in a safe state prior to dfx_open().
101033f810b2SJeff Kirsher *
101133f810b2SJeff Kirsher * Returns:
101233f810b2SJeff Kirsher * Condition code
101333f810b2SJeff Kirsher *
101433f810b2SJeff Kirsher * Arguments:
101533f810b2SJeff Kirsher * dev - pointer to device information
101633f810b2SJeff Kirsher * print_name - printable device name
101733f810b2SJeff Kirsher *
101833f810b2SJeff Kirsher * Functional Description:
101933f810b2SJeff Kirsher * This function allocates additional resources such as the host memory
102033f810b2SJeff Kirsher * blocks needed by the adapter (eg. descriptor and consumer blocks).
102133f810b2SJeff Kirsher * Remaining bus initialization steps are also completed. The adapter
102233f810b2SJeff Kirsher * is also reset so that it is in the DMA_UNAVAILABLE state. The OS
102333f810b2SJeff Kirsher * must call dfx_open() to open the adapter and bring it on-line.
102433f810b2SJeff Kirsher *
102533f810b2SJeff Kirsher * Return Codes:
102633f810b2SJeff Kirsher * DFX_K_SUCCESS - initialization succeeded
102733f810b2SJeff Kirsher * DFX_K_FAILURE - initialization failed - could not allocate memory
102833f810b2SJeff Kirsher * or read adapter MAC address
102933f810b2SJeff Kirsher *
103033f810b2SJeff Kirsher * Assumptions:
1031b38bcb41SCai Huoqing * Memory allocated from dma_alloc_coherent() call is physically
103233f810b2SJeff Kirsher * contiguous, locked memory.
103333f810b2SJeff Kirsher *
103433f810b2SJeff Kirsher * Side Effects:
103533f810b2SJeff Kirsher * Adapter is reset and should be in DMA_UNAVAILABLE state before
103633f810b2SJeff Kirsher * returning from this routine.
103733f810b2SJeff Kirsher */
103833f810b2SJeff Kirsher
dfx_driver_init(struct net_device * dev,const char * print_name,resource_size_t bar_start)10391dd06ae8SGreg Kroah-Hartman static int dfx_driver_init(struct net_device *dev, const char *print_name,
104033f810b2SJeff Kirsher resource_size_t bar_start)
104133f810b2SJeff Kirsher {
104233f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
104333f810b2SJeff Kirsher struct device *bdev = bp->bus_dev;
10445349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
104533f810b2SJeff Kirsher int dfx_bus_eisa = DFX_BUS_EISA(bdev);
104633f810b2SJeff Kirsher int dfx_bus_tc = DFX_BUS_TC(bdev);
104733f810b2SJeff Kirsher int alloc_size; /* total buffer size needed */
104833f810b2SJeff Kirsher char *top_v, *curr_v; /* virtual addrs into memory block */
104933f810b2SJeff Kirsher dma_addr_t top_p, curr_p; /* physical addrs into memory block */
105033f810b2SJeff Kirsher u32 data; /* host data register value */
105133f810b2SJeff Kirsher __le32 le32;
105233f810b2SJeff Kirsher char *board_name = NULL;
105333f810b2SJeff Kirsher
105433f810b2SJeff Kirsher DBG_printk("In dfx_driver_init...\n");
105533f810b2SJeff Kirsher
105633f810b2SJeff Kirsher /* Initialize bus-specific hardware registers */
105733f810b2SJeff Kirsher
105833f810b2SJeff Kirsher dfx_bus_init(dev);
105933f810b2SJeff Kirsher
106033f810b2SJeff Kirsher /*
106133f810b2SJeff Kirsher * Initialize default values for configurable parameters
106233f810b2SJeff Kirsher *
106333f810b2SJeff Kirsher * Note: All of these parameters are ones that a user may
106433f810b2SJeff Kirsher * want to customize. It'd be nice to break these
106533f810b2SJeff Kirsher * out into Space.c or someplace else that's more
106633f810b2SJeff Kirsher * accessible/understandable than this file.
106733f810b2SJeff Kirsher */
106833f810b2SJeff Kirsher
106933f810b2SJeff Kirsher bp->full_duplex_enb = PI_SNMP_K_FALSE;
107033f810b2SJeff Kirsher bp->req_ttrt = 8 * 12500; /* 8ms in 80 nanosec units */
107133f810b2SJeff Kirsher bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_DEF;
107233f810b2SJeff Kirsher bp->rcv_bufs_to_post = RCV_BUFS_DEF;
107333f810b2SJeff Kirsher
107433f810b2SJeff Kirsher /*
107533f810b2SJeff Kirsher * Ensure that HW configuration is OK
107633f810b2SJeff Kirsher *
107733f810b2SJeff Kirsher * Note: Depending on the hardware revision, we may need to modify
107833f810b2SJeff Kirsher * some of the configurable parameters to workaround hardware
107933f810b2SJeff Kirsher * limitations. We'll perform this configuration check AFTER
108033f810b2SJeff Kirsher * setting the parameters to their default values.
108133f810b2SJeff Kirsher */
108233f810b2SJeff Kirsher
108333f810b2SJeff Kirsher dfx_bus_config_check(bp);
108433f810b2SJeff Kirsher
108533f810b2SJeff Kirsher /* Disable PDQ interrupts first */
108633f810b2SJeff Kirsher
108733f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
108833f810b2SJeff Kirsher
108933f810b2SJeff Kirsher /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
109033f810b2SJeff Kirsher
109133f810b2SJeff Kirsher (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
109233f810b2SJeff Kirsher
109333f810b2SJeff Kirsher /* Read the factory MAC address from the adapter then save it */
109433f810b2SJeff Kirsher
109533f810b2SJeff Kirsher if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
109633f810b2SJeff Kirsher &data) != DFX_K_SUCCESS) {
109733f810b2SJeff Kirsher printk("%s: Could not read adapter factory MAC address!\n",
109833f810b2SJeff Kirsher print_name);
109933f810b2SJeff Kirsher return DFX_K_FAILURE;
110033f810b2SJeff Kirsher }
110133f810b2SJeff Kirsher le32 = cpu_to_le32(data);
110233f810b2SJeff Kirsher memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
110333f810b2SJeff Kirsher
110433f810b2SJeff Kirsher if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
110533f810b2SJeff Kirsher &data) != DFX_K_SUCCESS) {
110633f810b2SJeff Kirsher printk("%s: Could not read adapter factory MAC address!\n",
110733f810b2SJeff Kirsher print_name);
110833f810b2SJeff Kirsher return DFX_K_FAILURE;
110933f810b2SJeff Kirsher }
111033f810b2SJeff Kirsher le32 = cpu_to_le32(data);
111133f810b2SJeff Kirsher memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
111233f810b2SJeff Kirsher
111333f810b2SJeff Kirsher /*
111433f810b2SJeff Kirsher * Set current address to factory address
111533f810b2SJeff Kirsher *
111633f810b2SJeff Kirsher * Note: Node address override support is handled through
111733f810b2SJeff Kirsher * dfx_ctl_set_mac_address.
111833f810b2SJeff Kirsher */
111933f810b2SJeff Kirsher
11201e9258c3SJakub Kicinski dev_addr_set(dev, bp->factory_mac_addr);
112133f810b2SJeff Kirsher if (dfx_bus_tc)
112233f810b2SJeff Kirsher board_name = "DEFTA";
112333f810b2SJeff Kirsher if (dfx_bus_eisa)
112433f810b2SJeff Kirsher board_name = "DEFEA";
112533f810b2SJeff Kirsher if (dfx_bus_pci)
112633f810b2SJeff Kirsher board_name = "DEFPA";
112733f810b2SJeff Kirsher pr_info("%s: %s at %s addr = 0x%llx, IRQ = %d, Hardware addr = %pMF\n",
11284d0438e5SMaciej W. Rozycki print_name, board_name, dfx_use_mmio ? "MMIO" : "I/O",
112933f810b2SJeff Kirsher (long long)bar_start, dev->irq, dev->dev_addr);
113033f810b2SJeff Kirsher
113133f810b2SJeff Kirsher /*
113233f810b2SJeff Kirsher * Get memory for descriptor block, consumer block, and other buffers
113333f810b2SJeff Kirsher * that need to be DMA read or written to by the adapter.
113433f810b2SJeff Kirsher */
113533f810b2SJeff Kirsher
113633f810b2SJeff Kirsher alloc_size = sizeof(PI_DESCR_BLOCK) +
113733f810b2SJeff Kirsher PI_CMD_REQ_K_SIZE_MAX +
113833f810b2SJeff Kirsher PI_CMD_RSP_K_SIZE_MAX +
113933f810b2SJeff Kirsher #ifndef DYNAMIC_BUFFERS
114033f810b2SJeff Kirsher (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
114133f810b2SJeff Kirsher #endif
114233f810b2SJeff Kirsher sizeof(PI_CONSUMER_BLOCK) +
114333f810b2SJeff Kirsher (PI_ALIGN_K_DESC_BLK - 1);
1144750afb08SLuis Chamberlain bp->kmalloced = top_v = dma_alloc_coherent(bp->bus_dev, alloc_size,
114533f810b2SJeff Kirsher &bp->kmalloced_dma,
1146ede23fa8SJoe Perches GFP_ATOMIC);
1147d0320f75SJoe Perches if (top_v == NULL)
114833f810b2SJeff Kirsher return DFX_K_FAILURE;
1149d0320f75SJoe Perches
115033f810b2SJeff Kirsher top_p = bp->kmalloced_dma; /* get physical address of buffer */
115133f810b2SJeff Kirsher
115233f810b2SJeff Kirsher /*
115333f810b2SJeff Kirsher * To guarantee the 8K alignment required for the descriptor block, 8K - 1
115433f810b2SJeff Kirsher * plus the amount of memory needed was allocated. The physical address
115533f810b2SJeff Kirsher * is now 8K aligned. By carving up the memory in a specific order,
115633f810b2SJeff Kirsher * we'll guarantee the alignment requirements for all other structures.
115733f810b2SJeff Kirsher *
115833f810b2SJeff Kirsher * Note: If the assumptions change regarding the non-paged, non-cached,
115933f810b2SJeff Kirsher * physically contiguous nature of the memory block or the address
116033f810b2SJeff Kirsher * alignments, then we'll need to implement a different algorithm
116133f810b2SJeff Kirsher * for allocating the needed memory.
116233f810b2SJeff Kirsher */
116333f810b2SJeff Kirsher
116433f810b2SJeff Kirsher curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
116533f810b2SJeff Kirsher curr_v = top_v + (curr_p - top_p);
116633f810b2SJeff Kirsher
116733f810b2SJeff Kirsher /* Reserve space for descriptor block */
116833f810b2SJeff Kirsher
116933f810b2SJeff Kirsher bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
117033f810b2SJeff Kirsher bp->descr_block_phys = curr_p;
117133f810b2SJeff Kirsher curr_v += sizeof(PI_DESCR_BLOCK);
117233f810b2SJeff Kirsher curr_p += sizeof(PI_DESCR_BLOCK);
117333f810b2SJeff Kirsher
117433f810b2SJeff Kirsher /* Reserve space for command request buffer */
117533f810b2SJeff Kirsher
117633f810b2SJeff Kirsher bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
117733f810b2SJeff Kirsher bp->cmd_req_phys = curr_p;
117833f810b2SJeff Kirsher curr_v += PI_CMD_REQ_K_SIZE_MAX;
117933f810b2SJeff Kirsher curr_p += PI_CMD_REQ_K_SIZE_MAX;
118033f810b2SJeff Kirsher
118133f810b2SJeff Kirsher /* Reserve space for command response buffer */
118233f810b2SJeff Kirsher
118333f810b2SJeff Kirsher bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
118433f810b2SJeff Kirsher bp->cmd_rsp_phys = curr_p;
118533f810b2SJeff Kirsher curr_v += PI_CMD_RSP_K_SIZE_MAX;
118633f810b2SJeff Kirsher curr_p += PI_CMD_RSP_K_SIZE_MAX;
118733f810b2SJeff Kirsher
118833f810b2SJeff Kirsher /* Reserve space for the LLC host receive queue buffers */
118933f810b2SJeff Kirsher
119033f810b2SJeff Kirsher bp->rcv_block_virt = curr_v;
119133f810b2SJeff Kirsher bp->rcv_block_phys = curr_p;
119233f810b2SJeff Kirsher
119333f810b2SJeff Kirsher #ifndef DYNAMIC_BUFFERS
119433f810b2SJeff Kirsher curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
119533f810b2SJeff Kirsher curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
119633f810b2SJeff Kirsher #endif
119733f810b2SJeff Kirsher
119833f810b2SJeff Kirsher /* Reserve space for the consumer block */
119933f810b2SJeff Kirsher
120033f810b2SJeff Kirsher bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
120133f810b2SJeff Kirsher bp->cons_block_phys = curr_p;
120233f810b2SJeff Kirsher
120333f810b2SJeff Kirsher /* Display virtual and physical addresses if debug driver */
120433f810b2SJeff Kirsher
120551ba0ed1SMaciej W. Rozycki DBG_printk("%s: Descriptor block virt = %p, phys = %pad\n",
120651ba0ed1SMaciej W. Rozycki print_name, bp->descr_block_virt, &bp->descr_block_phys);
120751ba0ed1SMaciej W. Rozycki DBG_printk("%s: Command Request buffer virt = %p, phys = %pad\n",
120851ba0ed1SMaciej W. Rozycki print_name, bp->cmd_req_virt, &bp->cmd_req_phys);
120951ba0ed1SMaciej W. Rozycki DBG_printk("%s: Command Response buffer virt = %p, phys = %pad\n",
121051ba0ed1SMaciej W. Rozycki print_name, bp->cmd_rsp_virt, &bp->cmd_rsp_phys);
121151ba0ed1SMaciej W. Rozycki DBG_printk("%s: Receive buffer block virt = %p, phys = %pad\n",
121251ba0ed1SMaciej W. Rozycki print_name, bp->rcv_block_virt, &bp->rcv_block_phys);
121351ba0ed1SMaciej W. Rozycki DBG_printk("%s: Consumer block virt = %p, phys = %pad\n",
121451ba0ed1SMaciej W. Rozycki print_name, bp->cons_block_virt, &bp->cons_block_phys);
121533f810b2SJeff Kirsher
121633f810b2SJeff Kirsher return DFX_K_SUCCESS;
121733f810b2SJeff Kirsher }
121833f810b2SJeff Kirsher
121933f810b2SJeff Kirsher
122033f810b2SJeff Kirsher /*
122133f810b2SJeff Kirsher * =================
122233f810b2SJeff Kirsher * = dfx_adap_init =
122333f810b2SJeff Kirsher * =================
122433f810b2SJeff Kirsher *
122533f810b2SJeff Kirsher * Overview:
122633f810b2SJeff Kirsher * Brings the adapter to the link avail/link unavailable state.
122733f810b2SJeff Kirsher *
122833f810b2SJeff Kirsher * Returns:
122933f810b2SJeff Kirsher * Condition code
123033f810b2SJeff Kirsher *
123133f810b2SJeff Kirsher * Arguments:
123233f810b2SJeff Kirsher * bp - pointer to board information
123333f810b2SJeff Kirsher * get_buffers - non-zero if buffers to be allocated
123433f810b2SJeff Kirsher *
123533f810b2SJeff Kirsher * Functional Description:
123633f810b2SJeff Kirsher * Issues the low-level firmware/hardware calls necessary to bring
123733f810b2SJeff Kirsher * the adapter up, or to properly reset and restore adapter during
123833f810b2SJeff Kirsher * run-time.
123933f810b2SJeff Kirsher *
124033f810b2SJeff Kirsher * Return Codes:
124133f810b2SJeff Kirsher * DFX_K_SUCCESS - Adapter brought up successfully
124233f810b2SJeff Kirsher * DFX_K_FAILURE - Adapter initialization failed
124333f810b2SJeff Kirsher *
124433f810b2SJeff Kirsher * Assumptions:
124533f810b2SJeff Kirsher * bp->reset_type should be set to a valid reset type value before
124633f810b2SJeff Kirsher * calling this routine.
124733f810b2SJeff Kirsher *
124833f810b2SJeff Kirsher * Side Effects:
124933f810b2SJeff Kirsher * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
125033f810b2SJeff Kirsher * upon a successful return of this routine.
125133f810b2SJeff Kirsher */
125233f810b2SJeff Kirsher
dfx_adap_init(DFX_board_t * bp,int get_buffers)125333f810b2SJeff Kirsher static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
125433f810b2SJeff Kirsher {
125533f810b2SJeff Kirsher DBG_printk("In dfx_adap_init...\n");
125633f810b2SJeff Kirsher
125733f810b2SJeff Kirsher /* Disable PDQ interrupts first */
125833f810b2SJeff Kirsher
125933f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
126033f810b2SJeff Kirsher
126133f810b2SJeff Kirsher /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
126233f810b2SJeff Kirsher
126333f810b2SJeff Kirsher if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
126433f810b2SJeff Kirsher {
126533f810b2SJeff Kirsher printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
126633f810b2SJeff Kirsher return DFX_K_FAILURE;
126733f810b2SJeff Kirsher }
126833f810b2SJeff Kirsher
126933f810b2SJeff Kirsher /*
127033f810b2SJeff Kirsher * When the PDQ is reset, some false Type 0 interrupts may be pending,
127133f810b2SJeff Kirsher * so we'll acknowledge all Type 0 interrupts now before continuing.
127233f810b2SJeff Kirsher */
127333f810b2SJeff Kirsher
127433f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
127533f810b2SJeff Kirsher
127633f810b2SJeff Kirsher /*
127733f810b2SJeff Kirsher * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
127833f810b2SJeff Kirsher *
127933f810b2SJeff Kirsher * Note: We only need to clear host copies of these registers. The PDQ reset
128033f810b2SJeff Kirsher * takes care of the on-board register values.
128133f810b2SJeff Kirsher */
128233f810b2SJeff Kirsher
128333f810b2SJeff Kirsher bp->cmd_req_reg.lword = 0;
128433f810b2SJeff Kirsher bp->cmd_rsp_reg.lword = 0;
128533f810b2SJeff Kirsher bp->rcv_xmt_reg.lword = 0;
128633f810b2SJeff Kirsher
128733f810b2SJeff Kirsher /* Clear consumer block before going to DMA_AVAILABLE state */
128833f810b2SJeff Kirsher
128933f810b2SJeff Kirsher memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
129033f810b2SJeff Kirsher
129133f810b2SJeff Kirsher /* Initialize the DMA Burst Size */
129233f810b2SJeff Kirsher
129333f810b2SJeff Kirsher if (dfx_hw_port_ctrl_req(bp,
129433f810b2SJeff Kirsher PI_PCTRL_M_SUB_CMD,
129533f810b2SJeff Kirsher PI_SUB_CMD_K_BURST_SIZE_SET,
129633f810b2SJeff Kirsher bp->burst_size,
129733f810b2SJeff Kirsher NULL) != DFX_K_SUCCESS)
129833f810b2SJeff Kirsher {
129933f810b2SJeff Kirsher printk("%s: Could not set adapter burst size!\n", bp->dev->name);
130033f810b2SJeff Kirsher return DFX_K_FAILURE;
130133f810b2SJeff Kirsher }
130233f810b2SJeff Kirsher
130333f810b2SJeff Kirsher /*
130433f810b2SJeff Kirsher * Set base address of Consumer Block
130533f810b2SJeff Kirsher *
130633f810b2SJeff Kirsher * Assumption: 32-bit physical address of consumer block is 64 byte
130733f810b2SJeff Kirsher * aligned. That is, bits 0-5 of the address must be zero.
130833f810b2SJeff Kirsher */
130933f810b2SJeff Kirsher
131033f810b2SJeff Kirsher if (dfx_hw_port_ctrl_req(bp,
131133f810b2SJeff Kirsher PI_PCTRL_M_CONS_BLOCK,
131233f810b2SJeff Kirsher bp->cons_block_phys,
131333f810b2SJeff Kirsher 0,
131433f810b2SJeff Kirsher NULL) != DFX_K_SUCCESS)
131533f810b2SJeff Kirsher {
131633f810b2SJeff Kirsher printk("%s: Could not set consumer block address!\n", bp->dev->name);
131733f810b2SJeff Kirsher return DFX_K_FAILURE;
131833f810b2SJeff Kirsher }
131933f810b2SJeff Kirsher
132033f810b2SJeff Kirsher /*
132133f810b2SJeff Kirsher * Set the base address of Descriptor Block and bring adapter
132233f810b2SJeff Kirsher * to DMA_AVAILABLE state.
132333f810b2SJeff Kirsher *
132433f810b2SJeff Kirsher * Note: We also set the literal and data swapping requirements
132533f810b2SJeff Kirsher * in this command.
132633f810b2SJeff Kirsher *
132733f810b2SJeff Kirsher * Assumption: 32-bit physical address of descriptor block
132833f810b2SJeff Kirsher * is 8Kbyte aligned.
132933f810b2SJeff Kirsher */
133033f810b2SJeff Kirsher if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
133133f810b2SJeff Kirsher (u32)(bp->descr_block_phys |
133233f810b2SJeff Kirsher PI_PDATA_A_INIT_M_BSWAP_INIT),
133333f810b2SJeff Kirsher 0, NULL) != DFX_K_SUCCESS) {
133433f810b2SJeff Kirsher printk("%s: Could not set descriptor block address!\n",
133533f810b2SJeff Kirsher bp->dev->name);
133633f810b2SJeff Kirsher return DFX_K_FAILURE;
133733f810b2SJeff Kirsher }
133833f810b2SJeff Kirsher
133933f810b2SJeff Kirsher /* Set transmit flush timeout value */
134033f810b2SJeff Kirsher
134133f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
134233f810b2SJeff Kirsher bp->cmd_req_virt->char_set.item[0].item_code = PI_ITEM_K_FLUSH_TIME;
134333f810b2SJeff Kirsher bp->cmd_req_virt->char_set.item[0].value = 3; /* 3 seconds */
134433f810b2SJeff Kirsher bp->cmd_req_virt->char_set.item[0].item_index = 0;
134533f810b2SJeff Kirsher bp->cmd_req_virt->char_set.item[1].item_code = PI_ITEM_K_EOL;
134633f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
134733f810b2SJeff Kirsher {
134833f810b2SJeff Kirsher printk("%s: DMA command request failed!\n", bp->dev->name);
134933f810b2SJeff Kirsher return DFX_K_FAILURE;
135033f810b2SJeff Kirsher }
135133f810b2SJeff Kirsher
135233f810b2SJeff Kirsher /* Set the initial values for eFDXEnable and MACTReq MIB objects */
135333f810b2SJeff Kirsher
135433f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
135533f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[0].item_code = PI_ITEM_K_FDX_ENB_DIS;
135633f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[0].value = bp->full_duplex_enb;
135733f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[0].item_index = 0;
135833f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[1].item_code = PI_ITEM_K_MAC_T_REQ;
135933f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[1].value = bp->req_ttrt;
136033f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[1].item_index = 0;
136133f810b2SJeff Kirsher bp->cmd_req_virt->snmp_set.item[2].item_code = PI_ITEM_K_EOL;
136233f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
136333f810b2SJeff Kirsher {
136433f810b2SJeff Kirsher printk("%s: DMA command request failed!\n", bp->dev->name);
136533f810b2SJeff Kirsher return DFX_K_FAILURE;
136633f810b2SJeff Kirsher }
136733f810b2SJeff Kirsher
136833f810b2SJeff Kirsher /* Initialize adapter CAM */
136933f810b2SJeff Kirsher
137033f810b2SJeff Kirsher if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
137133f810b2SJeff Kirsher {
137233f810b2SJeff Kirsher printk("%s: Adapter CAM update failed!\n", bp->dev->name);
137333f810b2SJeff Kirsher return DFX_K_FAILURE;
137433f810b2SJeff Kirsher }
137533f810b2SJeff Kirsher
137633f810b2SJeff Kirsher /* Initialize adapter filters */
137733f810b2SJeff Kirsher
137833f810b2SJeff Kirsher if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
137933f810b2SJeff Kirsher {
138033f810b2SJeff Kirsher printk("%s: Adapter filters update failed!\n", bp->dev->name);
138133f810b2SJeff Kirsher return DFX_K_FAILURE;
138233f810b2SJeff Kirsher }
138333f810b2SJeff Kirsher
138433f810b2SJeff Kirsher /*
138533f810b2SJeff Kirsher * Remove any existing dynamic buffers (i.e. if the adapter is being
138633f810b2SJeff Kirsher * reinitialized)
138733f810b2SJeff Kirsher */
138833f810b2SJeff Kirsher
138933f810b2SJeff Kirsher if (get_buffers)
139033f810b2SJeff Kirsher dfx_rcv_flush(bp);
139133f810b2SJeff Kirsher
139233f810b2SJeff Kirsher /* Initialize receive descriptor block and produce buffers */
139333f810b2SJeff Kirsher
139433f810b2SJeff Kirsher if (dfx_rcv_init(bp, get_buffers))
139533f810b2SJeff Kirsher {
139633f810b2SJeff Kirsher printk("%s: Receive buffer allocation failed\n", bp->dev->name);
139733f810b2SJeff Kirsher if (get_buffers)
139833f810b2SJeff Kirsher dfx_rcv_flush(bp);
139933f810b2SJeff Kirsher return DFX_K_FAILURE;
140033f810b2SJeff Kirsher }
140133f810b2SJeff Kirsher
140233f810b2SJeff Kirsher /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
140333f810b2SJeff Kirsher
140433f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
140533f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
140633f810b2SJeff Kirsher {
140733f810b2SJeff Kirsher printk("%s: Start command failed\n", bp->dev->name);
140833f810b2SJeff Kirsher if (get_buffers)
140933f810b2SJeff Kirsher dfx_rcv_flush(bp);
141033f810b2SJeff Kirsher return DFX_K_FAILURE;
141133f810b2SJeff Kirsher }
141233f810b2SJeff Kirsher
141333f810b2SJeff Kirsher /* Initialization succeeded, reenable PDQ interrupts */
141433f810b2SJeff Kirsher
141533f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
141633f810b2SJeff Kirsher return DFX_K_SUCCESS;
141733f810b2SJeff Kirsher }
141833f810b2SJeff Kirsher
141933f810b2SJeff Kirsher
142033f810b2SJeff Kirsher /*
142133f810b2SJeff Kirsher * ============
142233f810b2SJeff Kirsher * = dfx_open =
142333f810b2SJeff Kirsher * ============
142433f810b2SJeff Kirsher *
142533f810b2SJeff Kirsher * Overview:
142633f810b2SJeff Kirsher * Opens the adapter
142733f810b2SJeff Kirsher *
142833f810b2SJeff Kirsher * Returns:
142933f810b2SJeff Kirsher * Condition code
143033f810b2SJeff Kirsher *
143133f810b2SJeff Kirsher * Arguments:
143233f810b2SJeff Kirsher * dev - pointer to device information
143333f810b2SJeff Kirsher *
143433f810b2SJeff Kirsher * Functional Description:
143533f810b2SJeff Kirsher * This function brings the adapter to an operational state.
143633f810b2SJeff Kirsher *
143733f810b2SJeff Kirsher * Return Codes:
143833f810b2SJeff Kirsher * 0 - Adapter was successfully opened
143933f810b2SJeff Kirsher * -EAGAIN - Could not register IRQ or adapter initialization failed
144033f810b2SJeff Kirsher *
144133f810b2SJeff Kirsher * Assumptions:
144233f810b2SJeff Kirsher * This routine should only be called for a device that was
144333f810b2SJeff Kirsher * initialized successfully.
144433f810b2SJeff Kirsher *
144533f810b2SJeff Kirsher * Side Effects:
144633f810b2SJeff Kirsher * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
144733f810b2SJeff Kirsher * if the open is successful.
144833f810b2SJeff Kirsher */
144933f810b2SJeff Kirsher
dfx_open(struct net_device * dev)145033f810b2SJeff Kirsher static int dfx_open(struct net_device *dev)
145133f810b2SJeff Kirsher {
145233f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
145333f810b2SJeff Kirsher int ret;
145433f810b2SJeff Kirsher
145533f810b2SJeff Kirsher DBG_printk("In dfx_open...\n");
145633f810b2SJeff Kirsher
145733f810b2SJeff Kirsher /* Register IRQ - support shared interrupts by passing device ptr */
145833f810b2SJeff Kirsher
145933f810b2SJeff Kirsher ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
146033f810b2SJeff Kirsher dev);
146133f810b2SJeff Kirsher if (ret) {
146233f810b2SJeff Kirsher printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
146333f810b2SJeff Kirsher return ret;
146433f810b2SJeff Kirsher }
146533f810b2SJeff Kirsher
146633f810b2SJeff Kirsher /*
146733f810b2SJeff Kirsher * Set current address to factory MAC address
146833f810b2SJeff Kirsher *
146933f810b2SJeff Kirsher * Note: We've already done this step in dfx_driver_init.
147033f810b2SJeff Kirsher * However, it's possible that a user has set a node
147133f810b2SJeff Kirsher * address override, then closed and reopened the
147233f810b2SJeff Kirsher * adapter. Unless we reset the device address field
147333f810b2SJeff Kirsher * now, we'll continue to use the existing modified
147433f810b2SJeff Kirsher * address.
147533f810b2SJeff Kirsher */
147633f810b2SJeff Kirsher
14771e9258c3SJakub Kicinski dev_addr_set(dev, bp->factory_mac_addr);
147833f810b2SJeff Kirsher
147933f810b2SJeff Kirsher /* Clear local unicast/multicast address tables and counts */
148033f810b2SJeff Kirsher
148133f810b2SJeff Kirsher memset(bp->uc_table, 0, sizeof(bp->uc_table));
148233f810b2SJeff Kirsher memset(bp->mc_table, 0, sizeof(bp->mc_table));
148333f810b2SJeff Kirsher bp->uc_count = 0;
148433f810b2SJeff Kirsher bp->mc_count = 0;
148533f810b2SJeff Kirsher
148633f810b2SJeff Kirsher /* Disable promiscuous filter settings */
148733f810b2SJeff Kirsher
148833f810b2SJeff Kirsher bp->ind_group_prom = PI_FSTATE_K_BLOCK;
148933f810b2SJeff Kirsher bp->group_prom = PI_FSTATE_K_BLOCK;
149033f810b2SJeff Kirsher
149133f810b2SJeff Kirsher spin_lock_init(&bp->lock);
149233f810b2SJeff Kirsher
149333f810b2SJeff Kirsher /* Reset and initialize adapter */
149433f810b2SJeff Kirsher
149533f810b2SJeff Kirsher bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST; /* skip self-test */
149633f810b2SJeff Kirsher if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
149733f810b2SJeff Kirsher {
149833f810b2SJeff Kirsher printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
149933f810b2SJeff Kirsher free_irq(dev->irq, dev);
150033f810b2SJeff Kirsher return -EAGAIN;
150133f810b2SJeff Kirsher }
150233f810b2SJeff Kirsher
150333f810b2SJeff Kirsher /* Set device structure info */
150433f810b2SJeff Kirsher netif_start_queue(dev);
150533f810b2SJeff Kirsher return 0;
150633f810b2SJeff Kirsher }
150733f810b2SJeff Kirsher
150833f810b2SJeff Kirsher
150933f810b2SJeff Kirsher /*
151033f810b2SJeff Kirsher * =============
151133f810b2SJeff Kirsher * = dfx_close =
151233f810b2SJeff Kirsher * =============
151333f810b2SJeff Kirsher *
151433f810b2SJeff Kirsher * Overview:
151533f810b2SJeff Kirsher * Closes the device/module.
151633f810b2SJeff Kirsher *
151733f810b2SJeff Kirsher * Returns:
151833f810b2SJeff Kirsher * Condition code
151933f810b2SJeff Kirsher *
152033f810b2SJeff Kirsher * Arguments:
152133f810b2SJeff Kirsher * dev - pointer to device information
152233f810b2SJeff Kirsher *
152333f810b2SJeff Kirsher * Functional Description:
152433f810b2SJeff Kirsher * This routine closes the adapter and brings it to a safe state.
152533f810b2SJeff Kirsher * The interrupt service routine is deregistered with the OS.
152633f810b2SJeff Kirsher * The adapter can be opened again with another call to dfx_open().
152733f810b2SJeff Kirsher *
152833f810b2SJeff Kirsher * Return Codes:
152933f810b2SJeff Kirsher * Always return 0.
153033f810b2SJeff Kirsher *
153133f810b2SJeff Kirsher * Assumptions:
153233f810b2SJeff Kirsher * No further requests for this adapter are made after this routine is
153333f810b2SJeff Kirsher * called. dfx_open() can be called to reset and reinitialize the
153433f810b2SJeff Kirsher * adapter.
153533f810b2SJeff Kirsher *
153633f810b2SJeff Kirsher * Side Effects:
153733f810b2SJeff Kirsher * Adapter should be in DMA_UNAVAILABLE state upon completion of this
153833f810b2SJeff Kirsher * routine.
153933f810b2SJeff Kirsher */
154033f810b2SJeff Kirsher
dfx_close(struct net_device * dev)154133f810b2SJeff Kirsher static int dfx_close(struct net_device *dev)
154233f810b2SJeff Kirsher {
154333f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
154433f810b2SJeff Kirsher
154533f810b2SJeff Kirsher DBG_printk("In dfx_close...\n");
154633f810b2SJeff Kirsher
154733f810b2SJeff Kirsher /* Disable PDQ interrupts first */
154833f810b2SJeff Kirsher
154933f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
155033f810b2SJeff Kirsher
155133f810b2SJeff Kirsher /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
155233f810b2SJeff Kirsher
155333f810b2SJeff Kirsher (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
155433f810b2SJeff Kirsher
155533f810b2SJeff Kirsher /*
155633f810b2SJeff Kirsher * Flush any pending transmit buffers
155733f810b2SJeff Kirsher *
155833f810b2SJeff Kirsher * Note: It's important that we flush the transmit buffers
155933f810b2SJeff Kirsher * BEFORE we clear our copy of the Type 2 register.
156033f810b2SJeff Kirsher * Otherwise, we'll have no idea how many buffers
156133f810b2SJeff Kirsher * we need to free.
156233f810b2SJeff Kirsher */
156333f810b2SJeff Kirsher
156433f810b2SJeff Kirsher dfx_xmt_flush(bp);
156533f810b2SJeff Kirsher
156633f810b2SJeff Kirsher /*
156733f810b2SJeff Kirsher * Clear Type 1 and Type 2 registers after adapter reset
156833f810b2SJeff Kirsher *
156933f810b2SJeff Kirsher * Note: Even though we're closing the adapter, it's
157033f810b2SJeff Kirsher * possible that an interrupt will occur after
157133f810b2SJeff Kirsher * dfx_close is called. Without some assurance to
157233f810b2SJeff Kirsher * the contrary we want to make sure that we don't
157333f810b2SJeff Kirsher * process receive and transmit LLC frames and update
157433f810b2SJeff Kirsher * the Type 2 register with bad information.
157533f810b2SJeff Kirsher */
157633f810b2SJeff Kirsher
157733f810b2SJeff Kirsher bp->cmd_req_reg.lword = 0;
157833f810b2SJeff Kirsher bp->cmd_rsp_reg.lword = 0;
157933f810b2SJeff Kirsher bp->rcv_xmt_reg.lword = 0;
158033f810b2SJeff Kirsher
158133f810b2SJeff Kirsher /* Clear consumer block for the same reason given above */
158233f810b2SJeff Kirsher
158333f810b2SJeff Kirsher memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
158433f810b2SJeff Kirsher
158533f810b2SJeff Kirsher /* Release all dynamically allocate skb in the receive ring. */
158633f810b2SJeff Kirsher
158733f810b2SJeff Kirsher dfx_rcv_flush(bp);
158833f810b2SJeff Kirsher
158933f810b2SJeff Kirsher /* Clear device structure flags */
159033f810b2SJeff Kirsher
159133f810b2SJeff Kirsher netif_stop_queue(dev);
159233f810b2SJeff Kirsher
159333f810b2SJeff Kirsher /* Deregister (free) IRQ */
159433f810b2SJeff Kirsher
159533f810b2SJeff Kirsher free_irq(dev->irq, dev);
159633f810b2SJeff Kirsher
159733f810b2SJeff Kirsher return 0;
159833f810b2SJeff Kirsher }
159933f810b2SJeff Kirsher
160033f810b2SJeff Kirsher
160133f810b2SJeff Kirsher /*
160233f810b2SJeff Kirsher * ======================
160333f810b2SJeff Kirsher * = dfx_int_pr_halt_id =
160433f810b2SJeff Kirsher * ======================
160533f810b2SJeff Kirsher *
160633f810b2SJeff Kirsher * Overview:
160733f810b2SJeff Kirsher * Displays halt id's in string form.
160833f810b2SJeff Kirsher *
160933f810b2SJeff Kirsher * Returns:
161033f810b2SJeff Kirsher * None
161133f810b2SJeff Kirsher *
161233f810b2SJeff Kirsher * Arguments:
161333f810b2SJeff Kirsher * bp - pointer to board information
161433f810b2SJeff Kirsher *
161533f810b2SJeff Kirsher * Functional Description:
161633f810b2SJeff Kirsher * Determine current halt id and display appropriate string.
161733f810b2SJeff Kirsher *
161833f810b2SJeff Kirsher * Return Codes:
161933f810b2SJeff Kirsher * None
162033f810b2SJeff Kirsher *
162133f810b2SJeff Kirsher * Assumptions:
162233f810b2SJeff Kirsher * None
162333f810b2SJeff Kirsher *
162433f810b2SJeff Kirsher * Side Effects:
162533f810b2SJeff Kirsher * None
162633f810b2SJeff Kirsher */
162733f810b2SJeff Kirsher
dfx_int_pr_halt_id(DFX_board_t * bp)162833f810b2SJeff Kirsher static void dfx_int_pr_halt_id(DFX_board_t *bp)
162933f810b2SJeff Kirsher {
163033f810b2SJeff Kirsher PI_UINT32 port_status; /* PDQ port status register value */
163133f810b2SJeff Kirsher PI_UINT32 halt_id; /* PDQ port status halt ID */
163233f810b2SJeff Kirsher
163333f810b2SJeff Kirsher /* Read the latest port status */
163433f810b2SJeff Kirsher
163533f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
163633f810b2SJeff Kirsher
163733f810b2SJeff Kirsher /* Display halt state transition information */
163833f810b2SJeff Kirsher
163933f810b2SJeff Kirsher halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
164033f810b2SJeff Kirsher switch (halt_id)
164133f810b2SJeff Kirsher {
164233f810b2SJeff Kirsher case PI_HALT_ID_K_SELFTEST_TIMEOUT:
164333f810b2SJeff Kirsher printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
164433f810b2SJeff Kirsher break;
164533f810b2SJeff Kirsher
164633f810b2SJeff Kirsher case PI_HALT_ID_K_PARITY_ERROR:
164733f810b2SJeff Kirsher printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
164833f810b2SJeff Kirsher break;
164933f810b2SJeff Kirsher
165033f810b2SJeff Kirsher case PI_HALT_ID_K_HOST_DIR_HALT:
165133f810b2SJeff Kirsher printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
165233f810b2SJeff Kirsher break;
165333f810b2SJeff Kirsher
165433f810b2SJeff Kirsher case PI_HALT_ID_K_SW_FAULT:
165533f810b2SJeff Kirsher printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
165633f810b2SJeff Kirsher break;
165733f810b2SJeff Kirsher
165833f810b2SJeff Kirsher case PI_HALT_ID_K_HW_FAULT:
165933f810b2SJeff Kirsher printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
166033f810b2SJeff Kirsher break;
166133f810b2SJeff Kirsher
166233f810b2SJeff Kirsher case PI_HALT_ID_K_PC_TRACE:
166333f810b2SJeff Kirsher printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
166433f810b2SJeff Kirsher break;
166533f810b2SJeff Kirsher
166633f810b2SJeff Kirsher case PI_HALT_ID_K_DMA_ERROR:
166733f810b2SJeff Kirsher printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
166833f810b2SJeff Kirsher break;
166933f810b2SJeff Kirsher
167033f810b2SJeff Kirsher case PI_HALT_ID_K_IMAGE_CRC_ERROR:
167133f810b2SJeff Kirsher printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
167233f810b2SJeff Kirsher break;
167333f810b2SJeff Kirsher
167433f810b2SJeff Kirsher case PI_HALT_ID_K_BUS_EXCEPTION:
167533f810b2SJeff Kirsher printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
167633f810b2SJeff Kirsher break;
167733f810b2SJeff Kirsher
167833f810b2SJeff Kirsher default:
167933f810b2SJeff Kirsher printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
168033f810b2SJeff Kirsher break;
168133f810b2SJeff Kirsher }
168233f810b2SJeff Kirsher }
168333f810b2SJeff Kirsher
168433f810b2SJeff Kirsher
168533f810b2SJeff Kirsher /*
168633f810b2SJeff Kirsher * ==========================
168733f810b2SJeff Kirsher * = dfx_int_type_0_process =
168833f810b2SJeff Kirsher * ==========================
168933f810b2SJeff Kirsher *
169033f810b2SJeff Kirsher * Overview:
169133f810b2SJeff Kirsher * Processes Type 0 interrupts.
169233f810b2SJeff Kirsher *
169333f810b2SJeff Kirsher * Returns:
169433f810b2SJeff Kirsher * None
169533f810b2SJeff Kirsher *
169633f810b2SJeff Kirsher * Arguments:
169733f810b2SJeff Kirsher * bp - pointer to board information
169833f810b2SJeff Kirsher *
169933f810b2SJeff Kirsher * Functional Description:
170033f810b2SJeff Kirsher * Processes all enabled Type 0 interrupts. If the reason for the interrupt
170133f810b2SJeff Kirsher * is a serious fault on the adapter, then an error message is displayed
170233f810b2SJeff Kirsher * and the adapter is reset.
170333f810b2SJeff Kirsher *
170433f810b2SJeff Kirsher * One tricky potential timing window is the rapid succession of "link avail"
170533f810b2SJeff Kirsher * "link unavail" state change interrupts. The acknowledgement of the Type 0
170633f810b2SJeff Kirsher * interrupt must be done before reading the state from the Port Status
170733f810b2SJeff Kirsher * register. This is true because a state change could occur after reading
170833f810b2SJeff Kirsher * the data, but before acknowledging the interrupt. If this state change
170933f810b2SJeff Kirsher * does happen, it would be lost because the driver is using the old state,
171033f810b2SJeff Kirsher * and it will never know about the new state because it subsequently
171133f810b2SJeff Kirsher * acknowledges the state change interrupt.
171233f810b2SJeff Kirsher *
171333f810b2SJeff Kirsher * INCORRECT CORRECT
171433f810b2SJeff Kirsher * read type 0 int reasons read type 0 int reasons
171533f810b2SJeff Kirsher * read adapter state ack type 0 interrupts
171633f810b2SJeff Kirsher * ack type 0 interrupts read adapter state
171733f810b2SJeff Kirsher * ... process interrupt ... ... process interrupt ...
171833f810b2SJeff Kirsher *
171933f810b2SJeff Kirsher * Return Codes:
172033f810b2SJeff Kirsher * None
172133f810b2SJeff Kirsher *
172233f810b2SJeff Kirsher * Assumptions:
172333f810b2SJeff Kirsher * None
172433f810b2SJeff Kirsher *
172533f810b2SJeff Kirsher * Side Effects:
172633f810b2SJeff Kirsher * An adapter reset may occur if the adapter has any Type 0 error interrupts
172733f810b2SJeff Kirsher * or if the port status indicates that the adapter is halted. The driver
172833f810b2SJeff Kirsher * is responsible for reinitializing the adapter with the current CAM
172933f810b2SJeff Kirsher * contents and adapter filter settings.
173033f810b2SJeff Kirsher */
173133f810b2SJeff Kirsher
dfx_int_type_0_process(DFX_board_t * bp)173233f810b2SJeff Kirsher static void dfx_int_type_0_process(DFX_board_t *bp)
173333f810b2SJeff Kirsher
173433f810b2SJeff Kirsher {
173533f810b2SJeff Kirsher PI_UINT32 type_0_status; /* Host Interrupt Type 0 register */
173633f810b2SJeff Kirsher PI_UINT32 state; /* current adap state (from port status) */
173733f810b2SJeff Kirsher
173833f810b2SJeff Kirsher /*
173933f810b2SJeff Kirsher * Read host interrupt Type 0 register to determine which Type 0
174033f810b2SJeff Kirsher * interrupts are pending. Immediately write it back out to clear
174133f810b2SJeff Kirsher * those interrupts.
174233f810b2SJeff Kirsher */
174333f810b2SJeff Kirsher
174433f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
174533f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
174633f810b2SJeff Kirsher
174733f810b2SJeff Kirsher /* Check for Type 0 error interrupts */
174833f810b2SJeff Kirsher
174933f810b2SJeff Kirsher if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
175033f810b2SJeff Kirsher PI_TYPE_0_STAT_M_PM_PAR_ERR |
175133f810b2SJeff Kirsher PI_TYPE_0_STAT_M_BUS_PAR_ERR))
175233f810b2SJeff Kirsher {
175333f810b2SJeff Kirsher /* Check for Non-Existent Memory error */
175433f810b2SJeff Kirsher
175533f810b2SJeff Kirsher if (type_0_status & PI_TYPE_0_STAT_M_NXM)
175633f810b2SJeff Kirsher printk("%s: Non-Existent Memory Access Error\n", bp->dev->name);
175733f810b2SJeff Kirsher
175833f810b2SJeff Kirsher /* Check for Packet Memory Parity error */
175933f810b2SJeff Kirsher
176033f810b2SJeff Kirsher if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
176133f810b2SJeff Kirsher printk("%s: Packet Memory Parity Error\n", bp->dev->name);
176233f810b2SJeff Kirsher
176333f810b2SJeff Kirsher /* Check for Host Bus Parity error */
176433f810b2SJeff Kirsher
176533f810b2SJeff Kirsher if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
176633f810b2SJeff Kirsher printk("%s: Host Bus Parity Error\n", bp->dev->name);
176733f810b2SJeff Kirsher
176833f810b2SJeff Kirsher /* Reset adapter and bring it back on-line */
176933f810b2SJeff Kirsher
177033f810b2SJeff Kirsher bp->link_available = PI_K_FALSE; /* link is no longer available */
177133f810b2SJeff Kirsher bp->reset_type = 0; /* rerun on-board diagnostics */
177233f810b2SJeff Kirsher printk("%s: Resetting adapter...\n", bp->dev->name);
177333f810b2SJeff Kirsher if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
177433f810b2SJeff Kirsher {
177533f810b2SJeff Kirsher printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
177633f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
177733f810b2SJeff Kirsher return;
177833f810b2SJeff Kirsher }
177933f810b2SJeff Kirsher printk("%s: Adapter reset successful!\n", bp->dev->name);
178033f810b2SJeff Kirsher return;
178133f810b2SJeff Kirsher }
178233f810b2SJeff Kirsher
178333f810b2SJeff Kirsher /* Check for transmit flush interrupt */
178433f810b2SJeff Kirsher
178533f810b2SJeff Kirsher if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
178633f810b2SJeff Kirsher {
178733f810b2SJeff Kirsher /* Flush any pending xmt's and acknowledge the flush interrupt */
178833f810b2SJeff Kirsher
178933f810b2SJeff Kirsher bp->link_available = PI_K_FALSE; /* link is no longer available */
179033f810b2SJeff Kirsher dfx_xmt_flush(bp); /* flush any outstanding packets */
179133f810b2SJeff Kirsher (void) dfx_hw_port_ctrl_req(bp,
179233f810b2SJeff Kirsher PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
179333f810b2SJeff Kirsher 0,
179433f810b2SJeff Kirsher 0,
179533f810b2SJeff Kirsher NULL);
179633f810b2SJeff Kirsher }
179733f810b2SJeff Kirsher
179833f810b2SJeff Kirsher /* Check for adapter state change */
179933f810b2SJeff Kirsher
180033f810b2SJeff Kirsher if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
180133f810b2SJeff Kirsher {
180233f810b2SJeff Kirsher /* Get latest adapter state */
180333f810b2SJeff Kirsher
180433f810b2SJeff Kirsher state = dfx_hw_adap_state_rd(bp); /* get adapter state */
180533f810b2SJeff Kirsher if (state == PI_STATE_K_HALTED)
180633f810b2SJeff Kirsher {
180733f810b2SJeff Kirsher /*
180833f810b2SJeff Kirsher * Adapter has transitioned to HALTED state, try to reset
180933f810b2SJeff Kirsher * adapter to bring it back on-line. If reset fails,
181033f810b2SJeff Kirsher * leave the adapter in the broken state.
181133f810b2SJeff Kirsher */
181233f810b2SJeff Kirsher
181333f810b2SJeff Kirsher printk("%s: Controller has transitioned to HALTED state!\n", bp->dev->name);
181433f810b2SJeff Kirsher dfx_int_pr_halt_id(bp); /* display halt id as string */
181533f810b2SJeff Kirsher
181633f810b2SJeff Kirsher /* Reset adapter and bring it back on-line */
181733f810b2SJeff Kirsher
181833f810b2SJeff Kirsher bp->link_available = PI_K_FALSE; /* link is no longer available */
181933f810b2SJeff Kirsher bp->reset_type = 0; /* rerun on-board diagnostics */
182033f810b2SJeff Kirsher printk("%s: Resetting adapter...\n", bp->dev->name);
182133f810b2SJeff Kirsher if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
182233f810b2SJeff Kirsher {
182333f810b2SJeff Kirsher printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
182433f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
182533f810b2SJeff Kirsher return;
182633f810b2SJeff Kirsher }
182733f810b2SJeff Kirsher printk("%s: Adapter reset successful!\n", bp->dev->name);
182833f810b2SJeff Kirsher }
182933f810b2SJeff Kirsher else if (state == PI_STATE_K_LINK_AVAIL)
183033f810b2SJeff Kirsher {
183133f810b2SJeff Kirsher bp->link_available = PI_K_TRUE; /* set link available flag */
183233f810b2SJeff Kirsher }
183333f810b2SJeff Kirsher }
183433f810b2SJeff Kirsher }
183533f810b2SJeff Kirsher
183633f810b2SJeff Kirsher
183733f810b2SJeff Kirsher /*
183833f810b2SJeff Kirsher * ==================
183933f810b2SJeff Kirsher * = dfx_int_common =
184033f810b2SJeff Kirsher * ==================
184133f810b2SJeff Kirsher *
184233f810b2SJeff Kirsher * Overview:
184333f810b2SJeff Kirsher * Interrupt service routine (ISR)
184433f810b2SJeff Kirsher *
184533f810b2SJeff Kirsher * Returns:
184633f810b2SJeff Kirsher * None
184733f810b2SJeff Kirsher *
184833f810b2SJeff Kirsher * Arguments:
184933f810b2SJeff Kirsher * bp - pointer to board information
185033f810b2SJeff Kirsher *
185133f810b2SJeff Kirsher * Functional Description:
185233f810b2SJeff Kirsher * This is the ISR which processes incoming adapter interrupts.
185333f810b2SJeff Kirsher *
185433f810b2SJeff Kirsher * Return Codes:
185533f810b2SJeff Kirsher * None
185633f810b2SJeff Kirsher *
185733f810b2SJeff Kirsher * Assumptions:
185833f810b2SJeff Kirsher * This routine assumes PDQ interrupts have not been disabled.
185933f810b2SJeff Kirsher * When interrupts are disabled at the PDQ, the Port Status register
186033f810b2SJeff Kirsher * is automatically cleared. This routine uses the Port Status
186133f810b2SJeff Kirsher * register value to determine whether a Type 0 interrupt occurred,
186233f810b2SJeff Kirsher * so it's important that adapter interrupts are not normally
186333f810b2SJeff Kirsher * enabled/disabled at the PDQ.
186433f810b2SJeff Kirsher *
186533f810b2SJeff Kirsher * It's vital that this routine is NOT reentered for the
186633f810b2SJeff Kirsher * same board and that the OS is not in another section of
186733f810b2SJeff Kirsher * code (eg. dfx_xmt_queue_pkt) for the same board on a
186833f810b2SJeff Kirsher * different thread.
186933f810b2SJeff Kirsher *
187033f810b2SJeff Kirsher * Side Effects:
187133f810b2SJeff Kirsher * Pending interrupts are serviced. Depending on the type of
187233f810b2SJeff Kirsher * interrupt, acknowledging and clearing the interrupt at the
187333f810b2SJeff Kirsher * PDQ involves writing a register to clear the interrupt bit
187433f810b2SJeff Kirsher * or updating completion indices.
187533f810b2SJeff Kirsher */
187633f810b2SJeff Kirsher
dfx_int_common(struct net_device * dev)187733f810b2SJeff Kirsher static void dfx_int_common(struct net_device *dev)
187833f810b2SJeff Kirsher {
187933f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
188033f810b2SJeff Kirsher PI_UINT32 port_status; /* Port Status register */
188133f810b2SJeff Kirsher
188233f810b2SJeff Kirsher /* Process xmt interrupts - frequent case, so always call this routine */
188333f810b2SJeff Kirsher
188433f810b2SJeff Kirsher if(dfx_xmt_done(bp)) /* free consumed xmt packets */
188533f810b2SJeff Kirsher netif_wake_queue(dev);
188633f810b2SJeff Kirsher
188733f810b2SJeff Kirsher /* Process rcv interrupts - frequent case, so always call this routine */
188833f810b2SJeff Kirsher
188933f810b2SJeff Kirsher dfx_rcv_queue_process(bp); /* service received LLC frames */
189033f810b2SJeff Kirsher
189133f810b2SJeff Kirsher /*
189233f810b2SJeff Kirsher * Transmit and receive producer and completion indices are updated on the
189333f810b2SJeff Kirsher * adapter by writing to the Type 2 Producer register. Since the frequent
189433f810b2SJeff Kirsher * case is that we'll be processing either LLC transmit or receive buffers,
189533f810b2SJeff Kirsher * we'll optimize I/O writes by doing a single register write here.
189633f810b2SJeff Kirsher */
189733f810b2SJeff Kirsher
189833f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
189933f810b2SJeff Kirsher
190033f810b2SJeff Kirsher /* Read PDQ Port Status register to find out which interrupts need processing */
190133f810b2SJeff Kirsher
190233f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
190333f810b2SJeff Kirsher
190433f810b2SJeff Kirsher /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
190533f810b2SJeff Kirsher
190633f810b2SJeff Kirsher if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
190733f810b2SJeff Kirsher dfx_int_type_0_process(bp); /* process Type 0 interrupts */
190833f810b2SJeff Kirsher }
190933f810b2SJeff Kirsher
191033f810b2SJeff Kirsher
191133f810b2SJeff Kirsher /*
191233f810b2SJeff Kirsher * =================
191333f810b2SJeff Kirsher * = dfx_interrupt =
191433f810b2SJeff Kirsher * =================
191533f810b2SJeff Kirsher *
191633f810b2SJeff Kirsher * Overview:
191733f810b2SJeff Kirsher * Interrupt processing routine
191833f810b2SJeff Kirsher *
191933f810b2SJeff Kirsher * Returns:
192033f810b2SJeff Kirsher * Whether a valid interrupt was seen.
192133f810b2SJeff Kirsher *
192233f810b2SJeff Kirsher * Arguments:
192333f810b2SJeff Kirsher * irq - interrupt vector
192433f810b2SJeff Kirsher * dev_id - pointer to device information
192533f810b2SJeff Kirsher *
192633f810b2SJeff Kirsher * Functional Description:
192733f810b2SJeff Kirsher * This routine calls the interrupt processing routine for this adapter. It
192833f810b2SJeff Kirsher * disables and reenables adapter interrupts, as appropriate. We can support
192933f810b2SJeff Kirsher * shared interrupts since the incoming dev_id pointer provides our device
193033f810b2SJeff Kirsher * structure context.
193133f810b2SJeff Kirsher *
193233f810b2SJeff Kirsher * Return Codes:
193333f810b2SJeff Kirsher * IRQ_HANDLED - an IRQ was handled.
193433f810b2SJeff Kirsher * IRQ_NONE - no IRQ was handled.
193533f810b2SJeff Kirsher *
193633f810b2SJeff Kirsher * Assumptions:
193733f810b2SJeff Kirsher * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
193833f810b2SJeff Kirsher * on Intel-based systems) is done by the operating system outside this
193933f810b2SJeff Kirsher * routine.
194033f810b2SJeff Kirsher *
194133f810b2SJeff Kirsher * System interrupts are enabled through this call.
194233f810b2SJeff Kirsher *
194333f810b2SJeff Kirsher * Side Effects:
194433f810b2SJeff Kirsher * Interrupts are disabled, then reenabled at the adapter.
194533f810b2SJeff Kirsher */
194633f810b2SJeff Kirsher
dfx_interrupt(int irq,void * dev_id)194733f810b2SJeff Kirsher static irqreturn_t dfx_interrupt(int irq, void *dev_id)
194833f810b2SJeff Kirsher {
194933f810b2SJeff Kirsher struct net_device *dev = dev_id;
195033f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
195133f810b2SJeff Kirsher struct device *bdev = bp->bus_dev;
19525349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
195333f810b2SJeff Kirsher int dfx_bus_eisa = DFX_BUS_EISA(bdev);
195433f810b2SJeff Kirsher int dfx_bus_tc = DFX_BUS_TC(bdev);
195533f810b2SJeff Kirsher
195633f810b2SJeff Kirsher /* Service adapter interrupts */
195733f810b2SJeff Kirsher
195833f810b2SJeff Kirsher if (dfx_bus_pci) {
195933f810b2SJeff Kirsher u32 status;
196033f810b2SJeff Kirsher
196133f810b2SJeff Kirsher dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
196233f810b2SJeff Kirsher if (!(status & PFI_STATUS_M_PDQ_INT))
196333f810b2SJeff Kirsher return IRQ_NONE;
196433f810b2SJeff Kirsher
196533f810b2SJeff Kirsher spin_lock(&bp->lock);
196633f810b2SJeff Kirsher
196733f810b2SJeff Kirsher /* Disable PDQ-PFI interrupts at PFI */
196833f810b2SJeff Kirsher dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
196933f810b2SJeff Kirsher PFI_MODE_M_DMA_ENB);
197033f810b2SJeff Kirsher
197133f810b2SJeff Kirsher /* Call interrupt service routine for this adapter */
197233f810b2SJeff Kirsher dfx_int_common(dev);
197333f810b2SJeff Kirsher
197433f810b2SJeff Kirsher /* Clear PDQ interrupt status bit and reenable interrupts */
197533f810b2SJeff Kirsher dfx_port_write_long(bp, PFI_K_REG_STATUS,
197633f810b2SJeff Kirsher PFI_STATUS_M_PDQ_INT);
197733f810b2SJeff Kirsher dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
197833f810b2SJeff Kirsher (PFI_MODE_M_PDQ_INT_ENB |
197933f810b2SJeff Kirsher PFI_MODE_M_DMA_ENB));
198033f810b2SJeff Kirsher
198133f810b2SJeff Kirsher spin_unlock(&bp->lock);
198233f810b2SJeff Kirsher }
198333f810b2SJeff Kirsher if (dfx_bus_eisa) {
198433f810b2SJeff Kirsher unsigned long base_addr = to_eisa_device(bdev)->base_addr;
198533f810b2SJeff Kirsher u8 status;
198633f810b2SJeff Kirsher
198733f810b2SJeff Kirsher status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
198833f810b2SJeff Kirsher if (!(status & PI_CONFIG_STAT_0_M_PEND))
198933f810b2SJeff Kirsher return IRQ_NONE;
199033f810b2SJeff Kirsher
199133f810b2SJeff Kirsher spin_lock(&bp->lock);
199233f810b2SJeff Kirsher
199333f810b2SJeff Kirsher /* Disable interrupts at the ESIC */
199433f810b2SJeff Kirsher status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
19958a189f12SMaciej W. Rozycki outb(status, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
199633f810b2SJeff Kirsher
199733f810b2SJeff Kirsher /* Call interrupt service routine for this adapter */
199833f810b2SJeff Kirsher dfx_int_common(dev);
199933f810b2SJeff Kirsher
200033f810b2SJeff Kirsher /* Reenable interrupts at the ESIC */
200133f810b2SJeff Kirsher status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
200233f810b2SJeff Kirsher status |= PI_CONFIG_STAT_0_M_INT_ENB;
20038a189f12SMaciej W. Rozycki outb(status, base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
200433f810b2SJeff Kirsher
200533f810b2SJeff Kirsher spin_unlock(&bp->lock);
200633f810b2SJeff Kirsher }
200733f810b2SJeff Kirsher if (dfx_bus_tc) {
200833f810b2SJeff Kirsher u32 status;
200933f810b2SJeff Kirsher
201033f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &status);
201133f810b2SJeff Kirsher if (!(status & (PI_PSTATUS_M_RCV_DATA_PENDING |
201233f810b2SJeff Kirsher PI_PSTATUS_M_XMT_DATA_PENDING |
201333f810b2SJeff Kirsher PI_PSTATUS_M_SMT_HOST_PENDING |
201433f810b2SJeff Kirsher PI_PSTATUS_M_UNSOL_PENDING |
201533f810b2SJeff Kirsher PI_PSTATUS_M_CMD_RSP_PENDING |
201633f810b2SJeff Kirsher PI_PSTATUS_M_CMD_REQ_PENDING |
201733f810b2SJeff Kirsher PI_PSTATUS_M_TYPE_0_PENDING)))
201833f810b2SJeff Kirsher return IRQ_NONE;
201933f810b2SJeff Kirsher
202033f810b2SJeff Kirsher spin_lock(&bp->lock);
202133f810b2SJeff Kirsher
202233f810b2SJeff Kirsher /* Call interrupt service routine for this adapter */
202333f810b2SJeff Kirsher dfx_int_common(dev);
202433f810b2SJeff Kirsher
202533f810b2SJeff Kirsher spin_unlock(&bp->lock);
202633f810b2SJeff Kirsher }
202733f810b2SJeff Kirsher
202833f810b2SJeff Kirsher return IRQ_HANDLED;
202933f810b2SJeff Kirsher }
203033f810b2SJeff Kirsher
203133f810b2SJeff Kirsher
203233f810b2SJeff Kirsher /*
203333f810b2SJeff Kirsher * =====================
203433f810b2SJeff Kirsher * = dfx_ctl_get_stats =
203533f810b2SJeff Kirsher * =====================
203633f810b2SJeff Kirsher *
203733f810b2SJeff Kirsher * Overview:
203833f810b2SJeff Kirsher * Get statistics for FDDI adapter
203933f810b2SJeff Kirsher *
204033f810b2SJeff Kirsher * Returns:
204133f810b2SJeff Kirsher * Pointer to FDDI statistics structure
204233f810b2SJeff Kirsher *
204333f810b2SJeff Kirsher * Arguments:
204433f810b2SJeff Kirsher * dev - pointer to device information
204533f810b2SJeff Kirsher *
204633f810b2SJeff Kirsher * Functional Description:
204733f810b2SJeff Kirsher * Gets current MIB objects from adapter, then
204833f810b2SJeff Kirsher * returns FDDI statistics structure as defined
204933f810b2SJeff Kirsher * in if_fddi.h.
205033f810b2SJeff Kirsher *
205133f810b2SJeff Kirsher * Note: Since the FDDI statistics structure is
205233f810b2SJeff Kirsher * still new and the device structure doesn't
205333f810b2SJeff Kirsher * have an FDDI-specific get statistics handler,
205433f810b2SJeff Kirsher * we'll return the FDDI statistics structure as
205533f810b2SJeff Kirsher * a pointer to an Ethernet statistics structure.
205633f810b2SJeff Kirsher * That way, at least the first part of the statistics
205733f810b2SJeff Kirsher * structure can be decoded properly, and it allows
205833f810b2SJeff Kirsher * "smart" applications to perform a second cast to
205933f810b2SJeff Kirsher * decode the FDDI-specific statistics.
206033f810b2SJeff Kirsher *
206133f810b2SJeff Kirsher * We'll have to pay attention to this routine as the
206233f810b2SJeff Kirsher * device structure becomes more mature and LAN media
206333f810b2SJeff Kirsher * independent.
206433f810b2SJeff Kirsher *
206533f810b2SJeff Kirsher * Return Codes:
206633f810b2SJeff Kirsher * None
206733f810b2SJeff Kirsher *
206833f810b2SJeff Kirsher * Assumptions:
206933f810b2SJeff Kirsher * None
207033f810b2SJeff Kirsher *
207133f810b2SJeff Kirsher * Side Effects:
207233f810b2SJeff Kirsher * None
207333f810b2SJeff Kirsher */
207433f810b2SJeff Kirsher
dfx_ctl_get_stats(struct net_device * dev)207533f810b2SJeff Kirsher static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
207633f810b2SJeff Kirsher {
207733f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
207833f810b2SJeff Kirsher
207933f810b2SJeff Kirsher /* Fill the bp->stats structure with driver-maintained counters */
208033f810b2SJeff Kirsher
208133f810b2SJeff Kirsher bp->stats.gen.rx_packets = bp->rcv_total_frames;
208233f810b2SJeff Kirsher bp->stats.gen.tx_packets = bp->xmt_total_frames;
208333f810b2SJeff Kirsher bp->stats.gen.rx_bytes = bp->rcv_total_bytes;
208433f810b2SJeff Kirsher bp->stats.gen.tx_bytes = bp->xmt_total_bytes;
208533f810b2SJeff Kirsher bp->stats.gen.rx_errors = bp->rcv_crc_errors +
208633f810b2SJeff Kirsher bp->rcv_frame_status_errors +
208733f810b2SJeff Kirsher bp->rcv_length_errors;
208833f810b2SJeff Kirsher bp->stats.gen.tx_errors = bp->xmt_length_errors;
208933f810b2SJeff Kirsher bp->stats.gen.rx_dropped = bp->rcv_discards;
209033f810b2SJeff Kirsher bp->stats.gen.tx_dropped = bp->xmt_discards;
209133f810b2SJeff Kirsher bp->stats.gen.multicast = bp->rcv_multicast_frames;
209233f810b2SJeff Kirsher bp->stats.gen.collisions = 0; /* always zero (0) for FDDI */
209333f810b2SJeff Kirsher
209433f810b2SJeff Kirsher /* Get FDDI SMT MIB objects */
209533f810b2SJeff Kirsher
209633f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
209733f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
209833f810b2SJeff Kirsher return (struct net_device_stats *)&bp->stats;
209933f810b2SJeff Kirsher
210033f810b2SJeff Kirsher /* Fill the bp->stats structure with the SMT MIB object values */
210133f810b2SJeff Kirsher
210233f810b2SJeff Kirsher 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));
210333f810b2SJeff Kirsher bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
210433f810b2SJeff Kirsher bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
210533f810b2SJeff Kirsher bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
210633f810b2SJeff Kirsher 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));
210733f810b2SJeff Kirsher bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
210833f810b2SJeff Kirsher bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
210933f810b2SJeff Kirsher bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
211033f810b2SJeff Kirsher bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
211133f810b2SJeff Kirsher bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
211233f810b2SJeff Kirsher bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
211333f810b2SJeff Kirsher bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
211433f810b2SJeff Kirsher bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
211533f810b2SJeff Kirsher bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
211633f810b2SJeff Kirsher bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
211733f810b2SJeff Kirsher bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
211833f810b2SJeff Kirsher bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
211933f810b2SJeff Kirsher bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
212033f810b2SJeff Kirsher bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
212133f810b2SJeff Kirsher bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
212233f810b2SJeff Kirsher bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
212333f810b2SJeff Kirsher bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
212433f810b2SJeff Kirsher bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
212533f810b2SJeff Kirsher bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
212633f810b2SJeff Kirsher bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
212733f810b2SJeff Kirsher bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
212833f810b2SJeff Kirsher bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
212933f810b2SJeff Kirsher bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
213033f810b2SJeff Kirsher bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
213133f810b2SJeff Kirsher memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
213233f810b2SJeff Kirsher memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
213333f810b2SJeff Kirsher memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
213433f810b2SJeff Kirsher memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
213533f810b2SJeff Kirsher bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
213633f810b2SJeff Kirsher bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
213733f810b2SJeff Kirsher bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
213833f810b2SJeff Kirsher memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
213933f810b2SJeff Kirsher bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
214033f810b2SJeff Kirsher bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
214133f810b2SJeff Kirsher bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
214233f810b2SJeff Kirsher bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
214333f810b2SJeff Kirsher bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
214433f810b2SJeff Kirsher bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
214533f810b2SJeff Kirsher bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
214633f810b2SJeff Kirsher bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
214733f810b2SJeff Kirsher bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
214833f810b2SJeff Kirsher bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
214933f810b2SJeff Kirsher bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
215033f810b2SJeff Kirsher bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
215133f810b2SJeff Kirsher bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
215233f810b2SJeff Kirsher bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
215333f810b2SJeff Kirsher bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
215433f810b2SJeff Kirsher bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
215533f810b2SJeff Kirsher memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
215633f810b2SJeff Kirsher bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
215733f810b2SJeff Kirsher bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
215833f810b2SJeff Kirsher bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
215933f810b2SJeff Kirsher bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
216033f810b2SJeff Kirsher bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
216133f810b2SJeff Kirsher bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
216233f810b2SJeff Kirsher bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
216333f810b2SJeff Kirsher bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
216433f810b2SJeff Kirsher bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
216533f810b2SJeff Kirsher bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
216633f810b2SJeff Kirsher memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
216733f810b2SJeff Kirsher memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
216833f810b2SJeff Kirsher bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
216933f810b2SJeff Kirsher bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
217033f810b2SJeff Kirsher bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
217133f810b2SJeff Kirsher bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
217233f810b2SJeff Kirsher bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
217333f810b2SJeff Kirsher bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
217433f810b2SJeff Kirsher bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
217533f810b2SJeff Kirsher bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
217633f810b2SJeff Kirsher bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
217733f810b2SJeff Kirsher bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
217833f810b2SJeff Kirsher bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
217933f810b2SJeff Kirsher bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
218033f810b2SJeff Kirsher bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
218133f810b2SJeff Kirsher bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
218233f810b2SJeff Kirsher bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
218333f810b2SJeff Kirsher bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
218433f810b2SJeff Kirsher bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
218533f810b2SJeff Kirsher bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
218633f810b2SJeff Kirsher bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
218733f810b2SJeff Kirsher bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
218833f810b2SJeff Kirsher bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
218933f810b2SJeff Kirsher bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
219033f810b2SJeff Kirsher bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
219133f810b2SJeff Kirsher bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
219233f810b2SJeff Kirsher bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
219333f810b2SJeff Kirsher bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
219433f810b2SJeff Kirsher
219533f810b2SJeff Kirsher /* Get FDDI counters */
219633f810b2SJeff Kirsher
219733f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
219833f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
219933f810b2SJeff Kirsher return (struct net_device_stats *)&bp->stats;
220033f810b2SJeff Kirsher
220133f810b2SJeff Kirsher /* Fill the bp->stats structure with the FDDI counter values */
220233f810b2SJeff Kirsher
220333f810b2SJeff Kirsher bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
220433f810b2SJeff Kirsher bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
220533f810b2SJeff Kirsher bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
220633f810b2SJeff Kirsher bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
220733f810b2SJeff Kirsher bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
220833f810b2SJeff Kirsher bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
220933f810b2SJeff Kirsher bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
221033f810b2SJeff Kirsher bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
221133f810b2SJeff Kirsher bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
221233f810b2SJeff Kirsher bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
221333f810b2SJeff Kirsher bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
221433f810b2SJeff Kirsher
221533f810b2SJeff Kirsher return (struct net_device_stats *)&bp->stats;
221633f810b2SJeff Kirsher }
221733f810b2SJeff Kirsher
221833f810b2SJeff Kirsher
221933f810b2SJeff Kirsher /*
222033f810b2SJeff Kirsher * ==============================
222133f810b2SJeff Kirsher * = dfx_ctl_set_multicast_list =
222233f810b2SJeff Kirsher * ==============================
222333f810b2SJeff Kirsher *
222433f810b2SJeff Kirsher * Overview:
222533f810b2SJeff Kirsher * Enable/Disable LLC frame promiscuous mode reception
222633f810b2SJeff Kirsher * on the adapter and/or update multicast address table.
222733f810b2SJeff Kirsher *
222833f810b2SJeff Kirsher * Returns:
222933f810b2SJeff Kirsher * None
223033f810b2SJeff Kirsher *
223133f810b2SJeff Kirsher * Arguments:
223233f810b2SJeff Kirsher * dev - pointer to device information
223333f810b2SJeff Kirsher *
223433f810b2SJeff Kirsher * Functional Description:
223533f810b2SJeff Kirsher * This routine follows a fairly simple algorithm for setting the
223633f810b2SJeff Kirsher * adapter filters and CAM:
223733f810b2SJeff Kirsher *
223833f810b2SJeff Kirsher * if IFF_PROMISC flag is set
223933f810b2SJeff Kirsher * enable LLC individual/group promiscuous mode
224033f810b2SJeff Kirsher * else
224133f810b2SJeff Kirsher * disable LLC individual/group promiscuous mode
224233f810b2SJeff Kirsher * if number of incoming multicast addresses >
224333f810b2SJeff Kirsher * (CAM max size - number of unicast addresses in CAM)
224433f810b2SJeff Kirsher * enable LLC group promiscuous mode
224533f810b2SJeff Kirsher * set driver-maintained multicast address count to zero
224633f810b2SJeff Kirsher * else
224733f810b2SJeff Kirsher * disable LLC group promiscuous mode
224833f810b2SJeff Kirsher * set driver-maintained multicast address count to incoming count
224933f810b2SJeff Kirsher * update adapter CAM
225033f810b2SJeff Kirsher * update adapter filters
225133f810b2SJeff Kirsher *
225233f810b2SJeff Kirsher * Return Codes:
225333f810b2SJeff Kirsher * None
225433f810b2SJeff Kirsher *
225533f810b2SJeff Kirsher * Assumptions:
225633f810b2SJeff Kirsher * Multicast addresses are presented in canonical (LSB) format.
225733f810b2SJeff Kirsher *
225833f810b2SJeff Kirsher * Side Effects:
225933f810b2SJeff Kirsher * On-board adapter CAM and filters are updated.
226033f810b2SJeff Kirsher */
226133f810b2SJeff Kirsher
dfx_ctl_set_multicast_list(struct net_device * dev)226233f810b2SJeff Kirsher static void dfx_ctl_set_multicast_list(struct net_device *dev)
226333f810b2SJeff Kirsher {
226433f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
226533f810b2SJeff Kirsher int i; /* used as index in for loop */
226633f810b2SJeff Kirsher struct netdev_hw_addr *ha;
226733f810b2SJeff Kirsher
226833f810b2SJeff Kirsher /* Enable LLC frame promiscuous mode, if necessary */
226933f810b2SJeff Kirsher
227033f810b2SJeff Kirsher if (dev->flags & IFF_PROMISC)
227133f810b2SJeff Kirsher bp->ind_group_prom = PI_FSTATE_K_PASS; /* Enable LLC ind/group prom mode */
227233f810b2SJeff Kirsher
227333f810b2SJeff Kirsher /* Else, update multicast address table */
227433f810b2SJeff Kirsher
227533f810b2SJeff Kirsher else
227633f810b2SJeff Kirsher {
227733f810b2SJeff Kirsher bp->ind_group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC ind/group prom mode */
227833f810b2SJeff Kirsher /*
227933f810b2SJeff Kirsher * Check whether incoming multicast address count exceeds table size
228033f810b2SJeff Kirsher *
228133f810b2SJeff Kirsher * Note: The adapters utilize an on-board 64 entry CAM for
228233f810b2SJeff Kirsher * supporting perfect filtering of multicast packets
228333f810b2SJeff Kirsher * and bridge functions when adding unicast addresses.
228433f810b2SJeff Kirsher * There is no hash function available. To support
228533f810b2SJeff Kirsher * additional multicast addresses, the all multicast
228633f810b2SJeff Kirsher * filter (LLC group promiscuous mode) must be enabled.
228733f810b2SJeff Kirsher *
228833f810b2SJeff Kirsher * The firmware reserves two CAM entries for SMT-related
228933f810b2SJeff Kirsher * multicast addresses, which leaves 62 entries available.
229033f810b2SJeff Kirsher * The following code ensures that we're not being asked
229133f810b2SJeff Kirsher * to add more than 62 addresses to the CAM. If we are,
229233f810b2SJeff Kirsher * the driver will enable the all multicast filter.
229333f810b2SJeff Kirsher * Should the number of multicast addresses drop below
229433f810b2SJeff Kirsher * the high water mark, the filter will be disabled and
229533f810b2SJeff Kirsher * perfect filtering will be used.
229633f810b2SJeff Kirsher */
229733f810b2SJeff Kirsher
229833f810b2SJeff Kirsher if (netdev_mc_count(dev) > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
229933f810b2SJeff Kirsher {
230033f810b2SJeff Kirsher bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
230133f810b2SJeff Kirsher bp->mc_count = 0; /* Don't add mc addrs to CAM */
230233f810b2SJeff Kirsher }
230333f810b2SJeff Kirsher else
230433f810b2SJeff Kirsher {
230533f810b2SJeff Kirsher bp->group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC group prom mode */
230633f810b2SJeff Kirsher bp->mc_count = netdev_mc_count(dev); /* Add mc addrs to CAM */
230733f810b2SJeff Kirsher }
230833f810b2SJeff Kirsher
230933f810b2SJeff Kirsher /* Copy addresses to multicast address table, then update adapter CAM */
231033f810b2SJeff Kirsher
231133f810b2SJeff Kirsher i = 0;
231233f810b2SJeff Kirsher netdev_for_each_mc_addr(ha, dev)
231333f810b2SJeff Kirsher memcpy(&bp->mc_table[i++ * FDDI_K_ALEN],
231433f810b2SJeff Kirsher ha->addr, FDDI_K_ALEN);
231533f810b2SJeff Kirsher
231633f810b2SJeff Kirsher if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
231733f810b2SJeff Kirsher {
231833f810b2SJeff Kirsher DBG_printk("%s: Could not update multicast address table!\n", dev->name);
231933f810b2SJeff Kirsher }
232033f810b2SJeff Kirsher else
232133f810b2SJeff Kirsher {
232233f810b2SJeff Kirsher DBG_printk("%s: Multicast address table updated! Added %d addresses.\n", dev->name, bp->mc_count);
232333f810b2SJeff Kirsher }
232433f810b2SJeff Kirsher }
232533f810b2SJeff Kirsher
232633f810b2SJeff Kirsher /* Update adapter filters */
232733f810b2SJeff Kirsher
232833f810b2SJeff Kirsher if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
232933f810b2SJeff Kirsher {
233033f810b2SJeff Kirsher DBG_printk("%s: Could not update adapter filters!\n", dev->name);
233133f810b2SJeff Kirsher }
233233f810b2SJeff Kirsher else
233333f810b2SJeff Kirsher {
233433f810b2SJeff Kirsher DBG_printk("%s: Adapter filters updated!\n", dev->name);
233533f810b2SJeff Kirsher }
233633f810b2SJeff Kirsher }
233733f810b2SJeff Kirsher
233833f810b2SJeff Kirsher
233933f810b2SJeff Kirsher /*
234033f810b2SJeff Kirsher * ===========================
234133f810b2SJeff Kirsher * = dfx_ctl_set_mac_address =
234233f810b2SJeff Kirsher * ===========================
234333f810b2SJeff Kirsher *
234433f810b2SJeff Kirsher * Overview:
234533f810b2SJeff Kirsher * Add node address override (unicast address) to adapter
234633f810b2SJeff Kirsher * CAM and update dev_addr field in device table.
234733f810b2SJeff Kirsher *
234833f810b2SJeff Kirsher * Returns:
234933f810b2SJeff Kirsher * None
235033f810b2SJeff Kirsher *
235133f810b2SJeff Kirsher * Arguments:
235233f810b2SJeff Kirsher * dev - pointer to device information
235333f810b2SJeff Kirsher * addr - pointer to sockaddr structure containing unicast address to add
235433f810b2SJeff Kirsher *
235533f810b2SJeff Kirsher * Functional Description:
235633f810b2SJeff Kirsher * The adapter supports node address overrides by adding one or more
235733f810b2SJeff Kirsher * unicast addresses to the adapter CAM. This is similar to adding
235833f810b2SJeff Kirsher * multicast addresses. In this routine we'll update the driver and
235933f810b2SJeff Kirsher * device structures with the new address, then update the adapter CAM
236033f810b2SJeff Kirsher * to ensure that the adapter will copy and strip frames destined and
236133f810b2SJeff Kirsher * sourced by that address.
236233f810b2SJeff Kirsher *
236333f810b2SJeff Kirsher * Return Codes:
236433f810b2SJeff Kirsher * Always returns zero.
236533f810b2SJeff Kirsher *
236633f810b2SJeff Kirsher * Assumptions:
236733f810b2SJeff Kirsher * The address pointed to by addr->sa_data is a valid unicast
236833f810b2SJeff Kirsher * address and is presented in canonical (LSB) format.
236933f810b2SJeff Kirsher *
237033f810b2SJeff Kirsher * Side Effects:
237133f810b2SJeff Kirsher * On-board adapter CAM is updated. On-board adapter filters
237233f810b2SJeff Kirsher * may be updated.
237333f810b2SJeff Kirsher */
237433f810b2SJeff Kirsher
dfx_ctl_set_mac_address(struct net_device * dev,void * addr)237533f810b2SJeff Kirsher static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
237633f810b2SJeff Kirsher {
237733f810b2SJeff Kirsher struct sockaddr *p_sockaddr = (struct sockaddr *)addr;
237833f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
237933f810b2SJeff Kirsher
238033f810b2SJeff Kirsher /* Copy unicast address to driver-maintained structs and update count */
238133f810b2SJeff Kirsher
23821e9258c3SJakub Kicinski dev_addr_set(dev, p_sockaddr->sa_data); /* update device struct */
238333f810b2SJeff Kirsher memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN); /* update driver struct */
238433f810b2SJeff Kirsher bp->uc_count = 1;
238533f810b2SJeff Kirsher
238633f810b2SJeff Kirsher /*
238733f810b2SJeff Kirsher * Verify we're not exceeding the CAM size by adding unicast address
238833f810b2SJeff Kirsher *
238933f810b2SJeff Kirsher * Note: It's possible that before entering this routine we've
239033f810b2SJeff Kirsher * already filled the CAM with 62 multicast addresses.
239133f810b2SJeff Kirsher * Since we need to place the node address override into
239233f810b2SJeff Kirsher * the CAM, we have to check to see that we're not
239333f810b2SJeff Kirsher * exceeding the CAM size. If we are, we have to enable
239433f810b2SJeff Kirsher * the LLC group (multicast) promiscuous mode filter as
239533f810b2SJeff Kirsher * in dfx_ctl_set_multicast_list.
239633f810b2SJeff Kirsher */
239733f810b2SJeff Kirsher
239833f810b2SJeff Kirsher if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
239933f810b2SJeff Kirsher {
240033f810b2SJeff Kirsher bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
240133f810b2SJeff Kirsher bp->mc_count = 0; /* Don't add mc addrs to CAM */
240233f810b2SJeff Kirsher
240333f810b2SJeff Kirsher /* Update adapter filters */
240433f810b2SJeff Kirsher
240533f810b2SJeff Kirsher if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
240633f810b2SJeff Kirsher {
240733f810b2SJeff Kirsher DBG_printk("%s: Could not update adapter filters!\n", dev->name);
240833f810b2SJeff Kirsher }
240933f810b2SJeff Kirsher else
241033f810b2SJeff Kirsher {
241133f810b2SJeff Kirsher DBG_printk("%s: Adapter filters updated!\n", dev->name);
241233f810b2SJeff Kirsher }
241333f810b2SJeff Kirsher }
241433f810b2SJeff Kirsher
241533f810b2SJeff Kirsher /* Update adapter CAM with new unicast address */
241633f810b2SJeff Kirsher
241733f810b2SJeff Kirsher if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
241833f810b2SJeff Kirsher {
241933f810b2SJeff Kirsher DBG_printk("%s: Could not set new MAC address!\n", dev->name);
242033f810b2SJeff Kirsher }
242133f810b2SJeff Kirsher else
242233f810b2SJeff Kirsher {
242333f810b2SJeff Kirsher DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev->name);
242433f810b2SJeff Kirsher }
242533f810b2SJeff Kirsher return 0; /* always return zero */
242633f810b2SJeff Kirsher }
242733f810b2SJeff Kirsher
242833f810b2SJeff Kirsher
242933f810b2SJeff Kirsher /*
243033f810b2SJeff Kirsher * ======================
243133f810b2SJeff Kirsher * = dfx_ctl_update_cam =
243233f810b2SJeff Kirsher * ======================
243333f810b2SJeff Kirsher *
243433f810b2SJeff Kirsher * Overview:
243533f810b2SJeff Kirsher * Procedure to update adapter CAM (Content Addressable Memory)
243633f810b2SJeff Kirsher * with desired unicast and multicast address entries.
243733f810b2SJeff Kirsher *
243833f810b2SJeff Kirsher * Returns:
243933f810b2SJeff Kirsher * Condition code
244033f810b2SJeff Kirsher *
244133f810b2SJeff Kirsher * Arguments:
244233f810b2SJeff Kirsher * bp - pointer to board information
244333f810b2SJeff Kirsher *
244433f810b2SJeff Kirsher * Functional Description:
244533f810b2SJeff Kirsher * Updates adapter CAM with current contents of board structure
244633f810b2SJeff Kirsher * unicast and multicast address tables. Since there are only 62
244733f810b2SJeff Kirsher * free entries in CAM, this routine ensures that the command
244833f810b2SJeff Kirsher * request buffer is not overrun.
244933f810b2SJeff Kirsher *
245033f810b2SJeff Kirsher * Return Codes:
245133f810b2SJeff Kirsher * DFX_K_SUCCESS - Request succeeded
245233f810b2SJeff Kirsher * DFX_K_FAILURE - Request failed
245333f810b2SJeff Kirsher *
245433f810b2SJeff Kirsher * Assumptions:
245533f810b2SJeff Kirsher * All addresses being added (unicast and multicast) are in canonical
245633f810b2SJeff Kirsher * order.
245733f810b2SJeff Kirsher *
245833f810b2SJeff Kirsher * Side Effects:
245933f810b2SJeff Kirsher * On-board adapter CAM is updated.
246033f810b2SJeff Kirsher */
246133f810b2SJeff Kirsher
dfx_ctl_update_cam(DFX_board_t * bp)246233f810b2SJeff Kirsher static int dfx_ctl_update_cam(DFX_board_t *bp)
246333f810b2SJeff Kirsher {
246433f810b2SJeff Kirsher int i; /* used as index */
246533f810b2SJeff Kirsher PI_LAN_ADDR *p_addr; /* pointer to CAM entry */
246633f810b2SJeff Kirsher
246733f810b2SJeff Kirsher /*
246833f810b2SJeff Kirsher * Fill in command request information
246933f810b2SJeff Kirsher *
247033f810b2SJeff Kirsher * Note: Even though both the unicast and multicast address
247133f810b2SJeff Kirsher * table entries are stored as contiguous 6 byte entries,
247233f810b2SJeff Kirsher * the firmware address filter set command expects each
247333f810b2SJeff Kirsher * entry to be two longwords (8 bytes total). We must be
247433f810b2SJeff Kirsher * careful to only copy the six bytes of each unicast and
247533f810b2SJeff Kirsher * multicast table entry into each command entry. This
247633f810b2SJeff Kirsher * is also why we must first clear the entire command
247733f810b2SJeff Kirsher * request buffer.
247833f810b2SJeff Kirsher */
247933f810b2SJeff Kirsher
248033f810b2SJeff Kirsher memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX); /* first clear buffer */
248133f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
248233f810b2SJeff Kirsher p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
248333f810b2SJeff Kirsher
248433f810b2SJeff Kirsher /* Now add unicast addresses to command request buffer, if any */
248533f810b2SJeff Kirsher
248633f810b2SJeff Kirsher for (i=0; i < (int)bp->uc_count; i++)
248733f810b2SJeff Kirsher {
248833f810b2SJeff Kirsher if (i < PI_CMD_ADDR_FILTER_K_SIZE)
248933f810b2SJeff Kirsher {
249033f810b2SJeff Kirsher memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
249133f810b2SJeff Kirsher p_addr++; /* point to next command entry */
249233f810b2SJeff Kirsher }
249333f810b2SJeff Kirsher }
249433f810b2SJeff Kirsher
249533f810b2SJeff Kirsher /* Now add multicast addresses to command request buffer, if any */
249633f810b2SJeff Kirsher
249733f810b2SJeff Kirsher for (i=0; i < (int)bp->mc_count; i++)
249833f810b2SJeff Kirsher {
249933f810b2SJeff Kirsher if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
250033f810b2SJeff Kirsher {
250133f810b2SJeff Kirsher memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
250233f810b2SJeff Kirsher p_addr++; /* point to next command entry */
250333f810b2SJeff Kirsher }
250433f810b2SJeff Kirsher }
250533f810b2SJeff Kirsher
250633f810b2SJeff Kirsher /* Issue command to update adapter CAM, then return */
250733f810b2SJeff Kirsher
250833f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
250933f810b2SJeff Kirsher return DFX_K_FAILURE;
251033f810b2SJeff Kirsher return DFX_K_SUCCESS;
251133f810b2SJeff Kirsher }
251233f810b2SJeff Kirsher
251333f810b2SJeff Kirsher
251433f810b2SJeff Kirsher /*
251533f810b2SJeff Kirsher * ==========================
251633f810b2SJeff Kirsher * = dfx_ctl_update_filters =
251733f810b2SJeff Kirsher * ==========================
251833f810b2SJeff Kirsher *
251933f810b2SJeff Kirsher * Overview:
252033f810b2SJeff Kirsher * Procedure to update adapter filters with desired
252133f810b2SJeff Kirsher * filter settings.
252233f810b2SJeff Kirsher *
252333f810b2SJeff Kirsher * Returns:
252433f810b2SJeff Kirsher * Condition code
252533f810b2SJeff Kirsher *
252633f810b2SJeff Kirsher * Arguments:
252733f810b2SJeff Kirsher * bp - pointer to board information
252833f810b2SJeff Kirsher *
252933f810b2SJeff Kirsher * Functional Description:
253033f810b2SJeff Kirsher * Enables or disables filter using current filter settings.
253133f810b2SJeff Kirsher *
253233f810b2SJeff Kirsher * Return Codes:
253333f810b2SJeff Kirsher * DFX_K_SUCCESS - Request succeeded.
253433f810b2SJeff Kirsher * DFX_K_FAILURE - Request failed.
253533f810b2SJeff Kirsher *
253633f810b2SJeff Kirsher * Assumptions:
253733f810b2SJeff Kirsher * We must always pass up packets destined to the broadcast
253833f810b2SJeff Kirsher * address (FF-FF-FF-FF-FF-FF), so we'll always keep the
253933f810b2SJeff Kirsher * broadcast filter enabled.
254033f810b2SJeff Kirsher *
254133f810b2SJeff Kirsher * Side Effects:
254233f810b2SJeff Kirsher * On-board adapter filters are updated.
254333f810b2SJeff Kirsher */
254433f810b2SJeff Kirsher
dfx_ctl_update_filters(DFX_board_t * bp)254533f810b2SJeff Kirsher static int dfx_ctl_update_filters(DFX_board_t *bp)
254633f810b2SJeff Kirsher {
254733f810b2SJeff Kirsher int i = 0; /* used as index */
254833f810b2SJeff Kirsher
254933f810b2SJeff Kirsher /* Fill in command request information */
255033f810b2SJeff Kirsher
255133f810b2SJeff Kirsher bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
255233f810b2SJeff Kirsher
255333f810b2SJeff Kirsher /* Initialize Broadcast filter - * ALWAYS ENABLED * */
255433f810b2SJeff Kirsher
255533f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_BROADCAST;
255633f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i++].value = PI_FSTATE_K_PASS;
255733f810b2SJeff Kirsher
255833f810b2SJeff Kirsher /* Initialize LLC Individual/Group Promiscuous filter */
255933f810b2SJeff Kirsher
256033f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_IND_GROUP_PROM;
256133f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i++].value = bp->ind_group_prom;
256233f810b2SJeff Kirsher
256333f810b2SJeff Kirsher /* Initialize LLC Group Promiscuous filter */
256433f810b2SJeff Kirsher
256533f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_GROUP_PROM;
256633f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i++].value = bp->group_prom;
256733f810b2SJeff Kirsher
256833f810b2SJeff Kirsher /* Terminate the item code list */
256933f810b2SJeff Kirsher
257033f810b2SJeff Kirsher bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_EOL;
257133f810b2SJeff Kirsher
257233f810b2SJeff Kirsher /* Issue command to update adapter filters, then return */
257333f810b2SJeff Kirsher
257433f810b2SJeff Kirsher if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
257533f810b2SJeff Kirsher return DFX_K_FAILURE;
257633f810b2SJeff Kirsher return DFX_K_SUCCESS;
257733f810b2SJeff Kirsher }
257833f810b2SJeff Kirsher
257933f810b2SJeff Kirsher
258033f810b2SJeff Kirsher /*
258133f810b2SJeff Kirsher * ======================
258233f810b2SJeff Kirsher * = dfx_hw_dma_cmd_req =
258333f810b2SJeff Kirsher * ======================
258433f810b2SJeff Kirsher *
258533f810b2SJeff Kirsher * Overview:
258633f810b2SJeff Kirsher * Sends PDQ DMA command to adapter firmware
258733f810b2SJeff Kirsher *
258833f810b2SJeff Kirsher * Returns:
258933f810b2SJeff Kirsher * Condition code
259033f810b2SJeff Kirsher *
259133f810b2SJeff Kirsher * Arguments:
259233f810b2SJeff Kirsher * bp - pointer to board information
259333f810b2SJeff Kirsher *
259433f810b2SJeff Kirsher * Functional Description:
259533f810b2SJeff Kirsher * The command request and response buffers are posted to the adapter in the manner
259633f810b2SJeff Kirsher * described in the PDQ Port Specification:
259733f810b2SJeff Kirsher *
259833f810b2SJeff Kirsher * 1. Command Response Buffer is posted to adapter.
259933f810b2SJeff Kirsher * 2. Command Request Buffer is posted to adapter.
260033f810b2SJeff Kirsher * 3. Command Request consumer index is polled until it indicates that request
260133f810b2SJeff Kirsher * buffer has been DMA'd to adapter.
260233f810b2SJeff Kirsher * 4. Command Response consumer index is polled until it indicates that response
260333f810b2SJeff Kirsher * buffer has been DMA'd from adapter.
260433f810b2SJeff Kirsher *
260533f810b2SJeff Kirsher * This ordering ensures that a response buffer is already available for the firmware
260633f810b2SJeff Kirsher * to use once it's done processing the request buffer.
260733f810b2SJeff Kirsher *
260833f810b2SJeff Kirsher * Return Codes:
260933f810b2SJeff Kirsher * DFX_K_SUCCESS - DMA command succeeded
261033f810b2SJeff Kirsher * DFX_K_OUTSTATE - Adapter is NOT in proper state
261133f810b2SJeff Kirsher * DFX_K_HW_TIMEOUT - DMA command timed out
261233f810b2SJeff Kirsher *
261333f810b2SJeff Kirsher * Assumptions:
261433f810b2SJeff Kirsher * Command request buffer has already been filled with desired DMA command.
261533f810b2SJeff Kirsher *
261633f810b2SJeff Kirsher * Side Effects:
261733f810b2SJeff Kirsher * None
261833f810b2SJeff Kirsher */
261933f810b2SJeff Kirsher
dfx_hw_dma_cmd_req(DFX_board_t * bp)262033f810b2SJeff Kirsher static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
262133f810b2SJeff Kirsher {
262233f810b2SJeff Kirsher int status; /* adapter status */
262333f810b2SJeff Kirsher int timeout_cnt; /* used in for loops */
262433f810b2SJeff Kirsher
262533f810b2SJeff Kirsher /* Make sure the adapter is in a state that we can issue the DMA command in */
262633f810b2SJeff Kirsher
262733f810b2SJeff Kirsher status = dfx_hw_adap_state_rd(bp);
262833f810b2SJeff Kirsher if ((status == PI_STATE_K_RESET) ||
262933f810b2SJeff Kirsher (status == PI_STATE_K_HALTED) ||
263033f810b2SJeff Kirsher (status == PI_STATE_K_DMA_UNAVAIL) ||
263133f810b2SJeff Kirsher (status == PI_STATE_K_UPGRADE))
263233f810b2SJeff Kirsher return DFX_K_OUTSTATE;
263333f810b2SJeff Kirsher
263433f810b2SJeff Kirsher /* Put response buffer on the command response queue */
263533f810b2SJeff Kirsher
263633f810b2SJeff Kirsher bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
263733f810b2SJeff Kirsher ((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
263833f810b2SJeff Kirsher bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
263933f810b2SJeff Kirsher
264033f810b2SJeff Kirsher /* Bump (and wrap) the producer index and write out to register */
264133f810b2SJeff Kirsher
264233f810b2SJeff Kirsher bp->cmd_rsp_reg.index.prod += 1;
264333f810b2SJeff Kirsher bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
264433f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
264533f810b2SJeff Kirsher
264633f810b2SJeff Kirsher /* Put request buffer on the command request queue */
264733f810b2SJeff Kirsher
264833f810b2SJeff Kirsher bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
264933f810b2SJeff Kirsher PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
265033f810b2SJeff Kirsher bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
265133f810b2SJeff Kirsher
265233f810b2SJeff Kirsher /* Bump (and wrap) the producer index and write out to register */
265333f810b2SJeff Kirsher
265433f810b2SJeff Kirsher bp->cmd_req_reg.index.prod += 1;
265533f810b2SJeff Kirsher bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
265633f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
265733f810b2SJeff Kirsher
265833f810b2SJeff Kirsher /*
265933f810b2SJeff Kirsher * Here we wait for the command request consumer index to be equal
266033f810b2SJeff Kirsher * to the producer, indicating that the adapter has DMAed the request.
266133f810b2SJeff Kirsher */
266233f810b2SJeff Kirsher
266333f810b2SJeff Kirsher for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
266433f810b2SJeff Kirsher {
266533f810b2SJeff Kirsher if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
266633f810b2SJeff Kirsher break;
266733f810b2SJeff Kirsher udelay(100); /* wait for 100 microseconds */
266833f810b2SJeff Kirsher }
266933f810b2SJeff Kirsher if (timeout_cnt == 0)
267033f810b2SJeff Kirsher return DFX_K_HW_TIMEOUT;
267133f810b2SJeff Kirsher
267233f810b2SJeff Kirsher /* Bump (and wrap) the completion index and write out to register */
267333f810b2SJeff Kirsher
267433f810b2SJeff Kirsher bp->cmd_req_reg.index.comp += 1;
267533f810b2SJeff Kirsher bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
267633f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
267733f810b2SJeff Kirsher
267833f810b2SJeff Kirsher /*
267933f810b2SJeff Kirsher * Here we wait for the command response consumer index to be equal
268033f810b2SJeff Kirsher * to the producer, indicating that the adapter has DMAed the response.
268133f810b2SJeff Kirsher */
268233f810b2SJeff Kirsher
268333f810b2SJeff Kirsher for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
268433f810b2SJeff Kirsher {
268533f810b2SJeff Kirsher if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
268633f810b2SJeff Kirsher break;
268733f810b2SJeff Kirsher udelay(100); /* wait for 100 microseconds */
268833f810b2SJeff Kirsher }
268933f810b2SJeff Kirsher if (timeout_cnt == 0)
269033f810b2SJeff Kirsher return DFX_K_HW_TIMEOUT;
269133f810b2SJeff Kirsher
269233f810b2SJeff Kirsher /* Bump (and wrap) the completion index and write out to register */
269333f810b2SJeff Kirsher
269433f810b2SJeff Kirsher bp->cmd_rsp_reg.index.comp += 1;
269533f810b2SJeff Kirsher bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
269633f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
269733f810b2SJeff Kirsher return DFX_K_SUCCESS;
269833f810b2SJeff Kirsher }
269933f810b2SJeff Kirsher
270033f810b2SJeff Kirsher
270133f810b2SJeff Kirsher /*
270233f810b2SJeff Kirsher * ========================
270333f810b2SJeff Kirsher * = dfx_hw_port_ctrl_req =
270433f810b2SJeff Kirsher * ========================
270533f810b2SJeff Kirsher *
270633f810b2SJeff Kirsher * Overview:
270733f810b2SJeff Kirsher * Sends PDQ port control command to adapter firmware
270833f810b2SJeff Kirsher *
270933f810b2SJeff Kirsher * Returns:
271033f810b2SJeff Kirsher * Host data register value in host_data if ptr is not NULL
271133f810b2SJeff Kirsher *
271233f810b2SJeff Kirsher * Arguments:
271333f810b2SJeff Kirsher * bp - pointer to board information
271433f810b2SJeff Kirsher * command - port control command
271533f810b2SJeff Kirsher * data_a - port data A register value
271633f810b2SJeff Kirsher * data_b - port data B register value
271733f810b2SJeff Kirsher * host_data - ptr to host data register value
271833f810b2SJeff Kirsher *
271933f810b2SJeff Kirsher * Functional Description:
272033f810b2SJeff Kirsher * Send generic port control command to adapter by writing
272133f810b2SJeff Kirsher * to various PDQ port registers, then polling for completion.
272233f810b2SJeff Kirsher *
272333f810b2SJeff Kirsher * Return Codes:
272433f810b2SJeff Kirsher * DFX_K_SUCCESS - port control command succeeded
272533f810b2SJeff Kirsher * DFX_K_HW_TIMEOUT - port control command timed out
272633f810b2SJeff Kirsher *
272733f810b2SJeff Kirsher * Assumptions:
272833f810b2SJeff Kirsher * None
272933f810b2SJeff Kirsher *
273033f810b2SJeff Kirsher * Side Effects:
273133f810b2SJeff Kirsher * None
273233f810b2SJeff Kirsher */
273333f810b2SJeff Kirsher
dfx_hw_port_ctrl_req(DFX_board_t * bp,PI_UINT32 command,PI_UINT32 data_a,PI_UINT32 data_b,PI_UINT32 * host_data)273433f810b2SJeff Kirsher static int dfx_hw_port_ctrl_req(
273533f810b2SJeff Kirsher DFX_board_t *bp,
273633f810b2SJeff Kirsher PI_UINT32 command,
273733f810b2SJeff Kirsher PI_UINT32 data_a,
273833f810b2SJeff Kirsher PI_UINT32 data_b,
273933f810b2SJeff Kirsher PI_UINT32 *host_data
274033f810b2SJeff Kirsher )
274133f810b2SJeff Kirsher
274233f810b2SJeff Kirsher {
274333f810b2SJeff Kirsher PI_UINT32 port_cmd; /* Port Control command register value */
274433f810b2SJeff Kirsher int timeout_cnt; /* used in for loops */
274533f810b2SJeff Kirsher
274633f810b2SJeff Kirsher /* Set Command Error bit in command longword */
274733f810b2SJeff Kirsher
274833f810b2SJeff Kirsher port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
274933f810b2SJeff Kirsher
275033f810b2SJeff Kirsher /* Issue port command to the adapter */
275133f810b2SJeff Kirsher
275233f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
275333f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
275433f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
275533f810b2SJeff Kirsher
275633f810b2SJeff Kirsher /* Now wait for command to complete */
275733f810b2SJeff Kirsher
275833f810b2SJeff Kirsher if (command == PI_PCTRL_M_BLAST_FLASH)
275933f810b2SJeff Kirsher timeout_cnt = 600000; /* set command timeout count to 60 seconds */
276033f810b2SJeff Kirsher else
276133f810b2SJeff Kirsher timeout_cnt = 20000; /* set command timeout count to 2 seconds */
276233f810b2SJeff Kirsher
276333f810b2SJeff Kirsher for (; timeout_cnt > 0; timeout_cnt--)
276433f810b2SJeff Kirsher {
276533f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
276633f810b2SJeff Kirsher if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
276733f810b2SJeff Kirsher break;
276833f810b2SJeff Kirsher udelay(100); /* wait for 100 microseconds */
276933f810b2SJeff Kirsher }
277033f810b2SJeff Kirsher if (timeout_cnt == 0)
277133f810b2SJeff Kirsher return DFX_K_HW_TIMEOUT;
277233f810b2SJeff Kirsher
277333f810b2SJeff Kirsher /*
277433f810b2SJeff Kirsher * If the address of host_data is non-zero, assume caller has supplied a
277533f810b2SJeff Kirsher * non NULL pointer, and return the contents of the HOST_DATA register in
277633f810b2SJeff Kirsher * it.
277733f810b2SJeff Kirsher */
277833f810b2SJeff Kirsher
277933f810b2SJeff Kirsher if (host_data != NULL)
278033f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
278133f810b2SJeff Kirsher return DFX_K_SUCCESS;
278233f810b2SJeff Kirsher }
278333f810b2SJeff Kirsher
278433f810b2SJeff Kirsher
278533f810b2SJeff Kirsher /*
278633f810b2SJeff Kirsher * =====================
278733f810b2SJeff Kirsher * = dfx_hw_adap_reset =
278833f810b2SJeff Kirsher * =====================
278933f810b2SJeff Kirsher *
279033f810b2SJeff Kirsher * Overview:
279133f810b2SJeff Kirsher * Resets adapter
279233f810b2SJeff Kirsher *
279333f810b2SJeff Kirsher * Returns:
279433f810b2SJeff Kirsher * None
279533f810b2SJeff Kirsher *
279633f810b2SJeff Kirsher * Arguments:
279733f810b2SJeff Kirsher * bp - pointer to board information
279833f810b2SJeff Kirsher * type - type of reset to perform
279933f810b2SJeff Kirsher *
280033f810b2SJeff Kirsher * Functional Description:
280133f810b2SJeff Kirsher * Issue soft reset to adapter by writing to PDQ Port Reset
280233f810b2SJeff Kirsher * register. Use incoming reset type to tell adapter what
280333f810b2SJeff Kirsher * kind of reset operation to perform.
280433f810b2SJeff Kirsher *
280533f810b2SJeff Kirsher * Return Codes:
280633f810b2SJeff Kirsher * None
280733f810b2SJeff Kirsher *
280833f810b2SJeff Kirsher * Assumptions:
280933f810b2SJeff Kirsher * This routine merely issues a soft reset to the adapter.
281033f810b2SJeff Kirsher * It is expected that after this routine returns, the caller
281133f810b2SJeff Kirsher * will appropriately poll the Port Status register for the
281233f810b2SJeff Kirsher * adapter to enter the proper state.
281333f810b2SJeff Kirsher *
281433f810b2SJeff Kirsher * Side Effects:
281533f810b2SJeff Kirsher * Internal adapter registers are cleared.
281633f810b2SJeff Kirsher */
281733f810b2SJeff Kirsher
dfx_hw_adap_reset(DFX_board_t * bp,PI_UINT32 type)281833f810b2SJeff Kirsher static void dfx_hw_adap_reset(
281933f810b2SJeff Kirsher DFX_board_t *bp,
282033f810b2SJeff Kirsher PI_UINT32 type
282133f810b2SJeff Kirsher )
282233f810b2SJeff Kirsher
282333f810b2SJeff Kirsher {
282433f810b2SJeff Kirsher /* Set Reset type and assert reset */
282533f810b2SJeff Kirsher
282633f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type); /* tell adapter type of reset */
282733f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
282833f810b2SJeff Kirsher
282933f810b2SJeff Kirsher /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
283033f810b2SJeff Kirsher
283133f810b2SJeff Kirsher udelay(20);
283233f810b2SJeff Kirsher
283333f810b2SJeff Kirsher /* Deassert reset */
283433f810b2SJeff Kirsher
283533f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
283633f810b2SJeff Kirsher }
283733f810b2SJeff Kirsher
283833f810b2SJeff Kirsher
283933f810b2SJeff Kirsher /*
284033f810b2SJeff Kirsher * ========================
284133f810b2SJeff Kirsher * = dfx_hw_adap_state_rd =
284233f810b2SJeff Kirsher * ========================
284333f810b2SJeff Kirsher *
284433f810b2SJeff Kirsher * Overview:
284533f810b2SJeff Kirsher * Returns current adapter state
284633f810b2SJeff Kirsher *
284733f810b2SJeff Kirsher * Returns:
284833f810b2SJeff Kirsher * Adapter state per PDQ Port Specification
284933f810b2SJeff Kirsher *
285033f810b2SJeff Kirsher * Arguments:
285133f810b2SJeff Kirsher * bp - pointer to board information
285233f810b2SJeff Kirsher *
285333f810b2SJeff Kirsher * Functional Description:
285433f810b2SJeff Kirsher * Reads PDQ Port Status register and returns adapter state.
285533f810b2SJeff Kirsher *
285633f810b2SJeff Kirsher * Return Codes:
285733f810b2SJeff Kirsher * None
285833f810b2SJeff Kirsher *
285933f810b2SJeff Kirsher * Assumptions:
286033f810b2SJeff Kirsher * None
286133f810b2SJeff Kirsher *
286233f810b2SJeff Kirsher * Side Effects:
286333f810b2SJeff Kirsher * None
286433f810b2SJeff Kirsher */
286533f810b2SJeff Kirsher
dfx_hw_adap_state_rd(DFX_board_t * bp)286633f810b2SJeff Kirsher static int dfx_hw_adap_state_rd(DFX_board_t *bp)
286733f810b2SJeff Kirsher {
286833f810b2SJeff Kirsher PI_UINT32 port_status; /* Port Status register value */
286933f810b2SJeff Kirsher
287033f810b2SJeff Kirsher dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
287133f810b2SJeff Kirsher return (port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE;
287233f810b2SJeff Kirsher }
287333f810b2SJeff Kirsher
287433f810b2SJeff Kirsher
287533f810b2SJeff Kirsher /*
287633f810b2SJeff Kirsher * =====================
287733f810b2SJeff Kirsher * = dfx_hw_dma_uninit =
287833f810b2SJeff Kirsher * =====================
287933f810b2SJeff Kirsher *
288033f810b2SJeff Kirsher * Overview:
288133f810b2SJeff Kirsher * Brings adapter to DMA_UNAVAILABLE state
288233f810b2SJeff Kirsher *
288333f810b2SJeff Kirsher * Returns:
288433f810b2SJeff Kirsher * Condition code
288533f810b2SJeff Kirsher *
288633f810b2SJeff Kirsher * Arguments:
288733f810b2SJeff Kirsher * bp - pointer to board information
288833f810b2SJeff Kirsher * type - type of reset to perform
288933f810b2SJeff Kirsher *
289033f810b2SJeff Kirsher * Functional Description:
289133f810b2SJeff Kirsher * Bring adapter to DMA_UNAVAILABLE state by performing the following:
289233f810b2SJeff Kirsher * 1. Set reset type bit in Port Data A Register then reset adapter.
289333f810b2SJeff Kirsher * 2. Check that adapter is in DMA_UNAVAILABLE state.
289433f810b2SJeff Kirsher *
289533f810b2SJeff Kirsher * Return Codes:
289633f810b2SJeff Kirsher * DFX_K_SUCCESS - adapter is in DMA_UNAVAILABLE state
289733f810b2SJeff Kirsher * DFX_K_HW_TIMEOUT - adapter did not reset properly
289833f810b2SJeff Kirsher *
289933f810b2SJeff Kirsher * Assumptions:
290033f810b2SJeff Kirsher * None
290133f810b2SJeff Kirsher *
290233f810b2SJeff Kirsher * Side Effects:
290333f810b2SJeff Kirsher * Internal adapter registers are cleared.
290433f810b2SJeff Kirsher */
290533f810b2SJeff Kirsher
dfx_hw_dma_uninit(DFX_board_t * bp,PI_UINT32 type)290633f810b2SJeff Kirsher static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
290733f810b2SJeff Kirsher {
290833f810b2SJeff Kirsher int timeout_cnt; /* used in for loops */
290933f810b2SJeff Kirsher
291033f810b2SJeff Kirsher /* Set reset type bit and reset adapter */
291133f810b2SJeff Kirsher
291233f810b2SJeff Kirsher dfx_hw_adap_reset(bp, type);
291333f810b2SJeff Kirsher
291433f810b2SJeff Kirsher /* Now wait for adapter to enter DMA_UNAVAILABLE state */
291533f810b2SJeff Kirsher
291633f810b2SJeff Kirsher for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
291733f810b2SJeff Kirsher {
291833f810b2SJeff Kirsher if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
291933f810b2SJeff Kirsher break;
292033f810b2SJeff Kirsher udelay(100); /* wait for 100 microseconds */
292133f810b2SJeff Kirsher }
292233f810b2SJeff Kirsher if (timeout_cnt == 0)
292333f810b2SJeff Kirsher return DFX_K_HW_TIMEOUT;
292433f810b2SJeff Kirsher return DFX_K_SUCCESS;
292533f810b2SJeff Kirsher }
292633f810b2SJeff Kirsher
292733f810b2SJeff Kirsher /*
292833f810b2SJeff Kirsher * Align an sk_buff to a boundary power of 2
292933f810b2SJeff Kirsher *
293033f810b2SJeff Kirsher */
29311b037474SMaciej W. Rozycki #ifdef DYNAMIC_BUFFERS
my_skb_align(struct sk_buff * skb,int n)293233f810b2SJeff Kirsher static void my_skb_align(struct sk_buff *skb, int n)
293333f810b2SJeff Kirsher {
293433f810b2SJeff Kirsher unsigned long x = (unsigned long)skb->data;
293533f810b2SJeff Kirsher unsigned long v;
293633f810b2SJeff Kirsher
293733f810b2SJeff Kirsher v = ALIGN(x, n); /* Where we want to be */
293833f810b2SJeff Kirsher
293933f810b2SJeff Kirsher skb_reserve(skb, v - x);
294033f810b2SJeff Kirsher }
29411b037474SMaciej W. Rozycki #endif
294233f810b2SJeff Kirsher
294333f810b2SJeff Kirsher /*
294433f810b2SJeff Kirsher * ================
294533f810b2SJeff Kirsher * = dfx_rcv_init =
294633f810b2SJeff Kirsher * ================
294733f810b2SJeff Kirsher *
294833f810b2SJeff Kirsher * Overview:
294933f810b2SJeff Kirsher * Produces buffers to adapter LLC Host receive descriptor block
295033f810b2SJeff Kirsher *
295133f810b2SJeff Kirsher * Returns:
295233f810b2SJeff Kirsher * None
295333f810b2SJeff Kirsher *
295433f810b2SJeff Kirsher * Arguments:
295533f810b2SJeff Kirsher * bp - pointer to board information
295633f810b2SJeff Kirsher * get_buffers - non-zero if buffers to be allocated
295733f810b2SJeff Kirsher *
295833f810b2SJeff Kirsher * Functional Description:
295933f810b2SJeff Kirsher * This routine can be called during dfx_adap_init() or during an adapter
296033f810b2SJeff Kirsher * reset. It initializes the descriptor block and produces all allocated
296133f810b2SJeff Kirsher * LLC Host queue receive buffers.
296233f810b2SJeff Kirsher *
296333f810b2SJeff Kirsher * Return Codes:
296433f810b2SJeff Kirsher * Return 0 on success or -ENOMEM if buffer allocation failed (when using
296533f810b2SJeff Kirsher * dynamic buffer allocation). If the buffer allocation failed, the
296633f810b2SJeff Kirsher * already allocated buffers will not be released and the caller should do
296733f810b2SJeff Kirsher * this.
296833f810b2SJeff Kirsher *
296933f810b2SJeff Kirsher * Assumptions:
297033f810b2SJeff Kirsher * The PDQ has been reset and the adapter and driver maintained Type 2
297133f810b2SJeff Kirsher * register indices are cleared.
297233f810b2SJeff Kirsher *
297333f810b2SJeff Kirsher * Side Effects:
297433f810b2SJeff Kirsher * Receive buffers are posted to the adapter LLC queue and the adapter
297533f810b2SJeff Kirsher * is notified.
297633f810b2SJeff Kirsher */
297733f810b2SJeff Kirsher
dfx_rcv_init(DFX_board_t * bp,int get_buffers)297833f810b2SJeff Kirsher static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
297933f810b2SJeff Kirsher {
298033f810b2SJeff Kirsher int i, j; /* used in for loop */
298133f810b2SJeff Kirsher
298233f810b2SJeff Kirsher /*
298333f810b2SJeff Kirsher * Since each receive buffer is a single fragment of same length, initialize
298433f810b2SJeff Kirsher * first longword in each receive descriptor for entire LLC Host descriptor
298533f810b2SJeff Kirsher * block. Also initialize second longword in each receive descriptor with
298633f810b2SJeff Kirsher * physical address of receive buffer. We'll always allocate receive
298733f810b2SJeff Kirsher * buffers in powers of 2 so that we can easily fill the 256 entry descriptor
298833f810b2SJeff Kirsher * block and produce new receive buffers by simply updating the receive
298933f810b2SJeff Kirsher * producer index.
299033f810b2SJeff Kirsher *
299133f810b2SJeff Kirsher * Assumptions:
299233f810b2SJeff Kirsher * To support all shipping versions of PDQ, the receive buffer size
299333f810b2SJeff Kirsher * must be mod 128 in length and the physical address must be 128 byte
299433f810b2SJeff Kirsher * aligned. In other words, bits 0-6 of the length and address must
299533f810b2SJeff Kirsher * be zero for the following descriptor field entries to be correct on
299633f810b2SJeff Kirsher * all PDQ-based boards. We guaranteed both requirements during
299733f810b2SJeff Kirsher * driver initialization when we allocated memory for the receive buffers.
299833f810b2SJeff Kirsher */
299933f810b2SJeff Kirsher
300033f810b2SJeff Kirsher if (get_buffers) {
300133f810b2SJeff Kirsher #ifdef DYNAMIC_BUFFERS
300233f810b2SJeff Kirsher for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
300333f810b2SJeff Kirsher for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
300433f810b2SJeff Kirsher {
3005b37cccf0SMaciej W. Rozycki struct sk_buff *newskb;
3006b37cccf0SMaciej W. Rozycki dma_addr_t dma_addr;
3007b37cccf0SMaciej W. Rozycki
3008b37cccf0SMaciej W. Rozycki newskb = __netdev_alloc_skb(bp->dev, NEW_SKB_SIZE,
3009b37cccf0SMaciej W. Rozycki GFP_NOIO);
301033f810b2SJeff Kirsher if (!newskb)
301133f810b2SJeff Kirsher return -ENOMEM;
301233f810b2SJeff Kirsher /*
301333f810b2SJeff Kirsher * align to 128 bytes for compatibility with
301433f810b2SJeff Kirsher * the old EISA boards.
301533f810b2SJeff Kirsher */
301633f810b2SJeff Kirsher
301733f810b2SJeff Kirsher my_skb_align(newskb, 128);
3018b37cccf0SMaciej W. Rozycki dma_addr = dma_map_single(bp->bus_dev,
3019b37cccf0SMaciej W. Rozycki newskb->data,
3020d68ab591SMaciej W. Rozycki PI_RCV_DATA_K_SIZE_MAX,
302133f810b2SJeff Kirsher DMA_FROM_DEVICE);
3022b37cccf0SMaciej W. Rozycki if (dma_mapping_error(bp->bus_dev, dma_addr)) {
3023b37cccf0SMaciej W. Rozycki dev_kfree_skb(newskb);
3024b37cccf0SMaciej W. Rozycki return -ENOMEM;
3025b37cccf0SMaciej W. Rozycki }
3026b37cccf0SMaciej W. Rozycki bp->descr_block_virt->rcv_data[i + j].long_0 =
3027b37cccf0SMaciej W. Rozycki (u32)(PI_RCV_DESCR_M_SOP |
3028b37cccf0SMaciej W. Rozycki ((PI_RCV_DATA_K_SIZE_MAX /
3029b37cccf0SMaciej W. Rozycki PI_ALIGN_K_RCV_DATA_BUFF) <<
3030b37cccf0SMaciej W. Rozycki PI_RCV_DESCR_V_SEG_LEN));
3031b37cccf0SMaciej W. Rozycki bp->descr_block_virt->rcv_data[i + j].long_1 =
3032b37cccf0SMaciej W. Rozycki (u32)dma_addr;
3033b37cccf0SMaciej W. Rozycki
303433f810b2SJeff Kirsher /*
303533f810b2SJeff Kirsher * p_rcv_buff_va is only used inside the
303633f810b2SJeff Kirsher * kernel so we put the skb pointer here.
303733f810b2SJeff Kirsher */
303833f810b2SJeff Kirsher bp->p_rcv_buff_va[i+j] = (char *) newskb;
303933f810b2SJeff Kirsher }
304033f810b2SJeff Kirsher #else
304133f810b2SJeff Kirsher for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
304233f810b2SJeff Kirsher for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
304333f810b2SJeff Kirsher {
304433f810b2SJeff Kirsher bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
304533f810b2SJeff Kirsher ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
304633f810b2SJeff Kirsher bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
3047c2fd03a0SJoe Perches bp->p_rcv_buff_va[i+j] = (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
304833f810b2SJeff Kirsher }
304933f810b2SJeff Kirsher #endif
305033f810b2SJeff Kirsher }
305133f810b2SJeff Kirsher
305233f810b2SJeff Kirsher /* Update receive producer and Type 2 register */
305333f810b2SJeff Kirsher
305433f810b2SJeff Kirsher bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
305533f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
305633f810b2SJeff Kirsher return 0;
305733f810b2SJeff Kirsher }
305833f810b2SJeff Kirsher
305933f810b2SJeff Kirsher
306033f810b2SJeff Kirsher /*
306133f810b2SJeff Kirsher * =========================
306233f810b2SJeff Kirsher * = dfx_rcv_queue_process =
306333f810b2SJeff Kirsher * =========================
306433f810b2SJeff Kirsher *
306533f810b2SJeff Kirsher * Overview:
306633f810b2SJeff Kirsher * Process received LLC frames.
306733f810b2SJeff Kirsher *
306833f810b2SJeff Kirsher * Returns:
306933f810b2SJeff Kirsher * None
307033f810b2SJeff Kirsher *
307133f810b2SJeff Kirsher * Arguments:
307233f810b2SJeff Kirsher * bp - pointer to board information
307333f810b2SJeff Kirsher *
307433f810b2SJeff Kirsher * Functional Description:
307533f810b2SJeff Kirsher * Received LLC frames are processed until there are no more consumed frames.
307633f810b2SJeff Kirsher * Once all frames are processed, the receive buffers are returned to the
307733f810b2SJeff Kirsher * adapter. Note that this algorithm fixes the length of time that can be spent
307833f810b2SJeff Kirsher * in this routine, because there are a fixed number of receive buffers to
307933f810b2SJeff Kirsher * process and buffers are not produced until this routine exits and returns
308033f810b2SJeff Kirsher * to the ISR.
308133f810b2SJeff Kirsher *
308233f810b2SJeff Kirsher * Return Codes:
308333f810b2SJeff Kirsher * None
308433f810b2SJeff Kirsher *
308533f810b2SJeff Kirsher * Assumptions:
308633f810b2SJeff Kirsher * None
308733f810b2SJeff Kirsher *
308833f810b2SJeff Kirsher * Side Effects:
308933f810b2SJeff Kirsher * None
309033f810b2SJeff Kirsher */
309133f810b2SJeff Kirsher
dfx_rcv_queue_process(DFX_board_t * bp)309233f810b2SJeff Kirsher static void dfx_rcv_queue_process(
309333f810b2SJeff Kirsher DFX_board_t *bp
309433f810b2SJeff Kirsher )
309533f810b2SJeff Kirsher
309633f810b2SJeff Kirsher {
309733f810b2SJeff Kirsher PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
309833f810b2SJeff Kirsher char *p_buff; /* ptr to start of packet receive buffer (FMC descriptor) */
309933f810b2SJeff Kirsher u32 descr, pkt_len; /* FMC descriptor field and packet length */
3100b37cccf0SMaciej W. Rozycki struct sk_buff *skb = NULL; /* pointer to a sk_buff to hold incoming packet data */
310133f810b2SJeff Kirsher
310233f810b2SJeff Kirsher /* Service all consumed LLC receive frames */
310333f810b2SJeff Kirsher
310433f810b2SJeff Kirsher p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
310533f810b2SJeff Kirsher while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
310633f810b2SJeff Kirsher {
310733f810b2SJeff Kirsher /* Process any errors */
31088848761fSMaciej W. Rozycki dma_addr_t dma_addr;
310933f810b2SJeff Kirsher int entry;
311033f810b2SJeff Kirsher
311133f810b2SJeff Kirsher entry = bp->rcv_xmt_reg.index.rcv_comp;
311233f810b2SJeff Kirsher #ifdef DYNAMIC_BUFFERS
311333f810b2SJeff Kirsher p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
311433f810b2SJeff Kirsher #else
3115c2fd03a0SJoe Perches p_buff = bp->p_rcv_buff_va[entry];
311633f810b2SJeff Kirsher #endif
31178848761fSMaciej W. Rozycki dma_addr = bp->descr_block_virt->rcv_data[entry].long_1;
31188848761fSMaciej W. Rozycki dma_sync_single_for_cpu(bp->bus_dev,
31198848761fSMaciej W. Rozycki dma_addr + RCV_BUFF_K_DESCR,
31208848761fSMaciej W. Rozycki sizeof(u32),
31218848761fSMaciej W. Rozycki DMA_FROM_DEVICE);
312233f810b2SJeff Kirsher memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
312333f810b2SJeff Kirsher
312433f810b2SJeff Kirsher if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
312533f810b2SJeff Kirsher {
312633f810b2SJeff Kirsher if (descr & PI_FMC_DESCR_M_RCC_CRC)
312733f810b2SJeff Kirsher bp->rcv_crc_errors++;
312833f810b2SJeff Kirsher else
312933f810b2SJeff Kirsher bp->rcv_frame_status_errors++;
313033f810b2SJeff Kirsher }
313133f810b2SJeff Kirsher else
313233f810b2SJeff Kirsher {
313333f810b2SJeff Kirsher int rx_in_place = 0;
313433f810b2SJeff Kirsher
313533f810b2SJeff Kirsher /* The frame was received without errors - verify packet length */
313633f810b2SJeff Kirsher
313733f810b2SJeff Kirsher pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
313833f810b2SJeff Kirsher pkt_len -= 4; /* subtract 4 byte CRC */
313933f810b2SJeff Kirsher if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
314033f810b2SJeff Kirsher bp->rcv_length_errors++;
314133f810b2SJeff Kirsher else{
314233f810b2SJeff Kirsher #ifdef DYNAMIC_BUFFERS
3143b37cccf0SMaciej W. Rozycki struct sk_buff *newskb = NULL;
3144b37cccf0SMaciej W. Rozycki
314533f810b2SJeff Kirsher if (pkt_len > SKBUFF_RX_COPYBREAK) {
3146b37cccf0SMaciej W. Rozycki dma_addr_t new_dma_addr;
314733f810b2SJeff Kirsher
3148a630be70SMaciej W. Rozycki newskb = netdev_alloc_skb(bp->dev,
3149a630be70SMaciej W. Rozycki NEW_SKB_SIZE);
315033f810b2SJeff Kirsher if (newskb){
3151b37cccf0SMaciej W. Rozycki my_skb_align(newskb, 128);
3152b37cccf0SMaciej W. Rozycki new_dma_addr = dma_map_single(
3153b37cccf0SMaciej W. Rozycki bp->bus_dev,
3154b37cccf0SMaciej W. Rozycki newskb->data,
3155b37cccf0SMaciej W. Rozycki PI_RCV_DATA_K_SIZE_MAX,
3156b37cccf0SMaciej W. Rozycki DMA_FROM_DEVICE);
3157b37cccf0SMaciej W. Rozycki if (dma_mapping_error(
3158b37cccf0SMaciej W. Rozycki bp->bus_dev,
3159b37cccf0SMaciej W. Rozycki new_dma_addr)) {
3160b37cccf0SMaciej W. Rozycki dev_kfree_skb(newskb);
3161b37cccf0SMaciej W. Rozycki newskb = NULL;
3162b37cccf0SMaciej W. Rozycki }
3163b37cccf0SMaciej W. Rozycki }
3164b37cccf0SMaciej W. Rozycki if (newskb) {
316533f810b2SJeff Kirsher rx_in_place = 1;
316633f810b2SJeff Kirsher
316733f810b2SJeff Kirsher skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
316833f810b2SJeff Kirsher dma_unmap_single(bp->bus_dev,
31698848761fSMaciej W. Rozycki dma_addr,
3170d68ab591SMaciej W. Rozycki PI_RCV_DATA_K_SIZE_MAX,
317133f810b2SJeff Kirsher DMA_FROM_DEVICE);
317233f810b2SJeff Kirsher skb_reserve(skb, RCV_BUFF_K_PADDING);
317333f810b2SJeff Kirsher bp->p_rcv_buff_va[entry] = (char *)newskb;
3174b37cccf0SMaciej W. Rozycki bp->descr_block_virt->rcv_data[entry].long_1 = (u32)new_dma_addr;
3175b37cccf0SMaciej W. Rozycki }
3176b37cccf0SMaciej W. Rozycki }
3177b37cccf0SMaciej W. Rozycki if (!newskb)
317833f810b2SJeff Kirsher #endif
3179a630be70SMaciej W. Rozycki /* Alloc new buffer to pass up,
3180a630be70SMaciej W. Rozycki * add room for PRH. */
3181a630be70SMaciej W. Rozycki skb = netdev_alloc_skb(bp->dev,
3182a630be70SMaciej W. Rozycki pkt_len + 3);
318333f810b2SJeff Kirsher if (skb == NULL)
318433f810b2SJeff Kirsher {
318533f810b2SJeff Kirsher printk("%s: Could not allocate receive buffer. Dropping packet.\n", bp->dev->name);
318633f810b2SJeff Kirsher bp->rcv_discards++;
318733f810b2SJeff Kirsher break;
318833f810b2SJeff Kirsher }
318933f810b2SJeff Kirsher else {
3190f46d53d0SMaciej W. Rozycki if (!rx_in_place) {
319133f810b2SJeff Kirsher /* Receive buffer allocated, pass receive packet up */
31928848761fSMaciej W. Rozycki dma_sync_single_for_cpu(
31938848761fSMaciej W. Rozycki bp->bus_dev,
31948848761fSMaciej W. Rozycki dma_addr +
31958848761fSMaciej W. Rozycki RCV_BUFF_K_PADDING,
31968848761fSMaciej W. Rozycki pkt_len + 3,
31978848761fSMaciej W. Rozycki DMA_FROM_DEVICE);
319833f810b2SJeff Kirsher
319933f810b2SJeff Kirsher skb_copy_to_linear_data(skb,
320033f810b2SJeff Kirsher p_buff + RCV_BUFF_K_PADDING,
320133f810b2SJeff Kirsher pkt_len + 3);
320233f810b2SJeff Kirsher }
320333f810b2SJeff Kirsher
320433f810b2SJeff Kirsher skb_reserve(skb,3); /* adjust data field so that it points to FC byte */
320533f810b2SJeff Kirsher skb_put(skb, pkt_len); /* pass up packet length, NOT including CRC */
320633f810b2SJeff Kirsher skb->protocol = fddi_type_trans(skb, bp->dev);
320733f810b2SJeff Kirsher bp->rcv_total_bytes += skb->len;
320833f810b2SJeff Kirsher netif_rx(skb);
320933f810b2SJeff Kirsher
321033f810b2SJeff Kirsher /* Update the rcv counters */
321133f810b2SJeff Kirsher bp->rcv_total_frames++;
321233f810b2SJeff Kirsher if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
321333f810b2SJeff Kirsher bp->rcv_multicast_frames++;
321433f810b2SJeff Kirsher }
321533f810b2SJeff Kirsher }
321633f810b2SJeff Kirsher }
321733f810b2SJeff Kirsher
321833f810b2SJeff Kirsher /*
321933f810b2SJeff Kirsher * Advance the producer (for recycling) and advance the completion
322033f810b2SJeff Kirsher * (for servicing received frames). Note that it is okay to
322133f810b2SJeff Kirsher * advance the producer without checking that it passes the
322233f810b2SJeff Kirsher * completion index because they are both advanced at the same
322333f810b2SJeff Kirsher * rate.
322433f810b2SJeff Kirsher */
322533f810b2SJeff Kirsher
322633f810b2SJeff Kirsher bp->rcv_xmt_reg.index.rcv_prod += 1;
322733f810b2SJeff Kirsher bp->rcv_xmt_reg.index.rcv_comp += 1;
322833f810b2SJeff Kirsher }
322933f810b2SJeff Kirsher }
323033f810b2SJeff Kirsher
323133f810b2SJeff Kirsher
323233f810b2SJeff Kirsher /*
323333f810b2SJeff Kirsher * =====================
323433f810b2SJeff Kirsher * = dfx_xmt_queue_pkt =
323533f810b2SJeff Kirsher * =====================
323633f810b2SJeff Kirsher *
323733f810b2SJeff Kirsher * Overview:
323833f810b2SJeff Kirsher * Queues packets for transmission
323933f810b2SJeff Kirsher *
324033f810b2SJeff Kirsher * Returns:
324133f810b2SJeff Kirsher * Condition code
324233f810b2SJeff Kirsher *
324333f810b2SJeff Kirsher * Arguments:
324433f810b2SJeff Kirsher * skb - pointer to sk_buff to queue for transmission
324533f810b2SJeff Kirsher * dev - pointer to device information
324633f810b2SJeff Kirsher *
324733f810b2SJeff Kirsher * Functional Description:
324833f810b2SJeff Kirsher * Here we assume that an incoming skb transmit request
324933f810b2SJeff Kirsher * is contained in a single physically contiguous buffer
325033f810b2SJeff Kirsher * in which the virtual address of the start of packet
325133f810b2SJeff Kirsher * (skb->data) can be converted to a physical address
3252b38bcb41SCai Huoqing * by using dma_map_single().
325333f810b2SJeff Kirsher *
325433f810b2SJeff Kirsher * Since the adapter architecture requires a three byte
325533f810b2SJeff Kirsher * packet request header to prepend the start of packet,
325633f810b2SJeff Kirsher * we'll write the three byte field immediately prior to
325733f810b2SJeff Kirsher * the FC byte. This assumption is valid because we've
325833f810b2SJeff Kirsher * ensured that dev->hard_header_len includes three pad
325933f810b2SJeff Kirsher * bytes. By posting a single fragment to the adapter,
326033f810b2SJeff Kirsher * we'll reduce the number of descriptor fetches and
326133f810b2SJeff Kirsher * bus traffic needed to send the request.
326233f810b2SJeff Kirsher *
326333f810b2SJeff Kirsher * Also, we can't free the skb until after it's been DMA'd
326433f810b2SJeff Kirsher * out by the adapter, so we'll queue it in the driver and
326533f810b2SJeff Kirsher * return it in dfx_xmt_done.
326633f810b2SJeff Kirsher *
326733f810b2SJeff Kirsher * Return Codes:
326833f810b2SJeff Kirsher * 0 - driver queued packet, link is unavailable, or skbuff was bad
326933f810b2SJeff Kirsher * 1 - caller should requeue the sk_buff for later transmission
327033f810b2SJeff Kirsher *
327133f810b2SJeff Kirsher * Assumptions:
327233f810b2SJeff Kirsher * First and foremost, we assume the incoming skb pointer
327333f810b2SJeff Kirsher * is NOT NULL and is pointing to a valid sk_buff structure.
327433f810b2SJeff Kirsher *
327533f810b2SJeff Kirsher * The outgoing packet is complete, starting with the
327633f810b2SJeff Kirsher * frame control byte including the last byte of data,
327733f810b2SJeff Kirsher * but NOT including the 4 byte CRC. We'll let the
327833f810b2SJeff Kirsher * adapter hardware generate and append the CRC.
327933f810b2SJeff Kirsher *
328033f810b2SJeff Kirsher * The entire packet is stored in one physically
328133f810b2SJeff Kirsher * contiguous buffer which is not cached and whose
328233f810b2SJeff Kirsher * 32-bit physical address can be determined.
328333f810b2SJeff Kirsher *
328433f810b2SJeff Kirsher * It's vital that this routine is NOT reentered for the
328533f810b2SJeff Kirsher * same board and that the OS is not in another section of
328633f810b2SJeff Kirsher * code (eg. dfx_int_common) for the same board on a
328733f810b2SJeff Kirsher * different thread.
328833f810b2SJeff Kirsher *
328933f810b2SJeff Kirsher * Side Effects:
329033f810b2SJeff Kirsher * None
329133f810b2SJeff Kirsher */
329233f810b2SJeff Kirsher
dfx_xmt_queue_pkt(struct sk_buff * skb,struct net_device * dev)329333f810b2SJeff Kirsher static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
329433f810b2SJeff Kirsher struct net_device *dev)
329533f810b2SJeff Kirsher {
329633f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
329733f810b2SJeff Kirsher u8 prod; /* local transmit producer index */
329833f810b2SJeff Kirsher PI_XMT_DESCR *p_xmt_descr; /* ptr to transmit descriptor block entry */
329933f810b2SJeff Kirsher XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
3300b37cccf0SMaciej W. Rozycki dma_addr_t dma_addr;
330133f810b2SJeff Kirsher unsigned long flags;
330233f810b2SJeff Kirsher
330333f810b2SJeff Kirsher netif_stop_queue(dev);
330433f810b2SJeff Kirsher
330533f810b2SJeff Kirsher /*
330633f810b2SJeff Kirsher * Verify that incoming transmit request is OK
330733f810b2SJeff Kirsher *
330833f810b2SJeff Kirsher * Note: The packet size check is consistent with other
330933f810b2SJeff Kirsher * Linux device drivers, although the correct packet
331033f810b2SJeff Kirsher * size should be verified before calling the
331133f810b2SJeff Kirsher * transmit routine.
331233f810b2SJeff Kirsher */
331333f810b2SJeff Kirsher
331433f810b2SJeff Kirsher if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
331533f810b2SJeff Kirsher {
331633f810b2SJeff Kirsher printk("%s: Invalid packet length - %u bytes\n",
331733f810b2SJeff Kirsher dev->name, skb->len);
331833f810b2SJeff Kirsher bp->xmt_length_errors++; /* bump error counter */
331933f810b2SJeff Kirsher netif_wake_queue(dev);
332033f810b2SJeff Kirsher dev_kfree_skb(skb);
332133f810b2SJeff Kirsher return NETDEV_TX_OK; /* return "success" */
332233f810b2SJeff Kirsher }
332333f810b2SJeff Kirsher /*
332433f810b2SJeff Kirsher * See if adapter link is available, if not, free buffer
332533f810b2SJeff Kirsher *
332633f810b2SJeff Kirsher * Note: If the link isn't available, free buffer and return 0
332733f810b2SJeff Kirsher * rather than tell the upper layer to requeue the packet.
332833f810b2SJeff Kirsher * The methodology here is that by the time the link
332933f810b2SJeff Kirsher * becomes available, the packet to be sent will be
333033f810b2SJeff Kirsher * fairly stale. By simply dropping the packet, the
333133f810b2SJeff Kirsher * higher layer protocols will eventually time out
333233f810b2SJeff Kirsher * waiting for response packets which it won't receive.
333333f810b2SJeff Kirsher */
333433f810b2SJeff Kirsher
333533f810b2SJeff Kirsher if (bp->link_available == PI_K_FALSE)
333633f810b2SJeff Kirsher {
333733f810b2SJeff Kirsher if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL) /* is link really available? */
333833f810b2SJeff Kirsher bp->link_available = PI_K_TRUE; /* if so, set flag and continue */
333933f810b2SJeff Kirsher else
334033f810b2SJeff Kirsher {
334133f810b2SJeff Kirsher bp->xmt_discards++; /* bump error counter */
334233f810b2SJeff Kirsher dev_kfree_skb(skb); /* free sk_buff now */
334333f810b2SJeff Kirsher netif_wake_queue(dev);
334433f810b2SJeff Kirsher return NETDEV_TX_OK; /* return "success" */
334533f810b2SJeff Kirsher }
334633f810b2SJeff Kirsher }
334733f810b2SJeff Kirsher
3348b37cccf0SMaciej W. Rozycki /* Write the three PRH bytes immediately before the FC byte */
3349b37cccf0SMaciej W. Rozycki
3350b37cccf0SMaciej W. Rozycki skb_push(skb, 3);
3351b37cccf0SMaciej W. Rozycki skb->data[0] = DFX_PRH0_BYTE; /* these byte values are defined */
3352b37cccf0SMaciej W. Rozycki skb->data[1] = DFX_PRH1_BYTE; /* in the Motorola FDDI MAC chip */
3353b37cccf0SMaciej W. Rozycki skb->data[2] = DFX_PRH2_BYTE; /* specification */
3354b37cccf0SMaciej W. Rozycki
3355b37cccf0SMaciej W. Rozycki dma_addr = dma_map_single(bp->bus_dev, skb->data, skb->len,
3356b37cccf0SMaciej W. Rozycki DMA_TO_DEVICE);
3357b37cccf0SMaciej W. Rozycki if (dma_mapping_error(bp->bus_dev, dma_addr)) {
3358b37cccf0SMaciej W. Rozycki skb_pull(skb, 3);
3359b37cccf0SMaciej W. Rozycki return NETDEV_TX_BUSY;
3360b37cccf0SMaciej W. Rozycki }
3361b37cccf0SMaciej W. Rozycki
336233f810b2SJeff Kirsher spin_lock_irqsave(&bp->lock, flags);
336333f810b2SJeff Kirsher
336433f810b2SJeff Kirsher /* Get the current producer and the next free xmt data descriptor */
336533f810b2SJeff Kirsher
336633f810b2SJeff Kirsher prod = bp->rcv_xmt_reg.index.xmt_prod;
336733f810b2SJeff Kirsher p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
336833f810b2SJeff Kirsher
336933f810b2SJeff Kirsher /*
337033f810b2SJeff Kirsher * Get pointer to auxiliary queue entry to contain information
337133f810b2SJeff Kirsher * for this packet.
337233f810b2SJeff Kirsher *
337333f810b2SJeff Kirsher * Note: The current xmt producer index will become the
337433f810b2SJeff Kirsher * current xmt completion index when we complete this
337533f810b2SJeff Kirsher * packet later on. So, we'll get the pointer to the
337633f810b2SJeff Kirsher * next auxiliary queue entry now before we bump the
337733f810b2SJeff Kirsher * producer index.
337833f810b2SJeff Kirsher */
337933f810b2SJeff Kirsher
338033f810b2SJeff Kirsher p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]); /* also bump producer index */
338133f810b2SJeff Kirsher
338233f810b2SJeff Kirsher /*
338333f810b2SJeff Kirsher * Write the descriptor with buffer info and bump producer
338433f810b2SJeff Kirsher *
338533f810b2SJeff Kirsher * Note: Since we need to start DMA from the packet request
338633f810b2SJeff Kirsher * header, we'll add 3 bytes to the DMA buffer length,
338733f810b2SJeff Kirsher * and we'll determine the physical address of the
338833f810b2SJeff Kirsher * buffer from the PRH, not skb->data.
338933f810b2SJeff Kirsher *
339033f810b2SJeff Kirsher * Assumptions:
339133f810b2SJeff Kirsher * 1. Packet starts with the frame control (FC) byte
339233f810b2SJeff Kirsher * at skb->data.
339333f810b2SJeff Kirsher * 2. The 4-byte CRC is not appended to the buffer or
339433f810b2SJeff Kirsher * included in the length.
339533f810b2SJeff Kirsher * 3. Packet length (skb->len) is from FC to end of
339633f810b2SJeff Kirsher * data, inclusive.
339733f810b2SJeff Kirsher * 4. The packet length does not exceed the maximum
339833f810b2SJeff Kirsher * FDDI LLC frame length of 4491 bytes.
339933f810b2SJeff Kirsher * 5. The entire packet is contained in a physically
340033f810b2SJeff Kirsher * contiguous, non-cached, locked memory space
340133f810b2SJeff Kirsher * comprised of a single buffer pointed to by
340233f810b2SJeff Kirsher * skb->data.
340333f810b2SJeff Kirsher * 6. The physical address of the start of packet
340433f810b2SJeff Kirsher * can be determined from the virtual address
3405b38bcb41SCai Huoqing * by using dma_map_single() and is only 32-bits
340633f810b2SJeff Kirsher * wide.
340733f810b2SJeff Kirsher */
340833f810b2SJeff Kirsher
340933f810b2SJeff Kirsher p_xmt_descr->long_0 = (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
3410b37cccf0SMaciej W. Rozycki p_xmt_descr->long_1 = (u32)dma_addr;
341133f810b2SJeff Kirsher
341233f810b2SJeff Kirsher /*
341333f810b2SJeff Kirsher * Verify that descriptor is actually available
341433f810b2SJeff Kirsher *
341533f810b2SJeff Kirsher * Note: If descriptor isn't available, return 1 which tells
341633f810b2SJeff Kirsher * the upper layer to requeue the packet for later
341733f810b2SJeff Kirsher * transmission.
341833f810b2SJeff Kirsher *
341933f810b2SJeff Kirsher * We need to ensure that the producer never reaches the
342033f810b2SJeff Kirsher * completion, except to indicate that the queue is empty.
342133f810b2SJeff Kirsher */
342233f810b2SJeff Kirsher
342333f810b2SJeff Kirsher if (prod == bp->rcv_xmt_reg.index.xmt_comp)
342433f810b2SJeff Kirsher {
342533f810b2SJeff Kirsher skb_pull(skb,3);
342633f810b2SJeff Kirsher spin_unlock_irqrestore(&bp->lock, flags);
342733f810b2SJeff Kirsher return NETDEV_TX_BUSY; /* requeue packet for later */
342833f810b2SJeff Kirsher }
342933f810b2SJeff Kirsher
343033f810b2SJeff Kirsher /*
343133f810b2SJeff Kirsher * Save info for this packet for xmt done indication routine
343233f810b2SJeff Kirsher *
343333f810b2SJeff Kirsher * Normally, we'd save the producer index in the p_xmt_drv_descr
343433f810b2SJeff Kirsher * structure so that we'd have it handy when we complete this
343533f810b2SJeff Kirsher * packet later (in dfx_xmt_done). However, since the current
343633f810b2SJeff Kirsher * transmit architecture guarantees a single fragment for the
343733f810b2SJeff Kirsher * entire packet, we can simply bump the completion index by
343833f810b2SJeff Kirsher * one (1) for each completed packet.
343933f810b2SJeff Kirsher *
344033f810b2SJeff Kirsher * Note: If this assumption changes and we're presented with
344133f810b2SJeff Kirsher * an inconsistent number of transmit fragments for packet
344233f810b2SJeff Kirsher * data, we'll need to modify this code to save the current
344333f810b2SJeff Kirsher * transmit producer index.
344433f810b2SJeff Kirsher */
344533f810b2SJeff Kirsher
344633f810b2SJeff Kirsher p_xmt_drv_descr->p_skb = skb;
344733f810b2SJeff Kirsher
344833f810b2SJeff Kirsher /* Update Type 2 register */
344933f810b2SJeff Kirsher
345033f810b2SJeff Kirsher bp->rcv_xmt_reg.index.xmt_prod = prod;
345133f810b2SJeff Kirsher dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
345233f810b2SJeff Kirsher spin_unlock_irqrestore(&bp->lock, flags);
345333f810b2SJeff Kirsher netif_wake_queue(dev);
345433f810b2SJeff Kirsher return NETDEV_TX_OK; /* packet queued to adapter */
345533f810b2SJeff Kirsher }
345633f810b2SJeff Kirsher
345733f810b2SJeff Kirsher
345833f810b2SJeff Kirsher /*
345933f810b2SJeff Kirsher * ================
346033f810b2SJeff Kirsher * = dfx_xmt_done =
346133f810b2SJeff Kirsher * ================
346233f810b2SJeff Kirsher *
346333f810b2SJeff Kirsher * Overview:
346433f810b2SJeff Kirsher * Processes all frames that have been transmitted.
346533f810b2SJeff Kirsher *
346633f810b2SJeff Kirsher * Returns:
346733f810b2SJeff Kirsher * None
346833f810b2SJeff Kirsher *
346933f810b2SJeff Kirsher * Arguments:
347033f810b2SJeff Kirsher * bp - pointer to board information
347133f810b2SJeff Kirsher *
347233f810b2SJeff Kirsher * Functional Description:
347333f810b2SJeff Kirsher * For all consumed transmit descriptors that have not
347433f810b2SJeff Kirsher * yet been completed, we'll free the skb we were holding
347533f810b2SJeff Kirsher * onto using dev_kfree_skb and bump the appropriate
347633f810b2SJeff Kirsher * counters.
347733f810b2SJeff Kirsher *
347833f810b2SJeff Kirsher * Return Codes:
347933f810b2SJeff Kirsher * None
348033f810b2SJeff Kirsher *
348133f810b2SJeff Kirsher * Assumptions:
348233f810b2SJeff Kirsher * The Type 2 register is not updated in this routine. It is
348333f810b2SJeff Kirsher * assumed that it will be updated in the ISR when dfx_xmt_done
348433f810b2SJeff Kirsher * returns.
348533f810b2SJeff Kirsher *
348633f810b2SJeff Kirsher * Side Effects:
348733f810b2SJeff Kirsher * None
348833f810b2SJeff Kirsher */
348933f810b2SJeff Kirsher
dfx_xmt_done(DFX_board_t * bp)349033f810b2SJeff Kirsher static int dfx_xmt_done(DFX_board_t *bp)
349133f810b2SJeff Kirsher {
349233f810b2SJeff Kirsher XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
349333f810b2SJeff Kirsher PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
349433f810b2SJeff Kirsher u8 comp; /* local transmit completion index */
349533f810b2SJeff Kirsher int freed = 0; /* buffers freed */
349633f810b2SJeff Kirsher
349733f810b2SJeff Kirsher /* Service all consumed transmit frames */
349833f810b2SJeff Kirsher
349933f810b2SJeff Kirsher p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
350033f810b2SJeff Kirsher while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
350133f810b2SJeff Kirsher {
350233f810b2SJeff Kirsher /* Get pointer to the transmit driver descriptor block information */
350333f810b2SJeff Kirsher
350433f810b2SJeff Kirsher p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
350533f810b2SJeff Kirsher
350633f810b2SJeff Kirsher /* Increment transmit counters */
350733f810b2SJeff Kirsher
350833f810b2SJeff Kirsher bp->xmt_total_frames++;
350933f810b2SJeff Kirsher bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
351033f810b2SJeff Kirsher
351133f810b2SJeff Kirsher /* Return skb to operating system */
351233f810b2SJeff Kirsher comp = bp->rcv_xmt_reg.index.xmt_comp;
351333f810b2SJeff Kirsher dma_unmap_single(bp->bus_dev,
351433f810b2SJeff Kirsher bp->descr_block_virt->xmt_data[comp].long_1,
351533f810b2SJeff Kirsher p_xmt_drv_descr->p_skb->len,
351633f810b2SJeff Kirsher DMA_TO_DEVICE);
35173703a395SYang Wei dev_consume_skb_irq(p_xmt_drv_descr->p_skb);
351833f810b2SJeff Kirsher
351933f810b2SJeff Kirsher /*
352033f810b2SJeff Kirsher * Move to start of next packet by updating completion index
352133f810b2SJeff Kirsher *
352233f810b2SJeff Kirsher * Here we assume that a transmit packet request is always
352333f810b2SJeff Kirsher * serviced by posting one fragment. We can therefore
352433f810b2SJeff Kirsher * simplify the completion code by incrementing the
352533f810b2SJeff Kirsher * completion index by one. This code will need to be
352633f810b2SJeff Kirsher * modified if this assumption changes. See comments
352733f810b2SJeff Kirsher * in dfx_xmt_queue_pkt for more details.
352833f810b2SJeff Kirsher */
352933f810b2SJeff Kirsher
353033f810b2SJeff Kirsher bp->rcv_xmt_reg.index.xmt_comp += 1;
353133f810b2SJeff Kirsher freed++;
353233f810b2SJeff Kirsher }
353333f810b2SJeff Kirsher return freed;
353433f810b2SJeff Kirsher }
353533f810b2SJeff Kirsher
353633f810b2SJeff Kirsher
353733f810b2SJeff Kirsher /*
353833f810b2SJeff Kirsher * =================
353933f810b2SJeff Kirsher * = dfx_rcv_flush =
354033f810b2SJeff Kirsher * =================
354133f810b2SJeff Kirsher *
354233f810b2SJeff Kirsher * Overview:
354333f810b2SJeff Kirsher * Remove all skb's in the receive ring.
354433f810b2SJeff Kirsher *
354533f810b2SJeff Kirsher * Returns:
354633f810b2SJeff Kirsher * None
354733f810b2SJeff Kirsher *
354833f810b2SJeff Kirsher * Arguments:
354933f810b2SJeff Kirsher * bp - pointer to board information
355033f810b2SJeff Kirsher *
355133f810b2SJeff Kirsher * Functional Description:
355233f810b2SJeff Kirsher * Free's all the dynamically allocated skb's that are
355333f810b2SJeff Kirsher * currently attached to the device receive ring. This
355433f810b2SJeff Kirsher * function is typically only used when the device is
355533f810b2SJeff Kirsher * initialized or reinitialized.
355633f810b2SJeff Kirsher *
355733f810b2SJeff Kirsher * Return Codes:
355833f810b2SJeff Kirsher * None
355933f810b2SJeff Kirsher *
356033f810b2SJeff Kirsher * Side Effects:
356133f810b2SJeff Kirsher * None
356233f810b2SJeff Kirsher */
356333f810b2SJeff Kirsher #ifdef DYNAMIC_BUFFERS
dfx_rcv_flush(DFX_board_t * bp)356433f810b2SJeff Kirsher static void dfx_rcv_flush( DFX_board_t *bp )
356533f810b2SJeff Kirsher {
356633f810b2SJeff Kirsher int i, j;
356733f810b2SJeff Kirsher
356833f810b2SJeff Kirsher for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
356933f810b2SJeff Kirsher for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
357033f810b2SJeff Kirsher {
357133f810b2SJeff Kirsher struct sk_buff *skb;
357233f810b2SJeff Kirsher skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
35736329fe5cSMaciej W. Rozycki if (skb) {
35746329fe5cSMaciej W. Rozycki dma_unmap_single(bp->bus_dev,
35756329fe5cSMaciej W. Rozycki bp->descr_block_virt->rcv_data[i+j].long_1,
35766329fe5cSMaciej W. Rozycki PI_RCV_DATA_K_SIZE_MAX,
35776329fe5cSMaciej W. Rozycki DMA_FROM_DEVICE);
357833f810b2SJeff Kirsher dev_kfree_skb(skb);
35796329fe5cSMaciej W. Rozycki }
358033f810b2SJeff Kirsher bp->p_rcv_buff_va[i+j] = NULL;
358133f810b2SJeff Kirsher }
358233f810b2SJeff Kirsher
358333f810b2SJeff Kirsher }
358433f810b2SJeff Kirsher #endif /* DYNAMIC_BUFFERS */
358533f810b2SJeff Kirsher
358633f810b2SJeff Kirsher /*
358733f810b2SJeff Kirsher * =================
358833f810b2SJeff Kirsher * = dfx_xmt_flush =
358933f810b2SJeff Kirsher * =================
359033f810b2SJeff Kirsher *
359133f810b2SJeff Kirsher * Overview:
359233f810b2SJeff Kirsher * Processes all frames whether they've been transmitted
359333f810b2SJeff Kirsher * or not.
359433f810b2SJeff Kirsher *
359533f810b2SJeff Kirsher * Returns:
359633f810b2SJeff Kirsher * None
359733f810b2SJeff Kirsher *
359833f810b2SJeff Kirsher * Arguments:
359933f810b2SJeff Kirsher * bp - pointer to board information
360033f810b2SJeff Kirsher *
360133f810b2SJeff Kirsher * Functional Description:
360233f810b2SJeff Kirsher * For all produced transmit descriptors that have not
360333f810b2SJeff Kirsher * yet been completed, we'll free the skb we were holding
360433f810b2SJeff Kirsher * onto using dev_kfree_skb and bump the appropriate
360533f810b2SJeff Kirsher * counters. Of course, it's possible that some of
360633f810b2SJeff Kirsher * these transmit requests actually did go out, but we
360733f810b2SJeff Kirsher * won't make that distinction here. Finally, we'll
360833f810b2SJeff Kirsher * update the consumer index to match the producer.
360933f810b2SJeff Kirsher *
361033f810b2SJeff Kirsher * Return Codes:
361133f810b2SJeff Kirsher * None
361233f810b2SJeff Kirsher *
361333f810b2SJeff Kirsher * Assumptions:
361433f810b2SJeff Kirsher * This routine does NOT update the Type 2 register. It
361533f810b2SJeff Kirsher * is assumed that this routine is being called during a
361633f810b2SJeff Kirsher * transmit flush interrupt, or a shutdown or close routine.
361733f810b2SJeff Kirsher *
361833f810b2SJeff Kirsher * Side Effects:
361933f810b2SJeff Kirsher * None
362033f810b2SJeff Kirsher */
362133f810b2SJeff Kirsher
dfx_xmt_flush(DFX_board_t * bp)362233f810b2SJeff Kirsher static void dfx_xmt_flush( DFX_board_t *bp )
362333f810b2SJeff Kirsher {
362433f810b2SJeff Kirsher u32 prod_cons; /* rcv/xmt consumer block longword */
362533f810b2SJeff Kirsher XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
362633f810b2SJeff Kirsher u8 comp; /* local transmit completion index */
362733f810b2SJeff Kirsher
362833f810b2SJeff Kirsher /* Flush all outstanding transmit frames */
362933f810b2SJeff Kirsher
363033f810b2SJeff Kirsher while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
363133f810b2SJeff Kirsher {
363233f810b2SJeff Kirsher /* Get pointer to the transmit driver descriptor block information */
363333f810b2SJeff Kirsher
363433f810b2SJeff Kirsher p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
363533f810b2SJeff Kirsher
363633f810b2SJeff Kirsher /* Return skb to operating system */
363733f810b2SJeff Kirsher comp = bp->rcv_xmt_reg.index.xmt_comp;
363833f810b2SJeff Kirsher dma_unmap_single(bp->bus_dev,
363933f810b2SJeff Kirsher bp->descr_block_virt->xmt_data[comp].long_1,
364033f810b2SJeff Kirsher p_xmt_drv_descr->p_skb->len,
364133f810b2SJeff Kirsher DMA_TO_DEVICE);
364233f810b2SJeff Kirsher dev_kfree_skb(p_xmt_drv_descr->p_skb);
364333f810b2SJeff Kirsher
364433f810b2SJeff Kirsher /* Increment transmit error counter */
364533f810b2SJeff Kirsher
364633f810b2SJeff Kirsher bp->xmt_discards++;
364733f810b2SJeff Kirsher
364833f810b2SJeff Kirsher /*
364933f810b2SJeff Kirsher * Move to start of next packet by updating completion index
365033f810b2SJeff Kirsher *
365133f810b2SJeff Kirsher * Here we assume that a transmit packet request is always
365233f810b2SJeff Kirsher * serviced by posting one fragment. We can therefore
365333f810b2SJeff Kirsher * simplify the completion code by incrementing the
365433f810b2SJeff Kirsher * completion index by one. This code will need to be
365533f810b2SJeff Kirsher * modified if this assumption changes. See comments
365633f810b2SJeff Kirsher * in dfx_xmt_queue_pkt for more details.
365733f810b2SJeff Kirsher */
365833f810b2SJeff Kirsher
365933f810b2SJeff Kirsher bp->rcv_xmt_reg.index.xmt_comp += 1;
366033f810b2SJeff Kirsher }
366133f810b2SJeff Kirsher
366233f810b2SJeff Kirsher /* Update the transmit consumer index in the consumer block */
366333f810b2SJeff Kirsher
366433f810b2SJeff Kirsher prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
366533f810b2SJeff Kirsher prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
366633f810b2SJeff Kirsher bp->cons_block_virt->xmt_rcv_data = prod_cons;
366733f810b2SJeff Kirsher }
366833f810b2SJeff Kirsher
366933f810b2SJeff Kirsher /*
367033f810b2SJeff Kirsher * ==================
367133f810b2SJeff Kirsher * = dfx_unregister =
367233f810b2SJeff Kirsher * ==================
367333f810b2SJeff Kirsher *
367433f810b2SJeff Kirsher * Overview:
367533f810b2SJeff Kirsher * Shuts down an FDDI controller
367633f810b2SJeff Kirsher *
367733f810b2SJeff Kirsher * Returns:
367833f810b2SJeff Kirsher * Condition code
367933f810b2SJeff Kirsher *
368033f810b2SJeff Kirsher * Arguments:
368133f810b2SJeff Kirsher * bdev - pointer to device information
368233f810b2SJeff Kirsher *
368333f810b2SJeff Kirsher * Functional Description:
368433f810b2SJeff Kirsher *
368533f810b2SJeff Kirsher * Return Codes:
368633f810b2SJeff Kirsher * None
368733f810b2SJeff Kirsher *
368833f810b2SJeff Kirsher * Assumptions:
368933f810b2SJeff Kirsher * It compiles so it should work :-( (PCI cards do :-)
369033f810b2SJeff Kirsher *
369133f810b2SJeff Kirsher * Side Effects:
369233f810b2SJeff Kirsher * Device structures for FDDI adapters (fddi0, fddi1, etc) are
369333f810b2SJeff Kirsher * freed.
369433f810b2SJeff Kirsher */
dfx_unregister(struct device * bdev)3695c354dfc3SBill Pemberton static void dfx_unregister(struct device *bdev)
369633f810b2SJeff Kirsher {
369733f810b2SJeff Kirsher struct net_device *dev = dev_get_drvdata(bdev);
369833f810b2SJeff Kirsher DFX_board_t *bp = netdev_priv(dev);
36995349d937SYijing Wang int dfx_bus_pci = dev_is_pci(bdev);
370062f2aaabSSudip Mukherjee resource_size_t bar_start[3] = {0}; /* pointers to ports */
370162f2aaabSSudip Mukherjee resource_size_t bar_len[3] = {0}; /* resource lengths */
370233f810b2SJeff Kirsher int alloc_size; /* total buffer size used */
370333f810b2SJeff Kirsher
370433f810b2SJeff Kirsher unregister_netdev(dev);
370533f810b2SJeff Kirsher
370633f810b2SJeff Kirsher alloc_size = sizeof(PI_DESCR_BLOCK) +
370733f810b2SJeff Kirsher PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
370833f810b2SJeff Kirsher #ifndef DYNAMIC_BUFFERS
370933f810b2SJeff Kirsher (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
371033f810b2SJeff Kirsher #endif
371133f810b2SJeff Kirsher sizeof(PI_CONSUMER_BLOCK) +
371233f810b2SJeff Kirsher (PI_ALIGN_K_DESC_BLK - 1);
371333f810b2SJeff Kirsher if (bp->kmalloced)
371433f810b2SJeff Kirsher dma_free_coherent(bdev, alloc_size,
371533f810b2SJeff Kirsher bp->kmalloced, bp->kmalloced_dma);
371633f810b2SJeff Kirsher
371733f810b2SJeff Kirsher dfx_bus_uninit(dev);
371833f810b2SJeff Kirsher
3719795e272eSMaciej W. Rozycki dfx_get_bars(bp, bar_start, bar_len);
37204d0438e5SMaciej W. Rozycki if (bar_start[2] != 0)
37214d0438e5SMaciej W. Rozycki release_region(bar_start[2], bar_len[2]);
37224d0438e5SMaciej W. Rozycki if (bar_start[1] != 0)
37234d0438e5SMaciej W. Rozycki release_region(bar_start[1], bar_len[1]);
372433f810b2SJeff Kirsher if (dfx_use_mmio) {
372533f810b2SJeff Kirsher iounmap(bp->base.mem);
37264d0438e5SMaciej W. Rozycki release_mem_region(bar_start[0], bar_len[0]);
372733f810b2SJeff Kirsher } else
37284d0438e5SMaciej W. Rozycki release_region(bar_start[0], bar_len[0]);
372933f810b2SJeff Kirsher
373033f810b2SJeff Kirsher if (dfx_bus_pci)
373133f810b2SJeff Kirsher pci_disable_device(to_pci_dev(bdev));
373233f810b2SJeff Kirsher
373333f810b2SJeff Kirsher free_netdev(dev);
373433f810b2SJeff Kirsher }
373533f810b2SJeff Kirsher
373633f810b2SJeff Kirsher
3737c354dfc3SBill Pemberton static int __maybe_unused dfx_dev_register(struct device *);
3738c354dfc3SBill Pemberton static int __maybe_unused dfx_dev_unregister(struct device *);
373933f810b2SJeff Kirsher
374033f810b2SJeff Kirsher #ifdef CONFIG_PCI
37411dd06ae8SGreg Kroah-Hartman static int dfx_pci_register(struct pci_dev *, const struct pci_device_id *);
3742c354dfc3SBill Pemberton static void dfx_pci_unregister(struct pci_dev *);
374333f810b2SJeff Kirsher
37449baa3c34SBenoit Taine static const struct pci_device_id dfx_pci_table[] = {
374533f810b2SJeff Kirsher { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI) },
374633f810b2SJeff Kirsher { }
374733f810b2SJeff Kirsher };
374833f810b2SJeff Kirsher MODULE_DEVICE_TABLE(pci, dfx_pci_table);
374933f810b2SJeff Kirsher
375033f810b2SJeff Kirsher static struct pci_driver dfx_pci_driver = {
37514e052626SMaciej W. Rozycki .name = DRV_NAME,
375233f810b2SJeff Kirsher .id_table = dfx_pci_table,
375333f810b2SJeff Kirsher .probe = dfx_pci_register,
3754c354dfc3SBill Pemberton .remove = dfx_pci_unregister,
375533f810b2SJeff Kirsher };
375633f810b2SJeff Kirsher
dfx_pci_register(struct pci_dev * pdev,const struct pci_device_id * ent)3757c354dfc3SBill Pemberton static int dfx_pci_register(struct pci_dev *pdev,
375833f810b2SJeff Kirsher const struct pci_device_id *ent)
375933f810b2SJeff Kirsher {
376033f810b2SJeff Kirsher return dfx_register(&pdev->dev);
376133f810b2SJeff Kirsher }
376233f810b2SJeff Kirsher
dfx_pci_unregister(struct pci_dev * pdev)3763c354dfc3SBill Pemberton static void dfx_pci_unregister(struct pci_dev *pdev)
376433f810b2SJeff Kirsher {
376533f810b2SJeff Kirsher dfx_unregister(&pdev->dev);
376633f810b2SJeff Kirsher }
376733f810b2SJeff Kirsher #endif /* CONFIG_PCI */
376833f810b2SJeff Kirsher
376933f810b2SJeff Kirsher #ifdef CONFIG_EISA
377046d9ceaaSArvind Yadav static const struct eisa_device_id dfx_eisa_table[] = {
377133f810b2SJeff Kirsher { "DEC3001", DEFEA_PROD_ID_1 },
377233f810b2SJeff Kirsher { "DEC3002", DEFEA_PROD_ID_2 },
377333f810b2SJeff Kirsher { "DEC3003", DEFEA_PROD_ID_3 },
377433f810b2SJeff Kirsher { "DEC3004", DEFEA_PROD_ID_4 },
377533f810b2SJeff Kirsher { }
377633f810b2SJeff Kirsher };
377733f810b2SJeff Kirsher MODULE_DEVICE_TABLE(eisa, dfx_eisa_table);
377833f810b2SJeff Kirsher
377933f810b2SJeff Kirsher static struct eisa_driver dfx_eisa_driver = {
378033f810b2SJeff Kirsher .id_table = dfx_eisa_table,
378133f810b2SJeff Kirsher .driver = {
37824e052626SMaciej W. Rozycki .name = DRV_NAME,
378333f810b2SJeff Kirsher .bus = &eisa_bus_type,
378433f810b2SJeff Kirsher .probe = dfx_dev_register,
3785c354dfc3SBill Pemberton .remove = dfx_dev_unregister,
378633f810b2SJeff Kirsher },
378733f810b2SJeff Kirsher };
378833f810b2SJeff Kirsher #endif /* CONFIG_EISA */
378933f810b2SJeff Kirsher
379033f810b2SJeff Kirsher #ifdef CONFIG_TC
379133f810b2SJeff Kirsher static struct tc_device_id const dfx_tc_table[] = {
379233f810b2SJeff Kirsher { "DEC ", "PMAF-FA " },
379333f810b2SJeff Kirsher { "DEC ", "PMAF-FD " },
379433f810b2SJeff Kirsher { "DEC ", "PMAF-FS " },
379533f810b2SJeff Kirsher { "DEC ", "PMAF-FU " },
379633f810b2SJeff Kirsher { }
379733f810b2SJeff Kirsher };
379833f810b2SJeff Kirsher MODULE_DEVICE_TABLE(tc, dfx_tc_table);
379933f810b2SJeff Kirsher
380033f810b2SJeff Kirsher static struct tc_driver dfx_tc_driver = {
380133f810b2SJeff Kirsher .id_table = dfx_tc_table,
380233f810b2SJeff Kirsher .driver = {
38034e052626SMaciej W. Rozycki .name = DRV_NAME,
380433f810b2SJeff Kirsher .bus = &tc_bus_type,
380533f810b2SJeff Kirsher .probe = dfx_dev_register,
3806c354dfc3SBill Pemberton .remove = dfx_dev_unregister,
380733f810b2SJeff Kirsher },
380833f810b2SJeff Kirsher };
380933f810b2SJeff Kirsher #endif /* CONFIG_TC */
381033f810b2SJeff Kirsher
dfx_dev_register(struct device * dev)3811c354dfc3SBill Pemberton static int __maybe_unused dfx_dev_register(struct device *dev)
381233f810b2SJeff Kirsher {
381333f810b2SJeff Kirsher int status;
381433f810b2SJeff Kirsher
381533f810b2SJeff Kirsher status = dfx_register(dev);
381633f810b2SJeff Kirsher if (!status)
381733f810b2SJeff Kirsher get_device(dev);
381833f810b2SJeff Kirsher return status;
381933f810b2SJeff Kirsher }
382033f810b2SJeff Kirsher
dfx_dev_unregister(struct device * dev)3821c354dfc3SBill Pemberton static int __maybe_unused dfx_dev_unregister(struct device *dev)
382233f810b2SJeff Kirsher {
382333f810b2SJeff Kirsher put_device(dev);
382433f810b2SJeff Kirsher dfx_unregister(dev);
382533f810b2SJeff Kirsher return 0;
382633f810b2SJeff Kirsher }
382733f810b2SJeff Kirsher
382833f810b2SJeff Kirsher
dfx_init(void)3829c354dfc3SBill Pemberton static int dfx_init(void)
383033f810b2SJeff Kirsher {
383133f810b2SJeff Kirsher int status;
383233f810b2SJeff Kirsher
383333f810b2SJeff Kirsher status = pci_register_driver(&dfx_pci_driver);
3834*ae18dcdfSYongqiang Liu if (status)
3835*ae18dcdfSYongqiang Liu goto err_pci_register;
3836*ae18dcdfSYongqiang Liu
383733f810b2SJeff Kirsher status = eisa_driver_register(&dfx_eisa_driver);
3838*ae18dcdfSYongqiang Liu if (status)
3839*ae18dcdfSYongqiang Liu goto err_eisa_register;
3840*ae18dcdfSYongqiang Liu
384133f810b2SJeff Kirsher status = tc_register_driver(&dfx_tc_driver);
3842*ae18dcdfSYongqiang Liu if (status)
3843*ae18dcdfSYongqiang Liu goto err_tc_register;
3844*ae18dcdfSYongqiang Liu
3845*ae18dcdfSYongqiang Liu return 0;
3846*ae18dcdfSYongqiang Liu
3847*ae18dcdfSYongqiang Liu err_tc_register:
3848*ae18dcdfSYongqiang Liu eisa_driver_unregister(&dfx_eisa_driver);
3849*ae18dcdfSYongqiang Liu err_eisa_register:
3850*ae18dcdfSYongqiang Liu pci_unregister_driver(&dfx_pci_driver);
3851*ae18dcdfSYongqiang Liu err_pci_register:
385233f810b2SJeff Kirsher return status;
385333f810b2SJeff Kirsher }
385433f810b2SJeff Kirsher
dfx_cleanup(void)3855c354dfc3SBill Pemberton static void dfx_cleanup(void)
385633f810b2SJeff Kirsher {
385733f810b2SJeff Kirsher tc_unregister_driver(&dfx_tc_driver);
385833f810b2SJeff Kirsher eisa_driver_unregister(&dfx_eisa_driver);
385933f810b2SJeff Kirsher pci_unregister_driver(&dfx_pci_driver);
386033f810b2SJeff Kirsher }
386133f810b2SJeff Kirsher
386233f810b2SJeff Kirsher module_init(dfx_init);
386333f810b2SJeff Kirsher module_exit(dfx_cleanup);
386433f810b2SJeff Kirsher MODULE_AUTHOR("Lawrence V. Stefani");
386533f810b2SJeff Kirsher MODULE_DESCRIPTION("DEC FDDIcontroller TC/EISA/PCI (DEFTA/DEFEA/DEFPA) driver "
386633f810b2SJeff Kirsher DRV_VERSION " " DRV_RELDATE);
386733f810b2SJeff Kirsher MODULE_LICENSE("GPL");
3868