1/* SPDX-License-Identifier: GPL-2.0+ */
2/* Copyright (c) 2016-2017 Hisilicon Limited. */
3
4#ifndef __HCLGE_MBX_H
5#define __HCLGE_MBX_H
6#include <linux/init.h>
7#include <linux/mutex.h>
8#include <linux/types.h>
9
10enum HCLGE_MBX_OPCODE {
11	HCLGE_MBX_RESET = 0x01,		/* (VF -> PF) assert reset */
12	HCLGE_MBX_ASSERTING_RESET,	/* (PF -> VF) PF is asserting reset*/
13	HCLGE_MBX_SET_UNICAST,		/* (VF -> PF) set UC addr */
14	HCLGE_MBX_SET_MULTICAST,	/* (VF -> PF) set MC addr */
15	HCLGE_MBX_SET_VLAN,		/* (VF -> PF) set VLAN */
16	HCLGE_MBX_MAP_RING_TO_VECTOR,	/* (VF -> PF) map ring-to-vector */
17	HCLGE_MBX_UNMAP_RING_TO_VECTOR,	/* (VF -> PF) unamp ring-to-vector */
18	HCLGE_MBX_SET_PROMISC_MODE,	/* (VF -> PF) set promiscuous mode */
19	HCLGE_MBX_SET_MACVLAN,		/* (VF -> PF) set unicast filter */
20	HCLGE_MBX_API_NEGOTIATE,	/* (VF -> PF) negotiate API version */
21	HCLGE_MBX_GET_QINFO,		/* (VF -> PF) get queue config */
22	HCLGE_MBX_GET_QDEPTH,		/* (VF -> PF) get queue depth */
23	HCLGE_MBX_GET_TCINFO,		/* (VF -> PF) get TC config */
24	HCLGE_MBX_GET_RETA,		/* (VF -> PF) get RETA */
25	HCLGE_MBX_GET_RSS_KEY,		/* (VF -> PF) get RSS key */
26	HCLGE_MBX_GET_MAC_ADDR,		/* (VF -> PF) get MAC addr */
27	HCLGE_MBX_PF_VF_RESP,		/* (PF -> VF) generate response to VF */
28	HCLGE_MBX_GET_BDNUM,		/* (VF -> PF) get BD num */
29	HCLGE_MBX_GET_BUFSIZE,		/* (VF -> PF) get buffer size */
30	HCLGE_MBX_GET_STREAMID,		/* (VF -> PF) get stream id */
31	HCLGE_MBX_SET_AESTART,		/* (VF -> PF) start ae */
32	HCLGE_MBX_SET_TSOSTATS,		/* (VF -> PF) get tso stats */
33	HCLGE_MBX_LINK_STAT_CHANGE,	/* (PF -> VF) link status has changed */
34	HCLGE_MBX_GET_BASE_CONFIG,	/* (VF -> PF) get config */
35	HCLGE_MBX_BIND_FUNC_QUEUE,	/* (VF -> PF) bind function and queue */
36	HCLGE_MBX_GET_LINK_STATUS,	/* (VF -> PF) get link status */
37	HCLGE_MBX_QUEUE_RESET,		/* (VF -> PF) reset queue */
38	HCLGE_MBX_KEEP_ALIVE,		/* (VF -> PF) send keep alive cmd */
39	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	HCLGE_MBX_LINK_STAT_MODE,	/* (PF -> VF) link mode has changed */
43	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/* below are per-VF mac-vlan subcodes */
56enum hclge_mbx_mac_vlan_subcode {
57	HCLGE_MBX_MAC_VLAN_UC_MODIFY = 0,	/* modify UC mac addr */
58	HCLGE_MBX_MAC_VLAN_UC_ADD,		/* add a new UC mac addr */
59	HCLGE_MBX_MAC_VLAN_UC_REMOVE,		/* remove a new UC mac addr */
60	HCLGE_MBX_MAC_VLAN_MC_MODIFY,		/* modify MC mac addr */
61	HCLGE_MBX_MAC_VLAN_MC_ADD,		/* add new MC mac addr */
62	HCLGE_MBX_MAC_VLAN_MC_REMOVE,		/* remove MC mac addr */
63};
64
65/* below are per-VF vlan cfg subcodes */
66enum hclge_mbx_vlan_cfg_subcode {
67	HCLGE_MBX_VLAN_FILTER = 0,	/* set vlan filter */
68	HCLGE_MBX_VLAN_TX_OFF_CFG,	/* set tx side vlan offload */
69	HCLGE_MBX_VLAN_RX_OFF_CFG,	/* set rx side vlan offload */
70	HCLGE_MBX_PORT_BASE_VLAN_CFG,	/* set port based vlan configuration */
71	HCLGE_MBX_GET_PORT_BASE_VLAN_STATE,	/* get port based vlan state */
72};
73
74enum hclge_mbx_tbl_cfg_subcode {
75	HCLGE_MBX_VPORT_LIST_CLEAR,
76};
77
78#define HCLGE_MBX_MAX_MSG_SIZE	14
79#define HCLGE_MBX_MAX_RESP_DATA_SIZE	8U
80#define HCLGE_MBX_MAX_RING_CHAIN_PARAM_NUM	4
81
82struct hclge_ring_chain_param {
83	u8 ring_type;
84	u8 tqp_index;
85	u8 int_gl_index;
86};
87
88struct hclgevf_mbx_resp_status {
89	struct mutex mbx_mutex; /* protects against contending sync cmd resp */
90	u32 origin_mbx_msg;
91	bool received_resp;
92	int resp_status;
93	u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE];
94};
95
96struct hclge_respond_to_vf_msg {
97	int status;
98	u8 data[HCLGE_MBX_MAX_RESP_DATA_SIZE];
99	u16 len;
100};
101
102struct hclge_vf_to_pf_msg {
103	u8 code;
104	union {
105		struct {
106			u8 subcode;
107			u8 data[HCLGE_MBX_MAX_MSG_SIZE];
108		};
109		struct {
110			u8 en_bc;
111			u8 en_uc;
112			u8 en_mc;
113		};
114		struct {
115			u8 vector_id;
116			u8 ring_num;
117			struct hclge_ring_chain_param
118				param[HCLGE_MBX_MAX_RING_CHAIN_PARAM_NUM];
119		};
120	};
121};
122
123struct hclge_pf_to_vf_msg {
124	u16 code;
125	u16 vf_mbx_msg_code;
126	u16 vf_mbx_msg_subcode;
127	u16 resp_status;
128	u8 resp_data[HCLGE_MBX_MAX_RESP_DATA_SIZE];
129};
130
131struct hclge_mbx_vf_to_pf_cmd {
132	u8 rsv;
133	u8 mbx_src_vfid; /* Auto filled by IMP */
134	u8 mbx_need_resp;
135	u8 rsv1[1];
136	u8 msg_len;
137	u8 rsv2;
138	u16 match_id;
139	struct hclge_vf_to_pf_msg msg;
140};
141
142#define HCLGE_MBX_NEED_RESP_B		0
143
144struct hclge_mbx_pf_to_vf_cmd {
145	u8 dest_vfid;
146	u8 rsv[3];
147	u8 msg_len;
148	u8 rsv1;
149	u16 match_id;
150	struct hclge_pf_to_vf_msg msg;
151};
152
153struct hclge_vf_rst_cmd {
154	u8 dest_vfid;
155	u8 vf_rst;
156	u8 rsv[22];
157};
158
159/* used by VF to store the received Async responses from PF */
160struct hclgevf_mbx_arq_ring {
161#define HCLGE_MBX_MAX_ARQ_MSG_SIZE	8
162#define HCLGE_MBX_MAX_ARQ_MSG_NUM	1024
163	struct hclgevf_dev *hdev;
164	u32 head;
165	u32 tail;
166	atomic_t count;
167	u16 msg_q[HCLGE_MBX_MAX_ARQ_MSG_NUM][HCLGE_MBX_MAX_ARQ_MSG_SIZE];
168};
169
170#define hclge_mbx_ring_ptr_move_crq(crq) \
171	(crq->next_to_use = (crq->next_to_use + 1) % crq->desc_num)
172#define hclge_mbx_tail_ptr_move_arq(arq) \
173		(arq.tail = (arq.tail + 1) % HCLGE_MBX_MAX_ARQ_MSG_NUM)
174#define hclge_mbx_head_ptr_move_arq(arq) \
175		(arq.head = (arq.head + 1) % HCLGE_MBX_MAX_ARQ_MSG_NUM)
176#endif
177