PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/sys/dev/netif/ixgbe/ixgbe.h

https://bitbucket.org/cooljeanius/dragonflybsd
C Header | 514 lines | 314 code | 68 blank | 132 comment | 11 complexity | 22149c62384a611d3ca0fbee8f3a0a6b MD5 | raw file
  1. /******************************************************************************
  2. Copyright (c) 2001-2012, Intel Corporation
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. 3. Neither the name of the Intel Corporation nor the names of its
  12. contributors may be used to endorse or promote products derived from
  13. this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. POSSIBILITY OF SUCH DAMAGE.
  25. ******************************************************************************/
  26. /*$FreeBSD: src/sys/dev/ixgbe/ixgbe.h,v 1.26 2012/04/23 22:05:09 bz Exp $*/
  27. #ifndef _IXGBE_H_
  28. #define _IXGBE_H_
  29. #include <sys/param.h>
  30. #include <sys/systm.h>
  31. #include <sys/mbuf.h>
  32. #include <sys/protosw.h>
  33. #include <sys/socket.h>
  34. #include <sys/malloc.h>
  35. #include <sys/kernel.h>
  36. #include <sys/module.h>
  37. #include <sys/sockio.h>
  38. #include <net/if.h>
  39. #include <net/if_arp.h>
  40. #include <net/ifq_var.h>
  41. #include <net/bpf.h>
  42. #include <net/ethernet.h>
  43. #include <net/if_dl.h>
  44. #include <net/if_media.h>
  45. #include <net/bpf.h>
  46. #include <net/if_types.h>
  47. #include <net/vlan/if_vlan_var.h>
  48. #include <net/vlan/if_vlan_ether.h>
  49. #include <netinet/in_systm.h>
  50. #include <netinet/in.h>
  51. #include <netinet/if_ether.h>
  52. #include <netinet/ip.h>
  53. #include <netinet/ip6.h>
  54. #include <netinet/tcp.h>
  55. #ifdef NET_LRO
  56. #include <netinet/tcp_lro.h> /* XXX: IPv4 only */
  57. #endif
  58. #include <netinet/udp.h>
  59. #include <sys/in_cksum.h>
  60. #include <sys/bus.h>
  61. #include <sys/rman.h>
  62. #include <sys/resource.h>
  63. #include <vm/vm.h>
  64. #include <vm/pmap.h>
  65. #include <machine/clock.h>
  66. #include <bus/pci/pcivar.h>
  67. #include <bus/pci/pcireg.h>
  68. #include <sys/proc.h>
  69. #include <sys/sysctl.h>
  70. #include <sys/endian.h>
  71. #include <sys/taskqueue.h>
  72. #include <machine/smp.h>
  73. #include <sys/spinlock.h>
  74. #include <sys/spinlock2.h>
  75. #ifdef IXGBE_IEEE1588
  76. #include <sys/ieee1588.h>
  77. #endif
  78. #include "ixgbe_api.h"
  79. #include "ixgbe_defines.h"
  80. /* Tunables */
  81. /*
  82. * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
  83. * number of transmit descriptors allocated by the driver. Increasing this
  84. * value allows the driver to queue more transmits. Each descriptor is 16
  85. * bytes. Performance tests have show the 2K value to be optimal for top
  86. * performance.
  87. */
  88. #define DEFAULT_TXD 1024
  89. #define PERFORM_TXD 2048
  90. #define MAX_TXD 4096
  91. #define MIN_TXD 64
  92. /*
  93. * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
  94. * number of receive descriptors allocated for each RX queue. Increasing this
  95. * value allows the driver to buffer more incoming packets. Each descriptor
  96. * is 16 bytes. A receive buffer is also allocated for each descriptor.
  97. *
  98. * Note: with 8 rings and a dual port card, it is possible to bump up
  99. * against the system mbuf pool limit, you can tune nmbclusters
  100. * to adjust for this.
  101. */
  102. #define DEFAULT_RXD 1024
  103. #define PERFORM_RXD 2048
  104. #define MAX_RXD 4096
  105. #define MIN_RXD 64
  106. /* Alignment for rings */
  107. #define DBA_ALIGN 128
  108. /*
  109. * This parameter controls the maximum no of times the driver will loop in
  110. * the isr. Minimum Value = 1
  111. */
  112. #define MAX_LOOP 10
  113. /*
  114. * This is the max watchdog interval, ie. the time that can
  115. * pass between any two TX clean operations, such only happening
  116. * when the TX hardware is functioning.
  117. */
  118. #define IXGBE_WATCHDOG (10 * hz)
  119. /*
  120. * This parameters control when the driver calls the routine to reclaim
  121. * transmit descriptors.
  122. */
  123. #define IXGBE_TX_CLEANUP_THRESHOLD (adapter->num_tx_desc / 8)
  124. #define IXGBE_TX_OP_THRESHOLD (adapter->num_tx_desc / 32)
  125. #define IXGBE_MAX_FRAME_SIZE 0x3F00
  126. /* Flow control constants */
  127. #define IXGBE_FC_PAUSE 0xFFFF
  128. #define IXGBE_FC_HI 0x20000
  129. #define IXGBE_FC_LO 0x10000
  130. /* Keep older OS drivers building... */
  131. #if !defined(SYSCTL_ADD_UQUAD)
  132. #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
  133. #endif
  134. /* Defines for printing debug information */
  135. #define DEBUG_INIT 0
  136. #define DEBUG_IOCTL 0
  137. #define DEBUG_HW 0
  138. #define INIT_DEBUGOUT(S) if (DEBUG_INIT) kprintf(S "\n")
  139. #define INIT_DEBUGOUT1(S, A) if (DEBUG_INIT) kprintf(S "\n", A)
  140. #define INIT_DEBUGOUT2(S, A, B) if (DEBUG_INIT) kprintf(S "\n", A, B)
  141. #define IOCTL_DEBUGOUT(S) if (DEBUG_IOCTL) kprintf(S "\n")
  142. #define IOCTL_DEBUGOUT1(S, A) if (DEBUG_IOCTL) kprintf(S "\n", A)
  143. #define IOCTL_DEBUGOUT2(S, A, B) if (DEBUG_IOCTL) kprintf(S "\n", A, B)
  144. #define HW_DEBUGOUT(S) if (DEBUG_HW) kprintf(S "\n")
  145. #define HW_DEBUGOUT1(S, A) if (DEBUG_HW) kprintf(S "\n", A)
  146. #define HW_DEBUGOUT2(S, A, B) if (DEBUG_HW) kprintf(S "\n", A, B)
  147. #define MAX_NUM_MULTICAST_ADDRESSES 128
  148. #define IXGBE_82598_SCATTER 100
  149. #define IXGBE_82599_SCATTER 32
  150. #define MSIX_82598_BAR 3
  151. #define MSIX_82599_BAR 4
  152. #define IXGBE_TSO_SIZE 262140
  153. #define IXGBE_TX_BUFFER_SIZE ((u32) 1514)
  154. #define IXGBE_RX_HDR 128
  155. #define IXGBE_VFTA_SIZE 128
  156. #define IXGBE_BR_SIZE 4096
  157. #define IXGBE_QUEUE_MIN_FREE 32
  158. #define IXGBE_QUEUE_IDLE 1
  159. #define IXGBE_QUEUE_WORKING 2
  160. #define IXGBE_QUEUE_HUNG 4
  161. #define IXGBE_QUEUE_DEPLETED 8
  162. /* Offload bits in mbuf flag */
  163. #define CSUM_OFFLOAD (CSUM_IP|CSUM_TCP|CSUM_UDP)
  164. /* One for TX csum offloading desc, the other 2 are reserved */
  165. #define IXGBE_TX_RESERVED 3
  166. /*
  167. * Interrupt Moderation parameters
  168. */
  169. #define IXGBE_LOW_LATENCY 128
  170. #define IXGBE_AVE_LATENCY 400
  171. #define IXGBE_BULK_LATENCY 1200
  172. #define IXGBE_LINK_ITR 2000
  173. #define IXGBE_INTR_RATE 8000
  174. #define IXGBE_EITR_INTVL_MASK 0x7ffc
  175. #define IXGBE_EITR_INTVL_SHIFT 2
  176. /*
  177. *****************************************************************************
  178. * vendor_info_array
  179. *
  180. * This array contains the list of Subvendor/Subdevice IDs on which the driver
  181. * should load.
  182. *
  183. *****************************************************************************
  184. */
  185. typedef struct _ixgbe_vendor_info_t {
  186. unsigned int vendor_id;
  187. unsigned int device_id;
  188. unsigned int subvendor_id;
  189. unsigned int subdevice_id;
  190. unsigned int index;
  191. } ixgbe_vendor_info_t;
  192. struct ixgbe_tx_buf {
  193. u32 eop_index;
  194. struct mbuf *m_head;
  195. bus_dmamap_t map;
  196. };
  197. struct ixgbe_rx_buf {
  198. struct mbuf *m_head;
  199. struct mbuf *m_pack;
  200. struct mbuf *fmp;
  201. bus_dmamap_t hmap;
  202. bus_dmamap_t pmap;
  203. };
  204. /*
  205. * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
  206. */
  207. struct ixgbe_dma_alloc {
  208. bus_addr_t dma_paddr;
  209. caddr_t dma_vaddr;
  210. bus_dma_tag_t dma_tag;
  211. bus_dmamap_t dma_map;
  212. bus_dma_segment_t dma_seg;
  213. bus_size_t dma_size;
  214. int dma_nseg;
  215. };
  216. /*
  217. ** Driver queue struct: this is the interrupt container
  218. ** for the associated tx and rx ring.
  219. */
  220. struct ix_queue {
  221. struct adapter *adapter;
  222. u32 msix; /* This queue's MSIX vector */
  223. u32 eims; /* This queue's EIMS bit */
  224. u32 eitr_setting;
  225. struct resource *res;
  226. void *tag;
  227. struct tx_ring *txr;
  228. struct rx_ring *rxr;
  229. u64 irqs;
  230. struct lwkt_serialize serializer;
  231. };
  232. /*
  233. * The transmit ring, one per queue
  234. */
  235. struct tx_ring {
  236. struct adapter *adapter;
  237. struct lwkt_serialize tx_serialize;
  238. u32 me;
  239. int queue_status;
  240. int watchdog_time;
  241. union ixgbe_adv_tx_desc *tx_base;
  242. struct ixgbe_dma_alloc txdma;
  243. u32 next_avail_desc;
  244. u32 next_to_clean;
  245. struct ixgbe_tx_buf *tx_buffers;
  246. volatile u16 tx_avail;
  247. u32 txd_cmd;
  248. bus_dma_tag_t txtag;
  249. char lock_name[16];
  250. #ifdef IFNET_BUF_RING
  251. struct buf_ring *br;
  252. #endif
  253. #ifdef IXGBE_FDIR
  254. u16 atr_sample;
  255. u16 atr_count;
  256. #endif
  257. u32 bytes; /* used for AIM */
  258. u32 packets;
  259. /* Soft Stats */
  260. u64 no_desc_avail;
  261. u64 total_packets;
  262. };
  263. /*
  264. * The Receive ring, one per rx queue
  265. */
  266. struct rx_ring {
  267. struct adapter *adapter;
  268. struct lock rx_lock;
  269. u32 me;
  270. union ixgbe_adv_rx_desc *rx_base;
  271. struct ixgbe_dma_alloc rxdma;
  272. #ifdef NET_LRO
  273. struct lro_ctrl lro;
  274. #endif
  275. bool lro_enabled;
  276. bool hdr_split;
  277. bool hw_rsc;
  278. bool discard;
  279. bool vtag_strip;
  280. u32 next_to_refresh;
  281. u32 next_to_check;
  282. char lock_name[16];
  283. struct ixgbe_rx_buf *rx_buffers;
  284. bus_dma_tag_t htag;
  285. bus_dma_tag_t ptag;
  286. u32 bytes; /* Used for AIM calc */
  287. u32 packets;
  288. /* Soft stats */
  289. u64 rx_irq;
  290. u64 rx_split_packets;
  291. u64 rx_packets;
  292. u64 rx_bytes;
  293. u64 rx_discarded;
  294. u64 rsc_num;
  295. #ifdef IXGBE_FDIR
  296. u64 flm;
  297. #endif
  298. };
  299. /* Our adapter structure */
  300. struct adapter {
  301. struct ifnet *ifp;
  302. struct ixgbe_hw hw;
  303. struct ixgbe_osdep osdep;
  304. struct device *dev;
  305. struct resource *pci_mem;
  306. struct resource *msix_mem;
  307. /*
  308. * Interrupt resources: this set is
  309. * either used for legacy, or for Link
  310. * when doing MSIX
  311. */
  312. void *tag;
  313. struct resource *res;
  314. int intr_type;
  315. struct ifmedia media;
  316. struct callout timer;
  317. int msix;
  318. int if_flags;
  319. struct lock core_lock;
  320. eventhandler_tag vlan_attach;
  321. eventhandler_tag vlan_detach;
  322. u16 num_vlans;
  323. u16 num_queues;
  324. /*
  325. ** Shadow VFTA table, this is needed because
  326. ** the real vlan filter table gets cleared during
  327. ** a soft reset and the driver needs to be able
  328. ** to repopulate it.
  329. */
  330. u32 shadow_vfta[IXGBE_VFTA_SIZE];
  331. /* Info about the interface */
  332. u32 optics;
  333. u32 fc; /* local flow ctrl setting */
  334. int advertise; /* link speeds */
  335. bool link_active;
  336. u16 max_frame_size;
  337. u16 num_segs;
  338. u32 link_speed;
  339. bool link_up;
  340. u32 linkvec;
  341. /* Mbuf cluster size */
  342. u32 rx_mbuf_sz;
  343. /* Support for pluggable optics */
  344. bool sfp_probe;
  345. struct task mod_task; /* SFP tasklet */
  346. struct task msf_task; /* Multispeed Fiber */
  347. #ifdef IXGBE_FDIR
  348. int fdir_reinit;
  349. struct task fdir_task;
  350. #endif
  351. struct taskqueue *tq;
  352. /*
  353. ** Queues:
  354. ** This is the irq holder, it has
  355. ** and RX/TX pair or rings associated
  356. ** with it.
  357. */
  358. struct ix_queue *queues;
  359. /*
  360. * Transmit rings:
  361. * Allocated at run time, an array of rings.
  362. */
  363. struct tx_ring *tx_rings;
  364. int num_tx_desc;
  365. /*
  366. * Receive rings:
  367. * Allocated at run time, an array of rings.
  368. */
  369. struct rx_ring *rx_rings;
  370. int num_rx_desc;
  371. u64 que_mask;
  372. u32 rx_process_limit;
  373. /* Multicast array memory */
  374. u8 *mta;
  375. int intr_rate;
  376. /* Misc stats maintained by the driver */
  377. unsigned long dropped_pkts;
  378. unsigned long mbuf_defrag_failed;
  379. unsigned long mbuf_header_failed;
  380. unsigned long mbuf_packet_failed;
  381. unsigned long no_tx_map_avail;
  382. unsigned long no_tx_dma_setup;
  383. unsigned long watchdog_events;
  384. unsigned long tso_tx;
  385. unsigned long link_irq;
  386. struct ixgbe_hw_stats stats;
  387. struct lwkt_serialize serializer;
  388. struct sysctl_ctx_list sysctl_ctx;
  389. struct sysctl_oid *sysctl_tree;
  390. };
  391. /* Precision Time Sync (IEEE 1588) defines */
  392. #define ETHERTYPE_IEEE1588 0x88F7
  393. #define PICOSECS_PER_TICK 20833
  394. #define TSYNC_UDP_PORT 319 /* UDP port for the protocol */
  395. #define IXGBE_ADVTXD_TSTAMP 0x00080000
  396. #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
  397. lockinit(&(_sc)->core_lock, _name, 0, LK_CANRECURSE)
  398. #define IXGBE_TX_LOCK_INIT(_sc) lwkt_serialize_init(&(_sc)->tx_serialize)
  399. #define IXGBE_CORE_LOCK_DESTROY(_sc) lockuninit(&(_sc)->core_lock)
  400. #define IXGBE_TX_LOCK_DESTROY(_sc)
  401. #define IXGBE_RX_LOCK_DESTROY(_sc) lockuninit(&(_sc)->rx_lock)
  402. #define IXGBE_CORE_LOCK(_sc) lockmgr(&(_sc)->core_lock, LK_EXCLUSIVE)
  403. #define IXGBE_TX_LOCK(_sc) lwkt_serialize_enter(&(_sc)->tx_serialize)
  404. #define IXGBE_TX_TRYLOCK(_sc) lwkt_serialize_try(&(_sc)->tx_serialize)
  405. #define IXGBE_RX_LOCK(_sc) lockmgr(&(_sc)->rx_lock, LK_EXCLUSIVE)
  406. #define IXGBE_CORE_UNLOCK(_sc) lockmgr(&(_sc)->core_lock, LK_RELEASE)
  407. #define IXGBE_TX_UNLOCK(_sc) lwkt_serialize_exit(&(_sc)->tx_serialize)
  408. #define IXGBE_RX_UNLOCK(_sc) lockmgr(&(_sc)->rx_lock, LK_RELEASE)
  409. #define IXGBE_CORE_LOCK_ASSERT(_sc) KKASSERT(lockstatus(&(_sc)->core_lock, curthread) !=0)
  410. #define IXGBE_TX_LOCK_ASSERT(_sc) ASSERT_SERIALIZED(&(_sc)->tx_serialize)
  411. static inline bool
  412. ixgbe_is_sfp(struct ixgbe_hw *hw)
  413. {
  414. switch (hw->phy.type) {
  415. case ixgbe_phy_sfp_avago:
  416. case ixgbe_phy_sfp_ftl:
  417. case ixgbe_phy_sfp_intel:
  418. case ixgbe_phy_sfp_unknown:
  419. case ixgbe_phy_sfp_passive_tyco:
  420. case ixgbe_phy_sfp_passive_unknown:
  421. return TRUE;
  422. default:
  423. return FALSE;
  424. }
  425. }
  426. /*
  427. ** Find the number of unrefreshed RX descriptors
  428. */
  429. static inline u16
  430. ixgbe_rx_unrefreshed(struct rx_ring *rxr)
  431. {
  432. struct adapter *adapter = rxr->adapter;
  433. if (rxr->next_to_check > rxr->next_to_refresh)
  434. return (rxr->next_to_check - rxr->next_to_refresh - 1);
  435. else
  436. return ((adapter->num_rx_desc + rxr->next_to_check) -
  437. rxr->next_to_refresh - 1);
  438. }
  439. #endif /* _IXGBE_H_ */