opa_vnic_encap.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. #ifndef _OPA_VNIC_ENCAP_H
  2. #define _OPA_VNIC_ENCAP_H
  3. /*
  4. * Copyright(c) 2017 Intel Corporation.
  5. *
  6. * This file is provided under a dual BSD/GPLv2 license. When using or
  7. * redistributing this file, you may do so under either license.
  8. *
  9. * GPL LICENSE SUMMARY
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * - Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * - Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * - Neither the name of Intel Corporation nor the names of its
  33. * contributors may be used to endorse or promote products derived
  34. * from this software without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  43. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  44. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. /*
  50. * This file contains all OPA VNIC declaration required for encapsulation
  51. * and decapsulation of Ethernet packets
  52. */
  53. #include <linux/types.h>
  54. #include <rdma/ib_mad.h>
  55. /* EMA class version */
  56. #define OPA_EMA_CLASS_VERSION 0x80
  57. /*
  58. * Define the Intel vendor management class for OPA
  59. * ETHERNET MANAGEMENT
  60. */
  61. #define OPA_MGMT_CLASS_INTEL_EMA 0x34
  62. /* EM attribute IDs */
  63. #define OPA_EM_ATTR_CLASS_PORT_INFO 0x0001
  64. #define OPA_EM_ATTR_VESWPORT_INFO 0x0011
  65. #define OPA_EM_ATTR_VESWPORT_MAC_ENTRIES 0x0012
  66. #define OPA_EM_ATTR_IFACE_UCAST_MACS 0x0013
  67. #define OPA_EM_ATTR_IFACE_MCAST_MACS 0x0014
  68. #define OPA_EM_ATTR_DELETE_VESW 0x0015
  69. #define OPA_EM_ATTR_VESWPORT_SUMMARY_COUNTERS 0x0020
  70. #define OPA_EM_ATTR_VESWPORT_ERROR_COUNTERS 0x0022
  71. /* VNIC configured and operational state values */
  72. #define OPA_VNIC_STATE_DROP_ALL 0x1
  73. #define OPA_VNIC_STATE_FORWARDING 0x3
  74. #define OPA_VESW_MAX_NUM_DEF_PORT 16
  75. #define OPA_VNIC_MAX_NUM_PCP 8
  76. #define OPA_VNIC_EMA_DATA (OPA_MGMT_MAD_SIZE - IB_MGMT_VENDOR_HDR)
  77. /* Defines for vendor specific notice(trap) attributes */
  78. #define OPA_INTEL_EMA_NOTICE_TYPE_INFO 0x04
  79. /* INTEL OUI */
  80. #define INTEL_OUI_1 0x00
  81. #define INTEL_OUI_2 0x06
  82. #define INTEL_OUI_3 0x6a
  83. /* Trap opcodes sent from VNIC */
  84. #define OPA_VESWPORT_TRAP_IFACE_UCAST_MAC_CHANGE 0x1
  85. #define OPA_VESWPORT_TRAP_IFACE_MCAST_MAC_CHANGE 0x2
  86. #define OPA_VESWPORT_TRAP_ETH_LINK_STATUS_CHANGE 0x3
  87. #define OPA_VNIC_DLID_SD_IS_SRC_MAC(dlid_sd) (!!((dlid_sd) & 0x20))
  88. #define OPA_VNIC_DLID_SD_GET_DLID(dlid_sd) ((dlid_sd) >> 8)
  89. /* VNIC Ethernet link status */
  90. #define OPA_VNIC_ETH_LINK_UP 1
  91. #define OPA_VNIC_ETH_LINK_DOWN 2
  92. /* routing control */
  93. #define OPA_VNIC_ENCAP_RC_DEFAULT 0
  94. #define OPA_VNIC_ENCAP_RC_IPV4 4
  95. #define OPA_VNIC_ENCAP_RC_IPV4_UDP 8
  96. #define OPA_VNIC_ENCAP_RC_IPV4_TCP 12
  97. #define OPA_VNIC_ENCAP_RC_IPV6 16
  98. #define OPA_VNIC_ENCAP_RC_IPV6_TCP 20
  99. #define OPA_VNIC_ENCAP_RC_IPV6_UDP 24
  100. #define OPA_VNIC_ENCAP_RC_EXT(w, b) (((w) >> OPA_VNIC_ENCAP_RC_ ## b) & 0x7)
  101. /**
  102. * struct opa_vesw_info - OPA vnic switch information
  103. * @fabric_id: 10-bit fabric id
  104. * @vesw_id: 12-bit virtual ethernet switch id
  105. * @def_port_mask: bitmask of default ports
  106. * @pkey: partition key
  107. * @u_mcast_dlid: unknown multicast dlid
  108. * @u_ucast_dlid: array of unknown unicast dlids
  109. * @rc: routing control
  110. * @eth_mtu: Ethernet MTU
  111. */
  112. struct opa_vesw_info {
  113. __be16 fabric_id;
  114. __be16 vesw_id;
  115. u8 rsvd0[6];
  116. __be16 def_port_mask;
  117. u8 rsvd1[2];
  118. __be16 pkey;
  119. u8 rsvd2[4];
  120. __be32 u_mcast_dlid;
  121. __be32 u_ucast_dlid[OPA_VESW_MAX_NUM_DEF_PORT];
  122. __be32 rc;
  123. u8 rsvd3[56];
  124. __be16 eth_mtu;
  125. u8 rsvd4[2];
  126. } __packed;
  127. /**
  128. * struct opa_per_veswport_info - OPA vnic per port information
  129. * @port_num: port number
  130. * @eth_link_status: current ethernet link state
  131. * @base_mac_addr: base mac address
  132. * @config_state: configured port state
  133. * @oper_state: operational port state
  134. * @max_mac_tbl_ent: max number of mac table entries
  135. * @max_smac_ent: max smac entries in mac table
  136. * @mac_tbl_digest: mac table digest
  137. * @encap_slid: base slid for the port
  138. * @pcp_to_sc_uc: sc by pcp index for unicast ethernet packets
  139. * @pcp_to_vl_uc: vl by pcp index for unicast ethernet packets
  140. * @pcp_to_sc_mc: sc by pcp index for multicast ethernet packets
  141. * @pcp_to_vl_mc: vl by pcp index for multicast ethernet packets
  142. * @non_vlan_sc_uc: sc for non-vlan unicast ethernet packets
  143. * @non_vlan_vl_uc: vl for non-vlan unicast ethernet packets
  144. * @non_vlan_sc_mc: sc for non-vlan multicast ethernet packets
  145. * @non_vlan_vl_mc: vl for non-vlan multicast ethernet packets
  146. * @uc_macs_gen_count: generation count for unicast macs list
  147. * @mc_macs_gen_count: generation count for multicast macs list
  148. */
  149. struct opa_per_veswport_info {
  150. __be32 port_num;
  151. u8 eth_link_status;
  152. u8 rsvd0[3];
  153. u8 base_mac_addr[ETH_ALEN];
  154. u8 config_state;
  155. u8 oper_state;
  156. __be16 max_mac_tbl_ent;
  157. __be16 max_smac_ent;
  158. __be32 mac_tbl_digest;
  159. u8 rsvd1[4];
  160. __be32 encap_slid;
  161. u8 pcp_to_sc_uc[OPA_VNIC_MAX_NUM_PCP];
  162. u8 pcp_to_vl_uc[OPA_VNIC_MAX_NUM_PCP];
  163. u8 pcp_to_sc_mc[OPA_VNIC_MAX_NUM_PCP];
  164. u8 pcp_to_vl_mc[OPA_VNIC_MAX_NUM_PCP];
  165. u8 non_vlan_sc_uc;
  166. u8 non_vlan_vl_uc;
  167. u8 non_vlan_sc_mc;
  168. u8 non_vlan_vl_mc;
  169. u8 rsvd2[48];
  170. __be16 uc_macs_gen_count;
  171. __be16 mc_macs_gen_count;
  172. u8 rsvd3[8];
  173. } __packed;
  174. /**
  175. * struct opa_veswport_info - OPA vnic port information
  176. * @vesw: OPA vnic switch information
  177. * @vport: OPA vnic per port information
  178. *
  179. * On host, each of the virtual ethernet ports belongs
  180. * to a different virtual ethernet switches.
  181. */
  182. struct opa_veswport_info {
  183. struct opa_vesw_info vesw;
  184. struct opa_per_veswport_info vport;
  185. };
  186. /**
  187. * struct opa_veswport_mactable_entry - single entry in the forwarding table
  188. * @mac_addr: MAC address
  189. * @mac_addr_mask: MAC address bit mask
  190. * @dlid_sd: Matching DLID and side data
  191. *
  192. * On the host each virtual ethernet port will have
  193. * a forwarding table. These tables are used to
  194. * map a MAC to a LID and other data. For more
  195. * details see struct opa_veswport_mactable_entries.
  196. * This is the structure of a single mactable entry
  197. */
  198. struct opa_veswport_mactable_entry {
  199. u8 mac_addr[ETH_ALEN];
  200. u8 mac_addr_mask[ETH_ALEN];
  201. __be32 dlid_sd;
  202. } __packed;
  203. /**
  204. * struct opa_veswport_mactable - Forwarding table array
  205. * @offset: mac table starting offset
  206. * @num_entries: Number of entries to get or set
  207. * @mac_tbl_digest: mac table digest
  208. * @tbl_entries[]: Array of table entries
  209. *
  210. * The EM sends down this structure in a MAD indicating
  211. * the starting offset in the forwarding table that this
  212. * entry is to be loaded into and the number of entries
  213. * that that this MAD instance contains
  214. * The mac_tbl_digest has been added to this MAD structure. It will be set by
  215. * the EM and it will be used by the EM to check if there are any
  216. * discrepancies with this value and the value
  217. * maintained by the EM in the case of VNIC port being deleted or unloaded
  218. * A new instantiation of a VNIC will always have a value of zero.
  219. * This value is stored as part of the vnic adapter structure and will be
  220. * accessed by the GET and SET routines for both the mactable entries and the
  221. * veswport info.
  222. */
  223. struct opa_veswport_mactable {
  224. __be16 offset;
  225. __be16 num_entries;
  226. __be32 mac_tbl_digest;
  227. struct opa_veswport_mactable_entry tbl_entries[0];
  228. } __packed;
  229. /**
  230. * struct opa_veswport_summary_counters - summary counters
  231. * @vp_instance: vport instance on the OPA port
  232. * @vesw_id: virtual ethernet switch id
  233. * @veswport_num: virtual ethernet switch port number
  234. * @tx_errors: transmit errors
  235. * @rx_errors: receive errors
  236. * @tx_packets: transmit packets
  237. * @rx_packets: receive packets
  238. * @tx_bytes: transmit bytes
  239. * @rx_bytes: receive bytes
  240. * @tx_unicast: unicast packets transmitted
  241. * @tx_mcastbcast: multicast/broadcast packets transmitted
  242. * @tx_untagged: non-vlan packets transmitted
  243. * @tx_vlan: vlan packets transmitted
  244. * @tx_64_size: transmit packet length is 64 bytes
  245. * @tx_65_127: transmit packet length is >=65 and < 127 bytes
  246. * @tx_128_255: transmit packet length is >=128 and < 255 bytes
  247. * @tx_256_511: transmit packet length is >=256 and < 511 bytes
  248. * @tx_512_1023: transmit packet length is >=512 and < 1023 bytes
  249. * @tx_1024_1518: transmit packet length is >=1024 and < 1518 bytes
  250. * @tx_1519_max: transmit packet length >= 1519 bytes
  251. * @rx_unicast: unicast packets received
  252. * @rx_mcastbcast: multicast/broadcast packets received
  253. * @rx_untagged: non-vlan packets received
  254. * @rx_vlan: vlan packets received
  255. * @rx_64_size: received packet length is 64 bytes
  256. * @rx_65_127: received packet length is >=65 and < 127 bytes
  257. * @rx_128_255: received packet length is >=128 and < 255 bytes
  258. * @rx_256_511: received packet length is >=256 and < 511 bytes
  259. * @rx_512_1023: received packet length is >=512 and < 1023 bytes
  260. * @rx_1024_1518: received packet length is >=1024 and < 1518 bytes
  261. * @rx_1519_max: received packet length >= 1519 bytes
  262. *
  263. * All the above are counters of corresponding conditions.
  264. */
  265. struct opa_veswport_summary_counters {
  266. __be16 vp_instance;
  267. __be16 vesw_id;
  268. __be32 veswport_num;
  269. __be64 tx_errors;
  270. __be64 rx_errors;
  271. __be64 tx_packets;
  272. __be64 rx_packets;
  273. __be64 tx_bytes;
  274. __be64 rx_bytes;
  275. __be64 tx_unicast;
  276. __be64 tx_mcastbcast;
  277. __be64 tx_untagged;
  278. __be64 tx_vlan;
  279. __be64 tx_64_size;
  280. __be64 tx_65_127;
  281. __be64 tx_128_255;
  282. __be64 tx_256_511;
  283. __be64 tx_512_1023;
  284. __be64 tx_1024_1518;
  285. __be64 tx_1519_max;
  286. __be64 rx_unicast;
  287. __be64 rx_mcastbcast;
  288. __be64 rx_untagged;
  289. __be64 rx_vlan;
  290. __be64 rx_64_size;
  291. __be64 rx_65_127;
  292. __be64 rx_128_255;
  293. __be64 rx_256_511;
  294. __be64 rx_512_1023;
  295. __be64 rx_1024_1518;
  296. __be64 rx_1519_max;
  297. __be64 reserved[16];
  298. } __packed;
  299. /**
  300. * struct opa_veswport_error_counters - error counters
  301. * @vp_instance: vport instance on the OPA port
  302. * @vesw_id: virtual ethernet switch id
  303. * @veswport_num: virtual ethernet switch port number
  304. * @tx_errors: transmit errors
  305. * @rx_errors: receive errors
  306. * @tx_smac_filt: smac filter errors
  307. * @tx_dlid_zero: transmit packets with invalid dlid
  308. * @tx_logic: other transmit errors
  309. * @tx_drop_state: packet tansmission in non-forward port state
  310. * @rx_bad_veswid: received packet with invalid vesw id
  311. * @rx_runt: received ethernet packet with length < 64 bytes
  312. * @rx_oversize: received ethernet packet with length > MTU size
  313. * @rx_eth_down: received packets when interface is down
  314. * @rx_drop_state: received packets in non-forwarding port state
  315. * @rx_logic: other receive errors
  316. *
  317. * All the above are counters of corresponding erorr conditions.
  318. */
  319. struct opa_veswport_error_counters {
  320. __be16 vp_instance;
  321. __be16 vesw_id;
  322. __be32 veswport_num;
  323. __be64 tx_errors;
  324. __be64 rx_errors;
  325. __be64 rsvd0;
  326. __be64 tx_smac_filt;
  327. __be64 rsvd1;
  328. __be64 rsvd2;
  329. __be64 rsvd3;
  330. __be64 tx_dlid_zero;
  331. __be64 rsvd4;
  332. __be64 tx_logic;
  333. __be64 rsvd5;
  334. __be64 tx_drop_state;
  335. __be64 rx_bad_veswid;
  336. __be64 rsvd6;
  337. __be64 rx_runt;
  338. __be64 rx_oversize;
  339. __be64 rsvd7;
  340. __be64 rx_eth_down;
  341. __be64 rx_drop_state;
  342. __be64 rx_logic;
  343. __be64 rsvd8;
  344. __be64 rsvd9[16];
  345. } __packed;
  346. /**
  347. * struct opa_veswport_trap - Trap message sent to EM by VNIC
  348. * @fabric_id: 10 bit fabric id
  349. * @veswid: 12 bit virtual ethernet switch id
  350. * @veswportnum: logical port number on the Virtual switch
  351. * @opaportnum: physical port num (redundant on host)
  352. * @veswportindex: switch port index on opa port 0 based
  353. * @opcode: operation
  354. * @reserved: 32 bit for alignment
  355. *
  356. * The VNIC will send trap messages to the Ethernet manager to
  357. * inform it about changes to the VNIC config, behaviour etc.
  358. * This is the format of the trap payload.
  359. */
  360. struct opa_veswport_trap {
  361. __be16 fabric_id;
  362. __be16 veswid;
  363. __be32 veswportnum;
  364. __be16 opaportnum;
  365. u8 veswportindex;
  366. u8 opcode;
  367. __be32 reserved;
  368. } __packed;
  369. /**
  370. * struct opa_vnic_iface_macs_entry - single entry in the mac list
  371. * @mac_addr: MAC address
  372. */
  373. struct opa_vnic_iface_mac_entry {
  374. u8 mac_addr[ETH_ALEN];
  375. };
  376. /**
  377. * struct opa_veswport_iface_macs - Msg to set globally administered MAC
  378. * @start_idx: position of first entry (0 based)
  379. * @num_macs_in_msg: number of MACs in this message
  380. * @tot_macs_in_lst: The total number of MACs the agent has
  381. * @gen_count: gen_count to indicate change
  382. * @entry: The mac list entry
  383. *
  384. * Same attribute IDS and attribute modifiers as in locally administered
  385. * addresses used to set globally administered addresses
  386. */
  387. struct opa_veswport_iface_macs {
  388. __be16 start_idx;
  389. __be16 num_macs_in_msg;
  390. __be16 tot_macs_in_lst;
  391. __be16 gen_count;
  392. struct opa_vnic_iface_mac_entry entry[0];
  393. } __packed;
  394. /**
  395. * struct opa_vnic_vema_mad - Generic VEMA MAD
  396. * @mad_hdr: Generic MAD header
  397. * @rmpp_hdr: RMPP header for vendor specific MADs
  398. * @oui: Unique org identifier
  399. * @data: MAD data
  400. */
  401. struct opa_vnic_vema_mad {
  402. struct ib_mad_hdr mad_hdr;
  403. struct ib_rmpp_hdr rmpp_hdr;
  404. u8 reserved;
  405. u8 oui[3];
  406. u8 data[OPA_VNIC_EMA_DATA];
  407. };
  408. /**
  409. * struct opa_vnic_notice_attr - Generic Notice MAD
  410. * @gen_type: Generic/Specific bit and type of notice
  411. * @oui_1: Vendor ID byte 1
  412. * @oui_2: Vendor ID byte 2
  413. * @oui_3: Vendor ID byte 3
  414. * @trap_num: Trap number
  415. * @toggle_count: Notice toggle bit and count value
  416. * @issuer_lid: Trap issuer's lid
  417. * @issuer_gid: Issuer GID (only if Report method)
  418. * @raw_data: Trap message body
  419. */
  420. struct opa_vnic_notice_attr {
  421. u8 gen_type;
  422. u8 oui_1;
  423. u8 oui_2;
  424. u8 oui_3;
  425. __be16 trap_num;
  426. __be16 toggle_count;
  427. __be32 issuer_lid;
  428. __be32 reserved;
  429. u8 issuer_gid[16];
  430. u8 raw_data[64];
  431. } __packed;
  432. /**
  433. * struct opa_vnic_vema_mad_trap - Generic VEMA MAD Trap
  434. * @mad_hdr: Generic MAD header
  435. * @rmpp_hdr: RMPP header for vendor specific MADs
  436. * @oui: Unique org identifier
  437. * @notice: Notice structure
  438. */
  439. struct opa_vnic_vema_mad_trap {
  440. struct ib_mad_hdr mad_hdr;
  441. struct ib_rmpp_hdr rmpp_hdr;
  442. u8 reserved;
  443. u8 oui[3];
  444. struct opa_vnic_notice_attr notice;
  445. };
  446. #endif /* _OPA_VNIC_ENCAP_H */