6adab648dbb91278076d0de0270018892c524ee4
[safe/jmp/linux-2.6] / drivers / message / fusion / mptbase.h
1 /*
2  *  linux/drivers/message/fusion/mptbase.h
3  *      High performance SCSI + LAN / Fibre Channel device drivers.
4  *      For use with PCI chip/adapter(s):
5  *          LSIFC9xx/LSI409xx Fibre Channel
6  *      running LSI Fusion MPT (Message Passing Technology) firmware.
7  *
8  *  Copyright (c) 1999-2008 LSI Corporation
9  *  (mailto:DL-MPTFusionLinux@lsi.com)
10  *
11  */
12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13 /*
14     This program is free software; you can redistribute it and/or modify
15     it under the terms of the GNU General Public License as published by
16     the Free Software Foundation; version 2 of the License.
17
18     This program is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21     GNU General Public License for more details.
22
23     NO WARRANTY
24     THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
25     CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
26     LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
27     MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
28     solely responsible for determining the appropriateness of using and
29     distributing the Program and assumes all risks associated with its
30     exercise of rights under this Agreement, including but not limited to
31     the risks and costs of program errors, damage to or loss of data,
32     programs or equipment, and unavailability or interruption of operations.
33
34     DISCLAIMER OF LIABILITY
35     NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
36     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37     DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
38     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39     TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
40     USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
41     HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
42
43     You should have received a copy of the GNU General Public License
44     along with this program; if not, write to the Free Software
45     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
46 */
47
48 #ifndef MPTBASE_H_INCLUDED
49 #define MPTBASE_H_INCLUDED
50 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
51
52 #include <linux/kernel.h>
53 #include <linux/pci.h>
54 #include <linux/mutex.h>
55
56 #include "lsi/mpi_type.h"
57 #include "lsi/mpi.h"            /* Fusion MPI(nterface) basic defs */
58 #include "lsi/mpi_ioc.h"        /* Fusion MPT IOC(ontroller) defs */
59 #include "lsi/mpi_cnfg.h"       /* IOC configuration support */
60 #include "lsi/mpi_init.h"       /* SCSI Host (initiator) protocol support */
61 #include "lsi/mpi_lan.h"        /* LAN over FC protocol support */
62 #include "lsi/mpi_raid.h"       /* Integrated Mirroring support */
63
64 #include "lsi/mpi_fc.h"         /* Fibre Channel (lowlevel) support */
65 #include "lsi/mpi_targ.h"       /* SCSI/FCP Target protcol support */
66 #include "lsi/mpi_tool.h"       /* Tools support */
67 #include "lsi/mpi_sas.h"        /* SAS support */
68
69 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
70
71 #ifndef MODULEAUTHOR
72 #define MODULEAUTHOR    "LSI Corporation"
73 #endif
74
75 #ifndef COPYRIGHT
76 #define COPYRIGHT       "Copyright (c) 1999-2008 " MODULEAUTHOR
77 #endif
78
79 #define MPT_LINUX_VERSION_COMMON        "3.04.07"
80 #define MPT_LINUX_PACKAGE_NAME          "@(#)mptlinux-3.04.07"
81 #define WHAT_MAGIC_STRING               "@" "(" "#" ")"
82
83 #define show_mptmod_ver(s,ver)  \
84         printk(KERN_INFO "%s %s\n", s, ver);
85
86 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
87 /*
88  *  Fusion MPT(linux) driver configurable stuff...
89  */
90 #define MPT_MAX_ADAPTERS                18
91 #define MPT_MAX_PROTOCOL_DRIVERS        16
92 #define MPT_MAX_BUS                     1       /* Do not change */
93 #define MPT_MAX_FC_DEVICES              255
94 #define MPT_MAX_SCSI_DEVICES            16
95 #define MPT_LAST_LUN                    255
96 #define MPT_SENSE_BUFFER_ALLOC          64
97         /* allow for 256 max sense alloc, but only 255 max request */
98 #if MPT_SENSE_BUFFER_ALLOC >= 256
99 #       undef MPT_SENSE_BUFFER_ALLOC
100 #       define MPT_SENSE_BUFFER_ALLOC   256
101 #       define MPT_SENSE_BUFFER_SIZE    255
102 #else
103 #       define MPT_SENSE_BUFFER_SIZE    MPT_SENSE_BUFFER_ALLOC
104 #endif
105
106 #define MPT_NAME_LENGTH                 32
107
108 #define MPT_PROCFS_MPTBASEDIR           "mpt"
109                                                 /* chg it to "driver/fusion" ? */
110 #define MPT_PROCFS_SUMMARY_ALL_NODE             MPT_PROCFS_MPTBASEDIR "/summary"
111 #define MPT_PROCFS_SUMMARY_ALL_PATHNAME         "/proc/" MPT_PROCFS_SUMMARY_ALL_NODE
112 #define MPT_FW_REV_MAGIC_ID_STRING              "FwRev="
113
114 #define  MPT_MAX_REQ_DEPTH              1023
115 #define  MPT_DEFAULT_REQ_DEPTH          256
116 #define  MPT_MIN_REQ_DEPTH              128
117
118 #define  MPT_MAX_REPLY_DEPTH            MPT_MAX_REQ_DEPTH
119 #define  MPT_DEFAULT_REPLY_DEPTH        128
120 #define  MPT_MIN_REPLY_DEPTH            8
121 #define  MPT_MAX_REPLIES_PER_ISR        32
122
123 #define  MPT_MAX_FRAME_SIZE             128
124 #define  MPT_DEFAULT_FRAME_SIZE         128
125
126 #define  MPT_REPLY_FRAME_SIZE           0x50  /* Must be a multiple of 8 */
127
128 #define  MPT_SG_REQ_128_SCALE           1
129 #define  MPT_SG_REQ_96_SCALE            2
130 #define  MPT_SG_REQ_64_SCALE            4
131
132 #define  CAN_SLEEP                      1
133 #define  NO_SLEEP                       0
134
135 #define MPT_COALESCING_TIMEOUT          0x10
136
137 /*
138  * SCSI transfer rate defines.
139  */
140 #define MPT_ULTRA320                    0x08
141 #define MPT_ULTRA160                    0x09
142 #define MPT_ULTRA2                      0x0A
143 #define MPT_ULTRA                       0x0C
144 #define MPT_FAST                        0x19
145 #define MPT_SCSI                        0x32
146 #define MPT_ASYNC                       0xFF
147
148 #define MPT_NARROW                      0
149 #define MPT_WIDE                        1
150
151 #define C0_1030                         0x08
152 #define XL_929                          0x01
153
154
155 /*
156  *      Try to keep these at 2^N-1
157  */
158 #define MPT_FC_CAN_QUEUE        127
159 #define MPT_SCSI_CAN_QUEUE      127
160
161 /*
162  * Set the MAX_SGE value based on user input.
163  */
164 #ifdef  CONFIG_FUSION_MAX_SGE
165 #if     CONFIG_FUSION_MAX_SGE  < 16
166 #define MPT_SCSI_SG_DEPTH       16
167 #elif   CONFIG_FUSION_MAX_SGE  > 128
168 #define MPT_SCSI_SG_DEPTH       128
169 #else
170 #define MPT_SCSI_SG_DEPTH       CONFIG_FUSION_MAX_SGE
171 #endif
172 #else
173 #define MPT_SCSI_SG_DEPTH       40
174 #endif
175
176 /* debug print string length used for events and iocstatus */
177 # define EVENT_DESCR_STR_SZ             100
178
179 #define MPT_POLLING_INTERVAL            1000    /* in milliseconds */
180
181 #ifdef __KERNEL__       /* { */
182 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
183
184 #include <linux/proc_fs.h>
185
186 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
187 /*
188  * Attempt semi-consistent error & warning msgs across
189  * MPT drivers.  NOTE: Users of these macro defs must
190  * themselves define their own MYNAM.
191  */
192 #define MYIOC_s_FMT                     MYNAM ": %s: "
193 #define MYIOC_s_DEBUG_FMT               KERN_DEBUG MYNAM ": %s: "
194 #define MYIOC_s_INFO_FMT                KERN_INFO MYNAM ": %s: "
195 #define MYIOC_s_NOTE_FMT                KERN_NOTICE MYNAM ": %s: "
196 #define MYIOC_s_WARN_FMT                KERN_WARNING MYNAM ": %s: WARNING - "
197 #define MYIOC_s_ERR_FMT                 KERN_ERR MYNAM ": %s: ERROR - "
198
199 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
200 /*
201  *  ATTO UL4D associated structures and defines
202  */
203 #define ATTOFLAG_DISC     0x0001
204 #define ATTOFLAG_TAGGED   0x0002
205 #define ATTOFLAG_WIDE_ENB 0x0008
206 #define ATTOFLAG_ID_ENB   0x0010
207 #define ATTOFLAG_LUN_ENB  0x0060
208
209 typedef struct _ATTO_DEVICE_INFO
210 {
211         u8      Offset;                                 /* 00h */
212         u8      Period;                                 /* 01h */
213         u16     ATTOFlags;                              /* 02h */
214 } ATTO_DEVICE_INFO, MPI_POINTER PTR_ATTO_DEVICE_INFO,
215   ATTODeviceInfo_t, MPI_POINTER pATTODeviceInfo_t;
216
217 typedef struct _ATTO_CONFIG_PAGE_SCSI_PORT_2
218 {
219         CONFIG_PAGE_HEADER      Header;                 /* 00h */
220         u16                     PortFlags;              /* 04h */
221         u16                     Unused1;                /* 06h */
222         u32                     Unused2;                /* 08h */
223         ATTO_DEVICE_INFO        DeviceSettings[16];     /* 0Ch */
224 } fATTO_CONFIG_PAGE_SCSI_PORT_2, MPI_POINTER PTR_ATTO_CONFIG_PAGE_SCSI_PORT_2,
225   ATTO_SCSIPortPage2_t, MPI_POINTER pATTO_SCSIPortPage2_t;
226
227
228 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
229 /*
230  *  MPT protocol driver defs...
231  */
232 typedef enum {
233         MPTBASE_DRIVER,         /* MPT base class */
234         MPTCTL_DRIVER,          /* MPT ioctl class */
235         MPTSPI_DRIVER,          /* MPT SPI host class */
236         MPTFC_DRIVER,           /* MPT FC host class */
237         MPTSAS_DRIVER,          /* MPT SAS host class */
238         MPTLAN_DRIVER,          /* MPT LAN class */
239         MPTSTM_DRIVER,          /* MPT SCSI target mode class */
240         MPTUNKNOWN_DRIVER
241 } MPT_DRIVER_CLASS;
242
243 struct mpt_pci_driver{
244         int  (*probe) (struct pci_dev *dev, const struct pci_device_id *id);
245         void (*remove) (struct pci_dev *dev);
246 };
247
248 /*
249  *  MPT adapter / port / bus / device info structures...
250  */
251
252 typedef union _MPT_FRAME_TRACKER {
253         struct {
254                 struct list_head        list;
255                 u32                      arg1;
256                 u32                      pad;
257                 void                    *argp1;
258         } linkage;
259         /*
260          * NOTE: When request frames are free, on the linkage structure
261          * contets are valid.  All other values are invalid.
262          * In particular, do NOT reply on offset [2]
263          * (in words) being the * message context.
264          * The message context must be reset (computed via base address
265          * + an offset) prior to issuing any command.
266          *
267          * NOTE2: On non-32-bit systems, where pointers are LARGE,
268          * using the linkage pointers destroys our sacred MsgContext
269          * field contents.  But we don't care anymore because these
270          * are now reset in mpt_put_msg_frame() just prior to sending
271          * a request off to the IOC.
272          */
273         struct {
274                 u32 __hdr[2];
275                 /*
276                  * The following _MUST_ match the location of the
277                  * MsgContext field in the MPT message headers.
278                  */
279                 union {
280                         u32              MsgContext;
281                         struct {
282                                 u16      req_idx;       /* Request index */
283                                 u8       cb_idx;        /* callback function index */
284                                 u8       rsvd;
285                         } fld;
286                 } msgctxu;
287         } hwhdr;
288         /*
289          * Remark: 32 bit identifier:
290          *  31-24: reserved
291          *  23-16: call back index
292          *  15-0 : request index
293          */
294 } MPT_FRAME_TRACKER;
295
296 /*
297  *  We might want to view/access a frame as:
298  *    1) generic request header
299  *    2) SCSIIORequest
300  *    3) SCSIIOReply
301  *    4) MPIDefaultReply
302  *    5) frame tracker
303  */
304 typedef struct _MPT_FRAME_HDR {
305         union {
306                 MPIHeader_t             hdr;
307                 SCSIIORequest_t         scsireq;
308                 SCSIIOReply_t           sreply;
309                 ConfigReply_t           configreply;
310                 MPIDefaultReply_t       reply;
311                 MPT_FRAME_TRACKER       frame;
312         } u;
313 } MPT_FRAME_HDR;
314
315 #define MPT_REQ_MSGFLAGS_DROPME         0x80
316
317 typedef struct _MPT_SGL_HDR {
318         SGESimple32_t    sge[1];
319 } MPT_SGL_HDR;
320
321 typedef struct _MPT_SGL64_HDR {
322         SGESimple64_t    sge[1];
323 } MPT_SGL64_HDR;
324
325 /*
326  *  System interface register set
327  */
328
329 typedef struct _SYSIF_REGS
330 {
331         u32     Doorbell;       /* 00     System<->IOC Doorbell reg  */
332         u32     WriteSequence;  /* 04     Write Sequence register    */
333         u32     Diagnostic;     /* 08     Diagnostic register        */
334         u32     TestBase;       /* 0C     Test Base Address          */
335         u32     DiagRwData;     /* 10     Read Write Data (fw download)   */
336         u32     DiagRwAddress;  /* 14     Read Write Address (fw download)*/
337         u32     Reserved1[6];   /* 18-2F  reserved for future use    */
338         u32     IntStatus;      /* 30     Interrupt Status           */
339         u32     IntMask;        /* 34     Interrupt Mask             */
340         u32     Reserved2[2];   /* 38-3F  reserved for future use    */
341         u32     RequestFifo;    /* 40     Request Post/Free FIFO     */
342         u32     ReplyFifo;      /* 44     Reply   Post/Free FIFO     */
343         u32     RequestHiPriFifo; /* 48   Hi Priority Request FIFO   */
344         u32     Reserved3;      /* 4C-4F  reserved for future use    */
345         u32     HostIndex;      /* 50     Host Index register        */
346         u32     Reserved4[15];  /* 54-8F                             */
347         u32     Fubar;          /* 90     For Fubar usage            */
348         u32     Reserved5[1050];/* 94-10F8                           */
349         u32     Reset_1078;     /* 10FC   Reset 1078                 */
350 } SYSIF_REGS;
351
352 /*
353  * NOTE: Use MPI_{DOORBELL,WRITESEQ,DIAG}_xxx defs in lsi/mpi.h
354  * in conjunction with SYSIF_REGS accesses!
355  */
356
357
358 /*
359  *      Dynamic Multi-Pathing specific stuff...
360  */
361
362 /* VirtTarget negoFlags field */
363 #define MPT_TARGET_NO_NEGO_WIDE         0x01
364 #define MPT_TARGET_NO_NEGO_SYNC         0x02
365 #define MPT_TARGET_NO_NEGO_QAS          0x04
366 #define MPT_TAPE_NEGO_IDP               0x08
367
368 /*
369  *      VirtDevice - FC LUN device or SCSI target device
370  */
371 typedef struct _VirtTarget {
372         struct scsi_target      *starget;
373         u8                       tflags;
374         u8                       ioc_id;
375         u8                       id;
376         u8                       channel;
377         u8                       minSyncFactor; /* 0xFF is async */
378         u8                       maxOffset;     /* 0 if async */
379         u8                       maxWidth;      /* 0 if narrow, 1 if wide */
380         u8                       negoFlags;     /* bit field, see above */
381         u8                       raidVolume;    /* set, if RAID Volume */
382         u8                       type;          /* byte 0 of Inquiry data */
383         u8                       deleted;       /* target in process of being removed */
384         u32                      num_luns;
385 } VirtTarget;
386
387 typedef struct _VirtDevice {
388         VirtTarget              *vtarget;
389         u8                       configured_lun;
390         int                      lun;
391 } VirtDevice;
392
393 /*
394  *  Fibre Channel (SCSI) target device and associated defines...
395  */
396 #define MPT_TARGET_DEFAULT_DV_STATUS    0x00
397 #define MPT_TARGET_FLAGS_VALID_NEGO     0x01
398 #define MPT_TARGET_FLAGS_VALID_INQUIRY  0x02
399 #define MPT_TARGET_FLAGS_Q_YES          0x08
400 #define MPT_TARGET_FLAGS_VALID_56       0x10
401 #define MPT_TARGET_FLAGS_SAF_TE_ISSUED  0x20
402 #define MPT_TARGET_FLAGS_RAID_COMPONENT 0x40
403 #define MPT_TARGET_FLAGS_LED_ON         0x80
404
405 /*
406  *      /proc/mpt interface
407  */
408 typedef struct {
409         const char      *name;
410         mode_t           mode;
411         int              pad;
412         read_proc_t     *read_proc;
413         write_proc_t    *write_proc;
414 } mpt_proc_entry_t;
415
416 #define MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len) \
417 do { \
418         len -= offset;                  \
419         if (len < request) {            \
420                 *eof = 1;               \
421                 if (len <= 0)           \
422                         return 0;       \
423         } else                          \
424                 len = request;          \
425         *start = buf + offset;          \
426         return len;                     \
427 } while (0)
428
429
430 /*
431  *      IOCTL structure and associated defines
432  */
433
434 #define MPT_IOCTL_STATUS_DID_IOCRESET   0x01    /* IOC Reset occurred on the current*/
435 #define MPT_IOCTL_STATUS_RF_VALID       0x02    /* The Reply Frame is VALID */
436 #define MPT_IOCTL_STATUS_TIMER_ACTIVE   0x04    /* The timer is running */
437 #define MPT_IOCTL_STATUS_SENSE_VALID    0x08    /* Sense data is valid */
438 #define MPT_IOCTL_STATUS_COMMAND_GOOD   0x10    /* Command Status GOOD */
439 #define MPT_IOCTL_STATUS_TMTIMER_ACTIVE 0x20    /* The TM timer is running */
440 #define MPT_IOCTL_STATUS_TM_FAILED      0x40    /* User TM request failed */
441
442 #define MPTCTL_RESET_OK                 0x01    /* Issue Bus Reset */
443
444 typedef struct _MPT_IOCTL {
445         struct _MPT_ADAPTER     *ioc;
446         u8                       ReplyFrame[MPT_DEFAULT_FRAME_SIZE];    /* reply frame data */
447         u8                       sense[MPT_SENSE_BUFFER_ALLOC];
448         int                      wait_done;     /* wake-up value for this ioc */
449         u8                       rsvd;
450         u8                       status;        /* current command status */
451         u8                       reset;         /* 1 if bus reset allowed */
452         u8                       id;            /* target for reset */
453         struct mutex             ioctl_mutex;
454 } MPT_IOCTL;
455
456 #define MPT_SAS_MGMT_STATUS_RF_VALID    0x02    /* The Reply Frame is VALID */
457 #define MPT_SAS_MGMT_STATUS_COMMAND_GOOD        0x10    /* Command Status GOOD */
458 #define MPT_SAS_MGMT_STATUS_TM_FAILED   0x40    /* User TM request failed */
459
460 typedef struct _MPT_SAS_MGMT {
461         struct mutex             mutex;
462         struct completion        done;
463         u8                       reply[MPT_DEFAULT_FRAME_SIZE]; /* reply frame data */
464         u8                       status;        /* current command status */
465 }MPT_SAS_MGMT;
466
467 /*
468  *  Event Structure and define
469  */
470 #define MPTCTL_EVENT_LOG_SIZE           (0x000000032)
471 typedef struct _mpt_ioctl_events {
472         u32     event;          /* Specified by define above */
473         u32     eventContext;   /* Index or counter */
474         u32     data[2];        /* First 8 bytes of Event Data */
475 } MPT_IOCTL_EVENTS;
476
477 /*
478  * CONFIGPARM status  defines
479  */
480 #define MPT_CONFIG_GOOD         MPI_IOCSTATUS_SUCCESS
481 #define MPT_CONFIG_ERROR        0x002F
482
483 /*
484  *      Substructure to store SCSI specific configuration page data
485  */
486                                                 /* dvStatus defines: */
487 #define MPT_SCSICFG_USE_NVRAM           0x01    /* WriteSDP1 using NVRAM */
488 #define MPT_SCSICFG_ALL_IDS             0x02    /* WriteSDP1 to all IDS */
489 /* #define MPT_SCSICFG_BLK_NEGO         0x10       WriteSDP1 with WDTR and SDTR disabled */
490
491 typedef struct _SpiCfgData {
492         u32              PortFlags;
493         int             *nvram;                 /* table of device NVRAM values */
494         IOCPage4_t      *pIocPg4;               /* SEP devices addressing */
495         dma_addr_t       IocPg4_dma;            /* Phys Addr of IOCPage4 data */
496         int              IocPg4Sz;              /* IOCPage4 size */
497         u8               minSyncFactor;         /* 0xFF if async */
498         u8               maxSyncOffset;         /* 0 if async */
499         u8               maxBusWidth;           /* 0 if narrow, 1 if wide */
500         u8               busType;               /* SE, LVD, HD */
501         u8               sdp1version;           /* SDP1 version */
502         u8               sdp1length;            /* SDP1 length  */
503         u8               sdp0version;           /* SDP0 version */
504         u8               sdp0length;            /* SDP0 length  */
505         u8               dvScheduled;           /* 1 if scheduled */
506         u8               noQas;                 /* Disable QAS for this adapter */
507         u8               Saf_Te;                /* 1 to force all Processors as
508                                                  * SAF-TE if Inquiry data length
509                                                  * is too short to check for SAF-TE
510                                                  */
511         u8               bus_reset;             /* 1 to allow bus reset */
512         u8               rsvd[1];
513 }SpiCfgData;
514
515 typedef struct _SasCfgData {
516         u8               ptClear;               /* 1 to automatically clear the
517                                                  * persistent table.
518                                                  * 0 to disable
519                                                  * automatic clearing.
520                                                  */
521 }SasCfgData;
522
523 /*
524  * Inactive volume link list of raid component data
525  * @inactive_list
526  */
527 struct inactive_raid_component_info {
528         struct   list_head list;
529         u8               volumeID;              /* volume target id */
530         u8               volumeBus;             /* volume channel */
531         IOC_3_PHYS_DISK  d;                     /* phys disk info */
532 };
533
534 typedef struct _RaidCfgData {
535         IOCPage2_t      *pIocPg2;               /* table of Raid Volumes */
536         IOCPage3_t      *pIocPg3;               /* table of physical disks */
537         struct mutex    inactive_list_mutex;
538         struct list_head        inactive_list; /* link list for physical
539                                                 disk that belong in
540                                                 inactive volumes */
541 }RaidCfgData;
542
543 typedef struct _FcCfgData {
544         /* will ultimately hold fc_port_page0 also */
545         struct {
546                 FCPortPage1_t   *data;
547                 dma_addr_t       dma;
548                 int              pg_sz;
549         }                        fc_port_page1[2];
550 } FcCfgData;
551
552 #define MPT_RPORT_INFO_FLAGS_REGISTERED 0x01    /* rport registered */
553 #define MPT_RPORT_INFO_FLAGS_MISSING    0x02    /* missing from DevPage0 scan */
554
555 /*
556  * data allocated for each fc rport device
557  */
558 struct mptfc_rport_info
559 {
560         struct list_head list;
561         struct fc_rport *rport;
562         struct scsi_target *starget;
563         FCDevicePage0_t pg0;
564         u8              flags;
565 };
566
567 /*
568  *  Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
569  */
570 typedef struct _MPT_ADAPTER
571 {
572         int                      id;            /* Unique adapter id N {0,1,2,...} */
573         int                      pci_irq;       /* This irq           */
574         char                     name[MPT_NAME_LENGTH]; /* "iocN"             */
575         char                     prod_name[MPT_NAME_LENGTH];    /* "LSIFC9x9"         */
576         char                     board_name[16];
577         char                     board_assembly[16];
578         char                     board_tracer[16];
579         u16                      nvdata_version_persistent;
580         u16                      nvdata_version_default;
581         int                      debug_level;
582         u8                       io_missing_delay;
583         u8                       device_missing_delay;
584         SYSIF_REGS __iomem      *chip;          /* == c8817000 (mmap) */
585         SYSIF_REGS __iomem      *pio_chip;      /* Programmed IO (downloadboot) */
586         u8                       bus_type;
587         u32                      mem_phys;      /* == f4020000 (mmap) */
588         u32                      pio_mem_phys;  /* Programmed IO (downloadboot) */
589         int                      mem_size;      /* mmap memory size */
590         int                      number_of_buses;
591         int                      devices_per_bus;
592         int                      alloc_total;
593         u32                      last_state;
594         int                      active;
595         u8                      *alloc;         /* frames alloc ptr */
596         dma_addr_t               alloc_dma;
597         u32                      alloc_sz;
598         MPT_FRAME_HDR           *reply_frames;  /* Reply msg frames - rounded up! */
599         u32                      reply_frames_low_dma;
600         int                      reply_depth;   /* Num Allocated reply frames */
601         int                      reply_sz;      /* Reply frame size */
602         int                      num_chain;     /* Number of chain buffers */
603                 /* Pool of buffers for chaining. ReqToChain
604                  * and ChainToChain track index of chain buffers.
605                  * ChainBuffer (DMA) virt/phys addresses.
606                  * FreeChainQ (lock) locking mechanisms.
607                  */
608         int                     *ReqToChain;
609         int                     *RequestNB;
610         int                     *ChainToChain;
611         u8                      *ChainBuffer;
612         dma_addr_t               ChainBufferDMA;
613         struct list_head         FreeChainQ;
614         spinlock_t               FreeChainQlock;
615                 /* We (host driver) get to manage our own RequestQueue! */
616         dma_addr_t               req_frames_dma;
617         MPT_FRAME_HDR           *req_frames;    /* Request msg frames - rounded up! */
618         u32                      req_frames_low_dma;
619         int                      req_depth;     /* Number of request frames */
620         int                      req_sz;        /* Request frame size (bytes) */
621         spinlock_t               FreeQlock;
622         struct list_head         FreeQ;
623                 /* Pool of SCSI sense buffers for commands coming from
624                  * the SCSI mid-layer.  We have one 256 byte sense buffer
625                  * for each REQ entry.
626                  */
627         u8                      *sense_buf_pool;
628         dma_addr_t               sense_buf_pool_dma;
629         u32                      sense_buf_low_dma;
630         u8                      *HostPageBuffer; /* SAS - host page buffer support */
631         u32                     HostPageBuffer_sz;
632         dma_addr_t              HostPageBuffer_dma;
633         int                      mtrr_reg;
634         struct pci_dev          *pcidev;        /* struct pci_dev pointer */
635         int                     bars;           /* bitmask of BAR's that must be configured */
636         int                     msi_enable;
637         u8                      __iomem *memmap;        /* mmap address */
638         struct Scsi_Host        *sh;            /* Scsi Host pointer */
639         SpiCfgData              spi_data;       /* Scsi config. data */
640         RaidCfgData             raid_data;      /* Raid config. data */
641         SasCfgData              sas_data;       /* Sas config. data */
642         FcCfgData               fc_data;        /* Fc config. data */
643         MPT_IOCTL               *ioctl;         /* ioctl data pointer */
644         struct proc_dir_entry   *ioc_dentry;
645         struct _MPT_ADAPTER     *alt_ioc;       /* ptr to 929 bound adapter port */
646         spinlock_t               diagLock;      /* diagnostic reset lock */
647         int                      diagPending;
648         u32                      biosVersion;   /* BIOS version from IO Unit Page 2 */
649         int                      eventTypes;    /* Event logging parameters */
650         int                      eventContext;  /* Next event context */
651         int                      eventLogSize;  /* Max number of cached events */
652         struct _mpt_ioctl_events *events;       /* pointer to event log */
653         u8                      *cached_fw;     /* Pointer to FW */
654         dma_addr_t              cached_fw_dma;
655         struct list_head         configQ;       /* linked list of config. requests */
656         int                      hs_reply_idx;
657 #ifndef MFCNT
658         u32                      pad0;
659 #else
660         u32                      mfcnt;
661 #endif
662         u32                      NB_for_64_byte_frame;
663         u32                      hs_req[MPT_MAX_FRAME_SIZE/sizeof(u32)];
664         u16                      hs_reply[MPT_MAX_FRAME_SIZE/sizeof(u16)];
665         IOCFactsReply_t          facts;
666         PortFactsReply_t         pfacts[2];
667         FCPortPage0_t            fc_port_page0[2];
668         struct timer_list        persist_timer; /* persist table timer */
669         int                      persist_wait_done; /* persist completion flag */
670         u8                       persist_reply_frame[MPT_DEFAULT_FRAME_SIZE]; /* persist reply */
671         LANPage0_t               lan_cnfg_page0;
672         LANPage1_t               lan_cnfg_page1;
673
674         u8                       ir_firmware; /* =1 if IR firmware detected */
675         /*
676          * Description: errata_flag_1064
677          * If a PCIX read occurs within 1 or 2 cycles after the chip receives
678          * a split completion for a read data, an internal address pointer incorrectly
679          * increments by 32 bytes
680          */
681         int                      errata_flag_1064;
682         int                      aen_event_read_flag; /* flag to indicate event log was read*/
683         u8                       FirstWhoInit;
684         u8                       upload_fw;     /* If set, do a fw upload */
685         u8                       reload_fw;     /* Force a FW Reload on next reset */
686         u8                       NBShiftFactor;  /* NB Shift Factor based on Block Size (Facts)  */
687         u8                       pad1[4];
688         u8                       DoneCtx;
689         u8                       TaskCtx;
690         u8                       InternalCtx;
691         spinlock_t               initializing_hba_lock;
692         int                      initializing_hba_lock_flag;
693         struct list_head         list;
694         struct net_device       *netdev;
695         struct list_head         sas_topology;
696         struct mutex             sas_topology_mutex;
697         struct mutex             sas_discovery_mutex;
698         u8                       sas_discovery_runtime;
699         u8                       sas_discovery_ignore_events;
700         int                      sas_index; /* index refrencing */
701         MPT_SAS_MGMT             sas_mgmt;
702         struct work_struct       sas_persist_task;
703
704         struct work_struct       fc_setup_reset_work;
705         struct list_head         fc_rports;
706         struct work_struct       fc_lsc_work;
707         u8                       fc_link_speed[2];
708         spinlock_t               fc_rescan_work_lock;
709         struct work_struct       fc_rescan_work;
710         char                     fc_rescan_work_q_name[KOBJ_NAME_LEN];
711         struct workqueue_struct *fc_rescan_work_q;
712         struct scsi_cmnd        **ScsiLookup;
713         spinlock_t                scsi_lookup_lock;
714
715         char                     reset_work_q_name[KOBJ_NAME_LEN];
716         struct workqueue_struct *reset_work_q;
717         struct delayed_work      fault_reset_work;
718         spinlock_t               fault_reset_work_lock;
719
720 } MPT_ADAPTER;
721
722 /*
723  *  New return value convention:
724  *    1 = Ok to free associated request frame
725  *    0 = not Ok ...
726  */
727 typedef int (*MPT_CALLBACK)(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
728 typedef int (*MPT_EVHANDLER)(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply);
729 typedef int (*MPT_RESETHANDLER)(MPT_ADAPTER *ioc, int reset_phase);
730 /* reset_phase defs */
731 #define MPT_IOC_PRE_RESET               0
732 #define MPT_IOC_POST_RESET              1
733 #define MPT_IOC_SETUP_RESET             2
734
735 /*
736  * Invent MPT host event (super-set of MPI Events)
737  * Fitted to 1030's 64-byte [max] request frame size
738  */
739 typedef struct _MPT_HOST_EVENT {
740         EventNotificationReply_t         MpiEvent;      /* 8 32-bit words! */
741         u32                              pad[6];
742         void                            *next;
743 } MPT_HOST_EVENT;
744
745 #define MPT_HOSTEVENT_IOC_BRINGUP       0x91
746 #define MPT_HOSTEVENT_IOC_RECOVER       0x92
747
748 /* Define the generic types based on the size
749  * of the dma_addr_t type.
750  */
751 typedef struct _mpt_sge {
752         u32             FlagsLength;
753         dma_addr_t      Address;
754 } MptSge_t;
755
756 #define mpt_addr_size() \
757         ((sizeof(dma_addr_t) == sizeof(u64)) ? MPI_SGE_FLAGS_64_BIT_ADDRESSING : \
758                 MPI_SGE_FLAGS_32_BIT_ADDRESSING)
759
760 #define mpt_msg_flags() \
761         ((sizeof(dma_addr_t) == sizeof(u64)) ? MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_64 : \
762                 MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_32)
763
764 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
765 /*
766  *  Funky (private) macros...
767  */
768 #include "mptdebug.h"
769
770 #define MPT_INDEX_2_MFPTR(ioc,idx) \
771         (MPT_FRAME_HDR*)( (u8*)(ioc)->req_frames + (ioc)->req_sz * (idx) )
772
773 #define MFPTR_2_MPT_INDEX(ioc,mf) \
774         (int)( ((u8*)mf - (u8*)(ioc)->req_frames) / (ioc)->req_sz )
775
776 #define MPT_INDEX_2_RFPTR(ioc,idx) \
777         (MPT_FRAME_HDR*)( (u8*)(ioc)->reply_frames + (ioc)->req_sz * (idx) )
778
779 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
780
781 #define SCSI_STD_SENSE_BYTES    18
782 #define SCSI_STD_INQUIRY_BYTES  36
783 #define SCSI_MAX_INQUIRY_BYTES  96
784
785 /*
786  * MPT_SCSI_HOST defines - Used by the IOCTL and the SCSI drivers
787  * Private to the driver.
788  */
789 /* LOCAL structure and fields used when processing
790  * internally generated commands. These include:
791  * bus scan, dv and config requests.
792  */
793 typedef struct _MPT_LOCAL_REPLY {
794         ConfigPageHeader_t header;
795         int     completion;
796         u8      sense[SCSI_STD_SENSE_BYTES];
797         u8      scsiStatus;
798         u8      skip;
799         u32     pad;
800 } MPT_LOCAL_REPLY;
801
802 #define MPT_HOST_BUS_UNKNOWN            (0xFF)
803 #define MPT_HOST_TOO_MANY_TM            (0x05)
804 #define MPT_HOST_NVRAM_INVALID          (0xFFFFFFFF)
805 #define MPT_HOST_NO_CHAIN               (0xFFFFFFFF)
806 #define MPT_NVRAM_MASK_TIMEOUT          (0x000000FF)
807 #define MPT_NVRAM_SYNC_MASK             (0x0000FF00)
808 #define MPT_NVRAM_SYNC_SHIFT            (8)
809 #define MPT_NVRAM_DISCONNECT_ENABLE     (0x00010000)
810 #define MPT_NVRAM_ID_SCAN_ENABLE        (0x00020000)
811 #define MPT_NVRAM_LUN_SCAN_ENABLE       (0x00040000)
812 #define MPT_NVRAM_TAG_QUEUE_ENABLE      (0x00080000)
813 #define MPT_NVRAM_WIDE_DISABLE          (0x00100000)
814 #define MPT_NVRAM_BOOT_CHOICE           (0x00200000)
815
816 /* The TM_STATE variable is used to provide strict single threading of TM
817  * requests as well as communicate TM error conditions.
818  */
819 #define TM_STATE_NONE          (0)
820 #define TM_STATE_IN_PROGRESS   (1)
821 #define TM_STATE_ERROR         (2)
822
823 typedef enum {
824         FC,
825         SPI,
826         SAS
827 } BUS_TYPE;
828
829 typedef struct _MPT_SCSI_HOST {
830         MPT_ADAPTER              *ioc;
831         int                       port;
832         u32                       pad0;
833         MPT_LOCAL_REPLY          *pLocal;               /* used for internal commands */
834         struct timer_list         timer;
835                 /* Pool of memory for holding SCpnts before doing
836                  * OS callbacks. freeQ is the free pool.
837                  */
838         u8                        tmPending;
839         u8                        resetPending;
840         u8                        negoNvram;            /* DV disabled, nego NVRAM */
841         u8                        pad1;
842         u8                        tmState;
843         u8                        rsvd[2];
844         MPT_FRAME_HDR            *cmdPtr;               /* Ptr to nonOS request */
845         struct scsi_cmnd         *abortSCpnt;
846         MPT_LOCAL_REPLY           localReply;           /* internal cmd reply struct */
847         unsigned long             hard_resets;          /* driver forced bus resets count */
848         unsigned long             soft_resets;          /* fw/external bus resets count */
849         unsigned long             timeouts;             /* cmd timeouts */
850         ushort                    sel_timeout[MPT_MAX_FC_DEVICES];
851         char                      *info_kbuf;
852         wait_queue_head_t         scandv_waitq;
853         int                       scandv_wait_done;
854         long                      last_queue_full;
855         u16                       tm_iocstatus;
856         u16                       spi_pending;
857         struct list_head          target_reset_list;
858 } MPT_SCSI_HOST;
859
860 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
861 /*
862  *      More Dynamic Multi-Pathing stuff...
863  */
864
865 /* Forward decl, a strange C thing, to prevent gcc compiler warnings */
866 struct scsi_cmnd;
867
868 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
869 /*
870  * Generic structure passed to the base mpt_config function.
871  */
872 typedef struct _x_config_parms {
873         struct list_head         linkage;       /* linked list */
874         struct timer_list        timer;         /* timer function for this request  */
875         union {
876                 ConfigExtendedPageHeader_t      *ehdr;
877                 ConfigPageHeader_t      *hdr;
878         } cfghdr;
879         dma_addr_t               physAddr;
880         int                      wait_done;     /* wait for this request */
881         u32                      pageAddr;      /* properly formatted */
882         u8                       action;
883         u8                       dir;
884         u8                       timeout;       /* seconds */
885         u8                       pad1;
886         u16                      status;
887         u16                      pad2;
888 } CONFIGPARMS;
889
890 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
891 /*
892  *  Public entry points...
893  */
894 extern int       mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id);
895 extern void      mpt_detach(struct pci_dev *pdev);
896 #ifdef CONFIG_PM
897 extern int       mpt_suspend(struct pci_dev *pdev, pm_message_t state);
898 extern int       mpt_resume(struct pci_dev *pdev);
899 #endif
900 extern u8        mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass);
901 extern void      mpt_deregister(u8 cb_idx);
902 extern int       mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc);
903 extern void      mpt_event_deregister(u8 cb_idx);
904 extern int       mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func);
905 extern void      mpt_reset_deregister(u8 cb_idx);
906 extern int       mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
907 extern void      mpt_device_driver_deregister(u8 cb_idx);
908 extern MPT_FRAME_HDR    *mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc);
909 extern void      mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
910 extern void      mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
911 extern void      mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
912 extern void      mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr);
913
914 extern int       mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag);
915 extern int       mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp);
916 extern u32       mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
917 extern void      mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buf, int *size, int len, int showlan);
918 extern int       mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
919 extern int       mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *cfg);
920 extern int       mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size);
921 extern void      mpt_free_fw_memory(MPT_ADAPTER *ioc);
922 extern int       mpt_findImVolumes(MPT_ADAPTER *ioc);
923 extern int       mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
924 extern int       mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk);
925
926 /*
927  *  Public data decl's...
928  */
929 extern struct list_head   ioc_list;
930
931 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
932 #endif          /* } __KERNEL__ */
933
934 #ifdef CONFIG_64BIT
935 #define CAST_U32_TO_PTR(x)      ((void *)(u64)x)
936 #define CAST_PTR_TO_U32(x)      ((u32)(u64)x)
937 #else
938 #define CAST_U32_TO_PTR(x)      ((void *)x)
939 #define CAST_PTR_TO_U32(x)      ((u32)x)
940 #endif
941
942 #define MPT_PROTOCOL_FLAGS_c_c_c_c(pflags) \
943         ((pflags) & MPI_PORTFACTS_PROTOCOL_INITIATOR)   ? 'I' : 'i',    \
944         ((pflags) & MPI_PORTFACTS_PROTOCOL_TARGET)      ? 'T' : 't',    \
945         ((pflags) & MPI_PORTFACTS_PROTOCOL_LAN)         ? 'L' : 'l',    \
946         ((pflags) & MPI_PORTFACTS_PROTOCOL_LOGBUSADDR)  ? 'B' : 'b'
947
948 /*
949  *  Shifted SGE Defines - Use in SGE with FlagsLength member.
950  *  Otherwise, use MPI_xxx defines (refer to "lsi/mpi.h" header).
951  *  Defaults: 32 bit SGE, SYSTEM_ADDRESS if direction bit is 0, read
952  */
953 #define MPT_TRANSFER_IOC_TO_HOST                (0x00000000)
954 #define MPT_TRANSFER_HOST_TO_IOC                (0x04000000)
955 #define MPT_SGE_FLAGS_LAST_ELEMENT              (0x80000000)
956 #define MPT_SGE_FLAGS_END_OF_BUFFER             (0x40000000)
957 #define MPT_SGE_FLAGS_LOCAL_ADDRESS             (0x08000000)
958 #define MPT_SGE_FLAGS_DIRECTION                 (0x04000000)
959 #define MPT_SGE_FLAGS_ADDRESSING                (mpt_addr_size() << MPI_SGE_FLAGS_SHIFT)
960 #define MPT_SGE_FLAGS_END_OF_LIST               (0x01000000)
961
962 #define MPT_SGE_FLAGS_TRANSACTION_ELEMENT       (0x00000000)
963 #define MPT_SGE_FLAGS_SIMPLE_ELEMENT            (0x10000000)
964 #define MPT_SGE_FLAGS_CHAIN_ELEMENT             (0x30000000)
965 #define MPT_SGE_FLAGS_ELEMENT_MASK              (0x30000000)
966
967 #define MPT_SGE_FLAGS_SSIMPLE_READ \
968         (MPT_SGE_FLAGS_LAST_ELEMENT |   \
969          MPT_SGE_FLAGS_END_OF_BUFFER |  \
970          MPT_SGE_FLAGS_END_OF_LIST |    \
971          MPT_SGE_FLAGS_SIMPLE_ELEMENT | \
972          MPT_SGE_FLAGS_ADDRESSING | \
973          MPT_TRANSFER_IOC_TO_HOST)
974 #define MPT_SGE_FLAGS_SSIMPLE_WRITE \
975         (MPT_SGE_FLAGS_LAST_ELEMENT |   \
976          MPT_SGE_FLAGS_END_OF_BUFFER |  \
977          MPT_SGE_FLAGS_END_OF_LIST |    \
978          MPT_SGE_FLAGS_SIMPLE_ELEMENT | \
979          MPT_SGE_FLAGS_ADDRESSING | \
980          MPT_TRANSFER_HOST_TO_IOC)
981
982 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
983 #endif
984