Use get/put_unaligned_be<n>(...) instead of

get/put_unaligned(cpu_to_be<n>(...)).

BSD-Signed-off-by: Bart Van Assche <bvanassche@acm.org>



git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3941 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2011-12-01 03:28:39 +00:00
parent a2dcbab715
commit 295adebc0f
7 changed files with 61 additions and 71 deletions

View File

@@ -3729,8 +3729,7 @@ static int iscsi_get_initiator_port_transport_id(struct scst_tgt *tgt,
tr_id[0] = 0x40 | SCSI_TRANSPORTID_PROTOCOLID_ISCSI;
sprintf(&tr_id[4], "%s,i,0x%llx", sess->initiator_name, sid.id64);
put_unaligned(cpu_to_be16(tr_id_size - 4),
(__be16 *)&tr_id[2]);
put_unaligned_be16(tr_id_size - 4, &tr_id[2]);
*transport_id = tr_id;

View File

@@ -3668,8 +3668,8 @@ static int q24_do_send_cmd_to_scst(struct q2t_cmd *cmd)
else
dir = SCST_DATA_NONE;
scst_cmd_set_expected(cmd->scst_cmd, dir,
be32_to_cpu(get_unaligned((uint32_t *)
&atio->fcp_cmnd.add_cdb[atio->fcp_cmnd.add_cdb_len])));
get_unaligned_be32(
&atio->fcp_cmnd.add_cdb[atio->fcp_cmnd.add_cdb_len]));
switch (atio->fcp_cmnd.task_attr) {
case ATIO_SIMPLE_QUEUE:
@@ -4938,8 +4938,8 @@ static void q24_atio_pkt(scsi_qla_host_t *ha, atio7_entry_t *atio)
"add_cdb_len %d, data_length %04x, s_id %x:%x:%x",
ha->instance, atio->fcp_cmnd.lun, atio->fcp_cmnd.rddata,
atio->fcp_cmnd.wrdata, atio->fcp_cmnd.add_cdb_len,
be32_to_cpu(get_unaligned((uint32_t *)
&atio->fcp_cmnd.add_cdb[atio->fcp_cmnd.add_cdb_len])),
get_unaligned_be32(
&atio->fcp_cmnd.add_cdb[atio->fcp_cmnd.add_cdb_len]),
atio->fcp_hdr.s_id[0], atio->fcp_hdr.s_id[1],
atio->fcp_hdr.s_id[2]);
TRACE_BUFFER("Incoming ATIO7 packet data", atio,

View File

@@ -383,26 +383,26 @@ static int disk_cdb_get_transfer_data(const uint8_t *cdb,
switch (cdb[0]) {
case WRITE_6:
case READ_6:
lba = be16_to_cpu(get_unaligned((__be16 *)&cdb[2]));
lba = get_unaligned_be16(&cdb[2]);
len = cdb[4];
break;
case WRITE_10:
case READ_10:
case WRITE_VERIFY:
lba = be32_to_cpu(get_unaligned((__be32 *)&cdb[2]));
len = be16_to_cpu(get_unaligned((__be16 *)&cdb[7]));
lba = get_unaligned_be32(&cdb[2]);
len = get_unaligned_be16(&cdb[7]);
break;
case WRITE_12:
case READ_12:
case WRITE_VERIFY_12:
lba = be32_to_cpu(get_unaligned((__be32 *)&cdb[2]));
len = be32_to_cpu(get_unaligned((__be32 *)&cdb[6]));
lba = get_unaligned_be32(&cdb[2]);
len = get_unaligned_be32(&cdb[6]);
break;
case WRITE_16:
case READ_16:
case WRITE_VERIFY_16:
lba = be64_to_cpu(get_unaligned((__be64 *)&cdb[2]));
len = be32_to_cpu(get_unaligned((__be32 *)&cdb[10]));
lba = get_unaligned_be64(&cdb[2]);
len = get_unaligned_be32(&cdb[10]);
break;
default:
res = -EINVAL;
@@ -430,26 +430,26 @@ static int disk_cdb_set_transfer_data(uint8_t *cdb,
switch (cdb[0]) {
case WRITE_6:
case READ_6:
put_unaligned(cpu_to_be16(lba), (__be16 *)&cdb[2]);
put_unaligned_be16(lba, &cdb[2]);
cdb[4] = len;
break;
case WRITE_10:
case READ_10:
case WRITE_VERIFY:
put_unaligned(cpu_to_be32(lba), (__be32 *)&cdb[2]);
put_unaligned(cpu_to_be16(len), (__be16 *)&cdb[7]);
put_unaligned_be32(lba, &cdb[2]);
put_unaligned_be16(len, &cdb[7]);
break;
case WRITE_12:
case READ_12:
case WRITE_VERIFY_12:
put_unaligned(cpu_to_be32(lba), (__be32 *)&cdb[2]);
put_unaligned(cpu_to_be32(len), (__be32 *)&cdb[6]);
put_unaligned_be32(lba, &cdb[2]);
put_unaligned_be32(len, &cdb[6]);
break;
case WRITE_16:
case READ_16:
case WRITE_VERIFY_16:
put_unaligned(cpu_to_be64(lba), (__be64 *)&cdb[2]);
put_unaligned(cpu_to_be32(len), (__be32 *)&cdb[10]);
put_unaligned_be64(lba, &cdb[2]);
put_unaligned_be32(len, &cdb[10]);
break;
default:
res = -EINVAL;

View File

@@ -1354,9 +1354,9 @@ static void vdisk_exec_unmap(struct scst_cmd *cmd, struct scst_vdisk_thr *thr)
#endif
uint64_t start;
uint32_t len;
start = be64_to_cpu(get_unaligned((__be64 *)&address[offset]));
start = get_unaligned_be64(&address[offset]);
offset += 8;
len = be32_to_cpu(get_unaligned((__be32 *)&address[offset]));
len = get_unaligned_be32(&address[offset]);
offset += 8;
if ((start > virt_dev->nblocks) ||
@@ -1580,8 +1580,8 @@ static void vdisk_exec_inquiry(struct scst_cmd *cmd)
/* Relative target port id */
buf[num + 1] = 0x10 | 0x04;
put_unaligned(cpu_to_be16(cmd->tgt->rel_tgt_id),
(__be16 *)&buf[num + 4 + 2]);
put_unaligned_be16(cmd->tgt->rel_tgt_id,
&buf[num + 4 + 2]);
buf[num + 3] = 4;
num += buf[num + 3];
@@ -1597,8 +1597,7 @@ static void vdisk_exec_inquiry(struct scst_cmd *cmd)
/* Target port group id */
buf[num + 1] = 0x10 | 0x05;
put_unaligned(cpu_to_be16(tg_id),
(__be16 *)&buf[num + 4 + 2]);
put_unaligned_be16(tg_id, &buf[num + 4 + 2]);
buf[num + 3] = 4;
num += 4 + buf[num + 3];
@@ -1638,15 +1637,14 @@ static void vdisk_exec_inquiry(struct scst_cmd *cmd)
buf[1] = 0xB0;
buf[3] = 0x3C;
/* Optimal transfer granuality is PAGE_SIZE */
put_unaligned(cpu_to_be16(max_t(int,
PAGE_SIZE/virt_dev->block_size, 1)),
(uint16_t *)&buf[6]);
put_unaligned_be16(max_t(int,
PAGE_SIZE/virt_dev->block_size, 1),
&buf[6]);
/* Max transfer len is min of sg limit and 8M */
max_transfer = min_t(int,
cmd->tgt_dev->max_sg_cnt << PAGE_SHIFT,
8*1024*1024) / virt_dev->block_size;
put_unaligned(cpu_to_be32(max_transfer),
(uint32_t *)&buf[8]);
put_unaligned_be32(max_transfer, &buf[8]);
/*
* Let's have optimal transfer len 512KB. Better to not
* set it at all, because we don't have such limit,
@@ -1654,14 +1652,13 @@ static void vdisk_exec_inquiry(struct scst_cmd *cmd)
* From other side, too big transfers are not optimal,
* because SGV cache supports only <4M buffers.
*/
put_unaligned(cpu_to_be32(min_t(int,
put_unaligned_be32(min_t(int,
max_transfer,
512*1024 / virt_dev->block_size)),
(uint32_t *)&buf[12]);
512*1024 / virt_dev->block_size),
&buf[12]);
if (virt_dev->thin_provisioned) {
/* MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT is UNLIMITED */
put_unaligned(cpu_to_be32(0xFFFFFFFF),
(uint32_t *)&buf[24]);
put_unaligned_be32(0xFFFFFFFF, &buf[24]);
if (virt_dev->blockio) {
/*
* OPTIMAL UNMAP GRANULARITY, ALIGNMENT
@@ -1670,24 +1667,21 @@ static void vdisk_exec_inquiry(struct scst_cmd *cmd)
uint32_t gran, align, max_lba;
vdev_blockio_get_unmap_params(virt_dev,
&gran, &align, &max_lba);
put_unaligned(cpu_to_be32(max_lba),
(uint32_t *)&buf[20]);
put_unaligned(cpu_to_be32(gran),
(uint32_t *)&buf[28]);
put_unaligned_be32(max_lba, &buf[20]);
put_unaligned_be32(gran, &buf[28]);
if (align != 0) {
put_unaligned(cpu_to_be32(align),
(uint32_t *)&buf[32]);
put_unaligned_be32(align,
&buf[32]);
buf[32] |= 0x80;
}
} else {
/* MAXIMUM UNMAP LBA COUNT */
put_unaligned(cpu_to_be32(
put_unaligned_be32(
min_t(loff_t, 0xFFFFFFFF,
virt_dev->file_size >> virt_dev->block_shift)),
(uint32_t *)&buf[20]);
virt_dev->file_size >> virt_dev->block_shift),
&buf[20]);
/* OPTIMAL UNMAP GRANULARITY */
put_unaligned(cpu_to_be32(1),
(uint32_t *)&buf[28]);
put_unaligned_be32(1, &buf[28]);
}
}
resp_len = buf[3] + 4;
@@ -1698,10 +1692,9 @@ static void vdisk_exec_inquiry(struct scst_cmd *cmd)
buf[3] = 0x3C;
if (virt_dev->rotational) {
/* 15K RPM */
put_unaligned(cpu_to_be16(0x3A98),
(uint16_t *)&buf[4]);
put_unaligned_be16(0x3A98, &buf[4]);
} else
put_unaligned(cpu_to_be16(1), (uint16_t *)&buf[4]);
put_unaligned_be16(1, &buf[4]);
resp_len = buf[3] + 4;
} else if ((0xB2 == cmd->cdb[2]) &&
(virt_dev->dev->type == TYPE_DISK) &&
@@ -2343,7 +2336,7 @@ static void vdisk_exec_read_capacity(struct scst_cmd *cmd)
nblocks = virt_dev->nblocks;
if ((cmd->cdb[8] & 1) == 0) {
uint64_t lba = be64_to_cpu(get_unaligned((__be64 *)&cmd->cdb[2]));
uint64_t lba = get_unaligned_be64(&cmd->cdb[2]);
if (lba != 0) {
TRACE_DBG("PMI zero and LBA not zero (cmd %p)", cmd);
scst_set_cmd_error(cmd,
@@ -2416,7 +2409,7 @@ static void vdisk_exec_read_capacity16(struct scst_cmd *cmd)
nblocks = virt_dev->nblocks - 1;
if ((cmd->cdb[14] & 1) == 0) {
uint64_t lba = be64_to_cpu(get_unaligned((__be64 *)&cmd->cdb[2]));
uint64_t lba = get_unaligned_be64(&cmd->cdb[2]);
if (lba != 0) {
TRACE_DBG("PMI zero and LBA not zero (cmd %p)", cmd);
scst_set_cmd_error(cmd,
@@ -2522,7 +2515,7 @@ static void vdisk_exec_report_tpgs(struct scst_cmd *cmd)
dev = cmd->dev;
data_format = cmd->cdb_len > 1 ? cmd->cdb[1] >> 5 : 0;
allocation_length = cmd->cdb_len >= 10 ?
be32_to_cpu(get_unaligned((__be32 *)(cmd->cdb + 6))) : 1024;
get_unaligned_be32(cmd->cdb + 6) : 1024;
res = scst_tg_get_group_info(&buf, &data_length, dev, data_format);
if (res == -ENOMEM) {

View File

@@ -5027,7 +5027,7 @@ static int get_trans_len_serv_act_in(struct scst_cmd *cmd, uint8_t off)
if ((cmd->cdb[1] & 0x1f) == SAI_READ_CAPACITY_16) {
cmd->op_name = "READ CAPACITY(16)";
cmd->bufflen = be32_to_cpu(get_unaligned((__be32 *)&cmd->cdb[10]));
cmd->bufflen = get_unaligned_be32(&cmd->cdb[10]);
cmd->op_flags |= SCST_IMPLICIT_HQ | SCST_REG_RESERVE_ALLOWED |
SCST_WRITE_EXCL_ALLOWED | SCST_EXCL_ACCESS_ALLOWED;
} else

View File

@@ -79,7 +79,7 @@ static inline int tid_size(const uint8_t *tid)
sBUG_ON(tid == NULL);
if ((tid[0] & 0x0f) == SCSI_TRANSPORTID_PROTOCOLID_ISCSI)
return be16_to_cpu(get_unaligned((__be16 *)&tid[2])) + 4;
return get_unaligned_be16(&tid[2]) + 4;
else
return TID_COMMON_SIZE;
}
@@ -1370,7 +1370,7 @@ static int scst_pr_register_with_spec_i_pt(struct scst_cmd *cmd,
action_key = get_unaligned((__be64 *)&buffer[8]);
ext_size = be32_to_cpu(get_unaligned((__be32 *)&buffer[24]));
ext_size = get_unaligned_be32(&buffer[24]);
if ((ext_size + 28) > buffer_size) {
TRACE_PR("Invalid buffer size %d (max %d)", buffer_size,
ext_size + 28);
@@ -1868,7 +1868,7 @@ void scst_pr_register_and_move(struct scst_cmd *cmd, uint8_t *buffer,
key = get_unaligned((__be64 *)&buffer[0]);
action_key = get_unaligned((__be64 *)&buffer[8]);
unreg = (buffer[17] >> 1) & 0x01;
tid_buffer_size = be32_to_cpu(get_unaligned((__be32 *)&buffer[20]));
tid_buffer_size = get_unaligned_be32(&buffer[20]);
#ifdef CONFIG_SCST_PROC
if (aptpl) {
@@ -1934,7 +1934,7 @@ void scst_pr_register_and_move(struct scst_cmd *cmd, uint8_t *buffer,
transport_id = sess->transport_id;
transport_id_move = (uint8_t *)&buffer[24];
rel_tgt_id_move = be16_to_cpu(get_unaligned((__be16 *)&buffer[18]));
rel_tgt_id_move = get_unaligned_be16(&buffer[18]);
if ((tid_size(transport_id_move) + 24) > buffer_size) {
TRACE_PR("Invalid buffer size %d (%d)",
@@ -2602,7 +2602,7 @@ void scst_pr_read_keys(struct scst_cmd *cmd, uint8_t *buffer, int buffer_size)
TRACE_PR("Read Keys (dev %s): PRGen %d", dev->virt_name,
dev->pr_generation);
put_unaligned(cpu_to_be32(dev->pr_generation), (__be32 *)&buffer[0]);
put_unaligned_be32(dev->pr_generation, &buffer[0]);
offset = 8;
size = 0;
@@ -2625,7 +2625,7 @@ void scst_pr_read_keys(struct scst_cmd *cmd, uint8_t *buffer, int buffer_size)
size += 8;
}
put_unaligned(cpu_to_be32(size), (__be32 *)&buffer[4]);
put_unaligned_be32(size, &buffer[4]);
skip:
scst_set_resp_data_len(cmd, offset);
@@ -2652,7 +2652,7 @@ void scst_pr_read_reservation(struct scst_cmd *cmd, uint8_t *buffer,
memset(b, 0, sizeof(b));
put_unaligned(cpu_to_be32(dev->pr_generation), (__be32 *)&b[0]);
put_unaligned_be32(dev->pr_generation, &b[0]);
if (!dev->pr_is_set) {
TRACE_PR("Read Reservation: no reservations for dev %s",
@@ -2749,7 +2749,7 @@ void scst_pr_read_full_status(struct scst_cmd *cmd, uint8_t *buffer,
if (buffer_size < 8)
goto skip;
put_unaligned(cpu_to_be32(dev->pr_generation), (__be32 *)&buffer[0]);
put_unaligned_be32(dev->pr_generation, &buffer[0]);
offset += 8;
size = 0;
@@ -2773,10 +2773,9 @@ void scst_pr_read_full_status(struct scst_cmd *cmd, uint8_t *buffer,
buffer[offset + 13] = (dev->pr_scope << 8) | dev->pr_type;
}
put_unaligned(cpu_to_be16(reg->rel_tgt_id),
(__be16 *)&buffer[offset + 18]);
put_unaligned(cpu_to_be32(ts),
(__be32 *)&buffer[offset + 20]);
put_unaligned_be16(reg->rel_tgt_id,
&buffer[offset + 18]);
put_unaligned_be32(ts, &buffer[offset + 20]);
memcpy(&buffer[offset + 24], reg->transport_id, ts);
@@ -2785,7 +2784,7 @@ void scst_pr_read_full_status(struct scst_cmd *cmd, uint8_t *buffer,
size += rec_len;
}
put_unaligned(cpu_to_be32(size), (__be32 *)&buffer[4]);
put_unaligned_be32(size, &buffer[4]);
skip:
scst_set_resp_data_len(cmd, offset);

View File

@@ -782,7 +782,7 @@ int scst_tg_get_group_info(void **buf, uint32_t *length,
p = *buf;
/* Return data length. */
put_unaligned(cpu_to_be32(ret_data_len), (__be32 *)p);
put_unaligned_be32(ret_data_len, p);
p += 4;
if (data_format == 1) {
/* Extended header */
@@ -801,7 +801,7 @@ int scst_tg_get_group_info(void **buf, uint32_t *length,
| SCST_TG_SUP_NONOPTIMIZED
| SCST_TG_SUP_STANDBY
| SCST_TG_SUP_UNAVAILABLE;
put_unaligned(cpu_to_be16(tg->group_id), (__be16 *)p);
put_unaligned_be16(tg->group_id, p);
p += 2;
p++; /* reserved */
*p++ = 2; /* status code: implicit transition */
@@ -815,8 +815,7 @@ int scst_tg_get_group_info(void **buf, uint32_t *length,
/* Target port descriptor. */
p += 2; /* reserved */
/* Relative target port identifier. */
put_unaligned(cpu_to_be16(rel_tgt_id),
(__be16 *)p);
put_unaligned_be16(rel_tgt_id, p);
p += 2;
}
}