Commit 1b7d0d28 authored by Stephen M. Cameron's avatar Stephen M. Cameron Committed by Jens Axboe

cciss: detect bad alignment of scsi commands at build time

cciss: detect bad alignment of scsi commands at build time
Incidentally fix some nearby c++ style comments.
Signed-off-by: default avatarStephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 58daa9ce
...@@ -4496,7 +4496,7 @@ static int __init cciss_init(void) ...@@ -4496,7 +4496,7 @@ static int __init cciss_init(void)
* boundary. Given that we use pci_alloc_consistent() to allocate an * boundary. Given that we use pci_alloc_consistent() to allocate an
* array of them, the size must be a multiple of 8 bytes. * array of them, the size must be a multiple of 8 bytes.
*/ */
BUILD_BUG_ON(sizeof(CommandList_struct) % 8); BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT);
printk(KERN_INFO DRIVER_NAME "\n"); printk(KERN_INFO DRIVER_NAME "\n");
......
...@@ -167,10 +167,13 @@ typedef struct _SGDescriptor_struct { ...@@ -167,10 +167,13 @@ typedef struct _SGDescriptor_struct {
#define CMD_MSG_TIMEOUT 0x05 #define CMD_MSG_TIMEOUT 0x05
#define CMD_MSG_STALE 0xff #define CMD_MSG_STALE 0xff
/* This structure needs to be divisible by 8 for new /* This structure needs to be divisible by COMMANDLIST_ALIGNMENT
* indexing method. PAD_32 and PAD_64 can be adjusted * because low bits of the address are used to to indicate that
* independently as needed for 32-bit and 64-bits systems. * whether the tag contains an index or an address. PAD_32 and
* PAD_64 can be adjusted independently as needed for 32-bit
* and 64-bits systems.
*/ */
#define COMMANDLIST_ALIGNMENT (8)
#define IS_64_BIT ((sizeof(long) - 4)/4) #define IS_64_BIT ((sizeof(long) - 4)/4)
#define IS_32_BIT (!IS_64_BIT) #define IS_32_BIT (!IS_64_BIT)
#define PAD_32 (0) #define PAD_32 (0)
......
...@@ -93,11 +93,15 @@ static struct scsi_host_template cciss_driver_template = { ...@@ -93,11 +93,15 @@ static struct scsi_host_template cciss_driver_template = {
}; };
#pragma pack(1) #pragma pack(1)
#define SCSI_PAD_32 4
#define SCSI_PAD_64 4
struct cciss_scsi_cmd_stack_elem_t { struct cciss_scsi_cmd_stack_elem_t {
CommandList_struct cmd; CommandList_struct cmd;
ErrorInfo_struct Err; ErrorInfo_struct Err;
__u32 busaddr; __u32 busaddr;
__u32 pad; u8 pad[IS_32_BIT * SCSI_PAD_32 + IS_64_BIT * SCSI_PAD_64];
}; };
#pragma pack() #pragma pack()
...@@ -202,9 +206,9 @@ scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa) ...@@ -202,9 +206,9 @@ scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa)
stk = &sa->cmd_stack; stk = &sa->cmd_stack;
size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE; size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE;
// pci_alloc_consistent guarantees 32-bit DMA address will /* Check alignment, see cciss_cmd.h near CommandList_struct def. */
// be used BUILD_BUG_ON((sizeof(*stk->pool) % COMMANDLIST_ALIGNMENT) != 0);
/* pci_alloc_consistent guarantees 32-bit DMA address will be used */
stk->pool = (struct cciss_scsi_cmd_stack_elem_t *) stk->pool = (struct cciss_scsi_cmd_stack_elem_t *)
pci_alloc_consistent(hba[ctlr]->pdev, size, &stk->cmd_pool_handle); pci_alloc_consistent(hba[ctlr]->pdev, size, &stk->cmd_pool_handle);
......
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