linux/drivers/scsi/megaraid.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __MEGARAID_H__
#define __MEGARAID_H__

#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <scsi/scsi_cmnd.h>

#define MEGARAID_VERSION

/*
 * Driver features - change the values to enable or disable features in the
 * driver.
 */

/*
 * Command coalescing - This feature allows the driver to be able to combine
 * two or more commands and issue as one command in order to boost I/O
 * performance. Useful if the nature of the I/O is sequential. It is not very
 * useful for random natured I/Os.
 */
#define MEGA_HAVE_COALESCING

/*
 * Clustering support - Set this flag if you are planning to use the
 * clustering services provided by the megaraid controllers and planning to
 * setup a cluster
 */
#define MEGA_HAVE_CLUSTERING

/*
 * Driver statistics - Set this flag if you are interested in statics about
 * number of I/O completed on each logical drive and how many interrupts
 * generated. If enabled, this information is available through /proc
 * interface and through the private ioctl. Setting this flag has a
 * performance penalty.
 */
#define MEGA_HAVE_STATS

/*
 * Enhanced /proc interface - This feature will allow you to have a more
 * detailed /proc interface for megaraid driver. E.g., a real time update of
 * the status of the logical drives, battery status, physical drives etc.
 */
#define MEGA_HAVE_ENH_PROC

#define MAX_DEV_TYPE

#define PCI_DEVICE_ID_DISCOVERY
#define PCI_DEVICE_ID_PERC4_DI
#define PCI_DEVICE_ID_PERC4_QC_VERDE

#define HBA_SIGNATURE
#define HBA_SIGNATURE_471
#define HBA_SIGNATURE_64BIT

#define MBOX_BUSY_WAIT
#define DEFAULT_INITIATOR_ID

#define MAX_SGLIST
#define MIN_SGLIST
#define MAX_COMMANDS
#define CMDID_INT_CMDS

#define MAX_CDB_LEN
#define MAX_EXT_CDB_LEN

#define DEF_CMD_PER_LUN
#define MAX_CMD_PER_LUN
#define MAX_FIRMWARE_STATUS
#define MAX_XFER_PER_CMD
#define MAX_SECTORS_PER_IO

#define MAX_LOGICAL_DRIVES_40LD
#define FC_MAX_PHYSICAL_DEVICES
#define MAX_LOGICAL_DRIVES_8LD
#define MAX_CHANNELS
#define MAX_TARGET
#define MAX_PHYSICAL_DRIVES
#define MAX_ROW_SIZE_40LD
#define MAX_ROW_SIZE_8LD
#define MAX_SPAN_DEPTH

#define NVIRT_CHAN
struct mbox_out {} __attribute__ ((packed));

struct mbox_in {} __attribute__ ((packed));

mbox_t;

mbox64_t;


/*
 * Passthru definitions
 */
#define MAX_REQ_SENSE_LEN

mega_passthru;


/*
 * Extended passthru: support CDB > 10 bytes
 */
mega_ext_passthru;

mega_sgl64;

mega_sglist;


/* Queued command data */
scb_t;

/*
 * Flags to follow the scb as it transitions between various stages
 */
#define SCB_FREE
#define SCB_ACTIVE
#define SCB_PENDQ
#define SCB_ISSUED
#define SCB_ABORT
#define SCB_RESET

/*
 * Utilities declare this strcture size as 1024 bytes. So more fields can
 * be added in future.
 */
mega_product_info;

struct notify {} __attribute__ ((packed));

#define MAX_NOTIFY_SIZE
#define CUR_NOTIFY_SIZE

mega_inquiry3;


/* Structures */
mega_adp_info;


mega_ldrv_info;

mega_pdrv_info;

/* RAID inquiry: Mailbox command 0x05*/
mraid_inquiry;


/* RAID extended inquiry: Mailbox command 0x04*/
mraid_ext_inquiry;


adp_device;

adp_span_40ld;

adp_span_8ld;

logdrv_param;

logdrv_40ld;

logdrv_8ld;

phys_drv;

disk_array_40ld;

disk_array_8ld;


/*
 * User ioctl structure.
 * This structure will be used for Traditional Method ioctl interface
 * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
 * Driver ioctls.
 * The Driver ioctl interface handles the commands at the driver level,
 * without being sent to the card.
 */
/* system call imposed limit. Change accordingly */
#define IOCTL_MAX_DATALEN

struct uioctl_t {} __attribute__ ((packed));

/*
 * struct mcontroller is used to pass information about the controllers in the
 * system. Its up to the application how to use the information. We are passing
 * as much info about the cards as possible and useful. Before issuing the
 * call to find information about the cards, the application needs to issue a
 * ioctl first to find out the number of controllers in the system.
 */
