t4vf_common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
  3. * driver for Linux.
  4. *
  5. * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #ifndef __T4VF_COMMON_H__
  36. #define __T4VF_COMMON_H__
  37. #include "../cxgb4/t4fw_api.h"
  38. #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
  39. #define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
  40. #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
  41. /* All T4 and later chips have their PCI-E Device IDs encoded as 0xVFPP where:
  42. *
  43. * V = "4" for T4; "5" for T5, etc. or
  44. * = "a" for T4 FPGA; "b" for T4 FPGA, etc.
  45. * F = "0" for PF 0..3; "4".."7" for PF4..7; and "8" for VFs
  46. * PP = adapter product designation
  47. */
  48. #define CHELSIO_T4 0x4
  49. #define CHELSIO_T5 0x5
  50. #define CHELSIO_T6 0x6
  51. enum chip_type {
  52. T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
  53. T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
  54. T4_FIRST_REV = T4_A1,
  55. T4_LAST_REV = T4_A2,
  56. T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
  57. T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
  58. T5_FIRST_REV = T5_A0,
  59. T5_LAST_REV = T5_A1,
  60. };
  61. /*
  62. * The "len16" field of a Firmware Command Structure ...
  63. */
  64. #define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
  65. /*
  66. * Per-VF statistics.
  67. */
  68. struct t4vf_port_stats {
  69. /*
  70. * TX statistics.
  71. */
  72. u64 tx_bcast_bytes; /* broadcast */
  73. u64 tx_bcast_frames;
  74. u64 tx_mcast_bytes; /* multicast */
  75. u64 tx_mcast_frames;
  76. u64 tx_ucast_bytes; /* unicast */
  77. u64 tx_ucast_frames;
  78. u64 tx_drop_frames; /* TX dropped frames */
  79. u64 tx_offload_bytes; /* offload */
  80. u64 tx_offload_frames;
  81. /*
  82. * RX statistics.
  83. */
  84. u64 rx_bcast_bytes; /* broadcast */
  85. u64 rx_bcast_frames;
  86. u64 rx_mcast_bytes; /* multicast */
  87. u64 rx_mcast_frames;
  88. u64 rx_ucast_bytes;
  89. u64 rx_ucast_frames; /* unicast */
  90. u64 rx_err_frames; /* RX error frames */
  91. };
  92. /*
  93. * Per-"port" (Virtual Interface) link configuration ...
  94. */
  95. struct link_config {
  96. unsigned int supported; /* link capabilities */
  97. unsigned int advertising; /* advertised capabilities */
  98. unsigned short requested_speed; /* speed user has requested */
  99. unsigned short speed; /* actual link speed */
  100. unsigned char requested_fc; /* flow control user has requested */
  101. unsigned char fc; /* actual link flow control */
  102. unsigned char autoneg; /* autonegotiating? */
  103. unsigned char link_ok; /* link up? */
  104. };
  105. enum {
  106. PAUSE_RX = 1 << 0,
  107. PAUSE_TX = 1 << 1,
  108. PAUSE_AUTONEG = 1 << 2
  109. };
  110. /*
  111. * General device parameters ...
  112. */
  113. struct dev_params {
  114. u32 fwrev; /* firmware version */
  115. u32 tprev; /* TP Microcode Version */
  116. };
  117. /*
  118. * Scatter Gather Engine parameters. These are almost all determined by the
  119. * Physical Function Driver. We just need to grab them to see within which
  120. * environment we're playing ...
  121. */
  122. struct sge_params {
  123. u32 sge_control; /* padding, boundaries, lengths, etc. */
  124. u32 sge_control2; /* T5: more of the same */
  125. u32 sge_host_page_size; /* PF0-7 page sizes */
  126. u32 sge_egress_queues_per_page; /* PF0-7 egress queues/page */
  127. u32 sge_ingress_queues_per_page;/* PF0-7 ingress queues/page */
  128. u32 sge_vf_hps; /* host page size for our vf */
  129. u32 sge_vf_eq_qpp; /* egress queues/page for our VF */
  130. u32 sge_vf_iq_qpp; /* ingress queues/page for our VF */
  131. u32 sge_fl_buffer_size[16]; /* free list buffer sizes */
  132. u32 sge_ingress_rx_threshold; /* RX counter interrupt threshold[4] */
  133. u32 sge_congestion_control; /* congestion thresholds, etc. */
  134. u32 sge_timer_value_0_and_1; /* interrupt coalescing timer values */
  135. u32 sge_timer_value_2_and_3;
  136. u32 sge_timer_value_4_and_5;
  137. };
  138. /*
  139. * Vital Product Data parameters.
  140. */
  141. struct vpd_params {
  142. u32 cclk; /* Core Clock (KHz) */
  143. };
  144. /* Stores chip specific parameters */
  145. struct arch_specific_params {
  146. u32 sge_fl_db;
  147. u16 mps_tcam_size;
  148. };
  149. /*
  150. * Global Receive Side Scaling (RSS) parameters in host-native format.
  151. */
  152. struct rss_params {
  153. unsigned int mode; /* RSS mode */
  154. union {
  155. struct {
  156. unsigned int synmapen:1; /* SYN Map Enable */
  157. unsigned int syn4tupenipv6:1; /* enable hashing 4-tuple IPv6 SYNs */
  158. unsigned int syn2tupenipv6:1; /* enable hashing 2-tuple IPv6 SYNs */
  159. unsigned int syn4tupenipv4:1; /* enable hashing 4-tuple IPv4 SYNs */
  160. unsigned int syn2tupenipv4:1; /* enable hashing 2-tuple IPv4 SYNs */
  161. unsigned int ofdmapen:1; /* Offload Map Enable */
  162. unsigned int tnlmapen:1; /* Tunnel Map Enable */
  163. unsigned int tnlalllookup:1; /* Tunnel All Lookup */
  164. unsigned int hashtoeplitz:1; /* use Toeplitz hash */
  165. } basicvirtual;
  166. } u;
  167. };
  168. /*
  169. * Virtual Interface RSS Configuration in host-native format.
  170. */
  171. union rss_vi_config {
  172. struct {
  173. u16 defaultq; /* Ingress Queue ID for !tnlalllookup */
  174. unsigned int ip6fourtupen:1; /* hash 4-tuple IPv6 ingress packets */
  175. unsigned int ip6twotupen:1; /* hash 2-tuple IPv6 ingress packets */
  176. unsigned int ip4fourtupen:1; /* hash 4-tuple IPv4 ingress packets */
  177. unsigned int ip4twotupen:1; /* hash 2-tuple IPv4 ingress packets */
  178. int udpen; /* hash 4-tuple UDP ingress packets */
  179. } basicvirtual;
  180. };
  181. /*
  182. * Maximum resources provisioned for a PCI VF.
  183. */
  184. struct vf_resources {
  185. unsigned int nvi; /* N virtual interfaces */
  186. unsigned int neq; /* N egress Qs */
  187. unsigned int nethctrl; /* N egress ETH or CTRL Qs */
  188. unsigned int niqflint; /* N ingress Qs/w free list(s) & intr */
  189. unsigned int niq; /* N ingress Qs */
  190. unsigned int tc; /* PCI-E traffic class */
  191. unsigned int pmask; /* port access rights mask */
  192. unsigned int nexactf; /* N exact MPS filters */
  193. unsigned int r_caps; /* read capabilities */
  194. unsigned int wx_caps; /* write/execute capabilities */
  195. };
  196. /*
  197. * Per-"adapter" (Virtual Function) parameters.
  198. */
  199. struct adapter_params {
  200. struct dev_params dev; /* general device parameters */
  201. struct sge_params sge; /* Scatter Gather Engine */
  202. struct vpd_params vpd; /* Vital Product Data */
  203. struct rss_params rss; /* Receive Side Scaling */
  204. struct vf_resources vfres; /* Virtual Function Resource limits */
  205. struct arch_specific_params arch; /* chip specific params */
  206. enum chip_type chip; /* chip code */
  207. u8 nports; /* # of Ethernet "ports" */
  208. };
  209. #include "adapter.h"
  210. #ifndef PCI_VENDOR_ID_CHELSIO
  211. # define PCI_VENDOR_ID_CHELSIO 0x1425
  212. #endif
  213. #define for_each_port(adapter, iter) \
  214. for (iter = 0; iter < (adapter)->params.nports; iter++)
  215. static inline bool is_10g_port(const struct link_config *lc)
  216. {
  217. return (lc->supported & FW_PORT_CAP_SPEED_10G) != 0;
  218. }
  219. static inline bool is_x_10g_port(const struct link_config *lc)
  220. {
  221. return (lc->supported & FW_PORT_CAP_SPEED_10G) != 0 ||
  222. (lc->supported & FW_PORT_CAP_SPEED_40G) != 0;
  223. }
  224. static inline unsigned int core_ticks_per_usec(const struct adapter *adapter)
  225. {
  226. return adapter->params.vpd.cclk / 1000;
  227. }
  228. static inline unsigned int us_to_core_ticks(const struct adapter *adapter,
  229. unsigned int us)
  230. {
  231. return (us * adapter->params.vpd.cclk) / 1000;
  232. }
  233. static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
  234. unsigned int ticks)
  235. {
  236. return (ticks * 1000) / adapter->params.vpd.cclk;
  237. }
  238. int t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool);
  239. static inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd,
  240. int size, void *rpl)
  241. {
  242. return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true);
  243. }
  244. static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
  245. int size, void *rpl)
  246. {
  247. return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false);
  248. }
  249. #define CHELSIO_PCI_ID_VER(dev_id) ((dev_id) >> 12)
  250. static inline int is_t4(enum chip_type chip)
  251. {
  252. return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
  253. }
  254. int t4vf_wait_dev_ready(struct adapter *);
  255. int t4vf_port_init(struct adapter *, int);
  256. int t4vf_fw_reset(struct adapter *);
  257. int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
  258. enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
  259. int t4vf_bar2_sge_qregs(struct adapter *adapter,
  260. unsigned int qid,
  261. enum t4_bar2_qtype qtype,
  262. u64 *pbar2_qoffset,
  263. unsigned int *pbar2_qid);
  264. int t4vf_get_sge_params(struct adapter *);
  265. int t4vf_get_vpd_params(struct adapter *);
  266. int t4vf_get_dev_params(struct adapter *);
  267. int t4vf_get_rss_glb_config(struct adapter *);
  268. int t4vf_get_vfres(struct adapter *);
  269. int t4vf_read_rss_vi_config(struct adapter *, unsigned int,
  270. union rss_vi_config *);
  271. int t4vf_write_rss_vi_config(struct adapter *, unsigned int,
  272. union rss_vi_config *);
  273. int t4vf_config_rss_range(struct adapter *, unsigned int, int, int,
  274. const u16 *, int);
  275. int t4vf_alloc_vi(struct adapter *, int);
  276. int t4vf_free_vi(struct adapter *, int);
  277. int t4vf_enable_vi(struct adapter *, unsigned int, bool, bool);
  278. int t4vf_identify_port(struct adapter *, unsigned int, unsigned int);
  279. int t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int,
  280. bool);
  281. int t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int,
  282. const u8 **, u16 *, u64 *, bool);
  283. int t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool);
  284. int t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool);
  285. int t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *);
  286. int t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int,
  287. unsigned int);
  288. int t4vf_eth_eq_free(struct adapter *, unsigned int);
  289. int t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
  290. int t4vf_prep_adapter(struct adapter *);
  291. #endif /* __T4VF_COMMON_H__ */