linux/drivers/net/ethernet/qlogic/qed/qed_sriov.h

/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
/* QLogic qed NIC Driver
 * Copyright (c) 2015-2017  QLogic Corporation
 * Copyright (c) 2019-2020 Marvell International Ltd.
 */

#ifndef _QED_SRIOV_H
#define _QED_SRIOV_H
#include <linux/types.h>
#include "qed_vf.h"

#define QED_ETH_VF_NUM_MAC_FILTERS
#define QED_ETH_VF_NUM_VLAN_FILTERS
#define QED_VF_ARRAY_LENGTH

#ifdef CONFIG_QED_SRIOV
#define IS_VF(cdev)
#define IS_PF(cdev)
#define IS_PF_SRIOV(p_hwfn)
#else
#define IS_VF
#define IS_PF
#define IS_PF_SRIOV
#endif
#define IS_PF_SRIOV_ALLOC(p_hwfn)

#define QED_MAX_VF_CHAINS_PER_PF

#define QED_ETH_MAX_VF_NUM_VLAN_FILTERS

enum qed_iov_vport_update_flag {};

struct qed_public_vf_info {};

struct qed_iov_vf_init_params {};

/* This struct is part of qed_dev and contains data relevant to all hwfns;
 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
 */
struct qed_hw_sriov_info {};

/* This mailbox is maintained per VF in its PF contains all information
 * required for sending / receiving a message.
 */
struct qed_iov_vf_mbx {};

#define QED_IOV_LEGACY_QID_RX
#define QED_IOV_LEGACY_QID_TX
#define QED_IOV_QID_INVALID

struct qed_vf_queue_cid {};

/* Describes a qzone associated with the VF */
struct qed_vf_queue {};

enum vf_state {};

struct qed_vf_vlan_shadow {};

struct qed_vf_shadow_config {};

/* PFs maintain an array of this structure, per VF */
struct qed_vf_info {};

/* This structure is part of qed_hwfn and used only for PFs that have sriov
 * capability enabled.
 */
struct qed_pf_iov {};

enum qed_iov_wq_flag {};

extern const struct qed_iov_hv_ops qed_iov_ops_pass;

#ifdef CONFIG_QED_SRIOV
/**
 * qed_iov_is_valid_vfid(): Check if given VF ID @vfid is valid
 *                          w.r.t. @b_enabled_only value
 *                          if b_enabled_only = true - only enabled
 *                          VF id is valid.
 *                          else any VF id less than max_vfs is valid.
 *
 * @p_hwfn: HW device data.
 * @rel_vf_id: Relative VF ID.
 * @b_enabled_only: consider only enabled VF.
 * @b_non_malicious: true iff we want to validate vf isn't malicious.
 *
 * Return: bool - true for valid VF ID
 */
bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
			   int rel_vf_id,
			   bool b_enabled_only, bool b_non_malicious);

/**
 * qed_iov_get_next_active_vf(): Given a VF index, return index of
 *                               next [including that] active VF.
 *
 * @p_hwfn: HW device data.
 * @rel_vf_id: VF ID.
 *
 * Return: MAX_NUM_VFS in case no further active VFs, otherwise index.
 */
u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);

void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
				    int vfid, u16 vxlan_port, u16 geneve_port);

/**
 * qed_iov_hw_info(): Read sriov related information and allocated resources
 *                    reads from configuration space, shmem, etc.
 *
 * @p_hwfn: HW device data.
 *
 * Return: Int.
 */
int qed_iov_hw_info(struct qed_hwfn *p_hwfn);

/**
 * qed_add_tlv(): place a given tlv on the tlv buffer at next offset
 *
 * @p_hwfn: HW device data.
 * @offset: offset.
 * @type: Type
 * @length: Length.
 *
 * Return: pointer to the newly placed tlv
 */
void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);

