Linux Audio

Check our new training course

Loading...
v3.1
   1#ifndef __MEGARAID_H__
   2#define __MEGARAID_H__
   3
   4#include <linux/spinlock.h>
   5#include <linux/mutex.h>
   6
   7#define MEGARAID_VERSION	\
   8	"v2.00.4 (Release Date: Thu Feb 9 08:51:30 EST 2006)\n"
   9
  10/*
  11 * Driver features - change the values to enable or disable features in the
  12 * driver.
  13 */
  14
  15/*
  16 * Command coalescing - This feature allows the driver to be able to combine
  17 * two or more commands and issue as one command in order to boost I/O
  18 * performance. Useful if the nature of the I/O is sequential. It is not very
  19 * useful for random natured I/Os.
  20 */
  21#define MEGA_HAVE_COALESCING	0
  22
  23/*
  24 * Clustering support - Set this flag if you are planning to use the
  25 * clustering services provided by the megaraid controllers and planning to
  26 * setup a cluster
  27 */
  28#define MEGA_HAVE_CLUSTERING	1
  29
  30/*
  31 * Driver statistics - Set this flag if you are interested in statics about
  32 * number of I/O completed on each logical drive and how many interrupts
  33 * generated. If enabled, this information is available through /proc
  34 * interface and through the private ioctl. Setting this flag has a
  35 * performance penalty.
  36 */
  37#define MEGA_HAVE_STATS		0
  38
  39/*
  40 * Enhanced /proc interface - This feature will allow you to have a more
  41 * detailed /proc interface for megaraid driver. E.g., a real time update of
  42 * the status of the logical drives, battery status, physical drives etc.
  43 */
  44#define MEGA_HAVE_ENH_PROC	1
  45
  46#define MAX_DEV_TYPE	32
  47
  48#ifndef PCI_VENDOR_ID_LSI_LOGIC
  49#define PCI_VENDOR_ID_LSI_LOGIC		0x1000
  50#endif
  51
  52#ifndef PCI_VENDOR_ID_AMI
  53#define PCI_VENDOR_ID_AMI		0x101E
  54#endif
  55
  56#ifndef PCI_VENDOR_ID_DELL
  57#define PCI_VENDOR_ID_DELL		0x1028
  58#endif
  59
  60#ifndef PCI_VENDOR_ID_INTEL
  61#define PCI_VENDOR_ID_INTEL		0x8086
  62#endif
  63
  64#ifndef PCI_DEVICE_ID_AMI_MEGARAID
  65#define PCI_DEVICE_ID_AMI_MEGARAID	0x9010
  66#endif
  67
  68#ifndef PCI_DEVICE_ID_AMI_MEGARAID2
  69#define PCI_DEVICE_ID_AMI_MEGARAID2	0x9060
  70#endif
  71
  72#ifndef PCI_DEVICE_ID_AMI_MEGARAID3
  73#define PCI_DEVICE_ID_AMI_MEGARAID3	0x1960
  74#endif
  75
  76#define PCI_DEVICE_ID_DISCOVERY		0x000E
  77#define PCI_DEVICE_ID_PERC4_DI		0x000F
  78#define PCI_DEVICE_ID_PERC4_QC_VERDE	0x0407
  79
  80/* Sub-System Vendor IDs */
  81#define	AMI_SUBSYS_VID			0x101E
  82#define DELL_SUBSYS_VID			0x1028
  83#define	HP_SUBSYS_VID			0x103C
  84#define LSI_SUBSYS_VID			0x1000
  85#define INTEL_SUBSYS_VID		0x8086
  86
  87#define HBA_SIGNATURE	      		0x3344
  88#define HBA_SIGNATURE_471	  	0xCCCC
  89#define HBA_SIGNATURE_64BIT		0x0299
  90
  91#define MBOX_BUSY_WAIT			10	/* wait for up to 10 usec for
  92						   mailbox to be free */
  93#define DEFAULT_INITIATOR_ID	7
  94
  95#define MAX_SGLIST		64	/* max supported in f/w */
  96#define MIN_SGLIST		26	/* guaranteed to support these many */
  97#define MAX_COMMANDS		126
  98#define CMDID_INT_CMDS		MAX_COMMANDS+1	/* make sure CMDID_INT_CMDS
  99					 	is less than max commands
 100						supported by any f/w */
 101
 102#define MAX_CDB_LEN	     	10
 103#define MAX_EXT_CDB_LEN		16	/* we support cdb length up to 16 */
 104
 105#define DEF_CMD_PER_LUN		63
 106#define MAX_CMD_PER_LUN		MAX_COMMANDS
 107#define MAX_FIRMWARE_STATUS	46
 108#define MAX_XFER_PER_CMD	(64*1024)
 109#define MAX_SECTORS_PER_IO	128
 110
 111#define MAX_LOGICAL_DRIVES_40LD		40
 112#define FC_MAX_PHYSICAL_DEVICES		256
 113#define MAX_LOGICAL_DRIVES_8LD		8
 114#define MAX_CHANNELS			5
 115#define MAX_TARGET			15
 116#define MAX_PHYSICAL_DRIVES		MAX_CHANNELS*MAX_TARGET
 117#define MAX_ROW_SIZE_40LD		32
 118#define MAX_ROW_SIZE_8LD		8
 119#define MAX_SPAN_DEPTH			8
 120
 121#define NVIRT_CHAN		4	/* # of virtual channels to represent
 122					   up to 60 logical drives */
 123struct mbox_out {
 124	/* 0x0 */ u8 cmd;
 125	/* 0x1 */ u8 cmdid;
 126	/* 0x2 */ u16 numsectors;
 127	/* 0x4 */ u32 lba;
 128	/* 0x8 */ u32 xferaddr;
 129	/* 0xC */ u8 logdrv;
 130	/* 0xD */ u8 numsgelements;
 131	/* 0xE */ u8 resvd;
 132} __attribute__ ((packed));
 133
 134struct mbox_in {
 135	/* 0xF */ volatile u8 busy;
 136	/* 0x10 */ volatile u8 numstatus;
 137	/* 0x11 */ volatile u8 status;
 138	/* 0x12 */ volatile u8 completed[MAX_FIRMWARE_STATUS];
 139	volatile u8 poll;
 140	volatile u8 ack;
 141} __attribute__ ((packed));
 142
 143typedef struct {
 144	struct mbox_out	m_out;
 145	struct mbox_in	m_in;
 146} __attribute__ ((packed)) mbox_t;
 147
 148typedef struct {
 149	u32 xfer_segment_lo;
 150	u32 xfer_segment_hi;
 151	mbox_t mbox;
 152} __attribute__ ((packed)) mbox64_t;
 153
 154
 155/*
 156 * Passthru definitions
 157 */
 158#define MAX_REQ_SENSE_LEN       0x20
 159
 160typedef struct {
 161	u8 timeout:3;		/* 0=6sec/1=60sec/2=10min/3=3hrs */
 162	u8 ars:1;
 163	u8 reserved:3;
 164	u8 islogical:1;
 165	u8 logdrv;		/* if islogical == 1 */
 166	u8 channel;		/* if islogical == 0 */
 167	u8 target;		/* if islogical == 0 */
 168	u8 queuetag;		/* unused */
 169	u8 queueaction;		/* unused */
 170	u8 cdb[MAX_CDB_LEN];
 171	u8 cdblen;
 172	u8 reqsenselen;
 173	u8 reqsensearea[MAX_REQ_SENSE_LEN];
 174	u8 numsgelements;
 175	u8 scsistatus;
 176	u32 dataxferaddr;
 177	u32 dataxferlen;
 178} __attribute__ ((packed)) mega_passthru;
 179
 180
 181/*
 182 * Extended passthru: support CDB > 10 bytes
 183 */
 184typedef struct {
 185	u8 timeout:3;		/* 0=6sec/1=60sec/2=10min/3=3hrs */
 186	u8 ars:1;
 187	u8 rsvd1:1;
 188	u8 cd_rom:1;
 189	u8 rsvd2:1;
 190	u8 islogical:1;
 191	u8 logdrv;		/* if islogical == 1 */
 192	u8 channel;		/* if islogical == 0 */
 193	u8 target;		/* if islogical == 0 */
 194	u8 queuetag;		/* unused */
 195	u8 queueaction;		/* unused */
 196	u8 cdblen;
 197	u8 rsvd3;
 198	u8 cdb[MAX_EXT_CDB_LEN];
 199	u8 numsgelements;
 200	u8 status;
 201	u8 reqsenselen;
 202	u8 reqsensearea[MAX_REQ_SENSE_LEN];
 203	u8 rsvd4;
 204	u32 dataxferaddr;
 205	u32 dataxferlen;
 206} __attribute__ ((packed)) mega_ext_passthru;
 207
 208typedef struct {
 209	u64 address;
 210	u32 length;
 211} __attribute__ ((packed)) mega_sgl64;
 212
 213typedef struct {
 214	u32 address;
 215	u32 length;
 216} __attribute__ ((packed)) mega_sglist;
 217
 218
 219/* Queued command data */
 220typedef struct {
 221	int	idx;
 222	u32	state;
 223	struct list_head	list;
 224	u8	raw_mbox[66];
 225	u32	dma_type;
 226	u32	dma_direction;
 227
 228	Scsi_Cmnd	*cmd;
 229	dma_addr_t	dma_h_bulkdata;
 230	dma_addr_t	dma_h_sgdata;
 231
 232	mega_sglist	*sgl;
 233	mega_sgl64	*sgl64;
 234	dma_addr_t	sgl_dma_addr;
 235
 236	mega_passthru		*pthru;
 237	dma_addr_t		pthru_dma_addr;
 238	mega_ext_passthru	*epthru;
 239	dma_addr_t		epthru_dma_addr;
 240} scb_t;
 241
 242/*
 243 * Flags to follow the scb as it transitions between various stages
 244 */
 245#define SCB_FREE	0x0000	/* on the free list */
 246#define SCB_ACTIVE	0x0001	/* off the free list */
 247#define SCB_PENDQ	0x0002	/* on the pending queue */
 248#define SCB_ISSUED	0x0004	/* issued - owner f/w */
 249#define SCB_ABORT	0x0008	/* Got an abort for this one */
 250#define SCB_RESET	0x0010	/* Got a reset for this one */
 251
 252/*
 253 * Utilities declare this strcture size as 1024 bytes. So more fields can
 254 * be added in future.
 255 */
 256typedef struct {
 257	u32	data_size; /* current size in bytes (not including resvd) */
 258
 259	u32	config_signature;
 260		/* Current value is 0x00282008
 261		 * 0x28=MAX_LOGICAL_DRIVES,
 262		 * 0x20=Number of stripes and
 263		 * 0x08=Number of spans */
 264
 265	u8	fw_version[16];		/* printable ASCI string */
 266	u8	bios_version[16];	/* printable ASCI string */
 267	u8	product_name[80];	/* printable ASCI string */
 268
 269	u8	max_commands;		/* Max. concurrent commands supported */
 270	u8	nchannels;		/* Number of SCSI Channels detected */
 271	u8	fc_loop_present;	/* Number of Fibre Loops detected */
 272	u8	mem_type;		/* EDO, FPM, SDRAM etc */
 273
 274	u32	signature;
 275	u16	dram_size;		/* In terms of MB */
 276	u16	subsysid;
 277
 278	u16	subsysvid;
 279	u8	notify_counters;
 280	u8	pad1k[889];		/* 135 + 889 resvd = 1024 total size */
 281} __attribute__ ((packed)) mega_product_info;
 282
 283struct notify {
 284	u32 global_counter;	/* Any change increments this counter */
 285
 286	u8 param_counter;	/* Indicates any params changed  */
 287	u8 param_id;		/* Param modified - defined below */
 288	u16 param_val;		/* New val of last param modified */
 289
 290	u8 write_config_counter;	/* write config occurred */
 291	u8 write_config_rsvd[3];
 292
 293	u8 ldrv_op_counter;	/* Indicates ldrv op started/completed */
 294	u8 ldrv_opid;		/* ldrv num */
 295	u8 ldrv_opcmd;		/* ldrv operation - defined below */
 296	u8 ldrv_opstatus;	/* status of the operation */
 297
 298	u8 ldrv_state_counter;	/* Indicates change of ldrv state */
 299	u8 ldrv_state_id;		/* ldrv num */
 300	u8 ldrv_state_new;	/* New state */
 301	u8 ldrv_state_old;	/* old state */
 302
 303	u8 pdrv_state_counter;	/* Indicates change of ldrv state */
 304	u8 pdrv_state_id;		/* pdrv id */
 305	u8 pdrv_state_new;	/* New state */
 306	u8 pdrv_state_old;	/* old state */
 307
 308	u8 pdrv_fmt_counter;	/* Indicates pdrv format started/over */
 309	u8 pdrv_fmt_id;		/* pdrv id */
 310	u8 pdrv_fmt_val;		/* format started/over */
 311	u8 pdrv_fmt_rsvd;
 312
 313	u8 targ_xfer_counter;	/* Indicates SCSI-2 Xfer rate change */
 314	u8 targ_xfer_id;	/* pdrv Id  */
 315	u8 targ_xfer_val;		/* new Xfer params of last pdrv */
 316	u8 targ_xfer_rsvd;
 317
 318	u8 fcloop_id_chg_counter;	/* Indicates loopid changed */
 319	u8 fcloopid_pdrvid;		/* pdrv id */
 320	u8 fcloop_id0;			/* loopid on fc loop 0 */
 321	u8 fcloop_id1;			/* loopid on fc loop 1 */
 322
 323	u8 fcloop_state_counter;	/* Indicates loop state changed */
 324	u8 fcloop_state0;		/* state of fc loop 0 */
 325	u8 fcloop_state1;		/* state of fc loop 1 */
 326	u8 fcloop_state_rsvd;
 327} __attribute__ ((packed));
 328
 329#define MAX_NOTIFY_SIZE     0x80
 330#define CUR_NOTIFY_SIZE     sizeof(struct notify)
 331
 332typedef struct {
 333	u32	data_size; /* current size in bytes (not including resvd) */
 334
 335	struct notify notify;
 336
 337	u8	notify_rsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
 338
 339	u8	rebuild_rate;		/* Rebuild rate (0% - 100%) */
 340	u8	cache_flush_interval;	/* In terms of Seconds */
 341	u8	sense_alert;
 342	u8	drive_insert_count;	/* drive insertion count */
 343
 344	u8	battery_status;
 345	u8	num_ldrv;		/* No. of Log Drives configured */
 346	u8	recon_state[MAX_LOGICAL_DRIVES_40LD / 8];	/* State of
 347							   reconstruct */
 348	u16	ldrv_op_status[MAX_LOGICAL_DRIVES_40LD / 8]; /* logdrv
 349								 Status */
 350
 351	u32	ldrv_size[MAX_LOGICAL_DRIVES_40LD];/* Size of each log drv */
 352	u8	ldrv_prop[MAX_LOGICAL_DRIVES_40LD];
 353	u8	ldrv_state[MAX_LOGICAL_DRIVES_40LD];/* State of log drives */
 354	u8	pdrv_state[FC_MAX_PHYSICAL_DEVICES];/* State of phys drvs. */
 355	u16	pdrv_format[FC_MAX_PHYSICAL_DEVICES / 16];
 356
 357	u8	targ_xfer[80];	/* phys device transfer rate */
 358	u8	pad1k[263];	/* 761 + 263reserved = 1024 bytes total size */
 359} __attribute__ ((packed)) mega_inquiry3;
 360
 361
 362/* Structures */
 363typedef struct {
 364	u8	max_commands;	/* Max concurrent commands supported */
 365	u8	rebuild_rate;	/* Rebuild rate - 0% thru 100% */
 366	u8	max_targ_per_chan;	/* Max targ per channel */
 367	u8	nchannels;	/* Number of channels on HBA */
 368	u8	fw_version[4];	/* Firmware version */
 369	u16	age_of_flash;	/* Number of times FW has been flashed */
 370	u8	chip_set_value;	/* Contents of 0xC0000832 */
 371	u8	dram_size;	/* In MB */
 372	u8	cache_flush_interval;	/* in seconds */
 373	u8	bios_version[4];
 374	u8	board_type;
 375	u8	sense_alert;
 376	u8	write_config_count;	/* Increase with every configuration
 377					   change */
 378	u8	drive_inserted_count;	/* Increase with every drive inserted
 379					 */
 380	u8	inserted_drive;	/* Channel:Id of inserted drive */
 381	u8	battery_status;	/*
 382				 * BIT 0: battery module missing
 383				 * BIT 1: VBAD
 384				 * BIT 2: temperature high
 385				 * BIT 3: battery pack missing
 386				 * BIT 4,5:
 387				 *   00 - charge complete
 388				 *   01 - fast charge in progress
 389				 *   10 - fast charge fail
 390				 *   11 - undefined
 391				 * Bit 6: counter > 1000
 392				 * Bit 7: Undefined
 393				 */
 394	u8	dec_fault_bus_info;
 395} __attribute__ ((packed)) mega_adp_info;
 396
 397
 398typedef struct {
 399	u8	num_ldrv;	/* Number of logical drives configured */
 400	u8	rsvd[3];
 401	u32	ldrv_size[MAX_LOGICAL_DRIVES_8LD];
 402	u8	ldrv_prop[MAX_LOGICAL_DRIVES_8LD];
 403	u8	ldrv_state[MAX_LOGICAL_DRIVES_8LD];
 404} __attribute__ ((packed)) mega_ldrv_info;
 405
 406typedef struct {
 407	u8	pdrv_state[MAX_PHYSICAL_DRIVES];
 408	u8	rsvd;
 409} __attribute__ ((packed)) mega_pdrv_info;
 410
 411/* RAID inquiry: Mailbox command 0x05*/
 412typedef struct {
 413	mega_adp_info	adapter_info;
 414	mega_ldrv_info	logdrv_info;
 415	mega_pdrv_info	pdrv_info;
 416} __attribute__ ((packed)) mraid_inquiry;
 417
 418
 419/* RAID extended inquiry: Mailbox command 0x04*/
 420typedef struct {
 421	mraid_inquiry	raid_inq;
 422	u16	phys_drv_format[MAX_CHANNELS];
 423	u8	stack_attn;
 424	u8	modem_status;
 425	u8	rsvd[2];
 426} __attribute__ ((packed)) mraid_ext_inquiry;
 427
 428
 429typedef struct {
 430	u8	channel;
 431	u8	target;
 432}__attribute__ ((packed)) adp_device;
 433
 434typedef struct {
 435	u32		start_blk;	/* starting block */
 436	u32		num_blks;	/* # of blocks */
 437	adp_device	device[MAX_ROW_SIZE_40LD];
 438}__attribute__ ((packed)) adp_span_40ld;
 439
 440typedef struct {
 441	u32		start_blk;	/* starting block */
 442	u32		num_blks;	/* # of blocks */
 443	adp_device	device[MAX_ROW_SIZE_8LD];
 444}__attribute__ ((packed)) adp_span_8ld;
 445
 446typedef struct {
 447	u8	span_depth;	/* Total # of spans */
 448	u8	level;		/* RAID level */
 449	u8	read_ahead;	/* read ahead, no read ahead, adaptive read
 450				   ahead */
 451	u8	stripe_sz;	/* Encoded stripe size */
 452	u8	status;		/* Status of the logical drive */
 453	u8	write_mode;	/* write mode, write_through/write_back */
 454	u8	direct_io;	/* direct io or through cache */
 455	u8	row_size;	/* Number of stripes in a row */
 456} __attribute__ ((packed)) logdrv_param;
 457
 458typedef struct {
 459	logdrv_param	lparam;
 460	adp_span_40ld	span[MAX_SPAN_DEPTH];
 461}__attribute__ ((packed)) logdrv_40ld;
 462
 463typedef struct {
 464	logdrv_param	lparam;
 465	adp_span_8ld	span[MAX_SPAN_DEPTH];
 466}__attribute__ ((packed)) logdrv_8ld;
 467
 468typedef struct {
 469	u8	type;		/* Type of the device */
 470	u8	cur_status;	/* current status of the device */
 471	u8	tag_depth;	/* Level of tagging */
 472	u8	sync_neg;	/* sync negotiation - ENABLE or DISABLE */
 473	u32	size;		/* configurable size in terms of 512 byte
 474				   blocks */
 475}__attribute__ ((packed)) phys_drv;
 476
 477typedef struct {
 478	u8		nlog_drives;		/* number of logical drives */
 479	u8		resvd[3];
 480	logdrv_40ld	ldrv[MAX_LOGICAL_DRIVES_40LD];
 481	phys_drv	pdrv[MAX_PHYSICAL_DRIVES];
 482}__attribute__ ((packed)) disk_array_40ld;
 483
 484typedef struct {
 485	u8		nlog_drives;	/* number of logical drives */
 486	u8		resvd[3];
 487	logdrv_8ld	ldrv[MAX_LOGICAL_DRIVES_8LD];
 488	phys_drv	pdrv[MAX_PHYSICAL_DRIVES];
 489}__attribute__ ((packed)) disk_array_8ld;
 490
 491
 492/*
 493 * User ioctl structure.
 494 * This structure will be used for Traditional Method ioctl interface
 495 * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
 496 * Driver ioctls.
 497 * The Driver ioctl interface handles the commands at the driver level,
 498 * without being sent to the card.
 499 */
 500/* system call imposed limit. Change accordingly */
 501#define IOCTL_MAX_DATALEN       4096
 502
 503struct uioctl_t {
 504	u32 inlen;
 505	u32 outlen;
 506	union {
 507		u8 fca[16];
 508		struct {
 509			u8 opcode;
 510			u8 subopcode;
 511			u16 adapno;
 512#if BITS_PER_LONG == 32
 513			u8 *buffer;
 514			u8 pad[4];
 515#endif
 516#if BITS_PER_LONG == 64
 517			u8 *buffer;
 518#endif
 519			u32 length;
 520		} __attribute__ ((packed)) fcs;
 521	} __attribute__ ((packed)) ui;
 522	u8 mbox[18];		/* 16 bytes + 2 status bytes */
 523	mega_passthru pthru;
 524#if BITS_PER_LONG == 32
 525	char __user *data;		/* buffer <= 4096 for 0x80 commands */
 526	char pad[4];
 527#endif
 528#if BITS_PER_LONG == 64
 529	char __user *data;
 530#endif
 531} __attribute__ ((packed));
 532
 533/*
 534 * struct mcontroller is used to pass information about the controllers in the
 535 * system. Its up to the application how to use the information. We are passing
 536 * as much info about the cards as possible and useful. Before issuing the
 537 * call to find information about the cards, the application needs to issue a
 538 * ioctl first to find out the number of controllers in the system.
 539 */
 540#define MAX_CONTROLLERS 32
 541
 542struct mcontroller {
 543	u64 base;
 544	u8 irq;
 545	u8 numldrv;
 546	u8 pcibus;
 547	u16 pcidev;
 548	u8 pcifun;
 549	u16 pciid;
 550	u16 pcivendor;
 551	u8 pcislot;
 552	u32 uid;
 553};
 554
 555/*
 556 * mailbox structure used for internal commands
 557 */
 558typedef struct {
 559	u8	cmd;
 560	u8	cmdid;
 561	u8	opcode;
 562	u8	subopcode;
 563	u32	lba;
 564	u32	xferaddr;
 565	u8	logdrv;
 566	u8	rsvd[3];
 567	u8	numstatus;
 568	u8	status;
 569} __attribute__ ((packed)) megacmd_t;
 570
 571/*
 572 * Defines for Driver IOCTL interface
 573 */
 574#define MEGAIOC_MAGIC  	'm'
 575
 576#define MEGAIOC_QNADAP		'm'	/* Query # of adapters */
 577#define MEGAIOC_QDRVRVER	'e'	/* Query driver version */
 578#define MEGAIOC_QADAPINFO   	'g'	/* Query adapter information */
 579#define MKADAP(adapno)	  	(MEGAIOC_MAGIC << 8 | (adapno) )
 580#define GETADAP(mkadap)	 	( (mkadap) ^ MEGAIOC_MAGIC << 8 )
 581
 582/*
 583 * Definition for the new ioctl interface (NIT)
 584 */
 585
 586/*
 587 * Vendor specific Group-7 commands
 588 */
 589#define VENDOR_SPECIFIC_COMMANDS	0xE0
 590#define MEGA_INTERNAL_CMD		VENDOR_SPECIFIC_COMMANDS + 0x01
 591
 592/*
 593 * The ioctl command. No other command shall be used for this interface
 594 */
 595#define USCSICMD	VENDOR_SPECIFIC_COMMANDS
 596
 597/*
 598 * Data direction flags
 599 */
 600#define UIOC_RD		0x00001
 601#define UIOC_WR		0x00002
 602
 603/*
 604 * ioctl opcodes
 605 */
 606#define MBOX_CMD	0x00000	/* DCMD or passthru command */
 607#define GET_DRIVER_VER	0x10000	/* Get driver version */
 608#define GET_N_ADAP	0x20000	/* Get number of adapters */
 609#define GET_ADAP_INFO	0x30000	/* Get information about a adapter */
 610#define GET_CAP		0x40000	/* Get ioctl capabilities */
 611#define GET_STATS	0x50000	/* Get statistics, including error info */
 612
 613
 614/*
 615 * The ioctl structure.
 616 * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
 617 * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
 618 */
 619typedef struct {
 620	char		signature[8];	/* Must contain "MEGANIT" */
 621	u32		opcode;		/* opcode for the command */
 622	u32		adapno;		/* adapter number */
 623	union {
 624		u8	__raw_mbox[18];
 625		void __user *__uaddr; /* xferaddr for non-mbox cmds */
 626	}__ua;
 627
 628#define uioc_rmbox	__ua.__raw_mbox
 629#define MBOX(uioc)	((megacmd_t *)&((uioc).__ua.__raw_mbox[0]))
 630#define MBOX_P(uioc)	((megacmd_t __user *)&((uioc)->__ua.__raw_mbox[0]))
 631#define uioc_uaddr	__ua.__uaddr
 632
 633	u32		xferlen;	/* xferlen for DCMD and non-mbox
 634					   commands */
 635	u32		flags;		/* data direction flags */
 636}nitioctl_t;
 637
 638
 639/*
 640 * I/O statistics for some applications like SNMP agent. The caller must
 641 * provide the number of logical drives for which status should be reported.
 642 */
 643typedef struct {
 644	int	num_ldrv;	/* Number for logical drives for which the
 645				   status should be reported. */
 646	u32	nreads[MAX_LOGICAL_DRIVES_40LD];	/* number of reads for
 647							each logical drive */
 648	u32	nreadblocks[MAX_LOGICAL_DRIVES_40LD];	/* number of blocks
 649							read for each logical
 650							drive */
 651	u32	nwrites[MAX_LOGICAL_DRIVES_40LD];	/* number of writes
 652							for each logical
 653							drive */
 654	u32	nwriteblocks[MAX_LOGICAL_DRIVES_40LD];	/* number of blocks
 655							writes for each
 656							logical drive */
 657	u32	rd_errors[MAX_LOGICAL_DRIVES_40LD];	/* number of read
 658							   errors for each
 659							   logical drive */
 660	u32	wr_errors[MAX_LOGICAL_DRIVES_40LD];	/* number of write
 661							   errors for each
 662							   logical drive */
 663}megastat_t;
 664
 665
 666struct private_bios_data {
 667	u8	geometry:4;	/*
 668				 * bits 0-3 - BIOS geometry
 669				 * 0x0001 - 1GB
 670				 * 0x0010 - 2GB
 671				 * 0x1000 - 8GB
 672				 * Others values are invalid
 673							 */
 674	u8	unused:4;	/* bits 4-7 are unused */
 675	u8	boot_drv;	/*
 676				 * logical drive set as boot drive
 677				 * 0..7 - for 8LD cards
 678				 * 0..39 - for 40LD cards
 679				 */
 680	u8	rsvd[12];
 681	u16	cksum;	/* 0-(sum of first 13 bytes of this structure) */
 682} __attribute__ ((packed));
 683
 684
 685
 686
 687/*
 688 * Mailbox and firmware commands and subopcodes used in this driver.
 689 */
 690
 691#define MEGA_MBOXCMD_LREAD	0x01
 692#define MEGA_MBOXCMD_LWRITE	0x02
 693#define MEGA_MBOXCMD_PASSTHRU	0x03
 694#define MEGA_MBOXCMD_ADPEXTINQ	0x04
 695#define MEGA_MBOXCMD_ADAPTERINQ	0x05
 696#define MEGA_MBOXCMD_LREAD64	0xA7
 697#define MEGA_MBOXCMD_LWRITE64	0xA8
 698#define MEGA_MBOXCMD_PASSTHRU64	0xC3
 699#define MEGA_MBOXCMD_EXTPTHRU	0xE3
 700
 701#define MAIN_MISC_OPCODE	0xA4	/* f/w misc opcode */
 702#define GET_MAX_SG_SUPPORT	0x01	/* get max sg len supported by f/w */
 703
 704#define FC_NEW_CONFIG		0xA1
 705#define NC_SUBOP_PRODUCT_INFO	0x0E
 706#define NC_SUBOP_ENQUIRY3	0x0F
 707#define ENQ3_GET_SOLICITED_FULL	0x02
 708#define OP_DCMD_READ_CONFIG	0x04
 709#define NEW_READ_CONFIG_8LD	0x67
 710#define READ_CONFIG_8LD		0x07
 711#define FLUSH_ADAPTER		0x0A
 712#define FLUSH_SYSTEM		0xFE
 713
 714/*
 715 * Command for random deletion of logical drives
 716 */
 717#define	FC_DEL_LOGDRV		0xA4	/* f/w command */
 718#define	OP_SUP_DEL_LOGDRV	0x2A	/* is feature supported */
 719#define OP_GET_LDID_MAP		0x18	/* get ldid and logdrv number map */
 720#define OP_DEL_LOGDRV		0x1C	/* delete logical drive */
 721
 722/*
 723 * BIOS commands
 724 */
 725#define IS_BIOS_ENABLED		0x62
 726#define GET_BIOS		0x01
 727#define CHNL_CLASS		0xA9
 728#define GET_CHNL_CLASS		0x00
 729#define SET_CHNL_CLASS		0x01
 730#define CH_RAID			0x01
 731#define CH_SCSI			0x00
 732#define BIOS_PVT_DATA		0x40
 733#define GET_BIOS_PVT_DATA	0x00
 734
 735
 736/*
 737 * Commands to support clustering
 738 */
 739#define MEGA_GET_TARGET_ID	0x7D
 740#define MEGA_CLUSTER_OP		0x70
 741#define MEGA_GET_CLUSTER_MODE	0x02
 742#define MEGA_CLUSTER_CMD	0x6E
 743#define MEGA_RESERVE_LD		0x01
 744#define MEGA_RELEASE_LD		0x02
 745#define MEGA_RESET_RESERVATIONS	0x03
 746#define MEGA_RESERVATION_STATUS	0x04
 747#define MEGA_RESERVE_PD		0x05
 748#define MEGA_RELEASE_PD		0x06
 749
 750
 751/*
 752 * Module battery status
 753 */
 754#define MEGA_BATT_MODULE_MISSING	0x01
 755#define MEGA_BATT_LOW_VOLTAGE		0x02
 756#define MEGA_BATT_TEMP_HIGH		0x04
 757#define MEGA_BATT_PACK_MISSING		0x08
 758#define MEGA_BATT_CHARGE_MASK		0x30
 759#define MEGA_BATT_CHARGE_DONE		0x00
 760#define MEGA_BATT_CHARGE_INPROG		0x10
 761#define MEGA_BATT_CHARGE_FAIL		0x20
 762#define MEGA_BATT_CYCLES_EXCEEDED	0x40
 763
 764/*
 765 * Physical drive states.
 766 */
 767#define PDRV_UNCNF	0
 768#define PDRV_ONLINE	3
 769#define PDRV_FAILED	4
 770#define PDRV_RBLD	5
 771#define PDRV_HOTSPARE	6
 772
 773
 774/*
 775 * Raid logical drive states.
 776 */
 777#define RDRV_OFFLINE	0
 778#define RDRV_DEGRADED	1
 779#define RDRV_OPTIMAL	2
 780#define RDRV_DELETED	3
 781
 782/*
 783 * Read, write and cache policies
 784 */
 785#define NO_READ_AHEAD		0
 786#define READ_AHEAD		1
 787#define ADAP_READ_AHEAD		2
 788#define WRMODE_WRITE_THRU	0
 789#define WRMODE_WRITE_BACK	1
 790#define CACHED_IO		0
 791#define DIRECT_IO		1
 792
 793
 794#define SCSI_LIST(scp) ((struct list_head *)(&(scp)->SCp))
 795
 796/*
 797 * Each controller's soft state
 798 */
 799typedef struct {
 800	int	this_id;	/* our id, may set to different than 7 if
 801				   clustering is available */
 802	u32	flag;
 803
 804	unsigned long		base;
 805	void __iomem		*mmio_base;
 806
 807	/* mbox64 with mbox not aligned on 16-byte boundary */
 808	mbox64_t	*una_mbox64;
 809	dma_addr_t	una_mbox64_dma;
 810
 811	volatile mbox64_t	*mbox64;/* ptr to 64-bit mailbox */
 812	volatile mbox_t		*mbox;	/* ptr to standard mailbox */
 813	dma_addr_t		mbox_dma;
 814
 815	struct pci_dev	*dev;
 816
 817	struct list_head	free_list;
 818	struct list_head	pending_list;
 819	struct list_head	completed_list;
 820
 821	struct Scsi_Host	*host;
 822
 823#define MEGA_BUFFER_SIZE (2*1024)
 824	u8		*mega_buffer;
 825	dma_addr_t	buf_dma_handle;
 826
 827	mega_product_info	product_info;
 828
 829	u8		max_cmds;
 830	scb_t		*scb_list;
 831
 832	atomic_t	pend_cmds;	/* maintain a counter for pending
 833					   commands in firmware */
 834
 835#if MEGA_HAVE_STATS
 836	u32	nreads[MAX_LOGICAL_DRIVES_40LD];
 837	u32	nreadblocks[MAX_LOGICAL_DRIVES_40LD];
 838	u32	nwrites[MAX_LOGICAL_DRIVES_40LD];
 839	u32	nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
 840	u32	rd_errors[MAX_LOGICAL_DRIVES_40LD];
 841	u32	wr_errors[MAX_LOGICAL_DRIVES_40LD];
 842#endif
 843
 844	/* Host adapter parameters */
 845	u8	numldrv;
 846	u8	fw_version[7];
 847	u8	bios_version[7];
 848
 849#ifdef CONFIG_PROC_FS
 850	struct proc_dir_entry	*controller_proc_dir_entry;
 851	struct proc_dir_entry	*proc_read;
 852	struct proc_dir_entry	*proc_stat;
 853	struct proc_dir_entry	*proc_mbox;
 854
 855#if MEGA_HAVE_ENH_PROC
 856	struct proc_dir_entry	*proc_rr;
 857	struct proc_dir_entry	*proc_battery;
 858#define MAX_PROC_CHANNELS	4
 859	struct proc_dir_entry	*proc_pdrvstat[MAX_PROC_CHANNELS];
 860	struct proc_dir_entry	*proc_rdrvstat[MAX_PROC_CHANNELS];
 861#endif
 862
 863#endif
 864
 865	int	has_64bit_addr;		/* are we using 64-bit addressing */
 866	int	support_ext_cdb;
 867	int	boot_ldrv_enabled;
 868	int	boot_ldrv;
 869	int	boot_pdrv_enabled;	/* boot from physical drive */
 870	int	boot_pdrv_ch;		/* boot physical drive channel */
 871	int	boot_pdrv_tgt;		/* boot physical drive target */
 872
 873
 874	int	support_random_del;	/* Do we support random deletion of
 875					   logdrvs */
 876	int	read_ldidmap;	/* set after logical drive deltion. The
 877				   logical drive number must be read from the
 878				   map */
 879	atomic_t	quiescent;	/* a stage reached when delete logical
 880					   drive needs to be done. Stop
 881					   sending requests to the hba till
 882					   delete operation is completed */
 883	spinlock_t	lock;
 884
 885	u8	logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
 886							what channels. */
 887	int	mega_ch_class;
 888
 889	u8	sglen;	/* f/w supported scatter-gather list length */
 890
 891	unsigned char int_cdb[MAX_COMMAND_SIZE];
 892	scb_t			int_scb;
 893	struct mutex		int_mtx;	/* To synchronize the internal
 894						commands */
 
 895	struct completion	int_waitq;	/* wait queue for internal
 896						 cmds */
 897
 898	int	has_cluster;	/* cluster support on this HBA */
 899}adapter_t;
 900
 901
 902struct mega_hbas {
 903	int is_bios_enabled;
 904	adapter_t *hostdata_addr;
 905};
 906
 907
 908/*
 909 * For state flag. Do not use LSB(8 bits) which are
 910 * reserved for storing info about channels.
 911 */
 912#define IN_ABORT	0x80000000L
 913#define IN_RESET	0x40000000L
 914#define BOARD_MEMMAP	0x20000000L
 915#define BOARD_IOMAP	0x10000000L
 916#define BOARD_40LD   	0x08000000L
 917#define BOARD_64BIT	0x04000000L
 918
 919#define INTR_VALID			0x40
 920
 921#define PCI_CONF_AMISIG			0xa0
 922#define PCI_CONF_AMISIG64		0xa4
 923
 924
 925#define MEGA_DMA_TYPE_NONE		0xFFFF
 926#define MEGA_BULK_DATA			0x0001
 927#define MEGA_SGLIST			0x0002
 928
 929/*
 930 * Parameters for the io-mapped controllers
 931 */
 932
 933/* I/O Port offsets */
 934#define CMD_PORT	 	0x00
 935#define ACK_PORT	 	0x00
 936#define TOGGLE_PORT		0x01
 937#define INTR_PORT	  	0x0a
 938
 939#define MBOX_BUSY_PORT     	0x00
 940#define MBOX_PORT0	 	0x04
 941#define MBOX_PORT1	 	0x05
 942#define MBOX_PORT2	 	0x06
 943#define MBOX_PORT3	 	0x07
 944#define ENABLE_MBOX_REGION 	0x0B
 945
 946/* I/O Port Values */
 947#define ISSUE_BYTE	 	0x10
 948#define ACK_BYTE	   	0x08
 949#define ENABLE_INTR_BYTE   	0xc0
 950#define DISABLE_INTR_BYTE  	0x00
 951#define VALID_INTR_BYTE    	0x40
 952#define MBOX_BUSY_BYTE     	0x10
 953#define ENABLE_MBOX_BYTE   	0x00
 954
 955
 956/* Setup some port macros here */
 957#define issue_command(adapter)	\
 958		outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
 959
 960#define irq_state(adapter)	inb_p((adapter)->base + INTR_PORT)
 961
 962#define set_irq_state(adapter, value)	\
 963		outb_p((value), (adapter)->base + INTR_PORT)
 964
 965#define irq_ack(adapter)	\
 966		outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
 967
 968#define irq_enable(adapter)	\
 969	outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
 970
 971#define irq_disable(adapter)	\
 972	outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
 973
 974
 975/*
 976 * This is our SYSDEP area. All kernel specific detail should be placed here -
 977 * as much as possible
 978 */
 979
 980/*
 981 * End of SYSDEP area
 982 */
 983
 984const char *megaraid_info (struct Scsi_Host *);
 985
 986static int mega_query_adapter(adapter_t *);
 987static int issue_scb(adapter_t *, scb_t *);
 988static int mega_setup_mailbox(adapter_t *);
 989
 990static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
 991static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
 992static void __mega_runpendq(adapter_t *);
 993static int issue_scb_block(adapter_t *, u_char *);
 994
 995static irqreturn_t megaraid_isr_memmapped(int, void *);
 996static irqreturn_t megaraid_isr_iomapped(int, void *);
 997
 998static void mega_free_scb(adapter_t *, scb_t *);
 999
