net_driver.h 50 KB

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