habanalabs: firmware returns 64bit argument
authorAlon Mizrahi <amizrahi@habana.ai>
Tue, 10 Nov 2020 11:49:10 +0000 (13:49 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Mon, 30 Nov 2020 08:47:35 +0000 (10:47 +0200)
F/W message returns 64bit value but up until now we casted it to
a 32bit variable, instead of receiving 64bit in the first place.

Signed-off-by: Alon Mizrahi <amizrahi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/debugfs.c
drivers/misc/habanalabs/common/firmware_if.c
drivers/misc/habanalabs/common/habanalabs.h
drivers/misc/habanalabs/common/hwmon.c
drivers/misc/habanalabs/common/sysfs.c
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/goya/goya.c
drivers/misc/habanalabs/goya/goyaP.h

index 1db804de45ba5cc664553dd284f8fc2b0cd737fc..b47a62da0b41e7441d9ab03fb60d8e76fdd3900d 100644 (file)
@@ -22,6 +22,7 @@ static int hl_debugfs_i2c_read(struct hl_device *hdev, u8 i2c_bus, u8 i2c_addr,
                                u8 i2c_reg, long *val)
 {
        struct cpucp_packet pkt;
+       u64 result;
        int rc;
 
        if (!hl_device_operational(hdev, NULL))
@@ -36,7 +37,9 @@ static int hl_debugfs_i2c_read(struct hl_device *hdev, u8 i2c_bus, u8 i2c_addr,
        pkt.i2c_reg = i2c_reg;
 
        rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
-                                               0, val);
+                                               0, &result);
+
+       *val = (long) result;
 
        if (rc)
                dev_err(hdev->dev, "Failed to read from I2C, error %d\n", rc);
index e37d451e6415a1659520950bea06751d9fead3a7..8f70d0bbe5e17e35477f6c957cdc0fadbede1a97 100644 (file)
@@ -88,7 +88,7 @@ int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode)
 }
 
 int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
-                               u16 len, u32 timeout, long *result)
+                               u16 len, u32 timeout, u64 *result)
 {
        struct cpucp_packet *pkt;
        dma_addr_t pkt_dma_addr;
@@ -143,7 +143,7 @@ int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
                                                >> CPUCP_PKT_CTL_OPCODE_SHIFT);
                rc = -EIO;
        } else if (result) {
-               *result = (long) le64_to_cpu(pkt->result);
+               *result = le64_to_cpu(pkt->result);
        }
 
 out:
