net_driver.h 28 KB

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