1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2024 Intel Corporation */
3
4 #ifndef _IDPF_VIRTCHNL_H_
5 #define _IDPF_VIRTCHNL_H_
6
7 #include "virtchnl2.h"
8
9 #define IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC (60 * 1000)
10 #define IDPF_VC_XN_IDX_M GENMASK(7, 0)
11 #define IDPF_VC_XN_SALT_M GENMASK(15, 8)
12 #define IDPF_VC_XN_RING_LEN U8_MAX
13
14 /**
15 * enum idpf_vc_xn_state - Virtchnl transaction status
16 * @IDPF_VC_XN_IDLE: not expecting a reply, ready to be used
17 * @IDPF_VC_XN_WAITING: expecting a reply, not yet received
18 * @IDPF_VC_XN_COMPLETED_SUCCESS: a reply was expected and received, buffer
19 * updated
20 * @IDPF_VC_XN_COMPLETED_FAILED: a reply was expected and received, but there
21 * was an error, buffer not updated
22 * @IDPF_VC_XN_SHUTDOWN: transaction object cannot be used, VC torn down
23 * @IDPF_VC_XN_ASYNC: transaction sent asynchronously and doesn't have the
24 * return context; a callback may be provided to handle
25 * return
26 */
27 enum idpf_vc_xn_state {
28 IDPF_VC_XN_IDLE = 1,
29 IDPF_VC_XN_WAITING,
30 IDPF_VC_XN_COMPLETED_SUCCESS,
31 IDPF_VC_XN_COMPLETED_FAILED,
32 IDPF_VC_XN_SHUTDOWN,
33 IDPF_VC_XN_ASYNC,
34 };
35
36 struct idpf_vc_xn;
37 /* Callback for asynchronous messages */
38 typedef int (*async_vc_cb) (struct idpf_adapter *, struct idpf_vc_xn *,
39 const struct idpf_ctlq_msg *);
40
41 /**
42 * struct idpf_vc_xn - Data structure representing virtchnl transactions
43 * @completed: virtchnl event loop uses that to signal when a reply is
44 * available, uses kernel completion API
45 * @lock: protects the transaction state fields below
46 * @state: virtchnl event loop stores the data below, protected by @lock
47 * @reply_sz: Original size of reply, may be > reply_buf.iov_len; it will be
48 * truncated on its way to the receiver thread according to
49 * reply_buf.iov_len.
50 * @reply: Reference to the buffer(s) where the reply data should be written
51 * to. May be 0-length (then NULL address permitted) if the reply data
52 * should be ignored.
53 * @async_handler: if sent asynchronously, a callback can be provided to handle
54 * the reply when it's received
55 * @vc_op: corresponding opcode sent with this transaction
56 * @idx: index used as retrieval on reply receive, used for cookie
57 * @salt: changed every message to make unique, used for cookie
58 */
59 struct idpf_vc_xn {
60 struct completion completed;
61 spinlock_t lock;
62 enum idpf_vc_xn_state state;
63 size_t reply_sz;
64 struct kvec reply;
65 async_vc_cb async_handler;
66 u32 vc_op;
67 u8 idx;
68 u8 salt;
69 };
70
71 /**
72 * struct idpf_vc_xn_params - Parameters for executing transaction
73 * @send_buf: kvec for send buffer
74 * @recv_buf: kvec for recv buffer, may be NULL, must then have zero length
75 * @timeout_ms: timeout to wait for reply
76 * @async: send message asynchronously, will not wait on completion
77 * @async_handler: If sent asynchronously, optional callback handler. The user
78 * must be careful when using async handlers as the memory for
79 * the recv_buf _cannot_ be on stack if this is async.
80 * @vc_op: virtchnl op to send
81 */
82 struct idpf_vc_xn_params {
83 struct kvec send_buf;
84 struct kvec recv_buf;
85 int timeout_ms;
86 bool async;
87 async_vc_cb async_handler;
88 u32 vc_op;
89 };
90
91 struct idpf_adapter;
92 struct idpf_netdev_priv;
93 struct idpf_vec_regs;
94 struct idpf_vport;
95 struct idpf_vport_max_q;
96 struct idpf_vport_config;
97 struct idpf_vport_user_config_data;
98
99 ssize_t idpf_vc_xn_exec(struct idpf_adapter *adapter,
100 const struct idpf_vc_xn_params *params);
101 int idpf_init_dflt_mbx(struct idpf_adapter *adapter);
102 void idpf_deinit_dflt_mbx(struct idpf_adapter *adapter);
103 int idpf_vc_core_init(struct idpf_adapter *adapter);
104 void idpf_vc_core_deinit(struct idpf_adapter *adapter);
105
106 int idpf_get_reg_intr_vecs(struct idpf_adapter *adapter,
107 struct idpf_vec_regs *reg_vals);
108 int idpf_queue_reg_init(struct idpf_vport *vport,
109 struct idpf_q_vec_rsrc *rsrc,
110 struct idpf_queue_id_reg_info *chunks);
111 int idpf_vport_queue_ids_init(struct idpf_vport *vport,
112 struct idpf_q_vec_rsrc *rsrc,
113 struct idpf_queue_id_reg_info *chunks);
114 static inline void
idpf_vport_deinit_queue_reg_chunks(struct idpf_vport_config * vport_cfg)115 idpf_vport_deinit_queue_reg_chunks(struct idpf_vport_config *vport_cfg)
116 {
117 kfree(vport_cfg->qid_reg_info.queue_chunks);
118 vport_cfg->qid_reg_info.queue_chunks = NULL;
119 }
120
121 bool idpf_vport_is_cap_ena(struct idpf_vport *vport, u16 flag);
122 bool idpf_sideband_flow_type_ena(struct idpf_vport *vport, u32 flow_type);
123 bool idpf_sideband_action_ena(struct idpf_vport *vport,
124 struct ethtool_rx_flow_spec *fsp);
125 unsigned int idpf_fsteer_max_rules(struct idpf_vport *vport);
126
127 int idpf_recv_mb_msg(struct idpf_adapter *adapter, struct idpf_ctlq_info *arq);
128 int idpf_send_mb_msg(struct idpf_adapter *adapter, struct idpf_ctlq_info *asq,
129 u32 op, u16 msg_size, u8 *msg, u16 cookie);
130
131 struct idpf_queue_ptr {
132 enum virtchnl2_queue_type type;
133 union {
134 struct idpf_rx_queue *rxq;
135 struct idpf_tx_queue *txq;
136 struct idpf_buf_queue *bufq;
137 struct idpf_compl_queue *complq;
138 };
139 };
140
141 struct idpf_queue_set {
142 struct idpf_adapter *adapter;
143 struct idpf_q_vec_rsrc *qv_rsrc;
144 u32 vport_id;
145
146 u32 num;
147 struct idpf_queue_ptr qs[] __counted_by(num);
148 };
149
150 struct idpf_queue_set *idpf_alloc_queue_set(struct idpf_adapter *adapter,
151 struct idpf_q_vec_rsrc *rsrc,
152 u32 vport_id, u32 num);
153
154 int idpf_send_enable_queue_set_msg(const struct idpf_queue_set *qs);
155 int idpf_send_disable_queue_set_msg(const struct idpf_queue_set *qs);
156 int idpf_send_config_queue_set_msg(const struct idpf_queue_set *qs);
157
158 int idpf_send_disable_queues_msg(struct idpf_vport *vport);
159 int idpf_send_enable_queues_msg(struct idpf_vport *vport);
160 int idpf_send_config_queues_msg(struct idpf_adapter *adapter,
161 struct idpf_q_vec_rsrc *rsrc,
162 u32 vport_id);
163
164 int idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q);
165 u32 idpf_get_vport_id(struct idpf_vport *vport);
166 int idpf_send_create_vport_msg(struct idpf_adapter *adapter,
167 struct idpf_vport_max_q *max_q);
168 int idpf_send_destroy_vport_msg(struct idpf_adapter *adapter, u32 vport_id);
169 int idpf_send_enable_vport_msg(struct idpf_adapter *adapter, u32 vport_id);
170 int idpf_send_disable_vport_msg(struct idpf_adapter *adapter, u32 vport_id);
171
172 int idpf_vport_adjust_qs(struct idpf_vport *vport,
173 struct idpf_q_vec_rsrc *rsrc);
174 int idpf_vport_alloc_max_qs(struct idpf_adapter *adapter,
175 struct idpf_vport_max_q *max_q);
176 void idpf_vport_dealloc_max_qs(struct idpf_adapter *adapter,
177 struct idpf_vport_max_q *max_q);
178 int idpf_send_add_queues_msg(struct idpf_adapter *adapter,
179 struct idpf_vport_config *vport_config,
180 struct idpf_q_vec_rsrc *rsrc,
181 u32 vport_id);
182 int idpf_send_delete_queues_msg(struct idpf_adapter *adapter,
183 struct idpf_queue_id_reg_info *chunks,
184 u32 vport_id);
185
186 int idpf_vport_alloc_vec_indexes(struct idpf_vport *vport,
187 struct idpf_q_vec_rsrc *rsrc);
188 int idpf_get_vec_ids(struct idpf_adapter *adapter,
189 u16 *vecids, int num_vecids,
190 struct virtchnl2_vector_chunks *chunks);
191 int idpf_send_alloc_vectors_msg(struct idpf_adapter *adapter, u16 num_vectors);
192 int idpf_send_dealloc_vectors_msg(struct idpf_adapter *adapter);
193 int idpf_send_map_unmap_queue_vector_msg(struct idpf_adapter *adapter,
194 struct idpf_q_vec_rsrc *rsrc,
195 u32 vport_id,
196 bool map);
197
198 int idpf_add_del_mac_filters(struct idpf_adapter *adapter,
199 struct idpf_vport_config *vport_config,
200 const u8 *default_mac_addr, u32 vport_id,
201 bool add, bool async);
202 int idpf_set_promiscuous(struct idpf_adapter *adapter,
203 struct idpf_vport_user_config_data *config_data,
204 u32 vport_id);
205 int idpf_check_supported_desc_ids(struct idpf_vport *vport);
206 int idpf_send_ena_dis_loopback_msg(struct idpf_adapter *adapter, u32 vport_id,
207 bool loopback_ena);
208 int idpf_send_get_stats_msg(struct idpf_netdev_priv *np,
209 struct idpf_port_stats *port_stats);
210 int idpf_send_set_sriov_vfs_msg(struct idpf_adapter *adapter, u16 num_vfs);
211 int idpf_send_get_set_rss_key_msg(struct idpf_adapter *adapter,
212 struct idpf_rss_data *rss_data,
213 u32 vport_id, bool get);
214 int idpf_send_get_set_rss_lut_msg(struct idpf_adapter *adapter,
215 struct idpf_rss_data *rss_data,
216 u32 vport_id, bool get);
217 void idpf_vc_xn_shutdown(struct idpf_vc_xn_manager *vcxn_mngr);
218 int idpf_idc_rdma_vc_send_sync(struct iidc_rdma_core_dev_info *cdev_info,
219 u8 *send_msg, u16 msg_size,
220 u8 *recv_msg, u16 *recv_len);
221
222 #endif /* _IDPF_VIRTCHNL_H_ */
223