cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

opa_vnic_internal.h (10726B)


      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
     71struct 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 */
     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 info
    101 *
    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 info
    141 *
    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 info
    151 *
    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 port
    166 * @ibdev: pointer to ib device
    167 * @ops: opa vnic control operations
    168 * @num_ports: number of opa ports
    169 */
    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 structure
    178 * @netdev: pointer to associated netdev
    179 * @ibdev: ib device
    180 * @cport: pointer to opa vnic control port
    181 * @rn_ops: rdma netdev's net_device_ops
    182 * @port_num: OPA port number
    183 * @vport_num: vesw port number
    184 * @lock: adapter lock
    185 * @info: virtual ethernet switch port information
    186 * @vema_mac_addr: mac address configured by vema
    187 * @umac_hash: unicast maclist hash
    188 * @mmac_hash: multicast maclist hash
    189 * @mactbl: hash table of MAC entries
    190 * @mactbl_lock: mac table lock
    191 * @stats_lock: statistics lock
    192 * @flow_tbl: flow to default port redirection table
    193 * @trap_timeout: trap timeout
    194 * @trap_count: no. of traps allowed within timeout period
    195 */
    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 node
    235 * @hlist: hash list handle
    236 * @index: index of entry in the mac table
    237 * @entry: entry in the table
    238 */
    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  2048
    263/* Limit of smac entries in mac table */
    264#define OPA_VNIC_MAX_SMAC_LIMIT       256
    265
    266/* The last octet of the MAC address is used as the key to the hash table */
    267#define OPA_VNIC_MAC_HASH_IDX         5
    268
    269/* The VNIC MAC hash table is of size 2^8 */
    270#define OPA_VNIC_MAC_TBL_HASH_BITS    8
    271#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 */