Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <assert.h>
7 : : #include <inttypes.h>
8 : : #include <stdbool.h>
9 : : #include <stdlib.h>
10 : : #include <string.h>
11 : :
12 : : #include "tf_em_common.h"
13 : : #include "tf_msg_common.h"
14 : : #include "tf_device.h"
15 : : #include "tf_msg.h"
16 : : #include "tf_util.h"
17 : : #include "tf_common.h"
18 : : #include "tf_session.h"
19 : : #include "tfp.h"
20 : : #include "tf_em.h"
21 : :
22 : : /* Specific msg size defines as we cannot use defines in tf.yaml. This
23 : : * means we have to manually sync hwrm with these defines if the
24 : : * tf.yaml changes.
25 : : */
26 : : #define TF_MSG_SET_GLOBAL_CFG_DATA_SIZE 16
27 : : #define TF_MSG_EM_INSERT_KEY_SIZE 64
28 : : #define TF_MSG_EM_INSERT_RECORD_SIZE 80
29 : : #define TF_MSG_TBL_TYPE_SET_DATA_SIZE 88
30 : :
31 : : /* Compile check - Catch any msg changes that we depend on, like the
32 : : * defines listed above for array size checking.
33 : : *
34 : : * Checking array size is dangerous in that the type could change and
35 : : * we wouldn't be able to catch it. Thus we check if the complete msg
36 : : * changed instead. Best we can do.
37 : : *
38 : : * If failure is observed then both msg size (defines below) and the
39 : : * array size (define above) should be checked and compared.
40 : : */
41 : : #define TF_MSG_SIZE_HWRM_TF_GLOBAL_CFG_SET 56
42 : : static_assert(sizeof(struct hwrm_tf_global_cfg_set_input) ==
43 : : TF_MSG_SIZE_HWRM_TF_GLOBAL_CFG_SET,
44 : : "HWRM message size changed: hwrm_tf_global_cfg_set_input");
45 : :
46 : : #define TF_MSG_SIZE_HWRM_TF_EM_INSERT 104
47 : : static_assert(sizeof(struct hwrm_tf_em_insert_input) ==
48 : : TF_MSG_SIZE_HWRM_TF_EM_INSERT,
49 : : "HWRM message size changed: hwrm_tf_em_insert_input");
50 : : #define TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET 128
51 : : static_assert(sizeof(struct hwrm_tf_tbl_type_set_input) ==
52 : : TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET,
53 : : "HWRM message size changed: hwrm_tf_tbl_type_set_input");
54 : :
55 : : /**
56 : : * This is the MAX data we can transport across regular HWRM
57 : : */
58 : : #define TF_PCI_BUF_SIZE_MAX 88
59 : :
60 : : /**
61 : : * This is the length of shared session name "tf_share"
62 : : */
63 : : #define TF_SHARED_SESSION_NAME_LEN 9
64 : :
65 : : /**
66 : : * This is the length of tcam shared session name "tf_shared-wc_tcam"
67 : : */
68 : : #define TF_TCAM_SHARED_SESSION_NAME_LEN 17
69 : :
70 : : /**
71 : : * This is the length of tcam shared session name "tf_shared-poolx"
72 : : */
73 : : #define TF_POOL_SHARED_SESSION_NAME_LEN 16
74 : :
75 : : /**
76 : : * If data bigger than TF_PCI_BUF_SIZE_MAX then use DMA method
77 : : */
78 : : struct tf_msg_dma_buf {
79 : : void *va_addr;
80 : : uint64_t pa_addr;
81 : : };
82 : :
83 : : /**
84 : : * Allocates a DMA buffer that can be used for message transfer.
85 : : *
86 : : * [in] buf
87 : : * Pointer to DMA buffer structure
88 : : *
89 : : * [in] size
90 : : * Requested size of the buffer in bytes
91 : : *
92 : : * Returns:
93 : : * 0 - Success
94 : : * -ENOMEM - Unable to allocate buffer, no memory
95 : : */
96 : : static int
97 : : tf_msg_alloc_dma_buf(struct tf_msg_dma_buf *buf, int size)
98 : : {
99 : : struct tfp_calloc_parms alloc_parms;
100 : : int rc;
101 : :
102 : : /* Allocate session */
103 : 0 : alloc_parms.nitems = 1;
104 : 0 : alloc_parms.size = size;
105 : 0 : alloc_parms.alignment = 4096;
106 : 0 : rc = tfp_calloc(&alloc_parms);
107 [ # # # # : 0 : if (rc)
# # # # #
# # # # #
# # ]
108 : : return -ENOMEM;
109 : :
110 : 0 : buf->pa_addr = (uintptr_t)alloc_parms.mem_pa;
111 : 0 : buf->va_addr = alloc_parms.mem_va;
112 : :
113 : : return 0;
114 : : }
115 : :
116 : : /**
117 : : * Free's a previous allocated DMA buffer.
118 : : *
119 : : * [in] buf
120 : : * Pointer to DMA buffer structure
121 : : */
122 : : static void
123 : : tf_msg_free_dma_buf(struct tf_msg_dma_buf *buf)
124 : : {
125 : 0 : tfp_free(buf->va_addr);
126 : : }
127 : :
128 : : /* HWRM Direct messages */
129 : :
130 : : int
131 : 0 : tf_msg_session_open(struct bnxt *bp,
132 : : char *ctrl_chan_name,
133 : : uint8_t *fw_session_id,
134 : : uint8_t *fw_session_client_id,
135 : : struct tf_dev_info *dev,
136 : : bool *shared_session_creator)
137 : : {
138 : : int rc;
139 : 0 : struct hwrm_tf_session_open_input req = { 0 };
140 : 0 : struct hwrm_tf_session_open_output resp = { 0 };
141 : 0 : struct tfp_send_msg_parms parms = { 0 };
142 : : char *session_name;
143 : : char *tcam_session_name;
144 : : char *pool_session_name;
145 : :
146 : : /*
147 : : * "tf_shared-wc_tcam" is defined for tf_fw version 1.0.0.
148 : : * "tf_shared-pool" is defined for version 1.0.1.
149 : : * "tf_shared" is used by both verions.
150 : : */
151 : 0 : tcam_session_name = strstr(ctrl_chan_name, "tf_shared-wc_tcam");
152 : 0 : pool_session_name = strstr(ctrl_chan_name, "tf_shared-pool");
153 : 0 : session_name = strstr(ctrl_chan_name, "tf_shared");
154 [ # # ]: 0 : if (tcam_session_name)
155 : 0 : tfp_memcpy(&req.session_name,
156 : : tcam_session_name,
157 : : TF_TCAM_SHARED_SESSION_NAME_LEN);
158 [ # # ]: 0 : else if (pool_session_name)
159 : 0 : tfp_memcpy(&req.session_name,
160 : : pool_session_name,
161 : : TF_POOL_SHARED_SESSION_NAME_LEN);
162 [ # # ]: 0 : else if (session_name)
163 : 0 : tfp_memcpy(&req.session_name,
164 : : session_name,
165 : : TF_SHARED_SESSION_NAME_LEN);
166 : : else
167 : 0 : tfp_memcpy(&req.session_name, ctrl_chan_name, TF_SESSION_NAME_MAX);
168 : :
169 : 0 : parms.tf_type = HWRM_TF_SESSION_OPEN;
170 : 0 : parms.req_data = (uint32_t *)&req;
171 : 0 : parms.req_size = sizeof(req);
172 : 0 : parms.resp_data = (uint32_t *)&resp;
173 : 0 : parms.resp_size = sizeof(resp);
174 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
175 : :
176 : 0 : rc = tfp_send_msg_direct(bp,
177 : : &parms);
178 [ # # ]: 0 : if (rc)
179 : : return rc;
180 : :
181 : 0 : *fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
182 : 0 : *fw_session_client_id =
183 : 0 : (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
184 : 0 : *shared_session_creator = (bool)tfp_le_to_cpu_32(resp.flags
185 : : & HWRM_TF_SESSION_OPEN_OUTPUT_FLAGS_SHARED_SESSION_CREATOR);
186 : :
187 : 0 : return rc;
188 : : }
189 : :
190 : : int
191 : 0 : tf_msg_session_attach(struct tf *tfp __rte_unused,
192 : : char *ctrl_chan_name __rte_unused,
193 : : uint8_t tf_fw_session_id __rte_unused)
194 : : {
195 : 0 : return -1;
196 : : }
197 : :
198 : : int
199 : 0 : tf_msg_session_client_register(struct tf *tfp,
200 : : struct tf_session *tfs,
201 : : char *ctrl_channel_name,
202 : : uint8_t *fw_session_client_id)
203 : : {
204 : : int rc;
205 : 0 : struct hwrm_tf_session_register_input req = { 0 };
206 : 0 : struct hwrm_tf_session_register_output resp = { 0 };
207 : 0 : struct tfp_send_msg_parms parms = { 0 };
208 : : uint8_t fw_session_id;
209 : : struct tf_dev_info *dev;
210 : : char *session_name;
211 : : char *tcam_session_name;
212 : : char *pool_session_name;
213 : :
214 : : /* Retrieve the device information */
215 : 0 : rc = tf_session_get_device(tfs, &dev);
216 [ # # ]: 0 : if (rc) {
217 : 0 : TFP_DRV_LOG(ERR,
218 : : "Failed to lookup device, rc:%s\n",
219 : : strerror(-rc));
220 : 0 : return rc;
221 : : }
222 : :
223 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
224 [ # # ]: 0 : if (rc) {
225 : 0 : TFP_DRV_LOG(ERR,
226 : : "Unable to lookup FW id, rc:%s\n",
227 : : strerror(-rc));
228 : 0 : return rc;
229 : : }
230 : :
231 : : /* Populate the request */
232 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
233 : :
234 : : /*
235 : : * "tf_shared-wc_tcam" is defined for tf_fw version 1.0.0.
236 : : * "tf_shared-pool" is defined for version 1.0.1.
237 : : * "tf_shared" is used by both verions.
238 : : */
239 : 0 : tcam_session_name = strstr(ctrl_channel_name, "tf_shared-wc_tcam");
240 : 0 : pool_session_name = strstr(ctrl_channel_name, "tf_shared-pool");
241 : 0 : session_name = strstr(ctrl_channel_name, "tf_shared");
242 [ # # ]: 0 : if (tcam_session_name)
243 : 0 : tfp_memcpy(&req.session_client_name,
244 : : tcam_session_name,
245 : : TF_TCAM_SHARED_SESSION_NAME_LEN);
246 [ # # ]: 0 : else if (pool_session_name)
247 : 0 : tfp_memcpy(&req.session_client_name,
248 : : pool_session_name,
249 : : TF_POOL_SHARED_SESSION_NAME_LEN);
250 [ # # ]: 0 : else if (session_name)
251 : 0 : tfp_memcpy(&req.session_client_name,
252 : : session_name,
253 : : TF_SHARED_SESSION_NAME_LEN);
254 : : else
255 : 0 : tfp_memcpy(&req.session_client_name,
256 : : ctrl_channel_name,
257 : : TF_SESSION_NAME_MAX);
258 : :
259 : 0 : parms.tf_type = HWRM_TF_SESSION_REGISTER;
260 : 0 : parms.req_data = (uint32_t *)&req;
261 : 0 : parms.req_size = sizeof(req);
262 : 0 : parms.resp_data = (uint32_t *)&resp;
263 : 0 : parms.resp_size = sizeof(resp);
264 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
265 : :
266 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
267 : : &parms);
268 [ # # ]: 0 : if (rc)
269 : : return rc;
270 : :
271 : 0 : *fw_session_client_id =
272 : 0 : (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
273 : :
274 : 0 : return rc;
275 : : }
276 : :
277 : : int
278 : 0 : tf_msg_session_client_unregister(struct tf *tfp,
279 : : struct tf_session *tfs,
280 : : uint8_t fw_session_client_id)
281 : : {
282 : : int rc;
283 : 0 : struct hwrm_tf_session_unregister_input req = { 0 };
284 : 0 : struct hwrm_tf_session_unregister_output resp = { 0 };
285 : 0 : struct tfp_send_msg_parms parms = { 0 };
286 : : uint8_t fw_session_id;
287 : : struct tf_dev_info *dev;
288 : :
289 : : /* Retrieve the device information */
290 : 0 : rc = tf_session_get_device(tfs, &dev);
291 [ # # ]: 0 : if (rc) {
292 : 0 : TFP_DRV_LOG(ERR,
293 : : "Failed to lookup device, rc:%s\n",
294 : : strerror(-rc));
295 : 0 : return rc;
296 : : }
297 : :
298 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
299 [ # # ]: 0 : if (rc) {
300 : 0 : TFP_DRV_LOG(ERR,
301 : : "Unable to lookup FW id, rc:%s\n",
302 : : strerror(-rc));
303 : 0 : return rc;
304 : : }
305 : :
306 : : /* Populate the request */
307 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
308 : 0 : req.fw_session_client_id = tfp_cpu_to_le_32(fw_session_client_id);
309 : :
310 : 0 : parms.tf_type = HWRM_TF_SESSION_UNREGISTER;
311 : 0 : parms.req_data = (uint32_t *)&req;
312 : 0 : parms.req_size = sizeof(req);
313 : 0 : parms.resp_data = (uint32_t *)&resp;
314 : 0 : parms.resp_size = sizeof(resp);
315 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
316 : :
317 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
318 : : &parms);
319 : :
320 : 0 : return rc;
321 : : }
322 : :
323 : : int
324 : 0 : tf_msg_session_close(struct tf *tfp,
325 : : uint8_t fw_session_id,
326 : : int mailbox)
327 : : {
328 : : int rc;
329 : 0 : struct hwrm_tf_session_close_input req = { 0 };
330 : 0 : struct hwrm_tf_session_close_output resp = { 0 };
331 : 0 : struct tfp_send_msg_parms parms = { 0 };
332 : :
333 : : /* Populate the request */
334 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
335 : :
336 : 0 : parms.tf_type = HWRM_TF_SESSION_CLOSE;
337 : 0 : parms.req_data = (uint32_t *)&req;
338 : 0 : parms.req_size = sizeof(req);
339 : 0 : parms.resp_data = (uint32_t *)&resp;
340 : 0 : parms.resp_size = sizeof(resp);
341 : 0 : parms.mailbox = mailbox;
342 : :
343 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
344 : : &parms);
345 : 0 : return rc;
346 : : }
347 : :
348 : : int
349 : 0 : tf_msg_session_qcfg(struct tf *tfp)
350 : : {
351 : : int rc;
352 : 0 : struct hwrm_tf_session_qcfg_input req = { 0 };
353 : 0 : struct hwrm_tf_session_qcfg_output resp = { 0 };
354 : 0 : struct tfp_send_msg_parms parms = { 0 };
355 : : uint8_t fw_session_id;
356 : : struct tf_dev_info *dev;
357 : : struct tf_session *tfs;
358 : :
359 : : /* Retrieve the session information */
360 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
361 [ # # ]: 0 : if (rc) {
362 : 0 : TFP_DRV_LOG(ERR,
363 : : "Failed to lookup session, rc:%s\n",
364 : : strerror(-rc));
365 : 0 : return rc;
366 : : }
367 : :
368 : : /* Retrieve the device information */
369 : 0 : rc = tf_session_get_device(tfs, &dev);
370 [ # # ]: 0 : if (rc) {
371 : 0 : TFP_DRV_LOG(ERR,
372 : : "Failed to lookup device, rc:%s\n",
373 : : strerror(-rc));
374 : 0 : return rc;
375 : : }
376 : :
377 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
378 [ # # ]: 0 : if (rc) {
379 : 0 : TFP_DRV_LOG(ERR,
380 : : "Unable to lookup FW id, rc:%s\n",
381 : : strerror(-rc));
382 : 0 : return rc;
383 : : }
384 : :
385 : : /* Populate the request */
386 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
387 : :
388 : 0 : parms.tf_type = HWRM_TF_SESSION_QCFG,
389 : 0 : parms.req_data = (uint32_t *)&req;
390 : 0 : parms.req_size = sizeof(req);
391 : 0 : parms.resp_data = (uint32_t *)&resp;
392 : 0 : parms.resp_size = sizeof(resp);
393 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
394 : :
395 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
396 : : &parms);
397 : 0 : return rc;
398 : : }
399 : :
400 : : int
401 : 0 : tf_msg_session_resc_qcaps(struct tf *tfp,
402 : : struct tf_dev_info *dev,
403 : : enum tf_dir dir,
404 : : uint16_t size,
405 : : struct tf_rm_resc_req_entry *query,
406 : : enum tf_rm_resc_resv_strategy *resv_strategy,
407 : : uint8_t *sram_profile)
408 : : {
409 : : int rc;
410 : : int i;
411 : 0 : struct tfp_send_msg_parms parms = { 0 };
412 : 0 : struct hwrm_tf_session_resc_qcaps_input req = { 0 };
413 : 0 : struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
414 : : struct tf_msg_dma_buf qcaps_buf = { 0 };
415 : : struct tf_rm_resc_req_entry *data;
416 : : int dma_size;
417 : :
418 [ # # # # ]: 0 : TF_CHECK_PARMS3(tfp, query, resv_strategy);
419 : :
420 : : /* Prepare DMA buffer */
421 : 0 : dma_size = size * sizeof(struct tf_rm_resc_req_entry);
422 : : rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
423 : : if (rc)
424 : 0 : return rc;
425 : :
426 : : /* Populate the request */
427 : 0 : req.fw_session_id = 0;
428 : 0 : req.flags = tfp_cpu_to_le_16(dir);
429 : 0 : req.qcaps_size = size;
430 : 0 : req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
431 : :
432 : 0 : parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
433 : 0 : parms.req_data = (uint32_t *)&req;
434 : 0 : parms.req_size = sizeof(req);
435 : 0 : parms.resp_data = (uint32_t *)&resp;
436 : 0 : parms.resp_size = sizeof(resp);
437 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
438 : :
439 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
440 [ # # ]: 0 : if (rc)
441 : 0 : goto cleanup;
442 : :
443 : : /* Process the response
444 : : * Should always get expected number of entries
445 : : */
446 [ # # ]: 0 : if (tfp_le_to_cpu_32(resp.size) != size) {
447 : 0 : TFP_DRV_LOG(WARNING,
448 : : "%s: QCAPS message size error, rc:%s, request %d vs response %d\n",
449 : : tf_dir_2_str(dir),
450 : : strerror(EINVAL),
451 : : size,
452 : : resp.size);
453 : : }
454 : :
455 : : /* Post process the response */
456 : : data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
457 [ # # ]: 0 : for (i = 0; i < resp.size; i++) {
458 : 0 : query[i].type = tfp_le_to_cpu_32(data[i].type);
459 : 0 : query[i].min = tfp_le_to_cpu_16(data[i].min);
460 : 0 : query[i].max = tfp_le_to_cpu_16(data[i].max);
461 : : }
462 : :
463 : 0 : *resv_strategy = resp.flags &
464 : : HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
465 : :
466 [ # # ]: 0 : if (sram_profile != NULL)
467 : 0 : *sram_profile = resp.sram_profile;
468 : :
469 : 0 : cleanup:
470 : : tf_msg_free_dma_buf(&qcaps_buf);
471 : :
472 : 0 : return rc;
473 : : }
474 : :
475 : : int
476 : 0 : tf_msg_session_resc_alloc(struct tf *tfp,
477 : : struct tf_dev_info *dev,
478 : : enum tf_dir dir,
479 : : uint16_t size,
480 : : struct tf_rm_resc_req_entry *request,
481 : : struct tf_rm_resc_entry *resv)
482 : : {
483 : : int rc;
484 : : int i;
485 : 0 : struct tfp_send_msg_parms parms = { 0 };
486 : 0 : struct hwrm_tf_session_resc_alloc_input req = { 0 };
487 : 0 : struct hwrm_tf_session_resc_alloc_output resp = { 0 };
488 : : uint8_t fw_session_id;
489 : : struct tf_msg_dma_buf req_buf = { 0 };
490 : : struct tf_msg_dma_buf resv_buf = { 0 };
491 : : struct tf_rm_resc_req_entry *req_data;
492 : : struct tf_rm_resc_entry *resv_data;
493 : : int dma_size;
494 : : struct tf_session *tfs;
495 : :
496 : : /* Retrieve the session information */
497 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
498 [ # # ]: 0 : if (rc) {
499 : 0 : TFP_DRV_LOG(ERR,
500 : : "Failed to lookup session, rc:%s\n",
501 : : strerror(-rc));
502 : 0 : return rc;
503 : : }
504 : :
505 [ # # # # ]: 0 : TF_CHECK_PARMS3(tfp, request, resv);
506 : :
507 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
508 [ # # ]: 0 : if (rc) {
509 : 0 : TFP_DRV_LOG(ERR,
510 : : "%s: Unable to lookup FW id, rc:%s\n",
511 : : tf_dir_2_str(dir),
512 : : strerror(-rc));
513 : 0 : return rc;
514 : : }
515 : :
516 : : /* Prepare DMA buffers */
517 : 0 : dma_size = size * sizeof(struct tf_rm_resc_req_entry);
518 : : rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
519 : : if (rc)
520 : 0 : return rc;
521 : :
522 : : dma_size = size * sizeof(struct tf_rm_resc_entry);
523 : : rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
524 : : if (rc) {
525 : : tf_msg_free_dma_buf(&req_buf);
526 : 0 : return rc;
527 : : }
528 : :
529 : : /* Populate the request */
530 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
531 : 0 : req.flags = tfp_cpu_to_le_16(dir);
532 : 0 : req.req_size = size;
533 : :
534 : : req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
535 [ # # ]: 0 : for (i = 0; i < size; i++) {
536 : 0 : req_data[i].type = tfp_cpu_to_le_32(request[i].type);
537 : 0 : req_data[i].min = tfp_cpu_to_le_16(request[i].min);
538 : 0 : req_data[i].max = tfp_cpu_to_le_16(request[i].max);
539 : : }
540 : :
541 : 0 : req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
542 : 0 : req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
543 : :
544 : 0 : parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
545 : 0 : parms.req_data = (uint32_t *)&req;
546 : 0 : parms.req_size = sizeof(req);
547 : 0 : parms.resp_data = (uint32_t *)&resp;
548 : 0 : parms.resp_size = sizeof(resp);
549 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
550 : :
551 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
552 [ # # ]: 0 : if (rc)
553 : 0 : goto cleanup;
554 : :
555 : : /* Process the response
556 : : * Should always get expected number of entries
557 : : */
558 [ # # ]: 0 : if (tfp_le_to_cpu_32(resp.size) != size) {
559 : 0 : TFP_DRV_LOG(ERR,
560 : : "%s: Alloc message size error, rc:%s\n",
561 : : tf_dir_2_str(dir),
562 : : strerror(EINVAL));
563 : : rc = -EINVAL;
564 : 0 : goto cleanup;
565 : : }
566 : :
567 : : /* Post process the response */
568 : : resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
569 [ # # ]: 0 : for (i = 0; i < size; i++) {
570 : 0 : resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
571 : 0 : resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
572 : 0 : resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
573 : : }
574 : :
575 : 0 : cleanup:
576 : : tf_msg_free_dma_buf(&req_buf);
577 : : tf_msg_free_dma_buf(&resv_buf);
578 : :
579 : 0 : return rc;
580 : : }
581 : :
582 : : int
583 : 0 : tf_msg_session_resc_info(struct tf *tfp,
584 : : struct tf_dev_info *dev,
585 : : enum tf_dir dir,
586 : : uint16_t size,
587 : : struct tf_rm_resc_req_entry *request,
588 : : struct tf_rm_resc_entry *resv)
589 : : {
590 : : int rc;
591 : : int i;
592 : 0 : struct tfp_send_msg_parms parms = { 0 };
593 : 0 : struct hwrm_tf_session_resc_info_input req = { 0 };
594 : 0 : struct hwrm_tf_session_resc_info_output resp = { 0 };
595 : : uint8_t fw_session_id;
596 : : struct tf_msg_dma_buf req_buf = { 0 };
597 : : struct tf_msg_dma_buf resv_buf = { 0 };
598 : : struct tf_rm_resc_req_entry *req_data;
599 : : struct tf_rm_resc_entry *resv_data;
600 : : int dma_size;
601 : : struct tf_session *tfs;
602 : :
603 : : /* Retrieve the session information */
604 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
605 [ # # ]: 0 : if (rc) {
606 : 0 : TFP_DRV_LOG(ERR,
607 : : "Failed to lookup session, rc:%s\n",
608 : : strerror(-rc));
609 : 0 : return rc;
610 : : }
611 : :
612 [ # # # # ]: 0 : TF_CHECK_PARMS3(tfp, request, resv);
613 : :
614 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
615 [ # # ]: 0 : if (rc) {
616 : 0 : TFP_DRV_LOG(ERR,
617 : : "%s: Unable to lookup FW id, rc:%s\n",
618 : : tf_dir_2_str(dir),
619 : : strerror(-rc));
620 : 0 : return rc;
621 : : }
622 : :
623 : : /* Prepare DMA buffers */
624 : 0 : dma_size = size * sizeof(struct tf_rm_resc_req_entry);
625 : : rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
626 : : if (rc)
627 : 0 : return rc;
628 : :
629 : : dma_size = size * sizeof(struct tf_rm_resc_entry);
630 : : rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
631 : : if (rc) {
632 : : tf_msg_free_dma_buf(&req_buf);
633 : 0 : return rc;
634 : : }
635 : :
636 : : /* Populate the request */
637 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
638 : 0 : req.flags = tfp_cpu_to_le_16(dir);
639 : 0 : req.req_size = size;
640 : :
641 : : req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
642 [ # # ]: 0 : for (i = 0; i < size; i++) {
643 : 0 : req_data[i].type = tfp_cpu_to_le_32(request[i].type);
644 : 0 : req_data[i].min = tfp_cpu_to_le_16(request[i].min);
645 : 0 : req_data[i].max = tfp_cpu_to_le_16(request[i].max);
646 : : }
647 : :
648 : 0 : req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
649 : 0 : req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
650 : :
651 : 0 : parms.tf_type = HWRM_TF_SESSION_RESC_INFO;
652 : 0 : parms.req_data = (uint32_t *)&req;
653 : 0 : parms.req_size = sizeof(req);
654 : 0 : parms.resp_data = (uint32_t *)&resp;
655 : 0 : parms.resp_size = sizeof(resp);
656 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
657 : :
658 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
659 [ # # ]: 0 : if (rc)
660 : 0 : goto cleanup;
661 : :
662 : : /* Process the response
663 : : * Should always get expected number of entries
664 : : */
665 [ # # ]: 0 : if (tfp_le_to_cpu_32(resp.size) != size) {
666 : 0 : TFP_DRV_LOG(ERR,
667 : : "%s: Alloc message size error, rc:%s\n",
668 : : tf_dir_2_str(dir),
669 : : strerror(EINVAL));
670 : : rc = -EINVAL;
671 : 0 : goto cleanup;
672 : : }
673 : :
674 : : /* Post process the response */
675 : : resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
676 [ # # ]: 0 : for (i = 0; i < size; i++) {
677 : 0 : resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
678 : 0 : resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
679 : 0 : resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
680 : : }
681 : :
682 : 0 : cleanup:
683 : : tf_msg_free_dma_buf(&req_buf);
684 : : tf_msg_free_dma_buf(&resv_buf);
685 : :
686 : 0 : return rc;
687 : : }
688 : :
689 : : int
690 : 0 : tf_msg_session_resc_flush(struct tf *tfp,
691 : : enum tf_dir dir,
692 : : uint16_t size,
693 : : struct tf_rm_resc_entry *resv)
694 : : {
695 : : int rc;
696 : : int i;
697 : 0 : struct tfp_send_msg_parms parms = { 0 };
698 : 0 : struct hwrm_tf_session_resc_flush_input req = { 0 };
699 : 0 : struct hwrm_tf_session_resc_flush_output resp = { 0 };
700 : : uint8_t fw_session_id;
701 : : struct tf_msg_dma_buf resv_buf = { 0 };
702 : : struct tf_rm_resc_entry *resv_data;
703 : : int dma_size;
704 : : struct tf_dev_info *dev;
705 : : struct tf_session *tfs;
706 : :
707 [ # # ]: 0 : TF_CHECK_PARMS2(tfp, resv);
708 : :
709 : : /* Retrieve the session information */
710 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
711 [ # # ]: 0 : if (rc) {
712 : 0 : TFP_DRV_LOG(ERR,
713 : : "%s: Failed to lookup session, rc:%s\n",
714 : : tf_dir_2_str(dir),
715 : : strerror(-rc));
716 : 0 : return rc;
717 : : }
718 : :
719 : : /* Retrieve the device information */
720 : 0 : rc = tf_session_get_device(tfs, &dev);
721 [ # # ]: 0 : if (rc) {
722 : 0 : TFP_DRV_LOG(ERR,
723 : : "%s: Failed to lookup device, rc:%s\n",
724 : : tf_dir_2_str(dir),
725 : : strerror(-rc));
726 : 0 : return rc;
727 : : }
728 : :
729 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
730 [ # # ]: 0 : if (rc) {
731 : 0 : TFP_DRV_LOG(ERR,
732 : : "%s: Unable to lookup FW id, rc:%s\n",
733 : : tf_dir_2_str(dir),
734 : : strerror(-rc));
735 : 0 : return rc;
736 : : }
737 : :
738 : : /* Prepare DMA buffers */
739 : 0 : dma_size = size * sizeof(struct tf_rm_resc_entry);
740 : : rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
741 : : if (rc)
742 : 0 : return rc;
743 : :
744 : : /* Populate the request */
745 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
746 : 0 : req.flags = tfp_cpu_to_le_16(dir);
747 : 0 : req.flush_size = size;
748 : :
749 : : resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
750 [ # # ]: 0 : for (i = 0; i < size; i++) {
751 : 0 : resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
752 : 0 : resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
753 : 0 : resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
754 : : }
755 : :
756 : 0 : req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
757 : :
758 : 0 : parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
759 : 0 : parms.req_data = (uint32_t *)&req;
760 : 0 : parms.req_size = sizeof(req);
761 : 0 : parms.resp_data = (uint32_t *)&resp;
762 : 0 : parms.resp_size = sizeof(resp);
763 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
764 : :
765 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
766 : :
767 : : tf_msg_free_dma_buf(&resv_buf);
768 : :
769 : 0 : return rc;
770 : : }
771 : :
772 : : int
773 : 0 : tf_msg_insert_em_internal_entry(struct tf *tfp,
774 : : struct tf_insert_em_entry_parms *em_parms,
775 : : uint16_t *rptr_index,
776 : : uint8_t *rptr_entry,
777 : : uint8_t *num_of_entries)
778 : : {
779 : : int rc;
780 : 0 : struct tfp_send_msg_parms parms = { 0 };
781 : 0 : struct hwrm_tf_em_insert_input req = { 0 };
782 : 0 : struct hwrm_tf_em_insert_output resp = { 0 };
783 : 0 : struct tf_em_64b_entry *em_result =
784 : : (struct tf_em_64b_entry *)em_parms->em_record;
785 : : uint16_t flags;
786 : : uint8_t fw_session_id;
787 : : uint8_t msg_key_size;
788 : : struct tf_dev_info *dev;
789 : : struct tf_session *tfs;
790 : :
791 : : RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
792 : : TF_MSG_SIZE_HWRM_TF_EM_INSERT);
793 : :
794 : : /* Retrieve the session information */
795 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
796 [ # # ]: 0 : if (rc) {
797 : 0 : TFP_DRV_LOG(ERR,
798 : : "%s: Failed to lookup session, rc:%s\n",
799 : : tf_dir_2_str(em_parms->dir),
800 : : strerror(-rc));
801 : 0 : return rc;
802 : : }
803 : :
804 : : /* Retrieve the device information */
805 : 0 : rc = tf_session_get_device(tfs, &dev);
806 [ # # ]: 0 : if (rc) {
807 : 0 : TFP_DRV_LOG(ERR,
808 : : "%s: Failed to lookup device, rc:%s\n",
809 : : tf_dir_2_str(em_parms->dir),
810 : : strerror(-rc));
811 : 0 : return rc;
812 : : }
813 : :
814 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
815 [ # # ]: 0 : if (rc) {
816 : 0 : TFP_DRV_LOG(ERR,
817 : : "%s: Unable to lookup FW id, rc:%s\n",
818 : : tf_dir_2_str(em_parms->dir),
819 : : strerror(-rc));
820 : 0 : return rc;
821 : : }
822 : :
823 : : /* Populate the request */
824 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
825 : :
826 : : /* Check for key size conformity */
827 : 0 : msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
828 [ # # ]: 0 : if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
829 : : rc = -EINVAL;
830 : 0 : TFP_DRV_LOG(ERR,
831 : : "%s: Invalid parameters for msg type, rc:%s\n",
832 : : tf_dir_2_str(em_parms->dir),
833 : : strerror(-rc));
834 : 0 : return rc;
835 : : }
836 : :
837 : 0 : tfp_memcpy(req.em_key,
838 : 0 : em_parms->key,
839 : : msg_key_size);
840 : :
841 [ # # ]: 0 : flags = (em_parms->dir == TF_DIR_TX ?
842 : : HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
843 : : HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
844 : 0 : req.flags = tfp_cpu_to_le_16(flags);
845 : 0 : req.strength = (em_result->hdr.word1 &
846 : 0 : CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
847 : : CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
848 : 0 : req.em_key_bitlen = em_parms->key_sz_in_bits;
849 : 0 : req.action_ptr = em_result->hdr.pointer;
850 : 0 : req.em_record_idx = *rptr_index;
851 : :
852 : 0 : parms.tf_type = HWRM_TF_EM_INSERT;
853 : 0 : parms.req_data = (uint32_t *)&req;
854 : 0 : parms.req_size = sizeof(req);
855 : 0 : parms.resp_data = (uint32_t *)&resp;
856 : 0 : parms.resp_size = sizeof(resp);
857 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
858 : :
859 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
860 : : &parms);
861 [ # # ]: 0 : if (rc)
862 : : return rc;
863 : :
864 : 0 : *rptr_entry = resp.rptr_entry;
865 : 0 : *rptr_index = resp.rptr_index;
866 : 0 : *num_of_entries = resp.num_of_entries;
867 : :
868 : 0 : return 0;
869 : : }
870 : :
871 : : int
872 : 0 : tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
873 : : struct tf_insert_em_entry_parms *em_parms,
874 : : uint32_t key0_hash,
875 : : uint32_t key1_hash,
876 : : uint16_t *rptr_index,
877 : : uint8_t *rptr_entry,
878 : : uint8_t *num_of_entries)
879 : : {
880 : : int rc;
881 : 0 : struct tfp_send_msg_parms parms = { 0 };
882 : 0 : struct hwrm_tf_em_hash_insert_input req = { 0 };
883 : 0 : struct hwrm_tf_em_hash_insert_output resp = { 0 };
884 : : uint16_t flags;
885 : : uint8_t fw_session_id;
886 : : uint8_t msg_record_size;
887 : : struct tf_dev_info *dev;
888 : : struct tf_session *tfs;
889 : :
890 : : /* Retrieve the session information */
891 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
892 [ # # ]: 0 : if (rc) {
893 : 0 : TFP_DRV_LOG(ERR,
894 : : "%s: Failed to lookup session, rc:%s\n",
895 : : tf_dir_2_str(em_parms->dir),
896 : : strerror(-rc));
897 : 0 : return rc;
898 : : }
899 : :
900 : : /* Retrieve the device information */
901 : 0 : rc = tf_session_get_device(tfs, &dev);
902 [ # # ]: 0 : if (rc) {
903 : 0 : TFP_DRV_LOG(ERR,
904 : : "%s: Failed to lookup device, rc:%s\n",
905 : : tf_dir_2_str(em_parms->dir),
906 : : strerror(-rc));
907 : 0 : return rc;
908 : : }
909 : :
910 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
911 [ # # ]: 0 : if (rc) {
912 : 0 : TFP_DRV_LOG(ERR,
913 : : "%s: Unable to lookup FW id, rc:%s\n",
914 : : tf_dir_2_str(em_parms->dir),
915 : : strerror(-rc));
916 : 0 : return rc;
917 : : }
918 : :
919 : : /* Populate the request */
920 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
921 : :
922 : : /* Check for key size conformity */
923 : 0 : msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
924 : :
925 [ # # ]: 0 : if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
926 : : rc = -EINVAL;
927 : 0 : TFP_DRV_LOG(ERR,
928 : : "%s: Record size to large, rc:%s\n",
929 : : tf_dir_2_str(em_parms->dir),
930 : : strerror(-rc));
931 : 0 : return rc;
932 : : }
933 : :
934 : 0 : tfp_memcpy((char *)req.em_record,
935 : 0 : em_parms->em_record,
936 : : msg_record_size);
937 : :
938 [ # # ]: 0 : flags = (em_parms->dir == TF_DIR_TX ?
939 : : HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
940 : : HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
941 : 0 : req.flags = tfp_cpu_to_le_16(flags);
942 : 0 : req.em_record_size_bits = em_parms->em_record_sz_in_bits;
943 : 0 : req.em_record_idx = *rptr_index;
944 : 0 : req.key0_hash = key0_hash;
945 : 0 : req.key1_hash = key1_hash;
946 : :
947 : 0 : parms.tf_type = HWRM_TF_EM_HASH_INSERT;
948 : 0 : parms.req_data = (uint32_t *)&req;
949 : 0 : parms.req_size = sizeof(req);
950 : 0 : parms.resp_data = (uint32_t *)&resp;
951 : 0 : parms.resp_size = sizeof(resp);
952 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
953 : :
954 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
955 : : &parms);
956 [ # # ]: 0 : if (rc)
957 : : return rc;
958 : :
959 : 0 : *rptr_entry = resp.rptr_entry;
960 : 0 : *rptr_index = resp.rptr_index;
961 : 0 : *num_of_entries = resp.num_of_entries;
962 : :
963 : 0 : return 0;
964 : : }
965 : :
966 : : int
967 : 0 : tf_msg_delete_em_entry(struct tf *tfp,
968 : : struct tf_delete_em_entry_parms *em_parms)
969 : : {
970 : : int rc;
971 : 0 : struct tfp_send_msg_parms parms = { 0 };
972 : 0 : struct hwrm_tf_em_delete_input req = { 0 };
973 : 0 : struct hwrm_tf_em_delete_output resp = { 0 };
974 : : uint16_t flags;
975 : : uint8_t fw_session_id;
976 : : struct tf_dev_info *dev;
977 : : struct tf_session *tfs;
978 : :
979 : : /* Retrieve the session information */
980 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
981 [ # # ]: 0 : if (rc) {
982 : 0 : TFP_DRV_LOG(ERR,
983 : : "%s: Failed to lookup session, rc:%s\n",
984 : : tf_dir_2_str(em_parms->dir),
985 : : strerror(-rc));
986 : 0 : return rc;
987 : : }
988 : :
989 : : /* Retrieve the device information */
990 : 0 : rc = tf_session_get_device(tfs, &dev);
991 [ # # ]: 0 : if (rc) {
992 : 0 : TFP_DRV_LOG(ERR,
993 : : "%s: Failed to lookup device, rc:%s\n",
994 : : tf_dir_2_str(em_parms->dir),
995 : : strerror(-rc));
996 : 0 : return rc;
997 : : }
998 : :
999 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1000 [ # # ]: 0 : if (rc) {
1001 : 0 : TFP_DRV_LOG(ERR,
1002 : : "%s: Unable to lookup FW id, rc:%s\n",
1003 : : tf_dir_2_str(em_parms->dir),
1004 : : strerror(-rc));
1005 : 0 : return rc;
1006 : : }
1007 : :
1008 : : /* Populate the request */
1009 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1010 : :
1011 [ # # ]: 0 : flags = (em_parms->dir == TF_DIR_TX ?
1012 : : HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
1013 : : HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
1014 : 0 : req.flags = tfp_cpu_to_le_16(flags);
1015 : 0 : req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
1016 : :
1017 : 0 : parms.tf_type = HWRM_TF_EM_DELETE;
1018 : 0 : parms.req_data = (uint32_t *)&req;
1019 : 0 : parms.req_size = sizeof(req);
1020 : 0 : parms.resp_data = (uint32_t *)&resp;
1021 : 0 : parms.resp_size = sizeof(resp);
1022 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1023 : :
1024 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1025 : : &parms);
1026 [ # # ]: 0 : if (rc)
1027 : : return rc;
1028 : :
1029 : 0 : em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1030 : :
1031 : 0 : return 0;
1032 : : }
1033 : :
1034 : : int
1035 : 0 : tf_msg_move_em_entry(struct tf *tfp,
1036 : : struct tf_move_em_entry_parms *em_parms)
1037 : : {
1038 : : int rc;
1039 : 0 : struct tfp_send_msg_parms parms = { 0 };
1040 : 0 : struct hwrm_tf_em_move_input req = { 0 };
1041 : 0 : struct hwrm_tf_em_move_output resp = { 0 };
1042 : : uint16_t flags;
1043 : : uint8_t fw_session_id;
1044 : : struct tf_dev_info *dev;
1045 : : struct tf_session *tfs;
1046 : :
1047 : : /* Retrieve the session information */
1048 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1049 [ # # ]: 0 : if (rc) {
1050 : 0 : TFP_DRV_LOG(ERR,
1051 : : "%s: Failed to lookup session, rc:%s\n",
1052 : : tf_dir_2_str(em_parms->dir),
1053 : : strerror(-rc));
1054 : 0 : return rc;
1055 : : }
1056 : :
1057 : : /* Retrieve the device information */
1058 : 0 : rc = tf_session_get_device(tfs, &dev);
1059 [ # # ]: 0 : if (rc) {
1060 : 0 : TFP_DRV_LOG(ERR,
1061 : : "%s: Failed to lookup device, rc:%s\n",
1062 : : tf_dir_2_str(em_parms->dir),
1063 : : strerror(-rc));
1064 : 0 : return rc;
1065 : : }
1066 : :
1067 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1068 [ # # ]: 0 : if (rc) {
1069 : 0 : TFP_DRV_LOG(ERR,
1070 : : "%s: Unable to lookup FW id, rc:%s\n",
1071 : : tf_dir_2_str(em_parms->dir),
1072 : : strerror(-rc));
1073 : 0 : return rc;
1074 : : }
1075 : :
1076 : : /* Populate the request */
1077 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1078 : :
1079 [ # # ]: 0 : flags = (em_parms->dir == TF_DIR_TX ?
1080 : : HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
1081 : : HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
1082 : 0 : req.flags = tfp_cpu_to_le_16(flags);
1083 : 0 : req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
1084 : 0 : req.new_index = tfp_cpu_to_le_32(em_parms->new_index);
1085 : :
1086 : 0 : parms.tf_type = HWRM_TF_EM_MOVE;
1087 : 0 : parms.req_data = (uint32_t *)&req;
1088 : 0 : parms.req_size = sizeof(req);
1089 : 0 : parms.resp_data = (uint32_t *)&resp;
1090 : 0 : parms.resp_size = sizeof(resp);
1091 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1092 : :
1093 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1094 : : &parms);
1095 [ # # ]: 0 : if (rc)
1096 : : return rc;
1097 : :
1098 : 0 : em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1099 : :
1100 : 0 : return 0;
1101 : : }
1102 : :
1103 : 0 : int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
1104 : : struct hcapi_cfa_em_table *tbl,
1105 : : uint64_t *dma_addr,
1106 : : uint32_t *page_lvl,
1107 : : uint32_t *page_size)
1108 : : {
1109 : 0 : struct tfp_send_msg_parms parms = { 0 };
1110 : 0 : struct hwrm_tf_ctxt_mem_alloc_input req = {0};
1111 : 0 : struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
1112 : : uint32_t mem_size_k;
1113 : : int rc = 0;
1114 : : struct tf_dev_info *dev;
1115 : : struct tf_session *tfs;
1116 : : uint32_t fw_se_id;
1117 : :
1118 : : /* Retrieve the session information */
1119 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1120 [ # # ]: 0 : if (rc) {
1121 : 0 : TFP_DRV_LOG(ERR,
1122 : : "Failed to lookup session, rc:%s\n",
1123 : : strerror(-rc));
1124 : 0 : return rc;
1125 : : }
1126 : :
1127 : : /* Retrieve the device information */
1128 : 0 : rc = tf_session_get_device(tfs, &dev);
1129 [ # # ]: 0 : if (rc) {
1130 : 0 : TFP_DRV_LOG(ERR,
1131 : : "Failed to lookup device, rc:%s\n",
1132 : : strerror(-rc));
1133 : 0 : return rc;
1134 : : }
1135 : : /* Retrieve the session information */
1136 : 0 : fw_se_id = tfs->session_id.internal.fw_session_id;
1137 : :
1138 [ # # # # ]: 0 : if (tbl->num_entries && tbl->entry_size) {
1139 : : /* unit: kbytes */
1140 : 0 : mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
1141 : 0 : req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1142 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1143 : 0 : parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
1144 : 0 : parms.req_data = (uint32_t *)&req;
1145 : 0 : parms.req_size = sizeof(req);
1146 : 0 : parms.resp_data = (uint32_t *)&resp;
1147 : 0 : parms.resp_size = sizeof(resp);
1148 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1149 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1150 [ # # ]: 0 : if (rc) {
1151 : 0 : TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
1152 : : strerror(-rc));
1153 : 0 : return rc;
1154 : : }
1155 : :
1156 : 0 : *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
1157 : 0 : *page_lvl = resp.page_level;
1158 : 0 : *page_size = resp.page_size;
1159 : : }
1160 : :
1161 : : return rc;
1162 : : }
1163 : :
1164 : 0 : int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
1165 : : uint32_t mem_size_k,
1166 : : uint64_t dma_addr,
1167 : : uint8_t page_level,
1168 : : uint8_t page_size)
1169 : : {
1170 : 0 : struct tfp_send_msg_parms parms = { 0 };
1171 : 0 : struct hwrm_tf_ctxt_mem_free_input req = {0};
1172 : 0 : struct hwrm_tf_ctxt_mem_free_output resp = {0};
1173 : : int rc = 0;
1174 : : struct tf_dev_info *dev;
1175 : : struct tf_session *tfs;
1176 : : uint32_t fw_se_id;
1177 : :
1178 : : /* Retrieve the session information */
1179 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1180 [ # # ]: 0 : if (rc) {
1181 : 0 : TFP_DRV_LOG(ERR,
1182 : : "Failed to lookup session, rc:%s\n",
1183 : : strerror(-rc));
1184 : 0 : return rc;
1185 : : }
1186 : :
1187 : : /* Retrieve the device information */
1188 : 0 : rc = tf_session_get_device(tfs, &dev);
1189 [ # # ]: 0 : if (rc) {
1190 : 0 : TFP_DRV_LOG(ERR,
1191 : : "Failed to lookup device, rc:%s\n",
1192 : : strerror(-rc));
1193 : 0 : return rc;
1194 : : }
1195 : : /* Retrieve the session information */
1196 : 0 : fw_se_id = tfs->session_id.internal.fw_session_id;
1197 : :
1198 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1199 : 0 : req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1200 : 0 : req.page_dir = tfp_cpu_to_le_64(dma_addr);
1201 : 0 : req.page_level = page_level;
1202 : 0 : req.page_size = page_size;
1203 : 0 : parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
1204 : 0 : parms.req_data = (uint32_t *)&req;
1205 : 0 : parms.req_size = sizeof(req);
1206 : 0 : parms.resp_data = (uint32_t *)&resp;
1207 : 0 : parms.resp_size = sizeof(resp);
1208 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1209 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1210 : :
1211 : 0 : return rc;
1212 : : }
1213 : :
1214 : : int
1215 : 0 : tf_msg_em_mem_rgtr(struct tf *tfp,
1216 : : int page_lvl,
1217 : : int page_size,
1218 : : uint64_t dma_addr,
1219 : : uint16_t *ctx_id)
1220 : : {
1221 : : int rc;
1222 : 0 : struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
1223 : 0 : struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
1224 : 0 : struct tfp_send_msg_parms parms = { 0 };
1225 : : struct tf_dev_info *dev;
1226 : : struct tf_session *tfs;
1227 : : uint32_t fw_se_id;
1228 : :
1229 : : /* Retrieve the session information */
1230 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1231 [ # # ]: 0 : if (rc) {
1232 : 0 : TFP_DRV_LOG(ERR,
1233 : : "Failed to lookup session, rc:%s\n",
1234 : : strerror(-rc));
1235 : 0 : return rc;
1236 : : }
1237 : :
1238 : : /* Retrieve the device information */
1239 : 0 : rc = tf_session_get_device(tfs, &dev);
1240 [ # # ]: 0 : if (rc) {
1241 : 0 : TFP_DRV_LOG(ERR,
1242 : : "Failed to lookup device, rc:%s\n",
1243 : : strerror(-rc));
1244 : 0 : return rc;
1245 : : }
1246 : 0 : fw_se_id = tfs->session_id.internal.fw_session_id;
1247 : :
1248 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1249 : 0 : req.page_level = page_lvl;
1250 : 0 : req.page_size = page_size;
1251 : 0 : req.page_dir = tfp_cpu_to_le_64(dma_addr);
1252 : :
1253 : 0 : parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
1254 : 0 : parms.req_data = (uint32_t *)&req;
1255 : 0 : parms.req_size = sizeof(req);
1256 : 0 : parms.resp_data = (uint32_t *)&resp;
1257 : 0 : parms.resp_size = sizeof(resp);
1258 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1259 : :
1260 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1261 : : &parms);
1262 [ # # ]: 0 : if (rc)
1263 : : return rc;
1264 : :
1265 : 0 : *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
1266 : :
1267 : 0 : return rc;
1268 : : }
1269 : :
1270 : : int
1271 : 0 : tf_msg_em_mem_unrgtr(struct tf *tfp,
1272 : : uint16_t *ctx_id)
1273 : : {
1274 : : int rc;
1275 : 0 : struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
1276 : 0 : struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
1277 : 0 : struct tfp_send_msg_parms parms = { 0 };
1278 : : struct tf_dev_info *dev;
1279 : : struct tf_session *tfs;
1280 : : uint32_t fw_se_id;
1281 : :
1282 : : /* Retrieve the session information */
1283 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1284 [ # # ]: 0 : if (rc) {
1285 : 0 : TFP_DRV_LOG(ERR,
1286 : : "Failed to lookup session, rc:%s\n",
1287 : : strerror(-rc));
1288 : 0 : return rc;
1289 : : }
1290 : :
1291 : : /* Retrieve the device information */
1292 : 0 : rc = tf_session_get_device(tfs, &dev);
1293 [ # # ]: 0 : if (rc) {
1294 : 0 : TFP_DRV_LOG(ERR,
1295 : : "Failed to lookup device, rc:%s\n",
1296 : : strerror(-rc));
1297 : 0 : return rc;
1298 : : }
1299 : :
1300 : 0 : fw_se_id = tfs->session_id.internal.fw_session_id;
1301 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1302 : :
1303 : 0 : req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
1304 : :
1305 : 0 : parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
1306 : 0 : parms.req_data = (uint32_t *)&req;
1307 : 0 : parms.req_size = sizeof(req);
1308 : 0 : parms.resp_data = (uint32_t *)&resp;
1309 : 0 : parms.resp_size = sizeof(resp);
1310 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1311 : :
1312 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1313 : : &parms);
1314 : 0 : return rc;
1315 : : }
1316 : :
1317 : : int
1318 : 0 : tf_msg_em_qcaps(struct tf *tfp,
1319 : : int dir,
1320 : : struct tf_em_caps *em_caps)
1321 : : {
1322 : : int rc;
1323 : 0 : struct hwrm_tf_ext_em_qcaps_input req = {0};
1324 : 0 : struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
1325 : : uint32_t flags;
1326 : 0 : struct tfp_send_msg_parms parms = { 0 };
1327 : : struct tf_dev_info *dev;
1328 : : struct tf_session *tfs;
1329 : : uint32_t fw_se_id;
1330 : :
1331 : : /* Retrieve the session information */
1332 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1333 [ # # ]: 0 : if (rc) {
1334 : 0 : TFP_DRV_LOG(ERR,
1335 : : "%s: Failed to lookup session, rc:%s\n",
1336 : : tf_dir_2_str(dir),
1337 : : strerror(-rc));
1338 : 0 : return rc;
1339 : : }
1340 : 0 : fw_se_id = tfs->session_id.internal.fw_session_id;
1341 : :
1342 : : /* Retrieve the device information */
1343 : 0 : rc = tf_session_get_device(tfs, &dev);
1344 [ # # ]: 0 : if (rc) {
1345 : 0 : TFP_DRV_LOG(ERR,
1346 : : "%s: Failed to lookup device, rc:%s\n",
1347 : : tf_dir_2_str(dir),
1348 : : strerror(-rc));
1349 : 0 : return rc;
1350 : : }
1351 : :
1352 [ # # ]: 0 : flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
1353 : : HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
1354 : 0 : req.flags = tfp_cpu_to_le_32(flags);
1355 : :
1356 : 0 : parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
1357 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1358 : 0 : parms.req_data = (uint32_t *)&req;
1359 : 0 : parms.req_size = sizeof(req);
1360 : 0 : parms.resp_data = (uint32_t *)&resp;
1361 : 0 : parms.resp_size = sizeof(resp);
1362 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1363 : :
1364 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1365 : : &parms);
1366 [ # # ]: 0 : if (rc)
1367 : : return rc;
1368 : :
1369 : 0 : em_caps->supported = tfp_le_to_cpu_32(resp.supported);
1370 : 0 : em_caps->max_entries_supported =
1371 : 0 : tfp_le_to_cpu_32(resp.max_entries_supported);
1372 : 0 : em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
1373 : 0 : em_caps->record_entry_size =
1374 : 0 : tfp_le_to_cpu_16(resp.record_entry_size);
1375 : 0 : em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
1376 : :
1377 : 0 : return rc;
1378 : : }
1379 : :
1380 : : int
1381 : 0 : tf_msg_em_cfg(struct tf *tfp,
1382 : : uint32_t num_entries,
1383 : : uint16_t key0_ctx_id,
1384 : : uint16_t key1_ctx_id,
1385 : : uint16_t record_ctx_id,
1386 : : uint16_t efc_ctx_id,
1387 : : uint8_t flush_interval,
1388 : : int dir)
1389 : : {
1390 : : int rc;
1391 : 0 : struct hwrm_tf_ext_em_cfg_input req = {0};
1392 : 0 : struct hwrm_tf_ext_em_cfg_output resp = {0};
1393 : : uint32_t flags;
1394 : 0 : struct tfp_send_msg_parms parms = { 0 };
1395 : : struct tf_dev_info *dev;
1396 : : struct tf_session *tfs;
1397 : :
1398 : : /* Retrieve the session information */
1399 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1400 [ # # ]: 0 : if (rc) {
1401 : 0 : TFP_DRV_LOG(ERR,
1402 : : "%s: Failed to lookup session, rc:%s\n",
1403 : : tf_dir_2_str(dir),
1404 : : strerror(-rc));
1405 : 0 : return rc;
1406 : : }
1407 : :
1408 : : /* Retrieve the device information */
1409 : 0 : rc = tf_session_get_device(tfs, &dev);
1410 [ # # ]: 0 : if (rc) {
1411 : 0 : TFP_DRV_LOG(ERR,
1412 : : "%s: Failed to lookup device, rc:%s\n",
1413 : : tf_dir_2_str(dir),
1414 : : strerror(-rc));
1415 : 0 : return rc;
1416 : : }
1417 : :
1418 [ # # ]: 0 : flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1419 : : HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1420 : 0 : flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1421 : :
1422 : 0 : req.flags = tfp_cpu_to_le_32(flags);
1423 : 0 : req.num_entries = tfp_cpu_to_le_32(num_entries);
1424 : :
1425 : 0 : req.flush_interval = flush_interval;
1426 : :
1427 : 0 : req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
1428 : 0 : req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
1429 : 0 : req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
1430 : 0 : req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
1431 : :
1432 : 0 : parms.tf_type = HWRM_TF_EXT_EM_CFG;
1433 : 0 : parms.req_data = (uint32_t *)&req;
1434 : 0 : parms.req_size = sizeof(req);
1435 : 0 : parms.resp_data = (uint32_t *)&resp;
1436 : 0 : parms.resp_size = sizeof(resp);
1437 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1438 : :
1439 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1440 : : &parms);
1441 : 0 : return rc;
1442 : : }
1443 : :
1444 : : int
1445 : 0 : tf_msg_ext_em_cfg(struct tf *tfp,
1446 : : struct tf_tbl_scope_cb *tbl_scope_cb,
1447 : : uint32_t st_buckets,
1448 : : uint8_t flush_interval,
1449 : : enum tf_dir dir)
1450 : : {
1451 : : struct hcapi_cfa_em_ctx_mem_info *ctxp = &tbl_scope_cb->em_ctx_info[dir];
1452 : : struct hcapi_cfa_em_table *lkup_tbl, *act_tbl;
1453 : 0 : struct hwrm_tf_ext_em_cfg_input req = {0};
1454 : 0 : struct hwrm_tf_ext_em_cfg_output resp = {0};
1455 : 0 : struct tfp_send_msg_parms parms = { 0 };
1456 : : uint32_t flags;
1457 : : struct tf_dev_info *dev;
1458 : : struct tf_session *tfs;
1459 : : uint32_t fw_se_id;
1460 : : int rc;
1461 : :
1462 : : /* Retrieve the session information */
1463 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1464 [ # # ]: 0 : if (rc) {
1465 : 0 : TFP_DRV_LOG(ERR,
1466 : : "%s: Failed to lookup session, rc:%s\n",
1467 : : tf_dir_2_str(dir),
1468 : : strerror(-rc));
1469 : 0 : return rc;
1470 : : }
1471 : :
1472 : : /* Retrieve the device information */
1473 : 0 : rc = tf_session_get_device(tfs, &dev);
1474 [ # # ]: 0 : if (rc) {
1475 : 0 : TFP_DRV_LOG(ERR,
1476 : : "%s: Failed to lookup device, rc:%s\n",
1477 : : tf_dir_2_str(dir),
1478 : : strerror(-rc));
1479 : 0 : return rc;
1480 : : }
1481 : 0 : fw_se_id = tfs->session_id.internal.fw_session_id;
1482 : :
1483 : : lkup_tbl = &ctxp->em_tables[TF_EM_LKUP_TABLE];
1484 : : act_tbl = &ctxp->em_tables[TF_ACTION_TABLE];
1485 [ # # ]: 0 : flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1486 : : HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1487 : 0 : flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1488 : :
1489 : 0 : req.flags = tfp_cpu_to_le_32(flags);
1490 : 0 : req.num_entries = tfp_cpu_to_le_32(act_tbl->num_entries);
1491 : 0 : req.lkup_static_buckets = tfp_cpu_to_le_32(st_buckets);
1492 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1493 : 0 : req.flush_interval = flush_interval;
1494 : 0 : req.action_ctx_id = tfp_cpu_to_le_16(act_tbl->ctx_id);
1495 : 0 : req.action_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1496 : 0 : req.lkup_ctx_id = tfp_cpu_to_le_16(lkup_tbl->ctx_id);
1497 : 0 : req.lkup_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1498 : :
1499 : 0 : req.enables = (HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_CTX_ID |
1500 : : HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_TBL_SCOPE |
1501 : : HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_CTX_ID |
1502 : : HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_TBL_SCOPE |
1503 : : HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_STATIC_BUCKETS |
1504 : : HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_NUM_ENTRIES);
1505 : :
1506 : 0 : parms.tf_type = HWRM_TF_EXT_EM_CFG;
1507 : 0 : parms.req_data = (uint32_t *)&req;
1508 : 0 : parms.req_size = sizeof(req);
1509 : 0 : parms.resp_data = (uint32_t *)&resp;
1510 : 0 : parms.resp_size = sizeof(resp);
1511 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1512 : :
1513 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1514 : : &parms);
1515 : 0 : return rc;
1516 : : }
1517 : :
1518 : : int
1519 : 0 : tf_msg_em_op(struct tf *tfp,
1520 : : int dir,
1521 : : uint16_t op)
1522 : : {
1523 : : int rc;
1524 : 0 : struct hwrm_tf_ext_em_op_input req = {0};
1525 : 0 : struct hwrm_tf_ext_em_op_output resp = {0};
1526 : : uint32_t flags;
1527 : 0 : struct tfp_send_msg_parms parms = { 0 };
1528 : : struct tf_dev_info *dev;
1529 : : struct tf_session *tfs;
1530 : :
1531 : : /* Retrieve the session information */
1532 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1533 [ # # ]: 0 : if (rc) {
1534 : 0 : TFP_DRV_LOG(ERR,
1535 : : "%s: Failed to lookup session, rc:%s\n",
1536 : : tf_dir_2_str(dir),
1537 : : strerror(-rc));
1538 : 0 : return rc;
1539 : : }
1540 : :
1541 : : /* Retrieve the device information */
1542 : 0 : rc = tf_session_get_device(tfs, &dev);
1543 [ # # ]: 0 : if (rc) {
1544 : 0 : TFP_DRV_LOG(ERR,
1545 : : "%s: Failed to lookup device, rc:%s\n",
1546 : : tf_dir_2_str(dir),
1547 : : strerror(-rc));
1548 : 0 : return rc;
1549 : : }
1550 : :
1551 [ # # ]: 0 : flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1552 : : HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1553 : 0 : req.flags = tfp_cpu_to_le_32(flags);
1554 : 0 : req.op = tfp_cpu_to_le_16(op);
1555 : :
1556 : 0 : parms.tf_type = HWRM_TF_EXT_EM_OP;
1557 : 0 : parms.req_data = (uint32_t *)&req;
1558 : 0 : parms.req_size = sizeof(req);
1559 : 0 : parms.resp_data = (uint32_t *)&resp;
1560 : 0 : parms.resp_size = sizeof(resp);
1561 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1562 : :
1563 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1564 : : &parms);
1565 : 0 : return rc;
1566 : : }
1567 : :
1568 : : int
1569 : 0 : tf_msg_tcam_entry_set(struct tf *tfp,
1570 : : struct tf_dev_info *dev,
1571 : : struct tf_tcam_set_parms *parms)
1572 : : {
1573 : : int rc;
1574 : 0 : struct tfp_send_msg_parms mparms = { 0 };
1575 : 0 : struct hwrm_tf_tcam_set_input req = { 0 };
1576 : 0 : struct hwrm_tf_tcam_set_output resp = { 0 };
1577 : 0 : struct tf_msg_dma_buf buf = { 0 };
1578 : : uint8_t *data = NULL;
1579 : : int data_size = 0;
1580 : : uint8_t fw_session_id;
1581 : : struct tf_session *tfs;
1582 : :
1583 : : /* Retrieve the session information */
1584 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1585 [ # # ]: 0 : if (rc) {
1586 : 0 : TFP_DRV_LOG(ERR,
1587 : : "Failed to lookup session, rc:%s\n",
1588 : : strerror(-rc));
1589 : 0 : return rc;
1590 : : }
1591 : :
1592 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1593 [ # # ]: 0 : if (rc) {
1594 : 0 : TFP_DRV_LOG(ERR,
1595 : : "%s: Unable to lookup FW id, rc:%s\n",
1596 : : tf_dir_2_str(parms->dir),
1597 : : strerror(-rc));
1598 : 0 : return rc;
1599 : : }
1600 : :
1601 : : /* Populate the request */
1602 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1603 : 0 : req.type = parms->hcapi_type;
1604 : 0 : req.idx = tfp_cpu_to_le_16(parms->idx);
1605 [ # # ]: 0 : if (parms->dir == TF_DIR_TX)
1606 : 0 : req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1607 : :
1608 : 0 : req.key_size = parms->key_size;
1609 : 0 : req.mask_offset = parms->key_size;
1610 : : /* Result follows after key and mask, thus multiply by 2 */
1611 : 0 : req.result_offset = 2 * parms->key_size;
1612 : 0 : req.result_size = parms->result_size;
1613 : 0 : data_size = 2 * req.key_size + req.result_size;
1614 : :
1615 [ # # ]: 0 : if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1616 : : /* use pci buffer */
1617 : : data = &req.dev_data[0];
1618 : : } else {
1619 : : /* use dma buffer */
1620 : 0 : req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1621 : : rc = tf_msg_alloc_dma_buf(&buf, data_size);
1622 : : if (rc)
1623 : 0 : goto cleanup;
1624 : : data = buf.va_addr;
1625 : 0 : tfp_memcpy(&req.dev_data[0],
1626 : : &buf.pa_addr,
1627 : : sizeof(buf.pa_addr));
1628 : : }
1629 : :
1630 : 0 : tfp_memcpy(&data[0], parms->key, parms->key_size);
1631 : 0 : tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1632 : 0 : tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1633 : :
1634 : 0 : mparms.tf_type = HWRM_TF_TCAM_SET;
1635 : 0 : mparms.req_data = (uint32_t *)&req;
1636 : 0 : mparms.req_size = sizeof(req);
1637 : 0 : mparms.resp_data = (uint32_t *)&resp;
1638 : 0 : mparms.resp_size = sizeof(resp);
1639 : 0 : mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1640 : :
1641 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1642 : : &mparms);
1643 : :
1644 : 0 : cleanup:
1645 : : tf_msg_free_dma_buf(&buf);
1646 : :
1647 : 0 : return rc;
1648 : : }
1649 : :
1650 : : int
1651 : 0 : tf_msg_tcam_entry_get(struct tf *tfp,
1652 : : struct tf_dev_info *dev,
1653 : : struct tf_tcam_get_parms *parms)
1654 : : {
1655 : : int rc;
1656 : 0 : struct tfp_send_msg_parms mparms = { 0 };
1657 : 0 : struct hwrm_tf_tcam_get_input req = { 0 };
1658 : 0 : struct hwrm_tf_tcam_get_output resp = { 0 };
1659 : : uint8_t fw_session_id;
1660 : : struct tf_session *tfs;
1661 : :
1662 : : /* Retrieve the session information */
1663 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1664 [ # # ]: 0 : if (rc) {
1665 : 0 : TFP_DRV_LOG(ERR,
1666 : : "Failed to lookup session, rc:%s\n",
1667 : : strerror(-rc));
1668 : 0 : return rc;
1669 : : }
1670 : :
1671 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1672 [ # # ]: 0 : if (rc) {
1673 : 0 : TFP_DRV_LOG(ERR,
1674 : : "%s: Unable to lookup FW id, rc:%s\n",
1675 : : tf_dir_2_str(parms->dir),
1676 : : strerror(-rc));
1677 : 0 : return rc;
1678 : : }
1679 : :
1680 : : /* Populate the request */
1681 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1682 : 0 : req.type = parms->hcapi_type;
1683 : 0 : req.idx = tfp_cpu_to_le_16(parms->idx);
1684 [ # # ]: 0 : if (parms->dir == TF_DIR_TX)
1685 : 0 : req.flags |= HWRM_TF_TCAM_GET_INPUT_FLAGS_DIR_TX;
1686 : :
1687 : 0 : mparms.tf_type = HWRM_TF_TCAM_GET;
1688 : 0 : mparms.req_data = (uint32_t *)&req;
1689 : 0 : mparms.req_size = sizeof(req);
1690 : 0 : mparms.resp_data = (uint32_t *)&resp;
1691 : 0 : mparms.resp_size = sizeof(resp);
1692 : 0 : mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1693 : :
1694 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1695 : : &mparms);
1696 : :
1697 [ # # ]: 0 : if (rc != 0)
1698 : : return rc;
1699 : :
1700 [ # # ]: 0 : if (parms->key_size < resp.key_size ||
1701 [ # # ]: 0 : parms->result_size < resp.result_size) {
1702 : : rc = -EINVAL;
1703 : 0 : TFP_DRV_LOG(ERR,
1704 : : "%s: Key buffer(%d) is smaller than the key(%d), rc:%s\n",
1705 : : tf_dir_2_str(parms->dir),
1706 : : parms->key_size,
1707 : : resp.key_size,
1708 : : strerror(-rc));
1709 : 0 : return rc;
1710 : : }
1711 : 0 : parms->key_size = resp.key_size;
1712 : 0 : parms->result_size = resp.result_size;
1713 : 0 : tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
1714 : 0 : tfp_memcpy(parms->mask, &resp.dev_data[resp.key_size], resp.key_size);
1715 : 0 : tfp_memcpy(parms->result, &resp.dev_data[resp.result_offset], resp.result_size);
1716 : :
1717 : 0 : return 0;
1718 : : }
1719 : :
1720 : : int
1721 : 0 : tf_msg_tcam_entry_free(struct tf *tfp,
1722 : : struct tf_dev_info *dev,
1723 : : struct tf_tcam_free_parms *in_parms)
1724 : : {
1725 : : int rc;
1726 : 0 : struct hwrm_tf_tcam_free_input req = { 0 };
1727 : 0 : struct hwrm_tf_tcam_free_output resp = { 0 };
1728 : 0 : struct tfp_send_msg_parms parms = { 0 };
1729 : : uint8_t fw_session_id;
1730 : : struct tf_session *tfs;
1731 : :
1732 : : /* Retrieve the session information */
1733 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1734 [ # # ]: 0 : if (rc) {
1735 : 0 : TFP_DRV_LOG(ERR,
1736 : : "Failed to lookup session, rc:%s\n",
1737 : : strerror(-rc));
1738 : 0 : return rc;
1739 : : }
1740 : :
1741 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1742 [ # # ]: 0 : if (rc) {
1743 : 0 : TFP_DRV_LOG(ERR,
1744 : : "%s: Unable to lookup FW id, rc:%s\n",
1745 : : tf_dir_2_str(in_parms->dir),
1746 : : strerror(-rc));
1747 : 0 : return rc;
1748 : : }
1749 : :
1750 : : /* Populate the request */
1751 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1752 : 0 : req.type = in_parms->hcapi_type;
1753 : 0 : req.count = 1;
1754 : 0 : req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1755 [ # # ]: 0 : if (in_parms->dir == TF_DIR_TX)
1756 : 0 : req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1757 : :
1758 : 0 : parms.tf_type = HWRM_TF_TCAM_FREE;
1759 : 0 : parms.req_data = (uint32_t *)&req;
1760 : 0 : parms.req_size = sizeof(req);
1761 : 0 : parms.resp_data = (uint32_t *)&resp;
1762 : 0 : parms.resp_size = sizeof(resp);
1763 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1764 : :
1765 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1766 : : &parms);
1767 : 0 : return rc;
1768 : : }
1769 : :
1770 : : int
1771 : 0 : tf_msg_set_tbl_entry(struct tf *tfp,
1772 : : enum tf_dir dir,
1773 : : uint16_t hcapi_type,
1774 : : uint16_t size,
1775 : : uint8_t *data,
1776 : : uint32_t index)
1777 : : {
1778 : : int rc;
1779 : 0 : struct hwrm_tf_tbl_type_set_input req = { 0 };
1780 : 0 : struct hwrm_tf_tbl_type_set_output resp = { 0 };
1781 : 0 : struct tfp_send_msg_parms parms = { 0 };
1782 : 0 : struct tf_msg_dma_buf buf = { 0 };
1783 : : uint8_t fw_session_id;
1784 : : struct tf_dev_info *dev;
1785 : : struct tf_session *tfs;
1786 : :
1787 : : RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_tbl_type_set_input) !=
1788 : : TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET);
1789 : :
1790 : : /* Retrieve the session information */
1791 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1792 [ # # ]: 0 : if (rc) {
1793 : 0 : TFP_DRV_LOG(ERR,
1794 : : "%s: Failed to lookup session, rc:%s\n",
1795 : : tf_dir_2_str(dir),
1796 : : strerror(-rc));
1797 : 0 : return rc;
1798 : : }
1799 : :
1800 : : /* Retrieve the device information */
1801 : 0 : rc = tf_session_get_device(tfs, &dev);
1802 [ # # ]: 0 : if (rc) {
1803 : 0 : TFP_DRV_LOG(ERR,
1804 : : "%s: Failed to lookup device, rc:%s\n",
1805 : : tf_dir_2_str(dir),
1806 : : strerror(-rc));
1807 : 0 : return rc;
1808 : : }
1809 : :
1810 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1811 [ # # ]: 0 : if (rc) {
1812 : 0 : TFP_DRV_LOG(ERR,
1813 : : "%s: Unable to lookup FW id, rc:%s\n",
1814 : : tf_dir_2_str(dir),
1815 : : strerror(-rc));
1816 : 0 : return rc;
1817 : : }
1818 : :
1819 : : /* Populate the request */
1820 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1821 : 0 : req.flags = tfp_cpu_to_le_16(dir);
1822 : 0 : req.type = tfp_cpu_to_le_32(hcapi_type);
1823 : 0 : req.size = tfp_cpu_to_le_16(size);
1824 : 0 : req.index = tfp_cpu_to_le_32(index);
1825 : :
1826 : : /* Check for data size conformity */
1827 [ # # ]: 0 : if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1828 : : /* use dma buffer */
1829 : 0 : req.flags |= HWRM_TF_TBL_TYPE_SET_INPUT_FLAGS_DMA;
1830 : : rc = tf_msg_alloc_dma_buf(&buf, size);
1831 : : if (rc)
1832 : 0 : goto cleanup;
1833 : 0 : tfp_memcpy(buf.va_addr, data, size);
1834 : 0 : tfp_memcpy(&req.data[0],
1835 : : &buf.pa_addr,
1836 : : sizeof(buf.pa_addr));
1837 : : } else {
1838 : 0 : tfp_memcpy(&req.data, data, size);
1839 : : }
1840 : :
1841 : 0 : parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1842 : 0 : parms.req_data = (uint32_t *)&req;
1843 : 0 : parms.req_size = sizeof(req);
1844 : 0 : parms.resp_data = (uint32_t *)&resp;
1845 : 0 : parms.resp_size = sizeof(resp);
1846 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1847 : :
1848 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1849 : : &parms);
1850 : 0 : cleanup:
1851 : : tf_msg_free_dma_buf(&buf);
1852 : :
1853 : 0 : return rc;
1854 : : }
1855 : :
1856 : : int
1857 : 0 : tf_msg_get_tbl_entry(struct tf *tfp,
1858 : : enum tf_dir dir,
1859 : : uint16_t hcapi_type,
1860 : : uint16_t size,
1861 : : uint8_t *data,
1862 : : uint32_t index,
1863 : : bool clear_on_read)
1864 : : {
1865 : : int rc;
1866 : 0 : struct hwrm_tf_tbl_type_get_input req = { 0 };
1867 : 0 : struct hwrm_tf_tbl_type_get_output resp = { 0 };
1868 : 0 : struct tfp_send_msg_parms parms = { 0 };
1869 : : uint8_t fw_session_id;
1870 : : struct tf_dev_info *dev;
1871 : : struct tf_session *tfs;
1872 : : uint32_t flags = 0;
1873 : :
1874 : : /* Retrieve the session information */
1875 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1876 [ # # ]: 0 : if (rc) {
1877 : 0 : TFP_DRV_LOG(ERR,
1878 : : "%s: Failed to lookup session, rc:%s\n",
1879 : : tf_dir_2_str(dir),
1880 : : strerror(-rc));
1881 : 0 : return rc;
1882 : : }
1883 : :
1884 : : /* Retrieve the device information */
1885 : 0 : rc = tf_session_get_device(tfs, &dev);
1886 [ # # ]: 0 : if (rc) {
1887 : 0 : TFP_DRV_LOG(ERR,
1888 : : "%s: Failed to lookup device, rc:%s\n",
1889 : : tf_dir_2_str(dir),
1890 : : strerror(-rc));
1891 : 0 : return rc;
1892 : : }
1893 : :
1894 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1895 [ # # ]: 0 : if (rc) {
1896 : 0 : TFP_DRV_LOG(ERR,
1897 : : "%s: Unable to lookup FW id, rc:%s\n",
1898 : : tf_dir_2_str(dir),
1899 : : strerror(-rc));
1900 : 0 : return rc;
1901 : : }
1902 : : flags = (dir == TF_DIR_TX ?
1903 [ # # ]: 0 : HWRM_TF_TBL_TYPE_GET_INPUT_FLAGS_DIR_TX :
1904 : : HWRM_TF_TBL_TYPE_GET_INPUT_FLAGS_DIR_RX);
1905 : :
1906 [ # # ]: 0 : if (clear_on_read)
1907 : 0 : flags |= HWRM_TF_TBL_TYPE_GET_INPUT_FLAGS_CLEAR_ON_READ;
1908 : :
1909 : : /* Populate the request */
1910 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1911 : 0 : req.flags = tfp_cpu_to_le_16(flags);
1912 : 0 : req.type = tfp_cpu_to_le_32(hcapi_type);
1913 : 0 : req.index = tfp_cpu_to_le_32(index);
1914 : :
1915 : 0 : parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1916 : 0 : parms.req_data = (uint32_t *)&req;
1917 : 0 : parms.req_size = sizeof(req);
1918 : 0 : parms.resp_data = (uint32_t *)&resp;
1919 : 0 : parms.resp_size = sizeof(resp);
1920 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
1921 : :
1922 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1923 : : &parms);
1924 [ # # ]: 0 : if (rc)
1925 : : return rc;
1926 : :
1927 : : /*
1928 : : * The response will be 64 bytes long, the response size will
1929 : : * be in words (16). All we can test for is that the response
1930 : : * size is < to the requested size.
1931 : : */
1932 [ # # ]: 0 : if ((tfp_le_to_cpu_32(resp.size) * 4) < size)
1933 : : return -EINVAL;
1934 : :
1935 : : /*
1936 : : * Copy the requested number of bytes
1937 : : */
1938 : 0 : tfp_memcpy(data,
1939 : : &resp.data,
1940 : : size);
1941 : :
1942 : 0 : return 0;
1943 : : }
1944 : :
1945 : : /* HWRM Tunneled messages */
1946 : :
1947 : : int
1948 : 0 : tf_msg_get_global_cfg(struct tf *tfp,
1949 : : struct tf_global_cfg_parms *params)
1950 : : {
1951 : : int rc = 0;
1952 : 0 : struct tfp_send_msg_parms parms = { 0 };
1953 : 0 : struct hwrm_tf_global_cfg_get_input req = { 0 };
1954 : 0 : struct hwrm_tf_global_cfg_get_output resp = { 0 };
1955 : : uint32_t flags = 0;
1956 : : uint8_t fw_session_id;
1957 : : uint16_t resp_size = 0;
1958 : : struct tf_dev_info *dev;
1959 : : struct tf_session *tfs;
1960 : :
1961 : : /* Retrieve the session information */
1962 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
1963 [ # # ]: 0 : if (rc) {
1964 : 0 : TFP_DRV_LOG(ERR,
1965 : : "%s: Failed to lookup session, rc:%s\n",
1966 : : tf_dir_2_str(params->dir),
1967 : : strerror(-rc));
1968 : 0 : return rc;
1969 : : }
1970 : :
1971 : : /* Retrieve the device information */
1972 : 0 : rc = tf_session_get_device(tfs, &dev);
1973 [ # # ]: 0 : if (rc) {
1974 : 0 : TFP_DRV_LOG(ERR,
1975 : : "%s: Failed to lookup device, rc:%s\n",
1976 : : tf_dir_2_str(params->dir),
1977 : : strerror(-rc));
1978 : 0 : return rc;
1979 : : }
1980 : :
1981 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1982 [ # # ]: 0 : if (rc) {
1983 : 0 : TFP_DRV_LOG(ERR,
1984 : : "%s: Unable to lookup FW id, rc:%s\n",
1985 : : tf_dir_2_str(params->dir),
1986 : : strerror(-rc));
1987 : 0 : return rc;
1988 : : }
1989 : :
1990 : 0 : flags = (params->dir == TF_DIR_TX ?
1991 [ # # ]: 0 : HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1992 : : HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1993 : :
1994 : : /* Populate the request */
1995 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1996 : 0 : req.flags = tfp_cpu_to_le_32(flags);
1997 : 0 : req.type = tfp_cpu_to_le_32(params->type);
1998 : 0 : req.offset = tfp_cpu_to_le_32(params->offset);
1999 : 0 : req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
2000 : :
2001 : 0 : parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
2002 : 0 : parms.req_data = (uint32_t *)&req;
2003 : 0 : parms.req_size = sizeof(req);
2004 : 0 : parms.resp_data = (uint32_t *)&resp;
2005 : 0 : parms.resp_size = sizeof(resp);
2006 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2007 : :
2008 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2009 [ # # ]: 0 : if (rc != 0)
2010 : : return rc;
2011 : :
2012 : : /* Verify that we got enough buffer to return the requested data */
2013 : 0 : resp_size = tfp_le_to_cpu_16(resp.size);
2014 [ # # ]: 0 : if (resp_size < params->config_sz_in_bytes)
2015 : : return -EINVAL;
2016 : :
2017 [ # # ]: 0 : if (params->config)
2018 : 0 : tfp_memcpy(params->config,
2019 : : resp.data,
2020 : : resp_size);
2021 : : else
2022 : : return -EFAULT;
2023 : :
2024 : 0 : return 0;
2025 : : }
2026 : :
2027 : : int
2028 : 0 : tf_msg_set_global_cfg(struct tf *tfp,
2029 : : struct tf_global_cfg_parms *params)
2030 : : {
2031 : : int rc = 0;
2032 : 0 : struct tfp_send_msg_parms parms = { 0 };
2033 : 0 : struct hwrm_tf_global_cfg_set_input req = { 0 };
2034 : 0 : struct hwrm_tf_global_cfg_set_output resp = { 0 };
2035 : : uint32_t flags = 0;
2036 : : uint8_t fw_session_id;
2037 : : struct tf_dev_info *dev;
2038 : : struct tf_session *tfs;
2039 : :
2040 : : /* Retrieve the session information */
2041 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
2042 [ # # ]: 0 : if (rc) {
2043 : 0 : TFP_DRV_LOG(ERR,
2044 : : "%s: Failed to lookup session, rc:%s\n",
2045 : : tf_dir_2_str(params->dir),
2046 : : strerror(-rc));
2047 : 0 : return rc;
2048 : : }
2049 : :
2050 : : /* Retrieve the device information */
2051 : 0 : rc = tf_session_get_device(tfs, &dev);
2052 [ # # ]: 0 : if (rc) {
2053 : 0 : TFP_DRV_LOG(ERR,
2054 : : "%s: Failed to lookup device, rc:%s\n",
2055 : : tf_dir_2_str(params->dir),
2056 : : strerror(-rc));
2057 : 0 : return rc;
2058 : : }
2059 : :
2060 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2061 [ # # ]: 0 : if (rc) {
2062 : 0 : TFP_DRV_LOG(ERR,
2063 : : "%s: Unable to lookup FW id, rc:%s\n",
2064 : : tf_dir_2_str(params->dir),
2065 : : strerror(-rc));
2066 : 0 : return rc;
2067 : : }
2068 : :
2069 : 0 : flags = (params->dir == TF_DIR_TX ?
2070 [ # # ]: 0 : HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
2071 : : HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
2072 : :
2073 : : /* Populate the request */
2074 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2075 : 0 : req.flags = tfp_cpu_to_le_32(flags);
2076 : 0 : req.type = tfp_cpu_to_le_32(params->type);
2077 : 0 : req.offset = tfp_cpu_to_le_32(params->offset);
2078 : :
2079 : : /* Check for data size conformity */
2080 [ # # ]: 0 : if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
2081 : : rc = -EINVAL;
2082 : 0 : TFP_DRV_LOG(ERR,
2083 : : "%s: Invalid parameters for msg type, rc:%s\n",
2084 : : tf_dir_2_str(params->dir),
2085 : : strerror(-rc));
2086 : 0 : return rc;
2087 : : }
2088 : :
2089 : 0 : tfp_memcpy(req.data, params->config,
2090 : : params->config_sz_in_bytes);
2091 : :
2092 : : /* Only set mask if pointer is provided
2093 : : */
2094 [ # # ]: 0 : if (params->config_mask) {
2095 : 0 : tfp_memcpy(req.mask,
2096 : : params->config_mask,
2097 : 0 : params->config_sz_in_bytes);
2098 : : }
2099 : :
2100 : 0 : req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
2101 : :
2102 : 0 : parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
2103 : 0 : parms.req_data = (uint32_t *)&req;
2104 : 0 : parms.req_size = sizeof(req);
2105 : 0 : parms.resp_data = (uint32_t *)&resp;
2106 : 0 : parms.resp_size = sizeof(resp);
2107 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2108 : :
2109 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2110 : :
2111 [ # # ]: 0 : if (rc != 0)
2112 : 0 : return rc;
2113 : :
2114 : : return 0;
2115 : : }
2116 : :
2117 : : int
2118 : 0 : tf_msg_bulk_get_tbl_entry(struct tf *tfp,
2119 : : enum tf_dir dir,
2120 : : uint16_t hcapi_type,
2121 : : uint32_t starting_idx,
2122 : : uint16_t num_entries,
2123 : : uint16_t entry_sz_in_bytes,
2124 : : uint64_t physical_mem_addr,
2125 : : bool clear_on_read)
2126 : : {
2127 : : int rc;
2128 : 0 : struct tfp_send_msg_parms parms = { 0 };
2129 : 0 : struct hwrm_tf_tbl_type_bulk_get_input req = { 0 };
2130 : 0 : struct hwrm_tf_tbl_type_bulk_get_output resp = { 0 };
2131 : : int data_size = 0;
2132 : : uint8_t fw_session_id;
2133 : : struct tf_dev_info *dev;
2134 : : struct tf_session *tfs;
2135 : : uint32_t flags = 0;
2136 : :
2137 : : /* Retrieve the session information */
2138 : 0 : rc = tf_session_get_session(tfp, &tfs);
2139 [ # # ]: 0 : if (rc) {
2140 : 0 : TFP_DRV_LOG(ERR,
2141 : : "%s: Failed to lookup session, rc:%s\n",
2142 : : tf_dir_2_str(dir),
2143 : : strerror(-rc));
2144 : 0 : return rc;
2145 : : }
2146 : :
2147 : : /* Retrieve the device information */
2148 : 0 : rc = tf_session_get_device(tfs, &dev);
2149 [ # # ]: 0 : if (rc) {
2150 : 0 : TFP_DRV_LOG(ERR,
2151 : : "%s: Failed to lookup device, rc:%s\n",
2152 : : tf_dir_2_str(dir),
2153 : : strerror(-rc));
2154 : 0 : return rc;
2155 : : }
2156 : :
2157 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2158 [ # # ]: 0 : if (rc) {
2159 : 0 : TFP_DRV_LOG(ERR,
2160 : : "%s: Unable to lookup FW id, rc:%s\n",
2161 : : tf_dir_2_str(dir),
2162 : : strerror(-rc));
2163 : 0 : return rc;
2164 : : }
2165 : : flags = (dir == TF_DIR_TX ?
2166 [ # # ]: 0 : HWRM_TF_TBL_TYPE_BULK_GET_INPUT_FLAGS_DIR_TX :
2167 : : HWRM_TF_TBL_TYPE_BULK_GET_INPUT_FLAGS_DIR_RX);
2168 : :
2169 [ # # ]: 0 : if (clear_on_read)
2170 : 0 : flags |= HWRM_TF_TBL_TYPE_BULK_GET_INPUT_FLAGS_CLEAR_ON_READ;
2171 : :
2172 : : /* Populate the request */
2173 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2174 : 0 : req.flags = tfp_cpu_to_le_16(flags);
2175 : 0 : req.type = tfp_cpu_to_le_32(hcapi_type);
2176 : 0 : req.start_index = tfp_cpu_to_le_32(starting_idx);
2177 : 0 : req.num_entries = tfp_cpu_to_le_32(num_entries);
2178 : :
2179 : 0 : data_size = num_entries * entry_sz_in_bytes;
2180 : :
2181 : 0 : req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
2182 : :
2183 : 0 : parms.tf_type = HWRM_TF_TBL_TYPE_BULK_GET;
2184 : 0 : parms.req_data = (uint32_t *)&req;
2185 : 0 : parms.req_size = sizeof(req);
2186 : 0 : parms.resp_data = (uint32_t *)&resp;
2187 : 0 : parms.resp_size = sizeof(resp);
2188 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2189 : :
2190 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
2191 : : &parms);
2192 [ # # ]: 0 : if (rc)
2193 : : return rc;
2194 : :
2195 : : /* Verify that we got enough buffer to return the requested data */
2196 [ # # ]: 0 : if (tfp_le_to_cpu_32(resp.size) != data_size)
2197 : 0 : return -EINVAL;
2198 : :
2199 : : return 0;
2200 : : }
2201 : :
2202 : : int
2203 : 0 : tf_msg_get_if_tbl_entry(struct tf *tfp,
2204 : : struct tf_if_tbl_get_parms *params)
2205 : : {
2206 : : int rc = 0;
2207 : 0 : struct tfp_send_msg_parms parms = { 0 };
2208 : 0 : struct hwrm_tf_if_tbl_get_input req = { 0 };
2209 : 0 : struct hwrm_tf_if_tbl_get_output resp = { 0 };
2210 : : uint32_t flags = 0;
2211 : : struct tf_dev_info *dev;
2212 : : struct tf_session *tfs;
2213 : :
2214 : : /* Retrieve the session information */
2215 : 0 : rc = tf_session_get_session(tfp, &tfs);
2216 [ # # ]: 0 : if (rc) {
2217 : 0 : TFP_DRV_LOG(ERR,
2218 : : "%s: Failed to lookup session, rc:%s\n",
2219 : : tf_dir_2_str(params->dir),
2220 : : strerror(-rc));
2221 : 0 : return rc;
2222 : : }
2223 : :
2224 : : /* Retrieve the device information */
2225 : 0 : rc = tf_session_get_device(tfs, &dev);
2226 [ # # ]: 0 : if (rc) {
2227 : 0 : TFP_DRV_LOG(ERR,
2228 : : "%s: Failed to lookup device, rc:%s\n",
2229 : : tf_dir_2_str(params->dir),
2230 : : strerror(-rc));
2231 : 0 : return rc;
2232 : : }
2233 : :
2234 : 0 : flags = (params->dir == TF_DIR_TX ?
2235 [ # # ]: 0 : HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
2236 : : HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
2237 : :
2238 : : /* Populate the request */
2239 : 0 : req.fw_session_id =
2240 : 0 : tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2241 : 0 : req.flags = flags;
2242 : 0 : req.type = params->hcapi_type;
2243 : 0 : req.index = tfp_cpu_to_le_16(params->idx);
2244 : 0 : req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
2245 : :
2246 : 0 : parms.tf_type = HWRM_TF_IF_TBL_GET;
2247 : 0 : parms.req_data = (uint32_t *)&req;
2248 : 0 : parms.req_size = sizeof(req);
2249 : 0 : parms.resp_data = (uint32_t *)&resp;
2250 : 0 : parms.resp_size = sizeof(resp);
2251 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2252 : :
2253 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2254 : :
2255 [ # # ]: 0 : if (rc != 0)
2256 : : return rc;
2257 : :
2258 : 0 : tfp_memcpy(¶ms->data[0], resp.data, req.size);
2259 : :
2260 : 0 : return 0;
2261 : : }
2262 : :
2263 : : int
2264 : 0 : tf_msg_set_if_tbl_entry(struct tf *tfp,
2265 : : struct tf_if_tbl_set_parms *params)
2266 : : {
2267 : : int rc = 0;
2268 : 0 : struct tfp_send_msg_parms parms = { 0 };
2269 : 0 : struct hwrm_tf_if_tbl_set_input req = { 0 };
2270 : 0 : struct hwrm_tf_if_tbl_get_output resp = { 0 };
2271 : : uint32_t flags = 0;
2272 : : struct tf_dev_info *dev;
2273 : : struct tf_session *tfs;
2274 : :
2275 : : /* Retrieve the session information */
2276 : 0 : rc = tf_session_get_session(tfp, &tfs);
2277 [ # # ]: 0 : if (rc) {
2278 : 0 : TFP_DRV_LOG(ERR,
2279 : : "%s: Failed to lookup session, rc:%s\n",
2280 : : tf_dir_2_str(params->dir),
2281 : : strerror(-rc));
2282 : 0 : return rc;
2283 : : }
2284 : :
2285 : : /* Retrieve the device information */
2286 : 0 : rc = tf_session_get_device(tfs, &dev);
2287 [ # # ]: 0 : if (rc)
2288 : : return rc;
2289 : :
2290 : 0 : flags = (params->dir == TF_DIR_TX ?
2291 [ # # ]: 0 : HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
2292 : : HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
2293 : :
2294 : : /* Populate the request */
2295 : 0 : req.fw_session_id =
2296 : 0 : tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2297 : 0 : req.flags = flags;
2298 : 0 : req.type = params->hcapi_type;
2299 : 0 : req.index = tfp_cpu_to_le_32(params->idx);
2300 : 0 : req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
2301 : 0 : tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
2302 : :
2303 : 0 : parms.tf_type = HWRM_TF_IF_TBL_SET;
2304 : 0 : parms.req_data = (uint32_t *)&req;
2305 : 0 : parms.req_size = sizeof(req);
2306 : 0 : parms.resp_data = (uint32_t *)&resp;
2307 : 0 : parms.resp_size = sizeof(resp);
2308 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2309 : :
2310 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2311 : :
2312 [ # # ]: 0 : if (rc != 0)
2313 : 0 : return rc;
2314 : :
2315 : : return 0;
2316 : : }
2317 : :
2318 : : int
2319 : 0 : tf_msg_get_version(struct bnxt *bp,
2320 : : struct tf_dev_info *dev,
2321 : : struct tf_get_version_parms *params)
2322 : :
2323 : : {
2324 : : int rc;
2325 : 0 : struct hwrm_tf_version_get_input req = { 0 };
2326 : 0 : struct hwrm_tf_version_get_output resp = { 0 };
2327 : 0 : struct tfp_send_msg_parms parms = { 0 };
2328 : :
2329 : : /* Populate the request */
2330 : 0 : parms.tf_type = HWRM_TF_VERSION_GET,
2331 : 0 : parms.req_data = (uint32_t *)&req;
2332 : 0 : parms.req_size = sizeof(req);
2333 : 0 : parms.resp_data = (uint32_t *)&resp;
2334 : 0 : parms.resp_size = sizeof(resp);
2335 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2336 : :
2337 : 0 : rc = tfp_send_msg_direct(bp,
2338 : : &parms);
2339 : :
2340 : 0 : params->major = resp.major;
2341 : 0 : params->minor = resp.minor;
2342 : 0 : params->update = resp.update;
2343 : :
2344 : 0 : dev->ops->tf_dev_map_hcapi_caps(resp.dev_caps_cfg,
2345 : : ¶ms->dev_ident_caps,
2346 : : ¶ms->dev_tcam_caps,
2347 : : ¶ms->dev_tbl_caps,
2348 : : ¶ms->dev_em_caps);
2349 : :
2350 : 0 : return rc;
2351 : : }
2352 : :
2353 : : int
2354 : 0 : tf_msg_session_set_hotup_state(struct tf *tfp, uint16_t state)
2355 : : {
2356 : : int rc;
2357 : 0 : struct hwrm_tf_session_hotup_state_set_input req = { 0 };
2358 : 0 : struct hwrm_tf_session_hotup_state_set_output resp = { 0 };
2359 : 0 : struct tfp_send_msg_parms parms = { 0 };
2360 : : uint8_t fw_session_id;
2361 : : struct tf_dev_info *dev;
2362 : : struct tf_session *tfs;
2363 : :
2364 : : /* Retrieve the session information */
2365 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
2366 [ # # ]: 0 : if (rc) {
2367 : 0 : TFP_DRV_LOG(ERR,
2368 : : "Failed to lookup session, rc:%s\n",
2369 : : strerror(-rc));
2370 : 0 : return rc;
2371 : : }
2372 : :
2373 : : /* Retrieve the device information */
2374 : 0 : rc = tf_session_get_device(tfs, &dev);
2375 [ # # ]: 0 : if (rc) {
2376 : 0 : TFP_DRV_LOG(ERR,
2377 : : "Failed to lookup device, rc:%s\n",
2378 : : strerror(-rc));
2379 : 0 : return rc;
2380 : : }
2381 : :
2382 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2383 [ # # ]: 0 : if (rc) {
2384 : 0 : TFP_DRV_LOG(ERR,
2385 : : "Unable to lookup FW id, rc:%s\n",
2386 : : strerror(-rc));
2387 : 0 : return rc;
2388 : : }
2389 : :
2390 : : /* Populate the request */
2391 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2392 : 0 : req.state = tfp_cpu_to_le_16(state);
2393 : :
2394 : 0 : parms.tf_type = HWRM_TF_SESSION_HOTUP_STATE_SET;
2395 : 0 : parms.req_data = (uint32_t *)&req;
2396 : 0 : parms.req_size = sizeof(req);
2397 : 0 : parms.resp_data = (uint32_t *)&resp;
2398 : 0 : parms.resp_size = sizeof(resp);
2399 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2400 : :
2401 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
2402 : : &parms);
2403 : 0 : return rc;
2404 : : }
2405 : :
2406 : : int
2407 : 0 : tf_msg_session_get_hotup_state(struct tf *tfp,
2408 : : uint16_t *state,
2409 : : uint16_t *ref_cnt)
2410 : : {
2411 : : int rc;
2412 : 0 : struct hwrm_tf_session_hotup_state_get_input req = { 0 };
2413 : 0 : struct hwrm_tf_session_hotup_state_get_output resp = { 0 };
2414 : 0 : struct tfp_send_msg_parms parms = { 0 };
2415 : : uint8_t fw_session_id;
2416 : : struct tf_dev_info *dev;
2417 : : struct tf_session *tfs;
2418 : :
2419 : : /* Retrieve the session information */
2420 : 0 : rc = tf_session_get_session_internal(tfp, &tfs);
2421 [ # # ]: 0 : if (rc) {
2422 : 0 : TFP_DRV_LOG(ERR,
2423 : : "Failed to lookup session, rc:%s\n",
2424 : : strerror(-rc));
2425 : 0 : return rc;
2426 : : }
2427 : :
2428 : : /* Retrieve the device information */
2429 : 0 : rc = tf_session_get_device(tfs, &dev);
2430 [ # # ]: 0 : if (rc) {
2431 : 0 : TFP_DRV_LOG(ERR,
2432 : : "Failed to lookup device, rc:%s\n",
2433 : : strerror(-rc));
2434 : 0 : return rc;
2435 : : }
2436 : :
2437 : 0 : rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2438 [ # # ]: 0 : if (rc) {
2439 : 0 : TFP_DRV_LOG(ERR,
2440 : : "Unable to lookup FW id, rc:%s\n",
2441 : : strerror(-rc));
2442 : 0 : return rc;
2443 : : }
2444 : :
2445 : : /* Populate the request */
2446 : 0 : req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2447 : :
2448 : 0 : parms.tf_type = HWRM_TF_SESSION_HOTUP_STATE_GET;
2449 : 0 : parms.req_data = (uint32_t *)&req;
2450 : 0 : parms.req_size = sizeof(req);
2451 : 0 : parms.resp_data = (uint32_t *)&resp;
2452 : 0 : parms.resp_size = sizeof(resp);
2453 : 0 : parms.mailbox = dev->ops->tf_dev_get_mailbox();
2454 : :
2455 : 0 : rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
2456 : : &parms);
2457 : :
2458 : 0 : *state = tfp_le_to_cpu_16(resp.state);
2459 : 0 : *ref_cnt = tfp_le_to_cpu_16(resp.ref_cnt);
2460 : :
2461 : 0 : return rc;
2462 : : }
|