diff options
author | Stephen M. Cameron <scameron@beardog.cce.hp.com> | 2010-02-26 17:01:17 -0500 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2010-02-28 13:42:31 -0500 |
commit | 1b7d0d28ad82cbd5650c26ec8e370176b112e407 (patch) | |
tree | 5b7cd9a673ad2fe6c28d141d8822b0ea80095bd4 | |
parent | 58daa9ce96b847ed130453f5fdd63c579fb1f84f (diff) |
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: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r-- | drivers/block/cciss.c | 2 | ||||
-rw-r--r-- | drivers/block/cciss_cmd.h | 9 | ||||
-rw-r--r-- | drivers/block/cciss_scsi.c | 12 |
3 files changed, 15 insertions, 8 deletions
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index a29e69418a03..cd8c7c20b1c3 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c | |||
@@ -4496,7 +4496,7 @@ static int __init cciss_init(void) | |||
4496 | * boundary. Given that we use pci_alloc_consistent() to allocate an | 4496 | * boundary. Given that we use pci_alloc_consistent() to allocate an |
4497 | * array of them, the size must be a multiple of 8 bytes. | 4497 | * array of them, the size must be a multiple of 8 bytes. |
4498 | */ | 4498 | */ |
4499 | BUILD_BUG_ON(sizeof(CommandList_struct) % 8); | 4499 | BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT); |
4500 | 4500 | ||
4501 | printk(KERN_INFO DRIVER_NAME "\n"); | 4501 | printk(KERN_INFO DRIVER_NAME "\n"); |
4502 | 4502 | ||
diff --git a/drivers/block/cciss_cmd.h b/drivers/block/cciss_cmd.h index 515c9f03c201..e624ff959cb6 100644 --- a/drivers/block/cciss_cmd.h +++ b/drivers/block/cciss_cmd.h | |||
@@ -167,10 +167,13 @@ typedef struct _SGDescriptor_struct { | |||
167 | #define CMD_MSG_TIMEOUT 0x05 | 167 | #define CMD_MSG_TIMEOUT 0x05 |
168 | #define CMD_MSG_STALE 0xff | 168 | #define CMD_MSG_STALE 0xff |
169 | 169 | ||
170 | /* This structure needs to be divisible by 8 for new | 170 | /* This structure needs to be divisible by COMMANDLIST_ALIGNMENT |
171 | * indexing method. PAD_32 and PAD_64 can be adjusted | 171 | * because low bits of the address are used to to indicate that |
172 | * independently as needed for 32-bit and 64-bits systems. | 172 | * whether the tag contains an index or an address. PAD_32 and |
173 | * PAD_64 can be adjusted independently as needed for 32-bit | ||
174 | * and 64-bits systems. | ||
173 | */ | 175 | */ |
176 | #define COMMANDLIST_ALIGNMENT (8) | ||
174 | #define IS_64_BIT ((sizeof(long) - 4)/4) | 177 | #define IS_64_BIT ((sizeof(long) - 4)/4) |
175 | #define IS_32_BIT (!IS_64_BIT) | 178 | #define IS_32_BIT (!IS_64_BIT) |
176 | #define PAD_32 (0) | 179 | #define PAD_32 (0) |
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c index 5d0e46dc3632..f203606faaff 100644 --- a/drivers/block/cciss_scsi.c +++ b/drivers/block/cciss_scsi.c | |||
@@ -93,11 +93,15 @@ static struct scsi_host_template cciss_driver_template = { | |||
93 | }; | 93 | }; |
94 | 94 | ||
95 | #pragma pack(1) | 95 | #pragma pack(1) |
96 | |||
97 | #define SCSI_PAD_32 4 | ||
98 | #define SCSI_PAD_64 4 | ||
99 | |||
96 | struct cciss_scsi_cmd_stack_elem_t { | 100 | struct cciss_scsi_cmd_stack_elem_t { |
97 | CommandList_struct cmd; | 101 | CommandList_struct cmd; |
98 | ErrorInfo_struct Err; | 102 | ErrorInfo_struct Err; |
99 | __u32 busaddr; | 103 | __u32 busaddr; |
100 | __u32 pad; | 104 | u8 pad[IS_32_BIT * SCSI_PAD_32 + IS_64_BIT * SCSI_PAD_64]; |
101 | }; | 105 | }; |
102 | 106 | ||
103 | #pragma pack() | 107 | #pragma pack() |
@@ -202,9 +206,9 @@ scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa) | |||
202 | stk = &sa->cmd_stack; | 206 | stk = &sa->cmd_stack; |
203 | size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE; | 207 | size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE; |
204 | 208 | ||
205 | // pci_alloc_consistent guarantees 32-bit DMA address will | 209 | /* Check alignment, see cciss_cmd.h near CommandList_struct def. */ |
206 | // be used | 210 | BUILD_BUG_ON((sizeof(*stk->pool) % COMMANDLIST_ALIGNMENT) != 0); |
207 | 211 | /* pci_alloc_consistent guarantees 32-bit DMA address will be used */ | |
208 | stk->pool = (struct cciss_scsi_cmd_stack_elem_t *) | 212 | stk->pool = (struct cciss_scsi_cmd_stack_elem_t *) |
209 | pci_alloc_consistent(hba[ctlr]->pdev, size, &stk->cmd_pool_handle); | 213 | pci_alloc_consistent(hba[ctlr]->pdev, size, &stk->cmd_pool_handle); |
210 | 214 | ||