blob: 6b35625549378e3143e519dc24fd0daeb8714634 [file] [log] [blame]
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001/*
adam radford3f1530c2010-12-14 18:51:48 -08002 * Linux MegaRAID driver for SAS based RAID controllers
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04003 *
adam radford3f1530c2010-12-14 18:51:48 -08004 * Copyright (c) 2009-2011 LSI Corporation.
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04005 *
adam radford3f1530c2010-12-14 18:51:48 -08006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040010 *
adam radford3f1530c2010-12-14 18:51:48 -080011 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040015 *
adam radford3f1530c2010-12-14 18:51:48 -080016 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * FILE: megaraid_sas.h
21 *
22 * Authors: LSI Corporation
23 *
24 * Send feedback to: <megaraidlinux@lsi.com>
25 *
26 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035
27 * ATTN: Linuxraid
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040028 */
29
30#ifndef LSI_MEGARAID_SAS_H
31#define LSI_MEGARAID_SAS_H
32
Randy Dunlapa69b74d2007-01-05 22:41:48 -080033/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040034 * MegaRAID SAS Driver meta data
35 */
adam radforde1703582011-07-26 15:43:01 -070036#define MEGASAS_VERSION "00.00.05.40-rc1"
37#define MEGASAS_RELDATE "Jul. 26, 2011"
38#define MEGASAS_EXT_VERSION "Tue. Jul. 26 17:00:00 PDT 2011"
Sumant Patro0e989362006-06-20 15:32:37 -070039
40/*
41 * Device IDs
42 */
43#define PCI_DEVICE_ID_LSI_SAS1078R 0x0060
bo yangaf7a5642008-03-17 04:13:07 -040044#define PCI_DEVICE_ID_LSI_SAS1078DE 0x007C
Sumant Patro0e989362006-06-20 15:32:37 -070045#define PCI_DEVICE_ID_LSI_VERDE_ZCR 0x0413
Yang, Bo6610a6b2008-08-10 12:42:38 -070046#define PCI_DEVICE_ID_LSI_SAS1078GEN2 0x0078
47#define PCI_DEVICE_ID_LSI_SAS0079GEN2 0x0079
Yang, Bo87911122009-10-06 14:31:54 -060048#define PCI_DEVICE_ID_LSI_SAS0073SKINNY 0x0073
49#define PCI_DEVICE_ID_LSI_SAS0071SKINNY 0x0071
adam radford9c915a82010-12-21 13:34:31 -080050#define PCI_DEVICE_ID_LSI_FUSION 0x005b
adam radford36807e62011-10-08 18:15:06 -070051#define PCI_DEVICE_ID_LSI_INVADER 0x005d
Sumant Patro0e989362006-06-20 15:32:37 -070052
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040053/*
54 * =====================================
55 * MegaRAID SAS MFI firmware definitions
56 * =====================================
57 */
58
59/*
60 * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
61 * protocol between the software and firmware. Commands are issued using
62 * "message frames"
63 */
64
Randy Dunlapa69b74d2007-01-05 22:41:48 -080065/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040066 * FW posts its state in upper 4 bits of outbound_msg_0 register
67 */
68#define MFI_STATE_MASK 0xF0000000
69#define MFI_STATE_UNDEFINED 0x00000000
70#define MFI_STATE_BB_INIT 0x10000000
71#define MFI_STATE_FW_INIT 0x40000000
72#define MFI_STATE_WAIT_HANDSHAKE 0x60000000
73#define MFI_STATE_FW_INIT_2 0x70000000
74#define MFI_STATE_DEVICE_SCAN 0x80000000
Sumant Patroe3bbff92006-10-03 12:28:49 -070075#define MFI_STATE_BOOT_MESSAGE_PENDING 0x90000000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040076#define MFI_STATE_FLUSH_CACHE 0xA0000000
77#define MFI_STATE_READY 0xB0000000
78#define MFI_STATE_OPERATIONAL 0xC0000000
79#define MFI_STATE_FAULT 0xF0000000
adam radford7e70e732011-05-11 18:34:08 -070080#define MFI_RESET_REQUIRED 0x00000001
81#define MFI_RESET_ADAPTER 0x00000002
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040082#define MEGAMFI_FRAME_SIZE 64
83
Randy Dunlapa69b74d2007-01-05 22:41:48 -080084/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040085 * During FW init, clear pending cmds & reset state using inbound_msg_0
86 *
87 * ABORT : Abort all pending cmds
88 * READY : Move from OPERATIONAL to READY state; discard queue info
89 * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??)
90 * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver
Sumant Patroe3bbff92006-10-03 12:28:49 -070091 * HOTPLUG : Resume from Hotplug
92 * MFI_STOP_ADP : Send signal to FW to stop processing
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040093 */
bo yang39a98552010-09-22 22:36:29 -040094#define WRITE_SEQUENCE_OFFSET (0x0000000FC) /* I20 */
95#define HOST_DIAGNOSTIC_OFFSET (0x000000F8) /* I20 */
96#define DIAG_WRITE_ENABLE (0x00000080)
97#define DIAG_RESET_ADAPTER (0x00000004)
98
99#define MFI_ADP_RESET 0x00000040
Sumant Patroe3bbff92006-10-03 12:28:49 -0700100#define MFI_INIT_ABORT 0x00000001
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400101#define MFI_INIT_READY 0x00000002
102#define MFI_INIT_MFIMODE 0x00000004
103#define MFI_INIT_CLEAR_HANDSHAKE 0x00000008
Sumant Patroe3bbff92006-10-03 12:28:49 -0700104#define MFI_INIT_HOTPLUG 0x00000010
105#define MFI_STOP_ADP 0x00000020
106#define MFI_RESET_FLAGS MFI_INIT_READY| \
107 MFI_INIT_MFIMODE| \
108 MFI_INIT_ABORT
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400109
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800110/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400111 * MFI frame flags
112 */
113#define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000
114#define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001
115#define MFI_FRAME_SGL32 0x0000
116#define MFI_FRAME_SGL64 0x0002
117#define MFI_FRAME_SENSE32 0x0000
118#define MFI_FRAME_SENSE64 0x0004
119#define MFI_FRAME_DIR_NONE 0x0000
120#define MFI_FRAME_DIR_WRITE 0x0008
121#define MFI_FRAME_DIR_READ 0x0010
122#define MFI_FRAME_DIR_BOTH 0x0018
Yang, Bof4c9a132009-10-06 14:43:28 -0600123#define MFI_FRAME_IEEE 0x0020
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400124
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800125/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400126 * Definition for cmd_status
127 */
128#define MFI_CMD_STATUS_POLL_MODE 0xFF
129
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800130/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400131 * MFI command opcodes
132 */
133#define MFI_CMD_INIT 0x00
134#define MFI_CMD_LD_READ 0x01
135#define MFI_CMD_LD_WRITE 0x02
136#define MFI_CMD_LD_SCSI_IO 0x03
137#define MFI_CMD_PD_SCSI_IO 0x04
138#define MFI_CMD_DCMD 0x05
139#define MFI_CMD_ABORT 0x06
140#define MFI_CMD_SMP 0x07
141#define MFI_CMD_STP 0x08
142
143#define MR_DCMD_CTRL_GET_INFO 0x01010000
Yang, Bobdc6fb82009-12-06 08:30:19 -0700144#define MR_DCMD_LD_GET_LIST 0x03010000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400145
146#define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000
147#define MR_FLUSH_CTRL_CACHE 0x01
148#define MR_FLUSH_DISK_CACHE 0x02
149
150#define MR_DCMD_CTRL_SHUTDOWN 0x01050000
bo yang31ea7082007-11-07 12:09:50 -0500151#define MR_DCMD_HIBERNATE_SHUTDOWN 0x01060000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400152#define MR_ENABLE_DRIVE_SPINDOWN 0x01
153
154#define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100
155#define MR_DCMD_CTRL_EVENT_GET 0x01040300
156#define MR_DCMD_CTRL_EVENT_WAIT 0x01040500
157#define MR_DCMD_LD_GET_PROPERTIES 0x03030000
158
159#define MR_DCMD_CLUSTER 0x08000000
160#define MR_DCMD_CLUSTER_RESET_ALL 0x08010100
161#define MR_DCMD_CLUSTER_RESET_LD 0x08010200
Yang, Bo81e403c2009-10-06 14:27:54 -0600162#define MR_DCMD_PD_LIST_QUERY 0x02010100
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400163
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800164/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400165 * MFI command completion codes
166 */
167enum MFI_STAT {
168 MFI_STAT_OK = 0x00,
169 MFI_STAT_INVALID_CMD = 0x01,
170 MFI_STAT_INVALID_DCMD = 0x02,
171 MFI_STAT_INVALID_PARAMETER = 0x03,
172 MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04,
173 MFI_STAT_ABORT_NOT_POSSIBLE = 0x05,
174 MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06,
175 MFI_STAT_APP_IN_USE = 0x07,
176 MFI_STAT_APP_NOT_INITIALIZED = 0x08,
177 MFI_STAT_ARRAY_INDEX_INVALID = 0x09,
178 MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a,
179 MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b,
180 MFI_STAT_DEVICE_NOT_FOUND = 0x0c,
181 MFI_STAT_DRIVE_TOO_SMALL = 0x0d,
182 MFI_STAT_FLASH_ALLOC_FAIL = 0x0e,
183 MFI_STAT_FLASH_BUSY = 0x0f,
184 MFI_STAT_FLASH_ERROR = 0x10,
185 MFI_STAT_FLASH_IMAGE_BAD = 0x11,
186 MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12,
187 MFI_STAT_FLASH_NOT_OPEN = 0x13,
188 MFI_STAT_FLASH_NOT_STARTED = 0x14,
189 MFI_STAT_FLUSH_FAILED = 0x15,
190 MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16,
191 MFI_STAT_LD_CC_IN_PROGRESS = 0x17,
192 MFI_STAT_LD_INIT_IN_PROGRESS = 0x18,
193 MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19,
194 MFI_STAT_LD_MAX_CONFIGURED = 0x1a,
195 MFI_STAT_LD_NOT_OPTIMAL = 0x1b,
196 MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c,
197 MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d,
198 MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e,
199 MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f,
200 MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20,
201 MFI_STAT_MFC_HW_ERROR = 0x21,
202 MFI_STAT_NO_HW_PRESENT = 0x22,
203 MFI_STAT_NOT_FOUND = 0x23,
204 MFI_STAT_NOT_IN_ENCL = 0x24,
205 MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25,
206 MFI_STAT_PD_TYPE_WRONG = 0x26,
207 MFI_STAT_PR_DISABLED = 0x27,
208 MFI_STAT_ROW_INDEX_INVALID = 0x28,
209 MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29,
210 MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a,
211 MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b,
212 MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c,
213 MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d,
214 MFI_STAT_SCSI_IO_FAILED = 0x2e,
215 MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f,
216 MFI_STAT_SHUTDOWN_FAILED = 0x30,
217 MFI_STAT_TIME_NOT_SET = 0x31,
218 MFI_STAT_WRONG_STATE = 0x32,
219 MFI_STAT_LD_OFFLINE = 0x33,
220 MFI_STAT_PEER_NOTIFICATION_REJECTED = 0x34,
221 MFI_STAT_PEER_NOTIFICATION_FAILED = 0x35,
222 MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
223 MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
224 MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
adam radford36807e62011-10-08 18:15:06 -0700225 MFI_STAT_CONFIG_SEQ_MISMATCH = 0x67,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400226
227 MFI_STAT_INVALID_STATUS = 0xFF
228};
229
230/*
231 * Number of mailbox bytes in DCMD message frame
232 */
233#define MFI_MBOX_SIZE 12
234
235enum MR_EVT_CLASS {
236
237 MR_EVT_CLASS_DEBUG = -2,
238 MR_EVT_CLASS_PROGRESS = -1,
239 MR_EVT_CLASS_INFO = 0,
240 MR_EVT_CLASS_WARNING = 1,
241 MR_EVT_CLASS_CRITICAL = 2,
242 MR_EVT_CLASS_FATAL = 3,
243 MR_EVT_CLASS_DEAD = 4,
244
245};
246
247enum MR_EVT_LOCALE {
248
249 MR_EVT_LOCALE_LD = 0x0001,
250 MR_EVT_LOCALE_PD = 0x0002,
251 MR_EVT_LOCALE_ENCL = 0x0004,
252 MR_EVT_LOCALE_BBU = 0x0008,
253 MR_EVT_LOCALE_SAS = 0x0010,
254 MR_EVT_LOCALE_CTRL = 0x0020,
255 MR_EVT_LOCALE_CONFIG = 0x0040,
256 MR_EVT_LOCALE_CLUSTER = 0x0080,
257 MR_EVT_LOCALE_ALL = 0xffff,
258
259};
260
261enum MR_EVT_ARGS {
262
263 MR_EVT_ARGS_NONE,
264 MR_EVT_ARGS_CDB_SENSE,
265 MR_EVT_ARGS_LD,
266 MR_EVT_ARGS_LD_COUNT,
267 MR_EVT_ARGS_LD_LBA,
268 MR_EVT_ARGS_LD_OWNER,
269 MR_EVT_ARGS_LD_LBA_PD_LBA,
270 MR_EVT_ARGS_LD_PROG,
271 MR_EVT_ARGS_LD_STATE,
272 MR_EVT_ARGS_LD_STRIP,
273 MR_EVT_ARGS_PD,
274 MR_EVT_ARGS_PD_ERR,
275 MR_EVT_ARGS_PD_LBA,
276 MR_EVT_ARGS_PD_LBA_LD,
277 MR_EVT_ARGS_PD_PROG,
278 MR_EVT_ARGS_PD_STATE,
279 MR_EVT_ARGS_PCI,
280 MR_EVT_ARGS_RATE,
281 MR_EVT_ARGS_STR,
282 MR_EVT_ARGS_TIME,
283 MR_EVT_ARGS_ECC,
Yang, Bo81e403c2009-10-06 14:27:54 -0600284 MR_EVT_ARGS_LD_PROP,
285 MR_EVT_ARGS_PD_SPARE,
286 MR_EVT_ARGS_PD_INDEX,
287 MR_EVT_ARGS_DIAG_PASS,
288 MR_EVT_ARGS_DIAG_FAIL,
289 MR_EVT_ARGS_PD_LBA_LBA,
290 MR_EVT_ARGS_PORT_PHY,
291 MR_EVT_ARGS_PD_MISSING,
292 MR_EVT_ARGS_PD_ADDRESS,
293 MR_EVT_ARGS_BITMAP,
294 MR_EVT_ARGS_CONNECTOR,
295 MR_EVT_ARGS_PD_PD,
296 MR_EVT_ARGS_PD_FRU,
297 MR_EVT_ARGS_PD_PATHINFO,
298 MR_EVT_ARGS_PD_POWER_STATE,
299 MR_EVT_ARGS_GENERIC,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400300};
301
302/*
Yang, Bo81e403c2009-10-06 14:27:54 -0600303 * define constants for device list query options
304 */
305enum MR_PD_QUERY_TYPE {
306 MR_PD_QUERY_TYPE_ALL = 0,
307 MR_PD_QUERY_TYPE_STATE = 1,
308 MR_PD_QUERY_TYPE_POWER_STATE = 2,
309 MR_PD_QUERY_TYPE_MEDIA_TYPE = 3,
310 MR_PD_QUERY_TYPE_SPEED = 4,
311 MR_PD_QUERY_TYPE_EXPOSED_TO_HOST = 5,
312};
313
Yang, Bo7e8a75f2009-10-06 14:50:17 -0600314#define MR_EVT_CFG_CLEARED 0x0004
315#define MR_EVT_LD_STATE_CHANGE 0x0051
316#define MR_EVT_PD_INSERTED 0x005b
317#define MR_EVT_PD_REMOVED 0x0070
318#define MR_EVT_LD_CREATED 0x008a
319#define MR_EVT_LD_DELETED 0x008b
320#define MR_EVT_FOREIGN_CFG_IMPORTED 0x00db
321#define MR_EVT_LD_OFFLINE 0x00fc
322#define MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED 0x0152
323#define MAX_LOGICAL_DRIVES 64
324
Yang, Bo81e403c2009-10-06 14:27:54 -0600325enum MR_PD_STATE {
326 MR_PD_STATE_UNCONFIGURED_GOOD = 0x00,
327 MR_PD_STATE_UNCONFIGURED_BAD = 0x01,
328 MR_PD_STATE_HOT_SPARE = 0x02,
329 MR_PD_STATE_OFFLINE = 0x10,
330 MR_PD_STATE_FAILED = 0x11,
331 MR_PD_STATE_REBUILD = 0x14,
332 MR_PD_STATE_ONLINE = 0x18,
333 MR_PD_STATE_COPYBACK = 0x20,
334 MR_PD_STATE_SYSTEM = 0x40,
335 };
336
337
338 /*
339 * defines the physical drive address structure
340 */
341struct MR_PD_ADDRESS {
342 u16 deviceId;
343 u16 enclDeviceId;
344
345 union {
346 struct {
347 u8 enclIndex;
348 u8 slotNumber;
349 } mrPdAddress;
350 struct {
351 u8 enclPosition;
352 u8 enclConnectorIndex;
353 } mrEnclAddress;
354 };
355 u8 scsiDevType;
356 union {
357 u8 connectedPortBitmap;
358 u8 connectedPortNumbers;
359 };
360 u64 sasAddr[2];
361} __packed;
362
363/*
364 * defines the physical drive list structure
365 */
366struct MR_PD_LIST {
367 u32 size;
368 u32 count;
369 struct MR_PD_ADDRESS addr[1];
370} __packed;
371
372struct megasas_pd_list {
373 u16 tid;
374 u8 driveType;
375 u8 driveState;
376} __packed;
377
Yang, Bobdc6fb82009-12-06 08:30:19 -0700378 /*
379 * defines the logical drive reference structure
380 */
381union MR_LD_REF {
382 struct {
383 u8 targetId;
384 u8 reserved;
385 u16 seqNum;
386 };
387 u32 ref;
388} __packed;
389
390/*
391 * defines the logical drive list structure
392 */
393struct MR_LD_LIST {
394 u32 ldCount;
395 u32 reserved;
396 struct {
397 union MR_LD_REF ref;
398 u8 state;
399 u8 reserved[3];
400 u64 size;
401 } ldList[MAX_LOGICAL_DRIVES];
402} __packed;
403
Yang, Bo81e403c2009-10-06 14:27:54 -0600404/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400405 * SAS controller properties
406 */
407struct megasas_ctrl_prop {
408
409 u16 seq_num;
410 u16 pred_fail_poll_interval;
411 u16 intr_throttle_count;
412 u16 intr_throttle_timeouts;
413 u8 rebuild_rate;
414 u8 patrol_read_rate;
415 u8 bgi_rate;
416 u8 cc_rate;
417 u8 recon_rate;
418 u8 cache_flush_interval;
419 u8 spinup_drv_count;
420 u8 spinup_delay;
421 u8 cluster_enable;
422 u8 coercion_mode;
423 u8 alarm_enable;
424 u8 disable_auto_rebuild;
425 u8 disable_battery_warn;
426 u8 ecc_bucket_size;
427 u16 ecc_bucket_leak_rate;
428 u8 restore_hotspare_on_insertion;
429 u8 expose_encl_devices;
bo yang39a98552010-09-22 22:36:29 -0400430 u8 maintainPdFailHistory;
431 u8 disallowHostRequestReordering;
432 u8 abortCCOnError;
433 u8 loadBalanceMode;
434 u8 disableAutoDetectBackplane;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400435
bo yang39a98552010-09-22 22:36:29 -0400436 u8 snapVDSpace;
437
438 /*
439 * Add properties that can be controlled by
440 * a bit in the following structure.
441 */
bo yang39a98552010-09-22 22:36:29 -0400442 struct {
443 u32 copyBackDisabled : 1;
444 u32 SMARTerEnabled : 1;
445 u32 prCorrectUnconfiguredAreas : 1;
446 u32 useFdeOnly : 1;
447 u32 disableNCQ : 1;
448 u32 SSDSMARTerEnabled : 1;
449 u32 SSDPatrolReadEnabled : 1;
450 u32 enableSpinDownUnconfigured : 1;
451 u32 autoEnhancedImport : 1;
452 u32 enableSecretKeyControl : 1;
453 u32 disableOnlineCtrlReset : 1;
454 u32 allowBootWithPinnedCache : 1;
455 u32 disableSpinDownHS : 1;
456 u32 enableJBOD : 1;
457 u32 reserved :18;
458 } OnOffProperties;
459 u8 autoSnapVDSpace;
460 u8 viewSpace;
461 u16 spinDownTime;
462 u8 reserved[24];
Yang, Bo81e403c2009-10-06 14:27:54 -0600463} __packed;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400464
465/*
466 * SAS controller information
467 */
468struct megasas_ctrl_info {
469
470 /*
471 * PCI device information
472 */
473 struct {
474
475 u16 vendor_id;
476 u16 device_id;
477 u16 sub_vendor_id;
478 u16 sub_device_id;
479 u8 reserved[24];
480
481 } __attribute__ ((packed)) pci;
482
483 /*
484 * Host interface information
485 */
486 struct {
487
488 u8 PCIX:1;
489 u8 PCIE:1;
490 u8 iSCSI:1;
491 u8 SAS_3G:1;
492 u8 reserved_0:4;
493 u8 reserved_1[6];
494 u8 port_count;
495 u64 port_addr[8];
496
497 } __attribute__ ((packed)) host_interface;
498
499 /*
500 * Device (backend) interface information
501 */
502 struct {
503
504 u8 SPI:1;
505 u8 SAS_3G:1;
506 u8 SATA_1_5G:1;
507 u8 SATA_3G:1;
508 u8 reserved_0:4;
509 u8 reserved_1[6];
510 u8 port_count;
511 u64 port_addr[8];
512
513 } __attribute__ ((packed)) device_interface;
514
515 /*
516 * List of components residing in flash. All str are null terminated
517 */
518 u32 image_check_word;
519 u32 image_component_count;
520
521 struct {
522
523 char name[8];
524 char version[32];
525 char build_date[16];
526 char built_time[16];
527
528 } __attribute__ ((packed)) image_component[8];
529
530 /*
531 * List of flash components that have been flashed on the card, but
532 * are not in use, pending reset of the adapter. This list will be
533 * empty if a flash operation has not occurred. All stings are null
534 * terminated
535 */
536 u32 pending_image_component_count;
537
538 struct {
539
540 char name[8];
541 char version[32];
542 char build_date[16];
543 char build_time[16];
544
545 } __attribute__ ((packed)) pending_image_component[8];
546
547 u8 max_arms;
548 u8 max_spans;
549 u8 max_arrays;
550 u8 max_lds;
551
552 char product_name[80];
553 char serial_no[32];
554
555 /*
556 * Other physical/controller/operation information. Indicates the
557 * presence of the hardware
558 */
559 struct {
560
561 u32 bbu:1;
562 u32 alarm:1;
563 u32 nvram:1;
564 u32 uart:1;
565 u32 reserved:28;
566
567 } __attribute__ ((packed)) hw_present;
568
569 u32 current_fw_time;
570
571 /*
572 * Maximum data transfer sizes
573 */
574 u16 max_concurrent_cmds;
575 u16 max_sge_count;
576 u32 max_request_size;
577
578 /*
579 * Logical and physical device counts
580 */
581 u16 ld_present_count;
582 u16 ld_degraded_count;
583 u16 ld_offline_count;
584
585 u16 pd_present_count;
586 u16 pd_disk_present_count;
587 u16 pd_disk_pred_failure_count;
588 u16 pd_disk_failed_count;
589
590 /*
591 * Memory size information
592 */
593 u16 nvram_size;
594 u16 memory_size;
595 u16 flash_size;
596
597 /*
598 * Error counters
599 */
600 u16 mem_correctable_error_count;
601 u16 mem_uncorrectable_error_count;
602
603 /*
604 * Cluster information
605 */
606 u8 cluster_permitted;
607 u8 cluster_active;
608
609 /*
610 * Additional max data transfer sizes
611 */
612 u16 max_strips_per_io;
613
614 /*
615 * Controller capabilities structures
616 */
617 struct {
618
619 u32 raid_level_0:1;
620 u32 raid_level_1:1;
621 u32 raid_level_5:1;
622 u32 raid_level_1E:1;
623 u32 raid_level_6:1;
624 u32 reserved:27;
625
626 } __attribute__ ((packed)) raid_levels;
627
628 struct {
629
630 u32 rbld_rate:1;
631 u32 cc_rate:1;
632 u32 bgi_rate:1;
633 u32 recon_rate:1;
634 u32 patrol_rate:1;
635 u32 alarm_control:1;
636 u32 cluster_supported:1;
637 u32 bbu:1;
638 u32 spanning_allowed:1;
639 u32 dedicated_hotspares:1;
640 u32 revertible_hotspares:1;
641 u32 foreign_config_import:1;
642 u32 self_diagnostic:1;
643 u32 mixed_redundancy_arr:1;
644 u32 global_hot_spares:1;
645 u32 reserved:17;
646
647 } __attribute__ ((packed)) adapter_operations;
648
649 struct {
650
651 u32 read_policy:1;
652 u32 write_policy:1;
653 u32 io_policy:1;
654 u32 access_policy:1;
655 u32 disk_cache_policy:1;
656 u32 reserved:27;
657
658 } __attribute__ ((packed)) ld_operations;
659
660 struct {
661
662 u8 min;
663 u8 max;
664 u8 reserved[2];
665
666 } __attribute__ ((packed)) stripe_sz_ops;
667
668 struct {
669
670 u32 force_online:1;
671 u32 force_offline:1;
672 u32 force_rebuild:1;
673 u32 reserved:29;
674
675 } __attribute__ ((packed)) pd_operations;
676
677 struct {
678
679 u32 ctrl_supports_sas:1;
680 u32 ctrl_supports_sata:1;
681 u32 allow_mix_in_encl:1;
682 u32 allow_mix_in_ld:1;
683 u32 allow_sata_in_cluster:1;
684 u32 reserved:27;
685
686 } __attribute__ ((packed)) pd_mix_support;
687
688 /*
689 * Define ECC single-bit-error bucket information
690 */
691 u8 ecc_bucket_count;
692 u8 reserved_2[11];
693
694 /*
695 * Include the controller properties (changeable items)
696 */
697 struct megasas_ctrl_prop properties;
698
699 /*
700 * Define FW pkg version (set in envt v'bles on OEM basis)
701 */
702 char package_version[0x60];
703
704 u8 pad[0x800 - 0x6a0];
705
Yang, Bo81e403c2009-10-06 14:27:54 -0600706} __packed;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400707
708/*
709 * ===============================
710 * MegaRAID SAS driver definitions
711 * ===============================
712 */
713#define MEGASAS_MAX_PD_CHANNELS 2
714#define MEGASAS_MAX_LD_CHANNELS 2
715#define MEGASAS_MAX_CHANNELS (MEGASAS_MAX_PD_CHANNELS + \
716 MEGASAS_MAX_LD_CHANNELS)
717#define MEGASAS_MAX_DEV_PER_CHANNEL 128
718#define MEGASAS_DEFAULT_INIT_ID -1
719#define MEGASAS_MAX_LUN 8
720#define MEGASAS_MAX_LD 64
adam radford6bf579a2011-10-08 18:14:33 -0700721#define MEGASAS_DEFAULT_CMD_PER_LUN 256
Yang, Bo81e403c2009-10-06 14:27:54 -0600722#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \
723 MEGASAS_MAX_DEV_PER_CHANNEL)
Yang, Bobdc6fb82009-12-06 08:30:19 -0700724#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
725 MEGASAS_MAX_DEV_PER_CHANNEL)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400726
Yang, Bo1fd10682010-10-12 07:18:50 -0600727#define MEGASAS_MAX_SECTORS (2*1024)
adam radford42a8d2b2011-02-24 20:57:09 -0800728#define MEGASAS_MAX_SECTORS_IEEE (2*128)
Sumant Patro658dced2006-10-03 13:09:14 -0700729#define MEGASAS_DBG_LVL 1
730
Sumant Patro05e9ebb2007-05-17 05:47:51 -0700731#define MEGASAS_FW_BUSY 1
732
bo yangd532dbe2008-03-17 03:36:43 -0400733/* Frame Type */
734#define IO_FRAME 0
735#define PTHRU_FRAME 1
736
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400737/*
738 * When SCSI mid-layer calls driver's reset routine, driver waits for
739 * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
740 * that the driver cannot _actually_ abort or reset pending commands. While
741 * it is waiting for the commands to complete, it prints a diagnostic message
742 * every MEGASAS_RESET_NOTICE_INTERVAL seconds
743 */
744#define MEGASAS_RESET_WAIT_TIME 180
Sumant Patro2a3681e2006-10-03 13:19:21 -0700745#define MEGASAS_INTERNAL_CMD_WAIT_TIME 180
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400746#define MEGASAS_RESET_NOTICE_INTERVAL 5
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400747#define MEGASAS_IOCTL_CMD 0
Sumant Patro05e9ebb2007-05-17 05:47:51 -0700748#define MEGASAS_DEFAULT_CMD_TIMEOUT 90
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400749
750/*
751 * FW reports the maximum of number of commands that it can accept (maximum
752 * commands that can be outstanding) at any time. The driver must report a
753 * lower number to the mid layer because it can issue a few internal commands
754 * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs
755 * is shown below
756 */
757#define MEGASAS_INT_CMDS 32
Yang, Bo7bebf5c2009-10-06 14:40:58 -0600758#define MEGASAS_SKINNY_INT_CMDS 5
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400759
760/*
761 * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
762 * SGLs based on the size of dma_addr_t
763 */
764#define IS_DMA64 (sizeof(dma_addr_t) == 8)
765
bo yang39a98552010-09-22 22:36:29 -0400766#define MFI_XSCALE_OMR0_CHANGE_INTERRUPT 0x00000001
767
768#define MFI_INTR_FLAG_REPLY_MESSAGE 0x00000001
769#define MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE 0x00000002
770#define MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT 0x00000004
771
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400772#define MFI_OB_INTR_STATUS_MASK 0x00000002
bo yang14faea92007-11-09 04:14:00 -0500773#define MFI_POLL_TIMEOUT_SECS 60
bo yangad84db22007-11-09 04:40:16 -0500774#define MEGASAS_COMPLETION_TIMER_INTERVAL (HZ/10)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400775
Sumant Patrof9876f02006-02-03 15:34:35 -0800776#define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
Yang, Bo6610a6b2008-08-10 12:42:38 -0700777#define MFI_REPLY_GEN2_MESSAGE_INTERRUPT 0x00000001
778#define MFI_GEN2_ENABLE_INTERRUPT_MASK (0x00000001 | 0x00000004)
Yang, Bo87911122009-10-06 14:31:54 -0600779#define MFI_REPLY_SKINNY_MESSAGE_INTERRUPT 0x40000000
780#define MFI_SKINNY_ENABLE_INTERRUPT_MASK (0x00000001)
Sumant Patro0e989362006-06-20 15:32:37 -0700781
bo yang39a98552010-09-22 22:36:29 -0400782#define MFI_1068_PCSR_OFFSET 0x84
783#define MFI_1068_FW_HANDSHAKE_OFFSET 0x64
784#define MFI_1068_FW_READY 0xDDDD0000
Sumant Patro0e989362006-06-20 15:32:37 -0700785/*
786* register set for both 1068 and 1078 controllers
787* structure extended for 1078 registers
788*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800789
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400790struct megasas_register_set {
adam radford9c915a82010-12-21 13:34:31 -0800791 u32 doorbell; /*0000h*/
792 u32 fusion_seq_offset; /*0004h*/
793 u32 fusion_host_diag; /*0008h*/
794 u32 reserved_01; /*000Ch*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400795
Sumant Patrof9876f02006-02-03 15:34:35 -0800796 u32 inbound_msg_0; /*0010h*/
797 u32 inbound_msg_1; /*0014h*/
798 u32 outbound_msg_0; /*0018h*/
799 u32 outbound_msg_1; /*001Ch*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400800
Sumant Patrof9876f02006-02-03 15:34:35 -0800801 u32 inbound_doorbell; /*0020h*/
802 u32 inbound_intr_status; /*0024h*/
803 u32 inbound_intr_mask; /*0028h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400804
Sumant Patrof9876f02006-02-03 15:34:35 -0800805 u32 outbound_doorbell; /*002Ch*/
806 u32 outbound_intr_status; /*0030h*/
807 u32 outbound_intr_mask; /*0034h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400808
Sumant Patrof9876f02006-02-03 15:34:35 -0800809 u32 reserved_1[2]; /*0038h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400810
Sumant Patrof9876f02006-02-03 15:34:35 -0800811 u32 inbound_queue_port; /*0040h*/
812 u32 outbound_queue_port; /*0044h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400813
adam radford9c915a82010-12-21 13:34:31 -0800814 u32 reserved_2[9]; /*0048h*/
815 u32 reply_post_host_index; /*006Ch*/
816 u32 reserved_2_2[12]; /*0070h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400817
Sumant Patrof9876f02006-02-03 15:34:35 -0800818 u32 outbound_doorbell_clear; /*00A0h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400819
Sumant Patrof9876f02006-02-03 15:34:35 -0800820 u32 reserved_3[3]; /*00A4h*/
821
822 u32 outbound_scratch_pad ; /*00B0h*/
adam radford9c915a82010-12-21 13:34:31 -0800823 u32 outbound_scratch_pad_2; /*00B4h*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800824
adam radford9c915a82010-12-21 13:34:31 -0800825 u32 reserved_4[2]; /*00B8h*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800826
827 u32 inbound_low_queue_port ; /*00C0h*/
828
829 u32 inbound_high_queue_port ; /*00C4h*/
830
831 u32 reserved_5; /*00C8h*/
bo yang39a98552010-09-22 22:36:29 -0400832 u32 res_6[11]; /*CCh*/
833 u32 host_diag;
834 u32 seq_offset;
835 u32 index_registers[807]; /*00CCh*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400836} __attribute__ ((packed));
837
838struct megasas_sge32 {
839
840 u32 phys_addr;
841 u32 length;
842
843} __attribute__ ((packed));
844
845struct megasas_sge64 {
846
847 u64 phys_addr;
848 u32 length;
849
850} __attribute__ ((packed));
851
Yang, Bof4c9a132009-10-06 14:43:28 -0600852struct megasas_sge_skinny {
853 u64 phys_addr;
854 u32 length;
855 u32 flag;
856} __packed;
857
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400858union megasas_sgl {
859
860 struct megasas_sge32 sge32[1];
861 struct megasas_sge64 sge64[1];
Yang, Bof4c9a132009-10-06 14:43:28 -0600862 struct megasas_sge_skinny sge_skinny[1];
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400863
864} __attribute__ ((packed));
865
866struct megasas_header {
867
868 u8 cmd; /*00h */
869 u8 sense_len; /*01h */
870 u8 cmd_status; /*02h */
871 u8 scsi_status; /*03h */
872
873 u8 target_id; /*04h */
874 u8 lun; /*05h */
875 u8 cdb_len; /*06h */
876 u8 sge_count; /*07h */
877
878 u32 context; /*08h */
879 u32 pad_0; /*0Ch */
880
881 u16 flags; /*10h */
882 u16 timeout; /*12h */
883 u32 data_xferlen; /*14h */
884
885} __attribute__ ((packed));
886
887union megasas_sgl_frame {
888
889 struct megasas_sge32 sge32[8];
890 struct megasas_sge64 sge64[5];
891
892} __attribute__ ((packed));
893
894struct megasas_init_frame {
895
896 u8 cmd; /*00h */
897 u8 reserved_0; /*01h */
898 u8 cmd_status; /*02h */
899
900 u8 reserved_1; /*03h */
901 u32 reserved_2; /*04h */
902
903 u32 context; /*08h */
904 u32 pad_0; /*0Ch */
905
906 u16 flags; /*10h */
907 u16 reserved_3; /*12h */
908 u32 data_xfer_len; /*14h */
909
910 u32 queue_info_new_phys_addr_lo; /*18h */
911 u32 queue_info_new_phys_addr_hi; /*1Ch */
912 u32 queue_info_old_phys_addr_lo; /*20h */
913 u32 queue_info_old_phys_addr_hi; /*24h */
914
915 u32 reserved_4[6]; /*28h */
916
917} __attribute__ ((packed));
918
919struct megasas_init_queue_info {
920
921 u32 init_flags; /*00h */
922 u32 reply_queue_entries; /*04h */
923
924 u32 reply_queue_start_phys_addr_lo; /*08h */
925 u32 reply_queue_start_phys_addr_hi; /*0Ch */
926 u32 producer_index_phys_addr_lo; /*10h */
927 u32 producer_index_phys_addr_hi; /*14h */
928 u32 consumer_index_phys_addr_lo; /*18h */
929 u32 consumer_index_phys_addr_hi; /*1Ch */
930
931} __attribute__ ((packed));
932
933struct megasas_io_frame {
934
935 u8 cmd; /*00h */
936 u8 sense_len; /*01h */
937 u8 cmd_status; /*02h */
938 u8 scsi_status; /*03h */
939
940 u8 target_id; /*04h */
941 u8 access_byte; /*05h */
942 u8 reserved_0; /*06h */
943 u8 sge_count; /*07h */
944
945 u32 context; /*08h */
946 u32 pad_0; /*0Ch */
947
948 u16 flags; /*10h */
949 u16 timeout; /*12h */
950 u32 lba_count; /*14h */
951
952 u32 sense_buf_phys_addr_lo; /*18h */
953 u32 sense_buf_phys_addr_hi; /*1Ch */
954
955 u32 start_lba_lo; /*20h */
956 u32 start_lba_hi; /*24h */
957
958 union megasas_sgl sgl; /*28h */
959
960} __attribute__ ((packed));
961
962struct megasas_pthru_frame {
963
964 u8 cmd; /*00h */
965 u8 sense_len; /*01h */
966 u8 cmd_status; /*02h */
967 u8 scsi_status; /*03h */
968
969 u8 target_id; /*04h */
970 u8 lun; /*05h */
971 u8 cdb_len; /*06h */
972 u8 sge_count; /*07h */
973
974 u32 context; /*08h */
975 u32 pad_0; /*0Ch */
976
977 u16 flags; /*10h */
978 u16 timeout; /*12h */
979 u32 data_xfer_len; /*14h */
980
981 u32 sense_buf_phys_addr_lo; /*18h */
982 u32 sense_buf_phys_addr_hi; /*1Ch */
983
984 u8 cdb[16]; /*20h */
985 union megasas_sgl sgl; /*30h */
986
987} __attribute__ ((packed));
988
989struct megasas_dcmd_frame {
990
991 u8 cmd; /*00h */
992 u8 reserved_0; /*01h */
993 u8 cmd_status; /*02h */
994 u8 reserved_1[4]; /*03h */
995 u8 sge_count; /*07h */
996
997 u32 context; /*08h */
998 u32 pad_0; /*0Ch */
999
1000 u16 flags; /*10h */
1001 u16 timeout; /*12h */
1002
1003 u32 data_xfer_len; /*14h */
1004 u32 opcode; /*18h */
1005
1006 union { /*1Ch */
1007 u8 b[12];
1008 u16 s[6];
1009 u32 w[3];
1010 } mbox;
1011
1012 union megasas_sgl sgl; /*28h */
1013
1014} __attribute__ ((packed));
1015
1016struct megasas_abort_frame {
1017
1018 u8 cmd; /*00h */
1019 u8 reserved_0; /*01h */
1020 u8 cmd_status; /*02h */
1021
1022 u8 reserved_1; /*03h */
1023 u32 reserved_2; /*04h */
1024
1025 u32 context; /*08h */
1026 u32 pad_0; /*0Ch */
1027
1028 u16 flags; /*10h */
1029 u16 reserved_3; /*12h */
1030 u32 reserved_4; /*14h */
1031
1032 u32 abort_context; /*18h */
1033 u32 pad_1; /*1Ch */
1034
1035 u32 abort_mfi_phys_addr_lo; /*20h */
1036 u32 abort_mfi_phys_addr_hi; /*24h */
1037
1038 u32 reserved_5[6]; /*28h */
1039
1040} __attribute__ ((packed));
1041
1042struct megasas_smp_frame {
1043
1044 u8 cmd; /*00h */
1045 u8 reserved_1; /*01h */
1046 u8 cmd_status; /*02h */
1047 u8 connection_status; /*03h */
1048
1049 u8 reserved_2[3]; /*04h */
1050 u8 sge_count; /*07h */
1051
1052 u32 context; /*08h */
1053 u32 pad_0; /*0Ch */
1054
1055 u16 flags; /*10h */
1056 u16 timeout; /*12h */
1057
1058 u32 data_xfer_len; /*14h */
1059 u64 sas_addr; /*18h */
1060
1061 union {
1062 struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */
1063 struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */
1064 } sgl;
1065
1066} __attribute__ ((packed));
1067
1068struct megasas_stp_frame {
1069
1070 u8 cmd; /*00h */
1071 u8 reserved_1; /*01h */
1072 u8 cmd_status; /*02h */
1073 u8 reserved_2; /*03h */
1074
1075 u8 target_id; /*04h */
1076 u8 reserved_3[2]; /*05h */
1077 u8 sge_count; /*07h */
1078
1079 u32 context; /*08h */
1080 u32 pad_0; /*0Ch */
1081
1082 u16 flags; /*10h */
1083 u16 timeout; /*12h */
1084
1085 u32 data_xfer_len; /*14h */
1086
1087 u16 fis[10]; /*18h */
1088 u32 stp_flags;
1089
1090 union {
1091 struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */
1092 struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */
1093 } sgl;
1094
1095} __attribute__ ((packed));
1096
1097union megasas_frame {
1098
1099 struct megasas_header hdr;
1100 struct megasas_init_frame init;
1101 struct megasas_io_frame io;
1102 struct megasas_pthru_frame pthru;
1103 struct megasas_dcmd_frame dcmd;
1104 struct megasas_abort_frame abort;
1105 struct megasas_smp_frame smp;
1106 struct megasas_stp_frame stp;
1107
1108 u8 raw_bytes[64];
1109};
1110
1111struct megasas_cmd;
1112
1113union megasas_evt_class_locale {
1114
1115 struct {
1116 u16 locale;
1117 u8 reserved;
1118 s8 class;
1119 } __attribute__ ((packed)) members;
1120
1121 u32 word;
1122
1123} __attribute__ ((packed));
1124
1125struct megasas_evt_log_info {
1126 u32 newest_seq_num;
1127 u32 oldest_seq_num;
1128 u32 clear_seq_num;
1129 u32 shutdown_seq_num;
1130 u32 boot_seq_num;
1131
1132} __attribute__ ((packed));
1133
1134struct megasas_progress {
1135
1136 u16 progress;
1137 u16 elapsed_seconds;
1138
1139} __attribute__ ((packed));
1140
1141struct megasas_evtarg_ld {
1142
1143 u16 target_id;
1144 u8 ld_index;
1145 u8 reserved;
1146
1147} __attribute__ ((packed));
1148
1149struct megasas_evtarg_pd {
1150 u16 device_id;
1151 u8 encl_index;
1152 u8 slot_number;
1153
1154} __attribute__ ((packed));
1155
1156struct megasas_evt_detail {
1157
1158 u32 seq_num;
1159 u32 time_stamp;
1160 u32 code;
1161 union megasas_evt_class_locale cl;
1162 u8 arg_type;
1163 u8 reserved1[15];
1164
1165 union {
1166 struct {
1167 struct megasas_evtarg_pd pd;
1168 u8 cdb_length;
1169 u8 sense_length;
1170 u8 reserved[2];
1171 u8 cdb[16];
1172 u8 sense[64];
1173 } __attribute__ ((packed)) cdbSense;
1174
1175 struct megasas_evtarg_ld ld;
1176
1177 struct {
1178 struct megasas_evtarg_ld ld;
1179 u64 count;
1180 } __attribute__ ((packed)) ld_count;
1181
1182 struct {
1183 u64 lba;
1184 struct megasas_evtarg_ld ld;
1185 } __attribute__ ((packed)) ld_lba;
1186
1187 struct {
1188 struct megasas_evtarg_ld ld;
1189 u32 prevOwner;
1190 u32 newOwner;
1191 } __attribute__ ((packed)) ld_owner;
1192
1193 struct {
1194 u64 ld_lba;
1195 u64 pd_lba;
1196 struct megasas_evtarg_ld ld;
1197 struct megasas_evtarg_pd pd;
1198 } __attribute__ ((packed)) ld_lba_pd_lba;
1199
1200 struct {
1201 struct megasas_evtarg_ld ld;
1202 struct megasas_progress prog;
1203 } __attribute__ ((packed)) ld_prog;
1204
1205 struct {
1206 struct megasas_evtarg_ld ld;
1207 u32 prev_state;
1208 u32 new_state;
1209 } __attribute__ ((packed)) ld_state;
1210
1211 struct {
1212 u64 strip;
1213 struct megasas_evtarg_ld ld;
1214 } __attribute__ ((packed)) ld_strip;
1215
1216 struct megasas_evtarg_pd pd;
1217
1218 struct {
1219 struct megasas_evtarg_pd pd;
1220 u32 err;
1221 } __attribute__ ((packed)) pd_err;
1222
1223 struct {
1224 u64 lba;
1225 struct megasas_evtarg_pd pd;
1226 } __attribute__ ((packed)) pd_lba;
1227
1228 struct {
1229 u64 lba;
1230 struct megasas_evtarg_pd pd;
1231 struct megasas_evtarg_ld ld;
1232 } __attribute__ ((packed)) pd_lba_ld;
1233
1234 struct {
1235 struct megasas_evtarg_pd pd;
1236 struct megasas_progress prog;
1237 } __attribute__ ((packed)) pd_prog;
1238
1239 struct {
1240 struct megasas_evtarg_pd pd;
1241 u32 prevState;
1242 u32 newState;
1243 } __attribute__ ((packed)) pd_state;
1244
1245 struct {
1246 u16 vendorId;
1247 u16 deviceId;
1248 u16 subVendorId;
1249 u16 subDeviceId;
1250 } __attribute__ ((packed)) pci;
1251
1252 u32 rate;
1253 char str[96];
1254
1255 struct {
1256 u32 rtc;
1257 u32 elapsedSeconds;
1258 } __attribute__ ((packed)) time;
1259
1260 struct {
1261 u32 ecar;
1262 u32 elog;
1263 char str[64];
1264 } __attribute__ ((packed)) ecc;
1265
1266 u8 b[96];
1267 u16 s[48];
1268 u32 w[24];
1269 u64 d[12];
1270 } args;
1271
1272 char description[128];
1273
1274} __attribute__ ((packed));
1275
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001276struct megasas_aen_event {
1277 struct work_struct hotplug_work;
1278 struct megasas_instance *instance;
1279};
1280
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001281struct megasas_instance {
1282
1283 u32 *producer;
1284 dma_addr_t producer_h;
1285 u32 *consumer;
1286 dma_addr_t consumer_h;
1287
1288 u32 *reply_queue;
1289 dma_addr_t reply_queue_h;
1290
1291 unsigned long base_addr;
1292 struct megasas_register_set __iomem *reg_set;
1293
Yang, Bo81e403c2009-10-06 14:27:54 -06001294 struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
Yang, Bobdc6fb82009-12-06 08:30:19 -07001295 u8 ld_ids[MEGASAS_MAX_LD_IDS];
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001296 s8 init_id;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001297
1298 u16 max_num_sge;
1299 u16 max_fw_cmds;
adam radford9c915a82010-12-21 13:34:31 -08001300 /* For Fusion its num IOCTL cmds, for others MFI based its
1301 max_fw_cmds */
1302 u16 max_mfi_cmds;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001303 u32 max_sectors_per_req;
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001304 struct megasas_aen_event *ev;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001305
1306 struct megasas_cmd **cmd_list;
1307 struct list_head cmd_pool;
bo yang39a98552010-09-22 22:36:29 -04001308 /* used to sync fire the cmd to fw */
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001309 spinlock_t cmd_pool_lock;
bo yang39a98552010-09-22 22:36:29 -04001310 /* used to sync fire the cmd to fw */
1311 spinlock_t hba_lock;
bo yang7343eb62007-11-09 04:35:44 -05001312 /* used to synch producer, consumer ptrs in dpc */
1313 spinlock_t completion_lock;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001314 struct dma_pool *frame_dma_pool;
1315 struct dma_pool *sense_dma_pool;
1316
1317 struct megasas_evt_detail *evt_detail;
1318 dma_addr_t evt_detail_h;
1319 struct megasas_cmd *aen_cmd;
Matthias Kaehlckee5a69e22007-10-27 09:48:46 +02001320 struct mutex aen_mutex;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001321 struct semaphore ioctl_sem;
1322
1323 struct Scsi_Host *host;
1324
1325 wait_queue_head_t int_cmd_wait_q;
1326 wait_queue_head_t abort_cmd_wait_q;
1327
1328 struct pci_dev *pdev;
1329 u32 unique_id;
bo yang39a98552010-09-22 22:36:29 -04001330 u32 fw_support_ieee;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001331
Sumant Patroe4a082c2006-05-30 12:03:37 -07001332 atomic_t fw_outstanding;
bo yang39a98552010-09-22 22:36:29 -04001333 atomic_t fw_reset_no_pci_access;
Sumant Patro1341c932006-01-25 12:02:40 -08001334
1335 struct megasas_instance_template *instancet;
Sumant Patro5d018ad2006-10-03 13:13:18 -07001336 struct tasklet_struct isr_tasklet;
bo yang39a98552010-09-22 22:36:29 -04001337 struct work_struct work_init;
Sumant Patro05e9ebb2007-05-17 05:47:51 -07001338
1339 u8 flag;
Yang, Boc3518832009-10-06 14:18:02 -06001340 u8 unload;
Yang, Bof4c9a132009-10-06 14:43:28 -06001341 u8 flag_ieee;
bo yang39a98552010-09-22 22:36:29 -04001342 u8 issuepend_done;
1343 u8 disableOnlineCtrlReset;
1344 u8 adprecovery;
Sumant Patro05e9ebb2007-05-17 05:47:51 -07001345 unsigned long last_time;
bo yang39a98552010-09-22 22:36:29 -04001346 u32 mfiStatus;
1347 u32 last_seq_num;
bo yangad84db22007-11-09 04:40:16 -05001348
1349 struct timer_list io_completion_timer;
bo yang39a98552010-09-22 22:36:29 -04001350 struct list_head internal_reset_pending_q;
adam radford80d9da92010-12-21 10:17:40 -08001351
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001352 /* Ptr to hba specific information */
adam radford9c915a82010-12-21 13:34:31 -08001353 void *ctrl_context;
adam radford80d9da92010-12-21 10:17:40 -08001354 u8 msi_flag;
1355 struct msix_entry msixentry;
adam radford9c915a82010-12-21 13:34:31 -08001356 u64 map_id;
1357 struct megasas_cmd *map_update_cmd;
adam radfordb6d5d882010-12-14 18:56:07 -08001358 unsigned long bar;
adam radford9c915a82010-12-21 13:34:31 -08001359 long reset_flags;
1360 struct mutex reset_mutex;
bo yang39a98552010-09-22 22:36:29 -04001361};
1362
1363enum {
1364 MEGASAS_HBA_OPERATIONAL = 0,
1365 MEGASAS_ADPRESET_SM_INFAULT = 1,
1366 MEGASAS_ADPRESET_SM_FW_RESET_SUCCESS = 2,
1367 MEGASAS_ADPRESET_SM_OPERATIONAL = 3,
1368 MEGASAS_HW_CRITICAL_ERROR = 4,
1369 MEGASAS_ADPRESET_INPROG_SIGN = 0xDEADDEAD,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001370};
1371
Yang, Bo0c79e682009-10-06 14:47:35 -06001372struct megasas_instance_template {
1373 void (*fire_cmd)(struct megasas_instance *, dma_addr_t, \
1374 u32, struct megasas_register_set __iomem *);
1375
1376 void (*enable_intr)(struct megasas_register_set __iomem *) ;
1377 void (*disable_intr)(struct megasas_register_set __iomem *);
1378
1379 int (*clear_intr)(struct megasas_register_set __iomem *);
1380
1381 u32 (*read_fw_status_reg)(struct megasas_register_set __iomem *);
bo yang39a98552010-09-22 22:36:29 -04001382 int (*adp_reset)(struct megasas_instance *, \
1383 struct megasas_register_set __iomem *);
1384 int (*check_reset)(struct megasas_instance *, \
1385 struct megasas_register_set __iomem *);
adam radfordcd50ba82010-12-21 10:23:23 -08001386 irqreturn_t (*service_isr)(int irq, void *devp);
1387 void (*tasklet)(unsigned long);
1388 u32 (*init_adapter)(struct megasas_instance *);
1389 u32 (*build_and_issue_cmd) (struct megasas_instance *,
1390 struct scsi_cmnd *);
1391 void (*issue_dcmd) (struct megasas_instance *instance,
1392 struct megasas_cmd *cmd);
Yang, Bo0c79e682009-10-06 14:47:35 -06001393};
1394
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001395#define MEGASAS_IS_LOGICAL(scp) \
1396 (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1
1397
1398#define MEGASAS_DEV_INDEX(inst, scp) \
1399 ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
1400 scp->device->id
1401
1402struct megasas_cmd {
1403
1404 union megasas_frame *frame;
1405 dma_addr_t frame_phys_addr;
1406 u8 *sense;
1407 dma_addr_t sense_phys_addr;
1408
1409 u32 index;
1410 u8 sync_cmd;
1411 u8 cmd_status;
bo yang39a98552010-09-22 22:36:29 -04001412 u8 abort_aen;
1413 u8 retry_for_fw_reset;
1414
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001415
1416 struct list_head list;
1417 struct scsi_cmnd *scmd;
1418 struct megasas_instance *instance;
adam radford9c915a82010-12-21 13:34:31 -08001419 union {
1420 struct {
1421 u16 smid;
1422 u16 resvd;
1423 } context;
1424 u32 frame_count;
1425 };
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001426};
1427
1428#define MAX_MGMT_ADAPTERS 1024
1429#define MAX_IOCTL_SGE 16
1430
1431struct megasas_iocpacket {
1432
1433 u16 host_no;
1434 u16 __pad1;
1435 u32 sgl_off;
1436 u32 sge_count;
1437 u32 sense_off;
1438 u32 sense_len;
1439 union {
1440 u8 raw[128];
1441 struct megasas_header hdr;
1442 } frame;
1443
1444 struct iovec sgl[MAX_IOCTL_SGE];
1445
1446} __attribute__ ((packed));
1447
1448struct megasas_aen {
1449 u16 host_no;
1450 u16 __pad1;
1451 u32 seq_num;
1452 u32 class_locale_word;
1453} __attribute__ ((packed));
1454
1455#ifdef CONFIG_COMPAT
1456struct compat_megasas_iocpacket {
1457 u16 host_no;
1458 u16 __pad1;
1459 u32 sgl_off;
1460 u32 sge_count;
1461 u32 sense_off;
1462 u32 sense_len;
1463 union {
1464 u8 raw[128];
1465 struct megasas_header hdr;
1466 } frame;
1467 struct compat_iovec sgl[MAX_IOCTL_SGE];
1468} __attribute__ ((packed));
1469
Sumant Patro0e989362006-06-20 15:32:37 -07001470#define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001471#endif
1472
Sumant Patrocb59aa62006-01-25 11:53:25 -08001473#define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001474#define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
1475
1476struct megasas_mgmt_info {
1477
1478 u16 count;
1479 struct megasas_instance *instance[MAX_MGMT_ADAPTERS];
1480 int max_index;
1481};
1482
adam radford66192dfe2011-02-24 20:56:28 -08001483#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
1484#define PCI_MSIX_FLAGS_ENABLE (1 << 15)
1485
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001486#endif /*LSI_MEGARAID_SAS_H */