Blame view

drivers/net/defxx.c 113 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
  /*
   * File Name:
   *   defxx.c
   *
   * Copyright Information:
   *   Copyright Digital Equipment Corporation 1996.
   *
   *   This software may be used and distributed according to the terms of
   *   the GNU General Public License, incorporated herein by reference.
   *
   * Abstract:
   *   A Linux device driver supporting the Digital Equipment Corporation
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
13
14
   *   FDDI TURBOchannel, EISA and PCI controller families.  Supported
   *   adapters include:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
   *
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
16
17
18
   *		DEC FDDIcontroller/TURBOchannel (DEFTA)
   *		DEC FDDIcontroller/EISA         (DEFEA)
   *		DEC FDDIcontroller/PCI          (DEFPA)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
   *
   * The original author:
   *   LVS	Lawrence V. Stefani <lstefani@yahoo.com>
   *
   * Maintainers:
   *   macro	Maciej W. Rozycki <macro@linux-mips.org>
   *
   * Credits:
   *   I'd like to thank Patricia Cross for helping me get started with
   *   Linux, David Davies for a lot of help upgrading and configuring
   *   my development system and for answering many OS and driver
   *   development questions, and Alan Cox for recommendations and
   *   integration help on getting FDDI support into Linux.  LVS
   *
   * Driver Architecture:
   *   The driver architecture is largely based on previous driver work
   *   for other operating systems.  The upper edge interface and
   *   functions were largely taken from existing Linux device drivers
   *   such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
   *   driver.
   *
   *   Adapter Probe -
   *		The driver scans for supported EISA adapters by reading the
   *		SLOT ID register for each EISA slot and making a match
   *		against the expected value.
   *
   *   Bus-Specific Initialization -
   *		This driver currently supports both EISA and PCI controller
   *		families.  While the custom DMA chip and FDDI logic is similar
   *		or identical, the bus logic is very different.  After
   *		initialization, the	only bus-specific differences is in how the
   *		driver enables and disables interrupts.  Other than that, the
   *		run-time critical code behaves the same on both families.
   *		It's important to note that both adapter families are configured
   *		to I/O map, rather than memory map, the adapter registers.
   *
   *   Driver Open/Close -
   *		In the driver open routine, the driver ISR (interrupt service
   *		routine) is registered and the adapter is brought to an
   *		operational state.  In the driver close routine, the opposite
   *		occurs; the driver ISR is deregistered and the adapter is
   *		brought to a safe, but closed state.  Users may use consecutive
   *		commands to bring the adapter up and down as in the following
   *		example:
   *					ifconfig fddi0 up
   *					ifconfig fddi0 down
   *					ifconfig fddi0 up
   *
   *   Driver Shutdown -
   *		Apparently, there is no shutdown or halt routine support under
   *		Linux.  This routine would be called during "reboot" or
   *		"shutdown" to allow the driver to place the adapter in a safe
   *		state before a warm reboot occurs.  To be really safe, the user
   *		should close the adapter before shutdown (eg. ifconfig fddi0 down)
   *		to ensure that the adapter DMA engine is taken off-line.  However,
   *		the current driver code anticipates this problem and always issues
   *		a soft reset of the adapter	at the beginning of driver initialization.
   *		A future driver enhancement in this area may occur in 2.1.X where
   *		Alan indicated that a shutdown handler may be implemented.
   *
   *   Interrupt Service Routine -
   *		The driver supports shared interrupts, so the ISR is registered for
   *		each board with the appropriate flag and the pointer to that board's
   *		device structure.  This provides the context during interrupt
   *		processing to support shared interrupts and multiple boards.
   *
   *		Interrupt enabling/disabling can occur at many levels.  At the host
   *		end, you can disable system interrupts, or disable interrupts at the
   *		PIC (on Intel systems).  Across the bus, both EISA and PCI adapters
   *		have a bus-logic chip interrupt enable/disable as well as a DMA
   *		controller interrupt enable/disable.
   *
   *		The driver currently enables and disables adapter interrupts at the
   *		bus-logic chip and assumes that Linux will take care of clearing or
   *		acknowledging any host-based interrupt chips.
   *
   *   Control Functions -
   *		Control functions are those used to support functions such as adding
   *		or deleting multicast addresses, enabling or disabling packet
   *		reception filters, or other custom/proprietary commands.  Presently,
   *		the driver supports the "get statistics", "set multicast list", and
   *		"set mac address" functions defined by Linux.  A list of possible
   *		enhancements include:
   *
   *				- Custom ioctl interface for executing port interface commands
   *				- Custom ioctl interface for adding unicast addresses to
   *				  adapter CAM (to support bridge functions).
   *				- Custom ioctl interface for supporting firmware upgrades.
   *
   *   Hardware (port interface) Support Routines -
   *		The driver function names that start with "dfx_hw_" represent
   *		low-level port interface routines that are called frequently.  They
   *		include issuing a DMA or port control command to the adapter,
   *		resetting the adapter, or reading the adapter state.  Since the
   *		driver initialization and run-time code must make calls into the
   *		port interface, these routines were written to be as generic and
   *		usable as possible.
   *
   *   Receive Path -
   *		The adapter DMA engine supports a 256 entry receive descriptor block
   *		of which up to 255 entries can be used at any given time.  The
   *		architecture is a standard producer, consumer, completion model in
   *		which the driver "produces" receive buffers to the adapter, the
   *		adapter "consumes" the receive buffers by DMAing incoming packet data,
   *		and the driver "completes" the receive buffers by servicing the
   *		incoming packet, then "produces" a new buffer and starts the cycle
   *		again.  Receive buffers can be fragmented in up to 16 fragments
   *		(descriptor	entries).  For simplicity, this driver posts
   *		single-fragment receive buffers of 4608 bytes, then allocates a
   *		sk_buff, copies the data, then reposts the buffer.  To reduce CPU
   *		utilization, a better approach would be to pass up the receive
   *		buffer (no extra copy) then allocate and post a replacement buffer.
   *		This is a performance enhancement that should be looked into at
   *		some point.
   *
   *   Transmit Path -
   *		Like the receive path, the adapter DMA engine supports a 256 entry
   *		transmit descriptor block of which up to 255 entries can be used at
   *		any	given time.  Transmit buffers can be fragmented	in up to 255
   *		fragments (descriptor entries).  This driver always posts one
   *		fragment per transmit packet request.
   *
   *		The fragment contains the entire packet from FC to end of data.
   *		Before posting the buffer to the adapter, the driver sets a three-byte
   *		packet request header (PRH) which is required by the Motorola MAC chip
   *		used on the adapters.  The PRH tells the MAC the type of token to
   *		receive/send, whether or not to generate and append the CRC, whether
   *		synchronous or asynchronous framing is used, etc.  Since the PRH
   *		definition is not necessarily consistent across all FDDI chipsets,
   *		the driver, rather than the common FDDI packet handler routines,
   *		sets these bytes.
   *
   *		To reduce the amount of descriptor fetches needed per transmit request,
   *		the driver takes advantage of the fact that there are at least three
   *		bytes available before the skb->data field on the outgoing transmit
   *		request.  This is guaranteed by having fddi_setup() in net_init.c set
   *		dev->hard_header_len to 24 bytes.  21 bytes accounts for the largest
   *		header in an 802.2 SNAP frame.  The other 3 bytes are the extra "pad"
   *		bytes which we'll use to store the PRH.
   *
   *		There's a subtle advantage to adding these pad bytes to the
   *		hard_header_len, it ensures that the data portion of the packet for
   *		an 802.2 SNAP frame is longword aligned.  Other FDDI driver
   *		implementations may not need the extra padding and can start copying
   *		or DMAing directly from the FC byte which starts at skb->data.  Should
   *		another driver implementation need ADDITIONAL padding, the net_init.c
   *		module should be updated and dev->hard_header_len should be increased.
   *		NOTE: To maintain the alignment on the data portion of the packet,
   *		dev->hard_header_len should always be evenly divisible by 4 and at
   *		least 24 bytes in size.
   *
   * Modification History:
   *		Date		Name	Description
   *		16-Aug-96	LVS		Created.
   *		20-Aug-96	LVS		Updated dfx_probe so that version information
   *							string is only displayed if 1 or more cards are
   *							found.  Changed dfx_rcv_queue_process to copy
   *							3 NULL bytes before FC to ensure that data is
   *							longword aligned in receive buffer.
   *		09-Sep-96	LVS		Updated dfx_ctl_set_multicast_list to enable
   *							LLC group promiscuous mode if multicast list
   *							is too large.  LLC individual/group promiscuous
   *							mode is now disabled if IFF_PROMISC flag not set.
   *							dfx_xmt_queue_pkt no longer checks for NULL skb
   *							on Alan Cox recommendation.  Added node address
   *							override support.
   *		12-Sep-96	LVS		Reset current address to factory address during
   *							device open.  Updated transmit path to post a
   *							single fragment which includes PRH->end of data.
   *		Mar 2000	AC		Did various cleanups for 2.3.x
   *		Jun 2000	jgarzik		PCI and resource alloc cleanups
   *		Jul 2000	tjeerd		Much cleanup and some bug fixes
   *		Sep 2000	tjeerd		Fix leak on unload, cosmetic code cleanup
   *		Feb 2001			Skb allocation fixes
   *		Feb 2001	davej		PCI enable cleanups.
   *		04 Aug 2003	macro		Converted to the DMA API.
   *		14 Aug 2004	macro		Fix device names reported.
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
196
   *		14 Jun 2005	macro		Use irqreturn_t.
b2e68aa33   Maciej W. Rozycki   [PATCH] defxx: Bi...
197
   *		23 Oct 2006	macro		Big-endian host support.
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
198
   *		14 Dec 2006	macro		TURBOchannel support.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
201
   */
  
  /* Include files */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
202
  #include <linux/bitops.h>
fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
203
  #include <linux/compiler.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
  #include <linux/delay.h>
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
205
206
207
208
  #include <linux/dma-mapping.h>
  #include <linux/eisa.h>
  #include <linux/errno.h>
  #include <linux/fddidevice.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
  #include <linux/init.h>
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
210
211
212
213
  #include <linux/interrupt.h>
  #include <linux/ioport.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
  #include <linux/netdevice.h>
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
215
  #include <linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216
  #include <linux/skbuff.h>
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
217
218
219
  #include <linux/slab.h>
  #include <linux/string.h>
  #include <linux/tc.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
220
221
222
223
224
225
226
227
  
  #include <asm/byteorder.h>
  #include <asm/io.h>
  
  #include "defxx.h"
  
  /* Version information string should be updated prior to each new release!  */
  #define DRV_NAME "defxx"
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
228
229
  #define DRV_VERSION "v1.10"
  #define DRV_RELDATE "2006/12/14"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
232
233
234
235
236
237
238
239
240
241
242
243
  
  static char version[] __devinitdata =
  	DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
  	"  Lawrence V. Stefani and others
  ";
  
  #define DYNAMIC_BUFFERS 1
  
  #define SKBUFF_RX_COPYBREAK 200
  /*
   * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
   * alignment for compatibility with old EISA boards.
   */
  #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  #ifdef CONFIG_PCI
  #define DFX_BUS_PCI(dev) (dev->bus == &pci_bus_type)
  #else
  #define DFX_BUS_PCI(dev) 0
  #endif
  
  #ifdef CONFIG_EISA
  #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
  #else
  #define DFX_BUS_EISA(dev) 0
  #endif
  
  #ifdef CONFIG_TC
  #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
  #else
  #define DFX_BUS_TC(dev) 0
  #endif
  
  #ifdef CONFIG_DEFXX_MMIO
  #define DFX_MMIO 1
  #else
  #define DFX_MMIO 0
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
268
269
  /* Define module-wide (static) routines */
  
  static void		dfx_bus_init(struct net_device *dev);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
