net_driver.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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.2"
  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. * @read_count: Current read pointer.
  143. * This is the number of buffers that have been removed from both rings.
  144. * @stopped: Stopped count.
  145. * Set if this TX queue is currently stopping its port.
  146. * @insert_count: Current insert pointer
  147. * This is the number of buffers that have been added to the
  148. * software ring.
  149. * @write_count: Current write pointer
  150. * This is the number of buffers that have been added to the
  151. * hardware ring.
  152. * @old_read_count: The value of read_count when last checked.
  153. * This is here for performance reasons. The xmit path will
  154. * only get the up-to-date value of read_count if this
  155. * variable indicates that the queue is full. This is to
  156. * avoid cache-line ping-pong between the xmit path and the
  157. * completion path.
  158. * @tso_headers_free: A list of TSO headers allocated for this TX queue
  159. * that are not in use, and so available for new TSO sends. The list
  160. * is protected by the TX queue lock.
  161. * @tso_bursts: Number of times TSO xmit invoked by kernel
  162. * @tso_long_headers: Number of packets with headers too long for standard
  163. * blocks
  164. * @tso_packets: Number of packets via the TSO xmit path
  165. */
  166. struct efx_tx_queue {
  167. /* Members which don't change on the fast path */
  168. struct efx_nic *efx ____cacheline_aligned_in_smp;
  169. int queue;
  170. struct efx_channel *channel;
  171. struct efx_nic *nic;
  172. struct efx_tx_buffer *buffer;
  173. struct efx_special_buffer txd;
  174. /* Members used mainly on the completion path */
  175. unsigned int read_count ____cacheline_aligned_in_smp;
  176. int stopped;
  177. /* Members used only on the xmit path */
  178. unsigned int insert_count ____cacheline_aligned_in_smp;
  179. unsigned int write_count;
  180. unsigned int old_read_count;
  181. struct efx_tso_header *tso_headers_free;
  182. unsigned int tso_bursts;
  183. unsigned int tso_long_headers;
  184. unsigned int tso_packets;
  185. };
  186. /**
  187. * struct efx_rx_buffer - An Efx RX data buffer
  188. * @dma_addr: DMA base address of the buffer
  189. * @skb: The associated socket buffer, if any.
  190. * If both this and page are %NULL, the buffer slot is currently free.
  191. * @page: The associated page buffer, if any.
  192. * If both this and skb are %NULL, the buffer slot is currently free.
  193. * @data: Pointer to ethernet header
  194. * @len: Buffer length, in bytes.
  195. * @unmap_addr: DMA address to unmap
  196. */
  197. struct efx_rx_buffer {
  198. dma_addr_t dma_addr;
  199. struct sk_buff *skb;
  200. struct page *page;
  201. char *data;
  202. unsigned int len;
  203. dma_addr_t unmap_addr;
  204. };
  205. /**
  206. * struct efx_rx_queue - An Efx RX queue
  207. * @efx: The associated Efx NIC
  208. * @queue: DMA queue number
  209. * @channel: The associated channel
  210. * @buffer: The software buffer ring
  211. * @rxd: The hardware descriptor ring
  212. * @added_count: Number of buffers added to the receive queue.
  213. * @notified_count: Number of buffers given to NIC (<= @added_count).
  214. * @removed_count: Number of buffers removed from the receive queue.
  215. * @add_lock: Receive queue descriptor add spin lock.
  216. * This lock must be held in order to add buffers to the RX
  217. * descriptor ring (rxd and buffer) and to update added_count (but
  218. * not removed_count).
  219. * @max_fill: RX descriptor maximum fill level (<= ring size)
  220. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  221. * (<= @max_fill)
  222. * @fast_fill_limit: The level to which a fast fill will fill
  223. * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
  224. * @min_fill: RX descriptor minimum non-zero fill level.
  225. * This records the minimum fill level observed when a ring
  226. * refill was triggered.
  227. * @min_overfill: RX descriptor minimum overflow fill level.
  228. * This records the minimum fill level at which RX queue
  229. * overflow was observed. It should never be set.
  230. * @alloc_page_count: RX allocation strategy counter.
  231. * @alloc_skb_count: RX allocation strategy counter.
  232. * @work: Descriptor push work thread
  233. * @buf_page: Page for next RX buffer.
  234. * We can use a single page for multiple RX buffers. This tracks
  235. * the remaining space in the allocation.
  236. * @buf_dma_addr: Page's DMA address.
  237. * @buf_data: Page's host address.
  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. };
  262. /**
  263. * struct efx_buffer - An Efx general-purpose buffer
  264. * @addr: host base address of the buffer
  265. * @dma_addr: DMA base address of the buffer
  266. * @len: Buffer length, in bytes
  267. *
  268. * Falcon uses these buffers for its interrupt status registers and
  269. * MAC stats dumps.
  270. */
  271. struct efx_buffer {
  272. void *addr;
  273. dma_addr_t dma_addr;
  274. unsigned int len;
  275. };
  276. /* Flags for channel->used_flags */
  277. #define EFX_USED_BY_RX 1
  278. #define EFX_USED_BY_TX 2
  279. #define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
  280. enum efx_rx_alloc_method {
  281. RX_ALLOC_METHOD_AUTO = 0,
  282. RX_ALLOC_METHOD_SKB = 1,
  283. RX_ALLOC_METHOD_PAGE = 2,
  284. };
  285. /**
  286. * struct efx_channel - An Efx channel
  287. *
  288. * A channel comprises an event queue, at least one TX queue, at least
  289. * one RX queue, and an associated tasklet for processing the event
  290. * queue.
  291. *
  292. * @efx: Associated Efx NIC
  293. * @channel: Channel instance number
  294. * @used_flags: Channel is used by net driver
  295. * @enabled: Channel enabled indicator
  296. * @irq: IRQ number (MSI and MSI-X only)
  297. * @irq_moderation: IRQ moderation value (in us)
  298. * @napi_dev: Net device used with NAPI
  299. * @napi_str: NAPI control structure
  300. * @reset_work: Scheduled reset work thread
  301. * @work_pending: Is work pending via NAPI?
  302. * @eventq: Event queue buffer
  303. * @eventq_read_ptr: Event queue read pointer
  304. * @last_eventq_read_ptr: Last event queue read pointer value.
  305. * @eventq_magic: Event queue magic value for driver-generated test events
  306. * @lro_mgr: LRO state
  307. * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
  308. * and diagnostic counters
  309. * @rx_alloc_push_pages: RX allocation method currently in use for pushing
  310. * descriptors
  311. * @rx_alloc_pop_pages: RX allocation method currently in use for popping
  312. * descriptors
  313. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  314. * @n_rx_ip_frag_err: Count of RX IP fragment errors
  315. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  316. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  317. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  318. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  319. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  320. */
  321. struct efx_channel {
  322. struct efx_nic *efx;
  323. int channel;
  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. struct net_lro_mgr lro_mgr;
  336. int rx_alloc_level;
  337. int rx_alloc_push_pages;
  338. int rx_alloc_pop_pages;
  339. unsigned n_rx_tobe_disc;
  340. unsigned n_rx_ip_frag_err;
  341. unsigned n_rx_ip_hdr_chksum_err;
  342. unsigned n_rx_tcp_udp_chksum_err;
  343. unsigned n_rx_frm_trunc;
  344. unsigned n_rx_overlength;
  345. unsigned n_skbuff_leaks;
  346. /* Used to pipeline received packets in order to optimise memory
  347. * access with prefetches.
  348. */
  349. struct efx_rx_buffer *rx_pkt;
  350. bool rx_pkt_csummed;
  351. };
  352. /**
  353. * struct efx_blinker - S/W LED blinking context
  354. * @led_num: LED ID (board-specific meaning)
  355. * @state: Current state - on or off
  356. * @resubmit: Timer resubmission flag
  357. * @timer: Control timer for blinking
  358. */
  359. struct efx_blinker {
  360. int led_num;
  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
  372. * @set_fault_led: Turns the fault LED on or off
  373. * @blink: Starts/stops blinking
  374. * @fini: Cleanup function
  375. * @blinker: used to blink LEDs in software
  376. * @hwmon_client: I2C client for hardware monitor
  377. * @ioexp_client: I2C client for power/port control
  378. */
  379. struct efx_board {
  380. int type;
  381. int major;
  382. int minor;
  383. int (*init) (struct efx_nic *nic);
  384. /* As the LEDs are typically attached to the PHY, LEDs
  385. * have a separate init callback that happens later than
  386. * board init. */
  387. int (*init_leds)(struct efx_nic *efx);
  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_CX4_RTMR = 1,
  407. PHY_TYPE_1G_ALASKA = 2,
  408. PHY_TYPE_10XPRESS = 3,
  409. PHY_TYPE_XFP = 4,
  410. PHY_TYPE_PM8358 = 6,
  411. PHY_TYPE_MAX /* Insert any new items before this */
  412. };
  413. #define PHY_ADDR_INVALID 0xff
  414. enum nic_state {
  415. STATE_INIT = 0,
  416. STATE_RUNNING = 1,
  417. STATE_FINI = 2,
  418. STATE_DISABLED = 3,
  419. STATE_MAX,
  420. };
  421. /*
  422. * Alignment of page-allocated RX buffers
  423. *
  424. * Controls the number of bytes inserted at the start of an RX buffer.
  425. * This is the equivalent of NET_IP_ALIGN [which controls the alignment
  426. * of the skb->head for hardware DMA].
  427. */
  428. #if defined(__i386__) || defined(__x86_64__)
  429. #define EFX_PAGE_IP_ALIGN 0
  430. #else
  431. #define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
  432. #endif
  433. /*
  434. * Alignment of the skb->head which wraps a page-allocated RX buffer
  435. *
  436. * The skb allocated to wrap an rx_buffer can have this alignment. Since
  437. * the data is memcpy'd from the rx_buf, it does not need to be equal to
  438. * EFX_PAGE_IP_ALIGN.
  439. */
  440. #define EFX_PAGE_SKB_ALIGN 2
  441. /* Forward declaration */
  442. struct efx_nic;
  443. /* Pseudo bit-mask flow control field */
  444. enum efx_fc_type {
  445. EFX_FC_RX = 1,
  446. EFX_FC_TX = 2,
  447. EFX_FC_AUTO = 4,
  448. };
  449. /**
  450. * struct efx_phy_operations - Efx PHY operations table
  451. * @init: Initialise PHY
  452. * @fini: Shut down PHY
  453. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  454. * @clear_interrupt: Clear down interrupt
  455. * @blink: Blink LEDs
  456. * @check_hw: Check hardware
  457. * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
  458. * @mmds: MMD presence mask
  459. * @loopbacks: Supported loopback modes mask
  460. */
  461. struct efx_phy_operations {
  462. int (*init) (struct efx_nic *efx);
  463. void (*fini) (struct efx_nic *efx);
  464. void (*reconfigure) (struct efx_nic *efx);
  465. void (*clear_interrupt) (struct efx_nic *efx);
  466. int (*check_hw) (struct efx_nic *efx);
  467. void (*reset_xaui) (struct efx_nic *efx);
  468. int (*test) (struct efx_nic *efx);
  469. int mmds;
  470. unsigned loopbacks;
  471. };
  472. /**
  473. * @enum efx_phy_mode - PHY operating mode flags
  474. * @PHY_MODE_NORMAL: on and should pass traffic
  475. * @PHY_MODE_TX_DISABLED: on with TX disabled
  476. * @PHY_MODE_SPECIAL: on but will not pass traffic
  477. */
  478. enum efx_phy_mode {
  479. PHY_MODE_NORMAL = 0,
  480. PHY_MODE_TX_DISABLED = 1,
  481. PHY_MODE_SPECIAL = 8,
  482. };
  483. static inline bool efx_phy_mode_disabled(enum efx_phy_mode mode)
  484. {
  485. return !!(mode & ~PHY_MODE_TX_DISABLED);
  486. }
  487. /*
  488. * Efx extended statistics
  489. *
  490. * Not all statistics are provided by all supported MACs. The purpose
  491. * is this structure is to contain the raw statistics provided by each
  492. * MAC.
  493. */
  494. struct efx_mac_stats {
  495. u64 tx_bytes;
  496. u64 tx_good_bytes;
  497. u64 tx_bad_bytes;
  498. unsigned long tx_packets;
  499. unsigned long tx_bad;
  500. unsigned long tx_pause;
  501. unsigned long tx_control;
  502. unsigned long tx_unicast;
  503. unsigned long tx_multicast;
  504. unsigned long tx_broadcast;
  505. unsigned long tx_lt64;
  506. unsigned long tx_64;
  507. unsigned long tx_65_to_127;
  508. unsigned long tx_128_to_255;
  509. unsigned long tx_256_to_511;
  510. unsigned long tx_512_to_1023;
  511. unsigned long tx_1024_to_15xx;
  512. unsigned long tx_15xx_to_jumbo;
  513. unsigned long tx_gtjumbo;
  514. unsigned long tx_collision;
  515. unsigned long tx_single_collision;
  516. unsigned long tx_multiple_collision;
  517. unsigned long tx_excessive_collision;
  518. unsigned long tx_deferred;
  519. unsigned long tx_late_collision;
  520. unsigned long tx_excessive_deferred;
  521. unsigned long tx_non_tcpudp;
  522. unsigned long tx_mac_src_error;
  523. unsigned long tx_ip_src_error;
  524. u64 rx_bytes;
  525. u64 rx_good_bytes;
  526. u64 rx_bad_bytes;
  527. unsigned long rx_packets;
  528. unsigned long rx_good;
  529. unsigned long rx_bad;
  530. unsigned long rx_pause;
  531. unsigned long rx_control;
  532. unsigned long rx_unicast;
  533. unsigned long rx_multicast;
  534. unsigned long rx_broadcast;
  535. unsigned long rx_lt64;
  536. unsigned long rx_64;
  537. unsigned long rx_65_to_127;
  538. unsigned long rx_128_to_255;
  539. unsigned long rx_256_to_511;
  540. unsigned long rx_512_to_1023;
  541. unsigned long rx_1024_to_15xx;
  542. unsigned long rx_15xx_to_jumbo;
  543. unsigned long rx_gtjumbo;
  544. unsigned long rx_bad_lt64;
  545. unsigned long rx_bad_64_to_15xx;
  546. unsigned long rx_bad_15xx_to_jumbo;
  547. unsigned long rx_bad_gtjumbo;
  548. unsigned long rx_overflow;
  549. unsigned long rx_missed;
  550. unsigned long rx_false_carrier;
  551. unsigned long rx_symbol_error;
  552. unsigned long rx_align_error;
  553. unsigned long rx_length_error;
  554. unsigned long rx_internal_error;
  555. unsigned long rx_good_lt64;
  556. };
  557. /* Number of bits used in a multicast filter hash address */
  558. #define EFX_MCAST_HASH_BITS 8
  559. /* Number of (single-bit) entries in a multicast filter hash */
  560. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  561. /* An Efx multicast filter hash */
  562. union efx_multicast_hash {
  563. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  564. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  565. };
  566. /**
  567. * struct efx_nic - an Efx NIC
  568. * @name: Device name (net device name or bus id before net device registered)
  569. * @pci_dev: The PCI device
  570. * @type: Controller type attributes
  571. * @legacy_irq: IRQ number
  572. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  573. * Work items do not hold and must not acquire RTNL.
  574. * @reset_workqueue: Workqueue for resets. Work item will acquire RTNL.
  575. * @reset_work: Scheduled reset workitem
  576. * @monitor_work: Hardware monitor workitem
  577. * @membase_phys: Memory BAR value as physical address
  578. * @membase: Memory BAR value
  579. * @biu_lock: BIU (bus interface unit) lock
  580. * @interrupt_mode: Interrupt mode
  581. * @i2c_adap: I2C adapter
  582. * @board_info: Board-level information
  583. * @state: Device state flag. Serialised by the rtnl_lock.
  584. * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
  585. * @tx_queue: TX DMA queues
  586. * @rx_queue: RX DMA queues
  587. * @channel: Channels
  588. * @n_rx_queues: Number of RX queues
  589. * @rx_buffer_len: RX buffer length
  590. * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
  591. * @irq_status: Interrupt status buffer
  592. * @last_irq_cpu: Last CPU to handle interrupt.
  593. * This register is written with the SMP processor ID whenever an
  594. * interrupt is handled. It is used by falcon_test_interrupt()
  595. * to verify that an interrupt has occurred.
  596. * @spi_flash: SPI flash device
  597. * This field will be %NULL if no flash device is present.
  598. * @spi_eeprom: SPI EEPROM device
  599. * This field will be %NULL if no EEPROM device is present.
  600. * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
  601. * @nic_data: Hardware dependant state
  602. * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
  603. * @port_inhibited, efx_monitor() and efx_reconfigure_port()
  604. * @port_enabled: Port enabled indicator.
  605. * Serialises efx_stop_all(), efx_start_all() and efx_monitor() and
  606. * efx_reconfigure_work with kernel interfaces. Safe to read under any
  607. * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
  608. * be held to modify it.
  609. * @port_inhibited: If set, the netif_carrier is always off. Hold the mac_lock
  610. * @port_initialized: Port initialized?
  611. * @net_dev: Operating system network device. Consider holding the rtnl lock
  612. * @rx_checksum_enabled: RX checksumming enabled
  613. * @netif_stop_count: Port stop count
  614. * @netif_stop_lock: Port stop lock
  615. * @mac_stats: MAC statistics. These include all statistics the MACs
  616. * can provide. Generic code converts these into a standard
  617. * &struct net_device_stats.
  618. * @stats_buffer: DMA buffer for statistics
  619. * @stats_lock: Statistics update lock. Serialises statistics fetches
  620. * @stats_enabled: Temporarily disable statistics fetches.
  621. * Serialised by @stats_lock
  622. * @mac_address: Permanent MAC address
  623. * @phy_type: PHY type
  624. * @phy_lock: PHY access lock
  625. * @phy_op: PHY interface
  626. * @phy_data: PHY private data (including PHY-specific stats)
  627. * @mii: PHY interface
  628. * @phy_mode: PHY operating mode. Serialised by @mac_lock.
  629. * @link_up: Link status
  630. * @link_options: Link options (MII/GMII format)
  631. * @n_link_state_changes: Number of times the link has changed state
  632. * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
  633. * @multicast_hash: Multicast hash table
  634. * @flow_control: Flow control flags - separate RX/TX so can't use link_options
  635. * @reconfigure_work: work item for dealing with PHY events
  636. * @loopback_mode: Loopback status
  637. * @loopback_modes: Supported loopback mode bitmask
  638. * @loopback_selftest: Offline self-test private state
  639. *
  640. * The @priv field of the corresponding &struct net_device points to
  641. * this.
  642. */
  643. struct efx_nic {
  644. char name[IFNAMSIZ];
  645. struct pci_dev *pci_dev;
  646. const struct efx_nic_type *type;
  647. int legacy_irq;
  648. struct workqueue_struct *workqueue;
  649. struct workqueue_struct *reset_workqueue;
  650. struct work_struct reset_work;
  651. struct delayed_work monitor_work;
  652. resource_size_t membase_phys;
  653. void __iomem *membase;
  654. spinlock_t biu_lock;
  655. enum efx_int_mode interrupt_mode;
  656. struct i2c_adapter i2c_adap;
  657. struct efx_board board_info;
  658. enum nic_state state;
  659. enum reset_type reset_pending;
  660. struct efx_tx_queue tx_queue[EFX_TX_QUEUE_COUNT];
  661. struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
  662. struct efx_channel channel[EFX_MAX_CHANNELS];
  663. int n_rx_queues;
  664. unsigned int rx_buffer_len;
  665. unsigned int rx_buffer_order;
  666. struct efx_buffer irq_status;
  667. volatile signed int last_irq_cpu;
  668. struct efx_spi_device *spi_flash;
  669. struct efx_spi_device *spi_eeprom;
  670. unsigned n_rx_nodesc_drop_cnt;
  671. struct falcon_nic_data *nic_data;
  672. struct mutex mac_lock;
  673. bool port_enabled;
  674. bool port_inhibited;
  675. bool port_initialized;
  676. struct net_device *net_dev;
  677. bool rx_checksum_enabled;
  678. atomic_t netif_stop_count;
  679. spinlock_t netif_stop_lock;
  680. struct efx_mac_stats mac_stats;
  681. struct efx_buffer stats_buffer;
  682. spinlock_t stats_lock;
  683. bool stats_enabled;
  684. unsigned char mac_address[ETH_ALEN];
  685. enum phy_type phy_type;
  686. spinlock_t phy_lock;
  687. struct efx_phy_operations *phy_op;
  688. void *phy_data;
  689. struct mii_if_info mii;
  690. enum efx_phy_mode phy_mode;
  691. bool link_up;
  692. unsigned int link_options;
  693. unsigned int n_link_state_changes;
  694. bool promiscuous;
  695. union efx_multicast_hash multicast_hash;
  696. enum efx_fc_type flow_control;
  697. struct work_struct reconfigure_work;
  698. atomic_t rx_reset;
  699. enum efx_loopback_mode loopback_mode;
  700. unsigned int loopback_modes;
  701. void *loopback_selftest;
  702. };
  703. static inline int efx_dev_registered(struct efx_nic *efx)
  704. {
  705. return efx->net_dev->reg_state == NETREG_REGISTERED;
  706. }
  707. /* Net device name, for inclusion in log messages if it has been registered.
  708. * Use efx->name not efx->net_dev->name so that races with (un)registration
  709. * are harmless.
  710. */
  711. static inline const char *efx_dev_name(struct efx_nic *efx)
  712. {
  713. return efx_dev_registered(efx) ? efx->name : "";
  714. }
  715. /**
  716. * struct efx_nic_type - Efx device type definition
  717. * @mem_bar: Memory BAR number
  718. * @mem_map_size: Memory BAR mapped size
  719. * @txd_ptr_tbl_base: TX descriptor ring base address
  720. * @rxd_ptr_tbl_base: RX descriptor ring base address
  721. * @buf_tbl_base: Buffer table base address
  722. * @evq_ptr_tbl_base: Event queue pointer table base address
  723. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  724. * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
  725. * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
  726. * @evq_size: Event queue size (must be a power of two)
  727. * @max_dma_mask: Maximum possible DMA mask
  728. * @tx_dma_mask: TX DMA mask
  729. * @bug5391_mask: Address mask for bug 5391 workaround
  730. * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
  731. * @rx_xon_thresh: RX FIFO XON watermark (bytes)
  732. * @rx_buffer_padding: Padding added to each RX buffer
  733. * @max_interrupt_mode: Highest capability interrupt mode supported
  734. * from &enum efx_init_mode.
  735. * @phys_addr_channels: Number of channels with physically addressed
  736. * descriptors
  737. */
  738. struct efx_nic_type {
  739. unsigned int mem_bar;
  740. unsigned int mem_map_size;
  741. unsigned int txd_ptr_tbl_base;
  742. unsigned int rxd_ptr_tbl_base;
  743. unsigned int buf_tbl_base;
  744. unsigned int evq_ptr_tbl_base;
  745. unsigned int evq_rptr_tbl_base;
  746. unsigned int txd_ring_mask;
  747. unsigned int rxd_ring_mask;
  748. unsigned int evq_size;
  749. u64 max_dma_mask;
  750. unsigned int tx_dma_mask;
  751. unsigned bug5391_mask;
  752. int rx_xoff_thresh;
  753. int rx_xon_thresh;
  754. unsigned int rx_buffer_padding;
  755. unsigned int max_interrupt_mode;
  756. unsigned int phys_addr_channels;
  757. };
  758. /**************************************************************************
  759. *
  760. * Prototypes and inline functions
  761. *
  762. *************************************************************************/
  763. /* Iterate over all used channels */
  764. #define efx_for_each_channel(_channel, _efx) \
  765. for (_channel = &_efx->channel[0]; \
  766. _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
  767. _channel++) \
  768. if (!_channel->used_flags) \
  769. continue; \
  770. else
  771. /* Iterate over all used TX queues */
  772. #define efx_for_each_tx_queue(_tx_queue, _efx) \
  773. for (_tx_queue = &_efx->tx_queue[0]; \
  774. _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
  775. _tx_queue++)
  776. /* Iterate over all TX queues belonging to a channel */
  777. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  778. for (_tx_queue = &_channel->efx->tx_queue[0]; \
  779. _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
  780. _tx_queue++) \
  781. if (_tx_queue->channel != _channel) \
  782. continue; \
  783. else
  784. /* Iterate over all used RX queues */
  785. #define efx_for_each_rx_queue(_rx_queue, _efx) \
  786. for (_rx_queue = &_efx->rx_queue[0]; \
  787. _rx_queue < &_efx->rx_queue[_efx->n_rx_queues]; \
  788. _rx_queue++)
  789. /* Iterate over all RX queues belonging to a channel */
  790. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  791. for (_rx_queue = &_channel->efx->rx_queue[_channel->channel]; \
  792. _rx_queue; \
  793. _rx_queue = NULL) \
  794. if (_rx_queue->channel != _channel) \
  795. continue; \
  796. else
  797. /* Returns a pointer to the specified receive buffer in the RX
  798. * descriptor queue.
  799. */
  800. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  801. unsigned int index)
  802. {
  803. return (&rx_queue->buffer[index]);
  804. }
  805. /* Set bit in a little-endian bitfield */
  806. static inline void set_bit_le(unsigned nr, unsigned char *addr)
  807. {
  808. addr[nr / 8] |= (1 << (nr % 8));
  809. }
  810. /* Clear bit in a little-endian bitfield */
  811. static inline void clear_bit_le(unsigned nr, unsigned char *addr)
  812. {
  813. addr[nr / 8] &= ~(1 << (nr % 8));
  814. }
  815. /**
  816. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  817. *
  818. * This calculates the maximum frame length that will be used for a
  819. * given MTU. The frame length will be equal to the MTU plus a
  820. * constant amount of header space and padding. This is the quantity
  821. * that the net driver will program into the MAC as the maximum frame
  822. * length.
  823. *
  824. * The 10G MAC used in Falcon requires 8-byte alignment on the frame
  825. * length, so we round up to the nearest 8.
  826. */
  827. #define EFX_MAX_FRAME_LEN(mtu) \
  828. ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
  829. #endif /* EFX_NET_DRIVER_H */