#define MAX_CONTROLLERS

struct mcontroller {};

/*
 * mailbox structure used for internal commands
 */
megacmd_t;

/*
 * Defines for Driver IOCTL interface
 */
#define MEGAIOC_MAGIC

#define MEGAIOC_QNADAP
#define MEGAIOC_QDRVRVER
#define MEGAIOC_QADAPINFO
#define MKADAP(adapno)
#define GETADAP(mkadap)

/*
 * Definition for the new ioctl interface (NIT)
 */

/*
 * Vendor specific Group-7 commands
 */
#define VENDOR_SPECIFIC_COMMANDS
#define MEGA_INTERNAL_CMD

/*
 * The ioctl command. No other command shall be used for this interface
 */
#define USCSICMD

/*
 * Data direction flags
 */
#define UIOC_RD
#define UIOC_WR

/*
 * ioctl opcodes
 */
#define MBOX_CMD
#define GET_DRIVER_VER
#define GET_N_ADAP
#define GET_ADAP_INFO
#define GET_CAP
#define GET_STATS


/*
 * The ioctl structure.
 * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
 * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
 */
nitioctl_t;


/*
 * I/O statistics for some applications like SNMP agent. The caller must
 * provide the number of logical drives for which status should be reported.
 */
megastat_t;


struct private_bios_data {} __attribute__ ((packed));




/*
 * Mailbox and firmware commands and subopcodes used in this driver.
 */

#define MEGA_MBOXCMD_LREAD
#define MEGA_MBOXCMD_LWRITE
#define MEGA_MBOXCMD_PASSTHRU
#define MEGA_MBOXCMD_ADPEXTINQ
#define MEGA_MBOXCMD_ADAPTERINQ
#define MEGA_MBOXCMD_LREAD64
#define MEGA_MBOXCMD_LWRITE64
#define MEGA_MBOXCMD_PASSTHRU64
#define MEGA_MBOXCMD_EXTPTHRU

#define MAIN_MISC_OPCODE
#define GET_MAX_SG_SUPPORT

#define FC_NEW_CONFIG
#define NC_SUBOP_PRODUCT_INFO
#define NC_SUBOP_ENQUIRY3
#define ENQ3_GET_SOLICITED_FULL
#define OP_DCMD_READ_CONFIG
#define NEW_READ_CONFIG_8LD
#define READ_CONFIG_8LD
#define FLUSH_ADAPTER
#define FLUSH_SYSTEM

/*
 * Command for random deletion of logical drives
 */
#define FC_DEL_LOGDRV
#define OP_SUP_DEL_LOGDRV
#define OP_GET_LDID_MAP
#define OP_DEL_LOGDRV

/*
 * BIOS commands
 */
#define IS_BIOS_ENABLED
#define GET_BIOS
#define CHNL_CLASS
#define GET_CHNL_CLASS
#define SET_CHNL_CLASS
#define CH_RAID
#define CH_SCSI
#define BIOS_PVT_DATA
#define GET_BIOS_PVT_DATA


/*
 * Commands to support clustering
 */
#define MEGA_GET_TARGET_ID
#define MEGA_CLUSTER_OP
#define MEGA_GET_CLUSTER_MODE
#define MEGA_CLUSTER_CMD
#define MEGA_RESERVE_LD
#define MEGA_RELEASE_LD
#define MEGA_RESET_RESERVATIONS
#define MEGA_RESERVATION_STATUS
#define MEGA_RESERVE_PD
#define MEGA_RELEASE_PD


/*
 * Module battery status
 */
#define MEGA_BATT_MODULE_MISSING
#define MEGA_BATT_LOW_VOLTAGE
#define MEGA_BATT_TEMP_HIGH
#define MEGA_BATT_PACK_MISSING
#define MEGA_BATT_CHARGE_MASK
#define MEGA_BATT_CHARGE_DONE
#define MEGA_BATT_CHARGE_INPROG
#define MEGA_BATT_CHARGE_FAIL
#define MEGA_BATT_CYCLES_EXCEEDED

/*
 * Physical drive states.
 */
#define PDRV_UNCNF
#define PDRV_ONLINE
#define PDRV_FAILED
#define PDRV_RBLD
#define PDRV_HOTSPARE


/*
 * Raid logical drive states.
 */
#define RDRV_OFFLINE
#define RDRV_DEGRADED
#define RDRV_OPTIMAL
#define RDRV_DELETED

/*
 * Read, write and cache policies
 */
#define NO_READ_AHEAD
#define READ_AHEAD
#define ADAP_READ_AHEAD
#define WRMODE_WRITE_THRU
#define WRMODE_WRITE_BACK
#define CACHED_IO
#define DIRECT_IO

