net_driver.h 31 KB

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