hpsa: get rid of type/attribute/direction bit field where possible

Using bit fields for hardware command fields isn't portable and
relies on assumptions about how the compiler lays out the bits.
We can fix this in the driver's internal command structure, but the
ioctl interface we can't change because it is part of the
userland ABI.

Signed-off-by: Don Brace <don.brace@pmcs.com>
Reviewed-by: Webb Scales <webb.scales@hp.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Stephen M. Cameron 2014-11-14 17:27:04 -06:00 committed by Christoph Hellwig
parent 50a0decf75
commit a505b86fde
2 changed files with 42 additions and 34 deletions

View File

@ -4019,17 +4019,18 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB)); BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB));
c->Request.CDBLen = cmd->cmd_len; c->Request.CDBLen = cmd->cmd_len;
memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len); memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len);
c->Request.Type.Type = TYPE_CMD;
c->Request.Type.Attribute = ATTR_SIMPLE;
switch (cmd->sc_data_direction) { switch (cmd->sc_data_direction) {
case DMA_TO_DEVICE: case DMA_TO_DEVICE:
c->Request.Type.Direction = XFER_WRITE; c->Request.type_attr_dir =
TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_WRITE);
break; break;
case DMA_FROM_DEVICE: case DMA_FROM_DEVICE:
c->Request.Type.Direction = XFER_READ; c->Request.type_attr_dir =
TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_READ);
break; break;
case DMA_NONE: case DMA_NONE:
c->Request.Type.Direction = XFER_NONE; c->Request.type_attr_dir =
TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_NONE);
break; break;
case DMA_BIDIRECTIONAL: case DMA_BIDIRECTIONAL:
/* This can happen if a buggy application does a scsi passthru /* This can happen if a buggy application does a scsi passthru
@ -4037,7 +4038,8 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
* ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
*/ */
c->Request.Type.Direction = XFER_RSVD; c->Request.type_attr_dir =
TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_RSVD);
/* This is technically wrong, and hpsa controllers should /* This is technically wrong, and hpsa controllers should
* reject it with CMD_INVALID, which is the most correct * reject it with CMD_INVALID, which is the most correct
* response, but non-fibre backends appear to let it * response, but non-fibre backends appear to let it
@ -5257,7 +5259,6 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
c->Header.tag = c->busaddr; c->Header.tag = c->busaddr;
memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8); memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8);
c->Request.Type.Type = cmd_type;
if (cmd_type == TYPE_CMD) { if (cmd_type == TYPE_CMD) {
switch (cmd) { switch (cmd) {
case HPSA_INQUIRY: case HPSA_INQUIRY:
@ -5267,8 +5268,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
c->Request.CDB[2] = (page_code & 0xff); c->Request.CDB[2] = (page_code & 0xff);
} }
c->Request.CDBLen = 6; c->Request.CDBLen = 6;
c->Request.Type.Attribute = ATTR_SIMPLE; c->Request.type_attr_dir =
c->Request.Type.Direction = XFER_READ; TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
c->Request.Timeout = 0; c->Request.Timeout = 0;
c->Request.CDB[0] = HPSA_INQUIRY; c->Request.CDB[0] = HPSA_INQUIRY;
c->Request.CDB[4] = size & 0xFF; c->Request.CDB[4] = size & 0xFF;
@ -5279,8 +5280,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
mode = 00 target = 0. Nothing to write. mode = 00 target = 0. Nothing to write.
*/ */
c->Request.CDBLen = 12; c->Request.CDBLen = 12;
c->Request.Type.Attribute = ATTR_SIMPLE; c->Request.type_attr_dir =
c->Request.Type.Direction = XFER_READ; TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
c->Request.Timeout = 0; c->Request.Timeout = 0;
c->Request.CDB[0] = cmd; c->Request.CDB[0] = cmd;
c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */
@ -5290,8 +5291,9 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
break; break;
case HPSA_CACHE_FLUSH: case HPSA_CACHE_FLUSH:
c->Request.CDBLen = 12; c->Request.CDBLen = 12;
c->Request.Type.Attribute = ATTR_SIMPLE; c->Request.type_attr_dir =
c->Request.Type.Direction = XFER_WRITE; TYPE_ATTR_DIR(cmd_type,
ATTR_SIMPLE, XFER_WRITE);
c->Request.Timeout = 0; c->Request.Timeout = 0;
c->Request.CDB[0] = BMIC_WRITE; c->Request.CDB[0] = BMIC_WRITE;
c->Request.CDB[6] = BMIC_CACHE_FLUSH; c->Request.CDB[6] = BMIC_CACHE_FLUSH;
@ -5300,14 +5302,14 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
break; break;
case TEST_UNIT_READY: case TEST_UNIT_READY:
c->Request.CDBLen = 6; c->Request.CDBLen = 6;
c->Request.Type.Attribute = ATTR_SIMPLE; c->Request.type_attr_dir =
c->Request.Type.Direction = XFER_NONE; TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE);
c->Request.Timeout = 0; c->Request.Timeout = 0;
break; break;
case HPSA_GET_RAID_MAP: case HPSA_GET_RAID_MAP:
c->Request.CDBLen = 12; c->Request.CDBLen = 12;
c->Request.Type.Attribute = ATTR_SIMPLE; c->Request.type_attr_dir =
c->Request.Type.Direction = XFER_READ; TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
c->Request.Timeout = 0; c->Request.Timeout = 0;
c->Request.CDB[0] = HPSA_CISS_READ; c->Request.CDB[0] = HPSA_CISS_READ;
c->Request.CDB[1] = cmd; c->Request.CDB[1] = cmd;
@ -5318,8 +5320,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
break; break;
case BMIC_SENSE_CONTROLLER_PARAMETERS: case BMIC_SENSE_CONTROLLER_PARAMETERS:
c->Request.CDBLen = 10; c->Request.CDBLen = 10;
c->Request.Type.Attribute = ATTR_SIMPLE; c->Request.type_attr_dir =
c->Request.Type.Direction = XFER_READ; TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
c->Request.Timeout = 0; c->Request.Timeout = 0;
c->Request.CDB[0] = BMIC_READ; c->Request.CDB[0] = BMIC_READ;
c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS; c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS;
@ -5336,9 +5338,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
case HPSA_DEVICE_RESET_MSG: case HPSA_DEVICE_RESET_MSG:
c->Request.CDBLen = 16; c->Request.CDBLen = 16;
c->Request.Type.Type = 1; /* It is a MSG not a CMD */ c->Request.type_attr_dir =
c->Request.Type.Attribute = ATTR_SIMPLE; TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE);
c->Request.Type.Direction = XFER_NONE;
c->Request.Timeout = 0; /* Don't time out */ c->Request.Timeout = 0; /* Don't time out */
memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
c->Request.CDB[0] = cmd; c->Request.CDB[0] = cmd;
@ -5357,9 +5358,9 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
tlower = (u32) (a->Header.tag >> 32); tlower = (u32) (a->Header.tag >> 32);
tupper = (u32) (a->Header.tag & 0x0ffffffffULL); tupper = (u32) (a->Header.tag & 0x0ffffffffULL);
c->Request.CDBLen = 16; c->Request.CDBLen = 16;
c->Request.Type.Type = TYPE_MSG; c->Request.type_attr_dir =
c->Request.Type.Attribute = ATTR_SIMPLE; TYPE_ATTR_DIR(cmd_type,
c->Request.Type.Direction = XFER_WRITE; ATTR_SIMPLE, XFER_WRITE);
c->Request.Timeout = 0; /* Don't time out */ c->Request.Timeout = 0; /* Don't time out */
c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; c->Request.CDB[0] = HPSA_TASK_MANAGEMENT;
c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; c->Request.CDB[1] = HPSA_TMF_ABORT_TASK;
@ -5389,7 +5390,7 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
BUG(); BUG();
} }
switch (c->Request.Type.Direction) { switch (GET_DIR(c->Request.type_attr_dir)) {
case XFER_READ: case XFER_READ:
pci_dir = PCI_DMA_FROMDEVICE; pci_dir = PCI_DMA_FROMDEVICE;
break; break;
@ -5747,9 +5748,8 @@ static int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8); memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8);
cmd->Request.CDBLen = 16; cmd->Request.CDBLen = 16;
cmd->Request.Type.Type = TYPE_MSG; cmd->Request.type_attr_dir =
cmd->Request.Type.Attribute = ATTR_HEADOFQUEUE; TYPE_ATTR_DIR(TYPE_MSG, ATTR_HEADOFQUEUE, XFER_NONE);
cmd->Request.Type.Direction = XFER_NONE;
cmd->Request.Timeout = 0; /* Don't time out */ cmd->Request.Timeout = 0; /* Don't time out */
cmd->Request.CDB[0] = opcode; cmd->Request.CDB[0] = opcode;
cmd->Request.CDB[1] = type; cmd->Request.CDB[1] = type;

View File

@ -320,11 +320,19 @@ struct CommandListHeader {
struct RequestBlock { struct RequestBlock {
u8 CDBLen; u8 CDBLen;
struct { /*
u8 Type:3; * type_attr_dir:
u8 Attribute:3; * type: low 3 bits
u8 Direction:2; * attr: middle 3 bits
} Type; * dir: high 2 bits
*/
u8 type_attr_dir;
#define TYPE_ATTR_DIR(t, a, d) ((((d) & 0x03) << 6) |\
(((a) & 0x07) << 3) |\
((t) & 0x07))
#define GET_TYPE(tad) ((tad) & 0x07)
#define GET_ATTR(tad) (((tad) >> 3) & 0x07)
#define GET_DIR(tad) (((tad) >> 6) & 0x03)
u16 Timeout; u16 Timeout;
u8 CDB[16]; u8 CDB[16];
}; };