net_driver.h 30 KB

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