sfc: Move shared members of struct falcon_nic_data into struct efx_nic
[deliverable/linux.git] / drivers / net / sfc / net_driver.h
CommitLineData
8ceee660
BH
1/****************************************************************************
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>
68e7f45e 22#include <linux/mdio.h>
8ceee660
BH
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>
37b5a603 28#include <linux/i2c.h>
8ceee660
BH
29
30#include "enum.h"
31#include "bitfield.h"
8ceee660 32
8ceee660
BH
33/**************************************************************************
34 *
35 * Build definitions
36 *
37 **************************************************************************/
38#ifndef EFX_DRIVER_NAME
39#define EFX_DRIVER_NAME "sfc"
40#endif
a7a81fc0 41#define EFX_DRIVER_VERSION "2.3"
8ceee660
BH
42
43#ifdef EFX_ENABLE_DEBUG
44#define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
45#define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
46#else
47#define EFX_BUG_ON_PARANOID(x) do {} while (0)
48#define EFX_WARN_ON_PARANOID(x) do {} while (0)
49#endif
50
8ceee660
BH
51/* Un-rate-limited logging */
52#define EFX_ERR(efx, fmt, args...) \
55668611 53dev_err(&((efx)->pci_dev->dev), "ERR: %s " fmt, efx_dev_name(efx), ##args)
8ceee660
BH
54
55#define EFX_INFO(efx, fmt, args...) \
55668611 56dev_info(&((efx)->pci_dev->dev), "INFO: %s " fmt, efx_dev_name(efx), ##args)
8ceee660
BH
57
58#ifdef EFX_ENABLE_DEBUG
59#define EFX_LOG(efx, fmt, args...) \
55668611 60dev_info(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
8ceee660
BH
61#else
62#define EFX_LOG(efx, fmt, args...) \
55668611 63dev_dbg(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
8ceee660
BH
64#endif
65
66#define EFX_TRACE(efx, fmt, args...) do {} while (0)
67
68#define EFX_REGDUMP(efx, fmt, args...) do {} while (0)
69
70/* Rate-limited logging */
71#define EFX_ERR_RL(efx, fmt, args...) \
72do {if (net_ratelimit()) EFX_ERR(efx, fmt, ##args); } while (0)
73
74#define EFX_INFO_RL(efx, fmt, args...) \
75do {if (net_ratelimit()) EFX_INFO(efx, fmt, ##args); } while (0)
76
77#define EFX_LOG_RL(efx, fmt, args...) \
78do {if (net_ratelimit()) EFX_LOG(efx, fmt, ##args); } while (0)
79
8ceee660
BH
80/**************************************************************************
81 *
82 * Efx data structures
83 *
84 **************************************************************************/
85
86#define EFX_MAX_CHANNELS 32
8ceee660
BH
87#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
88
60ac1065
BH
89#define EFX_TX_QUEUE_OFFLOAD_CSUM 0
90#define EFX_TX_QUEUE_NO_CSUM 1
91#define EFX_TX_QUEUE_COUNT 2
92
8ceee660
BH
93/**
94 * struct efx_special_buffer - An Efx special buffer
95 * @addr: CPU base address of the buffer
96 * @dma_addr: DMA base address of the buffer
97 * @len: Buffer length, in bytes
98 * @index: Buffer index within controller;s buffer table
99 * @entries: Number of buffer table entries
100 *
101 * Special buffers are used for the event queues and the TX and RX
102 * descriptor queues for each channel. They are *not* used for the
103 * actual transmit and receive buffers.
104 *
105 * Note that for Falcon, TX and RX descriptor queues live in host memory.
106 * Allocation and freeing procedures must take this into account.
107 */
108struct efx_special_buffer {
109 void *addr;
110 dma_addr_t dma_addr;
111 unsigned int len;
112 int index;
113 int entries;
114};
115
116/**
117 * struct efx_tx_buffer - An Efx TX buffer
118 * @skb: The associated socket buffer.
119 * Set only on the final fragment of a packet; %NULL for all other
120 * fragments. When this fragment completes, then we can free this
121 * skb.
b9b39b62
BH
122 * @tsoh: The associated TSO header structure, or %NULL if this
123 * buffer is not a TSO header.
8ceee660
BH
124 * @dma_addr: DMA address of the fragment.
125 * @len: Length of this fragment.
126 * This field is zero when the queue slot is empty.
127 * @continuation: True if this fragment is not the end of a packet.
128 * @unmap_single: True if pci_unmap_single should be used.
8ceee660
BH
129 * @unmap_len: Length of this fragment to unmap
130 */
131struct efx_tx_buffer {
132 const struct sk_buff *skb;
b9b39b62 133 struct efx_tso_header *tsoh;
8ceee660
BH
134 dma_addr_t dma_addr;
135 unsigned short len;
dc8cfa55
BH
136 bool continuation;
137 bool unmap_single;
8ceee660
BH
138 unsigned short unmap_len;
139};
140
141/**
142 * struct efx_tx_queue - An Efx TX queue
143 *
144 * This is a ring buffer of TX fragments.
145 * Since the TX completion path always executes on the same
146 * CPU and the xmit path can operate on different CPUs,
147 * performance is increased by ensuring that the completion
148 * path and the xmit path operate on different cache lines.
149 * This is particularly important if the xmit path is always
150 * executing on one CPU which is different from the completion
151 * path. There is also a cache line for members which are
152 * read but not written on the fast path.
153 *
154 * @efx: The associated Efx NIC
155 * @queue: DMA queue number
8ceee660
BH
156 * @channel: The associated channel
157 * @buffer: The software buffer ring
158 * @txd: The hardware descriptor ring
6bc5d3a9 159 * @flushed: Used when handling queue flushing
8ceee660
BH
160 * @read_count: Current read pointer.
161 * This is the number of buffers that have been removed from both rings.
dc8cfa55 162 * @stopped: Stopped count.
8ceee660
BH
163 * Set if this TX queue is currently stopping its port.
164 * @insert_count: Current insert pointer
165 * This is the number of buffers that have been added to the
166 * software ring.
167 * @write_count: Current write pointer
168 * This is the number of buffers that have been added to the
169 * hardware ring.
170 * @old_read_count: The value of read_count when last checked.
171 * This is here for performance reasons. The xmit path will
172 * only get the up-to-date value of read_count if this
173 * variable indicates that the queue is full. This is to
174 * avoid cache-line ping-pong between the xmit path and the
175 * completion path.
b9b39b62
BH
176 * @tso_headers_free: A list of TSO headers allocated for this TX queue
177 * that are not in use, and so available for new TSO sends. The list
178 * is protected by the TX queue lock.
179 * @tso_bursts: Number of times TSO xmit invoked by kernel
180 * @tso_long_headers: Number of packets with headers too long for standard
181 * blocks
182 * @tso_packets: Number of packets via the TSO xmit path
8ceee660
BH
183 */
184struct efx_tx_queue {
185 /* Members which don't change on the fast path */
186 struct efx_nic *efx ____cacheline_aligned_in_smp;
187 int queue;
8ceee660
BH
188 struct efx_channel *channel;
189 struct efx_nic *nic;
190 struct efx_tx_buffer *buffer;
191 struct efx_special_buffer txd;
6bc5d3a9 192 bool flushed;
8ceee660
BH
193
194 /* Members used mainly on the completion path */
195 unsigned int read_count ____cacheline_aligned_in_smp;
196 int stopped;
197
198 /* Members used only on the xmit path */
199 unsigned int insert_count ____cacheline_aligned_in_smp;
200 unsigned int write_count;
201 unsigned int old_read_count;
b9b39b62
BH
202 struct efx_tso_header *tso_headers_free;
203 unsigned int tso_bursts;
204 unsigned int tso_long_headers;
205 unsigned int tso_packets;
8ceee660
BH
206};
207
208/**
209 * struct efx_rx_buffer - An Efx RX data buffer
210 * @dma_addr: DMA base address of the buffer
211 * @skb: The associated socket buffer, if any.
212 * If both this and page are %NULL, the buffer slot is currently free.
213 * @page: The associated page buffer, if any.
214 * If both this and skb are %NULL, the buffer slot is currently free.
215 * @data: Pointer to ethernet header
216 * @len: Buffer length, in bytes.
217 * @unmap_addr: DMA address to unmap
218 */
219struct efx_rx_buffer {
220 dma_addr_t dma_addr;
221 struct sk_buff *skb;
222 struct page *page;
223 char *data;
224 unsigned int len;
225 dma_addr_t unmap_addr;
226};
227
228/**
229 * struct efx_rx_queue - An Efx RX queue
230 * @efx: The associated Efx NIC
231 * @queue: DMA queue number
8ceee660
BH
232 * @channel: The associated channel
233 * @buffer: The software buffer ring
234 * @rxd: The hardware descriptor ring
235 * @added_count: Number of buffers added to the receive queue.
236 * @notified_count: Number of buffers given to NIC (<= @added_count).
237 * @removed_count: Number of buffers removed from the receive queue.
238 * @add_lock: Receive queue descriptor add spin lock.
239 * This lock must be held in order to add buffers to the RX
240 * descriptor ring (rxd and buffer) and to update added_count (but
241 * not removed_count).
242 * @max_fill: RX descriptor maximum fill level (<= ring size)
243 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
244 * (<= @max_fill)
245 * @fast_fill_limit: The level to which a fast fill will fill
246 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
247 * @min_fill: RX descriptor minimum non-zero fill level.
248 * This records the minimum fill level observed when a ring
249 * refill was triggered.
250 * @min_overfill: RX descriptor minimum overflow fill level.
251 * This records the minimum fill level at which RX queue
252 * overflow was observed. It should never be set.
253 * @alloc_page_count: RX allocation strategy counter.
254 * @alloc_skb_count: RX allocation strategy counter.
255 * @work: Descriptor push work thread
256 * @buf_page: Page for next RX buffer.
257 * We can use a single page for multiple RX buffers. This tracks
258 * the remaining space in the allocation.
259 * @buf_dma_addr: Page's DMA address.
260 * @buf_data: Page's host address.
6bc5d3a9 261 * @flushed: Use when handling queue flushing
8ceee660
BH
262 */
263struct efx_rx_queue {
264 struct efx_nic *efx;
265 int queue;
8ceee660
BH
266 struct efx_channel *channel;
267 struct efx_rx_buffer *buffer;
268 struct efx_special_buffer rxd;
269
270 int added_count;
271 int notified_count;
272 int removed_count;
273 spinlock_t add_lock;
274 unsigned int max_fill;
275 unsigned int fast_fill_trigger;
276 unsigned int fast_fill_limit;
277 unsigned int min_fill;
278 unsigned int min_overfill;
279 unsigned int alloc_page_count;
280 unsigned int alloc_skb_count;
281 struct delayed_work work;
282 unsigned int slow_fill_count;
283
284 struct page *buf_page;
285 dma_addr_t buf_dma_addr;
286 char *buf_data;
6bc5d3a9 287 bool flushed;
8ceee660
BH
288};
289
290/**
291 * struct efx_buffer - An Efx general-purpose buffer
292 * @addr: host base address of the buffer
293 * @dma_addr: DMA base address of the buffer
294 * @len: Buffer length, in bytes
295 *
296 * Falcon uses these buffers for its interrupt status registers and
297 * MAC stats dumps.
298 */
299struct efx_buffer {
300 void *addr;
301 dma_addr_t dma_addr;
302 unsigned int len;
303};
304
305
306/* Flags for channel->used_flags */
307#define EFX_USED_BY_RX 1
308#define EFX_USED_BY_TX 2
309#define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
310
311enum efx_rx_alloc_method {
312 RX_ALLOC_METHOD_AUTO = 0,
313 RX_ALLOC_METHOD_SKB = 1,
314 RX_ALLOC_METHOD_PAGE = 2,
315};
316
317/**
318 * struct efx_channel - An Efx channel
319 *
320 * A channel comprises an event queue, at least one TX queue, at least
321 * one RX queue, and an associated tasklet for processing the event
322 * queue.
323 *
324 * @efx: Associated Efx NIC
8ceee660 325 * @channel: Channel instance number
56536e9c 326 * @name: Name for channel and IRQ
8ceee660
BH
327 * @used_flags: Channel is used by net driver
328 * @enabled: Channel enabled indicator
329 * @irq: IRQ number (MSI and MSI-X only)
8ceee660
BH
330 * @irq_moderation: IRQ moderation value (in us)
331 * @napi_dev: Net device used with NAPI
332 * @napi_str: NAPI control structure
333 * @reset_work: Scheduled reset work thread
334 * @work_pending: Is work pending via NAPI?
335 * @eventq: Event queue buffer
336 * @eventq_read_ptr: Event queue read pointer
337 * @last_eventq_read_ptr: Last event queue read pointer value.
338 * @eventq_magic: Event queue magic value for driver-generated test events
6fb70fd1
BH
339 * @irq_count: Number of IRQs since last adaptive moderation decision
340 * @irq_mod_score: IRQ moderation score
8ceee660
BH
341 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
342 * and diagnostic counters
343 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
344 * descriptors
8ceee660
BH
345 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
346 * @n_rx_ip_frag_err: Count of RX IP fragment errors
347 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
348 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
349 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
350 * @n_rx_overlength: Count of RX_OVERLENGTH errors
351 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
352 */
353struct efx_channel {
354 struct efx_nic *efx;
8ceee660 355 int channel;
56536e9c 356 char name[IFNAMSIZ + 6];
8ceee660 357 int used_flags;
dc8cfa55 358 bool enabled;
8ceee660 359 int irq;
8ceee660
BH
360 unsigned int irq_moderation;
361 struct net_device *napi_dev;
362 struct napi_struct napi_str;
dc8cfa55 363 bool work_pending;
8ceee660
BH
364 struct efx_special_buffer eventq;
365 unsigned int eventq_read_ptr;
366 unsigned int last_eventq_read_ptr;
367 unsigned int eventq_magic;
368
6fb70fd1
BH
369 unsigned int irq_count;
370 unsigned int irq_mod_score;
371
8ceee660
BH
372 int rx_alloc_level;
373 int rx_alloc_push_pages;
8ceee660
BH
374
375 unsigned n_rx_tobe_disc;
376 unsigned n_rx_ip_frag_err;
377 unsigned n_rx_ip_hdr_chksum_err;
378 unsigned n_rx_tcp_udp_chksum_err;
379 unsigned n_rx_frm_trunc;
380 unsigned n_rx_overlength;
381 unsigned n_skbuff_leaks;
382
383 /* Used to pipeline received packets in order to optimise memory
384 * access with prefetches.
385 */
386 struct efx_rx_buffer *rx_pkt;
dc8cfa55 387 bool rx_pkt_csummed;
8ceee660
BH
388
389};
390
8ceee660
BH
391/**
392 * struct efx_board - board information
393 * @type: Board model type
394 * @major: Major rev. ('A', 'B' ...)
395 * @minor: Minor rev. (0, 1, ...)
396 * @init: Initialisation function
8129d217
BH
397 * @init_leds: Sets up board LEDs. May be called repeatedly.
398 * @set_id_led: Turns the identification LED on or off
8ceee660 399 * @blink: Starts/stops blinking
3e133c44 400 * @monitor: Board-specific health check function
37b5a603 401 * @fini: Cleanup function
7d4cdb5a
BH
402 * @blink_state: Current blink state
403 * @blink_resubmit: Blink timer resubmission flag
404 * @blink_timer: Blink timer
37b5a603
BH
405 * @hwmon_client: I2C client for hardware monitor
406 * @ioexp_client: I2C client for power/port control
8ceee660
BH
407 */
408struct efx_board {
409 int type;
410 int major;
411 int minor;
412 int (*init) (struct efx_nic *nic);
413 /* As the LEDs are typically attached to the PHY, LEDs
414 * have a separate init callback that happens later than
415 * board init. */
8129d217
BH
416 void (*init_leds)(struct efx_nic *efx);
417 void (*set_id_led) (struct efx_nic *efx, bool state);
3e133c44 418 int (*monitor) (struct efx_nic *nic);
dc8cfa55 419 void (*blink) (struct efx_nic *efx, bool start);
37b5a603 420 void (*fini) (struct efx_nic *nic);
7d4cdb5a
BH
421 bool blink_state;
422 bool blink_resubmit;
423 struct timer_list blink_timer;
37b5a603 424 struct i2c_client *hwmon_client, *ioexp_client;
8ceee660
BH
425};
426
3273c2e8
BH
427#define STRING_TABLE_LOOKUP(val, member) \
428 member ## _names[val]
429
8ceee660
BH
430enum efx_int_mode {
431 /* Be careful if altering to correct macro below */
432 EFX_INT_MODE_MSIX = 0,
433 EFX_INT_MODE_MSI = 1,
434 EFX_INT_MODE_LEGACY = 2,
435 EFX_INT_MODE_MAX /* Insert any new items before this */
436};
437#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
438
439enum phy_type {
440 PHY_TYPE_NONE = 0,
ab377358
BH
441 PHY_TYPE_TXC43128 = 1,
442 PHY_TYPE_88E1111 = 2,
e6fa2eb7 443 PHY_TYPE_SFX7101 = 3,
ab377358 444 PHY_TYPE_QT2022C2 = 4,
8ceee660 445 PHY_TYPE_PM8358 = 6,
e6fa2eb7 446 PHY_TYPE_SFT9001A = 8,
d2d2c373 447 PHY_TYPE_QT2025C = 9,
e6fa2eb7 448 PHY_TYPE_SFT9001B = 10,
8ceee660
BH
449 PHY_TYPE_MAX /* Insert any new items before this */
450};
451
177dfcd8
BH
452#define EFX_IS10G(efx) ((efx)->link_speed == 10000)
453
8ceee660
BH
454enum nic_state {
455 STATE_INIT = 0,
456 STATE_RUNNING = 1,
457 STATE_FINI = 2,
3c78708f 458 STATE_DISABLED = 3,
8ceee660
BH
459 STATE_MAX,
460};
461
462/*
463 * Alignment of page-allocated RX buffers
464 *
465 * Controls the number of bytes inserted at the start of an RX buffer.
466 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
467 * of the skb->head for hardware DMA].
468 */
13e9ab11 469#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
8ceee660
BH
470#define EFX_PAGE_IP_ALIGN 0
471#else
472#define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
473#endif
474
475/*
476 * Alignment of the skb->head which wraps a page-allocated RX buffer
477 *
478 * The skb allocated to wrap an rx_buffer can have this alignment. Since
479 * the data is memcpy'd from the rx_buf, it does not need to be equal to
480 * EFX_PAGE_IP_ALIGN.
481 */
482#define EFX_PAGE_SKB_ALIGN 2
483
484/* Forward declaration */
485struct efx_nic;
486
487/* Pseudo bit-mask flow control field */
488enum efx_fc_type {
3f926da8
BH
489 EFX_FC_RX = FLOW_CTRL_RX,
490 EFX_FC_TX = FLOW_CTRL_TX,
8ceee660
BH
491 EFX_FC_AUTO = 4,
492};
493
177dfcd8
BH
494/* Supported MAC bit-mask */
495enum efx_mac_type {
496 EFX_GMAC = 1,
497 EFX_XMAC = 2,
498};
499
04cc8cac
BH
500static inline enum efx_fc_type efx_fc_resolve(enum efx_fc_type wanted_fc,
501 unsigned int lpa)
502{
3f926da8 503 BUILD_BUG_ON(EFX_FC_AUTO & (EFX_FC_RX | EFX_FC_TX));
04cc8cac
BH
504
505 if (!(wanted_fc & EFX_FC_AUTO))
506 return wanted_fc;
507
3f926da8 508 return mii_resolve_flowctrl_fdx(mii_advertise_flowctrl(wanted_fc), lpa);
04cc8cac
BH
509}
510
177dfcd8
BH
511/**
512 * struct efx_mac_operations - Efx MAC operations table
513 * @reconfigure: Reconfigure MAC. Serialised by the mac_lock
514 * @update_stats: Update statistics
766ca0fa
BH
515 * @irq: Hardware MAC event callback. Serialised by the mac_lock
516 * @poll: Poll for hardware state. Serialised by the mac_lock
177dfcd8
BH
517 */
518struct efx_mac_operations {
519 void (*reconfigure) (struct efx_nic *efx);
520 void (*update_stats) (struct efx_nic *efx);
766ca0fa
BH
521 void (*irq) (struct efx_nic *efx);
522 void (*poll) (struct efx_nic *efx);
177dfcd8
BH
523};
524
8ceee660
BH
525/**
526 * struct efx_phy_operations - Efx PHY operations table
527 * @init: Initialise PHY
528 * @fini: Shut down PHY
529 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
530 * @clear_interrupt: Clear down interrupt
531 * @blink: Blink LEDs
766ca0fa 532 * @poll: Poll for hardware state. Serialised by the mac_lock.
177dfcd8
BH
533 * @get_settings: Get ethtool settings. Serialised by the mac_lock.
534 * @set_settings: Set ethtool settings. Serialised by the mac_lock.
af4ad9bc 535 * @set_npage_adv: Set abilities advertised in (Extended) Next Page
04cc8cac 536 * (only needed where AN bit is set in mmds)
1796721a
BH
537 * @num_tests: Number of PHY-specific tests/results
538 * @test_names: Names of the tests/results
539 * @run_tests: Run tests and record results as appropriate.
540 * Flags are the ethtool tests flags.
8ceee660 541 * @mmds: MMD presence mask
3273c2e8 542 * @loopbacks: Supported loopback modes mask
8ceee660
BH
543 */
544struct efx_phy_operations {
177dfcd8 545 enum efx_mac_type macs;
8ceee660
BH
546 int (*init) (struct efx_nic *efx);
547 void (*fini) (struct efx_nic *efx);
548 void (*reconfigure) (struct efx_nic *efx);
549 void (*clear_interrupt) (struct efx_nic *efx);
766ca0fa 550 void (*poll) (struct efx_nic *efx);
177dfcd8
BH
551 void (*get_settings) (struct efx_nic *efx,
552 struct ethtool_cmd *ecmd);
553 int (*set_settings) (struct efx_nic *efx,
554 struct ethtool_cmd *ecmd);
af4ad9bc 555 void (*set_npage_adv) (struct efx_nic *efx, u32);
1796721a
BH
556 u32 num_tests;
557 const char *const *test_names;
558 int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
8ceee660 559 int mmds;
3273c2e8 560 unsigned loopbacks;
8ceee660
BH
561};
562
f8b87c17
BH
563/**
564 * @enum efx_phy_mode - PHY operating mode flags
565 * @PHY_MODE_NORMAL: on and should pass traffic
566 * @PHY_MODE_TX_DISABLED: on with TX disabled
3e133c44
BH
567 * @PHY_MODE_LOW_POWER: set to low power through MDIO
568 * @PHY_MODE_OFF: switched off through external control
f8b87c17
BH
569 * @PHY_MODE_SPECIAL: on but will not pass traffic
570 */
571enum efx_phy_mode {
572 PHY_MODE_NORMAL = 0,
573 PHY_MODE_TX_DISABLED = 1,
3e133c44
BH
574 PHY_MODE_LOW_POWER = 2,
575 PHY_MODE_OFF = 4,
f8b87c17
BH
576 PHY_MODE_SPECIAL = 8,
577};
578
579static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
580{
8c8661e4 581 return !!(mode & ~PHY_MODE_TX_DISABLED);
f8b87c17
BH
582}
583
8ceee660
BH
584/*
585 * Efx extended statistics
586 *
587 * Not all statistics are provided by all supported MACs. The purpose
588 * is this structure is to contain the raw statistics provided by each
589 * MAC.
590 */
591struct efx_mac_stats {
592 u64 tx_bytes;
593 u64 tx_good_bytes;
594 u64 tx_bad_bytes;
595 unsigned long tx_packets;
596 unsigned long tx_bad;
597 unsigned long tx_pause;
598 unsigned long tx_control;
599 unsigned long tx_unicast;
600 unsigned long tx_multicast;
601 unsigned long tx_broadcast;
602 unsigned long tx_lt64;
603 unsigned long tx_64;
604 unsigned long tx_65_to_127;
605 unsigned long tx_128_to_255;
606 unsigned long tx_256_to_511;
607 unsigned long tx_512_to_1023;
608 unsigned long tx_1024_to_15xx;
609 unsigned long tx_15xx_to_jumbo;
610 unsigned long tx_gtjumbo;
611 unsigned long tx_collision;
612 unsigned long tx_single_collision;
613 unsigned long tx_multiple_collision;
614 unsigned long tx_excessive_collision;
615 unsigned long tx_deferred;
616 unsigned long tx_late_collision;
617 unsigned long tx_excessive_deferred;
618 unsigned long tx_non_tcpudp;
619 unsigned long tx_mac_src_error;
620 unsigned long tx_ip_src_error;
621 u64 rx_bytes;
622 u64 rx_good_bytes;
623 u64 rx_bad_bytes;
624 unsigned long rx_packets;
625 unsigned long rx_good;
626 unsigned long rx_bad;
627 unsigned long rx_pause;
628 unsigned long rx_control;
629 unsigned long rx_unicast;
630 unsigned long rx_multicast;
631 unsigned long rx_broadcast;
632 unsigned long rx_lt64;
633 unsigned long rx_64;
634 unsigned long rx_65_to_127;
635 unsigned long rx_128_to_255;
636 unsigned long rx_256_to_511;
637 unsigned long rx_512_to_1023;
638 unsigned long rx_1024_to_15xx;
639 unsigned long rx_15xx_to_jumbo;
640 unsigned long rx_gtjumbo;
641 unsigned long rx_bad_lt64;
642 unsigned long rx_bad_64_to_15xx;
643 unsigned long rx_bad_15xx_to_jumbo;
644 unsigned long rx_bad_gtjumbo;
645 unsigned long rx_overflow;
646 unsigned long rx_missed;
647 unsigned long rx_false_carrier;
648 unsigned long rx_symbol_error;
649 unsigned long rx_align_error;
650 unsigned long rx_length_error;
651 unsigned long rx_internal_error;
652 unsigned long rx_good_lt64;
653};
654
655/* Number of bits used in a multicast filter hash address */
656#define EFX_MCAST_HASH_BITS 8
657
658/* Number of (single-bit) entries in a multicast filter hash */
659#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
660
661/* An Efx multicast filter hash */
662union efx_multicast_hash {
663 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
664 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
665};
666
667/**
668 * struct efx_nic - an Efx NIC
669 * @name: Device name (net device name or bus id before net device registered)
670 * @pci_dev: The PCI device
671 * @type: Controller type attributes
672 * @legacy_irq: IRQ number
8d9853d9
BH
673 * @workqueue: Workqueue for port reconfigures and the HW monitor.
674 * Work items do not hold and must not acquire RTNL.
6977dc63 675 * @workqueue_name: Name of workqueue
8ceee660
BH
676 * @reset_work: Scheduled reset workitem
677 * @monitor_work: Hardware monitor workitem
678 * @membase_phys: Memory BAR value as physical address
679 * @membase: Memory BAR value
680 * @biu_lock: BIU (bus interface unit) lock
681 * @interrupt_mode: Interrupt mode
6fb70fd1
BH
682 * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
683 * @irq_rx_moderation: IRQ moderation time for RX event queues
37b5a603 684 * @i2c_adap: I2C adapter
8ceee660
BH
685 * @board_info: Board-level information
686 * @state: Device state flag. Serialised by the rtnl_lock.
687 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
688 * @tx_queue: TX DMA queues
689 * @rx_queue: RX DMA queues
690 * @channel: Channels
0484e0db 691 * @next_buffer_table: First available buffer table id
8831da7b 692 * @n_rx_queues: Number of RX queues
28b581ab 693 * @n_channels: Number of channels in use
8ceee660
BH
694 * @rx_buffer_len: RX buffer length
695 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
0484e0db
BH
696 * @int_error_count: Number of internal errors seen recently
697 * @int_error_expire: Time at which error count will be expired
8ceee660
BH
698 * @irq_status: Interrupt status buffer
699 * @last_irq_cpu: Last CPU to handle interrupt.
700 * This register is written with the SMP processor ID whenever an
701 * interrupt is handled. It is used by falcon_test_interrupt()
702 * to verify that an interrupt has occurred.
4a5b504d
BH
703 * @spi_flash: SPI flash device
704 * This field will be %NULL if no flash device is present.
705 * @spi_eeprom: SPI EEPROM device
706 * This field will be %NULL if no EEPROM device is present.
f4150724 707 * @spi_lock: SPI bus lock
8ceee660
BH
708 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
709 * @nic_data: Hardware dependant state
8c8661e4
BH
710 * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
711 * @port_inhibited, efx_monitor() and efx_reconfigure_port()
8ceee660 712 * @port_enabled: Port enabled indicator.
766ca0fa
BH
713 * Serialises efx_stop_all(), efx_start_all(), efx_monitor(),
714 * efx_phy_work(), and efx_mac_work() with kernel interfaces. Safe to read
715 * under any one of the rtnl_lock, mac_lock, or netif_tx_lock, but all
716 * three must be held to modify it.
8c8661e4 717 * @port_inhibited: If set, the netif_carrier is always off. Hold the mac_lock
8ceee660
BH
718 * @port_initialized: Port initialized?
719 * @net_dev: Operating system network device. Consider holding the rtnl lock
720 * @rx_checksum_enabled: RX checksumming enabled
721 * @netif_stop_count: Port stop count
722 * @netif_stop_lock: Port stop lock
723 * @mac_stats: MAC statistics. These include all statistics the MACs
724 * can provide. Generic code converts these into a standard
725 * &struct net_device_stats.
726 * @stats_buffer: DMA buffer for statistics
8c8661e4 727 * @stats_lock: Statistics update lock. Serialises statistics fetches
1974cc20 728 * @stats_disable_count: Nest count for disabling statistics fetches
177dfcd8 729 * @mac_op: MAC interface
8ceee660
BH
730 * @mac_address: Permanent MAC address
731 * @phy_type: PHY type
732 * @phy_lock: PHY access lock
733 * @phy_op: PHY interface
734 * @phy_data: PHY private data (including PHY-specific stats)
68e7f45e 735 * @mdio: PHY MDIO interface
8c8661e4 736 * @phy_mode: PHY operating mode. Serialised by @mac_lock.
177dfcd8 737 * @mac_up: MAC link state
8ceee660 738 * @link_up: Link status
f31a45d2 739 * @link_fd: Link is full duplex
04cc8cac 740 * @link_fc: Actualy flow control flags
f31a45d2 741 * @link_speed: Link speed (Mbps)
8ceee660
BH
742 * @n_link_state_changes: Number of times the link has changed state
743 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
744 * @multicast_hash: Multicast hash table
04cc8cac 745 * @wanted_fc: Wanted flow control flags
766ca0fa
BH
746 * @phy_work: work item for dealing with PHY events
747 * @mac_work: work item for dealing with MAC events
3273c2e8
BH
748 * @loopback_mode: Loopback status
749 * @loopback_modes: Supported loopback mode bitmask
750 * @loopback_selftest: Offline self-test private state
8ceee660
BH
751 *
752 * The @priv field of the corresponding &struct net_device points to
753 * this.
754 */
755struct efx_nic {
756 char name[IFNAMSIZ];
757 struct pci_dev *pci_dev;
758 const struct efx_nic_type *type;
759 int legacy_irq;
760 struct workqueue_struct *workqueue;
6977dc63 761 char workqueue_name[16];
8ceee660
BH
762 struct work_struct reset_work;
763 struct delayed_work monitor_work;
086ea356 764 resource_size_t membase_phys;
8ceee660
BH
765 void __iomem *membase;
766 spinlock_t biu_lock;
767 enum efx_int_mode interrupt_mode;
6fb70fd1
BH
768 bool irq_rx_adaptive;
769 unsigned int irq_rx_moderation;
8ceee660 770
37b5a603 771 struct i2c_adapter i2c_adap;
8ceee660
BH
772 struct efx_board board_info;
773
774 enum nic_state state;
775 enum reset_type reset_pending;
776
60ac1065 777 struct efx_tx_queue tx_queue[EFX_TX_QUEUE_COUNT];
8ceee660
BH
778 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
779 struct efx_channel channel[EFX_MAX_CHANNELS];
780
0484e0db 781 unsigned next_buffer_table;
8831da7b 782 int n_rx_queues;
28b581ab 783 int n_channels;
8ceee660
BH
784 unsigned int rx_buffer_len;
785 unsigned int rx_buffer_order;
786
0484e0db
BH
787 unsigned int_error_count;
788 unsigned long int_error_expire;
789
8ceee660
BH
790 struct efx_buffer irq_status;
791 volatile signed int last_irq_cpu;
792
4a5b504d
BH
793 struct efx_spi_device *spi_flash;
794 struct efx_spi_device *spi_eeprom;
f4150724 795 struct mutex spi_lock;
4a5b504d 796
8ceee660
BH
797 unsigned n_rx_nodesc_drop_cnt;
798
5daab96d 799 struct falcon_nic_data *nic_data;
8ceee660
BH
800
801 struct mutex mac_lock;
766ca0fa 802 struct work_struct mac_work;
dc8cfa55 803 bool port_enabled;
8c8661e4 804 bool port_inhibited;
8ceee660 805
dc8cfa55 806 bool port_initialized;
8ceee660 807 struct net_device *net_dev;
dc8cfa55 808 bool rx_checksum_enabled;
8ceee660
BH
809
810 atomic_t netif_stop_count;
811 spinlock_t netif_stop_lock;
812
813 struct efx_mac_stats mac_stats;
814 struct efx_buffer stats_buffer;
815 spinlock_t stats_lock;
1974cc20 816 unsigned int stats_disable_count;
8ceee660 817
177dfcd8 818 struct efx_mac_operations *mac_op;
8ceee660
BH
819 unsigned char mac_address[ETH_ALEN];
820
821 enum phy_type phy_type;
822 spinlock_t phy_lock;
766ca0fa 823 struct work_struct phy_work;
8ceee660
BH
824 struct efx_phy_operations *phy_op;
825 void *phy_data;
68e7f45e 826 struct mdio_if_info mdio;
f8b87c17 827 enum efx_phy_mode phy_mode;
8ceee660 828
177dfcd8 829 bool mac_up;
dc8cfa55 830 bool link_up;
f31a45d2 831 bool link_fd;
04cc8cac 832 enum efx_fc_type link_fc;
f31a45d2 833 unsigned int link_speed;
8ceee660
BH
834 unsigned int n_link_state_changes;
835
dc8cfa55 836 bool promiscuous;
8ceee660 837 union efx_multicast_hash multicast_hash;
04cc8cac 838 enum efx_fc_type wanted_fc;
8ceee660
BH
839
840 atomic_t rx_reset;
3273c2e8
BH
841 enum efx_loopback_mode loopback_mode;
842 unsigned int loopback_modes;
843
844 void *loopback_selftest;
8ceee660
BH
845};
846
55668611
BH
847static inline int efx_dev_registered(struct efx_nic *efx)
848{
849 return efx->net_dev->reg_state == NETREG_REGISTERED;
850}
851
852/* Net device name, for inclusion in log messages if it has been registered.
853 * Use efx->name not efx->net_dev->name so that races with (un)registration
854 * are harmless.
855 */
856static inline const char *efx_dev_name(struct efx_nic *efx)
857{
858 return efx_dev_registered(efx) ? efx->name : "";
859}
860
8ceee660
BH
861/**
862 * struct efx_nic_type - Efx device type definition
863 * @mem_bar: Memory BAR number
864 * @mem_map_size: Memory BAR mapped size
865 * @txd_ptr_tbl_base: TX descriptor ring base address
866 * @rxd_ptr_tbl_base: RX descriptor ring base address
867 * @buf_tbl_base: Buffer table base address
868 * @evq_ptr_tbl_base: Event queue pointer table base address
869 * @evq_rptr_tbl_base: Event queue read-pointer table base address
8ceee660 870 * @max_dma_mask: Maximum possible DMA mask
8ceee660
BH
871 * @rx_buffer_padding: Padding added to each RX buffer
872 * @max_interrupt_mode: Highest capability interrupt mode supported
873 * from &enum efx_init_mode.
874 * @phys_addr_channels: Number of channels with physically addressed
875 * descriptors
876 */
877struct efx_nic_type {
878 unsigned int mem_bar;
879 unsigned int mem_map_size;
880 unsigned int txd_ptr_tbl_base;
881 unsigned int rxd_ptr_tbl_base;
882 unsigned int buf_tbl_base;
883 unsigned int evq_ptr_tbl_base;
884 unsigned int evq_rptr_tbl_base;
885
9bbd7d9a 886 u64 max_dma_mask;
8ceee660 887
8ceee660
BH
888 unsigned int rx_buffer_padding;
889 unsigned int max_interrupt_mode;
890 unsigned int phys_addr_channels;
891};
892
893/**************************************************************************
894 *
895 * Prototypes and inline functions
896 *
897 *************************************************************************/
898
899/* Iterate over all used channels */
900#define efx_for_each_channel(_channel, _efx) \
901 for (_channel = &_efx->channel[0]; \
902 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
903 _channel++) \
904 if (!_channel->used_flags) \
905 continue; \
906 else
907
8ceee660
BH
908/* Iterate over all used TX queues */
909#define efx_for_each_tx_queue(_tx_queue, _efx) \
910 for (_tx_queue = &_efx->tx_queue[0]; \
60ac1065
BH
911 _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
912 _tx_queue++)
8ceee660
BH
913
914/* Iterate over all TX queues belonging to a channel */
915#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
916 for (_tx_queue = &_channel->efx->tx_queue[0]; \
60ac1065 917 _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
8ceee660 918 _tx_queue++) \
60ac1065 919 if (_tx_queue->channel != _channel) \
8ceee660
BH
920 continue; \
921 else
922
923/* Iterate over all used RX queues */
924#define efx_for_each_rx_queue(_rx_queue, _efx) \
925 for (_rx_queue = &_efx->rx_queue[0]; \
8831da7b
BH
926 _rx_queue < &_efx->rx_queue[_efx->n_rx_queues]; \
927 _rx_queue++)
8ceee660
BH
928
929/* Iterate over all RX queues belonging to a channel */
930#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
a2589027
BH
931 for (_rx_queue = &_channel->efx->rx_queue[_channel->channel]; \
932 _rx_queue; \
933 _rx_queue = NULL) \
8831da7b 934 if (_rx_queue->channel != _channel) \
8ceee660
BH
935 continue; \
936 else
937
938/* Returns a pointer to the specified receive buffer in the RX
939 * descriptor queue.
940 */
941static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
942 unsigned int index)
943{
944 return (&rx_queue->buffer[index]);
945}
946
947/* Set bit in a little-endian bitfield */
18c2fc04 948static inline void set_bit_le(unsigned nr, unsigned char *addr)
8ceee660
BH
949{
950 addr[nr / 8] |= (1 << (nr % 8));
951}
952
953/* Clear bit in a little-endian bitfield */
18c2fc04 954static inline void clear_bit_le(unsigned nr, unsigned char *addr)
8ceee660
BH
955{
956 addr[nr / 8] &= ~(1 << (nr % 8));
957}
958
959
960/**
961 * EFX_MAX_FRAME_LEN - calculate maximum frame length
962 *
963 * This calculates the maximum frame length that will be used for a
964 * given MTU. The frame length will be equal to the MTU plus a
965 * constant amount of header space and padding. This is the quantity
966 * that the net driver will program into the MAC as the maximum frame
967 * length.
968 *
969 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
970 * length, so we round up to the nearest 8.
cc11763b
BH
971 *
972 * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
973 * XGMII cycle). If the frame length reaches the maximum value in the
974 * same cycle, the XMAC can miss the IPG altogether. We work around
975 * this by adding a further 16 bytes.
8ceee660
BH
976 */
977#define EFX_MAX_FRAME_LEN(mtu) \
cc11763b 978 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */ + 7) & ~7) + 16)
8ceee660
BH
979
980
981#endif /* EFX_NET_DRIVER_H */
This page took 0.269826 seconds and 5 git commands to generate.