net_driver.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2011 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/vmalloc.h>
  26. #include <linux/i2c.h>
  27. #include "enum.h"
  28. #include "bitfield.h"
  29. /**************************************************************************
  30. *
  31. * Build definitions
  32. *
  33. **************************************************************************/
  34. #define EFX_DRIVER_VERSION "3.2"
  35. #ifdef DEBUG
  36. #define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
  37. #define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
  38. #else
  39. #define EFX_BUG_ON_PARANOID(x) do {} while (0)
  40. #define EFX_WARN_ON_PARANOID(x) do {} while (0)
  41. #endif
  42. /**************************************************************************
  43. *
  44. * Efx data structures
  45. *
  46. **************************************************************************/
  47. #define EFX_MAX_CHANNELS 32U
  48. #define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
  49. #define EFX_EXTRA_CHANNEL_IOV 0
  50. #define EFX_EXTRA_CHANNEL_PTP 1
  51. #define EFX_MAX_EXTRA_CHANNELS 2U
  52. /* Checksum generation is a per-queue option in hardware, so each
  53. * queue visible to the networking core is backed by two hardware TX
  54. * queues. */
  55. #define EFX_MAX_TX_TC 2
  56. #define EFX_MAX_CORE_TX_QUEUES (EFX_MAX_TX_TC * EFX_MAX_CHANNELS)
  57. #define EFX_TXQ_TYPE_OFFLOAD 1 /* flag */
  58. #define EFX_TXQ_TYPE_HIGHPRI 2 /* flag */
  59. #define EFX_TXQ_TYPES 4
  60. #define EFX_MAX_TX_QUEUES (EFX_TXQ_TYPES * EFX_MAX_CHANNELS)
  61. /* Forward declare Precision Time Protocol (PTP) support structure. */
  62. struct efx_ptp_data;
  63. struct efx_self_tests;
  64. /**
  65. * struct efx_special_buffer - An Efx special buffer
  66. * @addr: CPU base address of the buffer
  67. * @dma_addr: DMA base address of the buffer
  68. * @len: Buffer length, in bytes
  69. * @index: Buffer index within controller;s buffer table
  70. * @entries: Number of buffer table entries
  71. *
  72. * Special buffers are used for the event queues and the TX and RX
  73. * descriptor queues for each channel. They are *not* used for the
  74. * actual transmit and receive buffers.
  75. */
  76. struct efx_special_buffer {
  77. void *addr;
  78. dma_addr_t dma_addr;
  79. unsigned int len;
  80. unsigned int index;
  81. unsigned int entries;
  82. };
  83. /**
  84. * struct efx_tx_buffer - buffer state for a TX descriptor
  85. * @skb: When @flags & %EFX_TX_BUF_SKB, the associated socket buffer to be
  86. * freed when descriptor completes
  87. * @heap_buf: When @flags & %EFX_TX_BUF_HEAP, the associated heap buffer to be
  88. * freed when descriptor completes.
  89. * @dma_addr: DMA address of the fragment.
  90. * @flags: Flags for allocation and DMA mapping type
  91. * @len: Length of this fragment.
  92. * This field is zero when the queue slot is empty.
  93. * @unmap_len: Length of this fragment to unmap
  94. */
  95. struct efx_tx_buffer {
  96. union {
  97. const struct sk_buff *skb;
  98. void *heap_buf;
  99. };
  100. dma_addr_t dma_addr;
  101. unsigned short flags;
  102. unsigned short len;
  103. unsigned short unmap_len;
  104. };
  105. #define EFX_TX_BUF_CONT 1 /* not last descriptor of packet */
  106. #define EFX_TX_BUF_SKB 2 /* buffer is last part of skb */
  107. #define EFX_TX_BUF_HEAP 4 /* buffer was allocated with kmalloc() */
  108. #define EFX_TX_BUF_MAP_SINGLE 8 /* buffer was mapped with dma_map_single() */
  109. /**
  110. * struct efx_tx_queue - An Efx TX queue
  111. *
  112. * This is a ring buffer of TX fragments.
  113. * Since the TX completion path always executes on the same
  114. * CPU and the xmit path can operate on different CPUs,
  115. * performance is increased by ensuring that the completion
  116. * path and the xmit path operate on different cache lines.
  117. * This is particularly important if the xmit path is always
  118. * executing on one CPU which is different from the completion
  119. * path. There is also a cache line for members which are
  120. * read but not written on the fast path.
  121. *
  122. * @efx: The associated Efx NIC
  123. * @queue: DMA queue number
  124. * @channel: The associated channel
  125. * @core_txq: The networking core TX queue structure
  126. * @buffer: The software buffer ring
  127. * @tsoh_page: Array of pages of TSO header buffers
  128. * @txd: The hardware descriptor ring
  129. * @ptr_mask: The size of the ring minus 1.
  130. * @initialised: Has hardware queue been initialised?
  131. * @read_count: Current read pointer.
  132. * This is the number of buffers that have been removed from both rings.
  133. * @old_write_count: The value of @write_count when last checked.
  134. * This is here for performance reasons. The xmit path will
  135. * only get the up-to-date value of @write_count if this
  136. * variable indicates that the queue is empty. This is to
  137. * avoid cache-line ping-pong between the xmit path and the
  138. * completion path.
  139. * @insert_count: Current insert pointer
  140. * This is the number of buffers that have been added to the
  141. * software ring.
  142. * @write_count: Current write pointer
  143. * This is the number of buffers that have been added to the
  144. * hardware ring.
  145. * @old_read_count: The value of read_count when last checked.
  146. * This is here for performance reasons. The xmit path will
  147. * only get the up-to-date value of read_count if this
  148. * variable indicates that the queue is full. This is to
  149. * avoid cache-line ping-pong between the xmit path and the
  150. * completion path.
  151. * @tso_bursts: Number of times TSO xmit invoked by kernel
  152. * @tso_long_headers: Number of packets with headers too long for standard
  153. * blocks
  154. * @tso_packets: Number of packets via the TSO xmit path
  155. * @pushes: Number of times the TX push feature has been used
  156. * @empty_read_count: If the completion path has seen the queue as empty
  157. * and the transmission path has not yet checked this, the value of
  158. * @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
  159. */
  160. struct efx_tx_queue {
  161. /* Members which don't change on the fast path */
  162. struct efx_nic *efx ____cacheline_aligned_in_smp;
  163. unsigned queue;
  164. struct efx_channel *channel;
  165. struct netdev_queue *core_txq;
  166. struct efx_tx_buffer *buffer;
  167. struct efx_buffer *tsoh_page;
  168. struct efx_special_buffer txd;
  169. unsigned int ptr_mask;
  170. bool initialised;
  171. /* Members used mainly on the completion path */
  172. unsigned int read_count ____cacheline_aligned_in_smp;
  173. unsigned int old_write_count;
  174. /* Members used only on the xmit path */
  175. unsigned int insert_count ____cacheline_aligned_in_smp;
  176. unsigned int write_count;
  177. unsigned int old_read_count;
  178. unsigned int tso_bursts;
  179. unsigned int tso_long_headers;
  180. unsigned int tso_packets;
  181. unsigned int pushes;
  182. /* Members shared between paths and sometimes updated */
  183. unsigned int empty_read_count ____cacheline_aligned_in_smp;
  184. #define EFX_EMPTY_COUNT_VALID 0x80000000
  185. atomic_t flush_outstanding;
  186. };
  187. /**
  188. * struct efx_rx_buffer - An Efx RX data buffer
  189. * @dma_addr: DMA base address of the buffer
  190. * @page: The associated page buffer.
  191. * Will be %NULL if the buffer slot is currently free.
  192. * @page_offset: Offset within page
  193. * @len: If pending: length for DMA descriptor.
  194. * If completed: received length, excluding hash prefix.
  195. * @flags: Flags for buffer and packet state.
  196. */
  197. struct efx_rx_buffer {
  198. dma_addr_t dma_addr;
  199. struct page *page;
  200. u16 page_offset;
  201. u16 len;
  202. u16 flags;
  203. };
  204. #define EFX_RX_PKT_CSUMMED 0x0002
  205. #define EFX_RX_PKT_DISCARD 0x0004
  206. /**
  207. * struct efx_rx_page_state - Page-based rx buffer state
  208. *
  209. * Inserted at the start of every page allocated for receive buffers.
  210. * Used to facilitate sharing dma mappings between recycled rx buffers
  211. * and those passed up to the kernel.
  212. *
  213. * @refcnt: Number of struct efx_rx_buffer's referencing this page.
  214. * When refcnt falls to zero, the page is unmapped for dma
  215. * @dma_addr: The dma address of this page.
  216. */
  217. struct efx_rx_page_state {
  218. unsigned refcnt;
  219. dma_addr_t dma_addr;
  220. unsigned int __pad[0] ____cacheline_aligned;
  221. };
  222. /**
  223. * struct efx_rx_queue - An Efx RX queue
  224. * @efx: The associated Efx NIC
  225. * @core_index: Index of network core RX queue. Will be >= 0 iff this
  226. * is associated with a real RX queue.
  227. * @buffer: The software buffer ring
  228. * @rxd: The hardware descriptor ring
  229. * @ptr_mask: The size of the ring minus 1.
  230. * @enabled: Receive queue enabled indicator.
  231. * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
  232. * @rxq_flush_pending.
  233. * @added_count: Number of buffers added to the receive queue.
  234. * @notified_count: Number of buffers given to NIC (<= @added_count).
  235. * @removed_count: Number of buffers removed from the receive queue.
  236. * @max_fill: RX descriptor maximum fill level (<= ring size)
  237. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  238. * (<= @max_fill)
  239. * @min_fill: RX descriptor minimum non-zero fill level.
  240. * This records the minimum fill level observed when a ring
  241. * refill was triggered.
  242. * @slow_fill: Timer used to defer efx_nic_generate_fill_event().
  243. */
  244. struct efx_rx_queue {
  245. struct efx_nic *efx;
  246. int core_index;
  247. struct efx_rx_buffer *buffer;
  248. struct efx_special_buffer rxd;
  249. unsigned int ptr_mask;
  250. bool enabled;
  251. bool flush_pending;
  252. unsigned int added_count;
  253. unsigned int notified_count;
  254. unsigned int removed_count;
  255. unsigned int max_fill;
  256. unsigned int fast_fill_trigger;
  257. unsigned int min_fill;
  258. unsigned int min_overfill;
  259. struct timer_list slow_fill;
  260. unsigned int slow_fill_count;
  261. };
  262. /**
  263. * struct efx_buffer - An Efx general-purpose buffer
  264. * @addr: host base address of the buffer
  265. * @dma_addr: DMA base address of the buffer
  266. * @len: Buffer length, in bytes
  267. *
  268. * The NIC uses these buffers for its interrupt status registers and
  269. * MAC stats dumps.
  270. */
  271. struct efx_buffer {
  272. void *addr;
  273. dma_addr_t dma_addr;
  274. unsigned int len;
  275. };
  276. enum efx_rx_alloc_method {
  277. RX_ALLOC_METHOD_AUTO = 0,
  278. RX_ALLOC_METHOD_SKB = 1,
  279. RX_ALLOC_METHOD_PAGE = 2,
  280. };
  281. /**
  282. * struct efx_channel - An Efx channel
  283. *
  284. * A channel comprises an event queue, at least one TX queue, at least
  285. * one RX queue, and an associated tasklet for processing the event
  286. * queue.
  287. *
  288. * @efx: Associated Efx NIC
  289. * @channel: Channel instance number
  290. * @type: Channel type definition
  291. * @enabled: Channel enabled indicator
  292. * @irq: IRQ number (MSI and MSI-X only)
  293. * @irq_moderation: IRQ moderation value (in hardware ticks)
  294. * @napi_dev: Net device used with NAPI
  295. * @napi_str: NAPI control structure
  296. * @work_pending: Is work pending via NAPI?
  297. * @eventq: Event queue buffer
  298. * @eventq_mask: Event queue pointer mask
  299. * @eventq_read_ptr: Event queue read pointer
  300. * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
  301. * @irq_count: Number of IRQs since last adaptive moderation decision
  302. * @irq_mod_score: IRQ moderation score
  303. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  304. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  305. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  306. * @n_rx_mcast_mismatch: Count of unmatched multicast frames
  307. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  308. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  309. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  310. * @rx_queue: RX queue for this channel
  311. * @tx_queue: TX queues for this channel
  312. */
  313. struct efx_channel {
  314. struct efx_nic *efx;
  315. int channel;
  316. const struct efx_channel_type *type;
  317. bool enabled;
  318. int irq;
  319. unsigned int irq_moderation;
  320. struct net_device *napi_dev;
  321. struct napi_struct napi_str;
  322. bool work_pending;
  323. struct efx_special_buffer eventq;
  324. unsigned int eventq_mask;
  325. unsigned int eventq_read_ptr;
  326. int event_test_cpu;
  327. unsigned int irq_count;
  328. unsigned int irq_mod_score;
  329. #ifdef CONFIG_RFS_ACCEL
  330. unsigned int rfs_filters_added;
  331. #endif
  332. unsigned n_rx_tobe_disc;
  333. unsigned n_rx_ip_hdr_chksum_err;
  334. unsigned n_rx_tcp_udp_chksum_err;
  335. unsigned n_rx_mcast_mismatch;
  336. unsigned n_rx_frm_trunc;
  337. unsigned n_rx_overlength;
  338. unsigned n_skbuff_leaks;
  339. /* Used to pipeline received packets in order to optimise memory
  340. * access with prefetches.
  341. */
  342. struct efx_rx_buffer *rx_pkt;
  343. struct efx_rx_queue rx_queue;
  344. struct efx_tx_queue tx_queue[EFX_TXQ_TYPES];
  345. };
  346. /**
  347. * struct efx_channel_type - distinguishes traffic and extra channels
  348. * @handle_no_channel: Handle failure to allocate an extra channel
  349. * @pre_probe: Set up extra state prior to initialisation
  350. * @post_remove: Tear down extra state after finalisation, if allocated.
  351. * May be called on channels that have not been probed.
  352. * @get_name: Generate the channel's name (used for its IRQ handler)
  353. * @copy: Copy the channel state prior to reallocation. May be %NULL if
  354. * reallocation is not supported.
  355. * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
  356. * @keep_eventq: Flag for whether event queue should be kept initialised
  357. * while the device is stopped
  358. */
  359. struct efx_channel_type {
  360. void (*handle_no_channel)(struct efx_nic *);
  361. int (*pre_probe)(struct efx_channel *);
  362. void (*post_remove)(struct efx_channel *);
  363. void (*get_name)(struct efx_channel *, char *buf, size_t len);
  364. struct efx_channel *(*copy)(const struct efx_channel *);
  365. bool (*receive_skb)(struct efx_channel *, struct sk_buff *);
  366. bool keep_eventq;
  367. };
  368. enum efx_led_mode {
  369. EFX_LED_OFF = 0,
  370. EFX_LED_ON = 1,
  371. EFX_LED_DEFAULT = 2
  372. };
  373. #define STRING_TABLE_LOOKUP(val, member) \
  374. ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
  375. extern const char *const efx_loopback_mode_names[];
  376. extern const unsigned int efx_loopback_mode_max;
  377. #define LOOPBACK_MODE(efx) \
  378. STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_loopback_mode)
  379. extern const char *const efx_reset_type_names[];
  380. extern const unsigned int efx_reset_type_max;
  381. #define RESET_TYPE(type) \
  382. STRING_TABLE_LOOKUP(type, efx_reset_type)
  383. enum efx_int_mode {
  384. /* Be careful if altering to correct macro below */
  385. EFX_INT_MODE_MSIX = 0,
  386. EFX_INT_MODE_MSI = 1,
  387. EFX_INT_MODE_LEGACY = 2,
  388. EFX_INT_MODE_MAX /* Insert any new items before this */
  389. };
  390. #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
  391. enum nic_state {
  392. STATE_UNINIT = 0, /* device being probed/removed or is frozen */
  393. STATE_READY = 1, /* hardware ready and netdev registered */
  394. STATE_DISABLED = 2, /* device disabled due to hardware errors */
  395. STATE_RECOVERY = 3, /* device recovering from PCI error */
  396. };
  397. /*
  398. * Alignment of page-allocated RX buffers
  399. *
  400. * Controls the number of bytes inserted at the start of an RX buffer.
  401. * This is the equivalent of NET_IP_ALIGN [which controls the alignment
  402. * of the skb->head for hardware DMA].
  403. */
  404. #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  405. #define EFX_PAGE_IP_ALIGN 0
  406. #else
  407. #define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
  408. #endif
  409. /*
  410. * Alignment of the skb->head which wraps a page-allocated RX buffer
  411. *
  412. * The skb allocated to wrap an rx_buffer can have this alignment. Since
  413. * the data is memcpy'd from the rx_buf, it does not need to be equal to
  414. * EFX_PAGE_IP_ALIGN.
  415. */
  416. #define EFX_PAGE_SKB_ALIGN 2
  417. /* Forward declaration */
  418. struct efx_nic;
  419. /* Pseudo bit-mask flow control field */
  420. #define EFX_FC_RX FLOW_CTRL_RX
  421. #define EFX_FC_TX FLOW_CTRL_TX
  422. #define EFX_FC_AUTO 4
  423. /**
  424. * struct efx_link_state - Current state of the link
  425. * @up: Link is up
  426. * @fd: Link is full-duplex
  427. * @fc: Actual flow control flags
  428. * @speed: Link speed (Mbps)
  429. */
  430. struct efx_link_state {
  431. bool up;
  432. bool fd;
  433. u8 fc;
  434. unsigned int speed;
  435. };
  436. static inline bool efx_link_state_equal(const struct efx_link_state *left,
  437. const struct efx_link_state *right)
  438. {
  439. return left->up == right->up && left->fd == right->fd &&
  440. left->fc == right->fc && left->speed == right->speed;
  441. }
  442. /**
  443. * struct efx_phy_operations - Efx PHY operations table
  444. * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
  445. * efx->loopback_modes.
  446. * @init: Initialise PHY
  447. * @fini: Shut down PHY
  448. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  449. * @poll: Update @link_state and report whether it changed.
  450. * Serialised by the mac_lock.
  451. * @get_settings: Get ethtool settings. Serialised by the mac_lock.
  452. * @set_settings: Set ethtool settings. Serialised by the mac_lock.
  453. * @set_npage_adv: Set abilities advertised in (Extended) Next Page
  454. * (only needed where AN bit is set in mmds)
  455. * @test_alive: Test that PHY is 'alive' (online)
  456. * @test_name: Get the name of a PHY-specific test/result
  457. * @run_tests: Run tests and record results as appropriate (offline).
  458. * Flags are the ethtool tests flags.
  459. */
  460. struct efx_phy_operations {
  461. int (*probe) (struct efx_nic *efx);
  462. int (*init) (struct efx_nic *efx);
  463. void (*fini) (struct efx_nic *efx);
  464. void (*remove) (struct efx_nic *efx);
  465. int (*reconfigure) (struct efx_nic *efx);
  466. bool (*poll) (struct efx_nic *efx);
  467. void (*get_settings) (struct efx_nic *efx,
  468. struct ethtool_cmd *ecmd);
  469. int (*set_settings) (struct efx_nic *efx,
  470. struct ethtool_cmd *ecmd);
  471. void (*set_npage_adv) (struct efx_nic *efx, u32);
  472. int (*test_alive) (struct efx_nic *efx);
  473. const char *(*test_name) (struct efx_nic *efx, unsigned int index);
  474. int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
  475. int (*get_module_eeprom) (struct efx_nic *efx,
  476. struct ethtool_eeprom *ee,
  477. u8 *data);
  478. int (*get_module_info) (struct efx_nic *efx,
  479. struct ethtool_modinfo *modinfo);
  480. };
  481. /**
  482. * enum efx_phy_mode - PHY operating mode flags
  483. * @PHY_MODE_NORMAL: on and should pass traffic
  484. * @PHY_MODE_TX_DISABLED: on with TX disabled
  485. * @PHY_MODE_LOW_POWER: set to low power through MDIO
  486. * @PHY_MODE_OFF: switched off through external control
  487. * @PHY_MODE_SPECIAL: on but will not pass traffic
  488. */
  489. enum efx_phy_mode {
  490. PHY_MODE_NORMAL = 0,
  491. PHY_MODE_TX_DISABLED = 1,
  492. PHY_MODE_LOW_POWER = 2,
  493. PHY_MODE_OFF = 4,
  494. PHY_MODE_SPECIAL = 8,
  495. };
  496. static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
  497. {
  498. return !!(mode & ~PHY_MODE_TX_DISABLED);
  499. }
  500. /*
  501. * Efx extended statistics
  502. *
  503. * Not all statistics are provided by all supported MACs. The purpose
  504. * is this structure is to contain the raw statistics provided by each
  505. * MAC.
  506. */
  507. struct efx_mac_stats {
  508. u64 tx_bytes;
  509. u64 tx_good_bytes;
  510. u64 tx_bad_bytes;
  511. u64 tx_packets;
  512. u64 tx_bad;
  513. u64 tx_pause;
  514. u64 tx_control;
  515. u64 tx_unicast;
  516. u64 tx_multicast;
  517. u64 tx_broadcast;
  518. u64 tx_lt64;
  519. u64 tx_64;
  520. u64 tx_65_to_127;
  521. u64 tx_128_to_255;
  522. u64 tx_256_to_511;
  523. u64 tx_512_to_1023;
  524. u64 tx_1024_to_15xx;
  525. u64 tx_15xx_to_jumbo;
  526. u64 tx_gtjumbo;
  527. u64 tx_collision;
  528. u64 tx_single_collision;
  529. u64 tx_multiple_collision;
  530. u64 tx_excessive_collision;
  531. u64 tx_deferred;
  532. u64 tx_late_collision;
  533. u64 tx_excessive_deferred;
  534. u64 tx_non_tcpudp;
  535. u64 tx_mac_src_error;
  536. u64 tx_ip_src_error;
  537. u64 rx_bytes;
  538. u64 rx_good_bytes;
  539. u64 rx_bad_bytes;
  540. u64 rx_packets;
  541. u64 rx_good;
  542. u64 rx_bad;
  543. u64 rx_pause;
  544. u64 rx_control;
  545. u64 rx_unicast;
  546. u64 rx_multicast;
  547. u64 rx_broadcast;
  548. u64 rx_lt64;
  549. u64 rx_64;
  550. u64 rx_65_to_127;
  551. u64 rx_128_to_255;
  552. u64 rx_256_to_511;
  553. u64 rx_512_to_1023;
  554. u64 rx_1024_to_15xx;
  555. u64 rx_15xx_to_jumbo;
  556. u64 rx_gtjumbo;
  557. u64 rx_bad_lt64;
  558. u64 rx_bad_64_to_15xx;
  559. u64 rx_bad_15xx_to_jumbo;
  560. u64 rx_bad_gtjumbo;
  561. u64 rx_overflow;
  562. u64 rx_missed;
  563. u64 rx_false_carrier;
  564. u64 rx_symbol_error;
  565. u64 rx_align_error;
  566. u64 rx_length_error;
  567. u64 rx_internal_error;
  568. u64 rx_good_lt64;
  569. };
  570. /* Number of bits used in a multicast filter hash address */
  571. #define EFX_MCAST_HASH_BITS 8
  572. /* Number of (single-bit) entries in a multicast filter hash */
  573. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  574. /* An Efx multicast filter hash */
  575. union efx_multicast_hash {
  576. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  577. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  578. };
  579. struct efx_filter_state;
  580. struct efx_vf;
  581. struct vfdi_status;
  582. /**
  583. * struct efx_nic - an Efx NIC
  584. * @name: Device name (net device name or bus id before net device registered)
  585. * @pci_dev: The PCI device
  586. * @type: Controller type attributes
  587. * @legacy_irq: IRQ number
  588. * @legacy_irq_enabled: Are IRQs enabled on NIC (INT_EN_KER register)?
  589. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  590. * Work items do not hold and must not acquire RTNL.
  591. * @workqueue_name: Name of workqueue
  592. * @reset_work: Scheduled reset workitem
  593. * @membase_phys: Memory BAR value as physical address
  594. * @membase: Memory BAR value
  595. * @interrupt_mode: Interrupt mode
  596. * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
  597. * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  598. * @irq_rx_moderation: IRQ moderation time for RX event queues
  599. * @msg_enable: Log message enable flags
  600. * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
  601. * @reset_pending: Bitmask for pending resets
  602. * @tx_queue: TX DMA queues
  603. * @rx_queue: RX DMA queues
  604. * @channel: Channels
  605. * @channel_name: Names for channels and their IRQs
  606. * @extra_channel_types: Types of extra (non-traffic) channels that
  607. * should be allocated for this NIC
  608. * @rxq_entries: Size of receive queues requested by user.
  609. * @txq_entries: Size of transmit queues requested by user.
  610. * @txq_stop_thresh: TX queue fill level at or above which we stop it.
  611. * @txq_wake_thresh: TX queue fill level at or below which we wake it.
  612. * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
  613. * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
  614. * @sram_lim_qw: Qword address limit of SRAM
  615. * @next_buffer_table: First available buffer table id
  616. * @n_channels: Number of channels in use
  617. * @n_rx_channels: Number of channels used for RX (= number of RX queues)
  618. * @n_tx_channels: Number of channels used for TX
  619. * @rx_dma_len: Current maximum RX DMA length
  620. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  621. * @rx_hash_key: Toeplitz hash key for RSS
  622. * @rx_indir_table: Indirection table for RSS
  623. * @int_error_count: Number of internal errors seen recently
  624. * @int_error_expire: Time at which error count will be expired
  625. * @irq_status: Interrupt status buffer
  626. * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
  627. * @irq_level: IRQ level/index for IRQs not triggered by an event queue
  628. * @selftest_work: Work item for asynchronous self-test
  629. * @mtd_list: List of MTDs attached to the NIC
  630. * @nic_data: Hardware dependent state
  631. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  632. * efx_monitor() and efx_reconfigure_port()
  633. * @port_enabled: Port enabled indicator.
  634. * Serialises efx_stop_all(), efx_start_all(), efx_monitor() and
  635. * efx_mac_work() with kernel interfaces. Safe to read under any
  636. * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
  637. * be held to modify it.
  638. * @port_initialized: Port initialized?
  639. * @net_dev: Operating system network device. Consider holding the rtnl lock
  640. * @stats_buffer: DMA buffer for statistics
  641. * @phy_type: PHY type
  642. * @phy_op: PHY interface
  643. * @phy_data: PHY private data (including PHY-specific stats)
  644. * @mdio: PHY MDIO interface
  645. * @mdio_bus: PHY MDIO bus ID (only used by Siena)
  646. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  647. * @link_advertising: Autonegotiation advertising flags
  648. * @link_state: Current state of the link
  649. * @n_link_state_changes: Number of times the link has changed state
  650. * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
  651. * @multicast_hash: Multicast hash table
  652. * @wanted_fc: Wanted flow control flags
  653. * @fc_disable: When non-zero flow control is disabled. Typically used to
  654. * ensure that network back pressure doesn't delay dma queue flushes.
  655. * Serialised by the rtnl lock.
  656. * @mac_work: Work item for changing MAC promiscuity and multicast hash
  657. * @loopback_mode: Loopback status
  658. * @loopback_modes: Supported loopback mode bitmask
  659. * @loopback_selftest: Offline self-test private state
  660. * @drain_pending: Count of RX and TX queues that haven't been flushed and drained.
  661. * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
  662. * Decremented when the efx_flush_rx_queue() is called.
  663. * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
  664. * completed (either success or failure). Not used when MCDI is used to
  665. * flush receive queues.
  666. * @flush_wq: wait queue used by efx_nic_flush_queues() to wait for flush completions.
  667. * @vf: Array of &struct efx_vf objects.
  668. * @vf_count: Number of VFs intended to be enabled.
  669. * @vf_init_count: Number of VFs that have been fully initialised.
  670. * @vi_scale: log2 number of vnics per VF.
  671. * @vf_buftbl_base: The zeroth buffer table index used to back VF queues.
  672. * @vfdi_status: Common VFDI status page to be dmad to VF address space.
  673. * @local_addr_list: List of local addresses. Protected by %local_lock.
  674. * @local_page_list: List of DMA addressable pages used to broadcast
  675. * %local_addr_list. Protected by %local_lock.
  676. * @local_lock: Mutex protecting %local_addr_list and %local_page_list.
  677. * @peer_work: Work item to broadcast peer addresses to VMs.
  678. * @ptp_data: PTP state data
  679. * @monitor_work: Hardware monitor workitem
  680. * @biu_lock: BIU (bus interface unit) lock
  681. * @last_irq_cpu: Last CPU to handle a possible test interrupt. This
  682. * field is used by efx_test_interrupts() to verify that an
  683. * interrupt has occurred.
  684. * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
  685. * @mac_stats: MAC statistics. These include all statistics the MACs
  686. * can provide. Generic code converts these into a standard
  687. * &struct net_device_stats.
  688. * @stats_lock: Statistics update lock. Serialises statistics fetches
  689. * and access to @mac_stats.
  690. *
  691. * This is stored in the private area of the &struct net_device.
  692. */
  693. struct efx_nic {
  694. /* The following fields should be written very rarely */
  695. char name[IFNAMSIZ];
  696. struct pci_dev *pci_dev;
  697. const struct efx_nic_type *type;
  698. int legacy_irq;
  699. bool legacy_irq_enabled;
  700. struct workqueue_struct *workqueue;
  701. char workqueue_name[16];
  702. struct work_struct reset_work;
  703. resource_size_t membase_phys;
  704. void __iomem *membase;
  705. enum efx_int_mode interrupt_mode;
  706. unsigned int timer_quantum_ns;
  707. bool irq_rx_adaptive;
  708. unsigned int irq_rx_moderation;
  709. u32 msg_enable;
  710. enum nic_state state;
  711. unsigned long reset_pending;
  712. struct efx_channel *channel[EFX_MAX_CHANNELS];
  713. char channel_name[EFX_MAX_CHANNELS][IFNAMSIZ + 6];
  714. const struct efx_channel_type *
  715. extra_channel_type[EFX_MAX_EXTRA_CHANNELS];
  716. unsigned rxq_entries;
  717. unsigned txq_entries;
  718. unsigned int txq_stop_thresh;
  719. unsigned int txq_wake_thresh;
  720. unsigned tx_dc_base;
  721. unsigned rx_dc_base;
  722. unsigned sram_lim_qw;
  723. unsigned next_buffer_table;
  724. unsigned n_channels;
  725. unsigned n_rx_channels;
  726. unsigned rss_spread;
  727. unsigned tx_channel_offset;
  728. unsigned n_tx_channels;
  729. unsigned int rx_dma_len;
  730. unsigned int rx_buffer_order;
  731. u8 rx_hash_key[40];
  732. u32 rx_indir_table[128];
  733. unsigned int_error_count;
  734. unsigned long int_error_expire;
  735. struct efx_buffer irq_status;
  736. unsigned irq_zero_count;
  737. unsigned irq_level;
  738. struct delayed_work selftest_work;
  739. #ifdef CONFIG_SFC_MTD
  740. struct list_head mtd_list;
  741. #endif
  742. void *nic_data;
  743. struct mutex mac_lock;
  744. struct work_struct mac_work;
  745. bool port_enabled;
  746. bool port_initialized;
  747. struct net_device *net_dev;
  748. struct efx_buffer stats_buffer;
  749. unsigned int phy_type;
  750. const struct efx_phy_operations *phy_op;
  751. void *phy_data;
  752. struct mdio_if_info mdio;
  753. unsigned int mdio_bus;
  754. enum efx_phy_mode phy_mode;
  755. u32 link_advertising;
  756. struct efx_link_state link_state;
  757. unsigned int n_link_state_changes;
  758. bool promiscuous;
  759. union efx_multicast_hash multicast_hash;
  760. u8 wanted_fc;
  761. unsigned fc_disable;
  762. atomic_t rx_reset;
  763. enum efx_loopback_mode loopback_mode;
  764. u64 loopback_modes;
  765. void *loopback_selftest;
  766. struct efx_filter_state *filter_state;
  767. atomic_t drain_pending;
  768. atomic_t rxq_flush_pending;
  769. atomic_t rxq_flush_outstanding;
  770. wait_queue_head_t flush_wq;
  771. #ifdef CONFIG_SFC_SRIOV
  772. struct efx_channel *vfdi_channel;
  773. struct efx_vf *vf;
  774. unsigned vf_count;
  775. unsigned vf_init_count;
  776. unsigned vi_scale;
  777. unsigned vf_buftbl_base;
  778. struct efx_buffer vfdi_status;
  779. struct list_head local_addr_list;
  780. struct list_head local_page_list;
  781. struct mutex local_lock;
  782. struct work_struct peer_work;
  783. #endif
  784. struct efx_ptp_data *ptp_data;
  785. /* The following fields may be written more often */
  786. struct delayed_work monitor_work ____cacheline_aligned_in_smp;
  787. spinlock_t biu_lock;
  788. int last_irq_cpu;
  789. unsigned n_rx_nodesc_drop_cnt;
  790. struct efx_mac_stats mac_stats;
  791. spinlock_t stats_lock;
  792. };
  793. static inline int efx_dev_registered(struct efx_nic *efx)
  794. {
  795. return efx->net_dev->reg_state == NETREG_REGISTERED;
  796. }
  797. static inline unsigned int efx_port_num(struct efx_nic *efx)
  798. {
  799. return efx->net_dev->dev_id;
  800. }
  801. /**
  802. * struct efx_nic_type - Efx device type definition
  803. * @probe: Probe the controller
  804. * @remove: Free resources allocated by probe()
  805. * @init: Initialise the controller
  806. * @dimension_resources: Dimension controller resources (buffer table,
  807. * and VIs once the available interrupt resources are clear)
  808. * @fini: Shut down the controller
  809. * @monitor: Periodic function for polling link state and hardware monitor
  810. * @map_reset_reason: Map ethtool reset reason to a reset method
  811. * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
  812. * @reset: Reset the controller hardware and possibly the PHY. This will
  813. * be called while the controller is uninitialised.
  814. * @probe_port: Probe the MAC and PHY
  815. * @remove_port: Free resources allocated by probe_port()
  816. * @handle_global_event: Handle a "global" event (may be %NULL)
  817. * @prepare_flush: Prepare the hardware for flushing the DMA queues
  818. * @finish_flush: Clean up after flushing the DMA queues
  819. * @update_stats: Update statistics not provided by event handling
  820. * @start_stats: Start the regular fetching of statistics
  821. * @stop_stats: Stop the regular fetching of statistics
  822. * @set_id_led: Set state of identifying LED or revert to automatic function
  823. * @push_irq_moderation: Apply interrupt moderation value
  824. * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
  825. * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
  826. * to the hardware. Serialised by the mac_lock.
  827. * @check_mac_fault: Check MAC fault state. True if fault present.
  828. * @get_wol: Get WoL configuration from driver state
  829. * @set_wol: Push WoL configuration to the NIC
  830. * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
  831. * @test_chip: Test registers. Should use efx_nic_test_registers(), and is
  832. * expected to reset the NIC.
  833. * @test_nvram: Test validity of NVRAM contents
  834. * @revision: Hardware architecture revision
  835. * @mem_map_size: Memory BAR mapped size
  836. * @txd_ptr_tbl_base: TX descriptor ring base address
  837. * @rxd_ptr_tbl_base: RX descriptor ring base address
  838. * @buf_tbl_base: Buffer table base address
  839. * @evq_ptr_tbl_base: Event queue pointer table base address
  840. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  841. * @max_dma_mask: Maximum possible DMA mask
  842. * @rx_buffer_hash_size: Size of hash at start of RX buffer
  843. * @rx_buffer_padding: Size of padding at end of RX buffer
  844. * @max_interrupt_mode: Highest capability interrupt mode supported
  845. * from &enum efx_init_mode.
  846. * @phys_addr_channels: Number of channels with physically addressed
  847. * descriptors
  848. * @timer_period_max: Maximum period of interrupt timer (in ticks)
  849. * @offload_features: net_device feature flags for protocol offload
  850. * features implemented in hardware
  851. */
  852. struct efx_nic_type {
  853. int (*probe)(struct efx_nic *efx);
  854. void (*remove)(struct efx_nic *efx);
  855. int (*init)(struct efx_nic *efx);
  856. void (*dimension_resources)(struct efx_nic *efx);
  857. void (*fini)(struct efx_nic *efx);
  858. void (*monitor)(struct efx_nic *efx);
  859. enum reset_type (*map_reset_reason)(enum reset_type reason);
  860. int (*map_reset_flags)(u32 *flags);
  861. int (*reset)(struct efx_nic *efx, enum reset_type method);
  862. int (*probe_port)(struct efx_nic *efx);
  863. void (*remove_port)(struct efx_nic *efx);
  864. bool (*handle_global_event)(struct efx_channel *channel, efx_qword_t *);
  865. void (*prepare_flush)(struct efx_nic *efx);
  866. void (*finish_flush)(struct efx_nic *efx);
  867. void (*update_stats)(struct efx_nic *efx);
  868. void (*start_stats)(struct efx_nic *efx);
  869. void (*stop_stats)(struct efx_nic *efx);
  870. void (*set_id_led)(struct efx_nic *efx, enum efx_led_mode mode);
  871. void (*push_irq_moderation)(struct efx_channel *channel);
  872. int (*reconfigure_port)(struct efx_nic *efx);
  873. int (*reconfigure_mac)(struct efx_nic *efx);
  874. bool (*check_mac_fault)(struct efx_nic *efx);
  875. void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
  876. int (*set_wol)(struct efx_nic *efx, u32 type);
  877. void (*resume_wol)(struct efx_nic *efx);
  878. int (*test_chip)(struct efx_nic *efx, struct efx_self_tests *tests);
  879. int (*test_nvram)(struct efx_nic *efx);
  880. int revision;
  881. unsigned int mem_map_size;
  882. unsigned int txd_ptr_tbl_base;
  883. unsigned int rxd_ptr_tbl_base;
  884. unsigned int buf_tbl_base;
  885. unsigned int evq_ptr_tbl_base;
  886. unsigned int evq_rptr_tbl_base;
  887. u64 max_dma_mask;
  888. unsigned int rx_buffer_hash_size;
  889. unsigned int rx_buffer_padding;
  890. unsigned int max_interrupt_mode;
  891. unsigned int phys_addr_channels;
  892. unsigned int timer_period_max;
  893. netdev_features_t offload_features;
  894. };
  895. /**************************************************************************
  896. *
  897. * Prototypes and inline functions
  898. *
  899. *************************************************************************/
  900. static inline struct efx_channel *
  901. efx_get_channel(struct efx_nic *efx, unsigned index)
  902. {
  903. EFX_BUG_ON_PARANOID(index >= efx->n_channels);
  904. return efx->channel[index];
  905. }
  906. /* Iterate over all used channels */
  907. #define efx_for_each_channel(_channel, _efx) \
  908. for (_channel = (_efx)->channel[0]; \
  909. _channel; \
  910. _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
  911. (_efx)->channel[_channel->channel + 1] : NULL)
  912. /* Iterate over all used channels in reverse */
  913. #define efx_for_each_channel_rev(_channel, _efx) \
  914. for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \
  915. _channel; \
  916. _channel = _channel->channel ? \
  917. (_efx)->channel[_channel->channel - 1] : NULL)
  918. static inline struct efx_tx_queue *
  919. efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)
  920. {
  921. EFX_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
  922. type >= EFX_TXQ_TYPES);
  923. return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
  924. }
  925. static inline bool efx_channel_has_tx_queues(struct efx_channel *channel)
  926. {
  927. return channel->channel - channel->efx->tx_channel_offset <
  928. channel->efx->n_tx_channels;
  929. }
  930. static inline struct efx_tx_queue *
  931. efx_channel_get_tx_queue(struct efx_channel *channel, unsigned type)
  932. {
  933. EFX_BUG_ON_PARANOID(!efx_channel_has_tx_queues(channel) ||
  934. type >= EFX_TXQ_TYPES);
  935. return &channel->tx_queue[type];
  936. }
  937. static inline bool efx_tx_queue_used(struct efx_tx_queue *tx_queue)
  938. {
  939. return !(tx_queue->efx->net_dev->num_tc < 2 &&
  940. tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI);
  941. }
  942. /* Iterate over all TX queues belonging to a channel */
  943. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  944. if (!efx_channel_has_tx_queues(_channel)) \
  945. ; \
  946. else \
  947. for (_tx_queue = (_channel)->tx_queue; \
  948. _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES && \
  949. efx_tx_queue_used(_tx_queue); \
  950. _tx_queue++)
  951. /* Iterate over all possible TX queues belonging to a channel */
  952. #define efx_for_each_possible_channel_tx_queue(_tx_queue, _channel) \
  953. if (!efx_channel_has_tx_queues(_channel)) \
  954. ; \
  955. else \
  956. for (_tx_queue = (_channel)->tx_queue; \
  957. _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES; \
  958. _tx_queue++)
  959. static inline bool efx_channel_has_rx_queue(struct efx_channel *channel)
  960. {
  961. return channel->rx_queue.core_index >= 0;
  962. }
  963. static inline struct efx_rx_queue *
  964. efx_channel_get_rx_queue(struct efx_channel *channel)
  965. {
  966. EFX_BUG_ON_PARANOID(!efx_channel_has_rx_queue(channel));
  967. return &channel->rx_queue;
  968. }
  969. /* Iterate over all RX queues belonging to a channel */
  970. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  971. if (!efx_channel_has_rx_queue(_channel)) \
  972. ; \
  973. else \
  974. for (_rx_queue = &(_channel)->rx_queue; \
  975. _rx_queue; \
  976. _rx_queue = NULL)
  977. static inline struct efx_channel *
  978. efx_rx_queue_channel(struct efx_rx_queue *rx_queue)
  979. {
  980. return container_of(rx_queue, struct efx_channel, rx_queue);
  981. }
  982. static inline int efx_rx_queue_index(struct efx_rx_queue *rx_queue)
  983. {
  984. return efx_rx_queue_channel(rx_queue)->channel;
  985. }
  986. /* Returns a pointer to the specified receive buffer in the RX
  987. * descriptor queue.
  988. */
  989. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  990. unsigned int index)
  991. {
  992. return &rx_queue->buffer[index];
  993. }
  994. /**
  995. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  996. *
  997. * This calculates the maximum frame length that will be used for a
  998. * given MTU. The frame length will be equal to the MTU plus a
  999. * constant amount of header space and padding. This is the quantity
  1000. * that the net driver will program into the MAC as the maximum frame
  1001. * length.
  1002. *
  1003. * The 10G MAC requires 8-byte alignment on the frame
  1004. * length, so we round up to the nearest 8.
  1005. *
  1006. * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
  1007. * XGMII cycle). If the frame length reaches the maximum value in the
  1008. * same cycle, the XMAC can miss the IPG altogether. We work around
  1009. * this by adding a further 16 bytes.
  1010. */
  1011. #define EFX_MAX_FRAME_LEN(mtu) \
  1012. ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */ + 7) & ~7) + 16)
  1013. static inline bool efx_xmit_with_hwtstamp(struct sk_buff *skb)
  1014. {
  1015. return skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP;
  1016. }
  1017. static inline void efx_xmit_hwtstamp_pending(struct sk_buff *skb)
  1018. {
  1019. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  1020. }
  1021. #endif /* EFX_NET_DRIVER_H */