net_driver.h 47 KB

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