/**
 * qed_dp_tlv_list(): list the types and lengths of the tlvs on the buffer
 *
 * @p_hwfn: HW device data.
 * @tlvs_list: Tlvs_list.
 *
 * Return: Void.
 */
void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);

/**
 * qed_sriov_vfpf_malicious(): Handle malicious VF/PF.
 *
 * @p_hwfn: HW device data.
 * @p_data: Pointer to data.
 *
 * Return: Void.
 */
void qed_sriov_vfpf_malicious(struct qed_hwfn *p_hwfn,
			      struct fw_err_data *p_data);

/**
 * qed_sriov_eqe_event(): Callback for SRIOV events.
 *
 * @p_hwfn: HW device data.
 * @opcode: Opcode.
 * @echo: Echo.
 * @data: data
 * @fw_return_code: FW return code.
 *
 * Return: Int.
 */
int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn, u8 opcode, __le16 echo,
			union event_ring_data *data, u8  fw_return_code);

/**
 * qed_iov_alloc(): allocate sriov related resources
 *
 * @p_hwfn: HW device data.
 *
 * Return: Int.
 */
int qed_iov_alloc(struct qed_hwfn *p_hwfn);

/**
 * qed_iov_setup(): setup sriov related resources
 *
 * @p_hwfn: HW device data.
 *
 * Return: Void.
 */
void qed_iov_setup(struct qed_hwfn *p_hwfn);

/**
 * qed_iov_free(): free sriov related resources
 *
 * @p_hwfn: HW device data.
 *
 * Return: Void.
 */
void qed_iov_free(struct qed_hwfn *p_hwfn);

/**
 * qed_iov_free_hw_info(): free sriov related memory that was
 *                          allocated during hw_prepare
 *
 * @cdev: Qed dev pointer.
 *
 * Return: Void.
 */
void qed_iov_free_hw_info(struct qed_dev *cdev);

/**
 * qed_iov_mark_vf_flr(): Mark structs of vfs that have been FLR-ed.
 *
 * @p_hwfn: HW device data.
 * @disabled_vfs: bitmask of all VFs on path that were FLRed
 *
 * Return: true iff one of the PF's vfs got FLRed. false otherwise.
 */
bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);

/**
 * qed_iov_search_list_tlvs(): Search extended TLVs in request/reply buffer.
 *
 * @p_hwfn: HW device data.
 * @p_tlvs_list: Pointer to tlvs list
 * @req_type: Type of TLV
 *
 * Return: pointer to tlv type if found, otherwise returns NULL.
 */
void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
			       void *p_tlvs_list, u16 req_type);

void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
int qed_iov_wq_start(struct qed_dev *cdev);

void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
void qed_vf_start_iov_wq(struct qed_dev *cdev);
int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
#else
static inline bool
qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
		      int rel_vf_id, bool b_enabled_only, bool b_non_malicious)
{
	return false;
}

static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
					     u16 rel_vf_id)
{
	return MAX_NUM_VFS;
}

static inline void
qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, int vfid,
			       u16 vxlan_port, u16 geneve_port)
{
}

static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
{
	return 0;
}

static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
{
	return 0;
}

static inline void qed_iov_setup(struct qed_hwfn *p_hwfn)
{
}

static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
{
}

static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
{
}

static inline bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
				       u32 *disabled_vfs)
{
	return false;
}

static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
{
}

static inline int qed_iov_wq_start(struct qed_dev *cdev)
{
	return 0;
}

static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
				    enum qed_iov_wq_flag flag)
{
}

static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
{
}

static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
{
	return 0;
}

static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
{
}

static inline void qed_sriov_vfpf_malicious(struct qed_hwfn *p_hwfn,
					    struct fw_err_data *p_data)
{
}

static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn, u8 opcode,
				      __le16 echo, union event_ring_data *data,
				      u8  fw_return_code)
{
	return 0;
}
#endif

#define qed_for_each_vf(_p_hwfn, _i)

#endif