blob: f539e2e0da1bcaff546a059acbbfe2fc3f070971 [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.
133 * @unmap_addr: DMA address to unmap
134 * @unmap_len: Length of this fragment to unmap
135 */
136struct efx_tx_buffer {
137 const struct sk_buff *skb;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100138 struct efx_tso_header *tsoh;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100139 dma_addr_t dma_addr;
140 unsigned short len;
141 unsigned char continuation;
142 unsigned char unmap_single;
143 dma_addr_t unmap_addr;
144 unsigned short unmap_len;
145};
146
147/**
148 * struct efx_tx_queue - An Efx TX queue
149 *
150 * This is a ring buffer of TX fragments.
151 * Since the TX completion path always executes on the same
152 * CPU and the xmit path can operate on different CPUs,
153 * performance is increased by ensuring that the completion
154 * path and the xmit path operate on different cache lines.
155 * This is particularly important if the xmit path is always
156 * executing on one CPU which is different from the completion
157 * path. There is also a cache line for members which are
158 * read but not written on the fast path.
159 *
160 * @efx: The associated Efx NIC
161 * @queue: DMA queue number
Ben Hutchings8ceee662008-04-27 12:55:59 +0100162 * @channel: The associated channel
163 * @buffer: The software buffer ring
164 * @txd: The hardware descriptor ring
165 * @read_count: Current read pointer.
166 * This is the number of buffers that have been removed from both rings.
167 * @stopped: Stopped flag.
168 * Set if this TX queue is currently stopping its port.
169 * @insert_count: Current insert pointer
170 * This is the number of buffers that have been added to the
171 * software ring.
172 * @write_count: Current write pointer
173 * This is the number of buffers that have been added to the
174 * hardware ring.
175 * @old_read_count: The value of read_count when last checked.
176 * This is here for performance reasons. The xmit path will
177 * only get the up-to-date value of read_count if this
178 * variable indicates that the queue is full. This is to
179 * avoid cache-line ping-pong between the xmit path and the
180 * completion path.
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100181 * @tso_headers_free: A list of TSO headers allocated for this TX queue
182 * that are not in use, and so available for new TSO sends. The list
183 * is protected by the TX queue lock.
184 * @tso_bursts: Number of times TSO xmit invoked by kernel
185 * @tso_long_headers: Number of packets with headers too long for standard
186 * blocks
187 * @tso_packets: Number of packets via the TSO xmit path
Ben Hutchings8ceee662008-04-27 12:55:59 +0100188 */
189struct efx_tx_queue {
190 /* Members which don't change on the fast path */
191 struct efx_nic *efx ____cacheline_aligned_in_smp;
192 int queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100193 struct efx_channel *channel;
194 struct efx_nic *nic;
195 struct efx_tx_buffer *buffer;
196 struct efx_special_buffer txd;
197
198 /* Members used mainly on the completion path */
199 unsigned int read_count ____cacheline_aligned_in_smp;
200 int stopped;
201
202 /* Members used only on the xmit path */
203 unsigned int insert_count ____cacheline_aligned_in_smp;
204 unsigned int write_count;
205 unsigned int old_read_count;
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100206 struct efx_tso_header *tso_headers_free;
207 unsigned int tso_bursts;
208 unsigned int tso_long_headers;
209 unsigned int tso_packets;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100210};
211
212/**
213 * struct efx_rx_buffer - An Efx RX data buffer
214 * @dma_addr: DMA base address of the buffer
215 * @skb: The associated socket buffer, if any.
216 * If both this and page are %NULL, the buffer slot is currently free.
217 * @page: The associated page buffer, if any.
218 * If both this and skb are %NULL, the buffer slot is currently free.
219 * @data: Pointer to ethernet header
220 * @len: Buffer length, in bytes.
221 * @unmap_addr: DMA address to unmap
222 */
223struct efx_rx_buffer {
224 dma_addr_t dma_addr;
225 struct sk_buff *skb;
226 struct page *page;
227 char *data;
228 unsigned int len;
229 dma_addr_t unmap_addr;
230};
231
232/**
233 * struct efx_rx_queue - An Efx RX queue
234 * @efx: The associated Efx NIC
235 * @queue: DMA queue number
236 * @used: Queue is used by net driver
237 * @channel: The associated channel
238 * @buffer: The software buffer ring
239 * @rxd: The hardware descriptor ring
240 * @added_count: Number of buffers added to the receive queue.
241 * @notified_count: Number of buffers given to NIC (<= @added_count).
242 * @removed_count: Number of buffers removed from the receive queue.
243 * @add_lock: Receive queue descriptor add spin lock.
244 * This lock must be held in order to add buffers to the RX
245 * descriptor ring (rxd and buffer) and to update added_count (but
246 * not removed_count).
247 * @max_fill: RX descriptor maximum fill level (<= ring size)
248 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
249 * (<= @max_fill)
250 * @fast_fill_limit: The level to which a fast fill will fill
251 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
252 * @min_fill: RX descriptor minimum non-zero fill level.
253 * This records the minimum fill level observed when a ring
254 * refill was triggered.
255 * @min_overfill: RX descriptor minimum overflow fill level.
256 * This records the minimum fill level at which RX queue
257 * overflow was observed. It should never be set.
258 * @alloc_page_count: RX allocation strategy counter.
259 * @alloc_skb_count: RX allocation strategy counter.
260 * @work: Descriptor push work thread
261 * @buf_page: Page for next RX buffer.
262 * We can use a single page for multiple RX buffers. This tracks
263 * the remaining space in the allocation.
264 * @buf_dma_addr: Page's DMA address.
265 * @buf_data: Page's host address.
266 */
267struct efx_rx_queue {
268 struct efx_nic *efx;
269 int queue;
270 int used;
271 struct efx_channel *channel;
272 struct efx_rx_buffer *buffer;
273 struct efx_special_buffer rxd;
274
275 int added_count;
276 int notified_count;
277 int removed_count;
278 spinlock_t add_lock;
279 unsigned int max_fill;
280 unsigned int fast_fill_trigger;
281 unsigned int fast_fill_limit;
282 unsigned int min_fill;
283 unsigned int min_overfill;
284 unsigned int alloc_page_count;
285 unsigned int alloc_skb_count;
286 struct delayed_work work;
287 unsigned int slow_fill_count;
288
289 struct page *buf_page;
290 dma_addr_t buf_dma_addr;
291 char *buf_data;
292};
293
294/**
295 * struct efx_buffer - An Efx general-purpose buffer
296 * @addr: host base address of the buffer
297 * @dma_addr: DMA base address of the buffer
298 * @len: Buffer length, in bytes
299 *
300 * Falcon uses these buffers for its interrupt status registers and
301 * MAC stats dumps.
302 */
303struct efx_buffer {
304 void *addr;
305 dma_addr_t dma_addr;
306 unsigned int len;
307};
308
309
310/* Flags for channel->used_flags */
311#define EFX_USED_BY_RX 1
312#define EFX_USED_BY_TX 2
313#define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
314
315enum efx_rx_alloc_method {
316 RX_ALLOC_METHOD_AUTO = 0,
317 RX_ALLOC_METHOD_SKB = 1,
318 RX_ALLOC_METHOD_PAGE = 2,
319};
320
321/**
322 * struct efx_channel - An Efx channel
323 *
324 * A channel comprises an event queue, at least one TX queue, at least
325 * one RX queue, and an associated tasklet for processing the event
326 * queue.
327 *
328 * @efx: Associated Efx NIC
329 * @evqnum: Event queue number
330 * @channel: Channel instance number
331 * @used_flags: Channel is used by net driver
332 * @enabled: Channel enabled indicator
333 * @irq: IRQ number (MSI and MSI-X only)
334 * @has_interrupt: Channel has an interrupt
335 * @irq_moderation: IRQ moderation value (in us)
336 * @napi_dev: Net device used with NAPI
337 * @napi_str: NAPI control structure
338 * @reset_work: Scheduled reset work thread
339 * @work_pending: Is work pending via NAPI?
340 * @eventq: Event queue buffer
341 * @eventq_read_ptr: Event queue read pointer
342 * @last_eventq_read_ptr: Last event queue read pointer value.
343 * @eventq_magic: Event queue magic value for driver-generated test events
344 * @lro_mgr: LRO state
345 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
346 * and diagnostic counters
347 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
348 * descriptors
349 * @rx_alloc_pop_pages: RX allocation method currently in use for popping
350 * descriptors
351 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
352 * @n_rx_ip_frag_err: Count of RX IP fragment errors
353 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
354 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
355 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
356 * @n_rx_overlength: Count of RX_OVERLENGTH errors
357 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
358 */
359struct efx_channel {
360 struct efx_nic *efx;
361 int evqnum;
362 int channel;
363 int used_flags;
364 int enabled;
365 int irq;
366 unsigned int has_interrupt;
367 unsigned int irq_moderation;
368 struct net_device *napi_dev;
369 struct napi_struct napi_str;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100370 int work_pending;
371 struct efx_special_buffer eventq;
372 unsigned int eventq_read_ptr;
373 unsigned int last_eventq_read_ptr;
374 unsigned int eventq_magic;
375
376 struct net_lro_mgr lro_mgr;
377 int rx_alloc_level;
378 int rx_alloc_push_pages;
379 int rx_alloc_pop_pages;
380
381 unsigned n_rx_tobe_disc;
382 unsigned n_rx_ip_frag_err;
383 unsigned n_rx_ip_hdr_chksum_err;
384 unsigned n_rx_tcp_udp_chksum_err;
385 unsigned n_rx_frm_trunc;
386 unsigned n_rx_overlength;
387 unsigned n_skbuff_leaks;
388
389 /* Used to pipeline received packets in order to optimise memory
390 * access with prefetches.
391 */
392 struct efx_rx_buffer *rx_pkt;
393 int rx_pkt_csummed;
394
395};
396
397/**
398 * struct efx_blinker - S/W LED blinking context
399 * @led_num: LED ID (board-specific meaning)
400 * @state: Current state - on or off
401 * @resubmit: Timer resubmission flag
402 * @timer: Control timer for blinking
403 */
404struct efx_blinker {
405 int led_num;
406 int state;
407 int resubmit;
408 struct timer_list timer;
409};
410
411
412/**
413 * struct efx_board - board information
414 * @type: Board model type
415 * @major: Major rev. ('A', 'B' ...)
416 * @minor: Minor rev. (0, 1, ...)
417 * @init: Initialisation function
418 * @init_leds: Sets up board LEDs
419 * @set_fault_led: Turns the fault LED on or off
420 * @blink: Starts/stops blinking
Ben Hutchings37b5a602008-05-30 22:27:04 +0100421 * @fini: Cleanup function
Ben Hutchings8ceee662008-04-27 12:55:59 +0100422 * @blinker: used to blink LEDs in software
Ben Hutchings37b5a602008-05-30 22:27:04 +0100423 * @hwmon_client: I2C client for hardware monitor
424 * @ioexp_client: I2C client for power/port control
Ben Hutchings8ceee662008-04-27 12:55:59 +0100425 */
426struct efx_board {
427 int type;
428 int major;
429 int minor;
430 int (*init) (struct efx_nic *nic);
431 /* As the LEDs are typically attached to the PHY, LEDs
432 * have a separate init callback that happens later than
433 * board init. */
434 int (*init_leds)(struct efx_nic *efx);
435 void (*set_fault_led) (struct efx_nic *efx, int state);
436 void (*blink) (struct efx_nic *efx, int start);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100437 void (*fini) (struct efx_nic *nic);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100438 struct efx_blinker blinker;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100439 struct i2c_client *hwmon_client, *ioexp_client;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100440};
441
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100442#define STRING_TABLE_LOOKUP(val, member) \
443 member ## _names[val]
444
Ben Hutchings8ceee662008-04-27 12:55:59 +0100445enum efx_int_mode {
446 /* Be careful if altering to correct macro below */
447 EFX_INT_MODE_MSIX = 0,
448 EFX_INT_MODE_MSI = 1,
449 EFX_INT_MODE_LEGACY = 2,
450 EFX_INT_MODE_MAX /* Insert any new items before this */
451};
452#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
453
454enum phy_type {
455 PHY_TYPE_NONE = 0,
456 PHY_TYPE_CX4_RTMR = 1,
457 PHY_TYPE_1G_ALASKA = 2,
458 PHY_TYPE_10XPRESS = 3,
459 PHY_TYPE_XFP = 4,
460 PHY_TYPE_PM8358 = 6,
461 PHY_TYPE_MAX /* Insert any new items before this */
462};
463
464#define PHY_ADDR_INVALID 0xff
465
466enum nic_state {
467 STATE_INIT = 0,
468 STATE_RUNNING = 1,
469 STATE_FINI = 2,
470 STATE_RESETTING = 3, /* rtnl_lock always held */
471 STATE_DISABLED = 4,
472 STATE_MAX,
473};
474
475/*
476 * Alignment of page-allocated RX buffers
477 *
478 * Controls the number of bytes inserted at the start of an RX buffer.
479 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
480 * of the skb->head for hardware DMA].
481 */
482#if defined(__i386__) || defined(__x86_64__)
483#define EFX_PAGE_IP_ALIGN 0
484#else
485#define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
486#endif
487
488/*
489 * Alignment of the skb->head which wraps a page-allocated RX buffer
490 *
491 * The skb allocated to wrap an rx_buffer can have this alignment. Since
492 * the data is memcpy'd from the rx_buf, it does not need to be equal to
493 * EFX_PAGE_IP_ALIGN.
494 */
495#define EFX_PAGE_SKB_ALIGN 2
496
497/* Forward declaration */
498struct efx_nic;
499
500/* Pseudo bit-mask flow control field */
501enum efx_fc_type {
502 EFX_FC_RX = 1,
503 EFX_FC_TX = 2,
504 EFX_FC_AUTO = 4,
505};
506
507/**
508 * struct efx_phy_operations - Efx PHY operations table
509 * @init: Initialise PHY
510 * @fini: Shut down PHY
511 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
512 * @clear_interrupt: Clear down interrupt
513 * @blink: Blink LEDs
514 * @check_hw: Check hardware
515 * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
516 * @mmds: MMD presence mask
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100517 * @loopbacks: Supported loopback modes mask
Ben Hutchings8ceee662008-04-27 12:55:59 +0100518 */
519struct efx_phy_operations {
520 int (*init) (struct efx_nic *efx);
521 void (*fini) (struct efx_nic *efx);
522 void (*reconfigure) (struct efx_nic *efx);
523 void (*clear_interrupt) (struct efx_nic *efx);
524 int (*check_hw) (struct efx_nic *efx);
525 void (*reset_xaui) (struct efx_nic *efx);
526 int mmds;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100527 unsigned loopbacks;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100528};
529
530/*
531 * Efx extended statistics
532 *
533 * Not all statistics are provided by all supported MACs. The purpose
534 * is this structure is to contain the raw statistics provided by each
535 * MAC.
536 */
537struct efx_mac_stats {
538 u64 tx_bytes;
539 u64 tx_good_bytes;
540 u64 tx_bad_bytes;
541 unsigned long tx_packets;
542 unsigned long tx_bad;
543 unsigned long tx_pause;
544 unsigned long tx_control;
545 unsigned long tx_unicast;
546 unsigned long tx_multicast;
547 unsigned long tx_broadcast;
548 unsigned long tx_lt64;
549 unsigned long tx_64;
550 unsigned long tx_65_to_127;
551 unsigned long tx_128_to_255;
552 unsigned long tx_256_to_511;
553 unsigned long tx_512_to_1023;
554 unsigned long tx_1024_to_15xx;
555 unsigned long tx_15xx_to_jumbo;
556 unsigned long tx_gtjumbo;
557 unsigned long tx_collision;
558 unsigned long tx_single_collision;
559 unsigned long tx_multiple_collision;
560 unsigned long tx_excessive_collision;
561 unsigned long tx_deferred;
562 unsigned long tx_late_collision;
563 unsigned long tx_excessive_deferred;
564 unsigned long tx_non_tcpudp;
565 unsigned long tx_mac_src_error;
566 unsigned long tx_ip_src_error;
567 u64 rx_bytes;
568 u64 rx_good_bytes;
569 u64 rx_bad_bytes;
570 unsigned long rx_packets;
571 unsigned long rx_good;
572 unsigned long rx_bad;
573 unsigned long rx_pause;
574 unsigned long rx_control;
575 unsigned long rx_unicast;
576 unsigned long rx_multicast;
577 unsigned long rx_broadcast;
578 unsigned long rx_lt64;
579 unsigned long rx_64;
580 unsigned long rx_65_to_127;
581 unsigned long rx_128_to_255;
582 unsigned long rx_256_to_511;
583 unsigned long rx_512_to_1023;
584 unsigned long rx_1024_to_15xx;
585 unsigned long rx_15xx_to_jumbo;
586 unsigned long rx_gtjumbo;
587 unsigned long rx_bad_lt64;
588 unsigned long rx_bad_64_to_15xx;
589 unsigned long rx_bad_15xx_to_jumbo;
590 unsigned long rx_bad_gtjumbo;
591 unsigned long rx_overflow;
592 unsigned long rx_missed;
593 unsigned long rx_false_carrier;
594 unsigned long rx_symbol_error;
595 unsigned long rx_align_error;
596 unsigned long rx_length_error;
597 unsigned long rx_internal_error;
598 unsigned long rx_good_lt64;
599};
600
601/* Number of bits used in a multicast filter hash address */
602#define EFX_MCAST_HASH_BITS 8
603
604/* Number of (single-bit) entries in a multicast filter hash */
605#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
606
607/* An Efx multicast filter hash */
608union efx_multicast_hash {
609 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
610 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
611};
612
613/**
614 * struct efx_nic - an Efx NIC
615 * @name: Device name (net device name or bus id before net device registered)
616 * @pci_dev: The PCI device
617 * @type: Controller type attributes
618 * @legacy_irq: IRQ number
Ben Hutchings8d9853d2008-07-18 19:01:20 +0100619 * @workqueue: Workqueue for port reconfigures and the HW monitor.
620 * Work items do not hold and must not acquire RTNL.
621 * @reset_workqueue: Workqueue for resets. Work item will acquire RTNL.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100622 * @reset_work: Scheduled reset workitem
623 * @monitor_work: Hardware monitor workitem
624 * @membase_phys: Memory BAR value as physical address
625 * @membase: Memory BAR value
626 * @biu_lock: BIU (bus interface unit) lock
627 * @interrupt_mode: Interrupt mode
Ben Hutchings37b5a602008-05-30 22:27:04 +0100628 * @i2c_adap: I2C adapter
Ben Hutchings8ceee662008-04-27 12:55:59 +0100629 * @board_info: Board-level information
630 * @state: Device state flag. Serialised by the rtnl_lock.
631 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
632 * @tx_queue: TX DMA queues
633 * @rx_queue: RX DMA queues
634 * @channel: Channels
635 * @rss_queues: Number of RSS queues
636 * @rx_buffer_len: RX buffer length
637 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
638 * @irq_status: Interrupt status buffer
639 * @last_irq_cpu: Last CPU to handle interrupt.
640 * This register is written with the SMP processor ID whenever an
641 * interrupt is handled. It is used by falcon_test_interrupt()
642 * to verify that an interrupt has occurred.
643 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
644 * @nic_data: Hardware dependant state
645 * @mac_lock: MAC access lock. Protects @port_enabled, efx_monitor() and
646 * efx_reconfigure_port()
647 * @port_enabled: Port enabled indicator.
648 * Serialises efx_stop_all(), efx_start_all() and efx_monitor() and
649 * efx_reconfigure_work with kernel interfaces. Safe to read under any
650 * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
651 * be held to modify it.
652 * @port_initialized: Port initialized?
653 * @net_dev: Operating system network device. Consider holding the rtnl lock
654 * @rx_checksum_enabled: RX checksumming enabled
655 * @netif_stop_count: Port stop count
656 * @netif_stop_lock: Port stop lock
657 * @mac_stats: MAC statistics. These include all statistics the MACs
658 * can provide. Generic code converts these into a standard
659 * &struct net_device_stats.
660 * @stats_buffer: DMA buffer for statistics
661 * @stats_lock: Statistics update lock
662 * @mac_address: Permanent MAC address
663 * @phy_type: PHY type
664 * @phy_lock: PHY access lock
665 * @phy_op: PHY interface
666 * @phy_data: PHY private data (including PHY-specific stats)
667 * @mii: PHY interface
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100668 * @tx_disabled: PHY transmitter turned off
Ben Hutchings8ceee662008-04-27 12:55:59 +0100669 * @link_up: Link status
670 * @link_options: Link options (MII/GMII format)
671 * @n_link_state_changes: Number of times the link has changed state
672 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
673 * @multicast_hash: Multicast hash table
674 * @flow_control: Flow control flags - separate RX/TX so can't use link_options
675 * @reconfigure_work: work item for dealing with PHY events
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100676 * @loopback_mode: Loopback status
677 * @loopback_modes: Supported loopback mode bitmask
678 * @loopback_selftest: Offline self-test private state
Ben Hutchings8ceee662008-04-27 12:55:59 +0100679 *
680 * The @priv field of the corresponding &struct net_device points to
681 * this.
682 */
683struct efx_nic {
684 char name[IFNAMSIZ];
685 struct pci_dev *pci_dev;
686 const struct efx_nic_type *type;
687 int legacy_irq;
688 struct workqueue_struct *workqueue;
Ben Hutchings8d9853d2008-07-18 19:01:20 +0100689 struct workqueue_struct *reset_workqueue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100690 struct work_struct reset_work;
691 struct delayed_work monitor_work;
Ben Hutchings086ea352008-05-16 21:17:06 +0100692 resource_size_t membase_phys;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100693 void __iomem *membase;
694 spinlock_t biu_lock;
695 enum efx_int_mode interrupt_mode;
696
Ben Hutchings37b5a602008-05-30 22:27:04 +0100697 struct i2c_adapter i2c_adap;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100698 struct efx_board board_info;
699
700 enum nic_state state;
701 enum reset_type reset_pending;
702
Ben Hutchings60ac1062008-09-01 12:44:59 +0100703 struct efx_tx_queue tx_queue[EFX_TX_QUEUE_COUNT];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100704 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
705 struct efx_channel channel[EFX_MAX_CHANNELS];
706
707 int rss_queues;
708 unsigned int rx_buffer_len;
709 unsigned int rx_buffer_order;
710
711 struct efx_buffer irq_status;
712 volatile signed int last_irq_cpu;
713
714 unsigned n_rx_nodesc_drop_cnt;
715
Ben Hutchings5daab962008-05-16 21:19:43 +0100716 struct falcon_nic_data *nic_data;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100717
718 struct mutex mac_lock;
719 int port_enabled;
720
721 int port_initialized;
722 struct net_device *net_dev;
723 int rx_checksum_enabled;
724
725 atomic_t netif_stop_count;
726 spinlock_t netif_stop_lock;
727
728 struct efx_mac_stats mac_stats;
729 struct efx_buffer stats_buffer;
730 spinlock_t stats_lock;
731
732 unsigned char mac_address[ETH_ALEN];
733
734 enum phy_type phy_type;
735 spinlock_t phy_lock;
736 struct efx_phy_operations *phy_op;
737 void *phy_data;
738 struct mii_if_info mii;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100739 unsigned tx_disabled;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100740
741 int link_up;
742 unsigned int link_options;
743 unsigned int n_link_state_changes;
744
745 int promiscuous;
746 union efx_multicast_hash multicast_hash;
747 enum efx_fc_type flow_control;
748 struct work_struct reconfigure_work;
749
750 atomic_t rx_reset;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100751 enum efx_loopback_mode loopback_mode;
752 unsigned int loopback_modes;
753
754 void *loopback_selftest;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100755};
756
Ben Hutchings55668612008-05-16 21:16:10 +0100757static inline int efx_dev_registered(struct efx_nic *efx)
758{
759 return efx->net_dev->reg_state == NETREG_REGISTERED;
760}
761
762/* Net device name, for inclusion in log messages if it has been registered.
763 * Use efx->name not efx->net_dev->name so that races with (un)registration
764 * are harmless.
765 */
766static inline const char *efx_dev_name(struct efx_nic *efx)
767{
768 return efx_dev_registered(efx) ? efx->name : "";
769}
770
Ben Hutchings8ceee662008-04-27 12:55:59 +0100771/**
772 * struct efx_nic_type - Efx device type definition
773 * @mem_bar: Memory BAR number
774 * @mem_map_size: Memory BAR mapped size
775 * @txd_ptr_tbl_base: TX descriptor ring base address
776 * @rxd_ptr_tbl_base: RX descriptor ring base address
777 * @buf_tbl_base: Buffer table base address
778 * @evq_ptr_tbl_base: Event queue pointer table base address
779 * @evq_rptr_tbl_base: Event queue read-pointer table base address
780 * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
781 * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
782 * @evq_size: Event queue size (must be a power of two)
783 * @max_dma_mask: Maximum possible DMA mask
784 * @tx_dma_mask: TX DMA mask
785 * @bug5391_mask: Address mask for bug 5391 workaround
786 * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
787 * @rx_xon_thresh: RX FIFO XON watermark (bytes)
788 * @rx_buffer_padding: Padding added to each RX buffer
789 * @max_interrupt_mode: Highest capability interrupt mode supported
790 * from &enum efx_init_mode.
791 * @phys_addr_channels: Number of channels with physically addressed
792 * descriptors
793 */
794struct efx_nic_type {
795 unsigned int mem_bar;
796 unsigned int mem_map_size;
797 unsigned int txd_ptr_tbl_base;
798 unsigned int rxd_ptr_tbl_base;
799 unsigned int buf_tbl_base;
800 unsigned int evq_ptr_tbl_base;
801 unsigned int evq_rptr_tbl_base;
802
803 unsigned int txd_ring_mask;
804 unsigned int rxd_ring_mask;
805 unsigned int evq_size;
Ben Hutchings9bbd7d92008-05-16 21:18:48 +0100806 u64 max_dma_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100807 unsigned int tx_dma_mask;
808 unsigned bug5391_mask;
809
810 int rx_xoff_thresh;
811 int rx_xon_thresh;
812 unsigned int rx_buffer_padding;
813 unsigned int max_interrupt_mode;
814 unsigned int phys_addr_channels;
815};
816
817/**************************************************************************
818 *
819 * Prototypes and inline functions
820 *
821 *************************************************************************/
822
823/* Iterate over all used channels */
824#define efx_for_each_channel(_channel, _efx) \
825 for (_channel = &_efx->channel[0]; \
826 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
827 _channel++) \
828 if (!_channel->used_flags) \
829 continue; \
830 else
831
832/* Iterate over all used channels with interrupts */
833#define efx_for_each_channel_with_interrupt(_channel, _efx) \
834 for (_channel = &_efx->channel[0]; \
835 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
836 _channel++) \
837 if (!(_channel->used_flags && _channel->has_interrupt)) \
838 continue; \
839 else
840
841/* Iterate over all used TX queues */
842#define efx_for_each_tx_queue(_tx_queue, _efx) \
843 for (_tx_queue = &_efx->tx_queue[0]; \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100844 _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
845 _tx_queue++)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100846
847/* Iterate over all TX queues belonging to a channel */
848#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
849 for (_tx_queue = &_channel->efx->tx_queue[0]; \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100850 _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100851 _tx_queue++) \
Ben Hutchings60ac1062008-09-01 12:44:59 +0100852 if (_tx_queue->channel != _channel) \
Ben Hutchings8ceee662008-04-27 12:55:59 +0100853 continue; \
854 else
855
856/* Iterate over all used RX queues */
857#define efx_for_each_rx_queue(_rx_queue, _efx) \
858 for (_rx_queue = &_efx->rx_queue[0]; \
859 _rx_queue < &_efx->rx_queue[EFX_MAX_RX_QUEUES]; \
860 _rx_queue++) \
861 if (!_rx_queue->used) \
862 continue; \
863 else
864
865/* Iterate over all RX queues belonging to a channel */
866#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
867 for (_rx_queue = &_channel->efx->rx_queue[0]; \
868 _rx_queue < &_channel->efx->rx_queue[EFX_MAX_RX_QUEUES]; \
869 _rx_queue++) \
870 if ((!_rx_queue->used) || \
871 (_rx_queue->channel != _channel)) \
872 continue; \
873 else
874
875/* Returns a pointer to the specified receive buffer in the RX
876 * descriptor queue.
877 */
878static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
879 unsigned int index)
880{
881 return (&rx_queue->buffer[index]);
882}
883
884/* Set bit in a little-endian bitfield */
Ben Hutchings18c2fc02008-09-01 12:43:39 +0100885static inline void set_bit_le(unsigned nr, unsigned char *addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100886{
887 addr[nr / 8] |= (1 << (nr % 8));
888}
889
890/* Clear bit in a little-endian bitfield */
Ben Hutchings18c2fc02008-09-01 12:43:39 +0100891static inline void clear_bit_le(unsigned nr, unsigned char *addr)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100892{
893 addr[nr / 8] &= ~(1 << (nr % 8));
894}
895
896
897/**
898 * EFX_MAX_FRAME_LEN - calculate maximum frame length
899 *
900 * This calculates the maximum frame length that will be used for a
901 * given MTU. The frame length will be equal to the MTU plus a
902 * constant amount of header space and padding. This is the quantity
903 * that the net driver will program into the MAC as the maximum frame
904 * length.
905 *
906 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
907 * length, so we round up to the nearest 8.
908 */
909#define EFX_MAX_FRAME_LEN(mtu) \
910 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
911
912
913#endif /* EFX_NET_DRIVER_H */