Linux Audio

Check our new training course

Loading...
v3.1
   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		"09.100.00.00"
  73#define MPT2SAS_MAJOR_VERSION		09
  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
 107#define	 CAN_SLEEP			1
 108#define  NO_SLEEP			0
 109
 110#define INTERNAL_CMDS_COUNT		10	/* reserved cmds */
 111
 112#define MPI2_HIM_MASK			0xFFFFFFFF /* mask every bit*/
 113
 114#define MPT2SAS_INVALID_DEVICE_HANDLE	0xFFFF
 115
 116
 117/*
 118 * reset phases
 119 */
 120#define MPT2_IOC_PRE_RESET		1 /* prior to host reset */
 121#define MPT2_IOC_AFTER_RESET		2 /* just after host reset */
 122#define MPT2_IOC_DONE_RESET		3 /* links re-initialized */
 123
 124/*
 125 * logging format
 126 */
 127#define MPT2SAS_FMT			"%s: "
 128#define MPT2SAS_INFO_FMT		KERN_INFO MPT2SAS_FMT
 129#define MPT2SAS_NOTE_FMT		KERN_NOTICE MPT2SAS_FMT
 130#define MPT2SAS_WARN_FMT		KERN_WARNING MPT2SAS_FMT
 131#define MPT2SAS_ERR_FMT			KERN_ERR MPT2SAS_FMT
 132
 133/*
 134 * Dell HBA branding
 135 */
 136#define MPT2SAS_DELL_BRANDING_SIZE                 32
 137
 138#define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING        "Dell 6Gbps SAS HBA"
 139#define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING    "Dell PERC H200 Adapter"
 140#define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated"
 141#define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING    "Dell PERC H200 Modular"
 142#define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING   "Dell PERC H200 Embedded"
 143#define MPT2SAS_DELL_PERC_H200_BRANDING            "Dell PERC H200"
 144#define MPT2SAS_DELL_6GBPS_SAS_BRANDING            "Dell 6Gbps SAS"
 145
 146/*
 147 * Dell HBA SSDIDs
 148 */
 149#define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID           0x1F1C
 150#define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID       0x1F1D
 151#define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID    0x1F1E
 152#define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID       0x1F1F
 153#define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID      0x1F20
 154#define MPT2SAS_DELL_PERC_H200_SSDID               0x1F21
 155#define MPT2SAS_DELL_6GBPS_SAS_SSDID               0x1F22
 156
 157/*
 158 * Intel HBA branding
 159 */
 
 
 
 
 
 
 
 
 
 
 
 
 160#define MPT2SAS_INTEL_RMS2LL080_BRANDING	\
 161				"Intel Integrated RAID Module RMS2LL080"
 162#define MPT2SAS_INTEL_RMS2LL040_BRANDING	\
 163				"Intel Integrated RAID Module RMS2LL040"
 164#define MPT2SAS_INTEL_RS25GB008_BRANDING       \
 165				"Intel(R) RAID Controller RS25GB008"
 166
 
 167/*
 168 * Intel HBA SSDIDs
 169 */
 
 
 
 
 
 
 170#define MPT2SAS_INTEL_RMS2LL080_SSDID          0x350E
 171#define MPT2SAS_INTEL_RMS2LL040_SSDID          0x350F
 172#define MPT2SAS_INTEL_RS25GB008_SSDID          0x3000
 173
 174
 175/*
 176 * HP HBA branding
 177 */
 178#define MPT2SAS_HP_3PAR_SSVID                0x1590
 179#define MPT2SAS_HP_2_4_INTERNAL_BRANDING        "HP H220 Host Bus Adapter"
 180#define MPT2SAS_HP_2_4_EXTERNAL_BRANDING        "HP H221 Host Bus Adapter"
 181#define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING "HP H222 Host Bus Adapter"
 182#define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING    "HP H220i Host Bus Adapter"
 183#define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING    "HP H210i Host Bus Adapter"
 184
 185/*
 186 * HO HBA SSDIDs
 187 */
 188#define MPT2SAS_HP_2_4_INTERNAL_SSDID            0x0041
 189#define MPT2SAS_HP_2_4_EXTERNAL_SSDID            0x0042
 190#define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID    0x0043
 191#define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID        0x0044
 192#define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID        0x0046
 193
 194/*
 195 *  WarpDrive Specific Log codes
 196 */
 197
 198#define MPT2_WARPDRIVE_LOGENTRY		(0x8002)
 199#define MPT2_WARPDRIVE_LC_SSDT		(0x41)
 200#define MPT2_WARPDRIVE_LC_SSDLW		(0x43)
 201#define MPT2_WARPDRIVE_LC_SSDLF		(0x44)
 202#define MPT2_WARPDRIVE_LC_BRMF		(0x4D)
 203
 204/*
 205 * per target private data
 206 */
 207#define MPT_TARGET_FLAGS_RAID_COMPONENT	0x01
 208#define MPT_TARGET_FLAGS_VOLUME		0x02
 209#define MPT_TARGET_FLAGS_DELETED	0x04
 210
 211/**
 212 * struct MPT2SAS_TARGET - starget private hostdata
 213 * @starget: starget object
 214 * @sas_address: target sas address
 215 * @raid_device: raid_device pointer to access volume data
 216 * @handle: device handle
 217 * @num_luns: number luns
 218 * @flags: MPT_TARGET_FLAGS_XXX flags
 219 * @deleted: target flaged for deletion
 220 * @tm_busy: target is busy with TM request.
 221 */
 222struct MPT2SAS_TARGET {
 223	struct scsi_target *starget;
 224	u64	sas_address;
 225	struct _raid_device *raid_device;
 226	u16	handle;
 227	int	num_luns;
 228	u32	flags;
 229	u8	deleted;
 230	u8	tm_busy;
 231};
 232
 233
 234/*
 235 * per device private data
 236 */
 237#define MPT_DEVICE_FLAGS_INIT		0x01
 238#define MPT_DEVICE_TLR_ON		0x02
 239
 240/**
 241 * struct MPT2SAS_DEVICE - sdev private hostdata
 242 * @sas_target: starget private hostdata
 243 * @lun: lun number
 244 * @flags: MPT_DEVICE_XXX flags
 245 * @configured_lun: lun is configured
 246 * @block: device is in SDEV_BLOCK state
 247 * @tlr_snoop_check: flag used in determining whether to disable TLR
 248 */
 249
 250/* OEM Identifiers */
 251#define MFG10_OEM_ID_INVALID                   (0x00000000)
 252#define MFG10_OEM_ID_DELL                      (0x00000001)
 253#define MFG10_OEM_ID_FSC                       (0x00000002)
 254#define MFG10_OEM_ID_SUN                       (0x00000003)
 255#define MFG10_OEM_ID_IBM                       (0x00000004)
 256
 257/* GENERIC Flags 0*/
 258#define MFG10_GF0_OCE_DISABLED                 (0x00000001)
 259#define MFG10_GF0_R1E_DRIVE_COUNT              (0x00000002)
 260#define MFG10_GF0_R10_DISPLAY                  (0x00000004)
 261#define MFG10_GF0_SSD_DATA_SCRUB_DISABLE       (0x00000008)
 262#define MFG10_GF0_SINGLE_DRIVE_R0              (0x00000010)
 263
 264/* OEM Specific Flags will come from OEM specific header files */
 265typedef struct _MPI2_CONFIG_PAGE_MAN_10 {
 266    MPI2_CONFIG_PAGE_HEADER Header;                                 /* 00h */
 267    U8                      OEMIdentifier;                          /* 04h */
 268    U8                      Reserved1;                              /* 05h */
 269    U16                     Reserved2;                              /* 08h */
 270    U32                     Reserved3;                              /* 0Ch */
 271    U32                     GenericFlags0;                          /* 10h */
 272    U32                     GenericFlags1;                          /* 14h */
 273    U32                     Reserved4;                              /* 18h */
 274    U32                     OEMSpecificFlags0;                      /* 1Ch */
 275    U32                     OEMSpecificFlags1;                      /* 20h */
 276    U32                     Reserved5[18];                          /* 24h-60h*/
 277} MPI2_CONFIG_PAGE_MAN_10,
 278  MPI2_POINTER PTR_MPI2_CONFIG_PAGE_MAN_10,
 279  Mpi2ManufacturingPage10_t, MPI2_POINTER pMpi2ManufacturingPage10_t;
 280
 281#define MFG_PAGE10_HIDE_SSDS_MASK	(0x00000003)
 282#define MFG_PAGE10_HIDE_ALL_DISKS	(0x00)
 283#define MFG_PAGE10_EXPOSE_ALL_DISKS	(0x01)
 284#define MFG_PAGE10_HIDE_IF_VOL_PRESENT	(0x02)
 285
 286
 287struct MPT2SAS_DEVICE {
 288	struct MPT2SAS_TARGET *sas_target;
 289	unsigned int	lun;
 290	u32	flags;
 291	u8	configured_lun;
 292	u8	block;
 293	u8	tlr_snoop_check;
 294};
 295
 296#define MPT2_CMD_NOT_USED	0x8000	/* free */
 297#define MPT2_CMD_COMPLETE	0x0001	/* completed */
 298#define MPT2_CMD_PENDING	0x0002	/* pending */
 299#define MPT2_CMD_REPLY_VALID	0x0004	/* reply is valid */
 300#define MPT2_CMD_RESET		0x0008	/* host reset dropped the command */
 301
 302/**
 303 * struct _internal_cmd - internal commands struct
 304 * @mutex: mutex
 305 * @done: completion
 306 * @reply: reply message pointer
 307 * @sense: sense data
 308 * @status: MPT2_CMD_XXX status
 309 * @smid: system message id
 310 */
 311struct _internal_cmd {
 312	struct mutex mutex;
 313	struct completion done;
 314	void 	*reply;
 315	void	*sense;
 316	u16	status;
 317	u16	smid;
 318};
 319
 320
 321/**
 322 * struct _sas_device - attached device information
 323 * @list: sas device list
 324 * @starget: starget object
 325 * @sas_address: device sas address
 326 * @device_name: retrieved from the SAS IDENTIFY frame.
 327 * @handle: device handle
 328 * @sas_address_parent: sas address of parent expander or sas host
 329 * @enclosure_handle: enclosure handle
 330 * @enclosure_logical_id: enclosure logical identifier
 331 * @volume_handle: volume handle (valid when hidden raid member)
 332 * @volume_wwid: volume unique identifier
 333 * @device_info: bitfield provides detailed info about the device
 334 * @id: target id
 335 * @channel: target channel
 336 * @slot: number number
 337 * @phy: phy identifier provided in sas device page 0
 338 * @responding: used in _scsih_sas_device_mark_responding
 339 */
 340struct _sas_device {
 341	struct list_head list;
 342	struct scsi_target *starget;
 343	u64	sas_address;
 344	u64	device_name;
 345	u16	handle;
 346	u64	sas_address_parent;
 347	u16	enclosure_handle;
 348	u64	enclosure_logical_id;
 349	u16	volume_handle;
 350	u64	volume_wwid;
 351	u32	device_info;
 352	int	id;
 353	int	channel;
 354	u16	slot;
 355	u8	phy;
 356	u8	responding;
 357};
 358
 359/**
 360 * struct _raid_device - raid volume link list
 361 * @list: sas device list
 362 * @starget: starget object
 363 * @sdev: scsi device struct (volumes are single lun)
 364 * @wwid: unique identifier for the volume
 365 * @handle: device handle
 366 * @block_size: Block size of the volume
 367 * @id: target id
 368 * @channel: target channel
 369 * @volume_type: the raid level
 370 * @device_info: bitfield provides detailed info about the hidden components
 371 * @num_pds: number of hidden raid components
 372 * @responding: used in _scsih_raid_device_mark_responding
 373 * @percent_complete: resync percent complete
 374 * @direct_io_enabled: Whether direct io to PDs are allowed or not
 375 * @stripe_exponent: X where 2powX is the stripe sz in blocks
 
 376 * @max_lba: Maximum number of LBA in the volume
 377 * @stripe_sz: Stripe Size of the volume
 378 * @device_info: Device info of the volume member disk
 379 * @pd_handle: Array of handles of the physical drives for direct I/O in le16
 380 */
 381#define MPT_MAX_WARPDRIVE_PDS		8
 382struct _raid_device {
 383	struct list_head list;
 384	struct scsi_target *starget;
 385	struct scsi_device *sdev;
 386	u64	wwid;
 387	u16	handle;
 388	u16	block_sz;
 389	int	id;
 390	int	channel;
 391	u8	volume_type;
 392	u8	num_pds;
 393	u8	responding;
 394	u8	percent_complete;
 395	u8	direct_io_enabled;
 396	u8	stripe_exponent;
 
 397	u64	max_lba;
 398	u32	stripe_sz;
 399	u32	device_info;
 400	u16	pd_handle[MPT_MAX_WARPDRIVE_PDS];
 401};
 402
 403/**
 404 * struct _boot_device - boot device info
 405 * @is_raid: flag to indicate whether this is volume
 406 * @device: holds pointer for either struct _sas_device or
 407 *     struct _raid_device
 408 */
 409struct _boot_device {
 410	u8 is_raid;
 411	void *device;
 412};
 413
 414/**
 415 * struct _sas_port - wide/narrow sas port information
 416 * @port_list: list of ports belonging to expander
 417 * @num_phys: number of phys belonging to this port
 418 * @remote_identify: attached device identification
 419 * @rphy: sas transport rphy object
 420 * @port: sas transport wide/narrow port object
 421 * @phy_list: _sas_phy list objects belonging to this port
 422 */
 423struct _sas_port {
 424	struct list_head port_list;
 425	u8	num_phys;
 426	struct sas_identify remote_identify;
 427	struct sas_rphy *rphy;
 428	struct sas_port *port;
 429	struct list_head phy_list;
 430};
 431
 432/**
 433 * struct _sas_phy - phy information
 434 * @port_siblings: list of phys belonging to a port
 435 * @identify: phy identification
 436 * @remote_identify: attached device identification
 437 * @phy: sas transport phy object
 438 * @phy_id: unique phy id
 439 * @handle: device handle for this phy
 440 * @attached_handle: device handle for attached device
 441 * @phy_belongs_to_port: port has been created for this phy
 442 */
 443struct _sas_phy {
 444	struct list_head port_siblings;
 445	struct sas_identify identify;
 446	struct sas_identify remote_identify;
 447	struct sas_phy *phy;
 448	u8	phy_id;
 449	u16	handle;
 450	u16	attached_handle;
 451	u8	phy_belongs_to_port;
 452};
 453
 454/**
 455 * struct _sas_node - sas_host/expander information
 456 * @list: list of expanders
 457 * @parent_dev: parent device class
 458 * @num_phys: number phys belonging to this sas_host/expander
 459 * @sas_address: sas address of this sas_host/expander
 460 * @handle: handle for this sas_host/expander
 461 * @sas_address_parent: sas address of parent expander or sas host
 462 * @enclosure_handle: handle for this a member of an enclosure
 463 * @device_info: bitwise defining capabilities of this sas_host/expander
 464 * @responding: used in _scsih_expander_device_mark_responding
 465 * @phy: a list of phys that make up this sas_host/expander
 466 * @sas_port_list: list of ports attached to this sas_host/expander
 467 */
 468struct _sas_node {
 469	struct list_head list;
 470	struct device *parent_dev;
 471	u8	num_phys;
 472	u64	sas_address;
 473	u16	handle;
 474	u64	sas_address_parent;
 475	u16	enclosure_handle;
 476	u64	enclosure_logical_id;
 477	u8	responding;
 478	struct	_sas_phy *phy;
 479	struct list_head sas_port_list;
 480};
 481
 482/**
 483 * enum reset_type - reset state
 484 * @FORCE_BIG_HAMMER: issue diagnostic reset
 485 * @SOFT_RESET: issue message_unit_reset, if fails to to big hammer
 486 */
 487enum reset_type {
 488	FORCE_BIG_HAMMER,
 489	SOFT_RESET,
 490};
 491
 492/**
 493 * struct chain_tracker - firmware chain tracker
 494 * @chain_buffer: chain buffer
 495 * @chain_buffer_dma: physical address
 496 * @tracker_list: list of free request (ioc->free_chain_list)
 497 */
 498struct chain_tracker {
 499	void *chain_buffer;
 500	dma_addr_t chain_buffer_dma;
 501	struct list_head tracker_list;
 502};
 503
 504/**
 505 * struct scsiio_tracker - scsi mf request tracker
 506 * @smid: system message id
 507 * @scmd: scsi request pointer
 508 * @cb_idx: callback index
 509 * @direct_io: To indicate whether I/O is direct (WARPDRIVE)
 510 * @chain_list: list of chains associated to this IO
 511 * @tracker_list: list of free request (ioc->free_list)
 512 */
 513struct scsiio_tracker {
 514	u16	smid;
 515	struct scsi_cmnd *scmd;
 516	u8	cb_idx;
 517	u8	direct_io;
 518	struct list_head chain_list;
 519	struct list_head tracker_list;
 520};
 521
 522/**
 523 * struct request_tracker - firmware request tracker
 524 * @smid: system message id
 525 * @cb_idx: callback index
 526 * @tracker_list: list of free request (ioc->free_list)
 527 */
 528struct request_tracker {
 529	u16	smid;
 530	u8	cb_idx;
 531	struct list_head tracker_list;
 532};
 533
 534/**
 535 * struct _tr_list - target reset list
 536 * @handle: device handle
 537 * @state: state machine
 538 */
 539struct _tr_list {
 540	struct list_head list;
 541	u16	handle;
 542	u16	state;
 543};
 544
 545typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
 546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 547/* IOC Facts and Port Facts converted from little endian to cpu */
 548union mpi2_version_union {
 549	MPI2_VERSION_STRUCT		Struct;
 550	u32				Word;
 551};
 552
 553struct mpt2sas_facts {
 554	u16			MsgVersion;
 555	u16			HeaderVersion;
 556	u8			IOCNumber;
 557	u8			VP_ID;
 558	u8			VF_ID;
 559	u16			IOCExceptions;
 560	u16			IOCStatus;
 561	u32			IOCLogInfo;
 562	u8			MaxChainDepth;
 563	u8			WhoInit;
 564	u8			NumberOfPorts;
 565	u8			MaxMSIxVectors;
 566	u16			RequestCredit;
 567	u16			ProductID;
 568	u32			IOCCapabilities;
 569	union mpi2_version_union	FWVersion;
 570	u16			IOCRequestFrameSize;
 571	u16			Reserved3;
 572	u16			MaxInitiators;
 573	u16			MaxTargets;
 574	u16			MaxSasExpanders;
 575	u16			MaxEnclosures;
 576	u16			ProtocolFlags;
 577	u16			HighPriorityCredit;
 578	u16			MaxReplyDescriptorPostQueueDepth;
 579	u8			ReplyFrameSize;
 580	u8			MaxVolumes;
 581	u16			MaxDevHandle;
 582	u16			MaxPersistentEntries;
 583	u16			MinDevHandle;
 584};
 585
 586struct mpt2sas_port_facts {
 587	u8			PortNumber;
 588	u8			VP_ID;
 589	u8			VF_ID;
 590	u8			PortType;
 591	u16			MaxPostedCmdBuffers;
 592};
 593
 594/**
 595 * enum mutex_type - task management mutex type
 596 * @TM_MUTEX_OFF: mutex is not required becuase calling function is acquiring it
 597 * @TM_MUTEX_ON: mutex is required
 598 */
 599enum mutex_type {
 600	TM_MUTEX_OFF = 0,
 601	TM_MUTEX_ON = 1,
 602};
 603
 
 604/**
 605 * struct MPT2SAS_ADAPTER - per adapter struct
 606 * @list: ioc_list
 607 * @shost: shost object
 608 * @id: unique adapter id
 609 * @pci_irq: irq number
 610 * @name: generic ioc string
 611 * @tmp_string: tmp string used for logging
 612 * @pdev: pci pdev object
 613 * @chip: memory mapped register space
 614 * @chip_phys: physical addrss prior to mapping
 615 * @logging_level: see mpt2sas_debug.h
 616 * @fwfault_debug: debuging FW timeouts
 617 * @ir_firmware: IR firmware present
 618 * @bars: bitmask of BAR's that must be configured
 619 * @mask_interrupts: ignore interrupt
 620 * @fault_reset_work_q_name: fw fault work queue
 621 * @fault_reset_work_q: ""
 622 * @fault_reset_work: ""
 623 * @firmware_event_name: fw event work queue
 624 * @firmware_event_thread: ""
 625 * @fw_events_off: flag to turn off fw event handling
 626 * @fw_event_lock:
 627 * @fw_event_list: list of fw events
 628 * @aen_event_read_flag: event log was read
 629 * @broadcast_aen_busy: broadcast aen waiting to be serviced
 630 * @shost_recovery: host reset in progress
 631 * @ioc_reset_in_progress_lock:
 632 * @ioc_link_reset_in_progress: phy/hard reset in progress
 633 * @ignore_loginfos: ignore loginfos during task management
 634 * @remove_host: flag for when driver unloads, to avoid sending dev resets
 635 * @pci_error_recovery: flag to prevent ioc access until slot reset completes
 636 * @wait_for_port_enable_to_complete:
 
 
 
 
 
 637 * @msix_enable: flag indicating msix is enabled
 638 * @msix_vector_count: number msix vectors
 639 * @msix_table: virt address to the msix table
 640 * @msix_table_backup: backup msix table
 
 641 * @scsi_io_cb_idx: shost generated commands
 642 * @tm_cb_idx: task management commands
 643 * @scsih_cb_idx: scsih internal commands
 644 * @transport_cb_idx: transport internal commands
 645 * @ctl_cb_idx: clt internal commands
 646 * @base_cb_idx: base internal commands
 647 * @config_cb_idx: base internal commands
 648 * @tm_tr_cb_idx : device removal target reset handshake
 649 * @tm_tr_volume_cb_idx : volume removal target reset
 650 * @base_cmds:
 651 * @transport_cmds:
 652 * @scsih_cmds:
 653 * @tm_cmds:
 654 * @ctl_cmds:
 655 * @config_cmds:
 656 * @base_add_sg_single: handler for either 32/64 bit sgl's
 657 * @event_type: bits indicating which events to log
 658 * @event_context: unique id for each logged event
 659 * @event_log: event log pointer
 660 * @event_masks: events that are masked
 661 * @facts: static facts data
 662 * @pfacts: static port facts data
 663 * @manu_pg0: static manufacturing page 0
 664 * @manu_pg10: static manufacturing page 10
 665 * @bios_pg2: static bios page 2
 666 * @bios_pg3: static bios page 3
 667 * @ioc_pg8: static ioc page 8
 668 * @iounit_pg0: static iounit page 0
 669 * @iounit_pg1: static iounit page 1
 670 * @sas_hba: sas host object
 671 * @sas_expander_list: expander object list
 672 * @sas_node_lock:
 673 * @sas_device_list: sas device object list
 674 * @sas_device_init_list: sas device object list (used only at init time)
 675 * @sas_device_lock:
 676 * @io_missing_delay: time for IO completed by fw when PDR enabled
 677 * @device_missing_delay: time for device missing by fw when PDR enabled
 678 * @sas_id : used for setting volume target IDs
 
 679 * @pd_handles : bitmask for PD handles
 680 * @pd_handles_sz : size of pd_handle bitmask
 681 * @config_page_sz: config page size
 682 * @config_page: reserve memory for config page payload
 683 * @config_page_dma:
 684 * @hba_queue_depth: hba request queue depth
 685 * @sge_size: sg element size for either 32/64 bit
 686 * @scsiio_depth: SCSI_IO queue depth
 687 * @request_sz: per request frame size
 688 * @request: pool of request frames
 689 * @request_dma:
 690 * @request_dma_sz:
 691 * @scsi_lookup: firmware request tracker list
 692 * @scsi_lookup_lock:
 693 * @free_list: free list of request
 694 * @chain: pool of chains
 695 * @pending_io_count:
 696 * @reset_wq:
 697 * @chain_dma:
 698 * @max_sges_in_main_message: number sg elements in main message
 699 * @max_sges_in_chain_message: number sg elements per chain
 700 * @chains_needed_per_io: max chains per io
 701 * @chain_offset_value_for_main_message: location 1st sg in main
 702 * @chain_depth: total chains allocated
 703 * @hi_priority_smid:
 704 * @hi_priority:
 705 * @hi_priority_dma:
 706 * @hi_priority_depth:
 707 * @hpr_lookup:
 708 * @hpr_free_list:
 709 * @internal_smid:
 710 * @internal:
 711 * @internal_dma:
 712 * @internal_depth:
 713 * @internal_lookup:
 714 * @internal_free_list:
 715 * @sense: pool of sense
 716 * @sense_dma:
 717 * @sense_dma_pool:
 718 * @reply_depth: hba reply queue depth:
 719 * @reply_sz: per reply frame size:
 720 * @reply: pool of replys:
 721 * @reply_dma:
 722 * @reply_dma_pool:
 723 * @reply_free_queue_depth: reply free depth
 724 * @reply_free: pool for reply free queue (32 bit addr)
 725 * @reply_free_dma:
 726 * @reply_free_dma_pool:
 727 * @reply_free_host_index: tail index in pool to insert free replys
 728 * @reply_post_queue_depth: reply post queue depth
 729 * @reply_post_free: pool for reply post (64bit descriptor)
 730 * @reply_post_free_dma:
 731 * @reply_post_free_dma_pool:
 
 732 * @reply_post_host_index: head index in the pool where FW completes IO
 733 * @delayed_tr_list: target reset link list
 734 * @delayed_tr_volume_list: volume target reset link list
 735 */
 736struct MPT2SAS_ADAPTER {
 737	struct list_head list;
 738	struct Scsi_Host *shost;
 739	u8		id;
 740	u32		pci_irq;
 741	char		name[MPT_NAME_LENGTH];
 742	char		tmp_string[MPT_STRING_LENGTH];
 743	struct pci_dev	*pdev;
 744	Mpi2SystemInterfaceRegs_t __iomem *chip;
 745	resource_size_t	chip_phys;
 746	int		logging_level;
 747	int		fwfault_debug;
 748	u8		ir_firmware;
 749	int		bars;
 750	u8		mask_interrupts;
 751
 752	/* fw fault handler */
 753	char		fault_reset_work_q_name[20];
 754	struct workqueue_struct *fault_reset_work_q;
 755	struct delayed_work fault_reset_work;
 756
 757	/* fw event handler */
 758	char		firmware_event_name[20];
 759	struct workqueue_struct	*firmware_event_thread;
 760	spinlock_t	fw_event_lock;
 761	struct list_head fw_event_list;
 762
 763	 /* misc flags */
 764	int		aen_event_read_flag;
 765	u8		broadcast_aen_busy;
 766	u16		broadcast_aen_pending;
 767	u8		shost_recovery;
 768
 769	struct mutex	reset_in_progress_mutex;
 770	struct completion	shost_recovery_done;
 771	spinlock_t 	ioc_reset_in_progress_lock;
 772	u8		ioc_link_reset_in_progress;
 773	int		ioc_reset_in_progress_status;
 774
 775	u8		ignore_loginfos;
 776	u8		remove_host;
 777	u8		pci_error_recovery;
 778	u8		wait_for_port_enable_to_complete;
 
 
 
 
 
 
 779
 780	u8		msix_enable;
 781	u16		msix_vector_count;
 782	u32		*msix_table;
 783	u32		*msix_table_backup;
 
 784	u32		ioc_reset_count;
 
 
 785
 786	/* internal commands, callback index */
 787	u8		scsi_io_cb_idx;
 788	u8		tm_cb_idx;
 789	u8		transport_cb_idx;
 790	u8		scsih_cb_idx;
 791	u8		ctl_cb_idx;
 792	u8		base_cb_idx;
 
 793	u8		config_cb_idx;
 794	u8		tm_tr_cb_idx;
 795	u8		tm_tr_volume_cb_idx;
 796	u8		tm_sas_control_cb_idx;
 797	struct _internal_cmd base_cmds;
 
 798	struct _internal_cmd transport_cmds;
 799	struct _internal_cmd scsih_cmds;
 800	struct _internal_cmd tm_cmds;
 801	struct _internal_cmd ctl_cmds;
 802	struct _internal_cmd config_cmds;
 803
 804	MPT_ADD_SGE	base_add_sg_single;
 805
 806	/* event log */
 807	u32		event_type[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
 808	u32		event_context;
 809	void		*event_log;
 810	u32		event_masks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
 811
 812	/* static config pages */
 813	struct mpt2sas_facts facts;
 814	struct mpt2sas_port_facts *pfacts;
 815	Mpi2ManufacturingPage0_t manu_pg0;
 816	Mpi2BiosPage2_t	bios_pg2;
 817	Mpi2BiosPage3_t	bios_pg3;
 818	Mpi2IOCPage8_t ioc_pg8;
 819	Mpi2IOUnitPage0_t iounit_pg0;
 820	Mpi2IOUnitPage1_t iounit_pg1;
 821
 822	struct _boot_device req_boot_device;
 823	struct _boot_device req_alt_boot_device;
 824	struct _boot_device current_boot_device;
 825
 826	/* sas hba, expander, and device list */
 827	struct _sas_node sas_hba;
 828	struct list_head sas_expander_list;
 829	spinlock_t	sas_node_lock;
 830	struct list_head sas_device_list;
 831	struct list_head sas_device_init_list;
 832	spinlock_t	sas_device_lock;
 833	struct list_head raid_device_list;
 834	spinlock_t	raid_device_lock;
 835	u8		io_missing_delay;
 836	u16		device_missing_delay;
 837	int		sas_id;
 838
 839	void		*pd_handles;
 840	u16		pd_handles_sz;
 841
 842	/* config page */
 843	u16		config_page_sz;
 844	void 		*config_page;
 845	dma_addr_t	config_page_dma;
 846
 847	/* scsiio request */
 848	u16		hba_queue_depth;
 849	u16		sge_size;
 850	u16 		scsiio_depth;
 851	u16		request_sz;
 852	u8		*request;
 853	dma_addr_t	request_dma;
 854	u32		request_dma_sz;
 855	struct scsiio_tracker *scsi_lookup;
 856	ulong		scsi_lookup_pages;
 857	spinlock_t 	scsi_lookup_lock;
 858	struct list_head free_list;
 859	int		pending_io_count;
 860	wait_queue_head_t reset_wq;
 861
 862	/* chain */
 863	struct chain_tracker *chain_lookup;
 864	struct list_head free_chain_list;
 865	struct dma_pool *chain_dma_pool;
 866	ulong		chain_pages;
 867	u16 		max_sges_in_main_message;
 868	u16		max_sges_in_chain_message;
 869	u16		chains_needed_per_io;
 870	u16		chain_offset_value_for_main_message;
 871	u32		chain_depth;
 872
 873	/* hi-priority queue */
 874	u16		hi_priority_smid;
 875	u8		*hi_priority;
 876	dma_addr_t	hi_priority_dma;
 877	u16		hi_priority_depth;
 878	struct request_tracker *hpr_lookup;
 879	struct list_head hpr_free_list;
 880
 881	/* internal queue */
 882	u16		internal_smid;
 883	u8		*internal;
 884	dma_addr_t	internal_dma;
 885	u16		internal_depth;
 886	struct request_tracker *internal_lookup;
 887	struct list_head internal_free_list;
 888
 889	/* sense */
 890	u8		*sense;
 891	dma_addr_t	sense_dma;
 892	struct dma_pool *sense_dma_pool;
 893
 894	/* reply */
 895	u16		reply_sz;
 896	u8		*reply;
 897	dma_addr_t	reply_dma;
 898	u32		reply_dma_max_address;
 899	u32		reply_dma_min_address;
 900	struct dma_pool *reply_dma_pool;
 901
 902	/* reply free queue */
 903	u16 		reply_free_queue_depth;
 904	__le32		*reply_free;
 905	dma_addr_t	reply_free_dma;
 906	struct dma_pool *reply_free_dma_pool;
 907	u32		reply_free_host_index;
 908
 909	/* reply post queue */
 910	u16 		reply_post_queue_depth;
 911	Mpi2ReplyDescriptorsUnion_t *reply_post_free;
 912	dma_addr_t	reply_post_free_dma;
 913	struct dma_pool *reply_post_free_dma_pool;
 914	u32		reply_post_host_index;
 
 915
 916	struct list_head delayed_tr_list;
 917	struct list_head delayed_tr_volume_list;
 918
 919	/* diag buffer support */
 920	u8		*diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT];
 921	u32		diag_buffer_sz[MPI2_DIAG_BUF_TYPE_COUNT];
 922	dma_addr_t	diag_buffer_dma[MPI2_DIAG_BUF_TYPE_COUNT];
 923	u8		diag_buffer_status[MPI2_DIAG_BUF_TYPE_COUNT];
 924	u32		unique_id[MPI2_DIAG_BUF_TYPE_COUNT];
 925	Mpi2ManufacturingPage10_t manu_pg10;
 926	u32		product_specific[MPI2_DIAG_BUF_TYPE_COUNT][23];
 927	u32		diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT];
 928	u32		ring_buffer_offset;
 929	u32		ring_buffer_sz;
 930	u8		is_warpdrive;
 931	u8		hide_ir_msg;
 932	u8		mfg_pg10_hide_flag;
 933	u8		hide_drives;
 934
 935};
 936
 937typedef u8 (*MPT_CALLBACK)(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
 938    u32 reply);
 939
 940
 941/* base shared API */
 942extern struct list_head mpt2sas_ioc_list;
 943void mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc);
 944void mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc);
 945
 946int mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc);
 947void mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc);
 948int mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc);
 949void mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc);
 950int mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
 951    enum reset_type type);
 952
 953void *mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid);
 954void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid);
 955void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr);
 956__le32 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc,
 957    u16 smid);
 
 958
 959/* hi-priority queue */
 960u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
 961u16 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
 962    struct scsi_cmnd *scmd);
 963
 964u16 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
 965void mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid);
 966void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid,
 967    u16 handle);
 968void mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid);
 969void mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
 970    u16 io_index);
 971void mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid);
 972void mpt2sas_base_initialize_callback_handler(void);
 973u8 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func);
 974void mpt2sas_base_release_callback_handler(u8 cb_idx);
 975
 976u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
 977    u32 reply);
 
 
 978void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr);
 979
 980u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked);
 981
 982void mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code);
 983int mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
 984    Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t
 985    *mpi_request);
 986int mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
 987    Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request);
 988void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type);
 989
 990void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc);
 991
 
 
 
 
 
 992/* scsih shared API */
 993u8 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
 994    u32 reply);
 995int mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle,
 996	uint channel, uint id, uint lun, u8 type, u16 smid_task,
 997	ulong timeout, unsigned long serial_number, enum mutex_type m_type);
 998void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
 999void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
