Merge branch 'topic/pcm-estrpipe-in-pm' into for-linus
[pandora-kernel.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-2008  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          "01.100.04.00"
73 #define MPT2SAS_MAJOR_VERSION           01
74 #define MPT2SAS_MINOR_VERSION           100
75 #define MPT2SAS_BUILD_VERSION           04
76 #define MPT2SAS_RELEASE_VERSION         00
77
78 /*
79  * Set MPT2SAS_SG_DEPTH value based on user input.
80  */
81 #ifdef CONFIG_SCSI_MPT2SAS_MAX_SGE
82 #if     CONFIG_SCSI_MPT2SAS_MAX_SGE  < 16
83 #define MPT2SAS_SG_DEPTH       16
84 #elif CONFIG_SCSI_MPT2SAS_MAX_SGE  > 128
85 #define MPT2SAS_SG_DEPTH       128
86 #else
87 #define MPT2SAS_SG_DEPTH       CONFIG_SCSI_MPT2SAS_MAX_SGE
88 #endif
89 #else
90 #define MPT2SAS_SG_DEPTH       128 /* MAX_HW_SEGMENTS */
91 #endif
92
93
94 /*
95  * Generic Defines
96  */
97 #define MPT2SAS_SATA_QUEUE_DEPTH        32
98 #define MPT2SAS_SAS_QUEUE_DEPTH         254
99 #define MPT2SAS_RAID_QUEUE_DEPTH        128
100
101 #define MPT_NAME_LENGTH                 32      /* generic length of strings */
102 #define MPT_STRING_LENGTH               64
103
104 #define MPT_MAX_CALLBACKS               16
105
106 #define  CAN_SLEEP                      1
107 #define  NO_SLEEP                       0
108
109 #define INTERNAL_CMDS_COUNT             10      /* reserved cmds */
110
111 #define MPI2_HIM_MASK                   0xFFFFFFFF /* mask every bit*/
112
113 #define MPT2SAS_INVALID_DEVICE_HANDLE   0xFFFF
114
115
116 /*
117  * reset phases
118  */
119 #define MPT2_IOC_PRE_RESET              1 /* prior to host reset */
120 #define MPT2_IOC_AFTER_RESET            2 /* just after host reset */
121 #define MPT2_IOC_DONE_RESET             3 /* links re-initialized */
122
123 /*
124  * logging format
125  */
126 #define MPT2SAS_FMT                     "%s: "
127 #define MPT2SAS_DEBUG_FMT               KERN_DEBUG MPT2SAS_FMT
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  * per target private data
159  */
160 #define MPT_TARGET_FLAGS_RAID_COMPONENT 0x01
161 #define MPT_TARGET_FLAGS_VOLUME         0x02
162 #define MPT_TARGET_FLAGS_DELETED        0x04
163
164 /**
165  * struct MPT2SAS_TARGET - starget private hostdata
166  * @starget: starget object
167  * @sas_address: target sas address
168  * @handle: device handle
169  * @num_luns: number luns
170  * @flags: MPT_TARGET_FLAGS_XXX flags
171  * @deleted: target flaged for deletion
172  * @tm_busy: target is busy with TM request.
173  */
174 struct MPT2SAS_TARGET {
175         struct scsi_target *starget;
176         u64     sas_address;
177         u16     handle;
178         int     num_luns;
179         u32     flags;
180         u8      deleted;
181         u8      tm_busy;
182 };
183
184 /*
185  * per device private data
186  */
187 #define MPT_DEVICE_FLAGS_INIT           0x01
188 #define MPT_DEVICE_TLR_ON               0x02
189
190 /**
191  * struct MPT2SAS_DEVICE - sdev private hostdata
192  * @sas_target: starget private hostdata
193  * @lun: lun number
194  * @flags: MPT_DEVICE_XXX flags
195  * @configured_lun: lun is configured
196  * @block: device is in SDEV_BLOCK state
197  * @tlr_snoop_check: flag used in determining whether to disable TLR
198  */
199 struct MPT2SAS_DEVICE {
200         struct MPT2SAS_TARGET *sas_target;
201         unsigned int    lun;
202         u32     flags;
203         u8      configured_lun;
204         u8      block;
205         u8      tlr_snoop_check;
206 };
207
208 #define MPT2_CMD_NOT_USED       0x8000  /* free */
209 #define MPT2_CMD_COMPLETE       0x0001  /* completed */
210 #define MPT2_CMD_PENDING        0x0002  /* pending */
211 #define MPT2_CMD_REPLY_VALID    0x0004  /* reply is valid */
212 #define MPT2_CMD_RESET          0x0008  /* host reset dropped the command */
213
214 /**
215  * struct _internal_cmd - internal commands struct
216  * @mutex: mutex
217  * @done: completion
218  * @reply: reply message pointer
219  * @status: MPT2_CMD_XXX status
220  * @smid: system message id
221  */
222 struct _internal_cmd {
223         struct mutex mutex;
224         struct completion done;
225         void    *reply;
226         u16     status;
227         u16     smid;
228 };
229
230 /*
231  * SAS Topology Structures
232  */
233
234 /**
235  * struct _sas_device - attached device information
236  * @list: sas device list
237  * @starget: starget object
238  * @sas_address: device sas address
239  * @device_name: retrieved from the SAS IDENTIFY frame.
240  * @handle: device handle
241  * @parent_handle: handle to parent device
242  * @enclosure_handle: enclosure handle
243  * @enclosure_logical_id: enclosure logical identifier
244  * @volume_handle: volume handle (valid when hidden raid member)
245  * @volume_wwid: volume unique identifier
246  * @device_info: bitfield provides detailed info about the device
247  * @id: target id
248  * @channel: target channel
249  * @slot: number number
250  * @hidden_raid_component: set to 1 when this is a raid member
251  * @responding: used in _scsih_sas_device_mark_responding
252  */
253 struct _sas_device {
254         struct list_head list;
255         struct scsi_target *starget;
256         u64     sas_address;
257         u64     device_name;
258         u16     handle;
259         u16     parent_handle;
260         u16     enclosure_handle;
261         u64     enclosure_logical_id;
262         u16     volume_handle;
263         u64     volume_wwid;
264         u32     device_info;
265         int     id;
266         int     channel;
267         u16     slot;
268         u8      hidden_raid_component;
269         u8      responding;
270 };
271
272 /**
273  * struct _raid_device - raid volume link list
274  * @list: sas device list
275  * @starget: starget object
276  * @sdev: scsi device struct (volumes are single lun)
277  * @wwid: unique identifier for the volume
278  * @handle: device handle
279  * @id: target id
280  * @channel: target channel
281  * @volume_type: the raid level
282  * @device_info: bitfield provides detailed info about the hidden components
283  * @num_pds: number of hidden raid components
284  * @responding: used in _scsih_raid_device_mark_responding
285  */
286 struct _raid_device {
287         struct list_head list;
288         struct scsi_target *starget;
289         struct scsi_device *sdev;
290         u64     wwid;
291         u16     handle;
292         int     id;
293         int     channel;
294         u8      volume_type;
295         u32     device_info;
296         u8      num_pds;
297         u8      responding;
298 };
299
300 /**
301  * struct _boot_device - boot device info
302  * @is_raid: flag to indicate whether this is volume
303  * @device: holds pointer for either struct _sas_device or
304  *     struct _raid_device
305  */
306 struct _boot_device {
307         u8 is_raid;
308         void *device;
309 };
310
311 /**
312  * struct _sas_port - wide/narrow sas port information
313  * @port_list: list of ports belonging to expander
314  * @handle: device handle for this port
315  * @sas_address: sas address of this port
316  * @num_phys: number of phys belonging to this port
317  * @remote_identify: attached device identification
318  * @rphy: sas transport rphy object
319  * @port: sas transport wide/narrow port object
320  * @phy_list: _sas_phy list objects belonging to this port
321  */
322 struct _sas_port {
323         struct list_head port_list;
324         u16     handle;
325         u64     sas_address;
326         u8      num_phys;
327         struct sas_identify remote_identify;
328         struct sas_rphy *rphy;
329         struct sas_port *port;
330         struct list_head phy_list;
331 };
332
333 /**
334  * struct _sas_phy - phy information
335  * @port_siblings: list of phys belonging to a port
336  * @identify: phy identification
337  * @remote_identify: attached device identification
338  * @phy: sas transport phy object
339  * @phy_id: unique phy id
340  * @handle: device handle for this phy
341  * @attached_handle: device handle for attached device
342  */
343 struct _sas_phy {
344         struct list_head port_siblings;
345         struct sas_identify identify;
346         struct sas_identify remote_identify;
347         struct sas_phy *phy;
348         u8      phy_id;
349         u16     handle;
350         u16     attached_handle;
351 };
352
353 /**
354  * struct _sas_node - sas_host/expander information
355  * @list: list of expanders
356  * @parent_dev: parent device class
357  * @num_phys: number phys belonging to this sas_host/expander
358  * @sas_address: sas address of this sas_host/expander
359  * @handle: handle for this sas_host/expander
360  * @parent_handle: parent handle
361  * @enclosure_handle: handle for this a member of an enclosure
362  * @device_info: bitwise defining capabilities of this sas_host/expander
363  * @responding: used in _scsih_expander_device_mark_responding
364  * @phy: a list of phys that make up this sas_host/expander
365  * @sas_port_list: list of ports attached to this sas_host/expander
366  */
367 struct _sas_node {
368         struct list_head list;
369         struct device *parent_dev;
370         u8      num_phys;
371         u64     sas_address;
372         u16     handle;
373         u16     parent_handle;
374         u16     enclosure_handle;
375         u64     enclosure_logical_id;
376         u8      responding;
377         struct  _sas_phy *phy;
378         struct list_head sas_port_list;
379 };
380
381 /**
382  * enum reset_type - reset state
383  * @FORCE_BIG_HAMMER: issue diagnostic reset
384  * @SOFT_RESET: issue message_unit_reset, if fails to to big hammer
385  */
386 enum reset_type {
387         FORCE_BIG_HAMMER,
388         SOFT_RESET,
389 };
390
391 /**
392  * struct request_tracker - firmware request tracker
393  * @smid: system message id
394  * @scmd: scsi request pointer
395  * @cb_idx: callback index
396  * @chain_list: list of chains associated to this IO
397  * @tracker_list: list of free request (ioc->free_list)
398  */
399 struct request_tracker {
400         u16     smid;
401         struct scsi_cmnd *scmd;
402         u8      cb_idx;
403         struct list_head tracker_list;
404 };
405
406 typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
407
408 /**
409  * struct MPT2SAS_ADAPTER - per adapter struct
410  * @list: ioc_list
411  * @shost: shost object
412  * @id: unique adapter id
413  * @pci_irq: irq number
414  * @name: generic ioc string
415  * @tmp_string: tmp string used for logging
416  * @pdev: pci pdev object
417  * @chip: memory mapped register space
418  * @chip_phys: physical addrss prior to mapping
419  * @pio_chip: I/O mapped register space
420  * @logging_level: see mpt2sas_debug.h
421  * @ir_firmware: IR firmware present
422  * @bars: bitmask of BAR's that must be configured
423  * @mask_interrupts: ignore interrupt
424  * @fault_reset_work_q_name: fw fault work queue
425  * @fault_reset_work_q: ""
426  * @fault_reset_work: ""
427  * @firmware_event_name: fw event work queue
428  * @firmware_event_thread: ""
429  * @fw_events_off: flag to turn off fw event handling
430  * @fw_event_lock:
431  * @fw_event_list: list of fw events
432  * @aen_event_read_flag: event log was read
433  * @broadcast_aen_busy: broadcast aen waiting to be serviced
434  * @ioc_reset_in_progress: host reset in progress
435  * @ioc_reset_in_progress_lock:
436  * @ioc_link_reset_in_progress: phy/hard reset in progress
437  * @ignore_loginfos: ignore loginfos during task managment
438  * @remove_host: flag for when driver unloads, to avoid sending dev resets
439  * @wait_for_port_enable_to_complete:
440  * @msix_enable: flag indicating msix is enabled
441  * @msix_vector_count: number msix vectors
442  * @msix_table: virt address to the msix table
443  * @msix_table_backup: backup msix table
444  * @scsi_io_cb_idx: shost generated commands
445  * @tm_cb_idx: task management commands
446  * @transport_cb_idx: transport internal commands
447  * @ctl_cb_idx: clt internal commands
448  * @base_cb_idx: base internal commands
449  * @config_cb_idx: base internal commands
450  * @base_cmds:
451  * @transport_cmds:
452  * @tm_cmds:
453  * @ctl_cmds:
454  * @config_cmds:
455  * @base_add_sg_single: handler for either 32/64 bit sgl's
456  * @event_type: bits indicating which events to log
457  * @event_context: unique id for each logged event
458  * @event_log: event log pointer
459  * @event_masks: events that are masked
460  * @facts: static facts data
461  * @pfacts: static port facts data
462  * @manu_pg0: static manufacturing page 0
463  * @bios_pg2: static bios page 2
464  * @bios_pg3: static bios page 3
465  * @ioc_pg8: static ioc page 8
466  * @iounit_pg0: static iounit page 0
467  * @iounit_pg1: static iounit page 1
468  * @sas_hba: sas host object
469  * @sas_expander_list: expander object list
470  * @sas_node_lock:
471  * @sas_device_list: sas device object list
472  * @sas_device_init_list: sas device object list (used only at init time)
473  * @sas_device_lock:
474  * @io_missing_delay: time for IO completed by fw when PDR enabled
475  * @device_missing_delay: time for device missing by fw when PDR enabled
476  * @config_page_sz: config page size
477  * @config_page: reserve memory for config page payload
478  * @config_page_dma:
479  * @sge_size: sg element size for either 32/64 bit
480  * @request_depth: hba request queue depth
481  * @request_sz: per request frame size
482  * @request: pool of request frames
483  * @request_dma:
484  * @request_dma_sz:
485  * @scsi_lookup: firmware request tracker list
486  * @scsi_lookup_lock:
487  * @free_list: free list of request
488  * @chain: pool of chains
489  * @pending_io_count:
490  * @reset_wq:
491  * @chain_dma:
492  * @max_sges_in_main_message: number sg elements in main message
493  * @max_sges_in_chain_message: number sg elements per chain
494  * @chains_needed_per_io: max chains per io
495  * @chain_offset_value_for_main_message: location 1st sg in main
496  * @chain_depth: total chains allocated
497  * @sense: pool of sense
498  * @sense_dma:
499  * @sense_dma_pool:
500  * @reply_depth: hba reply queue depth:
501  * @reply_sz: per reply frame size:
502  * @reply: pool of replys:
503  * @reply_dma:
504  * @reply_dma_pool:
505  * @reply_free_queue_depth: reply free depth
506  * @reply_free: pool for reply free queue (32 bit addr)
507  * @reply_free_dma:
508  * @reply_free_dma_pool:
509  * @reply_free_host_index: tail index in pool to insert free replys
510  * @reply_post_queue_depth: reply post queue depth
511  * @reply_post_free: pool for reply post (64bit descriptor)
512  * @reply_post_free_dma:
513  * @reply_post_free_dma_pool:
514  * @reply_post_host_index: head index in the pool where FW completes IO
515  */
516 struct MPT2SAS_ADAPTER {
517         struct list_head list;
518         struct Scsi_Host *shost;
519         u8              id;
520         u32             pci_irq;
521         char            name[MPT_NAME_LENGTH];
522         char            tmp_string[MPT_STRING_LENGTH];
523         struct pci_dev  *pdev;
524         Mpi2SystemInterfaceRegs_t __iomem *chip;
525         unsigned long   chip_phys;
526         unsigned long   pio_chip;
527         int             logging_level;
528         u8              ir_firmware;
529         int             bars;
530         u8              mask_interrupts;
531
532         /* fw fault handler */
533         char            fault_reset_work_q_name[20];
534         struct workqueue_struct *fault_reset_work_q;
535         struct delayed_work fault_reset_work;
536
537         /* fw event handler */
538         char            firmware_event_name[20];
539         struct workqueue_struct *firmware_event_thread;
540         u8              fw_events_off;
541         spinlock_t      fw_event_lock;
542         struct list_head fw_event_list;
543
544          /* misc flags */
545         int             aen_event_read_flag;
546         u8              broadcast_aen_busy;
547         u8              ioc_reset_in_progress;
548         u8              shost_recovery;
549         spinlock_t      ioc_reset_in_progress_lock;
550         u8              ioc_link_reset_in_progress;
551         u8              ignore_loginfos;
552         u8              remove_host;
553         u8              wait_for_port_enable_to_complete;
554
555         u8              msix_enable;
556         u16             msix_vector_count;
557         u32             *msix_table;
558         u32             *msix_table_backup;
559
560         /* internal commands, callback index */
561         u8              scsi_io_cb_idx;
562         u8              tm_cb_idx;
563         u8              transport_cb_idx;
564         u8              ctl_cb_idx;
565         u8              base_cb_idx;
566         u8              config_cb_idx;
567         struct _internal_cmd base_cmds;
568         struct _internal_cmd transport_cmds;
569         struct _internal_cmd tm_cmds;
570         struct _internal_cmd ctl_cmds;
571         struct _internal_cmd config_cmds;
572
573         MPT_ADD_SGE     base_add_sg_single;
574
575         /* event log */
576         u32             event_type[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
577         u32             event_context;
578         void            *event_log;
579         u32             event_masks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
580
581         /* static config pages */
582         Mpi2IOCFactsReply_t facts;
583         Mpi2PortFactsReply_t *pfacts;
584         Mpi2ManufacturingPage0_t manu_pg0;
585         Mpi2BiosPage2_t bios_pg2;
586         Mpi2BiosPage3_t bios_pg3;
587         Mpi2IOCPage8_t ioc_pg8;
588         Mpi2IOUnitPage0_t iounit_pg0;
589         Mpi2IOUnitPage1_t iounit_pg1;
590
591         struct _boot_device req_boot_device;
592         struct _boot_device req_alt_boot_device;
593         struct _boot_device current_boot_device;
594
595         /* sas hba, expander, and device list */
596         struct _sas_node sas_hba;
597         struct list_head sas_expander_list;
598         spinlock_t      sas_node_lock;
599         struct list_head sas_device_list;
600         struct list_head sas_device_init_list;
601         spinlock_t      sas_device_lock;
602         struct list_head raid_device_list;
603         spinlock_t      raid_device_lock;
604         u8              io_missing_delay;
605         u16             device_missing_delay;
606         int             sas_id;
607
608         /* config page */
609         u16             config_page_sz;
610         void            *config_page;
611         dma_addr_t      config_page_dma;
612
613         /* request */
614         u16             sge_size;
615         u16             request_depth;
616         u16             request_sz;
617         u8              *request;
618         dma_addr_t      request_dma;
619         u32             request_dma_sz;
620         struct request_tracker *scsi_lookup;
621         spinlock_t scsi_lookup_lock;
622         struct list_head free_list;
623         int             pending_io_count;
624         wait_queue_head_t reset_wq;
625
626         /* chain */
627         u8              *chain;
628         dma_addr_t      chain_dma;
629         u16             max_sges_in_main_message;
630         u16             max_sges_in_chain_message;
631         u16             chains_needed_per_io;
632         u16             chain_offset_value_for_main_message;
633         u16             chain_depth;
634
635         /* sense */
636         u8              *sense;
637         dma_addr_t      sense_dma;
638         struct dma_pool *sense_dma_pool;
639
640         /* reply */
641         u16             reply_sz;
642         u8              *reply;
643         dma_addr_t      reply_dma;
644         struct dma_pool *reply_dma_pool;
645
646         /* reply free queue */
647         u16             reply_free_queue_depth;
648         u32             *reply_free;
649         dma_addr_t      reply_free_dma;
650         struct dma_pool *reply_free_dma_pool;
651         u32             reply_free_host_index;
652
653         /* reply post queue */
654         u16             reply_post_queue_depth;
655         Mpi2ReplyDescriptorsUnion_t *reply_post_free;
656         dma_addr_t      reply_post_free_dma;
657         struct dma_pool *reply_post_free_dma_pool;
658         u32             reply_post_host_index;
659
660         /* diag buffer support */
661         u8              *diag_buffer[MPI2_DIAG_BUF_TYPE_COUNT];
662         u32             diag_buffer_sz[MPI2_DIAG_BUF_TYPE_COUNT];
663         dma_addr_t      diag_buffer_dma[MPI2_DIAG_BUF_TYPE_COUNT];
664         u8              diag_buffer_status[MPI2_DIAG_BUF_TYPE_COUNT];
665         u32             unique_id[MPI2_DIAG_BUF_TYPE_COUNT];
666         u32             product_specific[MPI2_DIAG_BUF_TYPE_COUNT][23];
667         u32             diagnostic_flags[MPI2_DIAG_BUF_TYPE_COUNT];
668 };
669
670 typedef void (*MPT_CALLBACK)(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID,
671     u32 reply);
672
673
674 /* base shared API */
675 extern struct list_head mpt2sas_ioc_list;
676 void mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc);
677 void mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc);
678
679 int mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc);
680 void mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc);
681 int mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc);
682 void mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc);
683 int mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
684     enum reset_type type);
685
686 void *mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid);
687 void *mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid);
688 void mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr);
689 dma_addr_t mpt2sas_base_get_msg_frame_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid);
690 dma_addr_t mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid);
691
692 u16 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);
693 void mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid);
694 void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 vf_id,
695     u16 handle);
696 void mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 vf_id);
697 void mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
698     u8 vf_id, u16 io_index);
699 void mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 vf_id);
700 void mpt2sas_base_initialize_callback_handler(void);
701 u8 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func);
702 void mpt2sas_base_release_callback_handler(u8 cb_idx);
703
704 void mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply);
705 void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr);
706
707 u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked);
708
709 void mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code);
710 int mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
711     Mpi2SasIoUnitControlReply_t *mpi_reply, Mpi2SasIoUnitControlRequest_t
712     *mpi_request);
713 int mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
714     Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request);
715 void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type);
716
717 /* scsih shared API */
718 void mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
719     u8 type, u16 smid_task, ulong timeout);
720 void mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
721 void mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle);
722 struct _sas_node *mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc,
723     u16 handle);
724 struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
725     *ioc, u64 sas_address);
726 struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address(
727     struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
728
729 void mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply);
730 void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
731
732 /* config shared API */
733 void mpt2sas_config_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply);
734 int mpt2sas_config_get_number_hba_phys(struct MPT2SAS_ADAPTER *ioc, u8 *num_phys);
735 int mpt2sas_config_get_manufacturing_pg0(struct MPT2SAS_ADAPTER *ioc,
736     Mpi2ConfigReply_t *mpi_reply, Mpi2ManufacturingPage0_t *config_page);
737 int mpt2sas_config_get_bios_pg2(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
738     *mpi_reply, Mpi2BiosPage2_t *config_page);
739 int mpt2sas_config_get_bios_pg3(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
740     *mpi_reply, Mpi2BiosPage3_t *config_page);
741 int mpt2sas_config_get_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
742     *mpi_reply, Mpi2IOUnitPage0_t *config_page);
743 int mpt2sas_config_get_sas_device_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
744     *mpi_reply, Mpi2SasDevicePage0_t *config_page, u32 form, u32 handle);
745 int mpt2sas_config_get_sas_device_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
746     *mpi_reply, Mpi2SasDevicePage1_t *config_page, u32 form, u32 handle);
747 int mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
748     *mpi_reply, Mpi2SasIOUnitPage0_t *config_page, u16 sz);
749 int mpt2sas_config_get_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
750     *mpi_reply, Mpi2IOUnitPage1_t *config_page);
751 int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
752     *mpi_reply, Mpi2IOUnitPage1_t config_page);
753 int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
754     *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
755 int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
756     *mpi_reply, Mpi2IOCPage8_t *config_page);
757 int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
758     *mpi_reply, Mpi2ExpanderPage0_t *config_page, u32 form, u32 handle);
759 int mpt2sas_config_get_expander_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
760     *mpi_reply, Mpi2ExpanderPage1_t *config_page, u32 phy_number, u16 handle);
761 int mpt2sas_config_get_enclosure_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
762     *mpi_reply, Mpi2SasEnclosurePage0_t *config_page, u32 form, u32 handle);
763 int mpt2sas_config_get_phy_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
764     *mpi_reply, Mpi2SasPhyPage0_t *config_page, u32 phy_number);
765 int mpt2sas_config_get_phy_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
766     *mpi_reply, Mpi2SasPhyPage1_t *config_page, u32 phy_number);
767 int mpt2sas_config_get_raid_volume_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
768     *mpi_reply, Mpi2RaidVolPage1_t *config_page, u32 form, u32 handle);
769 int mpt2sas_config_get_number_pds(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 *num_pds);
770 int mpt2sas_config_get_raid_volume_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
771     *mpi_reply, Mpi2RaidVolPage0_t *config_page, u32 form, u32 handle, u16 sz);
772 int mpt2sas_config_get_phys_disk_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
773     *mpi_reply, Mpi2RaidPhysDiskPage0_t *config_page, u32 form,
774     u32 form_specific);
775 int mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
776     u16 *volume_handle);
777 int mpt2sas_config_get_volume_wwid(struct MPT2SAS_ADAPTER *ioc, u16 volume_handle,
778     u64 *wwid);
779
780 /* ctl shared API */
781 extern struct device_attribute *mpt2sas_host_attrs[];
782 extern struct device_attribute *mpt2sas_dev_attrs[];
783 void mpt2sas_ctl_init(void);
784 void mpt2sas_ctl_exit(void);
785 void mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply);
786 void mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
787 void mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 VF_ID, u32 reply);
788 void mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc,
789     Mpi2EventNotificationReply_t *mpi_reply);
790
791 /* transport shared API */
792 void mpt2sas_transport_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 VF_ID, u32 reply);
793 struct _sas_port *mpt2sas_transport_port_add(struct MPT2SAS_ADAPTER *ioc,
794     u16 handle, u16 parent_handle);
795 void mpt2sas_transport_port_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
796     u16 parent_handle);
797 int mpt2sas_transport_add_host_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
798     *mpt2sas_phy, Mpi2SasPhyPage0_t phy_pg0, struct device *parent_dev);
799 int mpt2sas_transport_add_expander_phy(struct MPT2SAS_ADAPTER *ioc, struct _sas_phy
800     *mpt2sas_phy, Mpi2ExpanderPage1_t expander_pg1, struct device *parent_dev);
801 void mpt2sas_transport_update_phy_link_change(struct MPT2SAS_ADAPTER *ioc, u16 handle,
802    u16 attached_handle, u8 phy_number, u8 link_rate);
803 extern struct sas_function_template mpt2sas_transport_functions;
804 extern struct scsi_transport_template *mpt2sas_transport_template;
805
806 #endif /* MPT2SAS_BASE_H_INCLUDED */