1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/spinlock.h>
6 #include <linux/mutex.h>
8 #define MEGARAID_VERSION \
9 "v2.00.4 (Release Date: Thu Feb 9 08:51:30 EST 2006)\n"
12 * Driver features - change the values to enable or disable features in the
17 * Command coalescing - This feature allows the driver to be able to combine
18 * two or more commands and issue as one command in order to boost I/O
19 * performance. Useful if the nature of the I/O is sequential. It is not very
20 * useful for random natured I/Os.
22 #define MEGA_HAVE_COALESCING 0
25 * Clustering support - Set this flag if you are planning to use the
26 * clustering services provided by the megaraid controllers and planning to
29 #define MEGA_HAVE_CLUSTERING 1
32 * Driver statistics - Set this flag if you are interested in statics about
33 * number of I/O completed on each logical drive and how many interrupts
34 * generated. If enabled, this information is available through /proc
35 * interface and through the private ioctl. Setting this flag has a
36 * performance penalty.
38 #define MEGA_HAVE_STATS 0
41 * Enhanced /proc interface - This feature will allow you to have a more
42 * detailed /proc interface for megaraid driver. E.g., a real time update of
43 * the status of the logical drives, battery status, physical drives etc.
45 #define MEGA_HAVE_ENH_PROC 1
47 #define MAX_DEV_TYPE 32
49 #define PCI_DEVICE_ID_DISCOVERY 0x000E
50 #define PCI_DEVICE_ID_PERC4_DI 0x000F
51 #define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407
53 #define HBA_SIGNATURE 0x3344
54 #define HBA_SIGNATURE_471 0xCCCC
55 #define HBA_SIGNATURE_64BIT 0x0299
57 #define MBOX_BUSY_WAIT 10 /* wait for up to 10 usec for
59 #define DEFAULT_INITIATOR_ID 7
61 #define MAX_SGLIST 64 /* max supported in f/w */
62 #define MIN_SGLIST 26 /* guaranteed to support these many */
63 #define MAX_COMMANDS 126
64 #define CMDID_INT_CMDS MAX_COMMANDS+1 /* make sure CMDID_INT_CMDS
65 is less than max commands
66 supported by any f/w */
68 #define MAX_CDB_LEN 10
69 #define MAX_EXT_CDB_LEN 16 /* we support cdb length up to 16 */
71 #define DEF_CMD_PER_LUN 63
72 #define MAX_CMD_PER_LUN MAX_COMMANDS
73 #define MAX_FIRMWARE_STATUS 46
74 #define MAX_XFER_PER_CMD (64*1024)
75 #define MAX_SECTORS_PER_IO 128
77 #define MAX_LOGICAL_DRIVES_40LD 40
78 #define FC_MAX_PHYSICAL_DEVICES 256
79 #define MAX_LOGICAL_DRIVES_8LD 8
80 #define MAX_CHANNELS 5
82 #define MAX_PHYSICAL_DRIVES MAX_CHANNELS*MAX_TARGET
83 #define MAX_ROW_SIZE_40LD 32
84 #define MAX_ROW_SIZE_8LD 8
85 #define MAX_SPAN_DEPTH 8
87 #define NVIRT_CHAN 4 /* # of virtual channels to represent
88 up to 60 logical drives */
92 /* 0x2 */ u16 numsectors;
94 /* 0x8 */ u32 xferaddr;
96 /* 0xD */ u8 numsgelements;
98 } __attribute__ ((packed));
101 /* 0xF */ volatile u8 busy;
102 /* 0x10 */ volatile u8 numstatus;
103 /* 0x11 */ volatile u8 status;
104 /* 0x12 */ volatile u8 completed[MAX_FIRMWARE_STATUS];
107 } __attribute__ ((packed));
110 struct mbox_out m_out;
112 } __attribute__ ((packed)) mbox_t;
118 } __attribute__ ((packed)) mbox64_t;
122 * Passthru definitions
124 #define MAX_REQ_SENSE_LEN 0x20
127 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
131 u8 logdrv; /* if islogical == 1 */
132 u8 channel; /* if islogical == 0 */
133 u8 target; /* if islogical == 0 */
134 u8 queuetag; /* unused */
135 u8 queueaction; /* unused */
139 u8 reqsensearea[MAX_REQ_SENSE_LEN];
144 } __attribute__ ((packed)) mega_passthru;
148 * Extended passthru: support CDB > 10 bytes
151 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
157 u8 logdrv; /* if islogical == 1 */
158 u8 channel; /* if islogical == 0 */
159 u8 target; /* if islogical == 0 */
160 u8 queuetag; /* unused */
161 u8 queueaction; /* unused */
164 u8 cdb[MAX_EXT_CDB_LEN];
168 u8 reqsensearea[MAX_REQ_SENSE_LEN];
172 } __attribute__ ((packed)) mega_ext_passthru;
177 } __attribute__ ((packed)) mega_sgl64;
182 } __attribute__ ((packed)) mega_sglist;
185 /* Queued command data */
189 struct list_head list;
195 dma_addr_t dma_h_bulkdata;
196 dma_addr_t dma_h_sgdata;
200 dma_addr_t sgl_dma_addr;
202 mega_passthru *pthru;
203 dma_addr_t pthru_dma_addr;
204 mega_ext_passthru *epthru;
205 dma_addr_t epthru_dma_addr;
209 * Flags to follow the scb as it transitions between various stages
211 #define SCB_FREE 0x0000 /* on the free list */
212 #define SCB_ACTIVE 0x0001 /* off the free list */
213 #define SCB_PENDQ 0x0002 /* on the pending queue */
214 #define SCB_ISSUED 0x0004 /* issued - owner f/w */
215 #define SCB_ABORT 0x0008 /* Got an abort for this one */
216 #define SCB_RESET 0x0010 /* Got a reset for this one */
219 * Utilities declare this strcture size as 1024 bytes. So more fields can
220 * be added in future.
223 u32 data_size; /* current size in bytes (not including resvd) */
225 u32 config_signature;
226 /* Current value is 0x00282008
227 * 0x28=MAX_LOGICAL_DRIVES,
228 * 0x20=Number of stripes and
229 * 0x08=Number of spans */
231 u8 fw_version[16]; /* printable ASCI string */
232 u8 bios_version[16]; /* printable ASCI string */
233 u8 product_name[80]; /* printable ASCI string */
235 u8 max_commands; /* Max. concurrent commands supported */
236 u8 nchannels; /* Number of SCSI Channels detected */
237 u8 fc_loop_present; /* Number of Fibre Loops detected */
238 u8 mem_type; /* EDO, FPM, SDRAM etc */
241 u16 dram_size; /* In terms of MB */
246 u8 pad1k[889]; /* 135 + 889 resvd = 1024 total size */
247 } __attribute__ ((packed)) mega_product_info;
250 u32 global_counter; /* Any change increments this counter */
252 u8 param_counter; /* Indicates any params changed */
253 u8 param_id; /* Param modified - defined below */
254 u16 param_val; /* New val of last param modified */
256 u8 write_config_counter; /* write config occurred */
257 u8 write_config_rsvd[3];
259 u8 ldrv_op_counter; /* Indicates ldrv op started/completed */
260 u8 ldrv_opid; /* ldrv num */
261 u8 ldrv_opcmd; /* ldrv operation - defined below */
262 u8 ldrv_opstatus; /* status of the operation */
264 u8 ldrv_state_counter; /* Indicates change of ldrv state */
265 u8 ldrv_state_id; /* ldrv num */
266 u8 ldrv_state_new; /* New state */
267 u8 ldrv_state_old; /* old state */
269 u8 pdrv_state_counter; /* Indicates change of ldrv state */
270 u8 pdrv_state_id; /* pdrv id */
271 u8 pdrv_state_new; /* New state */
272 u8 pdrv_state_old; /* old state */
274 u8 pdrv_fmt_counter; /* Indicates pdrv format started/over */
275 u8 pdrv_fmt_id; /* pdrv id */
276 u8 pdrv_fmt_val; /* format started/over */
279 u8 targ_xfer_counter; /* Indicates SCSI-2 Xfer rate change */
280 u8 targ_xfer_id; /* pdrv Id */
281 u8 targ_xfer_val; /* new Xfer params of last pdrv */
284 u8 fcloop_id_chg_counter; /* Indicates loopid changed */
285 u8 fcloopid_pdrvid; /* pdrv id */
286 u8 fcloop_id0; /* loopid on fc loop 0 */
287 u8 fcloop_id1; /* loopid on fc loop 1 */
289 u8 fcloop_state_counter; /* Indicates loop state changed */
290 u8 fcloop_state0; /* state of fc loop 0 */
291 u8 fcloop_state1; /* state of fc loop 1 */
292 u8 fcloop_state_rsvd;
293 } __attribute__ ((packed));
295 #define MAX_NOTIFY_SIZE 0x80
296 #define CUR_NOTIFY_SIZE sizeof(struct notify)
299 u32 data_size; /* current size in bytes (not including resvd) */
301 struct notify notify;
303 u8 notify_rsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
305 u8 rebuild_rate; /* Rebuild rate (0% - 100%) */
306 u8 cache_flush_interval; /* In terms of Seconds */
308 u8 drive_insert_count; /* drive insertion count */
311 u8 num_ldrv; /* No. of Log Drives configured */
312 u8 recon_state[MAX_LOGICAL_DRIVES_40LD / 8]; /* State of
314 u16 ldrv_op_status[MAX_LOGICAL_DRIVES_40LD / 8]; /* logdrv
317 u32 ldrv_size[MAX_LOGICAL_DRIVES_40LD];/* Size of each log drv */
318 u8 ldrv_prop[MAX_LOGICAL_DRIVES_40LD];
319 u8 ldrv_state[MAX_LOGICAL_DRIVES_40LD];/* State of log drives */
320 u8 pdrv_state[FC_MAX_PHYSICAL_DEVICES];/* State of phys drvs. */
321 u16 pdrv_format[FC_MAX_PHYSICAL_DEVICES / 16];
323 u8 targ_xfer[80]; /* phys device transfer rate */
324 u8 pad1k[263]; /* 761 + 263reserved = 1024 bytes total size */
325 } __attribute__ ((packed)) mega_inquiry3;
330 u8 max_commands; /* Max concurrent commands supported */
331 u8 rebuild_rate; /* Rebuild rate - 0% thru 100% */
332 u8 max_targ_per_chan; /* Max targ per channel */
333 u8 nchannels; /* Number of channels on HBA */
334 u8 fw_version[4]; /* Firmware version */
335 u16 age_of_flash; /* Number of times FW has been flashed */
336 u8 chip_set_value; /* Contents of 0xC0000832 */
337 u8 dram_size; /* In MB */
338 u8 cache_flush_interval; /* in seconds */
342 u8 write_config_count; /* Increase with every configuration
344 u8 drive_inserted_count; /* Increase with every drive inserted
346 u8 inserted_drive; /* Channel:Id of inserted drive */
347 u8 battery_status; /*
348 * BIT 0: battery module missing
350 * BIT 2: temperature high
351 * BIT 3: battery pack missing
353 * 00 - charge complete
354 * 01 - fast charge in progress
355 * 10 - fast charge fail
357 * Bit 6: counter > 1000
360 u8 dec_fault_bus_info;
361 } __attribute__ ((packed)) mega_adp_info;
365 u8 num_ldrv; /* Number of logical drives configured */
367 u32 ldrv_size[MAX_LOGICAL_DRIVES_8LD];
368 u8 ldrv_prop[MAX_LOGICAL_DRIVES_8LD];
369 u8 ldrv_state[MAX_LOGICAL_DRIVES_8LD];
370 } __attribute__ ((packed)) mega_ldrv_info;
373 u8 pdrv_state[MAX_PHYSICAL_DRIVES];
375 } __attribute__ ((packed)) mega_pdrv_info;
377 /* RAID inquiry: Mailbox command 0x05*/
379 mega_adp_info adapter_info;
380 mega_ldrv_info logdrv_info;
381 mega_pdrv_info pdrv_info;
382 } __attribute__ ((packed)) mraid_inquiry;
385 /* RAID extended inquiry: Mailbox command 0x04*/
387 mraid_inquiry raid_inq;
388 u16 phys_drv_format[MAX_CHANNELS];
392 } __attribute__ ((packed)) mraid_ext_inquiry;
398 }__attribute__ ((packed)) adp_device;
401 u32 start_blk; /* starting block */
402 u32 num_blks; /* # of blocks */
403 adp_device device[MAX_ROW_SIZE_40LD];
404 }__attribute__ ((packed)) adp_span_40ld;
407 u32 start_blk; /* starting block */
408 u32 num_blks; /* # of blocks */
409 adp_device device[MAX_ROW_SIZE_8LD];
410 }__attribute__ ((packed)) adp_span_8ld;
413 u8 span_depth; /* Total # of spans */
414 u8 level; /* RAID level */
415 u8 read_ahead; /* read ahead, no read ahead, adaptive read
417 u8 stripe_sz; /* Encoded stripe size */
418 u8 status; /* Status of the logical drive */
419 u8 write_mode; /* write mode, write_through/write_back */
420 u8 direct_io; /* direct io or through cache */
421 u8 row_size; /* Number of stripes in a row */
422 } __attribute__ ((packed)) logdrv_param;
426 adp_span_40ld span[MAX_SPAN_DEPTH];
427 }__attribute__ ((packed)) logdrv_40ld;
431 adp_span_8ld span[MAX_SPAN_DEPTH];
432 }__attribute__ ((packed)) logdrv_8ld;
435 u8 type; /* Type of the device */
436 u8 cur_status; /* current status of the device */
437 u8 tag_depth; /* Level of tagging */
438 u8 sync_neg; /* sync negotiation - ENABLE or DISABLE */
439 u32 size; /* configurable size in terms of 512 byte
441 }__attribute__ ((packed)) phys_drv;
444 u8 nlog_drives; /* number of logical drives */
446 logdrv_40ld ldrv[MAX_LOGICAL_DRIVES_40LD];
447 phys_drv pdrv[MAX_PHYSICAL_DRIVES];
448 }__attribute__ ((packed)) disk_array_40ld;
451 u8 nlog_drives; /* number of logical drives */
453 logdrv_8ld ldrv[MAX_LOGICAL_DRIVES_8LD];
454 phys_drv pdrv[MAX_PHYSICAL_DRIVES];
455 }__attribute__ ((packed)) disk_array_8ld;
459 * User ioctl structure.
460 * This structure will be used for Traditional Method ioctl interface
461 * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
463 * The Driver ioctl interface handles the commands at the driver level,
464 * without being sent to the card.
466 /* system call imposed limit. Change accordingly */
467 #define IOCTL_MAX_DATALEN 4096
478 #if BITS_PER_LONG == 32
482 #if BITS_PER_LONG == 64
486 } __attribute__ ((packed)) fcs;
487 } __attribute__ ((packed)) ui;
488 u8 mbox[18]; /* 16 bytes + 2 status bytes */
490 #if BITS_PER_LONG == 32
491 char __user *data; /* buffer <= 4096 for 0x80 commands */
494 #if BITS_PER_LONG == 64
497 } __attribute__ ((packed));
500 * struct mcontroller is used to pass information about the controllers in the
501 * system. Its up to the application how to use the information. We are passing
502 * as much info about the cards as possible and useful. Before issuing the
503 * call to find information about the cards, the application needs to issue a
504 * ioctl first to find out the number of controllers in the system.
506 #define MAX_CONTROLLERS 32
522 * mailbox structure used for internal commands
535 } __attribute__ ((packed)) megacmd_t;
538 * Defines for Driver IOCTL interface
540 #define MEGAIOC_MAGIC 'm'
542 #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
543 #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
544 #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
545 #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
546 #define GETADAP(mkadap) ( (mkadap) ^ MEGAIOC_MAGIC << 8 )
549 * Definition for the new ioctl interface (NIT)
553 * Vendor specific Group-7 commands
555 #define VENDOR_SPECIFIC_COMMANDS 0xE0
556 #define MEGA_INTERNAL_CMD VENDOR_SPECIFIC_COMMANDS + 0x01
559 * The ioctl command. No other command shall be used for this interface
561 #define USCSICMD VENDOR_SPECIFIC_COMMANDS
564 * Data direction flags
566 #define UIOC_RD 0x00001
567 #define UIOC_WR 0x00002
572 #define MBOX_CMD 0x00000 /* DCMD or passthru command */
573 #define GET_DRIVER_VER 0x10000 /* Get driver version */
574 #define GET_N_ADAP 0x20000 /* Get number of adapters */
575 #define GET_ADAP_INFO 0x30000 /* Get information about a adapter */
576 #define GET_CAP 0x40000 /* Get ioctl capabilities */
577 #define GET_STATS 0x50000 /* Get statistics, including error info */
581 * The ioctl structure.
582 * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
583 * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
586 char signature[8]; /* Must contain "MEGANIT" */
587 u32 opcode; /* opcode for the command */
588 u32 adapno; /* adapter number */
591 void __user *__uaddr; /* xferaddr for non-mbox cmds */
594 #define uioc_rmbox __ua.__raw_mbox
595 #define MBOX(uioc) ((megacmd_t *)&((uioc).__ua.__raw_mbox[0]))
596 #define MBOX_P(uioc) ((megacmd_t __user *)&((uioc)->__ua.__raw_mbox[0]))
597 #define uioc_uaddr __ua.__uaddr
599 u32 xferlen; /* xferlen for DCMD and non-mbox
601 u32 flags; /* data direction flags */
606 * I/O statistics for some applications like SNMP agent. The caller must
607 * provide the number of logical drives for which status should be reported.
610 int num_ldrv; /* Number for logical drives for which the
611 status should be reported. */
612 u32 nreads[MAX_LOGICAL_DRIVES_40LD]; /* number of reads for
613 each logical drive */
614 u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD]; /* number of blocks
615 read for each logical
617 u32 nwrites[MAX_LOGICAL_DRIVES_40LD]; /* number of writes
620 u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD]; /* number of blocks
623 u32 rd_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of read
626 u32 wr_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of write
632 struct private_bios_data {
634 * bits 0-3 - BIOS geometry
638 * Others values are invalid
640 u8 unused:4; /* bits 4-7 are unused */
642 * logical drive set as boot drive
643 * 0..7 - for 8LD cards
644 * 0..39 - for 40LD cards
647 u16 cksum; /* 0-(sum of first 13 bytes of this structure) */
648 } __attribute__ ((packed));
654 * Mailbox and firmware commands and subopcodes used in this driver.
657 #define MEGA_MBOXCMD_LREAD 0x01
658 #define MEGA_MBOXCMD_LWRITE 0x02
659 #define MEGA_MBOXCMD_PASSTHRU 0x03
660 #define MEGA_MBOXCMD_ADPEXTINQ 0x04
661 #define MEGA_MBOXCMD_ADAPTERINQ 0x05
662 #define MEGA_MBOXCMD_LREAD64 0xA7
663 #define MEGA_MBOXCMD_LWRITE64 0xA8
664 #define MEGA_MBOXCMD_PASSTHRU64 0xC3
665 #define MEGA_MBOXCMD_EXTPTHRU 0xE3
667 #define MAIN_MISC_OPCODE 0xA4 /* f/w misc opcode */
668 #define GET_MAX_SG_SUPPORT 0x01 /* get max sg len supported by f/w */
670 #define FC_NEW_CONFIG 0xA1
671 #define NC_SUBOP_PRODUCT_INFO 0x0E
672 #define NC_SUBOP_ENQUIRY3 0x0F
673 #define ENQ3_GET_SOLICITED_FULL 0x02
674 #define OP_DCMD_READ_CONFIG 0x04
675 #define NEW_READ_CONFIG_8LD 0x67
676 #define READ_CONFIG_8LD 0x07
677 #define FLUSH_ADAPTER 0x0A
678 #define FLUSH_SYSTEM 0xFE
681 * Command for random deletion of logical drives
683 #define FC_DEL_LOGDRV 0xA4 /* f/w command */
684 #define OP_SUP_DEL_LOGDRV 0x2A /* is feature supported */
685 #define OP_GET_LDID_MAP 0x18 /* get ldid and logdrv number map */
686 #define OP_DEL_LOGDRV 0x1C /* delete logical drive */
691 #define IS_BIOS_ENABLED 0x62
692 #define GET_BIOS 0x01
693 #define CHNL_CLASS 0xA9
694 #define GET_CHNL_CLASS 0x00
695 #define SET_CHNL_CLASS 0x01
698 #define BIOS_PVT_DATA 0x40
699 #define GET_BIOS_PVT_DATA 0x00
703 * Commands to support clustering
705 #define MEGA_GET_TARGET_ID 0x7D
706 #define MEGA_CLUSTER_OP 0x70
707 #define MEGA_GET_CLUSTER_MODE 0x02
708 #define MEGA_CLUSTER_CMD 0x6E
709 #define MEGA_RESERVE_LD 0x01
710 #define MEGA_RELEASE_LD 0x02
711 #define MEGA_RESET_RESERVATIONS 0x03
712 #define MEGA_RESERVATION_STATUS 0x04
713 #define MEGA_RESERVE_PD 0x05
714 #define MEGA_RELEASE_PD 0x06
718 * Module battery status
720 #define MEGA_BATT_MODULE_MISSING 0x01
721 #define MEGA_BATT_LOW_VOLTAGE 0x02
722 #define MEGA_BATT_TEMP_HIGH 0x04
723 #define MEGA_BATT_PACK_MISSING 0x08
724 #define MEGA_BATT_CHARGE_MASK 0x30
725 #define MEGA_BATT_CHARGE_DONE 0x00
726 #define MEGA_BATT_CHARGE_INPROG 0x10
727 #define MEGA_BATT_CHARGE_FAIL 0x20
728 #define MEGA_BATT_CYCLES_EXCEEDED 0x40
731 * Physical drive states.
734 #define PDRV_ONLINE 3
735 #define PDRV_FAILED 4
737 #define PDRV_HOTSPARE 6
741 * Raid logical drive states.
743 #define RDRV_OFFLINE 0
744 #define RDRV_DEGRADED 1
745 #define RDRV_OPTIMAL 2
746 #define RDRV_DELETED 3
749 * Read, write and cache policies
751 #define NO_READ_AHEAD 0
753 #define ADAP_READ_AHEAD 2
754 #define WRMODE_WRITE_THRU 0
755 #define WRMODE_WRITE_BACK 1
760 #define SCSI_LIST(scp) ((struct list_head *)(&(scp)->SCp))
763 * Each controller's soft state
766 int this_id; /* our id, may set to different than 7 if
767 clustering is available */
771 void __iomem *mmio_base;
773 /* mbox64 with mbox not aligned on 16-byte boundary */
774 mbox64_t *una_mbox64;
775 dma_addr_t una_mbox64_dma;
777 volatile mbox64_t *mbox64;/* ptr to 64-bit mailbox */
778 volatile mbox_t *mbox; /* ptr to standard mailbox */
783 struct list_head free_list;
784 struct list_head pending_list;
785 struct list_head completed_list;
787 struct Scsi_Host *host;
789 #define MEGA_BUFFER_SIZE (2*1024)
791 dma_addr_t buf_dma_handle;
793 mega_product_info product_info;
798 atomic_t pend_cmds; /* maintain a counter for pending
799 commands in firmware */
802 u32 nreads[MAX_LOGICAL_DRIVES_40LD];
803 u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD];
804 u32 nwrites[MAX_LOGICAL_DRIVES_40LD];
805 u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
806 u32 rd_errors[MAX_LOGICAL_DRIVES_40LD];
807 u32 wr_errors[MAX_LOGICAL_DRIVES_40LD];
810 /* Host adapter parameters */
815 #ifdef CONFIG_PROC_FS
816 struct proc_dir_entry *controller_proc_dir_entry;
817 struct proc_dir_entry *proc_read;
818 struct proc_dir_entry *proc_stat;
819 struct proc_dir_entry *proc_mbox;
821 #if MEGA_HAVE_ENH_PROC
822 struct proc_dir_entry *proc_rr;
823 struct proc_dir_entry *proc_battery;
824 #define MAX_PROC_CHANNELS 4
825 struct proc_dir_entry *proc_pdrvstat[MAX_PROC_CHANNELS];
826 struct proc_dir_entry *proc_rdrvstat[MAX_PROC_CHANNELS];
831 int has_64bit_addr; /* are we using 64-bit addressing */
833 int boot_ldrv_enabled;
835 int boot_pdrv_enabled; /* boot from physical drive */
836 int boot_pdrv_ch; /* boot physical drive channel */
837 int boot_pdrv_tgt; /* boot physical drive target */
840 int support_random_del; /* Do we support random deletion of
842 int read_ldidmap; /* set after logical drive deltion. The
843 logical drive number must be read from the
845 atomic_t quiescent; /* a stage reached when delete logical
846 drive needs to be done. Stop
847 sending requests to the hba till
848 delete operation is completed */
851 u8 logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
855 u8 sglen; /* f/w supported scatter-gather list length */
858 struct mutex int_mtx; /* To synchronize the internal
860 int int_status; /* status of internal cmd */
861 struct completion int_waitq; /* wait queue for internal
864 int has_cluster; /* cluster support on this HBA */
870 adapter_t *hostdata_addr;
875 * For state flag. Do not use LSB(8 bits) which are
876 * reserved for storing info about channels.
878 #define IN_ABORT 0x80000000L
879 #define IN_RESET 0x40000000L
880 #define BOARD_MEMMAP 0x20000000L
881 #define BOARD_IOMAP 0x10000000L
882 #define BOARD_40LD 0x08000000L
883 #define BOARD_64BIT 0x04000000L
885 #define INTR_VALID 0x40
887 #define PCI_CONF_AMISIG 0xa0
888 #define PCI_CONF_AMISIG64 0xa4
891 #define MEGA_DMA_TYPE_NONE 0xFFFF
892 #define MEGA_BULK_DATA 0x0001
893 #define MEGA_SGLIST 0x0002
896 * Parameters for the io-mapped controllers
899 /* I/O Port offsets */
900 #define CMD_PORT 0x00
901 #define ACK_PORT 0x00
902 #define TOGGLE_PORT 0x01
903 #define INTR_PORT 0x0a
905 #define MBOX_BUSY_PORT 0x00
906 #define MBOX_PORT0 0x04
907 #define MBOX_PORT1 0x05
908 #define MBOX_PORT2 0x06
909 #define MBOX_PORT3 0x07
910 #define ENABLE_MBOX_REGION 0x0B
912 /* I/O Port Values */
913 #define ISSUE_BYTE 0x10
914 #define ACK_BYTE 0x08
915 #define ENABLE_INTR_BYTE 0xc0
916 #define DISABLE_INTR_BYTE 0x00
917 #define VALID_INTR_BYTE 0x40
918 #define MBOX_BUSY_BYTE 0x10
919 #define ENABLE_MBOX_BYTE 0x00
922 /* Setup some port macros here */
923 #define issue_command(adapter) \
924 outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
926 #define irq_state(adapter) inb_p((adapter)->base + INTR_PORT)
928 #define set_irq_state(adapter, value) \
929 outb_p((value), (adapter)->base + INTR_PORT)
931 #define irq_ack(adapter) \
932 outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
934 #define irq_enable(adapter) \
935 outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
937 #define irq_disable(adapter) \
938 outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
942 * This is our SYSDEP area. All kernel specific detail should be placed here -
943 * as much as possible
950 const char *megaraid_info (struct Scsi_Host *);
952 static int mega_query_adapter(adapter_t *);
953 static int issue_scb(adapter_t *, scb_t *);
954 static int mega_setup_mailbox(adapter_t *);
956 static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
957 static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
958 static void __mega_runpendq(adapter_t *);
959 static int issue_scb_block(adapter_t *, u_char *);
961 static irqreturn_t megaraid_isr_memmapped(int, void *);
962 static irqreturn_t megaraid_isr_iomapped(int, void *);
964 static void mega_free_scb(adapter_t *, scb_t *);
966 static int megaraid_abort(Scsi_Cmnd *);
967 static int megaraid_reset(Scsi_Cmnd *);
968 static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int);
969 static int megaraid_biosparam(struct scsi_device *, struct block_device *,
972 static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
973 u32 *buffer, u32 *length);
974 static int __mega_busywait_mbox (adapter_t *);
975 static void mega_rundoneq (adapter_t *);
976 static void mega_cmd_done(adapter_t *, u8 [], int, int);
977 static inline void mega_free_sgl (adapter_t *adapter);
978 static void mega_8_to_40ld (mraid_inquiry *inquiry,
979 mega_inquiry3 *enquiry3, mega_product_info *);
981 static int megadev_open (struct inode *, struct file *);
982 static int megadev_ioctl (struct file *, unsigned int, unsigned long);
983 static int mega_m_to_n(void __user *, nitioctl_t *);
984 static int mega_n_to_m(void __user *, megacmd_t *);
986 static int mega_init_scb (adapter_t *);
988 static int mega_is_bios_enabled (adapter_t *);
990 #ifdef CONFIG_PROC_FS
991 static void mega_create_proc_entry(int, struct proc_dir_entry *);
992 static int mega_adapinq(adapter_t *, dma_addr_t);
993 static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
996 static int mega_support_ext_cdb(adapter_t *);
997 static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
998 Scsi_Cmnd *, int, int);
999 static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
1000 scb_t *, Scsi_Cmnd *, int, int);
1001 static void mega_enum_raid_scsi(adapter_t *);
1002 static void mega_get_boot_drv(adapter_t *);
1003 static int mega_support_random_del(adapter_t *);
1004 static int mega_del_logdrv(adapter_t *, int);
1005 static int mega_do_del_logdrv(adapter_t *, int);
1006 static void mega_get_max_sgl(adapter_t *);
1007 static int mega_internal_command(adapter_t *, megacmd_t *, mega_passthru *);
1008 static int mega_support_cluster(adapter_t *);
1011 /* vi: set ts=8 sw=8 tw=78: */