net_driver.h 61 KB

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