net_driver.h 37 KB

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