net_driver.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  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/vmalloc.h>
  25. #include <linux/i2c.h>
  26. #include "enum.h"
  27. #include "bitfield.h"
  28. /**************************************************************************
  29. *
  30. * Build definitions
  31. *
  32. **************************************************************************/
  33. #define EFX_DRIVER_VERSION "3.1"
  34. #ifdef DEBUG
  35. #define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
  36. #define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
  37. #else
  38. #define EFX_BUG_ON_PARANOID(x) do {} while (0)
  39. #define EFX_WARN_ON_PARANOID(x) do {} while (0)
  40. #endif
  41. /**************************************************************************
  42. *
  43. * Efx data structures
  44. *
  45. **************************************************************************/
  46. #define EFX_MAX_CHANNELS 32
  47. #define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
  48. /* Checksum generation is a per-queue option in hardware, so each
  49. * queue visible to the networking core is backed by two hardware TX
  50. * queues. */
  51. #define EFX_MAX_TX_TC 2
  52. #define EFX_MAX_CORE_TX_QUEUES (EFX_MAX_TX_TC * EFX_MAX_CHANNELS)
  53. #define EFX_TXQ_TYPE_OFFLOAD 1 /* flag */
  54. #define EFX_TXQ_TYPE_HIGHPRI 2 /* flag */
  55. #define EFX_TXQ_TYPES 4
  56. #define EFX_MAX_TX_QUEUES (EFX_TXQ_TYPES * EFX_MAX_CHANNELS)
  57. /**
  58. * struct efx_special_buffer - An Efx special buffer
  59. * @addr: CPU base address of the buffer
  60. * @dma_addr: DMA base address of the buffer
  61. * @len: Buffer length, in bytes
  62. * @index: Buffer index within controller;s buffer table
  63. * @entries: Number of buffer table entries
  64. *
  65. * Special buffers are used for the event queues and the TX and RX
  66. * descriptor queues for each channel. They are *not* used for the
  67. * actual transmit and receive buffers.
  68. */
  69. struct efx_special_buffer {
  70. void *addr;
  71. dma_addr_t dma_addr;
  72. unsigned int len;
  73. int index;
  74. int entries;
  75. };
  76. enum efx_flush_state {
  77. FLUSH_NONE,
  78. FLUSH_PENDING,
  79. FLUSH_FAILED,
  80. FLUSH_DONE,
  81. };
  82. /**
  83. * struct efx_tx_buffer - An Efx TX buffer
  84. * @skb: The associated socket buffer.
  85. * Set only on the final fragment of a packet; %NULL for all other
  86. * fragments. When this fragment completes, then we can free this
  87. * skb.
  88. * @tsoh: The associated TSO header structure, or %NULL if this
  89. * buffer is not a TSO header.
  90. * @dma_addr: DMA address of the fragment.
  91. * @len: Length of this fragment.
  92. * This field is zero when the queue slot is empty.
  93. * @continuation: True if this fragment is not the end of a packet.
  94. * @unmap_single: True if pci_unmap_single should be used.
  95. * @unmap_len: Length of this fragment to unmap
  96. */
  97. struct efx_tx_buffer {
  98. const struct sk_buff *skb;
  99. struct efx_tso_header *tsoh;
  100. dma_addr_t dma_addr;
  101. unsigned short len;
  102. bool continuation;
  103. bool unmap_single;
  104. unsigned short unmap_len;
  105. };
  106. /**
  107. * struct efx_tx_queue - An Efx TX queue
  108. *
  109. * This is a ring buffer of TX fragments.
  110. * Since the TX completion path always executes on the same
  111. * CPU and the xmit path can operate on different CPUs,
  112. * performance is increased by ensuring that the completion
  113. * path and the xmit path operate on different cache lines.
  114. * This is particularly important if the xmit path is always
  115. * executing on one CPU which is different from the completion
  116. * path. There is also a cache line for members which are
  117. * read but not written on the fast path.
  118. *
  119. * @efx: The associated Efx NIC
  120. * @queue: DMA queue number
  121. * @channel: The associated channel
  122. * @core_txq: The networking core TX queue structure
  123. * @buffer: The software buffer ring
  124. * @txd: The hardware descriptor ring
  125. * @ptr_mask: The size of the ring minus 1.
  126. * @initialised: Has hardware queue been initialised?
  127. * @flushed: Used when handling queue flushing
  128. * @read_count: Current read pointer.
  129. * This is the number of buffers that have been removed from both rings.
  130. * @old_write_count: The value of @write_count when last checked.
  131. * This is here for performance reasons. The xmit path will
  132. * only get the up-to-date value of @write_count if this
  133. * variable indicates that the queue is empty. This is to
  134. * avoid cache-line ping-pong between the xmit path and the
  135. * completion path.
  136. * @insert_count: Current insert pointer
  137. * This is the number of buffers that have been added to the
  138. * software ring.
  139. * @write_count: Current write pointer
  140. * This is the number of buffers that have been added to the
  141. * hardware ring.
  142. * @old_read_count: The value of read_count when last checked.
  143. * This is here for performance reasons. The xmit path will
  144. * only get the up-to-date value of read_count if this
  145. * variable indicates that the queue is full. This is to
  146. * avoid cache-line ping-pong between the xmit path and the
  147. * completion path.
  148. * @tso_headers_free: A list of TSO headers allocated for this TX queue
  149. * that are not in use, and so available for new TSO sends. The list
  150. * is protected by the TX queue lock.
  151. * @tso_bursts: Number of times TSO xmit invoked by kernel
  152. * @tso_long_headers: Number of packets with headers too long for standard
  153. * blocks
  154. * @tso_packets: Number of packets via the TSO xmit path
  155. * @pushes: Number of times the TX push feature has been used
  156. * @empty_read_count: If the completion path has seen the queue as empty
  157. * and the transmission path has not yet checked this, the value of
  158. * @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
  159. */
  160. struct efx_tx_queue {
  161. /* Members which don't change on the fast path */
  162. struct efx_nic *efx ____cacheline_aligned_in_smp;
  163. unsigned queue;
  164. struct efx_channel *channel;
  165. struct netdev_queue *core_txq;
  166. struct efx_tx_buffer *buffer;
  167. struct efx_special_buffer txd;
  168. unsigned int ptr_mask;
  169. bool initialised;
  170. enum efx_flush_state flushed;
  171. /* Members used mainly on the completion path */
  172. unsigned int read_count ____cacheline_aligned_in_smp;
  173. unsigned int old_write_count;
  174. /* Members used only on the xmit path */
  175. unsigned int insert_count ____cacheline_aligned_in_smp;
  176. unsigned int write_count;
  177. unsigned int old_read_count;
  178. struct efx_tso_header *tso_headers_free;
  179. unsigned int tso_bursts;
  180. unsigned int tso_long_headers;
  181. unsigned int tso_packets;
  182. unsigned int pushes;
  183. /* Members shared between paths and sometimes updated */
  184. unsigned int empty_read_count ____cacheline_aligned_in_smp;
  185. #define EFX_EMPTY_COUNT_VALID 0x80000000
  186. };
  187. /**
  188. * struct efx_rx_buffer - An Efx RX data buffer
  189. * @dma_addr: DMA base address of the buffer
  190. * @skb: The associated socket buffer, if any.
  191. * If both this and page are %NULL, the buffer slot is currently free.
  192. * @page: The associated page buffer, if any.
  193. * If both this and skb are %NULL, the buffer slot is currently free.
  194. * @len: Buffer length, in bytes.
  195. * @is_page: Indicates if @page is valid. If false, @skb is valid.
  196. */
  197. struct efx_rx_buffer {
  198. dma_addr_t dma_addr;
  199. union {
  200. struct sk_buff *skb;
  201. struct page *page;
  202. } u;
  203. unsigned int len;
  204. bool is_page;
  205. };
  206. /**
  207. * struct efx_rx_page_state - Page-based rx buffer state
  208. *
  209. * Inserted at the start of every page allocated for receive buffers.
  210. * Used to facilitate sharing dma mappings between recycled rx buffers
  211. * and those passed up to the kernel.
  212. *
  213. * @refcnt: Number of struct efx_rx_buffer's referencing this page.
  214. * When refcnt falls to zero, the page is unmapped for dma
  215. * @dma_addr: The dma address of this page.
  216. */
  217. struct efx_rx_page_state {
  218. unsigned refcnt;
  219. dma_addr_t dma_addr;
  220. unsigned int __pad[0] ____cacheline_aligned;
  221. };
  222. /**
  223. * struct efx_rx_queue - An Efx RX queue
  224. * @efx: The associated Efx NIC
  225. * @buffer: The software buffer ring
  226. * @rxd: The hardware descriptor ring
  227. * @ptr_mask: The size of the ring minus 1.
  228. * @added_count: Number of buffers added to the receive queue.
  229. * @notified_count: Number of buffers given to NIC (<= @added_count).
  230. * @removed_count: Number of buffers removed from the receive queue.
  231. * @max_fill: RX descriptor maximum fill level (<= ring size)
  232. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  233. * (<= @max_fill)
  234. * @fast_fill_limit: The level to which a fast fill will fill
  235. * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
  236. * @min_fill: RX descriptor minimum non-zero fill level.
  237. * This records the minimum fill level observed when a ring
  238. * refill was triggered.
  239. * @alloc_page_count: RX allocation strategy counter.
  240. * @alloc_skb_count: RX allocation strategy counter.
  241. * @slow_fill: Timer used to defer efx_nic_generate_fill_event().
  242. * @flushed: Use when handling queue flushing
  243. */
  244. struct efx_rx_queue {
  245. struct efx_nic *efx;
  246. struct efx_rx_buffer *buffer;
  247. struct efx_special_buffer rxd;
  248. unsigned int ptr_mask;
  249. int added_count;
  250. int notified_count;
  251. int removed_count;
  252. unsigned int max_fill;
  253. unsigned int fast_fill_trigger;
  254. unsigned int fast_fill_limit;
  255. unsigned int min_fill;
  256. unsigned int min_overfill;
  257. unsigned int alloc_page_count;
  258. unsigned int alloc_skb_count;
  259. struct timer_list slow_fill;
  260. unsigned int slow_fill_count;
  261. enum efx_flush_state flushed;
  262. };
  263. /**
  264. * struct efx_buffer - An Efx general-purpose buffer
  265. * @addr: host base address of the buffer
  266. * @dma_addr: DMA base address of the buffer
  267. * @len: Buffer length, in bytes
  268. *
  269. * The NIC uses these buffers for its interrupt status registers and
  270. * MAC stats dumps.
  271. */
  272. struct efx_buffer {
  273. void *addr;
  274. dma_addr_t dma_addr;
  275. unsigned int len;
  276. };
  277. enum efx_rx_alloc_method {
  278. RX_ALLOC_METHOD_AUTO = 0,
  279. RX_ALLOC_METHOD_SKB = 1,
  280. RX_ALLOC_METHOD_PAGE = 2,
  281. };
  282. /**
  283. * struct efx_channel - An Efx channel
  284. *
  285. * A channel comprises an event queue, at least one TX queue, at least
  286. * one RX queue, and an associated tasklet for processing the event
  287. * queue.
  288. *
  289. * @efx: Associated Efx NIC
  290. * @channel: Channel instance number
  291. * @enabled: Channel enabled indicator
  292. * @irq: IRQ number (MSI and MSI-X only)
  293. * @irq_moderation: IRQ moderation value (in hardware ticks)
  294. * @napi_dev: Net device used with NAPI
  295. * @napi_str: NAPI control structure
  296. * @work_pending: Is work pending via NAPI?
  297. * @eventq: Event queue buffer
  298. * @eventq_mask: Event queue pointer mask
  299. * @eventq_read_ptr: Event queue read pointer
  300. * @last_eventq_read_ptr: Last event queue read pointer value.
  301. * @irq_count: Number of IRQs since last adaptive moderation decision
  302. * @irq_mod_score: IRQ moderation score
  303. * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
  304. * and diagnostic counters
  305. * @rx_alloc_push_pages: RX allocation method currently in use for pushing
  306. * descriptors
  307. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  308. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  309. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  310. * @n_rx_mcast_mismatch: Count of unmatched multicast frames
  311. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  312. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  313. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  314. * @rx_queue: RX queue for this channel
  315. * @tx_queue: TX queues for this channel
  316. */
  317. struct efx_channel {
  318. struct efx_nic *efx;
  319. int channel;
  320. bool enabled;
  321. int irq;
  322. unsigned int irq_moderation;
  323. struct net_device *napi_dev;
  324. struct napi_struct napi_str;
  325. bool work_pending;
  326. struct efx_special_buffer eventq;
  327. unsigned int eventq_mask;
  328. unsigned int eventq_read_ptr;
  329. unsigned int last_eventq_read_ptr;
  330. unsigned int irq_count;
  331. unsigned int irq_mod_score;
  332. #ifdef CONFIG_RFS_ACCEL
  333. unsigned int rfs_filters_added;
  334. #endif
  335. int rx_alloc_level;
  336. int rx_alloc_push_pages;
  337. unsigned n_rx_tobe_disc;
  338. unsigned n_rx_ip_hdr_chksum_err;
  339. unsigned n_rx_tcp_udp_chksum_err;
  340. unsigned n_rx_mcast_mismatch;
  341. unsigned n_rx_frm_trunc;
  342. unsigned n_rx_overlength;
  343. unsigned n_skbuff_leaks;
  344. /* Used to pipeline received packets in order to optimise memory
  345. * access with prefetches.
  346. */
  347. struct efx_rx_buffer *rx_pkt;
  348. bool rx_pkt_csummed;
  349. struct efx_rx_queue rx_queue;
  350. struct efx_tx_queue tx_queue[EFX_TXQ_TYPES];
  351. };
  352. enum efx_led_mode {
  353. EFX_LED_OFF = 0,
  354. EFX_LED_ON = 1,
  355. EFX_LED_DEFAULT = 2
  356. };
  357. #define STRING_TABLE_LOOKUP(val, member) \
  358. ((val) < member ## _max) ? member ## _names[val] : "(invalid)"
  359. extern const char *const efx_loopback_mode_names[];
  360. extern const unsigned int efx_loopback_mode_max;
  361. #define LOOPBACK_MODE(efx) \
  362. STRING_TABLE_LOOKUP((efx)->loopback_mode, efx_loopback_mode)
  363. extern const char *const efx_reset_type_names[];
  364. extern const unsigned int efx_reset_type_max;
  365. #define RESET_TYPE(type) \
  366. STRING_TABLE_LOOKUP(type, efx_reset_type)
  367. enum efx_int_mode {
  368. /* Be careful if altering to correct macro below */
  369. EFX_INT_MODE_MSIX = 0,
  370. EFX_INT_MODE_MSI = 1,
  371. EFX_INT_MODE_LEGACY = 2,
  372. EFX_INT_MODE_MAX /* Insert any new items before this */
  373. };
  374. #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
  375. enum nic_state {
  376. STATE_INIT = 0,
  377. STATE_RUNNING = 1,
  378. STATE_FINI = 2,
  379. STATE_DISABLED = 3,
  380. STATE_MAX,
  381. };
  382. /*
  383. * Alignment of page-allocated RX buffers
  384. *
  385. * Controls the number of bytes inserted at the start of an RX buffer.
  386. * This is the equivalent of NET_IP_ALIGN [which controls the alignment
  387. * of the skb->head for hardware DMA].
  388. */
  389. #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  390. #define EFX_PAGE_IP_ALIGN 0
  391. #else
  392. #define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
  393. #endif
  394. /*
  395. * Alignment of the skb->head which wraps a page-allocated RX buffer
  396. *
  397. * The skb allocated to wrap an rx_buffer can have this alignment. Since
  398. * the data is memcpy'd from the rx_buf, it does not need to be equal to
  399. * EFX_PAGE_IP_ALIGN.
  400. */
  401. #define EFX_PAGE_SKB_ALIGN 2
  402. /* Forward declaration */
  403. struct efx_nic;
  404. /* Pseudo bit-mask flow control field */
  405. #define EFX_FC_RX FLOW_CTRL_RX
  406. #define EFX_FC_TX FLOW_CTRL_TX
  407. #define EFX_FC_AUTO 4
  408. /**
  409. * struct efx_link_state - Current state of the link
  410. * @up: Link is up
  411. * @fd: Link is full-duplex
  412. * @fc: Actual flow control flags
  413. * @speed: Link speed (Mbps)
  414. */
  415. struct efx_link_state {
  416. bool up;
  417. bool fd;
  418. u8 fc;
  419. unsigned int speed;
  420. };
  421. static inline bool efx_link_state_equal(const struct efx_link_state *left,
  422. const struct efx_link_state *right)
  423. {
  424. return left->up == right->up && left->fd == right->fd &&
  425. left->fc == right->fc && left->speed == right->speed;
  426. }
  427. /**
  428. * struct efx_phy_operations - Efx PHY operations table
  429. * @probe: Probe PHY and initialise efx->mdio.mode_support, efx->mdio.mmds,
  430. * efx->loopback_modes.
  431. * @init: Initialise PHY
  432. * @fini: Shut down PHY
  433. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  434. * @poll: Update @link_state and report whether it changed.
  435. * Serialised by the mac_lock.
  436. * @get_settings: Get ethtool settings. Serialised by the mac_lock.
  437. * @set_settings: Set ethtool settings. Serialised by the mac_lock.
  438. * @set_npage_adv: Set abilities advertised in (Extended) Next Page
  439. * (only needed where AN bit is set in mmds)
  440. * @test_alive: Test that PHY is 'alive' (online)
  441. * @test_name: Get the name of a PHY-specific test/result
  442. * @run_tests: Run tests and record results as appropriate (offline).
  443. * Flags are the ethtool tests flags.
  444. */
  445. struct efx_phy_operations {
  446. int (*probe) (struct efx_nic *efx);
  447. int (*init) (struct efx_nic *efx);
  448. void (*fini) (struct efx_nic *efx);
  449. void (*remove) (struct efx_nic *efx);
  450. int (*reconfigure) (struct efx_nic *efx);
  451. bool (*poll) (struct efx_nic *efx);
  452. void (*get_settings) (struct efx_nic *efx,
  453. struct ethtool_cmd *ecmd);
  454. int (*set_settings) (struct efx_nic *efx,
  455. struct ethtool_cmd *ecmd);
  456. void (*set_npage_adv) (struct efx_nic *efx, u32);
  457. int (*test_alive) (struct efx_nic *efx);
  458. const char *(*test_name) (struct efx_nic *efx, unsigned int index);
  459. int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
  460. };
  461. /**
  462. * @enum efx_phy_mode - PHY operating mode flags
  463. * @PHY_MODE_NORMAL: on and should pass traffic
  464. * @PHY_MODE_TX_DISABLED: on with TX disabled
  465. * @PHY_MODE_LOW_POWER: set to low power through MDIO
  466. * @PHY_MODE_OFF: switched off through external control
  467. * @PHY_MODE_SPECIAL: on but will not pass traffic
  468. */
  469. enum efx_phy_mode {
  470. PHY_MODE_NORMAL = 0,
  471. PHY_MODE_TX_DISABLED = 1,
  472. PHY_MODE_LOW_POWER = 2,
  473. PHY_MODE_OFF = 4,
  474. PHY_MODE_SPECIAL = 8,
  475. };
  476. static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
  477. {
  478. return !!(mode & ~PHY_MODE_TX_DISABLED);
  479. }
  480. /*
  481. * Efx extended statistics
  482. *
  483. * Not all statistics are provided by all supported MACs. The purpose
  484. * is this structure is to contain the raw statistics provided by each
  485. * MAC.
  486. */
  487. struct efx_mac_stats {
  488. u64 tx_bytes;
  489. u64 tx_good_bytes;
  490. u64 tx_bad_bytes;
  491. unsigned long tx_packets;
  492. unsigned long tx_bad;
  493. unsigned long tx_pause;
  494. unsigned long tx_control;
  495. unsigned long tx_unicast;
  496. unsigned long tx_multicast;
  497. unsigned long tx_broadcast;
  498. unsigned long tx_lt64;
  499. unsigned long tx_64;
  500. unsigned long tx_65_to_127;
  501. unsigned long tx_128_to_255;
  502. unsigned long tx_256_to_511;
  503. unsigned long tx_512_to_1023;
  504. unsigned long tx_1024_to_15xx;
  505. unsigned long tx_15xx_to_jumbo;
  506. unsigned long tx_gtjumbo;
  507. unsigned long tx_collision;
  508. unsigned long tx_single_collision;
  509. unsigned long tx_multiple_collision;
  510. unsigned long tx_excessive_collision;
  511. unsigned long tx_deferred;
  512. unsigned long tx_late_collision;
  513. unsigned long tx_excessive_deferred;
  514. unsigned long tx_non_tcpudp;
  515. unsigned long tx_mac_src_error;
  516. unsigned long tx_ip_src_error;
  517. u64 rx_bytes;
  518. u64 rx_good_bytes;
  519. u64 rx_bad_bytes;
  520. unsigned long rx_packets;
  521. unsigned long rx_good;
  522. unsigned long rx_bad;
  523. unsigned long rx_pause;
  524. unsigned long rx_control;
  525. unsigned long rx_unicast;
  526. unsigned long rx_multicast;
  527. unsigned long rx_broadcast;
  528. unsigned long rx_lt64;
  529. unsigned long rx_64;
  530. unsigned long rx_65_to_127;
  531. unsigned long rx_128_to_255;
  532. unsigned long rx_256_to_511;
  533. unsigned long rx_512_to_1023;
  534. unsigned long rx_1024_to_15xx;
  535. unsigned long rx_15xx_to_jumbo;
  536. unsigned long rx_gtjumbo;
  537. unsigned long rx_bad_lt64;
  538. unsigned long rx_bad_64_to_15xx;
  539. unsigned long rx_bad_15xx_to_jumbo;
  540. unsigned long rx_bad_gtjumbo;
  541. unsigned long rx_overflow;
  542. unsigned long rx_missed;
  543. unsigned long rx_false_carrier;
  544. unsigned long rx_symbol_error;
  545. unsigned long rx_align_error;
  546. unsigned long rx_length_error;
  547. unsigned long rx_internal_error;
  548. unsigned long rx_good_lt64;
  549. };
  550. /* Number of bits used in a multicast filter hash address */
  551. #define EFX_MCAST_HASH_BITS 8
  552. /* Number of (single-bit) entries in a multicast filter hash */
  553. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  554. /* An Efx multicast filter hash */
  555. union efx_multicast_hash {
  556. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  557. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  558. };
  559. struct efx_filter_state;
  560. /**
  561. * struct efx_nic - an Efx NIC
  562. * @name: Device name (net device name or bus id before net device registered)
  563. * @pci_dev: The PCI device
  564. * @type: Controller type attributes
  565. * @legacy_irq: IRQ number
  566. * @legacy_irq_enabled: Are IRQs enabled on NIC (INT_EN_KER register)?
  567. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  568. * Work items do not hold and must not acquire RTNL.
  569. * @workqueue_name: Name of workqueue
  570. * @reset_work: Scheduled reset workitem
  571. * @membase_phys: Memory BAR value as physical address
  572. * @membase: Memory BAR value
  573. * @interrupt_mode: Interrupt mode
  574. * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  575. * @irq_rx_moderation: IRQ moderation time for RX event queues
  576. * @msg_enable: Log message enable flags
  577. * @state: Device state flag. Serialised by the rtnl_lock.
  578. * @reset_pending: Bitmask for pending resets
  579. * @tx_queue: TX DMA queues
  580. * @rx_queue: RX DMA queues
  581. * @channel: Channels
  582. * @channel_name: Names for channels and their IRQs
  583. * @rxq_entries: Size of receive queues requested by user.
  584. * @txq_entries: Size of transmit queues requested by user.
  585. * @next_buffer_table: First available buffer table id
  586. * @n_channels: Number of channels in use
  587. * @n_rx_channels: Number of channels used for RX (= number of RX queues)
  588. * @n_tx_channels: Number of channels used for TX
  589. * @rx_buffer_len: RX buffer length
  590. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  591. * @rx_hash_key: Toeplitz hash key for RSS
  592. * @rx_indir_table: Indirection table for RSS
  593. * @int_error_count: Number of internal errors seen recently
  594. * @int_error_expire: Time at which error count will be expired
  595. * @irq_status: Interrupt status buffer
  596. * @irq_zero_count: Number of legacy IRQs seen with queue flags == 0
  597. * @fatal_irq_level: IRQ level (bit number) used for serious errors
  598. * @mtd_list: List of MTDs attached to the NIC
  599. * @nic_data: Hardware dependent state
  600. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  601. * efx_monitor() and efx_reconfigure_port()
  602. * @port_enabled: Port enabled indicator.
  603. * Serialises efx_stop_all(), efx_start_all(), efx_monitor() and
  604. * efx_mac_work() with kernel interfaces. Safe to read under any
  605. * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
  606. * be held to modify it.
  607. * @port_initialized: Port initialized?
  608. * @net_dev: Operating system network device. Consider holding the rtnl lock
  609. * @stats_buffer: DMA buffer for statistics
  610. * @phy_type: PHY type
  611. * @phy_op: PHY interface
  612. * @phy_data: PHY private data (including PHY-specific stats)
  613. * @mdio: PHY MDIO interface
  614. * @mdio_bus: PHY MDIO bus ID (only used by Siena)
  615. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  616. * @link_advertising: Autonegotiation advertising flags
  617. * @link_state: Current state of the link
  618. * @n_link_state_changes: Number of times the link has changed state
  619. * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
  620. * @multicast_hash: Multicast hash table
  621. * @wanted_fc: Wanted flow control flags
  622. * @mac_work: Work item for changing MAC promiscuity and multicast hash
  623. * @loopback_mode: Loopback status
  624. * @loopback_modes: Supported loopback mode bitmask
  625. * @loopback_selftest: Offline self-test private state
  626. * @monitor_work: Hardware monitor workitem
  627. * @biu_lock: BIU (bus interface unit) lock
  628. * @last_irq_cpu: Last CPU to handle interrupt.
  629. * This register is written with the SMP processor ID whenever an
  630. * interrupt is handled. It is used by efx_nic_test_interrupt()
  631. * to verify that an interrupt has occurred.
  632. * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
  633. * @mac_stats: MAC statistics. These include all statistics the MACs
  634. * can provide. Generic code converts these into a standard
  635. * &struct net_device_stats.
  636. * @stats_lock: Statistics update lock. Serialises statistics fetches
  637. * and access to @mac_stats.
  638. *
  639. * This is stored in the private area of the &struct net_device.
  640. */
  641. struct efx_nic {
  642. /* The following fields should be written very rarely */
  643. char name[IFNAMSIZ];
  644. struct pci_dev *pci_dev;
  645. const struct efx_nic_type *type;
  646. int legacy_irq;
  647. bool legacy_irq_enabled;
  648. struct workqueue_struct *workqueue;
  649. char workqueue_name[16];
  650. struct work_struct reset_work;
  651. resource_size_t membase_phys;
  652. void __iomem *membase;
  653. enum efx_int_mode interrupt_mode;
  654. bool irq_rx_adaptive;
  655. unsigned int irq_rx_moderation;
  656. u32 msg_enable;
  657. enum nic_state state;
  658. unsigned long reset_pending;
  659. struct efx_channel *channel[EFX_MAX_CHANNELS];
  660. char channel_name[EFX_MAX_CHANNELS][IFNAMSIZ + 6];
  661. unsigned rxq_entries;
  662. unsigned txq_entries;
  663. unsigned next_buffer_table;
  664. unsigned n_channels;
  665. unsigned n_rx_channels;
  666. unsigned tx_channel_offset;
  667. unsigned n_tx_channels;
  668. unsigned int rx_buffer_len;
  669. unsigned int rx_buffer_order;
  670. u8 rx_hash_key[40];
  671. u32 rx_indir_table[128];
  672. unsigned int_error_count;
  673. unsigned long int_error_expire;
  674. struct efx_buffer irq_status;
  675. unsigned irq_zero_count;
  676. unsigned fatal_irq_level;
  677. #ifdef CONFIG_SFC_MTD
  678. struct list_head mtd_list;
  679. #endif
  680. void *nic_data;
  681. struct mutex mac_lock;
  682. struct work_struct mac_work;
  683. bool port_enabled;
  684. bool port_initialized;
  685. struct net_device *net_dev;
  686. struct efx_buffer stats_buffer;
  687. unsigned int phy_type;
  688. const struct efx_phy_operations *phy_op;
  689. void *phy_data;
  690. struct mdio_if_info mdio;
  691. unsigned int mdio_bus;
  692. enum efx_phy_mode phy_mode;
  693. u32 link_advertising;
  694. struct efx_link_state link_state;
  695. unsigned int n_link_state_changes;
  696. bool promiscuous;
  697. union efx_multicast_hash multicast_hash;
  698. u8 wanted_fc;
  699. atomic_t rx_reset;
  700. enum efx_loopback_mode loopback_mode;
  701. u64 loopback_modes;
  702. void *loopback_selftest;
  703. struct efx_filter_state *filter_state;
  704. /* The following fields may be written more often */
  705. struct delayed_work monitor_work ____cacheline_aligned_in_smp;
  706. spinlock_t biu_lock;
  707. volatile signed int last_irq_cpu;
  708. unsigned n_rx_nodesc_drop_cnt;
  709. struct efx_mac_stats mac_stats;
  710. spinlock_t stats_lock;
  711. };
  712. static inline int efx_dev_registered(struct efx_nic *efx)
  713. {
  714. return efx->net_dev->reg_state == NETREG_REGISTERED;
  715. }
  716. /* Net device name, for inclusion in log messages if it has been registered.
  717. * Use efx->name not efx->net_dev->name so that races with (un)registration
  718. * are harmless.
  719. */
  720. static inline const char *efx_dev_name(struct efx_nic *efx)
  721. {
  722. return efx_dev_registered(efx) ? efx->name : "";
  723. }
  724. static inline unsigned int efx_port_num(struct efx_nic *efx)
  725. {
  726. return efx->net_dev->dev_id;
  727. }
  728. /**
  729. * struct efx_nic_type - Efx device type definition
  730. * @probe: Probe the controller
  731. * @remove: Free resources allocated by probe()
  732. * @init: Initialise the controller
  733. * @fini: Shut down the controller
  734. * @monitor: Periodic function for polling link state and hardware monitor
  735. * @map_reset_reason: Map ethtool reset reason to a reset method
  736. * @map_reset_flags: Map ethtool reset flags to a reset method, if possible
  737. * @reset: Reset the controller hardware and possibly the PHY. This will
  738. * be called while the controller is uninitialised.
  739. * @probe_port: Probe the MAC and PHY
  740. * @remove_port: Free resources allocated by probe_port()
  741. * @handle_global_event: Handle a "global" event (may be %NULL)
  742. * @prepare_flush: Prepare the hardware for flushing the DMA queues
  743. * @update_stats: Update statistics not provided by event handling
  744. * @start_stats: Start the regular fetching of statistics
  745. * @stop_stats: Stop the regular fetching of statistics
  746. * @set_id_led: Set state of identifying LED or revert to automatic function
  747. * @push_irq_moderation: Apply interrupt moderation value
  748. * @reconfigure_port: Push loopback/power/txdis changes to the MAC and PHY
  749. * @reconfigure_mac: Push MAC address, MTU, flow control and filter settings
  750. * to the hardware. Serialised by the mac_lock.
  751. * @check_mac_fault: Check MAC fault state. True if fault present.
  752. * @get_wol: Get WoL configuration from driver state
  753. * @set_wol: Push WoL configuration to the NIC
  754. * @resume_wol: Synchronise WoL state between driver and MC (e.g. after resume)
  755. * @test_registers: Test read/write functionality of control registers
  756. * @test_nvram: Test validity of NVRAM contents
  757. * @revision: Hardware architecture revision
  758. * @mem_map_size: Memory BAR mapped size
  759. * @txd_ptr_tbl_base: TX descriptor ring base address
  760. * @rxd_ptr_tbl_base: RX descriptor ring base address
  761. * @buf_tbl_base: Buffer table base address
  762. * @evq_ptr_tbl_base: Event queue pointer table base address
  763. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  764. * @max_dma_mask: Maximum possible DMA mask
  765. * @rx_buffer_hash_size: Size of hash at start of RX buffer
  766. * @rx_buffer_padding: Size of padding at end of RX buffer
  767. * @max_interrupt_mode: Highest capability interrupt mode supported
  768. * from &enum efx_init_mode.
  769. * @phys_addr_channels: Number of channels with physically addressed
  770. * descriptors
  771. * @tx_dc_base: Base address in SRAM of TX queue descriptor caches
  772. * @rx_dc_base: Base address in SRAM of RX queue descriptor caches
  773. * @offload_features: net_device feature flags for protocol offload
  774. * features implemented in hardware
  775. */
  776. struct efx_nic_type {
  777. int (*probe)(struct efx_nic *efx);
  778. void (*remove)(struct efx_nic *efx);
  779. int (*init)(struct efx_nic *efx);
  780. void (*fini)(struct efx_nic *efx);
  781. void (*monitor)(struct efx_nic *efx);
  782. enum reset_type (*map_reset_reason)(enum reset_type reason);
  783. int (*map_reset_flags)(u32 *flags);
  784. int (*reset)(struct efx_nic *efx, enum reset_type method);
  785. int (*probe_port)(struct efx_nic *efx);
  786. void (*remove_port)(struct efx_nic *efx);
  787. bool (*handle_global_event)(struct efx_channel *channel, efx_qword_t *);
  788. void (*prepare_flush)(struct efx_nic *efx);
  789. void (*update_stats)(struct efx_nic *efx);
  790. void (*start_stats)(struct efx_nic *efx);
  791. void (*stop_stats)(struct efx_nic *efx);
  792. void (*set_id_led)(struct efx_nic *efx, enum efx_led_mode mode);
  793. void (*push_irq_moderation)(struct efx_channel *channel);
  794. int (*reconfigure_port)(struct efx_nic *efx);
  795. int (*reconfigure_mac)(struct efx_nic *efx);
  796. bool (*check_mac_fault)(struct efx_nic *efx);
  797. void (*get_wol)(struct efx_nic *efx, struct ethtool_wolinfo *wol);
  798. int (*set_wol)(struct efx_nic *efx, u32 type);
  799. void (*resume_wol)(struct efx_nic *efx);
  800. int (*test_registers)(struct efx_nic *efx);
  801. int (*test_nvram)(struct efx_nic *efx);
  802. int revision;
  803. unsigned int mem_map_size;
  804. unsigned int txd_ptr_tbl_base;
  805. unsigned int rxd_ptr_tbl_base;
  806. unsigned int buf_tbl_base;
  807. unsigned int evq_ptr_tbl_base;
  808. unsigned int evq_rptr_tbl_base;
  809. u64 max_dma_mask;
  810. unsigned int rx_buffer_hash_size;
  811. unsigned int rx_buffer_padding;
  812. unsigned int max_interrupt_mode;
  813. unsigned int phys_addr_channels;
  814. unsigned int tx_dc_base;
  815. unsigned int rx_dc_base;
  816. netdev_features_t offload_features;
  817. };
  818. /**************************************************************************
  819. *
  820. * Prototypes and inline functions
  821. *
  822. *************************************************************************/
  823. static inline struct efx_channel *
  824. efx_get_channel(struct efx_nic *efx, unsigned index)
  825. {
  826. EFX_BUG_ON_PARANOID(index >= efx->n_channels);
  827. return efx->channel[index];
  828. }
  829. /* Iterate over all used channels */
  830. #define efx_for_each_channel(_channel, _efx) \
  831. for (_channel = (_efx)->channel[0]; \
  832. _channel; \
  833. _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
  834. (_efx)->channel[_channel->channel + 1] : NULL)
  835. static inline struct efx_tx_queue *
  836. efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)
  837. {
  838. EFX_BUG_ON_PARANOID(index >= efx->n_tx_channels ||
  839. type >= EFX_TXQ_TYPES);
  840. return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
  841. }
  842. static inline bool efx_channel_has_tx_queues(struct efx_channel *channel)
  843. {
  844. return channel->channel - channel->efx->tx_channel_offset <
  845. channel->efx->n_tx_channels;
  846. }
  847. static inline struct efx_tx_queue *
  848. efx_channel_get_tx_queue(struct efx_channel *channel, unsigned type)
  849. {
  850. EFX_BUG_ON_PARANOID(!efx_channel_has_tx_queues(channel) ||
  851. type >= EFX_TXQ_TYPES);
  852. return &channel->tx_queue[type];
  853. }
  854. static inline bool efx_tx_queue_used(struct efx_tx_queue *tx_queue)
  855. {
  856. return !(tx_queue->efx->net_dev->num_tc < 2 &&
  857. tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI);
  858. }
  859. /* Iterate over all TX queues belonging to a channel */
  860. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  861. if (!efx_channel_has_tx_queues(_channel)) \
  862. ; \
  863. else \
  864. for (_tx_queue = (_channel)->tx_queue; \
  865. _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES && \
  866. efx_tx_queue_used(_tx_queue); \
  867. _tx_queue++)
  868. /* Iterate over all possible TX queues belonging to a channel */
  869. #define efx_for_each_possible_channel_tx_queue(_tx_queue, _channel) \
  870. for (_tx_queue = (_channel)->tx_queue; \
  871. _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES; \
  872. _tx_queue++)
  873. static inline struct efx_rx_queue *
  874. efx_get_rx_queue(struct efx_nic *efx, unsigned index)
  875. {
  876. EFX_BUG_ON_PARANOID(index >= efx->n_rx_channels);
  877. return &efx->channel[index]->rx_queue;
  878. }
  879. static inline bool efx_channel_has_rx_queue(struct efx_channel *channel)
  880. {
  881. return channel->channel < channel->efx->n_rx_channels;
  882. }
  883. static inline struct efx_rx_queue *
  884. efx_channel_get_rx_queue(struct efx_channel *channel)
  885. {
  886. EFX_BUG_ON_PARANOID(!efx_channel_has_rx_queue(channel));
  887. return &channel->rx_queue;
  888. }
  889. /* Iterate over all RX queues belonging to a channel */
  890. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  891. if (!efx_channel_has_rx_queue(_channel)) \
  892. ; \
  893. else \
  894. for (_rx_queue = &(_channel)->rx_queue; \
  895. _rx_queue; \
  896. _rx_queue = NULL)
  897. static inline struct efx_channel *
  898. efx_rx_queue_channel(struct efx_rx_queue *rx_queue)
  899. {
  900. return container_of(rx_queue, struct efx_channel, rx_queue);
  901. }
  902. static inline int efx_rx_queue_index(struct efx_rx_queue *rx_queue)
  903. {
  904. return efx_rx_queue_channel(rx_queue)->channel;
  905. }
  906. /* Returns a pointer to the specified receive buffer in the RX
  907. * descriptor queue.
  908. */
  909. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  910. unsigned int index)
  911. {
  912. return &rx_queue->buffer[index];
  913. }
  914. /* Set bit in a little-endian bitfield */
  915. static inline void set_bit_le(unsigned nr, unsigned char *addr)
  916. {
  917. addr[nr / 8] |= (1 << (nr % 8));
  918. }
  919. /* Clear bit in a little-endian bitfield */
  920. static inline void clear_bit_le(unsigned nr, unsigned char *addr)
  921. {
  922. addr[nr / 8] &= ~(1 << (nr % 8));
  923. }
  924. /**
  925. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  926. *
  927. * This calculates the maximum frame length that will be used for a
  928. * given MTU. The frame length will be equal to the MTU plus a
  929. * constant amount of header space and padding. This is the quantity
  930. * that the net driver will program into the MAC as the maximum frame
  931. * length.
  932. *
  933. * The 10G MAC requires 8-byte alignment on the frame
  934. * length, so we round up to the nearest 8.
  935. *
  936. * Re-clocking by the XGXS on RX can reduce an IPG to 32 bits (half an
  937. * XGMII cycle). If the frame length reaches the maximum value in the
  938. * same cycle, the XMAC can miss the IPG altogether. We work around
  939. * this by adding a further 16 bytes.
  940. */
  941. #define EFX_MAX_FRAME_LEN(mtu) \
  942. ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */ + 7) & ~7) + 16)
  943. #endif /* EFX_NET_DRIVER_H */