net_driver.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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/mii.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_blinker - S/W LED blinking context
  356. * @state: Current state - on or off
  357. * @resubmit: Timer resubmission flag
  358. * @timer: Control timer for blinking
  359. */
  360. struct efx_blinker {
  361. bool state;
  362. bool resubmit;
  363. struct timer_list timer;
  364. };
  365. /**
  366. * struct efx_board - board information
  367. * @type: Board model type
  368. * @major: Major rev. ('A', 'B' ...)
  369. * @minor: Minor rev. (0, 1, ...)
  370. * @init: Initialisation function
  371. * @init_leds: Sets up board LEDs. May be called repeatedly.
  372. * @set_id_led: Turns the identification LED on or off
  373. * @blink: Starts/stops blinking
  374. * @monitor: Board-specific health check function
  375. * @fini: Cleanup function
  376. * @blinker: used to blink LEDs in software
  377. * @hwmon_client: I2C client for hardware monitor
  378. * @ioexp_client: I2C client for power/port control
  379. */
  380. struct efx_board {
  381. int type;
  382. int major;
  383. int minor;
  384. int (*init) (struct efx_nic *nic);
  385. /* As the LEDs are typically attached to the PHY, LEDs
  386. * have a separate init callback that happens later than
  387. * board init. */
  388. void (*init_leds)(struct efx_nic *efx);
  389. void (*set_id_led) (struct efx_nic *efx, bool state);
  390. int (*monitor) (struct efx_nic *nic);
  391. void (*blink) (struct efx_nic *efx, bool start);
  392. void (*fini) (struct efx_nic *nic);
  393. struct efx_blinker blinker;
  394. struct i2c_client *hwmon_client, *ioexp_client;
  395. };
  396. #define STRING_TABLE_LOOKUP(val, member) \
  397. member ## _names[val]
  398. enum efx_int_mode {
  399. /* Be careful if altering to correct macro below */
  400. EFX_INT_MODE_MSIX = 0,
  401. EFX_INT_MODE_MSI = 1,
  402. EFX_INT_MODE_LEGACY = 2,
  403. EFX_INT_MODE_MAX /* Insert any new items before this */
  404. };
  405. #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
  406. enum phy_type {
  407. PHY_TYPE_NONE = 0,
  408. PHY_TYPE_TXC43128 = 1,
  409. PHY_TYPE_88E1111 = 2,
  410. PHY_TYPE_SFX7101 = 3,
  411. PHY_TYPE_QT2022C2 = 4,
  412. PHY_TYPE_PM8358 = 6,
  413. PHY_TYPE_SFT9001A = 8,
  414. PHY_TYPE_QT2025C = 9,
  415. PHY_TYPE_SFT9001B = 10,
  416. PHY_TYPE_MAX /* Insert any new items before this */
  417. };
  418. #define PHY_ADDR_INVALID 0xff
  419. #define EFX_IS10G(efx) ((efx)->link_speed == 10000)
  420. enum nic_state {
  421. STATE_INIT = 0,
  422. STATE_RUNNING = 1,
  423. STATE_FINI = 2,
  424. STATE_DISABLED = 3,
  425. STATE_MAX,
  426. };
  427. /*
  428. * Alignment of page-allocated RX buffers
  429. *
  430. * Controls the number of bytes inserted at the start of an RX buffer.
  431. * This is the equivalent of NET_IP_ALIGN [which controls the alignment
  432. * of the skb->head for hardware DMA].
  433. */
  434. #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  435. #define EFX_PAGE_IP_ALIGN 0
  436. #else
  437. #define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
  438. #endif
  439. /*
  440. * Alignment of the skb->head which wraps a page-allocated RX buffer
  441. *
  442. * The skb allocated to wrap an rx_buffer can have this alignment. Since
  443. * the data is memcpy'd from the rx_buf, it does not need to be equal to
  444. * EFX_PAGE_IP_ALIGN.
  445. */
  446. #define EFX_PAGE_SKB_ALIGN 2
  447. /* Forward declaration */
  448. struct efx_nic;
  449. /* Pseudo bit-mask flow control field */
  450. enum efx_fc_type {
  451. EFX_FC_RX = 1,
  452. EFX_FC_TX = 2,
  453. EFX_FC_AUTO = 4,
  454. };
  455. /* Supported MAC bit-mask */
  456. enum efx_mac_type {
  457. EFX_GMAC = 1,
  458. EFX_XMAC = 2,
  459. };
  460. static inline unsigned int efx_fc_advertise(enum efx_fc_type wanted_fc)
  461. {
  462. unsigned int adv = 0;
  463. if (wanted_fc & EFX_FC_RX)
  464. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  465. if (wanted_fc & EFX_FC_TX)
  466. adv ^= ADVERTISE_PAUSE_ASYM;
  467. return adv;
  468. }
  469. static inline enum efx_fc_type efx_fc_resolve(enum efx_fc_type wanted_fc,
  470. unsigned int lpa)
  471. {
  472. unsigned int adv = efx_fc_advertise(wanted_fc);
  473. if (!(wanted_fc & EFX_FC_AUTO))
  474. return wanted_fc;
  475. if (adv & lpa & ADVERTISE_PAUSE_CAP)
  476. return EFX_FC_RX | EFX_FC_TX;
  477. if (adv & lpa & ADVERTISE_PAUSE_ASYM) {
  478. if (adv & ADVERTISE_PAUSE_CAP)
  479. return EFX_FC_RX;
  480. if (lpa & ADVERTISE_PAUSE_CAP)
  481. return EFX_FC_TX;
  482. }
  483. return 0;
  484. }
  485. /**
  486. * struct efx_mac_operations - Efx MAC operations table
  487. * @reconfigure: Reconfigure MAC. Serialised by the mac_lock
  488. * @update_stats: Update statistics
  489. * @irq: Hardware MAC event callback. Serialised by the mac_lock
  490. * @poll: Poll for hardware state. Serialised by the mac_lock
  491. */
  492. struct efx_mac_operations {
  493. void (*reconfigure) (struct efx_nic *efx);
  494. void (*update_stats) (struct efx_nic *efx);
  495. void (*irq) (struct efx_nic *efx);
  496. void (*poll) (struct efx_nic *efx);
  497. };
  498. /**
  499. * struct efx_phy_operations - Efx PHY operations table
  500. * @init: Initialise PHY
  501. * @fini: Shut down PHY
  502. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  503. * @clear_interrupt: Clear down interrupt
  504. * @blink: Blink LEDs
  505. * @poll: Poll for hardware state. Serialised by the mac_lock.
  506. * @get_settings: Get ethtool settings. Serialised by the mac_lock.
  507. * @set_settings: Set ethtool settings. Serialised by the mac_lock.
  508. * @set_npage_adv: Set abilities advertised in (Extended) Next Page
  509. * (only needed where AN bit is set in mmds)
  510. * @num_tests: Number of PHY-specific tests/results
  511. * @test_names: Names of the tests/results
  512. * @run_tests: Run tests and record results as appropriate.
  513. * Flags are the ethtool tests flags.
  514. * @mmds: MMD presence mask
  515. * @loopbacks: Supported loopback modes mask
  516. */
  517. struct efx_phy_operations {
  518. enum efx_mac_type macs;
  519. int (*init) (struct efx_nic *efx);
  520. void (*fini) (struct efx_nic *efx);
  521. void (*reconfigure) (struct efx_nic *efx);
  522. void (*clear_interrupt) (struct efx_nic *efx);
  523. void (*poll) (struct efx_nic *efx);
  524. void (*get_settings) (struct efx_nic *efx,
  525. struct ethtool_cmd *ecmd);
  526. int (*set_settings) (struct efx_nic *efx,
  527. struct ethtool_cmd *ecmd);
  528. void (*set_npage_adv) (struct efx_nic *efx, u32);
  529. u32 num_tests;
  530. const char *const *test_names;
  531. int (*run_tests) (struct efx_nic *efx, int *results, unsigned flags);
  532. int mmds;
  533. unsigned loopbacks;
  534. };
  535. /**
  536. * @enum efx_phy_mode - PHY operating mode flags
  537. * @PHY_MODE_NORMAL: on and should pass traffic
  538. * @PHY_MODE_TX_DISABLED: on with TX disabled
  539. * @PHY_MODE_LOW_POWER: set to low power through MDIO
  540. * @PHY_MODE_OFF: switched off through external control
  541. * @PHY_MODE_SPECIAL: on but will not pass traffic
  542. */
  543. enum efx_phy_mode {
  544. PHY_MODE_NORMAL = 0,
  545. PHY_MODE_TX_DISABLED = 1,
  546. PHY_MODE_LOW_POWER = 2,
  547. PHY_MODE_OFF = 4,
  548. PHY_MODE_SPECIAL = 8,
  549. };
  550. static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
  551. {
  552. return !!(mode & ~PHY_MODE_TX_DISABLED);
  553. }
  554. /*
  555. * Efx extended statistics
  556. *
  557. * Not all statistics are provided by all supported MACs. The purpose
  558. * is this structure is to contain the raw statistics provided by each
  559. * MAC.
  560. */
  561. struct efx_mac_stats {
  562. u64 tx_bytes;
  563. u64 tx_good_bytes;
  564. u64 tx_bad_bytes;
  565. unsigned long tx_packets;
  566. unsigned long tx_bad;
  567. unsigned long tx_pause;
  568. unsigned long tx_control;
  569. unsigned long tx_unicast;
  570. unsigned long tx_multicast;
  571. unsigned long tx_broadcast;
  572. unsigned long tx_lt64;
  573. unsigned long tx_64;
  574. unsigned long tx_65_to_127;
  575. unsigned long tx_128_to_255;
  576. unsigned long tx_256_to_511;
  577. unsigned long tx_512_to_1023;
  578. unsigned long tx_1024_to_15xx;
  579. unsigned long tx_15xx_to_jumbo;
  580. unsigned long tx_gtjumbo;
  581. unsigned long tx_collision;
  582. unsigned long tx_single_collision;
  583. unsigned long tx_multiple_collision;
  584. unsigned long tx_excessive_collision;
  585. unsigned long tx_deferred;
  586. unsigned long tx_late_collision;
  587. unsigned long tx_excessive_deferred;
  588. unsigned long tx_non_tcpudp;
  589. unsigned long tx_mac_src_error;
  590. unsigned long tx_ip_src_error;
  591. u64 rx_bytes;
  592. u64 rx_good_bytes;
  593. u64 rx_bad_bytes;
  594. unsigned long rx_packets;
  595. unsigned long rx_good;
  596. unsigned long rx_bad;
  597. unsigned long rx_pause;
  598. unsigned long rx_control;
  599. unsigned long rx_unicast;
  600. unsigned long rx_multicast;
  601. unsigned long rx_broadcast;
  602. unsigned long rx_lt64;
  603. unsigned long rx_64;
  604. unsigned long rx_65_to_127;
  605. unsigned long rx_128_to_255;
  606. unsigned long rx_256_to_511;
  607. unsigned long rx_512_to_1023;
  608. unsigned long rx_1024_to_15xx;
  609. unsigned long rx_15xx_to_jumbo;
  610. unsigned long rx_gtjumbo;
  611. unsigned long rx_bad_lt64;
  612. unsigned long rx_bad_64_to_15xx;
  613. unsigned long rx_bad_15xx_to_jumbo;
  614. unsigned long rx_bad_gtjumbo;
  615. unsigned long rx_overflow;
  616. unsigned long rx_missed;
  617. unsigned long rx_false_carrier;
  618. unsigned long rx_symbol_error;
  619. unsigned long rx_align_error;
  620. unsigned long rx_length_error;
  621. unsigned long rx_internal_error;
  622. unsigned long rx_good_lt64;
  623. };
  624. /* Number of bits used in a multicast filter hash address */
  625. #define EFX_MCAST_HASH_BITS 8
  626. /* Number of (single-bit) entries in a multicast filter hash */
  627. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  628. /* An Efx multicast filter hash */
  629. union efx_multicast_hash {
  630. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  631. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  632. };
  633. /**
  634. * struct efx_nic - an Efx NIC
  635. * @name: Device name (net device name or bus id before net device registered)
  636. * @pci_dev: The PCI device
  637. * @type: Controller type attributes
  638. * @legacy_irq: IRQ number
  639. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  640. * Work items do not hold and must not acquire RTNL.
  641. * @workqueue_name: Name of workqueue
  642. * @reset_work: Scheduled reset workitem
  643. * @monitor_work: Hardware monitor workitem
  644. * @membase_phys: Memory BAR value as physical address
  645. * @membase: Memory BAR value
  646. * @biu_lock: BIU (bus interface unit) lock
  647. * @interrupt_mode: Interrupt mode
  648. * @irq_rx_adaptive: Adaptive IRQ moderation enabled for RX event queues
  649. * @irq_rx_moderation: IRQ moderation time for RX event queues
  650. * @i2c_adap: I2C adapter
  651. * @board_info: Board-level information
  652. * @state: Device state flag. Serialised by the rtnl_lock.
  653. * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
  654. * @tx_queue: TX DMA queues
  655. * @rx_queue: RX DMA queues
  656. * @channel: Channels
  657. * @n_rx_queues: Number of RX queues
  658. * @n_channels: Number of channels in use
  659. * @rx_buffer_len: RX buffer length
  660. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  661. * @irq_status: Interrupt status buffer
  662. * @last_irq_cpu: Last CPU to handle interrupt.
  663. * This register is written with the SMP processor ID whenever an
  664. * interrupt is handled. It is used by falcon_test_interrupt()
  665. * to verify that an interrupt has occurred.
  666. * @spi_flash: SPI flash device
  667. * This field will be %NULL if no flash device is present.
  668. * @spi_eeprom: SPI EEPROM device
  669. * This field will be %NULL if no EEPROM device is present.
  670. * @spi_lock: SPI bus lock
  671. * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
  672. * @nic_data: Hardware dependant state
  673. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  674. * @port_inhibited, efx_monitor() and efx_reconfigure_port()
  675. * @port_enabled: Port enabled indicator.
  676. * Serialises efx_stop_all(), efx_start_all(), efx_monitor(),
  677. * efx_phy_work(), and efx_mac_work() with kernel interfaces. Safe to read
  678. * under any one of the rtnl_lock, mac_lock, or netif_tx_lock, but all
  679. * three must be held to modify it.
  680. * @port_inhibited: If set, the netif_carrier is always off. Hold the mac_lock
  681. * @port_initialized: Port initialized?
  682. * @net_dev: Operating system network device. Consider holding the rtnl lock
  683. * @rx_checksum_enabled: RX checksumming enabled
  684. * @netif_stop_count: Port stop count
  685. * @netif_stop_lock: Port stop lock
  686. * @mac_stats: MAC statistics. These include all statistics the MACs
  687. * can provide. Generic code converts these into a standard
  688. * &struct net_device_stats.
  689. * @stats_buffer: DMA buffer for statistics
  690. * @stats_lock: Statistics update lock. Serialises statistics fetches
  691. * @stats_disable_count: Nest count for disabling statistics fetches
  692. * @mac_op: MAC interface
  693. * @mac_address: Permanent MAC address
  694. * @phy_type: PHY type
  695. * @phy_lock: PHY access lock
  696. * @phy_op: PHY interface
  697. * @phy_data: PHY private data (including PHY-specific stats)
  698. * @mii: PHY interface
  699. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  700. * @mac_up: MAC link state
  701. * @link_up: Link status
  702. * @link_fd: Link is full duplex
  703. * @link_fc: Actualy flow control flags
  704. * @link_speed: Link speed (Mbps)
  705. * @n_link_state_changes: Number of times the link has changed state
  706. * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
  707. * @multicast_hash: Multicast hash table
  708. * @wanted_fc: Wanted flow control flags
  709. * @phy_work: work item for dealing with PHY events
  710. * @mac_work: work item for dealing with MAC events
  711. * @loopback_mode: Loopback status
  712. * @loopback_modes: Supported loopback mode bitmask
  713. * @loopback_selftest: Offline self-test private state
  714. *
  715. * The @priv field of the corresponding &struct net_device points to
  716. * this.
  717. */
  718. struct efx_nic {
  719. char name[IFNAMSIZ];
  720. struct pci_dev *pci_dev;
  721. const struct efx_nic_type *type;
  722. int legacy_irq;
  723. struct workqueue_struct *workqueue;
  724. char workqueue_name[16];
  725. struct work_struct reset_work;
  726. struct delayed_work monitor_work;
  727. resource_size_t membase_phys;
  728. void __iomem *membase;
  729. spinlock_t biu_lock;
  730. enum efx_int_mode interrupt_mode;
  731. bool irq_rx_adaptive;
  732. unsigned int irq_rx_moderation;
  733. struct i2c_adapter i2c_adap;
  734. struct efx_board board_info;
  735. enum nic_state state;
  736. enum reset_type reset_pending;
  737. struct efx_tx_queue tx_queue[EFX_TX_QUEUE_COUNT];
  738. struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
  739. struct efx_channel channel[EFX_MAX_CHANNELS];
  740. int n_rx_queues;
  741. int n_channels;
  742. unsigned int rx_buffer_len;
  743. unsigned int rx_buffer_order;
  744. struct efx_buffer irq_status;
  745. volatile signed int last_irq_cpu;
  746. struct efx_spi_device *spi_flash;
  747. struct efx_spi_device *spi_eeprom;
  748. struct mutex spi_lock;
  749. unsigned n_rx_nodesc_drop_cnt;
  750. struct falcon_nic_data *nic_data;
  751. struct mutex mac_lock;
  752. struct work_struct mac_work;
  753. bool port_enabled;
  754. bool port_inhibited;
  755. bool port_initialized;
  756. struct net_device *net_dev;
  757. bool rx_checksum_enabled;
  758. atomic_t netif_stop_count;
  759. spinlock_t netif_stop_lock;
  760. struct efx_mac_stats mac_stats;
  761. struct efx_buffer stats_buffer;
  762. spinlock_t stats_lock;
  763. unsigned int stats_disable_count;
  764. struct efx_mac_operations *mac_op;
  765. unsigned char mac_address[ETH_ALEN];
  766. enum phy_type phy_type;
  767. spinlock_t phy_lock;
  768. struct work_struct phy_work;
  769. struct efx_phy_operations *phy_op;
  770. void *phy_data;
  771. struct mii_if_info mii;
  772. enum efx_phy_mode phy_mode;
  773. bool mac_up;
  774. bool link_up;
  775. bool link_fd;
  776. enum efx_fc_type link_fc;
  777. unsigned int link_speed;
  778. unsigned int n_link_state_changes;
  779. bool promiscuous;
  780. union efx_multicast_hash multicast_hash;
  781. enum efx_fc_type wanted_fc;
  782. atomic_t rx_reset;
  783. enum efx_loopback_mode loopback_mode;
  784. unsigned int loopback_modes;
  785. void *loopback_selftest;
  786. };
  787. static inline int efx_dev_registered(struct efx_nic *efx)
  788. {
  789. return efx->net_dev->reg_state == NETREG_REGISTERED;
  790. }
  791. /* Net device name, for inclusion in log messages if it has been registered.
  792. * Use efx->name not efx->net_dev->name so that races with (un)registration
  793. * are harmless.
  794. */
  795. static inline const char *efx_dev_name(struct efx_nic *efx)
  796. {
  797. return efx_dev_registered(efx) ? efx->name : "";
  798. }
  799. /**
  800. * struct efx_nic_type - Efx device type definition
  801. * @mem_bar: Memory BAR number
  802. * @mem_map_size: Memory BAR mapped size
  803. * @txd_ptr_tbl_base: TX descriptor ring base address
  804. * @rxd_ptr_tbl_base: RX descriptor ring base address
  805. * @buf_tbl_base: Buffer table base address
  806. * @evq_ptr_tbl_base: Event queue pointer table base address
  807. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  808. * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
  809. * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
  810. * @evq_size: Event queue size (must be a power of two)
  811. * @max_dma_mask: Maximum possible DMA mask
  812. * @tx_dma_mask: TX DMA mask
  813. * @bug5391_mask: Address mask for bug 5391 workaround
  814. * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
  815. * @rx_xon_thresh: RX FIFO XON watermark (bytes)
  816. * @rx_buffer_padding: Padding added to each RX buffer
  817. * @max_interrupt_mode: Highest capability interrupt mode supported
  818. * from &enum efx_init_mode.
  819. * @phys_addr_channels: Number of channels with physically addressed
  820. * descriptors
  821. */
  822. struct efx_nic_type {
  823. unsigned int mem_bar;
  824. unsigned int mem_map_size;
  825. unsigned int txd_ptr_tbl_base;
  826. unsigned int rxd_ptr_tbl_base;
  827. unsigned int buf_tbl_base;
  828. unsigned int evq_ptr_tbl_base;
  829. unsigned int evq_rptr_tbl_base;
  830. unsigned int txd_ring_mask;
  831. unsigned int rxd_ring_mask;
  832. unsigned int evq_size;
  833. u64 max_dma_mask;
  834. unsigned int tx_dma_mask;
  835. unsigned bug5391_mask;
  836. int rx_xoff_thresh;
  837. int rx_xon_thresh;
  838. unsigned int rx_buffer_padding;
  839. unsigned int max_interrupt_mode;
  840. unsigned int phys_addr_channels;
  841. };
  842. /**************************************************************************
  843. *
  844. * Prototypes and inline functions
  845. *
  846. *************************************************************************/
  847. /* Iterate over all used channels */
  848. #define efx_for_each_channel(_channel, _efx) \
  849. for (_channel = &_efx->channel[0]; \
  850. _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
  851. _channel++) \
  852. if (!_channel->used_flags) \
  853. continue; \
  854. else
  855. /* Iterate over all used TX queues */
  856. #define efx_for_each_tx_queue(_tx_queue, _efx) \
  857. for (_tx_queue = &_efx->tx_queue[0]; \
  858. _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
  859. _tx_queue++)
  860. /* Iterate over all TX queues belonging to a channel */
  861. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  862. for (_tx_queue = &_channel->efx->tx_queue[0]; \
  863. _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
  864. _tx_queue++) \
  865. if (_tx_queue->channel != _channel) \
  866. continue; \
  867. else
  868. /* Iterate over all used RX queues */
  869. #define efx_for_each_rx_queue(_rx_queue, _efx) \
  870. for (_rx_queue = &_efx->rx_queue[0]; \
  871. _rx_queue < &_efx->rx_queue[_efx->n_rx_queues]; \
  872. _rx_queue++)
  873. /* Iterate over all RX queues belonging to a channel */
  874. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  875. for (_rx_queue = &_channel->efx->rx_queue[_channel->channel]; \
  876. _rx_queue; \
  877. _rx_queue = NULL) \
  878. if (_rx_queue->channel != _channel) \
  879. continue; \
  880. else
  881. /* Returns a pointer to the specified receive buffer in the RX
  882. * descriptor queue.
  883. */
  884. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  885. unsigned int index)
  886. {
  887. return (&rx_queue->buffer[index]);
  888. }
  889. /* Set bit in a little-endian bitfield */
  890. static inline void set_bit_le(unsigned nr, unsigned char *addr)
  891. {
  892. addr[nr / 8] |= (1 << (nr % 8));
  893. }
  894. /* Clear bit in a little-endian bitfield */
  895. static inline void clear_bit_le(unsigned nr, unsigned char *addr)
  896. {
  897. addr[nr / 8] &= ~(1 << (nr % 8));
  898. }
  899. /**
  900. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  901. *
  902. * This calculates the maximum frame length that will be used for a
  903. * given MTU. The frame length will be equal to the MTU plus a
  904. * constant amount of header space and padding. This is the quantity
  905. * that the net driver will program into the MAC as the maximum frame
  906. * length.
  907. *
  908. * The 10G MAC used in Falcon requires 8-byte alignment on the frame
  909. * length, so we round up to the nearest 8.
  910. */
  911. #define EFX_MAX_FRAME_LEN(mtu) \
  912. ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
  913. #endif /* EFX_NET_DRIVER_H */