net_driver.h 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2013 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/rwsem.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/i2c.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <net/busy_poll.h>
  30. #include "enum.h"
  31. #include "bitfield.h"
  32. #include "filter.h"
  33. /**************************************************************************
  34. *
  35. * Build definitions
  36. *
  37. **************************************************************************/
  38. #define EFX_DRIVER_VERSION "4.0"
  39. #ifdef DEBUG
  40. #define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
  41. #define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
  42. #else
  43. #define EFX_BUG_ON_PARANOID(x) do {} while (0)
  44. #define EFX_WARN_ON_PARANOID(x) do {} while (0)
  45. #endif
  46. /**************************************************************************
  47. *
  48. * Efx data structures
  49. *
  50. **************************************************************************/
  51. #define EFX_MAX_CHANNELS 32U
  52. #define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
  53. #define EFX_EXTRA_CHANNEL_IOV 0
  54. #define EFX_EXTRA_CHANNEL_PTP 1
  55. #define EFX_MAX_EXTRA_CHANNELS 2U
  56. /* Checksum generation is a per-queue option in hardware, so each
  57. * queue visible to the networking core is backed by two hardware TX
  58. * queues. */
  59. #define EFX_MAX_TX_TC 2
  60. #define EFX_MAX_CORE_TX_QUEUES (EFX_MAX_TX_TC * EFX_MAX_CHANNELS)
  61. #define EFX_TXQ_TYPE_OFFLOAD 1 /* flag */
  62. #define EFX_TXQ_TYPE_HIGHPRI 2 /* flag */
  63. #define EFX_TXQ_TYPES 4
  64. #define EFX_MAX_TX_QUEUES (EFX_TXQ_TYPES * EFX_MAX_CHANNELS)
  65. /* Maximum possible MTU the driver supports */
  66. #define EFX_MAX_MTU (9 * 1024)
  67. /* Minimum MTU, from RFC791 (IP) */
  68. #define EFX_MIN_MTU 68
  69. /* Size of an RX scatter buffer. Small enough to pack 2 into a 4K page,
  70. * and should be a multiple of the cache line size.
  71. */
  72. #define EFX_RX_USR_BUF_SIZE (2048 - 256)
  73. /* If possible, we should ensure cache line alignment at start and end
  74. * of every buffer. Otherwise, we just need to ensure 4-byte
  75. * alignment of the network header.
  76. */
  77. #if NET_IP_ALIGN == 0
  78. #define EFX_RX_BUF_ALIGNMENT L1_CACHE_BYTES
  79. #else
  80. #define EFX_RX_BUF_ALIGNMENT 4
  81. #endif
  82. /* Forward declare Precision Time Protocol (PTP) support structure. */
  83. struct efx_ptp_data;
  84. struct hwtstamp_config;
  85. struct efx_self_tests;
  86. /**
  87. * struct efx_buffer - A general-purpose DMA buffer
  88. * @addr: host base address of the buffer
  89. * @dma_addr: DMA base address of the buffer
  90. * @len: Buffer length, in bytes
  91. *
  92. * The NIC uses these buffers for its interrupt status registers and
  93. * MAC stats dumps.
  94. */
  95. struct efx_buffer {
  96. void *addr;
  97. dma_addr_t dma_addr;
  98. unsigned int len;
  99. };
  100. /**
  101. * struct efx_special_buffer - DMA buffer entered into buffer table
  102. * @buf: Standard &struct efx_buffer
  103. * @index: Buffer index within controller;s buffer table
  104. * @entries: Number of buffer table entries
  105. *
  106. * The NIC has a buffer table that maps buffers of size %EFX_BUF_SIZE.
  107. * Event and descriptor rings are addressed via one or more buffer
  108. * table entries (and so can be physically non-contiguous, although we
  109. * currently do not take advantage of that). On Falcon and Siena we
  110. * have to take care of allocating and initialising the entries
  111. * ourselves. On later hardware this is managed by the firmware and
  112. * @index and @entries are left as 0.
  113. */
  114. struct efx_special_buffer {
  115. struct efx_buffer buf;
  116. unsigned int index;
  117. unsigned int entries;
  118. };
  119. /**
  120. * struct efx_tx_buffer - buffer state for a TX descriptor
  121. * @skb: When @flags & %EFX_TX_BUF_SKB, the associated socket buffer to be
  122. * freed when descriptor completes
  123. * @heap_buf: When @flags & %EFX_TX_BUF_HEAP, the associated heap buffer to be
  124. * freed when descriptor completes.
  125. * @option: When @flags & %EFX_TX_BUF_OPTION, a NIC-specific option descriptor.
  126. * @dma_addr: DMA address of the fragment.
  127. * @flags: Flags for allocation and DMA mapping type
  128. * @len: Length of this fragment.
  129. * This field is zero when the queue slot is empty.
  130. * @unmap_len: Length of this fragment to unmap
  131. * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping.
  132. * Only valid if @unmap_len != 0.
  133. */
  134. struct efx_tx_buffer {
  135. union {
  136. const struct sk_buff *skb;
  137. void *heap_buf;
  138. };
  139. union {
  140. efx_qword_t option;
  141. dma_addr_t dma_addr;
  142. };
  143. unsigned short flags;
  144. unsigned short len;
  145. unsigned short unmap_len;
  146. unsigned short dma_offset;
  147. };
  148. #define EFX_TX_BUF_CONT 1 /* not last descriptor of packet */
  149. #define EFX_TX_BUF_SKB 2 /* buffer is last part of skb */
  150. #define EFX_TX_BUF_HEAP 4 /* buffer was allocated with kmalloc() */
  151. #define EFX_TX_BUF_MAP_SINGLE 8 /* buffer was mapped with dma_map_single() */
  152. #define EFX_TX_BUF_OPTION 0x10 /* empty buffer for option descriptor */
  153. /**
  154. * struct efx_tx_queue - An Efx TX queue
  155. *
  156. * This is a ring buffer of TX fragments.
  157. * Since the TX completion path always executes on the same
  158. * CPU and the xmit path can operate on different CPUs,
  159. * performance is increased by ensuring that the completion
  160. * path and the xmit path operate on different cache lines.
  161. * This is particularly important if the xmit path is always
  162. * executing on one CPU which is different from the completion
  163. * path. There is also a cache line for members which are
  164. * read but not written on the fast path.
  165. *
  166. * @efx: The associated Efx NIC
  167. * @queue: DMA queue number
  168. * @tso_version: Version of TSO in use for this queue.
  169. * @channel: The associated channel
  170. * @core_txq: The networking core TX queue structure
  171. * @buffer: The software buffer ring
  172. * @tsoh_page: Array of pages of TSO header buffers
  173. * @txd: The hardware descriptor ring
  174. * @ptr_mask: The size of the ring minus 1.
  175. * @piobuf: PIO buffer region for this TX queue (shared with its partner).
  176. * Size of the region is efx_piobuf_size.
  177. * @piobuf_offset: Buffer offset to be specified in PIO descriptors
  178. * @initialised: Has hardware queue been initialised?
  179. * @read_count: Current read pointer.
  180. * This is the number of buffers that have been removed from both rings.
  181. * @old_write_count: The value of @write_count when last checked.
  182. * This is here for performance reasons. The xmit path will
  183. * only get the up-to-date value of @write_count if this
  184. * variable indicates that the queue is empty. This is to
  185. * avoid cache-line ping-pong between the xmit path and the
  186. * completion path.
  187. * @merge_events: Number of TX merged completion events
  188. * @insert_count: Current insert pointer
  189. * This is the number of buffers that have been added to the
  190. * software ring.
  191. * @write_count: Current write pointer
  192. * This is the number of buffers that have been added to the
  193. * hardware ring.
  194. * @old_read_count: The value of read_count when last checked.
  195. * This is here for performance reasons. The xmit path will
  196. * only get the up-to-date value of read_count if this
  197. * variable indicates that the queue is full. This is to
  198. * avoid cache-line ping-pong between the xmit path and the
  199. * completion path.
  200. * @tso_bursts: Number of times TSO xmit invoked by kernel
  201. * @tso_long_headers: Number of packets with headers too long for standard
  202. * blocks
  203. * @tso_packets: Number of packets via the TSO xmit path
  204. * @pushes: Number of times the TX push feature has been used
  205. * @pio_packets: Number of times the TX PIO feature has been used
  206. * @xmit_more_available: Are any packets waiting to be pushed to the NIC
  207. * @empty_read_count: If the completion path has seen the queue as empty
  208. * and the transmission path has not yet checked this, the value of
  209. * @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
  210. */
  211. struct efx_tx_queue {
  212. /* Members which don't change on the fast path */
  213. struct efx_nic *efx ____cacheline_aligned_in_smp;
  214. unsigned queue;
  215. unsigned int tso_version;
  216. struct efx_channel *channel;
  217. struct netdev_queue *core_txq;
  218. struct efx_tx_buffer *buffer;
  219. struct efx_buffer *tsoh_page;
  220. struct efx_special_buffer txd;
  221. unsigned int ptr_mask;
  222. void __iomem *piobuf;
  223. unsigned int piobuf_offset;
  224. bool initialised;
  225. /* Members used mainly on the completion path */
  226. unsigned int read_count ____cacheline_aligned_in_smp;
  227. unsigned int old_write_count;
  228. unsigned int merge_events;
  229. unsigned int bytes_compl;
  230. unsigned int pkts_compl;
  231. /* Members used only on the xmit path */
  232. unsigned int insert_count ____cacheline_aligned_in_smp;
  233. unsigned int write_count;
  234. unsigned int old_read_count;
  235. unsigned int tso_bursts;
  236. unsigned int tso_long_headers;
  237. unsigned int tso_packets;
  238. unsigned int pushes;
  239. unsigned int pio_packets;
  240. bool xmit_more_available;
  241. /* Statistics to supplement MAC stats */
  242. unsigned long tx_packets;
  243. /* Members shared between paths and sometimes updated */
  244. unsigned int empty_read_count ____cacheline_aligned_in_smp;
  245. #define EFX_EMPTY_COUNT_VALID 0x80000000
  246. atomic_t flush_outstanding;
  247. };
  248. /**
  249. * struct efx_rx_buffer - An Efx RX data buffer
  250. * @dma_addr: DMA base address of the buffer
  251. * @page: The associated page buffer.
  252. * Will be %NULL if the buffer slot is currently free.
  253. * @page_offset: If pending: offset in @page of DMA base address.
  254. * If completed: offset in @page of Ethernet header.
  255. * @len: If pending: length for DMA descriptor.
  256. * If completed: received length, excluding hash prefix.
  257. * @flags: Flags for buffer and packet state. These are only set on the
  258. * first buffer of a scattered packet.
  259. */
  260. struct efx_rx_buffer {
  261. dma_addr_t dma_addr;
  262. struct page *page;
  263. u16 page_offset;
  264. u16 len;
  265. u16 flags;
  266. };
  267. #define EFX_RX_BUF_LAST_IN_PAGE 0x0001
  268. #define EFX_RX_PKT_CSUMMED 0x0002
  269. #define EFX_RX_PKT_DISCARD 0x0004
  270. #define EFX_RX_PKT_TCP 0x0040
  271. #define EFX_RX_PKT_PREFIX_LEN 0x0080 /* length is in prefix only */
  272. /**
  273. * struct efx_rx_page_state - Page-based rx buffer state
  274. *
  275. * Inserted at the start of every page allocated for receive buffers.
  276. * Used to facilitate sharing dma mappings between recycled rx buffers
  277. * and those passed up to the kernel.
  278. *
  279. * @dma_addr: The dma address of this page.
  280. */
  281. struct efx_rx_page_state {
  282. dma_addr_t dma_addr;
  283. unsigned int __pad[0] ____cacheline_aligned;
  284. };
  285. /**
  286. * struct efx_rx_queue - An Efx RX queue
  287. * @efx: The associated Efx NIC
  288. * @core_index: Index of network core RX queue. Will be >= 0 iff this
  289. * is associated with a real RX queue.
  290. * @buffer: The software buffer ring
  291. * @rxd: The hardware descriptor ring
  292. * @ptr_mask: The size of the ring minus 1.
  293. * @refill_enabled: Enable refill whenever fill level is low
  294. * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
  295. * @rxq_flush_pending.
  296. * @added_count: Number of buffers added to the receive queue.
  297. * @notified_count: Number of buffers given to NIC (<= @added_count).
  298. * @removed_count: Number of buffers removed from the receive queue.
  299. * @scatter_n: Used by NIC specific receive code.
  300. * @scatter_len: Used by NIC specific receive code.
  301. * @page_ring: The ring to store DMA mapped pages for reuse.
  302. * @page_add: Counter to calculate the write pointer for the recycle ring.
  303. * @page_remove: Counter to calculate the read pointer for the recycle ring.
  304. * @page_recycle_count: The number of pages that have been recycled.
  305. * @page_recycle_failed: The number of pages that couldn't be recycled because
  306. * the kernel still held a reference to them.
  307. * @page_recycle_full: The number of pages that were released because the
  308. * recycle ring was full.
  309. * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
  310. * @max_fill: RX descriptor maximum fill level (<= ring size)
  311. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  312. * (<= @max_fill)
  313. * @min_fill: RX descriptor minimum non-zero fill level.
  314. * This records the minimum fill level observed when a ring
  315. * refill was triggered.
  316. * @recycle_count: RX buffer recycle counter.
  317. * @slow_fill: Timer used to defer efx_nic_generate_fill_event().
  318. */
  319. struct efx_rx_queue {
  320. struct efx_nic *efx;
  321. int core_index;
  322. struct efx_rx_buffer *buffer;
  323. struct efx_special_buffer rxd;
  324. unsigned int ptr_mask;
  325. bool refill_enabled;
  326. bool flush_pending;
  327. unsigned int added_count;
  328. unsigned int notified_count;
  329. unsigned int removed_count;
  330. unsigned int scatter_n;
  331. unsigned int scatter_len;
  332. struct page **page_ring;
  333. unsigned int page_add;
  334. unsigned int page_remove;
  335. unsigned int page_recycle_count;
  336. unsigned int page_recycle_failed;
  337. unsigned int page_recycle_full;
  338. unsigned int page_ptr_mask;
  339. unsigned int max_fill;
  340. unsigned int fast_fill_trigger;
  341. unsigned int min_fill;
  342. unsigned int min_overfill;
  343. unsigned int recycle_count;
  344. struct timer_list slow_fill;
  345. unsigned int slow_fill_count;
  346. /* Statistics to supplement MAC stats */
  347. unsigned long rx_packets;
  348. };
  349. enum efx_sync_events_state {
  350. SYNC_EVENTS_DISABLED = 0,
  351. SYNC_EVENTS_QUIESCENT,
  352. SYNC_EVENTS_REQUESTED,
  353. SYNC_EVENTS_VALID,
  354. };
  355. /**
  356. * struct efx_channel - An Efx channel
  357. *
  358. * A channel comprises an event queue, at least one TX queue, at least
  359. * one RX queue, and an associated tasklet for processing the event
  360. * queue.
  361. *
  362. * @efx: Associated Efx NIC
  363. * @channel: Channel instance number
  364. * @type: Channel type definition
  365. * @eventq_init: Event queue initialised flag
  366. * @enabled: Channel enabled indicator
  367. * @irq: IRQ number (MSI and MSI-X only)
  368. * @irq_moderation_us: IRQ moderation value (in microseconds)
  369. * @napi_dev: Net device used with NAPI
  370. * @napi_str: NAPI control structure
  371. * @state: state for NAPI vs busy polling
  372. * @state_lock: lock protecting @state
  373. * @eventq: Event queue buffer
  374. * @eventq_mask: Event queue pointer mask
  375. * @eventq_read_ptr: Event queue read pointer
  376. * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
  377. * @irq_count: Number of IRQs since last adaptive moderation decision
  378. * @irq_mod_score: IRQ moderation score
  379. * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
  380. * indexed by filter ID
  381. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  382. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  383. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  384. * @n_rx_mcast_mismatch: Count of unmatched multicast frames
  385. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  386. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  387. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  388. * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
  389. * lack of descriptors
  390. * @n_rx_merge_events: Number of RX merged completion events
  391. * @n_rx_merge_packets: Number of RX packets completed by merged events
  392. * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
  393. * __efx_rx_packet(), or zero if there is none
  394. * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
  395. * by __efx_rx_packet(), if @rx_pkt_n_frags != 0
  396. * @rx_queue: RX queue for this channel
  397. * @tx_queue: TX queues for this channel
  398. * @sync_events_state: Current state of sync events on this channel
  399. * @sync_timestamp_major: Major part of the last ptp sync event
  400. * @sync_timestamp_minor: Minor part of the last ptp sync event
  401. */
  402. struct efx_channel {
  403. struct efx_nic *efx;
  404. int channel;
  405. const struct efx_channel_type *type;
  406. bool eventq_init;
  407. bool enabled;
  408. int irq;
  409. unsigned int irq_moderation_us;
  410. struct net_device *napi_dev;
  411. struct napi_struct napi_str;
  412. #ifdef CONFIG_NET_RX_BUSY_POLL
  413. unsigned long busy_poll_state;
  414. #endif
  415. struct efx_special_buffer eventq;
  416. unsigned int eventq_mask;
  417. unsigned int eventq_read_ptr;
  418. int event_test_cpu;
  419. unsigned int irq_count;
  420. unsigned int irq_mod_score;
  421. #ifdef CONFIG_RFS_ACCEL
  422. unsigned int rfs_filters_added;
  423. #define RPS_FLOW_ID_INVALID 0xFFFFFFFF
  424. u32 *rps_flow_id;
  425. #endif
  426. unsigned n_rx_tobe_disc;
  427. unsigned n_rx_ip_hdr_chksum_err;
  428. unsigned n_rx_tcp_udp_chksum_err;
  429. unsigned n_rx_mcast_mismatch;
  430. unsigned n_rx_frm_trunc;
  431. unsigned n_rx_overlength;
  432. unsigned n_skbuff_leaks;
  433. unsigned int n_rx_nodesc_trunc;
  434. unsigned int n_rx_merge_events;
  435. unsigned int n_rx_merge_packets;
  436. unsigned int rx_pkt_n_frags;
  437. unsigned int rx_pkt_index;
  438. struct efx_rx_queue rx_queue;
  439. struct efx_tx_queue tx_queue[EFX_TXQ_TYPES];
  440. enum efx_sync_events_state sync_events_state;
  441. u32 sync_timestamp_major;
  442. u32 sync_timestamp_minor;
  443. };
  444. #ifdef CONFIG_NET_RX_BUSY_POLL
  445. enum efx_channel_busy_poll_state {
  446. EFX_CHANNEL_STATE_IDLE = 0,
  447. EFX_CHANNEL_STATE_NAPI = BIT(0),
  448. EFX_CHANNEL_STATE_NAPI_REQ_BIT = 1,
  449. EFX_CHANNEL_STATE_NAPI_REQ = BIT(1),
  450. EFX_CHANNEL_STATE_POLL_BIT = 2,
  451. EFX_CHANNEL_STATE_POLL = BIT(2),
  452. EFX_CHANNEL_STATE_DISABLE_BIT = 3,
  453. };
  454. static inline void efx_channel_busy_poll_init(struct efx_channel *channel)
  455. {
  456. WRITE_ONCE(channel->busy_poll_state, EFX_CHANNEL_STATE_IDLE);
  457. }
  458. /* Called from the device poll routine to get ownership of a channel. */
  459. static inline bool efx_channel_lock_napi(struct efx_channel *channel)
  460. {
  461. unsigned long prev, old = READ_ONCE(channel->busy_poll_state);
  462. while (1) {
  463. switch (old) {
  464. case EFX_CHANNEL_STATE_POLL:
  465. /* Ensure efx_channel_try_lock_poll() wont starve us */
  466. set_bit(EFX_CHANNEL_STATE_NAPI_REQ_BIT,
  467. &channel->busy_poll_state);
  468. /* fallthrough */
  469. case EFX_CHANNEL_STATE_POLL | EFX_CHANNEL_STATE_NAPI_REQ:
  470. return false;
  471. default:
  472. break;
  473. }
  474. prev = cmpxchg(&channel->busy_poll_state, old,
  475. EFX_CHANNEL_STATE_NAPI);
  476. if (unlikely(prev != old)) {
  477. /* This is likely to mean we've just entered polling
  478. * state. Go back round to set the REQ bit.
  479. */
  480. old = prev;
  481. continue;
  482. }
  483. return true;
  484. }
  485. }
  486. static inline void efx_channel_unlock_napi(struct efx_channel *channel)
  487. {
  488. /* Make sure write has completed from efx_channel_lock_napi() */
  489. smp_wmb();
  490. WRITE_ONCE(channel->busy_poll_state, EFX_CHANNEL_STATE_IDLE);
  491. }
  492. /* Called from efx_busy_poll(). */
  493. static inline bool efx_channel_try_lock_poll(struct efx_channel *channel)
  494. {
  495. return cmpxchg(&channel->busy_poll_state, EFX_CHANNEL_STATE_IDLE,
  496. EFX_CHANNEL_STATE_POLL) == EFX_CHANNEL_STATE_IDLE;
  497. }
  498. static inline void efx_channel_unlock_poll(struct efx_channel *channel)
  499. {
  500. clear_bit_unlock(EFX_CHANNEL_STATE_POLL_BIT, &channel->busy_poll_state);
  501. }
  502. static inline bool efx_channel_busy_polling(struct efx_channel *channel)
  503. {
  504. return test_bit(EFX_CHANNEL_STATE_POLL_BIT, &channel->busy_poll_state);
  505. }
  506. static inline void efx_channel_enable(struct efx_channel *channel)
  507. {
  508. clear_bit_unlock(EFX_CHANNEL_STATE_DISABLE_BIT,
  509. &channel->busy_poll_state);
  510. }
  511. /* Stop further polling or napi access.
  512. * Returns false if the channel is currently busy polling.
  513. */
  514. static inline bool efx_channel_disable(struct efx_channel *channel)
  515. {
  516. set_bit(EFX_CHANNEL_STATE_DISABLE_BIT, &channel->busy_poll_state);
  517. /* Implicit barrier in efx_channel_busy_polling() */
  518. return !efx_channel_busy_polling(channel);
  519. }
  520. #else /* CONFIG_NET_RX_BUSY_POLL */
  521. static inline void efx_channel_busy_poll_init(struct efx_channel *channel)
  522. {
  523. }
  524. static inline bool efx_channel_lock_napi(struct efx_channel *channel)
  525. {
  526. return true;
  527. }
  528. static inline void efx_channel_unlock_napi(struct efx_channel *channel)
  529. {
  530. }
  531. static inline bool efx_channel_try_lock_poll(struct efx_channel *channel)
  532. {
  533. return false;
  534. }
  535. static inline void efx_channel_unlock_poll(struct efx_channel *channel)
  536. {
  537. }
  538. static inline bool efx_channel_busy_polling(struct efx_channel *channel)
  539. {
  540. return false;
  541. }
  542. static inline void efx_channel_enable(struct efx_channel *channel)
  543. {
  544. }
  545. static inline bool efx_channel_disable(struct efx_channel *channel)
  546. {
  547. return true;
  548. }
  549. #endif /* CONFIG_NET_RX_BUSY_POLL */
  550. /**
  551. * struct efx_msi_context - Context for each MSI
  552. * @efx: The associated NIC
  553. * @index: Index of the channel/IRQ
  554. * @name: Name of the channel/IRQ
  555. *
  556. * Unlike &struct efx_channel, this is never reallocated and is always
  557. * safe for the IRQ handler to access.
  558. */
  559. struct efx_msi_context {
  560. struct efx_nic *efx;
  561. unsigned int index;
  562. char name[IFNAMSIZ + 6];
  563. };
  564. /**
  565. * struct efx_channel_type - distinguishes traffic and extra channels
  566. * @handle_no_channel: Handle failure to allocate an extra channel
  567. * @pre_probe: Set up extra state prior to initialisation
  568. * @post_remove: Tear down extra state after finalisation, if allocated.
  569. * May be called on channels that have not been probed.
  570. * @get_name: Generate the channel's name (used for its IRQ handler)
  571. * @copy: Copy the channel state prior to reallocation. May be %NULL if
  572. * reallocation is not supported.
  573. * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
  574. * @keep_eventq: Flag for whether event queue should be kept initialised
  575. * while the device is stopped
  576. */
  577. struct efx_channel_type {
  578. void (*handle_no_channel)(struct efx_nic *);
  579. int (*pre_probe)(struct efx_channel *);
  580. void (*post_remove)(struct efx_channel *);
  581. void (*get_name)(struct efx_channel *, char *buf, size_t len);
  582. struct efx_channel *(*copy)(const struct efx_channel *);
  583. bool (*receive_skb)(struct efx_channel *, struct sk_buff *);
  584. bool keep_eventq;
  585. };
  586. enum efx_led_mode {
  587. EFX_LED_OFF = 0,
  588. EFX_LED_ON = 1,
  589. EFX_LED_DEFAULT = 2
  590. };
  591. #define STRING_TABLE_LOOKUP(val, member) \
  592. ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
  593. extern const char *const efx_loopback_mode_names[];
  594. extern const unsigned int efx_loopback_mode_max;
  595. #define LOOPBACK_MODE(efx) \
  596. STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_loopback_mode)
  597. extern const char *const efx_reset_type_names[];
  598. extern const unsigned int efx_reset_type_max;
  599. #define RESET_TYPE(type) \
  600. STRING_TABLE_LOOKUP(type, efx_reset_type)
  601. enum efx_int_mode {
  602. /* Be careful if altering to correct macro below */
  603. EFX_INT_MODE_MSIX = 0,
  604. EFX_INT_MODE_MSI = 1,
  605. EFX_INT_MODE_LEGACY = 2,
  606. EFX_INT_MODE_MAX /* Insert any new items before this */
  607. };
  608. #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
  609. enum nic_state {
  610. STATE_UNINIT = 0, /* device being probed/removed or is frozen */
  611. STATE_READY = 1, /* hardware ready and netdev registered */
  612. STATE_DISABLED = 2, /* device disabled due to hardware errors */
  613. STATE_RECOVERY = 3, /* device recovering from PCI error */
  614. };
  615. /* Forward declaration */
  616. struct efx_nic;
  617. /* Pseudo bit-mask flow control field */
  618. #define EFX_FC_RX FLOW_CTRL_RX
  619. #define EFX_FC_TX FLOW_CTRL_TX
  620. #define EFX_FC_AUTO 4
  621. /**
  622. * struct efx_link_state - Current state of the link
  623. * @up: Link is up
  624. * @fd: Link is full-duplex
  625. * @fc: Actual flow control flags
  626. * @speed: Link speed (Mbps)
  627. */
  628. struct efx_link_state {
  629. bool up;
  630. bool fd;
  631. u8 fc;
  632. unsigned int speed;
  633. };
  634. static inline bool efx_link_state_equal(const struct efx_link_state *left,
  635. const struct efx_link_state *right)
  636. {
  637. return left->up == right->up && left->fd == right->fd &&
  638. left->fc == right->fc && left->speed == right->speed;
  639. }
  640. /**
  641. * struct efx_phy_operations - Efx PHY operations table
  642. * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
  643. * efx->loopback_modes.
  644. * @init: Initialise PHY
  645. * @fini: Shut down PHY
  646. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  647. * @poll: Update @link_state and report whether it changed.
  648. * Serialised by the mac_lock.
  649. * @get_settings: Get ethtool settings. Serialised by the mac_lock.
  650. * @set_settings: Set ethtool settings. Serialised by the mac_lock.
  651. * @set_npage_adv: Set abilities advertised in (Extended) Next Page
  652. * (only needed where AN bit is set in mmds)
  653. * @test_alive: Test that PHY is 'alive' (online)
  654. * @test_name: Get the name of a PHY-specific test/result
  655. * @run_tests: Run tests and record results as appropriate (offline).
  656. * Flags are the ethtool tests flags.
  657. */
  658. struct efx_phy_operations {
  659. int (*probe) (struct efx_nic *efx);
  660. int (*init) (struct efx_nic *efx);
  661. void (*fini) (struct efx_nic *efx);
  662. void (*remove) (struct efx_nic *efx);
  663. int (*reconfigure) (struct efx_nic *efx);
  664. bool (*poll) (struct efx_nic *efx);
  665. void (*get_settings) (struct efx_nic *efx,
  666. struct ethtool_cmd *ecmd);
  667. int (*set_settings) (struct efx_nic *efx,
  668. struct ethtool_cmd *ecmd);
  669. void (*set_npage_adv) (struct efx_nic *efx, u32);
  670. int (*test_alive) (struct efx_nic *efx);
  671. const char *(*test_name) (struct efx_nic *efx, unsigned int index);
  672. int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
  673. int (*get_module_eeprom) (struct efx_nic *efx,
  674. struct ethtool_eeprom *ee,
  675. u8 *data);
  676. int (*get_module_info) (struct efx_nic *efx,
  677. struct ethtool_modinfo *modinfo);
  678. };
  679. /**
  680. * enum efx_phy_mode - PHY operating mode flags
  681. * @PHY_MODE_NORMAL: on and should pass traffic
  682. * @PHY_MODE_TX_DISABLED: on with TX disabled
  683. * @PHY_MODE_LOW_POWER: set to low power through MDIO
  684. * @PHY_MODE_OFF: switched off through external control
  685. * @PHY_MODE_SPECIAL: on but will not pass traffic
  686. */
  687. enum efx_phy_mode {
  688. PHY_MODE_NORMAL = 0,
  689. PHY_MODE_TX_DISABLED = 1,
  690. PHY_MODE_LOW_POWER = 2,
  691. PHY_MODE_OFF = 4,
  692. PHY_MODE_SPECIAL = 8,
  693. };
  694. static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
  695. {
  696. return !!(mode & ~PHY_MODE_TX_DISABLED);
  697. }
  698. /**
  699. * struct efx_hw_stat_desc - Description of a hardware statistic
  700. * @name: Name of the statistic as visible through ethtool, or %NULL if
  701. * it should not be exposed
  702. * @dma_width: Width in bits (0 for non-DMA statistics)
  703. * @offset: Offset within stats (ignored for non-DMA statistics)
  704. */
  705. struct efx_hw_stat_desc {
  706. const char *name;
  707. u16 dma_width;
  708. u16 offset;
  709. };
  710. /* Number of bits used in a multicast filter hash address */
  711. #define EFX_MCAST_HASH_BITS 8
  712. /* Number of (single-bit) entries in a multicast filter hash */
  713. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  714. /* An Efx multicast filter hash */
  715. union efx_multicast_hash {
  716. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  717. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  718. };
  719. struct vfdi_status;
  720. /**
  721. * struct efx_nic - an Efx NIC
  722. * @name: Device name (net device name or bus id before net device registered)
  723. * @pci_dev: The PCI device
  724. * @node: List node for maintaning primary/secondary function lists
  725. * @primary: &struct efx_nic instance for the primary function of this
  726. * controller. May be the same structure, and may be %NULL if no
  727. * primary function is bound. Serialised by rtnl_lock.
  728. * @secondary_list: List of &struct efx_nic instances for the secondary PCI
  729. * functions of the controller, if this is for the primary function.
  730. * Serialised by rtnl_lock.
  731. * @type: Controller type attributes
  732. * @legacy_irq: IRQ number
  733. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  734. * Work items do not hold and must not acquire RTNL.
  735. * @workqueue_name: Name of workqueue
  736. * @reset_work: Scheduled reset workitem
  737. * @membase_phys: Memory BAR value as physical address
  738. * @membase: Memory BAR value
  739. * @interrupt_mode: Interrupt mode
  740. * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
  741. * @timer_max_ns: Interrupt timer maximum value, in nanoseconds
  742. * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  743. * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues
  744. * @irq_rx_moderation_us: IRQ moderation time for RX event queues
  745. * @msg_enable: Log message enable flags
  746. * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
  747. * @reset_pending: Bitmask for pending resets
  748. * @tx_queue: TX DMA queues
  749. * @rx_queue: RX DMA queues
  750. * @channel: Channels
  751. * @msi_context: Context for each MSI
  752. * @extra_channel_types: Types of extra (non-traffic) channels that
  753. * should be allocated for this NIC
  754. * @rxq_entries: Size of receive queues requested by user.
  755. * @txq_entries: Size of transmit queues requested by user.
  756. * @txq_stop_thresh: TX queue fill level at or above which we stop it.
  757. * @txq_wake_thresh: TX queue fill level at or below which we wake it.
  758. * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
  759. * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
  760. * @sram_lim_qw: Qword address limit of SRAM
  761. * @next_buffer_table: First available buffer table id
  762. * @n_channels: Number of channels in use
  763. * @n_rx_channels: Number of channels used for RX (= number of RX queues)
  764. * @n_tx_channels: Number of channels used for TX
  765. * @rx_ip_align: RX DMA address offset to have IP header aligned in
  766. * in accordance with NET_IP_ALIGN
  767. * @rx_dma_len: Current maximum RX DMA length
  768. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  769. * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
  770. * for use in sk_buff::truesize
  771. * @rx_prefix_size: Size of RX prefix before packet data
  772. * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data
  773. * (valid only if @rx_prefix_size != 0; always negative)
  774. * @rx_packet_len_offset: Offset of RX packet length from start of packet data
  775. * (valid only for NICs that set %EFX_RX_PKT_PREFIX_LEN; always negative)
  776. * @rx_packet_ts_offset: Offset of timestamp from start of packet data
  777. * (valid only if channel->sync_timestamps_enabled; always negative)
  778. * @rx_hash_key: Toeplitz hash key for RSS
  779. * @rx_indir_table: Indirection table for RSS
  780. * @rx_scatter: Scatter mode enabled for receives
  781. * @int_error_count: Number of internal errors seen recently
  782. * @int_error_expire: Time at which error count will be expired
  783. * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
  784. * acknowledge but do nothing else.
  785. * @irq_status: Interrupt status buffer
  786. * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
  787. * @irq_level: IRQ level/index for IRQs not triggered by an event queue
  788. * @selftest_work: Work item for asynchronous self-test
  789. * @mtd_list: List of MTDs attached to the NIC
  790. * @nic_data: Hardware dependent state
  791. * @mcdi: Management-Controller-to-Driver Interface state
  792. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  793. * efx_monitor() and efx_reconfigure_port()
  794. * @port_enabled: Port enabled indicator.
  795. * Serialises efx_stop_all(), efx_start_all(), efx_monitor() and
  796. * efx_mac_work() with kernel interfaces. Safe to read under any
  797. * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
  798. * be held to modify it.
  799. * @port_initialized: Port initialized?
  800. * @net_dev: Operating system network device. Consider holding the rtnl lock
  801. * @fixed_features: Features which cannot be turned off
  802. * @stats_buffer: DMA buffer for statistics
  803. * @phy_type: PHY type
  804. * @phy_op: PHY interface
  805. * @phy_data: PHY private data (including PHY-specific stats)
  806. * @mdio: PHY MDIO interface
  807. * @mdio_bus: PHY MDIO bus ID (only used by Siena)
  808. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  809. * @link_advertising: Autonegotiation advertising flags
  810. * @link_state: Current state of the link
  811. * @n_link_state_changes: Number of times the link has changed state
  812. * @unicast_filter: Flag for Falcon-arch simple unicast filter.
  813. * Protected by @mac_lock.
  814. * @multicast_hash: Multicast hash table for Falcon-arch.
  815. * Protected by @mac_lock.
  816. * @wanted_fc: Wanted flow control flags
  817. * @fc_disable: When non-zero flow control is disabled. Typically used to
  818. * ensure that network back pressure doesn't delay dma queue flushes.
  819. * Serialised by the rtnl lock.
  820. * @mac_work: Work item for changing MAC promiscuity and multicast hash
  821. * @loopback_mode: Loopback status
  822. * @loopback_modes: Supported loopback mode bitmask
  823. * @loopback_selftest: Offline self-test private state
  824. * @filter_sem: Filter table rw_semaphore, for freeing the table
  825. * @filter_lock: Filter table lock, for mere content changes
  826. * @filter_state: Architecture-dependent filter table state
  827. * @rps_expire_channel: Next channel to check for expiry
  828. * @rps_expire_index: Next index to check for expiry in
  829. * @rps_expire_channel's @rps_flow_id
  830. * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
  831. * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
  832. * Decremented when the efx_flush_rx_queue() is called.
  833. * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
  834. * completed (either success or failure). Not used when MCDI is used to
  835. * flush receive queues.
  836. * @flush_wq: wait queue used by efx_nic_flush_queues() to wait for flush completions.
  837. * @vf_count: Number of VFs intended to be enabled.
  838. * @vf_init_count: Number of VFs that have been fully initialised.
  839. * @vi_scale: log2 number of vnics per VF.
  840. * @ptp_data: PTP state data
  841. * @vpd_sn: Serial number read from VPD
  842. * @monitor_work: Hardware monitor workitem
  843. * @biu_lock: BIU (bus interface unit) lock
  844. * @last_irq_cpu: Last CPU to handle a possible test interrupt. This
  845. * field is used by efx_test_interrupts() to verify that an
  846. * interrupt has occurred.
  847. * @stats_lock: Statistics update lock. Must be held when calling
  848. * efx_nic_type::{update,start,stop}_stats.
  849. * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb
  850. *
  851. * This is stored in the private area of the &struct net_device.
  852. */
  853. struct efx_nic {
  854. /* The following fields should be written very rarely */
  855. char name[IFNAMSIZ];
  856. struct list_head node;
  857. struct efx_nic *primary;
  858. struct list_head secondary_list;
  859. struct pci_dev *pci_dev;
  860. unsigned int port_num;
  861. const struct efx_nic_type *type;
  862. int legacy_irq;
  863. bool eeh_disabled_legacy_irq;
  864. struct workqueue_struct *workqueue;
  865. char workqueue_name[16];
  866. struct work_struct reset_work;
  867. resource_size_t membase_phys;
  868. void __iomem *membase;
  869. enum efx_int_mode interrupt_mode;
  870. unsigned int timer_quantum_ns;
  871. unsigned int timer_max_ns;
  872. bool irq_rx_adaptive;
  873. unsigned int irq_mod_step_us;
  874. unsigned int irq_rx_moderation_us;
  875. u32 msg_enable;
  876. enum nic_state state;
  877. unsigned long reset_pending;
  878. struct efx_channel *channel[EFX_MAX_CHANNELS];
  879. struct efx_msi_context msi_context[EFX_MAX_CHANNELS];
  880. const struct efx_channel_type *
  881. extra_channel_type[EFX_MAX_EXTRA_CHANNELS];
  882. unsigned rxq_entries;
  883. unsigned txq_entries;
  884. unsigned int txq_stop_thresh;
  885. unsigned int txq_wake_thresh;
  886. unsigned tx_dc_base;
  887. unsigned rx_dc_base;
  888. unsigned sram_lim_qw;
  889. unsigned next_buffer_table;
  890. unsigned int max_channels;
  891. unsigned int max_tx_channels;
  892. unsigned n_channels;
  893. unsigned n_rx_channels;
  894. unsigned rss_spread;
  895. unsigned tx_channel_offset;
  896. unsigned n_tx_channels;
  897. unsigned int rx_ip_align;
  898. unsigned int rx_dma_len;
  899. unsigned int rx_buffer_order;
  900. unsigned int rx_buffer_truesize;
  901. unsigned int rx_page_buf_step;
  902. unsigned int rx_bufs_per_page;
  903. unsigned int rx_pages_per_batch;
  904. unsigned int rx_prefix_size;
  905. int rx_packet_hash_offset;
  906. int rx_packet_len_offset;
  907. int rx_packet_ts_offset;
  908. u8 rx_hash_key[40];
  909. u32 rx_indir_table[128];
  910. bool rx_scatter;
  911. unsigned int_error_count;
  912. unsigned long int_error_expire;
  913. bool irq_soft_enabled;
  914. struct efx_buffer irq_status;
  915. unsigned irq_zero_count;
  916. unsigned irq_level;
  917. struct delayed_work selftest_work;
  918. #ifdef CONFIG_SFC_MTD
  919. struct list_head mtd_list;
  920. #endif
  921. void *nic_data;
  922. struct efx_mcdi_data *mcdi;
  923. struct mutex mac_lock;
  924. struct work_struct mac_work;
  925. bool port_enabled;
  926. bool mc_bist_for_other_fn;
  927. bool port_initialized;
  928. struct net_device *net_dev;
  929. netdev_features_t fixed_features;
  930. struct efx_buffer stats_buffer;
  931. u64 rx_nodesc_drops_total;
  932. u64 rx_nodesc_drops_while_down;
  933. bool rx_nodesc_drops_prev_state;
  934. unsigned int phy_type;
  935. const struct efx_phy_operations *phy_op;
  936. void *phy_data;
  937. struct mdio_if_info mdio;
  938. unsigned int mdio_bus;
  939. enum efx_phy_mode phy_mode;
  940. u32 link_advertising;
  941. struct efx_link_state link_state;
  942. unsigned int n_link_state_changes;
  943. bool unicast_filter;
  944. union efx_multicast_hash multicast_hash;
  945. u8 wanted_fc;
  946. unsigned fc_disable;
  947. atomic_t rx_reset;
  948. enum efx_loopback_mode loopback_mode;
  949. u64 loopback_modes;
  950. void *loopback_selftest;
  951. struct rw_semaphore filter_sem;
  952. spinlock_t filter_lock;
  953. void *filter_state;
  954. #ifdef CONFIG_RFS_ACCEL
  955. unsigned int rps_expire_channel;
  956. unsigned int rps_expire_index;
  957. #endif
  958. atomic_t active_queues;
  959. atomic_t rxq_flush_pending;
  960. atomic_t rxq_flush_outstanding;
  961. wait_queue_head_t flush_wq;
  962. #ifdef CONFIG_SFC_SRIOV
  963. unsigned vf_count;
  964. unsigned vf_init_count;
  965. unsigned vi_scale;
  966. #endif
  967. struct efx_ptp_data *ptp_data;
  968. char *vpd_sn;
  969. /* The following fields may be written more often */
  970. struct delayed_work monitor_work ____cacheline_aligned_in_smp;
  971. spinlock_t biu_lock;
  972. int last_irq_cpu;
  973. spinlock_t stats_lock;
  974. atomic_t n_rx_noskb_drops;
  975. };
  976. static inline int efx_dev_registered(struct efx_nic *efx)
  977. {
  978. return efx->net_dev->reg_state == NETREG_REGISTERED;
  979. }
  980. static inline unsigned int efx_port_num(struct efx_nic *efx)
  981. {
  982. return efx->port_num;
  983. }
  984. struct efx_mtd_partition {
  985. struct list_head node;
  986. struct mtd_info mtd;
  987. const char *dev_type_name;
  988. const char *type_name;
  989. char name[IFNAMSIZ + 20];
  990. };
  991. /**
  992. * struct efx_nic_type - Efx device type definition
  993. * @mem_bar: Get the memory BAR
  994. * @mem_map_size: Get memory BAR mapped size
  995. * @probe: Probe the controller
  996. * @remove: Free resources allocated by probe()
  997. * @init: Initialise the controller
  998. * @dimension_resources: Dimension controller resources (buffer table,
  999. * and VIs once the available interrupt resources are clear)
  1000. * @fini: Shut down the controller
  1001. * @monitor: Periodic function for polling link state and hardware monitor
  1002. * @map_reset_reason: Map ethtool reset reason to a reset method
  1003. * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
  1004. * @reset: Reset the controller hardware and possibly the PHY. This will
  1005. * be called while the controller is uninitialised.
  1006. * @probe_port: Probe the MAC and PHY
  1007. * @remove_port: Free resources allocated by probe_port()
  1008. * @handle_global_event: Handle a "global" event (may be %NULL)
  1009. * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
  1010. * @prepare_flush: Prepare the hardware for flushing the DMA queues
  1011. * (for Falcon architecture)
  1012. * @finish_flush: Clean up after flushing the DMA queues (for Falcon
  1013. * architecture)
  1014. * @prepare_flr: Prepare for an FLR
  1015. * @finish_flr: Clean up after an FLR
  1016. * @describe_stats: Describe statistics for ethtool
  1017. * @update_stats: Update statistics not provided by event handling.
  1018. * Either argument may be %NULL.
  1019. * @start_stats: Start the regular fetching of statistics
  1020. * @pull_stats: Pull stats from the NIC and wait until they arrive.
  1021. * @stop_stats: Stop the regular fetching of statistics
  1022. * @set_id_led: Set state of identifying LED or revert to automatic function
  1023. * @push_irq_moderation: Apply interrupt moderation value
  1024. * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
  1025. * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
  1026. * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
  1027. * to the hardware. Serialised by the mac_lock.
  1028. * @check_mac_fault: Check MAC fault state. True if fault present.
  1029. * @get_wol: Get WoL configuration from driver state
  1030. * @set_wol: Push WoL configuration to the NIC
  1031. * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
  1032. * @test_chip: Test registers. May use efx_farch_test_registers(), and is
  1033. * expected to reset the NIC.
  1034. * @test_nvram: Test validity of NVRAM contents
  1035. * @mcdi_request: Send an MCDI request with the given header and SDU.
  1036. * The SDU length may be any value from 0 up to the protocol-
  1037. * defined maximum, but its buffer will be padded to a multiple
  1038. * of 4 bytes.
  1039. * @mcdi_poll_response: Test whether an MCDI response is available.
  1040. * @mcdi_read_response: Read the MCDI response PDU. The offset will
  1041. * be a multiple of 4. The length may not be, but the buffer
  1042. * will be padded so it is safe to round up.
  1043. * @mcdi_poll_reboot: Test whether the MCDI has rebooted. If so,
  1044. * return an appropriate error code for aborting any current
  1045. * request; otherwise return 0.
  1046. * @irq_enable_master: Enable IRQs on the NIC. Each event queue must
  1047. * be separately enabled after this.
  1048. * @irq_test_generate: Generate a test IRQ
  1049. * @irq_disable_non_ev: Disable non-event IRQs on the NIC. Each event
  1050. * queue must be separately disabled before this.
  1051. * @irq_handle_msi: Handle MSI for a channel. The @dev_id argument is
  1052. * a pointer to the &struct efx_msi_context for the channel.
  1053. * @irq_handle_legacy: Handle legacy interrupt. The @dev_id argument
  1054. * is a pointer to the &struct efx_nic.
  1055. * @tx_probe: Allocate resources for TX queue
  1056. * @tx_init: Initialise TX queue on the NIC
  1057. * @tx_remove: Free resources for TX queue
  1058. * @tx_write: Write TX descriptors and doorbell
  1059. * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC
  1060. * @rx_probe: Allocate resources for RX queue
  1061. * @rx_init: Initialise RX queue on the NIC
  1062. * @rx_remove: Free resources for RX queue
  1063. * @rx_write: Write RX descriptors and doorbell
  1064. * @rx_defer_refill: Generate a refill reminder event
  1065. * @ev_probe: Allocate resources for event queue
  1066. * @ev_init: Initialise event queue on the NIC
  1067. * @ev_fini: Deinitialise event queue on the NIC
  1068. * @ev_remove: Free resources for event queue
  1069. * @ev_process: Process events for a queue, up to the given NAPI quota
  1070. * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
  1071. * @ev_test_generate: Generate a test event
  1072. * @filter_table_probe: Probe filter capabilities and set up filter software state
  1073. * @filter_table_restore: Restore filters removed from hardware
  1074. * @filter_table_remove: Remove filters from hardware and tear down software state
  1075. * @filter_update_rx_scatter: Update filters after change to rx scatter setting
  1076. * @filter_insert: add or replace a filter
  1077. * @filter_remove_safe: remove a filter by ID, carefully
  1078. * @filter_get_safe: retrieve a filter by ID, carefully
  1079. * @filter_clear_rx: Remove all RX filters whose priority is less than or
  1080. * equal to the given priority and is not %EFX_FILTER_PRI_AUTO
  1081. * @filter_count_rx_used: Get the number of filters in use at a given priority
  1082. * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
  1083. * @filter_get_rx_ids: Get list of RX filters at a given priority
  1084. * @filter_rfs_insert: Add or replace a filter for RFS. This must be
  1085. * atomic. The hardware change may be asynchronous but should
  1086. * not be delayed for long. It may fail if this can't be done
  1087. * atomically.
  1088. * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
  1089. * This must check whether the specified table entry is used by RFS
  1090. * and that rps_may_expire_flow() returns true for it.
  1091. * @mtd_probe: Probe and add MTD partitions associated with this net device,
  1092. * using efx_mtd_add()
  1093. * @mtd_rename: Set an MTD partition name using the net device name
  1094. * @mtd_read: Read from an MTD partition
  1095. * @mtd_erase: Erase part of an MTD partition
  1096. * @mtd_write: Write to an MTD partition
  1097. * @mtd_sync: Wait for write-back to complete on MTD partition. This
  1098. * also notifies the driver that a writer has finished using this
  1099. * partition.
  1100. * @ptp_write_host_time: Send host time to MC as part of sync protocol
  1101. * @ptp_set_ts_sync_events: Enable or disable sync events for inline RX
  1102. * timestamping, possibly only temporarily for the purposes of a reset.
  1103. * @ptp_set_ts_config: Set hardware timestamp configuration. The flags
  1104. * and tx_type will already have been validated but this operation
  1105. * must validate and update rx_filter.
  1106. * @set_mac_address: Set the MAC address of the device
  1107. * @revision: Hardware architecture revision
  1108. * @txd_ptr_tbl_base: TX descriptor ring base address
  1109. * @rxd_ptr_tbl_base: RX descriptor ring base address
  1110. * @buf_tbl_base: Buffer table base address
  1111. * @evq_ptr_tbl_base: Event queue pointer table base address
  1112. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  1113. * @max_dma_mask: Maximum possible DMA mask
  1114. * @rx_prefix_size: Size of RX prefix before packet data
  1115. * @rx_hash_offset: Offset of RX flow hash within prefix
  1116. * @rx_ts_offset: Offset of timestamp within prefix
  1117. * @rx_buffer_padding: Size of padding at end of RX packet
  1118. * @can_rx_scatter: NIC is able to scatter packets to multiple buffers
  1119. * @always_rx_scatter: NIC will always scatter packets to multiple buffers
  1120. * @max_interrupt_mode: Highest capability interrupt mode supported
  1121. * from &enum efx_init_mode.
  1122. * @timer_period_max: Maximum period of interrupt timer (in ticks)
  1123. * @offload_features: net_device feature flags for protocol offload
  1124. * features implemented in hardware
  1125. * @mcdi_max_ver: Maximum MCDI version supported
  1126. * @hwtstamp_filters: Mask of hardware timestamp filter types supported
  1127. */
  1128. struct efx_nic_type {
  1129. bool is_vf;
  1130. unsigned int mem_bar;
  1131. unsigned int (*mem_map_size)(struct efx_nic *efx);
  1132. int (*probe)(struct efx_nic *efx);
  1133. void (*remove)(struct efx_nic *efx);
  1134. int (*init)(struct efx_nic *efx);
  1135. int (*dimension_resources)(struct efx_nic *efx);
  1136. void (*fini)(struct efx_nic *efx);
  1137. void (*monitor)(struct efx_nic *efx);
  1138. enum reset_type (*map_reset_reason)(enum reset_type reason);
  1139. int (*map_reset_flags)(u32 *flags);
  1140. int (*reset)(struct efx_nic *efx, enum reset_type method);
  1141. int (*probe_port)(struct efx_nic *efx);
  1142. void (*remove_port)(struct efx_nic *efx);
  1143. bool (*handle_global_event)(struct efx_channel *channel, efx_qword_t *);
  1144. int (*fini_dmaq)(struct efx_nic *efx);
  1145. void (*prepare_flush)(struct efx_nic *efx);
  1146. void (*finish_flush)(struct efx_nic *efx);
  1147. void (*prepare_flr)(struct efx_nic *efx);
  1148. void (*finish_flr)(struct efx_nic *efx);
  1149. size_t (*describe_stats)(struct efx_nic *efx, u8 *names);
  1150. size_t (*update_stats)(struct efx_nic *efx, u64 *full_stats,
  1151. struct rtnl_link_stats64 *core_stats);
  1152. void (*start_stats)(struct efx_nic *efx);
  1153. void (*pull_stats)(struct efx_nic *efx);
  1154. void (*stop_stats)(struct efx_nic *efx);
  1155. void (*set_id_led)(struct efx_nic *efx, enum efx_led_mode mode);
  1156. void (*push_irq_moderation)(struct efx_channel *channel);
  1157. int (*reconfigure_port)(struct efx_nic *efx);
  1158. void (*prepare_enable_fc_tx)(struct efx_nic *efx);
  1159. int (*reconfigure_mac)(struct efx_nic *efx);
  1160. bool (*check_mac_fault)(struct efx_nic *efx);
  1161. void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
  1162. int (*set_wol)(struct efx_nic *efx, u32 type);
  1163. void (*resume_wol)(struct efx_nic *efx);
  1164. int (*test_chip)(struct efx_nic *efx, struct efx_self_tests *tests);
  1165. int (*test_nvram)(struct efx_nic *efx);
  1166. void (*mcdi_request)(struct efx_nic *efx,
  1167. const efx_dword_t *hdr, size_t hdr_len,
  1168. const efx_dword_t *sdu, size_t sdu_len);
  1169. bool (*mcdi_poll_response)(struct efx_nic *efx);
  1170. void (*mcdi_read_response)(struct efx_nic *efx, efx_dword_t *pdu,
  1171. size_t pdu_offset, size_t pdu_len);
  1172. int (*mcdi_poll_reboot)(struct efx_nic *efx);
  1173. void (*mcdi_reboot_detected)(struct efx_nic *efx);
  1174. void (*irq_enable_master)(struct efx_nic *efx);
  1175. int (*irq_test_generate)(struct efx_nic *efx);
  1176. void (*irq_disable_non_ev)(struct efx_nic *efx);
  1177. irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
  1178. irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
  1179. int (*tx_probe)(struct efx_tx_queue *tx_queue);
  1180. void (*tx_init)(struct efx_tx_queue *tx_queue);
  1181. void (*tx_remove)(struct efx_tx_queue *tx_queue);
  1182. void (*tx_write)(struct efx_tx_queue *tx_queue);
  1183. int (*rx_push_rss_config)(struct efx_nic *efx, bool user,
  1184. const u32 *rx_indir_table);
  1185. int (*rx_probe)(struct efx_rx_queue *rx_queue);
  1186. void (*rx_init)(struct efx_rx_queue *rx_queue);
  1187. void (*rx_remove)(struct efx_rx_queue *rx_queue);
  1188. void (*rx_write)(struct efx_rx_queue *rx_queue);
  1189. void (*rx_defer_refill)(struct efx_rx_queue *rx_queue);
  1190. int (*ev_probe)(struct efx_channel *channel);
  1191. int (*ev_init)(struct efx_channel *channel);
  1192. void (*ev_fini)(struct efx_channel *channel);
  1193. void (*ev_remove)(struct efx_channel *channel);
  1194. int (*ev_process)(struct efx_channel *channel, int quota);
  1195. void (*ev_read_ack)(struct efx_channel *channel);
  1196. void (*ev_test_generate)(struct efx_channel *channel);
  1197. int (*filter_table_probe)(struct efx_nic *efx);
  1198. void (*filter_table_restore)(struct efx_nic *efx);
  1199. void (*filter_table_remove)(struct efx_nic *efx);
  1200. void (*filter_update_rx_scatter)(struct efx_nic *efx);
  1201. s32 (*filter_insert)(struct efx_nic *efx,
  1202. struct efx_filter_spec *spec, bool replace);
  1203. int (*filter_remove_safe)(struct efx_nic *efx,
  1204. enum efx_filter_priority priority,
  1205. u32 filter_id);
  1206. int (*filter_get_safe)(struct efx_nic *efx,
  1207. enum efx_filter_priority priority,
  1208. u32 filter_id, struct efx_filter_spec *);
  1209. int (*filter_clear_rx)(struct efx_nic *efx,
  1210. enum efx_filter_priority priority);
  1211. u32 (*filter_count_rx_used)(struct efx_nic *efx,
  1212. enum efx_filter_priority priority);
  1213. u32 (*filter_get_rx_id_limit)(struct efx_nic *efx);
  1214. s32 (*filter_get_rx_ids)(struct efx_nic *efx,
  1215. enum efx_filter_priority priority,
  1216. u32 *buf, u32 size);
  1217. #ifdef CONFIG_RFS_ACCEL
  1218. s32 (*filter_rfs_insert)(struct efx_nic *efx,
  1219. struct efx_filter_spec *spec);
  1220. bool (*filter_rfs_expire_one)(struct efx_nic *efx, u32 flow_id,
  1221. unsigned int index);
  1222. #endif
  1223. #ifdef CONFIG_SFC_MTD
  1224. int (*mtd_probe)(struct efx_nic *efx);
  1225. void (*mtd_rename)(struct efx_mtd_partition *part);
  1226. int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len,
  1227. size_t *retlen, u8 *buffer);
  1228. int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len);
  1229. int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len,
  1230. size_t *retlen, const u8 *buffer);
  1231. int (*mtd_sync)(struct mtd_info *mtd);
  1232. #endif
  1233. void (*ptp_write_host_time)(struct efx_nic *efx, u32 host_time);
  1234. int (*ptp_set_ts_sync_events)(struct efx_nic *efx, bool en, bool temp);
  1235. int (*ptp_set_ts_config)(struct efx_nic *efx,
  1236. struct hwtstamp_config *init);
  1237. int (*sriov_configure)(struct efx_nic *efx, int num_vfs);
  1238. int (*vlan_rx_add_vid)(struct efx_nic *efx, __be16 proto, u16 vid);
  1239. int (*vlan_rx_kill_vid)(struct efx_nic *efx, __be16 proto, u16 vid);
  1240. int (*sriov_init)(struct efx_nic *efx);
  1241. void (*sriov_fini)(struct efx_nic *efx);
  1242. bool (*sriov_wanted)(struct efx_nic *efx);
  1243. void (*sriov_reset)(struct efx_nic *efx);
  1244. void (*sriov_flr)(struct efx_nic *efx, unsigned vf_i);
  1245. int (*sriov_set_vf_mac)(struct efx_nic *efx, int vf_i, u8 *mac);
  1246. int (*sriov_set_vf_vlan)(struct efx_nic *efx, int vf_i, u16 vlan,
  1247. u8 qos);
  1248. int (*sriov_set_vf_spoofchk)(struct efx_nic *efx, int vf_i,
  1249. bool spoofchk);
  1250. int (*sriov_get_vf_config)(struct efx_nic *efx, int vf_i,
  1251. struct ifla_vf_info *ivi);
  1252. int (*sriov_set_vf_link_state)(struct efx_nic *efx, int vf_i,
  1253. int link_state);
  1254. int (*sriov_get_phys_port_id)(struct efx_nic *efx,
  1255. struct netdev_phys_item_id *ppid);
  1256. int (*vswitching_probe)(struct efx_nic *efx);
  1257. int (*vswitching_restore)(struct efx_nic *efx);
  1258. void (*vswitching_remove)(struct efx_nic *efx);
  1259. int (*get_mac_address)(struct efx_nic *efx, unsigned char *perm_addr);
  1260. int (*set_mac_address)(struct efx_nic *efx);
  1261. int revision;
  1262. unsigned int txd_ptr_tbl_base;
  1263. unsigned int rxd_ptr_tbl_base;
  1264. unsigned int buf_tbl_base;
  1265. unsigned int evq_ptr_tbl_base;
  1266. unsigned int evq_rptr_tbl_base;
  1267. u64 max_dma_mask;
  1268. unsigned int rx_prefix_size;
  1269. unsigned int rx_hash_offset;
  1270. unsigned int rx_ts_offset;
  1271. unsigned int rx_buffer_padding;
  1272. bool can_rx_scatter;
  1273. bool always_rx_scatter;
  1274. unsigned int max_interrupt_mode;
  1275. unsigned int timer_period_max;
  1276. netdev_features_t offload_features;
  1277. int mcdi_max_ver;
  1278. unsigned int max_rx_ip_filters;
  1279. u32 hwtstamp_filters;
  1280. };
  1281. /**************************************************************************
  1282. *
  1283. * Prototypes and inline functions
  1284. *
  1285. *************************************************************************/
  1286. static inline struct efx_channel *
  1287. efx_get_channel(struct efx_nic *efx, unsigned index)
  1288. {
  1289. EFX_BUG_ON_PARANOID(index >= efx->n_channels);
  1290. return efx->channel[index];
  1291. }
  1292. /* Iterate over all used channels */
  1293. #define efx_for_each_channel(_channel, _efx) \
  1294. for (_channel = (_efx)->channel[0]; \
  1295. _channel; \
  1296. _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
  1297. (_efx)->channel[_channel->channel + 1] : NULL)
  1298. /* Iterate over all used channels in reverse */
  1299. #define efx_for_each_channel_rev(_channel, _efx) \
  1300. for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \
  1301. _channel; \
  1302. _channel = _channel->channel ? \
  1303. (_efx)->channel[_channel->channel - 1] : NULL)
  1304. static inline struct efx_tx_queue *
  1305. efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)
  1306. {
  1307. EFX_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
  1308. type >= EFX_TXQ_TYPES);
  1309. return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
  1310. }
  1311. static inline bool efx_channel_has_tx_queues(struct efx_channel *channel)
  1312. {
  1313. return channel->channel - channel->efx->tx_channel_offset <
  1314. channel->efx->n_tx_channels;
  1315. }
  1316. static inline struct efx_tx_queue *
  1317. efx_channel_get_tx_queue(struct efx_channel *channel, unsigned type)
  1318. {
  1319. EFX_BUG_ON_PARANOID(!efx_channel_has_tx_queues(channel) ||
  1320. type >= EFX_TXQ_TYPES);
  1321. return &channel->tx_queue[type];
  1322. }
  1323. static inline bool efx_tx_queue_used(struct efx_tx_queue *tx_queue)
  1324. {
  1325. return !(tx_queue->efx->net_dev->num_tc < 2 &&
  1326. tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI);
  1327. }
  1328. /* Iterate over all TX queues belonging to a channel */
  1329. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  1330. if (!efx_channel_has_tx_queues(_channel)) \
  1331. ; \
  1332. else \
  1333. for (_tx_queue = (_channel)->tx_queue; \
  1334. _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES && \
  1335. efx_tx_queue_used(_tx_queue); \
  1336. _tx_queue++)
  1337. /* Iterate over all possible TX queues belonging to a channel */
  1338. #define efx_for_each_possible_channel_tx_queue(_tx_queue, _channel) \
  1339. if (!efx_channel_has_tx_queues(_channel)) \
  1340. ; \
  1341. else \
  1342. for (_tx_queue = (_channel)->tx_queue; \
  1343. _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES; \
  1344. _tx_queue++)
  1345. static inline bool efx_channel_has_rx_queue(struct efx_channel *channel)
  1346. {
  1347. return channel->rx_queue.core_index >= 0;
  1348. }
  1349. static inline struct efx_rx_queue *
  1350. efx_channel_get_rx_queue(struct efx_channel *channel)
  1351. {
  1352. EFX_BUG_ON_PARANOID(!efx_channel_has_rx_queue(channel));
  1353. return &channel->rx_queue;
  1354. }
  1355. /* Iterate over all RX queues belonging to a channel */
  1356. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  1357. if (!efx_channel_has_rx_queue(_channel)) \
  1358. ; \
  1359. else \
  1360. for (_rx_queue = &(_channel)->rx_queue; \
  1361. _rx_queue; \
  1362. _rx_queue = NULL)
  1363. static inline struct efx_channel *
  1364. efx_rx_queue_channel(struct efx_rx_queue *rx_queue)
  1365. {
  1366. return container_of(rx_queue, struct efx_channel, rx_queue);
  1367. }
  1368. static inline int efx_rx_queue_index(struct efx_rx_queue *rx_queue)
  1369. {
  1370. return efx_rx_queue_channel(rx_queue)->channel;
  1371. }
  1372. /* Returns a pointer to the specified receive buffer in the RX
  1373. * descriptor queue.
  1374. */
  1375. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  1376. unsigned int index)
  1377. {
  1378. return &rx_queue->buffer[index];
  1379. }
  1380. /**
  1381. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  1382. *
  1383. * This calculates the maximum frame length that will be used for a
  1384. * given MTU. The frame length will be equal to the MTU plus a
  1385. * constant amount of header space and padding. This is the quantity
  1386. * that the net driver will program into the MAC as the maximum frame
  1387. * length.
  1388. *
  1389. * The 10G MAC requires 8-byte alignment on the frame
  1390. * length, so we round up to the nearest 8.
  1391. *
  1392. * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
  1393. * XGMII cycle). If the frame length reaches the maximum value in the
  1394. * same cycle, the XMAC can miss the IPG altogether. We work around
  1395. * this by adding a further 16 bytes.
  1396. */
  1397. #define EFX_FRAME_PAD 16
  1398. #define EFX_MAX_FRAME_LEN(mtu) \
  1399. (ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EFX_FRAME_PAD), 8))
  1400. static inline bool efx_xmit_with_hwtstamp(struct sk_buff *skb)
  1401. {
  1402. return skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP;
  1403. }
  1404. static inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)
  1405. {
  1406. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  1407. }
  1408. /* Get all supported features.
  1409. * If a feature is not fixed, it is present in hw_features.
  1410. * If a feature is fixed, it does not present in hw_features, but
  1411. * always in features.
  1412. */
  1413. static inline netdev_features_t efx_supported_features(const struct efx_nic *efx)
  1414. {
  1415. const struct net_device *net_dev = efx->net_dev;
  1416. return net_dev->features | net_dev->hw_features;
  1417. }
  1418. #endif /* EFX_NET_DRIVER_H */