hclge_mbx.h 6.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2017 Hisilicon Limited. */

#ifndef __HCLGE_MBX_H
#define __HCLGE_MBX_H
#include <linux/init.h>
#include <linux/mutex.h>
#include <linux/types.h>

enum HCLGE_MBX_OPCODE {
	HCLGE_MBX_RESET = 0x01,		/* (VF -> PF) assert reset */
12
	HCLGE_MBX_ASSERTING_RESET,	/* (PF -> VF) PF is asserting reset */
13 14 15 16 17 18 19 20 21
	HCLGE_MBX_SET_UNICAST,		/* (VF -> PF) set UC addr */
	HCLGE_MBX_SET_MULTICAST,	/* (VF -> PF) set MC addr */
	HCLGE_MBX_SET_VLAN,		/* (VF -> PF) set VLAN */
	HCLGE_MBX_MAP_RING_TO_VECTOR,	/* (VF -> PF) map ring-to-vector */
	HCLGE_MBX_UNMAP_RING_TO_VECTOR,	/* (VF -> PF) unamp ring-to-vector */
	HCLGE_MBX_SET_PROMISC_MODE,	/* (VF -> PF) set promiscuous mode */
	HCLGE_MBX_SET_MACVLAN,		/* (VF -> PF) set unicast filter */
	HCLGE_MBX_API_NEGOTIATE,	/* (VF -> PF) negotiate API version */
	HCLGE_MBX_GET_QINFO,		/* (VF -> PF) get queue config */
22
	HCLGE_MBX_GET_QDEPTH,		/* (VF -> PF) get queue depth */
23
	HCLGE_MBX_GET_BASIC_INFO,	/* (VF -> PF) get basic info */
24 25 26
	HCLGE_MBX_GET_RETA,		/* (VF -> PF) get RETA */
	HCLGE_MBX_GET_RSS_KEY,		/* (VF -> PF) get RSS key */
	HCLGE_MBX_GET_MAC_ADDR,		/* (VF -> PF) get MAC addr */
27
	HCLGE_MBX_PF_VF_RESP,		/* (PF -> VF) generate response to VF */
28 29 30 31 32 33 34 35 36 37
	HCLGE_MBX_GET_BDNUM,		/* (VF -> PF) get BD num */
	HCLGE_MBX_GET_BUFSIZE,		/* (VF -> PF) get buffer size */
	HCLGE_MBX_GET_STREAMID,		/* (VF -> PF) get stream id */
	HCLGE_MBX_SET_AESTART,		/* (VF -> PF) start ae */
	HCLGE_MBX_SET_TSOSTATS,		/* (VF -> PF) get tso stats */
	HCLGE_MBX_LINK_STAT_CHANGE,	/* (PF -> VF) link status has changed */
	HCLGE_MBX_GET_BASE_CONFIG,	/* (VF -> PF) get config */
	HCLGE_MBX_BIND_FUNC_QUEUE,	/* (VF -> PF) bind function and queue */
	HCLGE_MBX_GET_LINK_STATUS,	/* (VF -> PF) get link status */
	HCLGE_MBX_QUEUE_RESET,		/* (VF -> PF) reset queue */
38 39
	HCLGE_MBX_KEEP_ALIVE,		/* (VF -> PF) send keep alive cmd */
	HCLGE_MBX_SET_ALIVE,		/* (VF -> PF) set alive state */
40
	HCLGE_MBX_SET_MTU,		/* (VF -> PF) set mtu */
41
	HCLGE_MBX_GET_QID_IN_PF,	/* (VF -> PF) get queue id in pf */
42 43
	HCLGE_MBX_LINK_STAT_MODE,	/* (PF -> VF) link mode has changed */
	HCLGE_MBX_GET_LINK_MODE,	/* (VF -> PF) get the link mode of pf */
44
	HCLGE_MBX_PUSH_VLAN_INFO,	/* (PF -> VF) push port base vlan */
45
	HCLGE_MBX_GET_MEDIA_TYPE,       /* (VF -> PF) get media type */
46
	HCLGE_MBX_PUSH_PROMISC_INFO,	/* (PF -> VF) push vf promisc info */
47
	HCLGE_MBX_VF_UNINIT,            /* (VF -> PF) vf is unintializing */
48
	HCLGE_MBX_HANDLE_VF_TBL,	/* (VF -> PF) store/clear hw table */
49

50
	HCLGE_MBX_GET_VF_FLR_STATUS = 200, /* (M7 -> PF) get vf flr status */
51
	HCLGE_MBX_PUSH_LINK_STATUS,	/* (M7 -> PF) get port link status */
52
	HCLGE_MBX_NCSI_ERROR,		/* (M7 -> PF) receive a NCSI error */
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
};

/* below are per-VF mac-vlan subcodes */
enum hclge_mbx_mac_vlan_subcode {
	HCLGE_MBX_MAC_VLAN_UC_MODIFY = 0,	/* modify UC mac addr */
	HCLGE_MBX_MAC_VLAN_UC_ADD,		/* add a new UC mac addr */
	HCLGE_MBX_MAC_VLAN_UC_REMOVE,		/* remove a new UC mac addr */
	HCLGE_MBX_MAC_VLAN_MC_MODIFY,		/* modify MC mac addr */
	HCLGE_MBX_MAC_VLAN_MC_ADD,		/* add new MC mac addr */
	HCLGE_MBX_MAC_VLAN_MC_REMOVE,		/* remove MC mac addr */
};

