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