net_driver.h 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2005-2006 Fen Systems Ltd.
  5. * Copyright 2005-2013 Solarflare Communications Inc.
  6. */
  7. /* Common definitions for all Efx net driver code */
  8. #ifndef EFX_NET_DRIVER_H
  9. #define EFX_NET_DRIVER_H
  10. #include <linux/netdevice.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/ethtool.h>
  13. #include <linux/if_vlan.h>
  14. #include <linux/timer.h>
  15. #include <linux/mdio.h>
  16. #include <linux/list.h>
  17. #include <linux/pci.h>
  18. #include <linux/device.h>
  19. #include <linux/highmem.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/mutex.h>
  22. #include <linux/rwsem.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/mtd/mtd.h>
  25. #include <net/busy_poll.h>
  26. #include <net/xdp.h>
  27. #include "enum.h"
  28. #include "bitfield.h"
  29. #include "filter.h"
  30. /**************************************************************************
  31. *
  32. * Build definitions
  33. *
  34. **************************************************************************/
  35. #ifdef DEBUG
  36. #define EFX_WARN_ON_ONCE_PARANOID(x) WARN_ON_ONCE(x)
  37. #define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
  38. #else
  39. #define EFX_WARN_ON_ONCE_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_OUTER_CSUM 1 /* Outer checksum offload */
  58. #define EFX_TXQ_TYPE_INNER_CSUM 2 /* Inner checksum offload */
  59. #define EFX_TXQ_TYPE_HIGHPRI 4 /* High-priority (for TC) */
  60. #define EFX_TXQ_TYPES 8
  61. /* HIGHPRI is Siena-only, and INNER_CSUM is EF10, so no need for both */
  62. #define EFX_MAX_TXQ_PER_CHANNEL 4
  63. #define EFX_MAX_TX_QUEUES (EFX_MAX_TXQ_PER_CHANNEL * EFX_MAX_CHANNELS)
  64. /* Maximum possible MTU the driver supports */
  65. #define EFX_MAX_MTU (9 * 1024)
  66. /* Minimum MTU, from RFC791 (IP) */
  67. #define EFX_MIN_MTU 68
  68. /* Maximum total header length for TSOv2 */
  69. #define EFX_TSO2_MAX_HDRLEN 208
  70. /* Size of an RX scatter buffer. Small enough to pack 2 into a 4K page,
  71. * and should be a multiple of the cache line size.
  72. */
  73. #define EFX_RX_USR_BUF_SIZE (2048 - 256)
  74. /* If possible, we should ensure cache line alignment at start and end
  75. * of every buffer. Otherwise, we just need to ensure 4-byte
  76. * alignment of the network header.
  77. */
  78. #if NET_IP_ALIGN == 0
  79. #define EFX_RX_BUF_ALIGNMENT L1_CACHE_BYTES
  80. #else
  81. #define EFX_RX_BUF_ALIGNMENT 4
  82. #endif
  83. /* Non-standard XDP_PACKET_HEADROOM and tailroom to satisfy XDP_REDIRECT and
  84. * still fit two standard MTU size packets into a single 4K page.
  85. */
  86. #define EFX_XDP_HEADROOM 128
  87. #define EFX_XDP_TAILROOM SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
  88. /* Forward declare Precision Time Protocol (PTP) support structure. */
  89. struct efx_ptp_data;
  90. struct hwtstamp_config;
  91. struct efx_self_tests;
  92. /**
  93. * struct efx_buffer - A general-purpose DMA buffer
  94. * @addr: host base address of the buffer
  95. * @dma_addr: DMA base address of the buffer
  96. * @len: Buffer length, in bytes
  97. *
  98. * The NIC uses these buffers for its interrupt status registers and
  99. * MAC stats dumps.
  100. */
  101. struct efx_buffer {
  102. void *addr;
  103. dma_addr_t dma_addr;
  104. unsigned int len;
  105. };
  106. /**
  107. * struct efx_special_buffer - DMA buffer entered into buffer table
  108. * @buf: Standard &struct efx_buffer
  109. * @index: Buffer index within controller;s buffer table
  110. * @entries: Number of buffer table entries
  111. *
  112. * The NIC has a buffer table that maps buffers of size %EFX_BUF_SIZE.
  113. * Event and descriptor rings are addressed via one or more buffer
  114. * table entries (and so can be physically non-contiguous, although we
  115. * currently do not take advantage of that). On Falcon and Siena we
  116. * have to take care of allocating and initialising the entries
  117. * ourselves. On later hardware this is managed by the firmware and
  118. * @index and @entries are left as 0.
  119. */
  120. struct efx_special_buffer {
  121. struct efx_buffer buf;
  122. unsigned int index;
  123. unsigned int entries;
  124. };
  125. /**
  126. * struct efx_tx_buffer - buffer state for a TX descriptor
  127. * @skb: When @flags & %EFX_TX_BUF_SKB, the associated socket buffer to be
  128. * freed when descriptor completes
  129. * @xdpf: When @flags & %EFX_TX_BUF_XDP, the XDP frame information; its @data
  130. * member is the associated buffer to drop a page reference on.
  131. * @option: When @flags & %EFX_TX_BUF_OPTION, an EF10-specific option
  132. * descriptor.
  133. * @dma_addr: DMA address of the fragment.
  134. * @flags: Flags for allocation and DMA mapping type
  135. * @len: Length of this fragment.
  136. * This field is zero when the queue slot is empty.
  137. * @unmap_len: Length of this fragment to unmap
  138. * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping.
  139. * Only valid if @unmap_len != 0.
  140. */
  141. struct efx_tx_buffer {
  142. union {
  143. const struct sk_buff *skb;
  144. struct xdp_frame *xdpf;
  145. };
  146. union {
  147. efx_qword_t option; /* EF10 */
  148. dma_addr_t dma_addr;
  149. };
  150. unsigned short flags;
  151. unsigned short len;
  152. unsigned short unmap_len;
  153. unsigned short dma_offset;
  154. };
  155. #define EFX_TX_BUF_CONT 1 /* not last descriptor of packet */
  156. #define EFX_TX_BUF_SKB 2 /* buffer is last part of skb */
  157. #define EFX_TX_BUF_MAP_SINGLE 8 /* buffer was mapped with dma_map_single() */
  158. #define EFX_TX_BUF_OPTION 0x10 /* empty buffer for option descriptor */
  159. #define EFX_TX_BUF_XDP 0x20 /* buffer was sent with XDP */
  160. #define EFX_TX_BUF_TSO_V3 0x40 /* empty buffer for a TSO_V3 descriptor */
  161. #define EFX_TX_BUF_EFV 0x100 /* buffer was sent from representor */
  162. /**
  163. * struct efx_tx_queue - An Efx TX queue
  164. *
  165. * This is a ring buffer of TX fragments.
  166. * Since the TX completion path always executes on the same
  167. * CPU and the xmit path can operate on different CPUs,
  168. * performance is increased by ensuring that the completion
  169. * path and the xmit path operate on different cache lines.
  170. * This is particularly important if the xmit path is always
  171. * executing on one CPU which is different from the completion
  172. * path. There is also a cache line for members which are
  173. * read but not written on the fast path.
  174. *
  175. * @efx: The associated Efx NIC
  176. * @queue: DMA queue number
  177. * @label: Label for TX completion events.
  178. * Is our index within @channel->tx_queue array.
  179. * @type: configuration type of this TX queue. A bitmask of %EFX_TXQ_TYPE_* flags.
  180. * @tso_version: Version of TSO in use for this queue.
  181. * @tso_encap: Is encapsulated TSO supported? Supported in TSOv2 on 8000 series.
  182. * @channel: The associated channel
  183. * @core_txq: The networking core TX queue structure
  184. * @buffer: The software buffer ring
  185. * @cb_page: Array of pages of copy buffers. Carved up according to
  186. * %EFX_TX_CB_ORDER into %EFX_TX_CB_SIZE-sized chunks.
  187. * @txd: The hardware descriptor ring
  188. * @ptr_mask: The size of the ring minus 1.
  189. * @piobuf: PIO buffer region for this TX queue (shared with its partner).
  190. * Size of the region is efx_piobuf_size.
  191. * @piobuf_offset: Buffer offset to be specified in PIO descriptors
  192. * @initialised: Has hardware queue been initialised?
  193. * @timestamping: Is timestamping enabled for this channel?
  194. * @xdp_tx: Is this an XDP tx queue?
  195. * @read_count: Current read pointer.
  196. * This is the number of buffers that have been removed from both rings.
  197. * @old_write_count: The value of @write_count when last checked.
  198. * This is here for performance reasons. The xmit path will
  199. * only get the up-to-date value of @write_count if this
  200. * variable indicates that the queue is empty. This is to
  201. * avoid cache-line ping-pong between the xmit path and the
  202. * completion path.
  203. * @merge_events: Number of TX merged completion events
  204. * @completed_timestamp_major: Top part of the most recent tx timestamp.
  205. * @completed_timestamp_minor: Low part of the most recent tx timestamp.
  206. * @insert_count: Current insert pointer
  207. * This is the number of buffers that have been added to the
  208. * software ring.
  209. * @write_count: Current write pointer
  210. * This is the number of buffers that have been added to the
  211. * hardware ring.
  212. * @packet_write_count: Completable write pointer
  213. * This is the write pointer of the last packet written.
  214. * Normally this will equal @write_count, but as option descriptors
  215. * don't produce completion events, they won't update this.
  216. * Filled in iff @efx->type->option_descriptors; only used for PIO.
  217. * Thus, this is written and used on EF10, and neither on farch.
  218. * @old_read_count: The value of read_count when last checked.
  219. * This is here for performance reasons. The xmit path will
  220. * only get the up-to-date value of read_count if this
  221. * variable indicates that the queue is full. This is to
  222. * avoid cache-line ping-pong between the xmit path and the
  223. * completion path.
  224. * @tso_bursts: Number of times TSO xmit invoked by kernel
  225. * @tso_long_headers: Number of packets with headers too long for standard
  226. * blocks
  227. * @tso_packets: Number of packets via the TSO xmit path
  228. * @tso_fallbacks: Number of times TSO fallback used
  229. * @pushes: Number of times the TX push feature has been used
  230. * @pio_packets: Number of times the TX PIO feature has been used
  231. * @xmit_pending: Are any packets waiting to be pushed to the NIC
  232. * @cb_packets: Number of times the TX copybreak feature has been used
  233. * @notify_count: Count of notified descriptors to the NIC
  234. * @empty_read_count: If the completion path has seen the queue as empty
  235. * and the transmission path has not yet checked this, the value of
  236. * @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
  237. */
  238. struct efx_tx_queue {
  239. /* Members which don't change on the fast path */
  240. struct efx_nic *efx ____cacheline_aligned_in_smp;
  241. unsigned int queue;
  242. unsigned int label;
  243. unsigned int type;
  244. unsigned int tso_version;
  245. bool tso_encap;
  246. struct efx_channel *channel;
  247. struct netdev_queue *core_txq;
  248. struct efx_tx_buffer *buffer;
  249. struct efx_buffer *cb_page;
  250. struct efx_special_buffer txd;
  251. unsigned int ptr_mask;
  252. void __iomem *piobuf;
  253. unsigned int piobuf_offset;
  254. bool initialised;
  255. bool timestamping;
  256. bool xdp_tx;
  257. /* Members used mainly on the completion path */
  258. unsigned int read_count ____cacheline_aligned_in_smp;
  259. unsigned int old_write_count;
  260. unsigned int merge_events;
  261. unsigned int bytes_compl;
  262. unsigned int pkts_compl;
  263. u32 completed_timestamp_major;
  264. u32 completed_timestamp_minor;
  265. /* Members used only on the xmit path */
  266. unsigned int insert_count ____cacheline_aligned_in_smp;
  267. unsigned int write_count;
  268. unsigned int packet_write_count;
  269. unsigned int old_read_count;
  270. unsigned int tso_bursts;
  271. unsigned int tso_long_headers;
  272. unsigned int tso_packets;
  273. unsigned int tso_fallbacks;
  274. unsigned int pushes;
  275. unsigned int pio_packets;
  276. bool xmit_pending;
  277. unsigned int cb_packets;
  278. unsigned int notify_count;
  279. /* Statistics to supplement MAC stats */
  280. unsigned long tx_packets;
  281. /* Members shared between paths and sometimes updated */
  282. unsigned int empty_read_count ____cacheline_aligned_in_smp;
  283. #define EFX_EMPTY_COUNT_VALID 0x80000000
  284. atomic_t flush_outstanding;
  285. };
  286. #define EFX_TX_CB_ORDER 7
  287. #define EFX_TX_CB_SIZE (1 << EFX_TX_CB_ORDER) - NET_IP_ALIGN
  288. /**
  289. * struct efx_rx_buffer - An Efx RX data buffer
  290. * @dma_addr: DMA base address of the buffer
  291. * @page: The associated page buffer.
  292. * Will be %NULL if the buffer slot is currently free.
  293. * @page_offset: If pending: offset in @page of DMA base address.
  294. * If completed: offset in @page of Ethernet header.
  295. * @len: If pending: length for DMA descriptor.
  296. * If completed: received length, excluding hash prefix.
  297. * @flags: Flags for buffer and packet state. These are only set on the
  298. * first buffer of a scattered packet.
  299. */
  300. struct efx_rx_buffer {
  301. dma_addr_t dma_addr;
  302. struct page *page;
  303. u16 page_offset;
  304. u16 len;
  305. u16 flags;
  306. };
  307. #define EFX_RX_BUF_LAST_IN_PAGE 0x0001
  308. #define EFX_RX_PKT_CSUMMED 0x0002
  309. #define EFX_RX_PKT_DISCARD 0x0004
  310. #define EFX_RX_PKT_TCP 0x0040
  311. #define EFX_RX_PKT_PREFIX_LEN 0x0080 /* length is in prefix only */
  312. #define EFX_RX_PKT_CSUM_LEVEL 0x0200
  313. /**
  314. * struct efx_rx_page_state - Page-based rx buffer state
  315. *
  316. * Inserted at the start of every page allocated for receive buffers.
  317. * Used to facilitate sharing dma mappings between recycled rx buffers
  318. * and those passed up to the kernel.
  319. *
  320. * @dma_addr: The dma address of this page.
  321. */
  322. struct efx_rx_page_state {
  323. dma_addr_t dma_addr;
  324. unsigned int __pad[] ____cacheline_aligned;
  325. };
  326. /**
  327. * struct efx_rx_queue - An Efx RX queue
  328. * @efx: The associated Efx NIC
  329. * @core_index: Index of network core RX queue. Will be >= 0 iff this
  330. * is associated with a real RX queue.
  331. * @buffer: The software buffer ring
  332. * @rxd: The hardware descriptor ring
  333. * @ptr_mask: The size of the ring minus 1.
  334. * @refill_enabled: Enable refill whenever fill level is low
  335. * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
  336. * @rxq_flush_pending.
  337. * @added_count: Number of buffers added to the receive queue.
  338. * @notified_count: Number of buffers given to NIC (<= @added_count).
  339. * @removed_count: Number of buffers removed from the receive queue.
  340. * @scatter_n: Used by NIC specific receive code.
  341. * @scatter_len: Used by NIC specific receive code.
  342. * @page_ring: The ring to store DMA mapped pages for reuse.
  343. * @page_add: Counter to calculate the write pointer for the recycle ring.
  344. * @page_remove: Counter to calculate the read pointer for the recycle ring.
  345. * @page_recycle_count: The number of pages that have been recycled.
  346. * @page_recycle_failed: The number of pages that couldn't be recycled because
  347. * the kernel still held a reference to them.
  348. * @page_recycle_full: The number of pages that were released because the
  349. * recycle ring was full.
  350. * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
  351. * @max_fill: RX descriptor maximum fill level (<= ring size)
  352. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  353. * (<= @max_fill)
  354. * @min_fill: RX descriptor minimum non-zero fill level.
  355. * This records the minimum fill level observed when a ring
  356. * refill was triggered.
  357. * @recycle_count: RX buffer recycle counter.
  358. * @slow_fill: Timer used to defer efx_nic_generate_fill_event().
  359. * @xdp_rxq_info: XDP specific RX queue information.
  360. * @xdp_rxq_info_valid: Is xdp_rxq_info valid data?.
  361. */
  362. struct efx_rx_queue {
  363. struct efx_nic *efx;
  364. int core_index;
  365. struct efx_rx_buffer *buffer;
  366. struct efx_special_buffer rxd;
  367. unsigned int ptr_mask;
  368. bool refill_enabled;
  369. bool flush_pending;
  370. unsigned int added_count;
  371. unsigned int notified_count;
  372. unsigned int removed_count;
  373. unsigned int scatter_n;
  374. unsigned int scatter_len;
  375. struct page **page_ring;
  376. unsigned int page_add;
  377. unsigned int page_remove;
  378. unsigned int page_recycle_count;
  379. unsigned int page_recycle_failed;
  380. unsigned int page_recycle_full;
  381. unsigned int page_ptr_mask;
  382. unsigned int max_fill;
  383. unsigned int fast_fill_trigger;
  384. unsigned int min_fill;
  385. unsigned int min_overfill;
  386. unsigned int recycle_count;
  387. struct timer_list slow_fill;
  388. unsigned int slow_fill_count;
  389. /* Statistics to supplement MAC stats */
  390. unsigned long rx_packets;
  391. struct xdp_rxq_info xdp_rxq_info;
  392. bool xdp_rxq_info_valid;
  393. };
  394. enum efx_sync_events_state {
  395. SYNC_EVENTS_DISABLED = 0,
  396. SYNC_EVENTS_QUIESCENT,
  397. SYNC_EVENTS_REQUESTED,
  398. SYNC_EVENTS_VALID,
  399. };
  400. /**
  401. * struct efx_channel - An Efx channel
  402. *
  403. * A channel comprises an event queue, at least one TX queue, at least
  404. * one RX queue, and an associated tasklet for processing the event
  405. * queue.
  406. *
  407. * @efx: Associated Efx NIC
  408. * @channel: Channel instance number
  409. * @type: Channel type definition
  410. * @eventq_init: Event queue initialised flag
  411. * @enabled: Channel enabled indicator
  412. * @irq: IRQ number (MSI and MSI-X only)
  413. * @irq_moderation_us: IRQ moderation value (in microseconds)
  414. * @napi_dev: Net device used with NAPI
  415. * @napi_str: NAPI control structure
  416. * @state: state for NAPI vs busy polling
  417. * @state_lock: lock protecting @state
  418. * @eventq: Event queue buffer
  419. * @eventq_mask: Event queue pointer mask
  420. * @eventq_read_ptr: Event queue read pointer
  421. * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
  422. * @irq_count: Number of IRQs since last adaptive moderation decision
  423. * @irq_mod_score: IRQ moderation score
  424. * @rfs_filter_count: number of accelerated RFS filters currently in place;
  425. * equals the count of @rps_flow_id slots filled
  426. * @rfs_last_expiry: value of jiffies last time some accelerated RFS filters
  427. * were checked for expiry
  428. * @rfs_expire_index: next accelerated RFS filter ID to check for expiry
  429. * @n_rfs_succeeded: number of successful accelerated RFS filter insertions
  430. * @n_rfs_failed: number of failed accelerated RFS filter insertions
  431. * @filter_work: Work item for efx_filter_rfs_expire()
  432. * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
  433. * indexed by filter ID
  434. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  435. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  436. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  437. * @n_rx_mcast_mismatch: Count of unmatched multicast frames
  438. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  439. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  440. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  441. * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
  442. * lack of descriptors
  443. * @n_rx_merge_events: Number of RX merged completion events
  444. * @n_rx_merge_packets: Number of RX packets completed by merged events
  445. * @n_rx_xdp_drops: Count of RX packets intentionally dropped due to XDP
  446. * @n_rx_xdp_bad_drops: Count of RX packets dropped due to XDP errors
  447. * @n_rx_xdp_tx: Count of RX packets retransmitted due to XDP
  448. * @n_rx_xdp_redirect: Count of RX packets redirected to a different NIC by XDP
  449. * @n_rx_mport_bad: Count of RX packets dropped because their ingress mport was
  450. * not recognised
  451. * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
  452. * __efx_rx_packet(), or zero if there is none
  453. * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
  454. * by __efx_rx_packet(), if @rx_pkt_n_frags != 0
  455. * @rx_list: list of SKBs from current RX, awaiting processing
  456. * @rx_queue: RX queue for this channel
  457. * @tx_queue: TX queues for this channel
  458. * @tx_queue_by_type: pointers into @tx_queue, or %NULL, indexed by txq type
  459. * @sync_events_state: Current state of sync events on this channel
  460. * @sync_timestamp_major: Major part of the last ptp sync event
  461. * @sync_timestamp_minor: Minor part of the last ptp sync event
  462. */
  463. struct efx_channel {
  464. struct efx_nic *efx;
  465. int channel;
  466. const struct efx_channel_type *type;
  467. bool eventq_init;
  468. bool enabled;
  469. int irq;
  470. unsigned int irq_moderation_us;
  471. struct net_device *napi_dev;
  472. struct napi_struct napi_str;
  473. #ifdef CONFIG_NET_RX_BUSY_POLL
  474. unsigned long busy_poll_state;
  475. #endif
  476. struct efx_special_buffer eventq;
  477. unsigned int eventq_mask;
  478. unsigned int eventq_read_ptr;
  479. int event_test_cpu;
  480. unsigned int irq_count;
  481. unsigned int irq_mod_score;
  482. #ifdef CONFIG_RFS_ACCEL
  483. unsigned int rfs_filter_count;
  484. unsigned int rfs_last_expiry;
  485. unsigned int rfs_expire_index;
  486. unsigned int n_rfs_succeeded;
  487. unsigned int n_rfs_failed;
  488. struct delayed_work filter_work;
  489. #define RPS_FLOW_ID_INVALID 0xFFFFFFFF
  490. u32 *rps_flow_id;
  491. #endif
  492. unsigned int n_rx_tobe_disc;
  493. unsigned int n_rx_ip_hdr_chksum_err;
  494. unsigned int n_rx_tcp_udp_chksum_err;
  495. unsigned int n_rx_outer_ip_hdr_chksum_err;
  496. unsigned int n_rx_outer_tcp_udp_chksum_err;
  497. unsigned int n_rx_inner_ip_hdr_chksum_err;
  498. unsigned int n_rx_inner_tcp_udp_chksum_err;
  499. unsigned int n_rx_eth_crc_err;
  500. unsigned int n_rx_mcast_mismatch;
  501. unsigned int n_rx_frm_trunc;
  502. unsigned int n_rx_overlength;
  503. unsigned int n_skbuff_leaks;
  504. unsigned int n_rx_nodesc_trunc;
  505. unsigned int n_rx_merge_events;
  506. unsigned int n_rx_merge_packets;
  507. unsigned int n_rx_xdp_drops;
  508. unsigned int n_rx_xdp_bad_drops;
  509. unsigned int n_rx_xdp_tx;
  510. unsigned int n_rx_xdp_redirect;
  511. unsigned int n_rx_mport_bad;
  512. unsigned int rx_pkt_n_frags;
  513. unsigned int rx_pkt_index;
  514. struct list_head *rx_list;
  515. struct efx_rx_queue rx_queue;
  516. struct efx_tx_queue tx_queue[EFX_MAX_TXQ_PER_CHANNEL];
  517. struct efx_tx_queue *tx_queue_by_type[EFX_TXQ_TYPES];
  518. enum efx_sync_events_state sync_events_state;
  519. u32 sync_timestamp_major;
  520. u32 sync_timestamp_minor;
  521. };
  522. /**
  523. * struct efx_msi_context - Context for each MSI
  524. * @efx: The associated NIC
  525. * @index: Index of the channel/IRQ
  526. * @name: Name of the channel/IRQ
  527. *
  528. * Unlike &struct efx_channel, this is never reallocated and is always
  529. * safe for the IRQ handler to access.
  530. */
  531. struct efx_msi_context {
  532. struct efx_nic *efx;
  533. unsigned int index;
  534. char name[IFNAMSIZ + 6];
  535. };
  536. /**
  537. * struct efx_channel_type - distinguishes traffic and extra channels
  538. * @handle_no_channel: Handle failure to allocate an extra channel
  539. * @pre_probe: Set up extra state prior to initialisation
  540. * @post_remove: Tear down extra state after finalisation, if allocated.
  541. * May be called on channels that have not been probed.
  542. * @get_name: Generate the channel's name (used for its IRQ handler)
  543. * @copy: Copy the channel state prior to reallocation. May be %NULL if
  544. * reallocation is not supported.
  545. * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
  546. * @want_txqs: Determine whether this channel should have TX queues
  547. * created. If %NULL, TX queues are not created.
  548. * @keep_eventq: Flag for whether event queue should be kept initialised
  549. * while the device is stopped
  550. * @want_pio: Flag for whether PIO buffers should be linked to this
  551. * channel's TX queues.
  552. */
  553. struct efx_channel_type {
  554. void (*handle_no_channel)(struct efx_nic *);
  555. int (*pre_probe)(struct efx_channel *);
  556. void (*post_remove)(struct efx_channel *);
  557. void (*get_name)(struct efx_channel *, char *buf, size_t len);
  558. struct efx_channel *(*copy)(const struct efx_channel *);
  559. bool (*receive_skb)(struct efx_channel *, struct sk_buff *);
  560. bool (*want_txqs)(struct efx_channel *);
  561. bool keep_eventq;
  562. bool want_pio;
  563. };
  564. enum efx_led_mode {
  565. EFX_LED_OFF = 0,
  566. EFX_LED_ON = 1,
  567. EFX_LED_DEFAULT = 2
  568. };
  569. #define STRING_TABLE_LOOKUP(val, member) \
  570. ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
  571. extern const char *const efx_loopback_mode_names[];
  572. extern const unsigned int efx_loopback_mode_max;
  573. #define LOOPBACK_MODE(efx) \
  574. STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_loopback_mode)
  575. enum efx_int_mode {
  576. /* Be careful if altering to correct macro below */
  577. EFX_INT_MODE_MSIX = 0,
  578. EFX_INT_MODE_MSI = 1,
  579. EFX_INT_MODE_LEGACY = 2,
  580. EFX_INT_MODE_MAX /* Insert any new items before this */
  581. };
  582. #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
  583. enum nic_state {
  584. STATE_UNINIT = 0, /* device being probed/removed */
  585. STATE_PROBED, /* hardware probed */
  586. STATE_NET_DOWN, /* netdev registered */
  587. STATE_NET_UP, /* ready for traffic */
  588. STATE_DISABLED, /* device disabled due to hardware errors */
  589. STATE_RECOVERY = 0x100,/* recovering from PCI error */
  590. STATE_FROZEN = 0x200, /* frozen by power management */
  591. };
  592. static inline bool efx_net_active(enum nic_state state)
  593. {
  594. return state == STATE_NET_DOWN || state == STATE_NET_UP;
  595. }
  596. static inline bool efx_frozen(enum nic_state state)
  597. {
  598. return state & STATE_FROZEN;
  599. }
  600. static inline bool efx_recovering(enum nic_state state)
  601. {
  602. return state & STATE_RECOVERY;
  603. }
  604. static inline enum nic_state efx_freeze(enum nic_state state)
  605. {
  606. WARN_ON(!efx_net_active(state));
  607. return state | STATE_FROZEN;
  608. }
  609. static inline enum nic_state efx_thaw(enum nic_state state)
  610. {
  611. WARN_ON(!efx_frozen(state));
  612. return state & ~STATE_FROZEN;
  613. }
  614. static inline enum nic_state efx_recover(enum nic_state state)
  615. {
  616. WARN_ON(!efx_net_active(state));
  617. return state | STATE_RECOVERY;
  618. }
  619. static inline enum nic_state efx_recovered(enum nic_state state)
  620. {
  621. WARN_ON(!efx_recovering(state));
  622. return state & ~STATE_RECOVERY;
  623. }
  624. /* Forward declaration */
  625. struct efx_nic;
  626. /* Pseudo bit-mask flow control field */
  627. #define EFX_FC_RX FLOW_CTRL_RX
  628. #define EFX_FC_TX FLOW_CTRL_TX
  629. #define EFX_FC_AUTO 4
  630. /**
  631. * struct efx_link_state - Current state of the link
  632. * @up: Link is up
  633. * @fd: Link is full-duplex
  634. * @fc: Actual flow control flags
  635. * @speed: Link speed (Mbps)
  636. */
  637. struct efx_link_state {
  638. bool up;
  639. bool fd;
  640. u8 fc;
  641. unsigned int speed;
  642. };
  643. static inline bool efx_link_state_equal(const struct efx_link_state *left,
  644. const struct efx_link_state *right)
  645. {
  646. return left->up == right->up && left->fd == right->fd &&
  647. left->fc == right->fc && left->speed == right->speed;
  648. }
  649. /**
  650. * enum efx_phy_mode - PHY operating mode flags
  651. * @PHY_MODE_NORMAL: on and should pass traffic
  652. * @PHY_MODE_TX_DISABLED: on with TX disabled
  653. * @PHY_MODE_LOW_POWER: set to low power through MDIO
  654. * @PHY_MODE_OFF: switched off through external control
  655. * @PHY_MODE_SPECIAL: on but will not pass traffic
  656. */
  657. enum efx_phy_mode {
  658. PHY_MODE_NORMAL = 0,
  659. PHY_MODE_TX_DISABLED = 1,
  660. PHY_MODE_LOW_POWER = 2,
  661. PHY_MODE_OFF = 4,
  662. PHY_MODE_SPECIAL = 8,
  663. };
  664. static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
  665. {
  666. return !!(mode & ~PHY_MODE_TX_DISABLED);
  667. }
  668. /**
  669. * struct efx_hw_stat_desc - Description of a hardware statistic
  670. * @name: Name of the statistic as visible through ethtool, or %NULL if
  671. * it should not be exposed
  672. * @dma_width: Width in bits (0 for non-DMA statistics)
  673. * @offset: Offset within stats (ignored for non-DMA statistics)
  674. */
  675. struct efx_hw_stat_desc {
  676. const char *name;
  677. u16 dma_width;
  678. u16 offset;
  679. };
  680. /* Number of bits used in a multicast filter hash address */
  681. #define EFX_MCAST_HASH_BITS 8
  682. /* Number of (single-bit) entries in a multicast filter hash */
  683. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  684. /* An Efx multicast filter hash */
  685. union efx_multicast_hash {
  686. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  687. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  688. };
  689. struct vfdi_status;
  690. /* The reserved RSS context value */
  691. #define EFX_MCDI_RSS_CONTEXT_INVALID 0xffffffff
  692. /**
  693. * struct efx_rss_context - A user-defined RSS context for filtering
  694. * @list: node of linked list on which this struct is stored
  695. * @context_id: the RSS_CONTEXT_ID returned by MC firmware, or
  696. * %EFX_MCDI_RSS_CONTEXT_INVALID if this context is not present on the NIC.
  697. * For Siena, 0 if RSS is active, else %EFX_MCDI_RSS_CONTEXT_INVALID.
  698. * @user_id: the rss_context ID exposed to userspace over ethtool.
  699. * @rx_hash_udp_4tuple: UDP 4-tuple hashing enabled
  700. * @rx_hash_key: Toeplitz hash key for this RSS context
  701. * @indir_table: Indirection table for this RSS context
  702. */
  703. struct efx_rss_context {
  704. struct list_head list;
  705. u32 context_id;
  706. u32 user_id;
  707. bool rx_hash_udp_4tuple;
  708. u8 rx_hash_key[40];
  709. u32 rx_indir_table[128];
  710. };
  711. #ifdef CONFIG_RFS_ACCEL
  712. /* Order of these is important, since filter_id >= %EFX_ARFS_FILTER_ID_PENDING
  713. * is used to test if filter does or will exist.
  714. */
  715. #define EFX_ARFS_FILTER_ID_PENDING -1
  716. #define EFX_ARFS_FILTER_ID_ERROR -2
  717. #define EFX_ARFS_FILTER_ID_REMOVING -3
  718. /**
  719. * struct efx_arfs_rule - record of an ARFS filter and its IDs
  720. * @node: linkage into hash table
  721. * @spec: details of the filter (used as key for hash table). Use efx->type to
  722. * determine which member to use.
  723. * @rxq_index: channel to which the filter will steer traffic.
  724. * @arfs_id: filter ID which was returned to ARFS
  725. * @filter_id: index in software filter table. May be
  726. * %EFX_ARFS_FILTER_ID_PENDING if filter was not inserted yet,
  727. * %EFX_ARFS_FILTER_ID_ERROR if filter insertion failed, or
  728. * %EFX_ARFS_FILTER_ID_REMOVING if expiry is currently removing the filter.
  729. */
  730. struct efx_arfs_rule {
  731. struct hlist_node node;
  732. struct efx_filter_spec spec;
  733. u16 rxq_index;
  734. u16 arfs_id;
  735. s32 filter_id;
  736. };
  737. /* Size chosen so that the table is one page (4kB) */
  738. #define EFX_ARFS_HASH_TABLE_SIZE 512
  739. /**
  740. * struct efx_async_filter_insertion - Request to asynchronously insert a filter
  741. * @net_dev: Reference to the netdevice
  742. * @spec: The filter to insert
  743. * @work: Workitem for this request
  744. * @rxq_index: Identifies the channel for which this request was made
  745. * @flow_id: Identifies the kernel-side flow for which this request was made
  746. */
  747. struct efx_async_filter_insertion {
  748. struct net_device *net_dev;
  749. struct efx_filter_spec spec;
  750. struct work_struct work;
  751. u16 rxq_index;
  752. u32 flow_id;
  753. };
  754. /* Maximum number of ARFS workitems that may be in flight on an efx_nic */
  755. #define EFX_RPS_MAX_IN_FLIGHT 8
  756. #endif /* CONFIG_RFS_ACCEL */
  757. enum efx_xdp_tx_queues_mode {
  758. EFX_XDP_TX_QUEUES_DEDICATED, /* one queue per core, locking not needed */
  759. EFX_XDP_TX_QUEUES_SHARED, /* each queue used by more than 1 core */
  760. EFX_XDP_TX_QUEUES_BORROWED /* queues borrowed from net stack */
  761. };
  762. /**
  763. * struct efx_nic - an Efx NIC
  764. * @name: Device name (net device name or bus id before net device registered)
  765. * @pci_dev: The PCI device
  766. * @node: List node for maintaning primary/secondary function lists
  767. * @primary: &struct efx_nic instance for the primary function of this
  768. * controller. May be the same structure, and may be %NULL if no
  769. * primary function is bound. Serialised by rtnl_lock.
  770. * @secondary_list: List of &struct efx_nic instances for the secondary PCI
  771. * functions of the controller, if this is for the primary function.
  772. * Serialised by rtnl_lock.
  773. * @type: Controller type attributes
  774. * @legacy_irq: IRQ number
  775. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  776. * Work items do not hold and must not acquire RTNL.
  777. * @workqueue_name: Name of workqueue
  778. * @reset_work: Scheduled reset workitem
  779. * @membase_phys: Memory BAR value as physical address
  780. * @membase: Memory BAR value
  781. * @vi_stride: step between per-VI registers / memory regions
  782. * @interrupt_mode: Interrupt mode
  783. * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
  784. * @timer_max_ns: Interrupt timer maximum value, in nanoseconds
  785. * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  786. * @irqs_hooked: Channel interrupts are hooked
  787. * @log_tc_errs: Error logging for TC filter insertion is enabled
  788. * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues
  789. * @irq_rx_moderation_us: IRQ moderation time for RX event queues
  790. * @msg_enable: Log message enable flags
  791. * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
  792. * @reset_pending: Bitmask for pending resets
  793. * @tx_queue: TX DMA queues
  794. * @rx_queue: RX DMA queues
  795. * @channel: Channels
  796. * @msi_context: Context for each MSI
  797. * @extra_channel_types: Types of extra (non-traffic) channels that
  798. * should be allocated for this NIC
  799. * @xdp_tx_queue_count: Number of entries in %xdp_tx_queues.
  800. * @xdp_tx_queues: Array of pointers to tx queues used for XDP transmit.
  801. * @xdp_txq_queues_mode: XDP TX queues sharing strategy.
  802. * @rxq_entries: Size of receive queues requested by user.
  803. * @txq_entries: Size of transmit queues requested by user.
  804. * @txq_stop_thresh: TX queue fill level at or above which we stop it.
  805. * @txq_wake_thresh: TX queue fill level at or below which we wake it.
  806. * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
  807. * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
  808. * @sram_lim_qw: Qword address limit of SRAM
  809. * @next_buffer_table: First available buffer table id
  810. * @n_channels: Number of channels in use
  811. * @n_rx_channels: Number of channels used for RX (= number of RX queues)
  812. * @n_tx_channels: Number of channels used for TX
  813. * @n_extra_tx_channels: Number of extra channels with TX queues
  814. * @tx_queues_per_channel: number of TX queues probed on each channel
  815. * @n_xdp_channels: Number of channels used for XDP TX
  816. * @xdp_channel_offset: Offset of zeroth channel used for XPD TX.
  817. * @xdp_tx_per_channel: Max number of TX queues on an XDP TX channel.
  818. * @rx_ip_align: RX DMA address offset to have IP header aligned in
  819. * in accordance with NET_IP_ALIGN
  820. * @rx_dma_len: Current maximum RX DMA length
  821. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  822. * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
  823. * for use in sk_buff::truesize
  824. * @rx_prefix_size: Size of RX prefix before packet data
  825. * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data
  826. * (valid only if @rx_prefix_size != 0; always negative)
  827. * @rx_packet_len_offset: Offset of RX packet length from start of packet data
  828. * (valid only for NICs that set %EFX_RX_PKT_PREFIX_LEN; always negative)
  829. * @rx_packet_ts_offset: Offset of timestamp from start of packet data
  830. * (valid only if channel->sync_timestamps_enabled; always negative)
  831. * @rx_scatter: Scatter mode enabled for receives
  832. * @rss_context: Main RSS context. Its @list member is the head of the list of
  833. * RSS contexts created by user requests
  834. * @rss_lock: Protects custom RSS context software state in @rss_context.list
  835. * @vport_id: The function's vport ID, only relevant for PFs
  836. * @int_error_count: Number of internal errors seen recently
  837. * @int_error_expire: Time at which error count will be expired
  838. * @must_realloc_vis: Flag: VIs have yet to be reallocated after MC reboot
  839. * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
  840. * acknowledge but do nothing else.
  841. * @irq_status: Interrupt status buffer
  842. * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
  843. * @irq_level: IRQ level/index for IRQs not triggered by an event queue
  844. * @selftest_work: Work item for asynchronous self-test
  845. * @mtd_list: List of MTDs attached to the NIC
  846. * @nic_data: Hardware dependent state
  847. * @mcdi: Management-Controller-to-Driver Interface state
  848. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  849. * efx_monitor() and efx_reconfigure_port()
  850. * @port_enabled: Port enabled indicator.
  851. * Serialises efx_stop_all(), efx_start_all(), efx_monitor() and
  852. * efx_mac_work() with kernel interfaces. Safe to read under any
  853. * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
  854. * be held to modify it.
  855. * @port_initialized: Port initialized?
  856. * @net_dev: Operating system network device. Consider holding the rtnl lock
  857. * @fixed_features: Features which cannot be turned off
  858. * @num_mac_stats: Number of MAC stats reported by firmware (MAC_STATS_NUM_STATS
  859. * field of %MC_CMD_GET_CAPABILITIES_V4 response, or %MC_CMD_MAC_NSTATS)
  860. * @stats_buffer: DMA buffer for statistics
  861. * @phy_type: PHY type
  862. * @phy_data: PHY private data (including PHY-specific stats)
  863. * @mdio: PHY MDIO interface
  864. * @mdio_bus: PHY MDIO bus ID (only used by Siena)
  865. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  866. * @link_advertising: Autonegotiation advertising flags
  867. * @fec_config: Forward Error Correction configuration flags. For bit positions
  868. * see &enum ethtool_fec_config_bits.
  869. * @link_state: Current state of the link
  870. * @n_link_state_changes: Number of times the link has changed state
  871. * @unicast_filter: Flag for Falcon-arch simple unicast filter.
  872. * Protected by @mac_lock.
  873. * @multicast_hash: Multicast hash table for Falcon-arch.
  874. * Protected by @mac_lock.
  875. * @wanted_fc: Wanted flow control flags
  876. * @fc_disable: When non-zero flow control is disabled. Typically used to
  877. * ensure that network back pressure doesn't delay dma queue flushes.
  878. * Serialised by the rtnl lock.
  879. * @mac_work: Work item for changing MAC promiscuity and multicast hash
  880. * @loopback_mode: Loopback status
  881. * @loopback_modes: Supported loopback mode bitmask
  882. * @loopback_selftest: Offline self-test private state
  883. * @xdp_prog: Current XDP programme for this interface
  884. * @filter_sem: Filter table rw_semaphore, protects existence of @filter_state
  885. * @filter_state: Architecture-dependent filter table state
  886. * @rps_mutex: Protects RPS state of all channels
  887. * @rps_slot_map: bitmap of in-flight entries in @rps_slot
  888. * @rps_slot: array of ARFS insertion requests for efx_filter_rfs_work()
  889. * @rps_hash_lock: Protects ARFS filter mapping state (@rps_hash_table and
  890. * @rps_next_id).
  891. * @rps_hash_table: Mapping between ARFS filters and their various IDs
  892. * @rps_next_id: next arfs_id for an ARFS filter
  893. * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
  894. * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
  895. * Decremented when the efx_flush_rx_queue() is called.
  896. * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
  897. * completed (either success or failure). Not used when MCDI is used to
  898. * flush receive queues.
  899. * @flush_wq: wait queue used by efx_nic_flush_queues() to wait for flush completions.
  900. * @vf_count: Number of VFs intended to be enabled.
  901. * @vf_init_count: Number of VFs that have been fully initialised.
  902. * @vi_scale: log2 number of vnics per VF.
  903. * @vf_reps_lock: Protects vf_reps list
  904. * @vf_reps: local VF reps
  905. * @ptp_data: PTP state data
  906. * @ptp_warned: has this NIC seen and warned about unexpected PTP events?
  907. * @vpd_sn: Serial number read from VPD
  908. * @xdp_rxq_info_failed: Have any of the rx queues failed to initialise their
  909. * xdp_rxq_info structures?
  910. * @netdev_notifier: Netdevice notifier.
  911. * @tc: state for TC offload (EF100).
  912. * @mem_bar: The BAR that is mapped into membase.
  913. * @reg_base: Offset from the start of the bar to the function control window.
  914. * @monitor_work: Hardware monitor workitem
  915. * @biu_lock: BIU (bus interface unit) lock
  916. * @last_irq_cpu: Last CPU to handle a possible test interrupt. This
  917. * field is used by efx_test_interrupts() to verify that an
  918. * interrupt has occurred.
  919. * @stats_lock: Statistics update lock. Must be held when calling
  920. * efx_nic_type::{update,start,stop}_stats.
  921. * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb
  922. *
  923. * This is stored in the private area of the &struct net_device.
  924. */
  925. struct efx_nic {
  926. /* The following fields should be written very rarely */
  927. char name[IFNAMSIZ];
  928. struct list_head node;
  929. struct efx_nic *primary;
  930. struct list_head secondary_list;
  931. struct pci_dev *pci_dev;
  932. unsigned int port_num;
  933. const struct efx_nic_type *type;
  934. int legacy_irq;
  935. bool eeh_disabled_legacy_irq;
  936. struct workqueue_struct *workqueue;
  937. char workqueue_name[16];
  938. struct work_struct reset_work;
  939. resource_size_t membase_phys;
  940. void __iomem *membase;
  941. unsigned int vi_stride;
  942. enum efx_int_mode interrupt_mode;
  943. unsigned int timer_quantum_ns;
  944. unsigned int timer_max_ns;
  945. bool irq_rx_adaptive;
  946. bool irqs_hooked;
  947. bool log_tc_errs;
  948. unsigned int irq_mod_step_us;
  949. unsigned int irq_rx_moderation_us;
  950. u32 msg_enable;
  951. enum nic_state state;
  952. unsigned long reset_pending;
  953. struct efx_channel *channel[EFX_MAX_CHANNELS];
  954. struct efx_msi_context msi_context[EFX_MAX_CHANNELS];
  955. const struct efx_channel_type *
  956. extra_channel_type[EFX_MAX_EXTRA_CHANNELS];
  957. unsigned int xdp_tx_queue_count;
  958. struct efx_tx_queue **xdp_tx_queues;
  959. enum efx_xdp_tx_queues_mode xdp_txq_queues_mode;
  960. unsigned rxq_entries;
  961. unsigned txq_entries;
  962. unsigned int txq_stop_thresh;
  963. unsigned int txq_wake_thresh;
  964. unsigned tx_dc_base;
  965. unsigned rx_dc_base;
  966. unsigned sram_lim_qw;
  967. unsigned next_buffer_table;
  968. unsigned int max_channels;
  969. unsigned int max_vis;
  970. unsigned int max_tx_channels;
  971. unsigned n_channels;
  972. unsigned n_rx_channels;
  973. unsigned rss_spread;
  974. unsigned tx_channel_offset;
  975. unsigned n_tx_channels;
  976. unsigned n_extra_tx_channels;
  977. unsigned int tx_queues_per_channel;
  978. unsigned int n_xdp_channels;
  979. unsigned int xdp_channel_offset;
  980. unsigned int xdp_tx_per_channel;
  981. unsigned int rx_ip_align;
  982. unsigned int rx_dma_len;
  983. unsigned int rx_buffer_order;
  984. unsigned int rx_buffer_truesize;
  985. unsigned int rx_page_buf_step;
  986. unsigned int rx_bufs_per_page;
  987. unsigned int rx_pages_per_batch;
  988. unsigned int rx_prefix_size;
  989. int rx_packet_hash_offset;
  990. int rx_packet_len_offset;
  991. int rx_packet_ts_offset;
  992. bool rx_scatter;
  993. struct efx_rss_context rss_context;
  994. struct mutex rss_lock;
  995. u32 vport_id;
  996. unsigned int_error_count;
  997. unsigned long int_error_expire;
  998. bool must_realloc_vis;
  999. bool irq_soft_enabled;
  1000. struct efx_buffer irq_status;
  1001. unsigned irq_zero_count;
  1002. unsigned irq_level;
  1003. struct delayed_work selftest_work;
  1004. #ifdef CONFIG_SFC_MTD
  1005. struct list_head mtd_list;
  1006. #endif
  1007. void *nic_data;
  1008. struct efx_mcdi_data *mcdi;
  1009. struct mutex mac_lock;
  1010. struct work_struct mac_work;
  1011. bool port_enabled;
  1012. bool mc_bist_for_other_fn;
  1013. bool port_initialized;
  1014. struct net_device *net_dev;
  1015. netdev_features_t fixed_features;
  1016. u16 num_mac_stats;
  1017. struct efx_buffer stats_buffer;
  1018. u64 rx_nodesc_drops_total;
  1019. u64 rx_nodesc_drops_while_down;
  1020. bool rx_nodesc_drops_prev_state;
  1021. unsigned int phy_type;
  1022. void *phy_data;
  1023. struct mdio_if_info mdio;
  1024. unsigned int mdio_bus;
  1025. enum efx_phy_mode phy_mode;
  1026. __ETHTOOL_DECLARE_LINK_MODE_MASK(link_advertising);
  1027. u32 fec_config;
  1028. struct efx_link_state link_state;
  1029. unsigned int n_link_state_changes;
  1030. bool unicast_filter;
  1031. union efx_multicast_hash multicast_hash;
  1032. u8 wanted_fc;
  1033. unsigned fc_disable;
  1034. atomic_t rx_reset;
  1035. enum efx_loopback_mode loopback_mode;
  1036. u64 loopback_modes;
  1037. void *loopback_selftest;
  1038. /* We access loopback_selftest immediately before running XDP,
  1039. * so we want them next to each other.
  1040. */
  1041. struct bpf_prog __rcu *xdp_prog;
  1042. struct rw_semaphore filter_sem;
  1043. void *filter_state;
  1044. #ifdef CONFIG_RFS_ACCEL
  1045. struct mutex rps_mutex;
  1046. unsigned long rps_slot_map;
  1047. struct efx_async_filter_insertion rps_slot[EFX_RPS_MAX_IN_FLIGHT];
  1048. spinlock_t rps_hash_lock;
  1049. struct hlist_head *rps_hash_table;
  1050. u32 rps_next_id;
  1051. #endif
  1052. atomic_t active_queues;
  1053. atomic_t rxq_flush_pending;
  1054. atomic_t rxq_flush_outstanding;
  1055. wait_queue_head_t flush_wq;
  1056. #ifdef CONFIG_SFC_SRIOV
  1057. unsigned vf_count;
  1058. unsigned vf_init_count;
  1059. unsigned vi_scale;
  1060. #endif
  1061. spinlock_t vf_reps_lock;
  1062. struct list_head vf_reps;
  1063. struct efx_ptp_data *ptp_data;
  1064. bool ptp_warned;
  1065. char *vpd_sn;
  1066. bool xdp_rxq_info_failed;
  1067. struct notifier_block netdev_notifier;
  1068. struct efx_tc_state *tc;
  1069. unsigned int mem_bar;
  1070. u32 reg_base;
  1071. /* The following fields may be written more often */
  1072. struct delayed_work monitor_work ____cacheline_aligned_in_smp;
  1073. spinlock_t biu_lock;
  1074. int last_irq_cpu;
  1075. spinlock_t stats_lock;
  1076. atomic_t n_rx_noskb_drops;
  1077. };
  1078. /**
  1079. * struct efx_probe_data - State after hardware probe
  1080. * @pci_dev: The PCI device
  1081. * @efx: Efx NIC details
  1082. */
  1083. struct efx_probe_data {
  1084. struct pci_dev *pci_dev;
  1085. struct efx_nic efx;
  1086. };
  1087. static inline struct efx_nic *efx_netdev_priv(struct net_device *dev)
  1088. {
  1089. struct efx_probe_data **probe_ptr = netdev_priv(dev);
  1090. struct efx_probe_data *probe_data = *probe_ptr;
  1091. return &probe_data->efx;
  1092. }
  1093. static inline int efx_dev_registered(struct efx_nic *efx)
  1094. {
  1095. return efx->net_dev->reg_state == NETREG_REGISTERED;
  1096. }
  1097. static inline unsigned int efx_port_num(struct efx_nic *efx)
  1098. {
  1099. return efx->port_num;
  1100. }
  1101. struct efx_mtd_partition {
  1102. struct list_head node;
  1103. struct mtd_info mtd;
  1104. const char *dev_type_name;
  1105. const char *type_name;
  1106. char name[IFNAMSIZ + 20];
  1107. };
  1108. struct efx_udp_tunnel {
  1109. #define TUNNEL_ENCAP_UDP_PORT_ENTRY_INVALID 0xffff
  1110. u16 type; /* TUNNEL_ENCAP_UDP_PORT_ENTRY_foo, see mcdi_pcol.h */
  1111. __be16 port;
  1112. };
  1113. /**
  1114. * struct efx_nic_type - Efx device type definition
  1115. * @mem_bar: Get the memory BAR
  1116. * @mem_map_size: Get memory BAR mapped size
  1117. * @probe: Probe the controller
  1118. * @remove: Free resources allocated by probe()
  1119. * @init: Initialise the controller
  1120. * @dimension_resources: Dimension controller resources (buffer table,
  1121. * and VIs once the available interrupt resources are clear)
  1122. * @fini: Shut down the controller
  1123. * @monitor: Periodic function for polling link state and hardware monitor
  1124. * @map_reset_reason: Map ethtool reset reason to a reset method
  1125. * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
  1126. * @reset: Reset the controller hardware and possibly the PHY. This will
  1127. * be called while the controller is uninitialised.
  1128. * @probe_port: Probe the MAC and PHY
  1129. * @remove_port: Free resources allocated by probe_port()
  1130. * @handle_global_event: Handle a "global" event (may be %NULL)
  1131. * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
  1132. * @prepare_flush: Prepare the hardware for flushing the DMA queues
  1133. * (for Falcon architecture)
  1134. * @finish_flush: Clean up after flushing the DMA queues (for Falcon
  1135. * architecture)
  1136. * @prepare_flr: Prepare for an FLR
  1137. * @finish_flr: Clean up after an FLR
  1138. * @describe_stats: Describe statistics for ethtool
  1139. * @update_stats: Update statistics not provided by event handling.
  1140. * Either argument may be %NULL.
  1141. * @update_stats_atomic: Update statistics while in atomic context, if that
  1142. * is more limiting than @update_stats. Otherwise, leave %NULL and
  1143. * driver core will call @update_stats.
  1144. * @start_stats: Start the regular fetching of statistics
  1145. * @pull_stats: Pull stats from the NIC and wait until they arrive.
  1146. * @stop_stats: Stop the regular fetching of statistics
  1147. * @push_irq_moderation: Apply interrupt moderation value
  1148. * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
  1149. * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
  1150. * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
  1151. * to the hardware. Serialised by the mac_lock.
  1152. * @check_mac_fault: Check MAC fault state. True if fault present.
  1153. * @get_wol: Get WoL configuration from driver state
  1154. * @set_wol: Push WoL configuration to the NIC
  1155. * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
  1156. * @get_fec_stats: Get standard FEC statistics.
  1157. * @test_chip: Test registers. May use efx_farch_test_registers(), and is
  1158. * expected to reset the NIC.
  1159. * @test_nvram: Test validity of NVRAM contents
  1160. * @mcdi_request: Send an MCDI request with the given header and SDU.
  1161. * The SDU length may be any value from 0 up to the protocol-
  1162. * defined maximum, but its buffer will be padded to a multiple
  1163. * of 4 bytes.
  1164. * @mcdi_poll_response: Test whether an MCDI response is available.
  1165. * @mcdi_read_response: Read the MCDI response PDU. The offset will
  1166. * be a multiple of 4. The length may not be, but the buffer
  1167. * will be padded so it is safe to round up.
  1168. * @mcdi_poll_reboot: Test whether the MCDI has rebooted. If so,
  1169. * return an appropriate error code for aborting any current
  1170. * request; otherwise return 0.
  1171. * @irq_enable_master: Enable IRQs on the NIC. Each event queue must
  1172. * be separately enabled after this.
  1173. * @irq_test_generate: Generate a test IRQ
  1174. * @irq_disable_non_ev: Disable non-event IRQs on the NIC. Each event
  1175. * queue must be separately disabled before this.
  1176. * @irq_handle_msi: Handle MSI for a channel. The @dev_id argument is
  1177. * a pointer to the &struct efx_msi_context for the channel.
  1178. * @irq_handle_legacy: Handle legacy interrupt. The @dev_id argument
  1179. * is a pointer to the &struct efx_nic.
  1180. * @tx_probe: Allocate resources for TX queue (and select TXQ type)
  1181. * @tx_init: Initialise TX queue on the NIC
  1182. * @tx_remove: Free resources for TX queue
  1183. * @tx_write: Write TX descriptors and doorbell
  1184. * @tx_enqueue: Add an SKB to TX queue
  1185. * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC
  1186. * @rx_pull_rss_config: Read RSS hash key and indirection table back from the NIC
  1187. * @rx_push_rss_context_config: Write RSS hash key and indirection table for
  1188. * user RSS context to the NIC
  1189. * @rx_pull_rss_context_config: Read RSS hash key and indirection table for user
  1190. * RSS context back from the NIC
  1191. * @rx_probe: Allocate resources for RX queue
  1192. * @rx_init: Initialise RX queue on the NIC
  1193. * @rx_remove: Free resources for RX queue
  1194. * @rx_write: Write RX descriptors and doorbell
  1195. * @rx_defer_refill: Generate a refill reminder event
  1196. * @rx_packet: Receive the queued RX buffer on a channel
  1197. * @rx_buf_hash_valid: Determine whether the RX prefix contains a valid hash
  1198. * @ev_probe: Allocate resources for event queue
  1199. * @ev_init: Initialise event queue on the NIC
  1200. * @ev_fini: Deinitialise event queue on the NIC
  1201. * @ev_remove: Free resources for event queue
  1202. * @ev_process: Process events for a queue, up to the given NAPI quota
  1203. * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
  1204. * @ev_test_generate: Generate a test event
  1205. * @filter_table_probe: Probe filter capabilities and set up filter software state
  1206. * @filter_table_restore: Restore filters removed from hardware
  1207. * @filter_table_remove: Remove filters from hardware and tear down software state
  1208. * @filter_update_rx_scatter: Update filters after change to rx scatter setting
  1209. * @filter_insert: add or replace a filter
  1210. * @filter_remove_safe: remove a filter by ID, carefully
  1211. * @filter_get_safe: retrieve a filter by ID, carefully
  1212. * @filter_clear_rx: Remove all RX filters whose priority is less than or
  1213. * equal to the given priority and is not %EFX_FILTER_PRI_AUTO
  1214. * @filter_count_rx_used: Get the number of filters in use at a given priority
  1215. * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
  1216. * @filter_get_rx_ids: Get list of RX filters at a given priority
  1217. * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
  1218. * This must check whether the specified table entry is used by RFS
  1219. * and that rps_may_expire_flow() returns true for it.
  1220. * @mtd_probe: Probe and add MTD partitions associated with this net device,
  1221. * using efx_mtd_add()
  1222. * @mtd_rename: Set an MTD partition name using the net device name
  1223. * @mtd_read: Read from an MTD partition
  1224. * @mtd_erase: Erase part of an MTD partition
  1225. * @mtd_write: Write to an MTD partition
  1226. * @mtd_sync: Wait for write-back to complete on MTD partition. This
  1227. * also notifies the driver that a writer has finished using this
  1228. * partition.
  1229. * @ptp_write_host_time: Send host time to MC as part of sync protocol
  1230. * @ptp_set_ts_sync_events: Enable or disable sync events for inline RX
  1231. * timestamping, possibly only temporarily for the purposes of a reset.
  1232. * @ptp_set_ts_config: Set hardware timestamp configuration. The flags
  1233. * and tx_type will already have been validated but this operation
  1234. * must validate and update rx_filter.
  1235. * @get_phys_port_id: Get the underlying physical port id.
  1236. * @set_mac_address: Set the MAC address of the device
  1237. * @tso_versions: Returns mask of firmware-assisted TSO versions supported.
  1238. * If %NULL, then device does not support any TSO version.
  1239. * @udp_tnl_push_ports: Push the list of UDP tunnel ports to the NIC if required.
  1240. * @udp_tnl_has_port: Check if a port has been added as UDP tunnel
  1241. * @print_additional_fwver: Dump NIC-specific additional FW version info
  1242. * @sensor_event: Handle a sensor event from MCDI
  1243. * @rx_recycle_ring_size: Size of the RX recycle ring
  1244. * @revision: Hardware architecture revision
  1245. * @txd_ptr_tbl_base: TX descriptor ring base address
  1246. * @rxd_ptr_tbl_base: RX descriptor ring base address
  1247. * @buf_tbl_base: Buffer table base address
  1248. * @evq_ptr_tbl_base: Event queue pointer table base address
  1249. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  1250. * @max_dma_mask: Maximum possible DMA mask
  1251. * @rx_prefix_size: Size of RX prefix before packet data
  1252. * @rx_hash_offset: Offset of RX flow hash within prefix
  1253. * @rx_ts_offset: Offset of timestamp within prefix
  1254. * @rx_buffer_padding: Size of padding at end of RX packet
  1255. * @can_rx_scatter: NIC is able to scatter packets to multiple buffers
  1256. * @always_rx_scatter: NIC will always scatter packets to multiple buffers
  1257. * @option_descriptors: NIC supports TX option descriptors
  1258. * @min_interrupt_mode: Lowest capability interrupt mode supported
  1259. * from &enum efx_int_mode.
  1260. * @timer_period_max: Maximum period of interrupt timer (in ticks)
  1261. * @offload_features: net_device feature flags for protocol offload
  1262. * features implemented in hardware
  1263. * @mcdi_max_ver: Maximum MCDI version supported
  1264. * @hwtstamp_filters: Mask of hardware timestamp filter types supported
  1265. */
  1266. struct efx_nic_type {
  1267. bool is_vf;
  1268. unsigned int (*mem_bar)(struct efx_nic *efx);
  1269. unsigned int (*mem_map_size)(struct efx_nic *efx);
  1270. int (*probe)(struct efx_nic *efx);
  1271. void (*remove)(struct efx_nic *efx);
  1272. int (*init)(struct efx_nic *efx);
  1273. int (*dimension_resources)(struct efx_nic *efx);
  1274. void (*fini)(struct efx_nic *efx);
  1275. void (*monitor)(struct efx_nic *efx);
  1276. enum reset_type (*map_reset_reason)(enum reset_type reason);
  1277. int (*map_reset_flags)(u32 *flags);
  1278. int (*reset)(struct efx_nic *efx, enum reset_type method);
  1279. int (*probe_port)(struct efx_nic *efx);
  1280. void (*remove_port)(struct efx_nic *efx);
  1281. bool (*handle_global_event)(struct efx_channel *channel, efx_qword_t *);
  1282. int (*fini_dmaq)(struct efx_nic *efx);
  1283. void (*prepare_flush)(struct efx_nic *efx);
  1284. void (*finish_flush)(struct efx_nic *efx);
  1285. void (*prepare_flr)(struct efx_nic *efx);
  1286. void (*finish_flr)(struct efx_nic *efx);
  1287. size_t (*describe_stats)(struct efx_nic *efx, u8 *names);
  1288. size_t (*update_stats)(struct efx_nic *efx, u64 *full_stats,
  1289. struct rtnl_link_stats64 *core_stats);
  1290. size_t (*update_stats_atomic)(struct efx_nic *efx, u64 *full_stats,
  1291. struct rtnl_link_stats64 *core_stats);
  1292. void (*start_stats)(struct efx_nic *efx);
  1293. void (*pull_stats)(struct efx_nic *efx);
  1294. void (*stop_stats)(struct efx_nic *efx);
  1295. void (*push_irq_moderation)(struct efx_channel *channel);
  1296. int (*reconfigure_port)(struct efx_nic *efx);
  1297. void (*prepare_enable_fc_tx)(struct efx_nic *efx);
  1298. int (*reconfigure_mac)(struct efx_nic *efx, bool mtu_only);
  1299. bool (*check_mac_fault)(struct efx_nic *efx);
  1300. void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
  1301. int (*set_wol)(struct efx_nic *efx, u32 type);
  1302. void (*resume_wol)(struct efx_nic *efx);
  1303. void (*get_fec_stats)(struct efx_nic *efx,
  1304. struct ethtool_fec_stats *fec_stats);
  1305. unsigned int (*check_caps)(const struct efx_nic *efx,
  1306. u8 flag,
  1307. u32 offset);
  1308. int (*test_chip)(struct efx_nic *efx, struct efx_self_tests *tests);
  1309. int (*test_nvram)(struct efx_nic *efx);
  1310. void (*mcdi_request)(struct efx_nic *efx,
  1311. const efx_dword_t *hdr, size_t hdr_len,
  1312. const efx_dword_t *sdu, size_t sdu_len);
  1313. bool (*mcdi_poll_response)(struct efx_nic *efx);
  1314. void (*mcdi_read_response)(struct efx_nic *efx, efx_dword_t *pdu,
  1315. size_t pdu_offset, size_t pdu_len);
  1316. int (*mcdi_poll_reboot)(struct efx_nic *efx);
  1317. void (*mcdi_reboot_detected)(struct efx_nic *efx);
  1318. void (*irq_enable_master)(struct efx_nic *efx);
  1319. int (*irq_test_generate)(struct efx_nic *efx);
  1320. void (*irq_disable_non_ev)(struct efx_nic *efx);
  1321. irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
  1322. irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
  1323. int (*tx_probe)(struct efx_tx_queue *tx_queue);
  1324. void (*tx_init)(struct efx_tx_queue *tx_queue);
  1325. void (*tx_remove)(struct efx_tx_queue *tx_queue);
  1326. void (*tx_write)(struct efx_tx_queue *tx_queue);
  1327. netdev_tx_t (*tx_enqueue)(struct efx_tx_queue *tx_queue, struct sk_buff *skb);
  1328. unsigned int (*tx_limit_len)(struct efx_tx_queue *tx_queue,
  1329. dma_addr_t dma_addr, unsigned int len);
  1330. int (*rx_push_rss_config)(struct efx_nic *efx, bool user,
  1331. const u32 *rx_indir_table, const u8 *key);
  1332. int (*rx_pull_rss_config)(struct efx_nic *efx);
  1333. int (*rx_push_rss_context_config)(struct efx_nic *efx,
  1334. struct efx_rss_context *ctx,
  1335. const u32 *rx_indir_table,
  1336. const u8 *key);
  1337. int (*rx_pull_rss_context_config)(struct efx_nic *efx,
  1338. struct efx_rss_context *ctx);
  1339. void (*rx_restore_rss_contexts)(struct efx_nic *efx);
  1340. int (*rx_probe)(struct efx_rx_queue *rx_queue);
  1341. void (*rx_init)(struct efx_rx_queue *rx_queue);
  1342. void (*rx_remove)(struct efx_rx_queue *rx_queue);
  1343. void (*rx_write)(struct efx_rx_queue *rx_queue);
  1344. void (*rx_defer_refill)(struct efx_rx_queue *rx_queue);
  1345. void (*rx_packet)(struct efx_channel *channel);
  1346. bool (*rx_buf_hash_valid)(const u8 *prefix);
  1347. int (*ev_probe)(struct efx_channel *channel);
  1348. int (*ev_init)(struct efx_channel *channel);
  1349. void (*ev_fini)(struct efx_channel *channel);
  1350. void (*ev_remove)(struct efx_channel *channel);
  1351. int (*ev_process)(struct efx_channel *channel, int quota);
  1352. void (*ev_read_ack)(struct efx_channel *channel);
  1353. void (*ev_test_generate)(struct efx_channel *channel);
  1354. int (*filter_table_probe)(struct efx_nic *efx);
  1355. void (*filter_table_restore)(struct efx_nic *efx);
  1356. void (*filter_table_remove)(struct efx_nic *efx);
  1357. void (*filter_update_rx_scatter)(struct efx_nic *efx);
  1358. s32 (*filter_insert)(struct efx_nic *efx,
  1359. struct efx_filter_spec *spec, bool replace);
  1360. int (*filter_remove_safe)(struct efx_nic *efx,
  1361. enum efx_filter_priority priority,
  1362. u32 filter_id);
  1363. int (*filter_get_safe)(struct efx_nic *efx,
  1364. enum efx_filter_priority priority,
  1365. u32 filter_id, struct efx_filter_spec *);
  1366. int (*filter_clear_rx)(struct efx_nic *efx,
  1367. enum efx_filter_priority priority);
  1368. u32 (*filter_count_rx_used)(struct efx_nic *efx,
  1369. enum efx_filter_priority priority);
  1370. u32 (*filter_get_rx_id_limit)(struct efx_nic *efx);
  1371. s32 (*filter_get_rx_ids)(struct efx_nic *efx,
  1372. enum efx_filter_priority priority,
  1373. u32 *buf, u32 size);
  1374. #ifdef CONFIG_RFS_ACCEL
  1375. bool (*filter_rfs_expire_one)(struct efx_nic *efx, u32 flow_id,
  1376. unsigned int index);
  1377. #endif
  1378. #ifdef CONFIG_SFC_MTD
  1379. int (*mtd_probe)(struct efx_nic *efx);
  1380. void (*mtd_rename)(struct efx_mtd_partition *part);
  1381. int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len,
  1382. size_t *retlen, u8 *buffer);
  1383. int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len);
  1384. int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len,
  1385. size_t *retlen, const u8 *buffer);
  1386. int (*mtd_sync)(struct mtd_info *mtd);
  1387. #endif
  1388. void (*ptp_write_host_time)(struct efx_nic *efx, u32 host_time);
  1389. int (*ptp_set_ts_sync_events)(struct efx_nic *efx, bool en, bool temp);
  1390. int (*ptp_set_ts_config)(struct efx_nic *efx,
  1391. struct hwtstamp_config *init);
  1392. int (*sriov_configure)(struct efx_nic *efx, int num_vfs);
  1393. int (*vlan_rx_add_vid)(struct efx_nic *efx, __be16 proto, u16 vid);
  1394. int (*vlan_rx_kill_vid)(struct efx_nic *efx, __be16 proto, u16 vid);
  1395. int (*get_phys_port_id)(struct efx_nic *efx,
  1396. struct netdev_phys_item_id *ppid);
  1397. int (*sriov_init)(struct efx_nic *efx);
  1398. void (*sriov_fini)(struct efx_nic *efx);
  1399. bool (*sriov_wanted)(struct efx_nic *efx);
  1400. void (*sriov_reset)(struct efx_nic *efx);
  1401. void (*sriov_flr)(struct efx_nic *efx, unsigned vf_i);
  1402. int (*sriov_set_vf_mac)(struct efx_nic *efx, int vf_i, const u8 *mac);
  1403. int (*sriov_set_vf_vlan)(struct efx_nic *efx, int vf_i, u16 vlan,
  1404. u8 qos);
  1405. int (*sriov_set_vf_spoofchk)(struct efx_nic *efx, int vf_i,
  1406. bool spoofchk);
  1407. int (*sriov_get_vf_config)(struct efx_nic *efx, int vf_i,
  1408. struct ifla_vf_info *ivi);
  1409. int (*sriov_set_vf_link_state)(struct efx_nic *efx, int vf_i,
  1410. int link_state);
  1411. int (*vswitching_probe)(struct efx_nic *efx);
  1412. int (*vswitching_restore)(struct efx_nic *efx);
  1413. void (*vswitching_remove)(struct efx_nic *efx);
  1414. int (*get_mac_address)(struct efx_nic *efx, unsigned char *perm_addr);
  1415. int (*set_mac_address)(struct efx_nic *efx);
  1416. u32 (*tso_versions)(struct efx_nic *efx);
  1417. int (*udp_tnl_push_ports)(struct efx_nic *efx);
  1418. bool (*udp_tnl_has_port)(struct efx_nic *efx, __be16 port);
  1419. size_t (*print_additional_fwver)(struct efx_nic *efx, char *buf,
  1420. size_t len);
  1421. void (*sensor_event)(struct efx_nic *efx, efx_qword_t *ev);
  1422. unsigned int (*rx_recycle_ring_size)(const struct efx_nic *efx);
  1423. int revision;
  1424. unsigned int txd_ptr_tbl_base;
  1425. unsigned int rxd_ptr_tbl_base;
  1426. unsigned int buf_tbl_base;
  1427. unsigned int evq_ptr_tbl_base;
  1428. unsigned int evq_rptr_tbl_base;
  1429. u64 max_dma_mask;
  1430. unsigned int rx_prefix_size;
  1431. unsigned int rx_hash_offset;
  1432. unsigned int rx_ts_offset;
  1433. unsigned int rx_buffer_padding;
  1434. bool can_rx_scatter;
  1435. bool always_rx_scatter;
  1436. bool option_descriptors;
  1437. unsigned int min_interrupt_mode;
  1438. unsigned int timer_period_max;
  1439. netdev_features_t offload_features;
  1440. int mcdi_max_ver;
  1441. unsigned int max_rx_ip_filters;
  1442. u32 hwtstamp_filters;
  1443. unsigned int rx_hash_key_size;
  1444. };
  1445. /**************************************************************************
  1446. *
  1447. * Prototypes and inline functions
  1448. *
  1449. *************************************************************************/
  1450. static inline struct efx_channel *
  1451. efx_get_channel(struct efx_nic *efx, unsigned index)
  1452. {
  1453. EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_channels);
  1454. return efx->channel[index];
  1455. }
  1456. /* Iterate over all used channels */
  1457. #define efx_for_each_channel(_channel, _efx) \
  1458. for (_channel = (_efx)->channel[0]; \
  1459. _channel; \
  1460. _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
  1461. (_efx)->channel[_channel->channel + 1] : NULL)
  1462. /* Iterate over all used channels in reverse */
  1463. #define efx_for_each_channel_rev(_channel, _efx) \
  1464. for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \
  1465. _channel; \
  1466. _channel = _channel->channel ? \
  1467. (_efx)->channel[_channel->channel - 1] : NULL)
  1468. static inline struct efx_channel *
  1469. efx_get_tx_channel(struct efx_nic *efx, unsigned int index)
  1470. {
  1471. EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_tx_channels);
  1472. return efx->channel[efx->tx_channel_offset + index];
  1473. }
  1474. static inline struct efx_channel *
  1475. efx_get_xdp_channel(struct efx_nic *efx, unsigned int index)
  1476. {
  1477. EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_xdp_channels);
  1478. return efx->channel[efx->xdp_channel_offset + index];
  1479. }
  1480. static inline bool efx_channel_is_xdp_tx(struct efx_channel *channel)
  1481. {
  1482. return channel->channel - channel->efx->xdp_channel_offset <
  1483. channel->efx->n_xdp_channels;
  1484. }
  1485. static inline bool efx_channel_has_tx_queues(struct efx_channel *channel)
  1486. {
  1487. return channel && channel->channel >= channel->efx->tx_channel_offset;
  1488. }
  1489. static inline unsigned int efx_channel_num_tx_queues(struct efx_channel *channel)
  1490. {
  1491. if (efx_channel_is_xdp_tx(channel))
  1492. return channel->efx->xdp_tx_per_channel;
  1493. return channel->efx->tx_queues_per_channel;
  1494. }
  1495. static inline struct efx_tx_queue *
  1496. efx_channel_get_tx_queue(struct efx_channel *channel, unsigned int type)
  1497. {
  1498. EFX_WARN_ON_ONCE_PARANOID(type >= EFX_TXQ_TYPES);
  1499. return channel->tx_queue_by_type[type];
  1500. }
  1501. static inline struct efx_tx_queue *
  1502. efx_get_tx_queue(struct efx_nic *efx, unsigned int index, unsigned int type)
  1503. {
  1504. struct efx_channel *channel = efx_get_tx_channel(efx, index);
  1505. return efx_channel_get_tx_queue(channel, type);
  1506. }
  1507. /* Iterate over all TX queues belonging to a channel */
  1508. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  1509. if (!efx_channel_has_tx_queues(_channel)) \
  1510. ; \
  1511. else \
  1512. for (_tx_queue = (_channel)->tx_queue; \
  1513. _tx_queue < (_channel)->tx_queue + \
  1514. efx_channel_num_tx_queues(_channel); \
  1515. _tx_queue++)
  1516. static inline bool efx_channel_has_rx_queue(struct efx_channel *channel)
  1517. {
  1518. return channel->rx_queue.core_index >= 0;
  1519. }
  1520. static inline struct efx_rx_queue *
  1521. efx_channel_get_rx_queue(struct efx_channel *channel)
  1522. {
  1523. EFX_WARN_ON_ONCE_PARANOID(!efx_channel_has_rx_queue(channel));
  1524. return &channel->rx_queue;
  1525. }
  1526. /* Iterate over all RX queues belonging to a channel */
  1527. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  1528. if (!efx_channel_has_rx_queue(_channel)) \
  1529. ; \
  1530. else \
  1531. for (_rx_queue = &(_channel)->rx_queue; \
  1532. _rx_queue; \
  1533. _rx_queue = NULL)
  1534. static inline struct efx_channel *
  1535. efx_rx_queue_channel(struct efx_rx_queue *rx_queue)
  1536. {
  1537. return container_of(rx_queue, struct efx_channel, rx_queue);
  1538. }
  1539. static inline int efx_rx_queue_index(struct efx_rx_queue *rx_queue)
  1540. {
  1541. return efx_rx_queue_channel(rx_queue)->channel;
  1542. }
  1543. /* Returns a pointer to the specified receive buffer in the RX
  1544. * descriptor queue.
  1545. */
  1546. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  1547. unsigned int index)
  1548. {
  1549. return &rx_queue->buffer[index];
  1550. }
  1551. static inline struct efx_rx_buffer *
  1552. efx_rx_buf_next(struct efx_rx_queue *rx_queue, struct efx_rx_buffer *rx_buf)
  1553. {
  1554. if (unlikely(rx_buf == efx_rx_buffer(rx_queue, rx_queue->ptr_mask)))
  1555. return efx_rx_buffer(rx_queue, 0);
  1556. else
  1557. return rx_buf + 1;
  1558. }
  1559. /**
  1560. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  1561. *
  1562. * This calculates the maximum frame length that will be used for a
  1563. * given MTU. The frame length will be equal to the MTU plus a
  1564. * constant amount of header space and padding. This is the quantity
  1565. * that the net driver will program into the MAC as the maximum frame
  1566. * length.
  1567. *
  1568. * The 10G MAC requires 8-byte alignment on the frame
  1569. * length, so we round up to the nearest 8.
  1570. *
  1571. * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
  1572. * XGMII cycle). If the frame length reaches the maximum value in the
  1573. * same cycle, the XMAC can miss the IPG altogether. We work around
  1574. * this by adding a further 16 bytes.
  1575. */
  1576. #define EFX_FRAME_PAD 16
  1577. #define EFX_MAX_FRAME_LEN(mtu) \
  1578. (ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EFX_FRAME_PAD), 8))
  1579. static inline bool efx_xmit_with_hwtstamp(struct sk_buff *skb)
  1580. {
  1581. return skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP;
  1582. }
  1583. static inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)
  1584. {
  1585. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  1586. }
  1587. /* Get the max fill level of the TX queues on this channel */
  1588. static inline unsigned int
  1589. efx_channel_tx_fill_level(struct efx_channel *channel)
  1590. {
  1591. struct efx_tx_queue *tx_queue;
  1592. unsigned int fill_level = 0;
  1593. efx_for_each_channel_tx_queue(tx_queue, channel)
  1594. fill_level = max(fill_level,
  1595. tx_queue->insert_count - tx_queue->read_count);
  1596. return fill_level;
  1597. }
  1598. /* Conservative approximation of efx_channel_tx_fill_level using cached value */
  1599. static inline unsigned int
  1600. efx_channel_tx_old_fill_level(struct efx_channel *channel)
  1601. {
  1602. struct efx_tx_queue *tx_queue;
  1603. unsigned int fill_level = 0;
  1604. efx_for_each_channel_tx_queue(tx_queue, channel)
  1605. fill_level = max(fill_level,
  1606. tx_queue->insert_count - tx_queue->old_read_count);
  1607. return fill_level;
  1608. }
  1609. /* Get all supported features.
  1610. * If a feature is not fixed, it is present in hw_features.
  1611. * If a feature is fixed, it does not present in hw_features, but
  1612. * always in features.
  1613. */
  1614. static inline netdev_features_t efx_supported_features(const struct efx_nic *efx)
  1615. {
  1616. const struct net_device *net_dev = efx->net_dev;
  1617. return net_dev->features | net_dev->hw_features;
  1618. }
  1619. /* Get the current TX queue insert index. */
  1620. static inline unsigned int
  1621. efx_tx_queue_get_insert_index(const struct efx_tx_queue *tx_queue)
  1622. {
  1623. return tx_queue->insert_count & tx_queue->ptr_mask;
  1624. }
  1625. /* Get a TX buffer. */
  1626. static inline struct efx_tx_buffer *
  1627. __efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue)
  1628. {
  1629. return &tx_queue->buffer[efx_tx_queue_get_insert_index(tx_queue)];
  1630. }
  1631. /* Get a TX buffer, checking it's not currently in use. */
  1632. static inline struct efx_tx_buffer *
  1633. efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue)
  1634. {
  1635. struct efx_tx_buffer *buffer =
  1636. __efx_tx_queue_get_insert_buffer(tx_queue);
  1637. EFX_WARN_ON_ONCE_PARANOID(buffer->len);
  1638. EFX_WARN_ON_ONCE_PARANOID(buffer->flags);
  1639. EFX_WARN_ON_ONCE_PARANOID(buffer->unmap_len);
  1640. return buffer;
  1641. }
  1642. #endif /* EFX_NET_DRIVER_H */