net_driver.h 40 KB

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