Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __MEGARAID_H__
0003 #define __MEGARAID_H__
0004 
0005 #include <linux/spinlock.h>
0006 #include <linux/mutex.h>
0007 #include <scsi/scsi_cmnd.h>
0008 
0009 #define MEGARAID_VERSION    \
0010     "v2.00.4 (Release Date: Thu Feb 9 08:51:30 EST 2006)\n"
0011 
0012 /*
0013  * Driver features - change the values to enable or disable features in the
0014  * driver.
0015  */
0016 
0017 /*
0018  * Command coalescing - This feature allows the driver to be able to combine
0019  * two or more commands and issue as one command in order to boost I/O
0020  * performance. Useful if the nature of the I/O is sequential. It is not very
0021  * useful for random natured I/Os.
0022  */
0023 #define MEGA_HAVE_COALESCING    0
0024 
0025 /*
0026  * Clustering support - Set this flag if you are planning to use the
0027  * clustering services provided by the megaraid controllers and planning to
0028  * setup a cluster
0029  */
0030 #define MEGA_HAVE_CLUSTERING    1
0031 
0032 /*
0033  * Driver statistics - Set this flag if you are interested in statics about
0034  * number of I/O completed on each logical drive and how many interrupts
0035  * generated. If enabled, this information is available through /proc
0036  * interface and through the private ioctl. Setting this flag has a
0037  * performance penalty.
0038  */
0039 #define MEGA_HAVE_STATS     0
0040 
0041 /*
0042  * Enhanced /proc interface - This feature will allow you to have a more
0043  * detailed /proc interface for megaraid driver. E.g., a real time update of
0044  * the status of the logical drives, battery status, physical drives etc.
0045  */
0046 #define MEGA_HAVE_ENH_PROC  1
0047 
0048 #define MAX_DEV_TYPE    32
0049 
0050 #define PCI_DEVICE_ID_DISCOVERY     0x000E
0051 #define PCI_DEVICE_ID_PERC4_DI      0x000F
0052 #define PCI_DEVICE_ID_PERC4_QC_VERDE    0x0407
0053 
0054 #define HBA_SIGNATURE               0x3344
0055 #define HBA_SIGNATURE_471       0xCCCC
0056 #define HBA_SIGNATURE_64BIT     0x0299
0057 
0058 #define MBOX_BUSY_WAIT          10  /* wait for up to 10 usec for
0059                            mailbox to be free */
0060 #define DEFAULT_INITIATOR_ID    7
0061 
0062 #define MAX_SGLIST      64  /* max supported in f/w */
0063 #define MIN_SGLIST      26  /* guaranteed to support these many */
0064 #define MAX_COMMANDS        126
0065 #define CMDID_INT_CMDS      MAX_COMMANDS+1  /* make sure CMDID_INT_CMDS
0066                         is less than max commands
0067                         supported by any f/w */
0068 
0069 #define MAX_CDB_LEN         10
0070 #define MAX_EXT_CDB_LEN     16  /* we support cdb length up to 16 */
0071 
0072 #define DEF_CMD_PER_LUN     63
0073 #define MAX_CMD_PER_LUN     MAX_COMMANDS
0074 #define MAX_FIRMWARE_STATUS 46
0075 #define MAX_XFER_PER_CMD    (64*1024)
0076 #define MAX_SECTORS_PER_IO  128
0077 
0078 #define MAX_LOGICAL_DRIVES_40LD     40
0079 #define FC_MAX_PHYSICAL_DEVICES     256
0080 #define MAX_LOGICAL_DRIVES_8LD      8
0081 #define MAX_CHANNELS            5
0082 #define MAX_TARGET          15
0083 #define MAX_PHYSICAL_DRIVES     MAX_CHANNELS*MAX_TARGET
0084 #define MAX_ROW_SIZE_40LD       32
0085 #define MAX_ROW_SIZE_8LD        8
0086 #define MAX_SPAN_DEPTH          8
0087 
0088 #define NVIRT_CHAN      4   /* # of virtual channels to represent
0089                        up to 60 logical drives */
0090 struct mbox_out {
0091     /* 0x0 */ u8 cmd;
0092     /* 0x1 */ u8 cmdid;
0093     /* 0x2 */ u16 numsectors;
0094     /* 0x4 */ u32 lba;
0095     /* 0x8 */ u32 xferaddr;
0096     /* 0xC */ u8 logdrv;
0097     /* 0xD */ u8 numsgelements;
0098     /* 0xE */ u8 resvd;
0099 } __attribute__ ((packed));
0100 
0101 struct mbox_in {
0102     /* 0xF */ volatile u8 busy;
0103     /* 0x10 */ volatile u8 numstatus;
0104     /* 0x11 */ volatile u8 status;
0105     /* 0x12 */ volatile u8 completed[MAX_FIRMWARE_STATUS];
0106     volatile u8 poll;
0107     volatile u8 ack;
0108 } __attribute__ ((packed));
0109 
0110 typedef struct {
0111     struct mbox_out m_out;
0112     struct mbox_in  m_in;
0113 } __attribute__ ((packed)) mbox_t;
0114 
0115 typedef struct {
0116     u32 xfer_segment_lo;
0117     u32 xfer_segment_hi;
0118     mbox_t mbox;
0119 } __attribute__ ((packed)) mbox64_t;
0120 
0121 
0122 /*
0123  * Passthru definitions
0124  */
0125 #define MAX_REQ_SENSE_LEN       0x20
0126 
0127 typedef struct {
0128     u8 timeout:3;       /* 0=6sec/1=60sec/2=10min/3=3hrs */
0129     u8 ars:1;
0130     u8 reserved:3;
0131     u8 islogical:1;
0132     u8 logdrv;      /* if islogical == 1 */
0133     u8 channel;     /* if islogical == 0 */
0134     u8 target;      /* if islogical == 0 */
0135     u8 queuetag;        /* unused */
0136     u8 queueaction;     /* unused */
0137     u8 cdb[MAX_CDB_LEN];
0138     u8 cdblen;
0139     u8 reqsenselen;
0140     u8 reqsensearea[MAX_REQ_SENSE_LEN];
0141     u8 numsgelements;
0142     u8 scsistatus;
0143     u32 dataxferaddr;
0144     u32 dataxferlen;
0145 } __attribute__ ((packed)) mega_passthru;
0146 
0147 
0148 /*
0149  * Extended passthru: support CDB > 10 bytes
0150  */
0151 typedef struct {
0152     u8 timeout:3;       /* 0=6sec/1=60sec/2=10min/3=3hrs */
0153     u8 ars:1;
0154     u8 rsvd1:1;
0155     u8 cd_rom:1;
0156     u8 rsvd2:1;
0157     u8 islogical:1;
0158     u8 logdrv;      /* if islogical == 1 */
0159     u8 channel;     /* if islogical == 0 */
0160     u8 target;      /* if islogical == 0 */
0161     u8 queuetag;        /* unused */
0162     u8 queueaction;     /* unused */
0163     u8 cdblen;
0164     u8 rsvd3;
0165     u8 cdb[MAX_EXT_CDB_LEN];
0166     u8 numsgelements;
0167     u8 status;
0168     u8 reqsenselen;
0169     u8 reqsensearea[MAX_REQ_SENSE_LEN];
0170     u8 rsvd4;
0171     u32 dataxferaddr;
0172     u32 dataxferlen;
0173 } __attribute__ ((packed)) mega_ext_passthru;
0174 
0175 typedef struct {
0176     u64 address;
0177     u32 length;
0178 } __attribute__ ((packed)) mega_sgl64;
0179 
0180 typedef struct {
0181     u32 address;
0182     u32 length;
0183 } __attribute__ ((packed)) mega_sglist;
0184 
0185 
0186 /* Queued command data */
0187 typedef struct {
0188     int idx;
0189     u32 state;
0190     struct list_head    list;
0191     u8  raw_mbox[66];
0192     u32 dma_type;
0193     u32 dma_direction;
0194 
0195     struct scsi_cmnd    *cmd;
0196     dma_addr_t  dma_h_bulkdata;
0197     dma_addr_t  dma_h_sgdata;
0198 
0199     mega_sglist *sgl;
0200     mega_sgl64  *sgl64;
0201     dma_addr_t  sgl_dma_addr;
0202 
0203     mega_passthru       *pthru;
0204     dma_addr_t      pthru_dma_addr;
0205     mega_ext_passthru   *epthru;
0206     dma_addr_t      epthru_dma_addr;
0207 } scb_t;
0208 
0209 /*
0210  * Flags to follow the scb as it transitions between various stages
0211  */
0212 #define SCB_FREE    0x0000  /* on the free list */
0213 #define SCB_ACTIVE  0x0001  /* off the free list */
0214 #define SCB_PENDQ   0x0002  /* on the pending queue */
0215 #define SCB_ISSUED  0x0004  /* issued - owner f/w */
0216 #define SCB_ABORT   0x0008  /* Got an abort for this one */
0217 #define SCB_RESET   0x0010  /* Got a reset for this one */
0218 
0219 /*
0220  * Utilities declare this strcture size as 1024 bytes. So more fields can
0221  * be added in future.
0222  */
0223 typedef struct {
0224     u32 data_size; /* current size in bytes (not including resvd) */
0225 
0226     u32 config_signature;
0227         /* Current value is 0x00282008
0228          * 0x28=MAX_LOGICAL_DRIVES,
0229          * 0x20=Number of stripes and
0230          * 0x08=Number of spans */
0231 
0232     u8  fw_version[16];     /* printable ASCI string */
0233     u8  bios_version[16];   /* printable ASCI string */
0234     u8  product_name[80];   /* printable ASCI string */
0235 
0236     u8  max_commands;       /* Max. concurrent commands supported */
0237     u8  nchannels;      /* Number of SCSI Channels detected */
0238     u8  fc_loop_present;    /* Number of Fibre Loops detected */
0239     u8  mem_type;       /* EDO, FPM, SDRAM etc */
0240 
0241     u32 signature;
0242     u16 dram_size;      /* In terms of MB */
0243     u16 subsysid;
0244 
0245     u16 subsysvid;
0246     u8  notify_counters;
0247     u8  pad1k[889];     /* 135 + 889 resvd = 1024 total size */
0248 } __attribute__ ((packed)) mega_product_info;
0249 
0250 struct notify {
0251     u32 global_counter; /* Any change increments this counter */
0252 
0253     u8 param_counter;   /* Indicates any params changed  */
0254     u8 param_id;        /* Param modified - defined below */
0255     u16 param_val;      /* New val of last param modified */
0256 
0257     u8 write_config_counter;    /* write config occurred */
0258     u8 write_config_rsvd[3];
0259 
0260     u8 ldrv_op_counter; /* Indicates ldrv op started/completed */
0261     u8 ldrv_opid;       /* ldrv num */
0262     u8 ldrv_opcmd;      /* ldrv operation - defined below */
0263     u8 ldrv_opstatus;   /* status of the operation */
0264 
0265     u8 ldrv_state_counter;  /* Indicates change of ldrv state */
0266     u8 ldrv_state_id;       /* ldrv num */
0267     u8 ldrv_state_new;  /* New state */
0268     u8 ldrv_state_old;  /* old state */
0269 
0270     u8 pdrv_state_counter;  /* Indicates change of ldrv state */
0271     u8 pdrv_state_id;       /* pdrv id */
0272     u8 pdrv_state_new;  /* New state */
0273     u8 pdrv_state_old;  /* old state */
0274 
0275     u8 pdrv_fmt_counter;    /* Indicates pdrv format started/over */
0276     u8 pdrv_fmt_id;     /* pdrv id */
0277     u8 pdrv_fmt_val;        /* format started/over */
0278     u8 pdrv_fmt_rsvd;
0279 
0280     u8 targ_xfer_counter;   /* Indicates SCSI-2 Xfer rate change */
0281     u8 targ_xfer_id;    /* pdrv Id  */
0282     u8 targ_xfer_val;       /* new Xfer params of last pdrv */
0283     u8 targ_xfer_rsvd;
0284 
0285     u8 fcloop_id_chg_counter;   /* Indicates loopid changed */
0286     u8 fcloopid_pdrvid;     /* pdrv id */
0287     u8 fcloop_id0;          /* loopid on fc loop 0 */
0288     u8 fcloop_id1;          /* loopid on fc loop 1 */
0289 
0290     u8 fcloop_state_counter;    /* Indicates loop state changed */
0291     u8 fcloop_state0;       /* state of fc loop 0 */
0292     u8 fcloop_state1;       /* state of fc loop 1 */
0293     u8 fcloop_state_rsvd;
0294 } __attribute__ ((packed));
0295 
0296 #define MAX_NOTIFY_SIZE     0x80
0297 #define CUR_NOTIFY_SIZE     sizeof(struct notify)
0298 
0299 typedef struct {
0300     u32 data_size; /* current size in bytes (not including resvd) */
0301 
0302     struct notify notify;
0303 
0304     u8  notify_rsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
0305 
0306     u8  rebuild_rate;       /* Rebuild rate (0% - 100%) */
0307     u8  cache_flush_interval;   /* In terms of Seconds */
0308     u8  sense_alert;
0309     u8  drive_insert_count; /* drive insertion count */
0310 
0311     u8  battery_status;
0312     u8  num_ldrv;       /* No. of Log Drives configured */
0313     u8  recon_state[MAX_LOGICAL_DRIVES_40LD / 8];   /* State of
0314                                reconstruct */
0315     u16 ldrv_op_status[MAX_LOGICAL_DRIVES_40LD / 8]; /* logdrv
0316                                  Status */
0317 
0318     u32 ldrv_size[MAX_LOGICAL_DRIVES_40LD];/* Size of each log drv */
0319     u8  ldrv_prop[MAX_LOGICAL_DRIVES_40LD];
0320     u8  ldrv_state[MAX_LOGICAL_DRIVES_40LD];/* State of log drives */
0321     u8  pdrv_state[FC_MAX_PHYSICAL_DEVICES];/* State of phys drvs. */
0322     u16 pdrv_format[FC_MAX_PHYSICAL_DEVICES / 16];
0323 
0324     u8  targ_xfer[80];  /* phys device transfer rate */
0325     u8  pad1k[263]; /* 761 + 263reserved = 1024 bytes total size */
0326 } __attribute__ ((packed)) mega_inquiry3;
0327 
0328 
0329 /* Structures */
0330 typedef struct {
0331     u8  max_commands;   /* Max concurrent commands supported */
0332     u8  rebuild_rate;   /* Rebuild rate - 0% thru 100% */
0333     u8  max_targ_per_chan;  /* Max targ per channel */
0334     u8  nchannels;  /* Number of channels on HBA */
0335     u8  fw_version[4];  /* Firmware version */
0336     u16 age_of_flash;   /* Number of times FW has been flashed */
0337     u8  chip_set_value; /* Contents of 0xC0000832 */
0338     u8  dram_size;  /* In MB */
0339     u8  cache_flush_interval;   /* in seconds */
0340     u8  bios_version[4];
0341     u8  board_type;
0342     u8  sense_alert;
0343     u8  write_config_count; /* Increase with every configuration
0344                        change */
0345     u8  drive_inserted_count;   /* Increase with every drive inserted
0346                      */
0347     u8  inserted_drive; /* Channel:Id of inserted drive */
0348     u8  battery_status; /*
0349                  * BIT 0: battery module missing
0350                  * BIT 1: VBAD
0351                  * BIT 2: temperature high
0352                  * BIT 3: battery pack missing
0353                  * BIT 4,5:
0354                  *   00 - charge complete
0355                  *   01 - fast charge in progress
0356                  *   10 - fast charge fail
0357                  *   11 - undefined
0358                  * Bit 6: counter > 1000
0359                  * Bit 7: Undefined
0360                  */
0361     u8  dec_fault_bus_info;
0362 } __attribute__ ((packed)) mega_adp_info;
0363 
0364 
0365 typedef struct {
0366     u8  num_ldrv;   /* Number of logical drives configured */
0367     u8  rsvd[3];
0368     u32 ldrv_size[MAX_LOGICAL_DRIVES_8LD];
0369     u8  ldrv_prop[MAX_LOGICAL_DRIVES_8LD];
0370     u8  ldrv_state[MAX_LOGICAL_DRIVES_8LD];
0371 } __attribute__ ((packed)) mega_ldrv_info;
0372 
0373 typedef struct {
0374     u8  pdrv_state[MAX_PHYSICAL_DRIVES];
0375     u8  rsvd;
0376 } __attribute__ ((packed)) mega_pdrv_info;
0377 
0378 /* RAID inquiry: Mailbox command 0x05*/
0379 typedef struct {
0380     mega_adp_info   adapter_info;
0381     mega_ldrv_info  logdrv_info;
0382     mega_pdrv_info  pdrv_info;
0383 } __attribute__ ((packed)) mraid_inquiry;
0384 
0385 
0386 /* RAID extended inquiry: Mailbox command 0x04*/
0387 typedef struct {
0388     mraid_inquiry   raid_inq;
0389     u16 phys_drv_format[MAX_CHANNELS];
0390     u8  stack_attn;
0391     u8  modem_status;
0392     u8  rsvd[2];
0393 } __attribute__ ((packed)) mraid_ext_inquiry;
0394 
0395 
0396 typedef struct {
0397     u8  channel;
0398     u8  target;
0399 }__attribute__ ((packed)) adp_device;
0400 
0401 typedef struct {
0402     u32     start_blk;  /* starting block */
0403     u32     num_blks;   /* # of blocks */
0404     adp_device  device[MAX_ROW_SIZE_40LD];
0405 }__attribute__ ((packed)) adp_span_40ld;
0406 
0407 typedef struct {
0408     u32     start_blk;  /* starting block */
0409     u32     num_blks;   /* # of blocks */
0410     adp_device  device[MAX_ROW_SIZE_8LD];
0411 }__attribute__ ((packed)) adp_span_8ld;
0412 
0413 typedef struct {
0414     u8  span_depth; /* Total # of spans */
0415     u8  level;      /* RAID level */
0416     u8  read_ahead; /* read ahead, no read ahead, adaptive read
0417                    ahead */
0418     u8  stripe_sz;  /* Encoded stripe size */
0419     u8  status;     /* Status of the logical drive */
0420     u8  write_mode; /* write mode, write_through/write_back */
0421     u8  direct_io;  /* direct io or through cache */
0422     u8  row_size;   /* Number of stripes in a row */
0423 } __attribute__ ((packed)) logdrv_param;
0424 
0425 typedef struct {
0426     logdrv_param    lparam;
0427     adp_span_40ld   span[MAX_SPAN_DEPTH];
0428 }__attribute__ ((packed)) logdrv_40ld;
0429 
0430 typedef struct {
0431     logdrv_param    lparam;
0432     adp_span_8ld    span[MAX_SPAN_DEPTH];
0433 }__attribute__ ((packed)) logdrv_8ld;
0434 
0435 typedef struct {
0436     u8  type;       /* Type of the device */
0437     u8  cur_status; /* current status of the device */
0438     u8  tag_depth;  /* Level of tagging */
0439     u8  sync_neg;   /* sync negotiation - ENABLE or DISABLE */
0440     u32 size;       /* configurable size in terms of 512 byte
0441                    blocks */
0442 }__attribute__ ((packed)) phys_drv;
0443 
0444 typedef struct {
0445     u8      nlog_drives;        /* number of logical drives */
0446     u8      resvd[3];
0447     logdrv_40ld ldrv[MAX_LOGICAL_DRIVES_40LD];
0448     phys_drv    pdrv[MAX_PHYSICAL_DRIVES];
0449 }__attribute__ ((packed)) disk_array_40ld;
0450 
0451 typedef struct {
0452     u8      nlog_drives;    /* number of logical drives */
0453     u8      resvd[3];
0454     logdrv_8ld  ldrv[MAX_LOGICAL_DRIVES_8LD];
0455     phys_drv    pdrv[MAX_PHYSICAL_DRIVES];
0456 }__attribute__ ((packed)) disk_array_8ld;
0457 
0458 
0459 /*
0460  * User ioctl structure.
0461  * This structure will be used for Traditional Method ioctl interface
0462  * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
0463  * Driver ioctls.
0464  * The Driver ioctl interface handles the commands at the driver level,
0465  * without being sent to the card.
0466  */
0467 /* system call imposed limit. Change accordingly */
0468 #define IOCTL_MAX_DATALEN       4096
0469 
0470 struct uioctl_t {
0471     u32 inlen;
0472     u32 outlen;
0473     union {
0474         u8 fca[16];
0475         struct {
0476             u8 opcode;
0477             u8 subopcode;
0478             u16 adapno;
0479 #if BITS_PER_LONG == 32
0480             u8 *buffer;
0481             u8 pad[4];
0482 #endif
0483 #if BITS_PER_LONG == 64
0484             u8 *buffer;
0485 #endif
0486             u32 length;
0487         } __attribute__ ((packed)) fcs;
0488     } __attribute__ ((packed)) ui;
0489     u8 mbox[18];        /* 16 bytes + 2 status bytes */
0490     mega_passthru pthru;
0491 #if BITS_PER_LONG == 32
0492     char __user *data;      /* buffer <= 4096 for 0x80 commands */
0493     char pad[4];
0494 #endif
0495 #if BITS_PER_LONG == 64
0496     char __user *data;
0497 #endif
0498 } __attribute__ ((packed));
0499 
0500 /*
0501  * struct mcontroller is used to pass information about the controllers in the
0502  * system. Its up to the application how to use the information. We are passing
0503  * as much info about the cards as possible and useful. Before issuing the
0504  * call to find information about the cards, the application needs to issue a
0505  * ioctl first to find out the number of controllers in the system.
0506  */
0507 #define MAX_CONTROLLERS 32
0508 
0509 struct mcontroller {
0510     u64 base;
0511     u8 irq;
0512     u8 numldrv;
0513     u8 pcibus;
0514     u16 pcidev;
0515     u8 pcifun;
0516     u16 pciid;
0517     u16 pcivendor;
0518     u8 pcislot;
0519     u32 uid;
0520 };
0521 
0522 /*
0523  * mailbox structure used for internal commands
0524  */
0525 typedef struct {
0526     u8  cmd;
0527     u8  cmdid;
0528     u8  opcode;
0529     u8  subopcode;
0530     u32 lba;
0531     u32 xferaddr;
0532     u8  logdrv;
0533     u8  rsvd[3];
0534     u8  numstatus;
0535     u8  status;
0536 } __attribute__ ((packed)) megacmd_t;
0537 
0538 /*
0539  * Defines for Driver IOCTL interface
0540  */
0541 #define MEGAIOC_MAGIC   'm'
0542 
0543 #define MEGAIOC_QNADAP      'm' /* Query # of adapters */
0544 #define MEGAIOC_QDRVRVER    'e' /* Query driver version */
0545 #define MEGAIOC_QADAPINFO       'g' /* Query adapter information */
0546 #define MKADAP(adapno)      (MEGAIOC_MAGIC << 8 | (adapno) )
0547 #define GETADAP(mkadap)     ( (mkadap) ^ MEGAIOC_MAGIC << 8 )
0548 
0549 /*
0550  * Definition for the new ioctl interface (NIT)
0551  */
0552 
0553 /*
0554  * Vendor specific Group-7 commands
0555  */
0556 #define VENDOR_SPECIFIC_COMMANDS    0xE0
0557 #define MEGA_INTERNAL_CMD       VENDOR_SPECIFIC_COMMANDS + 0x01
0558 
0559 /*
0560  * The ioctl command. No other command shall be used for this interface
0561  */
0562 #define USCSICMD    VENDOR_SPECIFIC_COMMANDS
0563 
0564 /*
0565  * Data direction flags
0566  */
0567 #define UIOC_RD     0x00001
0568 #define UIOC_WR     0x00002
0569 
0570 /*
0571  * ioctl opcodes
0572  */
0573 #define MBOX_CMD    0x00000 /* DCMD or passthru command */
0574 #define GET_DRIVER_VER  0x10000 /* Get driver version */
0575 #define GET_N_ADAP  0x20000 /* Get number of adapters */
0576 #define GET_ADAP_INFO   0x30000 /* Get information about a adapter */
0577 #define GET_CAP     0x40000 /* Get ioctl capabilities */
0578 #define GET_STATS   0x50000 /* Get statistics, including error info */
0579 
0580 
0581 /*
0582  * The ioctl structure.
0583  * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
0584  * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
0585  */
0586 typedef struct {
0587     char        signature[8];   /* Must contain "MEGANIT" */
0588     u32     opcode;     /* opcode for the command */
0589     u32     adapno;     /* adapter number */
0590     union {
0591         u8  __raw_mbox[18];
0592         void __user *__uaddr; /* xferaddr for non-mbox cmds */
0593     }__ua;
0594 
0595 #define uioc_rmbox  __ua.__raw_mbox
0596 #define MBOX(uioc)  ((megacmd_t *)&((uioc).__ua.__raw_mbox[0]))
0597 #define MBOX_P(uioc)    ((megacmd_t __user *)&((uioc)->__ua.__raw_mbox[0]))
0598 #define uioc_uaddr  __ua.__uaddr
0599 
0600     u32     xferlen;    /* xferlen for DCMD and non-mbox
0601                        commands */
0602     u32     flags;      /* data direction flags */
0603 }nitioctl_t;
0604 
0605 
0606 /*
0607  * I/O statistics for some applications like SNMP agent. The caller must
0608  * provide the number of logical drives for which status should be reported.
0609  */
0610 typedef struct {
0611     int num_ldrv;   /* Number for logical drives for which the
0612                    status should be reported. */
0613     u32 nreads[MAX_LOGICAL_DRIVES_40LD];    /* number of reads for
0614                             each logical drive */
0615     u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD];   /* number of blocks
0616                             read for each logical
0617                             drive */
0618     u32 nwrites[MAX_LOGICAL_DRIVES_40LD];   /* number of writes
0619                             for each logical
0620                             drive */
0621     u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD];  /* number of blocks
0622                             writes for each
0623                             logical drive */
0624     u32 rd_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of read
0625                                errors for each
0626                                logical drive */
0627     u32 wr_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of write
0628                                errors for each
0629                                logical drive */
0630 }megastat_t;
0631 
0632 
0633 struct private_bios_data {
0634     u8  geometry:4; /*
0635                  * bits 0-3 - BIOS geometry
0636                  * 0x0001 - 1GB
0637                  * 0x0010 - 2GB
0638                  * 0x1000 - 8GB
0639                  * Others values are invalid
0640                              */
0641     u8  unused:4;   /* bits 4-7 are unused */
0642     u8  boot_drv;   /*
0643                  * logical drive set as boot drive
0644                  * 0..7 - for 8LD cards
0645                  * 0..39 - for 40LD cards
0646                  */
0647     u8  rsvd[12];
0648     u16 cksum;  /* 0-(sum of first 13 bytes of this structure) */
0649 } __attribute__ ((packed));
0650 
0651 
0652 
0653 
0654 /*
0655  * Mailbox and firmware commands and subopcodes used in this driver.
0656  */
0657 
0658 #define MEGA_MBOXCMD_LREAD  0x01
0659 #define MEGA_MBOXCMD_LWRITE 0x02
0660 #define MEGA_MBOXCMD_PASSTHRU   0x03
0661 #define MEGA_MBOXCMD_ADPEXTINQ  0x04
0662 #define MEGA_MBOXCMD_ADAPTERINQ 0x05
0663 #define MEGA_MBOXCMD_LREAD64    0xA7
0664 #define MEGA_MBOXCMD_LWRITE64   0xA8
0665 #define MEGA_MBOXCMD_PASSTHRU64 0xC3
0666 #define MEGA_MBOXCMD_EXTPTHRU   0xE3
0667 
0668 #define MAIN_MISC_OPCODE    0xA4    /* f/w misc opcode */
0669 #define GET_MAX_SG_SUPPORT  0x01    /* get max sg len supported by f/w */
0670 
0671 #define FC_NEW_CONFIG       0xA1
0672 #define NC_SUBOP_PRODUCT_INFO   0x0E
0673 #define NC_SUBOP_ENQUIRY3   0x0F
0674 #define ENQ3_GET_SOLICITED_FULL 0x02
0675 #define OP_DCMD_READ_CONFIG 0x04
0676 #define NEW_READ_CONFIG_8LD 0x67
0677 #define READ_CONFIG_8LD     0x07
0678 #define FLUSH_ADAPTER       0x0A
0679 #define FLUSH_SYSTEM        0xFE
0680 
0681 /*
0682  * Command for random deletion of logical drives
0683  */
0684 #define FC_DEL_LOGDRV       0xA4    /* f/w command */
0685 #define OP_SUP_DEL_LOGDRV   0x2A    /* is feature supported */
0686 #define OP_GET_LDID_MAP     0x18    /* get ldid and logdrv number map */
0687 #define OP_DEL_LOGDRV       0x1C    /* delete logical drive */
0688 
0689 /*
0690  * BIOS commands
0691  */
0692 #define IS_BIOS_ENABLED     0x62
0693 #define GET_BIOS        0x01
0694 #define CHNL_CLASS      0xA9
0695 #define GET_CHNL_CLASS      0x00
0696 #define SET_CHNL_CLASS      0x01
0697 #define CH_RAID         0x01
0698 #define CH_SCSI         0x00
0699 #define BIOS_PVT_DATA       0x40
0700 #define GET_BIOS_PVT_DATA   0x00
0701 
0702 
0703 /*
0704  * Commands to support clustering
0705  */
0706 #define MEGA_GET_TARGET_ID  0x7D
0707 #define MEGA_CLUSTER_OP     0x70
0708 #define MEGA_GET_CLUSTER_MODE   0x02
0709 #define MEGA_CLUSTER_CMD    0x6E
0710 #define MEGA_RESERVE_LD     0x01
0711 #define MEGA_RELEASE_LD     0x02
0712 #define MEGA_RESET_RESERVATIONS 0x03
0713 #define MEGA_RESERVATION_STATUS 0x04
0714 #define MEGA_RESERVE_PD     0x05
0715 #define MEGA_RELEASE_PD     0x06
0716 
0717 
0718 /*
0719  * Module battery status
0720  */
0721 #define MEGA_BATT_MODULE_MISSING    0x01
0722 #define MEGA_BATT_LOW_VOLTAGE       0x02
0723 #define MEGA_BATT_TEMP_HIGH     0x04
0724 #define MEGA_BATT_PACK_MISSING      0x08
0725 #define MEGA_BATT_CHARGE_MASK       0x30
0726 #define MEGA_BATT_CHARGE_DONE       0x00
0727 #define MEGA_BATT_CHARGE_INPROG     0x10
0728 #define MEGA_BATT_CHARGE_FAIL       0x20
0729 #define MEGA_BATT_CYCLES_EXCEEDED   0x40
0730 
0731 /*
0732  * Physical drive states.
0733  */
0734 #define PDRV_UNCNF  0
0735 #define PDRV_ONLINE 3
0736 #define PDRV_FAILED 4
0737 #define PDRV_RBLD   5
0738 #define PDRV_HOTSPARE   6
0739 
0740 
0741 /*
0742  * Raid logical drive states.
0743  */
0744 #define RDRV_OFFLINE    0
0745 #define RDRV_DEGRADED   1
0746 #define RDRV_OPTIMAL    2
0747 #define RDRV_DELETED    3
0748 
0749 /*
0750  * Read, write and cache policies
0751  */
0752 #define NO_READ_AHEAD       0
0753 #define READ_AHEAD      1
0754 #define ADAP_READ_AHEAD     2
0755 #define WRMODE_WRITE_THRU   0
0756 #define WRMODE_WRITE_BACK   1
0757 #define CACHED_IO       0
0758 #define DIRECT_IO       1
0759 
0760 struct megaraid_cmd_priv {
0761     struct list_head entry;
0762 };
0763 
0764 #define SCSI_LIST(scp)                          \
0765     (&((struct megaraid_cmd_priv *)scsi_cmd_priv(scp))->entry)
0766 
0767 struct scsi_cmd_and_priv {
0768     struct scsi_cmnd     cmd;
0769     struct megaraid_cmd_priv priv;
0770 };
0771 
0772 static inline struct scsi_cmnd *
0773 megaraid_to_scsi_cmd(struct megaraid_cmd_priv *cmd_priv)
0774 {
0775     /* See also scsi_mq_setup_tags() */
0776     BUILD_BUG_ON(sizeof(struct scsi_cmd_and_priv) !=
0777              sizeof(struct scsi_cmnd) +
0778              sizeof(struct megaraid_cmd_priv));
0779 
0780     return &container_of(cmd_priv, struct scsi_cmd_and_priv, priv)->cmd;
0781 }
0782 
0783 /*
0784  * Each controller's soft state
0785  */
0786 typedef struct {
0787     int this_id;    /* our id, may set to different than 7 if
0788                    clustering is available */
0789     u32 flag;
0790 
0791     unsigned long       base;
0792     void __iomem        *mmio_base;
0793 
0794     /* mbox64 with mbox not aligned on 16-byte boundary */
0795     mbox64_t    *una_mbox64;
0796     dma_addr_t  una_mbox64_dma;
0797 
0798     volatile mbox64_t   *mbox64;/* ptr to 64-bit mailbox */
0799     volatile mbox_t     *mbox;  /* ptr to standard mailbox */
0800     dma_addr_t      mbox_dma;
0801 
0802     struct pci_dev  *dev;
0803 
0804     struct list_head    free_list;
0805     struct list_head    pending_list;
0806     struct list_head    completed_list;
0807 
0808     struct Scsi_Host    *host;
0809 
0810 #define MEGA_BUFFER_SIZE (2*1024)
0811     u8      *mega_buffer;
0812     dma_addr_t  buf_dma_handle;
0813 
0814     mega_product_info   product_info;
0815 
0816     u8      max_cmds;
0817     scb_t       *scb_list;
0818 
0819     atomic_t    pend_cmds;  /* maintain a counter for pending
0820                        commands in firmware */
0821 
0822 #if MEGA_HAVE_STATS
0823     u32 nreads[MAX_LOGICAL_DRIVES_40LD];
0824     u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD];
0825     u32 nwrites[MAX_LOGICAL_DRIVES_40LD];
0826     u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
0827     u32 rd_errors[MAX_LOGICAL_DRIVES_40LD];
0828     u32 wr_errors[MAX_LOGICAL_DRIVES_40LD];
0829 #endif
0830 
0831     /* Host adapter parameters */
0832     u8  numldrv;
0833     u8  fw_version[7];
0834     u8  bios_version[7];
0835 
0836 #ifdef CONFIG_PROC_FS
0837     struct proc_dir_entry   *controller_proc_dir_entry;
0838 #endif
0839 
0840     int has_64bit_addr;     /* are we using 64-bit addressing */
0841     int support_ext_cdb;
0842     int boot_ldrv_enabled;
0843     int boot_ldrv;
0844     int boot_pdrv_enabled;  /* boot from physical drive */
0845     int boot_pdrv_ch;       /* boot physical drive channel */
0846     int boot_pdrv_tgt;      /* boot physical drive target */
0847 
0848 
0849     int support_random_del; /* Do we support random deletion of
0850                        logdrvs */
0851     int read_ldidmap;   /* set after logical drive deltion. The
0852                    logical drive number must be read from the
0853                    map */
0854     atomic_t    quiescent;  /* a stage reached when delete logical
0855                        drive needs to be done. Stop
0856                        sending requests to the hba till
0857                        delete operation is completed */
0858     spinlock_t  lock;
0859 
0860     u8  logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
0861                             what channels. */
0862     int mega_ch_class;
0863 
0864     u8  sglen;  /* f/w supported scatter-gather list length */
0865 
0866     scb_t           int_scb;
0867     struct mutex        int_mtx;    /* To synchronize the internal
0868                         commands */
0869     int         int_status; /* status of internal cmd */
0870     struct completion   int_waitq;  /* wait queue for internal
0871                          cmds */
0872 
0873     int has_cluster;    /* cluster support on this HBA */
0874 }adapter_t;
0875 
0876 
0877 struct mega_hbas {
0878     int is_bios_enabled;
0879     adapter_t *hostdata_addr;
0880 };
0881 
0882 
0883 /*
0884  * For state flag. Do not use LSB(8 bits) which are
0885  * reserved for storing info about channels.
0886  */
0887 #define IN_ABORT    0x80000000L
0888 #define IN_RESET    0x40000000L
0889 #define BOARD_MEMMAP    0x20000000L
0890 #define BOARD_IOMAP 0x10000000L
0891 #define BOARD_40LD      0x08000000L
0892 #define BOARD_64BIT 0x04000000L
0893 
0894 #define INTR_VALID          0x40
0895 
0896 #define PCI_CONF_AMISIG         0xa0
0897 #define PCI_CONF_AMISIG64       0xa4
0898 
0899 
0900 #define MEGA_DMA_TYPE_NONE      0xFFFF
0901 #define MEGA_BULK_DATA          0x0001
0902 #define MEGA_SGLIST         0x0002
0903 
0904 /*
0905  * Parameters for the io-mapped controllers
0906  */
0907 
0908 /* I/O Port offsets */
0909 #define CMD_PORT        0x00
0910 #define ACK_PORT        0x00
0911 #define TOGGLE_PORT     0x01
0912 #define INTR_PORT       0x0a
0913 
0914 #define MBOX_BUSY_PORT      0x00
0915 #define MBOX_PORT0      0x04
0916 #define MBOX_PORT1      0x05
0917 #define MBOX_PORT2      0x06
0918 #define MBOX_PORT3      0x07
0919 #define ENABLE_MBOX_REGION  0x0B
0920 
0921 /* I/O Port Values */
0922 #define ISSUE_BYTE      0x10
0923 #define ACK_BYTE        0x08
0924 #define ENABLE_INTR_BYTE    0xc0
0925 #define DISABLE_INTR_BYTE   0x00
0926 #define VALID_INTR_BYTE     0x40
0927 #define MBOX_BUSY_BYTE      0x10
0928 #define ENABLE_MBOX_BYTE    0x00
0929 
0930 
0931 /* Setup some port macros here */
0932 #define issue_command(adapter)  \
0933         outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
0934 
0935 #define irq_state(adapter)  inb_p((adapter)->base + INTR_PORT)
0936 
0937 #define set_irq_state(adapter, value)   \
0938         outb_p((value), (adapter)->base + INTR_PORT)
0939 
0940 #define irq_ack(adapter)    \
0941         outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
0942 
0943 #define irq_enable(adapter) \
0944     outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
0945 
0946 #define irq_disable(adapter)    \
0947     outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
0948 
0949 
0950 /*
0951  * This is our SYSDEP area. All kernel specific detail should be placed here -
0952  * as much as possible
0953  */
0954 
0955 /*
0956  * End of SYSDEP area
0957  */
0958 
0959 const char *megaraid_info (struct Scsi_Host *);
0960 
0961 static int mega_query_adapter(adapter_t *);
0962 static int issue_scb(adapter_t *, scb_t *);
0963 static int mega_setup_mailbox(adapter_t *);
0964 
0965 static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
0966 static scb_t * mega_build_cmd(adapter_t *, struct scsi_cmnd *, int *);
0967 static void __mega_runpendq(adapter_t *);
0968 static int issue_scb_block(adapter_t *, u_char *);
0969 
0970 static irqreturn_t megaraid_isr_memmapped(int, void *);
0971 static irqreturn_t megaraid_isr_iomapped(int, void *);
0972 
0973 static void mega_free_scb(adapter_t *, scb_t *);
0974 
0975 static int megaraid_abort(struct scsi_cmnd *);
0976 static int megaraid_reset(struct scsi_cmnd *);
0977 static int megaraid_abort_and_reset(adapter_t *, struct scsi_cmnd *, int);
0978 static int megaraid_biosparam(struct scsi_device *, struct block_device *,
0979         sector_t, int []);
0980 
0981 static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
0982                   u32 *buffer, u32 *length);
0983 static int __mega_busywait_mbox (adapter_t *);
0984 static void mega_rundoneq (adapter_t *);
0985 static void mega_cmd_done(adapter_t *, u8 [], int, int);
0986 static inline void mega_free_sgl (adapter_t *adapter);
0987 static void mega_8_to_40ld (mraid_inquiry *inquiry,
0988         mega_inquiry3 *enquiry3, mega_product_info *);
0989 
0990 static int megadev_open (struct inode *, struct file *);
0991 static int megadev_ioctl (struct file *, unsigned int, unsigned long);
0992 static int mega_m_to_n(void __user *, nitioctl_t *);
0993 static int mega_n_to_m(void __user *, megacmd_t *);
0994 
0995 static int mega_init_scb (adapter_t *);
0996 
0997 static int mega_is_bios_enabled (adapter_t *);
0998 
0999 #ifdef CONFIG_PROC_FS
1000 static void mega_create_proc_entry(int, struct proc_dir_entry *);
1001 static int mega_adapinq(adapter_t *, dma_addr_t);
1002 static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
1003 #endif
1004 
1005 static int mega_support_ext_cdb(adapter_t *);
1006 static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
1007         struct scsi_cmnd *, int, int);
1008 static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
1009         scb_t *, struct scsi_cmnd *, int, int);
1010 static void mega_enum_raid_scsi(adapter_t *);
1011 static void mega_get_boot_drv(adapter_t *);
1012 static int mega_support_random_del(adapter_t *);
1013 static int mega_del_logdrv(adapter_t *, int);
1014 static int mega_do_del_logdrv(adapter_t *, int);
1015 static void mega_get_max_sgl(adapter_t *);
1016 static int mega_internal_command(adapter_t *, megacmd_t *, mega_passthru *);
1017 static int mega_support_cluster(adapter_t *);
1018 #endif
1019 
1020 /* vi: set ts=8 sw=8 tw=78: */