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 Logic Fusion MPT (Message Passing Technology) firmware.
11 * Copyright (c) 1999-2004 LSI Logic Corporation
12 * Originally By: Steven J. Ralston
13 * (mailto:sjralston1@netscape.net)
14 * (mailto:mpt_linux_developer@lsil.com)
16 * $Id: mptbase.h,v 1.144 2003/01/28 21:31:56 pdelaney Exp $
18 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License as published by
22 the Free Software Foundation; version 2 of the License.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
30 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
31 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
32 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
33 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
34 solely responsible for determining the appropriateness of using and
35 distributing the Program and assumes all risks associated with its
36 exercise of rights under this Agreement, including but not limited to
37 the risks and costs of program errors, damage to or loss of data,
38 programs or equipment, and unavailability or interruption of operations.
40 DISCLAIMER OF LIABILITY
41 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
42 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
46 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
47 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
49 You should have received a copy of the GNU General Public License
50 along with this program; if not, write to the Free Software
51 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
54 #ifndef MPTBASE_H_INCLUDED
55 #define MPTBASE_H_INCLUDED
56 /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
58 #include <linux/version.h>
59 #include <linux/config.h>
60 #include <linux/kernel.h>
61 #include <linux/pci.h>
63 #include "scsi3.h" /* SCSI defines */
65 #include "lsi/mpi_type.h"
66 #include "lsi/mpi.h" /* Fusion MPI(nterface) basic defs */
67 #include "lsi/mpi_ioc.h" /* Fusion MPT IOC(ontroller) defs */
68 #include "lsi/mpi_cnfg.h" /* IOC configuration support */
69 #include "lsi/mpi_init.h" /* SCSI Host (initiator) protocol support */
70 #include "lsi/mpi_lan.h" /* LAN over FC protocol support */
71 #include "lsi/mpi_raid.h" /* Integrated Mirroring support */
73 #include "lsi/mpi_fc.h" /* Fibre Channel (lowlevel) support */
74 #include "lsi/mpi_targ.h" /* SCSI/FCP Target protcol support */
75 #include "lsi/mpi_tool.h" /* Tools support */
76 #include "lsi/fc_log.h"
78 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
81 #define MODULEAUTHOR "LSI Logic Corporation"
85 #define COPYRIGHT "Copyright (c) 1999-2004 " MODULEAUTHOR
88 #define MPT_LINUX_VERSION_COMMON "3.01.09"
89 #define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.01.09"
90 #define WHAT_MAGIC_STRING "@" "(" "#" ")"
92 #define show_mptmod_ver(s,ver) \
93 printk(KERN_INFO "%s %s\n", s, ver);
95 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
97 * Fusion MPT(linux) driver configurable stuff...
99 #define MPT_MAX_ADAPTERS 18
100 #define MPT_MAX_PROTOCOL_DRIVERS 16
101 #define MPT_MAX_BUS 1 /* Do not change */
102 #define MPT_MAX_FC_DEVICES 255
103 #define MPT_MAX_SCSI_DEVICES 16
104 #define MPT_LAST_LUN 255
105 #define MPT_SENSE_BUFFER_ALLOC 64
106 /* allow for 256 max sense alloc, but only 255 max request */
107 #if MPT_SENSE_BUFFER_ALLOC >= 256
108 # undef MPT_SENSE_BUFFER_ALLOC
109 # define MPT_SENSE_BUFFER_ALLOC 256
110 # define MPT_SENSE_BUFFER_SIZE 255
112 # define MPT_SENSE_BUFFER_SIZE MPT_SENSE_BUFFER_ALLOC
115 #define MPT_NAME_LENGTH 32
117 #define MPT_PROCFS_MPTBASEDIR "mpt"
118 /* chg it to "driver/fusion" ? */
119 #define MPT_PROCFS_SUMMARY_ALL_NODE MPT_PROCFS_MPTBASEDIR "/summary"
120 #define MPT_PROCFS_SUMMARY_ALL_PATHNAME "/proc/" MPT_PROCFS_SUMMARY_ALL_NODE
121 #define MPT_FW_REV_MAGIC_ID_STRING "FwRev="
123 #define MPT_MAX_REQ_DEPTH 1023
124 #define MPT_DEFAULT_REQ_DEPTH 256
125 #define MPT_MIN_REQ_DEPTH 128
127 #define MPT_MAX_REPLY_DEPTH MPT_MAX_REQ_DEPTH
128 #define MPT_DEFAULT_REPLY_DEPTH 128
129 #define MPT_MIN_REPLY_DEPTH 8
130 #define MPT_MAX_REPLIES_PER_ISR 32
132 #define MPT_MAX_FRAME_SIZE 128
133 #define MPT_DEFAULT_FRAME_SIZE 128
135 #define MPT_REPLY_FRAME_SIZE 0x40 /* Must be a multiple of 8 */
137 #define MPT_SG_REQ_128_SCALE 1
138 #define MPT_SG_REQ_96_SCALE 2
139 #define MPT_SG_REQ_64_SCALE 4
144 #define MPT_COALESCING_TIMEOUT 0x10
147 * SCSI transfer rate defines.
149 #define MPT_ULTRA320 0x08
150 #define MPT_ULTRA160 0x09
151 #define MPT_ULTRA2 0x0A
152 #define MPT_ULTRA 0x0C
153 #define MPT_FAST 0x19
154 #define MPT_SCSI 0x32
155 #define MPT_ASYNC 0xFF
165 * Try to keep these at 2^N-1
167 #define MPT_FC_CAN_QUEUE 127
168 #define MPT_SCSI_CAN_QUEUE 127
171 * Set the MAX_SGE value based on user input.
173 #ifdef CONFIG_FUSION_MAX_SGE
174 #if CONFIG_FUSION_MAX_SGE < 16
175 #define MPT_SCSI_SG_DEPTH 16
176 #elif CONFIG_FUSION_MAX_SGE > 128
177 #define MPT_SCSI_SG_DEPTH 128
179 #define MPT_SCSI_SG_DEPTH CONFIG_FUSION_MAX_SGE
182 #define MPT_SCSI_SG_DEPTH 40
185 #ifdef __KERNEL__ /* { */
186 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
188 #include <linux/proc_fs.h>
190 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
192 * Attempt semi-consistent error & warning msgs across
193 * MPT drivers. NOTE: Users of these macro defs must
194 * themselves define their own MYNAM.
196 #define MYIOC_s_INFO_FMT KERN_INFO MYNAM ": %s: "
197 #define MYIOC_s_NOTE_FMT KERN_NOTICE MYNAM ": %s: "
198 #define MYIOC_s_WARN_FMT KERN_WARNING MYNAM ": %s: WARNING - "
199 #define MYIOC_s_ERR_FMT KERN_ERR MYNAM ": %s: ERROR - "
201 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
203 * MPT protocol driver defs...
206 MPTBASE_DRIVER, /* MPT base class */
207 MPTCTL_DRIVER, /* MPT ioctl class */
208 MPTSCSIH_DRIVER, /* MPT SCSI host (initiator) class */
209 MPTLAN_DRIVER, /* MPT LAN class */
210 MPTSTM_DRIVER, /* MPT SCSI target mode class */
211 MPTDMP_DRIVER, /* MPT Dynamic Multi-pathing class */
215 struct mpt_pci_driver{
216 int (*probe) (struct pci_dev *dev, const struct pci_device_id *id);
217 void (*remove) (struct pci_dev *dev);
218 void (*shutdown) (struct device * dev);
220 int (*resume) (struct pci_dev *dev);
221 int (*suspend) (struct pci_dev *dev, u32 state);
226 * MPT adapter / port / bus / device info structures...
229 typedef union _MPT_FRAME_TRACKER {
231 struct _MPT_FRAME_HDR *forw;
232 struct _MPT_FRAME_HDR *back;
238 * NOTE: When request frames are free, on the linkage structure
239 * contets are valid. All other values are invalid.
240 * In particular, do NOT reply on offset [2]
241 * (in words) being the * message context.
242 * The message context must be reset (computed via base address
243 * + an offset) prior to issuing any command.
245 * NOTE2: On non-32-bit systems, where pointers are LARGE,
246 * using the linkage pointers destroys our sacred MsgContext
247 * field contents. But we don't care anymore because these
248 * are now reset in mpt_put_msg_frame() just prior to sending
249 * a request off to the IOC.
254 * The following _MUST_ match the location of the
255 * MsgContext field in the MPT message headers.
260 u16 req_idx; /* Request index */
261 u8 cb_idx; /* callback function index */
267 * Remark: 32 bit identifier:
269 * 23-16: call back index
270 * 15-0 : request index
275 * We might want to view/access a frame as:
276 * 1) generic request header
282 typedef struct _MPT_FRAME_HDR {
285 SCSIIORequest_t scsireq;
286 SCSIIOReply_t sreply;
287 ConfigReply_t configreply;
288 MPIDefaultReply_t reply;
289 MPT_FRAME_TRACKER frame;
293 #define MPT_REQ_MSGFLAGS_DROPME 0x80
295 /* Used for tracking the free request frames
296 * and free reply frames.
298 typedef struct _MPT_Q_TRACKER {
304 typedef struct _MPT_SGL_HDR {
305 SGESimple32_t sge[1];
308 typedef struct _MPT_SGL64_HDR {
309 SGESimple64_t sge[1];
313 typedef struct _Q_ITEM {
314 struct _Q_ITEM *forw;
315 struct _Q_ITEM *back;
318 typedef struct _Q_TRACKER {
319 struct _Q_ITEM *head;
320 struct _Q_ITEM *tail;
323 typedef struct _MPT_DONE_Q {
324 struct _MPT_DONE_Q *forw;
325 struct _MPT_DONE_Q *back;
329 typedef struct _DONE_Q_TRACKER {
335 * Chip-specific stuff... FC929 delineates break between
336 * FC and Parallel SCSI parts. Do NOT re-order.
351 * System interface register set
354 typedef struct _SYSIF_REGS
356 u32 Doorbell; /* 00 System<->IOC Doorbell reg */
357 u32 WriteSequence; /* 04 Write Sequence register */
358 u32 Diagnostic; /* 08 Diagnostic register */
359 u32 TestBase; /* 0C Test Base Address */
360 u32 DiagRwData; /* 10 Read Write Data (fw download) */
361 u32 DiagRwAddress; /* 14 Read Write Address (fw download)*/
362 u32 Reserved1[6]; /* 18-2F reserved for future use */
363 u32 IntStatus; /* 30 Interrupt Status */
364 u32 IntMask; /* 34 Interrupt Mask */
365 u32 Reserved2[2]; /* 38-3F reserved for future use */
366 u32 RequestFifo; /* 40 Request Post/Free FIFO */
367 u32 ReplyFifo; /* 44 Reply Post/Free FIFO */
368 u32 Reserved3[2]; /* 48-4F reserved for future use */
369 u32 HostIndex; /* 50 Host Index register */
370 u32 Reserved4[15]; /* 54-8F */
371 u32 Fubar; /* 90 For Fubar usage */
372 u32 Reserved5[27]; /* 94-FF */
376 * NOTE: Use MPI_{DOORBELL,WRITESEQ,DIAG}_xxx defs in lsi/mpi.h
377 * in conjunction with SYSIF_REGS accesses!
382 * Dynamic Multi-Pathing specific stuff...
384 #define DMP_MAX_PATHS 8
386 typedef struct _PathInfo {
393 #define PATHINFO_FLAGS_OWNED 0x01
394 #define PATHINFO_FLAGS_EXISTS 0x02
395 #define PATHINFO_FLAGS_AVAILABLE 0x04
396 #define PATHINFO_FLAGS_SECONDARY 0x08
398 #define PFLAGS_EXISTS_AND_AVAIL (PATHINFO_FLAGS_EXISTS|PATHINFO_FLAGS_AVAILABLE)
399 #define PFLAGS_AVAIL_AND_OWNED (PATHINFO_FLAGS_AVAILABLE|PATHINFO_FLAGS_OWNED)
401 typedef struct _ScsiCmndTracker {
408 * VirtDevice - FC LUN device or SCSI target device
409 * (used to be FCSCSI_TARGET)
411 typedef struct _VirtDevice {
412 struct _VirtDevice *forw;
413 struct _VirtDevice *back;
414 struct scsi_device *device;
421 u8 minSyncFactor; /* 0xFF is async */
422 u8 maxOffset; /* 0 if async */
423 u8 maxWidth; /* 0 if narrow, 1 if wide*/
424 u8 negoFlags; /* bit field, 0 if WDTR/SDTR/QAS allowed */
425 u8 raidVolume; /* set, if RAID Volume */
426 u8 type; /* byte 0 of Inquiry data */
427 u8 cflags; /* controller flags */
433 PathInfo path[DMP_MAX_PATHS];
434 struct timer_list stall_timer;
435 struct timer_list retry_timer;
436 struct timer_list gone_timer;
437 ScsiCmndTracker WaitQ;
438 ScsiCmndTracker SentQ;
439 ScsiCmndTracker DoneQ;
441 u32 luns[8]; /* Max LUNs is 256 */
444 /* IEEE Registered Extended Identifier
445 obtained via INQUIRY VPD page 0x83 */
446 /* NOTE: Do not separate uniq_prepad and uniq_data
447 as they are treateed as a single entity in the code */
454 * Fibre Channel (SCSI) target device and associated defines...
456 #define MPT_TARGET_DEFAULT_DV_STATUS 0x00
457 #define MPT_TARGET_FLAGS_VALID_NEGO 0x01
458 #define MPT_TARGET_FLAGS_VALID_INQUIRY 0x02
459 #define MPT_TARGET_FLAGS_Q_YES 0x08
460 #define MPT_TARGET_FLAGS_VALID_56 0x10
461 #define MPT_TARGET_FLAGS_SAF_TE_ISSUED 0x20
463 #define MPT_TARGET_NO_NEGO_WIDE 0x01
464 #define MPT_TARGET_NO_NEGO_SYNC 0x02
465 #define MPT_TARGET_NO_NEGO_QAS 0x04
467 typedef struct _VirtDevTracker {
468 struct _VirtDevice *head;
469 struct _VirtDevice *tail;
476 * /proc/mpt interface
482 read_proc_t *read_proc;
483 write_proc_t *write_proc;
486 #define MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len) \
489 if (len < request) { \
495 *start = buf + offset; \
501 * IOCTL structure and associated defines
504 #define MPT_IOCTL_STATUS_DID_IOCRESET 0x01 /* IOC Reset occurred on the current*/
505 #define MPT_IOCTL_STATUS_RF_VALID 0x02 /* The Reply Frame is VALID */
506 #define MPT_IOCTL_STATUS_TIMER_ACTIVE 0x04 /* The timer is running */
507 #define MPT_IOCTL_STATUS_SENSE_VALID 0x08 /* Sense data is valid */
508 #define MPT_IOCTL_STATUS_COMMAND_GOOD 0x10 /* Command Status GOOD */
509 #define MPT_IOCTL_STATUS_TMTIMER_ACTIVE 0x20 /* The TM timer is running */
510 #define MPT_IOCTL_STATUS_TM_FAILED 0x40 /* User TM request failed */
512 #define MPTCTL_RESET_OK 0x01 /* Issue Bus Reset */
514 typedef struct _MPT_IOCTL {
515 struct _MPT_ADAPTER *ioc;
516 struct timer_list timer; /* timer function for this adapter */
517 u8 ReplyFrame[MPT_DEFAULT_FRAME_SIZE]; /* reply frame data */
518 u8 sense[MPT_SENSE_BUFFER_ALLOC];
519 int wait_done; /* wake-up value for this ioc */
521 u8 status; /* current command status */
522 u8 reset; /* 1 if bus reset allowed */
523 u8 target; /* target for reset */
525 struct timer_list TMtimer; /* timer function for this adapter */
529 * Event Structure and define
531 #define MPTCTL_EVENT_LOG_SIZE (0x0000000A)
532 typedef struct _mpt_ioctl_events {
533 u32 event; /* Specified by define above */
534 u32 eventContext; /* Index or counter */
535 int data[2]; /* First 8 bytes of Event Data */
539 * CONFIGPARM status defines
541 #define MPT_CONFIG_GOOD MPI_IOCSTATUS_SUCCESS
542 #define MPT_CONFIG_ERROR 0x002F
545 * Substructure to store SCSI specific configuration page data
547 /* dvStatus defines: */
548 #define MPT_SCSICFG_NEGOTIATE 0x01 /* Negotiate on next IO */
549 #define MPT_SCSICFG_NEED_DV 0x02 /* Schedule DV */
550 #define MPT_SCSICFG_DV_PENDING 0x04 /* DV on this physical id pending */
551 #define MPT_SCSICFG_DV_NOT_DONE 0x08 /* DV has not been performed */
552 #define MPT_SCSICFG_BLK_NEGO 0x10 /* WriteSDP1 with WDTR and SDTR disabled */
553 #define MPT_SCSICFG_RELOAD_IOC_PG3 0x20 /* IOC Pg 3 data is obsolete */
554 /* Args passed to writeSDP1: */
555 #define MPT_SCSICFG_USE_NVRAM 0x01 /* WriteSDP1 using NVRAM */
556 #define MPT_SCSICFG_ALL_IDS 0x02 /* WriteSDP1 to all IDS */
557 /* #define MPT_SCSICFG_BLK_NEGO 0x10 WriteSDP1 with WDTR and SDTR disabled */
559 typedef struct _ScsiCfgData {
561 int *nvram; /* table of device NVRAM values */
562 IOCPage2_t *pIocPg2; /* table of Raid Volumes */
563 IOCPage3_t *pIocPg3; /* table of physical disks */
564 IOCPage4_t *pIocPg4; /* SEP devices addressing */
565 dma_addr_t IocPg4_dma; /* Phys Addr of IOCPage4 data */
566 int IocPg4Sz; /* IOCPage4 size */
567 u8 dvStatus[MPT_MAX_SCSI_DEVICES];
568 int isRaid; /* bit field, 1 if RAID */
569 u8 minSyncFactor; /* 0xFF if async */
570 u8 maxSyncOffset; /* 0 if async */
571 u8 maxBusWidth; /* 0 if narrow, 1 if wide */
572 u8 busType; /* SE, LVD, HD */
573 u8 sdp1version; /* SDP1 version */
574 u8 sdp1length; /* SDP1 length */
575 u8 sdp0version; /* SDP0 version */
576 u8 sdp0length; /* SDP0 length */
577 u8 dvScheduled; /* 1 if scheduled */
578 u8 forceDv; /* 1 to force DV scheduling */
579 u8 noQas; /* Disable QAS for this adapter */
580 u8 Saf_Te; /* 1 to force all Processors as SAF-TE if Inquiry data length is too short to check for SAF-TE */
585 * Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
587 typedef struct _MPT_ADAPTER
589 struct _MPT_ADAPTER *forw;
590 struct _MPT_ADAPTER *back;
591 int id; /* Unique adapter id N {0,1,2,...} */
592 int pci_irq; /* This irq */
593 char name[MPT_NAME_LENGTH]; /* "iocN" */
594 char *prod_name; /* "LSIFC9x9" */
595 volatile SYSIF_REGS *chip; /* == c8817000 (mmap) */
596 volatile SYSIF_REGS *pio_chip; /* Programmed IO (downloadboot) */
597 u32 mem_phys; /* == f4020000 (mmap) */
598 u32 pio_mem_phys; /* Programmed IO (downloadboot) */
599 int mem_size; /* mmap memory size */
603 u8 *fifo_pool; /* dma pool for fifo's */
604 dma_addr_t fifo_pool_dma;
605 int fifo_pool_sz; /* allocated size */
606 u8 *chain_alloc; /* chain buffer alloc ptr */
607 dma_addr_t chain_alloc_dma;
609 u8 *reply_alloc; /* Reply frames alloc ptr */
610 dma_addr_t reply_alloc_dma;
611 MPT_FRAME_HDR *reply_frames; /* Reply msg frames - rounded up! */
612 dma_addr_t reply_frames_dma;
613 u32 reply_frames_low_dma;
614 int reply_depth; /* Num Allocated reply frames */
615 int reply_sz; /* Reply frame size */
617 /* We (host driver) get to manage our own RequestQueue! */
618 u8 *req_alloc; /* Request frames alloc ptr */
619 dma_addr_t req_alloc_dma;
620 MPT_FRAME_HDR *req_frames; /* Request msg frames - rounded up! */
621 dma_addr_t req_frames_dma;
622 u32 req_frames_low_dma;
623 int req_depth; /* Number of request frames */
624 int req_sz; /* Request frame size (bytes) */
625 spinlock_t FreeQlock;
627 /* Pool of SCSI sense buffers for commands coming from
628 * the SCSI mid-layer. We have one 256 byte sense buffer
629 * for each REQ entry.
632 dma_addr_t sense_buf_pool_dma;
633 u32 sense_buf_low_dma;
635 struct pci_dev *pcidev; /* struct pci_dev pointer */
636 u8 *memmap; /* mmap address */
637 struct Scsi_Host *sh; /* Scsi Host pointer */
638 ScsiCfgData spi_data; /* Scsi config. data */
639 MPT_IOCTL *ioctl; /* ioctl data pointer */
640 struct proc_dir_entry *ioc_dentry;
641 struct _MPT_ADAPTER *alt_ioc; /* ptr to 929 bound adapter port */
642 spinlock_t diagLock; /* diagnostic reset lock */
644 u32 biosVersion; /* BIOS version from IO Unit Page 2 */
645 int eventTypes; /* Event logging parameters */
646 int eventContext; /* Next event context */
647 int eventLogSize; /* Max number of cached events */
648 #ifdef MPTSCSIH_DBG_TIMEOUT
654 struct _mpt_ioctl_events *events; /* pointer to event log */
655 u8 *cached_fw; /* Pointer to FW */
656 dma_addr_t cached_fw_dma;
657 Q_TRACKER configQ; /* linked list of config. requests */
664 u32 hs_req[MPT_MAX_FRAME_SIZE/sizeof(u32)];
665 u16 hs_reply[MPT_MAX_FRAME_SIZE/sizeof(u16)];
666 IOCFactsReply_t facts;
667 PortFactsReply_t pfacts[2];
668 FCPortPage0_t fc_port_page0[2];
669 LANPage0_t lan_cnfg_page0;
670 LANPage1_t lan_cnfg_page1;
672 u32 PciState[64]; /* save PCI state to this area */
675 u8 upload_fw; /* If set, do a fw upload */
676 u8 reload_fw; /* Force a FW Reload on next reset */
678 struct list_head list;
682 typedef struct _MPT_ADAPTER_TRACKER {
685 } MPT_ADAPTER_TRACKER;
688 * New return value convention:
689 * 1 = Ok to free associated request frame
692 typedef int (*MPT_CALLBACK)(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
693 typedef int (*MPT_EVHANDLER)(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply);
694 typedef int (*MPT_RESETHANDLER)(MPT_ADAPTER *ioc, int reset_phase);
695 /* reset_phase defs */
696 #define MPT_IOC_PRE_RESET 0
697 #define MPT_IOC_POST_RESET 1
698 #define MPT_IOC_SETUP_RESET 2
701 * Invent MPT host event (super-set of MPI Events)
702 * Fitted to 1030's 64-byte [max] request frame size
704 typedef struct _MPT_HOST_EVENT {
705 EventNotificationReply_t MpiEvent; /* 8 32-bit words! */
710 #define MPT_HOSTEVENT_IOC_BRINGUP 0x91
711 #define MPT_HOSTEVENT_IOC_RECOVER 0x92
713 /* Define the generic types based on the size
714 * of the dma_addr_t type.
716 typedef struct _mpt_sge {
721 #define mpt_addr_size() \
722 ((sizeof(dma_addr_t) == sizeof(u64)) ? MPI_SGE_FLAGS_64_BIT_ADDRESSING : \
723 MPI_SGE_FLAGS_32_BIT_ADDRESSING)
725 #define mpt_msg_flags() \
726 ((sizeof(dma_addr_t) == sizeof(u64)) ? MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_64 : \
727 MPI_SCSIIO_MSGFLGS_SENSE_WIDTH_32)
729 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
731 * Funky (private) macros...
734 #define dprintk(x) printk x
739 #ifdef MPT_DEBUG_INIT
740 #define dinitprintk(x) printk x
741 #define DBG_DUMP_FW_REQUEST_FRAME(mfp) \
743 u32 *m = (u32 *)(mfp); \
744 printk(KERN_INFO " "); \
745 for (i=0; i<n; i++) \
746 printk(" %08x", le32_to_cpu(m[i])); \
750 #define dinitprintk(x)
751 #define DBG_DUMP_FW_REQUEST_FRAME(mfp)
754 #ifdef MPT_DEBUG_EXIT
755 #define dexitprintk(x) printk x
757 #define dexitprintk(x)
760 #ifdef MPT_DEBUG_RESET
761 #define drsprintk(x) printk x
766 #ifdef MPT_DEBUG_HANDSHAKE
767 #define dhsprintk(x) printk x
772 //#if defined(MPT_DEBUG) || defined(MPT_DEBUG_MSG_FRAME)
773 #if defined(MPT_DEBUG_MSG_FRAME)
774 #define dmfprintk(x) printk x
780 #define dirqprintk(x) printk x
782 #define dirqprintk(x)
786 #define dsgprintk(x) printk x
791 #if defined(MPT_DEBUG_DL) || defined(MPT_DEBUG)
792 #define ddlprintk(x) printk x
799 #define ddvprintk(x) printk x
804 #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
805 #define ddvtprintk(x) printk x
807 #define ddvtprintk(x)
810 #ifdef MPT_DEBUG_IOCTL
811 #define dctlprintk(x) printk x
813 #define dctlprintk(x)
816 #ifdef MPT_DEBUG_RESET
817 #define dtmprintk(x) printk x
823 #define nehprintk(x) printk x
828 #if defined(MPT_DEBUG_CONFIG) || defined(MPT_DEBUG)
829 #define dcprintk(x) printk x
834 #if defined(MPT_DEBUG_SCSI) || defined(MPT_DEBUG) || defined(MPT_DEBUG_MSG_FRAME)
835 #define dsprintk(x) printk x
841 #define MPT_INDEX_2_MFPTR(ioc,idx) \
842 (MPT_FRAME_HDR*)( (u8*)(ioc)->req_frames + (ioc)->req_sz * (idx) )
844 #define MFPTR_2_MPT_INDEX(ioc,mf) \
845 (int)( ((u8*)mf - (u8*)(ioc)->req_frames) / (ioc)->req_sz )
847 #define MPT_INDEX_2_RFPTR(ioc,idx) \
848 (MPT_FRAME_HDR*)( (u8*)(ioc)->reply_frames + (ioc)->req_sz * (idx) )
850 #define Q_INIT(q,type) (q)->head = (q)->tail = (type*)(q)
851 #define Q_IS_EMPTY(q) ((Q_ITEM*)(q)->head == (Q_ITEM*)(q))
853 #define Q_ADD_TAIL(qt,i,type) { \
854 Q_TRACKER *_qt = (Q_TRACKER*)(qt); \
855 Q_ITEM *oldTail = _qt->tail; \
856 (i)->forw = (type*)_qt; \
857 (i)->back = (type*)oldTail; \
858 oldTail->forw = (Q_ITEM*)(i); \
859 _qt->tail = (Q_ITEM*)(i); \
862 #define Q_ADD_HEAD(qt,i,type) { \
863 Q_TRACKER *_qt = (Q_TRACKER*)(qt); \
864 Q_ITEM *oldHead = _qt->head; \
865 (i)->forw = (type*)oldHead; \
866 (i)->back = (type*)_qt; \
867 oldHead->back = (Q_ITEM*)(i); \
868 _qt->head = (Q_ITEM*)(i); \
871 #define Q_DEL_ITEM(i) { \
872 Q_ITEM *_forw = (Q_ITEM*)(i)->forw; \
873 Q_ITEM *_back = (Q_ITEM*)(i)->back; \
874 _back->forw = _forw; \
875 _forw->back = _back; \
878 #define SWAB4(value) \
879 (u32)( (((value) & 0x000000ff) << 24) \
880 | (((value) & 0x0000ff00) << 8) \
881 | (((value) & 0x00ff0000) >> 8) \
882 | (((value) & 0xff000000) >> 24) )
885 #if defined(MPT_DEBUG) || defined(MPT_DEBUG_MSG_FRAME)
886 #define DBG_DUMP_REPLY_FRAME(mfp) \
887 { u32 *m = (u32 *)(mfp); \
888 int i, n = (le32_to_cpu(m[0]) & 0x00FF0000) >> 16; \
889 printk(KERN_INFO " "); \
890 for (i=0; i<n; i++) \
891 printk(" %08x", le32_to_cpu(m[i])); \
894 #define DBG_DUMP_REQUEST_FRAME_HDR(mfp) \
896 u32 *m = (u32 *)(mfp); \
897 printk(KERN_INFO " "); \
898 for (i=0; i<n; i++) \
899 printk(" %08x", le32_to_cpu(m[i])); \
903 #define DBG_DUMP_REPLY_FRAME(mfp)
904 #define DBG_DUMP_REQUEST_FRAME_HDR(mfp)
908 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
911 * MPT_SCSI_HOST defines - Used by the IOCTL and the SCSI drivers
912 * Private to the driver.
914 /* LOCAL structure and fields used when processing
915 * internally generated commands. These include:
916 * bus scan, dv and config requests.
918 typedef struct _MPT_LOCAL_REPLY {
919 ConfigPageHeader_t header;
921 u8 sense[SCSI_STD_SENSE_BYTES];
927 #define MPT_HOST_BUS_UNKNOWN (0xFF)
928 #define MPT_HOST_TOO_MANY_TM (0x05)
929 #define MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
930 #define MPT_HOST_NO_CHAIN (0xFFFFFFFF)
931 #define MPT_NVRAM_MASK_TIMEOUT (0x000000FF)
932 #define MPT_NVRAM_SYNC_MASK (0x0000FF00)
933 #define MPT_NVRAM_SYNC_SHIFT (8)
934 #define MPT_NVRAM_DISCONNECT_ENABLE (0x00010000)
935 #define MPT_NVRAM_ID_SCAN_ENABLE (0x00020000)
936 #define MPT_NVRAM_LUN_SCAN_ENABLE (0x00040000)
937 #define MPT_NVRAM_TAG_QUEUE_ENABLE (0x00080000)
938 #define MPT_NVRAM_WIDE_DISABLE (0x00100000)
939 #define MPT_NVRAM_BOOT_CHOICE (0x00200000)
941 /* The TM_STATE variable is used to provide strict single threading of TM
942 * requests as well as communicate TM error conditions.
944 #define TM_STATE_NONE (0)
945 #define TM_STATE_IN_PROGRESS (1)
946 #define TM_STATE_ERROR (2)
948 typedef struct _MPT_SCSI_HOST {
952 struct scsi_cmnd **ScsiLookup;
953 /* Pool of buffers for chaining. ReqToChain
954 * and ChainToChain track index of chain buffers.
955 * ChainBuffer (DMA) virt/phys addresses.
956 * FreeChainQ (lock) locking mechanisms.
961 dma_addr_t ChainBufferDMA;
962 MPT_Q_TRACKER FreeChainQ;
963 spinlock_t FreeChainQlock;
965 VirtDevice **Targets;
966 MPT_LOCAL_REPLY *pLocal; /* used for internal commands */
967 struct timer_list timer;
968 struct timer_list TMtimer; /* Timer for TM commands ONLY */
969 /* Pool of memory for holding SCpnts before doing
970 * OS callbacks. freeQ is the free pool.
973 DONE_Q_TRACKER freeQ;
974 DONE_Q_TRACKER doneQ; /* Holds Linux formmatted requests */
975 DONE_Q_TRACKER pendingQ; /* Holds MPI formmatted requests */
976 MPT_Q_TRACKER taskQ; /* TM request Q */
977 spinlock_t freedoneQlock;
979 int num_chain; /* Number of chain buffers */
980 int max_sge; /* Max No of SGE*/
984 u8 is_spi; /* Parallel SCSI i/f */
985 u8 negoNvram; /* DV disabled, nego NVRAM */
986 u8 is_multipath; /* Multi-path compatible */
989 MPT_FRAME_HDR *tmPtr; /* Ptr to TM request*/
990 MPT_FRAME_HDR *cmdPtr; /* Ptr to nonOS request */
991 struct scsi_cmnd *abortSCpnt;
992 MPT_LOCAL_REPLY localReply; /* internal cmd reply struct */
993 unsigned long hard_resets; /* driver forced bus resets count */
994 unsigned long soft_resets; /* fw/external bus resets count */
995 unsigned long timeouts; /* cmd timeouts */
996 ushort sel_timeout[MPT_MAX_FC_DEVICES];
999 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1001 * More Dynamic Multi-Pathing stuff...
1004 /* Forward decl, a strange C thing, to prevent gcc compiler warnings */
1008 * DMP service layer structure / API interface
1010 typedef struct _DmpServices {
1011 VirtDevTracker VdevList;
1012 struct semaphore *Daemon;
1013 int (*ScsiPathSelect)
1014 (struct scsi_cmnd *, MPT_SCSI_HOST **hd, int *target, int *lun);
1016 (MPT_SCSI_HOST *, struct scsi_cmnd *,
1019 void (*mptscsih_scanVlist)
1020 (MPT_SCSI_HOST *, int portnum);
1022 (struct scsi_cmnd *);
1024 (struct scsi_cmnd *);
1027 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1029 * Generic structure passed to the base mpt_config function.
1031 typedef struct _x_config_parms {
1032 Q_ITEM linkage; /* linked list */
1033 struct timer_list timer; /* timer function for this request */
1034 ConfigPageHeader_t *hdr;
1035 dma_addr_t physAddr;
1036 int wait_done; /* wait for this request */
1037 u32 pageAddr; /* properly formatted */
1040 u8 timeout; /* seconds */
1046 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1048 * Public entry points...
1050 extern int mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass);
1051 extern void mpt_deregister(int cb_idx);
1052 extern int mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc);
1053 extern void mpt_event_deregister(int cb_idx);
1054 extern int mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func);
1055 extern void mpt_reset_deregister(int cb_idx);
1056 extern int mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx);
1057 extern void mpt_device_driver_deregister(int cb_idx);
1058 extern int mpt_register_ascqops_strings(void *ascqTable, int ascqtbl_sz, const char **opsTable);
1059 extern void mpt_deregister_ascqops_strings(void);
1060 extern MPT_FRAME_HDR *mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc);
1061 extern void mpt_free_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
1062 extern void mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
1063 extern void mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr);
1064 extern void mpt_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr);
1066 extern int mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag);
1067 extern int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req, int replyBytes, u16 *u16reply, int maxwait, int sleepFlag);
1068 extern int mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp);
1069 extern u32 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
1070 extern void mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buf, int *size, int len, int showlan);
1071 extern int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
1072 extern int mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *cfg);
1073 extern int mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *cfg);
1074 extern void mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size);
1075 extern void mpt_free_fw_memory(MPT_ADAPTER *ioc);
1076 extern int mpt_findImVolumes(MPT_ADAPTER *ioc);
1077 extern int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
1080 * Public data decl's...
1082 extern struct list_head ioc_list;
1083 extern struct proc_dir_entry *mpt_proc_root_dir;
1084 extern DmpServices_t *DmpService;
1086 extern int mpt_lan_index; /* needed by mptlan.c */
1087 extern int mpt_stm_index; /* needed by mptstm.c */
1089 extern void *mpt_v_ASCQ_TablePtr;
1090 extern const char **mpt_ScsiOpcodesPtr;
1091 extern int mpt_ASCQ_TableSz;
1093 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1094 #endif /* } __KERNEL__ */
1097 * More (public) macros...
1100 #define offsetof(t, m) ((size_t) (&((t *)0)->m))
1103 #if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__x86_64__)
1104 #define CAST_U32_TO_PTR(x) ((void *)(u64)x)
1105 #define CAST_PTR_TO_U32(x) ((u32)(u64)x)
1107 #define CAST_U32_TO_PTR(x) ((void *)x)
1108 #define CAST_PTR_TO_U32(x) ((u32)x)
1111 #define MPT_PROTOCOL_FLAGS_c_c_c_c(pflags) \
1112 ((pflags) & MPI_PORTFACTS_PROTOCOL_INITIATOR) ? 'I' : 'i', \
1113 ((pflags) & MPI_PORTFACTS_PROTOCOL_TARGET) ? 'T' : 't', \
1114 ((pflags) & MPI_PORTFACTS_PROTOCOL_LAN) ? 'L' : 'l', \
1115 ((pflags) & MPI_PORTFACTS_PROTOCOL_LOGBUSADDR) ? 'B' : 'b'
1118 * Shifted SGE Defines - Use in SGE with FlagsLength member.
1119 * Otherwise, use MPI_xxx defines (refer to "lsi/mpi.h" header).
1120 * Defaults: 32 bit SGE, SYSTEM_ADDRESS if direction bit is 0, read
1122 #define MPT_TRANSFER_IOC_TO_HOST (0x00000000)
1123 #define MPT_TRANSFER_HOST_TO_IOC (0x04000000)
1124 #define MPT_SGE_FLAGS_LAST_ELEMENT (0x80000000)
1125 #define MPT_SGE_FLAGS_END_OF_BUFFER (0x40000000)
1126 #define MPT_SGE_FLAGS_LOCAL_ADDRESS (0x08000000)
1127 #define MPT_SGE_FLAGS_DIRECTION (0x04000000)
1128 #define MPT_SGE_FLAGS_ADDRESSING (mpt_addr_size() << MPI_SGE_FLAGS_SHIFT)
1129 #define MPT_SGE_FLAGS_END_OF_LIST (0x01000000)
1131 #define MPT_SGE_FLAGS_TRANSACTION_ELEMENT (0x00000000)
1132 #define MPT_SGE_FLAGS_SIMPLE_ELEMENT (0x10000000)
1133 #define MPT_SGE_FLAGS_CHAIN_ELEMENT (0x30000000)
1134 #define MPT_SGE_FLAGS_ELEMENT_MASK (0x30000000)
1136 #define MPT_SGE_FLAGS_SSIMPLE_READ \
1137 (MPT_SGE_FLAGS_LAST_ELEMENT | \
1138 MPT_SGE_FLAGS_END_OF_BUFFER | \
1139 MPT_SGE_FLAGS_END_OF_LIST | \
1140 MPT_SGE_FLAGS_SIMPLE_ELEMENT | \
1141 MPT_SGE_FLAGS_ADDRESSING | \
1142 MPT_TRANSFER_IOC_TO_HOST)
1143 #define MPT_SGE_FLAGS_SSIMPLE_WRITE \
1144 (MPT_SGE_FLAGS_LAST_ELEMENT | \
1145 MPT_SGE_FLAGS_END_OF_BUFFER | \
1146 MPT_SGE_FLAGS_END_OF_LIST | \
1147 MPT_SGE_FLAGS_SIMPLE_ELEMENT | \
1148 MPT_SGE_FLAGS_ADDRESSING | \
1149 MPT_TRANSFER_HOST_TO_IOC)
1151 /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/