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 * If data bigger than TF_PCI_BUF_SIZE_MAX then use DMA method
64 struct tf_msg_dma_buf {
70 * Allocates a DMA buffer that can be used for message transfer.
73 * Pointer to DMA buffer structure
76 * Requested size of the buffer in bytes
80 * -ENOMEM - Unable to allocate buffer, no memory
83 tf_msg_alloc_dma_buf(struct tf_msg_dma_buf *buf, int size)
85 struct tfp_calloc_parms alloc_parms;
88 /* Allocate session */
89 alloc_parms.nitems = 1;
90 alloc_parms.size = size;
91 alloc_parms.alignment = 4096;
92 rc = tfp_calloc(&alloc_parms);
96 buf->pa_addr = (uintptr_t)alloc_parms.mem_pa;
97 buf->va_addr = alloc_parms.mem_va;
103 * Free's a previous allocated DMA buffer.
106 * Pointer to DMA buffer structure
109 tf_msg_free_dma_buf(struct tf_msg_dma_buf *buf)
111 tfp_free(buf->va_addr);
114 /* HWRM Direct messages */
117 tf_msg_session_open(struct bnxt *bp,
118 char *ctrl_chan_name,
119 uint8_t *fw_session_id,
120 uint8_t *fw_session_client_id,
121 struct tf_dev_info *dev,
122 bool *shared_session_creator)
125 struct hwrm_tf_session_open_input req = { 0 };
126 struct hwrm_tf_session_open_output resp = { 0 };
127 struct tfp_send_msg_parms parms = { 0 };
131 /* Populate the request */
132 name_len = strnlen(ctrl_chan_name, TF_SESSION_NAME_MAX);
133 name = &ctrl_chan_name[name_len - strlen("tf_shared")];
134 if (!strncmp(name, "tf_shared", strlen("tf_shared")))
135 tfp_memcpy(&req.session_name, name, strlen("tf_share"));
137 tfp_memcpy(&req.session_name, ctrl_chan_name, TF_SESSION_NAME_MAX);
139 parms.tf_type = HWRM_TF_SESSION_OPEN;
140 parms.req_data = (uint32_t *)&req;
141 parms.req_size = sizeof(req);
142 parms.resp_data = (uint32_t *)&resp;
143 parms.resp_size = sizeof(resp);
144 parms.mailbox = dev->ops->tf_dev_get_mailbox();
146 rc = tfp_send_msg_direct(bp,
151 *fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
152 *fw_session_client_id =
153 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
154 *shared_session_creator = (bool)tfp_le_to_cpu_32(resp.flags
155 & HWRM_TF_SESSION_OPEN_OUTPUT_FLAGS_SHARED_SESSION_CREATOR);
161 tf_msg_session_attach(struct tf *tfp __rte_unused,
162 char *ctrl_chan_name __rte_unused,
163 uint8_t tf_fw_session_id __rte_unused)
169 tf_msg_session_client_register(struct tf *tfp,
170 struct tf_session *tfs,
171 char *ctrl_channel_name,
172 uint8_t *fw_session_client_id)
175 struct hwrm_tf_session_register_input req = { 0 };
176 struct hwrm_tf_session_register_output resp = { 0 };
177 struct tfp_send_msg_parms parms = { 0 };
178 uint8_t fw_session_id;
179 struct tf_dev_info *dev;
181 /* Retrieve the device information */
182 rc = tf_session_get_device(tfs, &dev);
185 "Failed to lookup device, rc:%s\n",
190 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
193 "Unable to lookup FW id, rc:%s\n",
198 /* Populate the request */
199 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
200 tfp_memcpy(&req.session_client_name,
202 TF_SESSION_NAME_MAX);
204 parms.tf_type = HWRM_TF_SESSION_REGISTER;
205 parms.req_data = (uint32_t *)&req;
206 parms.req_size = sizeof(req);
207 parms.resp_data = (uint32_t *)&resp;
208 parms.resp_size = sizeof(resp);
209 parms.mailbox = dev->ops->tf_dev_get_mailbox();
211 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
216 *fw_session_client_id =
217 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
223 tf_msg_session_client_unregister(struct tf *tfp,
224 struct tf_session *tfs,
225 uint8_t fw_session_client_id)
228 struct hwrm_tf_session_unregister_input req = { 0 };
229 struct hwrm_tf_session_unregister_output resp = { 0 };
230 struct tfp_send_msg_parms parms = { 0 };
231 uint8_t fw_session_id;
232 struct tf_dev_info *dev;
234 /* Retrieve the device information */
235 rc = tf_session_get_device(tfs, &dev);
238 "Failed to lookup device, rc:%s\n",
243 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
246 "Unable to lookup FW id, rc:%s\n",
251 /* Populate the request */
252 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
253 req.fw_session_client_id = tfp_cpu_to_le_32(fw_session_client_id);
255 parms.tf_type = HWRM_TF_SESSION_UNREGISTER;
256 parms.req_data = (uint32_t *)&req;
257 parms.req_size = sizeof(req);
258 parms.resp_data = (uint32_t *)&resp;
259 parms.resp_size = sizeof(resp);
260 parms.mailbox = dev->ops->tf_dev_get_mailbox();
262 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
269 tf_msg_session_close(struct tf *tfp,
270 struct tf_session *tfs)
273 struct hwrm_tf_session_close_input req = { 0 };
274 struct hwrm_tf_session_close_output resp = { 0 };
275 struct tfp_send_msg_parms parms = { 0 };
276 uint8_t fw_session_id;
277 struct tf_dev_info *dev;
279 /* Retrieve the device information */
280 rc = tf_session_get_device(tfs, &dev);
283 "Failed to lookup device, rc:%s\n",
288 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
291 "Unable to lookup FW id, rc:%s\n",
296 /* Populate the request */
297 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
299 parms.tf_type = HWRM_TF_SESSION_CLOSE;
300 parms.req_data = (uint32_t *)&req;
301 parms.req_size = sizeof(req);
302 parms.resp_data = (uint32_t *)&resp;
303 parms.resp_size = sizeof(resp);
304 parms.mailbox = dev->ops->tf_dev_get_mailbox();
306 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
312 tf_msg_session_qcfg(struct tf *tfp)
315 struct hwrm_tf_session_qcfg_input req = { 0 };
316 struct hwrm_tf_session_qcfg_output resp = { 0 };
317 struct tfp_send_msg_parms parms = { 0 };
318 uint8_t fw_session_id;
319 struct tf_dev_info *dev;
320 struct tf_session *tfs;
322 /* Retrieve the session information */
323 rc = tf_session_get_session_internal(tfp, &tfs);
326 "Failed to lookup session, rc:%s\n",
331 /* Retrieve the device information */
332 rc = tf_session_get_device(tfs, &dev);
335 "Failed to lookup device, rc:%s\n",
340 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
343 "Unable to lookup FW id, rc:%s\n",
348 /* Populate the request */
349 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
351 parms.tf_type = HWRM_TF_SESSION_QCFG,
352 parms.req_data = (uint32_t *)&req;
353 parms.req_size = sizeof(req);
354 parms.resp_data = (uint32_t *)&resp;
355 parms.resp_size = sizeof(resp);
356 parms.mailbox = dev->ops->tf_dev_get_mailbox();
358 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
364 tf_msg_session_resc_qcaps(struct tf *tfp,
365 struct tf_dev_info *dev,
368 struct tf_rm_resc_req_entry *query,
369 enum tf_rm_resc_resv_strategy *resv_strategy)
373 struct tfp_send_msg_parms parms = { 0 };
374 struct hwrm_tf_session_resc_qcaps_input req = { 0 };
375 struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
376 uint8_t fw_session_id;
377 struct tf_msg_dma_buf qcaps_buf = { 0 };
378 struct tf_rm_resc_req_entry *data;
380 struct tf_session *tfs;
382 /* Retrieve the session information */
383 rc = tf_session_get_session_internal(tfp, &tfs);
386 "Failed to lookup session, rc:%s\n",
391 TF_CHECK_PARMS3(tfp, query, resv_strategy);
393 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
396 "%s: Unable to lookup FW id, rc:%s\n",
402 /* Prepare DMA buffer */
403 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
404 rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
408 /* Populate the request */
409 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
410 req.flags = tfp_cpu_to_le_16(dir);
411 req.qcaps_size = size;
412 req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
414 parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
415 parms.req_data = (uint32_t *)&req;
416 parms.req_size = sizeof(req);
417 parms.resp_data = (uint32_t *)&resp;
418 parms.resp_size = sizeof(resp);
419 parms.mailbox = dev->ops->tf_dev_get_mailbox();
421 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
425 /* Process the response
426 * Should always get expected number of entries
428 if (tfp_le_to_cpu_32(resp.size) != size) {
430 "%s: QCAPS message size error, rc:%s\n",
437 /* Post process the response */
438 data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
440 for (i = 0; i < size; i++) {
441 query[i].type = tfp_le_to_cpu_32(data[i].type);
442 query[i].min = tfp_le_to_cpu_16(data[i].min);
443 query[i].max = tfp_le_to_cpu_16(data[i].max);
446 *resv_strategy = resp.flags &
447 HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
450 tf_msg_free_dma_buf(&qcaps_buf);
456 tf_msg_session_resc_alloc(struct tf *tfp,
457 struct tf_dev_info *dev,
460 struct tf_rm_resc_req_entry *request,
461 struct tf_rm_resc_entry *resv)
465 struct tfp_send_msg_parms parms = { 0 };
466 struct hwrm_tf_session_resc_alloc_input req = { 0 };
467 struct hwrm_tf_session_resc_alloc_output resp = { 0 };
468 uint8_t fw_session_id;
469 struct tf_msg_dma_buf req_buf = { 0 };
470 struct tf_msg_dma_buf resv_buf = { 0 };
471 struct tf_rm_resc_req_entry *req_data;
472 struct tf_rm_resc_entry *resv_data;
474 struct tf_session *tfs;
476 /* Retrieve the session information */
477 rc = tf_session_get_session_internal(tfp, &tfs);
480 "Failed to lookup session, rc:%s\n",
485 TF_CHECK_PARMS3(tfp, request, resv);
487 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
490 "%s: Unable to lookup FW id, rc:%s\n",
496 /* Prepare DMA buffers */
497 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
498 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
502 dma_size = size * sizeof(struct tf_rm_resc_entry);
503 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
505 tf_msg_free_dma_buf(&req_buf);
509 /* Populate the request */
510 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
511 req.flags = tfp_cpu_to_le_16(dir);
514 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
515 for (i = 0; i < size; i++) {
516 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
517 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
518 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
521 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
522 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
524 parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
525 parms.req_data = (uint32_t *)&req;
526 parms.req_size = sizeof(req);
527 parms.resp_data = (uint32_t *)&resp;
528 parms.resp_size = sizeof(resp);
529 parms.mailbox = dev->ops->tf_dev_get_mailbox();
531 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
535 /* Process the response
536 * Should always get expected number of entries
538 if (tfp_le_to_cpu_32(resp.size) != size) {
540 "%s: Alloc message size error, rc:%s\n",
547 /* Post process the response */
548 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
549 for (i = 0; i < size; i++) {
550 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
551 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
552 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
556 tf_msg_free_dma_buf(&req_buf);
557 tf_msg_free_dma_buf(&resv_buf);
563 tf_msg_session_resc_info(struct tf *tfp,
564 struct tf_dev_info *dev,
567 struct tf_rm_resc_req_entry *request,
568 struct tf_rm_resc_entry *resv)
572 struct tfp_send_msg_parms parms = { 0 };
573 struct hwrm_tf_session_resc_info_input req = { 0 };
574 struct hwrm_tf_session_resc_info_output resp = { 0 };
575 uint8_t fw_session_id;
576 struct tf_msg_dma_buf req_buf = { 0 };
577 struct tf_msg_dma_buf resv_buf = { 0 };
578 struct tf_rm_resc_req_entry *req_data;
579 struct tf_rm_resc_entry *resv_data;
581 struct tf_session *tfs;
583 /* Retrieve the session information */
584 rc = tf_session_get_session_internal(tfp, &tfs);
587 "Failed to lookup session, rc:%s\n",
592 TF_CHECK_PARMS3(tfp, request, resv);
594 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
597 "%s: Unable to lookup FW id, rc:%s\n",
603 /* Prepare DMA buffers */
604 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
605 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
609 dma_size = size * sizeof(struct tf_rm_resc_entry);
610 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
612 tf_msg_free_dma_buf(&req_buf);
616 /* Populate the request */
617 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
618 req.flags = tfp_cpu_to_le_16(dir);
621 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
622 for (i = 0; i < size; i++) {
623 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
624 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
625 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
628 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
629 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
631 parms.tf_type = HWRM_TF_SESSION_RESC_INFO;
632 parms.req_data = (uint32_t *)&req;
633 parms.req_size = sizeof(req);
634 parms.resp_data = (uint32_t *)&resp;
635 parms.resp_size = sizeof(resp);
636 parms.mailbox = dev->ops->tf_dev_get_mailbox();
638 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
642 /* Process the response
643 * Should always get expected number of entries
645 if (tfp_le_to_cpu_32(resp.size) != size) {
647 "%s: Alloc message size error, rc:%s\n",
654 /* Post process the response */
655 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
656 for (i = 0; i < size; i++) {
657 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
658 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
659 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
663 tf_msg_free_dma_buf(&req_buf);
664 tf_msg_free_dma_buf(&resv_buf);
670 tf_msg_session_resc_flush(struct tf *tfp,
673 struct tf_rm_resc_entry *resv)
677 struct tfp_send_msg_parms parms = { 0 };
678 struct hwrm_tf_session_resc_flush_input req = { 0 };
679 struct hwrm_tf_session_resc_flush_output resp = { 0 };
680 uint8_t fw_session_id;
681 struct tf_msg_dma_buf resv_buf = { 0 };
682 struct tf_rm_resc_entry *resv_data;
684 struct tf_dev_info *dev;
685 struct tf_session *tfs;
687 TF_CHECK_PARMS2(tfp, resv);
689 /* Retrieve the session information */
690 rc = tf_session_get_session_internal(tfp, &tfs);
693 "%s: Failed to lookup session, rc:%s\n",
699 /* Retrieve the device information */
700 rc = tf_session_get_device(tfs, &dev);
703 "%s: Failed to lookup device, rc:%s\n",
709 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
712 "%s: Unable to lookup FW id, rc:%s\n",
718 /* Prepare DMA buffers */
719 dma_size = size * sizeof(struct tf_rm_resc_entry);
720 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
724 /* Populate the request */
725 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
726 req.flags = tfp_cpu_to_le_16(dir);
727 req.flush_size = size;
729 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
730 for (i = 0; i < size; i++) {
731 resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
732 resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
733 resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
736 req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
738 parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
739 parms.req_data = (uint32_t *)&req;
740 parms.req_size = sizeof(req);
741 parms.resp_data = (uint32_t *)&resp;
742 parms.resp_size = sizeof(resp);
743 parms.mailbox = dev->ops->tf_dev_get_mailbox();
745 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
747 tf_msg_free_dma_buf(&resv_buf);
753 tf_msg_insert_em_internal_entry(struct tf *tfp,
754 struct tf_insert_em_entry_parms *em_parms,
755 uint16_t *rptr_index,
757 uint8_t *num_of_entries)
760 struct tfp_send_msg_parms parms = { 0 };
761 struct hwrm_tf_em_insert_input req = { 0 };
762 struct hwrm_tf_em_insert_output resp = { 0 };
763 struct tf_em_64b_entry *em_result =
764 (struct tf_em_64b_entry *)em_parms->em_record;
766 uint8_t fw_session_id;
767 uint8_t msg_key_size;
768 struct tf_dev_info *dev;
769 struct tf_session *tfs;
771 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
772 TF_MSG_SIZE_HWRM_TF_EM_INSERT);
774 /* Retrieve the session information */
775 rc = tf_session_get_session_internal(tfp, &tfs);
778 "%s: Failed to lookup session, rc:%s\n",
779 tf_dir_2_str(em_parms->dir),
784 /* Retrieve the device information */
785 rc = tf_session_get_device(tfs, &dev);
788 "%s: Failed to lookup device, rc:%s\n",
789 tf_dir_2_str(em_parms->dir),
794 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
797 "%s: Unable to lookup FW id, rc:%s\n",
798 tf_dir_2_str(em_parms->dir),
803 /* Populate the request */
804 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
806 /* Check for key size conformity */
807 msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
808 if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
811 "%s: Invalid parameters for msg type, rc:%s\n",
812 tf_dir_2_str(em_parms->dir),
817 tfp_memcpy(req.em_key,
821 flags = (em_parms->dir == TF_DIR_TX ?
822 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
823 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
824 req.flags = tfp_cpu_to_le_16(flags);
825 req.strength = (em_result->hdr.word1 &
826 CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
827 CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
828 req.em_key_bitlen = em_parms->key_sz_in_bits;
829 req.action_ptr = em_result->hdr.pointer;
830 req.em_record_idx = *rptr_index;
832 parms.tf_type = HWRM_TF_EM_INSERT;
833 parms.req_data = (uint32_t *)&req;
834 parms.req_size = sizeof(req);
835 parms.resp_data = (uint32_t *)&resp;
836 parms.resp_size = sizeof(resp);
837 parms.mailbox = dev->ops->tf_dev_get_mailbox();
839 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
844 *rptr_entry = resp.rptr_entry;
845 *rptr_index = resp.rptr_index;
846 *num_of_entries = resp.num_of_entries;
852 tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
853 struct tf_insert_em_entry_parms *em_parms,
856 uint16_t *rptr_index,
858 uint8_t *num_of_entries)
861 struct tfp_send_msg_parms parms = { 0 };
862 struct hwrm_tf_em_hash_insert_input req = { 0 };
863 struct hwrm_tf_em_hash_insert_output resp = { 0 };
865 uint8_t fw_session_id;
866 uint8_t msg_record_size;
867 struct tf_dev_info *dev;
868 struct tf_session *tfs;
870 /* Retrieve the session information */
871 rc = tf_session_get_session_internal(tfp, &tfs);
874 "%s: Failed to lookup session, rc:%s\n",
875 tf_dir_2_str(em_parms->dir),
880 /* Retrieve the device information */
881 rc = tf_session_get_device(tfs, &dev);
884 "%s: Failed to lookup device, rc:%s\n",
885 tf_dir_2_str(em_parms->dir),
890 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
893 "%s: Unable to lookup FW id, rc:%s\n",
894 tf_dir_2_str(em_parms->dir),
899 /* Populate the request */
900 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
902 /* Check for key size conformity */
903 msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
905 if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
908 "%s: Record size to large, rc:%s\n",
909 tf_dir_2_str(em_parms->dir),
914 tfp_memcpy((char *)req.em_record,
918 flags = (em_parms->dir == TF_DIR_TX ?
919 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
920 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
921 req.flags = tfp_cpu_to_le_16(flags);
922 req.em_record_size_bits = em_parms->em_record_sz_in_bits;
923 req.em_record_idx = *rptr_index;
924 req.key0_hash = key0_hash;
925 req.key1_hash = key1_hash;
927 parms.tf_type = HWRM_TF_EM_HASH_INSERT;
928 parms.req_data = (uint32_t *)&req;
929 parms.req_size = sizeof(req);
930 parms.resp_data = (uint32_t *)&resp;
931 parms.resp_size = sizeof(resp);
932 parms.mailbox = dev->ops->tf_dev_get_mailbox();
934 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
939 *rptr_entry = resp.rptr_entry;
940 *rptr_index = resp.rptr_index;
941 *num_of_entries = resp.num_of_entries;
947 tf_msg_delete_em_entry(struct tf *tfp,
948 struct tf_delete_em_entry_parms *em_parms)
951 struct tfp_send_msg_parms parms = { 0 };
952 struct hwrm_tf_em_delete_input req = { 0 };
953 struct hwrm_tf_em_delete_output resp = { 0 };
955 uint8_t fw_session_id;
956 struct tf_dev_info *dev;
957 struct tf_session *tfs;
959 /* Retrieve the session information */
960 rc = tf_session_get_session_internal(tfp, &tfs);
963 "%s: Failed to lookup session, rc:%s\n",
964 tf_dir_2_str(em_parms->dir),
969 /* Retrieve the device information */
970 rc = tf_session_get_device(tfs, &dev);
973 "%s: Failed to lookup device, rc:%s\n",
974 tf_dir_2_str(em_parms->dir),
979 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
982 "%s: Unable to lookup FW id, rc:%s\n",
983 tf_dir_2_str(em_parms->dir),
988 /* Populate the request */
989 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
991 flags = (em_parms->dir == TF_DIR_TX ?
992 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
993 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
994 req.flags = tfp_cpu_to_le_16(flags);
995 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
997 parms.tf_type = HWRM_TF_EM_DELETE;
998 parms.req_data = (uint32_t *)&req;
999 parms.req_size = sizeof(req);
1000 parms.resp_data = (uint32_t *)&resp;
1001 parms.resp_size = sizeof(resp);
1002 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1004 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1009 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1015 tf_msg_move_em_entry(struct tf *tfp,
1016 struct tf_move_em_entry_parms *em_parms)
1019 struct tfp_send_msg_parms parms = { 0 };
1020 struct hwrm_tf_em_move_input req = { 0 };
1021 struct hwrm_tf_em_move_output resp = { 0 };
1023 uint8_t fw_session_id;
1024 struct tf_dev_info *dev;
1025 struct tf_session *tfs;
1027 /* Retrieve the session information */
1028 rc = tf_session_get_session_internal(tfp, &tfs);
1031 "%s: Failed to lookup session, rc:%s\n",
1032 tf_dir_2_str(em_parms->dir),
1037 /* Retrieve the device information */
1038 rc = tf_session_get_device(tfs, &dev);
1041 "%s: Failed to lookup device, rc:%s\n",
1042 tf_dir_2_str(em_parms->dir),
1047 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1050 "%s: Unable to lookup FW id, rc:%s\n",
1051 tf_dir_2_str(em_parms->dir),
1056 /* Populate the request */
1057 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1059 flags = (em_parms->dir == TF_DIR_TX ?
1060 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
1061 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
1062 req.flags = tfp_cpu_to_le_16(flags);
1063 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
1064 req.new_index = tfp_cpu_to_le_32(em_parms->new_index);
1066 parms.tf_type = HWRM_TF_EM_MOVE;
1067 parms.req_data = (uint32_t *)&req;
1068 parms.req_size = sizeof(req);
1069 parms.resp_data = (uint32_t *)&resp;
1070 parms.resp_size = sizeof(resp);
1071 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1073 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1078 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1083 int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
1084 struct hcapi_cfa_em_table *tbl,
1087 uint32_t *page_size)
1089 struct tfp_send_msg_parms parms = { 0 };
1090 struct hwrm_tf_ctxt_mem_alloc_input req = {0};
1091 struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
1092 uint32_t mem_size_k;
1094 struct tf_dev_info *dev;
1095 struct tf_session *tfs;
1098 /* Retrieve the session information */
1099 rc = tf_session_get_session_internal(tfp, &tfs);
1102 "Failed to lookup session, rc:%s\n",
1107 /* Retrieve the device information */
1108 rc = tf_session_get_device(tfs, &dev);
1111 "Failed to lookup device, rc:%s\n",
1115 /* Retrieve the session information */
1116 fw_se_id = tfs->session_id.internal.fw_session_id;
1118 if (tbl->num_entries && tbl->entry_size) {
1120 mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
1121 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1122 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1123 parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
1124 parms.req_data = (uint32_t *)&req;
1125 parms.req_size = sizeof(req);
1126 parms.resp_data = (uint32_t *)&resp;
1127 parms.resp_size = sizeof(resp);
1128 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1129 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1131 TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
1136 *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
1137 *page_lvl = resp.page_level;
1138 *page_size = resp.page_size;
1144 int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
1145 uint32_t mem_size_k,
1150 struct tfp_send_msg_parms parms = { 0 };
1151 struct hwrm_tf_ctxt_mem_free_input req = {0};
1152 struct hwrm_tf_ctxt_mem_free_output resp = {0};
1154 struct tf_dev_info *dev;
1155 struct tf_session *tfs;
1158 /* Retrieve the session information */
1159 rc = tf_session_get_session_internal(tfp, &tfs);
1162 "Failed to lookup session, rc:%s\n",
1167 /* Retrieve the device information */
1168 rc = tf_session_get_device(tfs, &dev);
1171 "Failed to lookup device, rc:%s\n",
1175 /* Retrieve the session information */
1176 fw_se_id = tfs->session_id.internal.fw_session_id;
1178 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1179 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1180 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1181 req.page_level = page_level;
1182 req.page_size = page_size;
1183 parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
1184 parms.req_data = (uint32_t *)&req;
1185 parms.req_size = sizeof(req);
1186 parms.resp_data = (uint32_t *)&resp;
1187 parms.resp_size = sizeof(resp);
1188 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1189 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1195 tf_msg_em_mem_rgtr(struct tf *tfp,
1202 struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
1203 struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
1204 struct tfp_send_msg_parms parms = { 0 };
1205 struct tf_dev_info *dev;
1206 struct tf_session *tfs;
1209 /* Retrieve the session information */
1210 rc = tf_session_get_session_internal(tfp, &tfs);
1213 "Failed to lookup session, rc:%s\n",
1218 /* Retrieve the device information */
1219 rc = tf_session_get_device(tfs, &dev);
1222 "Failed to lookup device, rc:%s\n",
1226 fw_se_id = tfs->session_id.internal.fw_session_id;
1228 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1229 req.page_level = page_lvl;
1230 req.page_size = page_size;
1231 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1233 parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
1234 parms.req_data = (uint32_t *)&req;
1235 parms.req_size = sizeof(req);
1236 parms.resp_data = (uint32_t *)&resp;
1237 parms.resp_size = sizeof(resp);
1238 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1240 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1245 *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
1251 tf_msg_em_mem_unrgtr(struct tf *tfp,
1255 struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
1256 struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
1257 struct tfp_send_msg_parms parms = { 0 };
1258 struct tf_dev_info *dev;
1259 struct tf_session *tfs;
1262 /* Retrieve the session information */
1263 rc = tf_session_get_session_internal(tfp, &tfs);
1266 "Failed to lookup session, rc:%s\n",
1271 /* Retrieve the device information */
1272 rc = tf_session_get_device(tfs, &dev);
1275 "Failed to lookup device, rc:%s\n",
1280 fw_se_id = tfs->session_id.internal.fw_session_id;
1281 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1283 req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
1285 parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
1286 parms.req_data = (uint32_t *)&req;
1287 parms.req_size = sizeof(req);
1288 parms.resp_data = (uint32_t *)&resp;
1289 parms.resp_size = sizeof(resp);
1290 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1292 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1298 tf_msg_em_qcaps(struct tf *tfp,
1300 struct tf_em_caps *em_caps)
1303 struct hwrm_tf_ext_em_qcaps_input req = {0};
1304 struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
1306 struct tfp_send_msg_parms parms = { 0 };
1307 struct tf_dev_info *dev;
1308 struct tf_session *tfs;
1311 /* Retrieve the session information */
1312 rc = tf_session_get_session_internal(tfp, &tfs);
1315 "%s: Failed to lookup session, rc:%s\n",
1320 fw_se_id = tfs->session_id.internal.fw_session_id;
1322 /* Retrieve the device information */
1323 rc = tf_session_get_device(tfs, &dev);
1326 "%s: Failed to lookup device, rc:%s\n",
1332 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
1333 HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
1334 req.flags = tfp_cpu_to_le_32(flags);
1336 parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
1337 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1338 parms.req_data = (uint32_t *)&req;
1339 parms.req_size = sizeof(req);
1340 parms.resp_data = (uint32_t *)&resp;
1341 parms.resp_size = sizeof(resp);
1342 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1344 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1349 em_caps->supported = tfp_le_to_cpu_32(resp.supported);
1350 em_caps->max_entries_supported =
1351 tfp_le_to_cpu_32(resp.max_entries_supported);
1352 em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
1353 em_caps->record_entry_size =
1354 tfp_le_to_cpu_16(resp.record_entry_size);
1355 em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
1361 tf_msg_em_cfg(struct tf *tfp,
1362 uint32_t num_entries,
1363 uint16_t key0_ctx_id,
1364 uint16_t key1_ctx_id,
1365 uint16_t record_ctx_id,
1366 uint16_t efc_ctx_id,
1367 uint8_t flush_interval,
1371 struct hwrm_tf_ext_em_cfg_input req = {0};
1372 struct hwrm_tf_ext_em_cfg_output resp = {0};
1374 struct tfp_send_msg_parms parms = { 0 };
1375 struct tf_dev_info *dev;
1376 struct tf_session *tfs;
1378 /* Retrieve the session information */
1379 rc = tf_session_get_session_internal(tfp, &tfs);
1382 "%s: Failed to lookup session, rc:%s\n",
1388 /* Retrieve the device information */
1389 rc = tf_session_get_device(tfs, &dev);
1392 "%s: Failed to lookup device, rc:%s\n",
1398 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1399 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1400 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1402 req.flags = tfp_cpu_to_le_32(flags);
1403 req.num_entries = tfp_cpu_to_le_32(num_entries);
1405 req.flush_interval = flush_interval;
1407 req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
1408 req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
1409 req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
1410 req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
1412 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1413 parms.req_data = (uint32_t *)&req;
1414 parms.req_size = sizeof(req);
1415 parms.resp_data = (uint32_t *)&resp;
1416 parms.resp_size = sizeof(resp);
1417 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1419 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1425 tf_msg_ext_em_cfg(struct tf *tfp,
1426 struct tf_tbl_scope_cb *tbl_scope_cb,
1427 uint32_t st_buckets,
1428 uint8_t flush_interval,
1431 struct hcapi_cfa_em_ctx_mem_info *ctxp = &tbl_scope_cb->em_ctx_info[dir];
1432 struct hcapi_cfa_em_table *lkup_tbl, *act_tbl;
1433 struct hwrm_tf_ext_em_cfg_input req = {0};
1434 struct hwrm_tf_ext_em_cfg_output resp = {0};
1435 struct tfp_send_msg_parms parms = { 0 };
1437 struct tf_dev_info *dev;
1438 struct tf_session *tfs;
1442 /* Retrieve the session information */
1443 rc = tf_session_get_session_internal(tfp, &tfs);
1446 "%s: Failed to lookup session, rc:%s\n",
1452 /* Retrieve the device information */
1453 rc = tf_session_get_device(tfs, &dev);
1456 "%s: Failed to lookup device, rc:%s\n",
1461 fw_se_id = tfs->session_id.internal.fw_session_id;
1463 lkup_tbl = &ctxp->em_tables[TF_EM_LKUP_TABLE];
1464 act_tbl = &ctxp->em_tables[TF_ACTION_TABLE];
1465 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1466 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1467 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1469 req.flags = tfp_cpu_to_le_32(flags);
1470 req.num_entries = tfp_cpu_to_le_32(act_tbl->num_entries);
1471 req.lkup_static_buckets = tfp_cpu_to_le_32(st_buckets);
1472 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1473 req.flush_interval = flush_interval;
1474 req.action_ctx_id = tfp_cpu_to_le_16(act_tbl->ctx_id);
1475 req.action_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1476 req.lkup_ctx_id = tfp_cpu_to_le_16(lkup_tbl->ctx_id);
1477 req.lkup_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1479 req.enables = (HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_CTX_ID |
1480 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_TBL_SCOPE |
1481 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_CTX_ID |
1482 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_TBL_SCOPE |
1483 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_STATIC_BUCKETS |
1484 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_NUM_ENTRIES);
1486 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1487 parms.req_data = (uint32_t *)&req;
1488 parms.req_size = sizeof(req);
1489 parms.resp_data = (uint32_t *)&resp;
1490 parms.resp_size = sizeof(resp);
1491 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1493 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1499 tf_msg_em_op(struct tf *tfp,
1504 struct hwrm_tf_ext_em_op_input req = {0};
1505 struct hwrm_tf_ext_em_op_output resp = {0};
1507 struct tfp_send_msg_parms parms = { 0 };
1508 struct tf_dev_info *dev;
1509 struct tf_session *tfs;
1511 /* Retrieve the session information */
1512 rc = tf_session_get_session_internal(tfp, &tfs);
1515 "%s: Failed to lookup session, rc:%s\n",
1521 /* Retrieve the device information */
1522 rc = tf_session_get_device(tfs, &dev);
1525 "%s: Failed to lookup device, rc:%s\n",
1531 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1532 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1533 req.flags = tfp_cpu_to_le_32(flags);
1534 req.op = tfp_cpu_to_le_16(op);
1536 parms.tf_type = HWRM_TF_EXT_EM_OP;
1537 parms.req_data = (uint32_t *)&req;
1538 parms.req_size = sizeof(req);
1539 parms.resp_data = (uint32_t *)&resp;
1540 parms.resp_size = sizeof(resp);
1541 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1543 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1549 tf_msg_tcam_entry_set(struct tf *tfp,
1550 struct tf_dev_info *dev,
1551 struct tf_tcam_set_parms *parms)
1554 struct tfp_send_msg_parms mparms = { 0 };
1555 struct hwrm_tf_tcam_set_input req = { 0 };
1556 struct hwrm_tf_tcam_set_output resp = { 0 };
1557 struct tf_msg_dma_buf buf = { 0 };
1558 uint8_t *data = NULL;
1560 uint8_t fw_session_id;
1561 struct tf_session *tfs;
1563 /* Retrieve the session information */
1564 rc = tf_session_get_session_internal(tfp, &tfs);
1567 "Failed to lookup session, rc:%s\n",
1572 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1575 "%s: Unable to lookup FW id, rc:%s\n",
1576 tf_dir_2_str(parms->dir),
1581 /* Populate the request */
1582 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1583 req.type = parms->hcapi_type;
1584 req.idx = tfp_cpu_to_le_16(parms->idx);
1585 if (parms->dir == TF_DIR_TX)
1586 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1588 req.key_size = parms->key_size;
1589 req.mask_offset = parms->key_size;
1590 /* Result follows after key and mask, thus multiply by 2 */
1591 req.result_offset = 2 * parms->key_size;
1592 req.result_size = parms->result_size;
1593 data_size = 2 * req.key_size + req.result_size;
1595 if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1596 /* use pci buffer */
1597 data = &req.dev_data[0];
1599 /* use dma buffer */
1600 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1601 rc = tf_msg_alloc_dma_buf(&buf, data_size);
1605 tfp_memcpy(&req.dev_data[0],
1607 sizeof(buf.pa_addr));
1610 tfp_memcpy(&data[0], parms->key, parms->key_size);
1611 tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1612 tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1614 mparms.tf_type = HWRM_TF_TCAM_SET;
1615 mparms.req_data = (uint32_t *)&req;
1616 mparms.req_size = sizeof(req);
1617 mparms.resp_data = (uint32_t *)&resp;
1618 mparms.resp_size = sizeof(resp);
1619 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1621 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1625 tf_msg_free_dma_buf(&buf);
1631 tf_msg_tcam_entry_get(struct tf *tfp,
1632 struct tf_dev_info *dev,
1633 struct tf_tcam_get_parms *parms)
1636 struct tfp_send_msg_parms mparms = { 0 };
1637 struct hwrm_tf_tcam_get_input req = { 0 };
1638 struct hwrm_tf_tcam_get_output resp = { 0 };
1639 uint8_t fw_session_id;
1640 struct tf_session *tfs;
1642 /* Retrieve the session information */
1643 rc = tf_session_get_session_internal(tfp, &tfs);
1646 "Failed to lookup session, rc:%s\n",
1651 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1654 "%s: Unable to lookup FW id, rc:%s\n",
1655 tf_dir_2_str(parms->dir),
1660 /* Populate the request */
1661 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1662 req.type = parms->hcapi_type;
1663 req.idx = tfp_cpu_to_le_16(parms->idx);
1664 if (parms->dir == TF_DIR_TX)
1665 req.flags |= HWRM_TF_TCAM_GET_INPUT_FLAGS_DIR_TX;
1667 mparms.tf_type = HWRM_TF_TCAM_GET;
1668 mparms.req_data = (uint32_t *)&req;
1669 mparms.req_size = sizeof(req);
1670 mparms.resp_data = (uint32_t *)&resp;
1671 mparms.resp_size = sizeof(resp);
1672 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1674 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1680 if (parms->key_size < resp.key_size ||
1681 parms->result_size < resp.result_size) {
1684 "%s: Key buffer(%d) is smaller than the key(%d), rc:%s\n",
1685 tf_dir_2_str(parms->dir),
1691 parms->key_size = resp.key_size;
1692 parms->result_size = resp.result_size;
1693 tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
1694 tfp_memcpy(parms->mask, &resp.dev_data[resp.key_size], resp.key_size);
1695 tfp_memcpy(parms->result, &resp.dev_data[resp.result_offset], resp.result_size);
1701 tf_msg_tcam_entry_free(struct tf *tfp,
1702 struct tf_dev_info *dev,
1703 struct tf_tcam_free_parms *in_parms)
1706 struct hwrm_tf_tcam_free_input req = { 0 };
1707 struct hwrm_tf_tcam_free_output resp = { 0 };
1708 struct tfp_send_msg_parms parms = { 0 };
1709 uint8_t fw_session_id;
1710 struct tf_session *tfs;
1712 /* Retrieve the session information */
1713 rc = tf_session_get_session_internal(tfp, &tfs);
1716 "Failed to lookup session, rc:%s\n",
1721 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1724 "%s: Unable to lookup FW id, rc:%s\n",
1725 tf_dir_2_str(in_parms->dir),
1730 /* Populate the request */
1731 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1732 req.type = in_parms->hcapi_type;
1734 req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1735 if (in_parms->dir == TF_DIR_TX)
1736 req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1738 parms.tf_type = HWRM_TF_TCAM_FREE;
1739 parms.req_data = (uint32_t *)&req;
1740 parms.req_size = sizeof(req);
1741 parms.resp_data = (uint32_t *)&resp;
1742 parms.resp_size = sizeof(resp);
1743 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1745 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1751 tf_msg_set_tbl_entry(struct tf *tfp,
1753 uint16_t hcapi_type,
1759 struct hwrm_tf_tbl_type_set_input req = { 0 };
1760 struct hwrm_tf_tbl_type_set_output resp = { 0 };
1761 struct tfp_send_msg_parms parms = { 0 };
1762 uint8_t fw_session_id;
1763 struct tf_dev_info *dev;
1764 struct tf_session *tfs;
1766 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_tbl_type_set_input) !=
1767 TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET);
1769 /* Retrieve the session information */
1770 rc = tf_session_get_session_internal(tfp, &tfs);
1773 "%s: Failed to lookup session, rc:%s\n",
1779 /* Retrieve the device information */
1780 rc = tf_session_get_device(tfs, &dev);
1783 "%s: Failed to lookup device, rc:%s\n",
1789 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1792 "%s: Unable to lookup FW id, rc:%s\n",
1798 /* Populate the request */
1799 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1800 req.flags = tfp_cpu_to_le_16(dir);
1801 req.type = tfp_cpu_to_le_32(hcapi_type);
1802 req.size = tfp_cpu_to_le_16(size);
1803 req.index = tfp_cpu_to_le_32(index);
1805 /* Check for data size conformity */
1806 if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1809 "%s: Invalid parameters for msg type, rc:%s\n",
1815 tfp_memcpy(&req.data,
1819 parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1820 parms.req_data = (uint32_t *)&req;
1821 parms.req_size = sizeof(req);
1822 parms.resp_data = (uint32_t *)&resp;
1823 parms.resp_size = sizeof(resp);
1824 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1826 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1835 tf_msg_get_tbl_entry(struct tf *tfp,
1837 uint16_t hcapi_type,
1843 struct hwrm_tf_tbl_type_get_input req = { 0 };
1844 struct hwrm_tf_tbl_type_get_output resp = { 0 };
1845 struct tfp_send_msg_parms parms = { 0 };
1846 uint8_t fw_session_id;
1847 struct tf_dev_info *dev;
1848 struct tf_session *tfs;
1850 /* Retrieve the session information */
1851 rc = tf_session_get_session_internal(tfp, &tfs);
1854 "%s: Failed to lookup session, rc:%s\n",
1860 /* Retrieve the device information */
1861 rc = tf_session_get_device(tfs, &dev);
1864 "%s: Failed to lookup device, rc:%s\n",
1870 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1873 "%s: Unable to lookup FW id, rc:%s\n",
1879 /* Populate the request */
1880 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1881 req.flags = tfp_cpu_to_le_16(dir);
1882 req.type = tfp_cpu_to_le_32(hcapi_type);
1883 req.index = tfp_cpu_to_le_32(index);
1885 parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1886 parms.req_data = (uint32_t *)&req;
1887 parms.req_size = sizeof(req);
1888 parms.resp_data = (uint32_t *)&resp;
1889 parms.resp_size = sizeof(resp);
1890 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1892 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1898 * The response will be 64 bytes long, the response size will
1899 * be in words (16). All we can test for is that the response
1900 * size is < to the requested size.
1902 if ((tfp_le_to_cpu_32(resp.size) * 4) < size)
1906 * Copy the requested number of bytes
1915 /* HWRM Tunneled messages */
1918 tf_msg_get_global_cfg(struct tf *tfp,
1919 struct tf_global_cfg_parms *params)
1922 struct tfp_send_msg_parms parms = { 0 };
1923 struct hwrm_tf_global_cfg_get_input req = { 0 };
1924 struct hwrm_tf_global_cfg_get_output resp = { 0 };
1926 uint8_t fw_session_id;
1927 uint16_t resp_size = 0;
1928 struct tf_dev_info *dev;
1929 struct tf_session *tfs;
1931 /* Retrieve the session information */
1932 rc = tf_session_get_session_internal(tfp, &tfs);
1935 "%s: Failed to lookup session, rc:%s\n",
1936 tf_dir_2_str(params->dir),
1941 /* Retrieve the device information */
1942 rc = tf_session_get_device(tfs, &dev);
1945 "%s: Failed to lookup device, rc:%s\n",
1946 tf_dir_2_str(params->dir),
1951 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1954 "%s: Unable to lookup FW id, rc:%s\n",
1955 tf_dir_2_str(params->dir),
1960 flags = (params->dir == TF_DIR_TX ?
1961 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1962 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1964 /* Populate the request */
1965 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1966 req.flags = tfp_cpu_to_le_32(flags);
1967 req.type = tfp_cpu_to_le_32(params->type);
1968 req.offset = tfp_cpu_to_le_32(params->offset);
1969 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1971 parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
1972 parms.req_data = (uint32_t *)&req;
1973 parms.req_size = sizeof(req);
1974 parms.resp_data = (uint32_t *)&resp;
1975 parms.resp_size = sizeof(resp);
1976 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1978 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1982 /* Verify that we got enough buffer to return the requested data */
1983 resp_size = tfp_le_to_cpu_16(resp.size);
1984 if (resp_size < params->config_sz_in_bytes)
1988 tfp_memcpy(params->config,
1998 tf_msg_set_global_cfg(struct tf *tfp,
1999 struct tf_global_cfg_parms *params)
2002 struct tfp_send_msg_parms parms = { 0 };
2003 struct hwrm_tf_global_cfg_set_input req = { 0 };
2004 struct hwrm_tf_global_cfg_set_output resp = { 0 };
2006 uint8_t fw_session_id;
2007 struct tf_dev_info *dev;
2008 struct tf_session *tfs;
2010 /* Retrieve the session information */
2011 rc = tf_session_get_session_internal(tfp, &tfs);
2014 "%s: Failed to lookup session, rc:%s\n",
2015 tf_dir_2_str(params->dir),
2020 /* Retrieve the device information */
2021 rc = tf_session_get_device(tfs, &dev);
2024 "%s: Failed to lookup device, rc:%s\n",
2025 tf_dir_2_str(params->dir),
2030 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2033 "%s: Unable to lookup FW id, rc:%s\n",
2034 tf_dir_2_str(params->dir),
2039 flags = (params->dir == TF_DIR_TX ?
2040 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
2041 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
2043 /* Populate the request */
2044 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2045 req.flags = tfp_cpu_to_le_32(flags);
2046 req.type = tfp_cpu_to_le_32(params->type);
2047 req.offset = tfp_cpu_to_le_32(params->offset);
2049 /* Check for data size conformity */
2050 if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
2053 "%s: Invalid parameters for msg type, rc:%s\n",
2054 tf_dir_2_str(params->dir),
2059 tfp_memcpy(req.data, params->config,
2060 params->config_sz_in_bytes);
2062 /* Only set mask if pointer is provided
2064 if (params->config_mask) {
2065 tfp_memcpy(req.mask,
2066 params->config_mask,
2067 params->config_sz_in_bytes);
2070 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
2072 parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
2073 parms.req_data = (uint32_t *)&req;
2074 parms.req_size = sizeof(req);
2075 parms.resp_data = (uint32_t *)&resp;
2076 parms.resp_size = sizeof(resp);
2077 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2079 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2088 tf_msg_bulk_get_tbl_entry(struct tf *tfp,
2090 uint16_t hcapi_type,
2091 uint32_t starting_idx,
2092 uint16_t num_entries,
2093 uint16_t entry_sz_in_bytes,
2094 uint64_t physical_mem_addr)
2097 struct tfp_send_msg_parms parms = { 0 };
2098 struct hwrm_tf_tbl_type_bulk_get_input req = { 0 };
2099 struct hwrm_tf_tbl_type_bulk_get_output resp = { 0 };
2101 uint8_t fw_session_id;
2102 struct tf_dev_info *dev;
2103 struct tf_session *tfs;
2105 /* Retrieve the session information */
2106 rc = tf_session_get_session(tfp, &tfs);
2109 "%s: Failed to lookup session, rc:%s\n",
2115 /* Retrieve the device information */
2116 rc = tf_session_get_device(tfs, &dev);
2119 "%s: Failed to lookup device, rc:%s\n",
2125 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2128 "%s: Unable to lookup FW id, rc:%s\n",
2134 /* Populate the request */
2135 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2136 req.flags = tfp_cpu_to_le_16(dir);
2137 req.type = tfp_cpu_to_le_32(hcapi_type);
2138 req.start_index = tfp_cpu_to_le_32(starting_idx);
2139 req.num_entries = tfp_cpu_to_le_32(num_entries);
2141 data_size = num_entries * entry_sz_in_bytes;
2143 req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
2145 parms.tf_type = HWRM_TF_TBL_TYPE_BULK_GET;
2146 parms.req_data = (uint32_t *)&req;
2147 parms.req_size = sizeof(req);
2148 parms.resp_data = (uint32_t *)&resp;
2149 parms.resp_size = sizeof(resp);
2150 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2152 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
2157 /* Verify that we got enough buffer to return the requested data */
2158 if (tfp_le_to_cpu_32(resp.size) != data_size)
2165 tf_msg_get_if_tbl_entry(struct tf *tfp,
2166 struct tf_if_tbl_get_parms *params)
2169 struct tfp_send_msg_parms parms = { 0 };
2170 struct hwrm_tf_if_tbl_get_input req = { 0 };
2171 struct hwrm_tf_if_tbl_get_output resp = { 0 };
2173 struct tf_dev_info *dev;
2174 struct tf_session *tfs;
2176 /* Retrieve the session information */
2177 rc = tf_session_get_session(tfp, &tfs);
2180 "%s: Failed to lookup session, rc:%s\n",
2181 tf_dir_2_str(params->dir),
2186 /* Retrieve the device information */
2187 rc = tf_session_get_device(tfs, &dev);
2190 "%s: Failed to lookup device, rc:%s\n",
2191 tf_dir_2_str(params->dir),
2196 flags = (params->dir == TF_DIR_TX ?
2197 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
2198 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
2200 /* Populate the request */
2202 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2204 req.type = params->hcapi_type;
2205 req.index = tfp_cpu_to_le_16(params->idx);
2206 req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
2208 parms.tf_type = HWRM_TF_IF_TBL_GET;
2209 parms.req_data = (uint32_t *)&req;
2210 parms.req_size = sizeof(req);
2211 parms.resp_data = (uint32_t *)&resp;
2212 parms.resp_size = sizeof(resp);
2213 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2215 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2220 tfp_memcpy(params->data, resp.data, req.size);
2226 tf_msg_set_if_tbl_entry(struct tf *tfp,
2227 struct tf_if_tbl_set_parms *params)
2230 struct tfp_send_msg_parms parms = { 0 };
2231 struct hwrm_tf_if_tbl_set_input req = { 0 };
2232 struct hwrm_tf_if_tbl_get_output resp = { 0 };
2234 struct tf_dev_info *dev;
2235 struct tf_session *tfs;
2237 /* Retrieve the session information */
2238 rc = tf_session_get_session(tfp, &tfs);
2241 "%s: Failed to lookup session, rc:%s\n",
2242 tf_dir_2_str(params->dir),
2247 /* Retrieve the device information */
2248 rc = tf_session_get_device(tfs, &dev);
2252 flags = (params->dir == TF_DIR_TX ?
2253 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
2254 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
2256 /* Populate the request */
2258 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2260 req.type = params->hcapi_type;
2261 req.index = tfp_cpu_to_le_32(params->idx);
2262 req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
2263 tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
2265 parms.tf_type = HWRM_TF_IF_TBL_SET;
2266 parms.req_data = (uint32_t *)&req;
2267 parms.req_size = sizeof(req);
2268 parms.resp_data = (uint32_t *)&resp;
2269 parms.resp_size = sizeof(resp);
2270 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2272 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);