270
  static void		dfx_bus_uninit(struct net_device *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
  static void		dfx_bus_config_check(DFX_board_t *bp);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
272
273
274
  static int		dfx_driver_init(struct net_device *dev,
  					const char *print_name,
  					resource_size_t bar_start);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
275
276
277
278
279
280
281
282
  static int		dfx_adap_init(DFX_board_t *bp, int get_buffers);
  
  static int		dfx_open(struct net_device *dev);
  static int		dfx_close(struct net_device *dev);
  
  static void		dfx_int_pr_halt_id(DFX_board_t *bp);
  static void		dfx_int_type_0_process(DFX_board_t *bp);
  static void		dfx_int_common(struct net_device *dev);
7d12e780e   David Howells   IRQ: Maintain reg...
283
  static irqreturn_t	dfx_interrupt(int irq, void *dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  
  static struct		net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
  static void		dfx_ctl_set_multicast_list(struct net_device *dev);
  static int		dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
  static int		dfx_ctl_update_cam(DFX_board_t *bp);
  static int		dfx_ctl_update_filters(DFX_board_t *bp);
  
  static int		dfx_hw_dma_cmd_req(DFX_board_t *bp);
  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);
  static void		dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
  static int		dfx_hw_adap_state_rd(DFX_board_t *bp);
  static int		dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
  
  static int		dfx_rcv_init(DFX_board_t *bp, int get_buffers);
  static void		dfx_rcv_queue_process(DFX_board_t *bp);
  static void		dfx_rcv_flush(DFX_board_t *bp);
61357325f   Stephen Hemminger   netdev: convert b...
300
301
  static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
  				     struct net_device *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
303
304
305
  static int		dfx_xmt_done(DFX_board_t *bp);
  static void		dfx_xmt_flush(DFX_board_t *bp);
  
  /* Define module-wide (static) variables */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
306
307
308
  static struct pci_driver dfx_pci_driver;
  static struct eisa_driver dfx_eisa_driver;
  static struct tc_driver dfx_tc_driver;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
309

6aa20a223   Jeff Garzik   drivers/net: Trim...
310

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
312
  /*
   * =======================
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
314
315
   * = dfx_port_write_long =
   * = dfx_port_read_long  =
   * =======================
6aa20a223   Jeff Garzik   drivers/net: Trim...
316
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
   * Overview:
   *   Routines for reading and writing values from/to adapter
6aa20a223   Jeff Garzik   drivers/net: Trim...
319
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320
321
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
322
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
323
   * Arguments:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
324
325
326
327
328
   *   bp		- pointer to board information
   *   offset	- register offset from base I/O address
   *   data	- for dfx_port_write_long, this is a value to write;
   *		  for dfx_port_read_long, this is a pointer to store
   *		  the read value
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
330
331
332
   *
   * Functional Description:
   *   These routines perform the correct operation to read or write
   *   the adapter register.
6aa20a223   Jeff Garzik   drivers/net: Trim...
333
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
334
335
336
337
338
339
340
341
   *   EISA port block base addresses are based on the slot number in which the
   *   controller is installed.  For example, if the EISA controller is installed
   *   in slot 4, the port block base address is 0x4000.  If the controller is
   *   installed in slot 2, the port block base address is 0x2000, and so on.
   *   This port block can be used to access PDQ, ESIC, and DEFEA on-board
   *   registers using the register offsets defined in DEFXX.H.
   *
   *   PCI port block base addresses are assigned by the PCI BIOS or system
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
342
   *   firmware.  There is one 128 byte port block which can be accessed.  It
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
345
346
347
348
349
   *   allows for I/O mapping of both PDQ and PFI registers using the register
   *   offsets defined in DEFXX.H.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
350
   *   bp->base is a valid base I/O address for this adapter.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351
352
353
354
355
356
357
358
359
   *   offset is a valid register offset for this adapter.
   *
   * Side Effects:
   *   Rather than produce macros for these functions, these routines
   *   are defined using "inline" to ensure that the compiler will
   *   generate inline code and not waste a procedure call and return.
   *   This provides all the benefits of macros, but with the
   *   advantage of strict data type checking.
   */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
360
361
362
363
364
  static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
  {
  	writel(data, bp->base.mem + offset);
  	mb();
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
365

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
366
367
368
369
  static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
  {
  	outl(data, bp->base.port + offset);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
371
372
  static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
  {
fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
373
  	struct device __maybe_unused *bdev = bp->bus_dev;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
374
375
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
377
378
379
380
381
  	if (dfx_use_mmio)
  		dfx_writel(bp, offset, data);
  	else
  		dfx_outl(bp, offset, data);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
382

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
384
385
386
387
388
  static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
  {
  	mb();
  	*data = readl(bp->base.mem + offset);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
390
391
392
393
  static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
  {
  	*data = inl(bp->base.port + offset);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
395
396
  static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
  {
fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
397
  	struct device __maybe_unused *bdev = bp->bus_dev;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
398
399
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
401
402
403
404
405
  	if (dfx_use_mmio)
  		dfx_readl(bp, offset, data);
  	else
  		dfx_inl(bp, offset, data);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
406

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
  /*
   * ================
   * = dfx_get_bars =
   * ================
   *
   * Overview:
   *   Retrieves the address range used to access control and status
   *   registers.
   *
   * Returns:
   *   None
   *
   * Arguments:
   *   bdev	- pointer to device information
   *   bar_start	- pointer to store the start address
   *   bar_len	- pointer to store the length of the area
   *
   * Assumptions:
   *   I am sure there are some.
   *
   * Side Effects:
   *   None
   */
  static void dfx_get_bars(struct device *bdev,
  			 resource_size_t *bar_start, resource_size_t *bar_len)
  {
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
438

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
439
440
  	if (dfx_bus_pci) {
  		int num = dfx_use_mmio ? 0 : 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
  		*bar_start = pci_resource_start(to_pci_dev(bdev), num);
  		*bar_len = pci_resource_len(to_pci_dev(bdev), num);
  	}
  	if (dfx_bus_eisa) {
  		unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  		resource_size_t bar;
  
  		if (dfx_use_mmio) {
  			bar = inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_2);
  			bar <<= 8;
  			bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_1);
  			bar <<= 8;
  			bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_0);
  			bar <<= 16;
  			*bar_start = bar;
  			bar = inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_2);
  			bar <<= 8;
  			bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_1);
  			bar <<= 8;
  			bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_0);
  			bar <<= 16;
  			*bar_len = (bar | PI_MEM_ADD_MASK_M) + 1;
  		} else {
  			*bar_start = base_addr;
  			*bar_len = PI_ESIC_K_CSR_IO_LEN;
  		}
  	}
  	if (dfx_bus_tc) {
  		*bar_start = to_tc_dev(bdev)->resource.start +
  			     PI_TC_K_CSR_OFFSET;
  		*bar_len = PI_TC_K_CSR_LEN;
  	}
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
475

fd8f4997e   Stephen Hemminger   defxx: convert dr...
476
477
478
479
480
481
482
483
  static const struct net_device_ops dfx_netdev_ops = {
  	.ndo_open		= dfx_open,
  	.ndo_stop		= dfx_close,
  	.ndo_start_xmit		= dfx_xmt_queue_pkt,
  	.ndo_get_stats		= dfx_ctl_get_stats,
  	.ndo_set_multicast_list	= dfx_ctl_set_multicast_list,
  	.ndo_set_mac_address	= dfx_ctl_set_mac_address,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
484
  /*
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
485
486
487
   * ================
   * = dfx_register =
   * ================
6aa20a223   Jeff Garzik   drivers/net: Trim...
488
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
489
   * Overview:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
490
   *   Initializes a supported FDDI controller
6aa20a223   Jeff Garzik   drivers/net: Trim...
491
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
492
493
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
494
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
495
   * Arguments:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
496
   *   bdev - pointer to device information
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
   *
   * Functional Description:
   *
   * Return Codes:
   *   0		 - This device (fddi0, fddi1, etc) configured successfully
   *   -EBUSY      - Failed to get resources, or dfx_driver_init failed.
   *
   * Assumptions:
   *   It compiles so it should work :-( (PCI cards do :-)
   *
   * Side Effects:
   *   Device structures for FDDI adapters (fddi0, fddi1, etc) are
   *   initialized and the board resources are read and stored in
   *   the device structure.
   */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
512
  static int __devinit dfx_register(struct device *bdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
513
514
  {
  	static int version_disp;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
515
516
517
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
fb28ad359   Kay Sievers   net: struct devic...
518
  	const char *print_name = dev_name(bdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519
520
  	struct net_device *dev;
  	DFX_board_t	  *bp;			/* board pointer */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
521
522
  	resource_size_t bar_start = 0;		/* pointer to port */
  	resource_size_t bar_len = 0;		/* resource length */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523
  	int alloc_size;				/* total buffer size used */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
524
525
  	struct resource *region;
  	int err = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526
527
528
529
530
  
  	if (!version_disp) {	/* display version info if adapter is found */
  		version_disp = 1;	/* set display flag to TRUE so that */
  		printk(version);	/* we only display this string ONCE */
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531
532
  	dev = alloc_fddidev(sizeof(*bp));
  	if (!dev) {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
533
534
  		printk(KERN_ERR "%s: Unable to allocate fddidev, aborting
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
536
537
538
539
  		       print_name);
  		return -ENOMEM;
  	}
  
  	/* Enable PCI device. */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
540
541
542
543
544
  	if (dfx_bus_pci && pci_enable_device(to_pci_dev(bdev))) {
  		printk(KERN_ERR "%s: Cannot enable PCI device, aborting
  ",
  		       print_name);
  		goto err_out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
  	}
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
546
547
548
549
550
  	SET_NETDEV_DEV(dev, bdev);
  
  	bp = netdev_priv(dev);
  	bp->bus_dev = bdev;
  	dev_set_drvdata(bdev, dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
552
  	dfx_get_bars(bdev, &bar_start, &bar_len);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
554
555
556
557
558
  	if (dfx_use_mmio)
  		region = request_mem_region(bar_start, bar_len, print_name);
  	else
  		region = request_region(bar_start, bar_len, print_name);
  	if (!region) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
559
  		printk(KERN_ERR "%s: Cannot reserve I/O resource "
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
560
561
562
  		       "0x%lx @ 0x%lx, aborting
  ",
  		       print_name, (long)bar_len, (long)bar_start);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
  		err = -EBUSY;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
564
  		goto err_out_disable;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
565
  	}
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
566
567
568
569
570
571
  	/* Set up I/O base address. */
  	if (dfx_use_mmio) {
  		bp->base.mem = ioremap_nocache(bar_start, bar_len);
  		if (!bp->base.mem) {
  			printk(KERN_ERR "%s: Cannot map MMIO
  ", print_name);
8a3235266   Maciej W. Rozycki   defxx: Fix the ha...
572
  			err = -ENOMEM;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
573
574
575
576
577
578
  			goto err_out_region;
  		}
  	} else {
  		bp->base.port = bar_start;
  		dev->base_addr = bar_start;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
580
  	/* Initialize new device structure */
fd8f4997e   Stephen Hemminger   defxx: convert dr...
581
  	dev->netdev_ops			= &dfx_netdev_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
583
584
  	if (dfx_bus_pci)
  		pci_set_master(to_pci_dev(bdev));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
585

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
586
  	if (dfx_driver_init(dev, print_name, bar_start) != DFX_K_SUCCESS) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
587
  		err = -ENODEV;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
588
  		goto err_out_unmap;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
  	}
  
  	err = register_netdev(dev);
  	if (err)
  		goto err_out_kfree;
  
  	printk("%s: registered as %s
  ", print_name, dev->name);
  	return 0;
  
  err_out_kfree:
  	alloc_size = sizeof(PI_DESCR_BLOCK) +
  		     PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  #ifndef DYNAMIC_BUFFERS
  		     (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  #endif
  		     sizeof(PI_CONSUMER_BLOCK) +
  		     (PI_ALIGN_K_DESC_BLK - 1);
  	if (bp->kmalloced)
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
608
609
610
611
612
613
  		dma_free_coherent(bdev, alloc_size,
  				  bp->kmalloced, bp->kmalloced_dma);
  
  err_out_unmap:
  	if (dfx_use_mmio)
  		iounmap(bp->base.mem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614
  err_out_region:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
615
616
617
618
619
620
621
622
  	if (dfx_use_mmio)
  		release_mem_region(bar_start, bar_len);
  	else
  		release_region(bar_start, bar_len);
  
  err_out_disable:
  	if (dfx_bus_pci)
  		pci_disable_device(to_pci_dev(bdev));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
623
624
625
626
  err_out:
  	free_netdev(dev);
  	return err;
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
627

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
629
630
631
  /*
   * ================
   * = dfx_bus_init =
   * ================
6aa20a223   Jeff Garzik   drivers/net: Trim...
632
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
633
   * Overview:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
634
   *   Initializes the bus-specific controller logic.
6aa20a223   Jeff Garzik   drivers/net: Trim...
635
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
636
637
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
638
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
639
640
641
642
643
644
645
646
647
648
649
   * Arguments:
   *   dev - pointer to device information
   *
   * Functional Description:
   *   Determine and save adapter IRQ in device table,
   *   then perform bus-specific logic initialization.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
650
   *   bp->base has already been set with the proper
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
651
652
653
654
655
656
657
658
659
660
   *	 base I/O address for this device.
   *
   * Side Effects:
   *   Interrupts are enabled at the adapter bus-specific logic.
   *   Note:  Interrupts at the DMA engine (PDQ chip) are not
   *   enabled yet.
   */
  
  static void __devinit dfx_bus_init(struct net_device *dev)
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
661
662
663
664
665
666
667
  	DFX_board_t *bp = netdev_priv(dev);
  	struct device *bdev = bp->bus_dev;
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  	u8 val;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
668
669
670
  
  	DBG_printk("In dfx_bus_init...
  ");
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
671
  	/* Initialize a pointer back to the net_device struct */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
673
674
  	bp->dev = dev;
  
  	/* Initialize adapter based on bus type */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
675
676
677
678
  	if (dfx_bus_tc)
  		dev->irq = to_tc_dev(bdev)->interrupt;
  	if (dfx_bus_eisa) {
  		unsigned long base_addr = to_eisa_device(bdev)->base_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
679

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
680
681
682
683
  		/* Get the interrupt level from the ESIC chip.  */
  		val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  		val &= PI_CONFIG_STAT_0_M_IRQ;
  		val >>= PI_CONFIG_STAT_0_V_IRQ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
684

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
685
686
687
688
  		switch (val) {
  		case PI_CONFIG_STAT_0_IRQ_K_9:
  			dev->irq = 9;
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
689

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
690
691
692
  		case PI_CONFIG_STAT_0_IRQ_K_10:
  			dev->irq = 10;
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
693

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
694
695
696
  		case PI_CONFIG_STAT_0_IRQ_K_11:
  			dev->irq = 11;
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
697

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
698
699
700
701
  		case PI_CONFIG_STAT_0_IRQ_K_15:
  			dev->irq = 15;
  			break;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
702

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
703
704
705
706
707
708
709
710
711
712
  		/*
  		 * Enable memory decoding (MEMCS0) and/or port decoding
  		 * (IOCS1/IOCS0) as appropriate in Function Control
  		 * Register.  One of the port chip selects seems to be
  		 * used for the Burst Holdoff register, but this bit of
  		 * documentation is missing and as yet it has not been
  		 * determined which of the two.  This is also the reason
  		 * the size of the decoded port range is twice as large
  		 * as one required by the PDQ.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
713

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
  		/* Set the decode range of the board.  */
  		val = ((bp->base.port >> 12) << PI_IO_CMP_V_SLOT);
  		outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_1, val);
  		outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_0, 0);
  		outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_1, val);
  		outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_0, 0);
  		val = PI_ESIC_K_CSR_IO_LEN - 1;
  		outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_1, (val >> 8) & 0xff);
  		outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_0, val & 0xff);
  		outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_1, (val >> 8) & 0xff);
  		outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_0, val & 0xff);
  
  		/* Enable the decoders.  */
  		val = PI_FUNCTION_CNTRL_M_IOCS1 | PI_FUNCTION_CNTRL_M_IOCS0;
  		if (dfx_use_mmio)
  			val |= PI_FUNCTION_CNTRL_M_MEMCS0;
  		outb(base_addr + PI_ESIC_K_FUNCTION_CNTRL, val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
731
732
  
  		/*
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
733
734
  		 * Enable access to the rest of the module
  		 * (including PDQ and packet memory).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
735
  		 */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
736
737
  		val = PI_SLOT_CNTRL_M_ENB;
  		outb(base_addr + PI_ESIC_K_SLOT_CNTRL, val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
738

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
739
740
741
742
743
744
745
746
747
748
  		/*
  		 * Map PDQ registers into memory or port space.  This is
  		 * done with a bit in the Burst Holdoff register.
  		 */
  		val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  		if (dfx_use_mmio)
  			val |= PI_BURST_HOLDOFF_V_MEM_MAP;
  		else
  			val &= ~PI_BURST_HOLDOFF_V_MEM_MAP;
  		outb(base_addr + PI_DEFEA_K_BURST_HOLDOFF, val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
749
750
  
  		/* Enable interrupts at EISA bus interface chip (ESIC) */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
751
752
753
754
755
756
  		val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  		val |= PI_CONFIG_STAT_0_M_INT_ENB;
  		outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
  	}
  	if (dfx_bus_pci) {
  		struct pci_dev *pdev = to_pci_dev(bdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
757
758
759
760
761
762
763
764
  
  		/* Get the interrupt level from the PCI Configuration Table */
  
  		dev->irq = pdev->irq;
  
  		/* Check Latency Timer and set if less than minimal */
  
  		pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
765
  		if (val < PFI_K_LAT_TIMER_MIN) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
766
767
  			val = PFI_K_LAT_TIMER_DEF;
  			pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
768
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
769
770
  
  		/* Enable interrupts at PCI bus interface chip (PFI) */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
771
772
773
774
  		val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
  		dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
775

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
  /*
   * ==================
   * = dfx_bus_uninit =
   * ==================
   *
   * Overview:
   *   Uninitializes the bus-specific controller logic.
   *
   * Returns:
   *   None
   *
   * Arguments:
   *   dev - pointer to device information
   *
   * Functional Description:
   *   Perform bus-specific logic uninitialization.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   bp->base has already been set with the proper
   *	 base I/O address for this device.
   *
   * Side Effects:
   *   Interrupts are disabled at the adapter bus-specific logic.
   */
79d105081   Maciej W. Rozycki   defxx.c: dfx_bus_...
803
  static void __devexit dfx_bus_uninit(struct net_device *dev)
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
  {
  	DFX_board_t *bp = netdev_priv(dev);
  	struct device *bdev = bp->bus_dev;
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  	u8 val;
  
  	DBG_printk("In dfx_bus_uninit...
  ");
  
  	/* Uninitialize adapter based on bus type */
  
  	if (dfx_bus_eisa) {
  		unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  
  		/* Disable interrupts at EISA bus interface chip (ESIC) */
  		val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  		val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  		outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
  	}
  	if (dfx_bus_pci) {
  		/* Disable interrupts at PCI bus interface chip (PFI) */
  		dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
827
  	}
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
828
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
829

6aa20a223   Jeff Garzik   drivers/net: Trim...
830

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
831
832
833
834
  /*
   * ========================
   * = dfx_bus_config_check =
   * ========================
6aa20a223   Jeff Garzik   drivers/net: Trim...
835
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
836
837
838
   * Overview:
   *   Checks the configuration (burst size, full-duplex, etc.)  If any parameters
   *   are illegal, then this routine will set new defaults.
6aa20a223   Jeff Garzik   drivers/net: Trim...
839
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
840
841
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
842
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
   *   PDQ, and all FDDI PCI controllers, all values are legal.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   dfx_adap_init has NOT been called yet so burst size and other items have
   *   not been set.
   *
   * Side Effects:
   *   None
   */
  
  static void __devinit dfx_bus_config_check(DFX_board_t *bp)
  {
fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
863
  	struct device __maybe_unused *bdev = bp->bus_dev;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
864
  	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
865
  	int	status;				/* return code from adapter port control call */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
866
867
868
869
870
871
  	u32	host_data;			/* LW data returned from port control call */
  
  	DBG_printk("In dfx_bus_config_check...
  ");
  
  	/* Configuration check only valid for EISA adapter */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
872
  	if (dfx_bus_eisa) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
873
874
875
876
877
878
879
  		/*
  		 * First check if revision 2 EISA controller.  Rev. 1 cards used
  		 * PDQ revision B, so no workaround needed in this case.  Rev. 3
  		 * cards used PDQ revision E, so no workaround needed in this
  		 * case, either.  Only Rev. 2 cards used either Rev. D or E
  		 * chips, so we must verify the chip revision on Rev. 2 cards.
  		 */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
880
  		if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
881
  			/*
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
882
883
  			 * Revision 2 FDDI EISA controller found,
  			 * so let's check PDQ revision of adapter.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
884
  			 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
  			status = dfx_hw_port_ctrl_req(bp,
  											PI_PCTRL_M_SUB_CMD,
  											PI_SUB_CMD_K_PDQ_REV_GET,
  											0,
  											&host_data);
  			if ((status != DFX_K_SUCCESS) || (host_data == 2))
  				{
  				/*
  				 * Either we couldn't determine the PDQ revision, or
  				 * we determined that it is at revision D.  In either case,
  				 * we need to implement the workaround.
  				 */
  
  				/* Ensure that the burst size is set to 8 longwords or less */
  
  				switch (bp->burst_size)
  					{
  					case PI_PDATA_B_DMA_BURST_SIZE_32:
  					case PI_PDATA_B_DMA_BURST_SIZE_16:
  						bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
  						break;
  
  					default:
  						break;
  					}
  
  				/* Ensure that full-duplex mode is not enabled */
  
  				bp->full_duplex_enb = PI_SNMP_K_FALSE;
  				}
  			}
  		}
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
918

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
919
920
921
922
  /*
   * ===================
   * = dfx_driver_init =
   * ===================
6aa20a223   Jeff Garzik   drivers/net: Trim...
923
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
924
925
926
   * Overview:
   *   Initializes remaining adapter board structure information
   *   and makes sure adapter is in a safe state prior to dfx_open().
6aa20a223   Jeff Garzik   drivers/net: Trim...
927
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
928
929
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
930
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
   * Arguments:
   *   dev - pointer to device information
   *   print_name - printable device name
   *
   * Functional Description:
   *   This function allocates additional resources such as the host memory
   *   blocks needed by the adapter (eg. descriptor and consumer blocks).
   *	 Remaining bus initialization steps are also completed.  The adapter
   *   is also reset so that it is in the DMA_UNAVAILABLE state.  The OS
   *   must call dfx_open() to open the adapter and bring it on-line.
   *
   * Return Codes:
   *   DFX_K_SUCCESS	- initialization succeeded
   *   DFX_K_FAILURE	- initialization failed - could not allocate memory
   *						or read adapter MAC address
   *
   * Assumptions:
   *   Memory allocated from pci_alloc_consistent() call is physically
   *   contiguous, locked memory.
   *
   * Side Effects:
   *   Adapter is reset and should be in DMA_UNAVAILABLE state before
   *   returning from this routine.
   */
  
  static int __devinit dfx_driver_init(struct net_device *dev,
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
957
958
  				     const char *print_name,
  				     resource_size_t bar_start)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
959
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
960
961
962
963
964
965
966
967
968
  	DFX_board_t *bp = netdev_priv(dev);
  	struct device *bdev = bp->bus_dev;
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  	int alloc_size;			/* total buffer size needed */
  	char *top_v, *curr_v;		/* virtual addrs into memory block */
  	dma_addr_t top_p, curr_p;	/* physical addrs into memory block */
eca1ad82b   Al Viro   misc drivers/net ...
969
970
  	u32 data;			/* host data register value */
  	__le32 le32;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
971
  	char *board_name = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
  
  	DBG_printk("In dfx_driver_init...
  ");
  
  	/* Initialize bus-specific hardware registers */
  
  	dfx_bus_init(dev);
  
  	/*
  	 * Initialize default values for configurable parameters
  	 *
  	 * Note: All of these parameters are ones that a user may
  	 *       want to customize.  It'd be nice to break these
  	 *		 out into Space.c or someplace else that's more
  	 *		 accessible/understandable than this file.
  	 */
  
  	bp->full_duplex_enb		= PI_SNMP_K_FALSE;
  	bp->req_ttrt			= 8 * 12500;		/* 8ms in 80 nanosec units */
  	bp->burst_size			= PI_PDATA_B_DMA_BURST_SIZE_DEF;
  	bp->rcv_bufs_to_post	= RCV_BUFS_DEF;
  
  	/*
  	 * Ensure that HW configuration is OK
  	 *
  	 * Note: Depending on the hardware revision, we may need to modify
  	 *       some of the configurable parameters to workaround hardware
  	 *       limitations.  We'll perform this configuration check AFTER
  	 *       setting the parameters to their default values.
  	 */
  
  	dfx_bus_config_check(bp);
  
  	/* Disable PDQ interrupts first */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  
  	/* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  
  	(void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  
  	/*  Read the factory MAC address from the adapter then save it */
  
  	if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
  				 &data) != DFX_K_SUCCESS) {
  		printk("%s: Could not read adapter factory MAC address!
  ",
  		       print_name);
807540baa   Eric Dumazet   drivers/net: retu...
1020
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1021
  	}
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1022
1023
  	le32 = cpu_to_le32(data);
  	memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1024
1025
1026
1027
1028
1029
  
  	if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
  				 &data) != DFX_K_SUCCESS) {
  		printk("%s: Could not read adapter factory MAC address!
  ",
  		       print_name);
807540baa   Eric Dumazet   drivers/net: retu...
1030
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1031
  	}
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1032
1033
  	le32 = cpu_to_le32(data);
  	memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1034
1035
1036
1037
1038
1039
1040
1041
1042
  
  	/*
  	 * Set current address to factory address
  	 *
  	 * Note: Node address override support is handled through
  	 *       dfx_ctl_set_mac_address.
  	 */
  
  	memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1043
1044
1045
1046
1047
1048
  	if (dfx_bus_tc)
  		board_name = "DEFTA";
  	if (dfx_bus_eisa)
  		board_name = "DEFEA";
  	if (dfx_bus_pci)
  		board_name = "DEFPA";
69d279eaf   hartleys   drivers/net/defxx...
1049
1050
  	pr_info("%s: %s at %saddr = 0x%llx, IRQ = %d, Hardware addr = %pMF
  ",
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1051
  		print_name, board_name, dfx_use_mmio ? "" : "I/O ",
69d279eaf   hartleys   drivers/net/defxx...
1052
  		(long long)bar_start, dev->irq, dev->dev_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
  
  	/*
  	 * Get memory for descriptor block, consumer block, and other buffers
  	 * that need to be DMA read or written to by the adapter.
  	 */
  
  	alloc_size = sizeof(PI_DESCR_BLOCK) +
  					PI_CMD_REQ_K_SIZE_MAX +
  					PI_CMD_RSP_K_SIZE_MAX +
  #ifndef DYNAMIC_BUFFERS
  					(bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  #endif
  					sizeof(PI_CONSUMER_BLOCK) +
  					(PI_ALIGN_K_DESC_BLK - 1);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1067
1068
1069
  	bp->kmalloced = top_v = dma_alloc_coherent(bp->bus_dev, alloc_size,
  						   &bp->kmalloced_dma,
  						   GFP_ATOMIC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1070
1071
1072
1073
  	if (top_v == NULL) {
  		printk("%s: Could not allocate memory for host buffers "
  		       "and structures!
  ", print_name);
807540baa   Eric Dumazet   drivers/net: retu...
1074
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
  	}
  	memset(top_v, 0, alloc_size);	/* zero out memory before continuing */
  	top_p = bp->kmalloced_dma;	/* get physical address of buffer */
  
  	/*
  	 *  To guarantee the 8K alignment required for the descriptor block, 8K - 1
  	 *  plus the amount of memory needed was allocated.  The physical address
  	 *	is now 8K aligned.  By carving up the memory in a specific order,
  	 *  we'll guarantee the alignment requirements for all other structures.
  	 *
  	 *  Note: If the assumptions change regarding the non-paged, non-cached,
  	 *		  physically contiguous nature of the memory block or the address
  	 *		  alignments, then we'll need to implement a different algorithm
  	 *		  for allocating the needed memory.
  	 */
  
  	curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
  	curr_v = top_v + (curr_p - top_p);
  
  	/* Reserve space for descriptor block */
  
  	bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
  	bp->descr_block_phys = curr_p;
  	curr_v += sizeof(PI_DESCR_BLOCK);
  	curr_p += sizeof(PI_DESCR_BLOCK);
  
  	/* Reserve space for command request buffer */
  
  	bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
  	bp->cmd_req_phys = curr_p;
  	curr_v += PI_CMD_REQ_K_SIZE_MAX;
  	curr_p += PI_CMD_REQ_K_SIZE_MAX;
  
  	/* Reserve space for command response buffer */
  
  	bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
  	bp->cmd_rsp_phys = curr_p;
  	curr_v += PI_CMD_RSP_K_SIZE_MAX;
  	curr_p += PI_CMD_RSP_K_SIZE_MAX;
  
  	/* Reserve space for the LLC host receive queue buffers */
  
  	bp->rcv_block_virt = curr_v;
  	bp->rcv_block_phys = curr_p;
  
  #ifndef DYNAMIC_BUFFERS
  	curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  	curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  #endif
  
  	/* Reserve space for the consumer block */
  
  	bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
  	bp->cons_block_phys = curr_p;
  
  	/* Display virtual and physical addresses if debug driver */
  
  	DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X
  ",
  		   print_name,
  		   (long)bp->descr_block_virt, bp->descr_block_phys);
  	DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X
  ",
  		   print_name, (long)bp->cmd_req_virt, bp->cmd_req_phys);
  	DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X
  ",
  		   print_name, (long)bp->cmd_rsp_virt, bp->cmd_rsp_phys);
  	DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X
  ",
  		   print_name, (long)bp->rcv_block_virt, bp->rcv_block_phys);
  	DBG_printk("%s: Consumer block virt = %0lX, phys = %0X
  ",
  		   print_name, (long)bp->cons_block_virt, bp->cons_block_phys);
807540baa   Eric Dumazet   drivers/net: retu...
1148
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1149
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
1150

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1151
1152
1153
1154
  /*
   * =================
   * = dfx_adap_init =
   * =================
6aa20a223   Jeff Garzik   drivers/net: Trim...
1155
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1156
1157
   * Overview:
   *   Brings the adapter to the link avail/link unavailable state.
6aa20a223   Jeff Garzik   drivers/net: Trim...
1158
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1159
1160
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
1161
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
   * Arguments:
   *   bp - pointer to board information
   *   get_buffers - non-zero if buffers to be allocated
   *
   * Functional Description:
   *   Issues the low-level firmware/hardware calls necessary to bring
   *   the adapter up, or to properly reset and restore adapter during
   *   run-time.
   *
   * Return Codes:
   *   DFX_K_SUCCESS - Adapter brought up successfully
   *   DFX_K_FAILURE - Adapter initialization failed
   *
   * Assumptions:
   *   bp->reset_type should be set to a valid reset type value before
   *   calling this routine.
   *
   * Side Effects:
   *   Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
   *   upon a successful return of this routine.
   */
  
  static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
  	{
  	DBG_printk("In dfx_adap_init...
  ");
  
  	/* Disable PDQ interrupts first */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  
  	/* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  
  	if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
  		{
  		printk("%s: Could not uninitialize/reset adapter!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1199
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
  		}
  
  	/*
  	 * When the PDQ is reset, some false Type 0 interrupts may be pending,
  	 * so we'll acknowledge all Type 0 interrupts now before continuing.
  	 */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
  
  	/*
  	 * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
  	 *
  	 * Note: We only need to clear host copies of these registers.  The PDQ reset
  	 *       takes care of the on-board register values.
  	 */
  
  	bp->cmd_req_reg.lword	= 0;
  	bp->cmd_rsp_reg.lword	= 0;
  	bp->rcv_xmt_reg.lword	= 0;
  
  	/* Clear consumer block before going to DMA_AVAILABLE state */
  
  	memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  
  	/* Initialize the DMA Burst Size */
  
  	if (dfx_hw_port_ctrl_req(bp,
  							PI_PCTRL_M_SUB_CMD,
  							PI_SUB_CMD_K_BURST_SIZE_SET,
  							bp->burst_size,
  							NULL) != DFX_K_SUCCESS)
  		{
  		printk("%s: Could not set adapter burst size!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1234
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
  		}
  
  	/*
  	 * Set base address of Consumer Block
  	 *
  	 * Assumption: 32-bit physical address of consumer block is 64 byte
  	 *			   aligned.  That is, bits 0-5 of the address must be zero.
  	 */
  
  	if (dfx_hw_port_ctrl_req(bp,
  							PI_PCTRL_M_CONS_BLOCK,
  							bp->cons_block_phys,
  							0,
  							NULL) != DFX_K_SUCCESS)
  		{
  		printk("%s: Could not set consumer block address!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1252
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1253
1254
1255
  		}
  
  	/*
b2e68aa33   Maciej W. Rozycki   [PATCH] defxx: Bi...
1256
1257
  	 * Set the base address of Descriptor Block and bring adapter
  	 * to DMA_AVAILABLE state.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1258
  	 *
b2e68aa33   Maciej W. Rozycki   [PATCH] defxx: Bi...
1259
1260
  	 * Note: We also set the literal and data swapping requirements
  	 *       in this command.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1261
  	 *
b2e68aa33   Maciej W. Rozycki   [PATCH] defxx: Bi...
1262
1263
  	 * Assumption: 32-bit physical address of descriptor block
  	 *       is 8Kbyte aligned.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1264
  	 */
b2e68aa33   Maciej W. Rozycki   [PATCH] defxx: Bi...
1265
1266
1267
1268
1269
1270
1271
1272
1273
  	if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
  				 (u32)(bp->descr_block_phys |
  				       PI_PDATA_A_INIT_M_BSWAP_INIT),
  				 0, NULL) != DFX_K_SUCCESS) {
  		printk("%s: Could not set descriptor block address!
  ",
  		       bp->dev->name);
  		return DFX_K_FAILURE;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
  
  	/* Set transmit flush timeout value */
  
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
  	bp->cmd_req_virt->char_set.item[0].item_code	= PI_ITEM_K_FLUSH_TIME;
  	bp->cmd_req_virt->char_set.item[0].value		= 3;	/* 3 seconds */
  	bp->cmd_req_virt->char_set.item[0].item_index	= 0;
  	bp->cmd_req_virt->char_set.item[1].item_code	= PI_ITEM_K_EOL;
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  		{
  		printk("%s: DMA command request failed!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1286
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
  		}
  
  	/* Set the initial values for eFDXEnable and MACTReq MIB objects */
  
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
  	bp->cmd_req_virt->snmp_set.item[0].item_code	= PI_ITEM_K_FDX_ENB_DIS;
  	bp->cmd_req_virt->snmp_set.item[0].value		= bp->full_duplex_enb;
  	bp->cmd_req_virt->snmp_set.item[0].item_index	= 0;
  	bp->cmd_req_virt->snmp_set.item[1].item_code	= PI_ITEM_K_MAC_T_REQ;
  	bp->cmd_req_virt->snmp_set.item[1].value		= bp->req_ttrt;
  	bp->cmd_req_virt->snmp_set.item[1].item_index	= 0;
  	bp->cmd_req_virt->snmp_set.item[2].item_code	= PI_ITEM_K_EOL;
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  		{
  		printk("%s: DMA command request failed!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1303
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1304
1305
1306
1307
1308
1309
1310
1311
  		}
  
  	/* Initialize adapter CAM */
  
  	if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  		{
  		printk("%s: Adapter CAM update failed!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1312
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1313
1314
1315
1316
1317
1318
1319
1320
  		}
  
  	/* Initialize adapter filters */
  
  	if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  		{
  		printk("%s: Adapter filters update failed!
  ", bp->dev->name);
807540baa   Eric Dumazet   drivers/net: retu...
1321
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
  		}
  
  	/*
  	 * Remove any existing dynamic buffers (i.e. if the adapter is being
  	 * reinitialized)
  	 */
  
  	if (get_buffers)
  		dfx_rcv_flush(bp);
  
  	/* Initialize receive descriptor block and produce buffers */
  
  	if (dfx_rcv_init(bp, get_buffers))
  	        {
  		printk("%s: Receive buffer allocation failed
  ", bp->dev->name);
  		if (get_buffers)
  			dfx_rcv_flush(bp);
807540baa   Eric Dumazet   drivers/net: retu...
1340
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
  		}
  
  	/* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
  
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  		{
  		printk("%s: Start command failed
  ", bp->dev->name);
  		if (get_buffers)
  			dfx_rcv_flush(bp);
807540baa   Eric Dumazet   drivers/net: retu...
1352
  		return DFX_K_FAILURE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1353
1354
1355
1356
1357
  		}
  
  	/* Initialization succeeded, reenable PDQ interrupts */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
807540baa   Eric Dumazet   drivers/net: retu...
1358
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1359
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
1360

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1361
1362
1363
1364
  /*
   * ============
   * = dfx_open =
   * ============
6aa20a223   Jeff Garzik   drivers/net: Trim...
1365
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1366
1367
   * Overview:
   *   Opens the adapter
6aa20a223   Jeff Garzik   drivers/net: Trim...
1368
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1369
1370
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
1371
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
   * Arguments:
   *   dev - pointer to device information
   *
   * Functional Description:
   *   This function brings the adapter to an operational state.
   *
   * Return Codes:
   *   0		 - Adapter was successfully opened
   *   -EAGAIN - Could not register IRQ or adapter initialization failed
   *
   * Assumptions:
   *   This routine should only be called for a device that was
   *   initialized successfully.
   *
   * Side Effects:
   *   Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
   *   if the open is successful.
   */
  
  static int dfx_open(struct net_device *dev)
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1393
  	DFX_board_t *bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1394
  	int ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1395
1396
1397
  
  	DBG_printk("In dfx_open...
  ");
6aa20a223   Jeff Garzik   drivers/net: Trim...
1398

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1399
  	/* Register IRQ - support shared interrupts by passing device ptr */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1400
1401
  	ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
  			  dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
  	if (ret) {
  		printk(KERN_ERR "%s: Requested IRQ %d is busy
  ", dev->name, dev->irq);
  		return ret;
  	}
  
  	/*
  	 * Set current address to factory MAC address
  	 *
  	 * Note: We've already done this step in dfx_driver_init.
  	 *       However, it's possible that a user has set a node
  	 *		 address override, then closed and reopened the
  	 *		 adapter.  Unless we reset the device address field
  	 *		 now, we'll continue to use the existing modified
  	 *		 address.
  	 */
  
  	memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  
  	/* Clear local unicast/multicast address tables and counts */
  
  	memset(bp->uc_table, 0, sizeof(bp->uc_table));
  	memset(bp->mc_table, 0, sizeof(bp->mc_table));
  	bp->uc_count = 0;
  	bp->mc_count = 0;
  
  	/* Disable promiscuous filter settings */
  
  	bp->ind_group_prom	= PI_FSTATE_K_BLOCK;
  	bp->group_prom		= PI_FSTATE_K_BLOCK;
  
  	spin_lock_init(&bp->lock);
  
  	/* Reset and initialize adapter */
  
  	bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST;	/* skip self-test */
  	if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
  	{
  		printk(KERN_ERR "%s: Adapter open failed!
  ", dev->name);
  		free_irq(dev->irq, dev);
  		return -EAGAIN;
  	}
  
  	/* Set device structure info */
  	netif_start_queue(dev);
807540baa   Eric Dumazet   drivers/net: retu...
1448
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1449
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
1450

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1451
1452
1453
1454
  /*
   * =============
   * = dfx_close =
   * =============
6aa20a223   Jeff Garzik   drivers/net: Trim...
1455
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1456
1457
   * Overview:
   *   Closes the device/module.
6aa20a223   Jeff Garzik   drivers/net: Trim...
1458
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1459
1460
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
1461
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
   * Arguments:
   *   dev - pointer to device information
   *
   * Functional Description:
   *   This routine closes the adapter and brings it to a safe state.
   *   The interrupt service routine is deregistered with the OS.
   *   The adapter can be opened again with another call to dfx_open().
   *
   * Return Codes:
   *   Always return 0.
   *
   * Assumptions:
   *   No further requests for this adapter are made after this routine is
   *   called.  dfx_open() can be called to reset and reinitialize the
   *   adapter.
   *
   * Side Effects:
   *   Adapter should be in DMA_UNAVAILABLE state upon completion of this
   *   routine.
   */
  
  static int dfx_close(struct net_device *dev)
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1485
  	DFX_board_t *bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
  
  	DBG_printk("In dfx_close...
  ");
  
  	/* Disable PDQ interrupts first */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  
  	/* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  
  	(void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  
  	/*
  	 * Flush any pending transmit buffers
  	 *
  	 * Note: It's important that we flush the transmit buffers
  	 *		 BEFORE we clear our copy of the Type 2 register.
  	 *		 Otherwise, we'll have no idea how many buffers
  	 *		 we need to free.
  	 */
  
  	dfx_xmt_flush(bp);
  
  	/*
  	 * Clear Type 1 and Type 2 registers after adapter reset
  	 *
  	 * Note: Even though we're closing the adapter, it's
  	 *       possible that an interrupt will occur after
  	 *		 dfx_close is called.  Without some assurance to
  	 *		 the contrary we want to make sure that we don't
  	 *		 process receive and transmit LLC frames and update
  	 *		 the Type 2 register with bad information.
  	 */
  
  	bp->cmd_req_reg.lword	= 0;
  	bp->cmd_rsp_reg.lword	= 0;
  	bp->rcv_xmt_reg.lword	= 0;
  
  	/* Clear consumer block for the same reason given above */
  
  	memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  
  	/* Release all dynamically allocate skb in the receive ring. */
  
  	dfx_rcv_flush(bp);
  
  	/* Clear device structure flags */
  
  	netif_stop_queue(dev);
6aa20a223   Jeff Garzik   drivers/net: Trim...
1535

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1536
1537
1538
  	/* Deregister (free) IRQ */
  
  	free_irq(dev->irq, dev);
6aa20a223   Jeff Garzik   drivers/net: Trim...
1539

807540baa   Eric Dumazet   drivers/net: retu...
1540
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1541
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
1542

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1543
1544
1545
1546
  /*
   * ======================
   * = dfx_int_pr_halt_id =
   * ======================
6aa20a223   Jeff Garzik   drivers/net: Trim...
1547
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1548
1549
   * Overview:
   *   Displays halt id's in string form.
6aa20a223   Jeff Garzik   drivers/net: Trim...
1550
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1551
1552
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
1553
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Determine current halt id and display appropriate string.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   None
   */
  
  static void dfx_int_pr_halt_id(DFX_board_t	*bp)
  	{
  	PI_UINT32	port_status;			/* PDQ port status register value */
  	PI_UINT32	halt_id;				/* PDQ port status halt ID */
  
  	/* Read the latest port status */
  
  	dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  
  	/* Display halt state transition information */
  
  	halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
  	switch (halt_id)
  		{
  		case PI_HALT_ID_K_SELFTEST_TIMEOUT:
  			printk("%s: Halt ID: Selftest Timeout
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_PARITY_ERROR:
  			printk("%s: Halt ID: Host Bus Parity Error
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_HOST_DIR_HALT:
  			printk("%s: Halt ID: Host-Directed Halt
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_SW_FAULT:
  			printk("%s: Halt ID: Adapter Software Fault
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_HW_FAULT:
  			printk("%s: Halt ID: Adapter Hardware Fault
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_PC_TRACE:
  			printk("%s: Halt ID: FDDI Network PC Trace Path Test
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_DMA_ERROR:
  			printk("%s: Halt ID: Adapter DMA Error
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_IMAGE_CRC_ERROR:
  			printk("%s: Halt ID: Firmware Image CRC Error
  ", bp->dev->name);
  			break;
  
  		case PI_HALT_ID_K_BUS_EXCEPTION:
  			printk("%s: Halt ID: 68000 Bus Exception
  ", bp->dev->name);
  			break;
  
  		default:
  			printk("%s: Halt ID: Unknown (code = %X)
  ", bp->dev->name, halt_id);
  			break;
  		}
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
1635

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1636
1637
1638
1639
  /*
   * ==========================
   * = dfx_int_type_0_process =
   * ==========================
6aa20a223   Jeff Garzik   drivers/net: Trim...
1640
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1641
1642
   * Overview:
   *   Processes Type 0 interrupts.
6aa20a223   Jeff Garzik   drivers/net: Trim...
1643
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1644
1645
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
1646
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Processes all enabled Type 0 interrupts.  If the reason for the interrupt
   *   is a serious fault on the adapter, then an error message is displayed
   *   and the adapter is reset.
   *
   *   One tricky potential timing window is the rapid succession of "link avail"
   *   "link unavail" state change interrupts.  The acknowledgement of the Type 0
   *   interrupt must be done before reading the state from the Port Status
   *   register.  This is true because a state change could occur after reading
   *   the data, but before acknowledging the interrupt.  If this state change
   *   does happen, it would be lost because the driver is using the old state,
   *   and it will never know about the new state because it subsequently
   *   acknowledges the state change interrupt.
   *
   *          INCORRECT                                      CORRECT
   *      read type 0 int reasons                   read type 0 int reasons
   *      read adapter state                        ack type 0 interrupts
   *      ack type 0 interrupts                     read adapter state
   *      ... process interrupt ...                 ... process interrupt ...
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   An adapter reset may occur if the adapter has any Type 0 error interrupts
   *   or if the port status indicates that the adapter is halted.  The driver
   *   is responsible for reinitializing the adapter with the current CAM
   *   contents and adapter filter settings.
   */
  
  static void dfx_int_type_0_process(DFX_board_t	*bp)
  
  	{
  	PI_UINT32	type_0_status;		/* Host Interrupt Type 0 register */
  	PI_UINT32	state;				/* current adap state (from port status) */
  
  	/*
  	 * Read host interrupt Type 0 register to determine which Type 0
  	 * interrupts are pending.  Immediately write it back out to clear
  	 * those interrupts.
  	 */
  
  	dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
  	dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
  
  	/* Check for Type 0 error interrupts */
  
  	if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
  							PI_TYPE_0_STAT_M_PM_PAR_ERR |
  							PI_TYPE_0_STAT_M_BUS_PAR_ERR))
  		{
  		/* Check for Non-Existent Memory error */
  
  		if (type_0_status & PI_TYPE_0_STAT_M_NXM)
  			printk("%s: Non-Existent Memory Access Error
  ", bp->dev->name);
  
  		/* Check for Packet Memory Parity error */
  
  		if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
  			printk("%s: Packet Memory Parity Error
  ", bp->dev->name);
  
  		/* Check for Host Bus Parity error */
  
  		if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
  			printk("%s: Host Bus Parity Error
  ", bp->dev->name);
  
  		/* Reset adapter and bring it back on-line */
  
  		bp->link_available = PI_K_FALSE;	/* link is no longer available */
  		bp->reset_type = 0;					/* rerun on-board diagnostics */
  		printk("%s: Resetting adapter...
  ", bp->dev->name);
  		if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
  			{
  			printk("%s: Adapter reset failed!  Disabling adapter interrupts.
  ", bp->dev->name);
  			dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  			return;
  			}
  		printk("%s: Adapter reset successful!
  ", bp->dev->name);
  		return;
  		}
  
  	/* Check for transmit flush interrupt */
  
  	if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
  		{
  		/* Flush any pending xmt's and acknowledge the flush interrupt */
  
  		bp->link_available = PI_K_FALSE;		/* link is no longer available */
  		dfx_xmt_flush(bp);						/* flush any outstanding packets */
  		(void) dfx_hw_port_ctrl_req(bp,
  									PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
  									0,
  									0,
  									NULL);
  		}
  
  	/* Check for adapter state change */
  
  	if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
6aa20a223   Jeff Garzik   drivers/net: Trim...
1758
  		{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
  		/* Get latest adapter state */
  
  		state = dfx_hw_adap_state_rd(bp);	/* get adapter state */
  		if (state == PI_STATE_K_HALTED)
  			{
  			/*
  			 * Adapter has transitioned to HALTED state, try to reset
  			 * adapter to bring it back on-line.  If reset fails,
  			 * leave the adapter in the broken state.
  			 */
  
  			printk("%s: Controller has transitioned to HALTED state!
  ", bp->dev->name);
  			dfx_int_pr_halt_id(bp);			/* display halt id as string */
  
  			/* Reset adapter and bring it back on-line */
  
  			bp->link_available = PI_K_FALSE;	/* link is no longer available */
  			bp->reset_type = 0;					/* rerun on-board diagnostics */
  			printk("%s: Resetting adapter...
  ", bp->dev->name);
  			if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
  				{
  				printk("%s: Adapter reset failed!  Disabling adapter interrupts.
  ", bp->dev->name);
  				dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  				return;
  				}
  			printk("%s: Adapter reset successful!
  ", bp->dev->name);
  			}
  		else if (state == PI_STATE_K_LINK_AVAIL)
  			{
  			bp->link_available = PI_K_TRUE;		/* set link available flag */
  			}
  		}
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
1796

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1797
1798
1799
1800
  /*
   * ==================
   * = dfx_int_common =
   * ==================
6aa20a223   Jeff Garzik   drivers/net: Trim...
1801
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1802
1803
   * Overview:
   *   Interrupt service routine (ISR)
6aa20a223   Jeff Garzik   drivers/net: Trim...
1804
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1805
1806
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
1807
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   This is the ISR which processes incoming adapter interrupts.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   This routine assumes PDQ interrupts have not been disabled.
   *   When interrupts are disabled at the PDQ, the Port Status register
   *   is automatically cleared.  This routine uses the Port Status
   *   register value to determine whether a Type 0 interrupt occurred,
   *   so it's important that adapter interrupts are not normally
   *   enabled/disabled at the PDQ.
   *
   *   It's vital that this routine is NOT reentered for the
   *   same board and that the OS is not in another section of
   *   code (eg. dfx_xmt_queue_pkt) for the same board on a
   *   different thread.
   *
   * Side Effects:
   *   Pending interrupts are serviced.  Depending on the type of
   *   interrupt, acknowledging and clearing the interrupt at the
   *   PDQ involves writing a register to clear the interrupt bit
   *   or updating completion indices.
   */
  
  static void dfx_int_common(struct net_device *dev)
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1839
  	DFX_board_t *bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
  	PI_UINT32	port_status;		/* Port Status register */
  
  	/* Process xmt interrupts - frequent case, so always call this routine */
  
  	if(dfx_xmt_done(bp))				/* free consumed xmt packets */
  		netif_wake_queue(dev);
  
  	/* Process rcv interrupts - frequent case, so always call this routine */
  
  	dfx_rcv_queue_process(bp);		/* service received LLC frames */
  
  	/*
  	 * Transmit and receive producer and completion indices are updated on the
  	 * adapter by writing to the Type 2 Producer register.  Since the frequent
  	 * case is that we'll be processing either LLC transmit or receive buffers,
  	 * we'll optimize I/O writes by doing a single register write here.
  	 */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  
  	/* Read PDQ Port Status register to find out which interrupts need processing */
  
  	dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  
  	/* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
  
  	if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
  		dfx_int_type_0_process(bp);	/* process Type 0 interrupts */
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
1869

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1870
1871
1872
1873
  /*
   * =================
   * = dfx_interrupt =
   * =================
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1874
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1875
1876
   * Overview:
   *   Interrupt processing routine
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1877
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1878
   * Returns:
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1879
1880
   *   Whether a valid interrupt was seen.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1881
1882
1883
   * Arguments:
   *   irq	- interrupt vector
   *   dev_id	- pointer to device information
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1884
1885
1886
1887
1888
1889
1890
1891
   *
   * Functional Description:
   *   This routine calls the interrupt processing routine for this adapter.  It
   *   disables and reenables adapter interrupts, as appropriate.  We can support
   *   shared interrupts since the incoming dev_id pointer provides our device
   *   structure context.
   *
   * Return Codes:
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1892
1893
   *   IRQ_HANDLED - an IRQ was handled.
   *   IRQ_NONE    - no IRQ was handled.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
   *
   * Assumptions:
   *   The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
   *   on Intel-based systems) is done by the operating system outside this
   *   routine.
   *
   *	 System interrupts are enabled through this call.
   *
   * Side Effects:
   *   Interrupts are disabled, then reenabled at the adapter.
   */
7d12e780e   David Howells   IRQ: Maintain reg...
1905
  static irqreturn_t dfx_interrupt(int irq, void *dev_id)
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1906
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1907
1908
1909
1910
1911
1912
  	struct net_device *dev = dev_id;
  	DFX_board_t *bp = netdev_priv(dev);
  	struct device *bdev = bp->bus_dev;
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1913
1914
  
  	/* Service adapter interrupts */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1915
  	if (dfx_bus_pci) {
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1916
  		u32 status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1917

feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1918
1919
1920
  		dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
  		if (!(status & PFI_STATUS_M_PDQ_INT))
  			return IRQ_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1921

feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1922
1923
1924
1925
1926
  		spin_lock(&bp->lock);
  
  		/* Disable PDQ-PFI interrupts at PFI */
  		dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
  				    PFI_MODE_M_DMA_ENB);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1927

feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1928
  		/* Call interrupt service routine for this adapter */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1929
1930
1931
  		dfx_int_common(dev);
  
  		/* Clear PDQ interrupt status bit and reenable interrupts */
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1932
1933
  		dfx_port_write_long(bp, PFI_K_REG_STATUS,
  				    PFI_STATUS_M_PDQ_INT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1934
  		dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1935
1936
  				    (PFI_MODE_M_PDQ_INT_ENB |
  				     PFI_MODE_M_DMA_ENB));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1937

feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1938
  		spin_unlock(&bp->lock);
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1939
1940
1941
  	}
  	if (dfx_bus_eisa) {
  		unsigned long base_addr = to_eisa_device(bdev)->base_addr;
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1942
  		u8 status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1943

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1944
  		status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1945
1946
  		if (!(status & PI_CONFIG_STAT_0_M_PEND))
  			return IRQ_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1947

feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1948
1949
1950
1951
  		spin_lock(&bp->lock);
  
  		/* Disable interrupts at the ESIC */
  		status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1952
  		outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, status);
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1953
1954
  
  		/* Call interrupt service routine for this adapter */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1955
1956
1957
  		dfx_int_common(dev);
  
  		/* Reenable interrupts at the ESIC */
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1958
  		status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1959
  		status |= PI_CONFIG_STAT_0_M_INT_ENB;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
  		outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, status);
  
  		spin_unlock(&bp->lock);
  	}
  	if (dfx_bus_tc) {
  		u32 status;
  
  		dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &status);
  		if (!(status & (PI_PSTATUS_M_RCV_DATA_PENDING |
  				PI_PSTATUS_M_XMT_DATA_PENDING |
  				PI_PSTATUS_M_SMT_HOST_PENDING |
  				PI_PSTATUS_M_UNSOL_PENDING |
  				PI_PSTATUS_M_CMD_RSP_PENDING |
  				PI_PSTATUS_M_CMD_REQ_PENDING |
  				PI_PSTATUS_M_TYPE_0_PENDING)))
  			return IRQ_NONE;
  
  		spin_lock(&bp->lock);
  
  		/* Call interrupt service routine for this adapter */
  		dfx_int_common(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1981

feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1982
  		spin_unlock(&bp->lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1983
  	}
feea1db26   Maciej W. Rozycki   [PATCH] defxx: Us...
1984
1985
  	return IRQ_HANDLED;
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
1986

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1987
1988
1989
1990
  /*
   * =====================
   * = dfx_ctl_get_stats =
   * =====================
6aa20a223   Jeff Garzik   drivers/net: Trim...
1991
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1992
1993
   * Overview:
   *   Get statistics for FDDI adapter
6aa20a223   Jeff Garzik   drivers/net: Trim...
1994
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1995
1996
   * Returns:
   *   Pointer to FDDI statistics structure
6aa20a223   Jeff Garzik   drivers/net: Trim...
1997
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
   * Arguments:
   *   dev - pointer to device information
   *
   * Functional Description:
   *   Gets current MIB objects from adapter, then
   *   returns FDDI statistics structure as defined
   *   in if_fddi.h.
   *
   *   Note: Since the FDDI statistics structure is
   *   still new and the device structure doesn't
   *   have an FDDI-specific get statistics handler,
   *   we'll return the FDDI statistics structure as
   *   a pointer to an Ethernet statistics structure.
   *   That way, at least the first part of the statistics
   *   structure can be decoded properly, and it allows
   *   "smart" applications to perform a second cast to
   *   decode the FDDI-specific statistics.
   *
   *   We'll have to pay attention to this routine as the
   *   device structure becomes more mature and LAN media
   *   independent.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   None
   */
  
  static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
  	{
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
2032
  	DFX_board_t *bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
  
  	/* Fill the bp->stats structure with driver-maintained counters */
  
  	bp->stats.gen.rx_packets = bp->rcv_total_frames;
  	bp->stats.gen.tx_packets = bp->xmt_total_frames;
  	bp->stats.gen.rx_bytes   = bp->rcv_total_bytes;
  	bp->stats.gen.tx_bytes   = bp->xmt_total_bytes;
  	bp->stats.gen.rx_errors  = bp->rcv_crc_errors +
  				   bp->rcv_frame_status_errors +
  				   bp->rcv_length_errors;
  	bp->stats.gen.tx_errors  = bp->xmt_length_errors;
  	bp->stats.gen.rx_dropped = bp->rcv_discards;
  	bp->stats.gen.tx_dropped = bp->xmt_discards;
  	bp->stats.gen.multicast  = bp->rcv_multicast_frames;
  	bp->stats.gen.collisions = 0;		/* always zero (0) for FDDI */
  
  	/* Get FDDI SMT MIB objects */
  
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
807540baa   Eric Dumazet   drivers/net: retu...
2053
  		return (struct net_device_stats *)&bp->stats;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
  
  	/* Fill the bp->stats structure with the SMT MIB object values */
  
  	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));
  	bp->stats.smt_op_version_id					= bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
  	bp->stats.smt_hi_version_id					= bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
  	bp->stats.smt_lo_version_id					= bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
  	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));
  	bp->stats.smt_mib_version_id				= bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
  	bp->stats.smt_mac_cts						= bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
  	bp->stats.smt_non_master_cts				= bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
  	bp->stats.smt_master_cts					= bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
  	bp->stats.smt_available_paths				= bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
  	bp->stats.smt_config_capabilities			= bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
  	bp->stats.smt_config_policy					= bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
  	bp->stats.smt_connection_policy				= bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
  	bp->stats.smt_t_notify						= bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
  	bp->stats.smt_stat_rpt_policy				= bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
  	bp->stats.smt_trace_max_expiration			= bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
  	bp->stats.smt_bypass_present				= bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
  	bp->stats.smt_ecm_state						= bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
  	bp->stats.smt_cf_state						= bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
  	bp->stats.smt_remote_disconnect_flag		= bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
  	bp->stats.smt_station_status				= bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
  	bp->stats.smt_peer_wrap_flag				= bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
  	bp->stats.smt_time_stamp					= bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
  	bp->stats.smt_transition_time_stamp			= bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
  	bp->stats.mac_frame_status_functions		= bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
  	bp->stats.mac_t_max_capability				= bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
  	bp->stats.mac_tvx_capability				= bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
  	bp->stats.mac_available_paths				= bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
  	bp->stats.mac_current_path					= bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
  	memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
  	memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
  	memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
  	memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
  	bp->stats.mac_dup_address_test				= bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
  	bp->stats.mac_requested_paths				= bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
  	bp->stats.mac_downstream_port_type			= bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
  	memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
  	bp->stats.mac_t_req							= bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
  	bp->stats.mac_t_neg							= bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
  	bp->stats.mac_t_max							= bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
  	bp->stats.mac_tvx_value						= bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
  	bp->stats.mac_frame_error_threshold			= bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
  	bp->stats.mac_frame_error_ratio				= bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
  	bp->stats.mac_rmt_state						= bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
  	bp->stats.mac_da_flag						= bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
  	bp->stats.mac_una_da_flag					= bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
  	bp->stats.mac_frame_error_flag				= bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
  	bp->stats.mac_ma_unitdata_available			= bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
  	bp->stats.mac_hardware_present				= bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
  	bp->stats.mac_ma_unitdata_enable			= bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
  	bp->stats.path_tvx_lower_bound				= bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
  	bp->stats.path_t_max_lower_bound			= bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
  	bp->stats.path_max_t_req					= bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
  	memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
  	bp->stats.port_my_type[0]					= bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
  	bp->stats.port_my_type[1]					= bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
  	bp->stats.port_neighbor_type[0]				= bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
  	bp->stats.port_neighbor_type[1]				= bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
  	bp->stats.port_connection_policies[0]		= bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
  	bp->stats.port_connection_policies[1]		= bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
  	bp->stats.port_mac_indicated[0]				= bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
  	bp->stats.port_mac_indicated[1]				= bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
  	bp->stats.port_current_path[0]				= bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
  	bp->stats.port_current_path[1]				= bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
  	memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
  	memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
  	bp->stats.port_mac_placement[0]				= bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
  	bp->stats.port_mac_placement[1]				= bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
  	bp->stats.port_available_paths[0]			= bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
  	bp->stats.port_available_paths[1]			= bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
  	bp->stats.port_pmd_class[0]					= bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
  	bp->stats.port_pmd_class[1]					= bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
  	bp->stats.port_connection_capabilities[0]	= bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
  	bp->stats.port_connection_capabilities[1]	= bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
  	bp->stats.port_bs_flag[0]					= bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
  	bp->stats.port_bs_flag[1]					= bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
  	bp->stats.port_ler_estimate[0]				= bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
  	bp->stats.port_ler_estimate[1]				= bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
  	bp->stats.port_ler_cutoff[0]				= bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
  	bp->stats.port_ler_cutoff[1]				= bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
  	bp->stats.port_ler_alarm[0]					= bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
  	bp->stats.port_ler_alarm[1]					= bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
  	bp->stats.port_connect_state[0]				= bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
  	bp->stats.port_connect_state[1]				= bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
  	bp->stats.port_pcm_state[0]					= bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
  	bp->stats.port_pcm_state[1]					= bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
  	bp->stats.port_pc_withhold[0]				= bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
  	bp->stats.port_pc_withhold[1]				= bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
  	bp->stats.port_ler_flag[0]					= bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
  	bp->stats.port_ler_flag[1]					= bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
  	bp->stats.port_hardware_present[0]			= bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
  	bp->stats.port_hardware_present[1]			= bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
  
  	/* Get FDDI counters */
  
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
807540baa   Eric Dumazet   drivers/net: retu...
2154
  		return (struct net_device_stats *)&bp->stats;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
  
  	/* Fill the bp->stats structure with the FDDI counter values */
  
  	bp->stats.mac_frame_cts				= bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
  	bp->stats.mac_copied_cts			= bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
  	bp->stats.mac_transmit_cts			= bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
  	bp->stats.mac_error_cts				= bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
  	bp->stats.mac_lost_cts				= bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
  	bp->stats.port_lct_fail_cts[0]		= bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
  	bp->stats.port_lct_fail_cts[1]		= bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
  	bp->stats.port_lem_reject_cts[0]	= bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
  	bp->stats.port_lem_reject_cts[1]	= bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
  	bp->stats.port_lem_cts[0]			= bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
  	bp->stats.port_lem_cts[1]			= bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
807540baa   Eric Dumazet   drivers/net: retu...
2169
  	return (struct net_device_stats *)&bp->stats;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2170
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2171

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2172
2173
2174
2175
  /*
   * ==============================
   * = dfx_ctl_set_multicast_list =
   * ==============================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2176
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2177
2178
2179
   * Overview:
   *   Enable/Disable LLC frame promiscuous mode reception
   *   on the adapter and/or update multicast address table.
6aa20a223   Jeff Garzik   drivers/net: Trim...
2180
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2181
2182
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
2183
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
   * Arguments:
   *   dev - pointer to device information
   *
   * Functional Description:
   *   This routine follows a fairly simple algorithm for setting the
   *   adapter filters and CAM:
   *
   *		if IFF_PROMISC flag is set
   *			enable LLC individual/group promiscuous mode
   *		else
   *			disable LLC individual/group promiscuous mode
   *			if number of incoming multicast addresses >
   *					(CAM max size - number of unicast addresses in CAM)
   *				enable LLC group promiscuous mode
   *				set driver-maintained multicast address count to zero
   *			else
   *				disable LLC group promiscuous mode
   *				set driver-maintained multicast address count to incoming count
   *			update adapter CAM
   *		update adapter filters
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   Multicast addresses are presented in canonical (LSB) format.
   *
   * Side Effects:
   *   On-board adapter CAM and filters are updated.
   */
  
  static void dfx_ctl_set_multicast_list(struct net_device *dev)
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
2216
2217
  {
  	DFX_board_t *bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2218
  	int					i;			/* used as index in for loop */
22bedad3c   Jiri Pirko   net: convert mult...
2219
  	struct netdev_hw_addr *ha;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
  
  	/* Enable LLC frame promiscuous mode, if necessary */
  
  	if (dev->flags & IFF_PROMISC)
  		bp->ind_group_prom = PI_FSTATE_K_PASS;		/* Enable LLC ind/group prom mode */
  
  	/* Else, update multicast address table */
  
  	else
  		{
  		bp->ind_group_prom = PI_FSTATE_K_BLOCK;		/* Disable LLC ind/group prom mode */
  		/*
  		 * Check whether incoming multicast address count exceeds table size
  		 *
  		 * Note: The adapters utilize an on-board 64 entry CAM for
  		 *       supporting perfect filtering of multicast packets
  		 *		 and bridge functions when adding unicast addresses.
  		 *		 There is no hash function available.  To support
  		 *		 additional multicast addresses, the all multicast
  		 *		 filter (LLC group promiscuous mode) must be enabled.
  		 *
  		 *		 The firmware reserves two CAM entries for SMT-related
  		 *		 multicast addresses, which leaves 62 entries available.
  		 *		 The following code ensures that we're not being asked
  		 *		 to add more than 62 addresses to the CAM.  If we are,
  		 *		 the driver will enable the all multicast filter.
  		 *		 Should the number of multicast addresses drop below
  		 *		 the high water mark, the filter will be disabled and
  		 *		 perfect filtering will be used.
  		 */
4cd24eaf0   Jiri Pirko   net: use netdev_m...
2250
  		if (netdev_mc_count(dev) > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2251
2252
2253
2254
2255
2256
2257
  			{
  			bp->group_prom	= PI_FSTATE_K_PASS;		/* Enable LLC group prom mode */
  			bp->mc_count	= 0;					/* Don't add mc addrs to CAM */
  			}
  		else
  			{
  			bp->group_prom	= PI_FSTATE_K_BLOCK;	/* Disable LLC group prom mode */
4cd24eaf0   Jiri Pirko   net: use netdev_m...
2258
  			bp->mc_count	= netdev_mc_count(dev);		/* Add mc addrs to CAM */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2259
2260
2261
  			}
  
  		/* Copy addresses to multicast address table, then update adapter CAM */
e1d444771   Jiri Pirko   net: convert mult...
2262
  		i = 0;
22bedad3c   Jiri Pirko   net: convert mult...
2263
  		netdev_for_each_mc_addr(ha, dev)
e1d444771   Jiri Pirko   net: convert mult...
2264
  			memcpy(&bp->mc_table[i++ * FDDI_K_ALEN],
22bedad3c   Jiri Pirko   net: convert mult...
2265
  			       ha->addr, FDDI_K_ALEN);
e1d444771   Jiri Pirko   net: convert mult...
2266

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
  		if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  			{
  			DBG_printk("%s: Could not update multicast address table!
  ", dev->name);
  			}
  		else
  			{
  			DBG_printk("%s: Multicast address table updated!  Added %d addresses.
  ", dev->name, bp->mc_count);
  			}
  		}
  
  	/* Update adapter filters */
  
  	if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  		{
  		DBG_printk("%s: Could not update adapter filters!
  ", dev->name);
  		}
  	else
  		{
  		DBG_printk("%s: Adapter filters updated!
  ", dev->name);
  		}
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2292

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2293
2294
2295
2296
  /*
   * ===========================
   * = dfx_ctl_set_mac_address =
   * ===========================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2297
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2298
2299
2300
   * Overview:
   *   Add node address override (unicast address) to adapter
   *   CAM and update dev_addr field in device table.
6aa20a223   Jeff Garzik   drivers/net: Trim...
2301
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2302
2303
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
2304
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
   * Arguments:
   *   dev  - pointer to device information
   *   addr - pointer to sockaddr structure containing unicast address to add
   *
   * Functional Description:
   *   The adapter supports node address overrides by adding one or more
   *   unicast addresses to the adapter CAM.  This is similar to adding
   *   multicast addresses.  In this routine we'll update the driver and
   *   device structures with the new address, then update the adapter CAM
   *   to ensure that the adapter will copy and strip frames destined and
   *   sourced by that address.
   *
   * Return Codes:
   *   Always returns zero.
   *
   * Assumptions:
   *   The address pointed to by addr->sa_data is a valid unicast
   *   address and is presented in canonical (LSB) format.
   *
   * Side Effects:
   *   On-board adapter CAM is updated.  On-board adapter filters
   *   may be updated.
   */
  
  static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2331
  	struct sockaddr	*p_sockaddr = (struct sockaddr *)addr;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
2332
  	DFX_board_t *bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
  
  	/* Copy unicast address to driver-maintained structs and update count */
  
  	memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);	/* update device struct */
  	memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN);	/* update driver struct */
  	bp->uc_count = 1;
  
  	/*
  	 * Verify we're not exceeding the CAM size by adding unicast address
  	 *
  	 * Note: It's possible that before entering this routine we've
  	 *       already filled the CAM with 62 multicast addresses.
  	 *		 Since we need to place the node address override into
  	 *		 the CAM, we have to check to see that we're not
  	 *		 exceeding the CAM size.  If we are, we have to enable
  	 *		 the LLC group (multicast) promiscuous mode filter as
  	 *		 in dfx_ctl_set_multicast_list.
  	 */
  
  	if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
  		{
  		bp->group_prom	= PI_FSTATE_K_PASS;		/* Enable LLC group prom mode */
  		bp->mc_count	= 0;					/* Don't add mc addrs to CAM */
  
  		/* Update adapter filters */
  
  		if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  			{
  			DBG_printk("%s: Could not update adapter filters!
  ", dev->name);
  			}
  		else
  			{
  			DBG_printk("%s: Adapter filters updated!
  ", dev->name);
  			}
  		}
  
  	/* Update adapter CAM with new unicast address */
  
  	if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  		{
  		DBG_printk("%s: Could not set new MAC address!
  ", dev->name);
  		}
  	else
  		{
  		DBG_printk("%s: Adapter CAM updated with new MAC address
  ", dev->name);
  		}
807540baa   Eric Dumazet   drivers/net: retu...
2383
  	return 0;			/* always return zero */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2384
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2385

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
  /*
   * ======================
   * = dfx_ctl_update_cam =
   * ======================
   *
   * Overview:
   *   Procedure to update adapter CAM (Content Addressable Memory)
   *   with desired unicast and multicast address entries.
   *
   * Returns:
   *   Condition code
   *
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Updates adapter CAM with current contents of board structure
   *   unicast and multicast address tables.  Since there are only 62
   *   free entries in CAM, this routine ensures that the command
   *   request buffer is not overrun.
   *
   * Return Codes:
   *   DFX_K_SUCCESS - Request succeeded
   *   DFX_K_FAILURE - Request failed
   *
   * Assumptions:
   *   All addresses being added (unicast and multicast) are in canonical
   *   order.
   *
   * Side Effects:
   *   On-board adapter CAM is updated.
   */
  
  static int dfx_ctl_update_cam(DFX_board_t *bp)
  	{
  	int			i;				/* used as index */
  	PI_LAN_ADDR	*p_addr;		/* pointer to CAM entry */
  
  	/*
  	 * Fill in command request information
  	 *
  	 * Note: Even though both the unicast and multicast address
  	 *       table entries are stored as contiguous 6 byte entries,
  	 *		 the firmware address filter set command expects each
  	 *		 entry to be two longwords (8 bytes total).  We must be
  	 *		 careful to only copy the six bytes of each unicast and
  	 *		 multicast table entry into each command entry.  This
  	 *		 is also why we must first clear the entire command
  	 *		 request buffer.
  	 */
  
  	memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX);	/* first clear buffer */
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
  	p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
  
  	/* Now add unicast addresses to command request buffer, if any */
  
  	for (i=0; i < (int)bp->uc_count; i++)
  		{
  		if (i < PI_CMD_ADDR_FILTER_K_SIZE)
  			{
  			memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
  			p_addr++;			/* point to next command entry */
  			}
  		}
  
  	/* Now add multicast addresses to command request buffer, if any */
  
  	for (i=0; i < (int)bp->mc_count; i++)
  		{
  		if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
  			{
  			memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
  			p_addr++;			/* point to next command entry */
  			}
  		}
  
  	/* Issue command to update adapter CAM, then return */
  
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
807540baa   Eric Dumazet   drivers/net: retu...
2466
2467
  		return DFX_K_FAILURE;
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2468
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2469

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2470
2471
2472
2473
2474
2475
2476
2477
  /*
   * ==========================
   * = dfx_ctl_update_filters =
   * ==========================
   *
   * Overview:
   *   Procedure to update adapter filters with desired
   *   filter settings.
6aa20a223   Jeff Garzik   drivers/net: Trim...
2478
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2479
2480
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
2481
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Enables or disables filter using current filter settings.
   *
   * Return Codes:
   *   DFX_K_SUCCESS - Request succeeded.
   *   DFX_K_FAILURE - Request failed.
   *
   * Assumptions:
   *   We must always pass up packets destined to the broadcast
   *   address (FF-FF-FF-FF-FF-FF), so we'll always keep the
   *   broadcast filter enabled.
   *
   * Side Effects:
   *   On-board adapter filters are updated.
   */
  
  static int dfx_ctl_update_filters(DFX_board_t *bp)
  	{
  	int	i = 0;					/* used as index */
  
  	/* Fill in command request information */
  
  	bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
  
  	/* Initialize Broadcast filter - * ALWAYS ENABLED * */
  
  	bp->cmd_req_virt->filter_set.item[i].item_code	= PI_ITEM_K_BROADCAST;
  	bp->cmd_req_virt->filter_set.item[i++].value	= PI_FSTATE_K_PASS;
  
  	/* Initialize LLC Individual/Group Promiscuous filter */
  
  	bp->cmd_req_virt->filter_set.item[i].item_code	= PI_ITEM_K_IND_GROUP_PROM;
  	bp->cmd_req_virt->filter_set.item[i++].value	= bp->ind_group_prom;
  
  	/* Initialize LLC Group Promiscuous filter */
  
  	bp->cmd_req_virt->filter_set.item[i].item_code	= PI_ITEM_K_GROUP_PROM;
  	bp->cmd_req_virt->filter_set.item[i++].value	= bp->group_prom;
  
  	/* Terminate the item code list */
  
  	bp->cmd_req_virt->filter_set.item[i].item_code	= PI_ITEM_K_EOL;
  
  	/* Issue command to update adapter filters, then return */
  
  	if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
807540baa   Eric Dumazet   drivers/net: retu...
2531
2532
  		return DFX_K_FAILURE;
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2533
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2534

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2535
2536
2537
2538
  /*
   * ======================
   * = dfx_hw_dma_cmd_req =
   * ======================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2539
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2540
2541
   * Overview:
   *   Sends PDQ DMA command to adapter firmware
6aa20a223   Jeff Garzik   drivers/net: Trim...
2542
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2543
2544
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
2545
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   The command request and response buffers are posted to the adapter in the manner
   *   described in the PDQ Port Specification:
   *
   *		1. Command Response Buffer is posted to adapter.
   *		2. Command Request Buffer is posted to adapter.
   *		3. Command Request consumer index is polled until it indicates that request
   *         buffer has been DMA'd to adapter.
   *		4. Command Response consumer index is polled until it indicates that response
   *         buffer has been DMA'd from adapter.
   *
   *   This ordering ensures that a response buffer is already available for the firmware
   *   to use once it's done processing the request buffer.
   *
   * Return Codes:
   *   DFX_K_SUCCESS	  - DMA command succeeded
   * 	 DFX_K_OUTSTATE   - Adapter is NOT in proper state
   *   DFX_K_HW_TIMEOUT - DMA command timed out
   *
   * Assumptions:
   *   Command request buffer has already been filled with desired DMA command.
   *
   * Side Effects:
   *   None
   */
  
  static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
  	{
  	int status;			/* adapter status */
  	int timeout_cnt;	/* used in for loops */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2579

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2580
  	/* Make sure the adapter is in a state that we can issue the DMA command in */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2581

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2582
2583
2584
2585
2586
  	status = dfx_hw_adap_state_rd(bp);
  	if ((status == PI_STATE_K_RESET)		||
  		(status == PI_STATE_K_HALTED)		||
  		(status == PI_STATE_K_DMA_UNAVAIL)	||
  		(status == PI_STATE_K_UPGRADE))
807540baa   Eric Dumazet   drivers/net: retu...
2587
  		return DFX_K_OUTSTATE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
  
  	/* Put response buffer on the command response queue */
  
  	bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  			((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  	bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
  
  	/* Bump (and wrap) the producer index and write out to register */
  
  	bp->cmd_rsp_reg.index.prod += 1;
  	bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
  	dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
  
  	/* Put request buffer on the command request queue */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2602

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
  	bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
  			PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
  	bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
  
  	/* Bump (and wrap) the producer index and write out to register */
  
  	bp->cmd_req_reg.index.prod += 1;
  	bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
  	dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
  
  	/*
  	 * Here we wait for the command request consumer index to be equal
  	 * to the producer, indicating that the adapter has DMAed the request.
  	 */
  
  	for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
  		{
  		if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
  			break;
  		udelay(100);			/* wait for 100 microseconds */
  		}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2624
  	if (timeout_cnt == 0)
807540baa   Eric Dumazet   drivers/net: retu...
2625
  		return DFX_K_HW_TIMEOUT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
  
  	/* Bump (and wrap) the completion index and write out to register */
  
  	bp->cmd_req_reg.index.comp += 1;
  	bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
  	dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
  
  	/*
  	 * Here we wait for the command response consumer index to be equal
  	 * to the producer, indicating that the adapter has DMAed the response.
  	 */
  
  	for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
  		{
  		if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
  			break;
  		udelay(100);			/* wait for 100 microseconds */
  		}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2644
  	if (timeout_cnt == 0)
807540baa   Eric Dumazet   drivers/net: retu...
2645
  		return DFX_K_HW_TIMEOUT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2646
2647
2648
2649
2650
2651
  
  	/* Bump (and wrap) the completion index and write out to register */
  
  	bp->cmd_rsp_reg.index.comp += 1;
  	bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
  	dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
807540baa   Eric Dumazet   drivers/net: retu...
2652
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2653
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2654

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2655
2656
2657
2658
  /*
   * ========================
   * = dfx_hw_port_ctrl_req =
   * ========================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2659
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2660
2661
   * Overview:
   *   Sends PDQ port control command to adapter firmware
6aa20a223   Jeff Garzik   drivers/net: Trim...
2662
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2663
2664
   * Returns:
   *   Host data register value in host_data if ptr is not NULL
6aa20a223   Jeff Garzik   drivers/net: Trim...
2665
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
   * Arguments:
   *   bp			- pointer to board information
   *	 command	- port control command
   *	 data_a		- port data A register value
   *	 data_b		- port data B register value
   *	 host_data	- ptr to host data register value
   *
   * Functional Description:
   *   Send generic port control command to adapter by writing
   *   to various PDQ port registers, then polling for completion.
   *
   * Return Codes:
   *   DFX_K_SUCCESS	  - port control command succeeded
   *   DFX_K_HW_TIMEOUT - port control command timed out
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   None
   */
  
  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
  	)
  
  	{
  	PI_UINT32	port_cmd;		/* Port Control command register value */
  	int			timeout_cnt;	/* used in for loops */
  
  	/* Set Command Error bit in command longword */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2701

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
  	port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
  
  	/* Issue port command to the adapter */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
  	dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
  	dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
  
  	/* Now wait for command to complete */
  
  	if (command == PI_PCTRL_M_BLAST_FLASH)
  		timeout_cnt = 600000;	/* set command timeout count to 60 seconds */
  	else
  		timeout_cnt = 20000;	/* set command timeout count to 2 seconds */
  
  	for (; timeout_cnt > 0; timeout_cnt--)
  		{
  		dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
  		if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
  			break;
  		udelay(100);			/* wait for 100 microseconds */
  		}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2724
  	if (timeout_cnt == 0)
807540baa   Eric Dumazet   drivers/net: retu...
2725
  		return DFX_K_HW_TIMEOUT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2726
2727
  
  	/*
6aa20a223   Jeff Garzik   drivers/net: Trim...
2728
2729
  	 * If the address of host_data is non-zero, assume caller has supplied a
  	 * non NULL pointer, and return the contents of the HOST_DATA register in
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2730
2731
2732
2733
2734
  	 * it.
  	 */
  
  	if (host_data != NULL)
  		dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
807540baa   Eric Dumazet   drivers/net: retu...
2735
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2736
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2737

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2738
2739
2740
2741
  /*
   * =====================
   * = dfx_hw_adap_reset =
   * =====================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2742
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2743
2744
   * Overview:
   *   Resets adapter
6aa20a223   Jeff Garzik   drivers/net: Trim...
2745
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2746
2747
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
2748
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
   * Arguments:
   *   bp   - pointer to board information
   *   type - type of reset to perform
   *
   * Functional Description:
   *   Issue soft reset to adapter by writing to PDQ Port Reset
   *   register.  Use incoming reset type to tell adapter what
   *   kind of reset operation to perform.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   This routine merely issues a soft reset to the adapter.
   *   It is expected that after this routine returns, the caller
   *   will appropriately poll the Port Status register for the
   *   adapter to enter the proper state.
   *
   * Side Effects:
   *   Internal adapter registers are cleared.
   */
  
  static void dfx_hw_adap_reset(
  	DFX_board_t	*bp,
  	PI_UINT32	type
  	)
  
  	{
  	/* Set Reset type and assert reset */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type);	/* tell adapter type of reset */
  	dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
  
  	/* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
  
  	udelay(20);
  
  	/* Deassert reset */
  
  	dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2790

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2791
2792
2793
2794
  /*
   * ========================
   * = dfx_hw_adap_state_rd =
   * ========================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2795
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2796
2797
   * Overview:
   *   Returns current adapter state
6aa20a223   Jeff Garzik   drivers/net: Trim...
2798
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2799
2800
   * Returns:
   *   Adapter state per PDQ Port Specification
6aa20a223   Jeff Garzik   drivers/net: Trim...
2801
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Reads PDQ Port Status register and returns adapter state.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   None
   */
  
  static int dfx_hw_adap_state_rd(DFX_board_t *bp)
  	{
  	PI_UINT32 port_status;		/* Port Status register value */
  
  	dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
807540baa   Eric Dumazet   drivers/net: retu...
2823
  	return (port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2824
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2825

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2826
2827
2828
2829
  /*
   * =====================
   * = dfx_hw_dma_uninit =
   * =====================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2830
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2831
2832
   * Overview:
   *   Brings adapter to DMA_UNAVAILABLE state
6aa20a223   Jeff Garzik   drivers/net: Trim...
2833
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2834
2835
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
2836
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
   * Arguments:
   *   bp   - pointer to board information
   *   type - type of reset to perform
   *
   * Functional Description:
   *   Bring adapter to DMA_UNAVAILABLE state by performing the following:
   *		1. Set reset type bit in Port Data A Register then reset adapter.
   *		2. Check that adapter is in DMA_UNAVAILABLE state.
   *
   * Return Codes:
   *   DFX_K_SUCCESS	  - adapter is in DMA_UNAVAILABLE state
   *   DFX_K_HW_TIMEOUT - adapter did not reset properly
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   Internal adapter registers are cleared.
   */
  
  static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
  	{
  	int timeout_cnt;	/* used in for loops */
  
  	/* Set reset type bit and reset adapter */
  
  	dfx_hw_adap_reset(bp, type);
  
  	/* Now wait for adapter to enter DMA_UNAVAILABLE state */
  
  	for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
  		{
  		if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
  			break;
  		udelay(100);					/* wait for 100 microseconds */
  		}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2873
  	if (timeout_cnt == 0)
807540baa   Eric Dumazet   drivers/net: retu...
2874
2875
  		return DFX_K_HW_TIMEOUT;
  	return DFX_K_SUCCESS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2876
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2877

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2878
2879
2880
2881
  /*
   *	Align an sk_buff to a boundary power of 2
   *
   */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2882

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2883
2884
2885
2886
  static void my_skb_align(struct sk_buff *skb, int n)
  {
  	unsigned long x = (unsigned long)skb->data;
  	unsigned long v;
6aa20a223   Jeff Garzik   drivers/net: Trim...
2887

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2888
  	v = ALIGN(x, n);	/* Where we want to be */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2889

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2890
2891
  	skb_reserve(skb, v - x);
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
2892

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2893
2894
2895
2896
  /*
   * ================
   * = dfx_rcv_init =
   * ================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2897
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2898
2899
   * Overview:
   *   Produces buffers to adapter LLC Host receive descriptor block
6aa20a223   Jeff Garzik   drivers/net: Trim...
2900
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2901
2902
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
2903
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
   * Arguments:
   *   bp - pointer to board information
   *   get_buffers - non-zero if buffers to be allocated
   *
   * Functional Description:
   *   This routine can be called during dfx_adap_init() or during an adapter
   *	 reset.  It initializes the descriptor block and produces all allocated
   *   LLC Host queue receive buffers.
   *
   * Return Codes:
   *   Return 0 on success or -ENOMEM if buffer allocation failed (when using
   *   dynamic buffer allocation). If the buffer allocation failed, the
   *   already allocated buffers will not be released and the caller should do
   *   this.
   *
   * Assumptions:
   *   The PDQ has been reset and the adapter and driver maintained Type 2
   *   register indices are cleared.
   *
   * Side Effects:
   *   Receive buffers are posted to the adapter LLC queue and the adapter
   *   is notified.
   */
  
  static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
  	{
  	int	i, j;					/* used in for loop */
  
  	/*
  	 *  Since each receive buffer is a single fragment of same length, initialize
  	 *  first longword in each receive descriptor for entire LLC Host descriptor
  	 *  block.  Also initialize second longword in each receive descriptor with
  	 *  physical address of receive buffer.  We'll always allocate receive
  	 *  buffers in powers of 2 so that we can easily fill the 256 entry descriptor
  	 *  block and produce new receive buffers by simply updating the receive
  	 *  producer index.
  	 *
  	 * 	Assumptions:
  	 *		To support all shipping versions of PDQ, the receive buffer size
  	 *		must be mod 128 in length and the physical address must be 128 byte
  	 *		aligned.  In other words, bits 0-6 of the length and address must
  	 *		be zero for the following descriptor field entries to be correct on
  	 *		all PDQ-based boards.  We guaranteed both requirements during
  	 *		driver initialization when we allocated memory for the receive buffers.
  	 */
  
  	if (get_buffers) {
  #ifdef DYNAMIC_BUFFERS
  	for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
  		for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  		{
9034f77ba   David S. Miller   netdev: Use __net...
2955
  			struct sk_buff *newskb = __netdev_alloc_skb(bp->dev, NEW_SKB_SIZE, GFP_NOIO);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2956
2957
2958
2959
2960
2961
2962
2963
  			if (!newskb)
  				return -ENOMEM;
  			bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  				((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  			/*
  			 * align to 128 bytes for compatibility with
  			 * the old EISA boards.
  			 */
6aa20a223   Jeff Garzik   drivers/net: Trim...
2964

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2965
2966
  			my_skb_align(newskb, 128);
  			bp->descr_block_virt->rcv_data[i + j].long_1 =
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
2967
  				(u32)dma_map_single(bp->bus_dev, newskb->data,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2968
  						    NEW_SKB_SIZE,
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
2969
  						    DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
  			/*
  			 * p_rcv_buff_va is only used inside the
  			 * kernel so we put the skb pointer here.
  			 */
  			bp->p_rcv_buff_va[i+j] = (char *) newskb;
  		}
  #else
  	for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
  		for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  			{
  			bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  				((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  			bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
  			bp->p_rcv_buff_va[i+j] = (char *) (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
  			}
  #endif
  	}
  
  	/* Update receive producer and Type 2 register */
  
  	bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
  	dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  	return 0;
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
2994

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2995
2996
2997
2998
  /*
   * =========================
   * = dfx_rcv_queue_process =
   * =========================
6aa20a223   Jeff Garzik   drivers/net: Trim...
2999
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3000
3001
   * Overview:
   *   Process received LLC frames.
6aa20a223   Jeff Garzik   drivers/net: Trim...
3002
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3003
3004
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
3005
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Received LLC frames are processed until there are no more consumed frames.
   *   Once all frames are processed, the receive buffers are returned to the
   *   adapter.  Note that this algorithm fixes the length of time that can be spent
   *   in this routine, because there are a fixed number of receive buffers to
   *   process and buffers are not produced until this routine exits and returns
   *   to the ISR.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   None
   *
   * Side Effects:
   *   None
   */
  
  static void dfx_rcv_queue_process(
  	DFX_board_t *bp
  	)
  
  	{
  	PI_TYPE_2_CONSUMER	*p_type_2_cons;		/* ptr to rcv/xmt consumer block register */
  	char				*p_buff;			/* ptr to start of packet receive buffer (FMC descriptor) */
  	u32					descr, pkt_len;		/* FMC descriptor field and packet length */
  	struct sk_buff		*skb;				/* pointer to a sk_buff to hold incoming packet data */
  
  	/* Service all consumed LLC receive frames */
  
  	p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
  	while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
  		{
  		/* Process any errors */
  
  		int entry;
  
  		entry = bp->rcv_xmt_reg.index.rcv_comp;
  #ifdef DYNAMIC_BUFFERS
  		p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
  #else
  		p_buff = (char *) bp->p_rcv_buff_va[entry];
  #endif
  		memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
  
  		if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
  			{
  			if (descr & PI_FMC_DESCR_M_RCC_CRC)
  				bp->rcv_crc_errors++;
  			else
  				bp->rcv_frame_status_errors++;
  			}
  		else
  		{
  			int rx_in_place = 0;
  
  			/* The frame was received without errors - verify packet length */
  
  			pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
  			pkt_len -= 4;				/* subtract 4 byte CRC */
  			if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
  				bp->rcv_length_errors++;
  			else{
  #ifdef DYNAMIC_BUFFERS
  				if (pkt_len > SKBUFF_RX_COPYBREAK) {
  					struct sk_buff *newskb;
  
  					newskb = dev_alloc_skb(NEW_SKB_SIZE);
  					if (newskb){
  						rx_in_place = 1;
6aa20a223   Jeff Garzik   drivers/net: Trim...
3079

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3080
3081
  						my_skb_align(newskb, 128);
  						skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3082
  						dma_unmap_single(bp->bus_dev,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3083
3084
  							bp->descr_block_virt->rcv_data[entry].long_1,
  							NEW_SKB_SIZE,
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3085
  							DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3086
3087
3088
  						skb_reserve(skb, RCV_BUFF_K_PADDING);
  						bp->p_rcv_buff_va[entry] = (char *)newskb;
  						bp->descr_block_virt->rcv_data[entry].long_1 =
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3089
  							(u32)dma_map_single(bp->bus_dev,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3090
3091
  								newskb->data,
  								NEW_SKB_SIZE,
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3092
  								DMA_FROM_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
  					} else
  						skb = NULL;
  				} else
  #endif
  					skb = dev_alloc_skb(pkt_len+3);	/* alloc new buffer to pass up, add room for PRH */
  				if (skb == NULL)
  					{
  					printk("%s: Could not allocate receive buffer.  Dropping packet.
  ", bp->dev->name);
  					bp->rcv_discards++;
  					break;
  					}
  				else {
  #ifndef DYNAMIC_BUFFERS
  					if (! rx_in_place)
  #endif
  					{
  						/* Receive buffer allocated, pass receive packet up */
27d7ff46a   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
3111
3112
3113
  						skb_copy_to_linear_data(skb,
  							       p_buff + RCV_BUFF_K_PADDING,
  							       pkt_len + 3);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3114
  					}
6aa20a223   Jeff Garzik   drivers/net: Trim...
3115

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3116
3117
  					skb_reserve(skb,3);		/* adjust data field so that it points to FC byte */
  					skb_put(skb, pkt_len);		/* pass up packet length, NOT including CRC */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3118
3119
3120
3121
3122
  					skb->protocol = fddi_type_trans(skb, bp->dev);
  					bp->rcv_total_bytes += skb->len;
  					netif_rx(skb);
  
  					/* Update the rcv counters */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
  					bp->rcv_total_frames++;
  					if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
  						bp->rcv_multicast_frames++;
  				}
  			}
  			}
  
  		/*
  		 * Advance the producer (for recycling) and advance the completion
  		 * (for servicing received frames).  Note that it is okay to
  		 * advance the producer without checking that it passes the
  		 * completion index because they are both advanced at the same
  		 * rate.
  		 */
  
  		bp->rcv_xmt_reg.index.rcv_prod += 1;
  		bp->rcv_xmt_reg.index.rcv_comp += 1;
  		}
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
3142

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3143
3144
3145
3146
  /*
   * =====================
   * = dfx_xmt_queue_pkt =
   * =====================
6aa20a223   Jeff Garzik   drivers/net: Trim...
3147
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3148
3149
   * Overview:
   *   Queues packets for transmission
6aa20a223   Jeff Garzik   drivers/net: Trim...
3150
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3151
3152
   * Returns:
   *   Condition code
6aa20a223   Jeff Garzik   drivers/net: Trim...
3153
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
   * Arguments:
   *   skb - pointer to sk_buff to queue for transmission
   *   dev - pointer to device information
   *
   * Functional Description:
   *   Here we assume that an incoming skb transmit request
   *   is contained in a single physically contiguous buffer
   *   in which the virtual address of the start of packet
   *   (skb->data) can be converted to a physical address
   *   by using pci_map_single().
   *
   *   Since the adapter architecture requires a three byte
   *   packet request header to prepend the start of packet,
   *   we'll write the three byte field immediately prior to
   *   the FC byte.  This assumption is valid because we've
   *   ensured that dev->hard_header_len includes three pad
   *   bytes.  By posting a single fragment to the adapter,
   *   we'll reduce the number of descriptor fetches and
   *   bus traffic needed to send the request.
   *
   *   Also, we can't free the skb until after it's been DMA'd
   *   out by the adapter, so we'll queue it in the driver and
   *   return it in dfx_xmt_done.
   *
   * Return Codes:
   *   0 - driver queued packet, link is unavailable, or skbuff was bad
   *	 1 - caller should requeue the sk_buff for later transmission
   *
   * Assumptions:
   *	 First and foremost, we assume the incoming skb pointer
   *   is NOT NULL and is pointing to a valid sk_buff structure.
   *
   *   The outgoing packet is complete, starting with the
   *   frame control byte including the last byte of data,
   *   but NOT including the 4 byte CRC.  We'll let the
   *   adapter hardware generate and append the CRC.
   *
   *   The entire packet is stored in one physically
   *   contiguous buffer which is not cached and whose
   *   32-bit physical address can be determined.
   *
   *   It's vital that this routine is NOT reentered for the
   *   same board and that the OS is not in another section of
   *   code (eg. dfx_int_common) for the same board on a
   *   different thread.
   *
   * Side Effects:
   *   None
   */
61357325f   Stephen Hemminger   netdev: convert b...
3203
3204
  static netdev_tx_t dfx_xmt_queue_pkt(struct sk_buff *skb,
  				     struct net_device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3205
  	{
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3206
  	DFX_board_t		*bp = netdev_priv(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3207
3208
3209
3210
3211
3212
  	u8			prod;				/* local transmit producer index */
  	PI_XMT_DESCR		*p_xmt_descr;		/* ptr to transmit descriptor block entry */
  	XMT_DRIVER_DESCR	*p_xmt_drv_descr;	/* ptr to transmit driver descriptor */
  	unsigned long		flags;
  
  	netif_stop_queue(dev);
6aa20a223   Jeff Garzik   drivers/net: Trim...
3213

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
  	/*
  	 * Verify that incoming transmit request is OK
  	 *
  	 * Note: The packet size check is consistent with other
  	 *		 Linux device drivers, although the correct packet
  	 *		 size should be verified before calling the
  	 *		 transmit routine.
  	 */
  
  	if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
  	{
6aa20a223   Jeff Garzik   drivers/net: Trim...
3225
3226
  		printk("%s: Invalid packet length - %u bytes
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3227
3228
3229
3230
  			dev->name, skb->len);
  		bp->xmt_length_errors++;		/* bump error counter */
  		netif_wake_queue(dev);
  		dev_kfree_skb(skb);
ec634fe32   Patrick McHardy   net: convert rema...
3231
  		return NETDEV_TX_OK;			/* return "success" */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
  	}
  	/*
  	 * See if adapter link is available, if not, free buffer
  	 *
  	 * Note: If the link isn't available, free buffer and return 0
  	 *		 rather than tell the upper layer to requeue the packet.
  	 *		 The methodology here is that by the time the link
  	 *		 becomes available, the packet to be sent will be
  	 *		 fairly stale.  By simply dropping the packet, the
  	 *		 higher layer protocols will eventually time out
  	 *		 waiting for response packets which it won't receive.
  	 */
  
  	if (bp->link_available == PI_K_FALSE)
  		{
  		if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL)	/* is link really available? */
  			bp->link_available = PI_K_TRUE;		/* if so, set flag and continue */
  		else
  			{
  			bp->xmt_discards++;					/* bump error counter */
  			dev_kfree_skb(skb);		/* free sk_buff now */
  			netif_wake_queue(dev);
ec634fe32   Patrick McHardy   net: convert rema...
3254
  			return NETDEV_TX_OK;		/* return "success" */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3255
3256
3257
3258
  			}
  		}
  
  	spin_lock_irqsave(&bp->lock, flags);
6aa20a223   Jeff Garzik   drivers/net: Trim...
3259

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
  	/* Get the current producer and the next free xmt data descriptor */
  
  	prod		= bp->rcv_xmt_reg.index.xmt_prod;
  	p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
  
  	/*
  	 * Get pointer to auxiliary queue entry to contain information
  	 * for this packet.
  	 *
  	 * Note: The current xmt producer index will become the
  	 *	 current xmt completion index when we complete this
  	 *	 packet later on.  So, we'll get the pointer to the
  	 *	 next auxiliary queue entry now before we bump the
  	 *	 producer index.
  	 */
  
  	p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]);	/* also bump producer index */
  
  	/* Write the three PRH bytes immediately before the FC byte */
  
  	skb_push(skb,3);
  	skb->data[0] = DFX_PRH0_BYTE;	/* these byte values are defined */
  	skb->data[1] = DFX_PRH1_BYTE;	/* in the Motorola FDDI MAC chip */
  	skb->data[2] = DFX_PRH2_BYTE;	/* specification */
  
  	/*
  	 * Write the descriptor with buffer info and bump producer
  	 *
  	 * Note: Since we need to start DMA from the packet request
  	 *		 header, we'll add 3 bytes to the DMA buffer length,
  	 *		 and we'll determine the physical address of the
  	 *		 buffer from the PRH, not skb->data.
  	 *
  	 * Assumptions:
  	 *		 1. Packet starts with the frame control (FC) byte
  	 *		    at skb->data.
  	 *		 2. The 4-byte CRC is not appended to the buffer or
  	 *			included in the length.
  	 *		 3. Packet length (skb->len) is from FC to end of
  	 *			data, inclusive.
  	 *		 4. The packet length does not exceed the maximum
  	 *			FDDI LLC frame length of 4491 bytes.
  	 *		 5. The entire packet is contained in a physically
  	 *			contiguous, non-cached, locked memory space
  	 *			comprised of a single buffer pointed to by
  	 *			skb->data.
  	 *		 6. The physical address of the start of packet
  	 *			can be determined from the virtual address
  	 *			by using pci_map_single() and is only 32-bits
  	 *			wide.
  	 */
  
  	p_xmt_descr->long_0	= (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3313
3314
  	p_xmt_descr->long_1 = (u32)dma_map_single(bp->bus_dev, skb->data,
  						  skb->len, DMA_TO_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
  
  	/*
  	 * Verify that descriptor is actually available
  	 *
  	 * Note: If descriptor isn't available, return 1 which tells
  	 *	 the upper layer to requeue the packet for later
  	 *	 transmission.
  	 *
  	 *       We need to ensure that the producer never reaches the
  	 *	 completion, except to indicate that the queue is empty.
  	 */
  
  	if (prod == bp->rcv_xmt_reg.index.xmt_comp)
  	{
  		skb_pull(skb,3);
  		spin_unlock_irqrestore(&bp->lock, flags);
5b5481402   Patrick McHardy   net: use symbolic...
3331
  		return NETDEV_TX_BUSY;	/* requeue packet for later */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
  	}
  
  	/*
  	 * Save info for this packet for xmt done indication routine
  	 *
  	 * Normally, we'd save the producer index in the p_xmt_drv_descr
  	 * structure so that we'd have it handy when we complete this
  	 * packet later (in dfx_xmt_done).  However, since the current
  	 * transmit architecture guarantees a single fragment for the
  	 * entire packet, we can simply bump the completion index by
  	 * one (1) for each completed packet.
  	 *
  	 * Note: If this assumption changes and we're presented with
  	 *	 an inconsistent number of transmit fragments for packet
  	 *	 data, we'll need to modify this code to save the current
  	 *	 transmit producer index.
  	 */
  
  	p_xmt_drv_descr->p_skb = skb;
  
  	/* Update Type 2 register */
  
  	bp->rcv_xmt_reg.index.xmt_prod = prod;
  	dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  	spin_unlock_irqrestore(&bp->lock, flags);
  	netif_wake_queue(dev);
ec634fe32   Patrick McHardy   net: convert rema...
3358
  	return NETDEV_TX_OK;	/* packet queued to adapter */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3359
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
3360

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3361
3362
3363
3364
  /*
   * ================
   * = dfx_xmt_done =
   * ================
6aa20a223   Jeff Garzik   drivers/net: Trim...
3365
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3366
3367
   * Overview:
   *   Processes all frames that have been transmitted.
6aa20a223   Jeff Garzik   drivers/net: Trim...
3368
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3369
3370
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
3371
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   For all consumed transmit descriptors that have not
   *   yet been completed, we'll free the skb we were holding
   *   onto using dev_kfree_skb and bump the appropriate
   *   counters.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   The Type 2 register is not updated in this routine.  It is
   *   assumed that it will be updated in the ISR when dfx_xmt_done
   *   returns.
   *
   * Side Effects:
   *   None
   */
  
  static int dfx_xmt_done(DFX_board_t *bp)
  	{
  	XMT_DRIVER_DESCR	*p_xmt_drv_descr;	/* ptr to transmit driver descriptor */
  	PI_TYPE_2_CONSUMER	*p_type_2_cons;		/* ptr to rcv/xmt consumer block register */
  	u8			comp;			/* local transmit completion index */
  	int 			freed = 0;		/* buffers freed */
  
  	/* Service all consumed transmit frames */
  
  	p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
  	while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
  		{
  		/* Get pointer to the transmit driver descriptor block information */
  
  		p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
  
  		/* Increment transmit counters */
  
  		bp->xmt_total_frames++;
  		bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
  
  		/* Return skb to operating system */
  		comp = bp->rcv_xmt_reg.index.xmt_comp;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3416
  		dma_unmap_single(bp->bus_dev,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3417
3418
  				 bp->descr_block_virt->xmt_data[comp].long_1,
  				 p_xmt_drv_descr->p_skb->len,
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3419
  				 DMA_TO_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
  		dev_kfree_skb_irq(p_xmt_drv_descr->p_skb);
  
  		/*
  		 * Move to start of next packet by updating completion index
  		 *
  		 * Here we assume that a transmit packet request is always
  		 * serviced by posting one fragment.  We can therefore
  		 * simplify the completion code by incrementing the
  		 * completion index by one.  This code will need to be
  		 * modified if this assumption changes.  See comments
  		 * in dfx_xmt_queue_pkt for more details.
  		 */
  
  		bp->rcv_xmt_reg.index.xmt_comp += 1;
  		freed++;
  		}
  	return freed;
  	}
6aa20a223   Jeff Garzik   drivers/net: Trim...
3438

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3439
3440
3441
3442
  /*
   * =================
   * = dfx_rcv_flush =
   * =================
6aa20a223   Jeff Garzik   drivers/net: Trim...
3443
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3444
3445
   * Overview:
   *   Remove all skb's in the receive ring.
6aa20a223   Jeff Garzik   drivers/net: Trim...
3446
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3447
3448
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
3449
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   Free's all the dynamically allocated skb's that are
   *   currently attached to the device receive ring. This
   *   function is typically only used when the device is
   *   initialized or reinitialized.
   *
   * Return Codes:
   *   None
   *
   * Side Effects:
   *   None
   */
  #ifdef DYNAMIC_BUFFERS
  static void dfx_rcv_flush( DFX_board_t *bp )
  	{
  	int i, j;
  
  	for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
  		for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  		{
  			struct sk_buff *skb;
  			skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
  			if (skb)
  				dev_kfree_skb(skb);
  			bp->p_rcv_buff_va[i+j] = NULL;
  		}
  
  	}
  #else
  static inline void dfx_rcv_flush( DFX_board_t *bp )
  {
  }
  #endif /* DYNAMIC_BUFFERS */
  
  /*
   * =================
   * = dfx_xmt_flush =
   * =================
6aa20a223   Jeff Garzik   drivers/net: Trim...
3491
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3492
3493
3494
   * Overview:
   *   Processes all frames whether they've been transmitted
   *   or not.
6aa20a223   Jeff Garzik   drivers/net: Trim...
3495
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3496
3497
   * Returns:
   *   None
6aa20a223   Jeff Garzik   drivers/net: Trim...
3498
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
   * Arguments:
   *   bp - pointer to board information
   *
   * Functional Description:
   *   For all produced transmit descriptors that have not
   *   yet been completed, we'll free the skb we were holding
   *   onto using dev_kfree_skb and bump the appropriate
   *   counters.  Of course, it's possible that some of
   *   these transmit requests actually did go out, but we
   *   won't make that distinction here.  Finally, we'll
   *   update the consumer index to match the producer.
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   This routine does NOT update the Type 2 register.  It
   *   is assumed that this routine is being called during a
   *   transmit flush interrupt, or a shutdown or close routine.
   *
   * Side Effects:
   *   None
   */
  
  static void dfx_xmt_flush( DFX_board_t *bp )
  	{
  	u32			prod_cons;		/* rcv/xmt consumer block longword */
  	XMT_DRIVER_DESCR	*p_xmt_drv_descr;	/* ptr to transmit driver descriptor */
  	u8			comp;			/* local transmit completion index */
  
  	/* Flush all outstanding transmit frames */
  
  	while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
  		{
  		/* Get pointer to the transmit driver descriptor block information */
  
  		p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
  
  		/* Return skb to operating system */
  		comp = bp->rcv_xmt_reg.index.xmt_comp;
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3539
  		dma_unmap_single(bp->bus_dev,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3540
3541
  				 bp->descr_block_virt->xmt_data[comp].long_1,
  				 p_xmt_drv_descr->p_skb->len,
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3542
  				 DMA_TO_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
  		dev_kfree_skb(p_xmt_drv_descr->p_skb);
  
  		/* Increment transmit error counter */
  
  		bp->xmt_discards++;
  
  		/*
  		 * Move to start of next packet by updating completion index
  		 *
  		 * Here we assume that a transmit packet request is always
  		 * serviced by posting one fragment.  We can therefore
  		 * simplify the completion code by incrementing the
  		 * completion index by one.  This code will need to be
  		 * modified if this assumption changes.  See comments
  		 * in dfx_xmt_queue_pkt for more details.
  		 */
  
  		bp->rcv_xmt_reg.index.xmt_comp += 1;
  		}
  
  	/* Update the transmit consumer index in the consumer block */
  
  	prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
  	prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
  	bp->cons_block_virt->xmt_rcv_data = prod_cons;
  	}
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
  /*
   * ==================
   * = dfx_unregister =
   * ==================
   *
   * Overview:
   *   Shuts down an FDDI controller
   *
   * Returns:
   *   Condition code
   *
   * Arguments:
   *   bdev - pointer to device information
   *
   * Functional Description:
   *
   * Return Codes:
   *   None
   *
   * Assumptions:
   *   It compiles so it should work :-( (PCI cards do :-)
   *
   * Side Effects:
   *   Device structures for FDDI adapters (fddi0, fddi1, etc) are
   *   freed.
   */
  static void __devexit dfx_unregister(struct device *bdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3596
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3597
3598
3599
3600
3601
3602
3603
  	struct net_device *dev = dev_get_drvdata(bdev);
  	DFX_board_t *bp = netdev_priv(dev);
  	int dfx_bus_pci = DFX_BUS_PCI(bdev);
  	int dfx_bus_tc = DFX_BUS_TC(bdev);
  	int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  	resource_size_t bar_start = 0;		/* pointer to port */
  	resource_size_t bar_len = 0;		/* resource length */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3604
3605
3606
  	int		alloc_size;		/* total buffer size used */
  
  	unregister_netdev(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3607
3608
3609
3610
3611
3612
3613
3614
3615
  
  	alloc_size = sizeof(PI_DESCR_BLOCK) +
  		     PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  #ifndef DYNAMIC_BUFFERS
  		     (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  #endif
  		     sizeof(PI_CONSUMER_BLOCK) +
  		     (PI_ALIGN_K_DESC_BLK - 1);
  	if (bp->kmalloced)
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
  		dma_free_coherent(bdev, alloc_size,
  				  bp->kmalloced, bp->kmalloced_dma);
  
  	dfx_bus_uninit(dev);
  
  	dfx_get_bars(bdev, &bar_start, &bar_len);
  	if (dfx_use_mmio) {
  		iounmap(bp->base.mem);
  		release_mem_region(bar_start, bar_len);
  	} else
  		release_region(bar_start, bar_len);
  
  	if (dfx_bus_pci)
  		pci_disable_device(to_pci_dev(bdev));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3630
3631
  	free_netdev(dev);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3632

fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
3633
3634
  static int __devinit __maybe_unused dfx_dev_register(struct device *);
  static int __devexit __maybe_unused dfx_dev_unregister(struct device *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3635

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3636
3637
3638
3639
  #ifdef CONFIG_PCI
  static int __devinit dfx_pci_register(struct pci_dev *,
  				      const struct pci_device_id *);
  static void __devexit dfx_pci_unregister(struct pci_dev *);
a3aa18842   Alexey Dobriyan   drivers/net/: use...
3640
  static DEFINE_PCI_DEVICE_TABLE(dfx_pci_table) = {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3641
3642
  	{ PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI) },
  	{ }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3643
  };
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3644
  MODULE_DEVICE_TABLE(pci, dfx_pci_table);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3645

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3646
  static struct pci_driver dfx_pci_driver = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3647
  	.name		= "defxx",
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3648
3649
3650
  	.id_table	= dfx_pci_table,
  	.probe		= dfx_pci_register,
  	.remove		= __devexit_p(dfx_pci_unregister),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3651
  };
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3652
3653
3654
3655
3656
  static __devinit int dfx_pci_register(struct pci_dev *pdev,
  				      const struct pci_device_id *ent)
  {
  	return dfx_register(&pdev->dev);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3657

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3658
  static void __devexit dfx_pci_unregister(struct pci_dev *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3659
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
  	dfx_unregister(&pdev->dev);
  }
  #endif /* CONFIG_PCI */
  
  #ifdef CONFIG_EISA
  static struct eisa_device_id dfx_eisa_table[] = {
          { "DEC3001", DEFEA_PROD_ID_1 },
          { "DEC3002", DEFEA_PROD_ID_2 },
          { "DEC3003", DEFEA_PROD_ID_3 },
          { "DEC3004", DEFEA_PROD_ID_4 },
          { }
  };
  MODULE_DEVICE_TABLE(eisa, dfx_eisa_table);
  
  static struct eisa_driver dfx_eisa_driver = {
  	.id_table	= dfx_eisa_table,
  	.driver		= {
  		.name	= "defxx",
  		.bus	= &eisa_bus_type,
  		.probe	= dfx_dev_register,
  		.remove	= __devexit_p(dfx_dev_unregister),
  	},
  };
  #endif /* CONFIG_EISA */
  
  #ifdef CONFIG_TC
  static struct tc_device_id const dfx_tc_table[] = {
  	{ "DEC     ", "PMAF-FA " },
  	{ "DEC     ", "PMAF-FD " },
  	{ "DEC     ", "PMAF-FS " },
  	{ "DEC     ", "PMAF-FU " },
  	{ }
  };
  MODULE_DEVICE_TABLE(tc, dfx_tc_table);
  
  static struct tc_driver dfx_tc_driver = {
  	.id_table	= dfx_tc_table,
  	.driver		= {
  		.name	= "defxx",
  		.bus	= &tc_bus_type,
  		.probe	= dfx_dev_register,
  		.remove	= __devexit_p(dfx_dev_unregister),
  	},
  };
  #endif /* CONFIG_TC */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3705

fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
3706
  static int __devinit __maybe_unused dfx_dev_register(struct device *dev)
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3707
3708
  {
  	int status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3709

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3710
3711
3712
3713
  	status = dfx_register(dev);
  	if (!status)
  		get_device(dev);
  	return status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3714
  }
fcdff1390   Maciej W. Rozycki   defxx: Use __mayb...
3715
  static int __devexit __maybe_unused dfx_dev_unregister(struct device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3716
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3717
3718
3719
3720
  	put_device(dev);
  	dfx_unregister(dev);
  	return 0;
  }
6aa20a223   Jeff Garzik   drivers/net: Trim...
3721

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3722

e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
  static int __devinit dfx_init(void)
  {
  	int status;
  
  	status = pci_register_driver(&dfx_pci_driver);
  	if (!status)
  		status = eisa_driver_register(&dfx_eisa_driver);
  	if (!status)
  		status = tc_register_driver(&dfx_tc_driver);
  	return status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3733
  }
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3734
  static void __devexit dfx_cleanup(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3735
  {
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3736
3737
3738
  	tc_unregister_driver(&dfx_tc_driver);
  	eisa_driver_unregister(&dfx_eisa_driver);
  	pci_unregister_driver(&dfx_pci_driver);
6aa20a223   Jeff Garzik   drivers/net: Trim...
3739
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3740
3741
3742
3743
  
  module_init(dfx_init);
  module_exit(dfx_cleanup);
  MODULE_AUTHOR("Lawrence V. Stefani");
e89a2cfb7   Maciej W. Rozycki   [TC] defxx: TURBO...
3744
  MODULE_DESCRIPTION("DEC FDDIcontroller TC/EISA/PCI (DEFTA/DEFEA/DEFPA) driver "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3745
3746
  		   DRV_VERSION " " DRV_RELDATE);
  MODULE_LICENSE("GPL");