sfc: Use DMA_BIT_MASK() instead of our own DMA mask macros
[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>
29
30#include "enum.h"
31#include "bitfield.h"
32#include "i2c-direct.h"
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
45#define EFX_DRIVER_VERSION "2.2.0136"
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
84/* Kernel headers may redefine inline anyway */
85#ifndef inline
86#define inline inline __attribute__ ((always_inline))
87#endif
88
89/**************************************************************************
90 *
91 * Efx data structures
92 *
93 **************************************************************************/
94
95#define EFX_MAX_CHANNELS 32
96#define EFX_MAX_TX_QUEUES 1
97#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
98
99/**
100 * struct efx_special_buffer - An Efx special buffer
101 * @addr: CPU base address of the buffer
102 * @dma_addr: DMA base address of the buffer
103 * @len: Buffer length, in bytes
104 * @index: Buffer index within controller;s buffer table
105 * @entries: Number of buffer table entries
106 *
107 * Special buffers are used for the event queues and the TX and RX
108 * descriptor queues for each channel. They are *not* used for the
109 * actual transmit and receive buffers.
110 *
111 * Note that for Falcon, TX and RX descriptor queues live in host memory.
112 * Allocation and freeing procedures must take this into account.
113 */
114struct efx_special_buffer {
115 void *addr;
116 dma_addr_t dma_addr;
117 unsigned int len;
118 int index;
119 int entries;
120};
121
122/**
123 * struct efx_tx_buffer - An Efx TX buffer
124 * @skb: The associated socket buffer.
125 * Set only on the final fragment of a packet; %NULL for all other
126 * fragments. When this fragment completes, then we can free this
127 * skb.
b9b39b62
BH
128 * @tsoh: The associated TSO header structure, or %NULL if this
129 * buffer is not a TSO header.
8ceee660
BH
130 * @dma_addr: DMA address of the fragment.
131 * @len: Length of this fragment.
132 * This field is zero when the queue slot is empty.
133 * @continuation: True if this fragment is not the end of a packet.
134 * @unmap_single: True if pci_unmap_single should be used.
135 * @unmap_addr: DMA address to unmap
136 * @unmap_len: Length of this fragment to unmap
137 */
138struct efx_tx_buffer {
139 const struct sk_buff *skb;
b9b39b62 140 struct efx_tso_header *tsoh;
8ceee660
BH
141 dma_addr_t dma_addr;
142 unsigned short len;
143 unsigned char continuation;
144 unsigned char unmap_single;
145 dma_addr_t unmap_addr;
146 unsigned short unmap_len;
147};
148
149/**
150 * struct efx_tx_queue - An Efx TX queue
151 *
152 * This is a ring buffer of TX fragments.
153 * Since the TX completion path always executes on the same
154 * CPU and the xmit path can operate on different CPUs,
155 * performance is increased by ensuring that the completion
156 * path and the xmit path operate on different cache lines.
157 * This is particularly important if the xmit path is always
158 * executing on one CPU which is different from the completion
159 * path. There is also a cache line for members which are
160 * read but not written on the fast path.
161 *
162 * @efx: The associated Efx NIC
163 * @queue: DMA queue number
164 * @used: Queue is used by net driver
165 * @channel: The associated channel
166 * @buffer: The software buffer ring
167 * @txd: The hardware descriptor ring
168 * @read_count: Current read pointer.
169 * This is the number of buffers that have been removed from both rings.
170 * @stopped: Stopped flag.
171 * Set if this TX queue is currently stopping its port.
172 * @insert_count: Current insert pointer
173 * This is the number of buffers that have been added to the
174 * software ring.
175 * @write_count: Current write pointer
176 * This is the number of buffers that have been added to the
177 * hardware ring.
178 * @old_read_count: The value of read_count when last checked.
179 * This is here for performance reasons. The xmit path will
180 * only get the up-to-date value of read_count if this
181 * variable indicates that the queue is full. This is to
182 * avoid cache-line ping-pong between the xmit path and the
183 * completion path.
b9b39b62
BH
184 * @tso_headers_free: A list of TSO headers allocated for this TX queue
185 * that are not in use, and so available for new TSO sends. The list
186 * is protected by the TX queue lock.
187 * @tso_bursts: Number of times TSO xmit invoked by kernel
188 * @tso_long_headers: Number of packets with headers too long for standard
189 * blocks
190 * @tso_packets: Number of packets via the TSO xmit path
8ceee660
BH
191 */
192struct efx_tx_queue {
193 /* Members which don't change on the fast path */
194 struct efx_nic *efx ____cacheline_aligned_in_smp;
195 int queue;
196 int used;
197 struct efx_channel *channel;
198 struct efx_nic *nic;
199 struct efx_tx_buffer *buffer;
200 struct efx_special_buffer txd;
201
202 /* Members used mainly on the completion path */
203 unsigned int read_count ____cacheline_aligned_in_smp;
204 int stopped;
205
206 /* Members used only on the xmit path */
207 unsigned int insert_count ____cacheline_aligned_in_smp;
208 unsigned int write_count;
209 unsigned int old_read_count;
b9b39b62
BH
210 struct efx_tso_header *tso_headers_free;
211 unsigned int tso_bursts;
212 unsigned int tso_long_headers;
213 unsigned int tso_packets;
8ceee660
BH
214};
215
216/**
217 * struct efx_rx_buffer - An Efx RX data buffer
218 * @dma_addr: DMA base address of the buffer
219 * @skb: The associated socket buffer, if any.
220 * If both this and page are %NULL, the buffer slot is currently free.
221 * @page: The associated page buffer, if any.
222 * If both this and skb are %NULL, the buffer slot is currently free.
223 * @data: Pointer to ethernet header
224 * @len: Buffer length, in bytes.
225 * @unmap_addr: DMA address to unmap
226 */
227struct efx_rx_buffer {
228 dma_addr_t dma_addr;
229 struct sk_buff *skb;
230 struct page *page;
231 char *data;
232 unsigned int len;
233 dma_addr_t unmap_addr;
234};
235
236/**
237 * struct efx_rx_queue - An Efx RX queue
238 * @efx: The associated Efx NIC
239 * @queue: DMA queue number
240 * @used: Queue is used by net driver
241 * @channel: The associated channel
242 * @buffer: The software buffer ring
243 * @rxd: The hardware descriptor ring
244 * @added_count: Number of buffers added to the receive queue.
245 * @notified_count: Number of buffers given to NIC (<= @added_count).
246 * @removed_count: Number of buffers removed from the receive queue.
247 * @add_lock: Receive queue descriptor add spin lock.
248 * This lock must be held in order to add buffers to the RX
249 * descriptor ring (rxd and buffer) and to update added_count (but
250 * not removed_count).
251 * @max_fill: RX descriptor maximum fill level (<= ring size)
252 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
253 * (<= @max_fill)
254 * @fast_fill_limit: The level to which a fast fill will fill
255 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
256 * @min_fill: RX descriptor minimum non-zero fill level.
257 * This records the minimum fill level observed when a ring
258 * refill was triggered.
259 * @min_overfill: RX descriptor minimum overflow fill level.
260 * This records the minimum fill level at which RX queue
261 * overflow was observed. It should never be set.
262 * @alloc_page_count: RX allocation strategy counter.
263 * @alloc_skb_count: RX allocation strategy counter.
264 * @work: Descriptor push work thread
265 * @buf_page: Page for next RX buffer.
266 * We can use a single page for multiple RX buffers. This tracks
267 * the remaining space in the allocation.
268 * @buf_dma_addr: Page's DMA address.
269 * @buf_data: Page's host address.
270 */
271struct efx_rx_queue {
272 struct efx_nic *efx;
273 int queue;
274 int used;
275 struct efx_channel *channel;
276 struct efx_rx_buffer *buffer;
277 struct efx_special_buffer rxd;
278
279 int added_count;
280 int notified_count;
281 int removed_count;
282 spinlock_t add_lock;
283 unsigned int max_fill;
284 unsigned int fast_fill_trigger;
285 unsigned int fast_fill_limit;
286 unsigned int min_fill;
287 unsigned int min_overfill;
288 unsigned int alloc_page_count;
289 unsigned int alloc_skb_count;
290 struct delayed_work work;
291 unsigned int slow_fill_count;
292
293 struct page *buf_page;
294 dma_addr_t buf_dma_addr;
295 char *buf_data;
296};
297
298/**
299 * struct efx_buffer - An Efx general-purpose buffer
300 * @addr: host base address of the buffer
301 * @dma_addr: DMA base address of the buffer
302 * @len: Buffer length, in bytes
303 *
304 * Falcon uses these buffers for its interrupt status registers and
305 * MAC stats dumps.
306 */
307struct efx_buffer {
308 void *addr;
309 dma_addr_t dma_addr;
310 unsigned int len;
311};
312
313
314/* Flags for channel->used_flags */
315#define EFX_USED_BY_RX 1
316#define EFX_USED_BY_TX 2
317#define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
318
319enum efx_rx_alloc_method {
320 RX_ALLOC_METHOD_AUTO = 0,
321 RX_ALLOC_METHOD_SKB = 1,
322 RX_ALLOC_METHOD_PAGE = 2,
323};
324
325/**
326 * struct efx_channel - An Efx channel
327 *
328 * A channel comprises an event queue, at least one TX queue, at least
329 * one RX queue, and an associated tasklet for processing the event
330 * queue.
331 *
332 * @efx: Associated Efx NIC
333 * @evqnum: Event queue number
334 * @channel: Channel instance number
335 * @used_flags: Channel is used by net driver
336 * @enabled: Channel enabled indicator
337 * @irq: IRQ number (MSI and MSI-X only)
338 * @has_interrupt: Channel has an interrupt
339 * @irq_moderation: IRQ moderation value (in us)
340 * @napi_dev: Net device used with NAPI
341 * @napi_str: NAPI control structure
342 * @reset_work: Scheduled reset work thread
343 * @work_pending: Is work pending via NAPI?
344 * @eventq: Event queue buffer
345 * @eventq_read_ptr: Event queue read pointer
346 * @last_eventq_read_ptr: Last event queue read pointer value.
347 * @eventq_magic: Event queue magic value for driver-generated test events
348 * @lro_mgr: LRO state
349 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
350 * and diagnostic counters
351 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
352 * descriptors
353 * @rx_alloc_pop_pages: RX allocation method currently in use for popping
354 * descriptors
355 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
356 * @n_rx_ip_frag_err: Count of RX IP fragment errors
357 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
358 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
359 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
360 * @n_rx_overlength: Count of RX_OVERLENGTH errors
361 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
362 */
363struct efx_channel {
364 struct efx_nic *efx;
365 int evqnum;
366 int channel;
367 int used_flags;
368 int enabled;
369 int irq;
370 unsigned int has_interrupt;
371 unsigned int irq_moderation;
372 struct net_device *napi_dev;
373 struct napi_struct napi_str;
374 struct work_struct reset_work;
375 int work_pending;
376 struct efx_special_buffer eventq;
377 unsigned int eventq_read_ptr;
378 unsigned int last_eventq_read_ptr;
379 unsigned int eventq_magic;
380
381 struct net_lro_mgr lro_mgr;
382 int rx_alloc_level;
383 int rx_alloc_push_pages;
384 int rx_alloc_pop_pages;
385
386 unsigned n_rx_tobe_disc;
387 unsigned n_rx_ip_frag_err;
388 unsigned n_rx_ip_hdr_chksum_err;
389 unsigned n_rx_tcp_udp_chksum_err;
390 unsigned n_rx_frm_trunc;
391 unsigned n_rx_overlength;
392 unsigned n_skbuff_leaks;
393
394 /* Used to pipeline received packets in order to optimise memory
395 * access with prefetches.
396 */
397 struct efx_rx_buffer *rx_pkt;
398 int rx_pkt_csummed;
399
400};
401
402/**
403 * struct efx_blinker - S/W LED blinking context
404 * @led_num: LED ID (board-specific meaning)
405 * @state: Current state - on or off
406 * @resubmit: Timer resubmission flag
407 * @timer: Control timer for blinking
408 */
409struct efx_blinker {
410 int led_num;
411 int state;
412 int resubmit;
413 struct timer_list timer;
414};
415
416
417/**
418 * struct efx_board - board information
419 * @type: Board model type
420 * @major: Major rev. ('A', 'B' ...)
421 * @minor: Minor rev. (0, 1, ...)
422 * @init: Initialisation function
423 * @init_leds: Sets up board LEDs
424 * @set_fault_led: Turns the fault LED on or off
425 * @blink: Starts/stops blinking
426 * @blinker: used to blink LEDs in software
427 */
428struct efx_board {
429 int type;
430 int major;
431 int minor;
432 int (*init) (struct efx_nic *nic);
433 /* As the LEDs are typically attached to the PHY, LEDs
434 * have a separate init callback that happens later than
435 * board init. */
436 int (*init_leds)(struct efx_nic *efx);
437 void (*set_fault_led) (struct efx_nic *efx, int state);
438 void (*blink) (struct efx_nic *efx, int start);
439 struct efx_blinker blinker;
440};
441
3273c2e8
BH
442#define STRING_TABLE_LOOKUP(val, member) \
443 member ## _names[val]
444
8ceee660
BH
445enum efx_int_mode {
446 /* Be careful if altering to correct macro below */
447 EFX_INT_MODE_MSIX = 0,
448 EFX_INT_MODE_MSI = 1,
449 EFX_INT_MODE_LEGACY = 2,
450 EFX_INT_MODE_MAX /* Insert any new items before this */
451};
452#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
453
454enum phy_type {
455 PHY_TYPE_NONE = 0,
456 PHY_TYPE_CX4_RTMR = 1,
457 PHY_TYPE_1G_ALASKA = 2,
458 PHY_TYPE_10XPRESS = 3,
459 PHY_TYPE_XFP = 4,
460 PHY_TYPE_PM8358 = 6,
461 PHY_TYPE_MAX /* Insert any new items before this */
462};
463
464#define PHY_ADDR_INVALID 0xff
465
466enum nic_state {
467 STATE_INIT = 0,
468 STATE_RUNNING = 1,
469 STATE_FINI = 2,
470 STATE_RESETTING = 3, /* rtnl_lock always held */
471 STATE_DISABLED = 4,
472 STATE_MAX,
473};
474
475/*
476 * Alignment of page-allocated RX buffers
477 *
478 * Controls the number of bytes inserted at the start of an RX buffer.
479 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
480 * of the skb->head for hardware DMA].
481 */
482#if defined(__i386__) || defined(__x86_64__)
483#define EFX_PAGE_IP_ALIGN 0
484#else
485#define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
486#endif
487
488/*
489 * Alignment of the skb->head which wraps a page-allocated RX buffer
490 *
491 * The skb allocated to wrap an rx_buffer can have this alignment. Since
492 * the data is memcpy'd from the rx_buf, it does not need to be equal to
493 * EFX_PAGE_IP_ALIGN.
494 */
495#define EFX_PAGE_SKB_ALIGN 2
496
497/* Forward declaration */
498struct efx_nic;
499
500/* Pseudo bit-mask flow control field */
501enum efx_fc_type {
502 EFX_FC_RX = 1,
503 EFX_FC_TX = 2,
504 EFX_FC_AUTO = 4,
505};
506
507/**
508 * struct efx_phy_operations - Efx PHY operations table
509 * @init: Initialise PHY
510 * @fini: Shut down PHY
511 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
512 * @clear_interrupt: Clear down interrupt
513 * @blink: Blink LEDs
514 * @check_hw: Check hardware
515 * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
516 * @mmds: MMD presence mask
3273c2e8 517 * @loopbacks: Supported loopback modes mask
8ceee660
BH
518 */
519struct efx_phy_operations {
520 int (*init) (struct efx_nic *efx);
521 void (*fini) (struct efx_nic *efx);
522 void (*reconfigure) (struct efx_nic *efx);
523 void (*clear_interrupt) (struct efx_nic *efx);
524 int (*check_hw) (struct efx_nic *efx);
525 void (*reset_xaui) (struct efx_nic *efx);
526 int mmds;
3273c2e8 527 unsigned loopbacks;
8ceee660
BH
528};
529
530/*
531 * Efx extended statistics
532 *
533 * Not all statistics are provided by all supported MACs. The purpose
534 * is this structure is to contain the raw statistics provided by each
535 * MAC.
536 */
537struct efx_mac_stats {
538 u64 tx_bytes;
539 u64 tx_good_bytes;
540 u64 tx_bad_bytes;
541 unsigned long tx_packets;
542 unsigned long tx_bad;
543 unsigned long tx_pause;
544 unsigned long tx_control;
545 unsigned long tx_unicast;
546 unsigned long tx_multicast;
547 unsigned long tx_broadcast;
548 unsigned long tx_lt64;
549 unsigned long tx_64;
550 unsigned long tx_65_to_127;
551 unsigned long tx_128_to_255;
552 unsigned long tx_256_to_511;
553 unsigned long tx_512_to_1023;
554 unsigned long tx_1024_to_15xx;
555 unsigned long tx_15xx_to_jumbo;
556 unsigned long tx_gtjumbo;
557 unsigned long tx_collision;
558 unsigned long tx_single_collision;
559 unsigned long tx_multiple_collision;
560 unsigned long tx_excessive_collision;
561 unsigned long tx_deferred;
562 unsigned long tx_late_collision;
563 unsigned long tx_excessive_deferred;
564 unsigned long tx_non_tcpudp;
565 unsigned long tx_mac_src_error;
566 unsigned long tx_ip_src_error;
567 u64 rx_bytes;
568 u64 rx_good_bytes;
569 u64 rx_bad_bytes;
570 unsigned long rx_packets;
571 unsigned long rx_good;
572 unsigned long rx_bad;
573 unsigned long rx_pause;
574 unsigned long rx_control;
575 unsigned long rx_unicast;
576 unsigned long rx_multicast;
577 unsigned long rx_broadcast;
578 unsigned long rx_lt64;
579 unsigned long rx_64;
580 unsigned long rx_65_to_127;
581 unsigned long rx_128_to_255;
582 unsigned long rx_256_to_511;
583 unsigned long rx_512_to_1023;
584 unsigned long rx_1024_to_15xx;
585 unsigned long rx_15xx_to_jumbo;
586 unsigned long rx_gtjumbo;
587 unsigned long rx_bad_lt64;
588 unsigned long rx_bad_64_to_15xx;
589 unsigned long rx_bad_15xx_to_jumbo;
590 unsigned long rx_bad_gtjumbo;
591 unsigned long rx_overflow;
592 unsigned long rx_missed;
593 unsigned long rx_false_carrier;
594 unsigned long rx_symbol_error;
595 unsigned long rx_align_error;
596 unsigned long rx_length_error;
597 unsigned long rx_internal_error;
598 unsigned long rx_good_lt64;
599};
600
601/* Number of bits used in a multicast filter hash address */
602#define EFX_MCAST_HASH_BITS 8
603
604/* Number of (single-bit) entries in a multicast filter hash */
605#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
606
607/* An Efx multicast filter hash */
608union efx_multicast_hash {
609 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
610 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
611};
612
613/**
614 * struct efx_nic - an Efx NIC
615 * @name: Device name (net device name or bus id before net device registered)
616 * @pci_dev: The PCI device
617 * @type: Controller type attributes
618 * @legacy_irq: IRQ number
619 * @workqueue: Workqueue for resets, port reconfigures and the HW monitor
620 * @reset_work: Scheduled reset workitem
621 * @monitor_work: Hardware monitor workitem
622 * @membase_phys: Memory BAR value as physical address
623 * @membase: Memory BAR value
624 * @biu_lock: BIU (bus interface unit) lock
625 * @interrupt_mode: Interrupt mode
626 * @i2c: I2C interface
627 * @board_info: Board-level information
628 * @state: Device state flag. Serialised by the rtnl_lock.
629 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
630 * @tx_queue: TX DMA queues
631 * @rx_queue: RX DMA queues
632 * @channel: Channels
633 * @rss_queues: Number of RSS queues
634 * @rx_buffer_len: RX buffer length
635 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
636 * @irq_status: Interrupt status buffer
637 * @last_irq_cpu: Last CPU to handle interrupt.
638 * This register is written with the SMP processor ID whenever an
639 * interrupt is handled. It is used by falcon_test_interrupt()
640 * to verify that an interrupt has occurred.
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;
687 struct work_struct reset_work;
688 struct delayed_work monitor_work;
086ea356 689 resource_size_t membase_phys;
8ceee660
BH
690 void __iomem *membase;
691 spinlock_t biu_lock;
692 enum efx_int_mode interrupt_mode;
693
694 struct efx_i2c_interface i2c;
695 struct efx_board board_info;
696
697 enum nic_state state;
698 enum reset_type reset_pending;
699
700 struct efx_tx_queue tx_queue[EFX_MAX_TX_QUEUES];
701 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
702 struct efx_channel channel[EFX_MAX_CHANNELS];
703
704 int rss_queues;
705 unsigned int rx_buffer_len;
706 unsigned int rx_buffer_order;
707
708 struct efx_buffer irq_status;
709 volatile signed int last_irq_cpu;
710
711 unsigned n_rx_nodesc_drop_cnt;
712
713 void *nic_data;
714
715 struct mutex mac_lock;
716 int port_enabled;
717
718 int port_initialized;
719 struct net_device *net_dev;
720 int rx_checksum_enabled;
721
722 atomic_t netif_stop_count;
723 spinlock_t netif_stop_lock;
724
725 struct efx_mac_stats mac_stats;
726 struct efx_buffer stats_buffer;
727 spinlock_t stats_lock;
728
729 unsigned char mac_address[ETH_ALEN];
730
731 enum phy_type phy_type;
732 spinlock_t phy_lock;
733 struct efx_phy_operations *phy_op;
734 void *phy_data;
735 struct mii_if_info mii;
3273c2e8 736 unsigned tx_disabled;
8ceee660
BH
737
738 int link_up;
739 unsigned int link_options;
740 unsigned int n_link_state_changes;
741
742 int promiscuous;
743 union efx_multicast_hash multicast_hash;
744 enum efx_fc_type flow_control;
745 struct work_struct reconfigure_work;
746
747 atomic_t rx_reset;
3273c2e8
BH
748 enum efx_loopback_mode loopback_mode;
749 unsigned int loopback_modes;
750
751 void *loopback_selftest;
8ceee660
BH
752};
753
55668611
BH
754static inline int efx_dev_registered(struct efx_nic *efx)
755{
756 return efx->net_dev->reg_state == NETREG_REGISTERED;
757}
758
759/* Net device name, for inclusion in log messages if it has been registered.
760 * Use efx->name not efx->net_dev->name so that races with (un)registration
761 * are harmless.
762 */
763static inline const char *efx_dev_name(struct efx_nic *efx)
764{
765 return efx_dev_registered(efx) ? efx->name : "";
766}
767
8ceee660
BH
768/**
769 * struct efx_nic_type - Efx device type definition
770 * @mem_bar: Memory BAR number
771 * @mem_map_size: Memory BAR mapped size
772 * @txd_ptr_tbl_base: TX descriptor ring base address
773 * @rxd_ptr_tbl_base: RX descriptor ring base address
774 * @buf_tbl_base: Buffer table base address
775 * @evq_ptr_tbl_base: Event queue pointer table base address
776 * @evq_rptr_tbl_base: Event queue read-pointer table base address
777 * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
778 * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
779 * @evq_size: Event queue size (must be a power of two)
780 * @max_dma_mask: Maximum possible DMA mask
781 * @tx_dma_mask: TX DMA mask
782 * @bug5391_mask: Address mask for bug 5391 workaround
783 * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
784 * @rx_xon_thresh: RX FIFO XON watermark (bytes)
785 * @rx_buffer_padding: Padding added to each RX buffer
786 * @max_interrupt_mode: Highest capability interrupt mode supported
787 * from &enum efx_init_mode.
788 * @phys_addr_channels: Number of channels with physically addressed
789 * descriptors
790 */
791struct efx_nic_type {
792 unsigned int mem_bar;
793 unsigned int mem_map_size;
794 unsigned int txd_ptr_tbl_base;
795 unsigned int rxd_ptr_tbl_base;
796 unsigned int buf_tbl_base;
797 unsigned int evq_ptr_tbl_base;
798 unsigned int evq_rptr_tbl_base;
799
800 unsigned int txd_ring_mask;
801 unsigned int rxd_ring_mask;
802 unsigned int evq_size;
9bbd7d9a 803 u64 max_dma_mask;
8ceee660
BH
804 unsigned int tx_dma_mask;
805 unsigned bug5391_mask;
806
807 int rx_xoff_thresh;
808 int rx_xon_thresh;
809 unsigned int rx_buffer_padding;
810 unsigned int max_interrupt_mode;
811 unsigned int phys_addr_channels;
812};
813
814/**************************************************************************
815 *
816 * Prototypes and inline functions
817 *
818 *************************************************************************/
819
820/* Iterate over all used channels */
821#define efx_for_each_channel(_channel, _efx) \
822 for (_channel = &_efx->channel[0]; \
823 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
824 _channel++) \
825 if (!_channel->used_flags) \
826 continue; \
827 else
828
829/* Iterate over all used channels with interrupts */
830#define efx_for_each_channel_with_interrupt(_channel, _efx) \
831 for (_channel = &_efx->channel[0]; \
832 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
833 _channel++) \
834 if (!(_channel->used_flags && _channel->has_interrupt)) \
835 continue; \
836 else
837
838/* Iterate over all used TX queues */
839#define efx_for_each_tx_queue(_tx_queue, _efx) \
840 for (_tx_queue = &_efx->tx_queue[0]; \
841 _tx_queue < &_efx->tx_queue[EFX_MAX_TX_QUEUES]; \
842 _tx_queue++) \
843 if (!_tx_queue->used) \
844 continue; \
845 else
846
847/* Iterate over all TX queues belonging to a channel */
848#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
849 for (_tx_queue = &_channel->efx->tx_queue[0]; \
850 _tx_queue < &_channel->efx->tx_queue[EFX_MAX_TX_QUEUES]; \
851 _tx_queue++) \
852 if ((!_tx_queue->used) || \
853 (_tx_queue->channel != _channel)) \
854 continue; \
855 else
856
857/* Iterate over all used RX queues */
858#define efx_for_each_rx_queue(_rx_queue, _efx) \
859 for (_rx_queue = &_efx->rx_queue[0]; \
860 _rx_queue < &_efx->rx_queue[EFX_MAX_RX_QUEUES]; \
861 _rx_queue++) \
862 if (!_rx_queue->used) \
863 continue; \
864 else
865
866/* Iterate over all RX queues belonging to a channel */
867#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
868 for (_rx_queue = &_channel->efx->rx_queue[0]; \
869 _rx_queue < &_channel->efx->rx_queue[EFX_MAX_RX_QUEUES]; \
870 _rx_queue++) \
871 if ((!_rx_queue->used) || \
872 (_rx_queue->channel != _channel)) \
873 continue; \
874 else
875
876/* Returns a pointer to the specified receive buffer in the RX
877 * descriptor queue.
878 */
879static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
880 unsigned int index)
881{
882 return (&rx_queue->buffer[index]);
883}
884
885/* Set bit in a little-endian bitfield */
886static inline void set_bit_le(int nr, unsigned char *addr)
887{
888 addr[nr / 8] |= (1 << (nr % 8));
889}
890
891/* Clear bit in a little-endian bitfield */
892static inline void clear_bit_le(int nr, unsigned char *addr)
893{
894 addr[nr / 8] &= ~(1 << (nr % 8));
895}
896
897
898/**
899 * EFX_MAX_FRAME_LEN - calculate maximum frame length
900 *
901 * This calculates the maximum frame length that will be used for a
902 * given MTU. The frame length will be equal to the MTU plus a
903 * constant amount of header space and padding. This is the quantity
904 * that the net driver will program into the MAC as the maximum frame
905 * length.
906 *
907 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
908 * length, so we round up to the nearest 8.
909 */
910#define EFX_MAX_FRAME_LEN(mtu) \
911 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
912
913
914#endif /* EFX_NET_DRIVER_H */
This page took 0.067565 seconds and 5 git commands to generate.