net_driver.h 48 KB

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