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