@@ -157,7 +157,7 @@ out:
 int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type)
 {
        struct cpucp_packet pkt;
-       long result;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -180,7 +180,7 @@ int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
 {
        struct cpucp_unmask_irq_arr_packet *pkt;
        size_t total_pkt_size;
-       long result;
+       u64 result;
        int rc;
 
        total_pkt_size = sizeof(struct cpucp_unmask_irq_arr_packet) +
@@ -219,7 +219,7 @@ int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
 int hl_fw_test_cpu_queue(struct hl_device *hdev)
 {
        struct cpucp_packet test_pkt = {};
-       long result;
+       u64 result;
        int rc;
 
        test_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
@@ -232,7 +232,7 @@ int hl_fw_test_cpu_queue(struct hl_device *hdev)
        if (!rc) {
                if (result != CPUCP_PACKET_FENCE_VAL)
                        dev_err(hdev->dev,
-                               "CPU queue test failed (0x%08lX)\n", result);
+                               "CPU queue test failed (%#08llx)\n", result);
        } else {
                dev_err(hdev->dev, "CPU queue test failed, error %d\n", rc);
        }
@@ -263,7 +263,7 @@ void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
 int hl_fw_send_heartbeat(struct hl_device *hdev)
 {
        struct cpucp_packet hb_pkt = {};
-       long result;
+       u64 result;
        int rc;
 
        hb_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
@@ -285,7 +285,7 @@ int hl_fw_cpucp_info_get(struct hl_device *hdev)
        struct cpucp_packet pkt = {};
        void *cpucp_info_cpu_addr;
        dma_addr_t cpucp_info_dma_addr;
-       long result;
+       u64 result;
        int rc;
 
        cpucp_info_cpu_addr =
@@ -336,7 +336,7 @@ int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size)
        struct cpucp_packet pkt = {};
        void *eeprom_info_cpu_addr;
        dma_addr_t eeprom_info_dma_addr;
-       long result;
+       u64 result;
        int rc;
 
        eeprom_info_cpu_addr =
@@ -379,7 +379,7 @@ int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
                struct hl_info_pci_counters *counters)
 {
        struct cpucp_packet pkt = {};
-       long result;
+       u64 result;
        int rc;
 
        pkt.ctl = cpu_to_le32(CPUCP_PACKET_PCIE_THROUGHPUT_GET <<
@@ -426,7 +426,7 @@ int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
 int hl_fw_cpucp_total_energy_get(struct hl_device *hdev, u64 *total_energy)
 {
        struct cpucp_packet pkt = {};
-       long result;
+       u64 result;
        int rc;
 
        pkt.ctl = cpu_to_le32(CPUCP_PACKET_TOTAL_ENERGY_GET <<
@@ -452,7 +452,7 @@ int hl_fw_cpucp_pll_info_get(struct hl_device *hdev,
                u32 *pll_info)
 {
        struct cpucp_packet pkt;
-       long result;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -467,7 +467,7 @@ int hl_fw_cpucp_pll_info_get(struct hl_device *hdev,
        if (rc)
                dev_err(hdev->dev, "Failed to read PLL info, error %d\n", rc);
 
-       *pll_info = result;
+       *pll_info = (u32) result;
 
        return rc;
 }
index b8ad5bfa635973efddda251b87d3a9ba303538fd..43aa8cbd89694a2ceb1ab683272389f8ad3f01c3 100644 (file)
@@ -925,7 +925,7 @@ struct hl_asic_funcs {
        int (*get_eeprom_data)(struct hl_device *hdev, void *data,
                                size_t max_size);
        int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
-                               u16 len, u32 timeout, long *result);
+                               u16 len, u32 timeout, u64 *result);
        int (*pci_bars_map)(struct hl_device *hdev);
        int (*init_iatu)(struct hl_device *hdev);
        u32 (*rreg)(struct hl_device *hdev, u32 reg);
@@ -2178,7 +2178,7 @@ int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
                                void __iomem *dst, u32 src_offset, u32 size);
 int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode);
 int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
-                               u16 len, u32 timeout, long *result);
+                               u16 len, u32 timeout, u64 *result);
 int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type);
 int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
                size_t irq_arr_size);
