net_driver.h 60 KB

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