blob: 9504b519e12166ac158e7904f5942f04ec79ccb2 [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/*
Sumit.Saxena@lsi.com39b72c32013-05-22 12:32:43 +053055 * Intel HBA SSDIDs
56 */
57#define MEGARAID_INTEL_RS3DC080_SSDID 0x9360
58#define MEGARAID_INTEL_RS3DC040_SSDID 0x9362
59#define MEGARAID_INTEL_RS3SC008_SSDID 0x9380
60#define MEGARAID_INTEL_RS3MC044_SSDID 0x9381
61#define MEGARAID_INTEL_RS3WC080_SSDID 0x9341
62#define MEGARAID_INTEL_RS3WC040_SSDID 0x9343
63
64/*
65 * Intel HBA branding
66 */
67#define MEGARAID_INTEL_RS3DC080_BRANDING \
68 "Intel(R) RAID Controller RS3DC080"
69#define MEGARAID_INTEL_RS3DC040_BRANDING \
70 "Intel(R) RAID Controller RS3DC040"
71#define MEGARAID_INTEL_RS3SC008_BRANDING \
72 "Intel(R) RAID Controller RS3SC008"
73#define MEGARAID_INTEL_RS3MC044_BRANDING \
74 "Intel(R) RAID Controller RS3MC044"
75#define MEGARAID_INTEL_RS3WC080_BRANDING \
76 "Intel(R) RAID Controller RS3WC080"
77#define MEGARAID_INTEL_RS3WC040_BRANDING \
78 "Intel(R) RAID Controller RS3WC040"
79
80/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040081 * =====================================
82 * MegaRAID SAS MFI firmware definitions
83 * =====================================
84 */
85
86/*
87 * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
88 * protocol between the software and firmware. Commands are issued using
89 * "message frames"
90 */
91
Randy Dunlapa69b74d2007-01-05 22:41:48 -080092/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -040093 * FW posts its state in upper 4 bits of outbound_msg_0 register
94 */
95#define MFI_STATE_MASK 0xF0000000
96#define MFI_STATE_UNDEFINED 0x00000000
97#define MFI_STATE_BB_INIT 0x10000000
98#define MFI_STATE_FW_INIT 0x40000000
99#define MFI_STATE_WAIT_HANDSHAKE 0x60000000
100#define MFI_STATE_FW_INIT_2 0x70000000
101#define MFI_STATE_DEVICE_SCAN 0x80000000
Sumant Patroe3bbff92006-10-03 12:28:49 -0700102#define MFI_STATE_BOOT_MESSAGE_PENDING 0x90000000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400103#define MFI_STATE_FLUSH_CACHE 0xA0000000
104#define MFI_STATE_READY 0xB0000000
105#define MFI_STATE_OPERATIONAL 0xC0000000
106#define MFI_STATE_FAULT 0xF0000000
adam radford7e70e732011-05-11 18:34:08 -0700107#define MFI_RESET_REQUIRED 0x00000001
108#define MFI_RESET_ADAPTER 0x00000002
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400109#define MEGAMFI_FRAME_SIZE 64
110
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800111/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400112 * During FW init, clear pending cmds & reset state using inbound_msg_0
113 *
114 * ABORT : Abort all pending cmds
115 * READY : Move from OPERATIONAL to READY state; discard queue info
116 * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??)
117 * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver
Sumant Patroe3bbff92006-10-03 12:28:49 -0700118 * HOTPLUG : Resume from Hotplug
119 * MFI_STOP_ADP : Send signal to FW to stop processing
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400120 */
bo yang39a98552010-09-22 22:36:29 -0400121#define WRITE_SEQUENCE_OFFSET (0x0000000FC) /* I20 */
122#define HOST_DIAGNOSTIC_OFFSET (0x000000F8) /* I20 */
123#define DIAG_WRITE_ENABLE (0x00000080)
124#define DIAG_RESET_ADAPTER (0x00000004)
125
126#define MFI_ADP_RESET 0x00000040
Sumant Patroe3bbff92006-10-03 12:28:49 -0700127#define MFI_INIT_ABORT 0x00000001
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400128#define MFI_INIT_READY 0x00000002
129#define MFI_INIT_MFIMODE 0x00000004
130#define MFI_INIT_CLEAR_HANDSHAKE 0x00000008
Sumant Patroe3bbff92006-10-03 12:28:49 -0700131#define MFI_INIT_HOTPLUG 0x00000010
132#define MFI_STOP_ADP 0x00000020
133#define MFI_RESET_FLAGS MFI_INIT_READY| \
134 MFI_INIT_MFIMODE| \
135 MFI_INIT_ABORT
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400136
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800137/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400138 * MFI frame flags
139 */
140#define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000
141#define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001
142#define MFI_FRAME_SGL32 0x0000
143#define MFI_FRAME_SGL64 0x0002
144#define MFI_FRAME_SENSE32 0x0000
145#define MFI_FRAME_SENSE64 0x0004
146#define MFI_FRAME_DIR_NONE 0x0000
147#define MFI_FRAME_DIR_WRITE 0x0008
148#define MFI_FRAME_DIR_READ 0x0010
149#define MFI_FRAME_DIR_BOTH 0x0018
Yang, Bof4c9a132009-10-06 14:43:28 -0600150#define MFI_FRAME_IEEE 0x0020
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400151
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800152/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400153 * Definition for cmd_status
154 */
155#define MFI_CMD_STATUS_POLL_MODE 0xFF
156
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800157/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400158 * MFI command opcodes
159 */
160#define MFI_CMD_INIT 0x00
161#define MFI_CMD_LD_READ 0x01
162#define MFI_CMD_LD_WRITE 0x02
163#define MFI_CMD_LD_SCSI_IO 0x03
164#define MFI_CMD_PD_SCSI_IO 0x04
165#define MFI_CMD_DCMD 0x05
166#define MFI_CMD_ABORT 0x06
167#define MFI_CMD_SMP 0x07
168#define MFI_CMD_STP 0x08
adam radforde5f93a32011-10-08 18:15:19 -0700169#define MFI_CMD_INVALID 0xff
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400170
171#define MR_DCMD_CTRL_GET_INFO 0x01010000
Yang, Bobdc6fb82009-12-06 08:30:19 -0700172#define MR_DCMD_LD_GET_LIST 0x03010000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400173
174#define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000
175#define MR_FLUSH_CTRL_CACHE 0x01
176#define MR_FLUSH_DISK_CACHE 0x02
177
178#define MR_DCMD_CTRL_SHUTDOWN 0x01050000
bo yang31ea7082007-11-07 12:09:50 -0500179#define MR_DCMD_HIBERNATE_SHUTDOWN 0x01060000
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400180#define MR_ENABLE_DRIVE_SPINDOWN 0x01
181
182#define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100
183#define MR_DCMD_CTRL_EVENT_GET 0x01040300
184#define MR_DCMD_CTRL_EVENT_WAIT 0x01040500
185#define MR_DCMD_LD_GET_PROPERTIES 0x03030000
186
187#define MR_DCMD_CLUSTER 0x08000000
188#define MR_DCMD_CLUSTER_RESET_ALL 0x08010100
189#define MR_DCMD_CLUSTER_RESET_LD 0x08010200
Yang, Bo81e403c2009-10-06 14:27:54 -0600190#define MR_DCMD_PD_LIST_QUERY 0x02010100
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400191
Randy Dunlapa69b74d2007-01-05 22:41:48 -0800192/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400193 * MFI command completion codes
194 */
195enum MFI_STAT {
196 MFI_STAT_OK = 0x00,
197 MFI_STAT_INVALID_CMD = 0x01,
198 MFI_STAT_INVALID_DCMD = 0x02,
199 MFI_STAT_INVALID_PARAMETER = 0x03,
200 MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04,
201 MFI_STAT_ABORT_NOT_POSSIBLE = 0x05,
202 MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06,
203 MFI_STAT_APP_IN_USE = 0x07,
204 MFI_STAT_APP_NOT_INITIALIZED = 0x08,
205 MFI_STAT_ARRAY_INDEX_INVALID = 0x09,
206 MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a,
207 MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b,
208 MFI_STAT_DEVICE_NOT_FOUND = 0x0c,
209 MFI_STAT_DRIVE_TOO_SMALL = 0x0d,
210 MFI_STAT_FLASH_ALLOC_FAIL = 0x0e,
211 MFI_STAT_FLASH_BUSY = 0x0f,
212 MFI_STAT_FLASH_ERROR = 0x10,
213 MFI_STAT_FLASH_IMAGE_BAD = 0x11,
214 MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12,
215 MFI_STAT_FLASH_NOT_OPEN = 0x13,
216 MFI_STAT_FLASH_NOT_STARTED = 0x14,
217 MFI_STAT_FLUSH_FAILED = 0x15,
218 MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16,
219 MFI_STAT_LD_CC_IN_PROGRESS = 0x17,
220 MFI_STAT_LD_INIT_IN_PROGRESS = 0x18,
221 MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19,
222 MFI_STAT_LD_MAX_CONFIGURED = 0x1a,
223 MFI_STAT_LD_NOT_OPTIMAL = 0x1b,
224 MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c,
225 MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d,
226 MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e,
227 MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f,
228 MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20,
229 MFI_STAT_MFC_HW_ERROR = 0x21,
230 MFI_STAT_NO_HW_PRESENT = 0x22,
231 MFI_STAT_NOT_FOUND = 0x23,
232 MFI_STAT_NOT_IN_ENCL = 0x24,
233 MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25,
234 MFI_STAT_PD_TYPE_WRONG = 0x26,
235 MFI_STAT_PR_DISABLED = 0x27,
236 MFI_STAT_ROW_INDEX_INVALID = 0x28,
237 MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29,
238 MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a,
239 MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b,
240 MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c,
241 MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d,
242 MFI_STAT_SCSI_IO_FAILED = 0x2e,
243 MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f,
244 MFI_STAT_SHUTDOWN_FAILED = 0x30,
245 MFI_STAT_TIME_NOT_SET = 0x31,
246 MFI_STAT_WRONG_STATE = 0x32,
247 MFI_STAT_LD_OFFLINE = 0x33,
248 MFI_STAT_PEER_NOTIFICATION_REJECTED = 0x34,
249 MFI_STAT_PEER_NOTIFICATION_FAILED = 0x35,
250 MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
251 MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
252 MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
adam radford36807e62011-10-08 18:15:06 -0700253 MFI_STAT_CONFIG_SEQ_MISMATCH = 0x67,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400254
255 MFI_STAT_INVALID_STATUS = 0xFF
256};
257
258/*
259 * Number of mailbox bytes in DCMD message frame
260 */
261#define MFI_MBOX_SIZE 12
262
263enum MR_EVT_CLASS {
264
265 MR_EVT_CLASS_DEBUG = -2,
266 MR_EVT_CLASS_PROGRESS = -1,
267 MR_EVT_CLASS_INFO = 0,
268 MR_EVT_CLASS_WARNING = 1,
269 MR_EVT_CLASS_CRITICAL = 2,
270 MR_EVT_CLASS_FATAL = 3,
271 MR_EVT_CLASS_DEAD = 4,
272
273};
274
275enum MR_EVT_LOCALE {
276
277 MR_EVT_LOCALE_LD = 0x0001,
278 MR_EVT_LOCALE_PD = 0x0002,
279 MR_EVT_LOCALE_ENCL = 0x0004,
280 MR_EVT_LOCALE_BBU = 0x0008,
281 MR_EVT_LOCALE_SAS = 0x0010,
282 MR_EVT_LOCALE_CTRL = 0x0020,
283 MR_EVT_LOCALE_CONFIG = 0x0040,
284 MR_EVT_LOCALE_CLUSTER = 0x0080,
285 MR_EVT_LOCALE_ALL = 0xffff,
286
287};
288
289enum MR_EVT_ARGS {
290
291 MR_EVT_ARGS_NONE,
292 MR_EVT_ARGS_CDB_SENSE,
293 MR_EVT_ARGS_LD,
294 MR_EVT_ARGS_LD_COUNT,
295 MR_EVT_ARGS_LD_LBA,
296 MR_EVT_ARGS_LD_OWNER,
297 MR_EVT_ARGS_LD_LBA_PD_LBA,
298 MR_EVT_ARGS_LD_PROG,
299 MR_EVT_ARGS_LD_STATE,
300 MR_EVT_ARGS_LD_STRIP,
301 MR_EVT_ARGS_PD,
302 MR_EVT_ARGS_PD_ERR,
303 MR_EVT_ARGS_PD_LBA,
304 MR_EVT_ARGS_PD_LBA_LD,
305 MR_EVT_ARGS_PD_PROG,
306 MR_EVT_ARGS_PD_STATE,
307 MR_EVT_ARGS_PCI,
308 MR_EVT_ARGS_RATE,
309 MR_EVT_ARGS_STR,
310 MR_EVT_ARGS_TIME,
311 MR_EVT_ARGS_ECC,
Yang, Bo81e403c2009-10-06 14:27:54 -0600312 MR_EVT_ARGS_LD_PROP,
313 MR_EVT_ARGS_PD_SPARE,
314 MR_EVT_ARGS_PD_INDEX,
315 MR_EVT_ARGS_DIAG_PASS,
316 MR_EVT_ARGS_DIAG_FAIL,
317 MR_EVT_ARGS_PD_LBA_LBA,
318 MR_EVT_ARGS_PORT_PHY,
319 MR_EVT_ARGS_PD_MISSING,
320 MR_EVT_ARGS_PD_ADDRESS,
321 MR_EVT_ARGS_BITMAP,
322 MR_EVT_ARGS_CONNECTOR,
323 MR_EVT_ARGS_PD_PD,
324 MR_EVT_ARGS_PD_FRU,
325 MR_EVT_ARGS_PD_PATHINFO,
326 MR_EVT_ARGS_PD_POWER_STATE,
327 MR_EVT_ARGS_GENERIC,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400328};
329
330/*
Yang, Bo81e403c2009-10-06 14:27:54 -0600331 * define constants for device list query options
332 */
333enum MR_PD_QUERY_TYPE {
334 MR_PD_QUERY_TYPE_ALL = 0,
335 MR_PD_QUERY_TYPE_STATE = 1,
336 MR_PD_QUERY_TYPE_POWER_STATE = 2,
337 MR_PD_QUERY_TYPE_MEDIA_TYPE = 3,
338 MR_PD_QUERY_TYPE_SPEED = 4,
339 MR_PD_QUERY_TYPE_EXPOSED_TO_HOST = 5,
340};
341
Yang, Bo7e8a75f2009-10-06 14:50:17 -0600342#define MR_EVT_CFG_CLEARED 0x0004
343#define MR_EVT_LD_STATE_CHANGE 0x0051
344#define MR_EVT_PD_INSERTED 0x005b
345#define MR_EVT_PD_REMOVED 0x0070
346#define MR_EVT_LD_CREATED 0x008a
347#define MR_EVT_LD_DELETED 0x008b
348#define MR_EVT_FOREIGN_CFG_IMPORTED 0x00db
349#define MR_EVT_LD_OFFLINE 0x00fc
350#define MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED 0x0152
351#define MAX_LOGICAL_DRIVES 64
352
Yang, Bo81e403c2009-10-06 14:27:54 -0600353enum MR_PD_STATE {
354 MR_PD_STATE_UNCONFIGURED_GOOD = 0x00,
355 MR_PD_STATE_UNCONFIGURED_BAD = 0x01,
356 MR_PD_STATE_HOT_SPARE = 0x02,
357 MR_PD_STATE_OFFLINE = 0x10,
358 MR_PD_STATE_FAILED = 0x11,
359 MR_PD_STATE_REBUILD = 0x14,
360 MR_PD_STATE_ONLINE = 0x18,
361 MR_PD_STATE_COPYBACK = 0x20,
362 MR_PD_STATE_SYSTEM = 0x40,
363 };
364
365
366 /*
367 * defines the physical drive address structure
368 */
369struct MR_PD_ADDRESS {
370 u16 deviceId;
371 u16 enclDeviceId;
372
373 union {
374 struct {
375 u8 enclIndex;
376 u8 slotNumber;
377 } mrPdAddress;
378 struct {
379 u8 enclPosition;
380 u8 enclConnectorIndex;
381 } mrEnclAddress;
382 };
383 u8 scsiDevType;
384 union {
385 u8 connectedPortBitmap;
386 u8 connectedPortNumbers;
387 };
388 u64 sasAddr[2];
389} __packed;
390
391/*
392 * defines the physical drive list structure
393 */
394struct MR_PD_LIST {
395 u32 size;
396 u32 count;
397 struct MR_PD_ADDRESS addr[1];
398} __packed;
399
400struct megasas_pd_list {
401 u16 tid;
402 u8 driveType;
403 u8 driveState;
404} __packed;
405
Yang, Bobdc6fb82009-12-06 08:30:19 -0700406 /*
407 * defines the logical drive reference structure
408 */
409union MR_LD_REF {
410 struct {
411 u8 targetId;
412 u8 reserved;
413 u16 seqNum;
414 };
415 u32 ref;
416} __packed;
417
418/*
419 * defines the logical drive list structure
420 */
421struct MR_LD_LIST {
422 u32 ldCount;
423 u32 reserved;
424 struct {
425 union MR_LD_REF ref;
426 u8 state;
427 u8 reserved[3];
428 u64 size;
429 } ldList[MAX_LOGICAL_DRIVES];
430} __packed;
431
Yang, Bo81e403c2009-10-06 14:27:54 -0600432/*
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400433 * SAS controller properties
434 */
435struct megasas_ctrl_prop {
436
437 u16 seq_num;
438 u16 pred_fail_poll_interval;
439 u16 intr_throttle_count;
440 u16 intr_throttle_timeouts;
441 u8 rebuild_rate;
442 u8 patrol_read_rate;
443 u8 bgi_rate;
444 u8 cc_rate;
445 u8 recon_rate;
446 u8 cache_flush_interval;
447 u8 spinup_drv_count;
448 u8 spinup_delay;
449 u8 cluster_enable;
450 u8 coercion_mode;
451 u8 alarm_enable;
452 u8 disable_auto_rebuild;
453 u8 disable_battery_warn;
454 u8 ecc_bucket_size;
455 u16 ecc_bucket_leak_rate;
456 u8 restore_hotspare_on_insertion;
457 u8 expose_encl_devices;
bo yang39a98552010-09-22 22:36:29 -0400458 u8 maintainPdFailHistory;
459 u8 disallowHostRequestReordering;
460 u8 abortCCOnError;
461 u8 loadBalanceMode;
462 u8 disableAutoDetectBackplane;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400463
bo yang39a98552010-09-22 22:36:29 -0400464 u8 snapVDSpace;
465
466 /*
467 * Add properties that can be controlled by
468 * a bit in the following structure.
469 */
bo yang39a98552010-09-22 22:36:29 -0400470 struct {
471 u32 copyBackDisabled : 1;
472 u32 SMARTerEnabled : 1;
473 u32 prCorrectUnconfiguredAreas : 1;
474 u32 useFdeOnly : 1;
475 u32 disableNCQ : 1;
476 u32 SSDSMARTerEnabled : 1;
477 u32 SSDPatrolReadEnabled : 1;
478 u32 enableSpinDownUnconfigured : 1;
479 u32 autoEnhancedImport : 1;
480 u32 enableSecretKeyControl : 1;
481 u32 disableOnlineCtrlReset : 1;
482 u32 allowBootWithPinnedCache : 1;
483 u32 disableSpinDownHS : 1;
484 u32 enableJBOD : 1;
485 u32 reserved :18;
486 } OnOffProperties;
487 u8 autoSnapVDSpace;
488 u8 viewSpace;
489 u16 spinDownTime;
490 u8 reserved[24];
Yang, Bo81e403c2009-10-06 14:27:54 -0600491} __packed;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400492
493/*
494 * SAS controller information
495 */
496struct megasas_ctrl_info {
497
498 /*
499 * PCI device information
500 */
501 struct {
502
503 u16 vendor_id;
504 u16 device_id;
505 u16 sub_vendor_id;
506 u16 sub_device_id;
507 u8 reserved[24];
508
509 } __attribute__ ((packed)) pci;
510
511 /*
512 * Host interface information
513 */
514 struct {
515
516 u8 PCIX:1;
517 u8 PCIE:1;
518 u8 iSCSI:1;
519 u8 SAS_3G:1;
520 u8 reserved_0:4;
521 u8 reserved_1[6];
522 u8 port_count;
523 u64 port_addr[8];
524
525 } __attribute__ ((packed)) host_interface;
526
527 /*
528 * Device (backend) interface information
529 */
530 struct {
531
532 u8 SPI:1;
533 u8 SAS_3G:1;
534 u8 SATA_1_5G:1;
535 u8 SATA_3G:1;
536 u8 reserved_0:4;
537 u8 reserved_1[6];
538 u8 port_count;
539 u64 port_addr[8];
540
541 } __attribute__ ((packed)) device_interface;
542
543 /*
544 * List of components residing in flash. All str are null terminated
545 */
546 u32 image_check_word;
547 u32 image_component_count;
548
549 struct {
550
551 char name[8];
552 char version[32];
553 char build_date[16];
554 char built_time[16];
555
556 } __attribute__ ((packed)) image_component[8];
557
558 /*
559 * List of flash components that have been flashed on the card, but
560 * are not in use, pending reset of the adapter. This list will be
561 * empty if a flash operation has not occurred. All stings are null
562 * terminated
563 */
564 u32 pending_image_component_count;
565
566 struct {
567
568 char name[8];
569 char version[32];
570 char build_date[16];
571 char build_time[16];
572
573 } __attribute__ ((packed)) pending_image_component[8];
574
575 u8 max_arms;
576 u8 max_spans;
577 u8 max_arrays;
578 u8 max_lds;
579
580 char product_name[80];
581 char serial_no[32];
582
583 /*
584 * Other physical/controller/operation information. Indicates the
585 * presence of the hardware
586 */
587 struct {
588
589 u32 bbu:1;
590 u32 alarm:1;
591 u32 nvram:1;
592 u32 uart:1;
593 u32 reserved:28;
594
595 } __attribute__ ((packed)) hw_present;
596
597 u32 current_fw_time;
598
599 /*
600 * Maximum data transfer sizes
601 */
602 u16 max_concurrent_cmds;
603 u16 max_sge_count;
604 u32 max_request_size;
605
606 /*
607 * Logical and physical device counts
608 */
609 u16 ld_present_count;
610 u16 ld_degraded_count;
611 u16 ld_offline_count;
612
613 u16 pd_present_count;
614 u16 pd_disk_present_count;
615 u16 pd_disk_pred_failure_count;
616 u16 pd_disk_failed_count;
617
618 /*
619 * Memory size information
620 */
621 u16 nvram_size;
622 u16 memory_size;
623 u16 flash_size;
624
625 /*
626 * Error counters
627 */
628 u16 mem_correctable_error_count;
629 u16 mem_uncorrectable_error_count;
630
631 /*
632 * Cluster information
633 */
634 u8 cluster_permitted;
635 u8 cluster_active;
636
637 /*
638 * Additional max data transfer sizes
639 */
640 u16 max_strips_per_io;
641
642 /*
643 * Controller capabilities structures
644 */
645 struct {
646
647 u32 raid_level_0:1;
648 u32 raid_level_1:1;
649 u32 raid_level_5:1;
650 u32 raid_level_1E:1;
651 u32 raid_level_6:1;
652 u32 reserved:27;
653
654 } __attribute__ ((packed)) raid_levels;
655
656 struct {
657
658 u32 rbld_rate:1;
659 u32 cc_rate:1;
660 u32 bgi_rate:1;
661 u32 recon_rate:1;
662 u32 patrol_rate:1;
663 u32 alarm_control:1;
664 u32 cluster_supported:1;
665 u32 bbu:1;
666 u32 spanning_allowed:1;
667 u32 dedicated_hotspares:1;
668 u32 revertible_hotspares:1;
669 u32 foreign_config_import:1;
670 u32 self_diagnostic:1;
671 u32 mixed_redundancy_arr:1;
672 u32 global_hot_spares:1;
673 u32 reserved:17;
674
675 } __attribute__ ((packed)) adapter_operations;
676
677 struct {
678
679 u32 read_policy:1;
680 u32 write_policy:1;
681 u32 io_policy:1;
682 u32 access_policy:1;
683 u32 disk_cache_policy:1;
684 u32 reserved:27;
685
686 } __attribute__ ((packed)) ld_operations;
687
688 struct {
689
690 u8 min;
691 u8 max;
692 u8 reserved[2];
693
694 } __attribute__ ((packed)) stripe_sz_ops;
695
696 struct {
697
698 u32 force_online:1;
699 u32 force_offline:1;
700 u32 force_rebuild:1;
701 u32 reserved:29;
702
703 } __attribute__ ((packed)) pd_operations;
704
705 struct {
706
707 u32 ctrl_supports_sas:1;
708 u32 ctrl_supports_sata:1;
709 u32 allow_mix_in_encl:1;
710 u32 allow_mix_in_ld:1;
711 u32 allow_sata_in_cluster:1;
712 u32 reserved:27;
713
714 } __attribute__ ((packed)) pd_mix_support;
715
716 /*
717 * Define ECC single-bit-error bucket information
718 */
719 u8 ecc_bucket_count;
720 u8 reserved_2[11];
721
722 /*
723 * Include the controller properties (changeable items)
724 */
725 struct megasas_ctrl_prop properties;
726
727 /*
728 * Define FW pkg version (set in envt v'bles on OEM basis)
729 */
730 char package_version[0x60];
731
732 u8 pad[0x800 - 0x6a0];
733
Yang, Bo81e403c2009-10-06 14:27:54 -0600734} __packed;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400735
736/*
737 * ===============================
738 * MegaRAID SAS driver definitions
739 * ===============================
740 */
741#define MEGASAS_MAX_PD_CHANNELS 2
742#define MEGASAS_MAX_LD_CHANNELS 2
743#define MEGASAS_MAX_CHANNELS (MEGASAS_MAX_PD_CHANNELS + \
744 MEGASAS_MAX_LD_CHANNELS)
745#define MEGASAS_MAX_DEV_PER_CHANNEL 128
746#define MEGASAS_DEFAULT_INIT_ID -1
747#define MEGASAS_MAX_LUN 8
748#define MEGASAS_MAX_LD 64
adam radford6bf579a2011-10-08 18:14:33 -0700749#define MEGASAS_DEFAULT_CMD_PER_LUN 256
Yang, Bo81e403c2009-10-06 14:27:54 -0600750#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \
751 MEGASAS_MAX_DEV_PER_CHANNEL)
Yang, Bobdc6fb82009-12-06 08:30:19 -0700752#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
753 MEGASAS_MAX_DEV_PER_CHANNEL)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400754
Yang, Bo1fd10682010-10-12 07:18:50 -0600755#define MEGASAS_MAX_SECTORS (2*1024)
adam radford42a8d2b2011-02-24 20:57:09 -0800756#define MEGASAS_MAX_SECTORS_IEEE (2*128)
Sumant Patro658dced2006-10-03 13:09:14 -0700757#define MEGASAS_DBG_LVL 1
758
Sumant Patro05e9ebb2007-05-17 05:47:51 -0700759#define MEGASAS_FW_BUSY 1
760
bo yangd532dbe2008-03-17 03:36:43 -0400761/* Frame Type */
762#define IO_FRAME 0
763#define PTHRU_FRAME 1
764
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400765/*
766 * When SCSI mid-layer calls driver's reset routine, driver waits for
767 * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
768 * that the driver cannot _actually_ abort or reset pending commands. While
769 * it is waiting for the commands to complete, it prints a diagnostic message
770 * every MEGASAS_RESET_NOTICE_INTERVAL seconds
771 */
772#define MEGASAS_RESET_WAIT_TIME 180
Sumant Patro2a3681e2006-10-03 13:19:21 -0700773#define MEGASAS_INTERNAL_CMD_WAIT_TIME 180
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400774#define MEGASAS_RESET_NOTICE_INTERVAL 5
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400775#define MEGASAS_IOCTL_CMD 0
Sumant Patro05e9ebb2007-05-17 05:47:51 -0700776#define MEGASAS_DEFAULT_CMD_TIMEOUT 90
adam radfordc5daa6a2012-07-17 18:20:03 -0700777#define MEGASAS_THROTTLE_QUEUE_DEPTH 16
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400778
779/*
780 * FW reports the maximum of number of commands that it can accept (maximum
781 * commands that can be outstanding) at any time. The driver must report a
782 * lower number to the mid layer because it can issue a few internal commands
783 * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs
784 * is shown below
785 */
786#define MEGASAS_INT_CMDS 32
Yang, Bo7bebf5c2009-10-06 14:40:58 -0600787#define MEGASAS_SKINNY_INT_CMDS 5
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400788
adam radfordc8e858f2011-10-08 18:15:13 -0700789#define MEGASAS_MAX_MSIX_QUEUES 16
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400790/*
791 * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
792 * SGLs based on the size of dma_addr_t
793 */
794#define IS_DMA64 (sizeof(dma_addr_t) == 8)
795
bo yang39a98552010-09-22 22:36:29 -0400796#define MFI_XSCALE_OMR0_CHANGE_INTERRUPT 0x00000001
797
798#define MFI_INTR_FLAG_REPLY_MESSAGE 0x00000001
799#define MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE 0x00000002
800#define MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT 0x00000004
801
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400802#define MFI_OB_INTR_STATUS_MASK 0x00000002
bo yang14faea92007-11-09 04:14:00 -0500803#define MFI_POLL_TIMEOUT_SECS 60
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400804
Sumant Patrof9876f02006-02-03 15:34:35 -0800805#define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
Yang, Bo6610a6b2008-08-10 12:42:38 -0700806#define MFI_REPLY_GEN2_MESSAGE_INTERRUPT 0x00000001
807#define MFI_GEN2_ENABLE_INTERRUPT_MASK (0x00000001 | 0x00000004)
Yang, Bo87911122009-10-06 14:31:54 -0600808#define MFI_REPLY_SKINNY_MESSAGE_INTERRUPT 0x40000000
809#define MFI_SKINNY_ENABLE_INTERRUPT_MASK (0x00000001)
Sumant Patro0e989362006-06-20 15:32:37 -0700810
bo yang39a98552010-09-22 22:36:29 -0400811#define MFI_1068_PCSR_OFFSET 0x84
812#define MFI_1068_FW_HANDSHAKE_OFFSET 0x64
813#define MFI_1068_FW_READY 0xDDDD0000
Sumant Patro0e989362006-06-20 15:32:37 -0700814/*
815* register set for both 1068 and 1078 controllers
816* structure extended for 1078 registers
817*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800818
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400819struct megasas_register_set {
adam radford9c915a82010-12-21 13:34:31 -0800820 u32 doorbell; /*0000h*/
821 u32 fusion_seq_offset; /*0004h*/
822 u32 fusion_host_diag; /*0008h*/
823 u32 reserved_01; /*000Ch*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400824
Sumant Patrof9876f02006-02-03 15:34:35 -0800825 u32 inbound_msg_0; /*0010h*/
826 u32 inbound_msg_1; /*0014h*/
827 u32 outbound_msg_0; /*0018h*/
828 u32 outbound_msg_1; /*001Ch*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400829
Sumant Patrof9876f02006-02-03 15:34:35 -0800830 u32 inbound_doorbell; /*0020h*/
831 u32 inbound_intr_status; /*0024h*/
832 u32 inbound_intr_mask; /*0028h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400833
Sumant Patrof9876f02006-02-03 15:34:35 -0800834 u32 outbound_doorbell; /*002Ch*/
835 u32 outbound_intr_status; /*0030h*/
836 u32 outbound_intr_mask; /*0034h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400837
Sumant Patrof9876f02006-02-03 15:34:35 -0800838 u32 reserved_1[2]; /*0038h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400839
Sumant Patrof9876f02006-02-03 15:34:35 -0800840 u32 inbound_queue_port; /*0040h*/
841 u32 outbound_queue_port; /*0044h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400842
adam radford9c915a82010-12-21 13:34:31 -0800843 u32 reserved_2[9]; /*0048h*/
844 u32 reply_post_host_index; /*006Ch*/
845 u32 reserved_2_2[12]; /*0070h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400846
Sumant Patrof9876f02006-02-03 15:34:35 -0800847 u32 outbound_doorbell_clear; /*00A0h*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400848
Sumant Patrof9876f02006-02-03 15:34:35 -0800849 u32 reserved_3[3]; /*00A4h*/
850
851 u32 outbound_scratch_pad ; /*00B0h*/
adam radford9c915a82010-12-21 13:34:31 -0800852 u32 outbound_scratch_pad_2; /*00B4h*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800853
adam radford9c915a82010-12-21 13:34:31 -0800854 u32 reserved_4[2]; /*00B8h*/
Sumant Patrof9876f02006-02-03 15:34:35 -0800855
856 u32 inbound_low_queue_port ; /*00C0h*/
857
858 u32 inbound_high_queue_port ; /*00C4h*/
859
860 u32 reserved_5; /*00C8h*/
bo yang39a98552010-09-22 22:36:29 -0400861 u32 res_6[11]; /*CCh*/
862 u32 host_diag;
863 u32 seq_offset;
864 u32 index_registers[807]; /*00CCh*/
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400865} __attribute__ ((packed));
866
867struct megasas_sge32 {
868
869 u32 phys_addr;
870 u32 length;
871
872} __attribute__ ((packed));
873
874struct megasas_sge64 {
875
876 u64 phys_addr;
877 u32 length;
878
879} __attribute__ ((packed));
880
Yang, Bof4c9a132009-10-06 14:43:28 -0600881struct megasas_sge_skinny {
882 u64 phys_addr;
883 u32 length;
884 u32 flag;
885} __packed;
886
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400887union megasas_sgl {
888
889 struct megasas_sge32 sge32[1];
890 struct megasas_sge64 sge64[1];
Yang, Bof4c9a132009-10-06 14:43:28 -0600891 struct megasas_sge_skinny sge_skinny[1];
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -0400892
893} __attribute__ ((packed));
894
895struct megasas_header {
896
897 u8 cmd; /*00h */
898 u8 sense_len; /*01h */
899 u8 cmd_status; /*02h */
900 u8 scsi_status; /*03h */
901
902 u8 target_id; /*04h */
903 u8 lun; /*05h */
904 u8 cdb_len; /*06h */
905 u8 sge_count; /*07h */
906
907 u32 context; /*08h */
908 u32 pad_0; /*0Ch */
909
910 u16 flags; /*10h */
911 u16 timeout; /*12h */
912 u32 data_xferlen; /*14h */
913
914} __attribute__ ((packed));
915
916union megasas_sgl_frame {
917
918 struct megasas_sge32 sge32[8];
919 struct megasas_sge64 sge64[5];
920
921} __attribute__ ((packed));
922
923struct megasas_init_frame {
924
925 u8 cmd; /*00h */
926 u8 reserved_0; /*01h */
927 u8 cmd_status; /*02h */
928
929 u8 reserved_1; /*03h */
930 u32 reserved_2; /*04h */
931
932 u32 context; /*08h */
933 u32 pad_0; /*0Ch */
934
935 u16 flags; /*10h */
936 u16 reserved_3; /*12h */
937 u32 data_xfer_len; /*14h */
938
939 u32 queue_info_new_phys_addr_lo; /*18h */
940 u32 queue_info_new_phys_addr_hi; /*1Ch */
941 u32 queue_info_old_phys_addr_lo; /*20h */
942 u32 queue_info_old_phys_addr_hi; /*24h */
943
944 u32 reserved_4[6]; /*28h */
945
946} __attribute__ ((packed));
947
948struct megasas_init_queue_info {
949
950 u32 init_flags; /*00h */
951 u32 reply_queue_entries; /*04h */
952
953 u32 reply_queue_start_phys_addr_lo; /*08h */
954 u32 reply_queue_start_phys_addr_hi; /*0Ch */
955 u32 producer_index_phys_addr_lo; /*10h */
956 u32 producer_index_phys_addr_hi; /*14h */
957 u32 consumer_index_phys_addr_lo; /*18h */
958 u32 consumer_index_phys_addr_hi; /*1Ch */
959
960} __attribute__ ((packed));
961
962struct megasas_io_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 access_byte; /*05h */
971 u8 reserved_0; /*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 lba_count; /*14h */
980
981 u32 sense_buf_phys_addr_lo; /*18h */
982 u32 sense_buf_phys_addr_hi; /*1Ch */
983
984 u32 start_lba_lo; /*20h */
985 u32 start_lba_hi; /*24h */
986
987 union megasas_sgl sgl; /*28h */
988
989} __attribute__ ((packed));
990
991struct megasas_pthru_frame {
992
993 u8 cmd; /*00h */
994 u8 sense_len; /*01h */
995 u8 cmd_status; /*02h */
996 u8 scsi_status; /*03h */
997
998 u8 target_id; /*04h */
999 u8 lun; /*05h */
1000 u8 cdb_len; /*06h */
1001 u8 sge_count; /*07h */
1002
1003 u32 context; /*08h */
1004 u32 pad_0; /*0Ch */
1005
1006 u16 flags; /*10h */
1007 u16 timeout; /*12h */
1008 u32 data_xfer_len; /*14h */
1009
1010 u32 sense_buf_phys_addr_lo; /*18h */
1011 u32 sense_buf_phys_addr_hi; /*1Ch */
1012
1013 u8 cdb[16]; /*20h */
1014 union megasas_sgl sgl; /*30h */
1015
1016} __attribute__ ((packed));
1017
1018struct megasas_dcmd_frame {
1019
1020 u8 cmd; /*00h */
1021 u8 reserved_0; /*01h */
1022 u8 cmd_status; /*02h */
1023 u8 reserved_1[4]; /*03h */
1024 u8 sge_count; /*07h */
1025
1026 u32 context; /*08h */
1027 u32 pad_0; /*0Ch */
1028
1029 u16 flags; /*10h */
1030 u16 timeout; /*12h */
1031
1032 u32 data_xfer_len; /*14h */
1033 u32 opcode; /*18h */
1034
1035 union { /*1Ch */
1036 u8 b[12];
1037 u16 s[6];
1038 u32 w[3];
1039 } mbox;
1040
1041 union megasas_sgl sgl; /*28h */
1042
1043} __attribute__ ((packed));
1044
1045struct megasas_abort_frame {
1046
1047 u8 cmd; /*00h */
1048 u8 reserved_0; /*01h */
1049 u8 cmd_status; /*02h */
1050
1051 u8 reserved_1; /*03h */
1052 u32 reserved_2; /*04h */
1053
1054 u32 context; /*08h */
1055 u32 pad_0; /*0Ch */
1056
1057 u16 flags; /*10h */
1058 u16 reserved_3; /*12h */
1059 u32 reserved_4; /*14h */
1060
1061 u32 abort_context; /*18h */
1062 u32 pad_1; /*1Ch */
1063
1064 u32 abort_mfi_phys_addr_lo; /*20h */
1065 u32 abort_mfi_phys_addr_hi; /*24h */
1066
1067 u32 reserved_5[6]; /*28h */
1068
1069} __attribute__ ((packed));
1070
1071struct megasas_smp_frame {
1072
1073 u8 cmd; /*00h */
1074 u8 reserved_1; /*01h */
1075 u8 cmd_status; /*02h */
1076 u8 connection_status; /*03h */
1077
1078 u8 reserved_2[3]; /*04h */
1079 u8 sge_count; /*07h */
1080
1081 u32 context; /*08h */
1082 u32 pad_0; /*0Ch */
1083
1084 u16 flags; /*10h */
1085 u16 timeout; /*12h */
1086
1087 u32 data_xfer_len; /*14h */
1088 u64 sas_addr; /*18h */
1089
1090 union {
1091 struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */
1092 struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */
1093 } sgl;
1094
1095} __attribute__ ((packed));
1096
1097struct megasas_stp_frame {
1098
1099 u8 cmd; /*00h */
1100 u8 reserved_1; /*01h */
1101 u8 cmd_status; /*02h */
1102 u8 reserved_2; /*03h */
1103
1104 u8 target_id; /*04h */
1105 u8 reserved_3[2]; /*05h */
1106 u8 sge_count; /*07h */
1107
1108 u32 context; /*08h */
1109 u32 pad_0; /*0Ch */
1110
1111 u16 flags; /*10h */
1112 u16 timeout; /*12h */
1113
1114 u32 data_xfer_len; /*14h */
1115
1116 u16 fis[10]; /*18h */
1117 u32 stp_flags;
1118
1119 union {
1120 struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */
1121 struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */
1122 } sgl;
1123
1124} __attribute__ ((packed));
1125
1126union megasas_frame {
1127
1128 struct megasas_header hdr;
1129 struct megasas_init_frame init;
1130 struct megasas_io_frame io;
1131 struct megasas_pthru_frame pthru;
1132 struct megasas_dcmd_frame dcmd;
1133 struct megasas_abort_frame abort;
1134 struct megasas_smp_frame smp;
1135 struct megasas_stp_frame stp;
1136
1137 u8 raw_bytes[64];
1138};
1139
1140struct megasas_cmd;
1141
1142union megasas_evt_class_locale {
1143
1144 struct {
1145 u16 locale;
1146 u8 reserved;
1147 s8 class;
1148 } __attribute__ ((packed)) members;
1149
1150 u32 word;
1151
1152} __attribute__ ((packed));
1153
1154struct megasas_evt_log_info {
1155 u32 newest_seq_num;
1156 u32 oldest_seq_num;
1157 u32 clear_seq_num;
1158 u32 shutdown_seq_num;
1159 u32 boot_seq_num;
1160
1161} __attribute__ ((packed));
1162
1163struct megasas_progress {
1164
1165 u16 progress;
1166 u16 elapsed_seconds;
1167
1168} __attribute__ ((packed));
1169
1170struct megasas_evtarg_ld {
1171
1172 u16 target_id;
1173 u8 ld_index;
1174 u8 reserved;
1175
1176} __attribute__ ((packed));
1177
1178struct megasas_evtarg_pd {
1179 u16 device_id;
1180 u8 encl_index;
1181 u8 slot_number;
1182
1183} __attribute__ ((packed));
1184
1185struct megasas_evt_detail {
1186
1187 u32 seq_num;
1188 u32 time_stamp;
1189 u32 code;
1190 union megasas_evt_class_locale cl;
1191 u8 arg_type;
1192 u8 reserved1[15];
1193
1194 union {
1195 struct {
1196 struct megasas_evtarg_pd pd;
1197 u8 cdb_length;
1198 u8 sense_length;
1199 u8 reserved[2];
1200 u8 cdb[16];
1201 u8 sense[64];
1202 } __attribute__ ((packed)) cdbSense;
1203
1204 struct megasas_evtarg_ld ld;
1205
1206 struct {
1207 struct megasas_evtarg_ld ld;
1208 u64 count;
1209 } __attribute__ ((packed)) ld_count;
1210
1211 struct {
1212 u64 lba;
1213 struct megasas_evtarg_ld ld;
1214 } __attribute__ ((packed)) ld_lba;
1215
1216 struct {
1217 struct megasas_evtarg_ld ld;
1218 u32 prevOwner;
1219 u32 newOwner;
1220 } __attribute__ ((packed)) ld_owner;
1221
1222 struct {
1223 u64 ld_lba;
1224 u64 pd_lba;
1225 struct megasas_evtarg_ld ld;
1226 struct megasas_evtarg_pd pd;
1227 } __attribute__ ((packed)) ld_lba_pd_lba;
1228
1229 struct {
1230 struct megasas_evtarg_ld ld;
1231 struct megasas_progress prog;
1232 } __attribute__ ((packed)) ld_prog;
1233
1234 struct {
1235 struct megasas_evtarg_ld ld;
1236 u32 prev_state;
1237 u32 new_state;
1238 } __attribute__ ((packed)) ld_state;
1239
1240 struct {
1241 u64 strip;
1242 struct megasas_evtarg_ld ld;
1243 } __attribute__ ((packed)) ld_strip;
1244
1245 struct megasas_evtarg_pd pd;
1246
1247 struct {
1248 struct megasas_evtarg_pd pd;
1249 u32 err;
1250 } __attribute__ ((packed)) pd_err;
1251
1252 struct {
1253 u64 lba;
1254 struct megasas_evtarg_pd pd;
1255 } __attribute__ ((packed)) pd_lba;
1256
1257 struct {
1258 u64 lba;
1259 struct megasas_evtarg_pd pd;
1260 struct megasas_evtarg_ld ld;
1261 } __attribute__ ((packed)) pd_lba_ld;
1262
1263 struct {
1264 struct megasas_evtarg_pd pd;
1265 struct megasas_progress prog;
1266 } __attribute__ ((packed)) pd_prog;
1267
1268 struct {
1269 struct megasas_evtarg_pd pd;
1270 u32 prevState;
1271 u32 newState;
1272 } __attribute__ ((packed)) pd_state;
1273
1274 struct {
1275 u16 vendorId;
1276 u16 deviceId;
1277 u16 subVendorId;
1278 u16 subDeviceId;
1279 } __attribute__ ((packed)) pci;
1280
1281 u32 rate;
1282 char str[96];
1283
1284 struct {
1285 u32 rtc;
1286 u32 elapsedSeconds;
1287 } __attribute__ ((packed)) time;
1288
1289 struct {
1290 u32 ecar;
1291 u32 elog;
1292 char str[64];
1293 } __attribute__ ((packed)) ecc;
1294
1295 u8 b[96];
1296 u16 s[48];
1297 u32 w[24];
1298 u64 d[12];
1299 } args;
1300
1301 char description[128];
1302
1303} __attribute__ ((packed));
1304
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001305struct megasas_aen_event {
Xiaotian Fengc1d390d82012-12-04 19:33:54 +08001306 struct delayed_work hotplug_work;
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001307 struct megasas_instance *instance;
1308};
1309
adam radfordc8e858f2011-10-08 18:15:13 -07001310struct megasas_irq_context {
1311 struct megasas_instance *instance;
1312 u32 MSIxIndex;
1313};
1314
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001315struct megasas_instance {
1316
1317 u32 *producer;
1318 dma_addr_t producer_h;
1319 u32 *consumer;
1320 dma_addr_t consumer_h;
1321
1322 u32 *reply_queue;
1323 dma_addr_t reply_queue_h;
1324
1325 unsigned long base_addr;
1326 struct megasas_register_set __iomem *reg_set;
1327
Yang, Bo81e403c2009-10-06 14:27:54 -06001328 struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
Yang, Bobdc6fb82009-12-06 08:30:19 -07001329 u8 ld_ids[MEGASAS_MAX_LD_IDS];
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001330 s8 init_id;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001331
1332 u16 max_num_sge;
1333 u16 max_fw_cmds;
adam radford9c915a82010-12-21 13:34:31 -08001334 /* For Fusion its num IOCTL cmds, for others MFI based its
1335 max_fw_cmds */
1336 u16 max_mfi_cmds;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001337 u32 max_sectors_per_req;
Yang, Bo7e8a75f2009-10-06 14:50:17 -06001338 struct megasas_aen_event *ev;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001339
1340 struct megasas_cmd **cmd_list;
1341 struct list_head cmd_pool;
bo yang39a98552010-09-22 22:36:29 -04001342 /* used to sync fire the cmd to fw */
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001343 spinlock_t cmd_pool_lock;
bo yang39a98552010-09-22 22:36:29 -04001344 /* used to sync fire the cmd to fw */
1345 spinlock_t hba_lock;
bo yang7343eb62007-11-09 04:35:44 -05001346 /* used to synch producer, consumer ptrs in dpc */
1347 spinlock_t completion_lock;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001348 struct dma_pool *frame_dma_pool;
1349 struct dma_pool *sense_dma_pool;
1350
1351 struct megasas_evt_detail *evt_detail;
1352 dma_addr_t evt_detail_h;
1353 struct megasas_cmd *aen_cmd;
Matthias Kaehlckee5a69e22007-10-27 09:48:46 +02001354 struct mutex aen_mutex;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001355 struct semaphore ioctl_sem;
1356
1357 struct Scsi_Host *host;
1358
1359 wait_queue_head_t int_cmd_wait_q;
1360 wait_queue_head_t abort_cmd_wait_q;
1361
1362 struct pci_dev *pdev;
1363 u32 unique_id;
bo yang39a98552010-09-22 22:36:29 -04001364 u32 fw_support_ieee;
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001365
Sumant Patroe4a082c2006-05-30 12:03:37 -07001366 atomic_t fw_outstanding;
bo yang39a98552010-09-22 22:36:29 -04001367 atomic_t fw_reset_no_pci_access;
Sumant Patro1341c932006-01-25 12:02:40 -08001368
1369 struct megasas_instance_template *instancet;
Sumant Patro5d018ad2006-10-03 13:13:18 -07001370 struct tasklet_struct isr_tasklet;
bo yang39a98552010-09-22 22:36:29 -04001371 struct work_struct work_init;
Sumant Patro05e9ebb2007-05-17 05:47:51 -07001372
1373 u8 flag;
Yang, Boc3518832009-10-06 14:18:02 -06001374 u8 unload;
Yang, Bof4c9a132009-10-06 14:43:28 -06001375 u8 flag_ieee;
bo yang39a98552010-09-22 22:36:29 -04001376 u8 issuepend_done;
1377 u8 disableOnlineCtrlReset;
1378 u8 adprecovery;
Sumant Patro05e9ebb2007-05-17 05:47:51 -07001379 unsigned long last_time;
bo yang39a98552010-09-22 22:36:29 -04001380 u32 mfiStatus;
1381 u32 last_seq_num;
bo yangad84db22007-11-09 04:40:16 -05001382
bo yang39a98552010-09-22 22:36:29 -04001383 struct list_head internal_reset_pending_q;
adam radford80d9da92010-12-21 10:17:40 -08001384
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001385 /* Ptr to hba specific information */
adam radford9c915a82010-12-21 13:34:31 -08001386 void *ctrl_context;
adam radfordc8e858f2011-10-08 18:15:13 -07001387 unsigned int msix_vectors;
1388 struct msix_entry msixentry[MEGASAS_MAX_MSIX_QUEUES];
1389 struct megasas_irq_context irq_context[MEGASAS_MAX_MSIX_QUEUES];
adam radford9c915a82010-12-21 13:34:31 -08001390 u64 map_id;
1391 struct megasas_cmd *map_update_cmd;
adam radfordb6d5d882010-12-14 18:56:07 -08001392 unsigned long bar;
adam radford9c915a82010-12-21 13:34:31 -08001393 long reset_flags;
1394 struct mutex reset_mutex;
adam radfordc5daa6a2012-07-17 18:20:03 -07001395 int throttlequeuedepth;
bo yang39a98552010-09-22 22:36:29 -04001396};
1397
1398enum {
1399 MEGASAS_HBA_OPERATIONAL = 0,
1400 MEGASAS_ADPRESET_SM_INFAULT = 1,
1401 MEGASAS_ADPRESET_SM_FW_RESET_SUCCESS = 2,
1402 MEGASAS_ADPRESET_SM_OPERATIONAL = 3,
1403 MEGASAS_HW_CRITICAL_ERROR = 4,
1404 MEGASAS_ADPRESET_INPROG_SIGN = 0xDEADDEAD,
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001405};
1406
Yang, Bo0c79e682009-10-06 14:47:35 -06001407struct megasas_instance_template {
1408 void (*fire_cmd)(struct megasas_instance *, dma_addr_t, \
1409 u32, struct megasas_register_set __iomem *);
1410
1411 void (*enable_intr)(struct megasas_register_set __iomem *) ;
1412 void (*disable_intr)(struct megasas_register_set __iomem *);
1413
1414 int (*clear_intr)(struct megasas_register_set __iomem *);
1415
1416 u32 (*read_fw_status_reg)(struct megasas_register_set __iomem *);
bo yang39a98552010-09-22 22:36:29 -04001417 int (*adp_reset)(struct megasas_instance *, \
1418 struct megasas_register_set __iomem *);
1419 int (*check_reset)(struct megasas_instance *, \
1420 struct megasas_register_set __iomem *);
adam radfordcd50ba82010-12-21 10:23:23 -08001421 irqreturn_t (*service_isr)(int irq, void *devp);
1422 void (*tasklet)(unsigned long);
1423 u32 (*init_adapter)(struct megasas_instance *);
1424 u32 (*build_and_issue_cmd) (struct megasas_instance *,
1425 struct scsi_cmnd *);
1426 void (*issue_dcmd) (struct megasas_instance *instance,
1427 struct megasas_cmd *cmd);
Yang, Bo0c79e682009-10-06 14:47:35 -06001428};
1429
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001430#define MEGASAS_IS_LOGICAL(scp) \
1431 (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1
1432
1433#define MEGASAS_DEV_INDEX(inst, scp) \
1434 ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
1435 scp->device->id
1436
1437struct megasas_cmd {
1438
1439 union megasas_frame *frame;
1440 dma_addr_t frame_phys_addr;
1441 u8 *sense;
1442 dma_addr_t sense_phys_addr;
1443
1444 u32 index;
1445 u8 sync_cmd;
1446 u8 cmd_status;
bo yang39a98552010-09-22 22:36:29 -04001447 u8 abort_aen;
1448 u8 retry_for_fw_reset;
1449
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001450
1451 struct list_head list;
1452 struct scsi_cmnd *scmd;
1453 struct megasas_instance *instance;
adam radford9c915a82010-12-21 13:34:31 -08001454 union {
1455 struct {
1456 u16 smid;
1457 u16 resvd;
1458 } context;
1459 u32 frame_count;
1460 };
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001461};
1462
1463#define MAX_MGMT_ADAPTERS 1024
1464#define MAX_IOCTL_SGE 16
1465
1466struct megasas_iocpacket {
1467
1468 u16 host_no;
1469 u16 __pad1;
1470 u32 sgl_off;
1471 u32 sge_count;
1472 u32 sense_off;
1473 u32 sense_len;
1474 union {
1475 u8 raw[128];
1476 struct megasas_header hdr;
1477 } frame;
1478
1479 struct iovec sgl[MAX_IOCTL_SGE];
1480
1481} __attribute__ ((packed));
1482
1483struct megasas_aen {
1484 u16 host_no;
1485 u16 __pad1;
1486 u32 seq_num;
1487 u32 class_locale_word;
1488} __attribute__ ((packed));
1489
1490#ifdef CONFIG_COMPAT
1491struct compat_megasas_iocpacket {
1492 u16 host_no;
1493 u16 __pad1;
1494 u32 sgl_off;
1495 u32 sge_count;
1496 u32 sense_off;
1497 u32 sense_len;
1498 union {
1499 u8 raw[128];
1500 struct megasas_header hdr;
1501 } frame;
1502 struct compat_iovec sgl[MAX_IOCTL_SGE];
1503} __attribute__ ((packed));
1504
Sumant Patro0e989362006-06-20 15:32:37 -07001505#define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001506#endif
1507
Sumant Patrocb59aa62006-01-25 11:53:25 -08001508#define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001509#define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
1510
1511struct megasas_mgmt_info {
1512
1513 u16 count;
1514 struct megasas_instance *instance[MAX_MGMT_ADAPTERS];
1515 int max_index;
1516};
1517
Bagalkote, Sreenivasc4a3e0a2005-09-20 17:46:58 -04001518#endif /*LSI_MEGARAID_SAS_H */