net_driver.h 33 KB

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