kmemtrace: SLOB hooks.
[linux-2.6/kmemtrace.git] / drivers / net / sfc / net_driver.h
blob5e20e7551daeda8e9642d8bd300623d8ee321a11
1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc.
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 */
11 /* Common definitions for all Efx net driver code */
13 #ifndef EFX_NET_DRIVER_H
14 #define EFX_NET_DRIVER_H
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>
30 #include "enum.h"
31 #include "bitfield.h"
32 #include "i2c-direct.h"
34 #define EFX_MAX_LRO_DESCRIPTORS 8
35 #define EFX_MAX_LRO_AGGR MAX_SKB_FRAGS
37 /**************************************************************************
39 * Build definitions
41 **************************************************************************/
42 #ifndef EFX_DRIVER_NAME
43 #define EFX_DRIVER_NAME "sfc"
44 #endif
45 #define EFX_DRIVER_VERSION "2.2"
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
55 /* Un-rate-limited logging */
56 #define EFX_ERR(efx, fmt, args...) \
57 dev_err(&((efx)->pci_dev->dev), "ERR: %s " fmt, efx_dev_name(efx), ##args)
59 #define EFX_INFO(efx, fmt, args...) \
60 dev_info(&((efx)->pci_dev->dev), "INFO: %s " fmt, efx_dev_name(efx), ##args)
62 #ifdef EFX_ENABLE_DEBUG
63 #define EFX_LOG(efx, fmt, args...) \
64 dev_info(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
65 #else
66 #define EFX_LOG(efx, fmt, args...) \
67 dev_dbg(&((efx)->pci_dev->dev), "DBG: %s " fmt, efx_dev_name(efx), ##args)
68 #endif
70 #define EFX_TRACE(efx, fmt, args...) do {} while (0)
72 #define EFX_REGDUMP(efx, fmt, args...) do {} while (0)
74 /* Rate-limited logging */
75 #define EFX_ERR_RL(efx, fmt, args...) \
76 do {if (net_ratelimit()) EFX_ERR(efx, fmt, ##args); } while (0)
78 #define EFX_INFO_RL(efx, fmt, args...) \
79 do {if (net_ratelimit()) EFX_INFO(efx, fmt, ##args); } while (0)
81 #define EFX_LOG_RL(efx, fmt, args...) \
82 do {if (net_ratelimit()) EFX_LOG(efx, fmt, ##args); } while (0)
84 /**************************************************************************
86 * Efx data structures
88 **************************************************************************/
90 #define EFX_MAX_CHANNELS 32
91 #define EFX_MAX_TX_QUEUES 1
92 #define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
94 /**
95 * struct efx_special_buffer - An Efx special buffer
96 * @addr: CPU base address of the buffer
97 * @dma_addr: DMA base address of the buffer
98 * @len: Buffer length, in bytes
99 * @index: Buffer index within controller;s buffer table
100 * @entries: Number of buffer table entries
102 * Special buffers are used for the event queues and the TX and RX
103 * descriptor queues for each channel. They are *not* used for the
104 * actual transmit and receive buffers.
106 * Note that for Falcon, TX and RX descriptor queues live in host memory.
107 * Allocation and freeing procedures must take this into account.
109 struct efx_special_buffer {
110 void *addr;
111 dma_addr_t dma_addr;
112 unsigned int len;
113 int index;
114 int entries;
118 * struct efx_tx_buffer - An Efx TX buffer
119 * @skb: The associated socket buffer.
120 * Set only on the final fragment of a packet; %NULL for all other
121 * fragments. When this fragment completes, then we can free this
122 * skb.
123 * @tsoh: The associated TSO header structure, or %NULL if this
124 * buffer is not a TSO header.
125 * @dma_addr: DMA address of the fragment.
126 * @len: Length of this fragment.
127 * This field is zero when the queue slot is empty.
128 * @continuation: True if this fragment is not the end of a packet.
129 * @unmap_single: True if pci_unmap_single should be used.
130 * @unmap_addr: DMA address to unmap
131 * @unmap_len: Length of this fragment to unmap
133 struct efx_tx_buffer {
134 const struct sk_buff *skb;
135 struct efx_tso_header *tsoh;
136 dma_addr_t dma_addr;
137 unsigned short len;
138 unsigned char continuation;
139 unsigned char unmap_single;
140 dma_addr_t unmap_addr;
141 unsigned short unmap_len;
145 * struct efx_tx_queue - An Efx TX queue
147 * This is a ring buffer of TX fragments.
148 * Since the TX completion path always executes on the same
149 * CPU and the xmit path can operate on different CPUs,
150 * performance is increased by ensuring that the completion
151 * path and the xmit path operate on different cache lines.
152 * This is particularly important if the xmit path is always
153 * executing on one CPU which is different from the completion
154 * path. There is also a cache line for members which are
155 * read but not written on the fast path.
157 * @efx: The associated Efx NIC
158 * @queue: DMA queue number
159 * @used: Queue is used by net driver
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.
165 * @stopped: Stopped flag.
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.
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
187 struct 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;
191 int used;
192 struct efx_channel *channel;
193 struct efx_nic *nic;
194 struct efx_tx_buffer *buffer;
195 struct efx_special_buffer txd;
197 /* Members used mainly on the completion path */
198 unsigned int read_count ____cacheline_aligned_in_smp;
199 int stopped;
201 /* Members used only on the xmit path */
202 unsigned int insert_count ____cacheline_aligned_in_smp;
203 unsigned int write_count;
204 unsigned int old_read_count;
205 struct efx_tso_header *tso_headers_free;
206 unsigned int tso_bursts;
207 unsigned int tso_long_headers;
208 unsigned int tso_packets;
212 * struct efx_rx_buffer - An Efx RX data buffer
213 * @dma_addr: DMA base address of the buffer
214 * @skb: The associated socket buffer, if any.
215 * If both this and page are %NULL, the buffer slot is currently free.
216 * @page: The associated page buffer, if any.
217 * If both this and skb are %NULL, the buffer slot is currently free.
218 * @data: Pointer to ethernet header
219 * @len: Buffer length, in bytes.
220 * @unmap_addr: DMA address to unmap
222 struct efx_rx_buffer {
223 dma_addr_t dma_addr;
224 struct sk_buff *skb;
225 struct page *page;
226 char *data;
227 unsigned int len;
228 dma_addr_t unmap_addr;
232 * struct efx_rx_queue - An Efx RX queue
233 * @efx: The associated Efx NIC
234 * @queue: DMA queue number
235 * @used: Queue is used by net driver
236 * @channel: The associated channel
237 * @buffer: The software buffer ring
238 * @rxd: The hardware descriptor ring
239 * @added_count: Number of buffers added to the receive queue.
240 * @notified_count: Number of buffers given to NIC (<= @added_count).
241 * @removed_count: Number of buffers removed from the receive queue.
242 * @add_lock: Receive queue descriptor add spin lock.
243 * This lock must be held in order to add buffers to the RX
244 * descriptor ring (rxd and buffer) and to update added_count (but
245 * not removed_count).
246 * @max_fill: RX descriptor maximum fill level (<= ring size)
247 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
248 * (<= @max_fill)
249 * @fast_fill_limit: The level to which a fast fill will fill
250 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
251 * @min_fill: RX descriptor minimum non-zero fill level.
252 * This records the minimum fill level observed when a ring
253 * refill was triggered.
254 * @min_overfill: RX descriptor minimum overflow fill level.
255 * This records the minimum fill level at which RX queue
256 * overflow was observed. It should never be set.
257 * @alloc_page_count: RX allocation strategy counter.
258 * @alloc_skb_count: RX allocation strategy counter.
259 * @work: Descriptor push work thread
260 * @buf_page: Page for next RX buffer.
261 * We can use a single page for multiple RX buffers. This tracks
262 * the remaining space in the allocation.
263 * @buf_dma_addr: Page's DMA address.
264 * @buf_data: Page's host address.
266 struct efx_rx_queue {
267 struct efx_nic *efx;
268 int queue;
269 int used;
270 struct efx_channel *channel;
271 struct efx_rx_buffer *buffer;
272 struct efx_special_buffer rxd;
274 int added_count;
275 int notified_count;
276 int removed_count;
277 spinlock_t add_lock;
278 unsigned int max_fill;
279 unsigned int fast_fill_trigger;
280 unsigned int fast_fill_limit;
281 unsigned int min_fill;
282 unsigned int min_overfill;
283 unsigned int alloc_page_count;
284 unsigned int alloc_skb_count;
285 struct delayed_work work;
286 unsigned int slow_fill_count;
288 struct page *buf_page;
289 dma_addr_t buf_dma_addr;
290 char *buf_data;
294 * struct efx_buffer - An Efx general-purpose buffer
295 * @addr: host base address of the buffer
296 * @dma_addr: DMA base address of the buffer
297 * @len: Buffer length, in bytes
299 * Falcon uses these buffers for its interrupt status registers and
300 * MAC stats dumps.
302 struct efx_buffer {
303 void *addr;
304 dma_addr_t dma_addr;
305 unsigned int len;
309 /* Flags for channel->used_flags */
310 #define EFX_USED_BY_RX 1
311 #define EFX_USED_BY_TX 2
312 #define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
314 enum efx_rx_alloc_method {
315 RX_ALLOC_METHOD_AUTO = 0,
316 RX_ALLOC_METHOD_SKB = 1,
317 RX_ALLOC_METHOD_PAGE = 2,
321 * struct efx_channel - An Efx channel
323 * A channel comprises an event queue, at least one TX queue, at least
324 * one RX queue, and an associated tasklet for processing the event
325 * queue.
327 * @efx: Associated Efx NIC
328 * @evqnum: Event queue number
329 * @channel: Channel instance number
330 * @used_flags: Channel is used by net driver
331 * @enabled: Channel enabled indicator
332 * @irq: IRQ number (MSI and MSI-X only)
333 * @has_interrupt: Channel has an interrupt
334 * @irq_moderation: IRQ moderation value (in us)
335 * @napi_dev: Net device used with NAPI
336 * @napi_str: NAPI control structure
337 * @reset_work: Scheduled reset work thread
338 * @work_pending: Is work pending via NAPI?
339 * @eventq: Event queue buffer
340 * @eventq_read_ptr: Event queue read pointer
341 * @last_eventq_read_ptr: Last event queue read pointer value.
342 * @eventq_magic: Event queue magic value for driver-generated test events
343 * @lro_mgr: LRO state
344 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
345 * and diagnostic counters
346 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
347 * descriptors
348 * @rx_alloc_pop_pages: RX allocation method currently in use for popping
349 * descriptors
350 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
351 * @n_rx_ip_frag_err: Count of RX IP fragment errors
352 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
353 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
354 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
355 * @n_rx_overlength: Count of RX_OVERLENGTH errors
356 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
358 struct efx_channel {
359 struct efx_nic *efx;
360 int evqnum;
361 int channel;
362 int used_flags;
363 int enabled;
364 int irq;
365 unsigned int has_interrupt;
366 unsigned int irq_moderation;
367 struct net_device *napi_dev;
368 struct napi_struct napi_str;
369 struct work_struct reset_work;
370 int work_pending;
371 struct efx_special_buffer eventq;
372 unsigned int eventq_read_ptr;
373 unsigned int last_eventq_read_ptr;
374 unsigned int eventq_magic;
376 struct net_lro_mgr lro_mgr;
377 int rx_alloc_level;
378 int rx_alloc_push_pages;
379 int rx_alloc_pop_pages;
381 unsigned n_rx_tobe_disc;
382 unsigned n_rx_ip_frag_err;
383 unsigned n_rx_ip_hdr_chksum_err;
384 unsigned n_rx_tcp_udp_chksum_err;
385 unsigned n_rx_frm_trunc;
386 unsigned n_rx_overlength;
387 unsigned n_skbuff_leaks;
389 /* Used to pipeline received packets in order to optimise memory
390 * access with prefetches.
392 struct efx_rx_buffer *rx_pkt;
393 int rx_pkt_csummed;
398 * struct efx_blinker - S/W LED blinking context
399 * @led_num: LED ID (board-specific meaning)
400 * @state: Current state - on or off
401 * @resubmit: Timer resubmission flag
402 * @timer: Control timer for blinking
404 struct efx_blinker {
405 int led_num;
406 int state;
407 int resubmit;
408 struct timer_list timer;
413 * struct efx_board - board information
414 * @type: Board model type
415 * @major: Major rev. ('A', 'B' ...)
416 * @minor: Minor rev. (0, 1, ...)
417 * @init: Initialisation function
418 * @init_leds: Sets up board LEDs
419 * @set_fault_led: Turns the fault LED on or off
420 * @blink: Starts/stops blinking
421 * @blinker: used to blink LEDs in software
423 struct efx_board {
424 int type;
425 int major;
426 int minor;
427 int (*init) (struct efx_nic *nic);
428 /* As the LEDs are typically attached to the PHY, LEDs
429 * have a separate init callback that happens later than
430 * board init. */
431 int (*init_leds)(struct efx_nic *efx);
432 void (*set_fault_led) (struct efx_nic *efx, int state);
433 void (*blink) (struct efx_nic *efx, int start);
434 struct efx_blinker blinker;
437 #define STRING_TABLE_LOOKUP(val, member) \
438 member ## _names[val]
440 enum efx_int_mode {
441 /* Be careful if altering to correct macro below */
442 EFX_INT_MODE_MSIX = 0,
443 EFX_INT_MODE_MSI = 1,
444 EFX_INT_MODE_LEGACY = 2,
445 EFX_INT_MODE_MAX /* Insert any new items before this */
447 #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
449 enum phy_type {
450 PHY_TYPE_NONE = 0,
451 PHY_TYPE_CX4_RTMR = 1,
452 PHY_TYPE_1G_ALASKA = 2,
453 PHY_TYPE_10XPRESS = 3,
454 PHY_TYPE_XFP = 4,
455 PHY_TYPE_PM8358 = 6,
456 PHY_TYPE_MAX /* Insert any new items before this */
459 #define PHY_ADDR_INVALID 0xff
461 enum nic_state {
462 STATE_INIT = 0,
463 STATE_RUNNING = 1,
464 STATE_FINI = 2,
465 STATE_RESETTING = 3, /* rtnl_lock always held */
466 STATE_DISABLED = 4,
467 STATE_MAX,
471 * Alignment of page-allocated RX buffers
473 * Controls the number of bytes inserted at the start of an RX buffer.
474 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
475 * of the skb->head for hardware DMA].
477 #if defined(__i386__) || defined(__x86_64__)
478 #define EFX_PAGE_IP_ALIGN 0
479 #else
480 #define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
481 #endif
484 * Alignment of the skb->head which wraps a page-allocated RX buffer
486 * The skb allocated to wrap an rx_buffer can have this alignment. Since
487 * the data is memcpy'd from the rx_buf, it does not need to be equal to
488 * EFX_PAGE_IP_ALIGN.
490 #define EFX_PAGE_SKB_ALIGN 2
492 /* Forward declaration */
493 struct efx_nic;
495 /* Pseudo bit-mask flow control field */
496 enum efx_fc_type {
497 EFX_FC_RX = 1,
498 EFX_FC_TX = 2,
499 EFX_FC_AUTO = 4,
503 * struct efx_phy_operations - Efx PHY operations table
504 * @init: Initialise PHY
505 * @fini: Shut down PHY
506 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
507 * @clear_interrupt: Clear down interrupt
508 * @blink: Blink LEDs
509 * @check_hw: Check hardware
510 * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
511 * @mmds: MMD presence mask
512 * @loopbacks: Supported loopback modes mask
514 struct efx_phy_operations {
515 int (*init) (struct efx_nic *efx);
516 void (*fini) (struct efx_nic *efx);
517 void (*reconfigure) (struct efx_nic *efx);
518 void (*clear_interrupt) (struct efx_nic *efx);
519 int (*check_hw) (struct efx_nic *efx);
520 void (*reset_xaui) (struct efx_nic *efx);
521 int mmds;
522 unsigned loopbacks;
526 * Efx extended statistics
528 * Not all statistics are provided by all supported MACs. The purpose
529 * is this structure is to contain the raw statistics provided by each
530 * MAC.
532 struct efx_mac_stats {
533 u64 tx_bytes;
534 u64 tx_good_bytes;
535 u64 tx_bad_bytes;
536 unsigned long tx_packets;
537 unsigned long tx_bad;
538 unsigned long tx_pause;
539 unsigned long tx_control;
540 unsigned long tx_unicast;
541 unsigned long tx_multicast;
542 unsigned long tx_broadcast;
543 unsigned long tx_lt64;
544 unsigned long tx_64;
545 unsigned long tx_65_to_127;
546 unsigned long tx_128_to_255;
547 unsigned long tx_256_to_511;
548 unsigned long tx_512_to_1023;
549 unsigned long tx_1024_to_15xx;
550 unsigned long tx_15xx_to_jumbo;
551 unsigned long tx_gtjumbo;
552 unsigned long tx_collision;
553 unsigned long tx_single_collision;
554 unsigned long tx_multiple_collision;
555 unsigned long tx_excessive_collision;
556 unsigned long tx_deferred;
557 unsigned long tx_late_collision;
558 unsigned long tx_excessive_deferred;
559 unsigned long tx_non_tcpudp;
560 unsigned long tx_mac_src_error;
561 unsigned long tx_ip_src_error;
562 u64 rx_bytes;
563 u64 rx_good_bytes;
564 u64 rx_bad_bytes;
565 unsigned long rx_packets;
566 unsigned long rx_good;
567 unsigned long rx_bad;
568 unsigned long rx_pause;
569 unsigned long rx_control;
570 unsigned long rx_unicast;
571 unsigned long rx_multicast;
572 unsigned long rx_broadcast;
573 unsigned long rx_lt64;
574 unsigned long rx_64;
575 unsigned long rx_65_to_127;
576 unsigned long rx_128_to_255;
577 unsigned long rx_256_to_511;
578 unsigned long rx_512_to_1023;
579 unsigned long rx_1024_to_15xx;
580 unsigned long rx_15xx_to_jumbo;
581 unsigned long rx_gtjumbo;
582 unsigned long rx_bad_lt64;
583 unsigned long rx_bad_64_to_15xx;
584 unsigned long rx_bad_15xx_to_jumbo;
585 unsigned long rx_bad_gtjumbo;
586 unsigned long rx_overflow;
587 unsigned long rx_missed;
588 unsigned long rx_false_carrier;
589 unsigned long rx_symbol_error;
590 unsigned long rx_align_error;
591 unsigned long rx_length_error;
592 unsigned long rx_internal_error;
593 unsigned long rx_good_lt64;
596 /* Number of bits used in a multicast filter hash address */
597 #define EFX_MCAST_HASH_BITS 8
599 /* Number of (single-bit) entries in a multicast filter hash */
600 #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
602 /* An Efx multicast filter hash */
603 union efx_multicast_hash {
604 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
605 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
609 * struct efx_nic - an Efx NIC
610 * @name: Device name (net device name or bus id before net device registered)
611 * @pci_dev: The PCI device
612 * @type: Controller type attributes
613 * @legacy_irq: IRQ number
614 * @workqueue: Workqueue for resets, port reconfigures and the HW monitor
615 * @reset_work: Scheduled reset workitem
616 * @monitor_work: Hardware monitor workitem
617 * @membase_phys: Memory BAR value as physical address
618 * @membase: Memory BAR value
619 * @biu_lock: BIU (bus interface unit) lock
620 * @interrupt_mode: Interrupt mode
621 * @i2c: I2C interface
622 * @board_info: Board-level information
623 * @state: Device state flag. Serialised by the rtnl_lock.
624 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
625 * @tx_queue: TX DMA queues
626 * @rx_queue: RX DMA queues
627 * @channel: Channels
628 * @rss_queues: Number of RSS queues
629 * @rx_buffer_len: RX buffer length
630 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
631 * @irq_status: Interrupt status buffer
632 * @last_irq_cpu: Last CPU to handle interrupt.
633 * This register is written with the SMP processor ID whenever an
634 * interrupt is handled. It is used by falcon_test_interrupt()
635 * to verify that an interrupt has occurred.
636 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
637 * @nic_data: Hardware dependant state
638 * @mac_lock: MAC access lock. Protects @port_enabled, efx_monitor() and
639 * efx_reconfigure_port()
640 * @port_enabled: Port enabled indicator.
641 * Serialises efx_stop_all(), efx_start_all() and efx_monitor() and
642 * efx_reconfigure_work with kernel interfaces. Safe to read under any
643 * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
644 * be held to modify it.
645 * @port_initialized: Port initialized?
646 * @net_dev: Operating system network device. Consider holding the rtnl lock
647 * @rx_checksum_enabled: RX checksumming enabled
648 * @netif_stop_count: Port stop count
649 * @netif_stop_lock: Port stop lock
650 * @mac_stats: MAC statistics. These include all statistics the MACs
651 * can provide. Generic code converts these into a standard
652 * &struct net_device_stats.
653 * @stats_buffer: DMA buffer for statistics
654 * @stats_lock: Statistics update lock
655 * @mac_address: Permanent MAC address
656 * @phy_type: PHY type
657 * @phy_lock: PHY access lock
658 * @phy_op: PHY interface
659 * @phy_data: PHY private data (including PHY-specific stats)
660 * @mii: PHY interface
661 * @tx_disabled: PHY transmitter turned off
662 * @link_up: Link status
663 * @link_options: Link options (MII/GMII format)
664 * @n_link_state_changes: Number of times the link has changed state
665 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
666 * @multicast_hash: Multicast hash table
667 * @flow_control: Flow control flags - separate RX/TX so can't use link_options
668 * @reconfigure_work: work item for dealing with PHY events
669 * @loopback_mode: Loopback status
670 * @loopback_modes: Supported loopback mode bitmask
671 * @loopback_selftest: Offline self-test private state
673 * The @priv field of the corresponding &struct net_device points to
674 * this.
676 struct efx_nic {
677 char name[IFNAMSIZ];
678 struct pci_dev *pci_dev;
679 const struct efx_nic_type *type;
680 int legacy_irq;
681 struct workqueue_struct *workqueue;
682 struct work_struct reset_work;
683 struct delayed_work monitor_work;
684 resource_size_t membase_phys;
685 void __iomem *membase;
686 spinlock_t biu_lock;
687 enum efx_int_mode interrupt_mode;
689 struct efx_i2c_interface i2c;
690 struct efx_board board_info;
692 enum nic_state state;
693 enum reset_type reset_pending;
695 struct efx_tx_queue tx_queue[EFX_MAX_TX_QUEUES];
696 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
697 struct efx_channel channel[EFX_MAX_CHANNELS];
699 int rss_queues;
700 unsigned int rx_buffer_len;
701 unsigned int rx_buffer_order;
703 struct efx_buffer irq_status;
704 volatile signed int last_irq_cpu;
706 unsigned n_rx_nodesc_drop_cnt;
708 struct falcon_nic_data *nic_data;
710 struct mutex mac_lock;
711 int port_enabled;
713 int port_initialized;
714 struct net_device *net_dev;
715 int rx_checksum_enabled;
717 atomic_t netif_stop_count;
718 spinlock_t netif_stop_lock;
720 struct efx_mac_stats mac_stats;
721 struct efx_buffer stats_buffer;
722 spinlock_t stats_lock;
724 unsigned char mac_address[ETH_ALEN];
726 enum phy_type phy_type;
727 spinlock_t phy_lock;
728 struct efx_phy_operations *phy_op;
729 void *phy_data;
730 struct mii_if_info mii;
731 unsigned tx_disabled;
733 int link_up;
734 unsigned int link_options;
735 unsigned int n_link_state_changes;
737 int promiscuous;
738 union efx_multicast_hash multicast_hash;
739 enum efx_fc_type flow_control;
740 struct work_struct reconfigure_work;
742 atomic_t rx_reset;
743 enum efx_loopback_mode loopback_mode;
744 unsigned int loopback_modes;
746 void *loopback_selftest;
749 static inline int efx_dev_registered(struct efx_nic *efx)
751 return efx->net_dev->reg_state == NETREG_REGISTERED;
754 /* Net device name, for inclusion in log messages if it has been registered.
755 * Use efx->name not efx->net_dev->name so that races with (un)registration
756 * are harmless.
758 static inline const char *efx_dev_name(struct efx_nic *efx)
760 return efx_dev_registered(efx) ? efx->name : "";
764 * struct efx_nic_type - Efx device type definition
765 * @mem_bar: Memory BAR number
766 * @mem_map_size: Memory BAR mapped size
767 * @txd_ptr_tbl_base: TX descriptor ring base address
768 * @rxd_ptr_tbl_base: RX descriptor ring base address
769 * @buf_tbl_base: Buffer table base address
770 * @evq_ptr_tbl_base: Event queue pointer table base address
771 * @evq_rptr_tbl_base: Event queue read-pointer table base address
772 * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
773 * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
774 * @evq_size: Event queue size (must be a power of two)
775 * @max_dma_mask: Maximum possible DMA mask
776 * @tx_dma_mask: TX DMA mask
777 * @bug5391_mask: Address mask for bug 5391 workaround
778 * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
779 * @rx_xon_thresh: RX FIFO XON watermark (bytes)
780 * @rx_buffer_padding: Padding added to each RX buffer
781 * @max_interrupt_mode: Highest capability interrupt mode supported
782 * from &enum efx_init_mode.
783 * @phys_addr_channels: Number of channels with physically addressed
784 * descriptors
786 struct efx_nic_type {
787 unsigned int mem_bar;
788 unsigned int mem_map_size;
789 unsigned int txd_ptr_tbl_base;
790 unsigned int rxd_ptr_tbl_base;
791 unsigned int buf_tbl_base;
792 unsigned int evq_ptr_tbl_base;
793 unsigned int evq_rptr_tbl_base;
795 unsigned int txd_ring_mask;
796 unsigned int rxd_ring_mask;
797 unsigned int evq_size;
798 u64 max_dma_mask;
799 unsigned int tx_dma_mask;
800 unsigned bug5391_mask;
802 int rx_xoff_thresh;
803 int rx_xon_thresh;
804 unsigned int rx_buffer_padding;
805 unsigned int max_interrupt_mode;
806 unsigned int phys_addr_channels;
809 /**************************************************************************
811 * Prototypes and inline functions
813 *************************************************************************/
815 /* Iterate over all used channels */
816 #define efx_for_each_channel(_channel, _efx) \
817 for (_channel = &_efx->channel[0]; \
818 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
819 _channel++) \
820 if (!_channel->used_flags) \
821 continue; \
822 else
824 /* Iterate over all used channels with interrupts */
825 #define efx_for_each_channel_with_interrupt(_channel, _efx) \
826 for (_channel = &_efx->channel[0]; \
827 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
828 _channel++) \
829 if (!(_channel->used_flags && _channel->has_interrupt)) \
830 continue; \
831 else
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]; \
836 _tx_queue < &_efx->tx_queue[EFX_MAX_TX_QUEUES]; \
837 _tx_queue++) \
838 if (!_tx_queue->used) \
839 continue; \
840 else
842 /* Iterate over all TX queues belonging to a channel */
843 #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
844 for (_tx_queue = &_channel->efx->tx_queue[0]; \
845 _tx_queue < &_channel->efx->tx_queue[EFX_MAX_TX_QUEUES]; \
846 _tx_queue++) \
847 if ((!_tx_queue->used) || \
848 (_tx_queue->channel != _channel)) \
849 continue; \
850 else
852 /* Iterate over all used RX queues */
853 #define efx_for_each_rx_queue(_rx_queue, _efx) \
854 for (_rx_queue = &_efx->rx_queue[0]; \
855 _rx_queue < &_efx->rx_queue[EFX_MAX_RX_QUEUES]; \
856 _rx_queue++) \
857 if (!_rx_queue->used) \
858 continue; \
859 else
861 /* Iterate over all RX queues belonging to a channel */
862 #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
863 for (_rx_queue = &_channel->efx->rx_queue[0]; \
864 _rx_queue < &_channel->efx->rx_queue[EFX_MAX_RX_QUEUES]; \
865 _rx_queue++) \
866 if ((!_rx_queue->used) || \
867 (_rx_queue->channel != _channel)) \
868 continue; \
869 else
871 /* Returns a pointer to the specified receive buffer in the RX
872 * descriptor queue.
874 static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
875 unsigned int index)
877 return (&rx_queue->buffer[index]);
880 /* Set bit in a little-endian bitfield */
881 static inline void set_bit_le(int nr, unsigned char *addr)
883 addr[nr / 8] |= (1 << (nr % 8));
886 /* Clear bit in a little-endian bitfield */
887 static inline void clear_bit_le(int nr, unsigned char *addr)
889 addr[nr / 8] &= ~(1 << (nr % 8));
894 * EFX_MAX_FRAME_LEN - calculate maximum frame length
896 * This calculates the maximum frame length that will be used for a
897 * given MTU. The frame length will be equal to the MTU plus a
898 * constant amount of header space and padding. This is the quantity
899 * that the net driver will program into the MAC as the maximum frame
900 * length.
902 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
903 * length, so we round up to the nearest 8.
905 #define EFX_MAX_FRAME_LEN(mtu) \
906 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
909 #endif /* EFX_NET_DRIVER_H */