#ifndef TW_CL_H
#define TW_CL_H
#define TW_CLI_SECTOR_SIZE 0x200
#define TW_CLI_REQUEST_TIMEOUT_PERIOD 60
#define TW_CLI_RESET_TIMEOUT_PERIOD 60
#define TW_CLI_MAX_RESET_ATTEMPTS 2
#define TW_CLI_LOCK_FREE 0x0
#define TW_CLI_LOCK_HELD 0x1
#define TW_CLI_REQ_STATE_INIT 0x0
#define TW_CLI_REQ_STATE_BUSY 0x1
#define TW_CLI_REQ_STATE_PENDING 0x2
#define TW_CLI_REQ_STATE_COMPLETE 0x3
#define TW_CLI_REQ_FLAGS_7K (1<<0)
#define TW_CLI_REQ_FLAGS_9K (1<<1)
#define TW_CLI_REQ_FLAGS_INTERNAL (1<<2)
#define TW_CLI_REQ_FLAGS_PASSTHRU (1<<3)
#define TW_CLI_REQ_FLAGS_EXTERNAL (1<<4)
#ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
#define TW_CLI_PCI_CONFIG_COMMAND_OFFSET 0x4
#define TW_CLI_PCI_CONFIG_STATUS_OFFSET 0x6
#endif
#ifdef TW_OSL_DEBUG
struct tw_cli_q_stats {
TW_UINT32 cur_len;
TW_UINT32 max_len;
};
#endif
#define TW_CLI_FREE_Q 0
#define TW_CLI_BUSY_Q 1
#define TW_CLI_PENDING_Q 2
#define TW_CLI_COMPLETE_Q 3
#define TW_CLI_RESET_Q 4
#define TW_CLI_Q_COUNT 5
struct tw_cli_req_context {
struct tw_cl_req_handle *req_handle;
struct tw_cli_ctlr_context *ctlr;
struct tw_cl_command_packet *cmd_pkt;
TW_UINT64 cmd_pkt_phys;
TW_VOID *data;
TW_UINT32 length;
TW_UINT64 data_phys;
TW_UINT32 state;
TW_UINT32 flags;
TW_UINT32 error_code;
TW_VOID *orig_req;
TW_VOID (*tw_cli_callback)(struct tw_cli_req_context *req);
TW_UINT32 request_id;
struct tw_cl_link link;
};
struct tw_cli_ctlr_context {
struct tw_cl_ctlr_handle *ctlr_handle;
struct tw_cli_req_context *req_ctxt_buf;
struct tw_cl_command_packet *cmd_pkt_buf;
TW_UINT64 cmd_pkt_phys;
TW_UINT32 device_id;
TW_UINT32 arch_id;
TW_UINT8 active;
TW_UINT8 interrupts_enabled;
TW_UINT8 internal_req_busy;
TW_UINT8 get_more_aens;
TW_UINT8 reset_needed;
TW_UINT8 reset_in_progress;
TW_UINT8 reset_phase1_in_progress;
TW_UINT32 flags;
TW_UINT32 sg_size_factor;
struct tw_cl_link req_q_head[TW_CLI_Q_COUNT];
TW_UINT8 *internal_req_data;
TW_UINT64 internal_req_data_phys;
TW_UINT32 max_simult_reqs;
TW_UINT32 max_aens_supported;
struct tw_cl_event_packet *aen_queue;
TW_UINT32 aen_head;
TW_UINT32 aen_tail;
TW_UINT32 aen_cur_seq_id;
TW_UINT32 aen_q_overflow;
TW_UINT32 aen_q_wrapped;
TW_UINT16 working_srl;
TW_UINT16 working_branch;
TW_UINT16 working_build;
TW_UINT16 fw_on_ctlr_srl;
TW_UINT16 fw_on_ctlr_branch;
TW_UINT16 fw_on_ctlr_build;
TW_UINT32 operating_mode;
TW_INT32 host_intr_pending;
TW_INT32 attn_intr_pending;
TW_INT32 cmd_intr_pending;
TW_INT32 resp_intr_pending;
TW_LOCK_HANDLE gen_lock_handle;
TW_LOCK_HANDLE *gen_lock;
TW_LOCK_HANDLE io_lock_handle;
TW_LOCK_HANDLE *io_lock;
#ifdef TW_OSL_CAN_SLEEP
TW_SLEEP_HANDLE sleep_handle;
#endif
struct {
TW_UINT32 lock;
TW_TIME timeout;
} ioctl_lock;
#ifdef TW_OSL_DEBUG
struct tw_cli_q_stats q_stats[TW_CLI_Q_COUNT];
#endif
};
#ifdef TW_OSL_DEBUG
#define TW_CLI_Q_INIT(ctlr, q_type) do { \
(ctlr)->q_stats[q_type].cur_len = 0; \
(ctlr)->q_stats[q_type].max_len = 0; \
} while (0)
#define TW_CLI_Q_INSERT(ctlr, q_type) do { \
struct tw_cli_q_stats *q_stats = &((ctlr)->q_stats[q_type]); \
\
if (++(q_stats->cur_len) > q_stats->max_len) \
q_stats->max_len = q_stats->cur_len; \
} while (0)
#define TW_CLI_Q_REMOVE(ctlr, q_type) \
(ctlr)->q_stats[q_type].cur_len--
#else
#define TW_CLI_Q_INIT(ctlr, q_index)
#define TW_CLI_Q_INSERT(ctlr, q_index)
#define TW_CLI_Q_REMOVE(ctlr, q_index)
#endif
static __inline TW_VOID
tw_cli_req_q_init(struct tw_cli_ctlr_context *ctlr, TW_UINT8 q_type)
{
TW_CL_Q_INIT(&(ctlr->req_q_head[q_type]));
TW_CLI_Q_INIT(ctlr, q_type);
}
static __inline TW_VOID
tw_cli_req_q_insert_head(struct tw_cli_req_context *req, TW_UINT8 q_type)
{
struct tw_cli_ctlr_context *ctlr = req->ctlr;
tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock);
TW_CL_Q_INSERT_HEAD(&(ctlr->req_q_head[q_type]), &(req->link));
TW_CLI_Q_INSERT(ctlr, q_type);
tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock);
}
static __inline TW_VOID
tw_cli_req_q_insert_tail(struct tw_cli_req_context *req, TW_UINT8 q_type)
{
struct tw_cli_ctlr_context *ctlr = req->ctlr;
tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock);
TW_CL_Q_INSERT_TAIL(&(ctlr->req_q_head[q_type]), &(req->link));
TW_CLI_Q_INSERT(ctlr, q_type);
tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock);
}
static __inline struct tw_cli_req_context *
tw_cli_req_q_remove_head(struct tw_cli_ctlr_context *ctlr, TW_UINT8 q_type)
{
struct tw_cli_req_context *req = TW_CL_NULL;
struct tw_cl_link *link;
tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock);
if ((link = TW_CL_Q_FIRST_ITEM(&(ctlr->req_q_head[q_type]))) !=
TW_CL_NULL) {
req = TW_CL_STRUCT_HEAD(link,
struct tw_cli_req_context, link);
TW_CL_Q_REMOVE_ITEM(&(ctlr->req_q_head[q_type]), &(req->link));
TW_CLI_Q_REMOVE(ctlr, q_type);
}
tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock);
return(req);
}
static __inline TW_VOID
tw_cli_req_q_remove_item(struct tw_cli_req_context *req, TW_UINT8 q_type)
{
struct tw_cli_ctlr_context *ctlr = req->ctlr;
tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock);
TW_CL_Q_REMOVE_ITEM(&(ctlr->req_q_head[q_type]), &(req->link));
TW_CLI_Q_REMOVE(ctlr, q_type);
tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock);
}
#define tw_cli_create_ctlr_event(ctlr, event_src, cmd_hdr) do { \
TW_UINT8 severity = \
GET_SEVERITY((cmd_hdr)->status_block.res__severity); \
\
tw_cl_create_event(ctlr->ctlr_handle, TW_CL_TRUE, event_src, \
(cmd_hdr)->status_block.error, \
severity, \
tw_cli_severity_string_table[severity], \
(cmd_hdr)->err_specific_desc + \
tw_osl_strlen((cmd_hdr)->err_specific_desc) + 1, \
(cmd_hdr)->err_specific_desc); \
\
tw_cli_dbg_printf(2, ctlr->ctlr_handle, \
tw_osl_cur_func(), \
"sense info: %x %x %x %x %x %x %x %x %x " \
"%x %x %x %x %x %x %x %x %x", \
(cmd_hdr)->sense_data[0], (cmd_hdr)->sense_data[1], \
(cmd_hdr)->sense_data[2], (cmd_hdr)->sense_data[3], \
(cmd_hdr)->sense_data[4], (cmd_hdr)->sense_data[5], \
(cmd_hdr)->sense_data[6], (cmd_hdr)->sense_data[7], \
(cmd_hdr)->sense_data[8], (cmd_hdr)->sense_data[9], \
(cmd_hdr)->sense_data[10], (cmd_hdr)->sense_data[11], \
(cmd_hdr)->sense_data[12], (cmd_hdr)->sense_data[13], \
(cmd_hdr)->sense_data[14], (cmd_hdr)->sense_data[15], \
(cmd_hdr)->sense_data[16], (cmd_hdr)->sense_data[17]); \
} while (0)
#endif