


/****************************************************************************
;
; NAME: oswrap.h
;
;
; DESCRIPTION:
;
;       Linux interface wrap definitions
;
;
; REVISION HISTORY:
;
;       $Log: /ESASHBA2/Linux/driver/oswrap.h $
; 
; 38    11/05/08 2:45p Jseba
; OsAbortTarget is now OsAbortCommand
; 
; 37    10/07/08 4:51p Jseba
; ESAS2HBA support
; 
; 36    9/17/08 2:37p Jseba
; Remove OsDebugHeader; initial ESASHBA2 support
; 
; 35    8/14/08 3:59p Jseba
; Add SCSICMD_FLAGS_USE_CMD_PTR for 2.6.26 
; 
; 34    7/14/08 3:23p Jseba
; Add power management code
; 
; 33    5/27/08 4:23p Jseba
; Add OsDebugPrint so wrapper can pass debug information to the core; add
; a scsicmd_off flag to specify whether the sense_buffer is a pointer;
; bump CORE_REVs
; 
; 32    4/24/08 11:38a Jseba
; Bump core revs
; 
; 31    4/17/08 4:52p Jseba
; CELERITY8FC is now CELERITY8FC
; 
; 30    3/05/08 1:53p Jseba
; CELERITYFC8 changes
; 
; 29    11/27/07 5:06p Jseba
; Add OsAllowChangeNotification
; 
; 28    11/06/07 1:00p Jseba
; OsCleanup now returns index of adapter that was cleaned up; bump
; CORE_REVs for all families
; 
; 27    10/16/07 10:02a Jseba
; Added OsGetNextScanId and SCAN_STATE defines
; 
; 26    9/21/07 3:12p Jseba
; Cleaned up DEBUG_HEADER
; 
; 25    8/21/07 10:42a Jseba
; Removed unused OS core functions
; 
; 24    8/15/07 2:52p Jseba
; Use OsLikely/Unlikely
; 
; 23    8/06/07 3:29p Jseba
; Support for ESASHBA driver; remove wrapper structures in favor of
; direct access via structure offsets (see LinuxExchangeOffsets); new
; OsStartCommand prototype
; 
; 22    11/14/06 2:31p Jseba
; Add "fs" handlers for ESASRAID FS_API
; 
; 21    10/09/06 9:48a Jseba
; Added OsGetNvramSize instead of hard-coded NVRAM size; added
; OsReadVda/OsWriteVda for ESASRAID; added ATTO error codes; bump
; CELERITYFC core revision
; 
; 20    9/27/06 9:43a Jseba
; Don't use cmd->data_cmnd
; 
; 19    9/22/06 5:24p Jseba
; Remove ATTO_MAX_CMDS, ATTO_CMD_PER_LUN, and ATTO_SG_SEGS; use new
; OsStartCommand return values
; 
; 18    9/20/06 10:28a Jseba
; Support for EXPRESS2; OsStartCommand no longer returns a status -
; failed commands will be completed via LinuxCompleteRequest
; 
; 17    8/28/06 11:19a Jseba
; Support for ESASRAID driver
; 
; 16    7/24/06 4:15p Jseba
; Scrap GlobalFlags; increase default max commands to 128; bump core rev
; 
; 15    1/03/06 10:27a Jseba
; Add OsGetAdapterHost; bump CELERITYFC_CORE_REV
; 
; 14    8/04/05 11:56a Jseba
; Bump core rev for 2.13 release
; 
; 13    3/07/05 5:17p Jseba
; Bump core rev
; 
; 12    1/25/05 11:30a Jseba
; Bump CELERITYFC_CORE_REV for 2.00 release
; 
; 11    12/28/04 9:53a Jseba
; Add os_minor_version to tell core what kernel version we are running
; 
; 10    11/29/04 3:46p Sschmitz
; Bump CELERITYMEM_CORE_REV for 1.40 release
; 
; 9     11/19/04 11:27a Jseba
; sysfs support; bump core revision
; 
; 8     10/15/04 2:33p Jseba
; Bump CELERITYFC_CORE_REV for 1.31 release
; 
; 7     6/29/04 3:01p Jseba
; Add OsDebugHeader; bump CoreRev
; 
; 6     3/31/04 3:54p Jseba
; Initial support for 2.6 kernel
; 
; 5     2/04/04 9:41a Jseba
; Added CELERITYFC_MAX_ID and CELERITYFC_MAX_LUN
; 
; 4     12/10/03 3:22p Jseba
; Change CELERITYFC_LONGNAME
; 
; 3     12/09/03 9:52a Jseba
; Rename to celerityfc
; 
; 2     11/18/03 10:26a Jseba
; Add SCSICMPLTW structure; reduce EPCIFC3_MAX_CMDS to 63
; 
; 1     10/24/03 10:38a Jseba
; Initial entry
; 
; 
;
;
; THIS PROGRAM AND THE INFORMATION CONTAINED HEREIN IS THE PROPERTY OF
; ATTO TECHNOLOGY, INC. AND SHALL NOT BE REPRODUCED, COPIED, OR USED IN
; WHOLE OR IN PART OTHER THAN AS PROVIDED FOR IN THE LICENSE AGREEMENT
; PURSUANT TO WHICH IT WAS FURNISHED.
;
; COPYRIGHT (c) ATTO TECHNOLOGY, INC. 2003
; ALL RIGHTS RESERVED.
;
;***************************************************************************/

