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