0001 #ifndef _OPA_VNIC_INTERNAL_H
0002 #define _OPA_VNIC_INTERNAL_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
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
0066 #define OPA_VNIC_FLOW_TBL_SIZE 32
0067
0068
0069 #define OPA_VNIC_INVALID_PORT 0xff
0070
0071 struct opa_vnic_adapter;
0072
0073
0074
0075
0076
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
0101
0102
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
0141
0142
0143
0144 struct __opa_veswport_info {
0145 struct __opa_vesw_info vesw;
0146 struct __opa_per_veswport_info vport;
0147 };
0148
0149
0150
0151
0152
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
0166
0167
0168
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
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
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
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
0215 struct mutex mactbl_lock;
0216
0217
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
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
0235
0236
0237
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
0262 #define OPA_VNIC_MAC_TBL_MAX_ENTRIES 2048
0263
0264 #define OPA_VNIC_MAX_SMAC_LIMIT 256
0265
0266
0267 #define OPA_VNIC_MAC_HASH_IDX 5
0268
0269
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
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