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 uint8_t fw_session_id,
274 struct hwrm_tf_session_close_input req = { 0 };
275 struct hwrm_tf_session_close_output resp = { 0 };
276 struct tfp_send_msg_parms parms = { 0 };
278 /* Populate the request */
279 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
281 parms.tf_type = HWRM_TF_SESSION_CLOSE;
282 parms.req_data = (uint32_t *)&req;
283 parms.req_size = sizeof(req);
284 parms.resp_data = (uint32_t *)&resp;
285 parms.resp_size = sizeof(resp);
286 parms.mailbox = mailbox;
288 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
294 tf_msg_session_qcfg(struct tf *tfp)
297 struct hwrm_tf_session_qcfg_input req = { 0 };
298 struct hwrm_tf_session_qcfg_output resp = { 0 };
299 struct tfp_send_msg_parms parms = { 0 };
300 uint8_t fw_session_id;
301 struct tf_dev_info *dev;
302 struct tf_session *tfs;
304 /* Retrieve the session information */
305 rc = tf_session_get_session_internal(tfp, &tfs);
308 "Failed to lookup session, rc:%s\n",
313 /* Retrieve the device information */
314 rc = tf_session_get_device(tfs, &dev);
317 "Failed to lookup device, rc:%s\n",
322 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
325 "Unable to lookup FW id, rc:%s\n",
330 /* Populate the request */
331 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
333 parms.tf_type = HWRM_TF_SESSION_QCFG,
334 parms.req_data = (uint32_t *)&req;
335 parms.req_size = sizeof(req);
336 parms.resp_data = (uint32_t *)&resp;
337 parms.resp_size = sizeof(resp);
338 parms.mailbox = dev->ops->tf_dev_get_mailbox();
340 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
346 tf_msg_session_resc_qcaps(struct tf *tfp,
347 struct tf_dev_info *dev,
350 struct tf_rm_resc_req_entry *query,
351 enum tf_rm_resc_resv_strategy *resv_strategy)
355 struct tfp_send_msg_parms parms = { 0 };
356 struct hwrm_tf_session_resc_qcaps_input req = { 0 };
357 struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
358 uint8_t fw_session_id;
359 struct tf_msg_dma_buf qcaps_buf = { 0 };
360 struct tf_rm_resc_req_entry *data;
362 struct tf_session *tfs;
364 /* Retrieve the session information */
365 rc = tf_session_get_session_internal(tfp, &tfs);
368 "Failed to lookup session, rc:%s\n",
373 TF_CHECK_PARMS3(tfp, query, resv_strategy);
375 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
378 "%s: Unable to lookup FW id, rc:%s\n",
384 /* Prepare DMA buffer */
385 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
386 rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
390 /* Populate the request */
391 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
392 req.flags = tfp_cpu_to_le_16(dir);
393 req.qcaps_size = size;
394 req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
396 parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
397 parms.req_data = (uint32_t *)&req;
398 parms.req_size = sizeof(req);
399 parms.resp_data = (uint32_t *)&resp;
400 parms.resp_size = sizeof(resp);
401 parms.mailbox = dev->ops->tf_dev_get_mailbox();
403 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
407 /* Process the response
408 * Should always get expected number of entries
410 if (tfp_le_to_cpu_32(resp.size) != size) {
412 "%s: QCAPS message size error, rc:%s\n",
419 /* Post process the response */
420 data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
422 for (i = 0; i < size; i++) {
423 query[i].type = tfp_le_to_cpu_32(data[i].type);
424 query[i].min = tfp_le_to_cpu_16(data[i].min);
425 query[i].max = tfp_le_to_cpu_16(data[i].max);
428 *resv_strategy = resp.flags &
429 HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
432 tf_msg_free_dma_buf(&qcaps_buf);
438 tf_msg_session_resc_alloc(struct tf *tfp,
439 struct tf_dev_info *dev,
442 struct tf_rm_resc_req_entry *request,
443 struct tf_rm_resc_entry *resv)
447 struct tfp_send_msg_parms parms = { 0 };
448 struct hwrm_tf_session_resc_alloc_input req = { 0 };
449 struct hwrm_tf_session_resc_alloc_output resp = { 0 };
450 uint8_t fw_session_id;
451 struct tf_msg_dma_buf req_buf = { 0 };
452 struct tf_msg_dma_buf resv_buf = { 0 };
453 struct tf_rm_resc_req_entry *req_data;
454 struct tf_rm_resc_entry *resv_data;
456 struct tf_session *tfs;
458 /* Retrieve the session information */
459 rc = tf_session_get_session_internal(tfp, &tfs);
462 "Failed to lookup session, rc:%s\n",
467 TF_CHECK_PARMS3(tfp, request, resv);
469 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
472 "%s: Unable to lookup FW id, rc:%s\n",
478 /* Prepare DMA buffers */
479 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
480 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
484 dma_size = size * sizeof(struct tf_rm_resc_entry);
485 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
487 tf_msg_free_dma_buf(&req_buf);
491 /* Populate the request */
492 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
493 req.flags = tfp_cpu_to_le_16(dir);
496 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
497 for (i = 0; i < size; i++) {
498 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
499 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
500 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
503 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
504 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
506 parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
507 parms.req_data = (uint32_t *)&req;
508 parms.req_size = sizeof(req);
509 parms.resp_data = (uint32_t *)&resp;
510 parms.resp_size = sizeof(resp);
511 parms.mailbox = dev->ops->tf_dev_get_mailbox();
513 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
517 /* Process the response
518 * Should always get expected number of entries
520 if (tfp_le_to_cpu_32(resp.size) != size) {
522 "%s: Alloc message size error, rc:%s\n",
529 /* Post process the response */
530 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
531 for (i = 0; i < size; i++) {
532 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
533 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
534 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
538 tf_msg_free_dma_buf(&req_buf);
539 tf_msg_free_dma_buf(&resv_buf);
545 tf_msg_session_resc_info(struct tf *tfp,
546 struct tf_dev_info *dev,
549 struct tf_rm_resc_req_entry *request,
550 struct tf_rm_resc_entry *resv)
554 struct tfp_send_msg_parms parms = { 0 };
555 struct hwrm_tf_session_resc_info_input req = { 0 };
556 struct hwrm_tf_session_resc_info_output resp = { 0 };
557 uint8_t fw_session_id;
558 struct tf_msg_dma_buf req_buf = { 0 };
559 struct tf_msg_dma_buf resv_buf = { 0 };
560 struct tf_rm_resc_req_entry *req_data;
561 struct tf_rm_resc_entry *resv_data;
563 struct tf_session *tfs;
565 /* Retrieve the session information */
566 rc = tf_session_get_session_internal(tfp, &tfs);
569 "Failed to lookup session, rc:%s\n",
574 TF_CHECK_PARMS3(tfp, request, resv);
576 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
579 "%s: Unable to lookup FW id, rc:%s\n",
585 /* Prepare DMA buffers */
586 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
587 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
591 dma_size = size * sizeof(struct tf_rm_resc_entry);
592 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
594 tf_msg_free_dma_buf(&req_buf);
598 /* Populate the request */
599 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
600 req.flags = tfp_cpu_to_le_16(dir);
603 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
604 for (i = 0; i < size; i++) {
605 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
606 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
607 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
610 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
611 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
613 parms.tf_type = HWRM_TF_SESSION_RESC_INFO;
614 parms.req_data = (uint32_t *)&req;
615 parms.req_size = sizeof(req);
616 parms.resp_data = (uint32_t *)&resp;
617 parms.resp_size = sizeof(resp);
618 parms.mailbox = dev->ops->tf_dev_get_mailbox();
620 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
624 /* Process the response
625 * Should always get expected number of entries
627 if (tfp_le_to_cpu_32(resp.size) != size) {
629 "%s: Alloc message size error, rc:%s\n",
636 /* Post process the response */
637 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
638 for (i = 0; i < size; i++) {
639 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
640 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
641 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
645 tf_msg_free_dma_buf(&req_buf);
646 tf_msg_free_dma_buf(&resv_buf);
652 tf_msg_session_resc_flush(struct tf *tfp,
655 struct tf_rm_resc_entry *resv)
659 struct tfp_send_msg_parms parms = { 0 };
660 struct hwrm_tf_session_resc_flush_input req = { 0 };
661 struct hwrm_tf_session_resc_flush_output resp = { 0 };
662 uint8_t fw_session_id;
663 struct tf_msg_dma_buf resv_buf = { 0 };
664 struct tf_rm_resc_entry *resv_data;
666 struct tf_dev_info *dev;
667 struct tf_session *tfs;
669 TF_CHECK_PARMS2(tfp, resv);
671 /* Retrieve the session information */
672 rc = tf_session_get_session_internal(tfp, &tfs);
675 "%s: Failed to lookup session, rc:%s\n",
681 /* Retrieve the device information */
682 rc = tf_session_get_device(tfs, &dev);
685 "%s: Failed to lookup device, rc:%s\n",
691 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
694 "%s: Unable to lookup FW id, rc:%s\n",
700 /* Prepare DMA buffers */
701 dma_size = size * sizeof(struct tf_rm_resc_entry);
702 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
706 /* Populate the request */
707 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
708 req.flags = tfp_cpu_to_le_16(dir);
709 req.flush_size = size;
711 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
712 for (i = 0; i < size; i++) {
713 resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
714 resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
715 resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
718 req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
720 parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
721 parms.req_data = (uint32_t *)&req;
722 parms.req_size = sizeof(req);
723 parms.resp_data = (uint32_t *)&resp;
724 parms.resp_size = sizeof(resp);
725 parms.mailbox = dev->ops->tf_dev_get_mailbox();
727 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
729 tf_msg_free_dma_buf(&resv_buf);
735 tf_msg_insert_em_internal_entry(struct tf *tfp,
736 struct tf_insert_em_entry_parms *em_parms,
737 uint16_t *rptr_index,
739 uint8_t *num_of_entries)
742 struct tfp_send_msg_parms parms = { 0 };
743 struct hwrm_tf_em_insert_input req = { 0 };
744 struct hwrm_tf_em_insert_output resp = { 0 };
745 struct tf_em_64b_entry *em_result =
746 (struct tf_em_64b_entry *)em_parms->em_record;
748 uint8_t fw_session_id;
749 uint8_t msg_key_size;
750 struct tf_dev_info *dev;
751 struct tf_session *tfs;
753 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
754 TF_MSG_SIZE_HWRM_TF_EM_INSERT);
756 /* Retrieve the session information */
757 rc = tf_session_get_session_internal(tfp, &tfs);
760 "%s: Failed to lookup session, rc:%s\n",
761 tf_dir_2_str(em_parms->dir),
766 /* Retrieve the device information */
767 rc = tf_session_get_device(tfs, &dev);
770 "%s: Failed to lookup device, rc:%s\n",
771 tf_dir_2_str(em_parms->dir),
776 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
779 "%s: Unable to lookup FW id, rc:%s\n",
780 tf_dir_2_str(em_parms->dir),
785 /* Populate the request */
786 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
788 /* Check for key size conformity */
789 msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
790 if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
793 "%s: Invalid parameters for msg type, rc:%s\n",
794 tf_dir_2_str(em_parms->dir),
799 tfp_memcpy(req.em_key,
803 flags = (em_parms->dir == TF_DIR_TX ?
804 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
805 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
806 req.flags = tfp_cpu_to_le_16(flags);
807 req.strength = (em_result->hdr.word1 &
808 CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
809 CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
810 req.em_key_bitlen = em_parms->key_sz_in_bits;
811 req.action_ptr = em_result->hdr.pointer;
812 req.em_record_idx = *rptr_index;
814 parms.tf_type = HWRM_TF_EM_INSERT;
815 parms.req_data = (uint32_t *)&req;
816 parms.req_size = sizeof(req);
817 parms.resp_data = (uint32_t *)&resp;
818 parms.resp_size = sizeof(resp);
819 parms.mailbox = dev->ops->tf_dev_get_mailbox();
821 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
826 *rptr_entry = resp.rptr_entry;
827 *rptr_index = resp.rptr_index;
828 *num_of_entries = resp.num_of_entries;
834 tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
835 struct tf_insert_em_entry_parms *em_parms,
838 uint16_t *rptr_index,
840 uint8_t *num_of_entries)
843 struct tfp_send_msg_parms parms = { 0 };
844 struct hwrm_tf_em_hash_insert_input req = { 0 };
845 struct hwrm_tf_em_hash_insert_output resp = { 0 };
847 uint8_t fw_session_id;
848 uint8_t msg_record_size;
849 struct tf_dev_info *dev;
850 struct tf_session *tfs;
852 /* Retrieve the session information */
853 rc = tf_session_get_session_internal(tfp, &tfs);
856 "%s: Failed to lookup session, rc:%s\n",
857 tf_dir_2_str(em_parms->dir),
862 /* Retrieve the device information */
863 rc = tf_session_get_device(tfs, &dev);
866 "%s: Failed to lookup device, rc:%s\n",
867 tf_dir_2_str(em_parms->dir),
872 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
875 "%s: Unable to lookup FW id, rc:%s\n",
876 tf_dir_2_str(em_parms->dir),
881 /* Populate the request */
882 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
884 /* Check for key size conformity */
885 msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
887 if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
890 "%s: Record size to large, rc:%s\n",
891 tf_dir_2_str(em_parms->dir),
896 tfp_memcpy((char *)req.em_record,
900 flags = (em_parms->dir == TF_DIR_TX ?
901 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
902 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
903 req.flags = tfp_cpu_to_le_16(flags);
904 req.em_record_size_bits = em_parms->em_record_sz_in_bits;
905 req.em_record_idx = *rptr_index;
906 req.key0_hash = key0_hash;
907 req.key1_hash = key1_hash;
909 parms.tf_type = HWRM_TF_EM_HASH_INSERT;
910 parms.req_data = (uint32_t *)&req;
911 parms.req_size = sizeof(req);
912 parms.resp_data = (uint32_t *)&resp;
913 parms.resp_size = sizeof(resp);
914 parms.mailbox = dev->ops->tf_dev_get_mailbox();
916 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
921 *rptr_entry = resp.rptr_entry;
922 *rptr_index = resp.rptr_index;
923 *num_of_entries = resp.num_of_entries;
929 tf_msg_delete_em_entry(struct tf *tfp,
930 struct tf_delete_em_entry_parms *em_parms)
933 struct tfp_send_msg_parms parms = { 0 };
934 struct hwrm_tf_em_delete_input req = { 0 };
935 struct hwrm_tf_em_delete_output resp = { 0 };
937 uint8_t fw_session_id;
938 struct tf_dev_info *dev;
939 struct tf_session *tfs;
941 /* Retrieve the session information */
942 rc = tf_session_get_session_internal(tfp, &tfs);
945 "%s: Failed to lookup session, rc:%s\n",
946 tf_dir_2_str(em_parms->dir),
951 /* Retrieve the device information */
952 rc = tf_session_get_device(tfs, &dev);
955 "%s: Failed to lookup device, rc:%s\n",
956 tf_dir_2_str(em_parms->dir),
961 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
964 "%s: Unable to lookup FW id, rc:%s\n",
965 tf_dir_2_str(em_parms->dir),
970 /* Populate the request */
971 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
973 flags = (em_parms->dir == TF_DIR_TX ?
974 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
975 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
976 req.flags = tfp_cpu_to_le_16(flags);
977 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
979 parms.tf_type = HWRM_TF_EM_DELETE;
980 parms.req_data = (uint32_t *)&req;
981 parms.req_size = sizeof(req);
982 parms.resp_data = (uint32_t *)&resp;
983 parms.resp_size = sizeof(resp);
984 parms.mailbox = dev->ops->tf_dev_get_mailbox();
986 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
991 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
997 tf_msg_move_em_entry(struct tf *tfp,
998 struct tf_move_em_entry_parms *em_parms)
1001 struct tfp_send_msg_parms parms = { 0 };
1002 struct hwrm_tf_em_move_input req = { 0 };
1003 struct hwrm_tf_em_move_output resp = { 0 };
1005 uint8_t fw_session_id;
1006 struct tf_dev_info *dev;
1007 struct tf_session *tfs;
1009 /* Retrieve the session information */
1010 rc = tf_session_get_session_internal(tfp, &tfs);
1013 "%s: Failed to lookup session, rc:%s\n",
1014 tf_dir_2_str(em_parms->dir),
1019 /* Retrieve the device information */
1020 rc = tf_session_get_device(tfs, &dev);
1023 "%s: Failed to lookup device, rc:%s\n",
1024 tf_dir_2_str(em_parms->dir),
1029 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1032 "%s: Unable to lookup FW id, rc:%s\n",
1033 tf_dir_2_str(em_parms->dir),
1038 /* Populate the request */
1039 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1041 flags = (em_parms->dir == TF_DIR_TX ?
1042 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
1043 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
1044 req.flags = tfp_cpu_to_le_16(flags);
1045 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
1046 req.new_index = tfp_cpu_to_le_32(em_parms->new_index);
1048 parms.tf_type = HWRM_TF_EM_MOVE;
1049 parms.req_data = (uint32_t *)&req;
1050 parms.req_size = sizeof(req);
1051 parms.resp_data = (uint32_t *)&resp;
1052 parms.resp_size = sizeof(resp);
1053 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1055 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1060 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
1065 int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
1066 struct hcapi_cfa_em_table *tbl,
1069 uint32_t *page_size)
1071 struct tfp_send_msg_parms parms = { 0 };
1072 struct hwrm_tf_ctxt_mem_alloc_input req = {0};
1073 struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
1074 uint32_t mem_size_k;
1076 struct tf_dev_info *dev;
1077 struct tf_session *tfs;
1080 /* Retrieve the session information */
1081 rc = tf_session_get_session_internal(tfp, &tfs);
1084 "Failed to lookup session, rc:%s\n",
1089 /* Retrieve the device information */
1090 rc = tf_session_get_device(tfs, &dev);
1093 "Failed to lookup device, rc:%s\n",
1097 /* Retrieve the session information */
1098 fw_se_id = tfs->session_id.internal.fw_session_id;
1100 if (tbl->num_entries && tbl->entry_size) {
1102 mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
1103 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1104 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1105 parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
1106 parms.req_data = (uint32_t *)&req;
1107 parms.req_size = sizeof(req);
1108 parms.resp_data = (uint32_t *)&resp;
1109 parms.resp_size = sizeof(resp);
1110 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1111 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1113 TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
1118 *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
1119 *page_lvl = resp.page_level;
1120 *page_size = resp.page_size;
1126 int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
1127 uint32_t mem_size_k,
1132 struct tfp_send_msg_parms parms = { 0 };
1133 struct hwrm_tf_ctxt_mem_free_input req = {0};
1134 struct hwrm_tf_ctxt_mem_free_output resp = {0};
1136 struct tf_dev_info *dev;
1137 struct tf_session *tfs;
1140 /* Retrieve the session information */
1141 rc = tf_session_get_session_internal(tfp, &tfs);
1144 "Failed to lookup session, rc:%s\n",
1149 /* Retrieve the device information */
1150 rc = tf_session_get_device(tfs, &dev);
1153 "Failed to lookup device, rc:%s\n",
1157 /* Retrieve the session information */
1158 fw_se_id = tfs->session_id.internal.fw_session_id;
1160 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1161 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
1162 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1163 req.page_level = page_level;
1164 req.page_size = page_size;
1165 parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
1166 parms.req_data = (uint32_t *)&req;
1167 parms.req_size = sizeof(req);
1168 parms.resp_data = (uint32_t *)&resp;
1169 parms.resp_size = sizeof(resp);
1170 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1171 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1177 tf_msg_em_mem_rgtr(struct tf *tfp,
1184 struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
1185 struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
1186 struct tfp_send_msg_parms parms = { 0 };
1187 struct tf_dev_info *dev;
1188 struct tf_session *tfs;
1191 /* Retrieve the session information */
1192 rc = tf_session_get_session_internal(tfp, &tfs);
1195 "Failed to lookup session, rc:%s\n",
1200 /* Retrieve the device information */
1201 rc = tf_session_get_device(tfs, &dev);
1204 "Failed to lookup device, rc:%s\n",
1208 fw_se_id = tfs->session_id.internal.fw_session_id;
1210 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1211 req.page_level = page_lvl;
1212 req.page_size = page_size;
1213 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1215 parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
1216 parms.req_data = (uint32_t *)&req;
1217 parms.req_size = sizeof(req);
1218 parms.resp_data = (uint32_t *)&resp;
1219 parms.resp_size = sizeof(resp);
1220 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1222 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1227 *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
1233 tf_msg_em_mem_unrgtr(struct tf *tfp,
1237 struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
1238 struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
1239 struct tfp_send_msg_parms parms = { 0 };
1240 struct tf_dev_info *dev;
1241 struct tf_session *tfs;
1244 /* Retrieve the session information */
1245 rc = tf_session_get_session_internal(tfp, &tfs);
1248 "Failed to lookup session, rc:%s\n",
1253 /* Retrieve the device information */
1254 rc = tf_session_get_device(tfs, &dev);
1257 "Failed to lookup device, rc:%s\n",
1262 fw_se_id = tfs->session_id.internal.fw_session_id;
1263 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1265 req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
1267 parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
1268 parms.req_data = (uint32_t *)&req;
1269 parms.req_size = sizeof(req);
1270 parms.resp_data = (uint32_t *)&resp;
1271 parms.resp_size = sizeof(resp);
1272 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1274 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1280 tf_msg_em_qcaps(struct tf *tfp,
1282 struct tf_em_caps *em_caps)
1285 struct hwrm_tf_ext_em_qcaps_input req = {0};
1286 struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
1288 struct tfp_send_msg_parms parms = { 0 };
1289 struct tf_dev_info *dev;
1290 struct tf_session *tfs;
1293 /* Retrieve the session information */
1294 rc = tf_session_get_session_internal(tfp, &tfs);
1297 "%s: Failed to lookup session, rc:%s\n",
1302 fw_se_id = tfs->session_id.internal.fw_session_id;
1304 /* Retrieve the device information */
1305 rc = tf_session_get_device(tfs, &dev);
1308 "%s: Failed to lookup device, rc:%s\n",
1314 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
1315 HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
1316 req.flags = tfp_cpu_to_le_32(flags);
1318 parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
1319 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1320 parms.req_data = (uint32_t *)&req;
1321 parms.req_size = sizeof(req);
1322 parms.resp_data = (uint32_t *)&resp;
1323 parms.resp_size = sizeof(resp);
1324 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1326 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1331 em_caps->supported = tfp_le_to_cpu_32(resp.supported);
1332 em_caps->max_entries_supported =
1333 tfp_le_to_cpu_32(resp.max_entries_supported);
1334 em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
1335 em_caps->record_entry_size =
1336 tfp_le_to_cpu_16(resp.record_entry_size);
1337 em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
1343 tf_msg_em_cfg(struct tf *tfp,
1344 uint32_t num_entries,
1345 uint16_t key0_ctx_id,
1346 uint16_t key1_ctx_id,
1347 uint16_t record_ctx_id,
1348 uint16_t efc_ctx_id,
1349 uint8_t flush_interval,
1353 struct hwrm_tf_ext_em_cfg_input req = {0};
1354 struct hwrm_tf_ext_em_cfg_output resp = {0};
1356 struct tfp_send_msg_parms parms = { 0 };
1357 struct tf_dev_info *dev;
1358 struct tf_session *tfs;
1360 /* Retrieve the session information */
1361 rc = tf_session_get_session_internal(tfp, &tfs);
1364 "%s: Failed to lookup session, rc:%s\n",
1370 /* Retrieve the device information */
1371 rc = tf_session_get_device(tfs, &dev);
1374 "%s: Failed to lookup device, rc:%s\n",
1380 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1381 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1382 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1384 req.flags = tfp_cpu_to_le_32(flags);
1385 req.num_entries = tfp_cpu_to_le_32(num_entries);
1387 req.flush_interval = flush_interval;
1389 req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
1390 req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
1391 req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
1392 req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
1394 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1395 parms.req_data = (uint32_t *)&req;
1396 parms.req_size = sizeof(req);
1397 parms.resp_data = (uint32_t *)&resp;
1398 parms.resp_size = sizeof(resp);
1399 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1401 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1407 tf_msg_ext_em_cfg(struct tf *tfp,
1408 struct tf_tbl_scope_cb *tbl_scope_cb,
1409 uint32_t st_buckets,
1410 uint8_t flush_interval,
1413 struct hcapi_cfa_em_ctx_mem_info *ctxp = &tbl_scope_cb->em_ctx_info[dir];
1414 struct hcapi_cfa_em_table *lkup_tbl, *act_tbl;
1415 struct hwrm_tf_ext_em_cfg_input req = {0};
1416 struct hwrm_tf_ext_em_cfg_output resp = {0};
1417 struct tfp_send_msg_parms parms = { 0 };
1419 struct tf_dev_info *dev;
1420 struct tf_session *tfs;
1424 /* Retrieve the session information */
1425 rc = tf_session_get_session_internal(tfp, &tfs);
1428 "%s: Failed to lookup session, rc:%s\n",
1434 /* Retrieve the device information */
1435 rc = tf_session_get_device(tfs, &dev);
1438 "%s: Failed to lookup device, rc:%s\n",
1443 fw_se_id = tfs->session_id.internal.fw_session_id;
1445 lkup_tbl = &ctxp->em_tables[TF_EM_LKUP_TABLE];
1446 act_tbl = &ctxp->em_tables[TF_ACTION_TABLE];
1447 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1448 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1449 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1451 req.flags = tfp_cpu_to_le_32(flags);
1452 req.num_entries = tfp_cpu_to_le_32(act_tbl->num_entries);
1453 req.lkup_static_buckets = tfp_cpu_to_le_32(st_buckets);
1454 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1455 req.flush_interval = flush_interval;
1456 req.action_ctx_id = tfp_cpu_to_le_16(act_tbl->ctx_id);
1457 req.action_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1458 req.lkup_ctx_id = tfp_cpu_to_le_16(lkup_tbl->ctx_id);
1459 req.lkup_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1461 req.enables = (HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_CTX_ID |
1462 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_TBL_SCOPE |
1463 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_CTX_ID |
1464 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_TBL_SCOPE |
1465 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_STATIC_BUCKETS |
1466 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_NUM_ENTRIES);
1468 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1469 parms.req_data = (uint32_t *)&req;
1470 parms.req_size = sizeof(req);
1471 parms.resp_data = (uint32_t *)&resp;
1472 parms.resp_size = sizeof(resp);
1473 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1475 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1481 tf_msg_em_op(struct tf *tfp,
1486 struct hwrm_tf_ext_em_op_input req = {0};
1487 struct hwrm_tf_ext_em_op_output resp = {0};
1489 struct tfp_send_msg_parms parms = { 0 };
1490 struct tf_dev_info *dev;
1491 struct tf_session *tfs;
1493 /* Retrieve the session information */
1494 rc = tf_session_get_session_internal(tfp, &tfs);
1497 "%s: Failed to lookup session, rc:%s\n",
1503 /* Retrieve the device information */
1504 rc = tf_session_get_device(tfs, &dev);
1507 "%s: Failed to lookup device, rc:%s\n",
1513 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1514 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1515 req.flags = tfp_cpu_to_le_32(flags);
1516 req.op = tfp_cpu_to_le_16(op);
1518 parms.tf_type = HWRM_TF_EXT_EM_OP;
1519 parms.req_data = (uint32_t *)&req;
1520 parms.req_size = sizeof(req);
1521 parms.resp_data = (uint32_t *)&resp;
1522 parms.resp_size = sizeof(resp);
1523 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1525 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1531 tf_msg_tcam_entry_set(struct tf *tfp,
1532 struct tf_dev_info *dev,
1533 struct tf_tcam_set_parms *parms)
1536 struct tfp_send_msg_parms mparms = { 0 };
1537 struct hwrm_tf_tcam_set_input req = { 0 };
1538 struct hwrm_tf_tcam_set_output resp = { 0 };
1539 struct tf_msg_dma_buf buf = { 0 };
1540 uint8_t *data = NULL;
1542 uint8_t fw_session_id;
1543 struct tf_session *tfs;
1545 /* Retrieve the session information */
1546 rc = tf_session_get_session_internal(tfp, &tfs);
1549 "Failed to lookup session, rc:%s\n",
1554 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1557 "%s: Unable to lookup FW id, rc:%s\n",
1558 tf_dir_2_str(parms->dir),
1563 /* Populate the request */
1564 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1565 req.type = parms->hcapi_type;
1566 req.idx = tfp_cpu_to_le_16(parms->idx);
1567 if (parms->dir == TF_DIR_TX)
1568 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1570 req.key_size = parms->key_size;
1571 req.mask_offset = parms->key_size;
1572 /* Result follows after key and mask, thus multiply by 2 */
1573 req.result_offset = 2 * parms->key_size;
1574 req.result_size = parms->result_size;
1575 data_size = 2 * req.key_size + req.result_size;
1577 if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1578 /* use pci buffer */
1579 data = &req.dev_data[0];
1581 /* use dma buffer */
1582 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1583 rc = tf_msg_alloc_dma_buf(&buf, data_size);
1587 tfp_memcpy(&req.dev_data[0],
1589 sizeof(buf.pa_addr));
1592 tfp_memcpy(&data[0], parms->key, parms->key_size);
1593 tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1594 tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1596 mparms.tf_type = HWRM_TF_TCAM_SET;
1597 mparms.req_data = (uint32_t *)&req;
1598 mparms.req_size = sizeof(req);
1599 mparms.resp_data = (uint32_t *)&resp;
1600 mparms.resp_size = sizeof(resp);
1601 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1603 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1607 tf_msg_free_dma_buf(&buf);
1613 tf_msg_tcam_entry_get(struct tf *tfp,
1614 struct tf_dev_info *dev,
1615 struct tf_tcam_get_parms *parms)
1618 struct tfp_send_msg_parms mparms = { 0 };
1619 struct hwrm_tf_tcam_get_input req = { 0 };
1620 struct hwrm_tf_tcam_get_output resp = { 0 };
1621 uint8_t fw_session_id;
1622 struct tf_session *tfs;
1624 /* Retrieve the session information */
1625 rc = tf_session_get_session_internal(tfp, &tfs);
1628 "Failed to lookup session, rc:%s\n",
1633 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1636 "%s: Unable to lookup FW id, rc:%s\n",
1637 tf_dir_2_str(parms->dir),
1642 /* Populate the request */
1643 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1644 req.type = parms->hcapi_type;
1645 req.idx = tfp_cpu_to_le_16(parms->idx);
1646 if (parms->dir == TF_DIR_TX)
1647 req.flags |= HWRM_TF_TCAM_GET_INPUT_FLAGS_DIR_TX;
1649 mparms.tf_type = HWRM_TF_TCAM_GET;
1650 mparms.req_data = (uint32_t *)&req;
1651 mparms.req_size = sizeof(req);
1652 mparms.resp_data = (uint32_t *)&resp;
1653 mparms.resp_size = sizeof(resp);
1654 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1656 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1662 if (parms->key_size < resp.key_size ||
1663 parms->result_size < resp.result_size) {
1666 "%s: Key buffer(%d) is smaller than the key(%d), rc:%s\n",
1667 tf_dir_2_str(parms->dir),
1673 parms->key_size = resp.key_size;
1674 parms->result_size = resp.result_size;
1675 tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
1676 tfp_memcpy(parms->mask, &resp.dev_data[resp.key_size], resp.key_size);
1677 tfp_memcpy(parms->result, &resp.dev_data[resp.result_offset], resp.result_size);
1683 tf_msg_tcam_entry_free(struct tf *tfp,
1684 struct tf_dev_info *dev,
1685 struct tf_tcam_free_parms *in_parms)
1688 struct hwrm_tf_tcam_free_input req = { 0 };
1689 struct hwrm_tf_tcam_free_output resp = { 0 };
1690 struct tfp_send_msg_parms parms = { 0 };
1691 uint8_t fw_session_id;
1692 struct tf_session *tfs;
1694 /* Retrieve the session information */
1695 rc = tf_session_get_session_internal(tfp, &tfs);
1698 "Failed to lookup session, rc:%s\n",
1703 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1706 "%s: Unable to lookup FW id, rc:%s\n",
1707 tf_dir_2_str(in_parms->dir),
1712 /* Populate the request */
1713 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1714 req.type = in_parms->hcapi_type;
1716 req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1717 if (in_parms->dir == TF_DIR_TX)
1718 req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1720 parms.tf_type = HWRM_TF_TCAM_FREE;
1721 parms.req_data = (uint32_t *)&req;
1722 parms.req_size = sizeof(req);
1723 parms.resp_data = (uint32_t *)&resp;
1724 parms.resp_size = sizeof(resp);
1725 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1727 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1733 tf_msg_set_tbl_entry(struct tf *tfp,
1735 uint16_t hcapi_type,
1741 struct hwrm_tf_tbl_type_set_input req = { 0 };
1742 struct hwrm_tf_tbl_type_set_output resp = { 0 };
1743 struct tfp_send_msg_parms parms = { 0 };
1744 uint8_t fw_session_id;
1745 struct tf_dev_info *dev;
1746 struct tf_session *tfs;
1748 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_tbl_type_set_input) !=
1749 TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET);
1751 /* Retrieve the session information */
1752 rc = tf_session_get_session_internal(tfp, &tfs);
1755 "%s: Failed to lookup session, rc:%s\n",
1761 /* Retrieve the device information */
1762 rc = tf_session_get_device(tfs, &dev);
1765 "%s: Failed to lookup device, rc:%s\n",
1771 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1774 "%s: Unable to lookup FW id, rc:%s\n",
1780 /* Populate the request */
1781 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1782 req.flags = tfp_cpu_to_le_16(dir);
1783 req.type = tfp_cpu_to_le_32(hcapi_type);
1784 req.size = tfp_cpu_to_le_16(size);
1785 req.index = tfp_cpu_to_le_32(index);
1787 /* Check for data size conformity */
1788 if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1791 "%s: Invalid parameters for msg type, rc:%s\n",
1797 tfp_memcpy(&req.data,
1801 parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1802 parms.req_data = (uint32_t *)&req;
1803 parms.req_size = sizeof(req);
1804 parms.resp_data = (uint32_t *)&resp;
1805 parms.resp_size = sizeof(resp);
1806 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1808 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1817 tf_msg_get_tbl_entry(struct tf *tfp,
1819 uint16_t hcapi_type,
1825 struct hwrm_tf_tbl_type_get_input req = { 0 };
1826 struct hwrm_tf_tbl_type_get_output resp = { 0 };
1827 struct tfp_send_msg_parms parms = { 0 };
1828 uint8_t fw_session_id;
1829 struct tf_dev_info *dev;
1830 struct tf_session *tfs;
1832 /* Retrieve the session information */
1833 rc = tf_session_get_session_internal(tfp, &tfs);
1836 "%s: Failed to lookup session, rc:%s\n",
1842 /* Retrieve the device information */
1843 rc = tf_session_get_device(tfs, &dev);
1846 "%s: Failed to lookup device, rc:%s\n",
1852 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1855 "%s: Unable to lookup FW id, rc:%s\n",
1861 /* Populate the request */
1862 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1863 req.flags = tfp_cpu_to_le_16(dir);
1864 req.type = tfp_cpu_to_le_32(hcapi_type);
1865 req.index = tfp_cpu_to_le_32(index);
1867 parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1868 parms.req_data = (uint32_t *)&req;
1869 parms.req_size = sizeof(req);
1870 parms.resp_data = (uint32_t *)&resp;
1871 parms.resp_size = sizeof(resp);
1872 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1874 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
1880 * The response will be 64 bytes long, the response size will
1881 * be in words (16). All we can test for is that the response
1882 * size is < to the requested size.
1884 if ((tfp_le_to_cpu_32(resp.size) * 4) < size)
1888 * Copy the requested number of bytes
1897 /* HWRM Tunneled messages */
1900 tf_msg_get_global_cfg(struct tf *tfp,
1901 struct tf_global_cfg_parms *params)
1904 struct tfp_send_msg_parms parms = { 0 };
1905 struct hwrm_tf_global_cfg_get_input req = { 0 };
1906 struct hwrm_tf_global_cfg_get_output resp = { 0 };
1908 uint8_t fw_session_id;
1909 uint16_t resp_size = 0;
1910 struct tf_dev_info *dev;
1911 struct tf_session *tfs;
1913 /* Retrieve the session information */
1914 rc = tf_session_get_session_internal(tfp, &tfs);
1917 "%s: Failed to lookup session, rc:%s\n",
1918 tf_dir_2_str(params->dir),
1923 /* Retrieve the device information */
1924 rc = tf_session_get_device(tfs, &dev);
1927 "%s: Failed to lookup device, rc:%s\n",
1928 tf_dir_2_str(params->dir),
1933 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1936 "%s: Unable to lookup FW id, rc:%s\n",
1937 tf_dir_2_str(params->dir),
1942 flags = (params->dir == TF_DIR_TX ?
1943 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1944 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1946 /* Populate the request */
1947 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1948 req.flags = tfp_cpu_to_le_32(flags);
1949 req.type = tfp_cpu_to_le_32(params->type);
1950 req.offset = tfp_cpu_to_le_32(params->offset);
1951 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1953 parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
1954 parms.req_data = (uint32_t *)&req;
1955 parms.req_size = sizeof(req);
1956 parms.resp_data = (uint32_t *)&resp;
1957 parms.resp_size = sizeof(resp);
1958 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1960 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
1964 /* Verify that we got enough buffer to return the requested data */
1965 resp_size = tfp_le_to_cpu_16(resp.size);
1966 if (resp_size < params->config_sz_in_bytes)
1970 tfp_memcpy(params->config,
1980 tf_msg_set_global_cfg(struct tf *tfp,
1981 struct tf_global_cfg_parms *params)
1984 struct tfp_send_msg_parms parms = { 0 };
1985 struct hwrm_tf_global_cfg_set_input req = { 0 };
1986 struct hwrm_tf_global_cfg_set_output resp = { 0 };
1988 uint8_t fw_session_id;
1989 struct tf_dev_info *dev;
1990 struct tf_session *tfs;
1992 /* Retrieve the session information */
1993 rc = tf_session_get_session_internal(tfp, &tfs);
1996 "%s: Failed to lookup session, rc:%s\n",
1997 tf_dir_2_str(params->dir),
2002 /* Retrieve the device information */
2003 rc = tf_session_get_device(tfs, &dev);
2006 "%s: Failed to lookup device, rc:%s\n",
2007 tf_dir_2_str(params->dir),
2012 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2015 "%s: Unable to lookup FW id, rc:%s\n",
2016 tf_dir_2_str(params->dir),
2021 flags = (params->dir == TF_DIR_TX ?
2022 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
2023 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
2025 /* Populate the request */
2026 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2027 req.flags = tfp_cpu_to_le_32(flags);
2028 req.type = tfp_cpu_to_le_32(params->type);
2029 req.offset = tfp_cpu_to_le_32(params->offset);
2031 /* Check for data size conformity */
2032 if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
2035 "%s: Invalid parameters for msg type, rc:%s\n",
2036 tf_dir_2_str(params->dir),
2041 tfp_memcpy(req.data, params->config,
2042 params->config_sz_in_bytes);
2044 /* Only set mask if pointer is provided
2046 if (params->config_mask) {
2047 tfp_memcpy(req.mask,
2048 params->config_mask,
2049 params->config_sz_in_bytes);
2052 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
2054 parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
2055 parms.req_data = (uint32_t *)&req;
2056 parms.req_size = sizeof(req);
2057 parms.resp_data = (uint32_t *)&resp;
2058 parms.resp_size = sizeof(resp);
2059 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2061 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2070 tf_msg_bulk_get_tbl_entry(struct tf *tfp,
2072 uint16_t hcapi_type,
2073 uint32_t starting_idx,
2074 uint16_t num_entries,
2075 uint16_t entry_sz_in_bytes,
2076 uint64_t physical_mem_addr)
2079 struct tfp_send_msg_parms parms = { 0 };
2080 struct hwrm_tf_tbl_type_bulk_get_input req = { 0 };
2081 struct hwrm_tf_tbl_type_bulk_get_output resp = { 0 };
2083 uint8_t fw_session_id;
2084 struct tf_dev_info *dev;
2085 struct tf_session *tfs;
2087 /* Retrieve the session information */
2088 rc = tf_session_get_session(tfp, &tfs);
2091 "%s: Failed to lookup session, rc:%s\n",
2097 /* Retrieve the device information */
2098 rc = tf_session_get_device(tfs, &dev);
2101 "%s: Failed to lookup device, rc:%s\n",
2107 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
2110 "%s: Unable to lookup FW id, rc:%s\n",
2116 /* Populate the request */
2117 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
2118 req.flags = tfp_cpu_to_le_16(dir);
2119 req.type = tfp_cpu_to_le_32(hcapi_type);
2120 req.start_index = tfp_cpu_to_le_32(starting_idx);
2121 req.num_entries = tfp_cpu_to_le_32(num_entries);
2123 data_size = num_entries * entry_sz_in_bytes;
2125 req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
2127 parms.tf_type = HWRM_TF_TBL_TYPE_BULK_GET;
2128 parms.req_data = (uint32_t *)&req;
2129 parms.req_size = sizeof(req);
2130 parms.resp_data = (uint32_t *)&resp;
2131 parms.resp_size = sizeof(resp);
2132 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2134 rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
2139 /* Verify that we got enough buffer to return the requested data */
2140 if (tfp_le_to_cpu_32(resp.size) != data_size)
2147 tf_msg_get_if_tbl_entry(struct tf *tfp,
2148 struct tf_if_tbl_get_parms *params)
2151 struct tfp_send_msg_parms parms = { 0 };
2152 struct hwrm_tf_if_tbl_get_input req = { 0 };
2153 struct hwrm_tf_if_tbl_get_output resp = { 0 };
2155 struct tf_dev_info *dev;
2156 struct tf_session *tfs;
2158 /* Retrieve the session information */
2159 rc = tf_session_get_session(tfp, &tfs);
2162 "%s: Failed to lookup session, rc:%s\n",
2163 tf_dir_2_str(params->dir),
2168 /* Retrieve the device information */
2169 rc = tf_session_get_device(tfs, &dev);
2172 "%s: Failed to lookup device, rc:%s\n",
2173 tf_dir_2_str(params->dir),
2178 flags = (params->dir == TF_DIR_TX ?
2179 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
2180 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
2182 /* Populate the request */
2184 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2186 req.type = params->hcapi_type;
2187 req.index = tfp_cpu_to_le_16(params->idx);
2188 req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
2190 parms.tf_type = HWRM_TF_IF_TBL_GET;
2191 parms.req_data = (uint32_t *)&req;
2192 parms.req_size = sizeof(req);
2193 parms.resp_data = (uint32_t *)&resp;
2194 parms.resp_size = sizeof(resp);
2195 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2197 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
2202 tfp_memcpy(params->data, resp.data, req.size);
2208 tf_msg_set_if_tbl_entry(struct tf *tfp,
2209 struct tf_if_tbl_set_parms *params)
2212 struct tfp_send_msg_parms parms = { 0 };
2213 struct hwrm_tf_if_tbl_set_input req = { 0 };
2214 struct hwrm_tf_if_tbl_get_output resp = { 0 };
2216 struct tf_dev_info *dev;
2217 struct tf_session *tfs;
2219 /* Retrieve the session information */
2220 rc = tf_session_get_session(tfp, &tfs);
2223 "%s: Failed to lookup session, rc:%s\n",
2224 tf_dir_2_str(params->dir),
2229 /* Retrieve the device information */
2230 rc = tf_session_get_device(tfs, &dev);
2234 flags = (params->dir == TF_DIR_TX ?
2235 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
2236 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
2238 /* Populate the request */
2240 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2242 req.type = params->hcapi_type;
2243 req.index = tfp_cpu_to_le_32(params->idx);
2244 req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
2245 tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
2247 parms.tf_type = HWRM_TF_IF_TBL_SET;
2248 parms.req_data = (uint32_t *)&req;
2249 parms.req_size = sizeof(req);
2250 parms.resp_data = (uint32_t *)&resp;
2251 parms.resp_size = sizeof(resp);
2252 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2254 rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);