net_driver.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. unsigned char continuation;
  121. unsigned char 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 flag.
  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. * @used: Queue is used by net driver
  210. * @channel: The associated channel
  211. * @buffer: The software buffer ring
  212. * @rxd: The hardware descriptor ring
  213. * @added_count: Number of buffers added to the receive queue.
  214. * @notified_count: Number of buffers given to NIC (<= @added_count).
  215. * @removed_count: Number of buffers removed from the receive queue.
  216. * @add_lock: Receive queue descriptor add spin lock.
  217. * This lock must be held in order to add buffers to the RX
  218. * descriptor ring (rxd and buffer) and to update added_count (but
  219. * not removed_count).
  220. * @max_fill: RX descriptor maximum fill level (<= ring size)
  221. * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
  222. * (<= @max_fill)
  223. * @fast_fill_limit: The level to which a fast fill will fill
  224. * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
  225. * @min_fill: RX descriptor minimum non-zero fill level.
  226. * This records the minimum fill level observed when a ring
  227. * refill was triggered.
  228. * @min_overfill: RX descriptor minimum overflow fill level.
  229. * This records the minimum fill level at which RX queue
  230. * overflow was observed. It should never be set.
  231. * @alloc_page_count: RX allocation strategy counter.
  232. * @alloc_skb_count: RX allocation strategy counter.
  233. * @work: Descriptor push work thread
  234. * @buf_page: Page for next RX buffer.
  235. * We can use a single page for multiple RX buffers. This tracks
  236. * the remaining space in the allocation.
  237. * @buf_dma_addr: Page's DMA address.
  238. * @buf_data: Page's host address.
  239. */
  240. struct efx_rx_queue {
  241. struct efx_nic *efx;
  242. int queue;
  243. int used;
  244. struct efx_channel *channel;
  245. struct efx_rx_buffer *buffer;
  246. struct efx_special_buffer rxd;
  247. int added_count;
  248. int notified_count;
  249. int removed_count;
  250. spinlock_t add_lock;
  251. unsigned int max_fill;
  252. unsigned int fast_fill_trigger;
  253. unsigned int fast_fill_limit;
  254. unsigned int min_fill;
  255. unsigned int min_overfill;
  256. unsigned int alloc_page_count;
  257. unsigned int alloc_skb_count;
  258. struct delayed_work work;
  259. unsigned int slow_fill_count;
  260. struct page *buf_page;
  261. dma_addr_t buf_dma_addr;
  262. char *buf_data;
  263. };
  264. /**
  265. * struct efx_buffer - An Efx general-purpose buffer
  266. * @addr: host base address of the buffer
  267. * @dma_addr: DMA base address of the buffer
  268. * @len: Buffer length, in bytes
  269. *
  270. * Falcon uses these buffers for its interrupt status registers and
  271. * MAC stats dumps.
  272. */
  273. struct efx_buffer {
  274. void *addr;
  275. dma_addr_t dma_addr;
  276. unsigned int len;
  277. };
  278. /* Flags for channel->used_flags */
  279. #define EFX_USED_BY_RX 1
  280. #define EFX_USED_BY_TX 2
  281. #define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
  282. enum efx_rx_alloc_method {
  283. RX_ALLOC_METHOD_AUTO = 0,
  284. RX_ALLOC_METHOD_SKB = 1,
  285. RX_ALLOC_METHOD_PAGE = 2,
  286. };
  287. /**
  288. * struct efx_channel - An Efx channel
  289. *
  290. * A channel comprises an event queue, at least one TX queue, at least
  291. * one RX queue, and an associated tasklet for processing the event
  292. * queue.
  293. *
  294. * @efx: Associated Efx NIC
  295. * @evqnum: Event queue number
  296. * @channel: Channel instance number
  297. * @used_flags: Channel is used by net driver
  298. * @enabled: Channel enabled indicator
  299. * @irq: IRQ number (MSI and MSI-X only)
  300. * @has_interrupt: Channel has an interrupt
  301. * @irq_moderation: IRQ moderation value (in us)
  302. * @napi_dev: Net device used with NAPI
  303. * @napi_str: NAPI control structure
  304. * @reset_work: Scheduled reset work thread
  305. * @work_pending: Is work pending via NAPI?
  306. * @eventq: Event queue buffer
  307. * @eventq_read_ptr: Event queue read pointer
  308. * @last_eventq_read_ptr: Last event queue read pointer value.
  309. * @eventq_magic: Event queue magic value for driver-generated test events
  310. * @lro_mgr: LRO state
  311. * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
  312. * and diagnostic counters
  313. * @rx_alloc_push_pages: RX allocation method currently in use for pushing
  314. * descriptors
  315. * @rx_alloc_pop_pages: RX allocation method currently in use for popping
  316. * descriptors
  317. * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
  318. * @n_rx_ip_frag_err: Count of RX IP fragment errors
  319. * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
  320. * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
  321. * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
  322. * @n_rx_overlength: Count of RX_OVERLENGTH errors
  323. * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
  324. */
  325. struct efx_channel {
  326. struct efx_nic *efx;
  327. int evqnum;
  328. int channel;
  329. int used_flags;
  330. int enabled;
  331. int irq;
  332. unsigned int has_interrupt;
  333. unsigned int irq_moderation;
  334. struct net_device *napi_dev;
  335. struct napi_struct napi_str;
  336. int work_pending;
  337. struct efx_special_buffer eventq;
  338. unsigned int eventq_read_ptr;
  339. unsigned int last_eventq_read_ptr;
  340. unsigned int eventq_magic;
  341. struct net_lro_mgr lro_mgr;
  342. int rx_alloc_level;
  343. int rx_alloc_push_pages;
  344. int rx_alloc_pop_pages;
  345. unsigned n_rx_tobe_disc;
  346. unsigned n_rx_ip_frag_err;
  347. unsigned n_rx_ip_hdr_chksum_err;
  348. unsigned n_rx_tcp_udp_chksum_err;
  349. unsigned n_rx_frm_trunc;
  350. unsigned n_rx_overlength;
  351. unsigned n_skbuff_leaks;
  352. /* Used to pipeline received packets in order to optimise memory
  353. * access with prefetches.
  354. */
  355. struct efx_rx_buffer *rx_pkt;
  356. int rx_pkt_csummed;
  357. };
  358. /**
  359. * struct efx_blinker - S/W LED blinking context
  360. * @led_num: LED ID (board-specific meaning)
  361. * @state: Current state - on or off
  362. * @resubmit: Timer resubmission flag
  363. * @timer: Control timer for blinking
  364. */
  365. struct efx_blinker {
  366. int led_num;
  367. int state;
  368. int resubmit;
  369. struct timer_list timer;
  370. };
  371. /**
  372. * struct efx_board - board information
  373. * @type: Board model type
  374. * @major: Major rev. ('A', 'B' ...)
  375. * @minor: Minor rev. (0, 1, ...)
  376. * @init: Initialisation function
  377. * @init_leds: Sets up board LEDs
  378. * @set_fault_led: Turns the fault LED on or off
  379. * @blink: Starts/stops blinking
  380. * @fini: Cleanup function
  381. * @blinker: used to blink LEDs in software
  382. * @hwmon_client: I2C client for hardware monitor
  383. * @ioexp_client: I2C client for power/port control
  384. */
  385. struct efx_board {
  386. int type;
  387. int major;
  388. int minor;
  389. int (*init) (struct efx_nic *nic);
  390. /* As the LEDs are typically attached to the PHY, LEDs
  391. * have a separate init callback that happens later than
  392. * board init. */
  393. int (*init_leds)(struct efx_nic *efx);
  394. void (*set_fault_led) (struct efx_nic *efx, int state);
  395. void (*blink) (struct efx_nic *efx, int start);
  396. void (*fini) (struct efx_nic *nic);
  397. struct efx_blinker blinker;
  398. struct i2c_client *hwmon_client, *ioexp_client;
  399. };
  400. #define STRING_TABLE_LOOKUP(val, member) \
  401. member ## _names[val]
  402. enum efx_int_mode {
  403. /* Be careful if altering to correct macro below */
  404. EFX_INT_MODE_MSIX = 0,
  405. EFX_INT_MODE_MSI = 1,
  406. EFX_INT_MODE_LEGACY = 2,
  407. EFX_INT_MODE_MAX /* Insert any new items before this */
  408. };
  409. #define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
  410. enum phy_type {
  411. PHY_TYPE_NONE = 0,
  412. PHY_TYPE_CX4_RTMR = 1,
  413. PHY_TYPE_1G_ALASKA = 2,
  414. PHY_TYPE_10XPRESS = 3,
  415. PHY_TYPE_XFP = 4,
  416. PHY_TYPE_PM8358 = 6,
  417. PHY_TYPE_MAX /* Insert any new items before this */
  418. };
  419. #define PHY_ADDR_INVALID 0xff
  420. enum nic_state {
  421. STATE_INIT = 0,
  422. STATE_RUNNING = 1,
  423. STATE_FINI = 2,
  424. STATE_RESETTING = 3, /* rtnl_lock always held */
  425. STATE_DISABLED = 4,
  426. STATE_MAX,
  427. };
  428. /*
  429. * Alignment of page-allocated RX buffers
  430. *
  431. * Controls the number of bytes inserted at the start of an RX buffer.
  432. * This is the equivalent of NET_IP_ALIGN [which controls the alignment
  433. * of the skb->head for hardware DMA].
  434. */
  435. #if defined(__i386__) || defined(__x86_64__)
  436. #define EFX_PAGE_IP_ALIGN 0
  437. #else
  438. #define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
  439. #endif
  440. /*
  441. * Alignment of the skb->head which wraps a page-allocated RX buffer
  442. *
  443. * The skb allocated to wrap an rx_buffer can have this alignment. Since
  444. * the data is memcpy'd from the rx_buf, it does not need to be equal to
  445. * EFX_PAGE_IP_ALIGN.
  446. */
  447. #define EFX_PAGE_SKB_ALIGN 2
  448. /* Forward declaration */
  449. struct efx_nic;
  450. /* Pseudo bit-mask flow control field */
  451. enum efx_fc_type {
  452. EFX_FC_RX = 1,
  453. EFX_FC_TX = 2,
  454. EFX_FC_AUTO = 4,
  455. };
  456. /**
  457. * struct efx_phy_operations - Efx PHY operations table
  458. * @init: Initialise PHY
  459. * @fini: Shut down PHY
  460. * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
  461. * @clear_interrupt: Clear down interrupt
  462. * @blink: Blink LEDs
  463. * @check_hw: Check hardware
  464. * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
  465. * @mmds: MMD presence mask
  466. * @loopbacks: Supported loopback modes mask
  467. */
  468. struct efx_phy_operations {
  469. int (*init) (struct efx_nic *efx);
  470. void (*fini) (struct efx_nic *efx);
  471. void (*reconfigure) (struct efx_nic *efx);
  472. void (*clear_interrupt) (struct efx_nic *efx);
  473. int (*check_hw) (struct efx_nic *efx);
  474. void (*reset_xaui) (struct efx_nic *efx);
  475. int mmds;
  476. unsigned loopbacks;
  477. };
  478. /*
  479. * Efx extended statistics
  480. *
  481. * Not all statistics are provided by all supported MACs. The purpose
  482. * is this structure is to contain the raw statistics provided by each
  483. * MAC.
  484. */
  485. struct efx_mac_stats {
  486. u64 tx_bytes;
  487. u64 tx_good_bytes;
  488. u64 tx_bad_bytes;
  489. unsigned long tx_packets;
  490. unsigned long tx_bad;
  491. unsigned long tx_pause;
  492. unsigned long tx_control;
  493. unsigned long tx_unicast;
  494. unsigned long tx_multicast;
  495. unsigned long tx_broadcast;
  496. unsigned long tx_lt64;
  497. unsigned long tx_64;
  498. unsigned long tx_65_to_127;
  499. unsigned long tx_128_to_255;
  500. unsigned long tx_256_to_511;
  501. unsigned long tx_512_to_1023;
  502. unsigned long tx_1024_to_15xx;
  503. unsigned long tx_15xx_to_jumbo;
  504. unsigned long tx_gtjumbo;
  505. unsigned long tx_collision;
  506. unsigned long tx_single_collision;
  507. unsigned long tx_multiple_collision;
  508. unsigned long tx_excessive_collision;
  509. unsigned long tx_deferred;
  510. unsigned long tx_late_collision;
  511. unsigned long tx_excessive_deferred;
  512. unsigned long tx_non_tcpudp;
  513. unsigned long tx_mac_src_error;
  514. unsigned long tx_ip_src_error;
  515. u64 rx_bytes;
  516. u64 rx_good_bytes;
  517. u64 rx_bad_bytes;
  518. unsigned long rx_packets;
  519. unsigned long rx_good;
  520. unsigned long rx_bad;
  521. unsigned long rx_pause;
  522. unsigned long rx_control;
  523. unsigned long rx_unicast;
  524. unsigned long rx_multicast;
  525. unsigned long rx_broadcast;
  526. unsigned long rx_lt64;
  527. unsigned long rx_64;
  528. unsigned long rx_65_to_127;
  529. unsigned long rx_128_to_255;
  530. unsigned long rx_256_to_511;
  531. unsigned long rx_512_to_1023;
  532. unsigned long rx_1024_to_15xx;
  533. unsigned long rx_15xx_to_jumbo;
  534. unsigned long rx_gtjumbo;
  535. unsigned long rx_bad_lt64;
  536. unsigned long rx_bad_64_to_15xx;
  537. unsigned long rx_bad_15xx_to_jumbo;
  538. unsigned long rx_bad_gtjumbo;
  539. unsigned long rx_overflow;
  540. unsigned long rx_missed;
  541. unsigned long rx_false_carrier;
  542. unsigned long rx_symbol_error;
  543. unsigned long rx_align_error;
  544. unsigned long rx_length_error;
  545. unsigned long rx_internal_error;
  546. unsigned long rx_good_lt64;
  547. };
  548. /* Number of bits used in a multicast filter hash address */
  549. #define EFX_MCAST_HASH_BITS 8
  550. /* Number of (single-bit) entries in a multicast filter hash */
  551. #define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
  552. /* An Efx multicast filter hash */
  553. union efx_multicast_hash {
  554. u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
  555. efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
  556. };
  557. /**
  558. * struct efx_nic - an Efx NIC
  559. * @name: Device name (net device name or bus id before net device registered)
  560. * @pci_dev: The PCI device
  561. * @type: Controller type attributes
  562. * @legacy_irq: IRQ number
  563. * @workqueue: Workqueue for port reconfigures and the HW monitor.
  564. * Work items do not hold and must not acquire RTNL.
  565. * @reset_workqueue: Workqueue for resets. Work item will acquire RTNL.
  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_adap: I2C adapter
  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 workqueue_struct *reset_workqueue;
  634. struct work_struct reset_work;
  635. struct delayed_work monitor_work;
  636. resource_size_t membase_phys;
  637. void __iomem *membase;
  638. spinlock_t biu_lock;
  639. enum efx_int_mode interrupt_mode;
  640. struct i2c_adapter i2c_adap;
  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_TX_QUEUE_COUNT];
  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. struct falcon_nic_data *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. unsigned tx_disabled;
  671. int link_up;
  672. unsigned int link_options;
  673. unsigned int n_link_state_changes;
  674. int promiscuous;
  675. union efx_multicast_hash multicast_hash;
  676. enum efx_fc_type flow_control;
  677. struct work_struct reconfigure_work;
  678. atomic_t rx_reset;
  679. enum efx_loopback_mode loopback_mode;
  680. unsigned int loopback_modes;
  681. void *loopback_selftest;
  682. };
  683. static inline int efx_dev_registered(struct efx_nic *efx)
  684. {
  685. return efx->net_dev->reg_state == NETREG_REGISTERED;
  686. }
  687. /* Net device name, for inclusion in log messages if it has been registered.
  688. * Use efx->name not efx->net_dev->name so that races with (un)registration
  689. * are harmless.
  690. */
  691. static inline const char *efx_dev_name(struct efx_nic *efx)
  692. {
  693. return efx_dev_registered(efx) ? efx->name : "";
  694. }
  695. /**
  696. * struct efx_nic_type - Efx device type definition
  697. * @mem_bar: Memory BAR number
  698. * @mem_map_size: Memory BAR mapped size
  699. * @txd_ptr_tbl_base: TX descriptor ring base address
  700. * @rxd_ptr_tbl_base: RX descriptor ring base address
  701. * @buf_tbl_base: Buffer table base address
  702. * @evq_ptr_tbl_base: Event queue pointer table base address
  703. * @evq_rptr_tbl_base: Event queue read-pointer table base address
  704. * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
  705. * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
  706. * @evq_size: Event queue size (must be a power of two)
  707. * @max_dma_mask: Maximum possible DMA mask
  708. * @tx_dma_mask: TX DMA mask
  709. * @bug5391_mask: Address mask for bug 5391 workaround
  710. * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
  711. * @rx_xon_thresh: RX FIFO XON watermark (bytes)
  712. * @rx_buffer_padding: Padding added to each RX buffer
  713. * @max_interrupt_mode: Highest capability interrupt mode supported
  714. * from &enum efx_init_mode.
  715. * @phys_addr_channels: Number of channels with physically addressed
  716. * descriptors
  717. */
  718. struct efx_nic_type {
  719. unsigned int mem_bar;
  720. unsigned int mem_map_size;
  721. unsigned int txd_ptr_tbl_base;
  722. unsigned int rxd_ptr_tbl_base;
  723. unsigned int buf_tbl_base;
  724. unsigned int evq_ptr_tbl_base;
  725. unsigned int evq_rptr_tbl_base;
  726. unsigned int txd_ring_mask;
  727. unsigned int rxd_ring_mask;
  728. unsigned int evq_size;
  729. u64 max_dma_mask;
  730. unsigned int tx_dma_mask;
  731. unsigned bug5391_mask;
  732. int rx_xoff_thresh;
  733. int rx_xon_thresh;
  734. unsigned int rx_buffer_padding;
  735. unsigned int max_interrupt_mode;
  736. unsigned int phys_addr_channels;
  737. };
  738. /**************************************************************************
  739. *
  740. * Prototypes and inline functions
  741. *
  742. *************************************************************************/
  743. /* Iterate over all used channels */
  744. #define efx_for_each_channel(_channel, _efx) \
  745. for (_channel = &_efx->channel[0]; \
  746. _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
  747. _channel++) \
  748. if (!_channel->used_flags) \
  749. continue; \
  750. else
  751. /* Iterate over all used channels with interrupts */
  752. #define efx_for_each_channel_with_interrupt(_channel, _efx) \
  753. for (_channel = &_efx->channel[0]; \
  754. _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
  755. _channel++) \
  756. if (!(_channel->used_flags && _channel->has_interrupt)) \
  757. continue; \
  758. else
  759. /* Iterate over all used TX queues */
  760. #define efx_for_each_tx_queue(_tx_queue, _efx) \
  761. for (_tx_queue = &_efx->tx_queue[0]; \
  762. _tx_queue < &_efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
  763. _tx_queue++)
  764. /* Iterate over all TX queues belonging to a channel */
  765. #define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
  766. for (_tx_queue = &_channel->efx->tx_queue[0]; \
  767. _tx_queue < &_channel->efx->tx_queue[EFX_TX_QUEUE_COUNT]; \
  768. _tx_queue++) \
  769. if (_tx_queue->channel != _channel) \
  770. continue; \
  771. else
  772. /* Iterate over all used RX queues */
  773. #define efx_for_each_rx_queue(_rx_queue, _efx) \
  774. for (_rx_queue = &_efx->rx_queue[0]; \
  775. _rx_queue < &_efx->rx_queue[EFX_MAX_RX_QUEUES]; \
  776. _rx_queue++) \
  777. if (!_rx_queue->used) \
  778. continue; \
  779. else
  780. /* Iterate over all RX queues belonging to a channel */
  781. #define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
  782. for (_rx_queue = &_channel->efx->rx_queue[0]; \
  783. _rx_queue < &_channel->efx->rx_queue[EFX_MAX_RX_QUEUES]; \
  784. _rx_queue++) \
  785. if ((!_rx_queue->used) || \
  786. (_rx_queue->channel != _channel)) \
  787. continue; \
  788. else
  789. /* Returns a pointer to the specified receive buffer in the RX
  790. * descriptor queue.
  791. */
  792. static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
  793. unsigned int index)
  794. {
  795. return (&rx_queue->buffer[index]);
  796. }
  797. /* Set bit in a little-endian bitfield */
  798. static inline void set_bit_le(unsigned nr, unsigned char *addr)
  799. {
  800. addr[nr / 8] |= (1 << (nr % 8));
  801. }
  802. /* Clear bit in a little-endian bitfield */
  803. static inline void clear_bit_le(unsigned nr, unsigned char *addr)
  804. {
  805. addr[nr / 8] &= ~(1 << (nr % 8));
  806. }
  807. /**
  808. * EFX_MAX_FRAME_LEN - calculate maximum frame length
  809. *
  810. * This calculates the maximum frame length that will be used for a
  811. * given MTU. The frame length will be equal to the MTU plus a
  812. * constant amount of header space and padding. This is the quantity
  813. * that the net driver will program into the MAC as the maximum frame
  814. * length.
  815. *
  816. * The 10G MAC used in Falcon requires 8-byte alignment on the frame
  817. * length, so we round up to the nearest 8.
  818. */
  819. #define EFX_MAX_FRAME_LEN(mtu) \
  820. ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
  821. #endif /* EFX_NET_DRIVER_H */