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
  61struct ice_time_mac {
  62        unsigned long time_modified;
  63        u8 addr[ETH_ALEN];
  64};
  65
  66/* VF MDD events print structure */
  67struct ice_mdd_vf_events {
  68        u16 count;                      /* total count of Rx|Tx events */
  69        /* count number of the last printed event */
  70        u16 last_printed;
  71};
  72
  73/* VF information structure */
  74struct ice_vf {
  75        struct ice_pf *pf;
  76
  77        u16 vf_id;                      /* VF ID in the PF space */
  78        u16 lan_vsi_idx;                /* index into PF struct */
  79        u16 ctrl_vsi_idx;
  80        struct ice_vf_fdir fdir;
  81        /* first vector index of this VF in the PF space */
  82        int first_vector_idx;
  83        struct ice_sw *vf_sw_id;        /* switch ID the VF VSIs connect to */
  84        struct virtchnl_version_info vf_ver;
  85        u32 driver_caps;                /* reported by VF driver */
  86        struct virtchnl_ether_addr dev_lan_addr;
  87        struct virtchnl_ether_addr hw_lan_addr;
  88        struct ice_time_mac legacy_last_added_umac;
  89        DECLARE_BITMAP(txq_ena, ICE_MAX_RSS_QS_PER_VF);
  90        DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
  91        u16 port_vlan_info;             /* Port VLAN ID and QoS */
  92        u8 pf_set_mac:1;                /* VF MAC address set by VMM admin */
  93        u8 trusted:1;
  94        u8 spoofchk:1;
  95        u8 link_forced:1;
  96        u8 link_up:1;                   /* only valid if VF link is forced */
  97        /* VSI indices - actual VSI pointers are maintained in the PF structure
  98         * When assigned, these will be non-zero, because VSI 0 is always
  99         * the main LAN VSI for the PF.
 100         */
 101        u16 lan_vsi_num;                /* ID as used by firmware */
 102        unsigned int tx_rate;           /* Tx bandwidth limit in Mbps */
 103        DECLARE_BITMAP(vf_states, ICE_VF_STATES_NBITS); /* VF runtime states */
 104
 105        u64 num_inval_msgs;             /* number of continuous invalid msgs */
 106        u64 num_valid_msgs;             /* number of valid msgs detected */
 107        unsigned long vf_caps;          /* VF's adv. capabilities */
 108        u8 num_req_qs;                  /* num of queue pairs requested by VF */
 109        u16 num_mac;
 110        u16 num_vf_qs;                  /* num of queue configured per VF */
 111        struct ice_mdd_vf_events mdd_rx_events;
 112        struct ice_mdd_vf_events mdd_tx_events;
 113        DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
 114};
 115
 116#ifdef CONFIG_PCI_IOV
 117void ice_process_vflr_event(struct ice_pf *pf);
 118int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
 119int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
 120int
 121ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
 122
 123void ice_free_vfs(struct ice_pf *pf);
 124void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
 125void ice_vc_notify_link_state(struct ice_pf *pf);
 126void ice_vc_notify_reset(struct ice_pf *pf);
 127bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr);
 128bool ice_reset_vf(struct ice_vf *vf, bool is_vflr);
 129void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
 130bool
 131ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
 132                    u16 num_msg_proc, u16 num_msg_pending);
 133
 134int
 135ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
 136                     __be16 vlan_proto);
 137
 138int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted);
 139
 140int ice_set_vf_link_state(struct net_device *netdev, int vf_id, int link_state);
 141
 142int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena);
 143
 144int ice_calc_vf_reg_idx(struct ice_vf *vf, struct ice_q_vector *q_vector);
 145
 146void ice_set_vf_state_qs_dis(struct ice_vf *vf);
 147int
 148ice_get_vf_stats(struct net_device *netdev, int vf_id,
 149                 struct ifla_vf_stats *vf_stats);
 150bool ice_is_any_vf_in_promisc(struct ice_pf *pf);
 151void
 152ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event);
 153void ice_print_vfs_mdd_events(struct ice_pf *pf);
 154void ice_print_vf_rx_mdd_event(struct ice_vf *vf);
 155struct ice_vsi *ice_vf_ctrl_vsi_setup(struct ice_vf *vf);
 156int
 157ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
 158                      enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);
 159bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id);
 160#else /* CONFIG_PCI_IOV */
 161static inline void ice_process_vflr_event(struct ice_pf *pf) { }
 162static inline void ice_free_vfs(struct ice_pf *pf) { }
 163static inline
 164void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) { }
 165static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }
 166static inline void ice_vc_notify_reset(struct ice_pf *pf) { }
 167static inline void ice_set_vf_state_qs_dis(struct ice_vf *vf) { }
 168static inline
 169void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
 170static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
 171static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
 172static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
 173
 174static inline bool
 175ice_is_malicious_vf(struct ice_pf __always_unused *pf,
 176                    struct ice_rq_event_info __always_unused *event,
 177                    u16 __always_unused num_msg_proc,
 178                    u16 __always_unused num_msg_pending)
 179{
 180        return false;
 181}
 182
 183static inline bool
 184ice_reset_all_vfs(struct ice_pf __always_unused *pf,
 185                  bool __always_unused is_vflr)
 186{
 187        return true;
 188}
 189
 190static inline bool
 191ice_reset_vf(struct ice_vf __always_unused *vf, bool __always_unused is_vflr)
 192{
 193        return true;
 194}
 195
 196static inline int
 197ice_sriov_configure(struct pci_dev __always_unused *pdev,
 198                    int __always_unused num_vfs)
 199{
 200        return -EOPNOTSUPP;
 201}
 202
 203static inline int
 204ice_set_vf_mac(struct net_device __always_unused *netdev,
 205               int __always_unused vf_id, u8 __always_unused *mac)
 206{
 207        return -EOPNOTSUPP;
 208}
 209
 210static inline int
 211ice_get_vf_cfg(struct net_device __always_unused *netdev,
 212               int __always_unused vf_id,
 213               struct ifla_vf_info __always_unused *ivi)
 214{
 215        return -EOPNOTSUPP;
 216}
 217
 218static inline int
 219ice_set_vf_trust(struct net_device __always_unused *netdev,
 220                 int __always_unused vf_id, bool __always_unused trusted)
 221{
 222        return -EOPNOTSUPP;
 223}
 224
 225static inline int
 226ice_set_vf_port_vlan(struct net_device __always_unused *netdev,
 227                     int __always_unused vf_id, u16 __always_unused vid,
 228                     u8 __always_unused qos, __be16 __always_unused v_proto)
 229{
 230        return -EOPNOTSUPP;
 231}
 232
 233static inline int
 234ice_set_vf_spoofchk(struct net_device __always_unused *netdev,
 235                    int __always_unused vf_id, bool __always_unused ena)
 236{
 237        return -EOPNOTSUPP;
 238}
 239
 240static inline int
 241ice_set_vf_link_state(struct net_device __always_unused *netdev,
 242                      int __always_unused vf_id, int __always_unused link_state)
 243{
 244        return -EOPNOTSUPP;
 245}
 246
 247static inline int
 248ice_calc_vf_reg_idx(struct ice_vf __always_unused *vf,
 249                    struct ice_q_vector __always_unused *q_vector)
 250{
 251        return 0;
 252}
 253
 254static inline int
 255ice_get_vf_stats(struct net_device __always_unused *netdev,
 256                 int __always_unused vf_id,
 257                 struct ifla_vf_stats __always_unused *vf_stats)
 258{
 259        return -EOPNOTSUPP;
 260}
 261
 262static inline bool ice_is_any_vf_in_promisc(struct ice_pf __always_unused *pf)
 263{
 264        return false;
 265}
 266#endif /* CONFIG_PCI_IOV */
 267#endif /* _ICE_VIRTCHNL_PF_H_ */
 268