net_driver.h 47 KB

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