#ifndef LEAPRAID_FUNC_H_INCLUDED
#define LEAPRAID_FUNC_H_INCLUDED
#include <linux/pci.h>
#include <linux/aer.h>
#include <linux/poll.h>
#include <linux/atomic.h>
#include <linux/errno.h>
#include <linux/ktime.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <scsi/scsi.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsicam.h>
#include <scsi/scsi_tcq.h>
#include <scsi/scsi_dbg.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_transport_sas.h>
#include "leapraid.h"
#define LEAPRAID_REQUEST_SIZE 128
#define LEAPRAID_REPLY_SIZE 128
#define LEAPRAID_CHAIN_SEG_SIZE 128
#define LEAPRAID_MAX_SGES_IN_CHAIN 7
#define LEAPRAID_DEFAULT_CHAINS_PER_IO 19
#define LEAPRAID_DEFAULT_DIX_CHAINS_PER_IO \
(2 * LEAPRAID_DEFAULT_CHAINS_PER_IO) /* TODO DIX */
#define LEAPRAID_IEEE_SGE64_ENTRY_SIZE 16
#define LEAPRAID_REP_DESC_CHUNK_SIZE 16
#define LEAPRAID_REP_DESC_ENTRY_SIZE 8
#define LEAPRAID_REP_MSG_ADDR_SIZE 4
#define LEAPRAID_REP_RQ_CNT_SIZE 16
#define LEAPRAID_SYS_LOG_BUF_SIZE 0x200000
#define LEAPRAID_SYS_LOG_BUF_RESERVE 0x1000
#define LEAPRAID_DRIVER_NAME "LeapRAID"
#define LEAPRAID_NAME_LENGTH 48
#define LEAPRAID_BOARD_NAME_LENGTH 17
#define LEAPRAID_AUTHOR "LeapIO Inc."
#define LEAPRAID_DESCRIPTION "LeapRAID Driver"
#define LEAPRAID_DRIVER_VERSION "2.00.01.09"
#define LEAPRAID_MAJOR_VERSION 2
#define LEAPRAID_MINOR_VERSION 0
#define LEAPRAID_BUILD_VERSION 1
#define LEAPRAID_RELEASE_VERSION 9
#define LEAPRAID_MSG_VERSION 0x1021
#define LEAPRAID_HEADER_VERSION 0x0000
#define LEAPRAID_VENDOR_ID 0xD405
#define LEAPRAID_DEVID_HBA 0x8200
#define LEAPRAID_SUBVENDOR_ID 0xD405
#define LEAPRAID_SUBDEVID_HBA 0x8200
#define LEAPRAID_PCI_VENDOR_ID_MASK 0xFFFF
#define RAID_CHANNEL 1
#define LEAPRAID_MAX_PHYS_SEGMENTS SG_CHUNK_SIZE
#define LEAPRAID_KDUMP_MIN_PHYS_SEGMENTS 32
#define LEAPRAID_SG_DEPTH LEAPRAID_MAX_PHYS_SEGMENTS
#define LEAPRAID_CFG_REQ_RETRY_TIMES 2
#define leapraid_readl(addr) readl(addr)
#define leapraid_check_reset(status) \
(!((status) & LEAPRAID_CMD_RESET))
#define LEAPRAID_PCIE_LOG_POLLING_INTERVAL 1
#define LEAPRAID_FAULT_POLLING_INTERVAL 1000
#define LEAPRAID_RESET_IRQ_MASK 0x40000000
#define LEAPRAID_REPLY_INT_MASK 0x00000008
#define LEAPRAID_TO_SYS_DB_MASK 0x00000001
#define LEAPRAID_SATA_QUEUE_DEPTH 32
#define LEAPRAID_SAS_QUEUE_DEPTH 64
#define LEAPRAID_RAID_QUEUE_DEPTH 64
#define LEAPRAID_NO_ULD_ATTACH_FLAG 1
#define LEAPRAID_MAX_SECTORS 2048
#define LEAPRAID_MAX_CDB_LEN 32
#define LEAPRAID_MAX_LUNS 16384
#define LEAPRAID_CAN_QUEUE_MIN 1
#define LEAPRAID_THIS_ID_NONE -1
#define LEAPRAID_CMD_PER_LUN 128
#define LEAPRAID_MAX_SEGMENT_SIZE 0xffffffff
#define DESC_FORMAT_THRESHOLD 0x72
#define SENSE_KEY_MASK 0x0F
#define SCSI_SENSE_RESPONSE_CODE_MASK 0x7F
#define LEAPRAID_LARGE_DISK_THRESHOLD 0x200000UL
#define LEAPRAID_LARGE_DISK_HEADS 255
#define LEAPRAID_LARGE_DISK_SECTORS 63
#define LEAPRAID_SMALL_DISK_HEADS 64
#define LEAPRAID_SMALL_DISK_SECTORS 32
#define LEAPRAID_SMP_PT_FLAG_SGL_PTR 0x80
#define LEAPRAID_SMP_FRAME_HEADER_SIZE 4
#define LEAPRAID_SCSI_HOST_SHIFT 16
#define LEAPRAID_SCSI_DRIVER_SHIFT 24
#define LEAPRAID_VPD_PAGE_ATA_INFO 0x89
#define LEAPRAID_VPD_PG89_MAX_LEN 255
#define LEAPRAID_VPD_PG89_MIN_LEN 214
#define LEAPRAID_VPD_PG89_NCQ_BYTE_IDX 213
#define LEAPRAID_VPD_PG89_NCQ_BIT_SHIFT 4
#define LEAPRAID_VPD_PG89_NCQ_BIT_MASK 0x1
#define LEAPRAID_ADAPTER_READY_MAX_RETRY 15000
#define LEAPRAID_ADAPTER_READY_SLEEP_MIN_US 1000
#define LEAPRAID_ADAPTER_READY_SLEEP_MAX_US 1100
#define LEAPRAID_DB_WAIT_MAX_RETRY 20000
#define LEAPRAID_DB_WAIT_DELAY_US 500
#define LEAPRAID_DWORDS_BYTE_SIZE 4
#define LEAPRAID_WORD_BYTE_SIZE 2
#define LEAPRAID_SGL_INLINE_THRESHOLD 2
#define LEAPRAID_CHAIN_OFFSET_DWORDS 7
#define LEAPRAID_MSIX_GROUP_SIZE 8
#define LEAPRAID_MSIX_GROUP_MASK 7
#define LEAPRAID_BUSY_LIMIT 1
#define LEAPRAID_INVALID_HOST_DIAG_VAL 0xFFFFFFFF
#define LEAPRAID_WRSEQ_FLUSH_KEY_VALUE 0x0
#define LEAPRAID_WRSEQ_1ST_KEY_VALUE 0xF
#define LEAPRAID_WRSEQ_2ND_KEY_VALUE 0x4
#define LEAPRAID_WRSEQ_3RD_KEY_VALUE 0xB
#define LEAPRAID_WRSEQ_4TH_KEY_VALUE 0x2
#define LEAPRAID_WRSEQ_5TH_KEY_VALUE 0x7
#define LEAPRAID_WRSEQ_6TH_KEY_VALUE 0xD
#define LEAPRAID_UNLOCK_RETRY_LIMIT 20
#define LEAPRAID_UNLOCK_SLEEP_MS 100
#define LEAPRAID_MSLEEP_NORMAL_MS 100
#define LEAPRAID_MSLEEP_EXTRA_LONG_MS 500
#define LEAPRAID_IO_POLL_DELAY_US 500
#define LEAPRAID_MAX_VOLUMES_DEFAULT 32
#define LEAPRAID_MAX_DEV_HANDLE_DEFAULT 2048
#define LEAPRAID_INVALID_DEV_HANDLE 0xFFFF
#define LEAPRAID_DEFAULT_CMD_QD_OFFSET 64
#define LEAPRAID_REPLY_QD_ALIGNMENT 16
#define LEAPRAID_TASKID_OFFSET_CTRL_CMD 1
#define LEAPRAID_TASKID_OFFSET_CFG_OP_CMD 1
#define LEAPRAID_TASKID_OFFSET_TRANSPORT_CMD 2
#define LEAPRAID_TASKID_OFFSET_ENC_CMD 3
#define LEAPRAID_TASKID_OFFSET_NOTIFY_EVENT_CMD 4
#define LEAPRAID_HP_TASKID_OFFSET_CTL_CMD 0
#define LEAPRAID_HP_TASKID_OFFSET_TM_CMD 1
#define LEAPRAID_EVT_MASK_COUNT 4
#define LEAPRAID_BOOT_DEV_SIZE 24
#define LEAPRAID_UNIFIED_TIMEOUT 30
#define LEAPRAID_CFG_OP_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define LEAPRAID_CTL_CMD_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define LEAPRAID_SCAN_DEV_CMD_TIMEOUT 300
#define LEAPRAID_ENC_CMD_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define LEAPRAID_IO_CMD_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define LEAPRAID_NOTIFY_EVENT_CMD_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define LEAPRAID_TM_CMD_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define LEAPRAID_TRANSPORT_CMD_TIMEOUT LEAPRAID_UNIFIED_TIMEOUT
#define DMA_32_BITS 32
#define DMA_64_BITS 64
#define LEAPRAID_DMA_ALIGN 16
#define LEAPRAID_INVALID_INDEX -1
#define LEAPRAID_INVALID_MSIX_VECTORS -1
#define LEAPRAID_INVALID_INITIAL_VALUE -1
#define LEAPRAID_OPERATION_FAILED -1
#define LEAPRAID_VER_MAJOR_SHIFT 24
#define LEAPRAID_VER_MINOR_SHIFT 16
#define LEAPRAID_VER_BUILD_SHIFT 8
#define LEAPRAID_VER_MASK 0xFF
#define LEAPRAID_INTERRUPT_MODE_MSIX 0
#define LEAPRAID_INTERRUPT_MODE_MSI 1
#define LEAPRAID_INTERRUPT_MODE_LEGACY 2
#define SMP_PHY_CONTROL_LINK_RESET 0x01
#define SMP_PHY_CONTROL_HARD_RESET 0x02
#define SMP_PHY_CONTROL_DISABLE 0x03
struct leapraid_adapter_features {
u16 req_slot;
u16 hp_slot;
u32 adapter_caps;
u32 fw_version;
u8 max_msix_vectors;
u8 max_volumes;
u16 max_dev_handle;
u16 min_dev_handle;
u16 msg_ver;
u16 product_id;
};
struct leapraid_adapter_attr {
u8 id;
u8 raid_support;
u32 bios_version;
u8 enable_mp;
u32 wideport_max_queue_depth;
u32 narrowport_max_queue_depth;
u32 sata_max_queue_depth;
u32 raid_volume_max_queue_depth;
struct leapraid_adapter_features features;
u32 adapter_total_qd;
u32 io_qd;
u32 rep_msg_qd;
u32 rep_desc_qd;
u32 rep_desc_q_seg_cnt;
u16 rq_cnt;
u32 task_desc_dma_size;
u8 use_32_dma_mask;
char name[LEAPRAID_NAME_LENGTH];
char board_name[LEAPRAID_BOARD_NAME_LENGTH];
};
struct leapraid_io_req_tracker {
u16 taskid;
struct scsi_cmnd *scmd;
struct list_head chain_list;
u16 msix_io;
void *chain;
dma_addr_t chain_dma;
};
struct leapraid_task_tracker {
u16 taskid;
u8 cb_idx;
struct list_head tracker_list;
};
struct leapraid_rep_desc_maint {
union leapraid_rep_desc_union *rep_desc;
dma_addr_t rep_desc_dma;
};
struct leapraid_rep_desc_seg_maint {
void *rep_desc_seg;
dma_addr_t rep_desc_seg_dma;
struct leapraid_rep_desc_maint *rep_desc_maint;
};
struct leapraid_mem_desc {
void *task_desc;
dma_addr_t task_desc_dma;
struct dma_pool *sg_chain_pool;
u16 sg_chain_pool_size;
u16 *taskid_to_uniq_tag;
u8 *sense_data;
dma_addr_t sense_data_dma;
u8 *rep_msg;
dma_addr_t rep_msg_dma;
__le32 *rep_msg_addr;
dma_addr_t rep_msg_addr_dma;
struct leapraid_rep_desc_seg_maint *rep_desc_seg_maint;
struct leapraid_rep_desc_q_arr *rep_desc_q_arr;
dma_addr_t rep_desc_q_arr_dma;
};
#define LEAPRAID_FIXED_INTER_CMDS 5
#define LEAPRAID_FIXED_HP_CMDS 2
#define LEAPRAID_CMD_NOT_USED 0x8000
#define LEAPRAID_CMD_DONE 0x0001
#define LEAPRAID_CMD_PENDING 0x0002
#define LEAPRAID_CMD_REPLY_VALID 0x0004
#define LEAPRAID_CMD_RESET 0x0008
enum LEAPRAID_CB_INDEX {
LEAPRAID_SCAN_DEV_CB_IDX = 0x1,
LEAPRAID_CONFIG_CB_IDX = 0x2,
LEAPRAID_TRANSPORT_CB_IDX = 0x3,
LEAPRAID_SAS_CTRL_CB_IDX = 0x5,
LEAPRAID_ENC_CB_IDX = 0x6,
LEAPRAID_NOTIFY_EVENT_CB_IDX = 0x7,
LEAPRAID_CTL_CB_IDX = 0x8,
LEAPRAID_TM_CB_IDX = 0x9,
LEAPRAID_NUM_CB_IDXS
};
struct leapraid_default_reply {
u8 pad[LEAPRAID_REPLY_SIZE];
};
struct leapraid_sense_buffer {
u8 pad[SCSI_SENSE_BUFFERSIZE];
};
struct leapraid_driver_cmd {
struct leapraid_default_reply reply;
struct completion done;
u16 status;
u16 taskid;
u16 hp_taskid;
u16 inter_taskid;
u8 cb_idx;
u8 async_scan_dev;
struct leapraid_sense_buffer sense;
struct mutex mutex;
struct list_head list;
};
struct leapraid_driver_cmds {
struct list_head special_cmd_list;
struct leapraid_driver_cmd scan_dev_cmd;
struct leapraid_driver_cmd cfg_op_cmd;
struct leapraid_driver_cmd transport_cmd;
struct leapraid_driver_cmd enc_cmd;
struct leapraid_driver_cmd notify_event_cmd;
struct leapraid_driver_cmd ctl_cmd;
struct leapraid_driver_cmd tm_cmd;
};
struct leapraid_dynamic_task_desc {
spinlock_t task_lock;
u16 hp_taskid;
u16 hp_cmd_qd;
u16 inter_taskid;
u16 inter_cmd_qd;
};
struct leapraid_fw_evt_work {
struct list_head list;
struct leapraid_adapter *adapter;
struct work_struct work;
struct kref refcnt;
void *evt_data;
u16 dev_handle;
u16 evt_type;
u8 ignore;
};
struct leapraid_fw_evt_struct {
u32 leapraid_evt_masks[4];
struct workqueue_struct *fw_evt_thread;
spinlock_t fw_evt_lock;
struct list_head fw_evt_list;
struct leapraid_fw_evt_work *cur_evt;
struct task_struct *cur_evt_task;
u8 fw_evt_cleanup;
};
struct leapraid_rq {
struct leapraid_adapter *adapter;
u8 msix_idx;
u32 rep_post_host_idx;
union leapraid_rep_desc_union *rep_desc;
char name[LEAPRAID_NAME_LENGTH];
atomic_t busy;
};
struct leapraid_int_rq {
cpumask_var_t affinity_hint;
struct leapraid_rq rq;
};
struct leapraid_blk_mq_poll_rq {
atomic_t busy;
atomic_t pause;
struct leapraid_rq rq;
};
struct leapraid_notification_desc {
u32 iopoll_qdex;
u32 iopoll_qcnt;
u8 msix_enable;
u8 irq_vectors_allocated;
u8 irq_mode;
u8 *msix_cpu_map;
u32 msix_cpu_map_sz;
struct leapraid_int_rq *int_rqs;
u32 int_rqs_allocated;
struct leapraid_blk_mq_poll_rq *blk_mq_poll_rqs;
};
struct leapraid_overheat_desc {
struct workqueue_struct *fault_overheat_wq;
struct work_struct fault_overheat_work;
atomic_t thermal_alert;
char fault_overheat_wq_name[48];
};
struct leapraid_reset_desc {
struct workqueue_struct *fault_reset_wq;
struct delayed_work fault_reset_work;
char fault_reset_wq_name[48];
struct mutex host_diag_mutex;
spinlock_t adapter_reset_lock;
struct mutex adapter_reset_mutex;
u8 adapter_link_resetting;
int adapter_reset_results;
int pending_io_cnt;
wait_queue_head_t reset_wait_queue;
u32 reset_cnt;
};
struct leapraid_scan_dev_desc {
u8 wait_scan_dev_done;
u8 driver_loading;
wait_queue_head_t wait_driver_loading;
u8 first_scan_dev_fired;
u8 scan_dev_failed;
u8 scan_start;
u16 scan_start_failed;
};
struct leapraid_access_ctrl {
struct mutex pci_access_lock;
u8 shost_recovering;
wait_queue_head_t recovery_waitq;
u8 shost_recover_async;
wait_queue_head_t shost_recover_wq;
u8 host_removing;
u8 pcie_recovering;
};
struct leapraid_fw_log_desc {
u8 *fw_log_buffer;
dma_addr_t fw_log_buffer_dma;
char fw_log_wq_name[48];
struct workqueue_struct *fw_log_wq;
struct delayed_work fw_log_work;
int open_pcie_trace;
int fw_log_init_flag;
atomic_t mmap_refcnt;
wait_queue_head_t mmap_waitq;
};
#define LEAPRAID_CARD_PORT_FLG_DIRTY 0x01
#define LEAPRAID_CARD_PORT_FLG_NEW 0x02
#define LEAPRAID_DISABLE_MP_PORT_ID 0xFF
struct leapraid_card_port {
struct list_head list;
struct list_head vphys_list;
u8 port_id;
u64 sas_address;
u32 phy_mask;
u32 vphys_mask;
u8 flg;
};
struct leapraid_card_phy {
struct list_head port_siblings;
struct leapraid_card_port *card_port;
struct sas_identify identify;
struct sas_identify remote_identify;
struct sas_phy *phy;
u8 phy_id;
u16 hdl;
u16 attached_hdl;
u8 phy_is_assigned;
u8 vphy;
};
struct leapraid_topo_node {
struct list_head list;
struct list_head sas_port_list;
struct leapraid_card_port *card_port;
struct leapraid_card_phy *card_phy;
struct sas_rphy *rphy;
struct device *parent_dev;
u64 sas_address;
u64 sas_address_parent;
u8 phys_num;
u16 hdl;
u16 enc_hdl;
u64 enc_lid;
u8 resp;
};
struct leapraid_dev_topo {
spinlock_t topo_node_lock;
spinlock_t sas_dev_lock;
spinlock_t raid_volume_lock;
spinlock_t enc_lock;
int sas_id;
struct leapraid_topo_node card;
struct list_head exp_list;
struct list_head enc_list;
struct list_head sas_dev_list;
struct list_head sas_dev_init_list;
struct list_head raid_volume_list;
struct list_head card_port_list;
u16 pd_hdls_sz;
unsigned long *pd_hdls;
unsigned long *blocking_hdls;
};
struct leapraid_boot_dev {
void *dev;
u8 chnl;
u8 form;
u8 pg_dev[24];
};
struct leapraid_boot_devs {
spinlock_t lock;
struct leapraid_boot_dev requested_boot_dev;
struct leapraid_boot_dev requested_alt_boot_dev;
struct leapraid_boot_dev current_boot_dev;
};
struct leapraid_adapter {
struct list_head list;
struct Scsi_Host *shost;
struct pci_dev *pdev;
struct leapraid_reg_base __iomem *iomem_base;
u32 rep_msg_host_idx;
u8 mask_int;
struct leapraid_adapter_attr adapter_attr;
struct leapraid_mem_desc mem_desc;
struct leapraid_driver_cmds driver_cmds;
struct leapraid_dynamic_task_desc dynamic_task_desc;
struct leapraid_fw_evt_struct fw_evt_s;
struct leapraid_notification_desc notification_desc;
struct leapraid_reset_desc reset_desc;
struct leapraid_scan_dev_desc scan_dev_desc;
struct leapraid_access_ctrl access_ctrl;
struct leapraid_fw_log_desc fw_log_desc;
struct leapraid_dev_topo dev_topo;
struct leapraid_boot_devs boot_devs;
struct leapraid_overheat_desc overheat_desc;
};
union cfg_param_1 {
u32 form;
u32 size;
u32 phy_number;
};
union cfg_param_2 {
u32 handle;
u32 form_specific;
};
enum config_page_action {
GET_BIOS_PG2,
GET_BIOS_PG3,
GET_MANUFACTURING_PG0,
GET_SAS_DEVICE_PG0,
GET_SAS_IOUNIT_PG0,
GET_SAS_IOUNIT_PG1,
GET_SAS_EXPANDER_PG0,
GET_SAS_EXPANDER_PG1,
GET_SAS_ENCLOSURE_PG0,
GET_PHY_PG0,
GET_RAID_VOLUME_PG0,
GET_RAID_VOLUME_PG1,
GET_PHY_DISK_PG0,
};
struct leapraid_enc_node {
struct list_head list;
struct leapraid_enc_p0 pg0;
};
struct leapraid_raid_volume {
struct list_head list;
struct kref refcnt;
struct scsi_target *starget;
struct scsi_device *sdev;
unsigned int id;
unsigned int channel;
u64 wwid;
u16 hdl;
u8 vol_type;
u8 pd_num;
u8 resp;
u32 dev_info;
};
static inline void leapraid_raid_volume_free(struct kref *ref)
{
kfree(container_of(ref, struct leapraid_raid_volume, refcnt));
}
#define leapraid_raid_volume_get(volume) \
kref_get(&(volume)->refcnt)
#define leapraid_raid_volume_put(volume) \
kref_put(&(volume)->refcnt, leapraid_raid_volume_free)
#define LEAPRAID_TGT_FLG_RAID_MEMBER 0x01
#define LEAPRAID_TGT_FLG_VOLUME 0x02
#define LEAPRAID_NO_ULD_ATTACH 1
struct leapraid_starget_priv {
struct scsi_target *starget;
u64 sas_address;
u16 hdl;
int num_luns;
u32 flg;
u8 deleted;
u8 tm_busy;
struct leapraid_card_port *card_port;
struct leapraid_sas_dev *sas_dev;
};
#define LEAPRAID_DEVICE_FLG_INIT 0x01
struct leapraid_sdev_priv {
struct leapraid_starget_priv *starget_priv;
unsigned int lun;
u32 flg;
u8 ncq_prio_enable;
u8 block;
u8 deleted;
u8 sep;
};
struct leapraid_sas_dev {
struct list_head list;
struct scsi_target *starget;
struct leapraid_card_port *card_port;
struct sas_rphy *rphy;
struct kref refcnt;
unsigned int id;
unsigned int channel;
u16 slot;
u8 phy;
u8 resp;
u8 led_on;
u64 sas_addr;
u64 dev_name;
u16 hdl;
u64 parent_sas_addr;
u16 enc_hdl;
u64 enc_lid;
u16 volume_hdl;
u64 volume_wwid;
u32 dev_info;
u8 pend_sas_rphy_add;
u8 enc_level;
u8 port_connection;
u8 connector_name[LEAPRAID_SAS_DEV_P0_CON_NAME_LEN + 1];
};
static inline void leapraid_sdev_free(struct kref *ref)
{
kfree(container_of(ref, struct leapraid_sas_dev, refcnt));
}
#define leapraid_sdev_get(sdev) kref_get(&(sdev)->refcnt)
#define leapraid_sdev_put(sdev) kref_put(&(sdev)->refcnt, leapraid_sdev_free)
void leapraid_boot_dev_get(void *dev, u32 chnl);
void leapraid_boot_dev_put(void *dev, u32 chnl);
struct leapraid_sas_port {
struct list_head port_list;
struct list_head phy_list;
struct sas_port *port;
struct leapraid_card_port *card_port;
struct sas_identify remote_identify;
struct sas_rphy *rphy;
u8 phys_num;
};
#define LEAPRAID_VPHY_FLG_DIRTY 0x01
struct leapraid_vphy {
struct list_head list;
u64 sas_address;
u32 phy_mask;
u8 flg;
};
struct leapraid_tgt_rst_list {
struct list_head list;
u16 handle;
u16 state;
};
struct sense_info {
u8 sense_key;
u8 asc;
u8 ascq;
};
struct leapraid_fw_log_info {
u32 user_position;
u32 adapter_position;
};
enum reset_type {
FULL_RESET,
PART_RESET,
};
enum leapraid_card_port_checking_flg {
CARD_PORT_FURTHER_CHECKING_NEEDED = 0,
CARD_PORT_SKIP_CHECKING,
};
enum leapraid_port_checking_state {
NEW_CARD_PORT = 0,
SAME_PORT_WITH_NOTHING_CHANGED,
SAME_PORT_WITH_PARTIALLY_CHANGED_PHYS,
SAME_ADDR_WITH_PARTIALLY_CHANGED_PHYS,
SAME_ADDR_ONLY,
};
struct leapraid_card_port_feature {
u8 dirty_flg;
u8 same_addr;
u8 exact_phy;
u32 phy_overlap;
u8 same_port;
struct leapraid_card_port *cur_chking_old_port;
struct leapraid_card_port *expected_old_port;
int same_addr_port_count;
enum leapraid_port_checking_state checking_state;
};
#define SMP_REPORT_MANUFACTURER_INFORMATION_FRAME_TYPE 0x40
#define SMP_REPORT_MANUFACTURER_INFORMATION_FUNC 0x01
struct leapraid_rep_manu_request {
u8 smp_frame_type;
u8 function;
u8 allocated_response_length;
u8 request_length;
};
struct leapraid_rep_manu_reply {
u8 smp_frame_type;
u8 function;
u8 function_result;
u8 response_length;
u16 expander_change_count;
u8 r1[2];
u8 sas_format;
u8 r2[3];
u8 vendor_identification[SAS_EXPANDER_VENDOR_ID_LEN];
u8 product_identification[SAS_EXPANDER_PRODUCT_ID_LEN];
u8 product_revision_level[SAS_EXPANDER_PRODUCT_REV_LEN];
u8 comp_vendor_identification[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
u16 component_id;
u8 component_revision_level;
u8 r3;
u8 vendor_specific[8];
};
extern struct list_head leapraid_adapter_list;
extern spinlock_t leapraid_adapter_lock;
extern char driver_name[LEAPRAID_NAME_LENGTH];
int leapraid_ctrl_init(struct leapraid_adapter *adapter);
void leapraid_remove_ctrl(struct leapraid_adapter *adapter);
void leapraid_check_scheduled_fault_start(struct leapraid_adapter *adapter);
void leapraid_check_scheduled_fault_stop(struct leapraid_adapter *adapter);
void leapraid_fw_log_start(struct leapraid_adapter *adapter);
void leapraid_fw_log_stop(struct leapraid_adapter *adapter);
int leapraid_set_pcie_and_notification(struct leapraid_adapter *adapter);
void leapraid_disable_controller(struct leapraid_adapter *adapter);
int leapraid_hard_reset_handler(struct leapraid_adapter *adapter,
enum reset_type type);
void leapraid_mask_int(struct leapraid_adapter *adapter);
void leapraid_unmask_int(struct leapraid_adapter *adapter);
u32 leapraid_get_adapter_state(struct leapraid_adapter *adapter);
bool leapraid_pci_removed(struct leapraid_adapter *adapter);
int leapraid_check_adapter_is_op(struct leapraid_adapter *adapter, int wait,
const char *caller);
void *leapraid_get_task_desc(struct leapraid_adapter *adapter, u16 taskid);
void *leapraid_get_sense_buffer(struct leapraid_adapter *adapter, u16 taskid);
__le32 leapraid_get_sense_buffer_dma(struct leapraid_adapter *adapter,
u16 taskid);
void *leapraid_get_reply_vaddr(struct leapraid_adapter *adapter,
u32 phys_addr);
u16 leapraid_alloc_scsiio_taskid(struct leapraid_adapter *adapter,
struct scsi_cmnd *scmd);
void leapraid_free_taskid(struct leapraid_adapter *adapter, u16 taskid);
struct leapraid_io_req_tracker *leapraid_get_io_tracker_from_taskid(
struct leapraid_adapter *adapter, u16 taskid);
struct scsi_cmnd *leapraid_get_scmd_from_taskid(
struct leapraid_adapter *adapter, u16 taskid);
int leapraid_scan_dev(struct leapraid_adapter *adapter, bool async_scan_dev);
void leapraid_scan_dev_done(struct leapraid_adapter *adapter);
void leapraid_cleanup_lists(struct leapraid_adapter *adapter);
void leapraid_wait_cmds_done(struct leapraid_adapter *adapter);
void leapraid_clean_active_scsi_cmds(struct leapraid_adapter *adapter);
void leapraid_sync_irqs(struct leapraid_adapter *adapter, bool poll);
int leapraid_rep_queue_handler(struct leapraid_rq *rq);
int leapraid_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num);
void leapraid_mq_polling_pause(struct leapraid_adapter *adapter);
void leapraid_mq_polling_resume(struct leapraid_adapter *adapter);
void leapraid_set_tm_flg(struct leapraid_adapter *adapter, u16 handle);
void leapraid_clear_tm_flg(struct leapraid_adapter *adapter, u16 handle);
void leapraid_async_turn_on_led(struct leapraid_adapter *adapter, u16 handle);
int leapraid_issue_locked_tm(struct leapraid_adapter *adapter, u16 handle,
uint channel, uint id, uint lun, u8 type,
u16 taskid_task, u8 tr_method);
int leapraid_issue_tm(struct leapraid_adapter *adapter, u16 handle,
uint channel, uint id, uint lun, u8 type,
u16 taskid_task, u8 tr_method);
bool leapraid_scsiio_done(struct leapraid_adapter *adapter, u16 taskid,
u8 msix_index, u32 rep);
int leapraid_get_volume_cap(struct leapraid_adapter *adapter,
struct leapraid_raid_volume *raid_volume);
int leapraid_internal_init_cmd_priv(
struct leapraid_adapter *adapter,
struct leapraid_io_req_tracker *io_tracker);
void leapraid_internal_exit_cmd_priv(
struct leapraid_adapter *adapter,
struct leapraid_io_req_tracker *io_tracker);
void leapraid_clean_active_fw_evt(struct leapraid_adapter *adapter);
bool leapraid_scmd_find_by_lun(struct leapraid_adapter *adapter,
uint id, unsigned int lun, uint channel);
bool leapraid_scmd_find_by_tgt(struct leapraid_adapter *adapter,
uint id, uint channel);
struct leapraid_vphy *leapraid_get_vphy_by_phy(struct leapraid_card_port *port,
u32 phy);
struct leapraid_raid_volume *leapraid_raid_volume_find_by_id(
struct leapraid_adapter *adapter, uint id, uint channel);
struct leapraid_raid_volume *leapraid_raid_volume_find_by_hdl(
struct leapraid_adapter *adapter, u16 handle);
struct leapraid_topo_node *leapraid_exp_find_by_sas_address(
struct leapraid_adapter *adapter, u64 sas_address,
struct leapraid_card_port *port);
struct leapraid_sas_dev *leapraid_hold_lock_get_sas_dev_by_addr_and_rphy(
struct leapraid_adapter *adapter,
u64 sas_address, struct sas_rphy *rphy);
struct leapraid_sas_dev *leapraid_get_sas_dev_by_addr(
struct leapraid_adapter *adapter, u64 sas_address,
struct leapraid_card_port *port);
struct leapraid_sas_dev *leapraid_get_sas_dev_by_hdl(
struct leapraid_adapter *adapter, u16 handle);
struct leapraid_sas_dev *leapraid_get_sas_dev_from_tgt(
struct leapraid_adapter *adapter,
struct leapraid_starget_priv *tgt_priv);
struct leapraid_sas_dev *leapraid_hold_lock_get_sas_dev_from_tgt(
struct leapraid_adapter *adapter,
struct leapraid_starget_priv *tgt_priv);
struct leapraid_sas_dev *leapraid_hold_lock_get_sas_dev_by_hdl(
struct leapraid_adapter *adapter, u16 handle);
struct leapraid_sas_dev *leapraid_hold_lock_get_sas_dev_by_addr(
struct leapraid_adapter *adapter, u64 sas_address,
struct leapraid_card_port *port);
struct leapraid_sas_dev *leapraid_get_next_sas_dev_from_init_list(
struct leapraid_adapter *adapter);
void leapraid_sas_dev_remove_by_sas_address(
struct leapraid_adapter *adapter,
u64 sas_address, struct leapraid_card_port *port);
void leapraid_sas_dev_remove(struct leapraid_adapter *adapter,
struct leapraid_sas_dev *sas_dev);
void leapraid_raid_volume_remove(struct leapraid_adapter *adapter,
struct leapraid_raid_volume *raid_volume);
void leapraid_exp_rm(struct leapraid_adapter *adapter,
u64 sas_address, struct leapraid_card_port *port);
void leapraid_build_mpi_sg(struct leapraid_adapter *adapter,
void *sge, dma_addr_t h2c_dma_addr, size_t h2c_size,
dma_addr_t c2h_dma_addr, size_t c2h_size);
void leapraid_build_ieee_nodata_sg(struct leapraid_adapter *adapter,
void *sge);
void leapraid_build_ieee_sg(struct leapraid_adapter *adapter,
void *psge, dma_addr_t h2c_dma_addr,
size_t h2c_size, dma_addr_t c2h_dma_addr,
size_t c2h_size);
int leapraid_build_scmd_ieee_sg(struct leapraid_adapter *adapter,
struct scsi_cmnd *scmd, u16 taskid);
void leapraid_fire_scsi_io(struct leapraid_adapter *adapter,
u16 taskid, u16 handle);
void leapraid_fire_hpr_task(struct leapraid_adapter *adapter, u16 taskid,
u16 msix_task);
void leapraid_fire_task(struct leapraid_adapter *adapter, u16 taskid);
int leapraid_cfg_get_volume_hdl(struct leapraid_adapter *adapter,
u16 pd_handle, u16 *volume_handle);
int leapraid_cfg_get_volume_wwid(struct leapraid_adapter *adapter,
u16 volume_handle, u64 *wwid);
int leapraid_op_config_page(struct leapraid_adapter *adapter,
void *cfgp, union cfg_param_1 cfgp1,
union cfg_param_2 cfgp2,
enum config_page_action cfg_op);
void leapraid_log_req_context(struct leapraid_adapter *adapter, u16 smid,
const void *req_data);
int leapraid_change_queue_depth(struct scsi_device *sdev, int qdepth);
int leapraid_ctl_release(struct inode *inode, struct file *filep);
int leapraid_ctl_init(void);
void leapraid_ctl_exit(void);
extern struct sas_function_template leapraid_transport_functions;
extern struct scsi_transport_template *leapraid_transport_template;
struct leapraid_sas_port *leapraid_transport_port_add(
struct leapraid_adapter *adapter, u16 handle, u64 sas_address,
struct leapraid_card_port *card_port);
void leapraid_transport_port_remove(struct leapraid_adapter *adapter,
u64 sas_address, u64 sas_address_parent,
struct leapraid_card_port *card_port);
void leapraid_transport_add_card_phy(struct leapraid_adapter *adapter,
struct leapraid_card_phy *card_phy,
struct leapraid_sas_phy_p0 *phy_pg0,
struct device *parent_dev);
int leapraid_transport_add_exp_phy(struct leapraid_adapter *adapter,
struct leapraid_card_phy *card_phy,
struct leapraid_exp_p1 *exp_pg1,
struct device *parent_dev);
void leapraid_transport_update_links(struct leapraid_adapter *adapter,
u64 sas_address, u16 handle,
u8 phy_number, u8 link_rate,
struct leapraid_card_port *card_port);
void leapraid_transport_detach_phy_to_port(
struct leapraid_adapter *adapter,
struct leapraid_topo_node *topo_node,
struct leapraid_card_phy *card_phy);
void leapraid_transport_attach_phy_to_port(
struct leapraid_adapter *adapter,
struct leapraid_topo_node *sas_node,
struct leapraid_card_phy *card_phy,
u64 sas_address,
struct leapraid_card_port *card_port);
enum scsi_qc_status leapraid_queuecommand(struct Scsi_Host *shost,
struct scsi_cmnd *scmd);
void leapraid_overheat_cleanup(struct leapraid_adapter *adapter);
void leapraid_smart_fault_detect(struct leapraid_adapter *adapter, u16 hdl);
#endif /* LEAPRAID_FUNC_H_INCLUDED */