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