net_driver.h 30 KB

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