dsp: firmware_update: Change return type of downstream device ABI/APIs

So far all of the downstream device related ABI/APIs were marked as
`TESTING`, before stabilize them, any deprecated code should be
removed, including PLDM Completion Code, therefore, change all of the
return type of these to `ERRNO`.

Change-Id: Ie6b390fcc1c91a425f9181ec4ce4495729baab51
Signed-off-by: Unive Tien <unive.tien.wiwynn@gmail.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f94fc4c..548cc8d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,11 @@
 4. Return `ENOENT` rather than `ENOKEY` from
    `pldm_pdr_find_child_container_id_index_range_exclude()`
 
+5. dsp: firmware_update: Change return type of downstream device ABIs to ERRNO
+
+   Those downstream device related ABIs have not been stabilized yet, change
+   return type from PLDM Completion Code to ERRNO
+
 ### Fixed
 
 1. dsp: platform: Fix location of closing paren in overflow detection
diff --git a/include/libpldm/firmware_update.h b/include/libpldm/firmware_update.h
index 3fdd222..3232006 100644
--- a/include/libpldm/firmware_update.h
+++ b/include/libpldm/firmware_update.h
@@ -1130,7 +1130,9 @@
  *  @param[in] instance_id - Message's instance id
  *  @param[out] msg - Message will be written to this
  *
- *  @return pldm_completion_codes
+ *  @return 0 on success, otherwise -EINVAL if the input parameters' memory
+ *          are not allocated, -EOVERFLOW if the payload length is not enough
+ *          to encode the message, -EBADMSG if the message is not valid.
  *
  *  @note  Caller is responsible for memory alloc and dealloc of param
  *         'msg.payload'
@@ -1144,7 +1146,9 @@
  * @param[in] msg The PLDM message to decode.
  * @param[in] payload_length The length of the message payload.
  * @param[out] resp_data Pointer to the structure to store the decoded response data.
- * @return pldm_completion_codes
+ * @return 0 on success, otherwise -EINVAL if the input parameters' memory
+ *         are not allocated, -EOVERFLOW if the payload length is not enough
+ *         to decode the message, -EBADMSG if the message is not valid.
  *
  * @note  Caller is responsible for memory alloc and dealloc of param
  *         'msg.payload'
@@ -1161,7 +1165,9 @@
  * @param[in] transfer_operation_flag The flag indicating the transfer operation.
  * @param[out] msg Pointer to the PLDM message structure to store the encoded message.
  * @param[in] payload_length The length of the payload.
- * @return pldm_completion_codes
+ * @return 0 on success, otherwise -EINVAL if the input parameters' memory
+ *         are not allocated, -EOVERFLOW if the payload length is not enough
+ *         to encode the message, -EBADMSG if the message is not valid.
  *
  * @note Caller is responsible for memory alloc and dealloc of param
  *        'msg.payload'
@@ -1177,7 +1183,9 @@
  * @param[in] payload_length The length of the message payload.
  * @param[out] resp_data Pointer to the decoded response data.
  * @param[out] iter Pointer to the downstream device iterator structure.
- * @return pldm_completion_codes
+ * @return 0 on success, otherwise -EINVAL if the input parameters' memory
+ *         are not allocated, -EOVERFLOW if the payload length is not enough
+ *         to decode the message, -EBADMSG if the message is not valid.
  *
  * @note Caller is responsible for memory alloc and dealloc of pointer params
  */
@@ -1266,6 +1274,9 @@
  * @param[in] active_len - The size of the object pointed to by @p active
  * @param[out] pending - pointer to pending component version string container
  * @param[in] pending_len - The size of the object pointed to by @p pending
+ * @return 0 on success, otherwise -EINVAL if the input parameters' memory
+ *         are not allocated, -EOVERFLOW if the payload length is not enough
+ *         to decode the message, -EBADMSG if the message is not valid.
  *
  * @note Caller is responsible for memory alloc and dealloc of all the params,
  *    and the param `entry` should be the instance which has successfully decoded
