4 * Home page of code is: http://www.smartmontools.org
6 * Copyright (C) 2008 Jordan Hargrave
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 int megaraid_io_interface(int device
, int target
, struct scsi_cmnd_io
*, int);
20 /*======================================================
21 * PERC2/3/4 Passthrough SCSI Command Interface
24 * drivers/scsi/megaraid/megaraid_ioctl.h
25 * drivers/scsi/megaraid/mbox_defs.h
26 *======================================================*/
27 #define MEGAIOC_MAGIC 'm'
28 #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, struct uioctl_t)
30 /* Following subopcode work for opcode == 0x82 */
31 #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | adapno)
32 #define MEGAIOC_QNADAP 'm'
33 #define MEGAIOC_QDRVRVER 'e'
34 #define MEGAIOC_QADAPINFO 'g'
36 #define MEGA_MBOXCMD_PASSTHRU 0x03
38 #define MAX_REQ_SENSE_LEN 0x20
39 #define MAX_CDB_LEN 10
46 uint8_t islogical
: 1;
52 uint8_t cdb
[MAX_CDB_LEN
];
55 uint8_t reqsensearea
[MAX_REQ_SENSE_LEN
];
56 uint8_t numsgelements
;
58 uint32_t dataxferaddr
;
60 } __attribute__((packed
)) mega_passthru
;
74 } __attribute__((packed
)) megacmd_t
;
81 // The above definition assumes sizeof(void*) <= 8.
82 // This assumption also exists in the linux megaraid device driver.
83 // So define a macro to check expected size of ptr_t at compile time using
84 // a dummy typedef. On size mismatch, compiler reports a negative array
85 // size. If you see an error message of this form, it means that
86 // you have an unexpected pointer size on your platform and can not
87 // use megaraid support in smartmontools.
88 typedef char assert_sizeof_ptr_t
[sizeof(ptr_t
) == 8 ? 1 : -1];
102 } __attribute__((packed
)) fcs
;
103 } __attribute__((packed
)) ui
;
108 } __attribute__((packed
));
110 /*===================================================
111 * PERC5/6 Passthrough SCSI Command Interface
114 * drivers/scsi/megaraid/megaraid_sas.h
115 *===================================================*/
116 #define MEGASAS_MAGIC 'M'
117 #define MEGASAS_IOC_FIRMWARE _IOWR(MEGASAS_MAGIC, 1, struct megasas_iocpacket)
119 #define MFI_CMD_PD_SCSI_IO 0x04
120 #define MFI_CMD_DCMD 0x05
121 #define MFI_FRAME_SGL64 0x02
122 #define MFI_STAT_OK 0x00
123 #define MFI_DCMD_PD_GET_LIST 0x02010000
125 * Number of mailbox bytes in DCMD message frame
127 #define MFI_MBOX_SIZE 12
128 #define MAX_IOCTL_SGE 16
129 #define MFI_FRAME_DIR_NONE 0x0000
130 #define MFI_FRAME_DIR_WRITE 0x0008
131 #define MFI_FRAME_DIR_READ 0x0010
132 #define MFI_FRAME_DIR_BOTH 0x0018
134 #define MAX_SYS_PDS 240
136 struct megasas_sge32
{
141 } __attribute__ ((packed
));
143 struct megasas_sge64
{
148 } __attribute__ ((packed
));
152 struct megasas_sge32 sge32
[1];
153 struct megasas_sge64 sge64
[1];
155 } __attribute__ ((packed
));
157 struct megasas_header
{
160 u8 sense_len
; /*01h */
161 u8 cmd_status
; /*02h */
162 u8 scsi_status
; /*03h */
164 u8 target_id
; /*04h */
167 u8 sge_count
; /*07h */
169 u32 context
; /*08h */
173 u16 timeout
; /*12h */
174 u32 data_xferlen
; /*14h */
176 } __attribute__ ((packed
));
178 struct megasas_pthru_frame
{
181 u8 sense_len
; /*01h */
182 u8 cmd_status
; /*02h */
183 u8 scsi_status
; /*03h */
185 u8 target_id
; /*04h */
188 u8 sge_count
; /*07h */
190 u32 context
; /*08h */
194 u16 timeout
; /*12h */
195 u32 data_xfer_len
; /*14h */
197 u32 sense_buf_phys_addr_lo
; /*18h */
198 u32 sense_buf_phys_addr_hi
; /*1Ch */
201 union megasas_sgl sgl
; /*30h */
203 } __attribute__ ((packed
));
205 struct megasas_dcmd_frame
{
208 u8 reserved_0
; /*01h */
209 u8 cmd_status
; /*02h */
210 u8 reserved_1
[4]; /*03h */
211 u8 sge_count
; /*07h */
213 u32 context
; /*08h */
217 u16 timeout
; /*12h */
219 u32 data_xfer_len
; /*14h */
228 union megasas_sgl sgl
; /*28h */
230 } __attribute__ ((packed
));
232 struct megasas_iocpacket
{
241 struct megasas_header hdr
;
242 struct megasas_pthru_frame pthru
;
243 struct megasas_dcmd_frame dcmd
;
246 struct iovec sgl
[MAX_IOCTL_SGE
];
247 } __attribute__ ((packed
));
249 struct megasas_pd_address
{
254 u8 scsi_dev_type
; /* 0 = disk */
255 u8 connect_port_bitmap
;
257 } __attribute__ ((packed
));
259 struct megasas_pd_list
{
262 struct megasas_pd_address addr
[MAX_SYS_PDS
];
263 } __attribute__ ((packed
));