#include <sys/param.h>
#include <sys/module.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/bus.h>
#include <sys/rman.h>
#include <sys/device.h>
#include <machine/clock.h>
#include <bus/pci/pcivar.h>
#include <bus/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.001"
#define TWS_MAX_NUM_UNITS 65
#define TWS_MAX_NUM_LUNS 16
#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_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_TRAN 0
#define TWS_REQ_STATE_FREE 1
#define TWS_REQ_STATE_PENDING 2
#define TWS_REQ_STATE_BUSY 3
#define TWS_REQ_STATE_COMPLETE 4
#define TWS_INTERNAL_CMD_REQ 0x0
#define TWS_AEN_FETCH_REQ 0x1
#define TWS_PASSTHRU_REQ 0x2
#define TWS_GETSET_PARAM_REQ 0x3
#define TWS_SCSI_IO_REQ 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,
};
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;
};
#define boolean _Bool
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 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;
int irq_res_id;
void *intr_handle;
struct tws_msix_info msix;
struct cam_sim *sim;
struct cam_path *path;
struct lock q_lock;
struct lock sim_lock;
struct lock gen_lock;
struct lock io_lock;
struct tws_ioctl_lock ioctl_lock;
u_int32_t seq_id;
int chan;
struct tws_circular_q aen_q;
struct tws_circular_q trace_q;
struct tws_stats stats;
struct tws_init_connect_info cinfo;
boolean is64bit;
int 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;
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 print_stats_handle;
struct callout reset_cb_handle;
struct callout reinit_handle;
};