diff --git a/src/dsp/firmware_update.c b/src/dsp/firmware_update.c
index d570d5c..d2b068a 100644
--- a/src/dsp/firmware_update.c
+++ b/src/dsp/firmware_update.c
@@ -919,11 +919,13 @@
 					struct pldm_msg *msg)
 {
 	if (msg == NULL) {
-		return PLDM_ERROR_INVALID_DATA;
+		return -EINVAL;
 	}
 
-	return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP,
-				       PLDM_QUERY_DOWNSTREAM_DEVICES, msg);
+	return encode_pldm_header_only_errno(PLDM_REQUEST, instance_id,
+					     PLDM_FWUP,
+					     PLDM_QUERY_DOWNSTREAM_DEVICES,
+					     msg);
 }
 
 LIBPLDM_ABI_TESTING
@@ -936,7 +938,7 @@
 	int rc;
 
 	if (msg == NULL || resp_data == NULL || !payload_length) {
-		return PLDM_ERROR_INVALID_DATA;
+		return -EINVAL;
 	}
 
 	rc = pldm_msgbuf_init_errno(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN,
@@ -947,38 +949,33 @@
 
 	rc = pldm_msgbuf_extract(buf, resp_data->completion_code);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 	if (PLDM_SUCCESS != resp_data->completion_code) {
 		// Return the CC directly without decoding the rest of the payload
-		return PLDM_SUCCESS;
+		return 0;
 	}
 
 	if (payload_length < PLDM_QUERY_DOWNSTREAM_DEVICES_RESP_BYTES) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return -EBADMSG;
 	}
 
 	rc = pldm_msgbuf_extract(buf,
 				 resp_data->downstream_device_update_supported);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 
 	if (!is_downstream_device_update_support_valid(
 		    resp_data->downstream_device_update_supported)) {
-		return PLDM_ERROR_INVALID_DATA;
+		return -EINVAL;
 	}
 
 	pldm_msgbuf_extract(buf, resp_data->number_of_downstream_devices);
 	pldm_msgbuf_extract(buf, resp_data->max_number_of_downstream_devices);
 	pldm_msgbuf_extract(buf, resp_data->capabilities.value);
 
-	rc = pldm_msgbuf_destroy_consumed(buf);
-	if (rc) {
-		pldm_xlate_errno(rc);
-	}
-
-	return PLDM_SUCCESS;
+	return pldm_msgbuf_destroy_consumed(buf);
 }
 
 LIBPLDM_ABI_TESTING
@@ -992,11 +989,11 @@
 	int rc;
 
 	if (msg == NULL) {
-		return PLDM_ERROR_INVALID_DATA;
+		return -EINVAL;
 	}
 
 	if (!is_transfer_operation_flag_valid(transfer_operation_flag)) {
-		return PLDM_INVALID_TRANSFER_OPERATION_FLAG;
+		return -EINVAL;
 	}
 
 	struct pldm_header_info header = { 0 };
@@ -1004,7 +1001,7 @@
 	header.msg_type = PLDM_REQUEST;
 	header.pldm_type = PLDM_FWUP;
 	header.command = PLDM_QUERY_DOWNSTREAM_IDENTIFIERS;
-	rc = pack_pldm_header(&header, &(msg->hdr));
+	rc = pack_pldm_header_errno(&header, &(msg->hdr));
 	if (rc) {
 		return rc;
 	}
@@ -1013,19 +1010,14 @@
 				    PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_REQ_BYTES,
 				    msg->payload, payload_length);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 
 	pldm_msgbuf_insert(buf, data_transfer_handle);
 	// Data correctness has been verified, cast it to 1-byte data directly.
 	pldm_msgbuf_insert(buf, (uint8_t)transfer_operation_flag);
 
