1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
#ifndef _IDPF_H_
#define _IDPF_H_
struct idpf_adapter;
struct idpf_vport;
struct idpf_vport_max_q;
struct idpf_q_vec_rsrc;
struct idpf_rss_data;
#include <net/pkt_sched.h>
#include <linux/aer.h>
#include <linux/etherdevice.h>
#include <linux/ioport.h>
#include <linux/pci.h>
#include <linux/bitfield.h>
#include <linux/sctp.h>
#include <linux/ethtool_netlink.h>
#include <net/gro.h>
#include <linux/net/intel/iidc_rdma.h>
#include <linux/net/intel/iidc_rdma_idpf.h>
#include <linux/net/intel/libie/controlq.h>
#include <linux/net/intel/virtchnl2.h>
#include "idpf_txrx.h"
#define GETMAXVAL(num_bits) GENMASK((num_bits) - 1, 0)
#define IDPF_NO_FREE_SLOT 0xffff
#define IDPF_NUM_FILTERS_PER_MSG 20
#define IDPF_NUM_DFLT_MBX_Q 2 /* includes both TX and RX */
#define IDPF_DFLT_MBX_Q_LEN 64
#define IDPF_MB_MAX_ERR 20
#define IDPF_NUM_CHUNKS_PER_MSG(struct_sz, chunk_sz) \
((LIBIE_CTLQ_MAX_BUF_LEN - (struct_sz)) / (chunk_sz))
#define IDPF_WAIT_FOR_MARKER_TIMEO 500
#define IDPF_MAX_WAIT 500
#define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
#define IDPF_DIM_PROFILE_SLOTS 5
#define IDPF_VIRTCHNL_VERSION_MAJOR VIRTCHNL2_VERSION_MAJOR_2
#define IDPF_VIRTCHNL_VERSION_MINOR VIRTCHNL2_VERSION_MINOR_0
struct idpf_mac_filter {
struct list_head list;
u8 macaddr[ETH_ALEN];
bool remove;
bool add;
};
enum idpf_state {
__IDPF_VER_CHECK,
__IDPF_GET_CAPS,
__IDPF_INIT_SW,
__IDPF_STATE_LAST,
};
enum idpf_flags {
IDPF_HR_FUNC_RESET,
IDPF_HR_DRV_LOAD,
IDPF_HR_RESET_IN_PROG,
IDPF_REMOVE_IN_PROG,
IDPF_MB_INTR_MODE,
IDPF_VC_CORE_INIT,
IDPF_FLAGS_NBITS,
};
enum idpf_cap_field {
IDPF_BASE_CAPS = -1,
IDPF_CSUM_CAPS = offsetof(struct virtchnl2_get_capabilities,
csum_caps),
IDPF_SEG_CAPS = offsetof(struct virtchnl2_get_capabilities,
seg_caps),
IDPF_RSS_CAPS = offsetof(struct virtchnl2_get_capabilities,
rss_caps),
IDPF_HSPLIT_CAPS = offsetof(struct virtchnl2_get_capabilities,
hsplit_caps),
IDPF_RSC_CAPS = offsetof(struct virtchnl2_get_capabilities,
rsc_caps),
IDPF_OTHER_CAPS = offsetof(struct virtchnl2_get_capabilities,
other_caps),
};
enum idpf_vport_state {
IDPF_VPORT_UP,
IDPF_VPORT_STATE_NBITS
};
struct idpf_netdev_priv {
struct idpf_adapter *adapter;
struct idpf_vport *vport;
u32 vport_id;
u32 link_speed_mbps;
u16 vport_idx;
u16 max_tx_hdr_size;
u16 tx_max_bufs;
DECLARE_BITMAP(state, IDPF_VPORT_STATE_NBITS);
struct rtnl_link_stats64 netstats;
spinlock_t stats_lock;
};
struct idpf_reset_reg {
void __iomem *rstat;
u32 rstat_m;
};
struct idpf_vport_max_q {
u16 max_rxq;
u16 max_txq;
u16 max_bufq;
u16 max_complq;
};
struct idpf_reg_ops {
void (*ctlq_reg_init)(struct libie_mmio_info *mmio,
struct libie_ctlq_create_info *cctlq_info);
int (*intr_reg_init)(struct idpf_vport *vport,
struct idpf_q_vec_rsrc *rsrc);
void (*mb_intr_reg_init)(struct idpf_adapter *adapter);
void (*reset_reg_init)(struct idpf_adapter *adapter);
void (*trigger_reset)(struct idpf_adapter *adapter,
enum idpf_flags trig_cause);
void (*ptp_reg_init)(const struct idpf_adapter *adapter);
};
#define IDPF_MMIO_REG_NUM_STATIC 2
#define IDPF_PF_MBX_REGION_SZ 4096
#define IDPF_PF_RSTAT_REGION_SZ 2048
#define IDPF_VF_MBX_REGION_SZ 10240
#define IDPF_VF_RSTAT_REGION_SZ 2048
struct idpf_dev_ops {
struct idpf_reg_ops reg_ops;
int (*idc_init)(struct idpf_adapter *adapter);
struct resource static_reg_info[IDPF_MMIO_REG_NUM_STATIC];
};
enum idpf_vport_reset_cause {
IDPF_SR_Q_CHANGE,
IDPF_SR_Q_DESC_CHANGE,
IDPF_SR_MTU_CHANGE,
IDPF_SR_RSC_CHANGE,
};
enum idpf_vport_flags {
IDPF_VPORT_DEL_QUEUES,
IDPF_VPORT_FLAGS_NBITS,
};
struct idpf_tstamp_stats {
struct u64_stats_sync stats_sync;
u64_stats_t packets;
u64_stats_t discarded;
u64_stats_t flushed;
};
struct idpf_port_stats {
struct u64_stats_sync stats_sync;
u64_stats_t rx_hw_csum_err;
u64_stats_t rx_hsplit;
u64_stats_t rx_hsplit_hbo;
u64_stats_t rx_bad_descs;
u64_stats_t tx_linearize;
u64_stats_t tx_busy;
u64_stats_t tx_drops;
u64_stats_t tx_dma_map_errs;
struct virtchnl2_vport_stats vport_stats;
};
struct idpf_fsteer_fltr {
struct list_head list;
struct ethtool_rx_flow_spec fs;
};
struct idpf_q_vec_rsrc {
struct device *dev;
struct idpf_q_vector *q_vectors;
u16 *q_vector_idxs;
u16 num_q_vectors;
u16 noirq_v_idx;
u32 noirq_dyn_ctl_ena;
void __iomem *noirq_dyn_ctl;
struct idpf_txq_group *txq_grps;
u32 txq_desc_count;
u32 complq_desc_count;
u32 txq_model;
u16 num_txq;
u16 num_complq;
u16 num_txq_grp;
u16 xdp_txq_offset;
u16 num_rxq_grp;
u32 rxq_model;
struct idpf_rxq_group *rxq_grps;
u16 num_rxq;
u16 num_bufq;
u32 rxq_desc_count;
u32 bufq_desc_count[IDPF_MAX_BUFQS_PER_RXQ_GRP];
u8 num_bufqs_per_qgrp;
bool base_rxd;
};
struct idpf_vport {
struct idpf_q_vec_rsrc dflt_qv_rsrc;
struct idpf_tx_queue **txqs;
u16 num_txq;
u16 num_xdp_txq;
bool xdpsq_share;
struct bpf_prog *xdp_prog;
struct iidc_rdma_vport_dev_info *vdev_info;
struct idpf_adapter *adapter;
struct net_device *netdev;
DECLARE_BITMAP(flags, IDPF_VPORT_FLAGS_NBITS);
u32 compln_clean_budget;
u32 vport_id;
u16 vport_type;
u16 idx;
u16 max_mtu;
u8 default_mac_addr[ETH_ALEN];
u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
u16 tx_itr_profile[IDPF_DIM_PROFILE_SLOTS];
struct idpf_port_stats port_stats;
bool default_vport;
bool crc_enable;
bool link_up;
struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps;
struct kernel_hwtstamp_config tstamp_config;
struct work_struct tstamp_task;
struct idpf_tstamp_stats tstamp_stats;
};
enum idpf_user_flags {
__IDPF_USER_FLAG_HSPLIT = 0U,
__IDPF_PROMISC_UC = 32,
__IDPF_PROMISC_MC,
__IDPF_USER_FLAGS_NBITS,
};
struct idpf_rss_data {
u16 rss_key_size;
u8 *rss_key;
u16 rss_lut_size;
u32 *rss_lut;
};
struct idpf_q_coalesce {
u32 tx_intr_mode;
u32 rx_intr_mode;
u32 tx_coalesce_usecs;
u32 rx_coalesce_usecs;
};
struct idpf_vport_user_config_data {
struct idpf_rss_data rss_data;
struct idpf_q_coalesce *q_coalesce;
u16 num_req_tx_qs;
u16 num_req_rx_qs;
u32 num_req_txq_desc;
u32 num_req_rxq_desc;
struct bpf_prog *xdp_prog;
DECLARE_BITMAP(user_flags, __IDPF_USER_FLAGS_NBITS);
struct list_head mac_filter_list;
u32 num_fsteer_fltrs;
struct list_head flow_steer_list;
};
enum idpf_vport_config_flags {
IDPF_VPORT_REG_NETDEV,
IDPF_VPORT_UP_REQUESTED,
IDPF_VPORT_CONFIG_FLAGS_NBITS,
};
struct idpf_avail_queue_info {
u16 avail_rxq;
u16 avail_txq;
u16 avail_bufq;
u16 avail_complq;
};
struct idpf_vector_info {
u16 num_req_vecs;
u16 num_curr_vecs;
u16 index;
bool default_vport;
};
struct idpf_vector_lifo {
u16 top;
u16 base;
u16 size;
u16 *vec_idx;
};
struct idpf_queue_id_reg_chunk {
u64 qtail_reg_start;
u32 qtail_reg_spacing;
u32 type;
u32 start_queue_id;
u32 num_queues;
};
struct idpf_queue_id_reg_info {
u16 num_chunks;
struct idpf_queue_id_reg_chunk *queue_chunks;
};
struct idpf_vport_config {
struct idpf_vport_user_config_data user_config;
struct idpf_vport_max_q max_q;
struct idpf_queue_id_reg_info qid_reg_info;
spinlock_t mac_filter_list_lock;
spinlock_t flow_steer_list_lock;
DECLARE_BITMAP(flags, IDPF_VPORT_CONFIG_FLAGS_NBITS);
};
struct idpf_edt_caps_ilog2 {
u32 time_horizon_ns;
u8 tstamp_granularity_pow2;
};
#define idpf_for_each_vport(adapter, iter) \
for (struct idpf_vport **__##iter = &(adapter)->vports[0], \
*iter = (adapter)->max_vports ? *__##iter : NULL; \
iter; \
iter = (++__##iter) < &(adapter)->vports[(adapter)->max_vports] ? \
*__##iter : NULL)
struct idpf_adapter {
struct pci_dev *pdev;
u32 virt_ver_maj;
u32 virt_ver_min;
u32 msg_enable;
u32 mb_wait_count;
enum idpf_state state;
DECLARE_BITMAP(flags, IDPF_FLAGS_NBITS);
struct idpf_reset_reg reset_reg;
struct libie_ctlq_ctx ctlq_ctx;
struct libie_ctlq_info *asq;
struct libie_ctlq_info *arq;
struct libie_ctlq_xn_manager *xnm;
u16 num_avail_msix;
u16 num_msix_entries;
struct msix_entry *msix_entries;
u16 num_rdma_msix_entries;
struct msix_entry *rdma_msix_entries;
struct virtchnl2_alloc_vectors *req_vec_chunks;
struct idpf_q_vector mb_vector;
struct idpf_vector_lifo vector_stack;
irqreturn_t (*irq_mb_handler)(int irq, void *data);
u32 tx_timeout_count;
struct idpf_avail_queue_info avail_queues;
struct idpf_vport **vports;
struct net_device **netdevs;
struct virtchnl2_create_vport **vport_params_recvd;
u32 *vport_ids;
struct libeth_rx_pt *singleq_pt_lkup;
struct libeth_rx_pt *splitq_pt_lkup;
struct idpf_vport_config **vport_config;
u16 max_vports;
u16 num_alloc_vports;
u16 next_vport;
struct delayed_work init_task;
struct workqueue_struct *init_wq;
struct delayed_work serv_task;
struct workqueue_struct *serv_wq;
struct delayed_work mbx_task;
struct workqueue_struct *mbx_wq;
struct delayed_work vc_event_task;
struct workqueue_struct *vc_event_wq;
struct delayed_work stats_task;
struct workqueue_struct *stats_wq;
struct virtchnl2_get_capabilities caps;
struct idpf_edt_caps_ilog2 edt_caps;
struct idpf_dev_ops dev_ops;
struct iidc_rdma_core_dev_info *cdev_info;
int num_vfs;
bool crc_enable;
bool req_tx_splitq;
bool req_rx_splitq;
struct mutex vport_ctrl_lock;
struct mutex vector_lock;
struct mutex queue_lock;
struct mutex vc_buf_lock;
struct idpf_ptp *ptp;
};
static inline int idpf_is_queue_model_split(u16 q_model)
{
return !IS_ENABLED(CONFIG_IDPF_SINGLEQ) ||
q_model == VIRTCHNL2_QUEUE_MODEL_SPLIT;
}
static inline bool idpf_xdp_enabled(const struct idpf_vport *vport)
{
return vport->adapter && vport->xdp_prog;
}
#define idpf_is_cap_ena(adapter, field, flag) \
idpf_is_capability_ena(adapter, false, field, flag)
#define idpf_is_cap_ena_all(adapter, field, flag) \
idpf_is_capability_ena(adapter, true, field, flag)
bool idpf_is_capability_ena(struct idpf_adapter *adapter, bool all,
enum idpf_cap_field field, u64 flag);
static inline bool idpf_is_rdma_cap_ena(struct idpf_adapter *adapter)
{
return idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, VIRTCHNL2_CAP_RDMA);
}
#define IDPF_CAP_RSS (\
VIRTCHNL2_FLOW_IPV4_TCP |\
VIRTCHNL2_FLOW_IPV4_UDP |\
VIRTCHNL2_FLOW_IPV4_SCTP |\
VIRTCHNL2_FLOW_IPV4_OTHER |\
VIRTCHNL2_FLOW_IPV6_TCP |\
VIRTCHNL2_FLOW_IPV6_UDP |\
VIRTCHNL2_FLOW_IPV6_SCTP |\
VIRTCHNL2_FLOW_IPV6_OTHER)
#define IDPF_CAP_RSC (\
VIRTCHNL2_CAP_RSC_IPV4_TCP |\
VIRTCHNL2_CAP_RSC_IPV6_TCP)
#define IDPF_CAP_HSPLIT (\
VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\
VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6)
#define IDPF_CAP_TX_CSUM_L4V4 (\
VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP |\
VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP)
#define IDPF_CAP_TX_CSUM_L4V6 (\
VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP |\
VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP)
#define IDPF_CAP_RX_CSUM (\
VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 |\
VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP |\
VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP |\
VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP |\
VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP)
#define IDPF_CAP_TX_SCTP_CSUM (\
VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP |\
VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP)
#define IDPF_CAP_TUNNEL_TX_CSUM (\
VIRTCHNL2_CAP_TX_CSUM_L3_SINGLE_TUNNEL |\
VIRTCHNL2_CAP_TX_CSUM_L4_SINGLE_TUNNEL)
static inline u16 idpf_get_reserved_vecs(struct idpf_adapter *adapter)
{
return le16_to_cpu(adapter->caps.num_allocated_vectors);
}
static inline u16 idpf_get_reserved_rdma_vecs(struct idpf_adapter *adapter)
{
return le16_to_cpu(adapter->caps.num_rdma_allocated_vectors);
}
static inline u16 idpf_get_default_vports(struct idpf_adapter *adapter)
{
return le16_to_cpu(adapter->caps.default_num_vports);
}
static inline u16 idpf_get_max_vports(struct idpf_adapter *adapter)
{
return le16_to_cpu(adapter->caps.max_vports);
}
static inline unsigned int idpf_get_max_tx_bufs(struct idpf_adapter *adapter)
{
return adapter->caps.max_sg_bufs_per_tx_pkt;
}
static inline u8 idpf_get_min_tx_pkt_len(struct idpf_adapter *adapter)
{
u8 pkt_len = adapter->caps.min_sso_packet_len;
return pkt_len ? pkt_len : IDPF_TX_MIN_PKT_LEN;
}
static inline bool idpf_is_reset_detected(struct idpf_adapter *adapter)
{
struct libie_ctlq_info *arq = adapter->arq;
if (!arq)
return true;
return !(readl(arq->reg.len) & arq->reg.len_mask);
}
static inline bool idpf_is_reset_in_prog(struct idpf_adapter *adapter)
{
return (test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags) ||
test_bit(IDPF_HR_FUNC_RESET, adapter->flags) ||
test_bit(IDPF_HR_DRV_LOAD, adapter->flags));
}
static inline struct idpf_vport *idpf_netdev_to_vport(struct net_device *netdev)
{
struct idpf_netdev_priv *np = netdev_priv(netdev);
return np->vport;
}
static inline struct idpf_adapter *idpf_netdev_to_adapter(struct net_device *netdev)
{
struct idpf_netdev_priv *np = netdev_priv(netdev);
return np->adapter;
}
static inline bool idpf_is_feature_ena(const struct idpf_vport *vport,
netdev_features_t feature)
{
return vport->netdev->features & feature;
}
static inline u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter)
{
return le16_to_cpu(adapter->caps.max_tx_hdr_size);
}
static inline void idpf_vport_ctrl_lock(struct net_device *netdev)
{
struct idpf_netdev_priv *np = netdev_priv(netdev);
mutex_lock(&np->adapter->vport_ctrl_lock);
}
static inline void idpf_vport_ctrl_unlock(struct net_device *netdev)
{
struct idpf_netdev_priv *np = netdev_priv(netdev);
mutex_unlock(&np->adapter->vport_ctrl_lock);
}
static inline bool idpf_vport_ctrl_is_locked(struct net_device *netdev)
{
struct idpf_netdev_priv *np = netdev_priv(netdev);
return mutex_is_locked(&np->adapter->vport_ctrl_lock);
}
void idpf_statistics_task(struct work_struct *work);
void idpf_init_task(struct work_struct *work);
void idpf_service_task(struct work_struct *work);
void idpf_mbx_task(struct work_struct *work);
void idpf_vc_event_task(struct work_struct *work);
void idpf_dev_ops_init(struct idpf_adapter *adapter);
void idpf_vf_dev_ops_init(struct idpf_adapter *adapter);
int idpf_intr_req(struct idpf_adapter *adapter);
void idpf_mb_intr_rel_irq(struct idpf_adapter *adapter);
void idpf_intr_rel(struct idpf_adapter *adapter);
u16 idpf_get_max_tx_hdr_size(struct idpf_adapter *adapter);
int idpf_initiate_soft_reset(struct idpf_vport *vport,
enum idpf_vport_reset_cause reset_cause);
void idpf_deinit_task(struct idpf_adapter *adapter);
int idpf_req_rel_vector_indexes(struct idpf_adapter *adapter,
u16 *q_vector_idxs,
struct idpf_vector_info *vec_info);
void idpf_set_ethtool_ops(struct net_device *netdev);
void idpf_vport_intr_write_itr(struct idpf_q_vector *q_vector,
u16 itr, bool tx);
int idpf_sriov_configure(struct pci_dev *pdev, int num_vfs);
u8 idpf_vport_get_hsplit(const struct idpf_vport *vport);
bool idpf_vport_set_hsplit(const struct idpf_vport *vport, u8 val);
int idpf_idc_init(struct idpf_adapter *adapter);
int idpf_idc_init_aux_core_dev(struct idpf_adapter *adapter,
enum iidc_function_type ftype);
void idpf_idc_deinit_core_aux_device(struct idpf_adapter *adapter);
void idpf_idc_deinit_vport_aux_device(struct iidc_rdma_vport_dev_info *vdev_info);
void idpf_idc_issue_reset_event(struct iidc_rdma_core_dev_info *cdev_info);
void idpf_idc_vdev_mtu_event(struct iidc_rdma_vport_dev_info *vdev_info,
enum iidc_rdma_event_type event_type);
int idpf_add_del_fsteer_filters(struct idpf_adapter *adapter,
struct virtchnl2_flow_rule_add_del *rule,
enum virtchnl2_op opcode);
#endif /* !_IDPF_H_ */