#ifndef _OSWRAP_H_
#define _OSWRAP_H_

#ifdef CELERITYFC
#define ATTO_DRVR_NAME     "celerityfc"
#define ATTO_LONGNAME      "ATTO Celerity Fibre Channel Adapter"
#define ATTO_CORE_REV       15
#endif

#ifdef ESASRAID
#define ATTO_DRVR_NAME     "esasraid"
#define ATTO_LONGNAME      "ATTO ExpressSAS RAID Adapter"
#define ATTO_CORE_REV       5
#define initiator_mode      1
#endif

#ifdef EXPRESS2
#define ATTO_DRVR_NAME     "express2"
#define ATTO_LONGNAME      "ATTO ExpressPCI SCSI Adapter"
#define ATTO_CORE_REV       5
#define initiator_mode      1
#endif

#ifdef ESASHBA
#define ATTO_DRVR_NAME     "esashba"
#define ATTO_LONGNAME      "ATTO ExpressSAS Adapter"
#define ATTO_CORE_REV       4
#define initiator_mode      1
#endif

#ifdef EXPRESS2
#define ATTO_MAX_ID        15
#define ATTO_MAX_LUN       62
#else
#define ATTO_MAX_ID        255
#define ATTO_MAX_LUN       255
#endif

#ifdef CELERITY8FC
#define CELERITYFC
#define ATTO_DRVR_NAME     "celerity8fc"
#define ATTO_LONGNAME      "ATTO Celerity 8GB Fibre Channel Adapter"
#define ATTO_CORE_REV       3
#endif

#ifdef ESAS2HBA
#define ESASHBA
#define ATTO_DRVR_NAME     "esas2hba"
#define ATTO_LONGNAME      "ATTO ExpressSAS 6GB Adapter"
#define ATTO_CORE_REV       1
#define initiator_mode      ((target_mode) ? (multimode_ports) : 1)
#endif

#include "osioctl.h"

/* Wrappers for Linux structures */

typedef struct _pci_resource_wrapper
{
    unsigned long start;
    unsigned long end;
} PCIRW, *PPCIRW;

#define PCIDW_RESOURCE_COUNT   5

typedef struct _pci_dev_wrapper
{
    void *original;
    PCIRW resource [PCIDW_RESOURCE_COUNT];
    unsigned char bus_number;
    unsigned int devfn;
    unsigned int irq;
    unsigned short device;
    unsigned short vendor;

} PCIDW, *PPCIDW;

typedef struct _scsi_host_wrapper
{
    void *original;
    unsigned short host_no;
    int os_minor_version;
} SHW, *PSHW;

typedef struct _sg_list_offsets
{
    unsigned int    dma_len_offset;
    unsigned int    dma_addr_offset;
    unsigned int    dma_addr_size;
    unsigned int    sgl_size;
} SGL_OFFSETS, *PSGL_OFFSETS;

typedef struct _scsi_cmd_offsets
{
    unsigned int    scsi_done_offset;
    unsigned int    cmd_len_offset;
    unsigned int    sense_buffer_offset;
    unsigned int    data_dir_offset;
    unsigned int    cmnd_offset;
    unsigned int    req_bufflen_offset;
    unsigned int    req_buffer_offset;
    unsigned int    use_sg_offset;
    unsigned int    sense_buffer_size;
    unsigned int    data_dir_unknown;
    unsigned int    data_dir_write;
    unsigned int    data_dir_read;
    unsigned int    data_dir_none;
    unsigned int    tag_value_head;
    unsigned int    tag_value_simple;
    unsigned int    tag_value_ordered;
    DWORD           flags;
#define SCSICMD_FLAGS_USE_SENSE_PTR  0x00000001
#define SCSICMD_FLAGS_USE_CMD_PTR    0x00000002
} SCSICMD_OFFSETS, *PSCSICMD_OFFSETS;

