#define TWE_DRIVER_VERSION_STRING "1.50.01.002"
#ifdef TWE_DEBUG
#define debug(level, fmt, args...) \
do { \
if (level <= TWE_DEBUG) kprintf("%s: " fmt "\n", __func__ , ##args); \
} while(0)
#define debug_called(level) \
do { \
if (level <= TWE_DEBUG) kprintf("%s: called\n", __func__); \
} while(0)
#else
#define debug(level, fmt, args...)
#define debug_called(level)
#endif
struct twe_drive
{
u_int32_t td_size;
int td_cylinders;
int td_heads;
int td_sectors;
int td_sys_unit;
int td_twe_unit;
u_int8_t td_state;
u_int8_t td_type;
device_t td_disk;
};
struct twed_softc
{
device_t twed_dev;
cdev_t twed_dev_t;
struct twe_softc *twed_controller;
struct twe_drive *twed_drive;
struct disk twed_disk;
struct devstat twed_stats;
int twed_flags;
#define TWED_OPEN (1<<0)
};
struct twe_request
{
int tr_tag;
void *tr_data;
void *tr_realdata;
size_t tr_length;
TAILQ_ENTRY(twe_request) tr_link;
struct twe_softc *tr_sc;
int tr_status;
#define TWE_CMD_SETUP 0
#define TWE_CMD_BUSY 1
#define TWE_CMD_COMPLETE 2
#define TWE_CMD_ERROR 3
int tr_flags;
#define TWE_CMD_DATAIN (1<<0)
#define TWE_CMD_DATAOUT (1<<1)
#define TWE_CMD_ALIGNBUF (1<<2)
#define TWE_CMD_SLEEPER (1<<3)
#define TWE_CMD_IMMEDIATE (1<<4)
#define TWE_CMD_MAPPED (1<<5)
#define TWE_CMD_IN_PROGRESS (1<<6)
void (* tr_complete)(struct twe_request *tr);
void *tr_private;
TWE_PLATFORM_REQUEST
};
#define TWE_FIND_COMMAND(tr) \
(TWE_Command *)((u_int8_t *)(tr)->tr_sc->twe_cmd + \
((tr)->tr_tag * sizeof(TWE_Command)))
#define TWE_FIND_COMMANDPHYS(tr) ((tr)->tr_sc->twe_cmdphys + \
((tr)->tr_tag * sizeof(TWE_Command)))
struct twe_softc
{
TAILQ_HEAD(, twe_request) twe_free;
struct bio_queue_head twe_bioq;
TAILQ_HEAD(, twe_request) twe_ready;
TAILQ_HEAD(, twe_request) twe_busy;
TAILQ_HEAD(, twe_request) twe_complete;
struct twe_request *twe_lookup[TWE_Q_LENGTH];
struct twe_drive twe_drive[TWE_MAX_UNITS];
u_int16_t twe_aen_queue[TWE_Q_LENGTH];
int twe_aen_head, twe_aen_tail;
int twe_wait_aen;
char twe_aen_buf[80];
int twe_state;
#define TWE_STATE_INTEN (1<<0)
#define TWE_STATE_SHUTDOWN (1<<1)
#define TWE_STATE_OPEN (1<<2)
#define TWE_STATE_SUSPEND (1<<3)
#define TWE_STATE_FRZN (1<<4)
#define TWE_STATE_CTLR_BUSY (1<<5)
#define TWE_STATE_DETACHING (1<<6)
int twe_host_id;
struct twe_qstat twe_qstat[TWEQ_COUNT];
TWE_PLATFORM_SOFTC
};
extern int twe_setup(struct twe_softc *sc);
extern void twe_init(struct twe_softc *sc);
extern void twe_deinit(struct twe_softc *sc);
extern void twe_intr(struct twe_softc *sc);
extern void twe_startio(struct twe_softc *sc);
extern int twe_start(struct twe_request *tr);
extern int twe_dump_blocks(struct twe_softc *sc, int unit,
u_int64_t lba, void *data, int nblks);
extern int twe_ioctl(struct twe_softc *sc, u_long cmd,
void *addr);
extern void twe_describe_controller(struct twe_softc *sc);
extern void twe_print_controller(struct twe_softc *sc);
extern void twe_enable_interrupts(struct twe_softc *sc);
extern void twe_disable_interrupts(struct twe_softc *sc);
extern int twe_attach_drive(struct twe_softc *sc,
struct twe_drive *dr);
extern int twe_detach_drive(struct twe_softc *sc,
int unit);
extern void twe_clear_pci_parity_error(struct twe_softc *sc);
extern void twe_clear_pci_abort(struct twe_softc *sc);
extern void twed_intr(struct bio *bp);
extern struct twe_request *twe_allocate_request(struct twe_softc *sc, int tag);
extern void twe_free_request(struct twe_request *tr);
extern int twe_map_request(struct twe_request *tr);
extern void twe_unmap_request(struct twe_request *tr);
#define TWEQ_ADD(sc, qname) \
do { \
struct twe_qstat *qs = &(sc)->twe_qstat[qname]; \
\
qs->q_length++; \
if (qs->q_length > qs->q_max) \
qs->q_max = qs->q_length; \
} while(0)
#define TWEQ_REMOVE(sc, qname) \
do { \
struct twe_qstat *qs = &(sc)->twe_qstat[qname]; \
\
qs->q_length--; \
if (qs->q_length < qs->q_min) \
qs->q_min = qs->q_length; \
} while(0)
#define TWEQ_INIT(sc, qname) \
do { \
sc->twe_qstat[qname].q_length = 0; \
sc->twe_qstat[qname].q_max = 0; \
sc->twe_qstat[qname].q_min = 0xFFFFFFFF; \
} while(0)
#define TWEQ_REQUEST_QUEUE(name, index) \
static __inline void \
twe_initq_ ## name (struct twe_softc *sc) \
{ \
TAILQ_INIT(&sc->twe_ ## name); \
TWEQ_INIT(sc, index); \
} \
static __inline void \
twe_enqueue_ ## name (struct twe_request *tr) \
{ \
TAILQ_INSERT_TAIL(&tr->tr_sc->twe_ ## name, tr, tr_link); \
TWEQ_ADD(tr->tr_sc, index); \
} \
static __inline void \
twe_requeue_ ## name (struct twe_request *tr) \
{ \
TAILQ_INSERT_HEAD(&tr->tr_sc->twe_ ## name, tr, tr_link); \
TWEQ_ADD(tr->tr_sc, index); \
} \
static __inline struct twe_request * \
twe_dequeue_ ## name (struct twe_softc *sc) \
{ \
struct twe_request *tr; \
\
if ((tr = TAILQ_FIRST(&sc->twe_ ## name)) != NULL) { \
TAILQ_REMOVE(&sc->twe_ ## name, tr, tr_link); \
TWEQ_REMOVE(sc, index); \
} \
return(tr); \
} \
static __inline void \
twe_remove_ ## name (struct twe_request *tr) \
{ \
TAILQ_REMOVE(&tr->tr_sc->twe_ ## name, tr, tr_link); \
TWEQ_REMOVE(tr->tr_sc, index); \
}
TWEQ_REQUEST_QUEUE(free, TWEQ_FREE)
TWEQ_REQUEST_QUEUE(ready, TWEQ_READY)
TWEQ_REQUEST_QUEUE(busy, TWEQ_BUSY)
TWEQ_REQUEST_QUEUE(complete, TWEQ_COMPLETE)
static __inline void
twe_initq_bio(struct twe_softc *sc)
{
bioq_init(&sc->twe_bioq);
TWEQ_INIT(sc, TWEQ_BIO);
}
static __inline void
twe_enqueue_bio(struct twe_softc *sc, struct bio *bio)
{
bioqdisksort(&sc->twe_bioq, bio);
TWEQ_ADD(sc, TWEQ_BIO);
}
static __inline
struct bio *
twe_dequeue_bio(struct twe_softc *sc)
{
struct bio *bio;
if ((bio = bioq_first(&sc->twe_bioq)) != NULL) {
bioq_remove(&sc->twe_bioq, bio);
TWEQ_REMOVE(sc, TWEQ_BIO);
}
return(bio);
}