typedef STAILQ_HEAD(, ciss_request) cr_qhead_t;
#define CISS_MAX_REQUESTS 1024
#define CISS_MAX_LOGICAL 16
#define CISS_MAX_PHYSICAL 1024
#define CISS_INTERRUPT_COALESCE_DELAY 0
#define CISS_INTERRUPT_COALESCE_COUNT 16
#define CISS_HEARTBEAT_RATE 10
#define CISS_DRIVER_VERSION 20011201
struct ciss_request
{
STAILQ_ENTRY(ciss_request) cr_link;
int cr_onq;
struct ciss_softc *cr_sc;
void *cr_data;
u_int32_t cr_length;
bus_dmamap_t cr_datamap;
struct ciss_command *cr_cc;
uint32_t cr_ccphys;
int cr_tag;
int cr_flags;
#define CISS_REQ_MAPPED (1<<0)
#define CISS_REQ_SLEEP (1<<1)
#define CISS_REQ_POLL (1<<2)
#define CISS_REQ_DATAOUT (1<<3)
#define CISS_REQ_DATAIN (1<<4)
#define CISS_REQ_BUSY (1<<5)
#define CISS_REQ_CCB (1<<6)
void (* cr_complete)(struct ciss_request *);
void *cr_private;
int cr_sg_tag;
#define CISS_SG_MAX ((CISS_SG_FETCH_MAX << 1) | 0x1)
#define CISS_SG_1 ((CISS_SG_FETCH_1 << 1) | 0x01)
#define CISS_SG_2 ((CISS_SG_FETCH_2 << 1) | 0x01)
#define CISS_SG_4 ((CISS_SG_FETCH_4 << 1) | 0x01)
#define CISS_SG_8 ((CISS_SG_FETCH_8 << 1) | 0x01)
#define CISS_SG_16 ((CISS_SG_FETCH_16 << 1) | 0x01)
#define CISS_SG_32 ((CISS_SG_FETCH_32 << 1) | 0x01)
#define CISS_SG_NONE ((CISS_SG_FETCH_NONE << 1) | 0x01)
};
#define CISS_MAX_SG_ELEMENTS 65
#define CISS_COMMAND_ALIGN 32
#define CISS_COMMAND_SG_LENGTH (sizeof(struct ciss_sg_entry) * CISS_MAX_SG_ELEMENTS)
#define CISS_COMMAND_ALLOC_SIZE (roundup2(sizeof(struct ciss_command) + CISS_COMMAND_SG_LENGTH, CISS_COMMAND_ALIGN))
struct ciss_ldrive
{
union ciss_device_address cl_address;
union ciss_device_address *cl_controller;
int cl_status;
#define CISS_LD_NONEXISTENT 0
#define CISS_LD_ONLINE 1
#define CISS_LD_OFFLINE 2
int cl_update;
struct ciss_bmic_id_ldrive *cl_ldrive;
struct ciss_bmic_id_lstatus *cl_lstatus;
struct ciss_ldrive_geometry cl_geometry;
char cl_name[16];
};
struct ciss_pdrive
{
union ciss_device_address cp_address;
int cp_online;
};
#define CISS_PHYSICAL_SHIFT 5
#define CISS_PHYSICAL_BASE (1 << CISS_PHYSICAL_SHIFT)
#define CISS_MAX_PHYSTGT 256
#define CISS_IS_PHYSICAL(bus) (bus >= CISS_PHYSICAL_BASE)
#define CISS_CAM_TO_PBUS(bus) (bus - CISS_PHYSICAL_BASE)
struct ciss_softc
{
device_t ciss_dev;
struct cdev *ciss_dev_t;
struct resource *ciss_regs_resource;
int ciss_regs_rid;
bus_space_handle_t ciss_regs_bhandle;
bus_space_tag_t ciss_regs_btag;
struct resource *ciss_cfg_resource;
int ciss_cfg_rid;
struct ciss_config_table *ciss_cfg;
struct ciss_perf_config *ciss_perf;
struct ciss_bmic_id_table *ciss_id;
u_int32_t ciss_heartbeat;
int ciss_heart_attack;
int ciss_msi;
struct resource *ciss_irq_resource;
int ciss_irq_rid[CISS_MSI_COUNT];
void *ciss_intr;
bus_dma_tag_t ciss_parent_dmat;
bus_dma_tag_t ciss_buffer_dmat;
u_int32_t ciss_interrupt_mask;
uint64_t *ciss_reply;
int ciss_cycle;
int ciss_rqidx;
bus_dma_tag_t ciss_reply_dmat;
bus_dmamap_t ciss_reply_map;
uint32_t ciss_reply_phys;
int ciss_max_requests;
struct ciss_request ciss_request[CISS_MAX_REQUESTS];
void *ciss_command;
bus_dma_tag_t ciss_command_dmat;
bus_dmamap_t ciss_command_map;
u_int32_t ciss_command_phys;
cr_qhead_t ciss_free;
cr_qhead_t ciss_notify;
struct proc *ciss_notify_thread;
struct callout ciss_periodic;
struct ciss_request *ciss_periodic_notify;
struct mtx ciss_mtx;
struct ciss_ldrive **ciss_logical;
struct ciss_pdrive **ciss_physical;
union ciss_device_address *ciss_controllers;
int ciss_max_bus_number;
int ciss_max_logical_bus;
int ciss_max_physical_bus;
int ciss_max_physical_target;
struct cam_devq *ciss_cam_devq;
struct cam_sim **ciss_cam_sim;
int ciss_soft_reset;
int ciss_flags;
#define CISS_FLAG_NOTIFY_OK (1<<0)
#define CISS_FLAG_CONTROL_OPEN (1<<1)
#define CISS_FLAG_ABORTING (1<<2)
#define CISS_FLAG_RUNNING (1<<3)
#define CISS_FLAG_BUSY (1<<4)
#define CISS_FLAG_FAKE_SYNCH (1<<16)
#define CISS_FLAG_BMIC_ABORT (1<<17)
#define CISS_FLAG_THREAD_SHUT (1<<20)
struct ciss_qstat ciss_qstat[CISSQ_COUNT];
};
#ifdef CISS_DEBUG
# define debug(level, fmt, args...) \
do { \
if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); \
} while(0)
# define debug_called(level) \
do { \
if (level <= CISS_DEBUG) printf("%s: called\n", __func__); \
} while(0)
# define debug_struct(s) printf(" SIZE %s: %zu\n", #s, sizeof(struct s))
# define debug_union(s) printf(" SIZE %s: %zu\n", #s, sizeof(union s))
# define debug_type(s) printf(" SIZE %s: %zu\n", #s, sizeof(s))
# define debug_field(s, f) printf(" OFFSET %s.%s: %d\n", #s, #f, ((int)&(((struct s *)0)->f)))
# define debug_const(c) printf(" CONST %s %jd/0x%jx\n", #c, (intmax_t)c, (intmax_t)c);
#else
# define debug(level, fmt, args...)
# define debug_called(level)
# define debug_struct(s)
# define debug_union(s)
# define debug_type(s)
# define debug_field(s, f)
# define debug_const(c)
#endif
#define ciss_printf(sc, fmt, args...) device_printf(sc->ciss_dev, fmt , ##args)
#define CISSQ_ADD(sc, qname) \
do { \
struct ciss_qstat *qs = &(sc)->ciss_qstat[qname]; \
\
qs->q_length++; \
if (qs->q_length > qs->q_max) \
qs->q_max = qs->q_length; \
} while(0)
#define CISSQ_REMOVE(sc, qname) (sc)->ciss_qstat[qname].q_length--
#define CISSQ_INIT(sc, qname) \
do { \
sc->ciss_qstat[qname].q_length = 0; \
sc->ciss_qstat[qname].q_max = 0; \
} while(0)
#define CISSQ_REQUEST_QUEUE(name, index) \
static __inline void \
ciss_initq_ ## name (struct ciss_softc *sc) \
{ \
STAILQ_INIT(&sc->ciss_ ## name); \
CISSQ_INIT(sc, index); \
} \
static __inline void \
ciss_enqueue_ ## name (struct ciss_request *cr) \
{ \
\
STAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
CISSQ_ADD(cr->cr_sc, index); \
cr->cr_onq = index; \
} \
static __inline void \
ciss_requeue_ ## name (struct ciss_request *cr) \
{ \
\
STAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
CISSQ_ADD(cr->cr_sc, index); \
cr->cr_onq = index; \
} \
static __inline struct ciss_request * \
ciss_dequeue_ ## name (struct ciss_softc *sc) \
{ \
struct ciss_request *cr; \
\
if ((cr = STAILQ_FIRST(&sc->ciss_ ## name)) != NULL) { \
STAILQ_REMOVE_HEAD(&sc->ciss_ ## name, cr_link); \
CISSQ_REMOVE(sc, index); \
cr->cr_onq = -1; \
} \
return(cr); \
} \
struct hack
CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY);
static __inline void
ciss_enqueue_complete(struct ciss_request *ac, cr_qhead_t *head)
{
STAILQ_INSERT_TAIL(head, ac, cr_link);
}
static __inline struct ciss_request *
ciss_dequeue_complete(struct ciss_softc *sc, cr_qhead_t *head)
{
struct ciss_request *ac;
if ((ac = STAILQ_FIRST(head)) != NULL)
STAILQ_REMOVE_HEAD(head, cr_link);
return(ac);
}
static __inline void
padstr(char *targ, const char *src, int len)
{
while (len-- > 0) {
if (*src != 0) {
*targ++ = *src++;
} else {
*targ++ = ' ';
}
}
}
#define ciss_report_request(a, b, c) \
_ciss_report_request(a, b, c, __FUNCTION__)