1000void mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
1001void mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
 
1002struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc,
1003    u16 handle);
1004struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
1005    *ioc, u64 sas_address);
1006struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address(
1007    struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
1008
 
 
1009void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
1010
1011/* config shared API */
1012u8 mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1013    u32 reply);
1014int mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys);
1015int mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
1016    Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page);
1017int mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc,
1018    Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page);
1019int mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1020    *mpi_reply, Mpi2BiosPage2_t *config_page);
1021int mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1022    *mpi_reply, Mpi2BiosPage3_t *config_page);
1023int mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1024    *mpi_reply, Mpi2IOUnitPage0_t *config_page);
1025int mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1026    *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle);
1027int mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1028    *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle);
1029int mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1030    *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz);
1031int mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1032    *mpi_reply, Mpi2IOUnitPage1_t *config_page);
1033int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1034    *mpi_reply, Mpi2IOUnitPage1_t *config_page);
 
 
1035int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1036    *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
1037int mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
1038    Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
1039int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1040    *mpi_reply, Mpi2IOCPage8_t *config_page);
1041int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1042    *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle);
1043int mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1044    *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle);
1045int mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1046    *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle);
1047int mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1048    *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number);
1049int mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1050    *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number);
1051int mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1052    *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle);
1053int mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 *num_pds);
1054int mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1055    *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz);
1056int mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1057    *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
1058    u32 form_specific);
1059int mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1060    u16 *volume_handle);
1061int mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle,
1062    u64 *wwid);
1063/* ctl shared API */
1064extern struct device_attribute *mpt2sas_host_attrs[];
1065extern struct device_attribute *mpt2sas_dev_attrs[];
1066void mpt2sas_ctl_init(void);
1067void mpt2sas_ctl_exit(void);
1068u8 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1069    u32 reply);
1070void mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
1071u8 mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
1072    u32 reply);
1073void mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
1074    Mpi2EventNotificationReply_t *mpi_reply);
1075
1076void mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc,
1077	u8 bits_to_regsiter);
1078
1079/* transport shared API */
1080u8 mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1081    u32 reply);
1082struct _sas_port *mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc,
1083     u16 handle, u64 sas_address);
1084void mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
1085     u64 sas_address_parent);
1086int mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
1087    *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev);
1088int mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
1089    *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev);
1090void mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc,
1091     u64 sas_address, u16 handle, u8 phy_number, u8 link_rate);
1092extern struct sas_function_template mpt2sas_transport_functions;
1093extern struct scsi_transport_template *mpt2sas_transport_template;
1094extern int scsi_internal_device_block(struct scsi_device *sdev);
1095extern u8 mpt2sas_stm_zero_smid_handler(struct MPT2SAS_ADAPTER *ioc,
1096    u8 msix_index, u32 reply);
1097extern int scsi_internal_device_unblock(struct scsi_device *sdev);
 
