net_driver.h 31 KB

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