blob: eb768fcb3cc8fcbf1d632b1decfc49720bde960b [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11/* Common definitions for all Efx net driver code */
12
13#ifndef EFX_NET_DRIVER_H
14#define EFX_NET_DRIVER_H
15
16#include <linux/version.h>
17#include <linux/netdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/ethtool.h>
20#include <linux/if_vlan.h>
21#include <linux/timer.h>
22#include <linux/mii.h>
23#include <linux/list.h>
24#include <linux/pci.h>
25#include <linux/device.h>
26#include <linux/highmem.h>
27#include <linux/workqueue.h>
Ben Hutchings37b5a602008-05-30 22:27:04 +010028#include <linux/i2c.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010029
30#include "enum.h"
31#include "bitfield.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010032
Ben Hutchings8ceee662008-04-27 12:55:59 +010033/**************************************************************************
34 *
35 * Build definitions
36 *
37 **************************************************************************/
38#ifndef EFX_DRIVER_NAME
39#define EFX_DRIVER_NAME "sfc"
40#endif
Ben Hutchingsa7a81fc2008-12-12 22:10:23 -080041#define EFX_DRIVER_VERSION "2.3"
Ben Hutchings8ceee662008-04-27 12:55:59 +010042
43#ifdef EFX_ENABLE_DEBUG
44#define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
45#define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
46#else
47#define EFX_BUG_ON_PARANOID(x) do {} while (0)
48#define EFX_WARN_ON_PARANOID(x) do {} while (0)
49#endif
50
Ben Hutchings8ceee662008-04-27 12:55:59 +010051/* Un-rate-limited logging */
52#define EFX_ERR(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010053dev_err(&((efx)->pci_dev->dev), "ERR: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010054
55#define EFX_INFO(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010056dev_info(&((efx)->pci_dev->dev), "INFO: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010057
58#ifdef EFX_ENABLE_DEBUG
59#define EFX_LOG(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010060dev_info(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010061#else
62#define EFX_LOG(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010063dev_dbg(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010064#endif
65
66#define EFX_TRACE(efx, fmt, args...) do {} while (0)
67
68#define EFX_REGDUMP(efx, fmt, args...) do {} while (0)
69
70/* Rate-limited logging */
71#define EFX_ERR_RL(efx, fmt, args...) \
72do {if (net_ratelimit()) EFX_ERR(efx, fmt, ##args); } while (0)
73
74#define EFX_INFO_RL(efx, fmt, args...) \
75do {if (net_ratelimit()) EFX_INFO(efx, fmt, ##args); } while (0)
76
77#define EFX_LOG_RL(efx, fmt, args...) \
78do {if (net_ratelimit()) EFX_LOG(efx, fmt, ##args); } while (0)
79
Ben Hutchings8ceee662008-04-27 12:55:59 +010080/**************************************************************************
81 *
82 * Efx data structures
83 *
84 **************************************************************************/
85
86#define EFX_MAX_CHANNELS 32
Ben Hutchings8ceee662008-04-27 12:55:59 +010087#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
88
Ben Hutchings60ac1062008-09-01 12:44:59 +010089#define EFX_TX_QUEUE_OFFLOAD_CSUM 0
90#define EFX_TX_QUEUE_NO_CSUM 1
91#define EFX_TX_QUEUE_COUNT 2
92
Ben Hutchings8ceee662008-04-27 12:55:59 +010093/**
94 * struct efx_special_buffer - An Efx special buffer
95 * @addr: CPU base address of the buffer
96 * @dma_addr: DMA base address of the buffer
97 * @len: Buffer length, in bytes
98 * @index: Buffer index within controller;s buffer table
99 * @entries: Number of buffer table entries
100 *
101 * Special buffers are used for the event queues and the TX and RX
102 * descriptor queues for each channel. They are *not* used for the
103 * actual transmit and receive buffers.
104 *
105 * Note that for Falcon, TX and RX descriptor queues live in host memory.
106 * Allocation and freeing procedures must take this into account.
107 */
108struct efx_special_buffer {
109 void *addr;
110 dma_addr_t dma_addr;
111 unsigned int len;
112 int index;
113 int entries;
114};
115
116/**
117 * struct efx_tx_buffer - An Efx TX buffer
118 * @skb: The associated socket buffer.
119 * Set only on the final fragment of a packet; %NULL for all other
120 * fragments. When this fragment completes, then we can free this
121 * skb.
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100122 * @tsoh: The associated TSO header structure, or %NULL if this
123 * buffer is not a TSO header.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100124 * @dma_addr: DMA address of the fragment.
125 * @len: Length of this fragment.
126 * This field is zero when the queue slot is empty.
127 * @continuation: True if this fragment is not the end of a packet.
128 * @unmap_single: True if pci_unmap_single should be used.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100129 * @unmap_len: Length of this fragment to unmap
130 */
131struct efx_tx_buffer {
132 const struct sk_buff *skb;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100133 struct efx_tso_header *tsoh;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100134 dma_addr_t dma_addr;
135 unsigned short len;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100136 bool continuation;
137 bool unmap_single;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138 unsigned short unmap_len;
139};
140
141/**
142 * struct efx_tx_queue - An Efx TX queue
143 *
144 * This is a ring buffer of TX fragments.
145 * Since the TX completion path always executes on the same
146 * CPU and the xmit path can operate on different CPUs,
147 * performance is increased by ensuring that the completion
148 * path and the xmit path operate on different cache lines.
149 * This is particularly important if the xmit path is always
150 * executing on one CPU which is different from the completion
151 * path. There is also a cache line for members which are
152 * read but not written on the fast path.
153 *
154 * @efx: The associated Efx NIC
155 * @queue: DMA queue number
Ben Hutchings8ceee662008-04-27 12:55:59 +0100156 * @channel: The associated channel
157 * @buffer: The software buffer ring
158 * @txd: The hardware descriptor ring
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100159 * @flushed: Used when handling queue flushing
Ben Hutchings8ceee662008-04-27 12:55:59 +0100160 * @read_count: Current read pointer.
161 * This is the number of buffers that have been removed from both rings.
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100162 * @stopped: Stopped count.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100163 * Set if this TX queue is currently stopping its port.
164 * @insert_count: Current insert pointer
165 * This is the number of buffers that have been added to the
166 * software ring.
167 * @write_count: Current write pointer
168 * This is the number of buffers that have been added to the
169 * hardware ring.
170 * @old_read_count: The value of read_count when last checked.
171 * This is here for performance reasons. The xmit path will
172 * only get the up-to-date value of read_count if this
173 * variable indicates that the queue is full. This is to
174 * avoid cache-line ping-pong between the xmit path and the
175 * completion path.
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100176 * @tso_headers_free: A list of TSO headers allocated for this TX queue
177 * that are not in use, and so available for new TSO sends. The list
178 * is protected by the TX queue lock.
179 * @tso_bursts: Number of times TSO xmit invoked by kernel
180 * @tso_long_headers: Number of packets with headers too long for standard
181 * blocks
182 * @tso_packets: Number of packets via the TSO xmit path
Ben Hutchings8ceee662008-04-27 12:55:59 +0100183 */
184struct efx_tx_queue {
185 /* Members which don't change on the fast path */
186 struct efx_nic *efx ____cacheline_aligned_in_smp;
187 int queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100188 struct efx_channel *channel;
189 struct efx_nic *nic;
190 struct efx_tx_buffer *buffer;
191 struct efx_special_buffer txd;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100192 bool flushed;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100193
194 /* Members used mainly on the completion path */
195 unsigned int read_count ____cacheline_aligned_in_smp;
196 int stopped;
197
198 /* Members used only on the xmit path */
199 unsigned int insert_count ____cacheline_aligned_in_smp;
200 unsigned int write_count;
201 unsigned int old_read_count;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100202 struct efx_tso_header *tso_headers_free;
203 unsigned int tso_bursts;
204 unsigned int tso_long_headers;
205 unsigned int tso_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100206};
207
208/**
209 * struct efx_rx_buffer - An Efx RX data buffer
210 * @dma_addr: DMA base address of the buffer
211 * @skb: The associated socket buffer, if any.
212 * If both this and page are %NULL, the buffer slot is currently free.
213 * @page: The associated page buffer, if any.
214 * If both this and skb are %NULL, the buffer slot is currently free.
215 * @data: Pointer to ethernet header
216 * @len: Buffer length, in bytes.
217 * @unmap_addr: DMA address to unmap
218 */
219struct efx_rx_buffer {
220 dma_addr_t dma_addr;
221 struct sk_buff *skb;
222 struct page *page;
223 char *data;
224 unsigned int len;
225 dma_addr_t unmap_addr;
226};
227
228/**
229 * struct efx_rx_queue - An Efx RX queue
230 * @efx: The associated Efx NIC
231 * @queue: DMA queue number
Ben Hutchings8ceee662008-04-27 12:55:59 +0100232 * @channel: The associated channel
233 * @buffer: The software buffer ring
234 * @rxd: The hardware descriptor ring
235 * @added_count: Number of buffers added to the receive queue.
236 * @notified_count: Number of buffers given to NIC (<= @added_count).
237 * @removed_count: Number of buffers removed from the receive queue.
238 * @add_lock: Receive queue descriptor add spin lock.
239 * This lock must be held in order to add buffers to the RX
240 * descriptor ring (rxd and buffer) and to update added_count (but
241 * not removed_count).
242 * @max_fill: RX descriptor maximum fill level (<= ring size)
243 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
244 * (<= @max_fill)
245 * @fast_fill_limit: The level to which a fast fill will fill
246 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
247 * @min_fill: RX descriptor minimum non-zero fill level.
248 * This records the minimum fill level observed when a ring
249 * refill was triggered.
250 * @min_overfill: RX descriptor minimum overflow fill level.
251 * This records the minimum fill level at which RX queue
252 * overflow was observed. It should never be set.
253 * @alloc_page_count: RX allocation strategy counter.
254 * @alloc_skb_count: RX allocation strategy counter.
255 * @work: Descriptor push work thread
256 * @buf_page: Page for next RX buffer.
257 * We can use a single page for multiple RX buffers. This tracks
258 * the remaining space in the allocation.
259 * @buf_dma_addr: Page's DMA address.
260 * @buf_data: Page's host address.
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100261 * @flushed: Use when handling queue flushing
Ben Hutchings8ceee662008-04-27 12:55:59 +0100262 */
263struct efx_rx_queue {
264 struct efx_nic *efx;
265 int queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100266 struct efx_channel *channel;
267 struct efx_rx_buffer *buffer;
268 struct efx_special_buffer rxd;
269
270 int added_count;
271 int notified_count;
272 int removed_count;
273 spinlock_t add_lock;
274 unsigned int max_fill;
275 unsigned int fast_fill_trigger;
276 unsigned int fast_fill_limit;
277 unsigned int min_fill;
278 unsigned int min_overfill;
279 unsigned int alloc_page_count;
280 unsigned int alloc_skb_count;
281 struct delayed_work work;
282 unsigned int slow_fill_count;
283
284 struct page *buf_page;
285 dma_addr_t buf_dma_addr;
286 char *buf_data;
Ben Hutchings6bc5d3a2008-09-01 12:49:37 +0100287 bool flushed;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100288};
289
290/**
291 * struct efx_buffer - An Efx general-purpose buffer
292 * @addr: host base address of the buffer
293 * @dma_addr: DMA base address of the buffer
294 * @len: Buffer length, in bytes
295 *
296 * Falcon uses these buffers for its interrupt status registers and
297 * MAC stats dumps.
298 */
299struct efx_buffer {
300 void *addr;
301 dma_addr_t dma_addr;
302 unsigned int len;
303};
304
305
306/* Flags for channel->used_flags */
307#define EFX_USED_BY_RX 1
308#define EFX_USED_BY_TX 2
309#define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
310
311enum efx_rx_alloc_method {
312 RX_ALLOC_METHOD_AUTO = 0,
313 RX_ALLOC_METHOD_SKB = 1,
314 RX_ALLOC_METHOD_PAGE = 2,
315};
316
317/**
318 * struct efx_channel - An Efx channel
319 *
320 * A channel comprises an event queue, at least one TX queue, at least
321 * one RX queue, and an associated tasklet for processing the event
322 * queue.
323 *
324 * @efx: Associated Efx NIC
Ben Hutchings8ceee662008-04-27 12:55:59 +0100325 * @channel: Channel instance number
Ben Hutchings56536e92008-12-12 21:37:02 -0800326 * @name: Name for channel and IRQ
Ben Hutchings8ceee662008-04-27 12:55:59 +0100327 * @used_flags: Channel is used by net driver
328 * @enabled: Channel enabled indicator
329 * @irq: IRQ number (MSI and MSI-X only)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100330 * @irq_moderation: IRQ moderation value (in us)
331 * @napi_dev: Net device used with NAPI
332 * @napi_str: NAPI control structure
333 * @reset_work: Scheduled reset work thread
334 * @work_pending: Is work pending via NAPI?
335 * @eventq: Event queue buffer
336 * @eventq_read_ptr: Event queue read pointer
337 * @last_eventq_read_ptr: Last event queue read pointer value.
338 * @eventq_magic: Event queue magic value for driver-generated test events
Ben Hutchings8ceee662008-04-27 12:55:59 +0100339 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
340 * and diagnostic counters
341 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
342 * descriptors
Ben Hutchings8ceee662008-04-27 12:55:59 +0100343 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
344 * @n_rx_ip_frag_err: Count of RX IP fragment errors
345 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
346 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
347 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
348 * @n_rx_overlength: Count of RX_OVERLENGTH errors
349 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
350 */
351struct efx_channel {
352 struct efx_nic *efx;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100353 int channel;
Ben Hutchings56536e92008-12-12 21:37:02 -0800354 char name[IFNAMSIZ + 6];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100355 int used_flags;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100356 bool enabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100357 int irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100358 unsigned int irq_moderation;
359 struct net_device *napi_dev;
360 struct napi_struct napi_str;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100361 bool work_pending;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100362 struct efx_special_buffer eventq;
363 unsigned int eventq_read_ptr;
364 unsigned int last_eventq_read_ptr;
365 unsigned int eventq_magic;
366
Ben Hutchings8ceee662008-04-27 12:55:59 +0100367 int rx_alloc_level;
368 int rx_alloc_push_pages;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100369
370 unsigned n_rx_tobe_disc;
371 unsigned n_rx_ip_frag_err;
372 unsigned n_rx_ip_hdr_chksum_err;
373 unsigned n_rx_tcp_udp_chksum_err;
374 unsigned n_rx_frm_trunc;
375 unsigned n_rx_overlength;
376 unsigned n_skbuff_leaks;
377
378 /* Used to pipeline received packets in order to optimise memory
379 * access with prefetches.
380 */
381 struct efx_rx_buffer *rx_pkt;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100382 bool rx_pkt_csummed;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100383
384};
385
386/**
387 * struct efx_blinker - S/W LED blinking context
388 * @led_num: LED ID (board-specific meaning)
389 * @state: Current state - on or off
390 * @resubmit: Timer resubmission flag
391 * @timer: Control timer for blinking
392 */
393struct efx_blinker {
394 int led_num;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100395 bool state;
396 bool resubmit;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100397 struct timer_list timer;
398};
399
400
401/**
402 * struct efx_board - board information
403 * @type: Board model type
404 * @major: Major rev. ('A', 'B' ...)
405 * @minor: Minor rev. (0, 1, ...)
406 * @init: Initialisation function
407 * @init_leds: Sets up board LEDs
408 * @set_fault_led: Turns the fault LED on or off
409 * @blink: Starts/stops blinking
Ben Hutchings3e133c42008-11-04 20:34:56 +0000410 * @monitor: Board-specific health check function
Ben Hutchings37b5a602008-05-30 22:27:04 +0100411 * @fini: Cleanup function
Ben Hutchings8ceee662008-04-27 12:55:59 +0100412 * @blinker: used to blink LEDs in software
Ben Hutchings37b5a602008-05-30 22:27:04 +0100413 * @hwmon_client: I2C client for hardware monitor
414 * @ioexp_client: I2C client for power/port control
Ben Hutchings8ceee662008-04-27 12:55:59 +0100415 */
416struct efx_board {
417 int type;
418 int major;
419 int minor;
420 int (*init) (struct efx_nic *nic);
421 /* As the LEDs are typically attached to the PHY, LEDs
422 * have a separate init callback that happens later than
423 * board init. */
424 int (*init_leds)(struct efx_nic *efx);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000425 int (*monitor) (struct efx_nic *nic);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100426 void (*set_fault_led) (struct efx_nic *efx, bool state);
427 void (*blink) (struct efx_nic *efx, bool start);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100428 void (*fini) (struct efx_nic *nic);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100429 struct efx_blinker blinker;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100430 struct i2c_client *hwmon_client, *ioexp_client;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100431};
432
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100433#define STRING_TABLE_LOOKUP(val, member) \
434 member ## _names[val]
435
Ben Hutchings8ceee662008-04-27 12:55:59 +0100436enum efx_int_mode {
437 /* Be careful if altering to correct macro below */
438 EFX_INT_MODE_MSIX = 0,
439 EFX_INT_MODE_MSI = 1,
440 EFX_INT_MODE_LEGACY = 2,
441 EFX_INT_MODE_MAX /* Insert any new items before this */
442};
443#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
444
445enum phy_type {
446 PHY_TYPE_NONE = 0,
Ben Hutchingsab377352008-12-12 22:06:54 -0800447 PHY_TYPE_TXC43128 = 1,
448 PHY_TYPE_88E1111 = 2,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800449 PHY_TYPE_SFX7101 = 3,
Ben Hutchingsab377352008-12-12 22:06:54 -0800450 PHY_TYPE_QT2022C2 = 4,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100451 PHY_TYPE_PM8358 = 6,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800452 PHY_TYPE_SFT9001A = 8,
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000453 PHY_TYPE_QT2025C = 9,
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800454 PHY_TYPE_SFT9001B = 10,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100455 PHY_TYPE_MAX /* Insert any new items before this */
456};
457
458#define PHY_ADDR_INVALID 0xff
459
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800460#define EFX_IS10G(efx) ((efx)->link_speed == 10000)
461
Ben Hutchings8ceee662008-04-27 12:55:59 +0100462enum nic_state {
463 STATE_INIT = 0,
464 STATE_RUNNING = 1,
465 STATE_FINI = 2,
Ben Hutchings3c787082008-09-01 12:49:08 +0100466 STATE_DISABLED = 3,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100467 STATE_MAX,
468};
469
470/*
471 * Alignment of page-allocated RX buffers
472 *
473 * Controls the number of bytes inserted at the start of an RX buffer.
474 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
475 * of the skb->head for hardware DMA].
476 */
Ben Hutchings13e9ab12008-09-01 12:50:28 +0100477#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Ben Hutchings8ceee662008-04-27 12:55:59 +0100478#define EFX_PAGE_IP_ALIGN 0
479#else
480#define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
481#endif
482
483/*
484 * Alignment of the skb->head which wraps a page-allocated RX buffer
485 *
486 * The skb allocated to wrap an rx_buffer can have this alignment. Since
487 * the data is memcpy'd from the rx_buf, it does not need to be equal to
488 * EFX_PAGE_IP_ALIGN.
489 */
490#define EFX_PAGE_SKB_ALIGN 2
491
492/* Forward declaration */
493struct efx_nic;
494
495/* Pseudo bit-mask flow control field */
496enum efx_fc_type {
497 EFX_FC_RX = 1,
498 EFX_FC_TX = 2,
499 EFX_FC_AUTO = 4,
500};
501
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800502/* Supported MAC bit-mask */
503enum efx_mac_type {
504 EFX_GMAC = 1,
505 EFX_XMAC = 2,
506};
507
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800508static inline unsigned int efx_fc_advertise(enum efx_fc_type wanted_fc)
509{
510 unsigned int adv = 0;
511 if (wanted_fc & EFX_FC_RX)
512 adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
513 if (wanted_fc & EFX_FC_TX)
514 adv ^= ADVERTISE_PAUSE_ASYM;
515 return adv;
516}
517
518static inline enum efx_fc_type efx_fc_resolve(enum efx_fc_type wanted_fc,
519 unsigned int lpa)
520{
521 unsigned int adv = efx_fc_advertise(wanted_fc);
522
523 if (!(wanted_fc & EFX_FC_AUTO))
524 return wanted_fc;
525
526 if (adv & lpa & ADVERTISE_PAUSE_CAP)
527 return EFX_FC_RX | EFX_FC_TX;
528 if (adv & lpa & ADVERTISE_PAUSE_ASYM) {
529 if (adv & ADVERTISE_PAUSE_CAP)
530 return EFX_FC_RX;
531 if (lpa & ADVERTISE_PAUSE_CAP)
532 return EFX_FC_TX;
533 }
534 return 0;
535}
536
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800537/**
538 * struct efx_mac_operations - Efx MAC operations table
539 * @reconfigure: Reconfigure MAC. Serialised by the mac_lock
540 * @update_stats: Update statistics
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800541 * @irq: Hardware MAC event callback. Serialised by the mac_lock
542 * @poll: Poll for hardware state. Serialised by the mac_lock
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800543 */
544struct efx_mac_operations {
545 void (*reconfigure) (struct efx_nic *efx);
546 void (*update_stats) (struct efx_nic *efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800547 void (*irq) (struct efx_nic *efx);
548 void (*poll) (struct efx_nic *efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800549};
550
Ben Hutchings8ceee662008-04-27 12:55:59 +0100551/**
552 * struct efx_phy_operations - Efx PHY operations table
553 * @init: Initialise PHY
554 * @fini: Shut down PHY
555 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
556 * @clear_interrupt: Clear down interrupt
557 * @blink: Blink LEDs
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800558 * @poll: Poll for hardware state. Serialised by the mac_lock.
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800559 * @get_settings: Get ethtool settings. Serialised by the mac_lock.
560 * @set_settings: Set ethtool settings. Serialised by the mac_lock.
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000561 * @set_npage_adv: Set abilities advertised in (Extended) Next Page
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800562 * (only needed where AN bit is set in mmds)
Ben Hutchings17967212008-12-26 13:47:25 -0800563 * @num_tests: Number of PHY-specific tests/results
564 * @test_names: Names of the tests/results
565 * @run_tests: Run tests and record results as appropriate.
566 * Flags are the ethtool tests flags.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100567 * @mmds: MMD presence mask
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100568 * @loopbacks: Supported loopback modes mask
Ben Hutchings8ceee662008-04-27 12:55:59 +0100569 */
570struct efx_phy_operations {
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800571 enum efx_mac_type macs;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100572 int (*init) (struct efx_nic *efx);
573 void (*fini) (struct efx_nic *efx);
574 void (*reconfigure) (struct efx_nic *efx);
575 void (*clear_interrupt) (struct efx_nic *efx);
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800576 void (*poll) (struct efx_nic *efx);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800577 void (*get_settings) (struct efx_nic *efx,
578 struct ethtool_cmd *ecmd);
579 int (*set_settings) (struct efx_nic *efx,
580 struct ethtool_cmd *ecmd);
Ben Hutchingsaf4ad9b2009-01-29 17:59:37 +0000581 void (*set_npage_adv) (struct efx_nic *efx, u32);
Ben Hutchings17967212008-12-26 13:47:25 -0800582 u32 num_tests;
583 const char *const *test_names;
584 int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100585 int mmds;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100586 unsigned loopbacks;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100587};
588
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100589/**
590 * @enum efx_phy_mode - PHY operating mode flags
591 * @PHY_MODE_NORMAL: on and should pass traffic
592 * @PHY_MODE_TX_DISABLED: on with TX disabled
Ben Hutchings3e133c42008-11-04 20:34:56 +0000593 * @PHY_MODE_LOW_POWER: set to low power through MDIO
594 * @PHY_MODE_OFF: switched off through external control
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100595 * @PHY_MODE_SPECIAL: on but will not pass traffic
596 */
597enum efx_phy_mode {
598 PHY_MODE_NORMAL = 0,
599 PHY_MODE_TX_DISABLED = 1,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000600 PHY_MODE_LOW_POWER = 2,
601 PHY_MODE_OFF = 4,
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100602 PHY_MODE_SPECIAL = 8,
603};
604
605static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
606{
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100607 return !!(mode & ~PHY_MODE_TX_DISABLED);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100608}
609
Ben Hutchings8ceee662008-04-27 12:55:59 +0100610/*
611 * Efx extended statistics
612 *
613 * Not all statistics are provided by all supported MACs. The purpose
614 * is this structure is to contain the raw statistics provided by each
615 * MAC.
616 */
617struct efx_mac_stats {
618 u64 tx_bytes;
619 u64 tx_good_bytes;
620 u64 tx_bad_bytes;
621 unsigned long tx_packets;
622 unsigned long tx_bad;
623 unsigned long tx_pause;
624 unsigned long tx_control;
625 unsigned long tx_unicast;
626 unsigned long tx_multicast;
627 unsigned long tx_broadcast;
628 unsigned long tx_lt64;
629 unsigned long tx_64;
630 unsigned long tx_65_to_127;
631 unsigned long tx_128_to_255;
632 unsigned long tx_256_to_511;
633 unsigned long tx_512_to_1023;
634 unsigned long tx_1024_to_15xx;
635 unsigned long tx_15xx_to_jumbo;
636 unsigned long tx_gtjumbo;
637 unsigned long tx_collision;
638 unsigned long tx_single_collision;
639 unsigned long tx_multiple_collision;
640 unsigned long tx_excessive_collision;
641 unsigned long tx_deferred;
642 unsigned long tx_late_collision;
643 unsigned long tx_excessive_deferred;
644 unsigned long tx_non_tcpudp;
645 unsigned long tx_mac_src_error;
646 unsigned long tx_ip_src_error;
647 u64 rx_bytes;
648 u64 rx_good_bytes;
649 u64 rx_bad_bytes;
650 unsigned long rx_packets;
651 unsigned long rx_good;
652 unsigned long rx_bad;
653 unsigned long rx_pause;
654 unsigned long rx_control;
655 unsigned long rx_unicast;
656 unsigned long rx_multicast;
657 unsigned long rx_broadcast;
658 unsigned long rx_lt64;
659 unsigned long rx_64;
660 unsigned long rx_65_to_127;
661 unsigned long rx_128_to_255;
662 unsigned long rx_256_to_511;
663 unsigned long rx_512_to_1023;
664 unsigned long rx_1024_to_15xx;
665 unsigned long rx_15xx_to_jumbo;
666 unsigned long rx_gtjumbo;
667 unsigned long rx_bad_lt64;
668 unsigned long rx_bad_64_to_15xx;
669 unsigned long rx_bad_15xx_to_jumbo;
670 unsigned long rx_bad_gtjumbo;
671 unsigned long rx_overflow;
672 unsigned long rx_missed;
673 unsigned long rx_false_carrier;
674 unsigned long rx_symbol_error;
675 unsigned long rx_align_error;
676 unsigned long rx_length_error;
677 unsigned long rx_internal_error;
678 unsigned long rx_good_lt64;
679};
680
681/* Number of bits used in a multicast filter hash address */
682#define EFX_MCAST_HASH_BITS 8
683
684/* Number of (single-bit) entries in a multicast filter hash */
685#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
686
687/* An Efx multicast filter hash */
688union efx_multicast_hash {
689 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
690 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
691};
692
693/**
694 * struct efx_nic - an Efx NIC
695 * @name: Device name (net device name or bus id before net device registered)
696 * @pci_dev: The PCI device
697 * @type: Controller type attributes
698 * @legacy_irq: IRQ number
Ben Hutchings8d9853d2008-07-18 19:01:20 +0100699 * @workqueue: Workqueue for port reconfigures and the HW monitor.
700 * Work items do not hold and must not acquire RTNL.
Ben Hutchings6977dc62008-12-26 13:44:39 -0800701 * @workqueue_name: Name of workqueue
Ben Hutchings8ceee662008-04-27 12:55:59 +0100702 * @reset_work: Scheduled reset workitem
703 * @monitor_work: Hardware monitor workitem
704 * @membase_phys: Memory BAR value as physical address
705 * @membase: Memory BAR value
706 * @biu_lock: BIU (bus interface unit) lock
707 * @interrupt_mode: Interrupt mode
Ben Hutchings37b5a602008-05-30 22:27:04 +0100708 * @i2c_adap: I2C adapter
Ben Hutchings8ceee662008-04-27 12:55:59 +0100709 * @board_info: Board-level information
710 * @state: Device state flag. Serialised by the rtnl_lock.
711 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
712 * @tx_queue: TX DMA queues
713 * @rx_queue: RX DMA queues
714 * @channel: Channels
Ben Hutchings8831da72008-09-01 12:47:48 +0100715 * @n_rx_queues: Number of RX queues
Neil Turton28b581a2008-12-12 21:41:06 -0800716 * @n_channels: Number of channels in use
Ben Hutchings8ceee662008-04-27 12:55:59 +0100717 * @rx_buffer_len: RX buffer length
718 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
719 * @irq_status: Interrupt status buffer
720 * @last_irq_cpu: Last CPU to handle interrupt.
721 * This register is written with the SMP processor ID whenever an
722 * interrupt is handled. It is used by falcon_test_interrupt()
723 * to verify that an interrupt has occurred.
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100724 * @spi_flash: SPI flash device
725 * This field will be %NULL if no flash device is present.
726 * @spi_eeprom: SPI EEPROM device
727 * This field will be %NULL if no EEPROM device is present.
Ben Hutchingsf4150722008-11-04 20:34:28 +0000728 * @spi_lock: SPI bus lock
Ben Hutchings8ceee662008-04-27 12:55:59 +0100729 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
730 * @nic_data: Hardware dependant state
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100731 * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
732 * @port_inhibited, efx_monitor() and efx_reconfigure_port()
Ben Hutchings8ceee662008-04-27 12:55:59 +0100733 * @port_enabled: Port enabled indicator.
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800734 * Serialises efx_stop_all(), efx_start_all(), efx_monitor(),
735 * efx_phy_work(), and efx_mac_work() with kernel interfaces. Safe to read
736 * under any one of the rtnl_lock, mac_lock, or netif_tx_lock, but all
737 * three must be held to modify it.
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100738 * @port_inhibited: If set, the netif_carrier is always off. Hold the mac_lock
Ben Hutchings8ceee662008-04-27 12:55:59 +0100739 * @port_initialized: Port initialized?
740 * @net_dev: Operating system network device. Consider holding the rtnl lock
741 * @rx_checksum_enabled: RX checksumming enabled
742 * @netif_stop_count: Port stop count
743 * @netif_stop_lock: Port stop lock
744 * @mac_stats: MAC statistics. These include all statistics the MACs
745 * can provide. Generic code converts these into a standard
746 * &struct net_device_stats.
747 * @stats_buffer: DMA buffer for statistics
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100748 * @stats_lock: Statistics update lock. Serialises statistics fetches
Ben Hutchings1974cc22009-01-29 18:00:07 +0000749 * @stats_disable_count: Nest count for disabling statistics fetches
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800750 * @mac_op: MAC interface
Ben Hutchings8ceee662008-04-27 12:55:59 +0100751 * @mac_address: Permanent MAC address
752 * @phy_type: PHY type
753 * @phy_lock: PHY access lock
754 * @phy_op: PHY interface
755 * @phy_data: PHY private data (including PHY-specific stats)
756 * @mii: PHY interface
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100757 * @phy_mode: PHY operating mode. Serialised by @mac_lock.
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800758 * @mac_up: MAC link state
Ben Hutchings8ceee662008-04-27 12:55:59 +0100759 * @link_up: Link status
Ben Hutchingsf31a45d2008-12-12 21:43:33 -0800760 * @link_fd: Link is full duplex
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800761 * @link_fc: Actualy flow control flags
Ben Hutchingsf31a45d2008-12-12 21:43:33 -0800762 * @link_speed: Link speed (Mbps)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100763 * @n_link_state_changes: Number of times the link has changed state
764 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
765 * @multicast_hash: Multicast hash table
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800766 * @wanted_fc: Wanted flow control flags
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800767 * @phy_work: work item for dealing with PHY events
768 * @mac_work: work item for dealing with MAC events
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100769 * @loopback_mode: Loopback status
770 * @loopback_modes: Supported loopback mode bitmask
771 * @loopback_selftest: Offline self-test private state
Ben Hutchings8ceee662008-04-27 12:55:59 +0100772 *
773 * The @priv field of the corresponding &struct net_device points to
774 * this.
775 */
776struct efx_nic {
777 char name[IFNAMSIZ];
778 struct pci_dev *pci_dev;
779 const struct efx_nic_type *type;
780 int legacy_irq;
781 struct workqueue_struct *workqueue;
Ben Hutchings6977dc62008-12-26 13:44:39 -0800782 char workqueue_name[16];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100783 struct work_struct reset_work;
784 struct delayed_work monitor_work;
Ben Hutchings086ea352008-05-16 21:17:06 +0100785 resource_size_t membase_phys;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100786 void __iomem *membase;
787 spinlock_t biu_lock;
788 enum efx_int_mode interrupt_mode;
789
Ben Hutchings37b5a602008-05-30 22:27:04 +0100790 struct i2c_adapter i2c_adap;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100791 struct efx_board board_info;
792
793 enum nic_state state;
794 enum reset_type reset_pending;
795
Ben Hutchings60ac1062008-09-01 12:44:59 +0100796 struct efx_tx_queue tx_queue[EFX_TX_QUEUE_COUNT];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100797 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
798 struct efx_channel channel[EFX_MAX_CHANNELS];
799
Ben Hutchings8831da72008-09-01 12:47:48 +0100800 int n_rx_queues;
Neil Turton28b581a2008-12-12 21:41:06 -0800801 int n_channels;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100802 unsigned int rx_buffer_len;
803 unsigned int rx_buffer_order;
804
805 struct efx_buffer irq_status;
806 volatile signed int last_irq_cpu;
807
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100808 struct efx_spi_device *spi_flash;
809 struct efx_spi_device *spi_eeprom;
Ben Hutchingsf4150722008-11-04 20:34:28 +0000810 struct mutex spi_lock;
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100811
Ben Hutchings8ceee662008-04-27 12:55:59 +0100812 unsigned n_rx_nodesc_drop_cnt;
813
Ben Hutchings5daab962008-05-16 21:19:43 +0100814 struct falcon_nic_data *nic_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100815
816 struct mutex mac_lock;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800817 struct work_struct mac_work;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100818 bool port_enabled;
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100819 bool port_inhibited;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100820
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100821 bool port_initialized;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100822 struct net_device *net_dev;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100823 bool rx_checksum_enabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100824
825 atomic_t netif_stop_count;
826 spinlock_t netif_stop_lock;
827
828 struct efx_mac_stats mac_stats;
829 struct efx_buffer stats_buffer;
830 spinlock_t stats_lock;
Ben Hutchings1974cc22009-01-29 18:00:07 +0000831 unsigned int stats_disable_count;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100832
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800833 struct efx_mac_operations *mac_op;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100834 unsigned char mac_address[ETH_ALEN];
835
836 enum phy_type phy_type;
837 spinlock_t phy_lock;
Ben Hutchings766ca0f2008-12-12 21:59:24 -0800838 struct work_struct phy_work;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100839 struct efx_phy_operations *phy_op;
840 void *phy_data;
841 struct mii_if_info mii;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100842 enum efx_phy_mode phy_mode;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100843
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800844 bool mac_up;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100845 bool link_up;
Ben Hutchingsf31a45d2008-12-12 21:43:33 -0800846 bool link_fd;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800847 enum efx_fc_type link_fc;
Ben Hutchingsf31a45d2008-12-12 21:43:33 -0800848 unsigned int link_speed;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100849 unsigned int n_link_state_changes;
850
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100851 bool promiscuous;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100852 union efx_multicast_hash multicast_hash;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800853 enum efx_fc_type wanted_fc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100854
855 atomic_t rx_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100856 enum efx_loopback_mode loopback_mode;
857 unsigned int loopback_modes;
858
859 void *loopback_selftest;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100860};
861
Ben Hutchings55668612008-05-16 21:16:10 +0100862static inline int efx_dev_registered(struct efx_nic *efx)
863{
864 return efx->net_dev->reg_state == NETREG_REGISTERED;
865}
866
867/* Net device name, for inclusion in log messages if it has been registered.
868 * Use efx->name not efx->net_dev->name so that races with (un)registration
869 * are harmless.
870 */
871static inline const char *efx_dev_name(struct efx_nic *efx)
872{
873 return efx_dev_registered(efx) ? efx->name : "";
874}
875
Ben Hutchings8ceee662008-04-27 12:55:59 +0100876/**
877 * struct efx_nic_type - Efx device type definition
878 * @mem_bar: Memory BAR number
879 * @mem_map_size: Memory BAR mapped size
880 * @txd_ptr_tbl_base: TX descriptor ring base address
881 * @rxd_ptr_tbl_base: RX descriptor ring base address
882 * @buf_tbl_base: Buffer table base address
883 * @evq_ptr_tbl_base: Event queue pointer table base address
884 * @evq_rptr_tbl_base: Event queue read-pointer table base address
885 * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
886 * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
887 * @evq_size: Event queue size (must be a power of two)
888 * @max_dma_mask: Maximum possible DMA mask
889 * @tx_dma_mask: TX DMA mask
890 * @bug5391_mask: Address mask for bug 5391 workaround
891 * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
892 * @rx_xon_thresh: RX FIFO XON watermark (bytes)
893 * @rx_buffer_padding: Padding added to each RX buffer
894 * @max_interrupt_mode: Highest capability interrupt mode supported
895 * from &enum efx_init_mode.
896 * @phys_addr_channels: Number of channels with physically addressed
897 * descriptors
898 */
899struct efx_nic_type {
900 unsigned int mem_bar;
901 unsigned int mem_map_size;
902 unsigned int txd_ptr_tbl_base;
903 unsigned int rxd_ptr_tbl_base;
904 unsigned int buf_tbl_base;
905 unsigned int evq_ptr_tbl_base;
906 unsigned int evq_rptr_tbl_base;
907
908 unsigned int txd_ring_mask;
909 unsigned int rxd_ring_mask;
910 unsigned int evq_size;
Ben Hutchings9bbd7d92008-05-16 21:18:48 +0100911 u64 max_dma_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100912 unsigned int tx_dma_mask;
913 unsigned bug5391_mask;
914
915 int rx_xoff_thresh;
916 int rx_xon_thresh;
917 unsigned int rx_buffer_padding;
918 unsigned int max_interrupt_mode;
919 unsigned int phys_addr_channels;
920};
921
922/**************************************************************************
923 *
924 * Prototypes and inline functions
925 *
926 *************************************************************************/
927
928/* Iterate over all used channels */
929#define efx_for_each_channel(_channel, _efx) \
930 for (_channel = &_efx->channel[0]; \
931 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
932 _channel++) \
933 if (!_channel->used_flags) \
934 continue; \
935 else
936
Ben Hutchings8ceee662008-04-27 12:55:59 +0100937/* Iterate over all used TX queues */
938#define efx_for_each_tx_queue(_tx_queue, _efx) \
939 for (_tx_queue = &_efx->tx_queue[0]; \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100940 _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
941 _tx_queue++)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100942
943/* Iterate over all TX queues belonging to a channel */
944#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
945 for (_tx_queue = &_channel->efx->tx_queue[0]; \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100946 _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100947 _tx_queue++) \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100948 if (_tx_queue->channel != _channel) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100949 continue; \
950 else
951
952/* Iterate over all used RX queues */
953#define efx_for_each_rx_queue(_rx_queue, _efx) \
954 for (_rx_queue = &_efx->rx_queue[0]; \
Ben Hutchings8831da72008-09-01 12:47:48 +0100955 _rx_queue < &_efx->rx_queue[_efx->n_rx_queues]; \
956 _rx_queue++)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100957
958/* Iterate over all RX queues belonging to a channel */
959#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
Ben Hutchingsa2589022008-09-01 12:47:57 +0100960 for (_rx_queue = &_channel->efx->rx_queue[_channel->channel]; \
961 _rx_queue; \
962 _rx_queue = NULL) \
Ben Hutchings8831da72008-09-01 12:47:48 +0100963 if (_rx_queue->channel != _channel) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100964 continue; \
965 else
966
967/* Returns a pointer to the specified receive buffer in the RX
968 * descriptor queue.
969 */
970static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
971 unsigned int index)
972{
973 return (&rx_queue->buffer[index]);
974}
975
976/* Set bit in a little-endian bitfield */
Ben Hutchings18c2fc02008-09-01 12:43:39 +0100977static inline void set_bit_le(unsigned nr, unsigned char *addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100978{
979 addr[nr / 8] |= (1 << (nr % 8));
980}
981
982/* Clear bit in a little-endian bitfield */
Ben Hutchings18c2fc02008-09-01 12:43:39 +0100983static inline void clear_bit_le(unsigned nr, unsigned char *addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100984{
985 addr[nr / 8] &= ~(1 << (nr % 8));
986}
987
988
989/**
990 * EFX_MAX_FRAME_LEN - calculate maximum frame length
991 *
992 * This calculates the maximum frame length that will be used for a
993 * given MTU. The frame length will be equal to the MTU plus a
994 * constant amount of header space and padding. This is the quantity
995 * that the net driver will program into the MAC as the maximum frame
996 * length.
997 *
998 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
999 * length, so we round up to the nearest 8.
1000 */
1001#define EFX_MAX_FRAME_LEN(mtu) \
1002 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
1003
1004
1005#endif /* EFX_NET_DRIVER_H */