1098
1099#endif /* MPT2SAS_BASE_H_INCLUDED */
v3.15
   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-2013  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		"16.100.00.00"
  73#define MPT2SAS_MAJOR_VERSION		16
  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
 107#define	 CAN_SLEEP			1
 108#define  NO_SLEEP			0
 109
 110#define INTERNAL_CMDS_COUNT		10	/* reserved cmds */
 111
 112#define MPI2_HIM_MASK			0xFFFFFFFF /* mask every bit*/
 113
 114#define MPT2SAS_INVALID_DEVICE_HANDLE	0xFFFF
 115
 116
 117/*
 118 * reset phases
 119 */
 120#define MPT2_IOC_PRE_RESET		1 /* prior to host reset */
 121#define MPT2_IOC_AFTER_RESET		2 /* just after host reset */
 122#define MPT2_IOC_DONE_RESET		3 /* links re-initialized */
 123
 124/*
 125 * logging format
 126 */
 127#define MPT2SAS_FMT			"%s: "
 128#define MPT2SAS_INFO_FMT		KERN_INFO MPT2SAS_FMT
 129#define MPT2SAS_NOTE_FMT		KERN_NOTICE MPT2SAS_FMT
 130#define MPT2SAS_WARN_FMT		KERN_WARNING MPT2SAS_FMT
 131#define MPT2SAS_ERR_FMT			KERN_ERR MPT2SAS_FMT
 132
 133/*
 134 * Dell HBA branding
 135 */
 136#define MPT2SAS_DELL_BRANDING_SIZE                 32
 137
 138#define MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING        "Dell 6Gbps SAS HBA"
 139#define MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING    "Dell PERC H200 Adapter"
 140#define MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING "Dell PERC H200 Integrated"
 141#define MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING    "Dell PERC H200 Modular"
 142#define MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING   "Dell PERC H200 Embedded"
 143#define MPT2SAS_DELL_PERC_H200_BRANDING            "Dell PERC H200"
 144#define MPT2SAS_DELL_6GBPS_SAS_BRANDING            "Dell 6Gbps SAS"
 145
 146/*
 147 * Dell HBA SSDIDs
 148 */
 149#define MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID           0x1F1C
 150#define MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID       0x1F1D
 151#define MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID    0x1F1E
 152#define MPT2SAS_DELL_PERC_H200_MODULAR_SSDID       0x1F1F
 153#define MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID      0x1F20
 154#define MPT2SAS_DELL_PERC_H200_SSDID               0x1F21
 155#define MPT2SAS_DELL_6GBPS_SAS_SSDID               0x1F22
 156
 157/*
 158 * Intel HBA branding
 159 */
 160#define MPT2SAS_INTEL_RMS25JB080_BRANDING    \
 161				"Intel(R) Integrated RAID Module RMS25JB080"
 162#define MPT2SAS_INTEL_RMS25JB040_BRANDING    \
 163				"Intel(R) Integrated RAID Module RMS25JB040"
 164#define MPT2SAS_INTEL_RMS25KB080_BRANDING    \
 165				"Intel(R) Integrated RAID Module RMS25KB080"
 166#define MPT2SAS_INTEL_RMS25KB040_BRANDING    \
 167				"Intel(R) Integrated RAID Module RMS25KB040"
 168#define MPT2SAS_INTEL_RMS25LB040_BRANDING	\
 169				"Intel(R) Integrated RAID Module RMS25LB040"
 170#define MPT2SAS_INTEL_RMS25LB080_BRANDING	\
 171				"Intel(R) Integrated RAID Module RMS25LB080"
 172#define MPT2SAS_INTEL_RMS2LL080_BRANDING	\
 173				"Intel Integrated RAID Module RMS2LL080"
 174#define MPT2SAS_INTEL_RMS2LL040_BRANDING	\
 175				"Intel Integrated RAID Module RMS2LL040"
 176#define MPT2SAS_INTEL_RS25GB008_BRANDING       \
 177				"Intel(R) RAID Controller RS25GB008"
 178#define MPT2SAS_INTEL_SSD910_BRANDING          \
 179				"Intel(R) SSD 910 Series"
 180/*
 181 * Intel HBA SSDIDs
 182 */
 183#define MPT2SAS_INTEL_RMS25JB080_SSDID         0x3516
 184#define MPT2SAS_INTEL_RMS25JB040_SSDID         0x3517
 185#define MPT2SAS_INTEL_RMS25KB080_SSDID         0x3518
 186#define MPT2SAS_INTEL_RMS25KB040_SSDID         0x3519
 187#define MPT2SAS_INTEL_RMS25LB040_SSDID         0x351A
 188#define MPT2SAS_INTEL_RMS25LB080_SSDID         0x351B
 189#define MPT2SAS_INTEL_RMS2LL080_SSDID          0x350E
 190#define MPT2SAS_INTEL_RMS2LL040_SSDID          0x350F
 191#define MPT2SAS_INTEL_RS25GB008_SSDID          0x3000
 192#define MPT2SAS_INTEL_SSD910_SSDID             0x3700
 193
 194/*
 195 * HP HBA branding
 196 */
 197#define MPT2SAS_HP_3PAR_SSVID                0x1590
 198#define MPT2SAS_HP_2_4_INTERNAL_BRANDING        "HP H220 Host Bus Adapter"
 199#define MPT2SAS_HP_2_4_EXTERNAL_BRANDING        "HP H221 Host Bus Adapter"
 200#define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING "HP H222 Host Bus Adapter"
 201#define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING    "HP H220i Host Bus Adapter"
 202#define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING    "HP H210i Host Bus Adapter"
 203
 204/*
 205 * HO HBA SSDIDs
 206 */
 207#define MPT2SAS_HP_2_4_INTERNAL_SSDID            0x0041
 208#define MPT2SAS_HP_2_4_EXTERNAL_SSDID            0x0042
 209#define MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID    0x0043
 210#define MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID        0x0044
 211#define MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID        0x0046
 212
 213/*
 214 *  WarpDrive Specific Log codes
 215 */
 216
 217#define MPT2_WARPDRIVE_LOGENTRY		(0x8002)
 218#define MPT2_WARPDRIVE_LC_SSDT		(0x41)
 219#define MPT2_WARPDRIVE_LC_SSDLW		(0x43)
 220#define MPT2_WARPDRIVE_LC_SSDLF		(0x44)
 221#define MPT2_WARPDRIVE_LC_BRMF		(0x4D)
 222
 223/*
 224 * per target private data
 225 */
 226#define MPT_TARGET_FLAGS_RAID_COMPONENT	0x01
 227#define MPT_TARGET_FLAGS_VOLUME		0x02
 228#define MPT_TARGET_FLAGS_DELETED	0x04
 229
 230/**
 231 * struct MPT2SAS_TARGET - starget private hostdata
 232 * @starget: starget object
 233 * @sas_address: target sas address
 234 * @raid_device: raid_device pointer to access volume data
 235 * @handle: device handle
 236 * @num_luns: number luns
 237 * @flags: MPT_TARGET_FLAGS_XXX flags
 238 * @deleted: target flaged for deletion
 239 * @tm_busy: target is busy with TM request.
 240 */
 241struct MPT2SAS_TARGET {
 242	struct scsi_target *starget;
 243	u64	sas_address;
 244	struct _raid_device *raid_device;
 245	u16	handle;
 246	int	num_luns;
 247	u32	flags;
 248	u8	deleted;
 249	u8	tm_busy;
 250};
 251
 252
 253/*
 254 * per device private data
 255 */
 256#define MPT_DEVICE_FLAGS_INIT		0x01
 257#define MPT_DEVICE_TLR_ON		0x02
 258
 259/**
 260 * struct MPT2SAS_DEVICE - sdev private hostdata
 261 * @sas_target: starget private hostdata
 262 * @lun: lun number
 263 * @flags: MPT_DEVICE_XXX flags
 264 * @configured_lun: lun is configured
 265 * @block: device is in SDEV_BLOCK state
 266 * @tlr_snoop_check: flag used in determining whether to disable TLR
 267 */
 268
 269/* OEM Identifiers */
 270#define MFG10_OEM_ID_INVALID                   (0x00000000)
 271#define MFG10_OEM_ID_DELL                      (0x00000001)
 272#define MFG10_OEM_ID_FSC                       (0x00000002)
 273#define MFG10_OEM_ID_SUN                       (0x00000003)
 274#define MFG10_OEM_ID_IBM                       (0x00000004)
 275
 276/* GENERIC Flags 0*/
 277#define MFG10_GF0_OCE_DISABLED                 (0x00000001)
 278#define MFG10_GF0_R1E_DRIVE_COUNT              (0x00000002)
 279#define MFG10_GF0_R10_DISPLAY                  (0x00000004)
 280#define MFG10_GF0_SSD_DATA_SCRUB_DISABLE       (0x00000008)
 281#define MFG10_GF0_SINGLE_DRIVE_R0              (0x00000010)
 282
 283/* OEM Specific Flags will come from OEM specific header files */
 284typedef struct _MPI2_CONFIG_PAGE_MAN_10 {
 285    MPI2_CONFIG_PAGE_HEADER Header;                                 /* 00h */
 286    U8                      OEMIdentifier;                          /* 04h */
 287    U8                      Reserved1;                              /* 05h */
 288    U16                     Reserved2;                              /* 08h */
 289    U32                     Reserved3;                              /* 0Ch */
 290    U32                     GenericFlags0;                          /* 10h */
 291    U32                     GenericFlags1;                          /* 14h */
 292    U32                     Reserved4;                              /* 18h */
 293    U32                     OEMSpecificFlags0;                      /* 1Ch */
 294    U32                     OEMSpecificFlags1;                      /* 20h */
 295    U32                     Reserved5[18];                          /* 24h-60h*/
 296} MPI2_CONFIG_PAGE_MAN_10,
 297  MPI2_POINTER PTR_MPI2_CONFIG_PAGE_MAN_10,
 298  Mpi2ManufacturingPage10_t, MPI2_POINTER pMpi2ManufacturingPage10_t;
 299
 300#define MFG_PAGE10_HIDE_SSDS_MASK	(0x00000003)
 301#define MFG_PAGE10_HIDE_ALL_DISKS	(0x00)
 302#define MFG_PAGE10_EXPOSE_ALL_DISKS	(0x01)
 303#define MFG_PAGE10_HIDE_IF_VOL_PRESENT	(0x02)
 304
 305
 306struct MPT2SAS_DEVICE {
 307	struct MPT2SAS_TARGET *sas_target;
 308	unsigned int	lun;
 309	u32	flags;
 310	u8	configured_lun;
 311	u8	block;
 312	u8	tlr_snoop_check;
 313};
 314
 315#define MPT2_CMD_NOT_USED	0x8000	/* free */
 316#define MPT2_CMD_COMPLETE	0x0001	/* completed */
 317#define MPT2_CMD_PENDING	0x0002	/* pending */
 318#define MPT2_CMD_REPLY_VALID	0x0004	/* reply is valid */
 319#define MPT2_CMD_RESET		0x0008	/* host reset dropped the command */
 320
 321/**
 322 * struct _internal_cmd - internal commands struct
 323 * @mutex: mutex
 324 * @done: completion
 325 * @reply: reply message pointer
 326 * @sense: sense data
 327 * @status: MPT2_CMD_XXX status
 328 * @smid: system message id
 329 */
 330struct _internal_cmd {
 331	struct mutex mutex;
 332	struct completion done;
 333	void 	*reply;
 334	void	*sense;
 335	u16	status;
 336	u16	smid;
 337};
 338
 339
 340/**
 341 * struct _sas_device - attached device information
 342 * @list: sas device list
 343 * @starget: starget object
 344 * @sas_address: device sas address
 345 * @device_name: retrieved from the SAS IDENTIFY frame.
 346 * @handle: device handle
 347 * @sas_address_parent: sas address of parent expander or sas host
 348 * @enclosure_handle: enclosure handle
 349 * @enclosure_logical_id: enclosure logical identifier
 350 * @volume_handle: volume handle (valid when hidden raid member)
 351 * @volume_wwid: volume unique identifier
 352 * @device_info: bitfield provides detailed info about the device
 353 * @id: target id
 354 * @channel: target channel
 355 * @slot: number number
 356 * @phy: phy identifier provided in sas device page 0
 357 * @responding: used in _scsih_sas_device_mark_responding
 358 */
 359struct _sas_device {
 360	struct list_head list;
 361	struct scsi_target *starget;
 362	u64	sas_address;
 363	u64	device_name;
 364	u16	handle;
 365	u64	sas_address_parent;
 366	u16	enclosure_handle;
 367	u64	enclosure_logical_id;
 368	u16	volume_handle;
 369	u64	volume_wwid;
 370	u32	device_info;
 371	int	id;
 372	int	channel;
 373	u16	slot;
 374	u8	phy;
 375	u8	responding;
 376};
 377
 378/**
 379 * struct _raid_device - raid volume link list
 380 * @list: sas device list
 381 * @starget: starget object
 382 * @sdev: scsi device struct (volumes are single lun)
 383 * @wwid: unique identifier for the volume
 384 * @handle: device handle
 385 * @block_size: Block size of the volume
 386 * @id: target id
 387 * @channel: target channel
 388 * @volume_type: the raid level
 389 * @device_info: bitfield provides detailed info about the hidden components
 390 * @num_pds: number of hidden raid components
 391 * @responding: used in _scsih_raid_device_mark_responding
 392 * @percent_complete: resync percent complete
 393 * @direct_io_enabled: Whether direct io to PDs are allowed or not
 394 * @stripe_exponent: X where 2powX is the stripe sz in blocks
 395 * @block_exponent: X where 2powX is the block sz in bytes
 396 * @max_lba: Maximum number of LBA in the volume
 397 * @stripe_sz: Stripe Size of the volume
 398 * @device_info: Device info of the volume member disk
 399 * @pd_handle: Array of handles of the physical drives for direct I/O in le16
 400 */
 401#define MPT_MAX_WARPDRIVE_PDS		8
 402struct _raid_device {
 403	struct list_head list;
 404	struct scsi_target *starget;
 405	struct scsi_device *sdev;
 406	u64	wwid;
 407	u16	handle;
 408	u16	block_sz;
 409	int	id;
 410	int	channel;
 411	u8	volume_type;
 412	u8	num_pds;
 413	u8	responding;
 414	u8	percent_complete;
 415	u8	direct_io_enabled;
 416	u8	stripe_exponent;
 417	u8	block_exponent;
 418	u64	max_lba;
 419	u32	stripe_sz;
 420	u32	device_info;
 421	u16	pd_handle[MPT_MAX_WARPDRIVE_PDS];
 422};
 423
 424/**
 425 * struct _boot_device - boot device info
 426 * @is_raid: flag to indicate whether this is volume
 427 * @device: holds pointer for either struct _sas_device or
 428 *     struct _raid_device
 429 */
 430struct _boot_device {
 431	u8 is_raid;
 432	void *device;
 433};
 434
 435/**
 436 * struct _sas_port - wide/narrow sas port information
 437 * @port_list: list of ports belonging to expander
 438 * @num_phys: number of phys belonging to this port
 439 * @remote_identify: attached device identification
 440 * @rphy: sas transport rphy object
 441 * @port: sas transport wide/narrow port object
 442 * @phy_list: _sas_phy list objects belonging to this port
 443 */
 444struct _sas_port {
 445	struct list_head port_list;
 446	u8	num_phys;
 447	struct sas_identify remote_identify;
 448	struct sas_rphy *rphy;
 449	struct sas_port *port;
 450	struct list_head phy_list;
 451};
 452
 453/**
 454 * struct _sas_phy - phy information
 455 * @port_siblings: list of phys belonging to a port
 456 * @identify: phy identification
 457 * @remote_identify: attached device identification
 458 * @phy: sas transport phy object
 459 * @phy_id: unique phy id
 460 * @handle: device handle for this phy
 461 * @attached_handle: device handle for attached device
 462 * @phy_belongs_to_port: port has been created for this phy
 463 */
 464struct _sas_phy {
 465	struct list_head port_siblings;
 466	struct sas_identify identify;
 467	struct sas_identify remote_identify;
 468	struct sas_phy *phy;
 469	u8	phy_id;
 470	u16	handle;
 471	u16	attached_handle;
 472	u8	phy_belongs_to_port;
 473};
 474
 475/**
 476 * struct _sas_node - sas_host/expander information
 477 * @list: list of expanders
 478 * @parent_dev: parent device class
 479 * @num_phys: number phys belonging to this sas_host/expander
 480 * @sas_address: sas address of this sas_host/expander
 481 * @handle: handle for this sas_host/expander
 482 * @sas_address_parent: sas address of parent expander or sas host
 483 * @enclosure_handle: handle for this a member of an enclosure
 484 * @device_info: bitwise defining capabilities of this sas_host/expander
 485 * @responding: used in _scsih_expander_device_mark_responding
 486 * @phy: a list of phys that make up this sas_host/expander
 487 * @sas_port_list: list of ports attached to this sas_host/expander
 488 */
 489struct _sas_node {
 490	struct list_head list;
 491	struct device *parent_dev;
 492	u8	num_phys;
 493	u64	sas_address;
 494	u16	handle;
 495	u64	sas_address_parent;
 496	u16	enclosure_handle;
 497	u64	enclosure_logical_id;
 498	u8	responding;
 499	struct	_sas_phy *phy;
 500	struct list_head sas_port_list;
 501};
 502
 503/**
 504 * enum reset_type - reset state
 505 * @FORCE_BIG_HAMMER: issue diagnostic reset
 506 * @SOFT_RESET: issue message_unit_reset, if fails to to big hammer
 507 */
 508enum reset_type {
 509	FORCE_BIG_HAMMER,
 510	SOFT_RESET,
 511};
 512
 513/**
 514 * struct chain_tracker - firmware chain tracker
 515 * @chain_buffer: chain buffer
 516 * @chain_buffer_dma: physical address
 517 * @tracker_list: list of free request (ioc->free_chain_list)
 518 */
 519struct chain_tracker {
 520	void *chain_buffer;
 521	dma_addr_t chain_buffer_dma;
 522	struct list_head tracker_list;
 523};
 524
 525/**
 526 * struct scsiio_tracker - scsi mf request tracker
 527 * @smid: system message id
 528 * @scmd: scsi request pointer
 529 * @cb_idx: callback index
 530 * @direct_io: To indicate whether I/O is direct (WARPDRIVE)
 531 * @chain_list: list of chains associated to this IO
 532 * @tracker_list: list of free request (ioc->free_list)
 533 */
 534struct scsiio_tracker {
 535	u16	smid;
 536	struct scsi_cmnd *scmd;
 537	u8	cb_idx;
 538	u8	direct_io;
 539	struct list_head chain_list;
 540	struct list_head tracker_list;
 541};
 542
 543/**
 544 * struct request_tracker - firmware request tracker
 545 * @smid: system message id
 546 * @cb_idx: callback index
 547 * @tracker_list: list of free request (ioc->free_list)
 548 */
 549struct request_tracker {
 550	u16	smid;
 551	u8	cb_idx;
 552	struct list_head tracker_list;
 553};
 554
 555/**
 556 * struct _tr_list - target reset list
 557 * @handle: device handle
 558 * @state: state machine
 559 */
 560struct _tr_list {
 561	struct list_head list;
 562	u16	handle;
 563	u16	state;
 564};
 565
 566typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
 567
 568/**
 569 * struct adapter_reply_queue - the reply queue struct
 570 * @ioc: per adapter object
 571 * @msix_index: msix index into vector table
 572 * @vector: irq vector
 573 * @reply_post_host_index: head index in the pool where FW completes IO
 574 * @reply_post_free: reply post base virt address
 575 * @name: the name registered to request_irq()
 576 * @busy: isr is actively processing replies on another cpu
 577 * @list: this list
 578*/
 579struct adapter_reply_queue {
 580	struct MPT2SAS_ADAPTER	*ioc;
 581	u8			msix_index;
 582	unsigned int		vector;
 583	u32			reply_post_host_index;
 584	Mpi2ReplyDescriptorsUnion_t *reply_post_free;
 585	char			name[MPT_NAME_LENGTH];
 586	atomic_t		busy;
 587	struct list_head	list;
 588};
 589
 590/* IOC Facts and Port Facts converted from little endian to cpu */
 591union mpi2_version_union {
 592	MPI2_VERSION_STRUCT		Struct;
 593	u32				Word;
 594};
 595
 596struct mpt2sas_facts {
 597	u16			MsgVersion;
 598	u16			HeaderVersion;
 599	u8			IOCNumber;
 600	u8			VP_ID;
 601	u8			VF_ID;
 602	u16			IOCExceptions;
 603	u16			IOCStatus;
 604	u32			IOCLogInfo;
 605	u8			MaxChainDepth;
 606	u8			WhoInit;
 607	u8			NumberOfPorts;
 608	u8			MaxMSIxVectors;
 609	u16			RequestCredit;
 610	u16			ProductID;
 611	u32			IOCCapabilities;
 612	union mpi2_version_union	FWVersion;
 613	u16			IOCRequestFrameSize;
 614	u16			Reserved3;
 615	u16			MaxInitiators;
 616	u16			MaxTargets;
 617	u16			MaxSasExpanders;
 618	u16			MaxEnclosures;
 619	u16			ProtocolFlags;
 620	u16			HighPriorityCredit;
 621	u16			MaxReplyDescriptorPostQueueDepth;
 622	u8			ReplyFrameSize;
 623	u8			MaxVolumes;
 624	u16			MaxDevHandle;
 625	u16			MaxPersistentEntries;
 626	u16			MinDevHandle;
 627};
 628
 629struct mpt2sas_port_facts {
 630	u8			PortNumber;
 631	u8			VP_ID;
 632	u8			VF_ID;
 633	u8			PortType;
 634	u16			MaxPostedCmdBuffers;
 635};
 636
 637/**
 638 * enum mutex_type - task management mutex type
 639 * @TM_MUTEX_OFF: mutex is not required becuase calling function is acquiring it
 640 * @TM_MUTEX_ON: mutex is required
 641 */
 642enum mutex_type {
 643	TM_MUTEX_OFF = 0,
 644	TM_MUTEX_ON = 1,
 645};
 646
 647typedef void (*MPT2SAS_FLUSH_RUNNING_CMDS)(struct MPT2SAS_ADAPTER *ioc);
 648/**
 649 * struct MPT2SAS_ADAPTER - per adapter struct
 650 * @list: ioc_list
 651 * @shost: shost object
 652 * @id: unique adapter id
 653 * @cpu_count: number online cpus
 654 * @name: generic ioc string
 655 * @tmp_string: tmp string used for logging
 656 * @pdev: pci pdev object
 657 * @chip: memory mapped register space
 658 * @chip_phys: physical addrss prior to mapping
 659 * @logging_level: see mpt2sas_debug.h
 660 * @fwfault_debug: debuging FW timeouts
 661 * @ir_firmware: IR firmware present
 662 * @bars: bitmask of BAR's that must be configured
 663 * @mask_interrupts: ignore interrupt
 664 * @fault_reset_work_q_name: fw fault work queue
 665 * @fault_reset_work_q: ""
 666 * @fault_reset_work: ""
 667 * @firmware_event_name: fw event work queue
 668 * @firmware_event_thread: ""
 669 * @fw_events_off: flag to turn off fw event handling
 670 * @fw_event_lock:
 671 * @fw_event_list: list of fw events
 672 * @aen_event_read_flag: event log was read
 673 * @broadcast_aen_busy: broadcast aen waiting to be serviced
 674 * @shost_recovery: host reset in progress
 675 * @ioc_reset_in_progress_lock:
 676 * @ioc_link_reset_in_progress: phy/hard reset in progress
 677 * @ignore_loginfos: ignore loginfos during task management
 678 * @remove_host: flag for when driver unloads, to avoid sending dev resets
 679 * @pci_error_recovery: flag to prevent ioc access until slot reset completes
 680 * @wait_for_discovery_to_complete: flag set at driver load time when
 681 *                                               waiting on reporting devices
 682 * @is_driver_loading: flag set at driver load time
 683 * @port_enable_failed: flag set when port enable has failed
 684 * @start_scan: flag set from scan_start callback, cleared from _mpt2sas_fw_work
 685 * @start_scan_failed: means port enable failed, return's the ioc_status
 686 * @msix_enable: flag indicating msix is enabled
 687 * @msix_vector_count: number msix vectors
 688 * @cpu_msix_table: table for mapping cpus to msix index
 689 * @cpu_msix_table_sz: table size
 690 * @schedule_dead_ioc_flush_running_cmds: callback to flush pending commands
 691 * @scsi_io_cb_idx: shost generated commands
 692 * @tm_cb_idx: task management commands
 693 * @scsih_cb_idx: scsih internal commands
 694 * @transport_cb_idx: transport internal commands
 695 * @ctl_cb_idx: clt internal commands
 696 * @base_cb_idx: base internal commands
 697 * @config_cb_idx: base internal commands
 698 * @tm_tr_cb_idx : device removal target reset handshake
 699 * @tm_tr_volume_cb_idx : volume removal target reset
 700 * @base_cmds:
 701 * @transport_cmds:
 702 * @scsih_cmds:
 703 * @tm_cmds:
 704 * @ctl_cmds:
 705 * @config_cmds:
 706 * @base_add_sg_single: handler for either 32/64 bit sgl's
 707 * @event_type: bits indicating which events to log
 708 * @event_context: unique id for each logged event
 709 * @event_log: event log pointer
 710 * @event_masks: events that are masked
 711 * @facts: static facts data
 712 * @pfacts: static port facts data
 713 * @manu_pg0: static manufacturing page 0
 714 * @manu_pg10: static manufacturing page 10
 715 * @bios_pg2: static bios page 2
 716 * @bios_pg3: static bios page 3
 717 * @ioc_pg8: static ioc page 8
 718 * @iounit_pg0: static iounit page 0
 719 * @iounit_pg1: static iounit page 1
 720 * @sas_hba: sas host object
 721 * @sas_expander_list: expander object list
 722 * @sas_node_lock:
 723 * @sas_device_list: sas device object list
 724 * @sas_device_init_list: sas device object list (used only at init time)
 725 * @sas_device_lock:
 726 * @io_missing_delay: time for IO completed by fw when PDR enabled
 727 * @device_missing_delay: time for device missing by fw when PDR enabled
 728 * @sas_id : used for setting volume target IDs
 729 * @blocking_handles: bitmask used to identify which devices need blocking
 730 * @pd_handles : bitmask for PD handles
 731 * @pd_handles_sz : size of pd_handle bitmask
 732 * @config_page_sz: config page size
 733 * @config_page: reserve memory for config page payload
 734 * @config_page_dma:
 735 * @hba_queue_depth: hba request queue depth
 736 * @sge_size: sg element size for either 32/64 bit
 737 * @scsiio_depth: SCSI_IO queue depth
 738 * @request_sz: per request frame size
 739 * @request: pool of request frames
 740 * @request_dma:
 741 * @request_dma_sz:
 742 * @scsi_lookup: firmware request tracker list
 743 * @scsi_lookup_lock:
 744 * @free_list: free list of request
 745 * @chain: pool of chains
 746 * @pending_io_count:
 747 * @reset_wq:
 748 * @chain_dma:
 749 * @max_sges_in_main_message: number sg elements in main message
 750 * @max_sges_in_chain_message: number sg elements per chain
 751 * @chains_needed_per_io: max chains per io
 752 * @chain_offset_value_for_main_message: location 1st sg in main
 753 * @chain_depth: total chains allocated
 754 * @hi_priority_smid:
 755 * @hi_priority:
 756 * @hi_priority_dma:
 757 * @hi_priority_depth:
 758 * @hpr_lookup:
 759 * @hpr_free_list:
 760 * @internal_smid:
 761 * @internal:
 762 * @internal_dma:
 763 * @internal_depth:
 764 * @internal_lookup:
 765 * @internal_free_list:
 766 * @sense: pool of sense
 767 * @sense_dma:
 768 * @sense_dma_pool:
 769 * @reply_depth: hba reply queue depth:
 770 * @reply_sz: per reply frame size:
 771 * @reply: pool of replys:
 772 * @reply_dma:
 773 * @reply_dma_pool:
 774 * @reply_free_queue_depth: reply free depth
 775 * @reply_free: pool for reply free queue (32 bit addr)
 776 * @reply_free_dma:
 777 * @reply_free_dma_pool:
 778 * @reply_free_host_index: tail index in pool to insert free replys
 779 * @reply_post_queue_depth: reply post queue depth
 780 * @reply_post_free: pool for reply post (64bit descriptor)
 781 * @reply_post_free_dma:
 782 * @reply_queue_count: number of reply queue's
 783 * @reply_queue_list: link list contaning the reply queue info
 784 * @reply_post_host_index: head index in the pool where FW completes IO
 785 * @delayed_tr_list: target reset link list
 786 * @delayed_tr_volume_list: volume target reset link list
 787 */
 788struct MPT2SAS_ADAPTER {
 789	struct list_head list;
 790	struct Scsi_Host *shost;
 791	u8		id;
 792	int		cpu_count;
 793	char		name[MPT_NAME_LENGTH];
 794	char		tmp_string[MPT_STRING_LENGTH];
 795	struct pci_dev	*pdev;
 796	Mpi2SystemInterfaceRegs_t __iomem *chip;
 797	resource_size_t	chip_phys;
 798	int		logging_level;
 799	int		fwfault_debug;
 800	u8		ir_firmware;
 801	int		bars;
 802	u8		mask_interrupts;
 803
 804	/* fw fault handler */
 805	char		fault_reset_work_q_name[20];
 806	struct workqueue_struct *fault_reset_work_q;
 807	struct delayed_work fault_reset_work;
 808
 809	/* fw event handler */
 810	char		firmware_event_name[20];
 811	struct workqueue_struct	*firmware_event_thread;
 812	spinlock_t	fw_event_lock;
 813	struct list_head fw_event_list;
 814
 815	 /* misc flags */
 816	int		aen_event_read_flag;
 817	u8		broadcast_aen_busy;
 818	u16		broadcast_aen_pending;
 819	u8		shost_recovery;
 820
 821	struct mutex	reset_in_progress_mutex;
 
 822	spinlock_t 	ioc_reset_in_progress_lock;
 823	u8		ioc_link_reset_in_progress;
 824	u8		ioc_reset_in_progress_status;
 825
 826	u8		ignore_loginfos;
 827	u8		remove_host;
 828	u8		pci_error_recovery;
 829	u8		wait_for_discovery_to_complete;
 830	struct completion	port_enable_done;
 831	u8		is_driver_loading;
 832	u8		port_enable_failed;
 833
 834	u8		start_scan;
 835	u16		start_scan_failed;
 836
 837	u8		msix_enable;
 838	u16		msix_vector_count;
 839	u8		*cpu_msix_table;
 840	resource_size_t	**reply_post_host_index;
 841	u16		cpu_msix_table_sz;
 842	u32		ioc_reset_count;
 843	MPT2SAS_FLUSH_RUNNING_CMDS schedule_dead_ioc_flush_running_cmds;
 844	u32             non_operational_loop;
 845
 846	/* internal commands, callback index */
 847	u8		scsi_io_cb_idx;
 848	u8		tm_cb_idx;
 849	u8		transport_cb_idx;
 850	u8		scsih_cb_idx;
 851	u8		ctl_cb_idx;
 852	u8		base_cb_idx;
 853	u8		port_enable_cb_idx;
 854	u8		config_cb_idx;
 855	u8		tm_tr_cb_idx;
 856	u8		tm_tr_volume_cb_idx;
 857	u8		tm_sas_control_cb_idx;
 858	struct _internal_cmd base_cmds;
 859	struct _internal_cmd port_enable_cmds;
 860	struct _internal_cmd transport_cmds;
 861	struct _internal_cmd scsih_cmds;
 862	struct _internal_cmd tm_cmds;
 863	struct _internal_cmd ctl_cmds;
 864	struct _internal_cmd config_cmds;
 865
 866	MPT_ADD_SGE	base_add_sg_single;
 867
 868	/* event log */
 869	u32		event_type[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
 870	u32		event_context;
 871	void		*event_log;
 872	u32		event_masks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
 873
 874	/* static config pages */
 875	struct mpt2sas_facts facts;
 876	struct mpt2sas_port_facts *pfacts;
 877	Mpi2ManufacturingPage0_t manu_pg0;
 878	Mpi2BiosPage2_t	bios_pg2;
 879	Mpi2BiosPage3_t	bios_pg3;
 880	Mpi2IOCPage8_t ioc_pg8;
 881	Mpi2IOUnitPage0_t iounit_pg0;
 882	Mpi2IOUnitPage1_t iounit_pg1;
 883
 884	struct _boot_device req_boot_device;
 885	struct _boot_device req_alt_boot_device;
 886	struct _boot_device current_boot_device;
 887
 888	/* sas hba, expander, and device list */
 889	struct _sas_node sas_hba;
 890	struct list_head sas_expander_list;
 891	spinlock_t	sas_node_lock;
 892	struct list_head sas_device_list;
 893	struct list_head sas_device_init_list;
 894	spinlock_t	sas_device_lock;
 895	struct list_head raid_device_list;
 896	spinlock_t	raid_device_lock;
 897	u8		io_missing_delay;
 898	u16		device_missing_delay;
 899	int		sas_id;
 900	void		*blocking_handles;
 901	void		*pd_handles;
 902	u16		pd_handles_sz;
 903
 904	/* config page */
 905	u16		config_page_sz;
 906	void 		*config_page;
 907	dma_addr_t	config_page_dma;
 908
 909	/* scsiio request */
 910	u16		hba_queue_depth;
 911	u16		sge_size;
 912	u16 		scsiio_depth;
 913	u16		request_sz;
 914	u8		*request;
 915	dma_addr_t	request_dma;
 916	u32		request_dma_sz;
 917	struct scsiio_tracker *scsi_lookup;
 918	ulong		scsi_lookup_pages;
 919	spinlock_t 	scsi_lookup_lock;
 920	struct list_head free_list;
 921	int		pending_io_count;
 922	wait_queue_head_t reset_wq;
 923
 924	/* chain */
 925	struct chain_tracker *chain_lookup;
 926	struct list_head free_chain_list;
 927	struct dma_pool *chain_dma_pool;
 928	ulong		chain_pages;
 929	u16 		max_sges_in_main_message;
 930	u16		max_sges_in_chain_message;
 931	u16		chains_needed_per_io;
 932	u16		chain_offset_value_for_main_message;
 933	u32		chain_depth;
 934
 935	/* hi-priority queue */
 936	u16		hi_priority_smid;
 937	u8		*hi_priority;
 938	dma_addr_t	hi_priority_dma;
 939	u16		hi_priority_depth;
 940	struct request_tracker *hpr_lookup;
 941	struct list_head hpr_free_list;
 942
 943	/* internal queue */
 944	u16		internal_smid;
 945	u8		*internal;
 946	dma_addr_t	internal_dma;
 947	u16		internal_depth;
 948	struct request_tracker *internal_lookup;
 949	struct list_head internal_free_list;
 950
 951	/* sense */
 952	u8		*sense;
 953	dma_addr_t	sense_dma;
 954	struct dma_pool *sense_dma_pool;
 955
 956	/* reply */
 957	u16		reply_sz;
 958	u8		*reply;
 959	dma_addr_t	reply_dma;
 960	u32		reply_dma_max_address;
 961	u32		reply_dma_min_address;
 962	struct dma_pool *reply_dma_pool;
 963
 964	/* reply free queue */
 965	u16 		reply_free_queue_depth;
 966	__le32		*reply_free;
 967	dma_addr_t	reply_free_dma;
 968	struct dma_pool *reply_free_dma_pool;
 969	u32		reply_free_host_index;
 970
 971	/* reply post queue */
 972	u16 		reply_post_queue_depth;
 973	Mpi2ReplyDescriptorsUnion_t *reply_post_free;
 974	dma_addr_t	reply_post_free_dma;
 975	struct dma_pool *reply_post_free_dma_pool;
 976	u8		reply_queue_count;
 977	struct list_head reply_queue_list;
 978
 979	struct list_head delayed_tr_list;
 980	struct list_head delayed_tr_volume_list;
 981
 982	/* diag buffer support */
 983	u8		*diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT];
 984	u32		diag_buffer_sz[MPI2_DIAG_BUF_TYPE_COUNT];
 985	dma_addr_t	diag_buffer_dma[MPI2_DIAG_BUF_TYPE_COUNT];
 986	u8		diag_buffer_status[MPI2_DIAG_BUF_TYPE_COUNT];
 987	u32		unique_id[MPI2_DIAG_BUF_TYPE_COUNT];
 988	Mpi2ManufacturingPage10_t manu_pg10;
 989	u32		product_specific[MPI2_DIAG_BUF_TYPE_COUNT][23];
 990	u32		diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT];
 991	u32		ring_buffer_offset;
 992	u32		ring_buffer_sz;
 993	u8		is_warpdrive;
 994	u8		hide_ir_msg;
 995	u8		mfg_pg10_hide_flag;
 996	u8		hide_drives;
 997
 998};
 999
