xref: /openbmc/linux/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h (revision 023e41632e065d49bcbe31b3c4b336217f96a271)
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 
10 #define HCLGE_MBX_VF_MSG_DATA_NUM	16
11 
12 enum HCLGE_MBX_OPCODE {
13 	HCLGE_MBX_RESET = 0x01,		/* (VF -> PF) assert reset */
14 	HCLGE_MBX_ASSERTING_RESET,	/* (PF -> VF) PF is asserting reset*/
15 	HCLGE_MBX_SET_UNICAST,		/* (VF -> PF) set UC addr */
16 	HCLGE_MBX_SET_MULTICAST,	/* (VF -> PF) set MC addr */
17 	HCLGE_MBX_SET_VLAN,		/* (VF -> PF) set VLAN */
18 	HCLGE_MBX_MAP_RING_TO_VECTOR,	/* (VF -> PF) map ring-to-vector */
19 	HCLGE_MBX_UNMAP_RING_TO_VECTOR,	/* (VF -> PF) unamp ring-to-vector */
20 	HCLGE_MBX_SET_PROMISC_MODE,	/* (VF -> PF) set promiscuous mode */
21 	HCLGE_MBX_SET_MACVLAN,		/* (VF -> PF) set unicast filter */
22 	HCLGE_MBX_API_NEGOTIATE,	/* (VF -> PF) negotiate API version */
23 	HCLGE_MBX_GET_QINFO,		/* (VF -> PF) get queue config */
24 	HCLGE_MBX_GET_QDEPTH,		/* (VF -> PF) get queue depth */
25 	HCLGE_MBX_GET_TCINFO,		/* (VF -> PF) get TC config */
26 	HCLGE_MBX_GET_RETA,		/* (VF -> PF) get RETA */
27 	HCLGE_MBX_GET_RSS_KEY,		/* (VF -> PF) get RSS key */
28 	HCLGE_MBX_GET_MAC_ADDR,		/* (VF -> PF) get MAC addr */
29 	HCLGE_MBX_PF_VF_RESP,		/* (PF -> VF) generate respone to VF */
30 	HCLGE_MBX_GET_BDNUM,		/* (VF -> PF) get BD num */
31 	HCLGE_MBX_GET_BUFSIZE,		/* (VF -> PF) get buffer size */
32 	HCLGE_MBX_GET_STREAMID,		/* (VF -> PF) get stream id */
33 	HCLGE_MBX_SET_AESTART,		/* (VF -> PF) start ae */
34 	HCLGE_MBX_SET_TSOSTATS,		/* (VF -> PF) get tso stats */
35 	HCLGE_MBX_LINK_STAT_CHANGE,	/* (PF -> VF) link status has changed */
36 	HCLGE_MBX_GET_BASE_CONFIG,	/* (VF -> PF) get config */
37 	HCLGE_MBX_BIND_FUNC_QUEUE,	/* (VF -> PF) bind function and queue */
38 	HCLGE_MBX_GET_LINK_STATUS,	/* (VF -> PF) get link status */
39 	HCLGE_MBX_QUEUE_RESET,		/* (VF -> PF) reset queue */
40 	HCLGE_MBX_KEEP_ALIVE,		/* (VF -> PF) send keep alive cmd */
41 	HCLGE_MBX_SET_ALIVE,		/* (VF -> PF) set alive state */
42 	HCLGE_MBX_SET_MTU,		/* (VF -> PF) set mtu */
43 	HCLGE_MBX_GET_QID_IN_PF,	/* (VF -> PF) get queue id in pf */
44 	HCLGE_MBX_LINK_STAT_MODE,	/* (PF -> VF) link mode has changed */
45 	HCLGE_MBX_GET_LINK_MODE,	/* (VF -> PF) get the link mode of pf */
46 
47 	HCLGE_MBX_GET_VF_FLR_STATUS = 200, /* (M7 -> PF) get vf reset status */
48 };
49 
50 /* below are per-VF mac-vlan subcodes */
51 enum hclge_mbx_mac_vlan_subcode {
52 	HCLGE_MBX_MAC_VLAN_UC_MODIFY = 0,	/* modify UC mac addr */
53 	HCLGE_MBX_MAC_VLAN_UC_ADD,		/* add a new UC mac addr */
54 	HCLGE_MBX_MAC_VLAN_UC_REMOVE,		/* remove a new UC mac addr */
55 	HCLGE_MBX_MAC_VLAN_MC_MODIFY,		/* modify MC mac addr */
56 	HCLGE_MBX_MAC_VLAN_MC_ADD,		/* add new MC mac addr */
57 	HCLGE_MBX_MAC_VLAN_MC_REMOVE,		/* remove MC mac addr */
58 };
59 
60 /* below are per-VF vlan cfg subcodes */
61 enum hclge_mbx_vlan_cfg_subcode {
62 	HCLGE_MBX_VLAN_FILTER = 0,	/* set vlan filter */
63 	HCLGE_MBX_VLAN_TX_OFF_CFG,	/* set tx side vlan offload */
64 	HCLGE_MBX_VLAN_RX_OFF_CFG,	/* set rx side vlan offload */
65 };
66 
67 #define HCLGE_MBX_MAX_MSG_SIZE	16
68 #define HCLGE_MBX_MAX_RESP_DATA_SIZE	16
69 #define HCLGE_MBX_RING_MAP_BASIC_MSG_NUM	3
70 #define HCLGE_MBX_RING_NODE_VARIABLE_NUM	3
71 
72 struct hclgevf_mbx_resp_status {
73 	struct mutex mbx_mutex; /* protects against contending sync cmd resp */
74 	u32 origin_mbx_msg;
75 	bool received_resp;
76 	int resp_status;
77 	u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE];
78 };
79 
80 struct hclge_mbx_vf_to_pf_cmd {
81 	u8 rsv;
82 	u8 mbx_src_vfid; /* Auto filled by IMP */
83 	u8 rsv1[2];
84 	u8 msg_len;
85 	u8 rsv2[3];
86 	u8 msg[HCLGE_MBX_MAX_MSG_SIZE];
87 };
88 
89 struct hclge_mbx_pf_to_vf_cmd {
90 	u8 dest_vfid;
91 	u8 rsv[3];
92 	u8 msg_len;
93 	u8 rsv1[3];
94 	u16 msg[8];
95 };
96 
97 struct hclge_vf_rst_cmd {
98 	u8 dest_vfid;
99 	u8 vf_rst;
100 	u8 rsv[22];
101 };
102 
103 /* used by VF to store the received Async responses from PF */
104 struct hclgevf_mbx_arq_ring {
105 #define HCLGE_MBX_MAX_ARQ_MSG_SIZE	8
106 #define HCLGE_MBX_MAX_ARQ_MSG_NUM	1024
107 	struct hclgevf_dev *hdev;
108 	u32 head;
109 	u32 tail;
110 	u32 count;
111 	u16 msg_q[HCLGE_MBX_MAX_ARQ_MSG_NUM][HCLGE_MBX_MAX_ARQ_MSG_SIZE];
112 };
113 
114 #define hclge_mbx_ring_ptr_move_crq(crq) \
115 	(crq->next_to_use = (crq->next_to_use + 1) % crq->desc_num)
116 #define hclge_mbx_tail_ptr_move_arq(arq) \
117 	(arq.tail = (arq.tail + 1) % HCLGE_MBX_MAX_ARQ_MSG_SIZE)
118 #define hclge_mbx_head_ptr_move_arq(arq) \
119 		(arq.head = (arq.head + 1) % HCLGE_MBX_MAX_ARQ_MSG_SIZE)
120 #endif
121