2020#ifndef HPSA_CMD_H
2121#define HPSA_CMD_H
2222
23+ #include <linux/compiler.h>
24+
25+ #include <linux/build_bug.h> /* static_assert */
26+ #include <linux/stddef.h> /* offsetof */
27+
2328/* general boundary defintions */
2429#define SENSEINFOBYTES 32 /* may vary between hbas */
2530#define SG_ENTRIES_IN_CMD 32 /* Max SG entries excluding chain blocks */
@@ -200,12 +205,10 @@ union u64bit {
200205 MAX_EXT_TARGETS + 1) /* + 1 is for the controller itself */
201206
202207/* SCSI-3 Commands */
203- #pragma pack(1)
204-
205208#define HPSA_INQUIRY 0x12
206209struct InquiryData {
207210 u8 data_byte [36 ];
208- };
211+ } __packed ;
209212
210213#define HPSA_REPORT_LOG 0xc2 /* Report Logical LUNs */
211214#define HPSA_REPORT_PHYS 0xc3 /* Report Physical LUNs */
@@ -221,7 +224,7 @@ struct raid_map_disk_data {
221224 u8 xor_mult [2 ]; /**< XOR multipliers for this position,
222225 * valid for data disks only */
223226 u8 reserved [2 ];
224- };
227+ } __packed ;
225228
226229struct raid_map_data {
227230 __le32 structure_size ; /* Size of entire structure in bytes */
@@ -247,14 +250,14 @@ struct raid_map_data {
247250 __le16 dekindex ; /* Data encryption key index. */
248251 u8 reserved [16 ];
249252 struct raid_map_disk_data data [RAID_MAP_MAX_ENTRIES ];
250- };
253+ } __packed ;
251254
252255struct ReportLUNdata {
253256 u8 LUNListLength [4 ];
254257 u8 extended_response_flag ;
255258 u8 reserved [3 ];
256259 u8 LUN [HPSA_MAX_LUN ][8 ];
257- };
260+ } __packed ;
258261
259262struct ext_report_lun_entry {
260263 u8 lunid [8 ];
@@ -269,20 +272,20 @@ struct ext_report_lun_entry {
269272 u8 lun_count ; /* multi-lun device, how many luns */
270273 u8 redundant_paths ;
271274 u32 ioaccel_handle ; /* ioaccel1 only uses lower 16 bits */
272- };
275+ } __packed ;
273276
274277struct ReportExtendedLUNdata {
275278 u8 LUNListLength [4 ];
276279 u8 extended_response_flag ;
277280 u8 reserved [3 ];
278281 struct ext_report_lun_entry LUN [HPSA_MAX_PHYS_LUN ];
279- };
282+ } __packed ;
280283
281284struct SenseSubsystem_info {
282285 u8 reserved [36 ];
283286 u8 portname [8 ];
284287 u8 reserved1 [1108 ];
285- };
288+ } __packed ;
286289
287290/* BMIC commands */
288291#define BMIC_READ 0x26
@@ -317,36 +320,36 @@ union SCSI3Addr {
317320 u8 Targ :6 ;
318321 u8 Mode :2 ; /* b10 */
319322 } LogUnit ;
320- };
323+ } __packed ;
321324
322325struct PhysDevAddr {
323326 u32 TargetId :24 ;
324327 u32 Bus :6 ;
325328 u32 Mode :2 ;
326329 /* 2 level target device addr */
327330 union SCSI3Addr Target [2 ];
328- };
331+ } __packed ;
329332
330333struct LogDevAddr {
331334 u32 VolId :30 ;
332335 u32 Mode :2 ;
333336 u8 reserved [4 ];
334- };
337+ } __packed ;
335338
336339union LUNAddr {
337340 u8 LunAddrBytes [8 ];
338341 union SCSI3Addr SCSI3Lun [4 ];
339342 struct PhysDevAddr PhysDev ;
340343 struct LogDevAddr LogDev ;
341- };
344+ } __packed ;
342345
343346struct CommandListHeader {
344347 u8 ReplyQueue ;
345348 u8 SGList ;
346349 __le16 SGTotal ;
347350 __le64 tag ;
348351 union LUNAddr LUN ;
349- };
352+ } __packed ;
350353
351354struct RequestBlock {
352355 u8 CDBLen ;
@@ -365,18 +368,18 @@ struct RequestBlock {
365368#define GET_DIR (tad ) (((tad) >> 6) & 0x03)
366369 u16 Timeout ;
367370 u8 CDB [16 ];
368- };
371+ } __packed ;
369372
370373struct ErrDescriptor {
371374 __le64 Addr ;
372375 __le32 Len ;
373- };
376+ } __packed ;
374377
375378struct SGDescriptor {
376379 __le64 Addr ;
377380 __le32 Len ;
378381 __le32 Ext ;
379- };
382+ } __packed ;
380383
381384union MoreErrInfo {
382385 struct {
@@ -390,15 +393,16 @@ union MoreErrInfo {
390393 u8 offense_num ; /* byte # of offense 0-base */
391394 u32 offense_value ;
392395 } Invalid_Cmd ;
393- };
396+ } __packed ;
397+
394398struct ErrorInfo {
395399 u8 ScsiStatus ;
396400 u8 SenseLen ;
397401 u16 CommandStatus ;
398402 u32 ResidualCnt ;
399403 union MoreErrInfo MoreErrInfo ;
400404 u8 SenseInfo [SENSEINFOBYTES ];
401- };
405+ } __packed ;
402406/* Command types */
403407#define CMD_IOCTL_PEND 0x01
404408#define CMD_SCSI 0x03
@@ -453,6 +457,15 @@ struct CommandList {
453457 atomic_t refcount ; /* Must be last to avoid memset in hpsa_cmd_init() */
454458} __aligned (COMMANDLIST_ALIGNMENT );
455459
460+ /*
461+ * Make sure our embedded atomic variable is aligned. Otherwise we break atomic
462+ * operations on architectures that don't support unaligned atomics like IA64.
463+ *
464+ * The assert guards against reintroductin against unwanted __packed to
465+ * the struct CommandList.
466+ */
467+ static_assert (offsetof(struct CommandList , refcount ) % __alignof__(atomic_t ) == 0 );
468+
456469/* Max S/G elements in I/O accelerator command */
457470#define IOACCEL1_MAXSGENTRIES 24
458471#define IOACCEL2_MAXSGENTRIES 28
@@ -489,7 +502,7 @@ struct io_accel1_cmd {
489502 __le64 host_addr ; /* 0x70 - 0x77 */
490503 u8 CISS_LUN [8 ]; /* 0x78 - 0x7F */
491504 struct SGDescriptor SG [IOACCEL1_MAXSGENTRIES ];
492- } __aligned (IOACCEL1_COMMANDLIST_ALIGNMENT );
505+ } __packed __aligned (IOACCEL1_COMMANDLIST_ALIGNMENT );
493506
494507#define IOACCEL1_FUNCTION_SCSIIO 0x00
495508#define IOACCEL1_SGLOFFSET 32
@@ -519,7 +532,7 @@ struct ioaccel2_sg_element {
519532 u8 chain_indicator ;
520533#define IOACCEL2_CHAIN 0x80
521534#define IOACCEL2_LAST_SG 0x40
522- };
535+ } __packed ;
523536
524537/*
525538 * SCSI Response Format structure for IO Accelerator Mode 2
@@ -559,7 +572,7 @@ struct io_accel2_scsi_response {
559572 u8 sense_data_len ; /* sense/response data length */
560573 u8 resid_cnt [4 ]; /* residual count */
561574 u8 sense_data_buff [32 ]; /* sense/response data buffer */
562- };
575+ } __packed ;
563576
564577/*
565578 * Structure for I/O accelerator (mode 2 or m2) commands.
@@ -592,7 +605,7 @@ struct io_accel2_cmd {
592605 __le32 tweak_upper ; /* Encryption tweak, upper 4 bytes */
593606 struct ioaccel2_sg_element sg [IOACCEL2_MAXSGENTRIES ];
594607 struct io_accel2_scsi_response error_data ;
595- } __aligned (IOACCEL2_COMMANDLIST_ALIGNMENT );
608+ } __packed __aligned (IOACCEL2_COMMANDLIST_ALIGNMENT );
596609
597610/*
598611 * defines for Mode 2 command struct
@@ -618,15 +631,15 @@ struct hpsa_tmf_struct {
618631 __le64 abort_tag ; /* cciss tag of SCSI cmd or TMF to abort */
619632 __le64 error_ptr ; /* Error Pointer */
620633 __le32 error_len ; /* Error Length */
621- } __aligned (IOACCEL2_COMMANDLIST_ALIGNMENT );
634+ } __packed __aligned (IOACCEL2_COMMANDLIST_ALIGNMENT );
622635
623636/* Configuration Table Structure */
624637struct HostWrite {
625638 __le32 TransportRequest ;
626639 __le32 command_pool_addr_hi ;
627640 __le32 CoalIntDelay ;
628641 __le32 CoalIntCount ;
629- };
642+ } __packed ;
630643
631644#define SIMPLE_MODE 0x02
632645#define PERFORMANT_MODE 0x04
@@ -675,7 +688,7 @@ struct CfgTable {
675688#define HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE (1 << 30)
676689#define HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE (1 << 31)
677690 __le32 clear_event_notify ;
678- };
691+ } __packed ;
679692
680693#define NUM_BLOCKFETCH_ENTRIES 8
681694struct TransTable_struct {
@@ -686,14 +699,14 @@ struct TransTable_struct {
686699 __le32 RepQCtrAddrHigh32 ;
687700#define MAX_REPLY_QUEUES 64
688701 struct vals32 RepQAddr [MAX_REPLY_QUEUES ];
689- };
702+ } __packed ;
690703
691704struct hpsa_pci_info {
692705 unsigned char bus ;
693706 unsigned char dev_fn ;
694707 unsigned short domain ;
695708 u32 board_id ;
696- };
709+ } __packed ;
697710
698711struct bmic_identify_controller {
699712 u8 configured_logical_drive_count ; /* offset 0 */
@@ -702,7 +715,7 @@ struct bmic_identify_controller {
702715 u8 pad2 [136 ];
703716 u8 controller_mode ; /* offset 292 */
704717 u8 pad3 [32 ];
705- };
718+ } __packed ;
706719
707720
708721struct bmic_identify_physical_device {
@@ -845,7 +858,7 @@ struct bmic_identify_physical_device {
845858 u8 max_link_rate [256 ];
846859 u8 neg_phys_link_rate [256 ];
847860 u8 box_conn_name [8 ];
848- } __attribute((aligned (512 )));
861+ } __packed __attribute((aligned (512 )));
849862
850863struct bmic_sense_subsystem_info {
851864 u8 primary_slot_number ;
@@ -858,7 +871,7 @@ struct bmic_sense_subsystem_info {
858871 u8 secondary_array_serial_number [32 ];
859872 u8 secondary_cache_serial_number [32 ];
860873 u8 pad [332 ];
861- };
874+ } __packed ;
862875
863876struct bmic_sense_storage_box_params {
864877 u8 reserved [36 ];
@@ -870,7 +883,6 @@ struct bmic_sense_storage_box_params {
870883 u8 reserver_3 [84 ];
871884 u8 phys_connector [2 ];
872885 u8 reserved_4 [296 ];
873- };
886+ } __packed ;
874887
875- #pragma pack()
876888#endif /* HPSA_CMD_H */
0 commit comments