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 tf *tfp,
118 char *ctrl_chan_name,
119 uint8_t *fw_session_id,
120 uint8_t *fw_session_client_id,
121 struct tf_dev_info *dev)
124 struct hwrm_tf_session_open_input req = { 0 };
125 struct hwrm_tf_session_open_output resp = { 0 };
126 struct tfp_send_msg_parms parms = { 0 };
128 /* Populate the request */
129 tfp_memcpy(&req.session_name, ctrl_chan_name, TF_SESSION_NAME_MAX);
131 parms.tf_type = HWRM_TF_SESSION_OPEN;
132 parms.req_data = (uint32_t *)&req;
133 parms.req_size = sizeof(req);
134 parms.resp_data = (uint32_t *)&resp;
135 parms.resp_size = sizeof(resp);
136 parms.mailbox = dev->ops->tf_dev_get_mailbox();
138 rc = tfp_send_msg_direct(tfp,
143 *fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
144 *fw_session_client_id =
145 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
151 tf_msg_session_attach(struct tf *tfp __rte_unused,
152 char *ctrl_chan_name __rte_unused,
153 uint8_t tf_fw_session_id __rte_unused)
159 tf_msg_session_client_register(struct tf *tfp,
160 struct tf_session *tfs,
161 char *ctrl_channel_name,
162 uint8_t *fw_session_client_id)
165 struct hwrm_tf_session_register_input req = { 0 };
166 struct hwrm_tf_session_register_output resp = { 0 };
167 struct tfp_send_msg_parms parms = { 0 };
168 uint8_t fw_session_id;
169 struct tf_dev_info *dev;
171 /* Retrieve the device information */
172 rc = tf_session_get_device(tfs, &dev);
175 "Failed to lookup device, rc:%s\n",
180 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
183 "Unable to lookup FW id, rc:%s\n",
188 /* Populate the request */
189 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
190 tfp_memcpy(&req.session_client_name,
192 TF_SESSION_NAME_MAX);
194 parms.tf_type = HWRM_TF_SESSION_REGISTER;
195 parms.req_data = (uint32_t *)&req;
196 parms.req_size = sizeof(req);
197 parms.resp_data = (uint32_t *)&resp;
198 parms.resp_size = sizeof(resp);
199 parms.mailbox = dev->ops->tf_dev_get_mailbox();
201 rc = tfp_send_msg_direct(tfp,
206 *fw_session_client_id =
207 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
213 tf_msg_session_client_unregister(struct tf *tfp,
214 struct tf_session *tfs,
215 uint8_t fw_session_client_id)
218 struct hwrm_tf_session_unregister_input req = { 0 };
219 struct hwrm_tf_session_unregister_output resp = { 0 };
220 struct tfp_send_msg_parms parms = { 0 };
221 uint8_t fw_session_id;
222 struct tf_dev_info *dev;
224 /* Retrieve the device information */
225 rc = tf_session_get_device(tfs, &dev);
228 "Failed to lookup device, rc:%s\n",
233 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
236 "Unable to lookup FW id, rc:%s\n",
241 /* Populate the request */
242 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
243 req.fw_session_client_id = tfp_cpu_to_le_32(fw_session_client_id);
245 parms.tf_type = HWRM_TF_SESSION_UNREGISTER;
246 parms.req_data = (uint32_t *)&req;
247 parms.req_size = sizeof(req);
248 parms.resp_data = (uint32_t *)&resp;
249 parms.resp_size = sizeof(resp);
250 parms.mailbox = dev->ops->tf_dev_get_mailbox();
252 rc = tfp_send_msg_direct(tfp,
259 tf_msg_session_close(struct tf *tfp,
260 struct tf_session *tfs)
263 struct hwrm_tf_session_close_input req = { 0 };
264 struct hwrm_tf_session_close_output resp = { 0 };
265 struct tfp_send_msg_parms parms = { 0 };
266 uint8_t fw_session_id;
267 struct tf_dev_info *dev;
269 /* Retrieve the device information */
270 rc = tf_session_get_device(tfs, &dev);
273 "Failed to lookup device, rc:%s\n",
278 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
281 "Unable to lookup FW id, rc:%s\n",
286 /* Populate the request */
287 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
289 parms.tf_type = HWRM_TF_SESSION_CLOSE;
290 parms.req_data = (uint32_t *)&req;
291 parms.req_size = sizeof(req);
292 parms.resp_data = (uint32_t *)&resp;
293 parms.resp_size = sizeof(resp);
294 parms.mailbox = dev->ops->tf_dev_get_mailbox();
296 rc = tfp_send_msg_direct(tfp,
302 tf_msg_session_qcfg(struct tf *tfp)
305 struct hwrm_tf_session_qcfg_input req = { 0 };
306 struct hwrm_tf_session_qcfg_output resp = { 0 };
307 struct tfp_send_msg_parms parms = { 0 };
308 uint8_t fw_session_id;
309 struct tf_dev_info *dev;
310 struct tf_session *tfs;
312 /* Retrieve the session information */
313 rc = tf_session_get_session_internal(tfp, &tfs);
316 "Failed to lookup session, rc:%s\n",
321 /* Retrieve the device information */
322 rc = tf_session_get_device(tfs, &dev);
325 "Failed to lookup device, rc:%s\n",
330 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
333 "Unable to lookup FW id, rc:%s\n",
338 /* Populate the request */
339 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
341 parms.tf_type = HWRM_TF_SESSION_QCFG,
342 parms.req_data = (uint32_t *)&req;
343 parms.req_size = sizeof(req);
344 parms.resp_data = (uint32_t *)&resp;
345 parms.resp_size = sizeof(resp);
346 parms.mailbox = dev->ops->tf_dev_get_mailbox();
348 rc = tfp_send_msg_direct(tfp,
354 tf_msg_session_resc_qcaps(struct tf *tfp,
355 struct tf_dev_info *dev,
358 struct tf_rm_resc_req_entry *query,
359 enum tf_rm_resc_resv_strategy *resv_strategy)
363 struct tfp_send_msg_parms parms = { 0 };
364 struct hwrm_tf_session_resc_qcaps_input req = { 0 };
365 struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
366 uint8_t fw_session_id;
367 struct tf_msg_dma_buf qcaps_buf = { 0 };
368 struct tf_rm_resc_req_entry *data;
371 TF_CHECK_PARMS3(tfp, query, resv_strategy);
373 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
376 "%s: Unable to lookup FW id, rc:%s\n",
382 /* Prepare DMA buffer */
383 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
384 rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
388 /* Populate the request */
389 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
390 req.flags = tfp_cpu_to_le_16(dir);
391 req.qcaps_size = size;
392 req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
394 parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
395 parms.req_data = (uint32_t *)&req;
396 parms.req_size = sizeof(req);
397 parms.resp_data = (uint32_t *)&resp;
398 parms.resp_size = sizeof(resp);
399 parms.mailbox = dev->ops->tf_dev_get_mailbox();
401 rc = tfp_send_msg_direct(tfp, &parms);
405 /* Process the response
406 * Should always get expected number of entries
408 if (tfp_le_to_cpu_32(resp.size) != size) {
410 "%s: QCAPS message size error, rc:%s\n",
417 /* Post process the response */
418 data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
419 for (i = 0; i < size; i++) {
420 query[i].type = tfp_le_to_cpu_32(data[i].type);
421 query[i].min = tfp_le_to_cpu_16(data[i].min);
422 query[i].max = tfp_le_to_cpu_16(data[i].max);
425 *resv_strategy = resp.flags &
426 HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
429 tf_msg_free_dma_buf(&qcaps_buf);
435 tf_msg_session_resc_alloc(struct tf *tfp,
436 struct tf_dev_info *dev,
439 struct tf_rm_resc_req_entry *request,
440 struct tf_rm_resc_entry *resv)
444 struct tfp_send_msg_parms parms = { 0 };
445 struct hwrm_tf_session_resc_alloc_input req = { 0 };
446 struct hwrm_tf_session_resc_alloc_output resp = { 0 };
447 uint8_t fw_session_id;
448 struct tf_msg_dma_buf req_buf = { 0 };
449 struct tf_msg_dma_buf resv_buf = { 0 };
450 struct tf_rm_resc_req_entry *req_data;
451 struct tf_rm_resc_entry *resv_data;
454 TF_CHECK_PARMS3(tfp, request, resv);
456 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
459 "%s: Unable to lookup FW id, rc:%s\n",
465 /* Prepare DMA buffers */
466 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
467 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
471 dma_size = size * sizeof(struct tf_rm_resc_entry);
472 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
474 tf_msg_free_dma_buf(&req_buf);
478 /* Populate the request */
479 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
480 req.flags = tfp_cpu_to_le_16(dir);
483 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
484 for (i = 0; i < size; i++) {
485 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
486 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
487 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
490 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
491 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
493 parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
494 parms.req_data = (uint32_t *)&req;
495 parms.req_size = sizeof(req);
496 parms.resp_data = (uint32_t *)&resp;
497 parms.resp_size = sizeof(resp);
498 parms.mailbox = dev->ops->tf_dev_get_mailbox();
500 rc = tfp_send_msg_direct(tfp, &parms);
504 /* Process the response
505 * Should always get expected number of entries
507 if (tfp_le_to_cpu_32(resp.size) != size) {
509 "%s: Alloc message size error, rc:%s\n",
516 /* Post process the response */
517 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
518 for (i = 0; i < size; i++) {
519 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
520 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
521 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
525 tf_msg_free_dma_buf(&req_buf);
526 tf_msg_free_dma_buf(&resv_buf);
532 tf_msg_session_resc_flush(struct tf *tfp,
535 struct tf_rm_resc_entry *resv)
539 struct tfp_send_msg_parms parms = { 0 };
540 struct hwrm_tf_session_resc_flush_input req = { 0 };
541 struct hwrm_tf_session_resc_flush_output resp = { 0 };
542 uint8_t fw_session_id;
543 struct tf_msg_dma_buf resv_buf = { 0 };
544 struct tf_rm_resc_entry *resv_data;
546 struct tf_dev_info *dev;
547 struct tf_session *tfs;
549 TF_CHECK_PARMS2(tfp, resv);
551 /* Retrieve the session information */
552 rc = tf_session_get_session_internal(tfp, &tfs);
555 "%s: Failed to lookup session, rc:%s\n",
561 /* Retrieve the device information */
562 rc = tf_session_get_device(tfs, &dev);
565 "%s: Failed to lookup device, rc:%s\n",
571 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
574 "%s: Unable to lookup FW id, rc:%s\n",
580 /* Prepare DMA buffers */
581 dma_size = size * sizeof(struct tf_rm_resc_entry);
582 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
586 /* Populate the request */
587 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
588 req.flags = tfp_cpu_to_le_16(dir);
589 req.flush_size = size;
591 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
592 for (i = 0; i < size; i++) {
593 resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
594 resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
595 resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
598 req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
600 parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
601 parms.req_data = (uint32_t *)&req;
602 parms.req_size = sizeof(req);
603 parms.resp_data = (uint32_t *)&resp;
604 parms.resp_size = sizeof(resp);
605 parms.mailbox = dev->ops->tf_dev_get_mailbox();
607 rc = tfp_send_msg_direct(tfp, &parms);
609 tf_msg_free_dma_buf(&resv_buf);
615 tf_msg_insert_em_internal_entry(struct tf *tfp,
616 struct tf_insert_em_entry_parms *em_parms,
617 uint16_t *rptr_index,
619 uint8_t *num_of_entries)
622 struct tfp_send_msg_parms parms = { 0 };
623 struct hwrm_tf_em_insert_input req = { 0 };
624 struct hwrm_tf_em_insert_output resp = { 0 };
625 struct tf_em_64b_entry *em_result =
626 (struct tf_em_64b_entry *)em_parms->em_record;
628 uint8_t fw_session_id;
629 uint8_t msg_key_size;
630 struct tf_dev_info *dev;
631 struct tf_session *tfs;
633 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
634 TF_MSG_SIZE_HWRM_TF_EM_INSERT);
636 /* Retrieve the session information */
637 rc = tf_session_get_session_internal(tfp, &tfs);
640 "%s: Failed to lookup session, rc:%s\n",
641 tf_dir_2_str(em_parms->dir),
646 /* Retrieve the device information */
647 rc = tf_session_get_device(tfs, &dev);
650 "%s: Failed to lookup device, rc:%s\n",
651 tf_dir_2_str(em_parms->dir),
656 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
659 "%s: Unable to lookup FW id, rc:%s\n",
660 tf_dir_2_str(em_parms->dir),
665 /* Populate the request */
666 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
668 /* Check for key size conformity */
669 msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
670 if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
673 "%s: Invalid parameters for msg type, rc:%s\n",
674 tf_dir_2_str(em_parms->dir),
679 tfp_memcpy(req.em_key,
683 flags = (em_parms->dir == TF_DIR_TX ?
684 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
685 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
686 req.flags = tfp_cpu_to_le_16(flags);
687 req.strength = (em_result->hdr.word1 &
688 CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
689 CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
690 req.em_key_bitlen = em_parms->key_sz_in_bits;
691 req.action_ptr = em_result->hdr.pointer;
692 req.em_record_idx = *rptr_index;
694 parms.tf_type = HWRM_TF_EM_INSERT;
695 parms.req_data = (uint32_t *)&req;
696 parms.req_size = sizeof(req);
697 parms.resp_data = (uint32_t *)&resp;
698 parms.resp_size = sizeof(resp);
699 parms.mailbox = dev->ops->tf_dev_get_mailbox();
701 rc = tfp_send_msg_direct(tfp,
706 *rptr_entry = resp.rptr_entry;
707 *rptr_index = resp.rptr_index;
708 *num_of_entries = resp.num_of_entries;
714 tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
715 struct tf_insert_em_entry_parms *em_parms,
718 uint16_t *rptr_index,
720 uint8_t *num_of_entries)
723 struct tfp_send_msg_parms parms = { 0 };
724 struct hwrm_tf_em_hash_insert_input req = { 0 };
725 struct hwrm_tf_em_hash_insert_output resp = { 0 };
727 uint8_t fw_session_id;
728 uint8_t msg_record_size;
729 struct tf_dev_info *dev;
730 struct tf_session *tfs;
732 /* Retrieve the session information */
733 rc = tf_session_get_session_internal(tfp, &tfs);
736 "%s: Failed to lookup session, rc:%s\n",
737 tf_dir_2_str(em_parms->dir),
742 /* Retrieve the device information */
743 rc = tf_session_get_device(tfs, &dev);
746 "%s: Failed to lookup device, rc:%s\n",
747 tf_dir_2_str(em_parms->dir),
752 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
755 "%s: Unable to lookup FW id, rc:%s\n",
756 tf_dir_2_str(em_parms->dir),
761 /* Populate the request */
762 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
764 /* Check for key size conformity */
765 msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
767 if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
770 "%s: Record size to large, rc:%s\n",
771 tf_dir_2_str(em_parms->dir),
776 tfp_memcpy((char *)req.em_record,
780 flags = (em_parms->dir == TF_DIR_TX ?
781 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
782 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
783 req.flags = tfp_cpu_to_le_16(flags);
784 req.em_record_size_bits = em_parms->em_record_sz_in_bits;
785 req.em_record_idx = *rptr_index;
786 req.key0_hash = key0_hash;
787 req.key1_hash = key1_hash;
789 parms.tf_type = HWRM_TF_EM_HASH_INSERT;
790 parms.req_data = (uint32_t *)&req;
791 parms.req_size = sizeof(req);
792 parms.resp_data = (uint32_t *)&resp;
793 parms.resp_size = sizeof(resp);
794 parms.mailbox = dev->ops->tf_dev_get_mailbox();
796 rc = tfp_send_msg_direct(tfp,
801 *rptr_entry = resp.rptr_entry;
802 *rptr_index = resp.rptr_index;
803 *num_of_entries = resp.num_of_entries;
809 tf_msg_delete_em_entry(struct tf *tfp,
810 struct tf_delete_em_entry_parms *em_parms)
813 struct tfp_send_msg_parms parms = { 0 };
814 struct hwrm_tf_em_delete_input req = { 0 };
815 struct hwrm_tf_em_delete_output resp = { 0 };
817 uint8_t fw_session_id;
818 struct tf_dev_info *dev;
819 struct tf_session *tfs;
821 /* Retrieve the session information */
822 rc = tf_session_get_session_internal(tfp, &tfs);
825 "%s: Failed to lookup session, rc:%s\n",
826 tf_dir_2_str(em_parms->dir),
831 /* Retrieve the device information */
832 rc = tf_session_get_device(tfs, &dev);
835 "%s: Failed to lookup device, rc:%s\n",
836 tf_dir_2_str(em_parms->dir),
841 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
844 "%s: Unable to lookup FW id, rc:%s\n",
845 tf_dir_2_str(em_parms->dir),
850 /* Populate the request */
851 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
853 flags = (em_parms->dir == TF_DIR_TX ?
854 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
855 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
856 req.flags = tfp_cpu_to_le_16(flags);
857 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
859 parms.tf_type = HWRM_TF_EM_DELETE;
860 parms.req_data = (uint32_t *)&req;
861 parms.req_size = sizeof(req);
862 parms.resp_data = (uint32_t *)&resp;
863 parms.resp_size = sizeof(resp);
864 parms.mailbox = dev->ops->tf_dev_get_mailbox();
866 rc = tfp_send_msg_direct(tfp,
871 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
876 int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
877 struct hcapi_cfa_em_table *tbl,
882 struct tfp_send_msg_parms parms = { 0 };
883 struct hwrm_tf_ctxt_mem_alloc_input req = {0};
884 struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
887 struct tf_dev_info *dev;
888 struct tf_session *tfs;
891 /* Retrieve the session information */
892 rc = tf_session_get_session_internal(tfp, &tfs);
895 "Failed to lookup session, rc:%s\n",
900 /* Retrieve the device information */
901 rc = tf_session_get_device(tfs, &dev);
904 "Failed to lookup device, rc:%s\n",
908 /* Retrieve the session information */
909 fw_se_id = tfs->session_id.internal.fw_session_id;
911 if (tbl->num_entries && tbl->entry_size) {
913 mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
914 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
915 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
916 parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
917 parms.req_data = (uint32_t *)&req;
918 parms.req_size = sizeof(req);
919 parms.resp_data = (uint32_t *)&resp;
920 parms.resp_size = sizeof(resp);
921 parms.mailbox = dev->ops->tf_dev_get_mailbox();
922 rc = tfp_send_msg_direct(tfp, &parms);
924 TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
929 *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
930 *page_lvl = resp.page_level;
931 *page_size = resp.page_size;
937 int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
943 struct tfp_send_msg_parms parms = { 0 };
944 struct hwrm_tf_ctxt_mem_free_input req = {0};
945 struct hwrm_tf_ctxt_mem_free_output resp = {0};
947 struct tf_dev_info *dev;
948 struct tf_session *tfs;
951 /* Retrieve the session information */
952 rc = tf_session_get_session_internal(tfp, &tfs);
955 "Failed to lookup session, rc:%s\n",
960 /* Retrieve the device information */
961 rc = tf_session_get_device(tfs, &dev);
964 "Failed to lookup device, rc:%s\n",
968 /* Retrieve the session information */
969 fw_se_id = tfs->session_id.internal.fw_session_id;
971 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
972 req.mem_size = tfp_cpu_to_le_32(mem_size_k);
973 req.page_dir = tfp_cpu_to_le_64(dma_addr);
974 req.page_level = page_level;
975 req.page_size = page_size;
976 parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
977 parms.req_data = (uint32_t *)&req;
978 parms.req_size = sizeof(req);
979 parms.resp_data = (uint32_t *)&resp;
980 parms.resp_size = sizeof(resp);
981 parms.mailbox = dev->ops->tf_dev_get_mailbox();
982 rc = tfp_send_msg_direct(tfp, &parms);
988 tf_msg_em_mem_rgtr(struct tf *tfp,
995 struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
996 struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
997 struct tfp_send_msg_parms parms = { 0 };
998 struct tf_dev_info *dev;
999 struct tf_session *tfs;
1002 /* Retrieve the session information */
1003 rc = tf_session_get_session_internal(tfp, &tfs);
1006 "Failed to lookup session, rc:%s\n",
1011 /* Retrieve the device information */
1012 rc = tf_session_get_device(tfs, &dev);
1015 "Failed to lookup device, rc:%s\n",
1019 fw_se_id = tfs->session_id.internal.fw_session_id;
1021 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1022 req.page_level = page_lvl;
1023 req.page_size = page_size;
1024 req.page_dir = tfp_cpu_to_le_64(dma_addr);
1026 parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
1027 parms.req_data = (uint32_t *)&req;
1028 parms.req_size = sizeof(req);
1029 parms.resp_data = (uint32_t *)&resp;
1030 parms.resp_size = sizeof(resp);
1031 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1033 rc = tfp_send_msg_direct(tfp,
1038 *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
1044 tf_msg_em_mem_unrgtr(struct tf *tfp,
1048 struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
1049 struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
1050 struct tfp_send_msg_parms parms = { 0 };
1051 struct tf_dev_info *dev;
1052 struct tf_session *tfs;
1055 /* Retrieve the session information */
1056 rc = tf_session_get_session_internal(tfp, &tfs);
1059 "Failed to lookup session, rc:%s\n",
1064 /* Retrieve the device information */
1065 rc = tf_session_get_device(tfs, &dev);
1068 "Failed to lookup device, rc:%s\n",
1073 fw_se_id = tfs->session_id.internal.fw_session_id;
1074 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1076 req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
1078 parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
1079 parms.req_data = (uint32_t *)&req;
1080 parms.req_size = sizeof(req);
1081 parms.resp_data = (uint32_t *)&resp;
1082 parms.resp_size = sizeof(resp);
1083 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1085 rc = tfp_send_msg_direct(tfp,
1091 tf_msg_em_qcaps(struct tf *tfp,
1093 struct tf_em_caps *em_caps)
1096 struct hwrm_tf_ext_em_qcaps_input req = {0};
1097 struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
1099 struct tfp_send_msg_parms parms = { 0 };
1100 struct tf_dev_info *dev;
1101 struct tf_session *tfs;
1104 /* Retrieve the session information */
1105 rc = tf_session_get_session_internal(tfp, &tfs);
1108 "%s: Failed to lookup session, rc:%s\n",
1113 fw_se_id = tfs->session_id.internal.fw_session_id;
1115 /* Retrieve the device information */
1116 rc = tf_session_get_device(tfs, &dev);
1119 "%s: Failed to lookup device, rc:%s\n",
1125 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
1126 HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
1127 req.flags = tfp_cpu_to_le_32(flags);
1129 parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
1130 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1131 parms.req_data = (uint32_t *)&req;
1132 parms.req_size = sizeof(req);
1133 parms.resp_data = (uint32_t *)&resp;
1134 parms.resp_size = sizeof(resp);
1135 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1137 rc = tfp_send_msg_direct(tfp,
1142 em_caps->supported = tfp_le_to_cpu_32(resp.supported);
1143 em_caps->max_entries_supported =
1144 tfp_le_to_cpu_32(resp.max_entries_supported);
1145 em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
1146 em_caps->record_entry_size =
1147 tfp_le_to_cpu_16(resp.record_entry_size);
1148 em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
1154 tf_msg_em_cfg(struct tf *tfp,
1155 uint32_t num_entries,
1156 uint16_t key0_ctx_id,
1157 uint16_t key1_ctx_id,
1158 uint16_t record_ctx_id,
1159 uint16_t efc_ctx_id,
1160 uint8_t flush_interval,
1164 struct hwrm_tf_ext_em_cfg_input req = {0};
1165 struct hwrm_tf_ext_em_cfg_output resp = {0};
1167 struct tfp_send_msg_parms parms = { 0 };
1168 struct tf_dev_info *dev;
1169 struct tf_session *tfs;
1171 /* Retrieve the session information */
1172 rc = tf_session_get_session_internal(tfp, &tfs);
1175 "%s: Failed to lookup session, rc:%s\n",
1181 /* Retrieve the device information */
1182 rc = tf_session_get_device(tfs, &dev);
1185 "%s: Failed to lookup device, rc:%s\n",
1191 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1192 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1193 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1195 req.flags = tfp_cpu_to_le_32(flags);
1196 req.num_entries = tfp_cpu_to_le_32(num_entries);
1198 req.flush_interval = flush_interval;
1200 req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
1201 req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
1202 req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
1203 req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
1205 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1206 parms.req_data = (uint32_t *)&req;
1207 parms.req_size = sizeof(req);
1208 parms.resp_data = (uint32_t *)&resp;
1209 parms.resp_size = sizeof(resp);
1210 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1212 rc = tfp_send_msg_direct(tfp,
1218 tf_msg_ext_em_cfg(struct tf *tfp,
1219 struct tf_tbl_scope_cb *tbl_scope_cb,
1220 uint32_t st_buckets,
1221 uint8_t flush_interval,
1224 struct hcapi_cfa_em_ctx_mem_info *ctxp = &tbl_scope_cb->em_ctx_info[dir];
1225 struct hcapi_cfa_em_table *lkup_tbl, *act_tbl;
1226 struct hwrm_tf_ext_em_cfg_input req = {0};
1227 struct hwrm_tf_ext_em_cfg_output resp = {0};
1228 struct tfp_send_msg_parms parms = { 0 };
1230 struct tf_dev_info *dev;
1231 struct tf_session *tfs;
1235 /* Retrieve the session information */
1236 rc = tf_session_get_session_internal(tfp, &tfs);
1239 "%s: Failed to lookup session, rc:%s\n",
1245 /* Retrieve the device information */
1246 rc = tf_session_get_device(tfs, &dev);
1249 "%s: Failed to lookup device, rc:%s\n",
1254 fw_se_id = tfs->session_id.internal.fw_session_id;
1256 lkup_tbl = &ctxp->em_tables[TF_EM_LKUP_TABLE];
1257 act_tbl = &ctxp->em_tables[TF_ACTION_TABLE];
1258 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1259 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1260 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
1262 req.flags = tfp_cpu_to_le_32(flags);
1263 req.num_entries = tfp_cpu_to_le_32(act_tbl->num_entries);
1264 req.lkup_static_buckets = tfp_cpu_to_le_32(st_buckets);
1265 req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
1266 req.flush_interval = flush_interval;
1267 req.action_ctx_id = tfp_cpu_to_le_16(act_tbl->ctx_id);
1268 req.action_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1269 req.lkup_ctx_id = tfp_cpu_to_le_16(lkup_tbl->ctx_id);
1270 req.lkup_tbl_scope = tfp_cpu_to_le_16(tbl_scope_cb->tbl_scope_id);
1272 req.enables = (HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_CTX_ID |
1273 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_ACTION_TBL_SCOPE |
1274 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_CTX_ID |
1275 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_TBL_SCOPE |
1276 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_LKUP_STATIC_BUCKETS |
1277 HWRM_TF_EXT_EM_CFG_INPUT_ENABLES_NUM_ENTRIES);
1279 parms.tf_type = HWRM_TF_EXT_EM_CFG;
1280 parms.req_data = (uint32_t *)&req;
1281 parms.req_size = sizeof(req);
1282 parms.resp_data = (uint32_t *)&resp;
1283 parms.resp_size = sizeof(resp);
1284 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1286 rc = tfp_send_msg_direct(tfp,
1292 tf_msg_em_op(struct tf *tfp,
1297 struct hwrm_tf_ext_em_op_input req = {0};
1298 struct hwrm_tf_ext_em_op_output resp = {0};
1300 struct tfp_send_msg_parms parms = { 0 };
1301 struct tf_dev_info *dev;
1302 struct tf_session *tfs;
1304 /* Retrieve the session information */
1305 rc = tf_session_get_session_internal(tfp, &tfs);
1308 "%s: Failed to lookup session, rc:%s\n",
1314 /* Retrieve the device information */
1315 rc = tf_session_get_device(tfs, &dev);
1318 "%s: Failed to lookup device, rc:%s\n",
1324 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1325 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1326 req.flags = tfp_cpu_to_le_32(flags);
1327 req.op = tfp_cpu_to_le_16(op);
1329 parms.tf_type = HWRM_TF_EXT_EM_OP;
1330 parms.req_data = (uint32_t *)&req;
1331 parms.req_size = sizeof(req);
1332 parms.resp_data = (uint32_t *)&resp;
1333 parms.resp_size = sizeof(resp);
1334 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1336 rc = tfp_send_msg_direct(tfp,
1342 tf_msg_tcam_entry_set(struct tf *tfp,
1343 struct tf_dev_info *dev,
1344 struct tf_tcam_set_parms *parms)
1347 struct tfp_send_msg_parms mparms = { 0 };
1348 struct hwrm_tf_tcam_set_input req = { 0 };
1349 struct hwrm_tf_tcam_set_output resp = { 0 };
1350 struct tf_msg_dma_buf buf = { 0 };
1351 uint8_t *data = NULL;
1353 uint8_t fw_session_id;
1355 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1358 "%s: Unable to lookup FW id, rc:%s\n",
1359 tf_dir_2_str(parms->dir),
1364 /* Populate the request */
1365 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1366 req.type = parms->hcapi_type;
1367 req.idx = tfp_cpu_to_le_16(parms->idx);
1368 if (parms->dir == TF_DIR_TX)
1369 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1371 req.key_size = parms->key_size;
1372 req.mask_offset = parms->key_size;
1373 /* Result follows after key and mask, thus multiply by 2 */
1374 req.result_offset = 2 * parms->key_size;
1375 req.result_size = parms->result_size;
1376 data_size = 2 * req.key_size + req.result_size;
1378 if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1379 /* use pci buffer */
1380 data = &req.dev_data[0];
1382 /* use dma buffer */
1383 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1384 rc = tf_msg_alloc_dma_buf(&buf, data_size);
1388 tfp_memcpy(&req.dev_data[0],
1390 sizeof(buf.pa_addr));
1393 tfp_memcpy(&data[0], parms->key, parms->key_size);
1394 tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1395 tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1397 mparms.tf_type = HWRM_TF_TCAM_SET;
1398 mparms.req_data = (uint32_t *)&req;
1399 mparms.req_size = sizeof(req);
1400 mparms.resp_data = (uint32_t *)&resp;
1401 mparms.resp_size = sizeof(resp);
1402 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1404 rc = tfp_send_msg_direct(tfp,
1408 tf_msg_free_dma_buf(&buf);
1414 tf_msg_tcam_entry_get(struct tf *tfp,
1415 struct tf_dev_info *dev,
1416 struct tf_tcam_get_parms *parms)
1419 struct tfp_send_msg_parms mparms = { 0 };
1420 struct hwrm_tf_tcam_get_input req = { 0 };
1421 struct hwrm_tf_tcam_get_output resp = { 0 };
1422 uint8_t fw_session_id;
1424 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1427 "%s: Unable to lookup FW id, rc:%s\n",
1428 tf_dir_2_str(parms->dir),
1433 /* Populate the request */
1434 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1435 req.type = parms->hcapi_type;
1436 req.idx = tfp_cpu_to_le_16(parms->idx);
1437 if (parms->dir == TF_DIR_TX)
1438 req.flags |= HWRM_TF_TCAM_GET_INPUT_FLAGS_DIR_TX;
1440 mparms.tf_type = HWRM_TF_TCAM_GET;
1441 mparms.req_data = (uint32_t *)&req;
1442 mparms.req_size = sizeof(req);
1443 mparms.resp_data = (uint32_t *)&resp;
1444 mparms.resp_size = sizeof(resp);
1445 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1447 rc = tfp_send_msg_direct(tfp,
1453 if (parms->key_size < resp.key_size ||
1454 parms->result_size < resp.result_size) {
1457 "%s: Key buffer(%d) is smaller than the key(%d), rc:%s\n",
1458 tf_dir_2_str(parms->dir),
1464 parms->key_size = resp.key_size;
1465 parms->result_size = resp.result_size;
1466 tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
1467 tfp_memcpy(parms->mask, &resp.dev_data[resp.key_size], resp.key_size);
1468 tfp_memcpy(parms->result, &resp.dev_data[resp.result_offset], resp.result_size);
1474 tf_msg_tcam_entry_free(struct tf *tfp,
1475 struct tf_dev_info *dev,
1476 struct tf_tcam_free_parms *in_parms)
1479 struct hwrm_tf_tcam_free_input req = { 0 };
1480 struct hwrm_tf_tcam_free_output resp = { 0 };
1481 struct tfp_send_msg_parms parms = { 0 };
1482 uint8_t fw_session_id;
1484 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1487 "%s: Unable to lookup FW id, rc:%s\n",
1488 tf_dir_2_str(in_parms->dir),
1493 /* Populate the request */
1494 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1495 req.type = in_parms->hcapi_type;
1497 req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1498 if (in_parms->dir == TF_DIR_TX)
1499 req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1501 parms.tf_type = HWRM_TF_TCAM_FREE;
1502 parms.req_data = (uint32_t *)&req;
1503 parms.req_size = sizeof(req);
1504 parms.resp_data = (uint32_t *)&resp;
1505 parms.resp_size = sizeof(resp);
1506 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1508 rc = tfp_send_msg_direct(tfp,
1514 tf_msg_set_tbl_entry(struct tf *tfp,
1516 uint16_t hcapi_type,
1522 struct hwrm_tf_tbl_type_set_input req = { 0 };
1523 struct hwrm_tf_tbl_type_set_output resp = { 0 };
1524 struct tfp_send_msg_parms parms = { 0 };
1525 uint8_t fw_session_id;
1526 struct tf_dev_info *dev;
1527 struct tf_session *tfs;
1529 RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_tbl_type_set_input) !=
1530 TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET);
1532 /* Retrieve the session information */
1533 rc = tf_session_get_session_internal(tfp, &tfs);
1536 "%s: Failed to lookup session, rc:%s\n",
1542 /* Retrieve the device information */
1543 rc = tf_session_get_device(tfs, &dev);
1546 "%s: Failed to lookup device, rc:%s\n",
1552 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1555 "%s: Unable to lookup FW id, rc:%s\n",
1561 /* Populate the request */
1562 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1563 req.flags = tfp_cpu_to_le_16(dir);
1564 req.type = tfp_cpu_to_le_32(hcapi_type);
1565 req.size = tfp_cpu_to_le_16(size);
1566 req.index = tfp_cpu_to_le_32(index);
1568 /* Check for data size conformity */
1569 if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1572 "%s: Invalid parameters for msg type, rc:%s\n",
1578 tfp_memcpy(&req.data,
1582 parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1583 parms.req_data = (uint32_t *)&req;
1584 parms.req_size = sizeof(req);
1585 parms.resp_data = (uint32_t *)&resp;
1586 parms.resp_size = sizeof(resp);
1587 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1589 rc = tfp_send_msg_direct(tfp,
1598 tf_msg_get_tbl_entry(struct tf *tfp,
1600 uint16_t hcapi_type,
1606 struct hwrm_tf_tbl_type_get_input req = { 0 };
1607 struct hwrm_tf_tbl_type_get_output resp = { 0 };
1608 struct tfp_send_msg_parms parms = { 0 };
1609 uint8_t fw_session_id;
1610 struct tf_dev_info *dev;
1611 struct tf_session *tfs;
1613 /* Retrieve the session information */
1614 rc = tf_session_get_session_internal(tfp, &tfs);
1617 "%s: Failed to lookup session, rc:%s\n",
1623 /* Retrieve the device information */
1624 rc = tf_session_get_device(tfs, &dev);
1627 "%s: Failed to lookup device, 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",
1642 /* Populate the request */
1643 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1644 req.flags = tfp_cpu_to_le_16(dir);
1645 req.type = tfp_cpu_to_le_32(hcapi_type);
1646 req.index = tfp_cpu_to_le_32(index);
1648 parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1649 parms.req_data = (uint32_t *)&req;
1650 parms.req_size = sizeof(req);
1651 parms.resp_data = (uint32_t *)&resp;
1652 parms.resp_size = sizeof(resp);
1653 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1655 rc = tfp_send_msg_direct(tfp,
1661 * The response will be 64 bytes long, the response size will
1662 * be in words (16). All we can test for is that the response
1663 * size is < to the requested size.
1665 if ((tfp_le_to_cpu_32(resp.size) * 4) < size)
1669 * Copy the requested number of bytes
1678 /* HWRM Tunneled messages */
1681 tf_msg_get_global_cfg(struct tf *tfp,
1682 struct tf_global_cfg_parms *params)
1685 struct tfp_send_msg_parms parms = { 0 };
1686 struct hwrm_tf_global_cfg_get_input req = { 0 };
1687 struct hwrm_tf_global_cfg_get_output resp = { 0 };
1689 uint8_t fw_session_id;
1690 uint16_t resp_size = 0;
1691 struct tf_dev_info *dev;
1692 struct tf_session *tfs;
1694 /* Retrieve the session information */
1695 rc = tf_session_get_session_internal(tfp, &tfs);
1698 "%s: Failed to lookup session, rc:%s\n",
1699 tf_dir_2_str(params->dir),
1704 /* Retrieve the device information */
1705 rc = tf_session_get_device(tfs, &dev);
1708 "%s: Failed to lookup device, rc:%s\n",
1709 tf_dir_2_str(params->dir),
1714 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1717 "%s: Unable to lookup FW id, rc:%s\n",
1718 tf_dir_2_str(params->dir),
1723 flags = (params->dir == TF_DIR_TX ?
1724 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1725 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1727 /* Populate the request */
1728 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1729 req.flags = tfp_cpu_to_le_32(flags);
1730 req.type = tfp_cpu_to_le_32(params->type);
1731 req.offset = tfp_cpu_to_le_32(params->offset);
1732 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1734 parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
1735 parms.req_data = (uint32_t *)&req;
1736 parms.req_size = sizeof(req);
1737 parms.resp_data = (uint32_t *)&resp;
1738 parms.resp_size = sizeof(resp);
1739 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1741 rc = tfp_send_msg_direct(tfp, &parms);
1745 /* Verify that we got enough buffer to return the requested data */
1746 resp_size = tfp_le_to_cpu_16(resp.size);
1747 if (resp_size < params->config_sz_in_bytes)
1751 tfp_memcpy(params->config,
1761 tf_msg_set_global_cfg(struct tf *tfp,
1762 struct tf_global_cfg_parms *params)
1765 struct tfp_send_msg_parms parms = { 0 };
1766 struct hwrm_tf_global_cfg_set_input req = { 0 };
1767 struct hwrm_tf_global_cfg_set_output resp = { 0 };
1769 uint8_t fw_session_id;
1770 struct tf_dev_info *dev;
1771 struct tf_session *tfs;
1773 /* Retrieve the session information */
1774 rc = tf_session_get_session_internal(tfp, &tfs);
1777 "%s: Failed to lookup session, rc:%s\n",
1778 tf_dir_2_str(params->dir),
1783 /* Retrieve the device information */
1784 rc = tf_session_get_device(tfs, &dev);
1787 "%s: Failed to lookup device, rc:%s\n",
1788 tf_dir_2_str(params->dir),
1793 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1796 "%s: Unable to lookup FW id, rc:%s\n",
1797 tf_dir_2_str(params->dir),
1802 flags = (params->dir == TF_DIR_TX ?
1803 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
1804 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
1806 /* Populate the request */
1807 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1808 req.flags = tfp_cpu_to_le_32(flags);
1809 req.type = tfp_cpu_to_le_32(params->type);
1810 req.offset = tfp_cpu_to_le_32(params->offset);
1812 /* Check for data size conformity */
1813 if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
1816 "%s: Invalid parameters for msg type, rc:%s\n",
1817 tf_dir_2_str(params->dir),
1822 tfp_memcpy(req.data, params->config,
1823 params->config_sz_in_bytes);
1825 /* Only set mask if pointer is provided
1827 if (params->config_mask) {
1828 tfp_memcpy(req.mask,
1829 params->config_mask,
1830 params->config_sz_in_bytes);
1833 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1835 parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
1836 parms.req_data = (uint32_t *)&req;
1837 parms.req_size = sizeof(req);
1838 parms.resp_data = (uint32_t *)&resp;
1839 parms.resp_size = sizeof(resp);
1840 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1842 rc = tfp_send_msg_direct(tfp, &parms);
1851 tf_msg_bulk_get_tbl_entry(struct tf *tfp,
1853 uint16_t hcapi_type,
1854 uint32_t starting_idx,
1855 uint16_t num_entries,
1856 uint16_t entry_sz_in_bytes,
1857 uint64_t physical_mem_addr)
1860 struct tfp_send_msg_parms parms = { 0 };
1861 struct hwrm_tf_tbl_type_bulk_get_input req = { 0 };
1862 struct hwrm_tf_tbl_type_bulk_get_output resp = { 0 };
1864 uint8_t fw_session_id;
1865 struct tf_dev_info *dev;
1866 struct tf_session *tfs;
1868 /* Retrieve the session information */
1869 rc = tf_session_get_session(tfp, &tfs);
1872 "%s: Failed to lookup session, rc:%s\n",
1878 /* Retrieve the device information */
1879 rc = tf_session_get_device(tfs, &dev);
1882 "%s: Failed to lookup device, rc:%s\n",
1888 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1891 "%s: Unable to lookup FW id, rc:%s\n",
1897 /* Populate the request */
1898 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1899 req.flags = tfp_cpu_to_le_16(dir);
1900 req.type = tfp_cpu_to_le_32(hcapi_type);
1901 req.start_index = tfp_cpu_to_le_32(starting_idx);
1902 req.num_entries = tfp_cpu_to_le_32(num_entries);
1904 data_size = num_entries * entry_sz_in_bytes;
1906 req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
1908 parms.tf_type = HWRM_TF_TBL_TYPE_BULK_GET;
1909 parms.req_data = (uint32_t *)&req;
1910 parms.req_size = sizeof(req);
1911 parms.resp_data = (uint32_t *)&resp;
1912 parms.resp_size = sizeof(resp);
1913 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1915 rc = tfp_send_msg_direct(tfp,
1920 /* Verify that we got enough buffer to return the requested data */
1921 if (tfp_le_to_cpu_32(resp.size) != data_size)
1928 tf_msg_get_if_tbl_entry(struct tf *tfp,
1929 struct tf_if_tbl_get_parms *params)
1932 struct tfp_send_msg_parms parms = { 0 };
1933 struct hwrm_tf_if_tbl_get_input req = { 0 };
1934 struct hwrm_tf_if_tbl_get_output resp = { 0 };
1936 struct tf_dev_info *dev;
1937 struct tf_session *tfs;
1939 /* Retrieve the session information */
1940 rc = tf_session_get_session(tfp, &tfs);
1943 "%s: Failed to lookup session, rc:%s\n",
1944 tf_dir_2_str(params->dir),
1949 /* Retrieve the device information */
1950 rc = tf_session_get_device(tfs, &dev);
1953 "%s: Failed to lookup device, rc:%s\n",
1954 tf_dir_2_str(params->dir),
1959 flags = (params->dir == TF_DIR_TX ?
1960 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
1961 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
1963 /* Populate the request */
1965 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
1967 req.type = params->hcapi_type;
1968 req.index = tfp_cpu_to_le_16(params->idx);
1969 req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
1971 parms.tf_type = HWRM_TF_IF_TBL_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(tfp, &parms);
1983 tfp_memcpy(params->data, resp.data, req.size);
1989 tf_msg_set_if_tbl_entry(struct tf *tfp,
1990 struct tf_if_tbl_set_parms *params)
1993 struct tfp_send_msg_parms parms = { 0 };
1994 struct hwrm_tf_if_tbl_set_input req = { 0 };
1995 struct hwrm_tf_if_tbl_get_output resp = { 0 };
1997 struct tf_dev_info *dev;
1998 struct tf_session *tfs;
2000 /* Retrieve the session information */
2001 rc = tf_session_get_session(tfp, &tfs);
2004 "%s: Failed to lookup session, rc:%s\n",
2005 tf_dir_2_str(params->dir),
2010 /* Retrieve the device information */
2011 rc = tf_session_get_device(tfs, &dev);
2015 flags = (params->dir == TF_DIR_TX ?
2016 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
2017 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
2019 /* Populate the request */
2021 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
2023 req.type = params->hcapi_type;
2024 req.index = tfp_cpu_to_le_32(params->idx);
2025 req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
2026 tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
2028 parms.tf_type = HWRM_TF_IF_TBL_SET;
2029 parms.req_data = (uint32_t *)&req;
2030 parms.req_size = sizeof(req);
2031 parms.resp_data = (uint32_t *)&resp;
2032 parms.resp_size = sizeof(resp);
2033 parms.mailbox = dev->ops->tf_dev_get_mailbox();
2035 rc = tfp_send_msg_direct(tfp, &parms);