net_driver.h 54 KB

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