#include <sys/param.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/stat.h>
#define TWS_PULL_MODE_ENABLE 1
MALLOC_DECLARE(M_TWS);
extern int tws_queue_depth;
#define TWS_DRIVER_VERSION_STRING "10.80.00.005"
#define TWS_MAX_NUM_UNITS 65
#define TWS_MAX_NUM_LUNS 32
#define TWS_MAX_IRQS 2
#define TWS_SCSI_INITIATOR_ID 66
#define TWS_MAX_IO_SIZE 0x20000
#define TWS_SECTOR_SIZE 0x200
#define TWS_POLL_TIMEOUT 60
#define TWS_IO_TIMEOUT 60
#define TWS_IOCTL_TIMEOUT 60
#define TWS_RESET_TIMEOUT 60
#define TWS_PCI_BAR0 0x10
#define TWS_PCI_BAR1 0x14
#define TWS_PCI_BAR2 0x1C
#define TWS_VENDOR_ID 0x13C1
#define TWS_DEVICE_ID 0x1010
#define TWS_INVALID_REQID 0xFFFF
#define TWS_ALIGNMENT 4
#define TWS_IN_MF_ALIGNMENT 16
#define TWS_OUT_MF_ALIGNMENT 4
#define TWS_MAX_32BIT_SG_ELEMENTS 93
#define TWS_MAX_64BIT_SG_ELEMENTS 46
#define TWS_MAX_QS 4
#define TWS_MAX_REQS 256
#define TWS_RESERVED_REQS 4
#define TWS_REQ_STATE_FREE 0
#define TWS_REQ_STATE_BUSY 1
#define TWS_REQ_STATE_TRAN 2
#define TWS_REQ_STATE_COMPLETE 3
#define TWS_REQ_TYPE_INTERNAL_CMD 0x0
#define TWS_REQ_TYPE_AEN_FETCH 0x1
#define TWS_REQ_TYPE_PASSTHRU 0x2
#define TWS_REQ_TYPE_GETSET_PARAM 0x3
#define TWS_REQ_TYPE_SCSI_IO 0x4
enum tws_states {
TWS_INIT=50,
TWS_UNINIT,
TWS_OFFLINE,
TWS_ONLINE,
TWS_RESET,
};
enum tws_events {
TWS_INIT_START=100,
TWS_INIT_COMPLETE,
TWS_UNINIT_START,
TWS_RESET_START,
TWS_RESET_COMPLETE,
TWS_SCAN_FAILURE,
};
enum tws_req_flags {
TWS_DIR_UNKNOWN = 0x1,
TWS_DIR_IN = 0x2,
TWS_DIR_OUT = 0x4,
TWS_DIR_NONE = 0x8,
TWS_DATA_CCB = 0x10,
};
enum tws_intrs {
TWS_INTx,
TWS_MSI,
TWS_MSIX,
};
struct tws_msix_info {
int tbl_res_id;
bus_space_tag_t tbl_tag;
bus_space_handle_t tbl_handle;
struct resource *tbl_res;
};
struct tws_ioctl_lock {
u_int32_t lock;
time_t timeout;
};
#define TWS_TRACE_FNAME_LEN 10
#define TWS_TRACE_FUNC_LEN 15
#define TWS_TRACE_DESC_LEN 10
struct tws_trace_rec {
struct timespec ts;
char fname[TWS_TRACE_FNAME_LEN];
char func[TWS_TRACE_FUNC_LEN];
int linenum;
char desc[TWS_TRACE_DESC_LEN];
u_int64_t val1;
u_int64_t val2;
};
struct tws_circular_q {
volatile int16_t head;
volatile int16_t tail;
u_int16_t depth;
u_int8_t overflow;
void * q;
};
struct tws_stats {
u_int64_t reqs_in;
u_int64_t reqs_out;
u_int64_t reqs_errored;
u_int64_t spurios_intrs;
u_int64_t num_intrs;
u_int64_t num_aens;
u_int64_t ioctls;
u_int64_t scsi_ios;
};
struct tws_init_connect_info {
u_int16_t working_srl;
u_int16_t working_branch;
u_int16_t working_build;
u_int16_t fw_on_ctlr_srl;
u_int16_t fw_on_ctlr_branch;
u_int16_t fw_on_ctlr_build;
};
#ifndef __bool_true_false_are_defined
typedef enum _boolean { false, true } boolean;
#else
#define boolean bool
#endif
enum err { SUCCESS, FAILURE };
struct tws_softc {
device_t tws_dev;
struct cdev *tws_cdev;
u_int32_t device_id;
u_int32_t subvendor_id;
u_int32_t subdevice_id;
u_int8_t tws_state;
u_int8_t tws_prev_state;
struct sysctl_ctx_list tws_clist;
struct sysctl_oid *tws_oidp;
struct resource *reg_res;
struct resource *mfa_res;
int reg_res_id;
int mfa_res_id;
bus_space_handle_t bus_handle;
bus_space_handle_t bus_mfa_handle;
bus_space_tag_t bus_tag;
bus_space_tag_t bus_mfa_tag;
u_int64_t mfa_base;
struct resource *irq_res[TWS_MAX_IRQS];
int irq_res_id[TWS_MAX_IRQS];
void *intr_handle[TWS_MAX_IRQS];
int irqs;
struct tws_msix_info msix;
struct cam_sim *sim;
struct cam_path *path;
struct mtx q_lock;
struct mtx sim_lock;
struct mtx gen_lock;
struct mtx io_lock;
struct tws_ioctl_lock ioctl_lock;
u_int32_t seq_id;
struct tws_circular_q aen_q;
struct tws_circular_q trace_q;
struct tws_stats stats;
struct tws_init_connect_info cinfo;
boolean is64bit;
u_int8_t intr_type;
bus_dma_tag_t parent_tag;
bus_dma_tag_t cmd_tag;
bus_dmamap_t cmd_map;
void *dma_mem;
u_int64_t dma_mem_phys;
bus_dma_tag_t data_tag;
void *ioctl_data_mem;
bus_dmamap_t ioctl_data_map;
struct tws_request *reqs;
struct tws_sense *sense_bufs;
boolean obfl_q_overrun;
union ccb *scan_ccb;
struct tws_request *q_head[TWS_MAX_QS];
struct tws_request *q_tail[TWS_MAX_QS];
struct callout stats_timer;
};