1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
12 #include "tf_msg_common.h"
13 #include "tf_device.h"
16 #include "tf_common.h"
17 #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_TBL_TYPE_SET_DATA_SIZE 88
30 /* Compile check - Catch any msg changes that we depend on, like the
31 * defines listed above for array size checking.
33 * Checking array size is dangerous in that the type could change and
34 * we wouldn't be able to catch it. Thus we check if the complete msg
35 * changed instead. Best we can do.
37 * If failure is observed then both msg size (defines below) and the
38 * array size (define above) should be checked and compared.
40 #define TF_MSG_SIZE_HWRM_TF_GLOBAL_CFG_SET 56
41 static_assert(sizeof(struct hwrm_tf_global_cfg_set_input) ==
42 TF_MSG_SIZE_HWRM_TF_GLOBAL_CFG_SET,
43 "HWRM message size changed: hwrm_tf_global_cfg_set_input");
45 #define TF_MSG_SIZE_HWRM_TF_EM_INSERT 104
46 static_assert(sizeof(struct hwrm_tf_em_insert_input) ==
47 TF_MSG_SIZE_HWRM_TF_EM_INSERT,
48 "HWRM message size changed: hwrm_tf_em_insert_input");
50 #define TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET 128
51 static_assert(sizeof(struct hwrm_tf_tbl_type_set_input) ==
52 TF_MSG_SIZE_HWRM_TF_TBL_TYPE_SET,
53 "HWRM message size changed: hwrm_tf_tbl_type_set_input");
56 * This is the MAX data we can transport across regular HWRM
58 #define TF_PCI_BUF_SIZE_MAX 88
61 * If data bigger than TF_PCI_BUF_SIZE_MAX then use DMA method
63 struct tf_msg_dma_buf {
69 * Allocates a DMA buffer that can be used for message transfer.
72 * Pointer to DMA buffer structure
75 * Requested size of the buffer in bytes
79 * -ENOMEM - Unable to allocate buffer, no memory
82 tf_msg_alloc_dma_buf(struct tf_msg_dma_buf *buf, int size)
84 struct tfp_calloc_parms alloc_parms;
87 /* Allocate session */
88 alloc_parms.nitems = 1;
89 alloc_parms.size = size;
90 alloc_parms.alignment = 4096;
91 rc = tfp_calloc(&alloc_parms);
95 buf->pa_addr = (uintptr_t)alloc_parms.mem_pa;
96 buf->va_addr = alloc_parms.mem_va;
102 * Free's a previous allocated DMA buffer.
105 * Pointer to DMA buffer structure
108 tf_msg_free_dma_buf(struct tf_msg_dma_buf *buf)
110 tfp_free(buf->va_addr);
113 /* HWRM Direct messages */
116 tf_msg_session_open(struct tf *tfp,
117 char *ctrl_chan_name,
118 uint8_t *fw_session_id,
119 uint8_t *fw_session_client_id,
120 struct tf_dev_info *dev)
123 struct hwrm_tf_session_open_input req = { 0 };
124 struct hwrm_tf_session_open_output resp = { 0 };
125 struct tfp_send_msg_parms parms = { 0 };
127 /* Populate the request */
128 tfp_memcpy(&req.session_name, ctrl_chan_name, TF_SESSION_NAME_MAX);
130 parms.tf_type = HWRM_TF_SESSION_OPEN;
131 parms.req_data = (uint32_t *)&req;
132 parms.req_size = sizeof(req);
133 parms.resp_data = (uint32_t *)&resp;
134 parms.resp_size = sizeof(resp);
135 parms.mailbox = dev->ops->tf_dev_get_mailbox();
137 rc = tfp_send_msg_direct(tfp,
142 *fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
143 *fw_session_client_id =
144 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
150 tf_msg_session_attach(struct tf *tfp __rte_unused,
151 char *ctrl_chan_name __rte_unused,
152 uint8_t tf_fw_session_id __rte_unused)
158 tf_msg_session_client_register(struct tf *tfp,
159 struct tf_session *tfs,
160 char *ctrl_channel_name,
161 uint8_t *fw_session_client_id)
164 struct hwrm_tf_session_register_input req = { 0 };
165 struct hwrm_tf_session_register_output resp = { 0 };
166 struct tfp_send_msg_parms parms = { 0 };
167 uint8_t fw_session_id;
168 struct tf_dev_info *dev;
170 /* Retrieve the device information */
171 rc = tf_session_get_device(tfs, &dev);
174 "Failed to lookup device, rc:%s\n",
179 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
182 "Unable to lookup FW id, rc:%s\n",
187 /* Populate the request */
188 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
189 tfp_memcpy(&req.session_client_name,
191 TF_SESSION_NAME_MAX);
193 parms.tf_type = HWRM_TF_SESSION_REGISTER;
194 parms.req_data = (uint32_t *)&req;
195 parms.req_size = sizeof(req);
196 parms.resp_data = (uint32_t *)&resp;
197 parms.resp_size = sizeof(resp);
198 parms.mailbox = dev->ops->tf_dev_get_mailbox();
200 rc = tfp_send_msg_direct(tfp,
205 *fw_session_client_id =
206 (uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
212 tf_msg_session_client_unregister(struct tf *tfp,
213 struct tf_session *tfs,
214 uint8_t fw_session_client_id)
217 struct hwrm_tf_session_unregister_input req = { 0 };
218 struct hwrm_tf_session_unregister_output resp = { 0 };
219 struct tfp_send_msg_parms parms = { 0 };
220 uint8_t fw_session_id;
221 struct tf_dev_info *dev;
223 /* Retrieve the device information */
224 rc = tf_session_get_device(tfs, &dev);
227 "Failed to lookup device, rc:%s\n",
232 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
235 "Unable to lookup FW id, rc:%s\n",
240 /* Populate the request */
241 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
242 req.fw_session_client_id = tfp_cpu_to_le_32(fw_session_client_id);
244 parms.tf_type = HWRM_TF_SESSION_UNREGISTER;
245 parms.req_data = (uint32_t *)&req;
246 parms.req_size = sizeof(req);
247 parms.resp_data = (uint32_t *)&resp;
248 parms.resp_size = sizeof(resp);
249 parms.mailbox = dev->ops->tf_dev_get_mailbox();
251 rc = tfp_send_msg_direct(tfp,
258 tf_msg_session_close(struct tf *tfp,
259 struct tf_session *tfs)
262 struct hwrm_tf_session_close_input req = { 0 };
263 struct hwrm_tf_session_close_output resp = { 0 };
264 struct tfp_send_msg_parms parms = { 0 };
265 uint8_t fw_session_id;
266 struct tf_dev_info *dev;
268 /* Retrieve the device information */
269 rc = tf_session_get_device(tfs, &dev);
272 "Failed to lookup device, rc:%s\n",
277 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
280 "Unable to lookup FW id, rc:%s\n",
285 /* Populate the request */
286 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
288 parms.tf_type = HWRM_TF_SESSION_CLOSE;
289 parms.req_data = (uint32_t *)&req;
290 parms.req_size = sizeof(req);
291 parms.resp_data = (uint32_t *)&resp;
292 parms.resp_size = sizeof(resp);
293 parms.mailbox = dev->ops->tf_dev_get_mailbox();
295 rc = tfp_send_msg_direct(tfp,
301 tf_msg_session_qcfg(struct tf *tfp)
304 struct hwrm_tf_session_qcfg_input req = { 0 };
305 struct hwrm_tf_session_qcfg_output resp = { 0 };
306 struct tfp_send_msg_parms parms = { 0 };
307 uint8_t fw_session_id;
308 struct tf_dev_info *dev;
309 struct tf_session *tfs;
311 /* Retrieve the session information */
312 rc = tf_session_get_session_internal(tfp, &tfs);
315 "Failed to lookup session, rc:%s\n",
320 /* Retrieve the device information */
321 rc = tf_session_get_device(tfs, &dev);
324 "Failed to lookup device, rc:%s\n",
329 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
332 "Unable to lookup FW id, rc:%s\n",
337 /* Populate the request */
338 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
340 parms.tf_type = HWRM_TF_SESSION_QCFG,
341 parms.req_data = (uint32_t *)&req;
342 parms.req_size = sizeof(req);
343 parms.resp_data = (uint32_t *)&resp;
344 parms.resp_size = sizeof(resp);
345 parms.mailbox = dev->ops->tf_dev_get_mailbox();
347 rc = tfp_send_msg_direct(tfp,
353 tf_msg_session_resc_qcaps(struct tf *tfp,
354 struct tf_dev_info *dev,
357 struct tf_rm_resc_req_entry *query,
358 enum tf_rm_resc_resv_strategy *resv_strategy)
362 struct tfp_send_msg_parms parms = { 0 };
363 struct hwrm_tf_session_resc_qcaps_input req = { 0 };
364 struct hwrm_tf_session_resc_qcaps_output resp = { 0 };
365 uint8_t fw_session_id;
366 struct tf_msg_dma_buf qcaps_buf = { 0 };
367 struct tf_rm_resc_req_entry *data;
370 TF_CHECK_PARMS3(tfp, query, resv_strategy);
372 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
375 "%s: Unable to lookup FW id, rc:%s\n",
381 /* Prepare DMA buffer */
382 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
383 rc = tf_msg_alloc_dma_buf(&qcaps_buf, dma_size);
387 /* Populate the request */
388 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
389 req.flags = tfp_cpu_to_le_16(dir);
390 req.qcaps_size = size;
391 req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
393 parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
394 parms.req_data = (uint32_t *)&req;
395 parms.req_size = sizeof(req);
396 parms.resp_data = (uint32_t *)&resp;
397 parms.resp_size = sizeof(resp);
398 parms.mailbox = dev->ops->tf_dev_get_mailbox();
400 rc = tfp_send_msg_direct(tfp, &parms);
404 /* Process the response
405 * Should always get expected number of entries
407 if (tfp_le_to_cpu_32(resp.size) != size) {
409 "%s: QCAPS message size error, rc:%s\n",
416 /* Post process the response */
417 data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
418 for (i = 0; i < size; i++) {
419 query[i].type = tfp_le_to_cpu_32(data[i].type);
420 query[i].min = tfp_le_to_cpu_16(data[i].min);
421 query[i].max = tfp_le_to_cpu_16(data[i].max);
424 *resv_strategy = resp.flags &
425 HWRM_TF_SESSION_RESC_QCAPS_OUTPUT_FLAGS_SESS_RESV_STRATEGY_MASK;
428 tf_msg_free_dma_buf(&qcaps_buf);
434 tf_msg_session_resc_alloc(struct tf *tfp,
435 struct tf_dev_info *dev,
438 struct tf_rm_resc_req_entry *request,
439 struct tf_rm_resc_entry *resv)
443 struct tfp_send_msg_parms parms = { 0 };
444 struct hwrm_tf_session_resc_alloc_input req = { 0 };
445 struct hwrm_tf_session_resc_alloc_output resp = { 0 };
446 uint8_t fw_session_id;
447 struct tf_msg_dma_buf req_buf = { 0 };
448 struct tf_msg_dma_buf resv_buf = { 0 };
449 struct tf_rm_resc_req_entry *req_data;
450 struct tf_rm_resc_entry *resv_data;
453 TF_CHECK_PARMS3(tfp, request, resv);
455 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
458 "%s: Unable to lookup FW id, rc:%s\n",
464 /* Prepare DMA buffers */
465 dma_size = size * sizeof(struct tf_rm_resc_req_entry);
466 rc = tf_msg_alloc_dma_buf(&req_buf, dma_size);
470 dma_size = size * sizeof(struct tf_rm_resc_entry);
471 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
473 tf_msg_free_dma_buf(&req_buf);
477 /* Populate the request */
478 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
479 req.flags = tfp_cpu_to_le_16(dir);
482 req_data = (struct tf_rm_resc_req_entry *)req_buf.va_addr;
483 for (i = 0; i < size; i++) {
484 req_data[i].type = tfp_cpu_to_le_32(request[i].type);
485 req_data[i].min = tfp_cpu_to_le_16(request[i].min);
486 req_data[i].max = tfp_cpu_to_le_16(request[i].max);
489 req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
490 req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
492 parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
493 parms.req_data = (uint32_t *)&req;
494 parms.req_size = sizeof(req);
495 parms.resp_data = (uint32_t *)&resp;
496 parms.resp_size = sizeof(resp);
497 parms.mailbox = dev->ops->tf_dev_get_mailbox();
499 rc = tfp_send_msg_direct(tfp, &parms);
503 /* Process the response
504 * Should always get expected number of entries
506 if (tfp_le_to_cpu_32(resp.size) != size) {
508 "%s: Alloc message size error, rc:%s\n",
515 /* Post process the response */
516 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
517 for (i = 0; i < size; i++) {
518 resv[i].type = tfp_le_to_cpu_32(resv_data[i].type);
519 resv[i].start = tfp_le_to_cpu_16(resv_data[i].start);
520 resv[i].stride = tfp_le_to_cpu_16(resv_data[i].stride);
524 tf_msg_free_dma_buf(&req_buf);
525 tf_msg_free_dma_buf(&resv_buf);
531 tf_msg_session_resc_flush(struct tf *tfp,
534 struct tf_rm_resc_entry *resv)
538 struct tfp_send_msg_parms parms = { 0 };
539 struct hwrm_tf_session_resc_flush_input req = { 0 };
540 struct hwrm_tf_session_resc_flush_output resp = { 0 };
541 uint8_t fw_session_id;
542 struct tf_msg_dma_buf resv_buf = { 0 };
543 struct tf_rm_resc_entry *resv_data;
545 struct tf_dev_info *dev;
546 struct tf_session *tfs;
548 TF_CHECK_PARMS2(tfp, resv);
550 /* Retrieve the session information */
551 rc = tf_session_get_session_internal(tfp, &tfs);
554 "%s: Failed to lookup session, rc:%s\n",
560 /* Retrieve the device information */
561 rc = tf_session_get_device(tfs, &dev);
564 "%s: Failed to lookup device, rc:%s\n",
570 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
573 "%s: Unable to lookup FW id, rc:%s\n",
579 /* Prepare DMA buffers */
580 dma_size = size * sizeof(struct tf_rm_resc_entry);
581 rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
585 /* Populate the request */
586 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
587 req.flags = tfp_cpu_to_le_16(dir);
588 req.flush_size = size;
590 resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
591 for (i = 0; i < size; i++) {
592 resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
593 resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
594 resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
597 req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
599 parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
600 parms.req_data = (uint32_t *)&req;
601 parms.req_size = sizeof(req);
602 parms.resp_data = (uint32_t *)&resp;
603 parms.resp_size = sizeof(resp);
604 parms.mailbox = dev->ops->tf_dev_get_mailbox();
606 rc = tfp_send_msg_direct(tfp, &parms);
608 tf_msg_free_dma_buf(&resv_buf);
614 tf_msg_insert_em_internal_entry(struct tf *tfp,
615 struct tf_insert_em_entry_parms *em_parms,
616 uint16_t *rptr_index,
618 uint8_t *num_of_entries)
621 struct tfp_send_msg_parms parms = { 0 };
622 struct hwrm_tf_em_insert_input req = { 0 };
623 struct hwrm_tf_em_insert_output resp = { 0 };
624 struct tf_em_64b_entry *em_result =
625 (struct tf_em_64b_entry *)em_parms->em_record;
627 uint8_t fw_session_id;
628 uint8_t msg_key_size;
629 struct tf_dev_info *dev;
630 struct tf_session *tfs;
632 /* Retrieve the session information */
633 rc = tf_session_get_session_internal(tfp, &tfs);
636 "%s: Failed to lookup session, rc:%s\n",
637 tf_dir_2_str(em_parms->dir),
642 /* Retrieve the device information */
643 rc = tf_session_get_device(tfs, &dev);
646 "%s: Failed to lookup device, rc:%s\n",
647 tf_dir_2_str(em_parms->dir),
652 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
655 "%s: Unable to lookup FW id, rc:%s\n",
656 tf_dir_2_str(em_parms->dir),
661 /* Populate the request */
662 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
664 /* Check for key size conformity */
665 msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
666 if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
669 "%s: Invalid parameters for msg type, rc:%s\n",
670 tf_dir_2_str(em_parms->dir),
675 tfp_memcpy(req.em_key,
679 flags = (em_parms->dir == TF_DIR_TX ?
680 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
681 HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
682 req.flags = tfp_cpu_to_le_16(flags);
683 req.strength = (em_result->hdr.word1 &
684 CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
685 CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
686 req.em_key_bitlen = em_parms->key_sz_in_bits;
687 req.action_ptr = em_result->hdr.pointer;
688 req.em_record_idx = *rptr_index;
690 parms.tf_type = HWRM_TF_EM_INSERT;
691 parms.req_data = (uint32_t *)&req;
692 parms.req_size = sizeof(req);
693 parms.resp_data = (uint32_t *)&resp;
694 parms.resp_size = sizeof(resp);
695 parms.mailbox = dev->ops->tf_dev_get_mailbox();
697 rc = tfp_send_msg_direct(tfp,
702 *rptr_entry = resp.rptr_entry;
703 *rptr_index = resp.rptr_index;
704 *num_of_entries = resp.num_of_entries;
710 tf_msg_delete_em_entry(struct tf *tfp,
711 struct tf_delete_em_entry_parms *em_parms)
714 struct tfp_send_msg_parms parms = { 0 };
715 struct hwrm_tf_em_delete_input req = { 0 };
716 struct hwrm_tf_em_delete_output resp = { 0 };
718 uint8_t fw_session_id;
719 struct tf_dev_info *dev;
720 struct tf_session *tfs;
722 /* Retrieve the session information */
723 rc = tf_session_get_session_internal(tfp, &tfs);
726 "%s: Failed to lookup session, rc:%s\n",
727 tf_dir_2_str(em_parms->dir),
732 /* Retrieve the device information */
733 rc = tf_session_get_device(tfs, &dev);
736 "%s: Failed to lookup device, rc:%s\n",
737 tf_dir_2_str(em_parms->dir),
742 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
745 "%s: Unable to lookup FW id, rc:%s\n",
746 tf_dir_2_str(em_parms->dir),
751 /* Populate the request */
752 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
754 flags = (em_parms->dir == TF_DIR_TX ?
755 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
756 HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
757 req.flags = tfp_cpu_to_le_16(flags);
758 req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
760 parms.tf_type = HWRM_TF_EM_DELETE;
761 parms.req_data = (uint32_t *)&req;
762 parms.req_size = sizeof(req);
763 parms.resp_data = (uint32_t *)&resp;
764 parms.resp_size = sizeof(resp);
765 parms.mailbox = dev->ops->tf_dev_get_mailbox();
767 rc = tfp_send_msg_direct(tfp,
772 em_parms->index = tfp_le_to_cpu_16(resp.em_index);
778 tf_msg_em_mem_rgtr(struct tf *tfp,
785 struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
786 struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
787 struct tfp_send_msg_parms parms = { 0 };
788 struct tf_dev_info *dev;
789 struct tf_session *tfs;
791 /* Retrieve the session information */
792 rc = tf_session_get_session_internal(tfp, &tfs);
795 "Failed to lookup session, rc:%s\n",
800 /* Retrieve the device information */
801 rc = tf_session_get_device(tfs, &dev);
804 "Failed to lookup device, rc:%s\n",
809 req.page_level = page_lvl;
810 req.page_size = page_size;
811 req.page_dir = tfp_cpu_to_le_64(dma_addr);
813 parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
814 parms.req_data = (uint32_t *)&req;
815 parms.req_size = sizeof(req);
816 parms.resp_data = (uint32_t *)&resp;
817 parms.resp_size = sizeof(resp);
818 parms.mailbox = dev->ops->tf_dev_get_mailbox();
820 rc = tfp_send_msg_direct(tfp,
825 *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
831 tf_msg_em_mem_unrgtr(struct tf *tfp,
835 struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
836 struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
837 struct tfp_send_msg_parms parms = { 0 };
838 struct tf_dev_info *dev;
839 struct tf_session *tfs;
841 /* Retrieve the session information */
842 rc = tf_session_get_session_internal(tfp, &tfs);
845 "Failed to lookup session, rc:%s\n",
850 /* Retrieve the device information */
851 rc = tf_session_get_device(tfs, &dev);
854 "Failed to lookup device, rc:%s\n",
859 req.ctx_id = tfp_cpu_to_le_32(*ctx_id);
861 parms.tf_type = HWRM_TF_CTXT_MEM_UNRGTR;
862 parms.req_data = (uint32_t *)&req;
863 parms.req_size = sizeof(req);
864 parms.resp_data = (uint32_t *)&resp;
865 parms.resp_size = sizeof(resp);
866 parms.mailbox = dev->ops->tf_dev_get_mailbox();
868 rc = tfp_send_msg_direct(tfp,
874 tf_msg_em_qcaps(struct tf *tfp,
876 struct tf_em_caps *em_caps)
879 struct hwrm_tf_ext_em_qcaps_input req = {0};
880 struct hwrm_tf_ext_em_qcaps_output resp = { 0 };
882 struct tfp_send_msg_parms parms = { 0 };
883 struct tf_dev_info *dev;
884 struct tf_session *tfs;
886 /* Retrieve the session information */
887 rc = tf_session_get_session_internal(tfp, &tfs);
890 "%s: Failed to lookup session, rc:%s\n",
896 /* Retrieve the device information */
897 rc = tf_session_get_device(tfs, &dev);
900 "%s: Failed to lookup device, rc:%s\n",
906 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_TX :
907 HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_DIR_RX);
908 req.flags = tfp_cpu_to_le_32(flags);
910 parms.tf_type = HWRM_TF_EXT_EM_QCAPS;
911 parms.req_data = (uint32_t *)&req;
912 parms.req_size = sizeof(req);
913 parms.resp_data = (uint32_t *)&resp;
914 parms.resp_size = sizeof(resp);
915 parms.mailbox = dev->ops->tf_dev_get_mailbox();
917 rc = tfp_send_msg_direct(tfp,
922 em_caps->supported = tfp_le_to_cpu_32(resp.supported);
923 em_caps->max_entries_supported =
924 tfp_le_to_cpu_32(resp.max_entries_supported);
925 em_caps->key_entry_size = tfp_le_to_cpu_16(resp.key_entry_size);
926 em_caps->record_entry_size =
927 tfp_le_to_cpu_16(resp.record_entry_size);
928 em_caps->efc_entry_size = tfp_le_to_cpu_16(resp.efc_entry_size);
934 tf_msg_em_cfg(struct tf *tfp,
935 uint32_t num_entries,
936 uint16_t key0_ctx_id,
937 uint16_t key1_ctx_id,
938 uint16_t record_ctx_id,
940 uint8_t flush_interval,
944 struct hwrm_tf_ext_em_cfg_input req = {0};
945 struct hwrm_tf_ext_em_cfg_output resp = {0};
947 struct tfp_send_msg_parms parms = { 0 };
948 struct tf_dev_info *dev;
949 struct tf_session *tfs;
951 /* Retrieve the session information */
952 rc = tf_session_get_session_internal(tfp, &tfs);
955 "%s: Failed to lookup session, rc:%s\n",
961 /* Retrieve the device information */
962 rc = tf_session_get_device(tfs, &dev);
965 "%s: Failed to lookup device, rc:%s\n",
971 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
972 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
973 flags |= HWRM_TF_EXT_EM_QCAPS_INPUT_FLAGS_PREFERRED_OFFLOAD;
975 req.flags = tfp_cpu_to_le_32(flags);
976 req.num_entries = tfp_cpu_to_le_32(num_entries);
978 req.flush_interval = flush_interval;
980 req.key0_ctx_id = tfp_cpu_to_le_16(key0_ctx_id);
981 req.key1_ctx_id = tfp_cpu_to_le_16(key1_ctx_id);
982 req.record_ctx_id = tfp_cpu_to_le_16(record_ctx_id);
983 req.efc_ctx_id = tfp_cpu_to_le_16(efc_ctx_id);
985 parms.tf_type = HWRM_TF_EXT_EM_CFG;
986 parms.req_data = (uint32_t *)&req;
987 parms.req_size = sizeof(req);
988 parms.resp_data = (uint32_t *)&resp;
989 parms.resp_size = sizeof(resp);
990 parms.mailbox = dev->ops->tf_dev_get_mailbox();
992 rc = tfp_send_msg_direct(tfp,
998 tf_msg_em_op(struct tf *tfp,
1003 struct hwrm_tf_ext_em_op_input req = {0};
1004 struct hwrm_tf_ext_em_op_output resp = {0};
1006 struct tfp_send_msg_parms parms = { 0 };
1007 struct tf_dev_info *dev;
1008 struct tf_session *tfs;
1010 /* Retrieve the session information */
1011 rc = tf_session_get_session_internal(tfp, &tfs);
1014 "%s: Failed to lookup session, rc:%s\n",
1020 /* Retrieve the device information */
1021 rc = tf_session_get_device(tfs, &dev);
1024 "%s: Failed to lookup device, rc:%s\n",
1030 flags = (dir == TF_DIR_TX ? HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_TX :
1031 HWRM_TF_EXT_EM_CFG_INPUT_FLAGS_DIR_RX);
1032 req.flags = tfp_cpu_to_le_32(flags);
1033 req.op = tfp_cpu_to_le_16(op);
1035 parms.tf_type = HWRM_TF_EXT_EM_OP;
1036 parms.req_data = (uint32_t *)&req;
1037 parms.req_size = sizeof(req);
1038 parms.resp_data = (uint32_t *)&resp;
1039 parms.resp_size = sizeof(resp);
1040 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1042 rc = tfp_send_msg_direct(tfp,
1048 tf_msg_tcam_entry_set(struct tf *tfp,
1049 struct tf_dev_info *dev,
1050 struct tf_tcam_set_parms *parms)
1053 struct tfp_send_msg_parms mparms = { 0 };
1054 struct hwrm_tf_tcam_set_input req = { 0 };
1055 struct hwrm_tf_tcam_set_output resp = { 0 };
1056 struct tf_msg_dma_buf buf = { 0 };
1057 uint8_t *data = NULL;
1059 uint8_t fw_session_id;
1061 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1064 "%s: Unable to lookup FW id, rc:%s\n",
1065 tf_dir_2_str(parms->dir),
1070 /* Populate the request */
1071 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1072 req.type = parms->hcapi_type;
1073 req.idx = tfp_cpu_to_le_16(parms->idx);
1074 if (parms->dir == TF_DIR_TX)
1075 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DIR_TX;
1077 req.key_size = parms->key_size;
1078 req.mask_offset = parms->key_size;
1079 /* Result follows after key and mask, thus multiply by 2 */
1080 req.result_offset = 2 * parms->key_size;
1081 req.result_size = parms->result_size;
1082 data_size = 2 * req.key_size + req.result_size;
1084 if (data_size <= TF_PCI_BUF_SIZE_MAX) {
1085 /* use pci buffer */
1086 data = &req.dev_data[0];
1088 /* use dma buffer */
1089 req.flags |= HWRM_TF_TCAM_SET_INPUT_FLAGS_DMA;
1090 rc = tf_msg_alloc_dma_buf(&buf, data_size);
1094 tfp_memcpy(&req.dev_data[0],
1096 sizeof(buf.pa_addr));
1099 tfp_memcpy(&data[0], parms->key, parms->key_size);
1100 tfp_memcpy(&data[parms->key_size], parms->mask, parms->key_size);
1101 tfp_memcpy(&data[req.result_offset], parms->result, parms->result_size);
1103 mparms.tf_type = HWRM_TF_TCAM_SET;
1104 mparms.req_data = (uint32_t *)&req;
1105 mparms.req_size = sizeof(req);
1106 mparms.resp_data = (uint32_t *)&resp;
1107 mparms.resp_size = sizeof(resp);
1108 mparms.mailbox = dev->ops->tf_dev_get_mailbox();
1110 rc = tfp_send_msg_direct(tfp,
1114 tf_msg_free_dma_buf(&buf);
1120 tf_msg_tcam_entry_free(struct tf *tfp,
1121 struct tf_dev_info *dev,
1122 struct tf_tcam_free_parms *in_parms)
1125 struct hwrm_tf_tcam_free_input req = { 0 };
1126 struct hwrm_tf_tcam_free_output resp = { 0 };
1127 struct tfp_send_msg_parms parms = { 0 };
1128 uint8_t fw_session_id;
1130 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1133 "%s: Unable to lookup FW id, rc:%s\n",
1134 tf_dir_2_str(in_parms->dir),
1139 /* Populate the request */
1140 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1141 req.type = in_parms->hcapi_type;
1143 req.idx_list[0] = tfp_cpu_to_le_16(in_parms->idx);
1144 if (in_parms->dir == TF_DIR_TX)
1145 req.flags |= HWRM_TF_TCAM_FREE_INPUT_FLAGS_DIR_TX;
1147 parms.tf_type = HWRM_TF_TCAM_FREE;
1148 parms.req_data = (uint32_t *)&req;
1149 parms.req_size = sizeof(req);
1150 parms.resp_data = (uint32_t *)&resp;
1151 parms.resp_size = sizeof(resp);
1152 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1154 rc = tfp_send_msg_direct(tfp,
1160 tf_msg_set_tbl_entry(struct tf *tfp,
1162 uint16_t hcapi_type,
1168 struct hwrm_tf_tbl_type_set_input req = { 0 };
1169 struct hwrm_tf_tbl_type_set_output resp = { 0 };
1170 struct tfp_send_msg_parms parms = { 0 };
1171 uint8_t fw_session_id;
1172 struct tf_dev_info *dev;
1173 struct tf_session *tfs;
1175 /* Retrieve the session information */
1176 rc = tf_session_get_session_internal(tfp, &tfs);
1179 "%s: Failed to lookup session, rc:%s\n",
1185 /* Retrieve the device information */
1186 rc = tf_session_get_device(tfs, &dev);
1189 "%s: Failed to lookup device, rc:%s\n",
1195 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1198 "%s: Unable to lookup FW id, rc:%s\n",
1204 /* Populate the request */
1205 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1206 req.flags = tfp_cpu_to_le_16(dir);
1207 req.type = tfp_cpu_to_le_32(hcapi_type);
1208 req.size = tfp_cpu_to_le_16(size);
1209 req.index = tfp_cpu_to_le_32(index);
1211 /* Check for data size conformity */
1212 if (size > TF_MSG_TBL_TYPE_SET_DATA_SIZE) {
1215 "%s: Invalid parameters for msg type, rc:%s\n",
1221 tfp_memcpy(&req.data,
1225 parms.tf_type = HWRM_TF_TBL_TYPE_SET;
1226 parms.req_data = (uint32_t *)&req;
1227 parms.req_size = sizeof(req);
1228 parms.resp_data = (uint32_t *)&resp;
1229 parms.resp_size = sizeof(resp);
1230 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1232 rc = tfp_send_msg_direct(tfp,
1237 return tfp_le_to_cpu_32(parms.tf_resp_code);
1241 tf_msg_get_tbl_entry(struct tf *tfp,
1243 uint16_t hcapi_type,
1249 struct hwrm_tf_tbl_type_get_input req = { 0 };
1250 struct hwrm_tf_tbl_type_get_output resp = { 0 };
1251 struct tfp_send_msg_parms parms = { 0 };
1252 uint8_t fw_session_id;
1253 struct tf_dev_info *dev;
1254 struct tf_session *tfs;
1256 /* Retrieve the session information */
1257 rc = tf_session_get_session_internal(tfp, &tfs);
1260 "%s: Failed to lookup session, rc:%s\n",
1266 /* Retrieve the device information */
1267 rc = tf_session_get_device(tfs, &dev);
1270 "%s: Failed to lookup device, rc:%s\n",
1276 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1279 "%s: Unable to lookup FW id, rc:%s\n",
1285 /* Populate the request */
1286 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1287 req.flags = tfp_cpu_to_le_16(dir);
1288 req.type = tfp_cpu_to_le_32(hcapi_type);
1289 req.index = tfp_cpu_to_le_32(index);
1291 parms.tf_type = HWRM_TF_TBL_TYPE_GET;
1292 parms.req_data = (uint32_t *)&req;
1293 parms.req_size = sizeof(req);
1294 parms.resp_data = (uint32_t *)&resp;
1295 parms.resp_size = sizeof(resp);
1296 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1298 rc = tfp_send_msg_direct(tfp,
1303 /* Verify that we got enough buffer to return the requested data */
1304 if (tfp_le_to_cpu_32(resp.size) != size)
1311 return tfp_le_to_cpu_32(parms.tf_resp_code);
1314 /* HWRM Tunneled messages */
1317 tf_msg_get_global_cfg(struct tf *tfp,
1318 struct tf_global_cfg_parms *params)
1321 struct tfp_send_msg_parms parms = { 0 };
1322 struct hwrm_tf_global_cfg_get_input req = { 0 };
1323 struct hwrm_tf_global_cfg_get_output resp = { 0 };
1325 uint8_t fw_session_id;
1326 uint16_t resp_size = 0;
1327 struct tf_dev_info *dev;
1328 struct tf_session *tfs;
1330 /* Retrieve the session information */
1331 rc = tf_session_get_session_internal(tfp, &tfs);
1334 "%s: Failed to lookup session, rc:%s\n",
1335 tf_dir_2_str(params->dir),
1340 /* Retrieve the device information */
1341 rc = tf_session_get_device(tfs, &dev);
1344 "%s: Failed to lookup device, rc:%s\n",
1345 tf_dir_2_str(params->dir),
1350 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1353 "%s: Unable to lookup FW id, rc:%s\n",
1354 tf_dir_2_str(params->dir),
1359 flags = (params->dir == TF_DIR_TX ?
1360 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_TX :
1361 HWRM_TF_GLOBAL_CFG_GET_INPUT_FLAGS_DIR_RX);
1363 /* Populate the request */
1364 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1365 req.flags = tfp_cpu_to_le_32(flags);
1366 req.type = tfp_cpu_to_le_32(params->type);
1367 req.offset = tfp_cpu_to_le_32(params->offset);
1368 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1370 parms.tf_type = HWRM_TF_GLOBAL_CFG_GET;
1371 parms.req_data = (uint32_t *)&req;
1372 parms.req_size = sizeof(req);
1373 parms.resp_data = (uint32_t *)&resp;
1374 parms.resp_size = sizeof(resp);
1375 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1377 rc = tfp_send_msg_direct(tfp, &parms);
1381 /* Verify that we got enough buffer to return the requested data */
1382 resp_size = tfp_le_to_cpu_16(resp.size);
1383 if (resp_size < params->config_sz_in_bytes)
1387 tfp_memcpy(params->config,
1393 return tfp_le_to_cpu_32(parms.tf_resp_code);
1397 tf_msg_set_global_cfg(struct tf *tfp,
1398 struct tf_global_cfg_parms *params)
1401 struct tfp_send_msg_parms parms = { 0 };
1402 struct hwrm_tf_global_cfg_set_input req = { 0 };
1403 struct hwrm_tf_global_cfg_set_output resp = { 0 };
1405 uint8_t fw_session_id;
1406 struct tf_dev_info *dev;
1407 struct tf_session *tfs;
1409 /* Retrieve the session information */
1410 rc = tf_session_get_session_internal(tfp, &tfs);
1413 "%s: Failed to lookup session, rc:%s\n",
1414 tf_dir_2_str(params->dir),
1419 /* Retrieve the device information */
1420 rc = tf_session_get_device(tfs, &dev);
1423 "%s: Failed to lookup device, rc:%s\n",
1424 tf_dir_2_str(params->dir),
1429 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1432 "%s: Unable to lookup FW id, rc:%s\n",
1433 tf_dir_2_str(params->dir),
1438 flags = (params->dir == TF_DIR_TX ?
1439 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_TX :
1440 HWRM_TF_GLOBAL_CFG_SET_INPUT_FLAGS_DIR_RX);
1442 /* Populate the request */
1443 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1444 req.flags = tfp_cpu_to_le_32(flags);
1445 req.type = tfp_cpu_to_le_32(params->type);
1446 req.offset = tfp_cpu_to_le_32(params->offset);
1448 /* Check for data size conformity */
1449 if (params->config_sz_in_bytes > TF_MSG_SET_GLOBAL_CFG_DATA_SIZE) {
1452 "%s: Invalid parameters for msg type, rc:%s\n",
1453 tf_dir_2_str(params->dir),
1458 tfp_memcpy(req.data, params->config,
1459 params->config_sz_in_bytes);
1461 /* Only set mask if pointer is provided
1463 if (params->config_mask) {
1464 tfp_memcpy(req.mask,
1465 params->config_mask,
1466 params->config_sz_in_bytes);
1469 req.size = tfp_cpu_to_le_32(params->config_sz_in_bytes);
1471 parms.tf_type = HWRM_TF_GLOBAL_CFG_SET;
1472 parms.req_data = (uint32_t *)&req;
1473 parms.req_size = sizeof(req);
1474 parms.resp_data = (uint32_t *)&resp;
1475 parms.resp_size = sizeof(resp);
1476 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1478 rc = tfp_send_msg_direct(tfp, &parms);
1483 return tfp_le_to_cpu_32(parms.tf_resp_code);
1487 tf_msg_bulk_get_tbl_entry(struct tf *tfp,
1489 uint16_t hcapi_type,
1490 uint32_t starting_idx,
1491 uint16_t num_entries,
1492 uint16_t entry_sz_in_bytes,
1493 uint64_t physical_mem_addr)
1496 struct tfp_send_msg_parms parms = { 0 };
1497 struct tf_tbl_type_bulk_get_input req = { 0 };
1498 struct tf_tbl_type_bulk_get_output resp = { 0 };
1500 uint8_t fw_session_id;
1501 struct tf_dev_info *dev;
1502 struct tf_session *tfs;
1504 /* Retrieve the session information */
1505 rc = tf_session_get_session(tfp, &tfs);
1508 "%s: Failed to lookup session, rc:%s\n",
1514 /* Retrieve the device information */
1515 rc = tf_session_get_device(tfs, &dev);
1518 "%s: Failed to lookup device, rc:%s\n",
1524 rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
1527 "%s: Unable to lookup FW id, rc:%s\n",
1533 /* Populate the request */
1534 req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
1535 req.flags = tfp_cpu_to_le_16(dir);
1536 req.type = tfp_cpu_to_le_32(hcapi_type);
1537 req.start_index = tfp_cpu_to_le_32(starting_idx);
1538 req.num_entries = tfp_cpu_to_le_32(num_entries);
1540 data_size = num_entries * entry_sz_in_bytes;
1542 req.host_addr = tfp_cpu_to_le_64(physical_mem_addr);
1545 dev->ops->tf_dev_get_mailbox(),
1547 HWRM_TFT_TBL_TYPE_BULK_GET,
1551 rc = tfp_send_msg_tunneled(tfp, &parms);
1555 /* Verify that we got enough buffer to return the requested data */
1556 if (tfp_le_to_cpu_32(resp.size) != data_size)
1559 return tfp_le_to_cpu_32(parms.tf_resp_code);
1563 tf_msg_get_if_tbl_entry(struct tf *tfp,
1564 struct tf_if_tbl_get_parms *params)
1567 struct tfp_send_msg_parms parms = { 0 };
1568 struct hwrm_tf_if_tbl_get_input req = { 0 };
1569 struct hwrm_tf_if_tbl_get_output resp = { 0 };
1571 struct tf_dev_info *dev;
1572 struct tf_session *tfs;
1574 /* Retrieve the session information */
1575 rc = tf_session_get_session(tfp, &tfs);
1578 "%s: Failed to lookup session, rc:%s\n",
1579 tf_dir_2_str(params->dir),
1584 /* Retrieve the device information */
1585 rc = tf_session_get_device(tfs, &dev);
1588 "%s: Failed to lookup device, rc:%s\n",
1589 tf_dir_2_str(params->dir),
1594 flags = (params->dir == TF_DIR_TX ?
1595 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_TX :
1596 HWRM_TF_IF_TBL_GET_INPUT_FLAGS_DIR_RX);
1598 /* Populate the request */
1600 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
1602 req.type = params->hcapi_type;
1603 req.index = tfp_cpu_to_le_16(params->idx);
1604 req.size = tfp_cpu_to_le_16(params->data_sz_in_bytes);
1606 parms.tf_type = HWRM_TF_IF_TBL_GET;
1607 parms.req_data = (uint32_t *)&req;
1608 parms.req_size = sizeof(req);
1609 parms.resp_data = (uint32_t *)&resp;
1610 parms.resp_size = sizeof(resp);
1611 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1613 rc = tfp_send_msg_direct(tfp, &parms);
1618 if (parms.tf_resp_code != 0)
1619 return tfp_le_to_cpu_32(parms.tf_resp_code);
1621 tfp_memcpy(params->data, resp.data, req.size);
1623 return tfp_le_to_cpu_32(parms.tf_resp_code);
1627 tf_msg_set_if_tbl_entry(struct tf *tfp,
1628 struct tf_if_tbl_set_parms *params)
1631 struct tfp_send_msg_parms parms = { 0 };
1632 struct hwrm_tf_if_tbl_set_input req = { 0 };
1633 struct hwrm_tf_if_tbl_get_output resp = { 0 };
1635 struct tf_dev_info *dev;
1636 struct tf_session *tfs;
1638 /* Retrieve the session information */
1639 rc = tf_session_get_session(tfp, &tfs);
1642 "%s: Failed to lookup session, rc:%s\n",
1643 tf_dir_2_str(params->dir),
1648 /* Retrieve the device information */
1649 rc = tf_session_get_device(tfs, &dev);
1653 flags = (params->dir == TF_DIR_TX ?
1654 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_TX :
1655 HWRM_TF_IF_TBL_SET_INPUT_FLAGS_DIR_RX);
1657 /* Populate the request */
1659 tfp_cpu_to_le_32(tfs->session_id.internal.fw_session_id);
1661 req.type = params->hcapi_type;
1662 req.index = tfp_cpu_to_le_32(params->idx);
1663 req.size = tfp_cpu_to_le_32(params->data_sz_in_bytes);
1664 tfp_memcpy(&req.data[0], params->data, params->data_sz_in_bytes);
1666 parms.tf_type = HWRM_TF_IF_TBL_SET;
1667 parms.req_data = (uint32_t *)&req;
1668 parms.req_size = sizeof(req);
1669 parms.resp_data = (uint32_t *)&resp;
1670 parms.resp_size = sizeof(resp);
1671 parms.mailbox = dev->ops->tf_dev_get_mailbox();
1673 rc = tfp_send_msg_direct(tfp, &parms);
1678 return tfp_le_to_cpu_32(parms.tf_resp_code);