linux/drivers/net/ethernet/intel/ice/ice_virtchnl_pf.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/* Copyright (c) 2018, Intel Corporation. */
   3
   4#ifndef _ICE_VIRTCHNL_PF_H_
   5#define _ICE_VIRTCHNL_PF_H_
   6#include "ice.h"
   7#include "ice_virtchnl_fdir.h"
   8
   9/* Restrict number of MAC Addr and VLAN that non-trusted VF can programmed */
  10#define ICE_MAX_VLAN_PER_VF             8
  11/* MAC filters: 1 is reserved for the VF's default/perm_addr/LAA MAC, 1 for
  12 * broadcast, and 16 for additional unicast/multicast filters
  13 */
  14#define ICE_MAX_MACADDR_PER_VF          18
  15
  16/* Malicious Driver Detection */
  17#define ICE_DFLT_NUM_INVAL_MSGS_ALLOWED         10
  18#define ICE_MDD_EVENTS_THRESHOLD                30
  19
  20/* Static VF transaction/status register def */
  21#define VF_DEVICE_STATUS                0xAA
  22#define VF_TRANS_PENDING_M              0x20
  23
  24/* wait defines for polling PF_PCI_CIAD register status */
  25#define ICE_PCI_CIAD_WAIT_COUNT         100
  26#define ICE_PCI_CIAD_WAIT_DELAY_US      1
  27
  28/* VF resource constraints */
  29#define ICE_MAX_VF_COUNT                256
  30#define ICE_MIN_QS_PER_VF               1
  31#define ICE_NONQ_VECS_VF                1
  32#define ICE_MAX_SCATTER_QS_PER_VF       16
  33#define ICE_MAX_RSS_QS_PER_VF           16
  34#define ICE_NUM_VF_MSIX_MED             17
  35#define ICE_NUM_VF_MSIX_SMALL           5
  36#define ICE_NUM_VF_MSIX_MULTIQ_MIN      3
  37#define ICE_MIN_INTR_PER_VF             (ICE_MIN_QS_PER_VF + 1)
  38#define ICE_MAX_VF_RESET_TRIES          40
  39#define ICE_MAX_VF_RESET_SLEEP_MS       20
  40
  41#define ice_for_each_vf(pf, i) \
  42        for ((i) = 0; (i) < (pf)->num_alloc_vfs; (i)++)
  43
  44/* Specific VF states */
  45enum ice_vf_states {
  46        ICE_VF_STATE_INIT = 0,          /* PF is initializing VF */
  47        ICE_VF_STATE_ACTIVE,            /* VF resources are allocated for use */
  48        ICE_VF_STATE_QS_ENA,            /* VF queue(s) enabled */
  49        ICE_VF_STATE_DIS,
  50        ICE_VF_STATE_MC_PROMISC,
  51        ICE_VF_STATE_UC_PROMISC,
  52        ICE_VF_STATES_NBITS
  53};
  54
  55/* VF capabilities */
  56enum ice_virtchnl_cap {
  57        ICE_VIRTCHNL_VF_CAP_L2 = 0,
  58        ICE_VIRTCHNL_VF_CAP_PRIVILEGE,
  59};
  60
  61/* VF MDD events print structure */
  62struct ice_mdd_vf_events {
  63        u16 count;                      /* total count of Rx|Tx events */
  64        /* count number of the last printed event */
  65        u16 last_printed;
  66};
  67
  68/* VF information structure */
  69struct ice_vf {
  70        struct ice_pf *pf;
  71
  72        u16 vf_id;                      /* VF ID in the PF space */
  73        u16 lan_vsi_idx;                /* index into PF struct */
  74        u16 ctrl_vsi_idx;
  75        struct ice_vf_fdir fdir;
  76        /* first vector index of this VF in the PF space */
  77        int first_vector_idx;
  78        struct ice_sw *vf_sw_id;        /* switch ID the VF VSIs connect to */
  79        struct virtchnl_version_info vf_ver;
  80        u32 driver_caps;                /* reported by VF driver */
  81        struct virtchnl_ether_addr dflt_lan_addr;
  82        DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
  83        DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
  84        u16 port_vlan_info;             /* Port VLAN ID and QoS */
  85        u8 pf_set_mac:1;                /* VF MAC address set by VMM admin */
  86        u8 trusted:1;
  87        u8 spoofchk:1;
  88        u8 link_forced:1;
  89        u8 link_up:1;                   /* only valid if VF link is forced */
  90        /* VSI indices - actual VSI pointers are maintained in the PF structure
  91         * When assigned, these will be non-zero, because VSI 0 is always
  92         * the main LAN VSI for the PF.
  93         */
  94        u16 lan_vsi_num;                /* ID as used by firmware */
  95        unsigned int tx_rate;           /* Tx bandwidth limit in Mbps */
  96        DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
  97
  98        u64 num_inval_msgs;             /* number of continuous invalid msgs */
  99        u64 num_valid_msgs;             /* number of valid msgs detected */
 100        unsigned long vf_caps;          /* VF's adv. capabilities */
 101        u8 num_req_qs;                  /* num of queue pairs requested by VF */
 102        u16 num_mac;
 103        u16 num_vf_qs;                  /* num of queue configured per VF */
 104        struct ice_mdd_vf_events mdd_rx_events;
 105        struct ice_mdd_vf_events mdd_tx_events;
 106        DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
 107};
 108
 109#ifdef CONFIG_PCI_IOV
 110void ice_process_vflr_event(struct ice_pf *pf);
 111int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
 112int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
 113int
 114ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
 115
 116void ice_free_vfs(struct ice_pf *pf);
 117void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
 118void ice_vc_notify_link_state(struct ice_pf *pf);
 119void ice_vc_notify_reset(struct ice_pf *pf);
 120bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
 121bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
 122void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
 123bool
 124ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
 125                    u16 num_msg_proc, u16 num_msg_pending);
 126
 127int
 128ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
 129                     __be16 vlan_proto);
 130
 131int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
 132
 133int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
 134
 135int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
 136
 137int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
 138
 139void ice_set_vf_state_qs_dis(struct ice_vf *vf);
 140int
 141ice_get_vf_stats(struct net_device *netdev, int vf_id,
 142                 struct ifla_vf_stats *vf_stats);
 143bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
 144void
 145ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
 146void ice_print_vfs_mdd_events(struct ice_pf *pf);
 147void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
 148struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf);
 149int
 150ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
 151                      enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
 152bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
 153#else /* CONFIG_PCI_IOV */
 154#define ice_process_vflr_event(pf) do {} while (0)
 155#define ice_free_vfs(pf) do {} while (0)
 156#define ice_vc_process_vf_msg(pf, event) do {} while (0)
 157#define ice_vc_notify_link_state(pf) do {} while (0)
 158#define ice_vc_notify_reset(pf) do {} while (0)
 159#define ice_set_vf_state_qs_dis(vf) do {} while (0)
 160#define ice_vf_lan_overflow_event(pf, event) do {} while (0)
 161#define ice_print_vfs_mdd_events(pf) do {} while (0)
 162#define ice_print_vf_rx_mdd_event(vf) do {} while (0)
 163#define ice_restore_all_vfs_msi_state(pdev) do {} while (0)
 164
 165static inline bool
 166ice_is_malicious_vf(struct ice_pf __always_unused *pf,
 167                    struct ice_rq_event_info __always_unused *event,
 168                    u16 __always_unused num_msg_proc,
 169                    u16 __always_unused num_msg_pending)
 170{
 171        return false;
 172}
 173
 174static inline bool
 175ice_reset_all_vfs(struct ice_pf __always_unused *pf,
 176                  bool __always_unused is_vflr)
 177{
 178        return true;
 179}
 180
 181static inline bool
 182ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
 183{
 184        return true;
 185}
 186
 187static inline int
 188ice_sriov_configure(struct pci_dev __always_unused *pdev,
 189                    int __always_unused num_vfs)
 190{
 191        return -EOPNOTSUPP;
 192}
 193
 194static inline int
 195ice_set_vf_mac(struct net_device __always_unused *netdev,
 196               int __always_unused vf_id, u8 __always_unused *mac)
 197{
 198        return -EOPNOTSUPP;
 199}
 200
 201static inline int
 202ice_get_vf_cfg(struct net_device __always_unused *netdev,
 203               int __always_unused vf_id,
 204               struct ifla_vf_info __always_unused *ivi)
 205{
 206        return -EOPNOTSUPP;
 207}
 208
 209static inline int
 210ice_set_vf_trust(struct net_device __always_unused *netdev,
 211                 int __always_unused vf_id, bool __always_unused trusted)
 212{
 213        return -EOPNOTSUPP;
 214}
 215
 216static inline int
 217ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
 218                     int __always_unused vf_id, u16 __always_unused vid,
 219                     u8 __always_unused qos, __be16 __always_unused v_proto)
 220{
 221        return -EOPNOTSUPP;
 222}
 223
 224static inline int
 225ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
 226                    int __always_unused vf_id, bool __always_unused ena)
 227{
 228        return -EOPNOTSUPP;
 229}
 230
 231static inline int
 232ice_set_vf_link_state(struct net_device __always_unused *netdev,
 233                      int __always_unused vf_id, int __always_unused link_state)
 234{
 235        return -EOPNOTSUPP;
 236}
 237
 238static inline int
 239ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
 240                    struct ice_q_vector __always_unused *q_vector)
 241{
 242        return 0;
 243}
 244
 245static inline int
 246ice_get_vf_stats(struct net_device __always_unused *netdev,
 247                 int __always_unused vf_id,
 248                 struct ifla_vf_stats __always_unused *vf_stats)
 249{
 250        return -EOPNOTSUPP;
 251}
 252
 253static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
 254{
 255        return false;
 256}
 257#endif /* CONFIG_PCI_IOV */
 258#endif /* _ICE_VIRTCHNL_PF_H_ */
 259