net_driver.h 39 KB

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