[SCSI] mpt2sas: Return DID_TRANSPORT_DISRUPTED in nexus loss,SCSI_MLQUEUE_DEVICE_BUSY...
[linux-block.git] / drivers / scsi / mpt2sas / mpt2sas_base.h
CommitLineData
635374e7
EM
1/*
2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
4 *
5 * This code is based on drivers/scsi/mpt2sas/mpt2_base.h
19d3ebe3 6 * Copyright (C) 2007-2009 LSI Corporation
635374e7
EM
7 * (mailto:DL-MPTFusionLinux@lsi.com)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * NO WARRANTY
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
29
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
42 * USA.
43 */
44
45#ifndef MPT2SAS_BASE_H_INCLUDED
46#define MPT2SAS_BASE_H_INCLUDED
47
48#include "mpi/mpi2_type.h"
49#include "mpi/mpi2.h"
50#include "mpi/mpi2_ioc.h"
51#include "mpi/mpi2_cnfg.h"
52#include "mpi/mpi2_init.h"
53#include "mpi/mpi2_raid.h"
54#include "mpi/mpi2_tool.h"
55#include "mpi/mpi2_sas.h"
56
57#include <scsi/scsi.h>
58#include <scsi/scsi_cmnd.h>
59#include <scsi/scsi_device.h>
60#include <scsi/scsi_host.h>
61#include <scsi/scsi_tcq.h>
62#include <scsi/scsi_transport_sas.h>
63#include <scsi/scsi_dbg.h>
3c621b3e 64#include <scsi/scsi_eh.h>
635374e7
EM
65
66#include "mpt2sas_debug.h"
67
68/* driver versioning info */
69#define MPT2SAS_DRIVER_NAME "mpt2sas"
70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>"
71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver"
dac3bbd6
KD
72#define MPT2SAS_DRIVER_VERSION "02.100.03.00"
73#define MPT2SAS_MAJOR_VERSION 02
635374e7 74#define MPT2SAS_MINOR_VERSION 100
dac3bbd6 75#define MPT2SAS_BUILD_VERSION 03
3b8b5c9b 76#define MPT2SAS_RELEASE_VERSION 00
635374e7
EM
77
78/*
79 * Set MPT2SAS_SG_DEPTH value based on user input.
80 */
81#ifdef CONFIG_SCSI_MPT2SAS_MAX_SGE
82#if CONFIG_SCSI_MPT2SAS_MAX_SGE < 16
83#define MPT2SAS_SG_DEPTH 16
84#elif CONFIG_SCSI_MPT2SAS_MAX_SGE > 128
85#define MPT2SAS_SG_DEPTH 128
86#else
87#define MPT2SAS_SG_DEPTH CONFIG_SCSI_MPT2SAS_MAX_SGE
88#endif
89#else
90#define MPT2SAS_SG_DEPTH 128 /* MAX_HW_SEGMENTS */
91#endif
92
93
94/*
95 * Generic Defines
96 */
97#define MPT2SAS_SATA_QUEUE_DEPTH 32
98#define MPT2SAS_SAS_QUEUE_DEPTH 254
99#define MPT2SAS_RAID_QUEUE_DEPTH 128
100
101#define MPT_NAME_LENGTH 32 /* generic length of strings */
102#define MPT_STRING_LENGTH 64
103
104#define MPT_MAX_CALLBACKS 16
105
106#define CAN_SLEEP 1
107#define NO_SLEEP 0
108
109#define INTERNAL_CMDS_COUNT 10 /* reserved cmds */
110
111#define MPI2_HIM_MASK 0xFFFFFFFF /* mask every bit*/
112
113#define MPT2SAS_INVALID_DEVICE_HANDLE 0xFFFF
114
115
116/*
117 * reset phases
118 */
119#define MPT2_IOC_PRE_RESET 1 /* prior to host reset */
120#define MPT2_IOC_AFTER_RESET 2 /* just after host reset */
121#define MPT2_IOC_DONE_RESET 3 /* links re-initialized */
cd4e12e8 122#define MPT2_IOC_RUNNING 4 /* shost running */
635374e7
EM
123
124/*
125 * logging format
126 */
127#define MPT2SAS_FMT "%s: "
128#define MPT2SAS_DEBUG_FMT KERN_DEBUG MPT2SAS_FMT
129#define MPT2SAS_INFO_FMT KERN_INFO MPT2SAS_FMT
130#define MPT2SAS_NOTE_FMT KERN_NOTICE MPT2SAS_FMT
131#define MPT2SAS_WARN_FMT KERN_WARNING MPT2SAS_FMT
132#define MPT2SAS_ERR_FMT KERN_ERR MPT2SAS_FMT
133
f0f9cc1f
EM
134/*
135 * Dell HBA branding
136 */
137#define MPT2SAS_DELL_BRANDING_SIZE 32
138
139#define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING "Dell 6Gbps SAS HBA"
140#define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING "Dell PERC H200 Adapter"
141#define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated"
142#define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING "Dell PERC H200 Modular"
143#define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING "Dell PERC H200 Embedded"
144#define MPT2SAS_DELL_PERC_H200_BRANDING "Dell PERC H200"
145#define MPT2SAS_DELL_6GBPS_SAS_BRANDING "Dell 6Gbps SAS"
146
147/*
148 * Dell HBA SSDIDs
149 */
150#define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID 0x1F1C
151#define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID 0x1F1D
152#define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID 0x1F1E
153#define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID 0x1F1F
154#define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID 0x1F20
155#define MPT2SAS_DELL_PERC_H200_SSDID 0x1F21
156#define MPT2SAS_DELL_6GBPS_SAS_SSDID 0x1F22
157
635374e7
EM
158/*
159 * per target private data
160 */
161#define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01
162#define MPT_TARGET_FLAGS_VOLUME 0x02
163#define MPT_TARGET_FLAGS_DELETED 0x04
164
165/**
166 * struct MPT2SAS_TARGET - starget private hostdata
167 * @starget: starget object
168 * @sas_address: target sas address
169 * @handle: device handle
170 * @num_luns: number luns
171 * @flags: MPT_TARGET_FLAGS_XXX flags
172 * @deleted: target flaged for deletion
173 * @tm_busy: target is busy with TM request.
174 */
175struct MPT2SAS_TARGET {
176 struct scsi_target *starget;
177 u64 sas_address;
178 u16 handle;
179 int num_luns;
180 u32 flags;
181 u8 deleted;
182 u8 tm_busy;
183};
184
185/*
186 * per device private data
187 */
188#define MPT_DEVICE_FLAGS_INIT 0x01
189#define MPT_DEVICE_TLR_ON 0x02
190
191/**
192 * struct MPT2SAS_DEVICE - sdev private hostdata
193 * @sas_target: starget private hostdata
194 * @lun: lun number
195 * @flags: MPT_DEVICE_XXX flags
196 * @configured_lun: lun is configured
197 * @block: device is in SDEV_BLOCK state
198 * @tlr_snoop_check: flag used in determining whether to disable TLR
199 */
ed79f128
KD
200
201/* OEM Identifiers */
202#define MFG10_OEM_ID_INVALID (0x00000000)
203#define MFG10_OEM_ID_DELL (0x00000001)
204#define MFG10_OEM_ID_FSC (0x00000002)
205#define MFG10_OEM_ID_SUN (0x00000003)
206#define MFG10_OEM_ID_IBM (0x00000004)
207
208/* GENERIC Flags 0*/
209#define MFG10_GF0_OCE_DISABLED (0x00000001)
210#define MFG10_GF0_R1E_DRIVE_COUNT (0x00000002)
211#define MFG10_GF0_R10_DISPLAY (0x00000004)
212#define MFG10_GF0_SSD_DATA_SCRUB_DISABLE (0x00000008)
213#define MFG10_GF0_SINGLE_DRIVE_R0 (0x00000010)
214
215/* OEM Specific Flags will come from OEM specific header files */
216typedef struct _MPI2_CONFIG_PAGE_MAN_10 {
217 MPI2_CONFIG_PAGE_HEADER Header; /* 00h */
218 U8 OEMIdentifier; /* 04h */
219 U8 Reserved1; /* 05h */
220 U16 Reserved2; /* 08h */
221 U32 Reserved3; /* 0Ch */
222 U32 GenericFlags0; /* 10h */
223 U32 GenericFlags1; /* 14h */
224 U32 Reserved4; /* 18h */
225 U32 OEMSpecificFlags0; /* 1Ch */
226 U32 OEMSpecificFlags1; /* 20h */
227 U32 Reserved5[18]; /* 24h-60h*/
228} MPI2_CONFIG_PAGE_MAN_10,
229 MPI2_POINTER PTR_MPI2_CONFIG_PAGE_MAN_10,
230 Mpi2ManufacturingPage10_t, MPI2_POINTER pMpi2ManufacturingPage10_t;
231
635374e7
EM
232struct MPT2SAS_DEVICE {
233 struct MPT2SAS_TARGET *sas_target;
234 unsigned int lun;
235 u32 flags;
236 u8 configured_lun;
237 u8 block;
238 u8 tlr_snoop_check;
239};
240
241#define MPT2_CMD_NOT_USED 0x8000 /* free */
242#define MPT2_CMD_COMPLETE 0x0001 /* completed */
243#define MPT2_CMD_PENDING 0x0002 /* pending */
244#define MPT2_CMD_REPLY_VALID 0x0004 /* reply is valid */
245#define MPT2_CMD_RESET 0x0008 /* host reset dropped the command */
246
247/**
248 * struct _internal_cmd - internal commands struct
249 * @mutex: mutex
250 * @done: completion
251 * @reply: reply message pointer
252 * @status: MPT2_CMD_XXX status
253 * @smid: system message id
254 */
255struct _internal_cmd {
256 struct mutex mutex;
257 struct completion done;
258 void *reply;
259 u16 status;
260 u16 smid;
261};
262
263/*
264 * SAS Topology Structures
265 */
266
595bb0bd
KD
267#define MPTSAS_STATE_TR_SEND 0x0001
268#define MPTSAS_STATE_TR_COMPLETE 0x0002
269#define MPTSAS_STATE_CNTRL_SEND 0x0004
270#define MPTSAS_STATE_CNTRL_COMPLETE 0x0008
271
272#define MPT2SAS_REQ_SAS_CNTRL 0x0010
273
635374e7
EM
274/**
275 * struct _sas_device - attached device information
276 * @list: sas device list
277 * @starget: starget object
278 * @sas_address: device sas address
279 * @device_name: retrieved from the SAS IDENTIFY frame.
280 * @handle: device handle
c5e039be 281 * @sas_address_parent: sas address of parent expander or sas host
635374e7
EM
282 * @enclosure_handle: enclosure handle
283 * @enclosure_logical_id: enclosure logical identifier
284 * @volume_handle: volume handle (valid when hidden raid member)
285 * @volume_wwid: volume unique identifier
286 * @device_info: bitfield provides detailed info about the device
287 * @id: target id
288 * @channel: target channel
289 * @slot: number number
290 * @hidden_raid_component: set to 1 when this is a raid member
291 * @responding: used in _scsih_sas_device_mark_responding
292 */
293struct _sas_device {
294 struct list_head list;
295 struct scsi_target *starget;
296 u64 sas_address;
297 u64 device_name;
298 u16 handle;
c5e039be 299 u64 sas_address_parent;
635374e7
EM
300 u16 enclosure_handle;
301 u64 enclosure_logical_id;
302 u16 volume_handle;
303 u64 volume_wwid;
304 u32 device_info;
305 int id;
306 int channel;
307 u16 slot;
308 u8 hidden_raid_component;
309 u8 responding;
77e63ed4 310 u16 state;
635374e7
EM
311};
312
313/**
314 * struct _raid_device - raid volume link list
315 * @list: sas device list
316 * @starget: starget object
317 * @sdev: scsi device struct (volumes are single lun)
318 * @wwid: unique identifier for the volume
319 * @handle: device handle
320 * @id: target id
321 * @channel: target channel
322 * @volume_type: the raid level
323 * @device_info: bitfield provides detailed info about the hidden components
324 * @num_pds: number of hidden raid components
325 * @responding: used in _scsih_raid_device_mark_responding
326 */
327struct _raid_device {
328 struct list_head list;
329 struct scsi_target *starget;
330 struct scsi_device *sdev;
331 u64 wwid;
332 u16 handle;
333 int id;
334 int channel;
335 u8 volume_type;
336 u32 device_info;
337 u8 num_pds;
338 u8 responding;
339};
340
341/**
342 * struct _boot_device - boot device info
343 * @is_raid: flag to indicate whether this is volume
344 * @device: holds pointer for either struct _sas_device or
345 * struct _raid_device
346 */
347struct _boot_device {
348 u8 is_raid;
349 void *device;
350};
351
352/**
353 * struct _sas_port - wide/narrow sas port information
354 * @port_list: list of ports belonging to expander
635374e7
EM
355 * @num_phys: number of phys belonging to this port
356 * @remote_identify: attached device identification
357 * @rphy: sas transport rphy object
358 * @port: sas transport wide/narrow port object
359 * @phy_list: _sas_phy list objects belonging to this port
360 */
361struct _sas_port {
362 struct list_head port_list;
635374e7
EM
363 u8 num_phys;
364 struct sas_identify remote_identify;
365 struct sas_rphy *rphy;
366 struct sas_port *port;
367 struct list_head phy_list;
368};
369
370/**
371 * struct _sas_phy - phy information
372 * @port_siblings: list of phys belonging to a port
373 * @identify: phy identification
374 * @remote_identify: attached device identification
375 * @phy: sas transport phy object
376 * @phy_id: unique phy id
377 * @handle: device handle for this phy
378 * @attached_handle: device handle for attached device
379 */
380struct _sas_phy {
381 struct list_head port_siblings;
382 struct sas_identify identify;
383 struct sas_identify remote_identify;
384 struct sas_phy *phy;
385 u8 phy_id;
386 u16 handle;
387 u16 attached_handle;
388};
389
390/**
391 * struct _sas_node - sas_host/expander information
392 * @list: list of expanders
393 * @parent_dev: parent device class
394 * @num_phys: number phys belonging to this sas_host/expander
395 * @sas_address: sas address of this sas_host/expander
396 * @handle: handle for this sas_host/expander
c5e039be 397 * @sas_address_parent: sas address of parent expander or sas host
635374e7
EM
398 * @enclosure_handle: handle for this a member of an enclosure
399 * @device_info: bitwise defining capabilities of this sas_host/expander
400 * @responding: used in _scsih_expander_device_mark_responding
401 * @phy: a list of phys that make up this sas_host/expander
402 * @sas_port_list: list of ports attached to this sas_host/expander
403 */
404struct _sas_node {
405 struct list_head list;
406 struct device *parent_dev;
407 u8 num_phys;
408 u64 sas_address;
409 u16 handle;
c5e039be 410 u64 sas_address_parent;
635374e7
EM
411 u16 enclosure_handle;
412 u64 enclosure_logical_id;
413 u8 responding;
414 struct _sas_phy *phy;
415 struct list_head sas_port_list;
416};
417
418/**
419 * enum reset_type - reset state
420 * @FORCE_BIG_HAMMER: issue diagnostic reset
421 * @SOFT_RESET: issue message_unit_reset, if fails to to big hammer
422 */
423enum reset_type {
424 FORCE_BIG_HAMMER,
425 SOFT_RESET,
426};
427
428/**
429 * struct request_tracker - firmware request tracker
430 * @smid: system message id
431 * @scmd: scsi request pointer
432 * @cb_idx: callback index
433 * @chain_list: list of chains associated to this IO
434 * @tracker_list: list of free request (ioc->free_list)
435 */
436struct request_tracker {
437 u16 smid;
438 struct scsi_cmnd *scmd;
439 u8 cb_idx;
440 struct list_head tracker_list;
441};
442
77e63ed4
KD
443/**
444 * struct _tr_list - target reset list
445 * @handle: device handle
446 * @state: state machine
447 */
448struct _tr_list {
449 struct list_head list;
450 u16 handle;
451 u16 state;
452};
453
635374e7
EM
454typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
455
456/**
457 * struct MPT2SAS_ADAPTER - per adapter struct
458 * @list: ioc_list
459 * @shost: shost object
460 * @id: unique adapter id
461 * @pci_irq: irq number
462 * @name: generic ioc string
463 * @tmp_string: tmp string used for logging
464 * @pdev: pci pdev object
465 * @chip: memory mapped register space
466 * @chip_phys: physical addrss prior to mapping
467 * @pio_chip: I/O mapped register space
468 * @logging_level: see mpt2sas_debug.h
fa7f3167 469 * @fwfault_debug: debuging FW timeouts
635374e7
EM
470 * @ir_firmware: IR firmware present
471 * @bars: bitmask of BAR's that must be configured
472 * @mask_interrupts: ignore interrupt
473 * @fault_reset_work_q_name: fw fault work queue
474 * @fault_reset_work_q: ""
475 * @fault_reset_work: ""
476 * @firmware_event_name: fw event work queue
477 * @firmware_event_thread: ""
478 * @fw_events_off: flag to turn off fw event handling
479 * @fw_event_lock:
480 * @fw_event_list: list of fw events
481 * @aen_event_read_flag: event log was read
482 * @broadcast_aen_busy: broadcast aen waiting to be serviced
155dd4c7 483 * @shost_recovery: host reset in progress
635374e7
EM
484 * @ioc_reset_in_progress_lock:
485 * @ioc_link_reset_in_progress: phy/hard reset in progress
486 * @ignore_loginfos: ignore loginfos during task managment
487 * @remove_host: flag for when driver unloads, to avoid sending dev resets
488 * @wait_for_port_enable_to_complete:
489 * @msix_enable: flag indicating msix is enabled
490 * @msix_vector_count: number msix vectors
491 * @msix_table: virt address to the msix table
492 * @msix_table_backup: backup msix table
493 * @scsi_io_cb_idx: shost generated commands
494 * @tm_cb_idx: task management commands
495 * @transport_cb_idx: transport internal commands
496 * @ctl_cb_idx: clt internal commands
497 * @base_cb_idx: base internal commands
498 * @config_cb_idx: base internal commands
499 * @base_cmds:
500 * @transport_cmds:
501 * @tm_cmds:
502 * @ctl_cmds:
503 * @config_cmds:
504 * @base_add_sg_single: handler for either 32/64 bit sgl's
505 * @event_type: bits indicating which events to log
506 * @event_context: unique id for each logged event
507 * @event_log: event log pointer
508 * @event_masks: events that are masked
509 * @facts: static facts data
510 * @pfacts: static port facts data
511 * @manu_pg0: static manufacturing page 0
ed79f128 512 * @manu_pg10: static manufacturing page 10
635374e7
EM
513 * @bios_pg2: static bios page 2
514 * @bios_pg3: static bios page 3
515 * @ioc_pg8: static ioc page 8
516 * @iounit_pg0: static iounit page 0
517 * @iounit_pg1: static iounit page 1
518 * @sas_hba: sas host object
519 * @sas_expander_list: expander object list
520 * @sas_node_lock:
521 * @sas_device_list: sas device object list
522 * @sas_device_init_list: sas device object list (used only at init time)
523 * @sas_device_lock:
524 * @io_missing_delay: time for IO completed by fw when PDR enabled
525 * @device_missing_delay: time for device missing by fw when PDR enabled
526 * @config_page_sz: config page size
527 * @config_page: reserve memory for config page payload
528 * @config_page_dma:
595bb0bd 529 * @hba_queue_depth: hba request queue depth
635374e7 530 * @sge_size: sg element size for either 32/64 bit
595bb0bd 531 * @scsiio_depth: SCSI_IO queue depth
635374e7
EM
532 * @request_sz: per request frame size
533 * @request: pool of request frames
534 * @request_dma:
535 * @request_dma_sz:
536 * @scsi_lookup: firmware request tracker list
537 * @scsi_lookup_lock:
538 * @free_list: free list of request
539 * @chain: pool of chains
540 * @pending_io_count:
541 * @reset_wq:
542 * @chain_dma:
543 * @max_sges_in_main_message: number sg elements in main message
544 * @max_sges_in_chain_message: number sg elements per chain
545 * @chains_needed_per_io: max chains per io
546 * @chain_offset_value_for_main_message: location 1st sg in main
547 * @chain_depth: total chains allocated
595bb0bd
KD
548 * @hi_priority_smid:
549 * @hi_priority:
550 * @hi_priority_dma:
551 * @hi_priority_depth:
552 * @hpr_lookup:
553 * @hpr_free_list:
554 * @internal_smid:
555 * @internal:
556 * @internal_dma:
557 * @internal_depth:
558 * @internal_lookup:
559 * @internal_free_list:
635374e7
EM
560 * @sense: pool of sense
561 * @sense_dma:
562 * @sense_dma_pool:
563 * @reply_depth: hba reply queue depth:
564 * @reply_sz: per reply frame size:
565 * @reply: pool of replys:
566 * @reply_dma:
567 * @reply_dma_pool:
568 * @reply_free_queue_depth: reply free depth
569 * @reply_free: pool for reply free queue (32 bit addr)
570 * @reply_free_dma:
571 * @reply_free_dma_pool:
572 * @reply_free_host_index: tail index in pool to insert free replys
573 * @reply_post_queue_depth: reply post queue depth
574 * @reply_post_free: pool for reply post (64bit descriptor)
575 * @reply_post_free_dma:
576 * @reply_post_free_dma_pool:
577 * @reply_post_host_index: head index in the pool where FW completes IO
578 */
579struct MPT2SAS_ADAPTER {
580 struct list_head list;
581 struct Scsi_Host *shost;
582 u8 id;
583 u32 pci_irq;
584 char name[MPT_NAME_LENGTH];
585 char tmp_string[MPT_STRING_LENGTH];
586 struct pci_dev *pdev;
587 Mpi2SystemInterfaceRegs_t __iomem *chip;
588 unsigned long chip_phys;
589 unsigned long pio_chip;
590 int logging_level;
fa7f3167 591 int fwfault_debug;
635374e7
EM
592 u8 ir_firmware;
593 int bars;
594 u8 mask_interrupts;
595
596 /* fw fault handler */
597 char fault_reset_work_q_name[20];
598 struct workqueue_struct *fault_reset_work_q;
599 struct delayed_work fault_reset_work;
600
601 /* fw event handler */
602 char firmware_event_name[20];
603 struct workqueue_struct *firmware_event_thread;
604 u8 fw_events_off;
605 spinlock_t fw_event_lock;
606 struct list_head fw_event_list;
607
608 /* misc flags */
609 int aen_event_read_flag;
610 u8 broadcast_aen_busy;
635374e7
EM
611 u8 shost_recovery;
612 spinlock_t ioc_reset_in_progress_lock;
613 u8 ioc_link_reset_in_progress;
614 u8 ignore_loginfos;
615 u8 remove_host;
616 u8 wait_for_port_enable_to_complete;
617
618 u8 msix_enable;
619 u16 msix_vector_count;
620 u32 *msix_table;
621 u32 *msix_table_backup;
622
623 /* internal commands, callback index */
624 u8 scsi_io_cb_idx;
625 u8 tm_cb_idx;
626 u8 transport_cb_idx;
627 u8 ctl_cb_idx;
628 u8 base_cb_idx;
629 u8 config_cb_idx;
77e63ed4
KD
630 u8 tm_tr_cb_idx;
631 u8 tm_sas_control_cb_idx;
635374e7
EM
632 struct _internal_cmd base_cmds;
633 struct _internal_cmd transport_cmds;
634 struct _internal_cmd tm_cmds;
635 struct _internal_cmd ctl_cmds;
636 struct _internal_cmd config_cmds;
637
638 MPT_ADD_SGE base_add_sg_single;
639
640 /* event log */
641 u32 event_type[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
642 u32 event_context;
643 void *event_log;
644 u32 event_masks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
645
646 /* static config pages */
647 Mpi2IOCFactsReply_t facts;
648 Mpi2PortFactsReply_t *pfacts;
649 Mpi2ManufacturingPage0_t manu_pg0;
650 Mpi2BiosPage2_t bios_pg2;
651 Mpi2BiosPage3_t bios_pg3;
652 Mpi2IOCPage8_t ioc_pg8;
653 Mpi2IOUnitPage0_t iounit_pg0;
654 Mpi2IOUnitPage1_t iounit_pg1;
655
656 struct _boot_device req_boot_device;
657 struct _boot_device req_alt_boot_device;
658 struct _boot_device current_boot_device;
659
660 /* sas hba, expander, and device list */
661 struct _sas_node sas_hba;
662 struct list_head sas_expander_list;
663 spinlock_t sas_node_lock;
664 struct list_head sas_device_list;
665 struct list_head sas_device_init_list;
666 spinlock_t sas_device_lock;
667 struct list_head raid_device_list;
668 spinlock_t raid_device_lock;
669 u8 io_missing_delay;
670 u16 device_missing_delay;
671 int sas_id;
672
673 /* config page */
674 u16 config_page_sz;
675 void *config_page;
676 dma_addr_t config_page_dma;
677
595bb0bd
KD
678 /* scsiio request */
679 u16 hba_queue_depth;
635374e7 680 u16 sge_size;
595bb0bd 681 u16 scsiio_depth;
635374e7
EM
682 u16 request_sz;
683 u8 *request;
684 dma_addr_t request_dma;
685 u32 request_dma_sz;
686 struct request_tracker *scsi_lookup;
687 spinlock_t scsi_lookup_lock;
688 struct list_head free_list;
689 int pending_io_count;
690 wait_queue_head_t reset_wq;
691
692 /* chain */
693 u8 *chain;
694 dma_addr_t chain_dma;
695 u16 max_sges_in_main_message;
696 u16 max_sges_in_chain_message;
697 u16 chains_needed_per_io;
698 u16 chain_offset_value_for_main_message;
699 u16 chain_depth;
700
595bb0bd
KD
701 /* hi-priority queue */
702 u16 hi_priority_smid;
703 u8 *hi_priority;
704 dma_addr_t hi_priority_dma;
705 u16 hi_priority_depth;
706 struct request_tracker *hpr_lookup;
707 struct list_head hpr_free_list;
708
709 /* internal queue */
710 u16 internal_smid;
711 u8 *internal;
712 dma_addr_t internal_dma;
713 u16 internal_depth;
714 struct request_tracker *internal_lookup;
715 struct list_head internal_free_list;
716
635374e7
EM
717 /* sense */
718 u8 *sense;
719 dma_addr_t sense_dma;
720 struct dma_pool *sense_dma_pool;
721
722 /* reply */
723 u16 reply_sz;
724 u8 *reply;
725 dma_addr_t reply_dma;
726 struct dma_pool *reply_dma_pool;
727
728 /* reply free queue */
729 u16 reply_free_queue_depth;
730 u32 *reply_free;
731 dma_addr_t reply_free_dma;
732 struct dma_pool *reply_free_dma_pool;
733 u32 reply_free_host_index;
734
735 /* reply post queue */
736 u16 reply_post_queue_depth;
737 Mpi2ReplyDescriptorsUnion_t *reply_post_free;
738 dma_addr_t reply_post_free_dma;
739 struct dma_pool *reply_post_free_dma_pool;
740 u32 reply_post_host_index;
741
77e63ed4
KD
742 struct list_head delayed_tr_list;
743
635374e7
EM
744 /* diag buffer support */
745 u8 *diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT];
746 u32 diag_buffer_sz[MPI2_DIAG_BUF_TYPE_COUNT];
747 dma_addr_t diag_buffer_dma[MPI2_DIAG_BUF_TYPE_COUNT];
748 u8 diag_buffer_status[MPI2_DIAG_BUF_TYPE_COUNT];
749 u32 unique_id[MPI2_DIAG_BUF_TYPE_COUNT];
ed79f128 750 Mpi2ManufacturingPage10_t manu_pg10;
635374e7
EM
751 u32 product_specific[MPI2_DIAG_BUF_TYPE_COUNT][23];
752 u32 diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT];
753};
754
77e63ed4
KD
755typedef u8 (*MPT_CALLBACK)(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
756 u32 reply);
635374e7
EM
757
758
759/* base shared API */
ba33fadf 760extern struct list_head mpt2sas_ioc_list;
e4750c98
KD
761void mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc);
762void mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc);
635374e7
EM
763
764int mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc);
765void mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc);
766int mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc);
767void mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc);
768int mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
769 enum reset_type type);
770
771void *mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid);
772void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid);
773void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr);
77e63ed4
KD
774dma_addr_t mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc,
775 u16 smid);
635374e7 776
595bb0bd
KD
777/* hi-priority queue */
778u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
779u16 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
780 struct scsi_cmnd *scmd);
781
635374e7
EM
782u16 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
783void mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid);
7b936b02 784void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid,
635374e7 785 u16 handle);
7b936b02 786void mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid);
635374e7 787void mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
7b936b02
KD
788 u16 io_index);
789void mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid);
635374e7
EM
790void mpt2sas_base_initialize_callback_handler(void);
791u8 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func);
792void mpt2sas_base_release_callback_handler(u8 cb_idx);
793
77e63ed4 794u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
7b936b02 795 u32 reply);
635374e7
EM
796void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr);
797
798u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked);
799
800void mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code);
801int mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
802 Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t
803 *mpi_request);
804int mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
805 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request);
806void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type);
807
fa7f3167
KD
808void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc);
809
635374e7 810/* scsih shared API */
77e63ed4
KD
811u8 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
812 u32 reply);
635374e7
EM
813void mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
814 u8 type, u16 smid_task, ulong timeout);
815void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
816void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
817struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc,
818 u16 handle);
819struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
820 *ioc, u64 sas_address);
821struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address(
822 struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
823
635374e7
EM
824void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
825
826/* config shared API */
77e63ed4 827u8 mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
7b936b02 828 u32 reply);
635374e7
EM
829int mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys);
830int mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
831 Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page);
ed79f128
KD
832int mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc,
833 Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page);
635374e7
EM
834int mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
835 *mpi_reply, Mpi2BiosPage2_t *config_page);
836int mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
837 *mpi_reply, Mpi2BiosPage3_t *config_page);
838int mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
839 *mpi_reply, Mpi2IOUnitPage0_t *config_page);
840int mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
841 *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle);
842int mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
843 *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle);
844int mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
845 *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz);
846int mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
847 *mpi_reply, Mpi2IOUnitPage1_t *config_page);
848int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
5b768581 849 *mpi_reply, Mpi2IOUnitPage1_t *config_page);
635374e7
EM
850int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
851 *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
852int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
853 *mpi_reply, Mpi2IOCPage8_t *config_page);
854int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
855 *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle);
856int mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
857 *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle);
858int mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
859 *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle);
860int mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
861 *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number);
862int mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
863 *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number);
864int mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
865 *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle);
866int mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 *num_pds);
867int mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
868 *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz);
869int mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
870 *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
871 u32 form_specific);
872int mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
873 u16 *volume_handle);
874int mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle,
875 u64 *wwid);
635374e7
EM
876/* ctl shared API */
877extern struct device_attribute *mpt2sas_host_attrs[];
878extern struct device_attribute *mpt2sas_dev_attrs[];
879void mpt2sas_ctl_init(void);
880void mpt2sas_ctl_exit(void);
77e63ed4 881u8 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
7b936b02 882 u32 reply);
635374e7 883void mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
77e63ed4 884u8 mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7b936b02 885 u32 reply);
635374e7
EM
886void mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
887 Mpi2EventNotificationReply_t *mpi_reply);
888
32e0eb56
KD
889void mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc,
890 u8 bits_to_regsiter);
891
635374e7 892/* transport shared API */
77e63ed4
KD
893u8 mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
894 u32 reply);
635374e7 895struct _sas_port *mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc,
c5e039be 896 u16 handle, u64 sas_address);
635374e7 897void mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
c5e039be 898 u64 sas_address_parent);
635374e7
EM
899int mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
900 *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev);
901int mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
902 *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev);
c5e039be
KD
903void mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc,
904 u64 sas_address, u16 handle, u8 phy_number, u8 link_rate);
635374e7
EM
905extern struct sas_function_template mpt2sas_transport_functions;
906extern struct scsi_transport_template *mpt2sas_transport_template;
34a03bef 907extern int scsi_internal_device_block(struct scsi_device *sdev);
77e63ed4
KD
908extern u8 mpt2sas_stm_zero_smid_handler(struct MPT2SAS_ADAPTER *ioc,
909 u8 msix_index, u32 reply);
34a03bef 910extern int scsi_internal_device_unblock(struct scsi_device *sdev);
635374e7
EM
911
912#endif /* MPT2SAS_BASE_H_INCLUDED */