• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/scsi/mpt2sas/
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
6 * Copyright (C) 2007-2010  LSI Corporation
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>
64#include <scsi/scsi_eh.h>
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"
72#define MPT2SAS_DRIVER_VERSION		"06.100.00.00"
73#define MPT2SAS_MAJOR_VERSION		06
74#define MPT2SAS_MINOR_VERSION		100
75#define MPT2SAS_BUILD_VERSION		00
76#define MPT2SAS_RELEASE_VERSION		00
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 */
122
123/*
124 * logging format
125 */
126#define MPT2SAS_FMT			"%s: "
127#define MPT2SAS_INFO_FMT		KERN_INFO MPT2SAS_FMT
128#define MPT2SAS_NOTE_FMT		KERN_NOTICE MPT2SAS_FMT
129#define MPT2SAS_WARN_FMT		KERN_WARNING MPT2SAS_FMT
130#define MPT2SAS_ERR_FMT			KERN_ERR MPT2SAS_FMT
131
132/*
133 * Dell HBA branding
134 */
135#define MPT2SAS_DELL_BRANDING_SIZE                 32
136
137#define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING        "Dell 6Gbps SAS HBA"
138#define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING    "Dell PERC H200 Adapter"
139#define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated"
140#define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING    "Dell PERC H200 Modular"
141#define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING   "Dell PERC H200 Embedded"
142#define MPT2SAS_DELL_PERC_H200_BRANDING            "Dell PERC H200"
143#define MPT2SAS_DELL_6GBPS_SAS_BRANDING            "Dell 6Gbps SAS"
144
145/*
146 * Dell HBA SSDIDs
147 */
148#define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID           0x1F1C
149#define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID       0x1F1D
150#define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID    0x1F1E
151#define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID       0x1F1F
152#define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID      0x1F20
153#define MPT2SAS_DELL_PERC_H200_SSDID               0x1F21
154#define MPT2SAS_DELL_6GBPS_SAS_SSDID               0x1F22
155
156/*
157 * per target private data
158 */
159#define MPT_TARGET_FLAGS_RAID_COMPONENT	0x01
160#define MPT_TARGET_FLAGS_VOLUME		0x02
161#define MPT_TARGET_FLAGS_DELETED	0x04
162
163/**
164 * struct MPT2SAS_TARGET - starget private hostdata
165 * @starget: starget object
166 * @sas_address: target sas address
167 * @handle: device handle
168 * @num_luns: number luns
169 * @flags: MPT_TARGET_FLAGS_XXX flags
170 * @deleted: target flaged for deletion
171 * @tm_busy: target is busy with TM request.
172 */
173struct MPT2SAS_TARGET {
174	struct scsi_target *starget;
175	u64	sas_address;
176	u16	handle;
177	int	num_luns;
178	u32	flags;
179	u8	deleted;
180	u8	tm_busy;
181};
182
183/*
184 * per device private data
185 */
186#define MPT_DEVICE_FLAGS_INIT		0x01
187#define MPT_DEVICE_TLR_ON		0x02
188
189/**
190 * struct MPT2SAS_DEVICE - sdev private hostdata
191 * @sas_target: starget private hostdata
192 * @lun: lun number
193 * @flags: MPT_DEVICE_XXX flags
194 * @configured_lun: lun is configured
195 * @block: device is in SDEV_BLOCK state
196 * @tlr_snoop_check: flag used in determining whether to disable TLR
197 */
198
199/* OEM Identifiers */
200#define MFG10_OEM_ID_INVALID                   (0x00000000)
201#define MFG10_OEM_ID_DELL                      (0x00000001)
202#define MFG10_OEM_ID_FSC                       (0x00000002)
203#define MFG10_OEM_ID_SUN                       (0x00000003)
204#define MFG10_OEM_ID_IBM                       (0x00000004)
205
206/* GENERIC Flags 0*/
207#define MFG10_GF0_OCE_DISABLED                 (0x00000001)
208#define MFG10_GF0_R1E_DRIVE_COUNT              (0x00000002)
209#define MFG10_GF0_R10_DISPLAY                  (0x00000004)
210#define MFG10_GF0_SSD_DATA_SCRUB_DISABLE       (0x00000008)
211#define MFG10_GF0_SINGLE_DRIVE_R0              (0x00000010)
212
213/* OEM Specific Flags will come from OEM specific header files */
214typedef struct _MPI2_CONFIG_PAGE_MAN_10 {
215    MPI2_CONFIG_PAGE_HEADER Header;                                 /* 00h */
216    U8                      OEMIdentifier;                          /* 04h */
217    U8                      Reserved1;                              /* 05h */
218    U16                     Reserved2;                              /* 08h */
219    U32                     Reserved3;                              /* 0Ch */
220    U32                     GenericFlags0;                          /* 10h */
221    U32                     GenericFlags1;                          /* 14h */
222    U32                     Reserved4;                              /* 18h */
223    U32                     OEMSpecificFlags0;                      /* 1Ch */
224    U32                     OEMSpecificFlags1;                      /* 20h */
225    U32                     Reserved5[18];                          /* 24h-60h*/
226} MPI2_CONFIG_PAGE_MAN_10,
227  MPI2_POINTER PTR_MPI2_CONFIG_PAGE_MAN_10,
228  Mpi2ManufacturingPage10_t, MPI2_POINTER pMpi2ManufacturingPage10_t;
229
230struct MPT2SAS_DEVICE {
231	struct MPT2SAS_TARGET *sas_target;
232	unsigned int	lun;
233	u32	flags;
234	u8	configured_lun;
235	u8	block;
236	u8	tlr_snoop_check;
237};
238
239#define MPT2_CMD_NOT_USED	0x8000	/* free */
240#define MPT2_CMD_COMPLETE	0x0001	/* completed */
241#define MPT2_CMD_PENDING	0x0002	/* pending */
242#define MPT2_CMD_REPLY_VALID	0x0004	/* reply is valid */
243#define MPT2_CMD_RESET		0x0008	/* host reset dropped the command */
244
245/**
246 * struct _internal_cmd - internal commands struct
247 * @mutex: mutex
248 * @done: completion
249 * @reply: reply message pointer
250 * @sense: sense data
251 * @status: MPT2_CMD_XXX status
252 * @smid: system message id
253 */
254struct _internal_cmd {
255	struct mutex mutex;
256	struct completion done;
257	void 	*reply;
258	void	*sense;
259	u16	status;
260	u16	smid;
261};
262
263
264/**
265 * struct _sas_device - attached device information
266 * @list: sas device list
267 * @starget: starget object
268 * @sas_address: device sas address
269 * @device_name: retrieved from the SAS IDENTIFY frame.
270 * @handle: device handle
271 * @sas_address_parent: sas address of parent expander or sas host
272 * @enclosure_handle: enclosure handle
273 * @enclosure_logical_id: enclosure logical identifier
274 * @volume_handle: volume handle (valid when hidden raid member)
275 * @volume_wwid: volume unique identifier
276 * @device_info: bitfield provides detailed info about the device
277 * @id: target id
278 * @channel: target channel
279 * @slot: number number
280 * @phy: phy identifier provided in sas device page 0
281 * @responding: used in _scsih_sas_device_mark_responding
282 */
283struct _sas_device {
284	struct list_head list;
285	struct scsi_target *starget;
286	u64	sas_address;
287	u64	device_name;
288	u16	handle;
289	u64	sas_address_parent;
290	u16	enclosure_handle;
291	u64	enclosure_logical_id;
292	u16	volume_handle;
293	u64	volume_wwid;
294	u32	device_info;
295	int	id;
296	int	channel;
297	u16	slot;
298	u8	phy;
299	u8	responding;
300};
301
302/**
303 * struct _raid_device - raid volume link list
304 * @list: sas device list
305 * @starget: starget object
306 * @sdev: scsi device struct (volumes are single lun)
307 * @wwid: unique identifier for the volume
308 * @handle: device handle
309 * @id: target id
310 * @channel: target channel
311 * @volume_type: the raid level
312 * @device_info: bitfield provides detailed info about the hidden components
313 * @num_pds: number of hidden raid components
314 * @responding: used in _scsih_raid_device_mark_responding
315 * @percent_complete: resync percent complete
316 */
317struct _raid_device {
318	struct list_head list;
319	struct scsi_target *starget;
320	struct scsi_device *sdev;
321	u64	wwid;
322	u16	handle;
323	int	id;
324	int	channel;
325	u8	volume_type;
326	u32	device_info;
327	u8	num_pds;
328	u8	responding;
329	u8	percent_complete;
330};
331
332/**
333 * struct _boot_device - boot device info
334 * @is_raid: flag to indicate whether this is volume
335 * @device: holds pointer for either struct _sas_device or
336 *     struct _raid_device
337 */
338struct _boot_device {
339	u8 is_raid;
340	void *device;
341};
342
343/**
344 * struct _sas_port - wide/narrow sas port information
345 * @port_list: list of ports belonging to expander
346 * @num_phys: number of phys belonging to this port
347 * @remote_identify: attached device identification
348 * @rphy: sas transport rphy object
349 * @port: sas transport wide/narrow port object
350 * @phy_list: _sas_phy list objects belonging to this port
351 */
352struct _sas_port {
353	struct list_head port_list;
354	u8	num_phys;
355	struct sas_identify remote_identify;
356	struct sas_rphy *rphy;
357	struct sas_port *port;
358	struct list_head phy_list;
359};
360
361/**
362 * struct _sas_phy - phy information
363 * @port_siblings: list of phys belonging to a port
364 * @identify: phy identification
365 * @remote_identify: attached device identification
366 * @phy: sas transport phy object
367 * @phy_id: unique phy id
368 * @handle: device handle for this phy
369 * @attached_handle: device handle for attached device
370 * @phy_belongs_to_port: port has been created for this phy
371 */
372struct _sas_phy {
373	struct list_head port_siblings;
374	struct sas_identify identify;
375	struct sas_identify remote_identify;
376	struct sas_phy *phy;
377	u8	phy_id;
378	u16	handle;
379	u16	attached_handle;
380	u8	phy_belongs_to_port;
381};
382
383/**
384 * struct _sas_node - sas_host/expander information
385 * @list: list of expanders
386 * @parent_dev: parent device class
387 * @num_phys: number phys belonging to this sas_host/expander
388 * @sas_address: sas address of this sas_host/expander
389 * @handle: handle for this sas_host/expander
390 * @sas_address_parent: sas address of parent expander or sas host
391 * @enclosure_handle: handle for this a member of an enclosure
392 * @device_info: bitwise defining capabilities of this sas_host/expander
393 * @responding: used in _scsih_expander_device_mark_responding
394 * @phy: a list of phys that make up this sas_host/expander
395 * @sas_port_list: list of ports attached to this sas_host/expander
396 */
397struct _sas_node {
398	struct list_head list;
399	struct device *parent_dev;
400	u8	num_phys;
401	u64	sas_address;
402	u16	handle;
403	u64	sas_address_parent;
404	u16	enclosure_handle;
405	u64	enclosure_logical_id;
406	u8	responding;
407	struct	_sas_phy *phy;
408	struct list_head sas_port_list;
409};
410
411/**
412 * enum reset_type - reset state
413 * @FORCE_BIG_HAMMER: issue diagnostic reset
414 * @SOFT_RESET: issue message_unit_reset, if fails to to big hammer
415 */
416enum reset_type {
417	FORCE_BIG_HAMMER,
418	SOFT_RESET,
419};
420
421/**
422 * struct request_tracker - firmware request tracker
423 * @smid: system message id
424 * @scmd: scsi request pointer
425 * @cb_idx: callback index
426 * @chain_list: list of chains associated to this IO
427 * @tracker_list: list of free request (ioc->free_list)
428 */
429struct request_tracker {
430	u16	smid;
431	struct scsi_cmnd *scmd;
432	u8	cb_idx;
433	struct list_head tracker_list;
434};
435
436/**
437 * struct _tr_list - target reset list
438 * @handle: device handle
439 * @state: state machine
440 */
441struct _tr_list {
442	struct list_head list;
443	u16	handle;
444	u16	state;
445};
446
447typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
448
449/**
450 * struct MPT2SAS_ADAPTER - per adapter struct
451 * @list: ioc_list
452 * @shost: shost object
453 * @id: unique adapter id
454 * @pci_irq: irq number
455 * @name: generic ioc string
456 * @tmp_string: tmp string used for logging
457 * @pdev: pci pdev object
458 * @chip: memory mapped register space
459 * @chip_phys: physical addrss prior to mapping
460 * @logging_level: see mpt2sas_debug.h
461 * @fwfault_debug: debuging FW timeouts
462 * @ir_firmware: IR firmware present
463 * @bars: bitmask of BAR's that must be configured
464 * @mask_interrupts: ignore interrupt
465 * @fault_reset_work_q_name: fw fault work queue
466 * @fault_reset_work_q: ""
467 * @fault_reset_work: ""
468 * @firmware_event_name: fw event work queue
469 * @firmware_event_thread: ""
470 * @fw_events_off: flag to turn off fw event handling
471 * @fw_event_lock:
472 * @fw_event_list: list of fw events
473 * @aen_event_read_flag: event log was read
474 * @broadcast_aen_busy: broadcast aen waiting to be serviced
475 * @shost_recovery: host reset in progress
476 * @ioc_reset_in_progress_lock:
477 * @ioc_link_reset_in_progress: phy/hard reset in progress
478 * @ignore_loginfos: ignore loginfos during task management
479 * @remove_host: flag for when driver unloads, to avoid sending dev resets
480 * @pci_error_recovery: flag to prevent ioc access until slot reset completes
481 * @wait_for_port_enable_to_complete:
482 * @msix_enable: flag indicating msix is enabled
483 * @msix_vector_count: number msix vectors
484 * @msix_table: virt address to the msix table
485 * @msix_table_backup: backup msix table
486 * @scsi_io_cb_idx: shost generated commands
487 * @tm_cb_idx: task management commands
488 * @scsih_cb_idx: scsih internal commands
489 * @transport_cb_idx: transport internal commands
490 * @ctl_cb_idx: clt internal commands
491 * @base_cb_idx: base internal commands
492 * @config_cb_idx: base internal commands
493 * @tm_tr_cb_idx : device removal target reset handshake
494 * @tm_tr_volume_cb_idx : volume removal target reset
495 * @base_cmds:
496 * @transport_cmds:
497 * @scsih_cmds:
498 * @tm_cmds:
499 * @ctl_cmds:
500 * @config_cmds:
501 * @base_add_sg_single: handler for either 32/64 bit sgl's
502 * @event_type: bits indicating which events to log
503 * @event_context: unique id for each logged event
504 * @event_log: event log pointer
505 * @event_masks: events that are masked
506 * @facts: static facts data
507 * @pfacts: static port facts data
508 * @manu_pg0: static manufacturing page 0
509 * @manu_pg10: static manufacturing page 10
510 * @bios_pg2: static bios page 2
511 * @bios_pg3: static bios page 3
512 * @ioc_pg8: static ioc page 8
513 * @iounit_pg0: static iounit page 0
514 * @iounit_pg1: static iounit page 1
515 * @sas_hba: sas host object
516 * @sas_expander_list: expander object list
517 * @sas_node_lock:
518 * @sas_device_list: sas device object list
519 * @sas_device_init_list: sas device object list (used only at init time)
520 * @sas_device_lock:
521 * @io_missing_delay: time for IO completed by fw when PDR enabled
522 * @device_missing_delay: time for device missing by fw when PDR enabled
523 * @sas_id : used for setting volume target IDs
524 * @pd_handles : bitmask for PD handles
525 * @pd_handles_sz : size of pd_handle bitmask
526 * @config_page_sz: config page size
527 * @config_page: reserve memory for config page payload
528 * @config_page_dma:
529 * @hba_queue_depth: hba request queue depth
530 * @sge_size: sg element size for either 32/64 bit
531 * @scsiio_depth: SCSI_IO queue depth
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
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:
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 * @delayed_tr_list: target reset link list
579 * @delayed_tr_volume_list: volume target reset link list
580 */
581struct MPT2SAS_ADAPTER {
582	struct list_head list;
583	struct Scsi_Host *shost;
584	u8		id;
585	u32		pci_irq;
586	char		name[MPT_NAME_LENGTH];
587	char		tmp_string[MPT_STRING_LENGTH];
588	struct pci_dev	*pdev;
589	Mpi2SystemInterfaceRegs_t __iomem *chip;
590	resource_size_t	chip_phys;
591	int		logging_level;
592	int		fwfault_debug;
593	u8		ir_firmware;
594	int		bars;
595	u8		mask_interrupts;
596
597	/* fw fault handler */
598	char		fault_reset_work_q_name[20];
599	struct workqueue_struct *fault_reset_work_q;
600	struct delayed_work fault_reset_work;
601
602	/* fw event handler */
603	char		firmware_event_name[20];
604	struct workqueue_struct	*firmware_event_thread;
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;
611	u8		shost_recovery;
612
613	struct mutex	reset_in_progress_mutex;
614	struct completion	shost_recovery_done;
615	spinlock_t 	ioc_reset_in_progress_lock;
616	u8		ioc_link_reset_in_progress;
617	int		ioc_reset_in_progress_status;
618
619	u8		ignore_loginfos;
620	u8		remove_host;
621	u8		pci_error_recovery;
622	u8		wait_for_port_enable_to_complete;
623
624	u8		msix_enable;
625	u16		msix_vector_count;
626	u32		*msix_table;
627	u32		*msix_table_backup;
628	u32		ioc_reset_count;
629
630	/* internal commands, callback index */
631	u8		scsi_io_cb_idx;
632	u8		tm_cb_idx;
633	u8		transport_cb_idx;
634	u8		scsih_cb_idx;
635	u8		ctl_cb_idx;
636	u8		base_cb_idx;
637	u8		config_cb_idx;
638	u8		tm_tr_cb_idx;
639	u8		tm_tr_volume_cb_idx;
640	u8		tm_sas_control_cb_idx;
641	struct _internal_cmd base_cmds;
642	struct _internal_cmd transport_cmds;
643	struct _internal_cmd scsih_cmds;
644	struct _internal_cmd tm_cmds;
645	struct _internal_cmd ctl_cmds;
646	struct _internal_cmd config_cmds;
647
648	MPT_ADD_SGE	base_add_sg_single;
649
650	/* event log */
651	u32		event_type[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
652	u32		event_context;
653	void		*event_log;
654	u32		event_masks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
655
656	/* static config pages */
657	Mpi2IOCFactsReply_t facts;
658	Mpi2PortFactsReply_t *pfacts;
659	Mpi2ManufacturingPage0_t manu_pg0;
660	Mpi2BiosPage2_t	bios_pg2;
661	Mpi2BiosPage3_t	bios_pg3;
662	Mpi2IOCPage8_t ioc_pg8;
663	Mpi2IOUnitPage0_t iounit_pg0;
664	Mpi2IOUnitPage1_t iounit_pg1;
665
666	struct _boot_device req_boot_device;
667	struct _boot_device req_alt_boot_device;
668	struct _boot_device current_boot_device;
669
670	/* sas hba, expander, and device list */
671	struct _sas_node sas_hba;
672	struct list_head sas_expander_list;
673	spinlock_t	sas_node_lock;
674	struct list_head sas_device_list;
675	struct list_head sas_device_init_list;
676	spinlock_t	sas_device_lock;
677	struct list_head raid_device_list;
678	spinlock_t	raid_device_lock;
679	u8		io_missing_delay;
680	u16		device_missing_delay;
681	int		sas_id;
682
683	void		*pd_handles;
684	u16		pd_handles_sz;
685
686	/* config page */
687	u16		config_page_sz;
688	void 		*config_page;
689	dma_addr_t	config_page_dma;
690
691	/* scsiio request */
692	u16		hba_queue_depth;
693	u16		sge_size;
694	u16 		scsiio_depth;
695	u16		request_sz;
696	u8		*request;
697	dma_addr_t	request_dma;
698	u32		request_dma_sz;
699	struct request_tracker *scsi_lookup;
700	ulong		scsi_lookup_pages;
701	spinlock_t 	scsi_lookup_lock;
702	struct list_head free_list;
703	int		pending_io_count;
704	wait_queue_head_t reset_wq;
705
706	/* chain */
707	u8		*chain;
708	dma_addr_t	chain_dma;
709	u16 		max_sges_in_main_message;
710	u16		max_sges_in_chain_message;
711	u16		chains_needed_per_io;
712	u16		chain_offset_value_for_main_message;
713	u32		chain_depth;
714
715	/* hi-priority queue */
716	u16		hi_priority_smid;
717	u8		*hi_priority;
718	dma_addr_t	hi_priority_dma;
719	u16		hi_priority_depth;
720	struct request_tracker *hpr_lookup;
721	struct list_head hpr_free_list;
722
723	/* internal queue */
724	u16		internal_smid;
725	u8		*internal;
726	dma_addr_t	internal_dma;
727	u16		internal_depth;
728	struct request_tracker *internal_lookup;
729	struct list_head internal_free_list;
730
731	/* sense */
732	u8		*sense;
733	dma_addr_t	sense_dma;
734	struct dma_pool *sense_dma_pool;
735
736	/* reply */
737	u16		reply_sz;
738	u8		*reply;
739	dma_addr_t	reply_dma;
740	struct dma_pool *reply_dma_pool;
741
742	/* reply free queue */
743	u16 		reply_free_queue_depth;
744	u32		*reply_free;
745	dma_addr_t	reply_free_dma;
746	struct dma_pool *reply_free_dma_pool;
747	u32		reply_free_host_index;
748
749	/* reply post queue */
750	u16 		reply_post_queue_depth;
751	Mpi2ReplyDescriptorsUnion_t *reply_post_free;
752	dma_addr_t	reply_post_free_dma;
753	struct dma_pool *reply_post_free_dma_pool;
754	u32		reply_post_host_index;
755
756	struct list_head delayed_tr_list;
757	struct list_head delayed_tr_volume_list;
758
759	/* diag buffer support */
760	u8		*diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT];
761	u32		diag_buffer_sz[MPI2_DIAG_BUF_TYPE_COUNT];
762	dma_addr_t	diag_buffer_dma[MPI2_DIAG_BUF_TYPE_COUNT];
763	u8		diag_buffer_status[MPI2_DIAG_BUF_TYPE_COUNT];
764	u32		unique_id[MPI2_DIAG_BUF_TYPE_COUNT];
765	Mpi2ManufacturingPage10_t manu_pg10;
766	u32		product_specific[MPI2_DIAG_BUF_TYPE_COUNT][23];
767	u32		diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT];
768	u32		ring_buffer_offset;
769	u32		ring_buffer_sz;
770};
771
772typedef u8 (*MPT_CALLBACK)(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
773    u32 reply);
774
775
776/* base shared API */
777extern struct list_head mpt2sas_ioc_list;
778void mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc);
779void mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc);
780
781int mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc);
782void mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc);
783int mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc);
784void mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc);
785int mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
786    enum reset_type type);
787
788void *mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid);
789void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid);
790void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr);
791__le32 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc,
792    u16 smid);
793
794/* hi-priority queue */
795u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
796u16 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
797    struct scsi_cmnd *scmd);
798
799u16 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
800void mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid);
801void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid,
802    u16 handle);
803void mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid);
804void mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
805    u16 io_index);
806void mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid);
807void mpt2sas_base_initialize_callback_handler(void);
808u8 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func);
809void mpt2sas_base_release_callback_handler(u8 cb_idx);
810
811u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
812    u32 reply);
813void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr);
814
815u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked);
816
817void mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code);
818int mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
819    Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t
820    *mpi_request);
821int mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
822    Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request);
823void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type);
824
825void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc);
826
827/* scsih shared API */
828u8 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
829    u32 reply);
830int mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle,
831    uint channel, uint id, uint lun, u8 type, u16 smid_task,
832    ulong timeout, struct scsi_cmnd *scmd);
833void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
834void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
835struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc,
836    u16 handle);
837struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
838    *ioc, u64 sas_address);
839struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address(
840    struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
841
842void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
843
844/* config shared API */
845u8 mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
846    u32 reply);
847int mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys);
848int mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
849    Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page);
850int mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc,
851    Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page);
852int mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
853    *mpi_reply, Mpi2BiosPage2_t *config_page);
854int mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
855    *mpi_reply, Mpi2BiosPage3_t *config_page);
856int mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
857    *mpi_reply, Mpi2IOUnitPage0_t *config_page);
858int mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
859    *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle);
860int mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
861    *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle);
862int mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
863    *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz);
864int mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
865    *mpi_reply, Mpi2IOUnitPage1_t *config_page);
866int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
867    *mpi_reply, Mpi2IOUnitPage1_t *config_page);
868int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
869    *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
870int mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
871    Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
872int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
873    *mpi_reply, Mpi2IOCPage8_t *config_page);
874int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
875    *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle);
876int mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
877    *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle);
878int mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
879    *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle);
880int mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
881    *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number);
882int mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
883    *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number);
884int mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
885    *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle);
886int mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 *num_pds);
887int mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
888    *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz);
889int mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
890    *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
891    u32 form_specific);
892int mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
893    u16 *volume_handle);
894int mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle,
895    u64 *wwid);
896/* ctl shared API */
897extern struct device_attribute *mpt2sas_host_attrs[];
898extern struct device_attribute *mpt2sas_dev_attrs[];
899void mpt2sas_ctl_init(void);
900void mpt2sas_ctl_exit(void);
901u8 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
902    u32 reply);
903void mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
904u8 mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
905    u32 reply);
906void mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
907    Mpi2EventNotificationReply_t *mpi_reply);
908
909void mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc,
910	u8 bits_to_regsiter);
911
912/* transport shared API */
913u8 mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
914    u32 reply);
915struct _sas_port *mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc,
916     u16 handle, u64 sas_address);
917void mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
918     u64 sas_address_parent);
919int mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
920    *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev);
921int mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
922    *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev);
923void mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc,
924     u64 sas_address, u16 handle, u8 phy_number, u8 link_rate);
925extern struct sas_function_template mpt2sas_transport_functions;
926extern struct scsi_transport_template *mpt2sas_transport_template;
927extern int scsi_internal_device_block(struct scsi_device *sdev);
928extern u8 mpt2sas_stm_zero_smid_handler(struct MPT2SAS_ADAPTER *ioc,
929    u8 msix_index, u32 reply);
930extern int scsi_internal_device_unblock(struct scsi_device *sdev);
931
932#endif /* MPT2SAS_BASE_H_INCLUDED */
933