Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _OPA_VNIC_INTERNAL_H
0002 #define _OPA_VNIC_INTERNAL_H
0003 /*
0004  * Copyright(c) 2017 Intel Corporation.
0005  *
0006  * This file is provided under a dual BSD/GPLv2 license.  When using or
0007  * redistributing this file, you may do so under either license.
0008  *
0009  * GPL LICENSE SUMMARY
0010  *
0011  * This program is free software; you can redistribute it and/or modify
0012  * it under the terms of version 2 of the GNU General Public License as
0013  * published by the Free Software Foundation.
0014  *
0015  * This program is distributed in the hope that it will be useful, but
0016  * WITHOUT ANY WARRANTY; without even the implied warranty of
0017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0018  * General Public License for more details.
0019  *
0020  * BSD LICENSE
0021  *
0022  * Redistribution and use in source and binary forms, with or without
0023  * modification, are permitted provided that the following conditions
0024  * are met:
0025  *
0026  *  - Redistributions of source code must retain the above copyright
0027  *    notice, this list of conditions and the following disclaimer.
0028  *  - Redistributions in binary form must reproduce the above copyright
0029  *    notice, this list of conditions and the following disclaimer in
0030  *    the documentation and/or other materials provided with the
0031  *    distribution.
0032  *  - Neither the name of Intel Corporation nor the names of its
0033  *    contributors may be used to endorse or promote products derived
0034  *    from this software without specific prior written permission.
0035  *
0036  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0037  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0038  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0039  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0040  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0043  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0044  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0045  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0046  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0047  *
0048  */
0049 
0050 /*
0051  * This file contains OPA VNIC driver internal declarations
0052  */
0053 
0054 #include <linux/bitops.h>
0055 #include <linux/etherdevice.h>
0056 #include <linux/hashtable.h>
0057 #include <linux/sizes.h>
0058 #include <rdma/opa_vnic.h>
0059 
0060 #include "opa_vnic_encap.h"
0061 
0062 #define OPA_VNIC_VLAN_PCP(vlan_tci)  \
0063             (((vlan_tci) & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT)
0064 
0065 /* Flow to default port redirection table size */
0066 #define OPA_VNIC_FLOW_TBL_SIZE    32
0067 
0068 /* Invalid port number */
0069 #define OPA_VNIC_INVALID_PORT     0xff
0070 
0071 struct opa_vnic_adapter;
0072 
0073 /*
0074  * struct __opa_vesw_info - OPA vnic virtual switch info
0075  *
0076  * Same as opa_vesw_info without bitwise attribute.
0077  */
0078 struct __opa_vesw_info {
0079     u16  fabric_id;
0080     u16  vesw_id;
0081 
0082     u8   rsvd0[6];
0083     u16  def_port_mask;
0084 
0085     u8   rsvd1[2];
0086     u16  pkey;
0087 
0088     u8   rsvd2[4];
0089     u32  u_mcast_dlid;
0090     u32  u_ucast_dlid[OPA_VESW_MAX_NUM_DEF_PORT];
0091 
0092     u32  rc;
0093 
0094     u8   rsvd3[56];
0095     u16  eth_mtu;
0096     u8   rsvd4[2];
0097 } __packed;
0098 
0099 /*
0100  * struct __opa_per_veswport_info - OPA vnic per port info
0101  *
0102  * Same as opa_per_veswport_info without bitwise attribute.
0103  */
0104 struct __opa_per_veswport_info {
0105     u32  port_num;
0106 
0107     u8   eth_link_status;
0108     u8   rsvd0[3];
0109 
0110     u8   base_mac_addr[ETH_ALEN];
0111     u8   config_state;
0112     u8   oper_state;
0113 
0114     u16  max_mac_tbl_ent;
0115     u16  max_smac_ent;
0116     u32  mac_tbl_digest;
0117     u8   rsvd1[4];
0118 
0119     u32  encap_slid;
0120 
0121     u8   pcp_to_sc_uc[OPA_VNIC_MAX_NUM_PCP];
0122     u8   pcp_to_vl_uc[OPA_VNIC_MAX_NUM_PCP];
0123     u8   pcp_to_sc_mc[OPA_VNIC_MAX_NUM_PCP];
0124     u8   pcp_to_vl_mc[OPA_VNIC_MAX_NUM_PCP];
0125 
0126     u8   non_vlan_sc_uc;
0127     u8   non_vlan_vl_uc;
0128     u8   non_vlan_sc_mc;
0129     u8   non_vlan_vl_mc;
0130 
0131     u8   rsvd2[48];
0132 
0133     u16  uc_macs_gen_count;
0134     u16  mc_macs_gen_count;
0135 
0136     u8   rsvd3[8];
0137 } __packed;
0138 
0139 /*
0140  * struct __opa_veswport_info - OPA vnic port info
0141  *
0142  * Same as opa_veswport_info without bitwise attribute.
0143  */
0144 struct __opa_veswport_info {
0145     struct __opa_vesw_info            vesw;
0146     struct __opa_per_veswport_info    vport;
0147 };
0148 
0149 /*
0150  * struct __opa_veswport_trap - OPA vnic trap info
0151  *
0152  * Same as opa_veswport_trap without bitwise attribute.
0153  */
0154 struct __opa_veswport_trap {
0155     u16 fabric_id;
0156     u16 veswid;
0157     u32 veswportnum;
0158     u16 opaportnum;
0159     u8  veswportindex;
0160     u8  opcode;
0161     u32 reserved;
0162 } __packed;
0163 
0164 /**
0165  * struct opa_vnic_ctrl_port - OPA virtual NIC control port
0166  * @ibdev: pointer to ib device
0167  * @ops: opa vnic control operations
0168  * @num_ports: number of opa ports
0169  */
0170 struct opa_vnic_ctrl_port {
0171     struct ib_device           *ibdev;
0172     struct opa_vnic_ctrl_ops   *ops;
0173     u8                          num_ports;
0174 };
0175 
0176 /**
0177  * struct opa_vnic_adapter - OPA VNIC netdev private data structure
0178  * @netdev: pointer to associated netdev
0179  * @ibdev: ib device
0180  * @cport: pointer to opa vnic control port
0181  * @rn_ops: rdma netdev's net_device_ops
0182  * @port_num: OPA port number
0183  * @vport_num: vesw port number
0184  * @lock: adapter lock
0185  * @info: virtual ethernet switch port information
0186  * @vema_mac_addr: mac address configured by vema
0187  * @umac_hash: unicast maclist hash
0188  * @mmac_hash: multicast maclist hash
0189  * @mactbl: hash table of MAC entries
0190  * @mactbl_lock: mac table lock
0191  * @stats_lock: statistics lock
0192  * @flow_tbl: flow to default port redirection table
0193  * @trap_timeout: trap timeout
0194  * @trap_count: no. of traps allowed within timeout period
0195  */
0196 struct opa_vnic_adapter {
0197     struct net_device             *netdev;
0198     struct ib_device              *ibdev;
0199     struct opa_vnic_ctrl_port     *cport;
0200     const struct net_device_ops   *rn_ops;
0201 
0202     u8 port_num;
0203     u8 vport_num;
0204 
0205     /* Lock used around concurrent updates to netdev */
0206     struct mutex lock;
0207 
0208     struct __opa_veswport_info  info;
0209     u8                          vema_mac_addr[ETH_ALEN];
0210     u32                         umac_hash;
0211     u32                         mmac_hash;
0212     struct hlist_head  __rcu   *mactbl;
0213 
0214     /* Lock used to protect updates to mac table */
0215     struct mutex mactbl_lock;
0216 
0217     /* Lock used to protect access to vnic counters */
0218     spinlock_t stats_lock;
0219 
0220     u8 flow_tbl[OPA_VNIC_FLOW_TBL_SIZE];
0221 
0222     unsigned long trap_timeout;
0223     u8            trap_count;
0224 };
0225 
0226 /* Same as opa_veswport_mactable_entry, but without bitwise attribute */
0227 struct __opa_vnic_mactable_entry {
0228     u8  mac_addr[ETH_ALEN];
0229     u8  mac_addr_mask[ETH_ALEN];
0230     u32 dlid_sd;
0231 } __packed;
0232 
0233 /**
0234  * struct opa_vnic_mac_tbl_node - OPA VNIC mac table node
0235  * @hlist: hash list handle
0236  * @index: index of entry in the mac table
0237  * @entry: entry in the table
0238  */
0239 struct opa_vnic_mac_tbl_node {
0240     struct hlist_node                    hlist;
0241     u16                                  index;
0242     struct __opa_vnic_mactable_entry     entry;
0243 };
0244 
0245 #define v_dbg(format, arg...) \
0246     netdev_dbg(adapter->netdev, format, ## arg)
0247 #define v_err(format, arg...) \
0248     netdev_err(adapter->netdev, format, ## arg)
0249 #define v_info(format, arg...) \
0250     netdev_info(adapter->netdev, format, ## arg)
0251 #define v_warn(format, arg...) \
0252     netdev_warn(adapter->netdev, format, ## arg)
0253 
0254 #define c_err(format, arg...) \
0255     dev_err(&cport->ibdev->dev, format, ## arg)
0256 #define c_info(format, arg...) \
0257     dev_info(&cport->ibdev->dev, format, ## arg)
0258 #define c_dbg(format, arg...) \
0259     dev_dbg(&cport->ibdev->dev, format, ## arg)
0260 
0261 /* The maximum allowed entries in the mac table */
0262 #define OPA_VNIC_MAC_TBL_MAX_ENTRIES  2048
0263 /* Limit of smac entries in mac table */
0264 #define OPA_VNIC_MAX_SMAC_LIMIT       256
0265 
0266 /* The last octet of the MAC address is used as the key to the hash table */
0267 #define OPA_VNIC_MAC_HASH_IDX         5
0268 
0269 /* The VNIC MAC hash table is of size 2^8 */
0270 #define OPA_VNIC_MAC_TBL_HASH_BITS    8
0271 #define OPA_VNIC_MAC_TBL_SIZE  BIT(OPA_VNIC_MAC_TBL_HASH_BITS)
0272 
0273 /* VNIC HASH MACROS */
0274 #define vnic_hash_init(hashtable) __hash_init(hashtable, OPA_VNIC_MAC_TBL_SIZE)
0275 
0276 #define vnic_hash_add(hashtable, node, key)                                   \
0277     hlist_add_head(node,                                                  \
0278         &hashtable[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))])
0279 
0280 #define vnic_hash_for_each_safe(name, bkt, tmp, obj, member)                  \
0281     for ((bkt) = 0, obj = NULL;                                           \
0282             !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++)           \
0283         hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)
0284 
0285 #define vnic_hash_for_each_possible(name, obj, member, key)                   \
0286     hlist_for_each_entry(obj,                                             \
0287         &name[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))], member)
0288 
0289 #define vnic_hash_for_each(name, bkt, obj, member)                            \
0290     for ((bkt) = 0, obj = NULL;                                           \
0291             !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++)           \
0292         hlist_for_each_entry(obj, &name[bkt], member)
0293 
0294 extern char opa_vnic_driver_name[];
0295 
0296 struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
0297                          u8 port_num, u8 vport_num);
0298 void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter);
0299 void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
0300 u8 opa_vnic_get_vl(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
0301 u8 opa_vnic_calc_entropy(struct sk_buff *skb);
0302 void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter);
0303 void opa_vnic_release_mac_tbl(struct opa_vnic_adapter *adapter);
0304 void opa_vnic_query_mac_tbl(struct opa_vnic_adapter *adapter,
0305                 struct opa_veswport_mactable *tbl);
0306 int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter,
0307                 struct opa_veswport_mactable *tbl);
0308 void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,
0309                    struct opa_veswport_iface_macs *macs);
0310 void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,
0311                    struct opa_veswport_iface_macs *macs);
0312 void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,
0313                    struct opa_veswport_summary_counters *cntrs);
0314 void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,
0315                  struct opa_veswport_error_counters *cntrs);
0316 void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,
0317                 struct opa_vesw_info *info);
0318 void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,
0319                 struct opa_vesw_info *info);
0320 void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,
0321                     struct opa_per_veswport_info *info);
0322 void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,
0323                     struct opa_per_veswport_info *info);
0324 void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event);
0325 void opa_vnic_set_ethtool_ops(struct net_device *netdev);
0326 void opa_vnic_vema_send_trap(struct opa_vnic_adapter *adapter,
0327                  struct __opa_veswport_trap *data, u32 lid);
0328 
0329 #endif /* _OPA_VNIC_INTERNAL_H */