t4vf_common.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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/t4_hw.h"
  38. #include "../cxgb4/t4fw_api.h"
  39. #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
  40. #define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
  41. #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
  42. /* All T4 and later chips have their PCI-E Device IDs encoded as 0xVFPP where:
  43. *
  44. * V = "4" for T4; "5" for T5, etc. or
  45. * = "a" for T4 FPGA; "b" for T4 FPGA, etc.
  46. * F = "0" for PF 0..3; "4".."7" for PF4..7; and "8" for VFs
  47. * PP = adapter product designation
  48. */
  49. #define CHELSIO_T4 0x4
  50. #define CHELSIO_T5 0x5
  51. #define CHELSIO_T6 0x6
  52. enum chip_type {
  53. T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
  54. T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
  55. T4_FIRST_REV = T4_A1,
  56. T4_LAST_REV = T4_A2,
  57. T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
  58. T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
  59. T5_FIRST_REV = T5_A0,
  60. T5_LAST_REV = T5_A1,
  61. };
  62. /*
  63. * The "len16" field of a Firmware Command Structure ...
  64. */
  65. #define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
  66. /*
  67. * Per-VF statistics.
  68. */
  69. struct t4vf_port_stats {
  70. /*
  71. * TX statistics.
  72. */
  73. u64 tx_bcast_bytes; /* broadcast */
  74. u64 tx_bcast_frames;
  75. u64 tx_mcast_bytes; /* multicast */
  76. u64 tx_mcast_frames;
  77. u64 tx_ucast_bytes; /* unicast */
  78. u64 tx_ucast_frames;
  79. u64 tx_drop_frames; /* TX dropped frames */
  80. u64 tx_offload_bytes; /* offload */
  81. u64 tx_offload_frames;
  82. /*
  83. * RX statistics.
  84. */
  85. u64 rx_bcast_bytes; /* broadcast */
  86. u64 rx_bcast_frames;
  87. u64 rx_mcast_bytes; /* multicast */
  88. u64 rx_mcast_frames;
  89. u64 rx_ucast_bytes;
  90. u64 rx_ucast_frames; /* unicast */
  91. u64 rx_err_frames; /* RX error frames */
  92. };
  93. /*
  94. * Per-"port" (Virtual Interface) link configuration ...
  95. */
  96. typedef u16 fw_port_cap16_t; /* 16-bit Port Capabilities integral value */
  97. typedef u32 fw_port_cap32_t; /* 32-bit Port Capabilities integral value */
  98. enum fw_caps {
  99. FW_CAPS_UNKNOWN = 0, /* 0'ed out initial state */
  100. FW_CAPS16 = 1, /* old Firmware: 16-bit Port Capabilities */
  101. FW_CAPS32 = 2, /* new Firmware: 32-bit Port Capabilities */
  102. };
  103. enum cc_pause {
  104. PAUSE_RX = 1 << 0,
  105. PAUSE_TX = 1 << 1,
  106. PAUSE_AUTONEG = 1 << 2
  107. };
  108. enum cc_fec {
  109. FEC_AUTO = 1 << 0, /* IEEE 802.3 "automatic" */
  110. FEC_RS = 1 << 1, /* Reed-Solomon */
  111. FEC_BASER_RS = 1 << 2, /* BaseR/Reed-Solomon */
  112. };
  113. struct link_config {
  114. fw_port_cap32_t pcaps; /* link capabilities */
  115. fw_port_cap32_t acaps; /* advertised capabilities */
  116. fw_port_cap32_t lpacaps; /* peer advertised capabilities */
  117. fw_port_cap32_t speed_caps; /* speed(s) user has requested */
  118. u32 speed; /* actual link speed */
  119. enum cc_pause requested_fc; /* flow control user has requested */
  120. enum cc_pause fc; /* actual link flow control */
  121. enum cc_fec auto_fec; /* Forward Error Correction: */
  122. enum cc_fec requested_fec; /* "automatic" (IEEE 802.3), */
  123. enum cc_fec fec; /* requested, and actual in use */
  124. unsigned char autoneg; /* autonegotiating? */
  125. unsigned char link_ok; /* link up? */
  126. unsigned char link_down_rc; /* link down reason */
  127. };
  128. /* Return true if the Link Configuration supports "High Speeds" (those greater
  129. * than 1Gb/s).
  130. */
  131. static inline bool is_x_10g_port(const struct link_config *lc)
  132. {
  133. fw_port_cap32_t speeds, high_speeds;
  134. speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
  135. high_speeds =
  136. speeds & ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
  137. return high_speeds != 0;
  138. }
  139. /*
  140. * General device parameters ...
  141. */
  142. struct dev_params {
  143. u32 fwrev; /* firmware version */
  144. u32 tprev; /* TP Microcode Version */
  145. };
  146. /*
  147. * Scatter Gather Engine parameters. These are almost all determined by the
  148. * Physical Function Driver. We just need to grab them to see within which
  149. * environment we're playing ...
  150. */
  151. struct sge_params {
  152. u32 sge_control; /* padding, boundaries, lengths, etc. */
  153. u32 sge_control2; /* T5: more of the same */
  154. u32 sge_host_page_size; /* PF0-7 page sizes */
  155. u32 sge_egress_queues_per_page; /* PF0-7 egress queues/page */
  156. u32 sge_ingress_queues_per_page;/* PF0-7 ingress queues/page */
  157. u32 sge_vf_hps; /* host page size for our vf */
  158. u32 sge_vf_eq_qpp; /* egress queues/page for our VF */
  159. u32 sge_vf_iq_qpp; /* ingress queues/page for our VF */
  160. u32 sge_fl_buffer_size[16]; /* free list buffer sizes */
  161. u32 sge_ingress_rx_threshold; /* RX counter interrupt threshold[4] */
  162. u32 sge_congestion_control; /* congestion thresholds, etc. */
  163. u32 sge_timer_value_0_and_1; /* interrupt coalescing timer values */
  164. u32 sge_timer_value_2_and_3;
  165. u32 sge_timer_value_4_and_5;
  166. };
  167. /*
  168. * Vital Product Data parameters.
  169. */
  170. struct vpd_params {
  171. u32 cclk; /* Core Clock (KHz) */
  172. };
  173. /* Stores chip specific parameters */
  174. struct arch_specific_params {
  175. u32 sge_fl_db;
  176. u16 mps_tcam_size;
  177. };
  178. /*
  179. * Global Receive Side Scaling (RSS) parameters in host-native format.
  180. */
  181. struct rss_params {
  182. unsigned int mode; /* RSS mode */
  183. union {
  184. struct {
  185. unsigned int synmapen:1; /* SYN Map Enable */
  186. unsigned int syn4tupenipv6:1; /* enable hashing 4-tuple IPv6 SYNs */
  187. unsigned int syn2tupenipv6:1; /* enable hashing 2-tuple IPv6 SYNs */
  188. unsigned int syn4tupenipv4:1; /* enable hashing 4-tuple IPv4 SYNs */
  189. unsigned int syn2tupenipv4:1; /* enable hashing 2-tuple IPv4 SYNs */
  190. unsigned int ofdmapen:1; /* Offload Map Enable */
  191. unsigned int tnlmapen:1; /* Tunnel Map Enable */
  192. unsigned int tnlalllookup:1; /* Tunnel All Lookup */
  193. unsigned int hashtoeplitz:1; /* use Toeplitz hash */
  194. } basicvirtual;
  195. } u;
  196. };
  197. /*
  198. * Virtual Interface RSS Configuration in host-native format.
  199. */
  200. union rss_vi_config {
  201. struct {
  202. u16 defaultq; /* Ingress Queue ID for !tnlalllookup */
  203. unsigned int ip6fourtupen:1; /* hash 4-tuple IPv6 ingress packets */
  204. unsigned int ip6twotupen:1; /* hash 2-tuple IPv6 ingress packets */
  205. unsigned int ip4fourtupen:1; /* hash 4-tuple IPv4 ingress packets */
  206. unsigned int ip4twotupen:1; /* hash 2-tuple IPv4 ingress packets */
  207. int udpen; /* hash 4-tuple UDP ingress packets */
  208. } basicvirtual;
  209. };
  210. /*
  211. * Maximum resources provisioned for a PCI VF.
  212. */
  213. struct vf_resources {
  214. unsigned int nvi; /* N virtual interfaces */
  215. unsigned int neq; /* N egress Qs */
  216. unsigned int nethctrl; /* N egress ETH or CTRL Qs */
  217. unsigned int niqflint; /* N ingress Qs/w free list(s) & intr */
  218. unsigned int niq; /* N ingress Qs */
  219. unsigned int tc; /* PCI-E traffic class */
  220. unsigned int pmask; /* port access rights mask */
  221. unsigned int nexactf; /* N exact MPS filters */
  222. unsigned int r_caps; /* read capabilities */
  223. unsigned int wx_caps; /* write/execute capabilities */
  224. };
  225. /*
  226. * Per-"adapter" (Virtual Function) parameters.
  227. */
  228. struct adapter_params {
  229. struct dev_params dev; /* general device parameters */
  230. struct sge_params sge; /* Scatter Gather Engine */
  231. struct vpd_params vpd; /* Vital Product Data */
  232. struct rss_params rss; /* Receive Side Scaling */
  233. struct vf_resources vfres; /* Virtual Function Resource limits */
  234. struct arch_specific_params arch; /* chip specific params */
  235. enum chip_type chip; /* chip code */
  236. u8 nports; /* # of Ethernet "ports" */
  237. u8 fw_caps_support; /* 32-bit Port Capabilities */
  238. };
  239. /* Firmware Mailbox Command/Reply log. All values are in Host-Endian format.
  240. * The access and execute times are signed in order to accommodate negative
  241. * error returns.
  242. */
  243. struct mbox_cmd {
  244. u64 cmd[MBOX_LEN / 8]; /* a Firmware Mailbox Command/Reply */
  245. u64 timestamp; /* OS-dependent timestamp */
  246. u32 seqno; /* sequence number */
  247. s16 access; /* time (ms) to access mailbox */
  248. s16 execute; /* time (ms) to execute */
  249. };
  250. struct mbox_cmd_log {
  251. unsigned int size; /* number of entries in the log */
  252. unsigned int cursor; /* next position in the log to write */
  253. u32 seqno; /* next sequence number */
  254. /* variable length mailbox command log starts here */
  255. };
  256. /* Given a pointer to a Firmware Mailbox Command Log and a log entry index,
  257. * return a pointer to the specified entry.
  258. */
  259. static inline struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log,
  260. unsigned int entry_idx)
  261. {
  262. return &((struct mbox_cmd *)&(log)[1])[entry_idx];
  263. }
  264. #include "adapter.h"
  265. #ifndef PCI_VENDOR_ID_CHELSIO
  266. # define PCI_VENDOR_ID_CHELSIO 0x1425
  267. #endif
  268. #define for_each_port(adapter, iter) \
  269. for (iter = 0; iter < (adapter)->params.nports; iter++)
  270. static inline unsigned int core_ticks_per_usec(const struct adapter *adapter)
  271. {
  272. return adapter->params.vpd.cclk / 1000;
  273. }
  274. static inline unsigned int us_to_core_ticks(const struct adapter *adapter,
  275. unsigned int us)
  276. {
  277. return (us * adapter->params.vpd.cclk) / 1000;
  278. }
  279. static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
  280. unsigned int ticks)
  281. {
  282. return (ticks * 1000) / adapter->params.vpd.cclk;
  283. }
  284. int t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool);
  285. static inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd,
  286. int size, void *rpl)
  287. {
  288. return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true);
  289. }
  290. static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
  291. int size, void *rpl)
  292. {
  293. return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false);
  294. }
  295. #define CHELSIO_PCI_ID_VER(dev_id) ((dev_id) >> 12)
  296. static inline int is_t4(enum chip_type chip)
  297. {
  298. return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
  299. }
  300. /**
  301. * hash_mac_addr - return the hash value of a MAC address
  302. * @addr: the 48-bit Ethernet MAC address
  303. *
  304. * Hashes a MAC address according to the hash function used by hardware
  305. * inexact (hash) address matching.
  306. */
  307. static inline int hash_mac_addr(const u8 *addr)
  308. {
  309. u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
  310. u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
  311. a ^= b;
  312. a ^= (a >> 12);
  313. a ^= (a >> 6);
  314. return a & 0x3f;
  315. }
  316. int t4vf_wait_dev_ready(struct adapter *);
  317. int t4vf_port_init(struct adapter *, int);
  318. int t4vf_fw_reset(struct adapter *);
  319. int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
  320. int t4vf_fl_pkt_align(struct adapter *adapter);
  321. enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
  322. int t4vf_bar2_sge_qregs(struct adapter *adapter,
  323. unsigned int qid,
  324. enum t4_bar2_qtype qtype,
  325. u64 *pbar2_qoffset,
  326. unsigned int *pbar2_qid);
  327. unsigned int t4vf_get_pf_from_vf(struct adapter *);
  328. int t4vf_get_sge_params(struct adapter *);
  329. int t4vf_get_vpd_params(struct adapter *);
  330. int t4vf_get_dev_params(struct adapter *);
  331. int t4vf_get_rss_glb_config(struct adapter *);
  332. int t4vf_get_vfres(struct adapter *);
  333. int t4vf_read_rss_vi_config(struct adapter *, unsigned int,
  334. union rss_vi_config *);
  335. int t4vf_write_rss_vi_config(struct adapter *, unsigned int,
  336. union rss_vi_config *);
  337. int t4vf_config_rss_range(struct adapter *, unsigned int, int, int,
  338. const u16 *, int);
  339. int t4vf_alloc_vi(struct adapter *, int);
  340. int t4vf_free_vi(struct adapter *, int);
  341. int t4vf_enable_vi(struct adapter *adapter, unsigned int viid, bool rx_en,
  342. bool tx_en);
  343. int t4vf_enable_pi(struct adapter *adapter, struct port_info *pi, bool rx_en,
  344. bool tx_en);
  345. int t4vf_identify_port(struct adapter *, unsigned int, unsigned int);
  346. int t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int,
  347. bool);
  348. int t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int,
  349. const u8 **, u16 *, u64 *, bool);
  350. int t4vf_free_mac_filt(struct adapter *, unsigned int, unsigned int naddr,
  351. const u8 **, bool);
  352. int t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool);
  353. int t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool);
  354. int t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *);
  355. int t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int,
  356. unsigned int);
  357. int t4vf_eth_eq_free(struct adapter *, unsigned int);
  358. int t4vf_update_port_info(struct port_info *pi);
  359. int t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
  360. int t4vf_prep_adapter(struct adapter *);
  361. int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int pf,
  362. unsigned int *naddr, u8 *addr);
  363. int t4vf_get_vf_vlan_acl(struct adapter *adapter);
  364. #endif /* __T4VF_COMMON_H__ */