net_driver.h 56 KB

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