habanalabs: fix asic-specific functions documentation
PATCH 1/3 habanalabs: fix asic-specific functions documentation
From: Ohad Sharabi <[email protected]>
- Add missing documentation of set DRAM props
- fix typo
--- drivers/misc/habanalabs/common/habanalabs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/common/habanalabs.h +2 -1
@@ -1544,8 +1544,9 @@ struct engines_data {* @check_if_razwi_happened: check if there was a razwi due to RR violation. * @access_dev_mem: access device memory * @set_dram_bar_base: set the base of the DRAM BAR -* @set_engine_cores: set a config command to enigne cores +* @set_engine_cores: set a config command to engine cores * @send_device_activity: indication to FW about device availability +* @set_dram_properties: set DRAM related properties. */ struct hl_asic_funcs {int (*early_init)(struct hl_device *hdev);
Signature · 1 line
2.25.1
PATCH 2/3 habanalabs: support receiving ascii message from preboot f/w
From: Tal Cohen <[email protected]>
An Ascii message that is sent from preboot towards the driver will indicate the specific error that occurred on the f/w. This commit supports that message and parse the ascii string in order to print it into the kernel log
The commit also changes the way the descriptor struct is declared. While its size increased (it now above 1024 bytes), it will be allocated by using kmalloc instead of stack declaration.
--- drivers/misc/habanalabs/common/firmware_if.c | 74 +++++++++++++++---- .../habanalabs/include/common/hl_boot_if.h | 19 +++++ 2 files changed, 78 insertions(+), 15 deletions(-)
drivers/misc/habanalabs/common/firmware_if.c +59 -15
@@ -1915,7 +1915,7 @@ static int hl_fw_dynamic_validate_memory_bound(struct hl_device *hdev,* * @hdev: pointer to the habanalabs device structure * @fw_loader: managing structure for loading device's FW -* @fw_desc: the descriptor form FW +* @fw_desc: the descriptor from FW * * @return 0 on success, otherwise non-zero error code */
@@ -2007,6 +2007,43 @@ static int hl_fw_dynamic_validate_response(struct hl_device *hdev,return rc; } +/* +* hl_fw_dynamic_read_descriptor_msg - read and show the ascii msg that sent by fw +* +* @hdev: pointer to the habanalabs device structure +* @fw_desc: the descriptor from FW +*/ +static void hl_fw_dynamic_read_descriptor_msg (struct hl_device *hdev, +struct lkd_fw_comms_desc *fw_desc) +{ +int i; +char *msg; + +for (i =0 ; i <LKD_FW_ASCII_MSG_MAX ; i++) { +if (!fw_desc->ascii_msg[i].valid) +return ; + +/* force NULL termination */ + msg = fw_desc->ascii_msg[i].msg; + msg[LKD_FW_ASCII_MSG_MAX_LEN -1 ] ='\0' ; + +switch (fw_desc->ascii_msg[i].msg_lvl) { +case LKD_FW_ASCII_MSG_ERR : +dev_err (hdev->dev,"fw: %s" , fw_desc->ascii_msg[i].msg); +break ; +case LKD_FW_ASCII_MSG_WRN : +dev_warn (hdev->dev,"fw: %s" , fw_desc->ascii_msg[i].msg); +break ; +case LKD_FW_ASCII_MSG_INF : +dev_info (hdev->dev,"fw: %s" , fw_desc->ascii_msg[i].msg); +break ; +default : +dev_dbg (hdev->dev,"fw: %s" , fw_desc->ascii_msg[i].msg); +break ; + } + } +} +/** * hl_fw_dynamic_read_and_validate_descriptor - read and validate FW descriptor *
@@ -2071,6 +2108,10 @@ static int hl_fw_dynamic_read_and_validate_descriptor(struct hl_device *hdev, rc =hl_fw_dynamic_validate_descriptor (hdev, fw_loader, (struct lkd_fw_comms_desc *) temp_fw_desc); + +if (!rc) +hl_fw_dynamic_read_descriptor_msg (hdev, temp_fw_desc); +vfree (temp_fw_desc);return rc;
@@ -2491,51 +2532,54 @@ static void hl_fw_linux_update_state(struct hl_device *hdev,static int hl_fw_dynamic_send_msg (struct hl_device *hdev,struct fw_load_mgr *fw_loader,u8 msg_type,void *data) { -struct lkd_msg_comms msg; +struct lkd_msg_comms *msg;int rc; -memset (&msg,0 ,sizeof (msg)); + msg =kzalloc (sizeof (*msg),GFP_KERNEL ); +if (!msg) +return -ENOMEM ;/* create message to be sent */ - msg.header.type = msg_type; - msg.header.size =cpu_to_le16 (sizeof (struct comms_msg_header )); - msg.header.magic =cpu_to_le32 (HL_COMMS_MSG_MAGIC ); + msg->header.type = msg_type; + msg->header.size =cpu_to_le16 (sizeof (struct comms_msg_header )); + msg->header.magic =cpu_to_le32 (HL_COMMS_MSG_MAGIC );switch (msg_type) {case HL_COMMS_RESET_CAUSE_TYPE : - msg.reset_cause = *(__u8 *) data; + msg->reset_cause = *(__u8 *) data;break ;default :dev_err (hdev->dev,"Send COMMS message - invalid message type %u\n" , msg_type); -return -EINVAL ; + rc = -EINVAL ; + goto out; } rc =hl_fw_dynamic_request_descriptor (hdev, fw_loader,sizeof (struct lkd_msg_comms ));if (rc) -return rc; + goto out;/* copy message to space allocated by FW */ - rc =hl_fw_dynamic_copy_msg (hdev, &msg, fw_loader); + rc =hl_fw_dynamic_copy_msg (hdev, msg, fw_loader);if (rc) -return rc; + goto out; rc =hl_fw_dynamic_send_protocol_cmd (hdev, fw_loader,COMMS_DATA_RDY ,0 , true, fw_loader->cpu_timeout);if (rc) -return rc; + goto out; rc =hl_fw_dynamic_send_protocol_cmd (hdev, fw_loader,COMMS_EXEC ,0 , true, fw_loader->cpu_timeout); -if (rc) -return rc; -return 0 ; +out: +kfree (msg); +return rc; }/**
drivers/misc/habanalabs/include/common/hl_boot_if.h +19 -0
@@ -523,6 +523,23 @@ struct comms_msg_header {__u8 reserved[4 ];/* pad to 64 bit */ }; +enum lkd_fw_ascii_msg_lvls { +LKD_FW_ASCII_MSG_ERR =0 , +LKD_FW_ASCII_MSG_WRN =1 , +LKD_FW_ASCII_MSG_INF =2 , +LKD_FW_ASCII_MSG_DBG =3 , +}; + +#define LKD_FW_ASCII_MSG_MAX_LEN 128 +#define LKD_FW_ASCII_MSG_MAX 4/* consider ABI when changing */ + +struct lkd_fw_ascii_msg { +__u8 valid; +__u8 msg_lvl; +__u8 reserved[6 ]; +char msg[LKD_FW_ASCII_MSG_MAX_LEN ]; +}; +/* this is the main FW descriptor - consider ABI when changing */ struct lkd_fw_comms_desc {struct comms_desc_header header;
@@ -533,6 +550,7 @@ struct lkd_fw_comms_desc {char reserved0[VERSION_MAX_LEN ];__le64 img_addr;/* address for next FW component load */ struct lkd_fw_binning_info binning_info; +struct lkd_fw_ascii_msg ascii_msg[LKD_FW_ASCII_MSG_MAX ]; };enum comms_reset_cause {
@@ -558,6 +576,7 @@ struct lkd_fw_comms_msg {/* address for next FW component load */ __le64 img_addr;struct lkd_fw_binning_info binning_info; +struct lkd_fw_ascii_msg ascii_msg[LKD_FW_ASCII_MSG_MAX ]; };struct {__u8 reset_cause;
Signature · 1 line
2.25.1
PATCH 3/3 habanalabs: pass-through request from user to f/w
In reply to Oded GabbayFrom: farah kassabri <[email protected]>
Add a uAPI, as part of the INFO IOCTL, to allow users to send requests directly to f/w, according to a pre-defined set of opcodes that the f/w exposes.
The f/w will put the result in a kernel-allocated buffer, which the driver will then copy to the user-supplied buffer.
This will allow f/w tools to communicate directly with the f/w without the need to add a new uAPI to the driver for each new type of request.
--- drivers/misc/habanalabs/common/firmware_if.c | 24 +++++++ drivers/misc/habanalabs/common/habanalabs.h | 2 + .../misc/habanalabs/common/habanalabs_ioctl.c | 51 +++++++++++++++ .../misc/habanalabs/include/common/cpucp_if.h | 65 +++++++++++++++++-- include/uapi/misc/habanalabs.h | 4 ++ 5 files changed, 139 insertions(+), 7 deletions(-)
drivers/misc/habanalabs/common/firmware_if.c +24 -0
@@ -3145,3 +3145,27 @@ int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_insizeof (struct cpucp_sec_attest_info ), nonce, HL_CPUCP_SEC_ATTEST_INFO_TINEOUT_USEC); } + +int hl_fw_send_generic_request (struct hl_device *hdev,enum hl_passthrough_type sub_opcode, +dma_addr_t buff,u32 *size) +{ +struct cpucp_packet pkt = {0 }; +u64 result; +int rc =0 ; + + pkt.ctl =cpu_to_le32 (CPUCP_PACKET_GENERIC_PASSTHROUGH <<CPUCP_PKT_CTL_OPCODE_SHIFT ); + pkt.addr =cpu_to_le64 (buff); + pkt.data_max_size =cpu_to_le32 (*size); + pkt.pkt_subidx =cpu_to_le32 (sub_opcode); + + rc = hdev->asic_funcs->send_cpu_message (hdev, (u32 *)&pkt,sizeof (pkt), +HL_CPUCP_INFO_TIMEOUT_USEC , &result); +if (rc) +dev_err (hdev->dev,"failed to send CPUCP data of generic fw pkt\n" ); +else +dev_dbg (hdev->dev,"generic pkt was successful, result: 0x%llx\n" , result); + + *size = (u32 )result; + +return rc; +}
drivers/misc/habanalabs/common/habanalabs.h +2 -0
@@ -3790,6 +3790,8 @@ int hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);void hl_fw_set_pll_profile (struct hl_device *hdev);void hl_sysfs_add_dev_clk_attr (struct hl_device *hdev,struct attribute_group *dev_clk_attr_grp);void hl_sysfs_add_dev_vrm_attr (struct hl_device *hdev,struct attribute_group *dev_vrm_attr_grp); +int hl_fw_send_generic_request (struct hl_device *hdev,enum hl_passthrough_type sub_opcode, +dma_addr_t buff,u32 *size);void hw_sob_get (struct hl_hw_sob *hw_sob);void hw_sob_put (struct hl_hw_sob *hw_sob);
drivers/misc/habanalabs/common/habanalabs_ioctl.c +51 -0
63 lines not on this page · raw message
drivers/misc/habanalabs/include/common/cpucp_if.h +58 -7
119 lines not on this page · raw message
include/uapi/misc/habanalabs.h +4 -0
@@ -789,6 +789,7 @@ enum hl_server_type {* HL_INFO_ENGINE_STATUS - Retrieve the status of all the h/w engines in the asic. * HL_INFO_PAGE_FAULT_EVENT - Retrieve parameters of captured page fault. * HL_INFO_USER_MAPPINGS - Retrieve user mappings, captured after page fault event. +* HL_INFO_FW_GENERIC_REQ - Send generic request to FW. */ #define HL_INFO_HW_IP_INFO 0#define HL_INFO_HW_EVENTS 1
@@ -822,6 +823,7 @@ enum hl_server_type {#define HL_INFO_ENGINE_STATUS 32#define HL_INFO_PAGE_FAULT_EVENT 33#define HL_INFO_USER_MAPPINGS 34 +#define HL_INFO_FW_GENERIC_REQ 35#define HL_INFO_VERSION_MAX_LEN 128#define HL_INFO_CARD_NAME_MAX_LEN 16
@@ -1258,6 +1260,7 @@ enum gaudi_dcores {* @sec_attest_nonce: Nonce number used for attestation report. * @array_size: Number of array members copied to user buffer. * Relevant for HL_INFO_USER_MAPPINGS info ioctl. +* @fw_sub_opcode: generic requests sub opcodes. * @pad: Padding to 64 bit. */ struct hl_info_args {
@@ -1274,6 +1277,7 @@ struct hl_info_args {__u32 user_buffer_actual_size;__u32 sec_attest_nonce;__u32 array_size; +__u32 fw_sub_opcode; };__u32 pad;
Signature · 1 line
2.25.1