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