/* below are per-VF vlan cfg subcodes */
enum hclge_mbx_vlan_cfg_subcode {
	HCLGE_MBX_VLAN_FILTER = 0,	/* set vlan filter */
	HCLGE_MBX_VLAN_TX_OFF_CFG,	/* set tx side vlan offload */
	HCLGE_MBX_VLAN_RX_OFF_CFG,	/* set rx side vlan offload */
70 71
	HCLGE_MBX_PORT_BASE_VLAN_CFG,	/* set port based vlan configuration */
	HCLGE_MBX_GET_PORT_BASE_VLAN_STATE,	/* get port based vlan state */
72
	HCLGE_MBX_ENABLE_VLAN_FILTER,
73 74
};

75 76 77 78
enum hclge_mbx_tbl_cfg_subcode {
	HCLGE_MBX_VPORT_LIST_CLEAR,
};

79
#define HCLGE_MBX_MAX_MSG_SIZE	14
80
#define HCLGE_MBX_MAX_RESP_DATA_SIZE	8U
81 82
#define HCLGE_MBX_MAX_RING_CHAIN_PARAM_NUM	4

83 84 85
#define HCLGE_RESET_SCHED_TIMEOUT	(3 * HZ)
#define HCLGE_MBX_SCHED_TIMEOUT	(HZ / 2)

86 87 88 89 90
struct hclge_ring_chain_param {
	u8 ring_type;
	u8 tqp_index;
	u8 int_gl_index;
};
91

92 93 94 95 96 97 98
struct hclge_basic_info {
	u8 hw_tc_map;
	u8 rsv;
	u16 mbx_api_version;
	u32 pf_caps;
};

99 100 101 102 103
struct hclgevf_mbx_resp_status {
	struct mutex mbx_mutex; /* protects against contending sync cmd resp */
	u32 origin_mbx_msg;
	bool received_resp;
	int resp_status;
104
	u16 match_id;
105 106 107
	u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE];
};

108 109 110 111 112 113
struct hclge_respond_to_vf_msg {
	int status;
	u8 data[HCLGE_MBX_MAX_RESP_DATA_SIZE];
	u16 len;
};

114 115 116 117 118 119 120 121 122 123 124
struct hclge_vf_to_pf_msg {
	u8 code;
	union {
		struct {
			u8 subcode;
			u8 data[HCLGE_MBX_MAX_MSG_SIZE];
		};
		struct {
			u8 en_bc;
			u8 en_uc;
			u8 en_mc;
125
			u8 en_limit_promisc;
126 127 128 129 130 131 132 133 134 135 136 137
		};
		struct {
			u8 vector_id;
			u8 ring_num;
			struct hclge_ring_chain_param
				param[HCLGE_MBX_MAX_RING_CHAIN_PARAM_NUM];
		};
	};
};

struct hclge_pf_to_vf_msg {
	u16 code;
138 139 140 141 142 143 144 145 146 147 148 149 150
	union {
		/* used for mbx response */
		struct {
			u16 vf_mbx_msg_code;
			u16 vf_mbx_msg_subcode;
			u16 resp_status;
			u8 resp_data[HCLGE_MBX_MAX_RESP_DATA_SIZE];
		};
		/* used for general mbx */
		struct {
			u8 msg_data[HCLGE_MBX_MAX_MSG_SIZE];
		};
	};
151 152
};

153 154 155
struct hclge_mbx_vf_to_pf_cmd {
	u8 rsv;
	u8 mbx_src_vfid; /* Auto filled by IMP */
156 157
	u8 mbx_need_resp;
	u8 rsv1[1];
158
	u8 msg_len;
159 160
	u8 rsv2;
	u16 match_id;
161
	struct hclge_vf_to_pf_msg msg;
162 163
};

164
#define HCLGE_MBX_NEED_RESP_B		0
165

166 167 168 169
struct hclge_mbx_pf_to_vf_cmd {
	u8 dest_vfid;
	u8 rsv[3];
	u8 msg_len;
170 171
	u8 rsv1;
	u16 match_id;
172
	struct hclge_pf_to_vf_msg msg;
173 174
};

175 176 177 178 179 180
struct hclge_vf_rst_cmd {
	u8 dest_vfid;
	u8 vf_rst;
	u8 rsv[22];
};

181 182 183 184 185 186 187
/* used by VF to store the received Async responses from PF */
struct hclgevf_mbx_arq_ring {
#define HCLGE_MBX_MAX_ARQ_MSG_SIZE	8
#define HCLGE_MBX_MAX_ARQ_MSG_NUM	1024
	struct hclgevf_dev *hdev;
	u32 head;
	u32 tail;
188
	atomic_t count;
189 190 191
	u16 msg_q[HCLGE_MBX_MAX_ARQ_MSG_NUM][HCLGE_MBX_MAX_ARQ_MSG_SIZE];
};

192 193
#define hclge_mbx_ring_ptr_move_crq(crq) \
	(crq->next_to_use = (crq->next_to_use + 1) % crq->desc_num)
194
#define hclge_mbx_tail_ptr_move_arq(arq) \
195
		(arq.tail = (arq.tail + 1) % HCLGE_MBX_MAX_ARQ_MSG_NUM)
196
#define hclge_mbx_head_ptr_move_arq(arq) \
197
		(arq.head = (arq.head + 1) % HCLGE_MBX_MAX_ARQ_MSG_NUM)
198 199 200

/* PF immediately push link status to VFs when link status changed */
#define HCLGE_MBX_PUSH_LINK_STATUS_EN			BIT(0)
201
#endif