net_driver.h 40 KB

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