-	rc = pldm_msgbuf_destroy(buf);
-	if (rc) {
-		return pldm_xlate_errno(rc);
-	}
-
-	return PLDM_SUCCESS;
+	return pldm_msgbuf_destroy(buf);
 }
 
 LIBPLDM_ABI_TESTING
@@ -1037,29 +1029,29 @@
 	struct pldm_msgbuf _buf;
 	struct pldm_msgbuf *buf = &_buf;
 	void *remaining = NULL;
-	int rc = PLDM_ERROR;
+	int rc = 0;
 
 	if (msg == NULL || resp_data == NULL || iter == NULL ||
 	    !payload_length) {
-		return PLDM_ERROR_INVALID_DATA;
+		return -EINVAL;
 	}
 
 	rc = pldm_msgbuf_init_errno(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN,
 				    msg->payload, payload_length);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 
 	rc = pldm_msgbuf_extract(buf, resp_data->completion_code);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 	if (PLDM_SUCCESS != resp_data->completion_code) {
-		return PLDM_SUCCESS;
+		return 0;
 	}
 
 	if (payload_length < PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN) {
-		return PLDM_ERROR_INVALID_LENGTH;
+		return -EBADMSG;
 	}
 
 	pldm_msgbuf_extract(buf, resp_data->next_data_transfer_handle);
@@ -1067,26 +1059,26 @@
 
 	rc = pldm_msgbuf_extract(buf, resp_data->downstream_devices_length);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 
 	pldm_msgbuf_extract(buf, resp_data->number_of_downstream_devices);
 	rc = pldm_msgbuf_span_required(
 		buf, resp_data->downstream_devices_length, &remaining);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 
 	rc = pldm_msgbuf_destroy(buf);
 	if (rc) {
-		return pldm_xlate_errno(rc);
+		return rc;
 	}
 
 	iter->field.ptr = remaining;
 	iter->field.length = resp_data->downstream_devices_length;
 	iter->devs = resp_data->number_of_downstream_devices;
 
-	return PLDM_SUCCESS;
+	return 0;
 }
 
 LIBPLDM_ABI_TESTING
diff --git a/tests/dsp/firmware_update.cpp b/tests/dsp/firmware_update.cpp
index 878ba75..6fc1aa9 100644
--- a/tests/dsp/firmware_update.cpp
+++ b/tests/dsp/firmware_update.cpp
@@ -1316,7 +1316,7 @@
 
     auto rc = encode_query_downstream_devices_req(instanceId, requestPtr);
 
-    EXPECT_EQ(rc, PLDM_SUCCESS);
+    EXPECT_EQ(rc, 0);
     EXPECT_EQ(requestPtr->hdr.request, PLDM_REQUEST);
     EXPECT_EQ(requestPtr->hdr.instance_id, instanceId);
     EXPECT_EQ(requestPtr->hdr.type, PLDM_FWUP);
@@ -1331,7 +1331,7 @@
 
     auto rc = encode_query_downstream_devices_req(instanceId, nullptr);
 
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+    EXPECT_EQ(rc, -EINVAL);
 }
 #endif
 
@@ -1372,7 +1372,7 @@
     rc = decode_query_downstream_devices_resp(
         response, responseMsg.size() - hdrSize, &resp_data);
 
-    EXPECT_EQ(rc, PLDM_SUCCESS);
+    EXPECT_EQ(rc, 0);
     EXPECT_EQ(resp_data.completion_code, completion_code_resp);
     EXPECT_EQ(resp_data.downstream_device_update_supported,
               downstream_device_update_supported_resp);
@@ -1420,7 +1420,7 @@
     rc = decode_query_downstream_devices_resp(
         response, responseMsg.size() - hdrSize, &resp_data);
 
-    ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+    ASSERT_EQ(rc, -EINVAL);
 }
 #endif
 
@@ -1463,7 +1463,7 @@
     rc = decode_query_downstream_devices_resp(
         response, responseMsg.size() - hdrSize, &resp_data);
 
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_EQ(rc, -EBADMSG);
 }
 #endif
 
