net_driver.h 33 KB

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