blob: 390275710ef4da712308e662725cec11614b8289 [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>
28#include <linux/inet_lro.h>
Ben Hutchings37b5a602008-05-30 22:27:04 +010029#include <linux/i2c.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010030
31#include "enum.h"
32#include "bitfield.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010033
34#define EFX_MAX_LRO_DESCRIPTORS 8
35#define EFX_MAX_LRO_AGGR MAX_SKB_FRAGS
36
37/**************************************************************************
38 *
39 * Build definitions
40 *
41 **************************************************************************/
42#ifndef EFX_DRIVER_NAME
43#define EFX_DRIVER_NAME "sfc"
44#endif
Ben Hutchings8757a5f2008-05-16 21:21:06 +010045#define EFX_DRIVER_VERSION "2.2"
Ben Hutchings8ceee662008-04-27 12:55:59 +010046
47#ifdef EFX_ENABLE_DEBUG
48#define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
49#define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
50#else
51#define EFX_BUG_ON_PARANOID(x) do {} while (0)
52#define EFX_WARN_ON_PARANOID(x) do {} while (0)
53#endif
54
Ben Hutchings8ceee662008-04-27 12:55:59 +010055/* Un-rate-limited logging */
56#define EFX_ERR(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010057dev_err(&((efx)->pci_dev->dev), "ERR: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010058
59#define EFX_INFO(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010060dev_info(&((efx)->pci_dev->dev), "INFO: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010061
62#ifdef EFX_ENABLE_DEBUG
63#define EFX_LOG(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010064dev_info(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010065#else
66#define EFX_LOG(efx, fmt, args...) \
Ben Hutchings55668612008-05-16 21:16:10 +010067dev_dbg(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
Ben Hutchings8ceee662008-04-27 12:55:59 +010068#endif
69
70#define EFX_TRACE(efx, fmt, args...) do {} while (0)
71
72#define EFX_REGDUMP(efx, fmt, args...) do {} while (0)
73
74/* Rate-limited logging */
75#define EFX_ERR_RL(efx, fmt, args...) \
76do {if (net_ratelimit()) EFX_ERR(efx, fmt, ##args); } while (0)
77
78#define EFX_INFO_RL(efx, fmt, args...) \
79do {if (net_ratelimit()) EFX_INFO(efx, fmt, ##args); } while (0)
80
81#define EFX_LOG_RL(efx, fmt, args...) \
82do {if (net_ratelimit()) EFX_LOG(efx, fmt, ##args); } while (0)
83
Ben Hutchings8ceee662008-04-27 12:55:59 +010084/**************************************************************************
85 *
86 * Efx data structures
87 *
88 **************************************************************************/
89
90#define EFX_MAX_CHANNELS 32
Ben Hutchings8ceee662008-04-27 12:55:59 +010091#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
92
Ben Hutchings60ac1062008-09-01 12:44:59 +010093#define EFX_TX_QUEUE_OFFLOAD_CSUM 0
94#define EFX_TX_QUEUE_NO_CSUM 1
95#define EFX_TX_QUEUE_COUNT 2
96
Ben Hutchings8ceee662008-04-27 12:55:59 +010097/**
98 * struct efx_special_buffer - An Efx special buffer
99 * @addr: CPU base address of the buffer
100 * @dma_addr: DMA base address of the buffer
101 * @len: Buffer length, in bytes
102 * @index: Buffer index within controller;s buffer table
103 * @entries: Number of buffer table entries
104 *
105 * Special buffers are used for the event queues and the TX and RX
106 * descriptor queues for each channel. They are *not* used for the
107 * actual transmit and receive buffers.
108 *
109 * Note that for Falcon, TX and RX descriptor queues live in host memory.
110 * Allocation and freeing procedures must take this into account.
111 */
112struct efx_special_buffer {
113 void *addr;
114 dma_addr_t dma_addr;
115 unsigned int len;
116 int index;
117 int entries;
118};
119
120/**
121 * struct efx_tx_buffer - An Efx TX buffer
122 * @skb: The associated socket buffer.
123 * Set only on the final fragment of a packet; %NULL for all other
124 * fragments. When this fragment completes, then we can free this
125 * skb.
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100126 * @tsoh: The associated TSO header structure, or %NULL if this
127 * buffer is not a TSO header.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100128 * @dma_addr: DMA address of the fragment.
129 * @len: Length of this fragment.
130 * This field is zero when the queue slot is empty.
131 * @continuation: True if this fragment is not the end of a packet.
132 * @unmap_single: True if pci_unmap_single should be used.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100133 * @unmap_len: Length of this fragment to unmap
134 */
135struct efx_tx_buffer {
136 const struct sk_buff *skb;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100137 struct efx_tso_header *tsoh;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138 dma_addr_t dma_addr;
139 unsigned short len;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100140 bool continuation;
141 bool unmap_single;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100142 unsigned short unmap_len;
143};
144
145/**
146 * struct efx_tx_queue - An Efx TX queue
147 *
148 * This is a ring buffer of TX fragments.
149 * Since the TX completion path always executes on the same
150 * CPU and the xmit path can operate on different CPUs,
151 * performance is increased by ensuring that the completion
152 * path and the xmit path operate on different cache lines.
153 * This is particularly important if the xmit path is always
154 * executing on one CPU which is different from the completion
155 * path. There is also a cache line for members which are
156 * read but not written on the fast path.
157 *
158 * @efx: The associated Efx NIC
159 * @queue: DMA queue number
Ben Hutchings8ceee662008-04-27 12:55:59 +0100160 * @channel: The associated channel
161 * @buffer: The software buffer ring
162 * @txd: The hardware descriptor ring
163 * @read_count: Current read pointer.
164 * This is the number of buffers that have been removed from both rings.
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100165 * @stopped: Stopped count.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100166 * Set if this TX queue is currently stopping its port.
167 * @insert_count: Current insert pointer
168 * This is the number of buffers that have been added to the
169 * software ring.
170 * @write_count: Current write pointer
171 * This is the number of buffers that have been added to the
172 * hardware ring.
173 * @old_read_count: The value of read_count when last checked.
174 * This is here for performance reasons. The xmit path will
175 * only get the up-to-date value of read_count if this
176 * variable indicates that the queue is full. This is to
177 * avoid cache-line ping-pong between the xmit path and the
178 * completion path.
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100179 * @tso_headers_free: A list of TSO headers allocated for this TX queue
180 * that are not in use, and so available for new TSO sends. The list
181 * is protected by the TX queue lock.
182 * @tso_bursts: Number of times TSO xmit invoked by kernel
183 * @tso_long_headers: Number of packets with headers too long for standard
184 * blocks
185 * @tso_packets: Number of packets via the TSO xmit path
Ben Hutchings8ceee662008-04-27 12:55:59 +0100186 */
187struct efx_tx_queue {
188 /* Members which don't change on the fast path */
189 struct efx_nic *efx ____cacheline_aligned_in_smp;
190 int queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100191 struct efx_channel *channel;
192 struct efx_nic *nic;
193 struct efx_tx_buffer *buffer;
194 struct efx_special_buffer txd;
195
196 /* Members used mainly on the completion path */
197 unsigned int read_count ____cacheline_aligned_in_smp;
198 int stopped;
199
200 /* Members used only on the xmit path */
201 unsigned int insert_count ____cacheline_aligned_in_smp;
202 unsigned int write_count;
203 unsigned int old_read_count;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100204 struct efx_tso_header *tso_headers_free;
205 unsigned int tso_bursts;
206 unsigned int tso_long_headers;
207 unsigned int tso_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100208};
209
210/**
211 * struct efx_rx_buffer - An Efx RX data buffer
212 * @dma_addr: DMA base address of the buffer
213 * @skb: The associated socket buffer, if any.
214 * If both this and page are %NULL, the buffer slot is currently free.
215 * @page: The associated page buffer, if any.
216 * If both this and skb are %NULL, the buffer slot is currently free.
217 * @data: Pointer to ethernet header
218 * @len: Buffer length, in bytes.
219 * @unmap_addr: DMA address to unmap
220 */
221struct efx_rx_buffer {
222 dma_addr_t dma_addr;
223 struct sk_buff *skb;
224 struct page *page;
225 char *data;
226 unsigned int len;
227 dma_addr_t unmap_addr;
228};
229
230/**
231 * struct efx_rx_queue - An Efx RX queue
232 * @efx: The associated Efx NIC
233 * @queue: DMA queue number
234 * @used: Queue is used by net driver
235 * @channel: The associated channel
236 * @buffer: The software buffer ring
237 * @rxd: The hardware descriptor ring
238 * @added_count: Number of buffers added to the receive queue.
239 * @notified_count: Number of buffers given to NIC (<= @added_count).
240 * @removed_count: Number of buffers removed from the receive queue.
241 * @add_lock: Receive queue descriptor add spin lock.
242 * This lock must be held in order to add buffers to the RX
243 * descriptor ring (rxd and buffer) and to update added_count (but
244 * not removed_count).
245 * @max_fill: RX descriptor maximum fill level (<= ring size)
246 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
247 * (<= @max_fill)
248 * @fast_fill_limit: The level to which a fast fill will fill
249 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
250 * @min_fill: RX descriptor minimum non-zero fill level.
251 * This records the minimum fill level observed when a ring
252 * refill was triggered.
253 * @min_overfill: RX descriptor minimum overflow fill level.
254 * This records the minimum fill level at which RX queue
255 * overflow was observed. It should never be set.
256 * @alloc_page_count: RX allocation strategy counter.
257 * @alloc_skb_count: RX allocation strategy counter.
258 * @work: Descriptor push work thread
259 * @buf_page: Page for next RX buffer.
260 * We can use a single page for multiple RX buffers. This tracks
261 * the remaining space in the allocation.
262 * @buf_dma_addr: Page's DMA address.
263 * @buf_data: Page's host address.
264 */
265struct efx_rx_queue {
266 struct efx_nic *efx;
267 int queue;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100268 bool used;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100269 struct efx_channel *channel;
270 struct efx_rx_buffer *buffer;
271 struct efx_special_buffer rxd;
272
273 int added_count;
274 int notified_count;
275 int removed_count;
276 spinlock_t add_lock;
277 unsigned int max_fill;
278 unsigned int fast_fill_trigger;
279 unsigned int fast_fill_limit;
280 unsigned int min_fill;
281 unsigned int min_overfill;
282 unsigned int alloc_page_count;
283 unsigned int alloc_skb_count;
284 struct delayed_work work;
285 unsigned int slow_fill_count;
286
287 struct page *buf_page;
288 dma_addr_t buf_dma_addr;
289 char *buf_data;
290};
291
292/**
293 * struct efx_buffer - An Efx general-purpose buffer
294 * @addr: host base address of the buffer
295 * @dma_addr: DMA base address of the buffer
296 * @len: Buffer length, in bytes
297 *
298 * Falcon uses these buffers for its interrupt status registers and
299 * MAC stats dumps.
300 */
301struct efx_buffer {
302 void *addr;
303 dma_addr_t dma_addr;
304 unsigned int len;
305};
306
307
308/* Flags for channel->used_flags */
309#define EFX_USED_BY_RX 1
310#define EFX_USED_BY_TX 2
311#define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
312
313enum efx_rx_alloc_method {
314 RX_ALLOC_METHOD_AUTO = 0,
315 RX_ALLOC_METHOD_SKB = 1,
316 RX_ALLOC_METHOD_PAGE = 2,
317};
318
319/**
320 * struct efx_channel - An Efx channel
321 *
322 * A channel comprises an event queue, at least one TX queue, at least
323 * one RX queue, and an associated tasklet for processing the event
324 * queue.
325 *
326 * @efx: Associated Efx NIC
327 * @evqnum: Event queue number
328 * @channel: Channel instance number
329 * @used_flags: Channel is used by net driver
330 * @enabled: Channel enabled indicator
331 * @irq: IRQ number (MSI and MSI-X only)
332 * @has_interrupt: Channel has an interrupt
333 * @irq_moderation: IRQ moderation value (in us)
334 * @napi_dev: Net device used with NAPI
335 * @napi_str: NAPI control structure
336 * @reset_work: Scheduled reset work thread
337 * @work_pending: Is work pending via NAPI?
338 * @eventq: Event queue buffer
339 * @eventq_read_ptr: Event queue read pointer
340 * @last_eventq_read_ptr: Last event queue read pointer value.
341 * @eventq_magic: Event queue magic value for driver-generated test events
342 * @lro_mgr: LRO state
343 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
344 * and diagnostic counters
345 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
346 * descriptors
347 * @rx_alloc_pop_pages: RX allocation method currently in use for popping
348 * descriptors
349 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
350 * @n_rx_ip_frag_err: Count of RX IP fragment errors
351 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
352 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
353 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
354 * @n_rx_overlength: Count of RX_OVERLENGTH errors
355 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
356 */
357struct efx_channel {
358 struct efx_nic *efx;
359 int evqnum;
360 int channel;
361 int used_flags;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100362 bool enabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100363 int irq;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100364 bool has_interrupt;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100365 unsigned int irq_moderation;
366 struct net_device *napi_dev;
367 struct napi_struct napi_str;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100368 bool work_pending;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100369 struct efx_special_buffer eventq;
370 unsigned int eventq_read_ptr;
371 unsigned int last_eventq_read_ptr;
372 unsigned int eventq_magic;
373
374 struct net_lro_mgr lro_mgr;
375 int rx_alloc_level;
376 int rx_alloc_push_pages;
377 int rx_alloc_pop_pages;
378
379 unsigned n_rx_tobe_disc;
380 unsigned n_rx_ip_frag_err;
381 unsigned n_rx_ip_hdr_chksum_err;
382 unsigned n_rx_tcp_udp_chksum_err;
383 unsigned n_rx_frm_trunc;
384 unsigned n_rx_overlength;
385 unsigned n_skbuff_leaks;
386
387 /* Used to pipeline received packets in order to optimise memory
388 * access with prefetches.
389 */
390 struct efx_rx_buffer *rx_pkt;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100391 bool rx_pkt_csummed;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100392
393};
394
395/**
396 * struct efx_blinker - S/W LED blinking context
397 * @led_num: LED ID (board-specific meaning)
398 * @state: Current state - on or off
399 * @resubmit: Timer resubmission flag
400 * @timer: Control timer for blinking
401 */
402struct efx_blinker {
403 int led_num;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100404 bool state;
405 bool resubmit;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100406 struct timer_list timer;
407};
408
409
410/**
411 * struct efx_board - board information
412 * @type: Board model type
413 * @major: Major rev. ('A', 'B' ...)
414 * @minor: Minor rev. (0, 1, ...)
415 * @init: Initialisation function
416 * @init_leds: Sets up board LEDs
417 * @set_fault_led: Turns the fault LED on or off
418 * @blink: Starts/stops blinking
Ben Hutchings37b5a602008-05-30 22:27:04 +0100419 * @fini: Cleanup function
Ben Hutchings8ceee662008-04-27 12:55:59 +0100420 * @blinker: used to blink LEDs in software
Ben Hutchings37b5a602008-05-30 22:27:04 +0100421 * @hwmon_client: I2C client for hardware monitor
422 * @ioexp_client: I2C client for power/port control
Ben Hutchings8ceee662008-04-27 12:55:59 +0100423 */
424struct efx_board {
425 int type;
426 int major;
427 int minor;
428 int (*init) (struct efx_nic *nic);
429 /* As the LEDs are typically attached to the PHY, LEDs
430 * have a separate init callback that happens later than
431 * board init. */
432 int (*init_leds)(struct efx_nic *efx);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100433 void (*set_fault_led) (struct efx_nic *efx, bool state);
434 void (*blink) (struct efx_nic *efx, bool start);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100435 void (*fini) (struct efx_nic *nic);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100436 struct efx_blinker blinker;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100437 struct i2c_client *hwmon_client, *ioexp_client;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100438};
439
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100440#define STRING_TABLE_LOOKUP(val, member) \
441 member ## _names[val]
442
Ben Hutchings8ceee662008-04-27 12:55:59 +0100443enum efx_int_mode {
444 /* Be careful if altering to correct macro below */
445 EFX_INT_MODE_MSIX = 0,
446 EFX_INT_MODE_MSI = 1,
447 EFX_INT_MODE_LEGACY = 2,
448 EFX_INT_MODE_MAX /* Insert any new items before this */
449};
450#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
451
452enum phy_type {
453 PHY_TYPE_NONE = 0,
454 PHY_TYPE_CX4_RTMR = 1,
455 PHY_TYPE_1G_ALASKA = 2,
456 PHY_TYPE_10XPRESS = 3,
457 PHY_TYPE_XFP = 4,
458 PHY_TYPE_PM8358 = 6,
459 PHY_TYPE_MAX /* Insert any new items before this */
460};
461
462#define PHY_ADDR_INVALID 0xff
463
464enum nic_state {
465 STATE_INIT = 0,
466 STATE_RUNNING = 1,
467 STATE_FINI = 2,
468 STATE_RESETTING = 3, /* rtnl_lock always held */
469 STATE_DISABLED = 4,
470 STATE_MAX,
471};
472
473/*
474 * Alignment of page-allocated RX buffers
475 *
476 * Controls the number of bytes inserted at the start of an RX buffer.
477 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
478 * of the skb->head for hardware DMA].
479 */
480#if defined(__i386__) || defined(__x86_64__)
481#define EFX_PAGE_IP_ALIGN 0
482#else
483#define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
484#endif
485
486/*
487 * Alignment of the skb->head which wraps a page-allocated RX buffer
488 *
489 * The skb allocated to wrap an rx_buffer can have this alignment. Since
490 * the data is memcpy'd from the rx_buf, it does not need to be equal to
491 * EFX_PAGE_IP_ALIGN.
492 */
493#define EFX_PAGE_SKB_ALIGN 2
494
495/* Forward declaration */
496struct efx_nic;
497
498/* Pseudo bit-mask flow control field */
499enum efx_fc_type {
500 EFX_FC_RX = 1,
501 EFX_FC_TX = 2,
502 EFX_FC_AUTO = 4,
503};
504
505/**
506 * struct efx_phy_operations - Efx PHY operations table
507 * @init: Initialise PHY
508 * @fini: Shut down PHY
509 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
510 * @clear_interrupt: Clear down interrupt
511 * @blink: Blink LEDs
512 * @check_hw: Check hardware
513 * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
514 * @mmds: MMD presence mask
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100515 * @loopbacks: Supported loopback modes mask
Ben Hutchings8ceee662008-04-27 12:55:59 +0100516 */
517struct efx_phy_operations {
518 int (*init) (struct efx_nic *efx);
519 void (*fini) (struct efx_nic *efx);
520 void (*reconfigure) (struct efx_nic *efx);
521 void (*clear_interrupt) (struct efx_nic *efx);
522 int (*check_hw) (struct efx_nic *efx);
523 void (*reset_xaui) (struct efx_nic *efx);
524 int mmds;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100525 unsigned loopbacks;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100526};
527
528/*
529 * Efx extended statistics
530 *
531 * Not all statistics are provided by all supported MACs. The purpose
532 * is this structure is to contain the raw statistics provided by each
533 * MAC.
534 */
535struct efx_mac_stats {
536 u64 tx_bytes;
537 u64 tx_good_bytes;
538 u64 tx_bad_bytes;
539 unsigned long tx_packets;
540 unsigned long tx_bad;
541 unsigned long tx_pause;
542 unsigned long tx_control;
543 unsigned long tx_unicast;
544 unsigned long tx_multicast;
545 unsigned long tx_broadcast;
546 unsigned long tx_lt64;
547 unsigned long tx_64;
548 unsigned long tx_65_to_127;
549 unsigned long tx_128_to_255;
550 unsigned long tx_256_to_511;
551 unsigned long tx_512_to_1023;
552 unsigned long tx_1024_to_15xx;
553 unsigned long tx_15xx_to_jumbo;
554 unsigned long tx_gtjumbo;
555 unsigned long tx_collision;
556 unsigned long tx_single_collision;
557 unsigned long tx_multiple_collision;
558 unsigned long tx_excessive_collision;
559 unsigned long tx_deferred;
560 unsigned long tx_late_collision;
561 unsigned long tx_excessive_deferred;
562 unsigned long tx_non_tcpudp;
563 unsigned long tx_mac_src_error;
564 unsigned long tx_ip_src_error;
565 u64 rx_bytes;
566 u64 rx_good_bytes;
567 u64 rx_bad_bytes;
568 unsigned long rx_packets;
569 unsigned long rx_good;
570 unsigned long rx_bad;
571 unsigned long rx_pause;
572 unsigned long rx_control;
573 unsigned long rx_unicast;
574 unsigned long rx_multicast;
575 unsigned long rx_broadcast;
576 unsigned long rx_lt64;
577 unsigned long rx_64;
578 unsigned long rx_65_to_127;
579 unsigned long rx_128_to_255;
580 unsigned long rx_256_to_511;
581 unsigned long rx_512_to_1023;
582 unsigned long rx_1024_to_15xx;
583 unsigned long rx_15xx_to_jumbo;
584 unsigned long rx_gtjumbo;
585 unsigned long rx_bad_lt64;
586 unsigned long rx_bad_64_to_15xx;
587 unsigned long rx_bad_15xx_to_jumbo;
588 unsigned long rx_bad_gtjumbo;
589 unsigned long rx_overflow;
590 unsigned long rx_missed;
591 unsigned long rx_false_carrier;
592 unsigned long rx_symbol_error;
593 unsigned long rx_align_error;
594 unsigned long rx_length_error;
595 unsigned long rx_internal_error;
596 unsigned long rx_good_lt64;
597};
598
599/* Number of bits used in a multicast filter hash address */
600#define EFX_MCAST_HASH_BITS 8
601
602/* Number of (single-bit) entries in a multicast filter hash */
603#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
604
605/* An Efx multicast filter hash */
606union efx_multicast_hash {
607 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
608 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
609};
610
611/**
612 * struct efx_nic - an Efx NIC
613 * @name: Device name (net device name or bus id before net device registered)
614 * @pci_dev: The PCI device
615 * @type: Controller type attributes
616 * @legacy_irq: IRQ number
Ben Hutchings8d9853d2008-07-18 19:01:20 +0100617 * @workqueue: Workqueue for port reconfigures and the HW monitor.
618 * Work items do not hold and must not acquire RTNL.
619 * @reset_workqueue: Workqueue for resets. Work item will acquire RTNL.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100620 * @reset_work: Scheduled reset workitem
621 * @monitor_work: Hardware monitor workitem
622 * @membase_phys: Memory BAR value as physical address
623 * @membase: Memory BAR value
624 * @biu_lock: BIU (bus interface unit) lock
625 * @interrupt_mode: Interrupt mode
Ben Hutchings37b5a602008-05-30 22:27:04 +0100626 * @i2c_adap: I2C adapter
Ben Hutchings8ceee662008-04-27 12:55:59 +0100627 * @board_info: Board-level information
628 * @state: Device state flag. Serialised by the rtnl_lock.
629 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
630 * @tx_queue: TX DMA queues
631 * @rx_queue: RX DMA queues
632 * @channel: Channels
633 * @rss_queues: Number of RSS queues
634 * @rx_buffer_len: RX buffer length
635 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
636 * @irq_status: Interrupt status buffer
637 * @last_irq_cpu: Last CPU to handle interrupt.
638 * This register is written with the SMP processor ID whenever an
639 * interrupt is handled. It is used by falcon_test_interrupt()
640 * to verify that an interrupt has occurred.
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100641 * @spi_flash: SPI flash device
642 * This field will be %NULL if no flash device is present.
643 * @spi_eeprom: SPI EEPROM device
644 * This field will be %NULL if no EEPROM device is present.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100645 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
646 * @nic_data: Hardware dependant state
647 * @mac_lock: MAC access lock. Protects @port_enabled, efx_monitor() and
648 * efx_reconfigure_port()
649 * @port_enabled: Port enabled indicator.
650 * Serialises efx_stop_all(), efx_start_all() and efx_monitor() and
651 * efx_reconfigure_work with kernel interfaces. Safe to read under any
652 * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
653 * be held to modify it.
654 * @port_initialized: Port initialized?
655 * @net_dev: Operating system network device. Consider holding the rtnl lock
656 * @rx_checksum_enabled: RX checksumming enabled
657 * @netif_stop_count: Port stop count
658 * @netif_stop_lock: Port stop lock
659 * @mac_stats: MAC statistics. These include all statistics the MACs
660 * can provide. Generic code converts these into a standard
661 * &struct net_device_stats.
662 * @stats_buffer: DMA buffer for statistics
663 * @stats_lock: Statistics update lock
664 * @mac_address: Permanent MAC address
665 * @phy_type: PHY type
666 * @phy_lock: PHY access lock
667 * @phy_op: PHY interface
668 * @phy_data: PHY private data (including PHY-specific stats)
669 * @mii: PHY interface
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100670 * @tx_disabled: PHY transmitter turned off
Ben Hutchings8ceee662008-04-27 12:55:59 +0100671 * @link_up: Link status
672 * @link_options: Link options (MII/GMII format)
673 * @n_link_state_changes: Number of times the link has changed state
674 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
675 * @multicast_hash: Multicast hash table
676 * @flow_control: Flow control flags - separate RX/TX so can't use link_options
677 * @reconfigure_work: work item for dealing with PHY events
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100678 * @loopback_mode: Loopback status
679 * @loopback_modes: Supported loopback mode bitmask
680 * @loopback_selftest: Offline self-test private state
Ben Hutchings8ceee662008-04-27 12:55:59 +0100681 *
682 * The @priv field of the corresponding &struct net_device points to
683 * this.
684 */
685struct efx_nic {
686 char name[IFNAMSIZ];
687 struct pci_dev *pci_dev;
688 const struct efx_nic_type *type;
689 int legacy_irq;
690 struct workqueue_struct *workqueue;
Ben Hutchings8d9853d2008-07-18 19:01:20 +0100691 struct workqueue_struct *reset_workqueue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100692 struct work_struct reset_work;
693 struct delayed_work monitor_work;
Ben Hutchings086ea352008-05-16 21:17:06 +0100694 resource_size_t membase_phys;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100695 void __iomem *membase;
696 spinlock_t biu_lock;
697 enum efx_int_mode interrupt_mode;
698
Ben Hutchings37b5a602008-05-30 22:27:04 +0100699 struct i2c_adapter i2c_adap;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100700 struct efx_board board_info;
701
702 enum nic_state state;
703 enum reset_type reset_pending;
704
Ben Hutchings60ac1062008-09-01 12:44:59 +0100705 struct efx_tx_queue tx_queue[EFX_TX_QUEUE_COUNT];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100706 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
707 struct efx_channel channel[EFX_MAX_CHANNELS];
708
709 int rss_queues;
710 unsigned int rx_buffer_len;
711 unsigned int rx_buffer_order;
712
713 struct efx_buffer irq_status;
714 volatile signed int last_irq_cpu;
715
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100716 struct efx_spi_device *spi_flash;
717 struct efx_spi_device *spi_eeprom;
718
Ben Hutchings8ceee662008-04-27 12:55:59 +0100719 unsigned n_rx_nodesc_drop_cnt;
720
Ben Hutchings5daab962008-05-16 21:19:43 +0100721 struct falcon_nic_data *nic_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100722
723 struct mutex mac_lock;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100724 bool port_enabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100725
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100726 bool port_initialized;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100727 struct net_device *net_dev;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100728 bool rx_checksum_enabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100729
730 atomic_t netif_stop_count;
731 spinlock_t netif_stop_lock;
732
733 struct efx_mac_stats mac_stats;
734 struct efx_buffer stats_buffer;
735 spinlock_t stats_lock;
736
737 unsigned char mac_address[ETH_ALEN];
738
739 enum phy_type phy_type;
740 spinlock_t phy_lock;
741 struct efx_phy_operations *phy_op;
742 void *phy_data;
743 struct mii_if_info mii;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100744 bool tx_disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100745
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100746 bool link_up;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100747 unsigned int link_options;
748 unsigned int n_link_state_changes;
749
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100750 bool promiscuous;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100751 union efx_multicast_hash multicast_hash;
752 enum efx_fc_type flow_control;
753 struct work_struct reconfigure_work;
754
755 atomic_t rx_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100756 enum efx_loopback_mode loopback_mode;
757 unsigned int loopback_modes;
758
759 void *loopback_selftest;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100760};
761
Ben Hutchings55668612008-05-16 21:16:10 +0100762static inline int efx_dev_registered(struct efx_nic *efx)
763{
764 return efx->net_dev->reg_state == NETREG_REGISTERED;
765}
766
767/* Net device name, for inclusion in log messages if it has been registered.
768 * Use efx->name not efx->net_dev->name so that races with (un)registration
769 * are harmless.
770 */
771static inline const char *efx_dev_name(struct efx_nic *efx)
772{
773 return efx_dev_registered(efx) ? efx->name : "";
774}
775
Ben Hutchings8ceee662008-04-27 12:55:59 +0100776/**
777 * struct efx_nic_type - Efx device type definition
778 * @mem_bar: Memory BAR number
779 * @mem_map_size: Memory BAR mapped size
780 * @txd_ptr_tbl_base: TX descriptor ring base address
781 * @rxd_ptr_tbl_base: RX descriptor ring base address
782 * @buf_tbl_base: Buffer table base address
783 * @evq_ptr_tbl_base: Event queue pointer table base address
784 * @evq_rptr_tbl_base: Event queue read-pointer table base address
785 * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
786 * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
787 * @evq_size: Event queue size (must be a power of two)
788 * @max_dma_mask: Maximum possible DMA mask
789 * @tx_dma_mask: TX DMA mask
790 * @bug5391_mask: Address mask for bug 5391 workaround
791 * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
792 * @rx_xon_thresh: RX FIFO XON watermark (bytes)
793 * @rx_buffer_padding: Padding added to each RX buffer
794 * @max_interrupt_mode: Highest capability interrupt mode supported
795 * from &enum efx_init_mode.
796 * @phys_addr_channels: Number of channels with physically addressed
797 * descriptors
798 */
799struct efx_nic_type {
800 unsigned int mem_bar;
801 unsigned int mem_map_size;
802 unsigned int txd_ptr_tbl_base;
803 unsigned int rxd_ptr_tbl_base;
804 unsigned int buf_tbl_base;
805 unsigned int evq_ptr_tbl_base;
806 unsigned int evq_rptr_tbl_base;
807
808 unsigned int txd_ring_mask;
809 unsigned int rxd_ring_mask;
810 unsigned int evq_size;
Ben Hutchings9bbd7d92008-05-16 21:18:48 +0100811 u64 max_dma_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100812 unsigned int tx_dma_mask;
813 unsigned bug5391_mask;
814
815 int rx_xoff_thresh;
816 int rx_xon_thresh;
817 unsigned int rx_buffer_padding;
818 unsigned int max_interrupt_mode;
819 unsigned int phys_addr_channels;
820};
821
822/**************************************************************************
823 *
824 * Prototypes and inline functions
825 *
826 *************************************************************************/
827
828/* Iterate over all used channels */
829#define efx_for_each_channel(_channel, _efx) \
830 for (_channel = &_efx->channel[0]; \
831 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
832 _channel++) \
833 if (!_channel->used_flags) \
834 continue; \
835 else
836
837/* Iterate over all used channels with interrupts */
838#define efx_for_each_channel_with_interrupt(_channel, _efx) \
839 for (_channel = &_efx->channel[0]; \
840 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
841 _channel++) \
842 if (!(_channel->used_flags && _channel->has_interrupt)) \
843 continue; \
844 else
845
846/* Iterate over all used TX queues */
847#define efx_for_each_tx_queue(_tx_queue, _efx) \
848 for (_tx_queue = &_efx->tx_queue[0]; \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100849 _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
850 _tx_queue++)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100851
852/* Iterate over all TX queues belonging to a channel */
853#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
854 for (_tx_queue = &_channel->efx->tx_queue[0]; \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100855 _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100856 _tx_queue++) \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100857 if (_tx_queue->channel != _channel) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100858 continue; \
859 else
860
861/* Iterate over all used RX queues */
862#define efx_for_each_rx_queue(_rx_queue, _efx) \
863 for (_rx_queue = &_efx->rx_queue[0]; \
864 _rx_queue < &_efx->rx_queue[EFX_MAX_RX_QUEUES]; \
865 _rx_queue++) \
866 if (!_rx_queue->used) \
867 continue; \
868 else
869
870/* Iterate over all RX queues belonging to a channel */
871#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
872 for (_rx_queue = &_channel->efx->rx_queue[0]; \
873 _rx_queue < &_channel->efx->rx_queue[EFX_MAX_RX_QUEUES]; \
874 _rx_queue++) \
875 if ((!_rx_queue->used) || \
876 (_rx_queue->channel != _channel)) \
877 continue; \
878 else
879
880/* Returns a pointer to the specified receive buffer in the RX
881 * descriptor queue.
882 */
883static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
884 unsigned int index)
885{
886 return (&rx_queue->buffer[index]);
887}
888
889/* Set bit in a little-endian bitfield */
Ben Hutchings18c2fc02008-09-01 12:43:39 +0100890static inline void set_bit_le(unsigned nr, unsigned char *addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100891{
892 addr[nr / 8] |= (1 << (nr % 8));
893}
894
895/* Clear bit in a little-endian bitfield */
Ben Hutchings18c2fc02008-09-01 12:43:39 +0100896static inline void clear_bit_le(unsigned nr, unsigned char *addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100897{
898 addr[nr / 8] &= ~(1 << (nr % 8));
899}
900
901
902/**
903 * EFX_MAX_FRAME_LEN - calculate maximum frame length
904 *
905 * This calculates the maximum frame length that will be used for a
906 * given MTU. The frame length will be equal to the MTU plus a
907 * constant amount of header space and padding. This is the quantity
908 * that the net driver will program into the MAC as the maximum frame
909 * length.
910 *
911 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
912 * length, so we round up to the nearest 8.
913 */
914#define EFX_MAX_FRAME_LEN(mtu) \
915 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
916
917
918#endif /* EFX_NET_DRIVER_H */