Commit 6c07bab3 authored by Ofir Bitton's avatar Ofir Bitton Committed by Oded Gabbay

habanalabs: Use mask instead of shift in sync stream registers

Use proper bitfield masks instead of shifting values when configuring
packets sent to device.
Signed-off-by: default avatarOfir Bitton <obitton@habana.ai>
Reviewed-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent 21e7a346
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/iommu.h> #include <linux/iommu.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/bitfield.h>
/* /*
* Gaudi security scheme: * Gaudi security scheme:
...@@ -6322,16 +6323,17 @@ static void gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id) ...@@ -6322,16 +6323,17 @@ static void gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id)
pkt = (struct packet_msg_short *) (uintptr_t) cb->kernel_address; pkt = (struct packet_msg_short *) (uintptr_t) cb->kernel_address;
memset(pkt, 0, sizeof(*pkt)); memset(pkt, 0, sizeof(*pkt));
value = 1 << GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_SHIFT; /* inc by 1 */ /* Inc by 1, Mode ADD */
value |= 1 << GAUDI_PKT_SHORT_VAL_SOB_MOD_SHIFT; /* add mode */ value = FIELD_PREP(GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK, 1);
value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK, 1);
ctl = (sob_id * 4) << GAUDI_PKT_SHORT_CTL_ADDR_SHIFT; /* SOB id */ ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, sob_id * 4);
ctl |= 0 << GAUDI_PKT_SHORT_CTL_OP_SHIFT; /* write the value */ ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OP_MASK, 0); /* write the value */
ctl |= 3 << GAUDI_PKT_SHORT_CTL_BASE_SHIFT; /* W_S SOB base */ ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 3); /* W_S SOB base */
ctl |= PACKET_MSG_SHORT << GAUDI_PKT_SHORT_CTL_OPCODE_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
ctl |= 1 << GAUDI_PKT_SHORT_CTL_EB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 1);
ctl |= 1 << GAUDI_PKT_SHORT_CTL_RB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
ctl |= 1 << GAUDI_PKT_SHORT_CTL_MB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 1);
pkt->value = cpu_to_le32(value); pkt->value = cpu_to_le32(value);
pkt->ctl = cpu_to_le32(ctl); pkt->ctl = cpu_to_le32(ctl);
...@@ -6344,12 +6346,12 @@ static u32 gaudi_add_mon_msg_short(struct packet_msg_short *pkt, u32 value, ...@@ -6344,12 +6346,12 @@ static u32 gaudi_add_mon_msg_short(struct packet_msg_short *pkt, u32 value,
memset(pkt, 0, pkt_size); memset(pkt, 0, pkt_size);
ctl = addr << GAUDI_PKT_SHORT_CTL_ADDR_SHIFT; ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, addr);
ctl |= 2 << GAUDI_PKT_SHORT_CTL_BASE_SHIFT; /* W_S MON base */ ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 2); /* W_S MON base */
ctl |= PACKET_MSG_SHORT << GAUDI_PKT_SHORT_CTL_OPCODE_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
ctl |= 0 << GAUDI_PKT_SHORT_CTL_EB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 0);
ctl |= 1 << GAUDI_PKT_SHORT_CTL_RB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
ctl |= 0 << GAUDI_PKT_SHORT_CTL_MB_SHIFT; /* only last pkt needs MB */ ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 0); /* last pkt MB */
pkt->value = cpu_to_le32(value); pkt->value = cpu_to_le32(value);
pkt->ctl = cpu_to_le32(ctl); pkt->ctl = cpu_to_le32(ctl);
...@@ -6365,18 +6367,19 @@ static u32 gaudi_add_arm_monitor_pkt(struct packet_msg_short *pkt, u16 sob_id, ...@@ -6365,18 +6367,19 @@ static u32 gaudi_add_arm_monitor_pkt(struct packet_msg_short *pkt, u16 sob_id,
memset(pkt, 0, pkt_size); memset(pkt, 0, pkt_size);
value = (sob_id / 8) << GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_SHIFT; value = FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_MASK, sob_id / 8);
value |= sob_val << GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_SHIFT; value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_MASK, sob_val);
value |= 0 << GAUDI_PKT_SHORT_VAL_MON_MODE_SHIFT; /* GREATER_OR_EQUAL */ value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_MODE_MASK,
value |= mask << GAUDI_PKT_SHORT_VAL_MON_MASK_SHIFT; 0); /* GREATER OR EQUAL*/
value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_MASK_MASK, mask);
ctl = addr << GAUDI_PKT_SHORT_CTL_ADDR_SHIFT; ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, addr);
ctl |= 0 << GAUDI_PKT_SHORT_CTL_OP_SHIFT; /* write the value */ ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OP_MASK, 0); /* write the value */
ctl |= 2 << GAUDI_PKT_SHORT_CTL_BASE_SHIFT; /* W_S MON base */ ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 2); /* W_S MON base */
ctl |= PACKET_MSG_SHORT << GAUDI_PKT_SHORT_CTL_OPCODE_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
ctl |= 0 << GAUDI_PKT_SHORT_CTL_EB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 0);
ctl |= 1 << GAUDI_PKT_SHORT_CTL_RB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
ctl |= 1 << GAUDI_PKT_SHORT_CTL_MB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 1);
pkt->value = cpu_to_le32(value); pkt->value = cpu_to_le32(value);
pkt->ctl = cpu_to_le32(ctl); pkt->ctl = cpu_to_le32(ctl);
...@@ -6390,15 +6393,14 @@ static u32 gaudi_add_fence_pkt(struct packet_fence *pkt) ...@@ -6390,15 +6393,14 @@ static u32 gaudi_add_fence_pkt(struct packet_fence *pkt)
memset(pkt, 0, pkt_size); memset(pkt, 0, pkt_size);
cfg = 1 << GAUDI_PKT_FENCE_CFG_DEC_VAL_SHIFT; cfg = FIELD_PREP(GAUDI_PKT_FENCE_CFG_DEC_VAL_MASK, 1);
cfg |= 1 << GAUDI_PKT_FENCE_CFG_TARGET_VAL_SHIFT; cfg |= FIELD_PREP(GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK, 1);
cfg |= 2 << GAUDI_PKT_FENCE_CFG_ID_SHIFT; cfg |= FIELD_PREP(GAUDI_PKT_FENCE_CFG_ID_MASK, 2);
ctl = 0 << GAUDI_PKT_FENCE_CTL_PRED_SHIFT; ctl = FIELD_PREP(GAUDI_PKT_FENCE_CTL_OPCODE_MASK, PACKET_FENCE);
ctl |= PACKET_FENCE << GAUDI_PKT_FENCE_CTL_OPCODE_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 0);
ctl |= 0 << GAUDI_PKT_FENCE_CTL_EB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
ctl |= 1 << GAUDI_PKT_FENCE_CTL_RB_SHIFT; ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 1);
ctl |= 1 << GAUDI_PKT_FENCE_CTL_MB_SHIFT;
pkt->cfg = cpu_to_le32(cfg); pkt->cfg = cpu_to_le32(cfg);
pkt->ctl = cpu_to_le32(ctl); pkt->ctl = cpu_to_le32(ctl);
......
...@@ -85,7 +85,7 @@ struct packet_msg_long { ...@@ -85,7 +85,7 @@ struct packet_msg_long {
}; };
#define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_SHIFT 0 #define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_SHIFT 0
#define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK 0x0000EFFF #define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK 0x00007FFF
#define GAUDI_PKT_SHORT_VAL_SOB_MOD_SHIFT 31 #define GAUDI_PKT_SHORT_VAL_SOB_MOD_SHIFT 31
#define GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK 0x80000000 #define GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK 0x80000000
...@@ -141,7 +141,7 @@ struct packet_msg_prot { ...@@ -141,7 +141,7 @@ struct packet_msg_prot {
#define GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK 0x00FF0000 #define GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK 0x00FF0000
#define GAUDI_PKT_FENCE_CFG_ID_SHIFT 30 #define GAUDI_PKT_FENCE_CFG_ID_SHIFT 30
#define GAUDI_PKT_FENCE_CFG_ID_MASK 0xC000000 #define GAUDI_PKT_FENCE_CFG_ID_MASK 0xC0000000
#define GAUDI_PKT_FENCE_CTL_PRED_SHIFT 0 #define GAUDI_PKT_FENCE_CTL_PRED_SHIFT 0
#define GAUDI_PKT_FENCE_CTL_PRED_MASK 0x0000001F #define GAUDI_PKT_FENCE_CTL_PRED_MASK 0x0000001F
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment