1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2023 Intel Corporation */
4 #ifndef _IDPF_CONTROLQ_H_
5 #define _IDPF_CONTROLQ_H_
7 #include <linux/slab.h>
9 #include "idpf_controlq_api.h"
11 /* Maximum buffer length for all control queue types */
12 #define IDPF_CTLQ_MAX_BUF_LEN 4096
14 #define IDPF_CTLQ_DESC(R, i) \
15 (&(((struct idpf_ctlq_desc *)((R)->desc_ring.va))[i]))
17 #define IDPF_CTLQ_DESC_UNUSED(R) \
18 ((u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->ring_size) + \
19 (R)->next_to_clean - (R)->next_to_use - 1))
21 /* Control Queue default settings */
22 #define IDPF_CTRL_SQ_CMD_TIMEOUT 250 /* msecs */
24 struct idpf_ctlq_desc {
25 /* Control queue descriptor flags */
27 /* Control queue message opcode */
29 __le16 datalen; /* 0 for direct commands */
33 #define IDPF_CTLQ_DESC_VF_ID_S 0
34 #define IDPF_CTLQ_DESC_VF_ID_M (0x7FF << IDPF_CTLQ_DESC_VF_ID_S)
35 #define IDPF_CTLQ_DESC_PF_ID_S 11
36 #define IDPF_CTLQ_DESC_PF_ID_M (0x1F << IDPF_CTLQ_DESC_PF_ID_S)
39 /* Virtchnl message opcode and virtchnl descriptor type
40 * v_opcode=[27:0], v_dtype=[31:28]
42 __le32 v_opcode_dtype;
43 /* Virtchnl return value */
64 /* Flags sub-structure
65 * |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |11 |12 |13 |14 |15 |
66 * |DD |CMP|ERR| * RSV * |FTYPE | *RSV* |RD |VFC|BUF| HOST_ID |
68 /* command flags and offsets */
69 #define IDPF_CTLQ_FLAG_DD_S 0
70 #define IDPF_CTLQ_FLAG_CMP_S 1
71 #define IDPF_CTLQ_FLAG_ERR_S 2
72 #define IDPF_CTLQ_FLAG_FTYPE_S 6
73 #define IDPF_CTLQ_FLAG_RD_S 10
74 #define IDPF_CTLQ_FLAG_VFC_S 11
75 #define IDPF_CTLQ_FLAG_BUF_S 12
76 #define IDPF_CTLQ_FLAG_HOST_ID_S 13
78 #define IDPF_CTLQ_FLAG_DD BIT(IDPF_CTLQ_FLAG_DD_S) /* 0x1 */
79 #define IDPF_CTLQ_FLAG_CMP BIT(IDPF_CTLQ_FLAG_CMP_S) /* 0x2 */
80 #define IDPF_CTLQ_FLAG_ERR BIT(IDPF_CTLQ_FLAG_ERR_S) /* 0x4 */
81 #define IDPF_CTLQ_FLAG_FTYPE_VM BIT(IDPF_CTLQ_FLAG_FTYPE_S) /* 0x40 */
82 #define IDPF_CTLQ_FLAG_FTYPE_PF BIT(IDPF_CTLQ_FLAG_FTYPE_S + 1) /* 0x80 */
83 #define IDPF_CTLQ_FLAG_RD BIT(IDPF_CTLQ_FLAG_RD_S) /* 0x400 */
84 #define IDPF_CTLQ_FLAG_VFC BIT(IDPF_CTLQ_FLAG_VFC_S) /* 0x800 */
85 #define IDPF_CTLQ_FLAG_BUF BIT(IDPF_CTLQ_FLAG_BUF_S) /* 0x1000 */
87 /* Host ID is a special field that has 3b and not a 1b flag */
88 #define IDPF_CTLQ_FLAG_HOST_ID_M MAKE_MASK(0x7000UL, IDPF_CTLQ_FLAG_HOST_ID_S)
90 struct idpf_mbxq_desc {
91 u8 pad[8]; /* CTLQ flags/opcode/len/retval fields */
92 u32 chnl_opcode; /* avoid confusion with desc->opcode */
93 u32 chnl_retval; /* ditto for desc->retval */
94 u32 pf_vf_id; /* used by CP when sending to PF */
97 /* Define the driver hardware struct to replace other control structs as needed
98 * Align to ctlq_hw_info
101 void __iomem *hw_addr;
102 resource_size_t hw_addr_len;
104 struct idpf_adapter *back;
106 /* control queue - send and receive */
107 struct idpf_ctlq_info *asq;
108 struct idpf_ctlq_info *arq;
113 u16 subsystem_device_id;
114 u16 subsystem_vendor_id;
116 bool adapter_stopped;
118 struct list_head cq_list_head;
121 int idpf_ctlq_alloc_ring_res(struct idpf_hw *hw,
122 struct idpf_ctlq_info *cq);
124 void idpf_ctlq_dealloc_ring_res(struct idpf_hw *hw, struct idpf_ctlq_info *cq);
126 /* prototype for functions used for dynamic memory allocation */
127 void *idpf_alloc_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem,
129 void idpf_free_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem);
130 #endif /* _IDPF_CONTROLQ_H_ */