1000typedef u8 (*MPT_CALLBACK)(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1001    u32 reply);
1002
1003
1004/* base shared API */
1005extern struct list_head mpt2sas_ioc_list;
1006void mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc);
1007void mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc);
1008
1009int mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc);
1010void mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc);
1011int mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc);
1012void mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc);
1013int mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
1014    enum reset_type type);
1015
1016void *mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid);
1017void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid);
1018void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr);
1019__le32 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc,
1020    u16 smid);
1021void mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc);
1022
1023/* hi-priority queue */
1024u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
1025u16 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1026    struct scsi_cmnd *scmd);
1027
1028u16 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
1029void mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid);
1030void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1031    u16 handle);
1032void mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid);
1033void mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1034    u16 io_index);
1035void mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid);
1036void mpt2sas_base_initialize_callback_handler(void);
1037u8 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func);
1038void mpt2sas_base_release_callback_handler(u8 cb_idx);
1039
1040u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1041    u32 reply);
1042u8 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1043	u8 msix_index,	u32 reply);
1044void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr);
1045
1046u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked);
1047
1048void mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code);
1049int mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
1050    Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t
1051    *mpi_request);
1052int mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
1053    Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request);
1054void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type);
1055
1056void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc);
1057
1058void mpt2sas_base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
1059	u16 device_missing_delay, u8 io_missing_delay);
1060
1061int mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc);
1062
1063/* scsih shared API */
1064void mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
1065    u32 reply);
1066int mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle,
1067	uint channel, uint id, uint lun, u8 type, u16 smid_task,
1068	ulong timeout, unsigned long serial_number, enum mutex_type m_type);
1069void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
1070void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
1071void mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
1072void mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
1073		u64 sas_address);
1074struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc,
1075    u16 handle);
1076struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
1077    *ioc, u64 sas_address);
1078struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address(
1079    struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
1080
1081void mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc);
1082
1083void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
1084
1085/* config shared API */
1086u8 mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1087    u32 reply);
1088int mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys);
1089int mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
1090    Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page);
1091int mpt2sas_config_get_manufacturing_pg10(struct MPT2SAS_ADAPTER *ioc,
1092    Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage10_t *config_page);
1093int mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1094    *mpi_reply, Mpi2BiosPage2_t *config_page);
1095int mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1096    *mpi_reply, Mpi2BiosPage3_t *config_page);
1097int mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1098    *mpi_reply, Mpi2IOUnitPage0_t *config_page);
1099int mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1100    *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle);
1101int mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1102    *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle);
1103int mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1104    *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz);
1105int mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1106    *mpi_reply, Mpi2IOUnitPage1_t *config_page);
1107int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1108    *mpi_reply, Mpi2IOUnitPage1_t *config_page);
1109int mpt2sas_config_get_iounit_pg3(struct MPT2SAS_ADAPTER *ioc,
1110	Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz);
1111int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1112    *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
1113int mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
1114    Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
1115int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1116    *mpi_reply, Mpi2IOCPage8_t *config_page);
1117int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1118    *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle);
1119int mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1120    *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle);
1121int mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1122    *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle);
1123int mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1124    *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number);
1125int mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1126    *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number);
1127int mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1128    *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle);
1129int mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 *num_pds);
1130int mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1131    *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz);
1132int mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
1133    *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
1134    u32 form_specific);
1135int mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1136    u16 *volume_handle);
1137int mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle,
1138    u64 *wwid);
1139/* ctl shared API */
1140extern struct device_attribute *mpt2sas_host_attrs[];
1141extern struct device_attribute *mpt2sas_dev_attrs[];
1142void mpt2sas_ctl_init(void);
1143void mpt2sas_ctl_exit(void);
1144u8 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1145    u32 reply);
1146void mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
1147void mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
1148    u32 reply);
1149void mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
1150    Mpi2EventNotificationReply_t *mpi_reply);
1151
1152void mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc,
1153	u8 bits_to_regsiter);
1154
1155/* transport shared API */
1156u8 mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1157    u32 reply);
1158struct _sas_port *mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc,
1159     u16 handle, u64 sas_address);
1160void mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
1161     u64 sas_address_parent);
1162int mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
1163    *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev);
1164int mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
1165    *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev);
1166void mpt2sas_transport_update_links(struct MPT2SAS_ADAPTER *ioc,
1167     u64 sas_address, u16 handle, u8 phy_number, u8 link_rate);
1168extern struct sas_function_template mpt2sas_transport_functions;
1169extern struct scsi_transport_template *mpt2sas_transport_template;
1170extern int scsi_internal_device_block(struct scsi_device *sdev);
1171extern u8 mpt2sas_stm_zero_smid_handler(struct MPT2SAS_ADAPTER *ioc,
1172    u8 msix_index, u32 reply);
1173extern int scsi_internal_device_unblock(struct scsi_device *sdev,
1174					enum scsi_device_state new_state);
1175
1176#endif /* MPT2SAS_BASE_H_INCLUDED */