opa_vnic_internal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #ifndef _OPA_VNIC_INTERNAL_H
  2. #define _OPA_VNIC_INTERNAL_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 OPA VNIC driver internal declarations
  51. */
  52. #include <linux/bitops.h>
  53. #include <linux/etherdevice.h>
  54. #include <linux/hashtable.h>
  55. #include <linux/sizes.h>
  56. #include <rdma/opa_vnic.h>
  57. #include "opa_vnic_encap.h"
  58. #define OPA_VNIC_VLAN_PCP(vlan_tci) \
  59. (((vlan_tci) & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT)
  60. /* Flow to default port redirection table size */
  61. #define OPA_VNIC_FLOW_TBL_SIZE 32
  62. /* Invalid port number */
  63. #define OPA_VNIC_INVALID_PORT 0xff
  64. struct opa_vnic_adapter;
  65. /**
  66. * struct __opa_vesw_info - OPA vnic virtual switch info
  67. *
  68. * Same as opa_vesw_info without bitwise attribute.
  69. */
  70. struct __opa_vesw_info {
  71. u16 fabric_id;
  72. u16 vesw_id;
  73. u8 rsvd0[6];
  74. u16 def_port_mask;
  75. u8 rsvd1[2];
  76. u16 pkey;
  77. u8 rsvd2[4];
  78. u32 u_mcast_dlid;
  79. u32 u_ucast_dlid[OPA_VESW_MAX_NUM_DEF_PORT];
  80. u32 rc;
  81. u8 rsvd3[56];
  82. u16 eth_mtu;
  83. u8 rsvd4[2];
  84. } __packed;
  85. /**
  86. * struct __opa_per_veswport_info - OPA vnic per port info
  87. *
  88. * Same as opa_per_veswport_info without bitwise attribute.
  89. */
  90. struct __opa_per_veswport_info {
  91. u32 port_num;
  92. u8 eth_link_status;
  93. u8 rsvd0[3];
  94. u8 base_mac_addr[ETH_ALEN];
  95. u8 config_state;
  96. u8 oper_state;
  97. u16 max_mac_tbl_ent;
  98. u16 max_smac_ent;
  99. u32 mac_tbl_digest;
  100. u8 rsvd1[4];
  101. u32 encap_slid;
  102. u8 pcp_to_sc_uc[OPA_VNIC_MAX_NUM_PCP];
  103. u8 pcp_to_vl_uc[OPA_VNIC_MAX_NUM_PCP];
  104. u8 pcp_to_sc_mc[OPA_VNIC_MAX_NUM_PCP];
  105. u8 pcp_to_vl_mc[OPA_VNIC_MAX_NUM_PCP];
  106. u8 non_vlan_sc_uc;
  107. u8 non_vlan_vl_uc;
  108. u8 non_vlan_sc_mc;
  109. u8 non_vlan_vl_mc;
  110. u8 rsvd2[48];
  111. u16 uc_macs_gen_count;
  112. u16 mc_macs_gen_count;
  113. u8 rsvd3[8];
  114. } __packed;
  115. /**
  116. * struct __opa_veswport_info - OPA vnic port info
  117. *
  118. * Same as opa_veswport_info without bitwise attribute.
  119. */
  120. struct __opa_veswport_info {
  121. struct __opa_vesw_info vesw;
  122. struct __opa_per_veswport_info vport;
  123. };
  124. /**
  125. * struct __opa_veswport_trap - OPA vnic trap info
  126. *
  127. * Same as opa_veswport_trap without bitwise attribute.
  128. */
  129. struct __opa_veswport_trap {
  130. u16 fabric_id;
  131. u16 veswid;
  132. u32 veswportnum;
  133. u16 opaportnum;
  134. u8 veswportindex;
  135. u8 opcode;
  136. u32 reserved;
  137. } __packed;
  138. /**
  139. * struct opa_vnic_ctrl_port - OPA virtual NIC control port
  140. * @ibdev: pointer to ib device
  141. * @ops: opa vnic control operations
  142. * @num_ports: number of opa ports
  143. */
  144. struct opa_vnic_ctrl_port {
  145. struct ib_device *ibdev;
  146. struct opa_vnic_ctrl_ops *ops;
  147. u8 num_ports;
  148. };
  149. /**
  150. * struct opa_vnic_adapter - OPA VNIC netdev private data structure
  151. * @netdev: pointer to associated netdev
  152. * @ibdev: ib device
  153. * @cport: pointer to opa vnic control port
  154. * @rn_ops: rdma netdev's net_device_ops
  155. * @port_num: OPA port number
  156. * @vport_num: vesw port number
  157. * @lock: adapter lock
  158. * @info: virtual ethernet switch port information
  159. * @vema_mac_addr: mac address configured by vema
  160. * @umac_hash: unicast maclist hash
  161. * @mmac_hash: multicast maclist hash
  162. * @mactbl: hash table of MAC entries
  163. * @mactbl_lock: mac table lock
  164. * @stats_lock: statistics lock
  165. * @flow_tbl: flow to default port redirection table
  166. * @trap_timeout: trap timeout
  167. * @trap_count: no. of traps allowed within timeout period
  168. */
  169. struct opa_vnic_adapter {
  170. struct net_device *netdev;
  171. struct ib_device *ibdev;
  172. struct opa_vnic_ctrl_port *cport;
  173. const struct net_device_ops *rn_ops;
  174. u8 port_num;
  175. u8 vport_num;
  176. /* Lock used around concurrent updates to netdev */
  177. struct mutex lock;
  178. struct __opa_veswport_info info;
  179. u8 vema_mac_addr[ETH_ALEN];
  180. u32 umac_hash;
  181. u32 mmac_hash;
  182. struct hlist_head __rcu *mactbl;
  183. /* Lock used to protect updates to mac table */
  184. struct mutex mactbl_lock;
  185. /* Lock used to protect access to vnic counters */
  186. spinlock_t stats_lock;
  187. u8 flow_tbl[OPA_VNIC_FLOW_TBL_SIZE];
  188. unsigned long trap_timeout;
  189. u8 trap_count;
  190. };
  191. /* Same as opa_veswport_mactable_entry, but without bitwise attribute */
  192. struct __opa_vnic_mactable_entry {
  193. u8 mac_addr[ETH_ALEN];
  194. u8 mac_addr_mask[ETH_ALEN];
  195. u32 dlid_sd;
  196. } __packed;
  197. /**
  198. * struct opa_vnic_mac_tbl_node - OPA VNIC mac table node
  199. * @hlist: hash list handle
  200. * @index: index of entry in the mac table
  201. * @entry: entry in the table
  202. */
  203. struct opa_vnic_mac_tbl_node {
  204. struct hlist_node hlist;
  205. u16 index;
  206. struct __opa_vnic_mactable_entry entry;
  207. };
  208. #define v_dbg(format, arg...) \
  209. netdev_dbg(adapter->netdev, format, ## arg)
  210. #define v_err(format, arg...) \
  211. netdev_err(adapter->netdev, format, ## arg)
  212. #define v_info(format, arg...) \
  213. netdev_info(adapter->netdev, format, ## arg)
  214. #define v_warn(format, arg...) \
  215. netdev_warn(adapter->netdev, format, ## arg)
  216. #define c_err(format, arg...) \
  217. dev_err(&cport->ibdev->dev, format, ## arg)
  218. #define c_info(format, arg...) \
  219. dev_info(&cport->ibdev->dev, format, ## arg)
  220. #define c_dbg(format, arg...) \
  221. dev_dbg(&cport->ibdev->dev, format, ## arg)
  222. /* The maximum allowed entries in the mac table */
  223. #define OPA_VNIC_MAC_TBL_MAX_ENTRIES 2048
  224. /* Limit of smac entries in mac table */
  225. #define OPA_VNIC_MAX_SMAC_LIMIT 256
  226. /* The last octet of the MAC address is used as the key to the hash table */
  227. #define OPA_VNIC_MAC_HASH_IDX 5
  228. /* The VNIC MAC hash table is of size 2^8 */
  229. #define OPA_VNIC_MAC_TBL_HASH_BITS 8
  230. #define OPA_VNIC_MAC_TBL_SIZE BIT(OPA_VNIC_MAC_TBL_HASH_BITS)
  231. /* VNIC HASH MACROS */
  232. #define vnic_hash_init(hashtable) __hash_init(hashtable, OPA_VNIC_MAC_TBL_SIZE)
  233. #define vnic_hash_add(hashtable, node, key) \
  234. hlist_add_head(node, \
  235. &hashtable[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))])
  236. #define vnic_hash_for_each_safe(name, bkt, tmp, obj, member) \
  237. for ((bkt) = 0, obj = NULL; \
  238. !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++) \
  239. hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)
  240. #define vnic_hash_for_each_possible(name, obj, member, key) \
  241. hlist_for_each_entry(obj, \
  242. &name[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))], member)
  243. #define vnic_hash_for_each(name, bkt, obj, member) \
  244. for ((bkt) = 0, obj = NULL; \
  245. !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++) \
  246. hlist_for_each_entry(obj, &name[bkt], member)
  247. extern char opa_vnic_driver_name[];
  248. extern const char opa_vnic_driver_version[];
  249. struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
  250. u8 port_num, u8 vport_num);
  251. void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter);
  252. void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
  253. u8 opa_vnic_get_vl(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
  254. u8 opa_vnic_calc_entropy(struct sk_buff *skb);
  255. void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter);
  256. void opa_vnic_release_mac_tbl(struct opa_vnic_adapter *adapter);
  257. void opa_vnic_query_mac_tbl(struct opa_vnic_adapter *adapter,
  258. struct opa_veswport_mactable *tbl);
  259. int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter,
  260. struct opa_veswport_mactable *tbl);
  261. void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,
  262. struct opa_veswport_iface_macs *macs);
  263. void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,
  264. struct opa_veswport_iface_macs *macs);
  265. void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,
  266. struct opa_veswport_summary_counters *cntrs);
  267. void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,
  268. struct opa_veswport_error_counters *cntrs);
  269. void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,
  270. struct opa_vesw_info *info);
  271. void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,
  272. struct opa_vesw_info *info);
  273. void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,
  274. struct opa_per_veswport_info *info);
  275. void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,
  276. struct opa_per_veswport_info *info);
  277. void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event);
  278. void opa_vnic_set_ethtool_ops(struct net_device *netdev);
  279. void opa_vnic_vema_send_trap(struct opa_vnic_adapter *adapter,
  280. struct __opa_veswport_trap *data, u32 lid);
  281. #endif /* _OPA_VNIC_INTERNAL_H */