sfc: Extend and abstract efx_filter_spec to cover Huntington/EF10
[deliverable/linux.git] / drivers / net / ethernet / sfc / net_driver.h
CommitLineData
8ceee660
BH
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
0a6f40c6 4 * Copyright 2005-2011 Solarflare Communications Inc.
8ceee660
BH
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
8ceee660
BH
16#include <linux/netdevice.h>
17#include <linux/etherdevice.h>
18#include <linux/ethtool.h>
19#include <linux/if_vlan.h>
90d683af 20#include <linux/timer.h>
68e7f45e 21#include <linux/mdio.h>
8ceee660
BH
22#include <linux/list.h>
23#include <linux/pci.h>
24#include <linux/device.h>
25#include <linux/highmem.h>
26#include <linux/workqueue.h>
cd2d5b52 27#include <linux/mutex.h>
10ed61c4 28#include <linux/vmalloc.h>
37b5a603 29#include <linux/i2c.h>
8ceee660
BH
30
31#include "enum.h"
32#include "bitfield.h"
8ceee660 33
8ceee660
BH
34/**************************************************************************
35 *
36 * Build definitions
37 *
38 **************************************************************************/
c5d5f5fd 39
25ce2002 40#define EFX_DRIVER_VERSION "3.2"
8ceee660 41
5f3f9d6c 42#ifdef DEBUG
8ceee660
BH
43#define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
44#define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
45#else
46#define EFX_BUG_ON_PARANOID(x) do {} while (0)
47#define EFX_WARN_ON_PARANOID(x) do {} while (0)
48#endif
49
8ceee660
BH
50/**************************************************************************
51 *
52 * Efx data structures
53 *
54 **************************************************************************/
55
a16e5b24 56#define EFX_MAX_CHANNELS 32U
8ceee660 57#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
cd2d5b52 58#define EFX_EXTRA_CHANNEL_IOV 0
7c236c43
SH
59#define EFX_EXTRA_CHANNEL_PTP 1
60#define EFX_MAX_EXTRA_CHANNELS 2U
8ceee660 61
a4900ac9
BH
62/* Checksum generation is a per-queue option in hardware, so each
63 * queue visible to the networking core is backed by two hardware TX
64 * queues. */
94b274bf
BH
65#define EFX_MAX_TX_TC 2
66#define EFX_MAX_CORE_TX_QUEUES (EFX_MAX_TX_TC * EFX_MAX_CHANNELS)
67#define EFX_TXQ_TYPE_OFFLOAD 1 /* flag */
68#define EFX_TXQ_TYPE_HIGHPRI 2 /* flag */
69#define EFX_TXQ_TYPES 4
70#define EFX_MAX_TX_QUEUES (EFX_TXQ_TYPES * EFX_MAX_CHANNELS)
60ac1065 71
85740cdf
BH
72/* Maximum possible MTU the driver supports */
73#define EFX_MAX_MTU (9 * 1024)
74
950c54df
BH
75/* Size of an RX scatter buffer. Small enough to pack 2 into a 4K page,
76 * and should be a multiple of the cache line size.
77 */
78#define EFX_RX_USR_BUF_SIZE (2048 - 256)
79
80/* If possible, we should ensure cache line alignment at start and end
81 * of every buffer. Otherwise, we just need to ensure 4-byte
82 * alignment of the network header.
83 */
84#if NET_IP_ALIGN == 0
85#define EFX_RX_BUF_ALIGNMENT L1_CACHE_BYTES
86#else
87#define EFX_RX_BUF_ALIGNMENT 4
88#endif
85740cdf 89
7c236c43
SH
90/* Forward declare Precision Time Protocol (PTP) support structure. */
91struct efx_ptp_data;
92
d4f2cecc
BH
93struct efx_self_tests;
94
8ceee660 95/**
caa75586
BH
96 * struct efx_buffer - A general-purpose DMA buffer
97 * @addr: host base address of the buffer
8ceee660
BH
98 * @dma_addr: DMA base address of the buffer
99 * @len: Buffer length, in bytes
8ceee660 100 *
caa75586
BH
101 * The NIC uses these buffers for its interrupt status registers and
102 * MAC stats dumps.
8ceee660 103 */
caa75586 104struct efx_buffer {
8ceee660
BH
105 void *addr;
106 dma_addr_t dma_addr;
107 unsigned int len;
caa75586
BH
108};
109
110/**
111 * struct efx_special_buffer - DMA buffer entered into buffer table
112 * @buf: Standard &struct efx_buffer
113 * @index: Buffer index within controller;s buffer table
114 * @entries: Number of buffer table entries
115 *
116 * The NIC has a buffer table that maps buffers of size %EFX_BUF_SIZE.
117 * Event and descriptor rings are addressed via one or more buffer
118 * table entries (and so can be physically non-contiguous, although we
119 * currently do not take advantage of that). On Falcon and Siena we
120 * have to take care of allocating and initialising the entries
121 * ourselves. On later hardware this is managed by the firmware and
122 * @index and @entries are left as 0.
123 */
124struct efx_special_buffer {
125 struct efx_buffer buf;
5bbe2f4f
BH
126 unsigned int index;
127 unsigned int entries;
8ceee660
BH
128};
129
130/**
7668ff9c
BH
131 * struct efx_tx_buffer - buffer state for a TX descriptor
132 * @skb: When @flags & %EFX_TX_BUF_SKB, the associated socket buffer to be
133 * freed when descriptor completes
f7251a9c
BH
134 * @heap_buf: When @flags & %EFX_TX_BUF_HEAP, the associated heap buffer to be
135 * freed when descriptor completes.
8ceee660 136 * @dma_addr: DMA address of the fragment.
7668ff9c 137 * @flags: Flags for allocation and DMA mapping type
8ceee660
BH
138 * @len: Length of this fragment.
139 * This field is zero when the queue slot is empty.
8ceee660
BH
140 * @unmap_len: Length of this fragment to unmap
141 */
142struct efx_tx_buffer {
7668ff9c
BH
143 union {
144 const struct sk_buff *skb;
f7251a9c 145 void *heap_buf;
7668ff9c 146 };
8ceee660 147 dma_addr_t dma_addr;
7668ff9c 148 unsigned short flags;
8ceee660 149 unsigned short len;
8ceee660
BH
150 unsigned short unmap_len;
151};
7668ff9c
BH
152#define EFX_TX_BUF_CONT 1 /* not last descriptor of packet */
153#define EFX_TX_BUF_SKB 2 /* buffer is last part of skb */
f7251a9c 154#define EFX_TX_BUF_HEAP 4 /* buffer was allocated with kmalloc() */
7668ff9c 155#define EFX_TX_BUF_MAP_SINGLE 8 /* buffer was mapped with dma_map_single() */
8ceee660
BH
156
157/**
158 * struct efx_tx_queue - An Efx TX queue
159 *
160 * This is a ring buffer of TX fragments.
161 * Since the TX completion path always executes on the same
162 * CPU and the xmit path can operate on different CPUs,
163 * performance is increased by ensuring that the completion
164 * path and the xmit path operate on different cache lines.
165 * This is particularly important if the xmit path is always
166 * executing on one CPU which is different from the completion
167 * path. There is also a cache line for members which are
168 * read but not written on the fast path.
169 *
170 * @efx: The associated Efx NIC
171 * @queue: DMA queue number
8ceee660 172 * @channel: The associated channel
c04bfc6b 173 * @core_txq: The networking core TX queue structure
8ceee660 174 * @buffer: The software buffer ring
f7251a9c 175 * @tsoh_page: Array of pages of TSO header buffers
8ceee660 176 * @txd: The hardware descriptor ring
ecc910f5 177 * @ptr_mask: The size of the ring minus 1.
94b274bf 178 * @initialised: Has hardware queue been initialised?
8ceee660
BH
179 * @read_count: Current read pointer.
180 * This is the number of buffers that have been removed from both rings.
cd38557d
BH
181 * @old_write_count: The value of @write_count when last checked.
182 * This is here for performance reasons. The xmit path will
183 * only get the up-to-date value of @write_count if this
184 * variable indicates that the queue is empty. This is to
185 * avoid cache-line ping-pong between the xmit path and the
186 * completion path.
8ceee660
BH
187 * @insert_count: Current insert pointer
188 * This is the number of buffers that have been added to the
189 * software ring.
190 * @write_count: Current write pointer
191 * This is the number of buffers that have been added to the
192 * hardware ring.
193 * @old_read_count: The value of read_count when last checked.
194 * This is here for performance reasons. The xmit path will
195 * only get the up-to-date value of read_count if this
196 * variable indicates that the queue is full. This is to
197 * avoid cache-line ping-pong between the xmit path and the
198 * completion path.
b9b39b62
BH
199 * @tso_bursts: Number of times TSO xmit invoked by kernel
200 * @tso_long_headers: Number of packets with headers too long for standard
201 * blocks
202 * @tso_packets: Number of packets via the TSO xmit path
cd38557d
BH
203 * @pushes: Number of times the TX push feature has been used
204 * @empty_read_count: If the completion path has seen the queue as empty
205 * and the transmission path has not yet checked this, the value of
206 * @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
8ceee660
BH
207 */
208struct efx_tx_queue {
209 /* Members which don't change on the fast path */
210 struct efx_nic *efx ____cacheline_aligned_in_smp;
a4900ac9 211 unsigned queue;
8ceee660 212 struct efx_channel *channel;
c04bfc6b 213 struct netdev_queue *core_txq;
8ceee660 214 struct efx_tx_buffer *buffer;
f7251a9c 215 struct efx_buffer *tsoh_page;
8ceee660 216 struct efx_special_buffer txd;
ecc910f5 217 unsigned int ptr_mask;
94b274bf 218 bool initialised;
8ceee660
BH
219
220 /* Members used mainly on the completion path */
221 unsigned int read_count ____cacheline_aligned_in_smp;
cd38557d 222 unsigned int old_write_count;
8ceee660
BH
223
224 /* Members used only on the xmit path */
225 unsigned int insert_count ____cacheline_aligned_in_smp;
226 unsigned int write_count;
227 unsigned int old_read_count;
b9b39b62
BH
228 unsigned int tso_bursts;
229 unsigned int tso_long_headers;
230 unsigned int tso_packets;
cd38557d
BH
231 unsigned int pushes;
232
233 /* Members shared between paths and sometimes updated */
234 unsigned int empty_read_count ____cacheline_aligned_in_smp;
235#define EFX_EMPTY_COUNT_VALID 0x80000000
525d9e82 236 atomic_t flush_outstanding;
8ceee660
BH
237};
238
239/**
240 * struct efx_rx_buffer - An Efx RX data buffer
241 * @dma_addr: DMA base address of the buffer
97d48a10 242 * @page: The associated page buffer.
db339569 243 * Will be %NULL if the buffer slot is currently free.
b74e3e8c
BH
244 * @page_offset: If pending: offset in @page of DMA base address.
245 * If completed: offset in @page of Ethernet header.
80c2e716
BH
246 * @len: If pending: length for DMA descriptor.
247 * If completed: received length, excluding hash prefix.
85740cdf
BH
248 * @flags: Flags for buffer and packet state. These are only set on the
249 * first buffer of a scattered packet.
8ceee660
BH
250 */
251struct efx_rx_buffer {
252 dma_addr_t dma_addr;
97d48a10 253 struct page *page;
b590ace0
BH
254 u16 page_offset;
255 u16 len;
db339569 256 u16 flags;
8ceee660 257};
179ea7f0 258#define EFX_RX_BUF_LAST_IN_PAGE 0x0001
db339569
BH
259#define EFX_RX_PKT_CSUMMED 0x0002
260#define EFX_RX_PKT_DISCARD 0x0004
d07df8ec 261#define EFX_RX_PKT_TCP 0x0040
8ceee660 262
62b330ba
SH
263/**
264 * struct efx_rx_page_state - Page-based rx buffer state
265 *
266 * Inserted at the start of every page allocated for receive buffers.
267 * Used to facilitate sharing dma mappings between recycled rx buffers
268 * and those passed up to the kernel.
269 *
270 * @refcnt: Number of struct efx_rx_buffer's referencing this page.
271 * When refcnt falls to zero, the page is unmapped for dma
272 * @dma_addr: The dma address of this page.
273 */
274struct efx_rx_page_state {
275 unsigned refcnt;
276 dma_addr_t dma_addr;
277
278 unsigned int __pad[0] ____cacheline_aligned;
279};
280
8ceee660
BH
281/**
282 * struct efx_rx_queue - An Efx RX queue
283 * @efx: The associated Efx NIC
79d68b37
SH
284 * @core_index: Index of network core RX queue. Will be >= 0 iff this
285 * is associated with a real RX queue.
8ceee660
BH
286 * @buffer: The software buffer ring
287 * @rxd: The hardware descriptor ring
ecc910f5 288 * @ptr_mask: The size of the ring minus 1.
d8aec745 289 * @refill_enabled: Enable refill whenever fill level is low
9f2cb71c
BH
290 * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
291 * @rxq_flush_pending.
8ceee660
BH
292 * @added_count: Number of buffers added to the receive queue.
293 * @notified_count: Number of buffers given to NIC (<= @added_count).
294 * @removed_count: Number of buffers removed from the receive queue.
85740cdf 295 * @scatter_n: Number of buffers used by current packet
2768935a
DP
296 * @page_ring: The ring to store DMA mapped pages for reuse.
297 * @page_add: Counter to calculate the write pointer for the recycle ring.
298 * @page_remove: Counter to calculate the read pointer for the recycle ring.
299 * @page_recycle_count: The number of pages that have been recycled.
300 * @page_recycle_failed: The number of pages that couldn't be recycled because
301 * the kernel still held a reference to them.
302 * @page_recycle_full: The number of pages that were released because the
303 * recycle ring was full.
304 * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
8ceee660
BH
305 * @max_fill: RX descriptor maximum fill level (<= ring size)
306 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
307 * (<= @max_fill)
8ceee660
BH
308 * @min_fill: RX descriptor minimum non-zero fill level.
309 * This records the minimum fill level observed when a ring
310 * refill was triggered.
2768935a 311 * @recycle_count: RX buffer recycle counter.
90d683af 312 * @slow_fill: Timer used to defer efx_nic_generate_fill_event().
8ceee660
BH
313 */
314struct efx_rx_queue {
315 struct efx_nic *efx;
79d68b37 316 int core_index;
8ceee660
BH
317 struct efx_rx_buffer *buffer;
318 struct efx_special_buffer rxd;
ecc910f5 319 unsigned int ptr_mask;
d8aec745 320 bool refill_enabled;
9f2cb71c 321 bool flush_pending;
8ceee660 322
9bc2fc9b
BH
323 unsigned int added_count;
324 unsigned int notified_count;
325 unsigned int removed_count;
85740cdf 326 unsigned int scatter_n;
2768935a
DP
327 struct page **page_ring;
328 unsigned int page_add;
329 unsigned int page_remove;
330 unsigned int page_recycle_count;
331 unsigned int page_recycle_failed;
332 unsigned int page_recycle_full;
333 unsigned int page_ptr_mask;
8ceee660
BH
334 unsigned int max_fill;
335 unsigned int fast_fill_trigger;
8ceee660
BH
336 unsigned int min_fill;
337 unsigned int min_overfill;
2768935a 338 unsigned int recycle_count;
90d683af 339 struct timer_list slow_fill;
8ceee660 340 unsigned int slow_fill_count;
8ceee660
BH
341};
342
8ceee660
BH
343enum efx_rx_alloc_method {
344 RX_ALLOC_METHOD_AUTO = 0,
345 RX_ALLOC_METHOD_SKB = 1,
346 RX_ALLOC_METHOD_PAGE = 2,
347};
348
349/**
350 * struct efx_channel - An Efx channel
351 *
352 * A channel comprises an event queue, at least one TX queue, at least
353 * one RX queue, and an associated tasklet for processing the event
354 * queue.
355 *
356 * @efx: Associated Efx NIC
8ceee660 357 * @channel: Channel instance number
7f967c01 358 * @type: Channel type definition
be3fc09c 359 * @eventq_init: Event queue initialised flag
8ceee660
BH
360 * @enabled: Channel enabled indicator
361 * @irq: IRQ number (MSI and MSI-X only)
0d86ebd8 362 * @irq_moderation: IRQ moderation value (in hardware ticks)
8ceee660
BH
363 * @napi_dev: Net device used with NAPI
364 * @napi_str: NAPI control structure
8ceee660 365 * @eventq: Event queue buffer
ecc910f5 366 * @eventq_mask: Event queue pointer mask
8ceee660 367 * @eventq_read_ptr: Event queue read pointer
dd40781e 368 * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
6fb70fd1
BH
369 * @irq_count: Number of IRQs since last adaptive moderation decision
370 * @irq_mod_score: IRQ moderation score
8ceee660 371 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
8ceee660
BH
372 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
373 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
c1ac403b 374 * @n_rx_mcast_mismatch: Count of unmatched multicast frames
8ceee660
BH
375 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
376 * @n_rx_overlength: Count of RX_OVERLENGTH errors
377 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
85740cdf
BH
378 * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
379 * lack of descriptors
380 * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
381 * __efx_rx_packet(), or zero if there is none
382 * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
383 * by __efx_rx_packet(), if @rx_pkt_n_frags != 0
8313aca3 384 * @rx_queue: RX queue for this channel
8313aca3 385 * @tx_queue: TX queues for this channel
8ceee660
BH
386 */
387struct efx_channel {
388 struct efx_nic *efx;
8ceee660 389 int channel;
7f967c01 390 const struct efx_channel_type *type;
be3fc09c 391 bool eventq_init;
dc8cfa55 392 bool enabled;
8ceee660 393 int irq;
8ceee660
BH
394 unsigned int irq_moderation;
395 struct net_device *napi_dev;
396 struct napi_struct napi_str;
8ceee660 397 struct efx_special_buffer eventq;
ecc910f5 398 unsigned int eventq_mask;
8ceee660 399 unsigned int eventq_read_ptr;
dd40781e 400 int event_test_cpu;
8ceee660 401
6fb70fd1
BH
402 unsigned int irq_count;
403 unsigned int irq_mod_score;
64d8ad6d
BH
404#ifdef CONFIG_RFS_ACCEL
405 unsigned int rfs_filters_added;
406#endif
6fb70fd1 407
8ceee660 408 unsigned n_rx_tobe_disc;
8ceee660
BH
409 unsigned n_rx_ip_hdr_chksum_err;
410 unsigned n_rx_tcp_udp_chksum_err;
c1ac403b 411 unsigned n_rx_mcast_mismatch;
8ceee660
BH
412 unsigned n_rx_frm_trunc;
413 unsigned n_rx_overlength;
414 unsigned n_skbuff_leaks;
85740cdf 415 unsigned int n_rx_nodesc_trunc;
8ceee660 416
85740cdf
BH
417 unsigned int rx_pkt_n_frags;
418 unsigned int rx_pkt_index;
8ceee660 419
8313aca3 420 struct efx_rx_queue rx_queue;
94b274bf 421 struct efx_tx_queue tx_queue[EFX_TXQ_TYPES];
8ceee660
BH
422};
423
d8291187
BH
424/**
425 * struct efx_msi_context - Context for each MSI
426 * @efx: The associated NIC
427 * @index: Index of the channel/IRQ
428 * @name: Name of the channel/IRQ
429 *
430 * Unlike &struct efx_channel, this is never reallocated and is always
431 * safe for the IRQ handler to access.
432 */
433struct efx_msi_context {
434 struct efx_nic *efx;
435 unsigned int index;
436 char name[IFNAMSIZ + 6];
437};
438
7f967c01
BH
439/**
440 * struct efx_channel_type - distinguishes traffic and extra channels
441 * @handle_no_channel: Handle failure to allocate an extra channel
442 * @pre_probe: Set up extra state prior to initialisation
443 * @post_remove: Tear down extra state after finalisation, if allocated.
444 * May be called on channels that have not been probed.
445 * @get_name: Generate the channel's name (used for its IRQ handler)
446 * @copy: Copy the channel state prior to reallocation. May be %NULL if
447 * reallocation is not supported.
c31e5f9f 448 * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
7f967c01
BH
449 * @keep_eventq: Flag for whether event queue should be kept initialised
450 * while the device is stopped
451 */
452struct efx_channel_type {
453 void (*handle_no_channel)(struct efx_nic *);
454 int (*pre_probe)(struct efx_channel *);
c31e5f9f 455 void (*post_remove)(struct efx_channel *);
7f967c01
BH
456 void (*get_name)(struct efx_channel *, char *buf, size_t len);
457 struct efx_channel *(*copy)(const struct efx_channel *);
4a74dc65 458 bool (*receive_skb)(struct efx_channel *, struct sk_buff *);
7f967c01
BH
459 bool keep_eventq;
460};
461
398468ed
BH
462enum efx_led_mode {
463 EFX_LED_OFF = 0,
464 EFX_LED_ON = 1,
465 EFX_LED_DEFAULT = 2
466};
467
c459302d
BH
468#define STRING_TABLE_LOOKUP(val, member) \
469 ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
470
18e83e4c 471extern const char *const efx_loopback_mode_names[];
c459302d
BH
472extern const unsigned int efx_loopback_mode_max;
473#define LOOPBACK_MODE(efx) \
474 STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_loopback_mode)
475
18e83e4c 476extern const char *const efx_reset_type_names[];
c459302d
BH
477extern const unsigned int efx_reset_type_max;
478#define RESET_TYPE(type) \
479 STRING_TABLE_LOOKUP(type, efx_reset_type)
3273c2e8 480
8ceee660
BH
481enum efx_int_mode {
482 /* Be careful if altering to correct macro below */
483 EFX_INT_MODE_MSIX = 0,
484 EFX_INT_MODE_MSI = 1,
485 EFX_INT_MODE_LEGACY = 2,
486 EFX_INT_MODE_MAX /* Insert any new items before this */
487};
488#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
489
8ceee660 490enum nic_state {
f16aeea0
BH
491 STATE_UNINIT = 0, /* device being probed/removed or is frozen */
492 STATE_READY = 1, /* hardware ready and netdev registered */
493 STATE_DISABLED = 2, /* device disabled due to hardware errors */
626950db 494 STATE_RECOVERY = 3, /* device recovering from PCI error */
8ceee660
BH
495};
496
8ceee660
BH
497/*
498 * Alignment of the skb->head which wraps a page-allocated RX buffer
499 *
500 * The skb allocated to wrap an rx_buffer can have this alignment. Since
501 * the data is memcpy'd from the rx_buf, it does not need to be equal to
c14ff2ea 502 * NET_IP_ALIGN.
8ceee660
BH
503 */
504#define EFX_PAGE_SKB_ALIGN 2
505
506/* Forward declaration */
507struct efx_nic;
508
509/* Pseudo bit-mask flow control field */
b5626946
DM
510#define EFX_FC_RX FLOW_CTRL_RX
511#define EFX_FC_TX FLOW_CTRL_TX
512#define EFX_FC_AUTO 4
8ceee660 513
eb50c0d6
BH
514/**
515 * struct efx_link_state - Current state of the link
516 * @up: Link is up
517 * @fd: Link is full-duplex
518 * @fc: Actual flow control flags
519 * @speed: Link speed (Mbps)
520 */
521struct efx_link_state {
522 bool up;
523 bool fd;
b5626946 524 u8 fc;
eb50c0d6
BH
525 unsigned int speed;
526};
527
fdaa9aed
SH
528static inline bool efx_link_state_equal(const struct efx_link_state *left,
529 const struct efx_link_state *right)
530{
531 return left->up == right->up && left->fd == right->fd &&
532 left->fc == right->fc && left->speed == right->speed;
533}
534
8ceee660
BH
535/**
536 * struct efx_phy_operations - Efx PHY operations table
c1c4f453
BH
537 * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
538 * efx->loopback_modes.
8ceee660
BH
539 * @init: Initialise PHY
540 * @fini: Shut down PHY
541 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
fdaa9aed
SH
542 * @poll: Update @link_state and report whether it changed.
543 * Serialised by the mac_lock.
177dfcd8
BH
544 * @get_settings: Get ethtool settings. Serialised by the mac_lock.
545 * @set_settings: Set ethtool settings. Serialised by the mac_lock.
af4ad9bc 546 * @set_npage_adv: Set abilities advertised in (Extended) Next Page
04cc8cac 547 * (only needed where AN bit is set in mmds)
4f16c073 548 * @test_alive: Test that PHY is 'alive' (online)
c1c4f453 549 * @test_name: Get the name of a PHY-specific test/result
4f16c073 550 * @run_tests: Run tests and record results as appropriate (offline).
1796721a 551 * Flags are the ethtool tests flags.
8ceee660
BH
552 */
553struct efx_phy_operations {
c1c4f453 554 int (*probe) (struct efx_nic *efx);
8ceee660
BH
555 int (*init) (struct efx_nic *efx);
556 void (*fini) (struct efx_nic *efx);
ff3b00a0 557 void (*remove) (struct efx_nic *efx);
d3245b28 558 int (*reconfigure) (struct efx_nic *efx);
fdaa9aed 559 bool (*poll) (struct efx_nic *efx);
177dfcd8
BH
560 void (*get_settings) (struct efx_nic *efx,
561 struct ethtool_cmd *ecmd);
562 int (*set_settings) (struct efx_nic *efx,
563 struct ethtool_cmd *ecmd);
af4ad9bc 564 void (*set_npage_adv) (struct efx_nic *efx, u32);
4f16c073 565 int (*test_alive) (struct efx_nic *efx);
c1c4f453 566 const char *(*test_name) (struct efx_nic *efx, unsigned int index);
1796721a 567 int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
c087bd2c
SH
568 int (*get_module_eeprom) (struct efx_nic *efx,
569 struct ethtool_eeprom *ee,
570 u8 *data);
571 int (*get_module_info) (struct efx_nic *efx,
572 struct ethtool_modinfo *modinfo);
8ceee660
BH
573};
574
f8b87c17 575/**
49ce9c2c 576 * enum efx_phy_mode - PHY operating mode flags
f8b87c17
BH
577 * @PHY_MODE_NORMAL: on and should pass traffic
578 * @PHY_MODE_TX_DISABLED: on with TX disabled
3e133c44
BH
579 * @PHY_MODE_LOW_POWER: set to low power through MDIO
580 * @PHY_MODE_OFF: switched off through external control
f8b87c17
BH
581 * @PHY_MODE_SPECIAL: on but will not pass traffic
582 */
583enum efx_phy_mode {
584 PHY_MODE_NORMAL = 0,
585 PHY_MODE_TX_DISABLED = 1,
3e133c44
BH
586 PHY_MODE_LOW_POWER = 2,
587 PHY_MODE_OFF = 4,
f8b87c17
BH
588 PHY_MODE_SPECIAL = 8,
589};
590
591static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
592{
8c8661e4 593 return !!(mode & ~PHY_MODE_TX_DISABLED);
f8b87c17
BH
594}
595
8ceee660
BH
596/*
597 * Efx extended statistics
598 *
599 * Not all statistics are provided by all supported MACs. The purpose
600 * is this structure is to contain the raw statistics provided by each
601 * MAC.
602 */
603struct efx_mac_stats {
604 u64 tx_bytes;
605 u64 tx_good_bytes;
606 u64 tx_bad_bytes;
f9c76250
BH
607 u64 tx_packets;
608 u64 tx_bad;
609 u64 tx_pause;
610 u64 tx_control;
611 u64 tx_unicast;
612 u64 tx_multicast;
613 u64 tx_broadcast;
614 u64 tx_lt64;
615 u64 tx_64;
616 u64 tx_65_to_127;
617 u64 tx_128_to_255;
618 u64 tx_256_to_511;
619 u64 tx_512_to_1023;
620 u64 tx_1024_to_15xx;
621 u64 tx_15xx_to_jumbo;
622 u64 tx_gtjumbo;
623 u64 tx_collision;
624 u64 tx_single_collision;
625 u64 tx_multiple_collision;
626 u64 tx_excessive_collision;
627 u64 tx_deferred;
628 u64 tx_late_collision;
629 u64 tx_excessive_deferred;
630 u64 tx_non_tcpudp;
631 u64 tx_mac_src_error;
632 u64 tx_ip_src_error;
8ceee660
BH
633 u64 rx_bytes;
634 u64 rx_good_bytes;
635 u64 rx_bad_bytes;
f9c76250
BH
636 u64 rx_packets;
637 u64 rx_good;
638 u64 rx_bad;
639 u64 rx_pause;
640 u64 rx_control;
641 u64 rx_unicast;
642 u64 rx_multicast;
643 u64 rx_broadcast;
644 u64 rx_lt64;
645 u64 rx_64;
646 u64 rx_65_to_127;
647 u64 rx_128_to_255;
648 u64 rx_256_to_511;
649 u64 rx_512_to_1023;
650 u64 rx_1024_to_15xx;
651 u64 rx_15xx_to_jumbo;
652 u64 rx_gtjumbo;
653 u64 rx_bad_lt64;
654 u64 rx_bad_64_to_15xx;
655 u64 rx_bad_15xx_to_jumbo;
656 u64 rx_bad_gtjumbo;
657 u64 rx_overflow;
658 u64 rx_missed;
659 u64 rx_false_carrier;
660 u64 rx_symbol_error;
661 u64 rx_align_error;
662 u64 rx_length_error;
663 u64 rx_internal_error;
664 u64 rx_good_lt64;
8ceee660
BH
665};
666
667/* Number of bits used in a multicast filter hash address */
668#define EFX_MCAST_HASH_BITS 8
669
670/* Number of (single-bit) entries in a multicast filter hash */
671#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
672
673/* An Efx multicast filter hash */
674union efx_multicast_hash {
675 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
676 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
677};
678
64eebcfd 679struct efx_filter_state;
cd2d5b52
BH
680struct efx_vf;
681struct vfdi_status;
64eebcfd 682
8ceee660
BH
683/**
684 * struct efx_nic - an Efx NIC
685 * @name: Device name (net device name or bus id before net device registered)
686 * @pci_dev: The PCI device
687 * @type: Controller type attributes
688 * @legacy_irq: IRQ number
8d9853d9
BH
689 * @workqueue: Workqueue for port reconfigures and the HW monitor.
690 * Work items do not hold and must not acquire RTNL.
6977dc63 691 * @workqueue_name: Name of workqueue
8ceee660 692 * @reset_work: Scheduled reset workitem
8ceee660
BH
693 * @membase_phys: Memory BAR value as physical address
694 * @membase: Memory BAR value
8ceee660 695 * @interrupt_mode: Interrupt mode
cc180b69 696 * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
6fb70fd1
BH
697 * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
698 * @irq_rx_moderation: IRQ moderation time for RX event queues
62776d03 699 * @msg_enable: Log message enable flags
f16aeea0 700 * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
a7d529ae 701 * @reset_pending: Bitmask for pending resets
8ceee660
BH
702 * @tx_queue: TX DMA queues
703 * @rx_queue: RX DMA queues
704 * @channel: Channels
d8291187 705 * @msi_context: Context for each MSI
7f967c01
BH
706 * @extra_channel_types: Types of extra (non-traffic) channels that
707 * should be allocated for this NIC
ecc910f5
SH
708 * @rxq_entries: Size of receive queues requested by user.
709 * @txq_entries: Size of transmit queues requested by user.
14bf718f
BH
710 * @txq_stop_thresh: TX queue fill level at or above which we stop it.
711 * @txq_wake_thresh: TX queue fill level at or below which we wake it.
28e47c49
BH
712 * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
713 * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
714 * @sram_lim_qw: Qword address limit of SRAM
0484e0db 715 * @next_buffer_table: First available buffer table id
28b581ab 716 * @n_channels: Number of channels in use
a4900ac9
BH
717 * @n_rx_channels: Number of channels used for RX (= number of RX queues)
718 * @n_tx_channels: Number of channels used for TX
272baeeb 719 * @rx_dma_len: Current maximum RX DMA length
8ceee660 720 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
85740cdf
BH
721 * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
722 * for use in sk_buff::truesize
78d4189d 723 * @rx_hash_key: Toeplitz hash key for RSS
765c9f46 724 * @rx_indir_table: Indirection table for RSS
85740cdf 725 * @rx_scatter: Scatter mode enabled for receives
0484e0db
BH
726 * @int_error_count: Number of internal errors seen recently
727 * @int_error_expire: Time at which error count will be expired
d8291187
BH
728 * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
729 * acknowledge but do nothing else.
8ceee660 730 * @irq_status: Interrupt status buffer
c28884c5 731 * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
1646a6f3 732 * @irq_level: IRQ level/index for IRQs not triggered by an event queue
dd40781e 733 * @selftest_work: Work item for asynchronous self-test
76884835 734 * @mtd_list: List of MTDs attached to the NIC
25985edc 735 * @nic_data: Hardware dependent state
f3ad5003 736 * @mcdi: Management-Controller-to-Driver Interface state
8c8661e4 737 * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
e4abce85 738 * efx_monitor() and efx_reconfigure_port()
8ceee660 739 * @port_enabled: Port enabled indicator.
fdaa9aed
SH
740 * Serialises efx_stop_all(), efx_start_all(), efx_monitor() and
741 * efx_mac_work() with kernel interfaces. Safe to read under any
742 * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
743 * be held to modify it.
8ceee660
BH
744 * @port_initialized: Port initialized?
745 * @net_dev: Operating system network device. Consider holding the rtnl lock
8ceee660 746 * @stats_buffer: DMA buffer for statistics
8ceee660 747 * @phy_type: PHY type
8ceee660
BH
748 * @phy_op: PHY interface
749 * @phy_data: PHY private data (including PHY-specific stats)
68e7f45e 750 * @mdio: PHY MDIO interface
8880f4ec 751 * @mdio_bus: PHY MDIO bus ID (only used by Siena)
8c8661e4 752 * @phy_mode: PHY operating mode. Serialised by @mac_lock.
d3245b28 753 * @link_advertising: Autonegotiation advertising flags
eb50c0d6 754 * @link_state: Current state of the link
8ceee660
BH
755 * @n_link_state_changes: Number of times the link has changed state
756 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
757 * @multicast_hash: Multicast hash table
04cc8cac 758 * @wanted_fc: Wanted flow control flags
a606f432
SH
759 * @fc_disable: When non-zero flow control is disabled. Typically used to
760 * ensure that network back pressure doesn't delay dma queue flushes.
761 * Serialised by the rtnl lock.
8be4f3e6 762 * @mac_work: Work item for changing MAC promiscuity and multicast hash
3273c2e8
BH
763 * @loopback_mode: Loopback status
764 * @loopback_modes: Supported loopback mode bitmask
765 * @loopback_selftest: Offline self-test private state
9f2cb71c
BH
766 * @drain_pending: Count of RX and TX queues that haven't been flushed and drained.
767 * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
768 * Decremented when the efx_flush_rx_queue() is called.
769 * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
770 * completed (either success or failure). Not used when MCDI is used to
771 * flush receive queues.
772 * @flush_wq: wait queue used by efx_nic_flush_queues() to wait for flush completions.
cd2d5b52
BH
773 * @vf: Array of &struct efx_vf objects.
774 * @vf_count: Number of VFs intended to be enabled.
775 * @vf_init_count: Number of VFs that have been fully initialised.
776 * @vi_scale: log2 number of vnics per VF.
777 * @vf_buftbl_base: The zeroth buffer table index used to back VF queues.
778 * @vfdi_status: Common VFDI status page to be dmad to VF address space.
779 * @local_addr_list: List of local addresses. Protected by %local_lock.
780 * @local_page_list: List of DMA addressable pages used to broadcast
781 * %local_addr_list. Protected by %local_lock.
782 * @local_lock: Mutex protecting %local_addr_list and %local_page_list.
783 * @peer_work: Work item to broadcast peer addresses to VMs.
7c236c43 784 * @ptp_data: PTP state data
ab28c12a
BH
785 * @monitor_work: Hardware monitor workitem
786 * @biu_lock: BIU (bus interface unit) lock
1646a6f3
BH
787 * @last_irq_cpu: Last CPU to handle a possible test interrupt. This
788 * field is used by efx_test_interrupts() to verify that an
789 * interrupt has occurred.
ab28c12a
BH
790 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
791 * @mac_stats: MAC statistics. These include all statistics the MACs
792 * can provide. Generic code converts these into a standard
793 * &struct net_device_stats.
794 * @stats_lock: Statistics update lock. Serialises statistics fetches
1cb34522 795 * and access to @mac_stats.
8ceee660 796 *
754c653a 797 * This is stored in the private area of the &struct net_device.
8ceee660
BH
798 */
799struct efx_nic {
ab28c12a
BH
800 /* The following fields should be written very rarely */
801
8ceee660
BH
802 char name[IFNAMSIZ];
803 struct pci_dev *pci_dev;
6602041b 804 unsigned int port_num;
8ceee660
BH
805 const struct efx_nic_type *type;
806 int legacy_irq;
b28405b0 807 bool eeh_disabled_legacy_irq;
8ceee660 808 struct workqueue_struct *workqueue;
6977dc63 809 char workqueue_name[16];
8ceee660 810 struct work_struct reset_work;
086ea356 811 resource_size_t membase_phys;
8ceee660 812 void __iomem *membase;
ab28c12a 813
8ceee660 814 enum efx_int_mode interrupt_mode;
cc180b69 815 unsigned int timer_quantum_ns;
6fb70fd1
BH
816 bool irq_rx_adaptive;
817 unsigned int irq_rx_moderation;
62776d03 818 u32 msg_enable;
8ceee660 819
8ceee660 820 enum nic_state state;
a7d529ae 821 unsigned long reset_pending;
8ceee660 822
8313aca3 823 struct efx_channel *channel[EFX_MAX_CHANNELS];
d8291187 824 struct efx_msi_context msi_context[EFX_MAX_CHANNELS];
7f967c01
BH
825 const struct efx_channel_type *
826 extra_channel_type[EFX_MAX_EXTRA_CHANNELS];
8ceee660 827
ecc910f5
SH
828 unsigned rxq_entries;
829 unsigned txq_entries;
14bf718f
BH
830 unsigned int txq_stop_thresh;
831 unsigned int txq_wake_thresh;
832
28e47c49
BH
833 unsigned tx_dc_base;
834 unsigned rx_dc_base;
835 unsigned sram_lim_qw;
0484e0db 836 unsigned next_buffer_table;
b105798f
BH
837
838 unsigned int max_channels;
a4900ac9
BH
839 unsigned n_channels;
840 unsigned n_rx_channels;
cd2d5b52 841 unsigned rss_spread;
97653431 842 unsigned tx_channel_offset;
a4900ac9 843 unsigned n_tx_channels;
272baeeb 844 unsigned int rx_dma_len;
8ceee660 845 unsigned int rx_buffer_order;
85740cdf 846 unsigned int rx_buffer_truesize;
1648a23f 847 unsigned int rx_page_buf_step;
2768935a 848 unsigned int rx_bufs_per_page;
1648a23f 849 unsigned int rx_pages_per_batch;
5d3a6fca 850 u8 rx_hash_key[40];
765c9f46 851 u32 rx_indir_table[128];
85740cdf 852 bool rx_scatter;
8ceee660 853
0484e0db
BH
854 unsigned int_error_count;
855 unsigned long int_error_expire;
856
d8291187 857 bool irq_soft_enabled;
8ceee660 858 struct efx_buffer irq_status;
c28884c5 859 unsigned irq_zero_count;
1646a6f3 860 unsigned irq_level;
dd40781e 861 struct delayed_work selftest_work;
8ceee660 862
76884835
BH
863#ifdef CONFIG_SFC_MTD
864 struct list_head mtd_list;
865#endif
4a5b504d 866
8880f4ec 867 void *nic_data;
f3ad5003 868 struct efx_mcdi_data *mcdi;
8ceee660
BH
869
870 struct mutex mac_lock;
766ca0fa 871 struct work_struct mac_work;
dc8cfa55 872 bool port_enabled;
8ceee660 873
dc8cfa55 874 bool port_initialized;
8ceee660 875 struct net_device *net_dev;
8ceee660 876
8ceee660 877 struct efx_buffer stats_buffer;
8ceee660 878
c1c4f453 879 unsigned int phy_type;
6c8c2513 880 const struct efx_phy_operations *phy_op;
8ceee660 881 void *phy_data;
68e7f45e 882 struct mdio_if_info mdio;
8880f4ec 883 unsigned int mdio_bus;
f8b87c17 884 enum efx_phy_mode phy_mode;
8ceee660 885
d3245b28 886 u32 link_advertising;
eb50c0d6 887 struct efx_link_state link_state;
8ceee660
BH
888 unsigned int n_link_state_changes;
889
dc8cfa55 890 bool promiscuous;
8ceee660 891 union efx_multicast_hash multicast_hash;
b5626946 892 u8 wanted_fc;
a606f432 893 unsigned fc_disable;
8ceee660
BH
894
895 atomic_t rx_reset;
3273c2e8 896 enum efx_loopback_mode loopback_mode;
e58f69f4 897 u64 loopback_modes;
3273c2e8
BH
898
899 void *loopback_selftest;
64eebcfd
BH
900
901 struct efx_filter_state *filter_state;
ab28c12a 902
9f2cb71c
BH
903 atomic_t drain_pending;
904 atomic_t rxq_flush_pending;
905 atomic_t rxq_flush_outstanding;
906 wait_queue_head_t flush_wq;
907
cd2d5b52
BH
908#ifdef CONFIG_SFC_SRIOV
909 struct efx_channel *vfdi_channel;
910 struct efx_vf *vf;
911 unsigned vf_count;
912 unsigned vf_init_count;
913 unsigned vi_scale;
914 unsigned vf_buftbl_base;
915 struct efx_buffer vfdi_status;
916 struct list_head local_addr_list;
917 struct list_head local_page_list;
918 struct mutex local_lock;
919 struct work_struct peer_work;
920#endif
921
7c236c43 922 struct efx_ptp_data *ptp_data;
7c236c43 923
ab28c12a
BH
924 /* The following fields may be written more often */
925
926 struct delayed_work monitor_work ____cacheline_aligned_in_smp;
927 spinlock_t biu_lock;
1646a6f3 928 int last_irq_cpu;
ab28c12a
BH
929 unsigned n_rx_nodesc_drop_cnt;
930 struct efx_mac_stats mac_stats;
931 spinlock_t stats_lock;
8ceee660
BH
932};
933
55668611
BH
934static inline int efx_dev_registered(struct efx_nic *efx)
935{
936 return efx->net_dev->reg_state == NETREG_REGISTERED;
937}
938
8880f4ec
BH
939static inline unsigned int efx_port_num(struct efx_nic *efx)
940{
6602041b 941 return efx->port_num;
8880f4ec
BH
942}
943
8ceee660
BH
944/**
945 * struct efx_nic_type - Efx device type definition
b105798f 946 * @mem_map_size: Get memory BAR mapped size
ef2b90ee
BH
947 * @probe: Probe the controller
948 * @remove: Free resources allocated by probe()
949 * @init: Initialise the controller
28e47c49
BH
950 * @dimension_resources: Dimension controller resources (buffer table,
951 * and VIs once the available interrupt resources are clear)
ef2b90ee
BH
952 * @fini: Shut down the controller
953 * @monitor: Periodic function for polling link state and hardware monitor
0e2a9c7c
BH
954 * @map_reset_reason: Map ethtool reset reason to a reset method
955 * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
ef2b90ee
BH
956 * @reset: Reset the controller hardware and possibly the PHY. This will
957 * be called while the controller is uninitialised.
958 * @probe_port: Probe the MAC and PHY
959 * @remove_port: Free resources allocated by probe_port()
40641ed9 960 * @handle_global_event: Handle a "global" event (may be %NULL)
e42c3d85 961 * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
ef2b90ee 962 * @prepare_flush: Prepare the hardware for flushing the DMA queues
e42c3d85
BH
963 * (for Falcon architecture)
964 * @finish_flush: Clean up after flushing the DMA queues (for Falcon
965 * architecture)
ef2b90ee
BH
966 * @update_stats: Update statistics not provided by event handling
967 * @start_stats: Start the regular fetching of statistics
968 * @stop_stats: Stop the regular fetching of statistics
06629f07 969 * @set_id_led: Set state of identifying LED or revert to automatic function
ef2b90ee 970 * @push_irq_moderation: Apply interrupt moderation value
d3245b28 971 * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
9dd3a13b 972 * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
30b81cda
BH
973 * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
974 * to the hardware. Serialised by the mac_lock.
710b208d 975 * @check_mac_fault: Check MAC fault state. True if fault present.
89c758fa
BH
976 * @get_wol: Get WoL configuration from driver state
977 * @set_wol: Push WoL configuration to the NIC
978 * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
86094f7f 979 * @test_chip: Test registers. May use efx_farch_test_registers(), and is
d4f2cecc 980 * expected to reset the NIC.
0aa3fbaa 981 * @test_nvram: Test validity of NVRAM contents
f3ad5003
BH
982 * @mcdi_request: Send an MCDI request with the given header and SDU.
983 * The SDU length may be any value from 0 up to the protocol-
984 * defined maximum, but its buffer will be padded to a multiple
985 * of 4 bytes.
986 * @mcdi_poll_response: Test whether an MCDI response is available.
987 * @mcdi_read_response: Read the MCDI response PDU. The offset will
988 * be a multiple of 4. The length may not be, but the buffer
989 * will be padded so it is safe to round up.
990 * @mcdi_poll_reboot: Test whether the MCDI has rebooted. If so,
991 * return an appropriate error code for aborting any current
992 * request; otherwise return 0.
86094f7f
BH
993 * @irq_enable_master: Enable IRQs on the NIC. Each event queue must
994 * be separately enabled after this.
995 * @irq_test_generate: Generate a test IRQ
996 * @irq_disable_non_ev: Disable non-event IRQs on the NIC. Each event
997 * queue must be separately disabled before this.
998 * @irq_handle_msi: Handle MSI for a channel. The @dev_id argument is
999 * a pointer to the &struct efx_msi_context for the channel.
1000 * @irq_handle_legacy: Handle legacy interrupt. The @dev_id argument
1001 * is a pointer to the &struct efx_nic.
1002 * @tx_probe: Allocate resources for TX queue
1003 * @tx_init: Initialise TX queue on the NIC
1004 * @tx_remove: Free resources for TX queue
1005 * @tx_write: Write TX descriptors and doorbell
1006 * @rx_push_indir_table: Write RSS indirection table to the NIC
1007 * @rx_probe: Allocate resources for RX queue
1008 * @rx_init: Initialise RX queue on the NIC
1009 * @rx_remove: Free resources for RX queue
1010 * @rx_write: Write RX descriptors and doorbell
1011 * @rx_defer_refill: Generate a refill reminder event
1012 * @ev_probe: Allocate resources for event queue
1013 * @ev_init: Initialise event queue on the NIC
1014 * @ev_fini: Deinitialise event queue on the NIC
1015 * @ev_remove: Free resources for event queue
1016 * @ev_process: Process events for a queue, up to the given NAPI quota
1017 * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
1018 * @ev_test_generate: Generate a test event
daeda630 1019 * @revision: Hardware architecture revision
8ceee660
BH
1020 * @txd_ptr_tbl_base: TX descriptor ring base address
1021 * @rxd_ptr_tbl_base: RX descriptor ring base address
1022 * @buf_tbl_base: Buffer table base address
1023 * @evq_ptr_tbl_base: Event queue pointer table base address
1024 * @evq_rptr_tbl_base: Event queue read-pointer table base address
8ceee660 1025 * @max_dma_mask: Maximum possible DMA mask
85740cdf
BH
1026 * @rx_buffer_hash_size: Size of hash at start of RX packet
1027 * @rx_buffer_padding: Size of padding at end of RX packet
1028 * @can_rx_scatter: NIC is able to scatter packet to multiple buffers
8ceee660
BH
1029 * @max_interrupt_mode: Highest capability interrupt mode supported
1030 * from &enum efx_init_mode.
cc180b69 1031 * @timer_period_max: Maximum period of interrupt timer (in ticks)
c383b537
BH
1032 * @offload_features: net_device feature flags for protocol offload
1033 * features implemented in hardware
df2cd8af 1034 * @mcdi_max_ver: Maximum MCDI version supported
8ceee660
BH
1035 */
1036struct efx_nic_type {
b105798f 1037 unsigned int (*mem_map_size)(struct efx_nic *efx);
ef2b90ee
BH
1038 int (*probe)(struct efx_nic *efx);
1039 void (*remove)(struct efx_nic *efx);
1040 int (*init)(struct efx_nic *efx);
28e47c49 1041 void (*dimension_resources)(struct efx_nic *efx);
ef2b90ee
BH
1042 void (*fini)(struct efx_nic *efx);
1043 void (*monitor)(struct efx_nic *efx);
0e2a9c7c
BH
1044 enum reset_type (*map_reset_reason)(enum reset_type reason);
1045 int (*map_reset_flags)(u32 *flags);
ef2b90ee
BH
1046 int (*reset)(struct efx_nic *efx, enum reset_type method);
1047 int (*probe_port)(struct efx_nic *efx);
1048 void (*remove_port)(struct efx_nic *efx);
40641ed9 1049 bool (*handle_global_event)(struct efx_channel *channel, efx_qword_t *);
e42c3d85 1050 int (*fini_dmaq)(struct efx_nic *efx);
ef2b90ee 1051 void (*prepare_flush)(struct efx_nic *efx);
d5e8cc6c 1052 void (*finish_flush)(struct efx_nic *efx);
ef2b90ee
BH
1053 void (*update_stats)(struct efx_nic *efx);
1054 void (*start_stats)(struct efx_nic *efx);
1055 void (*stop_stats)(struct efx_nic *efx);
06629f07 1056 void (*set_id_led)(struct efx_nic *efx, enum efx_led_mode mode);
ef2b90ee 1057 void (*push_irq_moderation)(struct efx_channel *channel);
d3245b28 1058 int (*reconfigure_port)(struct efx_nic *efx);
9dd3a13b 1059 void (*prepare_enable_fc_tx)(struct efx_nic *efx);
710b208d
BH
1060 int (*reconfigure_mac)(struct efx_nic *efx);
1061 bool (*check_mac_fault)(struct efx_nic *efx);
89c758fa
BH
1062 void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
1063 int (*set_wol)(struct efx_nic *efx, u32 type);
1064 void (*resume_wol)(struct efx_nic *efx);
d4f2cecc 1065 int (*test_chip)(struct efx_nic *efx, struct efx_self_tests *tests);
0aa3fbaa 1066 int (*test_nvram)(struct efx_nic *efx);
f3ad5003
BH
1067 void (*mcdi_request)(struct efx_nic *efx,
1068 const efx_dword_t *hdr, size_t hdr_len,
1069 const efx_dword_t *sdu, size_t sdu_len);
1070 bool (*mcdi_poll_response)(struct efx_nic *efx);
1071 void (*mcdi_read_response)(struct efx_nic *efx, efx_dword_t *pdu,
1072 size_t pdu_offset, size_t pdu_len);
1073 int (*mcdi_poll_reboot)(struct efx_nic *efx);
86094f7f
BH
1074 void (*irq_enable_master)(struct efx_nic *efx);
1075 void (*irq_test_generate)(struct efx_nic *efx);
1076 void (*irq_disable_non_ev)(struct efx_nic *efx);
1077 irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
1078 irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
1079 int (*tx_probe)(struct efx_tx_queue *tx_queue);
1080 void (*tx_init)(struct efx_tx_queue *tx_queue);
1081 void (*tx_remove)(struct efx_tx_queue *tx_queue);
1082 void (*tx_write)(struct efx_tx_queue *tx_queue);
1083 void (*rx_push_indir_table)(struct efx_nic *efx);
1084 int (*rx_probe)(struct efx_rx_queue *rx_queue);
1085 void (*rx_init)(struct efx_rx_queue *rx_queue);
1086 void (*rx_remove)(struct efx_rx_queue *rx_queue);
1087 void (*rx_write)(struct efx_rx_queue *rx_queue);
1088 void (*rx_defer_refill)(struct efx_rx_queue *rx_queue);
1089 int (*ev_probe)(struct efx_channel *channel);
1090 void (*ev_init)(struct efx_channel *channel);
1091 void (*ev_fini)(struct efx_channel *channel);
1092 void (*ev_remove)(struct efx_channel *channel);
1093 int (*ev_process)(struct efx_channel *channel, int quota);
1094 void (*ev_read_ack)(struct efx_channel *channel);
1095 void (*ev_test_generate)(struct efx_channel *channel);
b895d73e 1096
daeda630 1097 int revision;
8ceee660
BH
1098 unsigned int txd_ptr_tbl_base;
1099 unsigned int rxd_ptr_tbl_base;
1100 unsigned int buf_tbl_base;
1101 unsigned int evq_ptr_tbl_base;
1102 unsigned int evq_rptr_tbl_base;
9bbd7d9a 1103 u64 max_dma_mask;
39c9cf07 1104 unsigned int rx_buffer_hash_size;
8ceee660 1105 unsigned int rx_buffer_padding;
85740cdf 1106 bool can_rx_scatter;
8ceee660 1107 unsigned int max_interrupt_mode;
cc180b69 1108 unsigned int timer_period_max;
c8f44aff 1109 netdev_features_t offload_features;
df2cd8af 1110 int mcdi_max_ver;
8ceee660
BH
1111};
1112
1113/**************************************************************************
1114 *
1115 * Prototypes and inline functions
1116 *
1117 *************************************************************************/
1118
f7d12cdc
BH
1119static inline struct efx_channel *
1120efx_get_channel(struct efx_nic *efx, unsigned index)
1121{
1122 EFX_BUG_ON_PARANOID(index >= efx->n_channels);
8313aca3 1123 return efx->channel[index];
f7d12cdc
BH
1124}
1125
8ceee660
BH
1126/* Iterate over all used channels */
1127#define efx_for_each_channel(_channel, _efx) \
8313aca3
BH
1128 for (_channel = (_efx)->channel[0]; \
1129 _channel; \
1130 _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
1131 (_efx)->channel[_channel->channel + 1] : NULL)
8ceee660 1132
7f967c01
BH
1133/* Iterate over all used channels in reverse */
1134#define efx_for_each_channel_rev(_channel, _efx) \
1135 for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \
1136 _channel; \
1137 _channel = _channel->channel ? \
1138 (_efx)->channel[_channel->channel - 1] : NULL)
1139
97653431
BH
1140static inline struct efx_tx_queue *
1141efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)
1142{
1143 EFX_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
1144 type >= EFX_TXQ_TYPES);
1145 return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
1146}
f7d12cdc 1147
525da907
BH
1148static inline bool efx_channel_has_tx_queues(struct efx_channel *channel)
1149{
1150 return channel->channel - channel->efx->tx_channel_offset <
1151 channel->efx->n_tx_channels;
1152}
1153
f7d12cdc
BH
1154static inline struct efx_tx_queue *
1155efx_channel_get_tx_queue(struct efx_channel *channel, unsigned type)
1156{
525da907
BH
1157 EFX_BUG_ON_PARANOID(!efx_channel_has_tx_queues(channel) ||
1158 type >= EFX_TXQ_TYPES);
1159 return &channel->tx_queue[type];
f7d12cdc 1160}
8ceee660 1161
94b274bf
BH
1162static inline bool efx_tx_queue_used(struct efx_tx_queue *tx_queue)
1163{
1164 return !(tx_queue->efx->net_dev->num_tc < 2 &&
1165 tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI);
1166}
1167
8ceee660
BH
1168/* Iterate over all TX queues belonging to a channel */
1169#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
525da907
BH
1170 if (!efx_channel_has_tx_queues(_channel)) \
1171 ; \
1172 else \
1173 for (_tx_queue = (_channel)->tx_queue; \
94b274bf
BH
1174 _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES && \
1175 efx_tx_queue_used(_tx_queue); \
525da907 1176 _tx_queue++)
8ceee660 1177
94b274bf
BH
1178/* Iterate over all possible TX queues belonging to a channel */
1179#define efx_for_each_possible_channel_tx_queue(_tx_queue, _channel) \
73e0026f
BH
1180 if (!efx_channel_has_tx_queues(_channel)) \
1181 ; \
1182 else \
1183 for (_tx_queue = (_channel)->tx_queue; \
1184 _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES; \
1185 _tx_queue++)
94b274bf 1186
525da907
BH
1187static inline bool efx_channel_has_rx_queue(struct efx_channel *channel)
1188{
79d68b37 1189 return channel->rx_queue.core_index >= 0;
525da907
BH
1190}
1191
f7d12cdc
BH
1192static inline struct efx_rx_queue *
1193efx_channel_get_rx_queue(struct efx_channel *channel)
1194{
525da907
BH
1195 EFX_BUG_ON_PARANOID(!efx_channel_has_rx_queue(channel));
1196 return &channel->rx_queue;
f7d12cdc
BH
1197}
1198
8ceee660
BH
1199/* Iterate over all RX queues belonging to a channel */
1200#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
525da907
BH
1201 if (!efx_channel_has_rx_queue(_channel)) \
1202 ; \
1203 else \
1204 for (_rx_queue = &(_channel)->rx_queue; \
1205 _rx_queue; \
1206 _rx_queue = NULL)
8ceee660 1207
ba1e8a35
BH
1208static inline struct efx_channel *
1209efx_rx_queue_channel(struct efx_rx_queue *rx_queue)
1210{
8313aca3 1211 return container_of(rx_queue, struct efx_channel, rx_queue);
ba1e8a35
BH
1212}
1213
1214static inline int efx_rx_queue_index(struct efx_rx_queue *rx_queue)
1215{
8313aca3 1216 return efx_rx_queue_channel(rx_queue)->channel;
ba1e8a35
BH
1217}
1218
8ceee660
BH
1219/* Returns a pointer to the specified receive buffer in the RX
1220 * descriptor queue.
1221 */
1222static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
1223 unsigned int index)
1224{
807540ba 1225 return &rx_queue->buffer[index];
8ceee660
BH
1226}
1227
8ceee660
BH
1228
1229/**
1230 * EFX_MAX_FRAME_LEN - calculate maximum frame length
1231 *
1232 * This calculates the maximum frame length that will be used for a
1233 * given MTU. The frame length will be equal to the MTU plus a
1234 * constant amount of header space and padding. This is the quantity
1235 * that the net driver will program into the MAC as the maximum frame
1236 * length.
1237 *
754c653a 1238 * The 10G MAC requires 8-byte alignment on the frame
8ceee660 1239 * length, so we round up to the nearest 8.
cc11763b
BH
1240 *
1241 * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
1242 * XGMII cycle). If the frame length reaches the maximum value in the
1243 * same cycle, the XMAC can miss the IPG altogether. We work around
1244 * this by adding a further 16 bytes.
8ceee660
BH
1245 */
1246#define EFX_MAX_FRAME_LEN(mtu) \
cc11763b 1247 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */ + 7) & ~7) + 16)
8ceee660 1248
7c236c43
SH
1249static inline bool efx_xmit_with_hwtstamp(struct sk_buff *skb)
1250{
1251 return skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP;
1252}
1253static inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)
1254{
1255 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
1256}
8ceee660
BH
1257
1258#endif /* EFX_NET_DRIVER_H */
This page took 3.776151 seconds and 5 git commands to generate.