net_driver.h 36 KB

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