index ab96401c3752a152fa88dd745d7a486c549e0aa2..6b421d76b3111dfac9edc4e44d16db5cf6a7c3ab 100644 (file)
@@ -312,6 +312,7 @@ int hl_get_temperature(struct hl_device *hdev,
                        int sensor_index, u32 attr, long *value)
 {
        struct cpucp_packet pkt;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -322,7 +323,9 @@ int hl_get_temperature(struct hl_device *hdev,
        pkt.type = __cpu_to_le16(attr);
 
        rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
-                                               0, value);
+                                               0, &result);
+
+       *value = (long) result;
 
        if (rc) {
                dev_err(hdev->dev,
@@ -363,6 +366,7 @@ int hl_get_voltage(struct hl_device *hdev,
                        int sensor_index, u32 attr, long *value)
 {
        struct cpucp_packet pkt;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -373,7 +377,9 @@ int hl_get_voltage(struct hl_device *hdev,
        pkt.type = __cpu_to_le16(attr);
 
        rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
-                                               0, value);
+                                               0, &result);
+
+       *value = (long) result;
 
        if (rc) {
                dev_err(hdev->dev,
@@ -389,6 +395,7 @@ int hl_get_current(struct hl_device *hdev,
                        int sensor_index, u32 attr, long *value)
 {
        struct cpucp_packet pkt;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -399,7 +406,9 @@ int hl_get_current(struct hl_device *hdev,
        pkt.type = __cpu_to_le16(attr);
 
        rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
-                                               0, value);
+                                               0, &result);
+
+       *value = (long) result;
 
        if (rc) {
                dev_err(hdev->dev,
@@ -415,6 +424,7 @@ int hl_get_fan_speed(struct hl_device *hdev,
                        int sensor_index, u32 attr, long *value)
 {
        struct cpucp_packet pkt;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -425,7 +435,9 @@ int hl_get_fan_speed(struct hl_device *hdev,
        pkt.type = __cpu_to_le16(attr);
 
        rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
-                                               0, value);
+                                               0, &result);
+
+       *value = (long) result;
 
        if (rc) {
                dev_err(hdev->dev,
@@ -441,6 +453,7 @@ int hl_get_pwm_info(struct hl_device *hdev,
                        int sensor_index, u32 attr, long *value)
 {
        struct cpucp_packet pkt;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -451,7 +464,9 @@ int hl_get_pwm_info(struct hl_device *hdev,
        pkt.type = __cpu_to_le16(attr);
 
        rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
-                                               0, value);
+                                               0, &result);
+
+       *value = (long) result;
 
        if (rc) {
                dev_err(hdev->dev,
index 94ca68e620005c54d191e5ae8e2d0c35448a7442..4366d8f9384290437e05fe23d06044f0bda9e50c 100644 (file)
@@ -12,7 +12,7 @@
 long hl_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr)
 {
        struct cpucp_packet pkt;
-       long result;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -32,10 +32,10 @@ long hl_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr)
                dev_err(hdev->dev,
                        "Failed to get frequency of PLL %d, error %d\n",
                        pll_index, rc);
-               result = rc;
+               return rc;
        }
 
-       return result;
+       return (long) result;
 }
 
 void hl_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq)
@@ -62,7 +62,7 @@ void hl_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq)
 u64 hl_get_max_power(struct hl_device *hdev)
 {
        struct cpucp_packet pkt;
-       long result;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
@@ -75,7 +75,7 @@ u64 hl_get_max_power(struct hl_device *hdev)
 
        if (rc) {
                dev_err(hdev->dev, "Failed to get max power, error %d\n", rc);
-               result = rc;
+               return (u64) rc;
        }
 
        return result;
index 4c884082be0477011af809a8b178f23656f6dca7..4fab90e331702f13ebbf6227bed36d067d1e7c21 100644 (file)
@@ -4561,7 +4561,7 @@ static void *gaudi_get_int_queue_base(struct hl_device *hdev,
 }
 
 static int gaudi_send_cpu_message(struct hl_device *hdev, u32 *msg,
-                               u16 len, u32 timeout, long *result)
+                               u16 len, u32 timeout, u64 *result)
 {
        struct gaudi_device *gaudi = hdev->asic_specific;
 
index 3398b4cc1298fd519ba1c33cf7fb4cc8c3fc7f76..55d174d3cac87acf6e3504eabb3eef91da8c973b 100644 (file)
@@ -2954,7 +2954,7 @@ free_fence_ptr:
 }
 
 int goya_send_cpu_message(struct hl_device *hdev, u32 *msg, u16 len,
-                               u32 timeout, long *result)
+                               u32 timeout, u64 *result)
 {
        struct goya_device *goya = hdev->asic_specific;
 
@@ -4540,7 +4540,7 @@ static int goya_unmask_irq_arr(struct hl_device *hdev, u32 *irq_arr,
 {
        struct cpucp_unmask_irq_arr_packet *pkt;
        size_t total_pkt_size;
-       long result;
+       u64 result;
        int rc;
        int irq_num_entries, irq_arr_index;
        __le32 *goya_irq_arr;
@@ -4599,7 +4599,7 @@ static int goya_soft_reset_late_init(struct hl_device *hdev)
 static int goya_unmask_irq(struct hl_device *hdev, u16 event_type)
 {
        struct cpucp_packet pkt;
-       long result;
+       u64 result;
        int rc;
 
        memset(&pkt, 0, sizeof(pkt));
index ef4298f84a0a178084bb6c8e91a384ec6946efbe..8b3408211af62c88d7423ab23ba1fa42cd4b658a 100644 (file)
@@ -192,7 +192,7 @@ int goya_test_queue(struct hl_device *hdev, u32 hw_queue_id);
 int goya_test_queues(struct hl_device *hdev);
 int goya_test_cpu_queue(struct hl_device *hdev);
 int goya_send_cpu_message(struct hl_device *hdev, u32 *msg, u16 len,
-                               u32 timeout, long *result);
+                               u32 timeout, u64 *result);
 
 long goya_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr);
 long goya_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr);