Commit 71ee9f01 authored by Stefan Richter's avatar Stefan Richter

firewire: fw-sbp2: remove usages of fw_memcpy_to_be32

Write directly in big endian instead of byte-swapping after the fact.
This saves a few conversions, lets gcc use constant endianess
conversions where possible, and enables deeper endianess annotation.
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 8ac3a47c
...@@ -224,8 +224,8 @@ struct sbp2_status { ...@@ -224,8 +224,8 @@ struct sbp2_status {
}; };
struct sbp2_pointer { struct sbp2_pointer {
u32 high; __be32 high;
u32 low; __be32 low;
}; };
struct sbp2_orb { struct sbp2_orb {
...@@ -253,8 +253,8 @@ struct sbp2_management_orb { ...@@ -253,8 +253,8 @@ struct sbp2_management_orb {
struct { struct {
struct sbp2_pointer password; struct sbp2_pointer password;
struct sbp2_pointer response; struct sbp2_pointer response;
u32 misc; __be32 misc;
u32 length; __be32 length;
struct sbp2_pointer status_fifo; struct sbp2_pointer status_fifo;
} request; } request;
__be32 response[4]; __be32 response[4];
...@@ -263,13 +263,10 @@ struct sbp2_management_orb { ...@@ -263,13 +263,10 @@ struct sbp2_management_orb {
struct sbp2_status status; struct sbp2_status status;
}; };
#define LOGIN_RESPONSE_GET_LOGIN_ID(v) ((v).misc & 0xffff)
#define LOGIN_RESPONSE_GET_LENGTH(v) (((v).misc >> 16) & 0xffff)
struct sbp2_login_response { struct sbp2_login_response {
u32 misc; __be32 misc;
struct sbp2_pointer command_block_agent; struct sbp2_pointer command_block_agent;
u32 reconnect_hold; __be32 reconnect_hold;
}; };
#define COMMAND_ORB_DATA_SIZE(v) ((v)) #define COMMAND_ORB_DATA_SIZE(v) ((v))
#define COMMAND_ORB_PAGE_SIZE(v) ((v) << 16) #define COMMAND_ORB_PAGE_SIZE(v) ((v) << 16)
...@@ -285,7 +282,7 @@ struct sbp2_command_orb { ...@@ -285,7 +282,7 @@ struct sbp2_command_orb {
struct { struct {
struct sbp2_pointer next; struct sbp2_pointer next;
struct sbp2_pointer data_descriptor; struct sbp2_pointer data_descriptor;
u32 misc; __be32 misc;
u8 command_block[12]; u8 command_block[12];
} request; } request;
struct scsi_cmnd *cmd; struct scsi_cmnd *cmd;
...@@ -459,8 +456,7 @@ sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, ...@@ -459,8 +456,7 @@ sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
unsigned long flags; unsigned long flags;
orb->pointer.high = 0; orb->pointer.high = 0;
orb->pointer.low = orb->request_bus; orb->pointer.low = cpu_to_be32(orb->request_bus);
fw_memcpy_to_be32(&orb->pointer, &orb->pointer, sizeof(orb->pointer));
spin_lock_irqsave(&device->card->lock, flags); spin_lock_irqsave(&device->card->lock, flags);
list_add_tail(&orb->link, &lu->orb_list); list_add_tail(&orb->link, &lu->orb_list);
...@@ -536,31 +532,31 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, ...@@ -536,31 +532,31 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
if (dma_mapping_error(orb->response_bus)) if (dma_mapping_error(orb->response_bus))
goto fail_mapping_response; goto fail_mapping_response;
orb->request.response.high = 0; orb->request.response.high = 0;
orb->request.response.low = orb->response_bus; orb->request.response.low = cpu_to_be32(orb->response_bus);
orb->request.misc = orb->request.misc = cpu_to_be32(
MANAGEMENT_ORB_NOTIFY | MANAGEMENT_ORB_NOTIFY |
MANAGEMENT_ORB_FUNCTION(function) | MANAGEMENT_ORB_FUNCTION(function) |
MANAGEMENT_ORB_LUN(lun_or_login_id); MANAGEMENT_ORB_LUN(lun_or_login_id));
orb->request.length = orb->request.length = cpu_to_be32(
MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response)); MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response)));
orb->request.status_fifo.high = lu->address_handler.offset >> 32; orb->request.status_fifo.high =
orb->request.status_fifo.low = lu->address_handler.offset; cpu_to_be32(lu->address_handler.offset >> 32);
orb->request.status_fifo.low =
cpu_to_be32(lu->address_handler.offset);
if (function == SBP2_LOGIN_REQUEST) { if (function == SBP2_LOGIN_REQUEST) {
/* Ask for 2^2 == 4 seconds reconnect grace period */ /* Ask for 2^2 == 4 seconds reconnect grace period */
orb->request.misc |= orb->request.misc |= cpu_to_be32(
MANAGEMENT_ORB_RECONNECT(2) | MANAGEMENT_ORB_RECONNECT(2) |
MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login); MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login));
timeout = lu->tgt->mgt_orb_timeout; timeout = lu->tgt->mgt_orb_timeout;
} else { } else {
timeout = SBP2_ORB_TIMEOUT; timeout = SBP2_ORB_TIMEOUT;
} }
fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
init_completion(&orb->done); init_completion(&orb->done);
orb->base.callback = complete_management_orb; orb->base.callback = complete_management_orb;
...@@ -605,8 +601,7 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, ...@@ -605,8 +601,7 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
sizeof(orb->response), DMA_FROM_DEVICE); sizeof(orb->response), DMA_FROM_DEVICE);
fail_mapping_response: fail_mapping_response:
if (response) if (response)
fw_memcpy_from_be32(response, memcpy(response, orb->response, sizeof(orb->response));
orb->response, sizeof(orb->response));
kref_put(&orb->base.kref, free_orb); kref_put(&orb->base.kref, free_orb);
return retval; return retval;
...@@ -885,11 +880,10 @@ static void sbp2_login(struct work_struct *work) ...@@ -885,11 +880,10 @@ static void sbp2_login(struct work_struct *work)
tgt->address_high = local_node_id << 16; tgt->address_high = local_node_id << 16;
sbp2_set_generation(lu, generation); sbp2_set_generation(lu, generation);
/* Get command block agent offset and login id. */
lu->command_block_agent_address = lu->command_block_agent_address =
((u64) (response.command_block_agent.high & 0xffff) << 32) | ((u64)(be32_to_cpu(response.command_block_agent.high) & 0xffff)
response.command_block_agent.low; << 32) | be32_to_cpu(response.command_block_agent.low);
lu->login_id = LOGIN_RESPONSE_GET_LOGIN_ID(response); lu->login_id = be32_to_cpu(response.misc) & 0xffff;
fw_notify("%s: logged in to LUN %04x (%d retries)\n", fw_notify("%s: logged in to LUN %04x (%d retries)\n",
tgt->bus_id, lu->lun, lu->retries); tgt->bus_id, lu->lun, lu->retries);
...@@ -1366,9 +1360,12 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, ...@@ -1366,9 +1360,12 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
* tables. * tables.
*/ */
if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) { if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) {
orb->request.data_descriptor.high = lu->tgt->address_high; orb->request.data_descriptor.high =
orb->request.data_descriptor.low = sg_dma_address(sg); cpu_to_be32(lu->tgt->address_high);
orb->request.misc |= COMMAND_ORB_DATA_SIZE(sg_dma_len(sg)); orb->request.data_descriptor.low =
cpu_to_be32(sg_dma_address(sg));
orb->request.misc |=
cpu_to_be32(COMMAND_ORB_DATA_SIZE(sg_dma_len(sg)));
return 0; return 0;
} }
...@@ -1389,16 +1386,14 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, ...@@ -1389,16 +1386,14 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
goto fail_page_table; goto fail_page_table;
} }
l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH); l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH);
orb->page_table[j].low = sg_addr; orb->page_table[j].low = cpu_to_be32(sg_addr);
orb->page_table[j].high = (l << 16); orb->page_table[j].high = cpu_to_be32(l << 16);
sg_addr += l; sg_addr += l;
sg_len -= l; sg_len -= l;
j++; j++;
} }
} }
fw_memcpy_to_be32(orb->page_table, orb->page_table,
sizeof(orb->page_table[0]) * j);
orb->page_table_bus = orb->page_table_bus =
dma_map_single(device->card->device, orb->page_table, dma_map_single(device->card->device, orb->page_table,
sizeof(orb->page_table), DMA_TO_DEVICE); sizeof(orb->page_table), DMA_TO_DEVICE);
...@@ -1412,11 +1407,10 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, ...@@ -1412,11 +1407,10 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
* initiator (i.e. us), but data_descriptor can refer to data * initiator (i.e. us), but data_descriptor can refer to data
* on other nodes so we need to put our ID in descriptor.high. * on other nodes so we need to put our ID in descriptor.high.
*/ */
orb->request.data_descriptor.high = lu->tgt->address_high; orb->request.data_descriptor.high = cpu_to_be32(lu->tgt->address_high);
orb->request.data_descriptor.low = orb->page_table_bus; orb->request.data_descriptor.low = cpu_to_be32(orb->page_table_bus);
orb->request.misc |= orb->request.misc |= cpu_to_be32(COMMAND_ORB_PAGE_TABLE_PRESENT |
COMMAND_ORB_PAGE_TABLE_PRESENT | COMMAND_ORB_DATA_SIZE(j));
COMMAND_ORB_DATA_SIZE(j);
return 0; return 0;
...@@ -1462,7 +1456,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) ...@@ -1462,7 +1456,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
orb->done = done; orb->done = done;
orb->cmd = cmd; orb->cmd = cmd;
orb->request.next.high = SBP2_ORB_NULL; orb->request.next.high = cpu_to_be32(SBP2_ORB_NULL);
orb->request.next.low = 0x0; orb->request.next.low = 0x0;
/* /*
* At speed 100 we can do 512 bytes per packet, at speed 200, * At speed 100 we can do 512 bytes per packet, at speed 200,
...@@ -1472,23 +1466,21 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) ...@@ -1472,23 +1466,21 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
*/ */
max_payload = min(device->max_speed + 7, max_payload = min(device->max_speed + 7,
device->card->max_receive - 1); device->card->max_receive - 1);
orb->request.misc = orb->request.misc = cpu_to_be32(
COMMAND_ORB_MAX_PAYLOAD(max_payload) | COMMAND_ORB_MAX_PAYLOAD(max_payload) |
COMMAND_ORB_SPEED(device->max_speed) | COMMAND_ORB_SPEED(device->max_speed) |
COMMAND_ORB_NOTIFY; COMMAND_ORB_NOTIFY);
if (cmd->sc_data_direction == DMA_FROM_DEVICE) if (cmd->sc_data_direction == DMA_FROM_DEVICE)
orb->request.misc |= orb->request.misc |= cpu_to_be32(
COMMAND_ORB_DIRECTION(SBP2_DIRECTION_FROM_MEDIA); COMMAND_ORB_DIRECTION(SBP2_DIRECTION_FROM_MEDIA));
else if (cmd->sc_data_direction == DMA_TO_DEVICE) else if (cmd->sc_data_direction == DMA_TO_DEVICE)
orb->request.misc |= orb->request.misc |= cpu_to_be32(
COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA); COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA));
if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0) if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
goto out; goto out;
fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
memset(orb->request.command_block, memset(orb->request.command_block,
0, sizeof(orb->request.command_block)); 0, sizeof(orb->request.command_block));
memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd)); memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
......
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