net_driver.h 55 KB

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