330 lines · c
1#ifndef _OPA_VNIC_INTERNAL_H2#define _OPA_VNIC_INTERNAL_H3/*4 * Copyright(c) 2017 Intel Corporation.5 *6 * This file is provided under a dual BSD/GPLv2 license. When using or7 * redistributing this file, you may do so under either license.8 *9 * GPL LICENSE SUMMARY10 *11 * This program is free software; you can redistribute it and/or modify12 * it under the terms of version 2 of the GNU General Public License as13 * published by the Free Software Foundation.14 *15 * This program is distributed in the hope that it will be useful, but16 * WITHOUT ANY WARRANTY; without even the implied warranty of17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18 * General Public License for more details.19 *20 * BSD LICENSE21 *22 * Redistribution and use in source and binary forms, with or without23 * modification, are permitted provided that the following conditions24 * are met:25 *26 * - Redistributions of source code must retain the above copyright27 * notice, this list of conditions and the following disclaimer.28 * - Redistributions in binary form must reproduce the above copyright29 * notice, this list of conditions and the following disclaimer in30 * the documentation and/or other materials provided with the31 * distribution.32 * - Neither the name of Intel Corporation nor the names of its33 * contributors may be used to endorse or promote products derived34 * from this software without specific prior written permission.35 *36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS37 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT38 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR39 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT40 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,43 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY44 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE46 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.47 *48 */49 50/*51 * This file contains OPA VNIC driver internal declarations52 */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 3267 68/* Invalid port number */69#define OPA_VNIC_INVALID_PORT 0xff70 71struct opa_vnic_adapter;72 73/*74 * struct __opa_vesw_info - OPA vnic virtual switch info75 *76 * Same as opa_vesw_info without bitwise attribute.77 */78struct __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 u32 rc;93 94 u8 rsvd3[56];95 u16 eth_mtu;96 u8 rsvd4[2];97} __packed;98 99/*100 * struct __opa_per_veswport_info - OPA vnic per port info101 *102 * Same as opa_per_veswport_info without bitwise attribute.103 */104struct __opa_per_veswport_info {105 u32 port_num;106 107 u8 eth_link_status;108 u8 rsvd0[3];109 110 u8 base_mac_addr[ETH_ALEN];111 u8 config_state;112 u8 oper_state;113 114 u16 max_mac_tbl_ent;115 u16 max_smac_ent;116 u32 mac_tbl_digest;117 u8 rsvd1[4];118 119 u32 encap_slid;120 121 u8 pcp_to_sc_uc[OPA_VNIC_MAX_NUM_PCP];122 u8 pcp_to_vl_uc[OPA_VNIC_MAX_NUM_PCP];123 u8 pcp_to_sc_mc[OPA_VNIC_MAX_NUM_PCP];124 u8 pcp_to_vl_mc[OPA_VNIC_MAX_NUM_PCP];125 126 u8 non_vlan_sc_uc;127 u8 non_vlan_vl_uc;128 u8 non_vlan_sc_mc;129 u8 non_vlan_vl_mc;130 131 u8 rsvd2[48];132 133 u16 uc_macs_gen_count;134 u16 mc_macs_gen_count;135 136 u8 rsvd3[8];137} __packed;138 139/*140 * struct __opa_veswport_info - OPA vnic port info141 *142 * Same as opa_veswport_info without bitwise attribute.143 */144struct __opa_veswport_info {145 struct __opa_vesw_info vesw;146 struct __opa_per_veswport_info vport;147};148 149/*150 * struct __opa_veswport_trap - OPA vnic trap info151 *152 * Same as opa_veswport_trap without bitwise attribute.153 */154struct __opa_veswport_trap {155 u16 fabric_id;156 u16 veswid;157 u32 veswportnum;158 u16 opaportnum;159 u8 veswportindex;160 u8 opcode;161 u32 reserved;162} __packed;163 164/**165 * struct opa_vnic_ctrl_port - OPA virtual NIC control port166 * @ibdev: pointer to ib device167 * @ops: opa vnic control operations168 * @num_ports: number of opa ports169 */170struct opa_vnic_ctrl_port {171 struct ib_device *ibdev;172 struct opa_vnic_ctrl_ops *ops;173 u8 num_ports;174};175 176/**177 * struct opa_vnic_adapter - OPA VNIC netdev private data structure178 * @netdev: pointer to associated netdev179 * @ibdev: ib device180 * @cport: pointer to opa vnic control port181 * @rn_ops: rdma netdev's net_device_ops182 * @port_num: OPA port number183 * @vport_num: vesw port number184 * @lock: adapter lock185 * @info: virtual ethernet switch port information186 * @vema_mac_addr: mac address configured by vema187 * @umac_hash: unicast maclist hash188 * @mmac_hash: multicast maclist hash189 * @mactbl: hash table of MAC entries190 * @mactbl_lock: mac table lock191 * @stats_lock: statistics lock192 * @flow_tbl: flow to default port redirection table193 * @trap_timeout: trap timeout194 * @trap_count: no. of traps allowed within timeout period195 */196struct opa_vnic_adapter {197 struct net_device *netdev;198 struct ib_device *ibdev;199 struct opa_vnic_ctrl_port *cport;200 const struct net_device_ops *rn_ops;201 202 u8 port_num;203 u8 vport_num;204 205 /* Lock used around concurrent updates to netdev */206 struct mutex lock;207 208 struct __opa_veswport_info info;209 u8 vema_mac_addr[ETH_ALEN];210 u32 umac_hash;211 u32 mmac_hash;212 struct hlist_head __rcu *mactbl;213 214 /* Lock used to protect updates to mac table */215 struct mutex mactbl_lock;216 217 /* Lock used to protect access to vnic counters */218 spinlock_t stats_lock;219 220 u8 flow_tbl[OPA_VNIC_FLOW_TBL_SIZE];221 222 unsigned long trap_timeout;223 u8 trap_count;224};225 226/* Same as opa_veswport_mactable_entry, but without bitwise attribute */227struct __opa_vnic_mactable_entry {228 u8 mac_addr[ETH_ALEN];229 u8 mac_addr_mask[ETH_ALEN];230 u32 dlid_sd;231} __packed;232 233/**234 * struct opa_vnic_mac_tbl_node - OPA VNIC mac table node235 * @hlist: hash list handle236 * @index: index of entry in the mac table237 * @entry: entry in the table238 */239struct opa_vnic_mac_tbl_node {240 struct hlist_node hlist;241 u16 index;242 struct __opa_vnic_mactable_entry entry;243};244 245#define v_dbg(format, arg...) \246 netdev_dbg(adapter->netdev, format, ## arg)247#define v_err(format, arg...) \248 netdev_err(adapter->netdev, format, ## arg)249#define v_info(format, arg...) \250 netdev_info(adapter->netdev, format, ## arg)251#define v_warn(format, arg...) \252 netdev_warn(adapter->netdev, format, ## arg)253 254#define c_err(format, arg...) \255 dev_err(&cport->ibdev->dev, format, ## arg)256#define c_info(format, arg...) \257 dev_info(&cport->ibdev->dev, format, ## arg)258#define c_dbg(format, arg...) \259 dev_dbg(&cport->ibdev->dev, format, ## arg)260 261/* The maximum allowed entries in the mac table */262#define OPA_VNIC_MAC_TBL_MAX_ENTRIES 2048263/* Limit of smac entries in mac table */264#define OPA_VNIC_MAX_SMAC_LIMIT 256265 266/* The last octet of the MAC address is used as the key to the hash table */267#define OPA_VNIC_MAC_HASH_IDX 5268 269/* The VNIC MAC hash table is of size 2^8 */270#define OPA_VNIC_MAC_TBL_HASH_BITS 8271#define OPA_VNIC_MAC_TBL_SIZE BIT(OPA_VNIC_MAC_TBL_HASH_BITS)272 273/* VNIC HASH MACROS */274#define vnic_hash_init(hashtable) __hash_init(hashtable, OPA_VNIC_MAC_TBL_SIZE)275 276#define vnic_hash_add(hashtable, node, key) \277 hlist_add_head(node, \278 &hashtable[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))])279 280#define vnic_hash_for_each_safe(name, bkt, tmp, obj, member) \281 for ((bkt) = 0, obj = NULL; \282 !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++) \283 hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)284 285#define vnic_hash_for_each_possible(name, obj, member, key) \286 hlist_for_each_entry(obj, \287 &name[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))], member)288 289#define vnic_hash_for_each(name, bkt, obj, member) \290 for ((bkt) = 0, obj = NULL; \291 !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++) \292 hlist_for_each_entry(obj, &name[bkt], member)293 294extern char opa_vnic_driver_name[];295 296struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,297 u8 port_num, u8 vport_num);298void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter);299void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb);300u8 opa_vnic_get_vl(struct opa_vnic_adapter *adapter, struct sk_buff *skb);301u8 opa_vnic_calc_entropy(struct sk_buff *skb);302void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter);303void opa_vnic_release_mac_tbl(struct opa_vnic_adapter *adapter);304void opa_vnic_query_mac_tbl(struct opa_vnic_adapter *adapter,305 struct opa_veswport_mactable *tbl);306int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter,307 struct opa_veswport_mactable *tbl);308void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,309 struct opa_veswport_iface_macs *macs);310void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,311 struct opa_veswport_iface_macs *macs);312void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,313 struct opa_veswport_summary_counters *cntrs);314void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,315 struct opa_veswport_error_counters *cntrs);316void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,317 struct opa_vesw_info *info);318void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,319 struct opa_vesw_info *info);320void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,321 struct opa_per_veswport_info *info);322void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,323 struct opa_per_veswport_info *info);324void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event);325void opa_vnic_set_ethtool_ops(struct net_device *netdev);326void 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