net_driver.h 63 KB

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