/* Other functions */

void LinuxPrint (char *fmt, ...);

/* Functions that live in the core driver */

int OsInitAdapter (PSHW shw, void *context, PPCIDW pcidw, DWORD index);
int OsHostReset (void *Context);
int OsBusReset (void *Context);
int OsDeviceReset (void *Context, DWORD target, DWORD lun);
int OsAbortCommand (void *Context, void *cmd);
int OsCleanup (void *host);
int OsInProcInfo (char *buffer, int len, int host);
int OsOutProcInfo (char *buffer, char **start, DWORD offset, int len, int host);
char *OsDriverInfo (void *Context);
int OsGetIoctlSize (int cmd);
int OsIoctl (void *Context, int cmd, void *ioctl_data);
int OsGetNvramSize (void *Context);
int OsGetCoreRev (void);
void OsUninitAdapters (void);
void OsDebugString (char *);
int OsReadFw (void *Context, char *buf, long off, int count);
int OsWriteFw (void *Context, char *buf, long off, int count);
int OsReadVda (void *Context, char *buf, long off, int count);
int OsWriteVda (void *Context, char *buf, long off, int count);
int OsReadFs (void *Context, char *buf, long off, int count);
int OsWriteFs (void *Context, char *buf, long off, int count);
int OsReadVersion (char *buf);
void *OsGetAdapterHost (int index);
unsigned int OsGetNextScanId (int index, BYTE *ScanState);
void OsAllowChangeNotification (int index, int Allow);
int OsStartCommand (void *hostdata, void *original_cmd, unsigned int target,
                    unsigned int lun, unsigned int tag);
int OsSuspend (void *host);
int OsResume (void *host);
#if defined (CELERITY8FC)
int celerity8fc_target_connect (int host, int cmd, PEXPRESS_IOCTL ioctl);
#elif defined (CELERITYFC)
int celerityfc_target_connect (int host, int cmd, PEXPRESS_IOCTL ioctl);
#elif defined (ESAS2HBA)
int esas2hba_target_connect (int host, int cmd, PEXPRESS_IOCTL ioctl);
#endif


/* Return values for OsStartCommand: */
#define OSSC_SUCCESS      (0)
#define OSSC_SEL_TIMEOUT  (-1)
#define OSSC_BUSY         (-2)

/* Scan states for device rescans */
#define SCAN_STATE_NO_SCAN      0x00
#define SCAN_STATE_LOGIN        0x01
#define SCAN_STATE_LOGOUT       0x02
#define SCAN_STATE_LUN_CHANGE   0x04
#define SCAN_STATE_RESCAN_MASK  0x07

/* Other needed defines */

#define ATTO_MAX_DEVICES       32
#define ATTO_VENDOR_ID         0x117C
#define LSI_VENDOR_ID          0x1000

#define OSIOCTL_ALL_DONE       0
#define OSIOCTL_COPY_BACK      1

#define ATTONODE_NAME         "ATTONode"

/* ATTO error codes, use LinuxGetErrno to */
/* translate to native system error codes */

#define ATTO_BUSY            -1
#define ATTO_NO_DEVICE       -2
#define ATTO_NOT_IMPLMNTD    -3
#define ATTO_INVALID_ARG     -4
#define ATTO_OUT_OF_MEMORY   -5

/* Max length for string parameters */

#define ATTO_PARAM_STR_LEN   1024

/* Debug output as printk calls */

#define DEBUG_HEADER  ATTO_DRVR_NAME ": "

#ifndef ATTO_DEBUG
#define DEBUG_ALL(a)
#define DEBUG_LOUD(a)
#else
#define DEBUG_ALL(a)  printk a
#ifndef ATTO_DEBUG_LOUD
#define DEBUG_LOUD(a)
#else
#define DEBUG_LOUD(a) printk a
#endif
#endif

void OsDebugPrint (char *fmt, ...);

#define OsLikely(_exp)      __builtin_expect (!! (_exp), 1)
#define OsUnlikely(_exp)    __builtin_expect (!! (_exp), 0)

#endif /* _OSWRAP_H_ */
