net_driver.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2013 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 EF4_NET_DRIVER_H
  12. #define EF4_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/rwsem.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/i2c.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <net/busy_poll.h>
  30. #include "enum.h"
  31. #include "bitfield.h"
  32. #include "filter.h"
  33. /**************************************************************************
  34. *
  35. * Build definitions
  36. *
  37. **************************************************************************/
  38. #define EF4_DRIVER_VERSION "4.1"
  39. #ifdef DEBUG
  40. #define EF4_BUG_ON_PARANOID(x) BUG_ON(x)
  41. #define EF4_WARN_ON_PARANOID(x) WARN_ON(x)
  42. #else
  43. #define EF4_BUG_ON_PARANOID(x) do {} while (0)
  44. #define EF4_WARN_ON_PARANOID(x) do {} while (0)
  45. #endif
  46. /**************************************************************************
  47. *
  48. * Efx data structures
  49. *
  50. **************************************************************************/
  51. #define EF4_MAX_CHANNELS 32U
  52. #define EF4_MAX_RX_QUEUES EF4_MAX_CHANNELS
  53. #define EF4_EXTRA_CHANNEL_IOV 0
  54. #define EF4_EXTRA_CHANNEL_PTP 1
  55. #define EF4_MAX_EXTRA_CHANNELS 2U
  56. /* Checksum generation is a per-queue option in hardware, so each
  57. * queue visible to the networking core is backed by two hardware TX
  58. * queues. */
  59. #define EF4_MAX_TX_TC 2
  60. #define EF4_MAX_CORE_TX_QUEUES (EF4_MAX_TX_TC * EF4_MAX_CHANNELS)
  61. #define EF4_TXQ_TYPE_OFFLOAD 1 /* flag */
  62. #define EF4_TXQ_TYPE_HIGHPRI 2 /* flag */
  63. #define EF4_TXQ_TYPES 4
  64. #define EF4_MAX_TX_QUEUES (EF4_TXQ_TYPES * EF4_MAX_CHANNELS)
  65. /* Maximum possible MTU the driver supports */
  66. #define EF4_MAX_MTU (9 * 1024)
  67. /* Minimum MTU, from RFC791 (IP) */
  68. #define EF4_MIN_MTU 68
  69. /* Size of an RX scatter buffer. Small enough to pack 2 into a 4K page,
  70. * and should be a multiple of the cache line size.
  71. */
  72. #define EF4_RX_USR_BUF_SIZE (2048 - 256)
  73. /* If possible, we should ensure cache line alignment at start and end
  74. * of every buffer. Otherwise, we just need to ensure 4-byte
  75. * alignment of the network header.
  76. */
  77. #if NET_IP_ALIGN == 0
  78. #define EF4_RX_BUF_ALIGNMENT L1_CACHE_BYTES
  79. #else
  80. #define EF4_RX_BUF_ALIGNMENT 4
  81. #endif
  82. struct ef4_self_tests;
  83. /**
  84. * struct ef4_buffer - A general-purpose DMA buffer
  85. * @addr: host base address of the buffer
  86. * @dma_addr: DMA base address of the buffer
  87. * @len: Buffer length, in bytes
  88. *
  89. * The NIC uses these buffers for its interrupt status registers and
  90. * MAC stats dumps.
  91. */
  92. struct ef4_buffer {
  93. void *addr;
  94. dma_addr_t dma_addr;
  95. unsigned int len;
  96. };
  97. /**
  98. * struct ef4_special_buffer - DMA buffer entered into buffer table
  99. * @buf: Standard &struct ef4_buffer
  100. * @index: Buffer index within controller;s buffer table
  101. * @entries: Number of buffer table entries
  102. *
  103. * The NIC has a buffer table that maps buffers of size %EF4_BUF_SIZE.
  104. * Event and descriptor rings are addressed via one or more buffer
  105. * table entries (and so can be physically non-contiguous, although we
  106. * currently do not take advantage of that). On Falcon and Siena we
  107. * have to take care of allocating and initialising the entries
  108. * ourselves. On later hardware this is managed by the firmware and
  109. * @index and @entries are left as 0.
  110. */
  111. struct ef4_special_buffer {
  112. struct ef4_buffer buf;
  113. unsigned int index;
  114. unsigned int entries;
  115. };
  116. /**
  117. * struct ef4_tx_buffer - buffer state for a TX descriptor
  118. * @skb: When @flags & %EF4_TX_BUF_SKB, the associated socket buffer to be
  119. * freed when descriptor completes
  120. * @option: When @flags & %EF4_TX_BUF_OPTION, a NIC-specific option descriptor.
  121. * @dma_addr: DMA address of the fragment.
  122. * @flags: Flags for allocation and DMA mapping type
  123. * @len: Length of this fragment.
  124. * This field is zero when the queue slot is empty.
  125. * @unmap_len: Length of this fragment to unmap
  126. * @dma_offset: Offset of @dma_addr from the address of the backing DMA mapping.
  127. * Only valid if @unmap_len != 0.
  128. */
  129. struct ef4_tx_buffer {
  130. const struct sk_buff *skb;
  131. union {
  132. ef4_qword_t option;
  133. dma_addr_t dma_addr;
  134. };
  135. unsigned short flags;
  136. unsigned short len;
  137. unsigned short unmap_len;
  138. unsigned short dma_offset;
  139. };
  140. #define EF4_TX_BUF_CONT 1 /* not last descriptor of packet */
  141. #define EF4_TX_BUF_SKB 2 /* buffer is last part of skb */
  142. #define EF4_TX_BUF_MAP_SINGLE 8 /* buffer was mapped with dma_map_single() */
  143. #define EF4_TX_BUF_OPTION 0x10 /* empty buffer for option descriptor */
  144. /**
  145. * struct ef4_tx_queue - An Efx TX queue
  146. *
  147. * This is a ring buffer of TX fragments.
  148. * Since the TX completion path always executes on the same
  149. * CPU and the xmit path can operate on different CPUs,
  150. * performance is increased by ensuring that the completion
  151. * path and the xmit path operate on different cache lines.
  152. * This is particularly important if the xmit path is always
  153. * executing on one CPU which is different from the completion
  154. * path. There is also a cache line for members which are
  155. * read but not written on the fast path.
  156. *
  157. * @efx: The associated Efx NIC
  158. * @queue: DMA queue number
  159. * @channel: The associated channel
  160. * @core_txq: The networking core TX queue structure
  161. * @buffer: The software buffer ring
  162. * @cb_page: Array of pages of copy buffers. Carved up according to
  163. * %EF4_TX_CB_ORDER into %EF4_TX_CB_SIZE-sized chunks.
  164. * @txd: The hardware descriptor ring
  165. * @ptr_mask: The size of the ring minus 1.
  166. * @initialised: Has hardware queue been initialised?
  167. * @tx_min_size: Minimum transmit size for this queue. Depends on HW.
  168. * @read_count: Current read pointer.
  169. * This is the number of buffers that have been removed from both rings.
  170. * @old_write_count: The value of @write_count when last checked.
  171. * This is here for performance reasons. The xmit path will
  172. * only get the up-to-date value of @write_count if this
  173. * variable indicates that the queue is empty. This is to
  174. * avoid cache-line ping-pong between the xmit path and the
  175. * completion path.
  176. * @merge_events: Number of TX merged completion events
  177. * @insert_count: Current insert pointer
  178. * This is the number of buffers that have been added to the
  179. * software ring.
  180. * @write_count: Current write pointer
  181. * This is the number of buffers that have been added to the
  182. * hardware ring.
  183. * @old_read_count: The value of read_count when last checked.
  184. * This is here for performance reasons. The xmit path will
  185. * only get the up-to-date value of read_count if this
  186. * variable indicates that the queue is full. This is to
  187. * avoid cache-line ping-pong between the xmit path and the
  188. * completion path.
  189. * @pushes: Number of times the TX push feature has been used
  190. * @xmit_more_available: Are any packets waiting to be pushed to the NIC
  191. * @cb_packets: Number of times the TX copybreak feature has been used
  192. * @empty_read_count: If the completion path has seen the queue as empty
  193. * and the transmission path has not yet checked this, the value of
  194. * @read_count bitwise-added to %EF4_EMPTY_COUNT_VALID; otherwise 0.
  195. */
  196. struct ef4_tx_queue {
  197. /* Members which don't change on the fast path */
  198. struct ef4_nic *efx ____cacheline_aligned_in_smp;
  199. unsigned queue;
  200. struct ef4_channel *channel;
  201. struct netdev_queue *core_txq;
  202. struct ef4_tx_buffer *buffer;
  203. struct ef4_buffer *cb_page;
  204. struct ef4_special_buffer txd;
  205. unsigned int ptr_mask;
  206. bool initialised;
  207. unsigned int tx_min_size;
  208. /* Function pointers used in the fast path. */
  209. int (*handle_tso)(struct ef4_tx_queue*, struct sk_buff*, bool *);
  210. /* Members used mainly on the completion path */
  211. unsigned int read_count ____cacheline_aligned_in_smp;
  212. unsigned int old_write_count;
  213. unsigned int merge_events;
  214. unsigned int bytes_compl;
  215. unsigned int pkts_compl;
  216. /* Members used only on the xmit path */
  217. unsigned int insert_count ____cacheline_aligned_in_smp;
  218. unsigned int write_count;
  219. unsigned int old_read_count;
  220. unsigned int pushes;
  221. bool xmit_more_available;
  222. unsigned int cb_packets;
  223. /* Statistics to supplement MAC stats */
  224. unsigned long tx_packets;
  225. /* Members shared between paths and sometimes updated */
  226. unsigned int empty_read_count ____cacheline_aligned_in_smp;
  227. #define EF4_EMPTY_COUNT_VALID 0x80000000
  228. atomic_t flush_outstanding;
  229. };
  230. #define EF4_TX_CB_ORDER 7
  231. #define EF4_TX_CB_SIZE (1 << EF4_TX_CB_ORDER) - NET_IP_ALIGN
  232. /**
  233. * struct ef4_rx_buffer - An Efx RX data buffer
  234. * @dma_addr: DMA base address of the buffer
  235. * @page: The associated page buffer.
  236. * Will be %NULL if the buffer slot is currently free.
  237. * @page_offset: If pending: offset in @page of DMA base address.
  238. * If completed: offset in @page of Ethernet header.
  239. * @len: If pending: length for DMA descriptor.
  240. * If completed: received length, excluding hash prefix.
  241. * @flags: Flags for buffer and packet state. These are only set on the
  242. * first buffer of a scattered packet.
  243. */
  244. struct ef4_rx_buffer {
  245. dma_addr_t dma_addr;
  246. struct page *page;
  247. u16 page_offset;
  248. u16 len;
  249. u16 flags;
  250. };
  251. #define EF4_RX_BUF_LAST_IN_PAGE 0x0001
  252. #define EF4_RX_PKT_CSUMMED 0x0002
  253. #define EF4_RX_PKT_DISCARD 0x0004
  254. #define EF4_RX_PKT_TCP 0x0040
  255. #define EF4_RX_PKT_PREFIX_LEN 0x0080 /* length is in prefix only */
  256. /**
  257. * struct ef4_rx_page_state - Page-based rx buffer state
  258. *
  259. * Inserted at the start of every page allocated for receive buffers.
  260. * Used to facilitate sharing dma mappings between recycled rx buffers
  261. * and those passed up to the kernel.
  262. *
  263. * @dma_addr: The dma address of this page.
  264. */
  265. struct ef4_rx_page_state {
  266. dma_addr_t dma_addr;
  267. unsigned int __pad[0] ____cacheline_aligned;
  268. };
  269. /**
  270. * struct ef4_rx_queue - An Efx RX queue
  271. * @efx: The associated Efx NIC
  272. * @core_index: Index of network core RX queue. Will be >= 0 iff this
  273. * is associated with a real RX queue.
  274. * @buffer: The software buffer ring
  275. * @rxd: The hardware descriptor ring
  276. * @ptr_mask: The size of the ring minus 1.
  277. * @refill_enabled: Enable refill whenever fill level is low
  278. * @flush_pending: Set when a RX flush is pending. Has the same lifetime as
  279. * @rxq_flush_pending.
  280. * @added_count: Number of buffers added to the receive queue.
  281. * @notified_count: Number of buffers given to NIC (<= @added_count).
  282. * @removed_count: Number of buffers removed from the receive queue.
  283. * @scatter_n: Used by NIC specific receive code.
  284. * @scatter_len: Used by NIC specific receive code.
  285. * @page_ring: The ring to store DMA mapped pages for reuse.
  286. * @page_add: Counter to calculate the write pointer for the recycle ring.
  287. * @page_remove: Counter to calculate the read pointer for the recycle ring.
  288. * @page_recycle_count: The number of pages that have been recycled.
  289. * @page_recycle_failed: The number of pages that couldn't be recycled because
  290. * the kernel still held a reference to them.
  291. * @page_recycle_full: The number of pages that were released because the
  292. * recycle ring was full.
  293. * @page_ptr_mask: The number of pages in the RX recycle ring minus 1.
  294. * @max_fill: RX descriptor maximum fill level (<= ring size)
  295. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  296. * (<= @max_fill)
  297. * @min_fill: RX descriptor minimum non-zero fill level.
  298. * This records the minimum fill level observed when a ring
  299. * refill was triggered.
  300. * @recycle_count: RX buffer recycle counter.
  301. * @slow_fill: Timer used to defer ef4_nic_generate_fill_event().
  302. */
  303. struct ef4_rx_queue {
  304. struct ef4_nic *efx;
  305. int core_index;
  306. struct ef4_rx_buffer *buffer;
  307. struct ef4_special_buffer rxd;
  308. unsigned int ptr_mask;
  309. bool refill_enabled;
  310. bool flush_pending;
  311. unsigned int added_count;
  312. unsigned int notified_count;
  313. unsigned int removed_count;
  314. unsigned int scatter_n;
  315. unsigned int scatter_len;
  316. struct page **page_ring;
  317. unsigned int page_add;
  318. unsigned int page_remove;
  319. unsigned int page_recycle_count;
  320. unsigned int page_recycle_failed;
  321. unsigned int page_recycle_full;
  322. unsigned int page_ptr_mask;
  323. unsigned int max_fill;
  324. unsigned int fast_fill_trigger;
  325. unsigned int min_fill;
  326. unsigned int min_overfill;
  327. unsigned int recycle_count;
  328. struct timer_list slow_fill;
  329. unsigned int slow_fill_count;
  330. /* Statistics to supplement MAC stats */
  331. unsigned long rx_packets;
  332. };
  333. /**
  334. * struct ef4_channel - An Efx channel
  335. *
  336. * A channel comprises an event queue, at least one TX queue, at least
  337. * one RX queue, and an associated tasklet for processing the event
  338. * queue.
  339. *
  340. * @efx: Associated Efx NIC
  341. * @channel: Channel instance number
  342. * @type: Channel type definition
  343. * @eventq_init: Event queue initialised flag
  344. * @enabled: Channel enabled indicator
  345. * @irq: IRQ number (MSI and MSI-X only)
  346. * @irq_moderation_us: IRQ moderation value (in microseconds)
  347. * @napi_dev: Net device used with NAPI
  348. * @napi_str: NAPI control structure
  349. * @state: state for NAPI vs busy polling
  350. * @state_lock: lock protecting @state
  351. * @eventq: Event queue buffer
  352. * @eventq_mask: Event queue pointer mask
  353. * @eventq_read_ptr: Event queue read pointer
  354. * @event_test_cpu: Last CPU to handle interrupt or test event for this channel
  355. * @irq_count: Number of IRQs since last adaptive moderation decision
  356. * @irq_mod_score: IRQ moderation score
  357. * @rps_flow_id: Flow IDs of filters allocated for accelerated RFS,
  358. * indexed by filter ID
  359. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  360. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  361. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  362. * @n_rx_mcast_mismatch: Count of unmatched multicast frames
  363. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  364. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  365. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  366. * @n_rx_nodesc_trunc: Number of RX packets truncated and then dropped due to
  367. * lack of descriptors
  368. * @n_rx_merge_events: Number of RX merged completion events
  369. * @n_rx_merge_packets: Number of RX packets completed by merged events
  370. * @rx_pkt_n_frags: Number of fragments in next packet to be delivered by
  371. * __ef4_rx_packet(), or zero if there is none
  372. * @rx_pkt_index: Ring index of first buffer for next packet to be delivered
  373. * by __ef4_rx_packet(), if @rx_pkt_n_frags != 0
  374. * @rx_queue: RX queue for this channel
  375. * @tx_queue: TX queues for this channel
  376. */
  377. struct ef4_channel {
  378. struct ef4_nic *efx;
  379. int channel;
  380. const struct ef4_channel_type *type;
  381. bool eventq_init;
  382. bool enabled;
  383. int irq;
  384. unsigned int irq_moderation_us;
  385. struct net_device *napi_dev;
  386. struct napi_struct napi_str;
  387. #ifdef CONFIG_NET_RX_BUSY_POLL
  388. unsigned long busy_poll_state;
  389. #endif
  390. struct ef4_special_buffer eventq;
  391. unsigned int eventq_mask;
  392. unsigned int eventq_read_ptr;
  393. int event_test_cpu;
  394. unsigned int irq_count;
  395. unsigned int irq_mod_score;
  396. #ifdef CONFIG_RFS_ACCEL
  397. unsigned int rfs_filters_added;
  398. #define RPS_FLOW_ID_INVALID 0xFFFFFFFF
  399. u32 *rps_flow_id;
  400. #endif
  401. unsigned n_rx_tobe_disc;
  402. unsigned n_rx_ip_hdr_chksum_err;
  403. unsigned n_rx_tcp_udp_chksum_err;
  404. unsigned n_rx_mcast_mismatch;
  405. unsigned n_rx_frm_trunc;
  406. unsigned n_rx_overlength;
  407. unsigned n_skbuff_leaks;
  408. unsigned int n_rx_nodesc_trunc;
  409. unsigned int n_rx_merge_events;
  410. unsigned int n_rx_merge_packets;
  411. unsigned int rx_pkt_n_frags;
  412. unsigned int rx_pkt_index;
  413. struct ef4_rx_queue rx_queue;
  414. struct ef4_tx_queue tx_queue[EF4_TXQ_TYPES];
  415. };
  416. /**
  417. * struct ef4_msi_context - Context for each MSI
  418. * @efx: The associated NIC
  419. * @index: Index of the channel/IRQ
  420. * @name: Name of the channel/IRQ
  421. *
  422. * Unlike &struct ef4_channel, this is never reallocated and is always
  423. * safe for the IRQ handler to access.
  424. */
  425. struct ef4_msi_context {
  426. struct ef4_nic *efx;
  427. unsigned int index;
  428. char name[IFNAMSIZ + 6];
  429. };
  430. /**
  431. * struct ef4_channel_type - distinguishes traffic and extra channels
  432. * @handle_no_channel: Handle failure to allocate an extra channel
  433. * @pre_probe: Set up extra state prior to initialisation
  434. * @post_remove: Tear down extra state after finalisation, if allocated.
  435. * May be called on channels that have not been probed.
  436. * @get_name: Generate the channel's name (used for its IRQ handler)
  437. * @copy: Copy the channel state prior to reallocation. May be %NULL if
  438. * reallocation is not supported.
  439. * @receive_skb: Handle an skb ready to be passed to netif_receive_skb()
  440. * @keep_eventq: Flag for whether event queue should be kept initialised
  441. * while the device is stopped
  442. */
  443. struct ef4_channel_type {
  444. void (*handle_no_channel)(struct ef4_nic *);
  445. int (*pre_probe)(struct ef4_channel *);
  446. void (*post_remove)(struct ef4_channel *);
  447. void (*get_name)(struct ef4_channel *, char *buf, size_t len);
  448. struct ef4_channel *(*copy)(const struct ef4_channel *);
  449. bool (*receive_skb)(struct ef4_channel *, struct sk_buff *);
  450. bool keep_eventq;
  451. };
  452. enum ef4_led_mode {
  453. EF4_LED_OFF = 0,
  454. EF4_LED_ON = 1,
  455. EF4_LED_DEFAULT = 2
  456. };
  457. #define STRING_TABLE_LOOKUP(val, member) \
  458. ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
  459. extern const char *const ef4_loopback_mode_names[];
  460. extern const unsigned int ef4_loopback_mode_max;
  461. #define LOOPBACK_MODE(efx) \
  462. STRING_TABLE_LOOKUP((efx)->loopback_mode, ef4_loopback_mode)
  463. extern const char *const ef4_reset_type_names[];
  464. extern const unsigned int ef4_reset_type_max;
  465. #define RESET_TYPE(type) \
  466. STRING_TABLE_LOOKUP(type, ef4_reset_type)
  467. enum ef4_int_mode {
  468. /* Be careful if altering to correct macro below */
  469. EF4_INT_MODE_MSIX = 0,
  470. EF4_INT_MODE_MSI = 1,
  471. EF4_INT_MODE_LEGACY = 2,
  472. EF4_INT_MODE_MAX /* Insert any new items before this */
  473. };
  474. #define EF4_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EF4_INT_MODE_MSI)
  475. enum nic_state {
  476. STATE_UNINIT = 0, /* device being probed/removed or is frozen */
  477. STATE_READY = 1, /* hardware ready and netdev registered */
  478. STATE_DISABLED = 2, /* device disabled due to hardware errors */
  479. STATE_RECOVERY = 3, /* device recovering from PCI error */
  480. };
  481. /* Forward declaration */
  482. struct ef4_nic;
  483. /* Pseudo bit-mask flow control field */
  484. #define EF4_FC_RX FLOW_CTRL_RX
  485. #define EF4_FC_TX FLOW_CTRL_TX
  486. #define EF4_FC_AUTO 4
  487. /**
  488. * struct ef4_link_state - Current state of the link
  489. * @up: Link is up
  490. * @fd: Link is full-duplex
  491. * @fc: Actual flow control flags
  492. * @speed: Link speed (Mbps)
  493. */
  494. struct ef4_link_state {
  495. bool up;
  496. bool fd;
  497. u8 fc;
  498. unsigned int speed;
  499. };
  500. static inline bool ef4_link_state_equal(const struct ef4_link_state *left,
  501. const struct ef4_link_state *right)
  502. {
  503. return left->up == right->up && left->fd == right->fd &&
  504. left->fc == right->fc && left->speed == right->speed;
  505. }
  506. /**
  507. * struct ef4_phy_operations - Efx PHY operations table
  508. * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
  509. * efx->loopback_modes.
  510. * @init: Initialise PHY
  511. * @fini: Shut down PHY
  512. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  513. * @poll: Update @link_state and report whether it changed.
  514. * Serialised by the mac_lock.
  515. * @get_link_ksettings: Get ethtool settings. Serialised by the mac_lock.
  516. * @set_link_ksettings: Set ethtool settings. Serialised by the mac_lock.
  517. * @set_npage_adv: Set abilities advertised in (Extended) Next Page
  518. * (only needed where AN bit is set in mmds)
  519. * @test_alive: Test that PHY is 'alive' (online)
  520. * @test_name: Get the name of a PHY-specific test/result
  521. * @run_tests: Run tests and record results as appropriate (offline).
  522. * Flags are the ethtool tests flags.
  523. */
  524. struct ef4_phy_operations {
  525. int (*probe) (struct ef4_nic *efx);
  526. int (*init) (struct ef4_nic *efx);
  527. void (*fini) (struct ef4_nic *efx);
  528. void (*remove) (struct ef4_nic *efx);
  529. int (*reconfigure) (struct ef4_nic *efx);
  530. bool (*poll) (struct ef4_nic *efx);
  531. void (*get_link_ksettings)(struct ef4_nic *efx,
  532. struct ethtool_link_ksettings *cmd);
  533. int (*set_link_ksettings)(struct ef4_nic *efx,
  534. const struct ethtool_link_ksettings *cmd);
  535. void (*set_npage_adv) (struct ef4_nic *efx, u32);
  536. int (*test_alive) (struct ef4_nic *efx);
  537. const char *(*test_name) (struct ef4_nic *efx, unsigned int index);
  538. int (*run_tests) (struct ef4_nic *efx, int *results, unsigned flags);
  539. int (*get_module_eeprom) (struct ef4_nic *efx,
  540. struct ethtool_eeprom *ee,
  541. u8 *data);
  542. int (*get_module_info) (struct ef4_nic *efx,
  543. struct ethtool_modinfo *modinfo);
  544. };
  545. /**
  546. * enum ef4_phy_mode - PHY operating mode flags
  547. * @PHY_MODE_NORMAL: on and should pass traffic
  548. * @PHY_MODE_TX_DISABLED: on with TX disabled
  549. * @PHY_MODE_LOW_POWER: set to low power through MDIO
  550. * @PHY_MODE_OFF: switched off through external control
  551. * @PHY_MODE_SPECIAL: on but will not pass traffic
  552. */
  553. enum ef4_phy_mode {
  554. PHY_MODE_NORMAL = 0,
  555. PHY_MODE_TX_DISABLED = 1,
  556. PHY_MODE_LOW_POWER = 2,
  557. PHY_MODE_OFF = 4,
  558. PHY_MODE_SPECIAL = 8,
  559. };
  560. static inline bool ef4_phy_mode_disabled(enum ef4_phy_mode mode)
  561. {
  562. return !!(mode & ~PHY_MODE_TX_DISABLED);
  563. }
  564. /**
  565. * struct ef4_hw_stat_desc - Description of a hardware statistic
  566. * @name: Name of the statistic as visible through ethtool, or %NULL if
  567. * it should not be exposed
  568. * @dma_width: Width in bits (0 for non-DMA statistics)
  569. * @offset: Offset within stats (ignored for non-DMA statistics)
  570. */
  571. struct ef4_hw_stat_desc {
  572. const char *name;
  573. u16 dma_width;
  574. u16 offset;
  575. };
  576. /* Number of bits used in a multicast filter hash address */
  577. #define EF4_MCAST_HASH_BITS 8
  578. /* Number of (single-bit) entries in a multicast filter hash */
  579. #define EF4_MCAST_HASH_ENTRIES (1 << EF4_MCAST_HASH_BITS)
  580. /* An Efx multicast filter hash */
  581. union ef4_multicast_hash {
  582. u8 byte[EF4_MCAST_HASH_ENTRIES / 8];
  583. ef4_oword_t oword[EF4_MCAST_HASH_ENTRIES / sizeof(ef4_oword_t) / 8];
  584. };
  585. /**
  586. * struct ef4_nic - an Efx NIC
  587. * @name: Device name (net device name or bus id before net device registered)
  588. * @pci_dev: The PCI device
  589. * @node: List node for maintaning primary/secondary function lists
  590. * @primary: &struct ef4_nic instance for the primary function of this
  591. * controller. May be the same structure, and may be %NULL if no
  592. * primary function is bound. Serialised by rtnl_lock.
  593. * @secondary_list: List of &struct ef4_nic instances for the secondary PCI
  594. * functions of the controller, if this is for the primary function.
  595. * Serialised by rtnl_lock.
  596. * @type: Controller type attributes
  597. * @legacy_irq: IRQ number
  598. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  599. * Work items do not hold and must not acquire RTNL.
  600. * @workqueue_name: Name of workqueue
  601. * @reset_work: Scheduled reset workitem
  602. * @membase_phys: Memory BAR value as physical address
  603. * @membase: Memory BAR value
  604. * @interrupt_mode: Interrupt mode
  605. * @timer_quantum_ns: Interrupt timer quantum, in nanoseconds
  606. * @timer_max_ns: Interrupt timer maximum value, in nanoseconds
  607. * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  608. * @irq_rx_mod_step_us: Step size for IRQ moderation for RX event queues
  609. * @irq_rx_moderation_us: IRQ moderation time for RX event queues
  610. * @msg_enable: Log message enable flags
  611. * @state: Device state number (%STATE_*). Serialised by the rtnl_lock.
  612. * @reset_pending: Bitmask for pending resets
  613. * @tx_queue: TX DMA queues
  614. * @rx_queue: RX DMA queues
  615. * @channel: Channels
  616. * @msi_context: Context for each MSI
  617. * @extra_channel_types: Types of extra (non-traffic) channels that
  618. * should be allocated for this NIC
  619. * @rxq_entries: Size of receive queues requested by user.
  620. * @txq_entries: Size of transmit queues requested by user.
  621. * @txq_stop_thresh: TX queue fill level at or above which we stop it.
  622. * @txq_wake_thresh: TX queue fill level at or below which we wake it.
  623. * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches
  624. * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches
  625. * @sram_lim_qw: Qword address limit of SRAM
  626. * @next_buffer_table: First available buffer table id
  627. * @n_channels: Number of channels in use
  628. * @n_rx_channels: Number of channels used for RX (= number of RX queues)
  629. * @n_tx_channels: Number of channels used for TX
  630. * @rx_ip_align: RX DMA address offset to have IP header aligned in
  631. * in accordance with NET_IP_ALIGN
  632. * @rx_dma_len: Current maximum RX DMA length
  633. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  634. * @rx_buffer_truesize: Amortised allocation size of an RX buffer,
  635. * for use in sk_buff::truesize
  636. * @rx_prefix_size: Size of RX prefix before packet data
  637. * @rx_packet_hash_offset: Offset of RX flow hash from start of packet data
  638. * (valid only if @rx_prefix_size != 0; always negative)
  639. * @rx_packet_len_offset: Offset of RX packet length from start of packet data
  640. * (valid only for NICs that set %EF4_RX_PKT_PREFIX_LEN; always negative)
  641. * @rx_packet_ts_offset: Offset of timestamp from start of packet data
  642. * (valid only if channel->sync_timestamps_enabled; always negative)
  643. * @rx_hash_key: Toeplitz hash key for RSS
  644. * @rx_indir_table: Indirection table for RSS
  645. * @rx_scatter: Scatter mode enabled for receives
  646. * @int_error_count: Number of internal errors seen recently
  647. * @int_error_expire: Time at which error count will be expired
  648. * @irq_soft_enabled: Are IRQs soft-enabled? If not, IRQ handler will
  649. * acknowledge but do nothing else.
  650. * @irq_status: Interrupt status buffer
  651. * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
  652. * @irq_level: IRQ level/index for IRQs not triggered by an event queue
  653. * @selftest_work: Work item for asynchronous self-test
  654. * @mtd_list: List of MTDs attached to the NIC
  655. * @nic_data: Hardware dependent state
  656. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  657. * ef4_monitor() and ef4_reconfigure_port()
  658. * @port_enabled: Port enabled indicator.
  659. * Serialises ef4_stop_all(), ef4_start_all(), ef4_monitor() and
  660. * ef4_mac_work() with kernel interfaces. Safe to read under any
  661. * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
  662. * be held to modify it.
  663. * @port_initialized: Port initialized?
  664. * @net_dev: Operating system network device. Consider holding the rtnl lock
  665. * @fixed_features: Features which cannot be turned off
  666. * @stats_buffer: DMA buffer for statistics
  667. * @phy_type: PHY type
  668. * @phy_op: PHY interface
  669. * @phy_data: PHY private data (including PHY-specific stats)
  670. * @mdio: PHY MDIO interface
  671. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  672. * @link_advertising: Autonegotiation advertising flags
  673. * @link_state: Current state of the link
  674. * @n_link_state_changes: Number of times the link has changed state
  675. * @unicast_filter: Flag for Falcon-arch simple unicast filter.
  676. * Protected by @mac_lock.
  677. * @multicast_hash: Multicast hash table for Falcon-arch.
  678. * Protected by @mac_lock.
  679. * @wanted_fc: Wanted flow control flags
  680. * @fc_disable: When non-zero flow control is disabled. Typically used to
  681. * ensure that network back pressure doesn't delay dma queue flushes.
  682. * Serialised by the rtnl lock.
  683. * @mac_work: Work item for changing MAC promiscuity and multicast hash
  684. * @loopback_mode: Loopback status
  685. * @loopback_modes: Supported loopback mode bitmask
  686. * @loopback_selftest: Offline self-test private state
  687. * @filter_sem: Filter table rw_semaphore, for freeing the table
  688. * @filter_lock: Filter table lock, for mere content changes
  689. * @filter_state: Architecture-dependent filter table state
  690. * @rps_expire_channel: Next channel to check for expiry
  691. * @rps_expire_index: Next index to check for expiry in
  692. * @rps_expire_channel's @rps_flow_id
  693. * @active_queues: Count of RX and TX queues that haven't been flushed and drained.
  694. * @rxq_flush_pending: Count of number of receive queues that need to be flushed.
  695. * Decremented when the ef4_flush_rx_queue() is called.
  696. * @rxq_flush_outstanding: Count of number of RX flushes started but not yet
  697. * completed (either success or failure). Not used when MCDI is used to
  698. * flush receive queues.
  699. * @flush_wq: wait queue used by ef4_nic_flush_queues() to wait for flush completions.
  700. * @vpd_sn: Serial number read from VPD
  701. * @monitor_work: Hardware monitor workitem
  702. * @biu_lock: BIU (bus interface unit) lock
  703. * @last_irq_cpu: Last CPU to handle a possible test interrupt. This
  704. * field is used by ef4_test_interrupts() to verify that an
  705. * interrupt has occurred.
  706. * @stats_lock: Statistics update lock. Must be held when calling
  707. * ef4_nic_type::{update,start,stop}_stats.
  708. * @n_rx_noskb_drops: Count of RX packets dropped due to failure to allocate an skb
  709. *
  710. * This is stored in the private area of the &struct net_device.
  711. */
  712. struct ef4_nic {
  713. /* The following fields should be written very rarely */
  714. char name[IFNAMSIZ];
  715. struct list_head node;
  716. struct ef4_nic *primary;
  717. struct list_head secondary_list;
  718. struct pci_dev *pci_dev;
  719. unsigned int port_num;
  720. const struct ef4_nic_type *type;
  721. int legacy_irq;
  722. bool eeh_disabled_legacy_irq;
  723. struct workqueue_struct *workqueue;
  724. char workqueue_name[16];
  725. struct work_struct reset_work;
  726. resource_size_t membase_phys;
  727. void __iomem *membase;
  728. enum ef4_int_mode interrupt_mode;
  729. unsigned int timer_quantum_ns;
  730. unsigned int timer_max_ns;
  731. bool irq_rx_adaptive;
  732. unsigned int irq_mod_step_us;
  733. unsigned int irq_rx_moderation_us;
  734. u32 msg_enable;
  735. enum nic_state state;
  736. unsigned long reset_pending;
  737. struct ef4_channel *channel[EF4_MAX_CHANNELS];
  738. struct ef4_msi_context msi_context[EF4_MAX_CHANNELS];
  739. const struct ef4_channel_type *
  740. extra_channel_type[EF4_MAX_EXTRA_CHANNELS];
  741. unsigned rxq_entries;
  742. unsigned txq_entries;
  743. unsigned int txq_stop_thresh;
  744. unsigned int txq_wake_thresh;
  745. unsigned tx_dc_base;
  746. unsigned rx_dc_base;
  747. unsigned sram_lim_qw;
  748. unsigned next_buffer_table;
  749. unsigned int max_channels;
  750. unsigned int max_tx_channels;
  751. unsigned n_channels;
  752. unsigned n_rx_channels;
  753. unsigned rss_spread;
  754. unsigned tx_channel_offset;
  755. unsigned n_tx_channels;
  756. unsigned int rx_ip_align;
  757. unsigned int rx_dma_len;
  758. unsigned int rx_buffer_order;
  759. unsigned int rx_buffer_truesize;
  760. unsigned int rx_page_buf_step;
  761. unsigned int rx_bufs_per_page;
  762. unsigned int rx_pages_per_batch;
  763. unsigned int rx_prefix_size;
  764. int rx_packet_hash_offset;
  765. int rx_packet_len_offset;
  766. int rx_packet_ts_offset;
  767. u8 rx_hash_key[40];
  768. u32 rx_indir_table[128];
  769. bool rx_scatter;
  770. unsigned int_error_count;
  771. unsigned long int_error_expire;
  772. bool irq_soft_enabled;
  773. struct ef4_buffer irq_status;
  774. unsigned irq_zero_count;
  775. unsigned irq_level;
  776. struct delayed_work selftest_work;
  777. #ifdef CONFIG_SFC_FALCON_MTD
  778. struct list_head mtd_list;
  779. #endif
  780. void *nic_data;
  781. struct mutex mac_lock;
  782. struct work_struct mac_work;
  783. bool port_enabled;
  784. bool mc_bist_for_other_fn;
  785. bool port_initialized;
  786. struct net_device *net_dev;
  787. netdev_features_t fixed_features;
  788. struct ef4_buffer stats_buffer;
  789. u64 rx_nodesc_drops_total;
  790. u64 rx_nodesc_drops_while_down;
  791. bool rx_nodesc_drops_prev_state;
  792. unsigned int phy_type;
  793. const struct ef4_phy_operations *phy_op;
  794. void *phy_data;
  795. struct mdio_if_info mdio;
  796. enum ef4_phy_mode phy_mode;
  797. u32 link_advertising;
  798. struct ef4_link_state link_state;
  799. unsigned int n_link_state_changes;
  800. bool unicast_filter;
  801. union ef4_multicast_hash multicast_hash;
  802. u8 wanted_fc;
  803. unsigned fc_disable;
  804. atomic_t rx_reset;
  805. enum ef4_loopback_mode loopback_mode;
  806. u64 loopback_modes;
  807. void *loopback_selftest;
  808. struct rw_semaphore filter_sem;
  809. spinlock_t filter_lock;
  810. void *filter_state;
  811. #ifdef CONFIG_RFS_ACCEL
  812. unsigned int rps_expire_channel;
  813. unsigned int rps_expire_index;
  814. #endif
  815. atomic_t active_queues;
  816. atomic_t rxq_flush_pending;
  817. atomic_t rxq_flush_outstanding;
  818. wait_queue_head_t flush_wq;
  819. char *vpd_sn;
  820. /* The following fields may be written more often */
  821. struct delayed_work monitor_work ____cacheline_aligned_in_smp;
  822. spinlock_t biu_lock;
  823. int last_irq_cpu;
  824. spinlock_t stats_lock;
  825. atomic_t n_rx_noskb_drops;
  826. };
  827. static inline int ef4_dev_registered(struct ef4_nic *efx)
  828. {
  829. return efx->net_dev->reg_state == NETREG_REGISTERED;
  830. }
  831. static inline unsigned int ef4_port_num(struct ef4_nic *efx)
  832. {
  833. return efx->port_num;
  834. }
  835. struct ef4_mtd_partition {
  836. struct list_head node;
  837. struct mtd_info mtd;
  838. const char *dev_type_name;
  839. const char *type_name;
  840. char name[IFNAMSIZ + 20];
  841. };
  842. /**
  843. * struct ef4_nic_type - Efx device type definition
  844. * @mem_bar: Get the memory BAR
  845. * @mem_map_size: Get memory BAR mapped size
  846. * @probe: Probe the controller
  847. * @remove: Free resources allocated by probe()
  848. * @init: Initialise the controller
  849. * @dimension_resources: Dimension controller resources (buffer table,
  850. * and VIs once the available interrupt resources are clear)
  851. * @fini: Shut down the controller
  852. * @monitor: Periodic function for polling link state and hardware monitor
  853. * @map_reset_reason: Map ethtool reset reason to a reset method
  854. * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
  855. * @reset: Reset the controller hardware and possibly the PHY. This will
  856. * be called while the controller is uninitialised.
  857. * @probe_port: Probe the MAC and PHY
  858. * @remove_port: Free resources allocated by probe_port()
  859. * @handle_global_event: Handle a "global" event (may be %NULL)
  860. * @fini_dmaq: Flush and finalise DMA queues (RX and TX queues)
  861. * @prepare_flush: Prepare the hardware for flushing the DMA queues
  862. * (for Falcon architecture)
  863. * @finish_flush: Clean up after flushing the DMA queues (for Falcon
  864. * architecture)
  865. * @prepare_flr: Prepare for an FLR
  866. * @finish_flr: Clean up after an FLR
  867. * @describe_stats: Describe statistics for ethtool
  868. * @update_stats: Update statistics not provided by event handling.
  869. * Either argument may be %NULL.
  870. * @start_stats: Start the regular fetching of statistics
  871. * @pull_stats: Pull stats from the NIC and wait until they arrive.
  872. * @stop_stats: Stop the regular fetching of statistics
  873. * @set_id_led: Set state of identifying LED or revert to automatic function
  874. * @push_irq_moderation: Apply interrupt moderation value
  875. * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
  876. * @prepare_enable_fc_tx: Prepare MAC to enable pause frame TX (may be %NULL)
  877. * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
  878. * to the hardware. Serialised by the mac_lock.
  879. * @check_mac_fault: Check MAC fault state. True if fault present.
  880. * @get_wol: Get WoL configuration from driver state
  881. * @set_wol: Push WoL configuration to the NIC
  882. * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
  883. * @test_chip: Test registers. May use ef4_farch_test_registers(), and is
  884. * expected to reset the NIC.
  885. * @test_nvram: Test validity of NVRAM contents
  886. * @irq_enable_master: Enable IRQs on the NIC. Each event queue must
  887. * be separately enabled after this.
  888. * @irq_test_generate: Generate a test IRQ
  889. * @irq_disable_non_ev: Disable non-event IRQs on the NIC. Each event
  890. * queue must be separately disabled before this.
  891. * @irq_handle_msi: Handle MSI for a channel. The @dev_id argument is
  892. * a pointer to the &struct ef4_msi_context for the channel.
  893. * @irq_handle_legacy: Handle legacy interrupt. The @dev_id argument
  894. * is a pointer to the &struct ef4_nic.
  895. * @tx_probe: Allocate resources for TX queue
  896. * @tx_init: Initialise TX queue on the NIC
  897. * @tx_remove: Free resources for TX queue
  898. * @tx_write: Write TX descriptors and doorbell
  899. * @rx_push_rss_config: Write RSS hash key and indirection table to the NIC
  900. * @rx_probe: Allocate resources for RX queue
  901. * @rx_init: Initialise RX queue on the NIC
  902. * @rx_remove: Free resources for RX queue
  903. * @rx_write: Write RX descriptors and doorbell
  904. * @rx_defer_refill: Generate a refill reminder event
  905. * @ev_probe: Allocate resources for event queue
  906. * @ev_init: Initialise event queue on the NIC
  907. * @ev_fini: Deinitialise event queue on the NIC
  908. * @ev_remove: Free resources for event queue
  909. * @ev_process: Process events for a queue, up to the given NAPI quota
  910. * @ev_read_ack: Acknowledge read events on a queue, rearming its IRQ
  911. * @ev_test_generate: Generate a test event
  912. * @filter_table_probe: Probe filter capabilities and set up filter software state
  913. * @filter_table_restore: Restore filters removed from hardware
  914. * @filter_table_remove: Remove filters from hardware and tear down software state
  915. * @filter_update_rx_scatter: Update filters after change to rx scatter setting
  916. * @filter_insert: add or replace a filter
  917. * @filter_remove_safe: remove a filter by ID, carefully
  918. * @filter_get_safe: retrieve a filter by ID, carefully
  919. * @filter_clear_rx: Remove all RX filters whose priority is less than or
  920. * equal to the given priority and is not %EF4_FILTER_PRI_AUTO
  921. * @filter_count_rx_used: Get the number of filters in use at a given priority
  922. * @filter_get_rx_id_limit: Get maximum value of a filter id, plus 1
  923. * @filter_get_rx_ids: Get list of RX filters at a given priority
  924. * @filter_rfs_insert: Add or replace a filter for RFS. This must be
  925. * atomic. The hardware change may be asynchronous but should
  926. * not be delayed for long. It may fail if this can't be done
  927. * atomically.
  928. * @filter_rfs_expire_one: Consider expiring a filter inserted for RFS.
  929. * This must check whether the specified table entry is used by RFS
  930. * and that rps_may_expire_flow() returns true for it.
  931. * @mtd_probe: Probe and add MTD partitions associated with this net device,
  932. * using ef4_mtd_add()
  933. * @mtd_rename: Set an MTD partition name using the net device name
  934. * @mtd_read: Read from an MTD partition
  935. * @mtd_erase: Erase part of an MTD partition
  936. * @mtd_write: Write to an MTD partition
  937. * @mtd_sync: Wait for write-back to complete on MTD partition. This
  938. * also notifies the driver that a writer has finished using this
  939. * partition.
  940. * @set_mac_address: Set the MAC address of the device
  941. * @revision: Hardware architecture revision
  942. * @txd_ptr_tbl_base: TX descriptor ring base address
  943. * @rxd_ptr_tbl_base: RX descriptor ring base address
  944. * @buf_tbl_base: Buffer table base address
  945. * @evq_ptr_tbl_base: Event queue pointer table base address
  946. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  947. * @max_dma_mask: Maximum possible DMA mask
  948. * @rx_prefix_size: Size of RX prefix before packet data
  949. * @rx_hash_offset: Offset of RX flow hash within prefix
  950. * @rx_ts_offset: Offset of timestamp within prefix
  951. * @rx_buffer_padding: Size of padding at end of RX packet
  952. * @can_rx_scatter: NIC is able to scatter packets to multiple buffers
  953. * @always_rx_scatter: NIC will always scatter packets to multiple buffers
  954. * @max_interrupt_mode: Highest capability interrupt mode supported
  955. * from &enum ef4_init_mode.
  956. * @timer_period_max: Maximum period of interrupt timer (in ticks)
  957. * @offload_features: net_device feature flags for protocol offload
  958. * features implemented in hardware
  959. */
  960. struct ef4_nic_type {
  961. unsigned int mem_bar;
  962. unsigned int (*mem_map_size)(struct ef4_nic *efx);
  963. int (*probe)(struct ef4_nic *efx);
  964. void (*remove)(struct ef4_nic *efx);
  965. int (*init)(struct ef4_nic *efx);
  966. int (*dimension_resources)(struct ef4_nic *efx);
  967. void (*fini)(struct ef4_nic *efx);
  968. void (*monitor)(struct ef4_nic *efx);
  969. enum reset_type (*map_reset_reason)(enum reset_type reason);
  970. int (*map_reset_flags)(u32 *flags);
  971. int (*reset)(struct ef4_nic *efx, enum reset_type method);
  972. int (*probe_port)(struct ef4_nic *efx);
  973. void (*remove_port)(struct ef4_nic *efx);
  974. bool (*handle_global_event)(struct ef4_channel *channel, ef4_qword_t *);
  975. int (*fini_dmaq)(struct ef4_nic *efx);
  976. void (*prepare_flush)(struct ef4_nic *efx);
  977. void (*finish_flush)(struct ef4_nic *efx);
  978. void (*prepare_flr)(struct ef4_nic *efx);
  979. void (*finish_flr)(struct ef4_nic *efx);
  980. size_t (*describe_stats)(struct ef4_nic *efx, u8 *names);
  981. size_t (*update_stats)(struct ef4_nic *efx, u64 *full_stats,
  982. struct rtnl_link_stats64 *core_stats);
  983. void (*start_stats)(struct ef4_nic *efx);
  984. void (*pull_stats)(struct ef4_nic *efx);
  985. void (*stop_stats)(struct ef4_nic *efx);
  986. void (*set_id_led)(struct ef4_nic *efx, enum ef4_led_mode mode);
  987. void (*push_irq_moderation)(struct ef4_channel *channel);
  988. int (*reconfigure_port)(struct ef4_nic *efx);
  989. void (*prepare_enable_fc_tx)(struct ef4_nic *efx);
  990. int (*reconfigure_mac)(struct ef4_nic *efx);
  991. bool (*check_mac_fault)(struct ef4_nic *efx);
  992. void (*get_wol)(struct ef4_nic *efx, struct ethtool_wolinfo *wol);
  993. int (*set_wol)(struct ef4_nic *efx, u32 type);
  994. void (*resume_wol)(struct ef4_nic *efx);
  995. int (*test_chip)(struct ef4_nic *efx, struct ef4_self_tests *tests);
  996. int (*test_nvram)(struct ef4_nic *efx);
  997. void (*irq_enable_master)(struct ef4_nic *efx);
  998. int (*irq_test_generate)(struct ef4_nic *efx);
  999. void (*irq_disable_non_ev)(struct ef4_nic *efx);
  1000. irqreturn_t (*irq_handle_msi)(int irq, void *dev_id);
  1001. irqreturn_t (*irq_handle_legacy)(int irq, void *dev_id);
  1002. int (*tx_probe)(struct ef4_tx_queue *tx_queue);
  1003. void (*tx_init)(struct ef4_tx_queue *tx_queue);
  1004. void (*tx_remove)(struct ef4_tx_queue *tx_queue);
  1005. void (*tx_write)(struct ef4_tx_queue *tx_queue);
  1006. unsigned int (*tx_limit_len)(struct ef4_tx_queue *tx_queue,
  1007. dma_addr_t dma_addr, unsigned int len);
  1008. int (*rx_push_rss_config)(struct ef4_nic *efx, bool user,
  1009. const u32 *rx_indir_table);
  1010. int (*rx_probe)(struct ef4_rx_queue *rx_queue);
  1011. void (*rx_init)(struct ef4_rx_queue *rx_queue);
  1012. void (*rx_remove)(struct ef4_rx_queue *rx_queue);
  1013. void (*rx_write)(struct ef4_rx_queue *rx_queue);
  1014. void (*rx_defer_refill)(struct ef4_rx_queue *rx_queue);
  1015. int (*ev_probe)(struct ef4_channel *channel);
  1016. int (*ev_init)(struct ef4_channel *channel);
  1017. void (*ev_fini)(struct ef4_channel *channel);
  1018. void (*ev_remove)(struct ef4_channel *channel);
  1019. int (*ev_process)(struct ef4_channel *channel, int quota);
  1020. void (*ev_read_ack)(struct ef4_channel *channel);
  1021. void (*ev_test_generate)(struct ef4_channel *channel);
  1022. int (*filter_table_probe)(struct ef4_nic *efx);
  1023. void (*filter_table_restore)(struct ef4_nic *efx);
  1024. void (*filter_table_remove)(struct ef4_nic *efx);
  1025. void (*filter_update_rx_scatter)(struct ef4_nic *efx);
  1026. s32 (*filter_insert)(struct ef4_nic *efx,
  1027. struct ef4_filter_spec *spec, bool replace);
  1028. int (*filter_remove_safe)(struct ef4_nic *efx,
  1029. enum ef4_filter_priority priority,
  1030. u32 filter_id);
  1031. int (*filter_get_safe)(struct ef4_nic *efx,
  1032. enum ef4_filter_priority priority,
  1033. u32 filter_id, struct ef4_filter_spec *);
  1034. int (*filter_clear_rx)(struct ef4_nic *efx,
  1035. enum ef4_filter_priority priority);
  1036. u32 (*filter_count_rx_used)(struct ef4_nic *efx,
  1037. enum ef4_filter_priority priority);
  1038. u32 (*filter_get_rx_id_limit)(struct ef4_nic *efx);
  1039. s32 (*filter_get_rx_ids)(struct ef4_nic *efx,
  1040. enum ef4_filter_priority priority,
  1041. u32 *buf, u32 size);
  1042. #ifdef CONFIG_RFS_ACCEL
  1043. s32 (*filter_rfs_insert)(struct ef4_nic *efx,
  1044. struct ef4_filter_spec *spec);
  1045. bool (*filter_rfs_expire_one)(struct ef4_nic *efx, u32 flow_id,
  1046. unsigned int index);
  1047. #endif
  1048. #ifdef CONFIG_SFC_FALCON_MTD
  1049. int (*mtd_probe)(struct ef4_nic *efx);
  1050. void (*mtd_rename)(struct ef4_mtd_partition *part);
  1051. int (*mtd_read)(struct mtd_info *mtd, loff_t start, size_t len,
  1052. size_t *retlen, u8 *buffer);
  1053. int (*mtd_erase)(struct mtd_info *mtd, loff_t start, size_t len);
  1054. int (*mtd_write)(struct mtd_info *mtd, loff_t start, size_t len,
  1055. size_t *retlen, const u8 *buffer);
  1056. int (*mtd_sync)(struct mtd_info *mtd);
  1057. #endif
  1058. int (*get_mac_address)(struct ef4_nic *efx, unsigned char *perm_addr);
  1059. int (*set_mac_address)(struct ef4_nic *efx);
  1060. int revision;
  1061. unsigned int txd_ptr_tbl_base;
  1062. unsigned int rxd_ptr_tbl_base;
  1063. unsigned int buf_tbl_base;
  1064. unsigned int evq_ptr_tbl_base;
  1065. unsigned int evq_rptr_tbl_base;
  1066. u64 max_dma_mask;
  1067. unsigned int rx_prefix_size;
  1068. unsigned int rx_hash_offset;
  1069. unsigned int rx_ts_offset;
  1070. unsigned int rx_buffer_padding;
  1071. bool can_rx_scatter;
  1072. bool always_rx_scatter;
  1073. unsigned int max_interrupt_mode;
  1074. unsigned int timer_period_max;
  1075. netdev_features_t offload_features;
  1076. unsigned int max_rx_ip_filters;
  1077. };
  1078. /**************************************************************************
  1079. *
  1080. * Prototypes and inline functions
  1081. *
  1082. *************************************************************************/
  1083. static inline struct ef4_channel *
  1084. ef4_get_channel(struct ef4_nic *efx, unsigned index)
  1085. {
  1086. EF4_BUG_ON_PARANOID(index >= efx->n_channels);
  1087. return efx->channel[index];
  1088. }
  1089. /* Iterate over all used channels */
  1090. #define ef4_for_each_channel(_channel, _efx) \
  1091. for (_channel = (_efx)->channel[0]; \
  1092. _channel; \
  1093. _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
  1094. (_efx)->channel[_channel->channel + 1] : NULL)
  1095. /* Iterate over all used channels in reverse */
  1096. #define ef4_for_each_channel_rev(_channel, _efx) \
  1097. for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \
  1098. _channel; \
  1099. _channel = _channel->channel ? \
  1100. (_efx)->channel[_channel->channel - 1] : NULL)
  1101. static inline struct ef4_tx_queue *
  1102. ef4_get_tx_queue(struct ef4_nic *efx, unsigned index, unsigned type)
  1103. {
  1104. EF4_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
  1105. type >= EF4_TXQ_TYPES);
  1106. return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
  1107. }
  1108. static inline bool ef4_channel_has_tx_queues(struct ef4_channel *channel)
  1109. {
  1110. return channel->channel - channel->efx->tx_channel_offset <
  1111. channel->efx->n_tx_channels;
  1112. }
  1113. static inline struct ef4_tx_queue *
  1114. ef4_channel_get_tx_queue(struct ef4_channel *channel, unsigned type)
  1115. {
  1116. EF4_BUG_ON_PARANOID(!ef4_channel_has_tx_queues(channel) ||
  1117. type >= EF4_TXQ_TYPES);
  1118. return &channel->tx_queue[type];
  1119. }
  1120. static inline bool ef4_tx_queue_used(struct ef4_tx_queue *tx_queue)
  1121. {
  1122. return !(tx_queue->efx->net_dev->num_tc < 2 &&
  1123. tx_queue->queue & EF4_TXQ_TYPE_HIGHPRI);
  1124. }
  1125. /* Iterate over all TX queues belonging to a channel */
  1126. #define ef4_for_each_channel_tx_queue(_tx_queue, _channel) \
  1127. if (!ef4_channel_has_tx_queues(_channel)) \
  1128. ; \
  1129. else \
  1130. for (_tx_queue = (_channel)->tx_queue; \
  1131. _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES && \
  1132. ef4_tx_queue_used(_tx_queue); \
  1133. _tx_queue++)
  1134. /* Iterate over all possible TX queues belonging to a channel */
  1135. #define ef4_for_each_possible_channel_tx_queue(_tx_queue, _channel) \
  1136. if (!ef4_channel_has_tx_queues(_channel)) \
  1137. ; \
  1138. else \
  1139. for (_tx_queue = (_channel)->tx_queue; \
  1140. _tx_queue < (_channel)->tx_queue + EF4_TXQ_TYPES; \
  1141. _tx_queue++)
  1142. static inline bool ef4_channel_has_rx_queue(struct ef4_channel *channel)
  1143. {
  1144. return channel->rx_queue.core_index >= 0;
  1145. }
  1146. static inline struct ef4_rx_queue *
  1147. ef4_channel_get_rx_queue(struct ef4_channel *channel)
  1148. {
  1149. EF4_BUG_ON_PARANOID(!ef4_channel_has_rx_queue(channel));
  1150. return &channel->rx_queue;
  1151. }
  1152. /* Iterate over all RX queues belonging to a channel */
  1153. #define ef4_for_each_channel_rx_queue(_rx_queue, _channel) \
  1154. if (!ef4_channel_has_rx_queue(_channel)) \
  1155. ; \
  1156. else \
  1157. for (_rx_queue = &(_channel)->rx_queue; \
  1158. _rx_queue; \
  1159. _rx_queue = NULL)
  1160. static inline struct ef4_channel *
  1161. ef4_rx_queue_channel(struct ef4_rx_queue *rx_queue)
  1162. {
  1163. return container_of(rx_queue, struct ef4_channel, rx_queue);
  1164. }
  1165. static inline int ef4_rx_queue_index(struct ef4_rx_queue *rx_queue)
  1166. {
  1167. return ef4_rx_queue_channel(rx_queue)->channel;
  1168. }
  1169. /* Returns a pointer to the specified receive buffer in the RX
  1170. * descriptor queue.
  1171. */
  1172. static inline struct ef4_rx_buffer *ef4_rx_buffer(struct ef4_rx_queue *rx_queue,
  1173. unsigned int index)
  1174. {
  1175. return &rx_queue->buffer[index];
  1176. }
  1177. /**
  1178. * EF4_MAX_FRAME_LEN - calculate maximum frame length
  1179. *
  1180. * This calculates the maximum frame length that will be used for a
  1181. * given MTU. The frame length will be equal to the MTU plus a
  1182. * constant amount of header space and padding. This is the quantity
  1183. * that the net driver will program into the MAC as the maximum frame
  1184. * length.
  1185. *
  1186. * The 10G MAC requires 8-byte alignment on the frame
  1187. * length, so we round up to the nearest 8.
  1188. *
  1189. * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
  1190. * XGMII cycle). If the frame length reaches the maximum value in the
  1191. * same cycle, the XMAC can miss the IPG altogether. We work around
  1192. * this by adding a further 16 bytes.
  1193. */
  1194. #define EF4_FRAME_PAD 16
  1195. #define EF4_MAX_FRAME_LEN(mtu) \
  1196. (ALIGN(((mtu) + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + EF4_FRAME_PAD), 8))
  1197. /* Get all supported features.
  1198. * If a feature is not fixed, it is present in hw_features.
  1199. * If a feature is fixed, it does not present in hw_features, but
  1200. * always in features.
  1201. */
  1202. static inline netdev_features_t ef4_supported_features(const struct ef4_nic *efx)
  1203. {
  1204. const struct net_device *net_dev = efx->net_dev;
  1205. return net_dev->features | net_dev->hw_features;
  1206. }
  1207. /* Get the current TX queue insert index. */
  1208. static inline unsigned int
  1209. ef4_tx_queue_get_insert_index(const struct ef4_tx_queue *tx_queue)
  1210. {
  1211. return tx_queue->insert_count & tx_queue->ptr_mask;
  1212. }
  1213. /* Get a TX buffer. */
  1214. static inline struct ef4_tx_buffer *
  1215. __ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue)
  1216. {
  1217. return &tx_queue->buffer[ef4_tx_queue_get_insert_index(tx_queue)];
  1218. }
  1219. /* Get a TX buffer, checking it's not currently in use. */
  1220. static inline struct ef4_tx_buffer *
  1221. ef4_tx_queue_get_insert_buffer(const struct ef4_tx_queue *tx_queue)
  1222. {
  1223. struct ef4_tx_buffer *buffer =
  1224. __ef4_tx_queue_get_insert_buffer(tx_queue);
  1225. EF4_BUG_ON_PARANOID(buffer->len);
  1226. EF4_BUG_ON_PARANOID(buffer->flags);
  1227. EF4_BUG_ON_PARANOID(buffer->unmap_len);
  1228. return buffer;
  1229. }
  1230. #endif /* EF4_NET_DRIVER_H */