@@ -1479,7 +1479,7 @@
     auto rc = encode_query_downstream_identifiers_req(
         instanceId, dataTransferHandle, transferOperationFlag, request,
         payloadLen);
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
     EXPECT_THAT(std::span<uint8_t>(request_buf, sizeof(request_buf)),
                 ElementsAreArray<uint8_t>(
                     {0x81, 0x05, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}));
@@ -1503,17 +1503,17 @@
     auto rc = encode_query_downstream_identifiers_req(
         instanceId, dataTransferHandle, transferOperationFlag, nullptr,
         payload_length);
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+    EXPECT_EQ(rc, -EINVAL);
 
     rc = encode_query_downstream_identifiers_req(
         instanceId, dataTransferHandle, transferOperationFlag, requestPtr,
         payload_length - 1);
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_EQ(rc, -EOVERFLOW);
 
     rc = encode_query_downstream_identifiers_req(instanceId, dataTransferHandle,
                                                  invalidTransferOperationFlag,
                                                  requestPtr, payload_length);
-    EXPECT_EQ(rc, PLDM_INVALID_TRANSFER_OPERATION_FLAG);
+    EXPECT_EQ(rc, -EINVAL);
 }
 #endif
 
@@ -1549,7 +1549,7 @@
         response, PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN, &resp_data,
         &devs);
 
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
     EXPECT_EQ(resp_data.completion_code, completion_code_resp);
     EXPECT_EQ(resp_data.next_data_transfer_handle,
               next_data_transfer_handle_resp);
@@ -1592,7 +1592,7 @@
 
     rc = decode_query_downstream_identifiers_resp(
         response, PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN, &resp, &devs);
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
 
     foreach_pldm_downstream_device(devs, dev, rc)
     {
@@ -1646,7 +1646,7 @@
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
 
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
     EXPECT_EQ(resp_data.completion_code, completion_code_resp);
     EXPECT_EQ(resp_data.next_data_transfer_handle,
               next_data_transfer_handle_resp);
@@ -1750,7 +1750,7 @@
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
 
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
     EXPECT_EQ(resp_data.number_of_downstream_devices,
               number_of_downstream_devices_resp);
 
@@ -1870,7 +1870,7 @@
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
 
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
     EXPECT_EQ(resp_data.number_of_downstream_devices,
               number_of_downstream_devices_resp);
 
@@ -1990,7 +1990,7 @@
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
 
-    ASSERT_EQ(rc, PLDM_SUCCESS);
+    ASSERT_EQ(rc, 0);
     EXPECT_EQ(resp_data.number_of_downstream_devices,
               number_of_downstream_devices_resp);
 
@@ -2048,13 +2048,13 @@
     // Test nullptr
     auto rc = decode_query_downstream_identifiers_resp(nullptr, payloadLen,
                                                        nullptr, &devs);
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+    EXPECT_EQ(rc, -EINVAL);
 
     // Test not PLDM_SUCCESS completion code
     response->payload[0] = PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
-    EXPECT_EQ(rc, PLDM_SUCCESS);
+    EXPECT_EQ(rc, 0);
     EXPECT_EQ(resp_data.completion_code, PLDM_ERROR_UNSUPPORTED_PLDM_CMD);
 
     // Test payload length less than minimum length
@@ -2062,7 +2062,7 @@
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
 
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_EQ(rc, -EBADMSG);
 }
 #endif
 
@@ -2110,7 +2110,7 @@
 
     EXPECT_NE(decode_query_downstream_identifiers_resp(response, payloadLen,
                                                        &resp_data, &devs),
-              PLDM_SUCCESS);
+              0);
 }
 #endif
 
@@ -2148,7 +2148,7 @@
     rc = decode_query_downstream_identifiers_resp(response, payloadLen,
                                                   &resp_data, &devs);
 
-    EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+    EXPECT_EQ(rc, -EBADMSG);
 }
 #endif