struct megaraid_cmd_priv {};

#define SCSI_LIST(scp)

struct scsi_cmd_and_priv {};

static inline struct scsi_cmnd *
megaraid_to_scsi_cmd(struct megaraid_cmd_priv *cmd_priv)
{}

/*
 * Each controller's soft state
 */
adapter_t;


struct mega_hbas {};


/*
 * For state flag. Do not use LSB(8 bits) which are
 * reserved for storing info about channels.
 */
#define IN_ABORT
#define IN_RESET
#define BOARD_MEMMAP
#define BOARD_IOMAP
#define BOARD_40LD
#define BOARD_64BIT

#define INTR_VALID

#define PCI_CONF_AMISIG
#define PCI_CONF_AMISIG64


#define MEGA_DMA_TYPE_NONE
#define MEGA_BULK_DATA
#define MEGA_SGLIST

/*
 * Parameters for the io-mapped controllers
 */

/* I/O Port offsets */
#define CMD_PORT
#define ACK_PORT
#define TOGGLE_PORT
#define INTR_PORT

#define MBOX_BUSY_PORT
#define MBOX_PORT0
#define MBOX_PORT1
#define MBOX_PORT2
#define MBOX_PORT3
#define ENABLE_MBOX_REGION

/* I/O Port Values */
#define ISSUE_BYTE
#define ACK_BYTE
#define ENABLE_INTR_BYTE
#define DISABLE_INTR_BYTE
#define VALID_INTR_BYTE
#define MBOX_BUSY_BYTE
#define ENABLE_MBOX_BYTE


/* Setup some port macros here */
#define issue_command(adapter)

#define irq_state(adapter)

#define set_irq_state(adapter, value)

#define irq_ack(adapter)

#define irq_enable(adapter)

#define irq_disable(adapter)


/*
 * This is our SYSDEP area. All kernel specific detail should be placed here -
 * as much as possible
 */

/*
 * End of SYSDEP area
 */

const char *megaraid_info (struct Scsi_Host *);

static int mega_query_adapter(adapter_t *);
static int issue_scb(adapter_t *, scb_t *);
static int mega_setup_mailbox(adapter_t *);

static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
static scb_t * mega_build_cmd(adapter_t *, struct scsi_cmnd *, int *);
static void __mega_runpendq(adapter_t *);
static int issue_scb_block(adapter_t *, u_char *);

static irqreturn_t megaraid_isr_memmapped(int, void *);
static irqreturn_t megaraid_isr_iomapped(int, void *);

static void mega_free_scb(adapter_t *, scb_t *);

static int megaraid_abort(struct scsi_cmnd *);
static int megaraid_reset(struct scsi_cmnd *);
static int megaraid_abort_and_reset(adapter_t *, struct scsi_cmnd *, int);
static int megaraid_biosparam(struct scsi_device *, struct block_device *,
		sector_t, int []);

static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
			      u32 *buffer, u32 *length);
static int __mega_busywait_mbox (adapter_t *);
static void mega_rundoneq (adapter_t *);
static void mega_cmd_done(adapter_t *, u8 [], int, int);
static inline void mega_free_sgl (adapter_t *adapter);
static void mega_8_to_40ld (mraid_inquiry *inquiry,
		mega_inquiry3 *enquiry3, mega_product_info *);

static int megadev_open (struct inode *, struct file *);
static int megadev_ioctl (struct file *, unsigned int, unsigned long);
static int mega_m_to_n(void __user *, nitioctl_t *);
static int mega_n_to_m(void __user *, megacmd_t *);

static int mega_init_scb (adapter_t *);

static int mega_is_bios_enabled (adapter_t *);

#ifdef CONFIG_PROC_FS
static void mega_create_proc_entry(int, struct proc_dir_entry *);
static int mega_adapinq(adapter_t *, dma_addr_t);
static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
#endif

static int mega_support_ext_cdb(adapter_t *);
static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
		struct scsi_cmnd *, int, int);
static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
		scb_t *, struct scsi_cmnd *, int, int);
static void mega_enum_raid_scsi(adapter_t *);
static void mega_get_boot_drv(adapter_t *);
static int mega_support_random_del(adapter_t *);
static int mega_del_logdrv(adapter_t *, int);
static int mega_do_del_logdrv(adapter_t *, int);
static void mega_get_max_sgl(adapter_t *);
static int mega_internal_command(adapter_t *, megacmd_t *, mega_passthru *);
static int mega_support_cluster(adapter_t *);
#endif

/* vi: set ts=8 sw=8 tw=78: */