+ struct hwrm_tf_session_resc_flush_input req = { 0 };
+ struct hwrm_tf_session_resc_flush_output resp = { 0 };
+ uint8_t fw_session_id;
+ struct tf_msg_dma_buf resv_buf = { 0 };
+ struct tf_rm_resc_entry *resv_data;
+ int dma_size;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+
+ TF_CHECK_PARMS2(tfp, resv);
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Unable to lookup FW id, rc:%s\n",
+ tf_dir_2_str(dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Prepare DMA buffers */
+ dma_size = size * sizeof(struct tf_rm_resc_entry);
+ rc = tf_msg_alloc_dma_buf(&resv_buf, dma_size);
+ if (rc)
+ return rc;
+
+ /* Populate the request */
+ req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
+ req.flags = tfp_cpu_to_le_16(dir);
+ req.flush_size = size;
+
+ resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
+ for (i = 0; i < size; i++) {
+ resv_data[i].type = tfp_cpu_to_le_32(resv[i].type);
+ resv_data[i].start = tfp_cpu_to_le_16(resv[i].start);
+ resv_data[i].stride = tfp_cpu_to_le_16(resv[i].stride);
+ }
+
+ req.flush_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
+
+ parms.tf_type = HWRM_TF_SESSION_RESC_FLUSH;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
+
+ tf_msg_free_dma_buf(&resv_buf);
+
+ return rc;
+}
+
+int
+tf_msg_insert_em_internal_entry(struct tf *tfp,
+ struct tf_insert_em_entry_parms *em_parms,
+ uint16_t *rptr_index,
+ uint8_t *rptr_entry,
+ uint8_t *num_of_entries)
+{
+ int rc;
+ struct tfp_send_msg_parms parms = { 0 };
+ struct hwrm_tf_em_insert_input req = { 0 };
+ struct hwrm_tf_em_insert_output resp = { 0 };
+ struct tf_em_64b_entry *em_result =
+ (struct tf_em_64b_entry *)em_parms->em_record;
+ uint16_t flags;
+ uint8_t fw_session_id;
+ uint8_t msg_key_size;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+
+ RTE_BUILD_BUG_ON(sizeof(struct hwrm_tf_em_insert_input) !=
+ TF_MSG_SIZE_HWRM_TF_EM_INSERT);
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Unable to lookup FW id, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Populate the request */
+ req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
+
+ /* Check for key size conformity */
+ msg_key_size = (em_parms->key_sz_in_bits + 7) / 8;
+ if (msg_key_size > TF_MSG_EM_INSERT_KEY_SIZE) {
+ rc = -EINVAL;
+ TFP_DRV_LOG(ERR,
+ "%s: Invalid parameters for msg type, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ tfp_memcpy(req.em_key,
+ em_parms->key,
+ msg_key_size);
+
+ flags = (em_parms->dir == TF_DIR_TX ?
+ HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
+ HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
+ req.flags = tfp_cpu_to_le_16(flags);
+ req.strength = (em_result->hdr.word1 &
+ CFA_P4_EEM_ENTRY_STRENGTH_MASK) >>
+ CFA_P4_EEM_ENTRY_STRENGTH_SHIFT;
+ req.em_key_bitlen = em_parms->key_sz_in_bits;
+ req.action_ptr = em_result->hdr.pointer;
+ req.em_record_idx = *rptr_index;
+
+ parms.tf_type = HWRM_TF_EM_INSERT;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
+ &parms);
+ if (rc)
+ return rc;
+
+ *rptr_entry = resp.rptr_entry;
+ *rptr_index = resp.rptr_index;
+ *num_of_entries = resp.num_of_entries;
+
+ return 0;
+}
+
+int
+tf_msg_hash_insert_em_internal_entry(struct tf *tfp,
+ struct tf_insert_em_entry_parms *em_parms,
+ uint32_t key0_hash,
+ uint32_t key1_hash,
+ uint16_t *rptr_index,
+ uint8_t *rptr_entry,
+ uint8_t *num_of_entries)
+{
+ int rc;
+ struct tfp_send_msg_parms parms = { 0 };
+ struct hwrm_tf_em_hash_insert_input req = { 0 };
+ struct hwrm_tf_em_hash_insert_output resp = { 0 };
+ uint16_t flags;
+ uint8_t fw_session_id;
+ uint8_t msg_record_size;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Unable to lookup FW id, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Populate the request */
+ req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
+
+ /* Check for key size conformity */
+ msg_record_size = (em_parms->em_record_sz_in_bits + 7) / 8;
+
+ if (msg_record_size > TF_MSG_EM_INSERT_RECORD_SIZE) {
+ rc = -EINVAL;
+ TFP_DRV_LOG(ERR,
+ "%s: Record size to large, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ tfp_memcpy((char *)req.em_record,
+ em_parms->em_record,
+ msg_record_size);
+
+ flags = (em_parms->dir == TF_DIR_TX ?
+ HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_TX :
+ HWRM_TF_EM_INSERT_INPUT_FLAGS_DIR_RX);
+ req.flags = tfp_cpu_to_le_16(flags);
+ req.em_record_size_bits = em_parms->em_record_sz_in_bits;
+ req.em_record_idx = *rptr_index;
+ req.key0_hash = key0_hash;
+ req.key1_hash = key1_hash;
+
+ parms.tf_type = HWRM_TF_EM_HASH_INSERT;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
+ &parms);
+ if (rc)
+ return rc;
+
+ *rptr_entry = resp.rptr_entry;
+ *rptr_index = resp.rptr_index;
+ *num_of_entries = resp.num_of_entries;
+
+ return 0;
+}
+
+int
+tf_msg_delete_em_entry(struct tf *tfp,
+ struct tf_delete_em_entry_parms *em_parms)
+{
+ int rc;
+ struct tfp_send_msg_parms parms = { 0 };
+ struct hwrm_tf_em_delete_input req = { 0 };
+ struct hwrm_tf_em_delete_output resp = { 0 };
+ uint16_t flags;
+ uint8_t fw_session_id;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Unable to lookup FW id, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Populate the request */
+ req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
+
+ flags = (em_parms->dir == TF_DIR_TX ?
+ HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
+ HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
+ req.flags = tfp_cpu_to_le_16(flags);
+ req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
+
+ parms.tf_type = HWRM_TF_EM_DELETE;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
+ &parms);
+ if (rc)
+ return rc;
+
+ em_parms->index = tfp_le_to_cpu_16(resp.em_index);
+
+ return 0;
+}
+
+int
+tf_msg_move_em_entry(struct tf *tfp,
+ struct tf_move_em_entry_parms *em_parms)
+{
+ int rc;
+ struct tfp_send_msg_parms parms = { 0 };
+ struct hwrm_tf_em_move_input req = { 0 };
+ struct hwrm_tf_em_move_output resp = { 0 };
+ uint16_t flags;
+ uint8_t fw_session_id;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Unable to lookup FW id, rc:%s\n",
+ tf_dir_2_str(em_parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Populate the request */
+ req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
+
+ flags = (em_parms->dir == TF_DIR_TX ?
+ HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_TX :
+ HWRM_TF_EM_DELETE_INPUT_FLAGS_DIR_RX);
+ req.flags = tfp_cpu_to_le_16(flags);
+ req.flow_handle = tfp_cpu_to_le_64(em_parms->flow_handle);
+ req.new_index = tfp_cpu_to_le_32(em_parms->new_index);
+
+ parms.tf_type = HWRM_TF_EM_MOVE;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
+ &parms);
+ if (rc)
+ return rc;
+
+ em_parms->index = tfp_le_to_cpu_16(resp.em_index);
+
+ return 0;
+}
+
+int tf_msg_ext_em_ctxt_mem_alloc(struct tf *tfp,
+ struct hcapi_cfa_em_table *tbl,
+ uint64_t *dma_addr,
+ uint32_t *page_lvl,
+ uint32_t *page_size)
+{
+ struct tfp_send_msg_parms parms = { 0 };
+ struct hwrm_tf_ctxt_mem_alloc_input req = {0};
+ struct hwrm_tf_ctxt_mem_alloc_output resp = {0};
+ uint32_t mem_size_k;
+ int rc = 0;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+ uint32_t fw_se_id;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+ /* Retrieve the session information */
+ fw_se_id = tfs->session_id.internal.fw_session_id;
+
+ if (tbl->num_entries && tbl->entry_size) {
+ /* unit: kbytes */
+ mem_size_k = (tbl->num_entries / TF_KILOBYTE) * tbl->entry_size;
+ req.mem_size = tfp_cpu_to_le_32(mem_size_k);
+ req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
+ parms.tf_type = HWRM_TF_CTXT_MEM_ALLOC;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
+ if (rc) {
+ TFP_DRV_LOG(ERR, "Failed ext_em_alloc error rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ *dma_addr = tfp_le_to_cpu_64(resp.page_dir);
+ *page_lvl = resp.page_level;
+ *page_size = resp.page_size;
+ }
+
+ return rc;
+}
+
+int tf_msg_ext_em_ctxt_mem_free(struct tf *tfp,
+ uint32_t mem_size_k,
+ uint64_t dma_addr,
+ uint8_t page_level,
+ uint8_t page_size)
+{
+ struct tfp_send_msg_parms parms = { 0 };
+ struct hwrm_tf_ctxt_mem_free_input req = {0};
+ struct hwrm_tf_ctxt_mem_free_output resp = {0};
+ int rc = 0;
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+ uint32_t fw_se_id;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+ /* Retrieve the session information */
+ fw_se_id = tfs->session_id.internal.fw_session_id;
+
+ req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
+ req.mem_size = tfp_cpu_to_le_32(mem_size_k);
+ req.page_dir = tfp_cpu_to_le_64(dma_addr);
+ req.page_level = page_level;
+ req.page_size = page_size;
+ parms.tf_type = HWRM_TF_CTXT_MEM_FREE;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp), &parms);
+
+ return rc;
+}
+
+int
+tf_msg_em_mem_rgtr(struct tf *tfp,
+ int page_lvl,
+ int page_size,
+ uint64_t dma_addr,
+ uint16_t *ctx_id)
+{
+ int rc;
+ struct hwrm_tf_ctxt_mem_rgtr_input req = { 0 };
+ struct hwrm_tf_ctxt_mem_rgtr_output resp = { 0 };
+ struct tfp_send_msg_parms parms = { 0 };
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+ uint32_t fw_se_id;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+ fw_se_id = tfs->session_id.internal.fw_session_id;
+
+ req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);
+ req.page_level = page_lvl;
+ req.page_size = page_size;
+ req.page_dir = tfp_cpu_to_le_64(dma_addr);
+
+ parms.tf_type = HWRM_TF_CTXT_MEM_RGTR;
+ parms.req_data = (uint32_t *)&req;
+ parms.req_size = sizeof(req);
+ parms.resp_data = (uint32_t *)&resp;
+ parms.resp_size = sizeof(resp);
+ parms.mailbox = dev->ops->tf_dev_get_mailbox();
+
+ rc = tfp_send_msg_direct(tf_session_get_bp(tfp),
+ &parms);
+ if (rc)
+ return rc;
+
+ *ctx_id = tfp_le_to_cpu_16(resp.ctx_id);
+
+ return rc;
+}
+
+int
+tf_msg_em_mem_unrgtr(struct tf *tfp,
+ uint16_t *ctx_id)
+{
+ int rc;
+ struct hwrm_tf_ctxt_mem_unrgtr_input req = {0};
+ struct hwrm_tf_ctxt_mem_unrgtr_output resp = {0};
+ struct tfp_send_msg_parms parms = { 0 };
+ struct tf_dev_info *dev;
+ struct tf_session *tfs;
+ uint32_t fw_se_id;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ fw_se_id = tfs->session_id.internal.fw_session_id;
+ req.fw_session_id = tfp_cpu_to_le_32(fw_se_id);