Commit 213ad5ad authored by Ben Segal's avatar Ben Segal Committed by Oded Gabbay

habanalabs: fix endianness handling for packets from user

Packets that arrive from the user and need to be parsed by the driver are
assumed to be in LE format.

This patch fix all the places where the code handles these packets and use
the correct endianness macros to handle them, as the driver handles the
packets in CPU format (LE or BE depending on the arch).
Signed-off-by: default avatarBen Segal <bpsegal20@gmail.com>
Reviewed-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent c8113756
...@@ -3428,12 +3428,13 @@ static int goya_validate_cb(struct hl_device *hdev, ...@@ -3428,12 +3428,13 @@ static int goya_validate_cb(struct hl_device *hdev,
while (cb_parsed_length < parser->user_cb_size) { while (cb_parsed_length < parser->user_cb_size) {
enum packet_id pkt_id; enum packet_id pkt_id;
u16 pkt_size; u16 pkt_size;
void *user_pkt; struct goya_packet *user_pkt;
user_pkt = (void *) (uintptr_t) user_pkt = (struct goya_packet *) (uintptr_t)
(parser->user_cb->kernel_address + cb_parsed_length); (parser->user_cb->kernel_address + cb_parsed_length);
pkt_id = (enum packet_id) (((*(u64 *) user_pkt) & pkt_id = (enum packet_id) (
(le64_to_cpu(user_pkt->header) &
PACKET_HEADER_PACKET_ID_MASK) >> PACKET_HEADER_PACKET_ID_MASK) >>
PACKET_HEADER_PACKET_ID_SHIFT); PACKET_HEADER_PACKET_ID_SHIFT);
...@@ -3453,7 +3454,8 @@ static int goya_validate_cb(struct hl_device *hdev, ...@@ -3453,7 +3454,8 @@ static int goya_validate_cb(struct hl_device *hdev,
* need to validate here as well because patch_cb() is * need to validate here as well because patch_cb() is
* not called in MMU path while this function is called * not called in MMU path while this function is called
*/ */
rc = goya_validate_wreg32(hdev, parser, user_pkt); rc = goya_validate_wreg32(hdev,
parser, (struct packet_wreg32 *) user_pkt);
break; break;
case PACKET_WREG_BULK: case PACKET_WREG_BULK:
...@@ -3481,10 +3483,10 @@ static int goya_validate_cb(struct hl_device *hdev, ...@@ -3481,10 +3483,10 @@ static int goya_validate_cb(struct hl_device *hdev,
case PACKET_LIN_DMA: case PACKET_LIN_DMA:
if (is_mmu) if (is_mmu)
rc = goya_validate_dma_pkt_mmu(hdev, parser, rc = goya_validate_dma_pkt_mmu(hdev, parser,
user_pkt); (struct packet_lin_dma *) user_pkt);
else else
rc = goya_validate_dma_pkt_no_mmu(hdev, parser, rc = goya_validate_dma_pkt_no_mmu(hdev, parser,
user_pkt); (struct packet_lin_dma *) user_pkt);
break; break;
case PACKET_MSG_LONG: case PACKET_MSG_LONG:
...@@ -3657,15 +3659,16 @@ static int goya_patch_cb(struct hl_device *hdev, ...@@ -3657,15 +3659,16 @@ static int goya_patch_cb(struct hl_device *hdev,
enum packet_id pkt_id; enum packet_id pkt_id;
u16 pkt_size; u16 pkt_size;
u32 new_pkt_size = 0; u32 new_pkt_size = 0;
void *user_pkt, *kernel_pkt; struct goya_packet *user_pkt, *kernel_pkt;
user_pkt = (void *) (uintptr_t) user_pkt = (struct goya_packet *) (uintptr_t)
(parser->user_cb->kernel_address + cb_parsed_length); (parser->user_cb->kernel_address + cb_parsed_length);
kernel_pkt = (void *) (uintptr_t) kernel_pkt = (struct goya_packet *) (uintptr_t)
(parser->patched_cb->kernel_address + (parser->patched_cb->kernel_address +
cb_patched_cur_length); cb_patched_cur_length);
pkt_id = (enum packet_id) (((*(u64 *) user_pkt) & pkt_id = (enum packet_id) (
(le64_to_cpu(user_pkt->header) &
PACKET_HEADER_PACKET_ID_MASK) >> PACKET_HEADER_PACKET_ID_MASK) >>
PACKET_HEADER_PACKET_ID_SHIFT); PACKET_HEADER_PACKET_ID_SHIFT);
...@@ -3680,15 +3683,18 @@ static int goya_patch_cb(struct hl_device *hdev, ...@@ -3680,15 +3683,18 @@ static int goya_patch_cb(struct hl_device *hdev,
switch (pkt_id) { switch (pkt_id) {
case PACKET_LIN_DMA: case PACKET_LIN_DMA:
rc = goya_patch_dma_packet(hdev, parser, user_pkt, rc = goya_patch_dma_packet(hdev, parser,
kernel_pkt, &new_pkt_size); (struct packet_lin_dma *) user_pkt,
(struct packet_lin_dma *) kernel_pkt,
&new_pkt_size);
cb_patched_cur_length += new_pkt_size; cb_patched_cur_length += new_pkt_size;
break; break;
case PACKET_WREG_32: case PACKET_WREG_32:
memcpy(kernel_pkt, user_pkt, pkt_size); memcpy(kernel_pkt, user_pkt, pkt_size);
cb_patched_cur_length += pkt_size; cb_patched_cur_length += pkt_size;
rc = goya_validate_wreg32(hdev, parser, kernel_pkt); rc = goya_validate_wreg32(hdev, parser,
(struct packet_wreg32 *) kernel_pkt);
break; break;
case PACKET_WREG_BULK: case PACKET_WREG_BULK:
......
...@@ -52,6 +52,19 @@ enum goya_dma_direction { ...@@ -52,6 +52,19 @@ enum goya_dma_direction {
#define GOYA_PKT_CTL_MB_SHIFT 31 #define GOYA_PKT_CTL_MB_SHIFT 31
#define GOYA_PKT_CTL_MB_MASK 0x80000000 #define GOYA_PKT_CTL_MB_MASK 0x80000000
/* All packets have, at least, an 8-byte header, which contains
* the packet type. The kernel driver uses the packet header for packet
* validation and to perform any necessary required preparation before
* sending them off to the hardware.
*/
struct goya_packet {
__le64 header;
/* The rest of the packet data follows. Use the corresponding
* packet_XXX struct to deference the data, based on packet type
*/
u8 contents[0];
};
struct packet_nop { struct packet_nop {
__le32 reserved; __le32 reserved;
__le32 ctl; __le32 ctl;
......
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