1000static int megaraid_abort(Scsi_Cmnd *);
1001static int megaraid_reset(Scsi_Cmnd *);
1002static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int);
1003static int megaraid_biosparam(struct scsi_device *, struct block_device *,
1004		sector_t, int []);
1005
1006static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
1007			      u32 *buffer, u32 *length);
1008static int __mega_busywait_mbox (adapter_t *);
1009static void mega_rundoneq (adapter_t *);
1010static void mega_cmd_done(adapter_t *, u8 [], int, int);
1011static inline void mega_free_sgl (adapter_t *adapter);
1012static void mega_8_to_40ld (mraid_inquiry *inquiry,
1013		mega_inquiry3 *enquiry3, mega_product_info *);
1014
1015static int megadev_open (struct inode *, struct file *);
1016static int megadev_ioctl (struct file *, unsigned int, unsigned long);
1017static int mega_m_to_n(void __user *, nitioctl_t *);
1018static int mega_n_to_m(void __user *, megacmd_t *);
1019
1020static int mega_init_scb (adapter_t *);
1021
1022static int mega_is_bios_enabled (adapter_t *);
1023
1024#ifdef CONFIG_PROC_FS
1025static int mega_print_inquiry(char *, char *);
1026static void mega_create_proc_entry(int, struct proc_dir_entry *);
1027static int proc_read_config(char *, char **, off_t, int, int *, void *);
1028static int proc_read_stat(char *, char **, off_t, int, int *, void *);
1029static int proc_read_mbox(char *, char **, off_t, int, int *, void *);
1030static int proc_rebuild_rate(char *, char **, off_t, int, int *, void *);
1031static int proc_battery(char *, char **, off_t, int, int *, void *);
1032static int proc_pdrv_ch0(char *, char **, off_t, int, int *, void *);
1033static int proc_pdrv_ch1(char *, char **, off_t, int, int *, void *);
1034static int proc_pdrv_ch2(char *, char **, off_t, int, int *, void *);
1035static int proc_pdrv_ch3(char *, char **, off_t, int, int *, void *);
1036static int proc_pdrv(adapter_t *, char *, int);
1037static int proc_rdrv_10(char *, char **, off_t, int, int *, void *);
1038static int proc_rdrv_20(char *, char **, off_t, int, int *, void *);
1039static int proc_rdrv_30(char *, char **, off_t, int, int *, void *);
1040static int proc_rdrv_40(char *, char **, off_t, int, int *, void *);
1041static int proc_rdrv(adapter_t *, char *, int, int);
1042
1043static int mega_adapinq(adapter_t *, dma_addr_t);
1044static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
1045#endif
1046
1047static int mega_support_ext_cdb(adapter_t *);
1048static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
1049		Scsi_Cmnd *, int, int);
1050static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
1051		scb_t *, Scsi_Cmnd *, int, int);
1052static void mega_enum_raid_scsi(adapter_t *);
1053static void mega_get_boot_drv(adapter_t *);
1054static int mega_support_random_del(adapter_t *);
1055static int mega_del_logdrv(adapter_t *, int);
1056static int mega_do_del_logdrv(adapter_t *, int);
1057static void mega_get_max_sgl(adapter_t *);
1058static int mega_internal_command(adapter_t *, megacmd_t *, mega_passthru *);
1059static void mega_internal_done(Scsi_Cmnd *);
1060static int mega_support_cluster(adapter_t *);
1061#endif
1062
1063/* vi: set ts=8 sw=8 tw=78: */
v4.6
   1#ifndef __MEGARAID_H__
   2#define __MEGARAID_H__
   3
   4#include <linux/spinlock.h>
   5#include <linux/mutex.h>
   6
   7#define MEGARAID_VERSION	\
   8	"v2.00.4 (Release Date: Thu Feb 9 08:51:30 EST 2006)\n"
   9
  10/*
  11 * Driver features - change the values to enable or disable features in the
  12 * driver.
  13 */
  14
  15/*
  16 * Command coalescing - This feature allows the driver to be able to combine
  17 * two or more commands and issue as one command in order to boost I/O
  18 * performance. Useful if the nature of the I/O is sequential. It is not very
  19 * useful for random natured I/Os.
  20 */
  21#define MEGA_HAVE_COALESCING	0
  22
  23/*
  24 * Clustering support - Set this flag if you are planning to use the
  25 * clustering services provided by the megaraid controllers and planning to
  26 * setup a cluster
  27 */
  28#define MEGA_HAVE_CLUSTERING	1
  29
  30/*
  31 * Driver statistics - Set this flag if you are interested in statics about
  32 * number of I/O completed on each logical drive and how many interrupts
  33 * generated. If enabled, this information is available through /proc
  34 * interface and through the private ioctl. Setting this flag has a
  35 * performance penalty.
  36 */
  37#define MEGA_HAVE_STATS		0
  38
  39/*
  40 * Enhanced /proc interface - This feature will allow you to have a more
  41 * detailed /proc interface for megaraid driver. E.g., a real time update of
  42 * the status of the logical drives, battery status, physical drives etc.
  43 */
  44#define MEGA_HAVE_ENH_PROC	1
  45
  46#define MAX_DEV_TYPE	32
  47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  48#define PCI_DEVICE_ID_DISCOVERY		0x000E
  49#define PCI_DEVICE_ID_PERC4_DI		0x000F
  50#define PCI_DEVICE_ID_PERC4_QC_VERDE	0x0407
  51
 
 
 
 
 
 
 
  52#define HBA_SIGNATURE	      		0x3344
  53#define HBA_SIGNATURE_471	  	0xCCCC
  54#define HBA_SIGNATURE_64BIT		0x0299
  55
  56#define MBOX_BUSY_WAIT			10	/* wait for up to 10 usec for
  57						   mailbox to be free */
  58#define DEFAULT_INITIATOR_ID	7
  59
  60#define MAX_SGLIST		64	/* max supported in f/w */
  61#define MIN_SGLIST		26	/* guaranteed to support these many */
  62#define MAX_COMMANDS		126
  63#define CMDID_INT_CMDS		MAX_COMMANDS+1	/* make sure CMDID_INT_CMDS
  64					 	is less than max commands
  65						supported by any f/w */
  66
  67#define MAX_CDB_LEN	     	10
  68#define MAX_EXT_CDB_LEN		16	/* we support cdb length up to 16 */
  69
  70#define DEF_CMD_PER_LUN		63
  71#define MAX_CMD_PER_LUN		MAX_COMMANDS
  72#define MAX_FIRMWARE_STATUS	46
  73#define MAX_XFER_PER_CMD	(64*1024)
  74#define MAX_SECTORS_PER_IO	128
  75
  76#define MAX_LOGICAL_DRIVES_40LD		40
  77#define FC_MAX_PHYSICAL_DEVICES		256
  78#define MAX_LOGICAL_DRIVES_8LD		8
  79#define MAX_CHANNELS			5
  80#define MAX_TARGET			15
  81#define MAX_PHYSICAL_DRIVES		MAX_CHANNELS*MAX_TARGET
  82#define MAX_ROW_SIZE_40LD		32
  83#define MAX_ROW_SIZE_8LD		8
  84#define MAX_SPAN_DEPTH			8
  85
  86#define NVIRT_CHAN		4	/* # of virtual channels to represent
  87					   up to 60 logical drives */
  88struct mbox_out {
  89	/* 0x0 */ u8 cmd;
  90	/* 0x1 */ u8 cmdid;
  91	/* 0x2 */ u16 numsectors;
  92	/* 0x4 */ u32 lba;
  93	/* 0x8 */ u32 xferaddr;
  94	/* 0xC */ u8 logdrv;
  95	/* 0xD */ u8 numsgelements;
  96	/* 0xE */ u8 resvd;
  97} __attribute__ ((packed));
  98
  99struct mbox_in {
 100	/* 0xF */ volatile u8 busy;
 101	/* 0x10 */ volatile u8 numstatus;
 102	/* 0x11 */ volatile u8 status;
 103	/* 0x12 */ volatile u8 completed[MAX_FIRMWARE_STATUS];
 104	volatile u8 poll;
 105	volatile u8 ack;
 106} __attribute__ ((packed));
 107
 108typedef struct {
 109	struct mbox_out	m_out;
 110	struct mbox_in	m_in;
 111} __attribute__ ((packed)) mbox_t;
 112
 113typedef struct {
 114	u32 xfer_segment_lo;
 115	u32 xfer_segment_hi;
 116	mbox_t mbox;
 117} __attribute__ ((packed)) mbox64_t;
 118
 119
 120/*
 121 * Passthru definitions
 122 */
 123#define MAX_REQ_SENSE_LEN       0x20
 124
 125typedef struct {
 126	u8 timeout:3;		/* 0=6sec/1=60sec/2=10min/3=3hrs */
 127	u8 ars:1;
 128	u8 reserved:3;
 129	u8 islogical:1;
 130	u8 logdrv;		/* if islogical == 1 */
 131	u8 channel;		/* if islogical == 0 */
 132	u8 target;		/* if islogical == 0 */
 133	u8 queuetag;		/* unused */
 134	u8 queueaction;		/* unused */
 135	u8 cdb[MAX_CDB_LEN];
 136	u8 cdblen;
 137	u8 reqsenselen;
 138	u8 reqsensearea[MAX_REQ_SENSE_LEN];
 139	u8 numsgelements;
 140	u8 scsistatus;
 141	u32 dataxferaddr;
 142	u32 dataxferlen;
 143} __attribute__ ((packed)) mega_passthru;
 144
 145
 146/*
 147 * Extended passthru: support CDB > 10 bytes
 148 */
 149typedef struct {
 150	u8 timeout:3;		/* 0=6sec/1=60sec/2=10min/3=3hrs */
 151	u8 ars:1;
 152	u8 rsvd1:1;
 153	u8 cd_rom:1;
 154	u8 rsvd2:1;
 155	u8 islogical:1;
 156	u8 logdrv;		/* if islogical == 1 */
 157	u8 channel;		/* if islogical == 0 */
 158	u8 target;		/* if islogical == 0 */
 159	u8 queuetag;		/* unused */
 160	u8 queueaction;		/* unused */
 161	u8 cdblen;
 162	u8 rsvd3;
 163	u8 cdb[MAX_EXT_CDB_LEN];
 164	u8 numsgelements;
 165	u8 status;
 166	u8 reqsenselen;
 167	u8 reqsensearea[MAX_REQ_SENSE_LEN];
 168	u8 rsvd4;
 169	u32 dataxferaddr;
 170	u32 dataxferlen;
 171} __attribute__ ((packed)) mega_ext_passthru;
 172
 173typedef struct {
 174	u64 address;
 175	u32 length;
 176} __attribute__ ((packed)) mega_sgl64;
 177
 178typedef struct {
 179	u32 address;
 180	u32 length;
 181} __attribute__ ((packed)) mega_sglist;
 182
 183
 184/* Queued command data */
 185typedef struct {
 186	int	idx;
 187	u32	state;
 188	struct list_head	list;
 189	u8	raw_mbox[66];
 190	u32	dma_type;
 191	u32	dma_direction;
 192
 193	Scsi_Cmnd	*cmd;
 194	dma_addr_t	dma_h_bulkdata;
 195	dma_addr_t	dma_h_sgdata;
 196
 197	mega_sglist	*sgl;
 198	mega_sgl64	*sgl64;
 199	dma_addr_t	sgl_dma_addr;
 200
 201	mega_passthru		*pthru;
 202	dma_addr_t		pthru_dma_addr;
 203	mega_ext_passthru	*epthru;
 204	dma_addr_t		epthru_dma_addr;
 205} scb_t;
 206
 207/*
 208 * Flags to follow the scb as it transitions between various stages
 209 */
 210#define SCB_FREE	0x0000	/* on the free list */
 211#define SCB_ACTIVE	0x0001	/* off the free list */
 212#define SCB_PENDQ	0x0002	/* on the pending queue */
 213#define SCB_ISSUED	0x0004	/* issued - owner f/w */
 214#define SCB_ABORT	0x0008	/* Got an abort for this one */
 215#define SCB_RESET	0x0010	/* Got a reset for this one */
 216
 217/*
 218 * Utilities declare this strcture size as 1024 bytes. So more fields can
 219 * be added in future.
 220 */
 221typedef struct {
 222	u32	data_size; /* current size in bytes (not including resvd) */
 223
 224	u32	config_signature;
 225		/* Current value is 0x00282008
 226		 * 0x28=MAX_LOGICAL_DRIVES,
 227		 * 0x20=Number of stripes and
 228		 * 0x08=Number of spans */
 229
 230	u8	fw_version[16];		/* printable ASCI string */
 231	u8	bios_version[16];	/* printable ASCI string */
 232	u8	product_name[80];	/* printable ASCI string */
 233
 234	u8	max_commands;		/* Max. concurrent commands supported */
 235	u8	nchannels;		/* Number of SCSI Channels detected */
 236	u8	fc_loop_present;	/* Number of Fibre Loops detected */
 237	u8	mem_type;		/* EDO, FPM, SDRAM etc */
 238
 239	u32	signature;
 240	u16	dram_size;		/* In terms of MB */
 241	u16	subsysid;
 242
 243	u16	subsysvid;
 244	u8	notify_counters;
 245	u8	pad1k[889];		/* 135 + 889 resvd = 1024 total size */
 246} __attribute__ ((packed)) mega_product_info;
 247
 248struct notify {
 249	u32 global_counter;	/* Any change increments this counter */
 250
 251	u8 param_counter;	/* Indicates any params changed  */
 252	u8 param_id;		/* Param modified - defined below */
 253	u16 param_val;		/* New val of last param modified */
 254
 255	u8 write_config_counter;	/* write config occurred */
 256	u8 write_config_rsvd[3];
 257
 258	u8 ldrv_op_counter;	/* Indicates ldrv op started/completed */
 259	u8 ldrv_opid;		/* ldrv num */
 260	u8 ldrv_opcmd;		/* ldrv operation - defined below */
 261	u8 ldrv_opstatus;	/* status of the operation */
 262
 263	u8 ldrv_state_counter;	/* Indicates change of ldrv state */
 264	u8 ldrv_state_id;		/* ldrv num */
 265	u8 ldrv_state_new;	/* New state */
 266	u8 ldrv_state_old;	/* old state */
 267
 268	u8 pdrv_state_counter;	/* Indicates change of ldrv state */
 269	u8 pdrv_state_id;		/* pdrv id */
 270	u8 pdrv_state_new;	/* New state */
 271	u8 pdrv_state_old;	/* old state */
 272
 273	u8 pdrv_fmt_counter;	/* Indicates pdrv format started/over */
 274	u8 pdrv_fmt_id;		/* pdrv id */
 275	u8 pdrv_fmt_val;		/* format started/over */
 276	u8 pdrv_fmt_rsvd;
 277
 278	u8 targ_xfer_counter;	/* Indicates SCSI-2 Xfer rate change */
 279	u8 targ_xfer_id;	/* pdrv Id  */
 280	u8 targ_xfer_val;		/* new Xfer params of last pdrv */
 281	u8 targ_xfer_rsvd;
 282
 283	u8 fcloop_id_chg_counter;	/* Indicates loopid changed */
 284	u8 fcloopid_pdrvid;		/* pdrv id */
 285	u8 fcloop_id0;			/* loopid on fc loop 0 */
 286	u8 fcloop_id1;			/* loopid on fc loop 1 */
 287
 288	u8 fcloop_state_counter;	/* Indicates loop state changed */
 289	u8 fcloop_state0;		/* state of fc loop 0 */
 290	u8 fcloop_state1;		/* state of fc loop 1 */
 291	u8 fcloop_state_rsvd;
 292} __attribute__ ((packed));
 293
 294#define MAX_NOTIFY_SIZE     0x80
 295#define CUR_NOTIFY_SIZE     sizeof(struct notify)
 296
 297typedef struct {
 298	u32	data_size; /* current size in bytes (not including resvd) */
 299
 300	struct notify notify;
 301
 302	u8	notify_rsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
 303
 304	u8	rebuild_rate;		/* Rebuild rate (0% - 100%) */
 305	u8	cache_flush_interval;	/* In terms of Seconds */
 306	u8	sense_alert;
 307	u8	drive_insert_count;	/* drive insertion count */
 308
 309	u8	battery_status;
 310	u8	num_ldrv;		/* No. of Log Drives configured */
 311	u8	recon_state[MAX_LOGICAL_DRIVES_40LD / 8];	/* State of
 312							   reconstruct */
 313	u16	ldrv_op_status[MAX_LOGICAL_DRIVES_40LD / 8]; /* logdrv
 314								 Status */
 315
 316	u32	ldrv_size[MAX_LOGICAL_DRIVES_40LD];/* Size of each log drv */
 317	u8	ldrv_prop[MAX_LOGICAL_DRIVES_40LD];
 318	u8	ldrv_state[MAX_LOGICAL_DRIVES_40LD];/* State of log drives */
 319	u8	pdrv_state[FC_MAX_PHYSICAL_DEVICES];/* State of phys drvs. */
 320	u16	pdrv_format[FC_MAX_PHYSICAL_DEVICES / 16];
 321
 322	u8	targ_xfer[80];	/* phys device transfer rate */
 323	u8	pad1k[263];	/* 761 + 263reserved = 1024 bytes total size */
 324} __attribute__ ((packed)) mega_inquiry3;
 325
 326
 327/* Structures */
 328typedef struct {
 329	u8	max_commands;	/* Max concurrent commands supported */
 330	u8	rebuild_rate;	/* Rebuild rate - 0% thru 100% */
 331	u8	max_targ_per_chan;	/* Max targ per channel */
 332	u8	nchannels;	/* Number of channels on HBA */
 333	u8	fw_version[4];	/* Firmware version */
 334	u16	age_of_flash;	/* Number of times FW has been flashed */
 335	u8	chip_set_value;	/* Contents of 0xC0000832 */
 336	u8	dram_size;	/* In MB */
 337	u8	cache_flush_interval;	/* in seconds */
 338	u8	bios_version[4];
 339	u8	board_type;
 340	u8	sense_alert;
 341	u8	write_config_count;	/* Increase with every configuration
 342					   change */
 343	u8	drive_inserted_count;	/* Increase with every drive inserted
 344					 */
 345	u8	inserted_drive;	/* Channel:Id of inserted drive */
 346	u8	battery_status;	/*
 347				 * BIT 0: battery module missing
 348				 * BIT 1: VBAD
 349				 * BIT 2: temperature high
 350				 * BIT 3: battery pack missing
 351				 * BIT 4,5:
 352				 *   00 - charge complete
 353				 *   01 - fast charge in progress
 354				 *   10 - fast charge fail
 355				 *   11 - undefined
 356				 * Bit 6: counter > 1000
 357				 * Bit 7: Undefined
 358				 */
 359	u8	dec_fault_bus_info;
 360} __attribute__ ((packed)) mega_adp_info;
 361
 362
 363typedef struct {
 364	u8	num_ldrv;	/* Number of logical drives configured */
 365	u8	rsvd[3];
 366	u32	ldrv_size[MAX_LOGICAL_DRIVES_8LD];
 367	u8	ldrv_prop[MAX_LOGICAL_DRIVES_8LD];
 368	u8	ldrv_state[MAX_LOGICAL_DRIVES_8LD];
 369} __attribute__ ((packed)) mega_ldrv_info;
 370
 371typedef struct {
 372	u8	pdrv_state[MAX_PHYSICAL_DRIVES];
 373	u8	rsvd;
 374} __attribute__ ((packed)) mega_pdrv_info;
 375
 376/* RAID inquiry: Mailbox command 0x05*/
 377typedef struct {
 378	mega_adp_info	adapter_info;
 379	mega_ldrv_info	logdrv_info;
 380	mega_pdrv_info	pdrv_info;
 381} __attribute__ ((packed)) mraid_inquiry;
 382
 383
 384/* RAID extended inquiry: Mailbox command 0x04*/
 385typedef struct {
 386	mraid_inquiry	raid_inq;
 387	u16	phys_drv_format[MAX_CHANNELS];
 388	u8	stack_attn;
 389	u8	modem_status;
 390	u8	rsvd[2];
 391} __attribute__ ((packed)) mraid_ext_inquiry;
 392
 393
 394typedef struct {
 395	u8	channel;
 396	u8	target;
 397}__attribute__ ((packed)) adp_device;
 398
 399typedef struct {
 400	u32		start_blk;	/* starting block */
 401	u32		num_blks;	/* # of blocks */
 402	adp_device	device[MAX_ROW_SIZE_40LD];
 403}__attribute__ ((packed)) adp_span_40ld;
 404
 405typedef struct {
 406	u32		start_blk;	/* starting block */
 407	u32		num_blks;	/* # of blocks */
 408	adp_device	device[MAX_ROW_SIZE_8LD];
 409}__attribute__ ((packed)) adp_span_8ld;
 410
 411typedef struct {
 412	u8	span_depth;	/* Total # of spans */
 413	u8	level;		/* RAID level */
 414	u8	read_ahead;	/* read ahead, no read ahead, adaptive read
 415				   ahead */
 416	u8	stripe_sz;	/* Encoded stripe size */
 417	u8	status;		/* Status of the logical drive */
 418	u8	write_mode;	/* write mode, write_through/write_back */
 419	u8	direct_io;	/* direct io or through cache */
 420	u8	row_size;	/* Number of stripes in a row */
 421} __attribute__ ((packed)) logdrv_param;
 422
 423typedef struct {
 424	logdrv_param	lparam;
 425	adp_span_40ld	span[MAX_SPAN_DEPTH];
 426}__attribute__ ((packed)) logdrv_40ld;
 427
 428typedef struct {
 429	logdrv_param	lparam;
 430	adp_span_8ld	span[MAX_SPAN_DEPTH];
 431}__attribute__ ((packed)) logdrv_8ld;
 432
 433typedef struct {
 434	u8	type;		/* Type of the device */
 435	u8	cur_status;	/* current status of the device */
 436	u8	tag_depth;	/* Level of tagging */
 437	u8	sync_neg;	/* sync negotiation - ENABLE or DISABLE */
 438	u32	size;		/* configurable size in terms of 512 byte
 439				   blocks */
 440}__attribute__ ((packed)) phys_drv;
 441
 442typedef struct {
 443	u8		nlog_drives;		/* number of logical drives */
 444	u8		resvd[3];
 445	logdrv_40ld	ldrv[MAX_LOGICAL_DRIVES_40LD];
 446	phys_drv	pdrv[MAX_PHYSICAL_DRIVES];
 447}__attribute__ ((packed)) disk_array_40ld;
 448
 449typedef struct {
 450	u8		nlog_drives;	/* number of logical drives */
 451	u8		resvd[3];
 452	logdrv_8ld	ldrv[MAX_LOGICAL_DRIVES_8LD];
 453	phys_drv	pdrv[MAX_PHYSICAL_DRIVES];
 454}__attribute__ ((packed)) disk_array_8ld;
 455
 456
 457/*
 458 * User ioctl structure.
 459 * This structure will be used for Traditional Method ioctl interface
 460 * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
 461 * Driver ioctls.
 462 * The Driver ioctl interface handles the commands at the driver level,
 463 * without being sent to the card.
 464 */
 465/* system call imposed limit. Change accordingly */
 466#define IOCTL_MAX_DATALEN       4096
 467
 468struct uioctl_t {
 469	u32 inlen;
 470	u32 outlen;
 471	union {
 472		u8 fca[16];
 473		struct {
 474			u8 opcode;
 475			u8 subopcode;
 476			u16 adapno;
 477#if BITS_PER_LONG == 32
 478			u8 *buffer;
 479			u8 pad[4];
 480#endif
 481#if BITS_PER_LONG == 64
 482			u8 *buffer;
 483#endif
 484			u32 length;
 485		} __attribute__ ((packed)) fcs;
 486	} __attribute__ ((packed)) ui;
 487	u8 mbox[18];		/* 16 bytes + 2 status bytes */
 488	mega_passthru pthru;
 489#if BITS_PER_LONG == 32
 490	char __user *data;		/* buffer <= 4096 for 0x80 commands */
 491	char pad[4];
 492#endif
 493#if BITS_PER_LONG == 64
 494	char __user *data;
 495#endif
 496} __attribute__ ((packed));
 497
 498/*
 499 * struct mcontroller is used to pass information about the controllers in the
 500 * system. Its up to the application how to use the information. We are passing
 501 * as much info about the cards as possible and useful. Before issuing the
 502 * call to find information about the cards, the application needs to issue a
 503 * ioctl first to find out the number of controllers in the system.
 504 */
 505#define MAX_CONTROLLERS 32
 506
 507struct mcontroller {
 508	u64 base;
 509	u8 irq;
 510	u8 numldrv;
 511	u8 pcibus;
 512	u16 pcidev;
 513	u8 pcifun;
 514	u16 pciid;
 515	u16 pcivendor;
 516	u8 pcislot;
 517	u32 uid;
 518};
 519
 520/*
 521 * mailbox structure used for internal commands
 522 */
 523typedef struct {
 524	u8	cmd;
 525	u8	cmdid;
 526	u8	opcode;
 527	u8	subopcode;
 528	u32	lba;
 529	u32	xferaddr;
 530	u8	logdrv;
 531	u8	rsvd[3];
 532	u8	numstatus;
 533	u8	status;
 534} __attribute__ ((packed)) megacmd_t;
 535
 536/*
 537 * Defines for Driver IOCTL interface
 538 */
 539#define MEGAIOC_MAGIC  	'm'
 540
 541#define MEGAIOC_QNADAP		'm'	/* Query # of adapters */
 542#define MEGAIOC_QDRVRVER	'e'	/* Query driver version */
 543#define MEGAIOC_QADAPINFO   	'g'	/* Query adapter information */
 544#define MKADAP(adapno)	  	(MEGAIOC_MAGIC << 8 | (adapno) )
 545#define GETADAP(mkadap)	 	( (mkadap) ^ MEGAIOC_MAGIC << 8 )
 546
 547/*
 548 * Definition for the new ioctl interface (NIT)
 549 */
 550
 551/*
 552 * Vendor specific Group-7 commands
 553 */
 554#define VENDOR_SPECIFIC_COMMANDS	0xE0
 555#define MEGA_INTERNAL_CMD		VENDOR_SPECIFIC_COMMANDS + 0x01
 556
 557/*
 558 * The ioctl command. No other command shall be used for this interface
 559 */
 560#define USCSICMD	VENDOR_SPECIFIC_COMMANDS
 561
 562/*
 563 * Data direction flags
 564 */
 565#define UIOC_RD		0x00001
 566#define UIOC_WR		0x00002
 567
 568/*
 569 * ioctl opcodes
 570 */
 571#define MBOX_CMD	0x00000	/* DCMD or passthru command */
 572#define GET_DRIVER_VER	0x10000	/* Get driver version */
 573#define GET_N_ADAP	0x20000	/* Get number of adapters */
 574#define GET_ADAP_INFO	0x30000	/* Get information about a adapter */
 575#define GET_CAP		0x40000	/* Get ioctl capabilities */
 576#define GET_STATS	0x50000	/* Get statistics, including error info */
 577
 578
 579/*
 580 * The ioctl structure.
 581 * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
 582 * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
 583 */
 584typedef struct {
 585	char		signature[8];	/* Must contain "MEGANIT" */
 586	u32		opcode;		/* opcode for the command */
 587	u32		adapno;		/* adapter number */
 588	union {
 589		u8	__raw_mbox[18];
 590		void __user *__uaddr; /* xferaddr for non-mbox cmds */
 591	}__ua;
 592
 593#define uioc_rmbox	__ua.__raw_mbox
 594#define MBOX(uioc)	((megacmd_t *)&((uioc).__ua.__raw_mbox[0]))
 595#define MBOX_P(uioc)	((megacmd_t __user *)&((uioc)->__ua.__raw_mbox[0]))
 596#define uioc_uaddr	__ua.__uaddr
 597
 598	u32		xferlen;	/* xferlen for DCMD and non-mbox
 599					   commands */
 600	u32		flags;		/* data direction flags */
 601}nitioctl_t;
 602
 603
 604/*
 605 * I/O statistics for some applications like SNMP agent. The caller must
 606 * provide the number of logical drives for which status should be reported.
 607 */
 608typedef struct {
 609	int	num_ldrv;	/* Number for logical drives for which the
 610				   status should be reported. */
 611	u32	nreads[MAX_LOGICAL_DRIVES_40LD];	/* number of reads for
 612							each logical drive */
 613	u32	nreadblocks[MAX_LOGICAL_DRIVES_40LD];	/* number of blocks
 614							read for each logical
 615							drive */
 616	u32	nwrites[MAX_LOGICAL_DRIVES_40LD];	/* number of writes
 617							for each logical
 618							drive */
 619	u32	nwriteblocks[MAX_LOGICAL_DRIVES_40LD];	/* number of blocks
 620							writes for each
 621							logical drive */
 622	u32	rd_errors[MAX_LOGICAL_DRIVES_40LD];	/* number of read
 623							   errors for each
 624							   logical drive */
 625	u32	wr_errors[MAX_LOGICAL_DRIVES_40LD];	/* number of write
 626							   errors for each
 627							   logical drive */
 628}megastat_t;
 629
 630
 631struct private_bios_data {
 632	u8	geometry:4;	/*
 633				 * bits 0-3 - BIOS geometry
 634				 * 0x0001 - 1GB
 635				 * 0x0010 - 2GB
 636				 * 0x1000 - 8GB
 637				 * Others values are invalid
 638							 */
 639	u8	unused:4;	/* bits 4-7 are unused */
 640	u8	boot_drv;	/*
 641				 * logical drive set as boot drive
 642				 * 0..7 - for 8LD cards
 643				 * 0..39 - for 40LD cards
 644				 */
 645	u8	rsvd[12];
 646	u16	cksum;	/* 0-(sum of first 13 bytes of this structure) */
 647} __attribute__ ((packed));
 648
 649
 650
 651
 652/*
 653 * Mailbox and firmware commands and subopcodes used in this driver.
 654 */
 655
 656#define MEGA_MBOXCMD_LREAD	0x01
 657#define MEGA_MBOXCMD_LWRITE	0x02
 658#define MEGA_MBOXCMD_PASSTHRU	0x03
 659#define MEGA_MBOXCMD_ADPEXTINQ	0x04
 660#define MEGA_MBOXCMD_ADAPTERINQ	0x05
 661#define MEGA_MBOXCMD_LREAD64	0xA7
 662#define MEGA_MBOXCMD_LWRITE64	0xA8
 663#define MEGA_MBOXCMD_PASSTHRU64	0xC3
 664#define MEGA_MBOXCMD_EXTPTHRU	0xE3
 665
 666#define MAIN_MISC_OPCODE	0xA4	/* f/w misc opcode */
 667#define GET_MAX_SG_SUPPORT	0x01	/* get max sg len supported by f/w */
 668
 669#define FC_NEW_CONFIG		0xA1
 670#define NC_SUBOP_PRODUCT_INFO	0x0E
 671#define NC_SUBOP_ENQUIRY3	0x0F
 672#define ENQ3_GET_SOLICITED_FULL	0x02
 673#define OP_DCMD_READ_CONFIG	0x04
 674#define NEW_READ_CONFIG_8LD	0x67
 675#define READ_CONFIG_8LD		0x07
 676#define FLUSH_ADAPTER		0x0A
 677#define FLUSH_SYSTEM		0xFE
 678
 679/*
 680 * Command for random deletion of logical drives
 681 */
 682#define	FC_DEL_LOGDRV		0xA4	/* f/w command */
 683#define	OP_SUP_DEL_LOGDRV	0x2A	/* is feature supported */
 684#define OP_GET_LDID_MAP		0x18	/* get ldid and logdrv number map */
 685#define OP_DEL_LOGDRV		0x1C	/* delete logical drive */
 686
 687/*
 688 * BIOS commands
 689 */
 690#define IS_BIOS_ENABLED		0x62
 691#define GET_BIOS		0x01
 692#define CHNL_CLASS		0xA9
 693#define GET_CHNL_CLASS		0x00
 694#define SET_CHNL_CLASS		0x01
 695#define CH_RAID			0x01
 696#define CH_SCSI			0x00
 697#define BIOS_PVT_DATA		0x40
 698#define GET_BIOS_PVT_DATA	0x00
 699
 700
 701/*
 702 * Commands to support clustering
 703 */
 704#define MEGA_GET_TARGET_ID	0x7D
 705#define MEGA_CLUSTER_OP		0x70
 706#define MEGA_GET_CLUSTER_MODE	0x02
 707#define MEGA_CLUSTER_CMD	0x6E
 708#define MEGA_RESERVE_LD		0x01
 709#define MEGA_RELEASE_LD		0x02
 710#define MEGA_RESET_RESERVATIONS	0x03
 711#define MEGA_RESERVATION_STATUS	0x04
 712#define MEGA_RESERVE_PD		0x05
 713#define MEGA_RELEASE_PD		0x06
 714
 715
 716/*
 717 * Module battery status
 718 */
 719#define MEGA_BATT_MODULE_MISSING	0x01
 720#define MEGA_BATT_LOW_VOLTAGE		0x02
 721#define MEGA_BATT_TEMP_HIGH		0x04
 722#define MEGA_BATT_PACK_MISSING		0x08
 723#define MEGA_BATT_CHARGE_MASK		0x30
 724#define MEGA_BATT_CHARGE_DONE		0x00
 725#define MEGA_BATT_CHARGE_INPROG		0x10
 726#define MEGA_BATT_CHARGE_FAIL		0x20
 727#define MEGA_BATT_CYCLES_EXCEEDED	0x40
 728
 729/*
 730 * Physical drive states.
 731 */
 732#define PDRV_UNCNF	0
 733#define PDRV_ONLINE	3
 734#define PDRV_FAILED	4
 735#define PDRV_RBLD	5
 736#define PDRV_HOTSPARE	6
 737
 738
 739/*
 740 * Raid logical drive states.
 741 */
 742#define RDRV_OFFLINE	0
 743#define RDRV_DEGRADED	1
 744#define RDRV_OPTIMAL	2
 745#define RDRV_DELETED	3
 746
 747/*
 748 * Read, write and cache policies
 749 */
 750#define NO_READ_AHEAD		0
 751#define READ_AHEAD		1
 752#define ADAP_READ_AHEAD		2
 753#define WRMODE_WRITE_THRU	0
 754#define WRMODE_WRITE_BACK	1
 755#define CACHED_IO		0
 756#define DIRECT_IO		1
 757
 758
 759#define SCSI_LIST(scp) ((struct list_head *)(&(scp)->SCp))
 760
 761/*
 762 * Each controller's soft state
 763 */
 764typedef struct {
 765	int	this_id;	/* our id, may set to different than 7 if
 766				   clustering is available */
 767	u32	flag;
 768
 769	unsigned long		base;
 770	void __iomem		*mmio_base;
 771
 772	/* mbox64 with mbox not aligned on 16-byte boundary */
 773	mbox64_t	*una_mbox64;
 774	dma_addr_t	una_mbox64_dma;
 775
 776	volatile mbox64_t	*mbox64;/* ptr to 64-bit mailbox */
 777	volatile mbox_t		*mbox;	/* ptr to standard mailbox */
 778	dma_addr_t		mbox_dma;
 779
 780	struct pci_dev	*dev;
 781
 782	struct list_head	free_list;
 783	struct list_head	pending_list;
 784	struct list_head	completed_list;
 785
 786	struct Scsi_Host	*host;
 787
 788#define MEGA_BUFFER_SIZE (2*1024)
 789	u8		*mega_buffer;
 790	dma_addr_t	buf_dma_handle;
 791
 792	mega_product_info	product_info;
 793
 794	u8		max_cmds;
 795	scb_t		*scb_list;
 796
 797	atomic_t	pend_cmds;	/* maintain a counter for pending
 798					   commands in firmware */
 799
 800#if MEGA_HAVE_STATS
 801	u32	nreads[MAX_LOGICAL_DRIVES_40LD];
 802	u32	nreadblocks[MAX_LOGICAL_DRIVES_40LD];
 803	u32	nwrites[MAX_LOGICAL_DRIVES_40LD];
 804	u32	nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
 805	u32	rd_errors[MAX_LOGICAL_DRIVES_40LD];
 806	u32	wr_errors[MAX_LOGICAL_DRIVES_40LD];
 807#endif
 808
 809	/* Host adapter parameters */
 810	u8	numldrv;
 811	u8	fw_version[7];
 812	u8	bios_version[7];
 813
 814#ifdef CONFIG_PROC_FS
 815	struct proc_dir_entry	*controller_proc_dir_entry;
 816	struct proc_dir_entry	*proc_read;
 817	struct proc_dir_entry	*proc_stat;
 818	struct proc_dir_entry	*proc_mbox;
 819
 820#if MEGA_HAVE_ENH_PROC
 821	struct proc_dir_entry	*proc_rr;
 822	struct proc_dir_entry	*proc_battery;
 823#define MAX_PROC_CHANNELS	4
 824	struct proc_dir_entry	*proc_pdrvstat[MAX_PROC_CHANNELS];
 825	struct proc_dir_entry	*proc_rdrvstat[MAX_PROC_CHANNELS];
 826#endif
 827
 828#endif
 829
 830	int	has_64bit_addr;		/* are we using 64-bit addressing */
 831	int	support_ext_cdb;
 832	int	boot_ldrv_enabled;
 833	int	boot_ldrv;
 834	int	boot_pdrv_enabled;	/* boot from physical drive */
 835	int	boot_pdrv_ch;		/* boot physical drive channel */
 836	int	boot_pdrv_tgt;		/* boot physical drive target */
 837
 838
 839	int	support_random_del;	/* Do we support random deletion of
 840					   logdrvs */
 841	int	read_ldidmap;	/* set after logical drive deltion. The
 842				   logical drive number must be read from the
 843				   map */
 844	atomic_t	quiescent;	/* a stage reached when delete logical
 845					   drive needs to be done. Stop
 846					   sending requests to the hba till
 847					   delete operation is completed */
 848	spinlock_t	lock;
 849
 850	u8	logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
 851							what channels. */
 852	int	mega_ch_class;
 853
 854	u8	sglen;	/* f/w supported scatter-gather list length */
 855
 
 856	scb_t			int_scb;
 857	struct mutex		int_mtx;	/* To synchronize the internal
 858						commands */
 859	int			int_status;	/* status of internal cmd */
 860	struct completion	int_waitq;	/* wait queue for internal
 861						 cmds */
 862
 863	int	has_cluster;	/* cluster support on this HBA */
 864}adapter_t;
 865
 866
 867struct mega_hbas {
 868	int is_bios_enabled;
 869	adapter_t *hostdata_addr;
 870};
 871
 872
 873/*
 874 * For state flag. Do not use LSB(8 bits) which are
 875 * reserved for storing info about channels.
 876 */
 877#define IN_ABORT	0x80000000L
 878#define IN_RESET	0x40000000L
 879#define BOARD_MEMMAP	0x20000000L
 880#define BOARD_IOMAP	0x10000000L
 881#define BOARD_40LD   	0x08000000L
 882#define BOARD_64BIT	0x04000000L
 883
 884#define INTR_VALID			0x40
 885
 886#define PCI_CONF_AMISIG			0xa0
 887#define PCI_CONF_AMISIG64		0xa4
 888
 889
 890#define MEGA_DMA_TYPE_NONE		0xFFFF
 891#define MEGA_BULK_DATA			0x0001
 892#define MEGA_SGLIST			0x0002
 893
 894/*
 895 * Parameters for the io-mapped controllers
 896 */
 897
 898/* I/O Port offsets */
 899#define CMD_PORT	 	0x00
 900#define ACK_PORT	 	0x00
 901#define TOGGLE_PORT		0x01
 902#define INTR_PORT	  	0x0a
 903
 904#define MBOX_BUSY_PORT     	0x00
 905#define MBOX_PORT0	 	0x04
 906#define MBOX_PORT1	 	0x05
 907#define MBOX_PORT2	 	0x06
 908#define MBOX_PORT3	 	0x07
 909#define ENABLE_MBOX_REGION 	0x0B
 910
 911/* I/O Port Values */
 912#define ISSUE_BYTE	 	0x10
 913#define ACK_BYTE	   	0x08
 914#define ENABLE_INTR_BYTE   	0xc0
 915#define DISABLE_INTR_BYTE  	0x00
 916#define VALID_INTR_BYTE    	0x40
 917#define MBOX_BUSY_BYTE     	0x10
 918#define ENABLE_MBOX_BYTE   	0x00
 919
 920
 921/* Setup some port macros here */
 922#define issue_command(adapter)	\
 923		outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
 924
 925#define irq_state(adapter)	inb_p((adapter)->base + INTR_PORT)
 926
 927#define set_irq_state(adapter, value)	\
 928		outb_p((value), (adapter)->base + INTR_PORT)
 929
 930#define irq_ack(adapter)	\
 931		outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
 932
 933#define irq_enable(adapter)	\
 934	outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
 935
 936#define irq_disable(adapter)	\
 937	outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
 938
 939
 940/*
 941 * This is our SYSDEP area. All kernel specific detail should be placed here -
 942 * as much as possible
 943 */
 944
 945/*
 946 * End of SYSDEP area
 947 */
 948
 949const char *megaraid_info (struct Scsi_Host *);
 950
 951static int mega_query_adapter(adapter_t *);
 952static int issue_scb(adapter_t *, scb_t *);
 953static int mega_setup_mailbox(adapter_t *);
 954
 955static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
 956static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
 957static void __mega_runpendq(adapter_t *);
 958static int issue_scb_block(adapter_t *, u_char *);
 959
 960static irqreturn_t megaraid_isr_memmapped(int, void *);
 961static irqreturn_t megaraid_isr_iomapped(int, void *);
 962
 963static void mega_free_scb(adapter_t *, scb_t *);
 964
 965static int megaraid_abort(Scsi_Cmnd *);
 966static int megaraid_reset(Scsi_Cmnd *);
 967static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int);
 968static int megaraid_biosparam(struct scsi_device *, struct block_device *,
 969		sector_t, int []);
 970
 971static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
 972			      u32 *buffer, u32 *length);
 973static int __mega_busywait_mbox (adapter_t *);
 974static void mega_rundoneq (adapter_t *);
 975static void mega_cmd_done(adapter_t *, u8 [], int, int);
 976static inline void mega_free_sgl (adapter_t *adapter);
 977static void mega_8_to_40ld (mraid_inquiry *inquiry,
 978		mega_inquiry3 *enquiry3, mega_product_info *);
 979
 980static int megadev_open (struct inode *, struct file *);
 981static int megadev_ioctl (struct file *, unsigned int, unsigned long);
 982static int mega_m_to_n(void __user *, nitioctl_t *);
 983static int mega_n_to_m(void __user *, megacmd_t *);
 984
 985static int mega_init_scb (adapter_t *);
 986
 987static int mega_is_bios_enabled (adapter_t *);
 988
 989#ifdef CONFIG_PROC_FS
 
 990static void mega_create_proc_entry(int, struct proc_dir_entry *);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 991static int mega_adapinq(adapter_t *, dma_addr_t);
 992static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
 993#endif
 994
 995static int mega_support_ext_cdb(adapter_t *);
 996static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
 997		Scsi_Cmnd *, int, int);
 998static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
 999		scb_t *, Scsi_Cmnd *, int, int);
1000static void mega_enum_raid_scsi(adapter_t *);
1001static void mega_get_boot_drv(adapter_t *);
1002static int mega_support_random_del(adapter_t *);
1003static int mega_del_logdrv(adapter_t *, int);
1004static int mega_do_del_logdrv(adapter_t *, int);
1005static void mega_get_max_sgl(adapter_t *);
1006static int mega_internal_command(adapter_t *, megacmd_t *, mega_passthru *);
 
1007static int mega_support_cluster(adapter_t *);
1008#endif
1009
1010/* vi: set ts=8 sw=8 tw=78: */