xref: /dpdk/drivers/common/idpf/base/idpf_controlq.h (revision 9510c5f874f652fcaa3cc6e6d9bce2c0f834a1d2)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2024 Intel Corporation
3  */
4 
5 #ifndef _IDPF_CONTROLQ_H_
6 #define _IDPF_CONTROLQ_H_
7 
8 #include "idpf_osdep.h"
9 #include "idpf_alloc.h"
10 #include "idpf_controlq_api.h"
11 
12 /* Maximum buffer lengths for all control queue types */
13 #define IDPF_CTLQ_MAX_RING_SIZE 1024
14 #define IDPF_CTLQ_MAX_BUF_LEN	4096
15 
16 #define IDPF_CTLQ_DESC(R, i) \
17 	(&(((struct idpf_ctlq_desc *)((R)->desc_ring.va))[i]))
18 
19 #define IDPF_CTLQ_DESC_UNUSED(R)					\
20 	((u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->ring_size) + \
21 	       (R)->next_to_clean - (R)->next_to_use - 1))
22 
23 /* Data type manipulation macros. */
24 #define IDPF_HI_DWORD(x)	((u32)((((x) >> 16) >> 16) & 0xFFFFFFFF))
25 #define IDPF_LO_DWORD(x)	((u32)((x) & 0xFFFFFFFF))
26 #define IDPF_HI_WORD(x)		((u16)(((x) >> 16) & 0xFFFF))
27 #define IDPF_LO_WORD(x)		((u16)((x) & 0xFFFF))
28 
29 /* Control Queue default settings */
30 #define IDPF_CTRL_SQ_CMD_TIMEOUT	250  /* msecs */
31 
32 struct idpf_ctlq_desc {
33 	__le16	flags;
34 	__le16	opcode;
35 	__le16	datalen;	/* 0 for direct commands */
36 	union {
37 		__le16 ret_val;
38 		__le16 pfid_vfid;
39 #define IDPF_CTLQ_DESC_VF_ID_S	0
40 #ifdef SIMICS_BUILD
41 #define IDPF_CTLQ_DESC_VF_ID_M	(0x3FF << IDPF_CTLQ_DESC_VF_ID_S)
42 #define IDPF_CTLQ_DESC_PF_ID_S	10
43 #define IDPF_CTLQ_DESC_PF_ID_M	(0x3F << IDPF_CTLQ_DESC_PF_ID_S)
44 #else
45 #define IDPF_CTLQ_DESC_VF_ID_M	(0x7FF << IDPF_CTLQ_DESC_VF_ID_S)
46 #define IDPF_CTLQ_DESC_PF_ID_S	11
47 #define IDPF_CTLQ_DESC_PF_ID_M	(0x1F << IDPF_CTLQ_DESC_PF_ID_S)
48 #endif
49 	};
50 	__le32 cookie_high;
51 	__le32 cookie_low;
52 	union {
53 		struct {
54 			__le32 param0;
55 			__le32 param1;
56 			__le32 param2;
57 			__le32 param3;
58 		} direct;
59 		struct {
60 			__le32 param0;
61 			__le32 param1;
62 			__le32 addr_high;
63 			__le32 addr_low;
64 		} indirect;
65 		u8 raw[16];
66 	} params;
67 };
68 
69 /* Flags sub-structure
70  * |0  |1  |2  |3  |4  |5  |6  |7  |8  |9  |10 |11 |12 |13 |14 |15 |
71  * |DD |CMP|ERR|  * RSV *  |FTYPE  | *RSV* |RD |VFC|BUF|  HOST_ID  |
72  */
73 /* command flags and offsets */
74 #define IDPF_CTLQ_FLAG_DD_S		0
75 #define IDPF_CTLQ_FLAG_CMP_S		1
76 #define IDPF_CTLQ_FLAG_ERR_S		2
77 #define IDPF_CTLQ_FLAG_FTYPE_S		6
78 #define IDPF_CTLQ_FLAG_RD_S		10
79 #define IDPF_CTLQ_FLAG_VFC_S		11
80 #define IDPF_CTLQ_FLAG_BUF_S		12
81 #define IDPF_CTLQ_FLAG_HOST_ID_S	13
82 
83 #define IDPF_CTLQ_FLAG_DD	BIT(IDPF_CTLQ_FLAG_DD_S)	/* 0x1	  */
84 #define IDPF_CTLQ_FLAG_CMP	BIT(IDPF_CTLQ_FLAG_CMP_S)	/* 0x2	  */
85 #define IDPF_CTLQ_FLAG_ERR	BIT(IDPF_CTLQ_FLAG_ERR_S)	/* 0x4	  */
86 #define IDPF_CTLQ_FLAG_FTYPE_VM	BIT(IDPF_CTLQ_FLAG_FTYPE_S)	/* 0x40	  */
87 #define IDPF_CTLQ_FLAG_FTYPE_PF	BIT(IDPF_CTLQ_FLAG_FTYPE_S + 1)	/* 0x80   */
88 #define IDPF_CTLQ_FLAG_RD	BIT(IDPF_CTLQ_FLAG_RD_S)	/* 0x400  */
89 #define IDPF_CTLQ_FLAG_VFC	BIT(IDPF_CTLQ_FLAG_VFC_S)	/* 0x800  */
90 #define IDPF_CTLQ_FLAG_BUF	BIT(IDPF_CTLQ_FLAG_BUF_S)	/* 0x1000 */
91 
92 struct idpf_mbxq_desc {
93 	u8 pad[8];		/* CTLQ flags/opcode/len/retval fields */
94 	u32 chnl_opcode;	/* avoid confusion with desc->opcode */
95 	u32 chnl_retval;	/* ditto for desc->retval */
96 	u32 pf_vf_id;		/* used by CP when sending to PF */
97 };
98 
99 int idpf_ctlq_alloc_ring_res(struct idpf_hw *hw,
100 			     struct idpf_ctlq_info *cq);
101 
102 void idpf_ctlq_dealloc_ring_res(struct idpf_hw *hw, struct idpf_ctlq_info *cq);
103 
104 /* prototype for functions used for dynamic memory allocation */
105 void *idpf_alloc_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem,
106 			 u64 size);
107 void idpf_free_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem);
108 #endif /* _IDPF_CONTROLQ_H_ */
109