net_driver.h 27 KB

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