1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
12 #include "tf_em_common.h"
13 #include "tf_msg_common.h"
14 #include "tf_device.h"
17 #include "tf_common.h"
18 #include "tf_session.h"
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
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
31 /* Compile check - Catch any msg changes that we depend on, like the
32 * defines listed above for array size checking.
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.
38 * If failure is observed then both msg size (defines below) and the
39 * array size (define above) should be checked and compared.
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");
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");
51 #define TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET 128
52 static_assert(sizeof(struct hwrm_tf_tbl_type_set_input) ==
53 TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET,
54 "HWRM message size changed: hwrm_tf_tbl_type_set_input");
57 * This is the MAX data we can transport across regular HWRM
59 #define TF_PCI_BUF_SIZE_MAX 88
62 * This is the length of shared session name "tf_share"
64 #define TF_SHARED_SESSION_NAME_LEN 8
67 * This is the length of tcam shared session name "tf_shared-wc_tcam"
69 #define TF_TCAM_SHARED_SESSION_NAME_LEN 17
72 * If data bigger than TF_PCI_BUF_SIZE_MAX then use DMA method
74 struct tf_msg_dma_buf {
80 * Allocates a DMA buffer that can be used for message transfer.
83 * Pointer to DMA buffer structure
86 * Requested size of the buffer in bytes
90 * -ENOMEM - Unable to allocate buffer, no memory
93 tf_msg_alloc_dma_buf(struct tf_msg_dma_buf *buf, int size)
95 struct tfp_calloc_parms alloc_parms;
98 /* Allocate session */
99 alloc_parms.nitems = 1;
100 alloc_parms.size = size;
101 alloc_parms.alignment = 4096;
102 rc = tfp_calloc(&alloc_parms);
106 buf->pa_addr = (uintptr_t)alloc_parms.mem_pa;
107 buf->va_addr = alloc_parms.mem_va;
113 * Free's a previous allocated DMA buffer.
116 * Pointer to DMA buffer structure
119 tf_msg_free_dma_buf(struct tf_msg_dma_buf *buf)
121 tfp_free(buf->va_addr);
124 /* HWRM Direct messages */
127 tf_msg_session_open(struct bnxt *bp,
128 char *ctrl_chan_name,
129 uint8_t *fw_session_id,
130 uint8_t *fw_session_client_id,
131 struct tf_dev_info *dev,
132 bool *shared_session_creator)
135 struct hwrm_tf_session_open_input req = { 0 };
136 struct hwrm_tf_session_open_output resp = { 0 };
137 struct tfp_send_msg_parms parms = { 0 };
140 char *tcam_session_name;
142 /* Populate the request */
143 name_len = strnlen(ctrl_chan_name, TF_SESSION_NAME_MAX);
144 session_name = &ctrl_chan_name[name_len - strlen("tf_shared")];
145 tcam_session_name = &ctrl_chan_name[name_len - strlen("tf_shared-wc_tcam")];
146 if (!strncmp(tcam_session_name, "tf_shared-wc_tcam", strlen("tf_shared-wc_tcam")))
147 tfp_memcpy(&req.session_name, tcam_session_name, TF_TCAM_SHARED_SESSION_NAME_LEN);
148 else if (!strncmp(session_name, "tf_shared", strlen("tf_shared")))
149 tfp_memcpy(&req.session_name, session_name, TF_SHARED_SESSION_NAME_LEN);
151 tfp_memcpy(&req.session_name, ctrl_chan_name, TF_SESSION_NAME_MAX);
153 parms.tf_type = HWRM_TF_SESSION_OPEN;
154 parms.req_data = (uint32_t *)&req;
155 parms.req_size = sizeof(req);
156 parms.resp_data = (uint32_t *)&resp;
157 parms.resp_size = sizeof(resp);
158 parms.mailbox = dev->ops->tf_dev_get_mailbox();
160 rc = tfp_send_msg_direct(bp,
165 *fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
166 *fw_session_client_id =
167 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
168 *shared_session_creator = (bool)tfp_le_to_cpu_32(resp.flags
169 & HWRM_TF_SESSION_OPEN_OUTPUT_FLAGS_SHARED_SESSION_CREATOR);
175 tf_msg_session_attach(struct tf *tfp __rte_unused,
176 char *ctrl_chan_name __rte_unused,
177 uint8_t tf_fw_session_id __rte_unused)
183 tf_msg_session_client_register(struct tf *tfp,
184 struct tf_session *tfs,
185 char *ctrl_channel_name,
186 uint8_t *fw_session_client_id)
189 struct hwrm_tf_session_register_input req = { 0 };
190 struct hwrm_tf_session_register_output resp = { 0 };
191 struct tfp_send_msg_parms parms = { 0 };
192 uint8_t fw_session_id;
193 struct tf_dev_info *dev;
196 char *tcam_session_name;
198 /* Retrieve the device information */
199 rc = tf_session_get_device(tfs, &dev);
202 "Failed to lookup device, rc:%s\n",
207 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
210 "Unable to lookup FW id, rc:%s\n",
215 /* Populate the request */
216 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
217 name_len = strnlen(ctrl_channel_name, TF_SESSION_NAME_MAX);
218 session_name = &ctrl_channel_name[name_len - strlen("tf_shared")];
219 tcam_session_name = &ctrl_channel_name[name_len -
220 strlen("tf_shared-wc_tcam")];
221 if (!strncmp(tcam_session_name,
223 strlen("tf_shared-wc_tcam")))
224 tfp_memcpy(&req.session_client_name,
226 TF_TCAM_SHARED_SESSION_NAME_LEN);
227 else if (!strncmp(session_name, "tf_shared", strlen("tf_shared")))
228 tfp_memcpy(&req.session_client_name,
230 TF_SHARED_SESSION_NAME_LEN);
232 tfp_memcpy(&req.session_client_name,
234 TF_SESSION_NAME_MAX);
236 parms.tf_type = HWRM_TF_SESSION_REGISTER;
237 parms.req_data = (uint32_t *)&req;
238 parms.req_size = sizeof(req);
239 parms.resp_data = (uint32_t *)&resp;
240 parms.resp_size = sizeof(resp);
241 parms.mailbox = dev->ops->tf_dev_get_mailbox();
243 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
248 *fw_session_client_id =
249 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
255 tf_msg_session_client_unregister(struct tf *tfp,
256 struct tf_session *tfs,
257 uint8_t fw_session_client_id)
260 struct hwrm_tf_session_unregister_input req = { 0 };
261 struct hwrm_tf_session_unregister_output resp = { 0 };
262 struct tfp_send_msg_parms parms = { 0 };
263 uint8_t fw_session_id;
264 struct tf_dev_info *dev;
266 /* Retrieve the device information */
267 rc = tf_session_get_device(tfs, &dev);
270 "Failed to lookup device, rc:%s\n",
275 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
278 "Unable to lookup FW id, rc:%s\n",
283 /* Populate the request */
284 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
285 req.fw_session_client_id = tfp_cpu_to_le_32(fw_session_client_id);
287 parms.tf_type = HWRM_TF_SESSION_UNREGISTER;
288 parms.req_data = (uint32_t *)&req;
289 parms.req_size = sizeof(req);
290 parms.resp_data = (uint32_t *)&resp;
291 parms.resp_size = sizeof(resp);
292 parms.mailbox = dev->ops->tf_dev_get_mailbox();
294 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
301 tf_msg_session_close(struct tf *tfp,
302 uint8_t fw_session_id,
306 struct hwrm_tf_session_close_input req = { 0 };
307 struct hwrm_tf_session_close_output resp = { 0 };
308 struct tfp_send_msg_parms parms = { 0 };
310 /* Populate the request */
311 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
313 parms.tf_type = HWRM_TF_SESSION_CLOSE;
314 parms.req_data = (uint32_t *)&req;
315 parms.req_size = sizeof(req);
316 parms.resp_data = (uint32_t *)&resp;
317 parms.resp_size = sizeof(resp);
318 parms.mailbox = mailbox;
320 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
326 tf_msg_session_qcfg(struct tf *tfp)
329 struct hwrm_tf_session_qcfg_input req = { 0 };
330 struct hwrm_tf_session_qcfg_output resp = { 0 };
331 struct tfp_send_msg_parms parms = { 0 };
332 uint8_t fw_session_id;
333 struct tf_dev_info *dev;
334 struct tf_session *tfs;
336 /* Retrieve the session information */
337 rc = tf_session_get_session_internal(tfp, &tfs);
340 "Failed to lookup session, rc:%s\n",
345 /* Retrieve the device information */
346 rc = tf_session_get_device(tfs, &dev);
349 "Failed to lookup device, rc:%s\n",
354 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
357 "Unable to lookup FW id, rc:%s\n",
362 /* Populate the request */
363 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
365 parms.tf_type = HWRM_TF_SESSION_QCFG,
366 parms.req_data = (uint32_t *)&req;
367 parms.req_size = sizeof(req);
368 parms.resp_data = (uint32_t *)&resp;
369 parms.resp_size = sizeof(resp);
370 parms.mailbox = dev->ops->tf_dev_get_mailbox();
372 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
378 tf_msg_session_resc_qcaps(struct tf *tfp,
379 struct tf_dev_info *dev,
382 struct tf_rm_resc_req_entry *query,
383 enum tf_rm_resc_resv_strategy *resv_strategy)
387 struct tfp_send_msg_parms parms = { 0 };
388 struct hwrm_tf_session_resc_qcaps_input req = { 0 };
389 struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
390 uint8_t fw_session_id;
391 struct tf_msg_dma_buf qcaps_buf = { 0 };
392 struct tf_rm_resc_req_entry *data;
394 struct tf_session *tfs;
396 /* Retrieve the session information */
397 rc = tf_session_get_session_internal(tfp, &tfs);
400 "Failed to lookup session, rc:%s\n",
405 TF_CHECK_PARMS3(tfp, query, resv_strategy);
407 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
410 "%s: Unable to lookup FW id, rc:%s\n",
416 /* Prepare DMA buffer */
417 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
418 rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
422 /* Populate the request */
423 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
424 req.flags = tfp_cpu_to_le_16(dir);
425 req.qcaps_size = size;
426 req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
428 parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
429 parms.req_data = (uint32_t *)&req;
430 parms.req_size = sizeof(req);
431 parms.resp_data = (uint32_t *)&resp;
432 parms.resp_size = sizeof(resp);
433 parms.mailbox = dev->ops->tf_dev_get_mailbox();
435 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
439 /* Process the response
440 * Should always get expected number of entries
442 if (tfp_le_to_cpu_32(resp.size) != size) {
444 "%s: QCAPS message size error, rc:%s, request %d vs response %d\n",
451 /* Post process the response */
452 data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
454 for (i = 0; i < resp.size; i++) {
455 query[i].type = tfp_le_to_cpu_32(data[i].type);
456 query[i].min = tfp_le_to_cpu_16(data[i].min);
457 query[i].max = tfp_le_to_cpu_16(data[i].max);
460 *resv_strategy = resp.flags &
461 HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
464 tf_msg_free_dma_buf(&qcaps_buf);
470 tf_msg_session_resc_alloc(struct tf *tfp,
471 struct tf_dev_info *dev,
474 struct tf_rm_resc_req_entry *request,
475 struct tf_rm_resc_entry *resv)
479 struct tfp_send_msg_parms parms = { 0 };
480 struct hwrm_tf_session_resc_alloc_input req = { 0 };
481 struct hwrm_tf_session_resc_alloc_output resp = { 0 };
482 uint8_t fw_session_id;
483 struct tf_msg_dma_buf req_buf = { 0 };
484 struct tf_msg_dma_buf resv_buf = { 0 };
485 struct tf_rm_resc_req_entry *req_data;
486 struct tf_rm_resc_entry *resv_data;
488 struct tf_session *tfs;
490 /* Retrieve the session information */
491 rc = tf_session_get_session_internal(tfp, &tfs);
494 "Failed to lookup session, rc:%s\n",
499 TF_CHECK_PARMS3(tfp, request, resv);
501 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
504 "%s: Unable to lookup FW id, rc:%s\n",
510 /* Prepare DMA buffers */
511 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
512 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
516 dma_size = size * sizeof(struct tf_rm_resc_entry);
517 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
519 tf_msg_free_dma_buf(&req_buf);
523 /* Populate the request */
524 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
525 req.flags = tfp_cpu_to_le_16(dir);
528 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
529 for (i = 0; i < size; i++) {
530 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
531 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
532 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
535 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
536 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
538 parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
539 parms.req_data = (uint32_t *)&req;
540 parms.req_size = sizeof(req);
541 parms.resp_data = (uint32_t *)&resp;
542 parms.resp_size = sizeof(resp);
543 parms.mailbox = dev->ops->tf_dev_get_mailbox();
545 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
549 /* Process the response
550 * Should always get expected number of entries
552 if (tfp_le_to_cpu_32(resp.size) != size) {
554 "%s: Alloc message size error, rc:%s\n",
561 /* Post process the response */
562 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
563 for (i = 0; i < size; i++) {
564 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
565 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
566 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
570 tf_msg_free_dma_buf(&req_buf);
571 tf_msg_free_dma_buf(&resv_buf);
577 tf_msg_session_resc_info(struct tf *tfp,
578 struct tf_dev_info *dev,
581 struct tf_rm_resc_req_entry *request,
582 struct tf_rm_resc_entry *resv)
586 struct tfp_send_msg_parms parms = { 0 };
587 struct hwrm_tf_session_resc_info_input req = { 0 };
588 struct hwrm_tf_session_resc_info_output resp = { 0 };
589 uint8_t fw_session_id;
590 struct tf_msg_dma_buf req_buf = { 0 };
591 struct tf_msg_dma_buf resv_buf = { 0 };
592 struct tf_rm_resc_req_entry *req_data;
593 struct tf_rm_resc_entry *resv_data;
595 struct tf_session *tfs;
597 /* Retrieve the session information */
598 rc = tf_session_get_session_internal(tfp, &tfs);
601 "Failed to lookup session, rc:%s\n",
606 TF_CHECK_PARMS3(tfp, request, resv);
608 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
611 "%s: Unable to lookup FW id, rc:%s\n",
617 /* Prepare DMA buffers */
618 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
619 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
623 dma_size = size * sizeof(struct tf_rm_resc_entry);
624 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
626 tf_msg_free_dma_buf(&req_buf);
630 /* Populate the request */
631 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
632 req.flags = tfp_cpu_to_le_16(dir);
635 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
636 for (i = 0; i < size; i++) {
637 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
638 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
639 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
642 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
643 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
645 parms.tf_type = HWRM_TF_SESSION_RESC_INFO;
646 parms.req_data = (uint32_t *)&req;
647 parms.req_size = sizeof(req);
648 parms.resp_data = (uint32_t *)&resp;
649 parms.resp_size = sizeof(resp);
650 parms.mailbox = dev->ops->tf_dev_get_mailbox();
652 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
656 /* Process the response
657 * Should always get expected number of entries
659 if (tfp_le_to_cpu_32(resp.size) != size) {
661 "%s: Alloc message size error, rc:%s\n",
668 /* Post process the response */
669 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
670 for (i = 0; i < size; i++) {
671 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
672 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
673 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
677 tf_msg_free_dma_buf(&req_buf);
678 tf_msg_free_dma_buf(&resv_buf);
684 tf_msg_session_resc_flush(struct tf *tfp,
687 struct tf_rm_resc_entry *resv)
691 struct tfp_send_msg_parms parms = { 0 };
692 struct hwrm_tf_session_resc_flush_input req = { 0 };
693 struct hwrm_tf_session_resc_flush_output resp = { 0 };
694 uint8_t fw_session_id;
695 struct tf_msg_dma_buf resv_buf = { 0 };
696 struct tf_rm_resc_entry *resv_data;
698 struct tf_dev_info *dev;
699 struct tf_session *tfs;
701 TF_CHECK_PARMS2(tfp, resv);
703 /* Retrieve the session information */
704 rc = tf_session_get_session_internal(tfp, &tfs);
707 "%s: Failed to lookup session, rc:%s\n",
713 /* Retrieve the device information */
714 rc = tf_session_get_device(tfs, &dev);
717 "%s: Failed to lookup device, rc:%s\n",
723 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
726 "%s: Unable to lookup FW id, rc:%s\n",
732 /* Prepare DMA buffers */
733 dma_size = size * sizeof(struct tf_rm_resc_entry);
734 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
738 /* Populate the request */
739 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
740 req.flags = tfp_cpu_to_le_16(dir);
741 req.flush_size = size;
743 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
744 for (i = 0; i < size; i++) {
745 resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
746 resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
747 resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
750 req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
752 parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
753 parms.req_data = (uint32_t *)&req;
754 parms.req_size = sizeof(req);
755 parms.resp_data = (uint32_t *)&resp;
756 parms.resp_size = sizeof(resp);
757 parms.mailbox = dev->ops->tf_dev_get_mailbox();
759 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
761 tf_msg_free_dma_buf(&resv_buf);
767 tf_msg_insert_em_internal_entry(struct tf *tfp,
768 struct tf_insert_em_entry_parms *em_parms,
769 uint16_t *rptr_index,
771 uint8_t *num_of_entries)
774 struct tfp_send_msg_parms parms = { 0 };
775 struct hwrm_tf_em_insert_input req = { 0 };
776 struct hwrm_tf_em_insert_output resp = { 0 };
777 struct tf_em_64b_entry *em_result =
778 (struct tf_em_64b_entry *)em_parms->em_record;
780 uint8_t fw_session_id;
781 uint8_t msg_key_size;
782 struct tf_dev_info *dev;
783 struct tf_session *tfs;
785 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
786 TF_MSG_SIZE_HWRM_TF_EM_INSERT);
788 /* Retrieve the session information */
789 rc = tf_session_get_session_internal(tfp, &tfs);
792 "%s: Failed to lookup session, rc:%s\n",
793 tf_dir_2_str(em_parms->dir),
798 /* Retrieve the device information */
799 rc = tf_session_get_device(tfs, &dev);
802 "%s: Failed to lookup device, rc:%s\n",
803 tf_dir_2_str(em_parms->dir),
808 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
811 "%s: Unable to lookup FW id, rc:%s\n",
812 tf_dir_2_str(em_parms->dir),
817 /* Populate the request */
818 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
820 /* Check for key size conformity */
821 msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
822 if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
825 "%s: Invalid parameters for msg type, rc:%s\n",
826 tf_dir_2_str(em_parms->dir),
831 tfp_memcpy(req.em_key,
835 flags = (em_parms->dir == TF_DIR_TX ?
836 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
837 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
838 req.flags = tfp_cpu_to_le_16(flags);
839 req.strength = (em_result->hdr.word1 &
840 CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
841 CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
842 req.em_key_bitlen = em_parms->key_sz_in_bits;
843 req.action_ptr = em_result->hdr.pointer;
844 req.em_record_idx = *rptr_index;
846 parms.tf_type = HWRM_TF_EM_INSERT;
847 parms.req_data = (uint32_t *)&req;
848 parms.req_size = sizeof(req);
849 parms.resp_data = (uint32_t *)&resp;
850 parms.resp_size = sizeof(resp);
851 parms.mailbox = dev->ops->tf_dev_get_mailbox();
853 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
858 *rptr_entry = resp.rptr_entry;
859 *rptr_index = resp.rptr_index;
860 *num_of_entries = resp.num_of_entries;
866 tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
867 struct tf_insert_em_entry_parms *em_parms,
870 uint16_t *rptr_index,
872 uint8_t *num_of_entries)
875 struct tfp_send_msg_parms parms = { 0 };
876 struct hwrm_tf_em_hash_insert_input req = { 0 };
877 struct hwrm_tf_em_hash_insert_output resp = { 0 };
879 uint8_t fw_session_id;
880 uint8_t msg_record_size;
881 struct tf_dev_info *dev;
882 struct tf_session *tfs;
884 /* Retrieve the session information */
885 rc = tf_session_get_session_internal(tfp, &tfs);
888 "%s: Failed to lookup session, rc:%s\n",
889 tf_dir_2_str(em_parms->dir),
894 /* Retrieve the device information */
895 rc = tf_session_get_device(tfs, &dev);
898 "%s: Failed to lookup device, rc:%s\n",
899 tf_dir_2_str(em_parms->dir),
904 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
907 "%s: Unable to lookup FW id, rc:%s\n",
908 tf_dir_2_str(em_parms->dir),
913 /* Populate the request */
914 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
916 /* Check for key size conformity */
917 msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
919 if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
922 "%s: Record size to large, rc:%s\n",
923 tf_dir_2_str(em_parms->dir),
928 tfp_memcpy((char *)req.em_record,
932 flags = (em_parms->dir == TF_DIR_TX ?
933 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
934 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
935 req.flags = tfp_cpu_to_le_16(flags);
936 req.em_record_size_bits = em_parms->em_record_sz_in_bits;
937 req.em_record_idx = *rptr_index;
938 req.key0_hash = key0_hash;
939 req.key1_hash = key1_hash;
941 parms.tf_type = HWRM_TF_EM_HASH_INSERT;
942 parms.req_data = (uint32_t *)&req;
943 parms.req_size = sizeof(req);
944 parms.resp_data = (uint32_t *)&resp;
945 parms.resp_size = sizeof(resp);
946 parms.mailbox = dev->ops->tf_dev_get_mailbox();
948 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
953 *rptr_entry = resp.rptr_entry;
954 *rptr_index = resp.rptr_index;
955 *num_of_entries = resp.num_of_entries;
961 tf_msg_delete_em_entry(struct tf *tfp,
962 struct tf_delete_em_entry_parms *em_parms)
965 struct tfp_send_msg_parms parms = { 0 };
966 struct hwrm_tf_em_delete_input req = { 0 };
967 struct hwrm_tf_em_delete_output resp = { 0 };
969 uint8_t fw_session_id;
970 struct tf_dev_info *dev;
971 struct tf_session *tfs;
973 /* Retrieve the session information */
974 rc = tf_session_get_session_internal(tfp, &tfs);
977 "%s: Failed to lookup session, rc:%s\n",
978 tf_dir_2_str(em_parms->dir),
983 /* Retrieve the device information */
984 rc = tf_session_get_device(tfs, &dev);
987 "%s: Failed to lookup device, rc:%s\n",
988 tf_dir_2_str(em_parms->dir),
993 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
996 "%s: Unable to lookup FW id, rc:%s\n",
997 tf_dir_2_str(em_parms->dir),
1002 /* Populate the request */
1003 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1005 flags = (em_parms->dir == TF_DIR_TX ?
1006 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
1007 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
1008 req.flags = tfp_cpu_to_le_16(flags);
1009 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
1011 parms.tf_type = HWRM_TF_EM_DELETE;
1012 parms.req_data = (uint32_t *)&req;
1013 parms.req_size = sizeof(req);
1014 parms.resp_data = (uint32_t *)&resp;
1015 parms.resp_size = sizeof(resp);
1016 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1018 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1023 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1029 tf_msg_move_em_entry(struct tf *tfp,
1030 struct tf_move_em_entry_parms *em_parms)
1033 struct tfp_send_msg_parms parms = { 0 };
1034 struct hwrm_tf_em_move_input req = { 0 };
1035 struct hwrm_tf_em_move_output resp = { 0 };
1037 uint8_t fw_session_id;
1038 struct tf_dev_info *dev;
1039 struct tf_session *tfs;
1041 /* Retrieve the session information */
1042 rc = tf_session_get_session_internal(tfp, &tfs);
1045 "%s: Failed to lookup session, rc:%s\n",
1046 tf_dir_2_str(em_parms->dir),
1051 /* Retrieve the device information */
1052 rc = tf_session_get_device(tfs, &dev);
1055 "%s: Failed to lookup device, rc:%s\n",
1056 tf_dir_2_str(em_parms->dir),
1061 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1064 "%s: Unable to lookup FW id, rc:%s\n",
1065 tf_dir_2_str(em_parms->dir),
1070 /* Populate the request */
1071 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1073 flags = (em_parms->dir == TF_DIR_TX ?
1074 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
1075 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
1076 req.flags = tfp_cpu_to_le_16(flags);
1077 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
1078 req.new_index = tfp_cpu_to_le_32(em_parms->new_index);
1080 parms.tf_type = HWRM_TF_EM_MOVE;
1081 parms.req_data = (uint32_t *)&req;
1082 parms.req_size = sizeof(req);
1083 parms.resp_data = (uint32_t *)&resp;
1084 parms.resp_size = sizeof(resp);
1085 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1087 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1092 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1097 int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
1098 struct hcapi_cfa_em_table *tbl,
1101 uint32_t *page_size)
1103 struct tfp_send_msg_parms parms = { 0 };
1104 struct hwrm_tf_ctxt_mem_alloc_input req = {0};
1105 struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
1106 uint32_t mem_size_k;
1108 struct tf_dev_info *dev;
1109 struct tf_session *tfs;
1112 /* Retrieve the session information */
1113 rc = tf_session_get_session_internal(tfp, &tfs);
1116 "Failed to lookup session, rc:%s\n",
1121 /* Retrieve the device information */
1122 rc = tf_session_get_device(tfs, &dev);
1125 "Failed to lookup device, rc:%s\n",
1129 /* Retrieve the session information */
1130 fw_se_id = tfs->session_id.internal.fw_session_id;
1132 if (tbl->num_entries && tbl->entry_size) {
1134 mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
1135 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1136 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1137 parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
1138 parms.req_data = (uint32_t *)&req;
1139 parms.req_size = sizeof(req);
1140 parms.resp_data = (uint32_t *)&resp;
1141 parms.resp_size = sizeof(resp);
1142 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1143 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1145 TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
1150 *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
1151 *page_lvl = resp.page_level;
1152 *page_size = resp.page_size;
1158 int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
1159 uint32_t mem_size_k,
1164 struct tfp_send_msg_parms parms = { 0 };
1165 struct hwrm_tf_ctxt_mem_free_input req = {0};
1166 struct hwrm_tf_ctxt_mem_free_output resp = {0};
1168 struct tf_dev_info *dev;
1169 struct tf_session *tfs;
1172 /* Retrieve the session information */
1173 rc = tf_session_get_session_internal(tfp, &tfs);
1176 "Failed to lookup session, rc:%s\n",
1181 /* Retrieve the device information */
1182 rc = tf_session_get_device(tfs, &dev);
1185 "Failed to lookup device, rc:%s\n",
1189 /* Retrieve the session information */
1190 fw_se_id = tfs->session_id.internal.fw_session_id;
1192 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1193 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1194 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1195 req.page_level = page_level;
1196 req.page_size = page_size;
1197 parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
1198 parms.req_data = (uint32_t *)&req;
1199 parms.req_size = sizeof(req);
1200 parms.resp_data = (uint32_t *)&resp;
1201 parms.resp_size = sizeof(resp);
1202 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1203 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1209 tf_msg_em_mem_rgtr(struct tf *tfp,
1216 struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
1217 struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
1218 struct tfp_send_msg_parms parms = { 0 };
1219 struct tf_dev_info *dev;
1220 struct tf_session *tfs;
1223 /* Retrieve the session information */
1224 rc = tf_session_get_session_internal(tfp, &tfs);
1227 "Failed to lookup session, rc:%s\n",
1232 /* Retrieve the device information */
1233 rc = tf_session_get_device(tfs, &dev);
1236 "Failed to lookup device, rc:%s\n",
1240 fw_se_id = tfs->session_id.internal.fw_session_id;
1242 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1243 req.page_level = page_lvl;
1244 req.page_size = page_size;
1245 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1247 parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
1248 parms.req_data = (uint32_t *)&req;
1249 parms.req_size = sizeof(req);
1250 parms.resp_data = (uint32_t *)&resp;
1251 parms.resp_size = sizeof(resp);
1252 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1254 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1259 *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
1265 tf_msg_em_mem_unrgtr(struct tf *tfp,
1269 struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
1270 struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
1271 struct tfp_send_msg_parms parms = { 0 };
1272 struct tf_dev_info *dev;
1273 struct tf_session *tfs;
1276 /* Retrieve the session information */
1277 rc = tf_session_get_session_internal(tfp, &tfs);
1280 "Failed to lookup session, rc:%s\n",
1285 /* Retrieve the device information */
1286 rc = tf_session_get_device(tfs, &dev);
1289 "Failed to lookup device, rc:%s\n",
1294 fw_se_id = tfs->session_id.internal.fw_session_id;
1295 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1297 req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
1299 parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
1300 parms.req_data = (uint32_t *)&req;
1301 parms.req_size = sizeof(req);
1302 parms.resp_data = (uint32_t *)&resp;
1303 parms.resp_size = sizeof(resp);
1304 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1306 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1312 tf_msg_em_qcaps(struct tf *tfp,
1314 struct tf_em_caps *em_caps)
1317 struct hwrm_tf_ext_em_qcaps_input req = {0};
1318 struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
1320 struct tfp_send_msg_parms parms = { 0 };
1321 struct tf_dev_info *dev;
1322 struct tf_session *tfs;
1325 /* Retrieve the session information */
1326 rc = tf_session_get_session_internal(tfp, &tfs);
1329 "%s: Failed to lookup session, rc:%s\n",
1334 fw_se_id = tfs->session_id.internal.fw_session_id;
1336 /* Retrieve the device information */
1337 rc = tf_session_get_device(tfs, &dev);
1340 "%s: Failed to lookup device, rc:%s\n",
1346 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
1347 HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
1348 req.flags = tfp_cpu_to_le_32(flags);
1350 parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
1351 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1352 parms.req_data = (uint32_t *)&req;
1353 parms.req_size = sizeof(req);
1354 parms.resp_data = (uint32_t *)&resp;
1355 parms.resp_size = sizeof(resp);
1356 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1358 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1363 em_caps->supported = tfp_le_to_cpu_32(resp.supported);
1364 em_caps->max_entries_supported =
1365 tfp_le_to_cpu_32(resp.max_entries_supported);
1366 em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
1367 em_caps->record_entry_size =
1368 tfp_le_to_cpu_16(resp.record_entry_size);
1369 em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
1375 tf_msg_em_cfg(struct tf *tfp,
1376 uint32_t num_entries,
1377 uint16_t key0_ctx_id,
1378 uint16_t key1_ctx_id,
1379 uint16_t record_ctx_id,
1380 uint16_t efc_ctx_id,
1381 uint8_t flush_interval,
1385 struct hwrm_tf_ext_em_cfg_input req = {0};
1386 struct hwrm_tf_ext_em_cfg_output resp = {0};
1388 struct tfp_send_msg_parms parms = { 0 };
1389 struct tf_dev_info *dev;
1390 struct tf_session *tfs;
1392 /* Retrieve the session information */
1393 rc = tf_session_get_session_internal(tfp, &tfs);
1396 "%s: Failed to lookup session, rc:%s\n",
1402 /* Retrieve the device information */
1403 rc = tf_session_get_device(tfs, &dev);
1406 "%s: Failed to lookup device, rc:%s\n",
1412 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1413 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1414 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1416 req.flags = tfp_cpu_to_le_32(flags);
1417 req.num_entries = tfp_cpu_to_le_32(num_entries);
1419 req.flush_interval = flush_interval;
1421 req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
1422 req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
1423 req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
1424 req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
1426 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1427 parms.req_data = (uint32_t *)&req;
1428 parms.req_size = sizeof(req);
1429 parms.resp_data = (uint32_t *)&resp;
1430 parms.resp_size = sizeof(resp);
1431 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1433 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1439 tf_msg_ext_em_cfg(struct tf *tfp,
1440 struct tf_tbl_scope_cb *tbl_scope_cb,
1441 uint32_t st_buckets,
1442 uint8_t flush_interval,
1445 struct hcapi_cfa_em_ctx_mem_info *ctxp = &tbl_scope_cb->em_ctx_info[dir];
1446 struct hcapi_cfa_em_table *lkup_tbl, *act_tbl;
1447 struct hwrm_tf_ext_em_cfg_input req = {0};
1448 struct hwrm_tf_ext_em_cfg_output resp = {0};
1449 struct tfp_send_msg_parms parms = { 0 };
1451 struct tf_dev_info *dev;
1452 struct tf_session *tfs;
1456 /* Retrieve the session information */
1457 rc = tf_session_get_session_internal(tfp, &tfs);
1460 "%s: Failed to lookup session, rc:%s\n",
1466 /* Retrieve the device information */
1467 rc = tf_session_get_device(tfs, &dev);
1470 "%s: Failed to lookup device, rc:%s\n",
1475 fw_se_id = tfs->session_id.internal.fw_session_id;
1477 lkup_tbl = &ctxp->em_tables[TF_EM_LKUP_TABLE];
1478 act_tbl = &ctxp->em_tables[TF_ACTION_TABLE];
1479 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1480 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1481 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1483 req.flags = tfp_cpu_to_le_32(flags);
1484 req.num_entries = tfp_cpu_to_le_32(act_tbl->num_entries);
1485 req.lkup_static_buckets = tfp_cpu_to_le_32(st_buckets);
1486 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1487 req.flush_interval = flush_interval;
1488 req.action_ctx_id = tfp_cpu_to_le_16(act_tbl->ctx_id);
1489 req.action_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1490 req.lkup_ctx_id = tfp_cpu_to_le_16(lkup_tbl->ctx_id);
1491 req.lkup_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1493 req.enables = (HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_CTX_ID |
1494 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_TBL_SCOPE |
1495 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_CTX_ID |
1496 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_TBL_SCOPE |
1497 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_STATIC_BUCKETS |
1498 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_NUM_ENTRIES);
1500 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1501 parms.req_data = (uint32_t *)&req;
1502 parms.req_size = sizeof(req);
1503 parms.resp_data = (uint32_t *)&resp;
1504 parms.resp_size = sizeof(resp);
1505 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1507 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1513 tf_msg_em_op(struct tf *tfp,
1518 struct hwrm_tf_ext_em_op_input req = {0};
1519 struct hwrm_tf_ext_em_op_output resp = {0};
1521 struct tfp_send_msg_parms parms = { 0 };
1522 struct tf_dev_info *dev;
1523 struct tf_session *tfs;
1525 /* Retrieve the session information */
1526 rc = tf_session_get_session_internal(tfp, &tfs);
1529 "%s: Failed to lookup session, rc:%s\n",
1535 /* Retrieve the device information */
1536 rc = tf_session_get_device(tfs, &dev);
1539 "%s: Failed to lookup device, rc:%s\n",
1545 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1546 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1547 req.flags = tfp_cpu_to_le_32(flags);
1548 req.op = tfp_cpu_to_le_16(op);
1550 parms.tf_type = HWRM_TF_EXT_EM_OP;
1551 parms.req_data = (uint32_t *)&req;
1552 parms.req_size = sizeof(req);
1553 parms.resp_data = (uint32_t *)&resp;
1554 parms.resp_size = sizeof(resp);
1555 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1557 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1563 tf_msg_tcam_entry_set(struct tf *tfp,
1564 struct tf_dev_info *dev,
1565 struct tf_tcam_set_parms *parms)
1568 struct tfp_send_msg_parms mparms = { 0 };
1569 struct hwrm_tf_tcam_set_input req = { 0 };
1570 struct hwrm_tf_tcam_set_output resp = { 0 };
1571 struct tf_msg_dma_buf buf = { 0 };
1572 uint8_t *data = NULL;
1574 uint8_t fw_session_id;
1575 struct tf_session *tfs;
1577 /* Retrieve the session information */
1578 rc = tf_session_get_session_internal(tfp, &tfs);
1581 "Failed to lookup session, rc:%s\n",
1586 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1589 "%s: Unable to lookup FW id, rc:%s\n",
1590 tf_dir_2_str(parms->dir),
1595 /* Populate the request */
1596 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1597 req.type = parms->hcapi_type;
1598 req.idx = tfp_cpu_to_le_16(parms->idx);
1599 if (parms->dir == TF_DIR_TX)
1600 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1602 req.key_size = parms->key_size;
1603 req.mask_offset = parms->key_size;
1604 /* Result follows after key and mask, thus multiply by 2 */
1605 req.result_offset = 2 * parms->key_size;
1606 req.result_size = parms->result_size;
1607 data_size = 2 * req.key_size + req.result_size;
1609 if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1610 /* use pci buffer */
1611 data = &req.dev_data[0];
1613 /* use dma buffer */
1614 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1615 rc = tf_msg_alloc_dma_buf(&buf, data_size);
1619 tfp_memcpy(&req.dev_data[0],
1621 sizeof(buf.pa_addr));
1624 tfp_memcpy(&data[0], parms->key, parms->key_size);
1625 tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1626 tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1628 mparms.tf_type = HWRM_TF_TCAM_SET;
1629 mparms.req_data = (uint32_t *)&req;
1630 mparms.req_size = sizeof(req);
1631 mparms.resp_data = (uint32_t *)&resp;
1632 mparms.resp_size = sizeof(resp);
1633 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1635 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1639 tf_msg_free_dma_buf(&buf);
1645 tf_msg_tcam_entry_get(struct tf *tfp,
1646 struct tf_dev_info *dev,
1647 struct tf_tcam_get_parms *parms)
1650 struct tfp_send_msg_parms mparms = { 0 };
1651 struct hwrm_tf_tcam_get_input req = { 0 };
1652 struct hwrm_tf_tcam_get_output resp = { 0 };
1653 uint8_t fw_session_id;
1654 struct tf_session *tfs;
1656 /* Retrieve the session information */
1657 rc = tf_session_get_session_internal(tfp, &tfs);
1660 "Failed to lookup session, rc:%s\n",
1665 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1668 "%s: Unable to lookup FW id, rc:%s\n",
1669 tf_dir_2_str(parms->dir),
1674 /* Populate the request */
1675 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1676 req.type = parms->hcapi_type;
1677 req.idx = tfp_cpu_to_le_16(parms->idx);
1678 if (parms->dir == TF_DIR_TX)
1679 req.flags |= HWRM_TF_TCAM_GET_INPUT_FLAGS_DIR_TX;
1681 mparms.tf_type = HWRM_TF_TCAM_GET;
1682 mparms.req_data = (uint32_t *)&req;
1683 mparms.req_size = sizeof(req);
1684 mparms.resp_data = (uint32_t *)&resp;
1685 mparms.resp_size = sizeof(resp);
1686 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1688 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1694 if (parms->key_size < resp.key_size ||
1695 parms->result_size < resp.result_size) {
1698 "%s: Key buffer(%d) is smaller than the key(%d), rc:%s\n",
1699 tf_dir_2_str(parms->dir),
1705 parms->key_size = resp.key_size;
1706 parms->result_size = resp.result_size;
1707 tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
1708 tfp_memcpy(parms->mask, &resp.dev_data[resp.key_size], resp.key_size);
1709 tfp_memcpy(parms->result, &resp.dev_data[resp.result_offset], resp.result_size);
1715 tf_msg_tcam_entry_free(struct tf *tfp,
1716 struct tf_dev_info *dev,
1717 struct tf_tcam_free_parms *in_parms)
1720 struct hwrm_tf_tcam_free_input req = { 0 };
1721 struct hwrm_tf_tcam_free_output resp = { 0 };
1722 struct tfp_send_msg_parms parms = { 0 };
1723 uint8_t fw_session_id;
1724 struct tf_session *tfs;
1726 /* Retrieve the session information */
1727 rc = tf_session_get_session_internal(tfp, &tfs);
1730 "Failed to lookup session, rc:%s\n",
1735 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1738 "%s: Unable to lookup FW id, rc:%s\n",
1739 tf_dir_2_str(in_parms->dir),
1744 /* Populate the request */
1745 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1746 req.type = in_parms->hcapi_type;
1748 req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1749 if (in_parms->dir == TF_DIR_TX)
1750 req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1752 parms.tf_type = HWRM_TF_TCAM_FREE;
1753 parms.req_data = (uint32_t *)&req;
1754 parms.req_size = sizeof(req);
1755 parms.resp_data = (uint32_t *)&resp;
1756 parms.resp_size = sizeof(resp);
1757 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1759 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1765 tf_msg_set_tbl_entry(struct tf *tfp,
1767 uint16_t hcapi_type,
1773 struct hwrm_tf_tbl_type_set_input req = { 0 };
1774 struct hwrm_tf_tbl_type_set_output resp = { 0 };
1775 struct tfp_send_msg_parms parms = { 0 };
1776 uint8_t fw_session_id;
1777 struct tf_dev_info *dev;
1778 struct tf_session *tfs;
1780 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_tbl_type_set_input) !=
1781 TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET);
1783 /* Retrieve the session information */
1784 rc = tf_session_get_session_internal(tfp, &tfs);
1787 "%s: Failed to lookup session, rc:%s\n",
1793 /* Retrieve the device information */
1794 rc = tf_session_get_device(tfs, &dev);
1797 "%s: Failed to lookup device, rc:%s\n",
1803 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1806 "%s: Unable to lookup FW id, rc:%s\n",
1812 /* Populate the request */
1813 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1814 req.flags = tfp_cpu_to_le_16(dir);
1815 req.type = tfp_cpu_to_le_32(hcapi_type);
1816 req.size = tfp_cpu_to_le_16(size);
1817 req.index = tfp_cpu_to_le_32(index);
1819 /* Check for data size conformity */
1820 if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1823 "%s: Invalid parameters for msg type, rc:%s\n",
1829 tfp_memcpy(&req.data,
1833 parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1834 parms.req_data = (uint32_t *)&req;
1835 parms.req_size = sizeof(req);
1836 parms.resp_data = (uint32_t *)&resp;
1837 parms.resp_size = sizeof(resp);
1838 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1840 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1849 tf_msg_get_tbl_entry(struct tf *tfp,
1851 uint16_t hcapi_type,
1857 struct hwrm_tf_tbl_type_get_input req = { 0 };
1858 struct hwrm_tf_tbl_type_get_output resp = { 0 };
1859 struct tfp_send_msg_parms parms = { 0 };
1860 uint8_t fw_session_id;
1861 struct tf_dev_info *dev;
1862 struct tf_session *tfs;
1864 /* Retrieve the session information */
1865 rc = tf_session_get_session_internal(tfp, &tfs);
1868 "%s: Failed to lookup session, rc:%s\n",
1874 /* Retrieve the device information */
1875 rc = tf_session_get_device(tfs, &dev);
1878 "%s: Failed to lookup device, rc:%s\n",
1884 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1887 "%s: Unable to lookup FW id, rc:%s\n",
1893 /* Populate the request */
1894 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1895 req.flags = tfp_cpu_to_le_16(dir);
1896 req.type = tfp_cpu_to_le_32(hcapi_type);
1897 req.index = tfp_cpu_to_le_32(index);
1899 parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1900 parms.req_data = (uint32_t *)&req;
1901 parms.req_size = sizeof(req);
1902 parms.resp_data = (uint32_t *)&resp;
1903 parms.resp_size = sizeof(resp);
1904 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1906 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1912 * The response will be 64 bytes long, the response size will
1913 * be in words (16). All we can test for is that the response
1914 * size is < to the requested size.
1916 if ((tfp_le_to_cpu_32(resp.size) * 4) < size)
1920 * Copy the requested number of bytes
1929 /* HWRM Tunneled messages */
1932 tf_msg_get_global_cfg(struct tf *tfp,
1933 struct tf_global_cfg_parms *params)
1936 struct tfp_send_msg_parms parms = { 0 };
1937 struct hwrm_tf_global_cfg_get_input req = { 0 };
1938 struct hwrm_tf_global_cfg_get_output resp = { 0 };
1940 uint8_t fw_session_id;
1941 uint16_t resp_size = 0;
1942 struct tf_dev_info *dev;
1943 struct tf_session *tfs;
1945 /* Retrieve the session information */
1946 rc = tf_session_get_session_internal(tfp, &tfs);
1949 "%s: Failed to lookup session, rc:%s\n",
1950 tf_dir_2_str(params->dir),
1955 /* Retrieve the device information */
1956 rc = tf_session_get_device(tfs, &dev);
1959 "%s: Failed to lookup device, rc:%s\n",
1960 tf_dir_2_str(params->dir),
1965 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1968 "%s: Unable to lookup FW id, rc:%s\n",
1969 tf_dir_2_str(params->dir),
1974 flags = (params->dir == TF_DIR_TX ?
1975 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1976 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1978 /* Populate the request */
1979 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1980 req.flags = tfp_cpu_to_le_32(flags);
1981 req.type = tfp_cpu_to_le_32(params->type);
1982 req.offset = tfp_cpu_to_le_32(params->offset);
1983 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1985 parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
1986 parms.req_data = (uint32_t *)&req;
1987 parms.req_size = sizeof(req);
1988 parms.resp_data = (uint32_t *)&resp;
1989 parms.resp_size = sizeof(resp);
1990 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1992 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1996 /* Verify that we got enough buffer to return the requested data */
1997 resp_size = tfp_le_to_cpu_16(resp.size);
1998 if (resp_size < params->config_sz_in_bytes)
2002 tfp_memcpy(params->config,
2012 tf_msg_set_global_cfg(struct tf *tfp,
2013 struct tf_global_cfg_parms *params)
2016 struct tfp_send_msg_parms parms = { 0 };
2017 struct hwrm_tf_global_cfg_set_input req = { 0 };
2018 struct hwrm_tf_global_cfg_set_output resp = { 0 };
2020 uint8_t fw_session_id;
2021 struct tf_dev_info *dev;
2022 struct tf_session *tfs;
2024 /* Retrieve the session information */
2025 rc = tf_session_get_session_internal(tfp, &tfs);
2028 "%s: Failed to lookup session, rc:%s\n",
2029 tf_dir_2_str(params->dir),
2034 /* Retrieve the device information */
2035 rc = tf_session_get_device(tfs, &dev);
2038 "%s: Failed to lookup device, rc:%s\n",
2039 tf_dir_2_str(params->dir),
2044 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2047 "%s: Unable to lookup FW id, rc:%s\n",
2048 tf_dir_2_str(params->dir),
2053 flags = (params->dir == TF_DIR_TX ?
2054 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
2055 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
2057 /* Populate the request */
2058 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2059 req.flags = tfp_cpu_to_le_32(flags);
2060 req.type = tfp_cpu_to_le_32(params->type);
2061 req.offset = tfp_cpu_to_le_32(params->offset);
2063 /* Check for data size conformity */
2064 if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
2067 "%s: Invalid parameters for msg type, rc:%s\n",
2068 tf_dir_2_str(params->dir),
2073 tfp_memcpy(req.data, params->config,
2074 params->config_sz_in_bytes);
2076 /* Only set mask if pointer is provided
2078 if (params->config_mask) {
2079 tfp_memcpy(req.mask,
2080 params->config_mask,
2081 params->config_sz_in_bytes);
2084 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
2086 parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
2087 parms.req_data = (uint32_t *)&req;
2088 parms.req_size = sizeof(req);
2089 parms.resp_data = (uint32_t *)&resp;
2090 parms.resp_size = sizeof(resp);
2091 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2093 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2102 tf_msg_bulk_get_tbl_entry(struct tf *tfp,
2104 uint16_t hcapi_type,
2105 uint32_t starting_idx,
2106 uint16_t num_entries,
2107 uint16_t entry_sz_in_bytes,
2108 uint64_t physical_mem_addr)
2111 struct tfp_send_msg_parms parms = { 0 };
2112 struct hwrm_tf_tbl_type_bulk_get_input req = { 0 };
2113 struct hwrm_tf_tbl_type_bulk_get_output resp = { 0 };
2115 uint8_t fw_session_id;
2116 struct tf_dev_info *dev;
2117 struct tf_session *tfs;
2119 /* Retrieve the session information */
2120 rc = tf_session_get_session(tfp, &tfs);
2123 "%s: Failed to lookup session, rc:%s\n",
2129 /* Retrieve the device information */
2130 rc = tf_session_get_device(tfs, &dev);
2133 "%s: Failed to lookup device, rc:%s\n",
2139 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2142 "%s: Unable to lookup FW id, rc:%s\n",
2148 /* Populate the request */
2149 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2150 req.flags = tfp_cpu_to_le_16(dir);
2151 req.type = tfp_cpu_to_le_32(hcapi_type);
2152 req.start_index = tfp_cpu_to_le_32(starting_idx);
2153 req.num_entries = tfp_cpu_to_le_32(num_entries);
2155 data_size = num_entries * entry_sz_in_bytes;
2157 req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
2159 parms.tf_type = HWRM_TF_TBL_TYPE_BULK_GET;
2160 parms.req_data = (uint32_t *)&req;
2161 parms.req_size = sizeof(req);
2162 parms.resp_data = (uint32_t *)&resp;
2163 parms.resp_size = sizeof(resp);
2164 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2166 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
2171 /* Verify that we got enough buffer to return the requested data */
2172 if (tfp_le_to_cpu_32(resp.size) != data_size)
2179 tf_msg_get_if_tbl_entry(struct tf *tfp,
2180 struct tf_if_tbl_get_parms *params)
2183 struct tfp_send_msg_parms parms = { 0 };
2184 struct hwrm_tf_if_tbl_get_input req = { 0 };
2185 struct hwrm_tf_if_tbl_get_output resp = { 0 };
2187 struct tf_dev_info *dev;
2188 struct tf_session *tfs;
2190 /* Retrieve the session information */
2191 rc = tf_session_get_session(tfp, &tfs);
2194 "%s: Failed to lookup session, rc:%s\n",
2195 tf_dir_2_str(params->dir),
2200 /* Retrieve the device information */
2201 rc = tf_session_get_device(tfs, &dev);
2204 "%s: Failed to lookup device, rc:%s\n",
2205 tf_dir_2_str(params->dir),
2210 flags = (params->dir == TF_DIR_TX ?
2211 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
2212 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
2214 /* Populate the request */
2216 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2218 req.type = params->hcapi_type;
2219 req.index = tfp_cpu_to_le_16(params->idx);
2220 req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
2222 parms.tf_type = HWRM_TF_IF_TBL_GET;
2223 parms.req_data = (uint32_t *)&req;
2224 parms.req_size = sizeof(req);
2225 parms.resp_data = (uint32_t *)&resp;
2226 parms.resp_size = sizeof(resp);
2227 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2229 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2234 tfp_memcpy(¶ms->data[0], resp.data, req.size);
2240 tf_msg_set_if_tbl_entry(struct tf *tfp,
2241 struct tf_if_tbl_set_parms *params)
2244 struct tfp_send_msg_parms parms = { 0 };
2245 struct hwrm_tf_if_tbl_set_input req = { 0 };
2246 struct hwrm_tf_if_tbl_get_output resp = { 0 };
2248 struct tf_dev_info *dev;
2249 struct tf_session *tfs;
2251 /* Retrieve the session information */
2252 rc = tf_session_get_session(tfp, &tfs);
2255 "%s: Failed to lookup session, rc:%s\n",
2256 tf_dir_2_str(params->dir),
2261 /* Retrieve the device information */
2262 rc = tf_session_get_device(tfs, &dev);
2266 flags = (params->dir == TF_DIR_TX ?
2267 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
2268 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
2270 /* Populate the request */
2272 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2274 req.type = params->hcapi_type;
2275 req.index = tfp_cpu_to_le_32(params->idx);
2276 req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
2277 tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
2279 parms.tf_type = HWRM_TF_IF_TBL_SET;
2280 parms.req_data = (uint32_t *)&req;
2281 parms.req_size = sizeof(req);
2282 parms.resp_data = (uint32_t *)&resp;
2283 parms.resp_size = sizeof(resp);
2284 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2286 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);