net_driver.h 32 KB

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