net_driver.h 27 KB

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