blob: d5efad70f234aab4b4eb7daf9509d2312b22eee1 [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 radfordae590572012-10-01 19:27:34 -07004 * Copyright (c) 2003-2012 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 radford5eca4a62013-02-09 15:29:25 -080036#define MEGASAS_VERSION "06.506.00.00-rc1"
37#define MEGASAS_RELDATE "Feb. 9, 2013"
38#define MEGASAS_EXT_VERSION "Sat. Feb. 9 17:00:00 PDT 2013"
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
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +053052#define PCI_DEVICE_ID_LSI_FURY 0x005f
Sumant Patro0e989362006-06-20 15:32:37 -070053
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040054/*
55 * =====================================
56 * MegaRAID SAS MFI firmware definitions
57 * =====================================
58 */
59
60/*
61 * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
62 * protocol between the software and firmware. Commands are issued using
63 * "message frames"
64 */
65
Randy Dunlapa69b74d2007-01-05 22:41:48 -080066/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040067 * FW posts its state in upper 4 bits of outbound_msg_0 register
68 */
69#define MFI_STATE_MASK 0xF0000000
70#define MFI_STATE_UNDEFINED 0x00000000
71#define MFI_STATE_BB_INIT 0x10000000
72#define MFI_STATE_FW_INIT 0x40000000
73#define MFI_STATE_WAIT_HANDSHAKE 0x60000000
74#define MFI_STATE_FW_INIT_2 0x70000000
75#define MFI_STATE_DEVICE_SCAN 0x80000000
Sumant Patroe3bbff92006-10-03 12:28:49 -070076#define MFI_STATE_BOOT_MESSAGE_PENDING 0x90000000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040077#define MFI_STATE_FLUSH_CACHE 0xA0000000
78#define MFI_STATE_READY 0xB0000000
79#define MFI_STATE_OPERATIONAL 0xC0000000
80#define MFI_STATE_FAULT 0xF0000000
adam radford7e70e732011-05-11 18:34:08 -070081#define MFI_RESET_REQUIRED 0x00000001
82#define MFI_RESET_ADAPTER 0x00000002
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040083#define MEGAMFI_FRAME_SIZE 64
84
Randy Dunlapa69b74d2007-01-05 22:41:48 -080085/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040086 * During FW init, clear pending cmds & reset state using inbound_msg_0
87 *
88 * ABORT : Abort all pending cmds
89 * READY : Move from OPERATIONAL to READY state; discard queue info
90 * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??)
91 * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver
Sumant Patroe3bbff92006-10-03 12:28:49 -070092 * HOTPLUG : Resume from Hotplug
93 * MFI_STOP_ADP : Send signal to FW to stop processing
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040094 */
bo yang39a98552010-09-22 22:36:29 -040095#define WRITE_SEQUENCE_OFFSET (0x0000000FC) /* I20 */
96#define HOST_DIAGNOSTIC_OFFSET (0x000000F8) /* I20 */
97#define DIAG_WRITE_ENABLE (0x00000080)
98#define DIAG_RESET_ADAPTER (0x00000004)
99
100#define MFI_ADP_RESET 0x00000040
Sumant Patroe3bbff92006-10-03 12:28:49 -0700101#define MFI_INIT_ABORT 0x00000001
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400102#define MFI_INIT_READY 0x00000002
103#define MFI_INIT_MFIMODE 0x00000004
104#define MFI_INIT_CLEAR_HANDSHAKE 0x00000008
Sumant Patroe3bbff92006-10-03 12:28:49 -0700105#define MFI_INIT_HOTPLUG 0x00000010
106#define MFI_STOP_ADP 0x00000020
107#define MFI_RESET_FLAGS MFI_INIT_READY| \
108 MFI_INIT_MFIMODE| \
109 MFI_INIT_ABORT
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400110
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800111/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400112 * MFI frame flags
113 */
114#define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000
115#define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001
116#define MFI_FRAME_SGL32 0x0000
117#define MFI_FRAME_SGL64 0x0002
118#define MFI_FRAME_SENSE32 0x0000
119#define MFI_FRAME_SENSE64 0x0004
120#define MFI_FRAME_DIR_NONE 0x0000
121#define MFI_FRAME_DIR_WRITE 0x0008
122#define MFI_FRAME_DIR_READ 0x0010
123#define MFI_FRAME_DIR_BOTH 0x0018
Yang, Bof4c9a132009-10-06 14:43:28 -0600124#define MFI_FRAME_IEEE 0x0020
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400125
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800126/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400127 * Definition for cmd_status
128 */
129#define MFI_CMD_STATUS_POLL_MODE 0xFF
130
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800131/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400132 * MFI command opcodes
133 */
134#define MFI_CMD_INIT 0x00
135#define MFI_CMD_LD_READ 0x01
136#define MFI_CMD_LD_WRITE 0x02
137#define MFI_CMD_LD_SCSI_IO 0x03
138#define MFI_CMD_PD_SCSI_IO 0x04
139#define MFI_CMD_DCMD 0x05
140#define MFI_CMD_ABORT 0x06
141#define MFI_CMD_SMP 0x07
142#define MFI_CMD_STP 0x08
adam radforde5f93a32011-10-08 18:15:19 -0700143#define MFI_CMD_INVALID 0xff
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400144
145#define MR_DCMD_CTRL_GET_INFO 0x01010000
Yang, Bobdc6fb82009-12-06 08:30:19 -0700146#define MR_DCMD_LD_GET_LIST 0x03010000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400147
148#define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000
149#define MR_FLUSH_CTRL_CACHE 0x01
150#define MR_FLUSH_DISK_CACHE 0x02
151
152#define MR_DCMD_CTRL_SHUTDOWN 0x01050000
bo yang31ea7082007-11-07 12:09:50 -0500153#define MR_DCMD_HIBERNATE_SHUTDOWN 0x01060000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400154#define MR_ENABLE_DRIVE_SPINDOWN 0x01
155
156#define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100
157#define MR_DCMD_CTRL_EVENT_GET 0x01040300
158#define MR_DCMD_CTRL_EVENT_WAIT 0x01040500
159#define MR_DCMD_LD_GET_PROPERTIES 0x03030000
160
161#define MR_DCMD_CLUSTER 0x08000000
162#define MR_DCMD_CLUSTER_RESET_ALL 0x08010100
163#define MR_DCMD_CLUSTER_RESET_LD 0x08010200
Yang, Bo81e403c2009-10-06 14:27:54 -0600164#define MR_DCMD_PD_LIST_QUERY 0x02010100
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400165
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800166/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400167 * MFI command completion codes
168 */
169enum MFI_STAT {
170 MFI_STAT_OK = 0x00,
171 MFI_STAT_INVALID_CMD = 0x01,
172 MFI_STAT_INVALID_DCMD = 0x02,
173 MFI_STAT_INVALID_PARAMETER = 0x03,
174 MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04,
175 MFI_STAT_ABORT_NOT_POSSIBLE = 0x05,
176 MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06,
177 MFI_STAT_APP_IN_USE = 0x07,
178 MFI_STAT_APP_NOT_INITIALIZED = 0x08,
179 MFI_STAT_ARRAY_INDEX_INVALID = 0x09,
180 MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a,
181 MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b,
182 MFI_STAT_DEVICE_NOT_FOUND = 0x0c,
183 MFI_STAT_DRIVE_TOO_SMALL = 0x0d,
184 MFI_STAT_FLASH_ALLOC_FAIL = 0x0e,
185 MFI_STAT_FLASH_BUSY = 0x0f,
186 MFI_STAT_FLASH_ERROR = 0x10,
187 MFI_STAT_FLASH_IMAGE_BAD = 0x11,
188 MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12,
189 MFI_STAT_FLASH_NOT_OPEN = 0x13,
190 MFI_STAT_FLASH_NOT_STARTED = 0x14,
191 MFI_STAT_FLUSH_FAILED = 0x15,
192 MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16,
193 MFI_STAT_LD_CC_IN_PROGRESS = 0x17,
194 MFI_STAT_LD_INIT_IN_PROGRESS = 0x18,
195 MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19,
196 MFI_STAT_LD_MAX_CONFIGURED = 0x1a,
197 MFI_STAT_LD_NOT_OPTIMAL = 0x1b,
198 MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c,
199 MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d,
200 MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e,
201 MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f,
202 MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20,
203 MFI_STAT_MFC_HW_ERROR = 0x21,
204 MFI_STAT_NO_HW_PRESENT = 0x22,
205 MFI_STAT_NOT_FOUND = 0x23,
206 MFI_STAT_NOT_IN_ENCL = 0x24,
207 MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25,
208 MFI_STAT_PD_TYPE_WRONG = 0x26,
209 MFI_STAT_PR_DISABLED = 0x27,
210 MFI_STAT_ROW_INDEX_INVALID = 0x28,
211 MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29,
212 MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a,
213 MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b,
214 MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c,
215 MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d,
216 MFI_STAT_SCSI_IO_FAILED = 0x2e,
217 MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f,
218 MFI_STAT_SHUTDOWN_FAILED = 0x30,
219 MFI_STAT_TIME_NOT_SET = 0x31,
220 MFI_STAT_WRONG_STATE = 0x32,
221 MFI_STAT_LD_OFFLINE = 0x33,
222 MFI_STAT_PEER_NOTIFICATION_REJECTED = 0x34,
223 MFI_STAT_PEER_NOTIFICATION_FAILED = 0x35,
224 MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
225 MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
226 MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
adam radford36807e62011-10-08 18:15:06 -0700227 MFI_STAT_CONFIG_SEQ_MISMATCH = 0x67,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400228
229 MFI_STAT_INVALID_STATUS = 0xFF
230};
231
232/*
233 * Number of mailbox bytes in DCMD message frame
234 */
235#define MFI_MBOX_SIZE 12
236
237enum MR_EVT_CLASS {
238
239 MR_EVT_CLASS_DEBUG = -2,
240 MR_EVT_CLASS_PROGRESS = -1,
241 MR_EVT_CLASS_INFO = 0,
242 MR_EVT_CLASS_WARNING = 1,
243 MR_EVT_CLASS_CRITICAL = 2,
244 MR_EVT_CLASS_FATAL = 3,
245 MR_EVT_CLASS_DEAD = 4,
246
247};
248
249enum MR_EVT_LOCALE {
250
251 MR_EVT_LOCALE_LD = 0x0001,
252 MR_EVT_LOCALE_PD = 0x0002,
253 MR_EVT_LOCALE_ENCL = 0x0004,
254 MR_EVT_LOCALE_BBU = 0x0008,
255 MR_EVT_LOCALE_SAS = 0x0010,
256 MR_EVT_LOCALE_CTRL = 0x0020,
257 MR_EVT_LOCALE_CONFIG = 0x0040,
258 MR_EVT_LOCALE_CLUSTER = 0x0080,
259 MR_EVT_LOCALE_ALL = 0xffff,
260
261};
262
263enum MR_EVT_ARGS {
264
265 MR_EVT_ARGS_NONE,
266 MR_EVT_ARGS_CDB_SENSE,
267 MR_EVT_ARGS_LD,
268 MR_EVT_ARGS_LD_COUNT,
269 MR_EVT_ARGS_LD_LBA,
270 MR_EVT_ARGS_LD_OWNER,
271 MR_EVT_ARGS_LD_LBA_PD_LBA,
272 MR_EVT_ARGS_LD_PROG,
273 MR_EVT_ARGS_LD_STATE,
274 MR_EVT_ARGS_LD_STRIP,
275 MR_EVT_ARGS_PD,
276 MR_EVT_ARGS_PD_ERR,
277 MR_EVT_ARGS_PD_LBA,
278 MR_EVT_ARGS_PD_LBA_LD,
279 MR_EVT_ARGS_PD_PROG,
280 MR_EVT_ARGS_PD_STATE,
281 MR_EVT_ARGS_PCI,
282 MR_EVT_ARGS_RATE,
283 MR_EVT_ARGS_STR,
284 MR_EVT_ARGS_TIME,
285 MR_EVT_ARGS_ECC,
Yang, Bo81e403c2009-10-06 14:27:54 -0600286 MR_EVT_ARGS_LD_PROP,
287 MR_EVT_ARGS_PD_SPARE,
288 MR_EVT_ARGS_PD_INDEX,
289 MR_EVT_ARGS_DIAG_PASS,
290 MR_EVT_ARGS_DIAG_FAIL,
291 MR_EVT_ARGS_PD_LBA_LBA,
292 MR_EVT_ARGS_PORT_PHY,
293 MR_EVT_ARGS_PD_MISSING,
294 MR_EVT_ARGS_PD_ADDRESS,
295 MR_EVT_ARGS_BITMAP,
296 MR_EVT_ARGS_CONNECTOR,
297 MR_EVT_ARGS_PD_PD,
298 MR_EVT_ARGS_PD_FRU,
299 MR_EVT_ARGS_PD_PATHINFO,
300 MR_EVT_ARGS_PD_POWER_STATE,
301 MR_EVT_ARGS_GENERIC,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400302};
303
304/*
Yang, Bo81e403c2009-10-06 14:27:54 -0600305 * define constants for device list query options
306 */
307enum MR_PD_QUERY_TYPE {
308 MR_PD_QUERY_TYPE_ALL = 0,
309 MR_PD_QUERY_TYPE_STATE = 1,
310 MR_PD_QUERY_TYPE_POWER_STATE = 2,
311 MR_PD_QUERY_TYPE_MEDIA_TYPE = 3,
312 MR_PD_QUERY_TYPE_SPEED = 4,
313 MR_PD_QUERY_TYPE_EXPOSED_TO_HOST = 5,
314};
315
Yang, Bo7e8a75f2009-10-06 14:50:17 -0600316#define MR_EVT_CFG_CLEARED 0x0004
317#define MR_EVT_LD_STATE_CHANGE 0x0051
318#define MR_EVT_PD_INSERTED 0x005b
319#define MR_EVT_PD_REMOVED 0x0070
320#define MR_EVT_LD_CREATED 0x008a
321#define MR_EVT_LD_DELETED 0x008b
322#define MR_EVT_FOREIGN_CFG_IMPORTED 0x00db
323#define MR_EVT_LD_OFFLINE 0x00fc
324#define MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED 0x0152
325#define MAX_LOGICAL_DRIVES 64
326
Yang, Bo81e403c2009-10-06 14:27:54 -0600327enum MR_PD_STATE {
328 MR_PD_STATE_UNCONFIGURED_GOOD = 0x00,
329 MR_PD_STATE_UNCONFIGURED_BAD = 0x01,
330 MR_PD_STATE_HOT_SPARE = 0x02,
331 MR_PD_STATE_OFFLINE = 0x10,
332 MR_PD_STATE_FAILED = 0x11,
333 MR_PD_STATE_REBUILD = 0x14,
334 MR_PD_STATE_ONLINE = 0x18,
335 MR_PD_STATE_COPYBACK = 0x20,
336 MR_PD_STATE_SYSTEM = 0x40,
337 };
338
339
340 /*
341 * defines the physical drive address structure
342 */
343struct MR_PD_ADDRESS {
344 u16 deviceId;
345 u16 enclDeviceId;
346
347 union {
348 struct {
349 u8 enclIndex;
350 u8 slotNumber;
351 } mrPdAddress;
352 struct {
353 u8 enclPosition;
354 u8 enclConnectorIndex;
355 } mrEnclAddress;
356 };
357 u8 scsiDevType;
358 union {
359 u8 connectedPortBitmap;
360 u8 connectedPortNumbers;
361 };
362 u64 sasAddr[2];
363} __packed;
364
365/*
366 * defines the physical drive list structure
367 */
368struct MR_PD_LIST {
369 u32 size;
370 u32 count;
371 struct MR_PD_ADDRESS addr[1];
372} __packed;
373
374struct megasas_pd_list {
375 u16 tid;
376 u8 driveType;
377 u8 driveState;
378} __packed;
379
Yang, Bobdc6fb82009-12-06 08:30:19 -0700380 /*
381 * defines the logical drive reference structure
382 */
383union MR_LD_REF {
384 struct {
385 u8 targetId;
386 u8 reserved;
387 u16 seqNum;
388 };
389 u32 ref;
390} __packed;
391
392/*
393 * defines the logical drive list structure
394 */
395struct MR_LD_LIST {
396 u32 ldCount;
397 u32 reserved;
398 struct {
399 union MR_LD_REF ref;
400 u8 state;
401 u8 reserved[3];
402 u64 size;
403 } ldList[MAX_LOGICAL_DRIVES];
404} __packed;
405
Yang, Bo81e403c2009-10-06 14:27:54 -0600406/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400407 * SAS controller properties
408 */
409struct megasas_ctrl_prop {
410
411 u16 seq_num;
412 u16 pred_fail_poll_interval;
413 u16 intr_throttle_count;
414 u16 intr_throttle_timeouts;
415 u8 rebuild_rate;
416 u8 patrol_read_rate;
417 u8 bgi_rate;
418 u8 cc_rate;
419 u8 recon_rate;
420 u8 cache_flush_interval;
421 u8 spinup_drv_count;
422 u8 spinup_delay;
423 u8 cluster_enable;
424 u8 coercion_mode;
425 u8 alarm_enable;
426 u8 disable_auto_rebuild;
427 u8 disable_battery_warn;
428 u8 ecc_bucket_size;
429 u16 ecc_bucket_leak_rate;
430 u8 restore_hotspare_on_insertion;
431 u8 expose_encl_devices;
bo yang39a98552010-09-22 22:36:29 -0400432 u8 maintainPdFailHistory;
433 u8 disallowHostRequestReordering;
434 u8 abortCCOnError;
435 u8 loadBalanceMode;
436 u8 disableAutoDetectBackplane;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400437
bo yang39a98552010-09-22 22:36:29 -0400438 u8 snapVDSpace;
439
440 /*
441 * Add properties that can be controlled by
442 * a bit in the following structure.
443 */
bo yang39a98552010-09-22 22:36:29 -0400444 struct {
445 u32 copyBackDisabled : 1;
446 u32 SMARTerEnabled : 1;
447 u32 prCorrectUnconfiguredAreas : 1;
448 u32 useFdeOnly : 1;
449 u32 disableNCQ : 1;
450 u32 SSDSMARTerEnabled : 1;
451 u32 SSDPatrolReadEnabled : 1;
452 u32 enableSpinDownUnconfigured : 1;
453 u32 autoEnhancedImport : 1;
454 u32 enableSecretKeyControl : 1;
455 u32 disableOnlineCtrlReset : 1;
456 u32 allowBootWithPinnedCache : 1;
457 u32 disableSpinDownHS : 1;
458 u32 enableJBOD : 1;
459 u32 reserved :18;
460 } OnOffProperties;
461 u8 autoSnapVDSpace;
462 u8 viewSpace;
463 u16 spinDownTime;
464 u8 reserved[24];
Yang, Bo81e403c2009-10-06 14:27:54 -0600465} __packed;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400466
467/*
468 * SAS controller information
469 */
470struct megasas_ctrl_info {
471
472 /*
473 * PCI device information
474 */
475 struct {
476
477 u16 vendor_id;
478 u16 device_id;
479 u16 sub_vendor_id;
480 u16 sub_device_id;
481 u8 reserved[24];
482
483 } __attribute__ ((packed)) pci;
484
485 /*
486 * Host interface information
487 */
488 struct {
489
490 u8 PCIX:1;
491 u8 PCIE:1;
492 u8 iSCSI:1;
493 u8 SAS_3G:1;
494 u8 reserved_0:4;
495 u8 reserved_1[6];
496 u8 port_count;
497 u64 port_addr[8];
498
499 } __attribute__ ((packed)) host_interface;
500
501 /*
502 * Device (backend) interface information
503 */
504 struct {
505
506 u8 SPI:1;
507 u8 SAS_3G:1;
508 u8 SATA_1_5G:1;
509 u8 SATA_3G:1;
510 u8 reserved_0:4;
511 u8 reserved_1[6];
512 u8 port_count;
513 u64 port_addr[8];
514
515 } __attribute__ ((packed)) device_interface;
516
517 /*
518 * List of components residing in flash. All str are null terminated
519 */
520 u32 image_check_word;
521 u32 image_component_count;
522
523 struct {
524
525 char name[8];
526 char version[32];
527 char build_date[16];
528 char built_time[16];
529
530 } __attribute__ ((packed)) image_component[8];
531
532 /*
533 * List of flash components that have been flashed on the card, but
534 * are not in use, pending reset of the adapter. This list will be
535 * empty if a flash operation has not occurred. All stings are null
536 * terminated
537 */
538 u32 pending_image_component_count;
539
540 struct {
541
542 char name[8];
543 char version[32];
544 char build_date[16];
545 char build_time[16];
546
547 } __attribute__ ((packed)) pending_image_component[8];
548
549 u8 max_arms;
550 u8 max_spans;
551 u8 max_arrays;
552 u8 max_lds;
553
554 char product_name[80];
555 char serial_no[32];
556
557 /*
558 * Other physical/controller/operation information. Indicates the
559 * presence of the hardware
560 */
561 struct {
562
563 u32 bbu:1;
564 u32 alarm:1;
565 u32 nvram:1;
566 u32 uart:1;
567 u32 reserved:28;
568
569 } __attribute__ ((packed)) hw_present;
570
571 u32 current_fw_time;
572
573 /*
574 * Maximum data transfer sizes
575 */
576 u16 max_concurrent_cmds;
577 u16 max_sge_count;
578 u32 max_request_size;
579
580 /*
581 * Logical and physical device counts
582 */
583 u16 ld_present_count;
584 u16 ld_degraded_count;
585 u16 ld_offline_count;
586
587 u16 pd_present_count;
588 u16 pd_disk_present_count;
589 u16 pd_disk_pred_failure_count;
590 u16 pd_disk_failed_count;
591
592 /*
593 * Memory size information
594 */
595 u16 nvram_size;
596 u16 memory_size;
597 u16 flash_size;
598
599 /*
600 * Error counters
601 */
602 u16 mem_correctable_error_count;
603 u16 mem_uncorrectable_error_count;
604
605 /*
606 * Cluster information
607 */
608 u8 cluster_permitted;
609 u8 cluster_active;
610
611 /*
612 * Additional max data transfer sizes
613 */
614 u16 max_strips_per_io;
615
616 /*
617 * Controller capabilities structures
618 */
619 struct {
620
621 u32 raid_level_0:1;
622 u32 raid_level_1:1;
623 u32 raid_level_5:1;
624 u32 raid_level_1E:1;
625 u32 raid_level_6:1;
626 u32 reserved:27;
627
628 } __attribute__ ((packed)) raid_levels;
629
630 struct {
631
632 u32 rbld_rate:1;
633 u32 cc_rate:1;
634 u32 bgi_rate:1;
635 u32 recon_rate:1;
636 u32 patrol_rate:1;
637 u32 alarm_control:1;
638 u32 cluster_supported:1;
639 u32 bbu:1;
640 u32 spanning_allowed:1;
641 u32 dedicated_hotspares:1;
642 u32 revertible_hotspares:1;
643 u32 foreign_config_import:1;
644 u32 self_diagnostic:1;
645 u32 mixed_redundancy_arr:1;
646 u32 global_hot_spares:1;
647 u32 reserved:17;
648
649 } __attribute__ ((packed)) adapter_operations;
650
651 struct {
652
653 u32 read_policy:1;
654 u32 write_policy:1;
655 u32 io_policy:1;
656 u32 access_policy:1;
657 u32 disk_cache_policy:1;
658 u32 reserved:27;
659
660 } __attribute__ ((packed)) ld_operations;
661
662 struct {
663
664 u8 min;
665 u8 max;
666 u8 reserved[2];
667
668 } __attribute__ ((packed)) stripe_sz_ops;
669
670 struct {
671
672 u32 force_online:1;
673 u32 force_offline:1;
674 u32 force_rebuild:1;
675 u32 reserved:29;
676
677 } __attribute__ ((packed)) pd_operations;
678
679 struct {
680
681 u32 ctrl_supports_sas:1;
682 u32 ctrl_supports_sata:1;
683 u32 allow_mix_in_encl:1;
684 u32 allow_mix_in_ld:1;
685 u32 allow_sata_in_cluster:1;
686 u32 reserved:27;
687
688 } __attribute__ ((packed)) pd_mix_support;
689
690 /*
691 * Define ECC single-bit-error bucket information
692 */
693 u8 ecc_bucket_count;
694 u8 reserved_2[11];
695
696 /*
697 * Include the controller properties (changeable items)
698 */
699 struct megasas_ctrl_prop properties;
700
701 /*
702 * Define FW pkg version (set in envt v'bles on OEM basis)
703 */
704 char package_version[0x60];
705
706 u8 pad[0x800 - 0x6a0];
707
Yang, Bo81e403c2009-10-06 14:27:54 -0600708} __packed;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400709
710/*
711 * ===============================
712 * MegaRAID SAS driver definitions
713 * ===============================
714 */
715#define MEGASAS_MAX_PD_CHANNELS 2
716#define MEGASAS_MAX_LD_CHANNELS 2
717#define MEGASAS_MAX_CHANNELS (MEGASAS_MAX_PD_CHANNELS + \
718 MEGASAS_MAX_LD_CHANNELS)
719#define MEGASAS_MAX_DEV_PER_CHANNEL 128
720#define MEGASAS_DEFAULT_INIT_ID -1
721#define MEGASAS_MAX_LUN 8
722#define MEGASAS_MAX_LD 64
adam radford6bf579a2011-10-08 18:14:33 -0700723#define MEGASAS_DEFAULT_CMD_PER_LUN 256
Yang, Bo81e403c2009-10-06 14:27:54 -0600724#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \
725 MEGASAS_MAX_DEV_PER_CHANNEL)
Yang, Bobdc6fb82009-12-06 08:30:19 -0700726#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
727 MEGASAS_MAX_DEV_PER_CHANNEL)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400728
Yang, Bo1fd10682010-10-12 07:18:50 -0600729#define MEGASAS_MAX_SECTORS (2*1024)
adam radford42a8d2b2011-02-24 20:57:09 -0800730#define MEGASAS_MAX_SECTORS_IEEE (2*128)
Sumant Patro658dced2006-10-03 13:09:14 -0700731#define MEGASAS_DBG_LVL 1
732
Sumant Patro05e9ebb2007-05-17 05:47:51 -0700733#define MEGASAS_FW_BUSY 1
734
bo yangd532dbe2008-03-17 03:36:43 -0400735/* Frame Type */
736#define IO_FRAME 0
737#define PTHRU_FRAME 1
738
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400739/*
740 * When SCSI mid-layer calls driver's reset routine, driver waits for
741 * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
742 * that the driver cannot _actually_ abort or reset pending commands. While
743 * it is waiting for the commands to complete, it prints a diagnostic message
744 * every MEGASAS_RESET_NOTICE_INTERVAL seconds
745 */
746#define MEGASAS_RESET_WAIT_TIME 180
Sumant Patro2a3681e2006-10-03 13:19:21 -0700747#define MEGASAS_INTERNAL_CMD_WAIT_TIME 180
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400748#define MEGASAS_RESET_NOTICE_INTERVAL 5
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400749#define MEGASAS_IOCTL_CMD 0
Sumant Patro05e9ebb2007-05-17 05:47:51 -0700750#define MEGASAS_DEFAULT_CMD_TIMEOUT 90
adam radfordc5daa6a2012-07-17 18:20:03 -0700751#define MEGASAS_THROTTLE_QUEUE_DEPTH 16
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400752
753/*
754 * FW reports the maximum of number of commands that it can accept (maximum
755 * commands that can be outstanding) at any time. The driver must report a
756 * lower number to the mid layer because it can issue a few internal commands
757 * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs
758 * is shown below
759 */
760#define MEGASAS_INT_CMDS 32
Yang, Bo7bebf5c2009-10-06 14:40:58 -0600761#define MEGASAS_SKINNY_INT_CMDS 5
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400762
adam radfordc8e858f2011-10-08 18:15:13 -0700763#define MEGASAS_MAX_MSIX_QUEUES 16
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400764/*
765 * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
766 * SGLs based on the size of dma_addr_t
767 */
768#define IS_DMA64 (sizeof(dma_addr_t) == 8)
769
bo yang39a98552010-09-22 22:36:29 -0400770#define MFI_XSCALE_OMR0_CHANGE_INTERRUPT 0x00000001
771
772#define MFI_INTR_FLAG_REPLY_MESSAGE 0x00000001
773#define MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE 0x00000002
774#define MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT 0x00000004
775
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400776#define MFI_OB_INTR_STATUS_MASK 0x00000002
bo yang14faea92007-11-09 04:14:00 -0500777#define MFI_POLL_TIMEOUT_SECS 60
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400778
Sumant Patrof9876f02006-02-03 15:34:35 -0800779#define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
Yang, Bo6610a6b2008-08-10 12:42:38 -0700780#define MFI_REPLY_GEN2_MESSAGE_INTERRUPT 0x00000001
781#define MFI_GEN2_ENABLE_INTERRUPT_MASK (0x00000001 | 0x00000004)
Yang, Bo87911122009-10-06 14:31:54 -0600782#define MFI_REPLY_SKINNY_MESSAGE_INTERRUPT 0x40000000
783#define MFI_SKINNY_ENABLE_INTERRUPT_MASK (0x00000001)
Sumant Patro0e989362006-06-20 15:32:37 -0700784
bo yang39a98552010-09-22 22:36:29 -0400785#define MFI_1068_PCSR_OFFSET 0x84
786#define MFI_1068_FW_HANDSHAKE_OFFSET 0x64
787#define MFI_1068_FW_READY 0xDDDD0000
Sumant Patro0e989362006-06-20 15:32:37 -0700788/*
789* register set for both 1068 and 1078 controllers
790* structure extended for 1078 registers
791*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800792
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400793struct megasas_register_set {
adam radford9c915a82010-12-21 13:34:31 -0800794 u32 doorbell; /*0000h*/
795 u32 fusion_seq_offset; /*0004h*/
796 u32 fusion_host_diag; /*0008h*/
797 u32 reserved_01; /*000Ch*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400798
Sumant Patrof9876f02006-02-03 15:34:35 -0800799 u32 inbound_msg_0; /*0010h*/
800 u32 inbound_msg_1; /*0014h*/
801 u32 outbound_msg_0; /*0018h*/
802 u32 outbound_msg_1; /*001Ch*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400803
Sumant Patrof9876f02006-02-03 15:34:35 -0800804 u32 inbound_doorbell; /*0020h*/
805 u32 inbound_intr_status; /*0024h*/
806 u32 inbound_intr_mask; /*0028h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400807
Sumant Patrof9876f02006-02-03 15:34:35 -0800808 u32 outbound_doorbell; /*002Ch*/
809 u32 outbound_intr_status; /*0030h*/
810 u32 outbound_intr_mask; /*0034h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400811
Sumant Patrof9876f02006-02-03 15:34:35 -0800812 u32 reserved_1[2]; /*0038h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400813
Sumant Patrof9876f02006-02-03 15:34:35 -0800814 u32 inbound_queue_port; /*0040h*/
815 u32 outbound_queue_port; /*0044h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400816
adam radford9c915a82010-12-21 13:34:31 -0800817 u32 reserved_2[9]; /*0048h*/
818 u32 reply_post_host_index; /*006Ch*/
819 u32 reserved_2_2[12]; /*0070h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400820
Sumant Patrof9876f02006-02-03 15:34:35 -0800821 u32 outbound_doorbell_clear; /*00A0h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400822
Sumant Patrof9876f02006-02-03 15:34:35 -0800823 u32 reserved_3[3]; /*00A4h*/
824
825 u32 outbound_scratch_pad ; /*00B0h*/
adam radford9c915a82010-12-21 13:34:31 -0800826 u32 outbound_scratch_pad_2; /*00B4h*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800827
adam radford9c915a82010-12-21 13:34:31 -0800828 u32 reserved_4[2]; /*00B8h*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800829
830 u32 inbound_low_queue_port ; /*00C0h*/
831
832 u32 inbound_high_queue_port ; /*00C4h*/
833
834 u32 reserved_5; /*00C8h*/
bo yang39a98552010-09-22 22:36:29 -0400835 u32 res_6[11]; /*CCh*/
836 u32 host_diag;
837 u32 seq_offset;
838 u32 index_registers[807]; /*00CCh*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400839} __attribute__ ((packed));
840
841struct megasas_sge32 {
842
843 u32 phys_addr;
844 u32 length;
845
846} __attribute__ ((packed));
847
848struct megasas_sge64 {
849
850 u64 phys_addr;
851 u32 length;
852
853} __attribute__ ((packed));
854
Yang, Bof4c9a132009-10-06 14:43:28 -0600855struct megasas_sge_skinny {
856 u64 phys_addr;
857 u32 length;
858 u32 flag;
859} __packed;
860
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400861union megasas_sgl {
862
863 struct megasas_sge32 sge32[1];
864 struct megasas_sge64 sge64[1];
Yang, Bof4c9a132009-10-06 14:43:28 -0600865 struct megasas_sge_skinny sge_skinny[1];
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400866
867} __attribute__ ((packed));
868
869struct megasas_header {
870
871 u8 cmd; /*00h */
872 u8 sense_len; /*01h */
873 u8 cmd_status; /*02h */
874 u8 scsi_status; /*03h */
875
876 u8 target_id; /*04h */
877 u8 lun; /*05h */
878 u8 cdb_len; /*06h */
879 u8 sge_count; /*07h */
880
881 u32 context; /*08h */
882 u32 pad_0; /*0Ch */
883
884 u16 flags; /*10h */
885 u16 timeout; /*12h */
886 u32 data_xferlen; /*14h */
887
888} __attribute__ ((packed));
889
890union megasas_sgl_frame {
891
892 struct megasas_sge32 sge32[8];
893 struct megasas_sge64 sge64[5];
894
895} __attribute__ ((packed));
896
897struct megasas_init_frame {
898
899 u8 cmd; /*00h */
900 u8 reserved_0; /*01h */
901 u8 cmd_status; /*02h */
902
903 u8 reserved_1; /*03h */
904 u32 reserved_2; /*04h */
905
906 u32 context; /*08h */
907 u32 pad_0; /*0Ch */
908
909 u16 flags; /*10h */
910 u16 reserved_3; /*12h */
911 u32 data_xfer_len; /*14h */
912
913 u32 queue_info_new_phys_addr_lo; /*18h */
914 u32 queue_info_new_phys_addr_hi; /*1Ch */
915 u32 queue_info_old_phys_addr_lo; /*20h */
916 u32 queue_info_old_phys_addr_hi; /*24h */
917
918 u32 reserved_4[6]; /*28h */
919
920} __attribute__ ((packed));
921
922struct megasas_init_queue_info {
923
924 u32 init_flags; /*00h */
925 u32 reply_queue_entries; /*04h */
926
927 u32 reply_queue_start_phys_addr_lo; /*08h */
928 u32 reply_queue_start_phys_addr_hi; /*0Ch */
929 u32 producer_index_phys_addr_lo; /*10h */
930 u32 producer_index_phys_addr_hi; /*14h */
931 u32 consumer_index_phys_addr_lo; /*18h */
932 u32 consumer_index_phys_addr_hi; /*1Ch */
933
934} __attribute__ ((packed));
935
936struct megasas_io_frame {
937
938 u8 cmd; /*00h */
939 u8 sense_len; /*01h */
940 u8 cmd_status; /*02h */
941 u8 scsi_status; /*03h */
942
943 u8 target_id; /*04h */
944 u8 access_byte; /*05h */
945 u8 reserved_0; /*06h */
946 u8 sge_count; /*07h */
947
948 u32 context; /*08h */
949 u32 pad_0; /*0Ch */
950
951 u16 flags; /*10h */
952 u16 timeout; /*12h */
953 u32 lba_count; /*14h */
954
955 u32 sense_buf_phys_addr_lo; /*18h */
956 u32 sense_buf_phys_addr_hi; /*1Ch */
957
958 u32 start_lba_lo; /*20h */
959 u32 start_lba_hi; /*24h */
960
961 union megasas_sgl sgl; /*28h */
962
963} __attribute__ ((packed));
964
965struct megasas_pthru_frame {
966
967 u8 cmd; /*00h */
968 u8 sense_len; /*01h */
969 u8 cmd_status; /*02h */
970 u8 scsi_status; /*03h */
971
972 u8 target_id; /*04h */
973 u8 lun; /*05h */
974 u8 cdb_len; /*06h */
975 u8 sge_count; /*07h */
976
977 u32 context; /*08h */
978 u32 pad_0; /*0Ch */
979
980 u16 flags; /*10h */
981 u16 timeout; /*12h */
982 u32 data_xfer_len; /*14h */
983
984 u32 sense_buf_phys_addr_lo; /*18h */
985 u32 sense_buf_phys_addr_hi; /*1Ch */
986
987 u8 cdb[16]; /*20h */
988 union megasas_sgl sgl; /*30h */
989
990} __attribute__ ((packed));
991
992struct megasas_dcmd_frame {
993
994 u8 cmd; /*00h */
995 u8 reserved_0; /*01h */
996 u8 cmd_status; /*02h */
997 u8 reserved_1[4]; /*03h */
998 u8 sge_count; /*07h */
999
1000 u32 context; /*08h */
1001 u32 pad_0; /*0Ch */
1002
1003 u16 flags; /*10h */
1004 u16 timeout; /*12h */
1005
1006 u32 data_xfer_len; /*14h */
1007 u32 opcode; /*18h */
1008
1009 union { /*1Ch */
1010 u8 b[12];
1011 u16 s[6];
1012 u32 w[3];
1013 } mbox;
1014
1015 union megasas_sgl sgl; /*28h */
1016
1017} __attribute__ ((packed));
1018
1019struct megasas_abort_frame {
1020
1021 u8 cmd; /*00h */
1022 u8 reserved_0; /*01h */
1023 u8 cmd_status; /*02h */
1024
1025 u8 reserved_1; /*03h */
1026 u32 reserved_2; /*04h */
1027
1028 u32 context; /*08h */
1029 u32 pad_0; /*0Ch */
1030
1031 u16 flags; /*10h */
1032 u16 reserved_3; /*12h */
1033 u32 reserved_4; /*14h */
1034
1035 u32 abort_context; /*18h */
1036 u32 pad_1; /*1Ch */
1037
1038 u32 abort_mfi_phys_addr_lo; /*20h */
1039 u32 abort_mfi_phys_addr_hi; /*24h */
1040
1041 u32 reserved_5[6]; /*28h */
1042
1043} __attribute__ ((packed));
1044
1045struct megasas_smp_frame {
1046
1047 u8 cmd; /*00h */
1048 u8 reserved_1; /*01h */
1049 u8 cmd_status; /*02h */
1050 u8 connection_status; /*03h */
1051
1052 u8 reserved_2[3]; /*04h */
1053 u8 sge_count; /*07h */
1054
1055 u32 context; /*08h */
1056 u32 pad_0; /*0Ch */
1057
1058 u16 flags; /*10h */
1059 u16 timeout; /*12h */
1060
1061 u32 data_xfer_len; /*14h */
1062 u64 sas_addr; /*18h */
1063
1064 union {
1065 struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */
1066 struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */
1067 } sgl;
1068
1069} __attribute__ ((packed));
1070
1071struct megasas_stp_frame {
1072
1073 u8 cmd; /*00h */
1074 u8 reserved_1; /*01h */
1075 u8 cmd_status; /*02h */
1076 u8 reserved_2; /*03h */
1077
1078 u8 target_id; /*04h */
1079 u8 reserved_3[2]; /*05h */
1080 u8 sge_count; /*07h */
1081
1082 u32 context; /*08h */
1083 u32 pad_0; /*0Ch */
1084
1085 u16 flags; /*10h */
1086 u16 timeout; /*12h */
1087
1088 u32 data_xfer_len; /*14h */
1089
1090 u16 fis[10]; /*18h */
1091 u32 stp_flags;
1092
1093 union {
1094 struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */
1095 struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */
1096 } sgl;
1097
1098} __attribute__ ((packed));
1099
1100union megasas_frame {
1101
1102 struct megasas_header hdr;
1103 struct megasas_init_frame init;
1104 struct megasas_io_frame io;
1105 struct megasas_pthru_frame pthru;
1106 struct megasas_dcmd_frame dcmd;
1107 struct megasas_abort_frame abort;
1108 struct megasas_smp_frame smp;
1109 struct megasas_stp_frame stp;
1110
1111 u8 raw_bytes[64];
1112};
1113
1114struct megasas_cmd;
1115
1116union megasas_evt_class_locale {
1117
1118 struct {
1119 u16 locale;
1120 u8 reserved;
1121 s8 class;
1122 } __attribute__ ((packed)) members;
1123
1124 u32 word;
1125
1126} __attribute__ ((packed));
1127
1128struct megasas_evt_log_info {
1129 u32 newest_seq_num;
1130 u32 oldest_seq_num;
1131 u32 clear_seq_num;
1132 u32 shutdown_seq_num;
1133 u32 boot_seq_num;
1134
1135} __attribute__ ((packed));
1136
1137struct megasas_progress {
1138
1139 u16 progress;
1140 u16 elapsed_seconds;
1141
1142} __attribute__ ((packed));
1143
1144struct megasas_evtarg_ld {
1145
1146 u16 target_id;
1147 u8 ld_index;
1148 u8 reserved;
1149
1150} __attribute__ ((packed));
1151
1152struct megasas_evtarg_pd {
1153 u16 device_id;
1154 u8 encl_index;
1155 u8 slot_number;
1156
1157} __attribute__ ((packed));
1158
1159struct megasas_evt_detail {
1160
1161 u32 seq_num;
1162 u32 time_stamp;
1163 u32 code;
1164 union megasas_evt_class_locale cl;
1165 u8 arg_type;
1166 u8 reserved1[15];
1167
1168 union {
1169 struct {
1170 struct megasas_evtarg_pd pd;
1171 u8 cdb_length;
1172 u8 sense_length;
1173 u8 reserved[2];
1174 u8 cdb[16];
1175 u8 sense[64];
1176 } __attribute__ ((packed)) cdbSense;
1177
1178 struct megasas_evtarg_ld ld;
1179
1180 struct {
1181 struct megasas_evtarg_ld ld;
1182 u64 count;
1183 } __attribute__ ((packed)) ld_count;
1184
1185 struct {
1186 u64 lba;
1187 struct megasas_evtarg_ld ld;
1188 } __attribute__ ((packed)) ld_lba;
1189
1190 struct {
1191 struct megasas_evtarg_ld ld;
1192 u32 prevOwner;
1193 u32 newOwner;
1194 } __attribute__ ((packed)) ld_owner;
1195
1196 struct {
1197 u64 ld_lba;
1198 u64 pd_lba;
1199 struct megasas_evtarg_ld ld;
1200 struct megasas_evtarg_pd pd;
1201 } __attribute__ ((packed)) ld_lba_pd_lba;
1202
1203 struct {
1204 struct megasas_evtarg_ld ld;
1205 struct megasas_progress prog;
1206 } __attribute__ ((packed)) ld_prog;
1207
1208 struct {
1209 struct megasas_evtarg_ld ld;
1210 u32 prev_state;
1211 u32 new_state;
1212 } __attribute__ ((packed)) ld_state;
1213
1214 struct {
1215 u64 strip;
1216 struct megasas_evtarg_ld ld;
1217 } __attribute__ ((packed)) ld_strip;
1218
1219 struct megasas_evtarg_pd pd;
1220
1221 struct {
1222 struct megasas_evtarg_pd pd;
1223 u32 err;
1224 } __attribute__ ((packed)) pd_err;
1225
1226 struct {
1227 u64 lba;
1228 struct megasas_evtarg_pd pd;
1229 } __attribute__ ((packed)) pd_lba;
1230
1231 struct {
1232 u64 lba;
1233 struct megasas_evtarg_pd pd;
1234 struct megasas_evtarg_ld ld;
1235 } __attribute__ ((packed)) pd_lba_ld;
1236
1237 struct {
1238 struct megasas_evtarg_pd pd;
1239 struct megasas_progress prog;
1240 } __attribute__ ((packed)) pd_prog;
1241
1242 struct {
1243 struct megasas_evtarg_pd pd;
1244 u32 prevState;
1245 u32 newState;
1246 } __attribute__ ((packed)) pd_state;
1247
1248 struct {
1249 u16 vendorId;
1250 u16 deviceId;
1251 u16 subVendorId;
1252 u16 subDeviceId;
1253 } __attribute__ ((packed)) pci;
1254
1255 u32 rate;
1256 char str[96];
1257
1258 struct {
1259 u32 rtc;
1260 u32 elapsedSeconds;
1261 } __attribute__ ((packed)) time;
1262
1263 struct {
1264 u32 ecar;
1265 u32 elog;
1266 char str[64];
1267 } __attribute__ ((packed)) ecc;
1268
1269 u8 b[96];
1270 u16 s[48];
1271 u32 w[24];
1272 u64 d[12];
1273 } args;
1274
1275 char description[128];
1276
1277} __attribute__ ((packed));
1278
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001279struct megasas_aen_event {
Xiaotian Fengc1d390d82012-12-04 19:33:54 +08001280 struct delayed_work hotplug_work;
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001281 struct megasas_instance *instance;
1282};
1283
adam radfordc8e858f2011-10-08 18:15:13 -07001284struct megasas_irq_context {
1285 struct megasas_instance *instance;
1286 u32 MSIxIndex;
1287};
1288
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001289struct megasas_instance {
1290
1291 u32 *producer;
1292 dma_addr_t producer_h;
1293 u32 *consumer;
1294 dma_addr_t consumer_h;
1295
1296 u32 *reply_queue;
1297 dma_addr_t reply_queue_h;
1298
1299 unsigned long base_addr;
1300 struct megasas_register_set __iomem *reg_set;
1301
Yang, Bo81e403c2009-10-06 14:27:54 -06001302 struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
Yang, Bobdc6fb82009-12-06 08:30:19 -07001303 u8 ld_ids[MEGASAS_MAX_LD_IDS];
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001304 s8 init_id;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001305
1306 u16 max_num_sge;
1307 u16 max_fw_cmds;
adam radford9c915a82010-12-21 13:34:31 -08001308 /* For Fusion its num IOCTL cmds, for others MFI based its
1309 max_fw_cmds */
1310 u16 max_mfi_cmds;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001311 u32 max_sectors_per_req;
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001312 struct megasas_aen_event *ev;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001313
1314 struct megasas_cmd **cmd_list;
1315 struct list_head cmd_pool;
bo yang39a98552010-09-22 22:36:29 -04001316 /* used to sync fire the cmd to fw */
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001317 spinlock_t cmd_pool_lock;
bo yang39a98552010-09-22 22:36:29 -04001318 /* used to sync fire the cmd to fw */
1319 spinlock_t hba_lock;
bo yang7343eb62007-11-09 04:35:44 -05001320 /* used to synch producer, consumer ptrs in dpc */
1321 spinlock_t completion_lock;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001322 struct dma_pool *frame_dma_pool;
1323 struct dma_pool *sense_dma_pool;
1324
1325 struct megasas_evt_detail *evt_detail;
1326 dma_addr_t evt_detail_h;
1327 struct megasas_cmd *aen_cmd;
Matthias Kaehlckee5a69e22007-10-27 09:48:46 +02001328 struct mutex aen_mutex;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001329 struct semaphore ioctl_sem;
1330
1331 struct Scsi_Host *host;
1332
1333 wait_queue_head_t int_cmd_wait_q;
1334 wait_queue_head_t abort_cmd_wait_q;
1335
1336 struct pci_dev *pdev;
1337 u32 unique_id;
bo yang39a98552010-09-22 22:36:29 -04001338 u32 fw_support_ieee;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001339
Sumant Patroe4a082c2006-05-30 12:03:37 -07001340 atomic_t fw_outstanding;
bo yang39a98552010-09-22 22:36:29 -04001341 atomic_t fw_reset_no_pci_access;
Sumant Patro1341c932006-01-25 12:02:40 -08001342
1343 struct megasas_instance_template *instancet;
Sumant Patro5d018ad2006-10-03 13:13:18 -07001344 struct tasklet_struct isr_tasklet;
bo yang39a98552010-09-22 22:36:29 -04001345 struct work_struct work_init;
Sumant Patro05e9ebb2007-05-17 05:47:51 -07001346
1347 u8 flag;
Yang, Boc3518832009-10-06 14:18:02 -06001348 u8 unload;
Yang, Bof4c9a132009-10-06 14:43:28 -06001349 u8 flag_ieee;
bo yang39a98552010-09-22 22:36:29 -04001350 u8 issuepend_done;
1351 u8 disableOnlineCtrlReset;
1352 u8 adprecovery;
Sumant Patro05e9ebb2007-05-17 05:47:51 -07001353 unsigned long last_time;
bo yang39a98552010-09-22 22:36:29 -04001354 u32 mfiStatus;
1355 u32 last_seq_num;
bo yangad84db22007-11-09 04:40:16 -05001356
bo yang39a98552010-09-22 22:36:29 -04001357 struct list_head internal_reset_pending_q;
adam radford80d9da92010-12-21 10:17:40 -08001358
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001359 /* Ptr to hba specific information */
adam radford9c915a82010-12-21 13:34:31 -08001360 void *ctrl_context;
adam radfordc8e858f2011-10-08 18:15:13 -07001361 unsigned int msix_vectors;
1362 struct msix_entry msixentry[MEGASAS_MAX_MSIX_QUEUES];
1363 struct megasas_irq_context irq_context[MEGASAS_MAX_MSIX_QUEUES];
adam radford9c915a82010-12-21 13:34:31 -08001364 u64 map_id;
1365 struct megasas_cmd *map_update_cmd;
adam radfordb6d5d882010-12-14 18:56:07 -08001366 unsigned long bar;
adam radford9c915a82010-12-21 13:34:31 -08001367 long reset_flags;
1368 struct mutex reset_mutex;
adam radfordc5daa6a2012-07-17 18:20:03 -07001369 int throttlequeuedepth;
bo yang39a98552010-09-22 22:36:29 -04001370};
1371
1372enum {
1373 MEGASAS_HBA_OPERATIONAL = 0,
1374 MEGASAS_ADPRESET_SM_INFAULT = 1,
1375 MEGASAS_ADPRESET_SM_FW_RESET_SUCCESS = 2,
1376 MEGASAS_ADPRESET_SM_OPERATIONAL = 3,
1377 MEGASAS_HW_CRITICAL_ERROR = 4,
1378 MEGASAS_ADPRESET_INPROG_SIGN = 0xDEADDEAD,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001379};
1380
Yang, Bo0c79e682009-10-06 14:47:35 -06001381struct megasas_instance_template {
1382 void (*fire_cmd)(struct megasas_instance *, dma_addr_t, \
1383 u32, struct megasas_register_set __iomem *);
1384
1385 void (*enable_intr)(struct megasas_register_set __iomem *) ;
1386 void (*disable_intr)(struct megasas_register_set __iomem *);
1387
1388 int (*clear_intr)(struct megasas_register_set __iomem *);
1389
1390 u32 (*read_fw_status_reg)(struct megasas_register_set __iomem *);
bo yang39a98552010-09-22 22:36:29 -04001391 int (*adp_reset)(struct megasas_instance *, \
1392 struct megasas_register_set __iomem *);
1393 int (*check_reset)(struct megasas_instance *, \
1394 struct megasas_register_set __iomem *);
adam radfordcd50ba82010-12-21 10:23:23 -08001395 irqreturn_t (*service_isr)(int irq, void *devp);
1396 void (*tasklet)(unsigned long);
1397 u32 (*init_adapter)(struct megasas_instance *);
1398 u32 (*build_and_issue_cmd) (struct megasas_instance *,
1399 struct scsi_cmnd *);
1400 void (*issue_dcmd) (struct megasas_instance *instance,
1401 struct megasas_cmd *cmd);
Yang, Bo0c79e682009-10-06 14:47:35 -06001402};
1403
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001404#define MEGASAS_IS_LOGICAL(scp) \
1405 (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1
1406
1407#define MEGASAS_DEV_INDEX(inst, scp) \
1408 ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
1409 scp->device->id
1410
1411struct megasas_cmd {
1412
1413 union megasas_frame *frame;
1414 dma_addr_t frame_phys_addr;
1415 u8 *sense;
1416 dma_addr_t sense_phys_addr;
1417
1418 u32 index;
1419 u8 sync_cmd;
1420 u8 cmd_status;
bo yang39a98552010-09-22 22:36:29 -04001421 u8 abort_aen;
1422 u8 retry_for_fw_reset;
1423
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001424
1425 struct list_head list;
1426 struct scsi_cmnd *scmd;
1427 struct megasas_instance *instance;
adam radford9c915a82010-12-21 13:34:31 -08001428 union {
1429 struct {
1430 u16 smid;
1431 u16 resvd;
1432 } context;
1433 u32 frame_count;
1434 };
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001435};
1436
1437#define MAX_MGMT_ADAPTERS 1024
1438#define MAX_IOCTL_SGE 16
1439
1440struct megasas_iocpacket {
1441
1442 u16 host_no;
1443 u16 __pad1;
1444 u32 sgl_off;
1445 u32 sge_count;
1446 u32 sense_off;
1447 u32 sense_len;
1448 union {
1449 u8 raw[128];
1450 struct megasas_header hdr;
1451 } frame;
1452
1453 struct iovec sgl[MAX_IOCTL_SGE];
1454
1455} __attribute__ ((packed));
1456
1457struct megasas_aen {
1458 u16 host_no;
1459 u16 __pad1;
1460 u32 seq_num;
1461 u32 class_locale_word;
1462} __attribute__ ((packed));
1463
1464#ifdef CONFIG_COMPAT
1465struct compat_megasas_iocpacket {
1466 u16 host_no;
1467 u16 __pad1;
1468 u32 sgl_off;
1469 u32 sge_count;
1470 u32 sense_off;
1471 u32 sense_len;
1472 union {
1473 u8 raw[128];
1474 struct megasas_header hdr;
1475 } frame;
1476 struct compat_iovec sgl[MAX_IOCTL_SGE];
1477} __attribute__ ((packed));
1478
Sumant Patro0e989362006-06-20 15:32:37 -07001479#define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001480#endif
1481
Sumant Patrocb59aa62006-01-25 11:53:25 -08001482#define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001483#define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
1484
1485struct megasas_mgmt_info {
1486
1487 u16 count;
1488 struct megasas_instance *instance[MAX_MGMT_ADAPTERS];
1489 int max_index;
1490};
1491
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001492#endif /*LSI_MEGARAID_SAS_H */