net_driver.h 37 KB

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