#ifndef _PCI_MLYVAR_H_
#define _PCI_MLYVAR_H_
#define MLY_MAX_CCBS 256
#define MLY_CCBS_RESV 4
#define MLY_MAX_SEGS 17
#define MLY_SGL_SIZE (MLY_MAX_SEGS * sizeof(struct mly_sg_entry))
#define MLY_MAX_XFER ((MLY_MAX_SEGS - 1) * PAGE_SIZE)
#define MLY_PERIODIC_INTERVAL 5
#define MLY_SLOT_START 1
#define MLY_SLOT_MAX (MLY_SLOT_START + MLY_MAX_CCBS)
struct mly_btl {
int mb_flags;
int mb_state;
int mb_type;
int mb_speed;
int mb_width;
};
#define MLY_BTL_PHYSICAL 0x01
#define MLY_BTL_LOGICAL 0x02
#define MLY_BTL_PROTECTED 0x04
#define MLY_BTL_TQING 0x08
#define MLY_BTL_SCANNING 0x10
#define MLY_BTL_RESCAN 0x20
struct mly_softc;
struct mly_ccb {
union {
SLIST_ENTRY(mly_ccb) slist;
SIMPLEQ_ENTRY(mly_ccb) simpleq;
} mc_link;
u_int mc_slot;
u_int mc_flags;
u_int mc_status;
u_int mc_sense;
int32_t mc_resid;
union mly_cmd_packet *mc_packet;
bus_addr_t mc_packetphys;
void *mc_data;
size_t mc_length;
bus_dmamap_t mc_datamap;
u_int mc_sgoff;
void (*mc_complete)(struct mly_softc *, struct mly_ccb *);
void *mc_private;
};
#define MLY_CCB_DATAIN 0x01
#define MLY_CCB_DATAOUT 0x02
#define MLY_CCB_MAPPED 0x04
#define MLY_CCB_COMPLETE 0x08
struct mly_softc {
device_t mly_dv;
bus_space_handle_t mly_ioh;
bus_space_tag_t mly_iot;
bus_dma_tag_t mly_dmat;
void *mly_ih;
struct mly_sg_entry *mly_sg;
bus_addr_t mly_sg_busaddr;
bus_dma_tag_t mly_sg_dmat;
bus_dmamap_t mly_sg_dmamap;
bus_dma_segment_t mly_sg_seg;
struct mly_mmbox *mly_mmbox;
bus_addr_t mly_mmbox_busaddr;
bus_dma_tag_t mly_mmbox_dmat;
bus_dmamap_t mly_mmbox_dmamap;
bus_dma_segment_t mly_mmbox_seg;
u_int mly_mmbox_cmd_idx;
u_int mly_mmbox_sts_idx;
union mly_cmd_packet *mly_pkt;
bus_addr_t mly_pkt_busaddr;
bus_dma_tag_t mly_pkt_dmat;
bus_dmamap_t mly_pkt_dmamap;
bus_dma_segment_t mly_pkt_seg;
struct mly_ccb *mly_ccbs;
SLIST_HEAD(,mly_ccb) mly_ccb_free;
SIMPLEQ_HEAD(,mly_ccb) mly_ccb_queue;
u_int mly_ncmds;
u_int mly_hwif;
u_int mly_doorbell_true;
u_int mly_cmd_mailbox;
u_int mly_status_mailbox;
u_int mly_idbr;
u_int mly_odbr;
u_int mly_error_status;
u_int mly_interrupt_status;
u_int mly_interrupt_mask;
u_int mly_state;
struct mly_ioctl_getcontrollerinfo *mly_controllerinfo;
struct mly_param_controller *mly_controllerparam;
struct mly_btl mly_btl[MLY_MAX_CHANNELS][MLY_MAX_TARGETS];
u_int mly_event_change;
u_int mly_event_counter;
u_int mly_event_waiting;
struct lwp *mly_thread;
struct scsipi_adapter mly_adapt;
struct scsipi_channel mly_chans[MLY_MAX_CHANNELS];
u_int mly_nchans;
};
#define MLY_HWIF_I960RX 0
#define MLY_HWIF_STRONGARM 1
#define MLY_STATE_OPEN 0x01
#define MLY_STATE_MMBOX_ACTIVE 0x02
#define MLY_STATE_INITOK 0x04
static __inline u_int8_t mly_inb(struct mly_softc *, int);
static __inline u_int16_t mly_inw(struct mly_softc *, int);
static __inline u_int32_t mly_inl(struct mly_softc *, int);
static __inline void mly_outb(struct mly_softc *, int, u_int8_t);
static __inline void mly_outw(struct mly_softc *, int, u_int16_t);
static __inline void mly_outl(struct mly_softc *, int, u_int32_t);
static __inline int mly_idbr_true(struct mly_softc *, u_int8_t);
static __inline int mly_odbr_true(struct mly_softc *, u_int8_t);
static __inline int mly_error_valid(struct mly_softc *);
static __inline u_int8_t
mly_inb(struct mly_softc *mly, int off)
{
bus_space_barrier(mly->mly_iot, mly->mly_ioh, off, 1,
BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
return (bus_space_read_1(mly->mly_iot, mly->mly_ioh, off));
}
static __inline u_int16_t
mly_inw(struct mly_softc *mly, int off)
{
bus_space_barrier(mly->mly_iot, mly->mly_ioh, off, 2,
BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
return (bus_space_read_2(mly->mly_iot, mly->mly_ioh, off));
}
static __inline u_int32_t
mly_inl(struct mly_softc *mly, int off)
{
bus_space_barrier(mly->mly_iot, mly->mly_ioh, off, 4,
BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
return (bus_space_read_4(mly->mly_iot, mly->mly_ioh, off));
}
static __inline void
mly_outb(struct mly_softc *mly, int off, u_int8_t val)
{
bus_space_write_1(mly->mly_iot, mly->mly_ioh, off, val);
bus_space_barrier(mly->mly_iot, mly->mly_ioh, off, 1,
BUS_SPACE_BARRIER_WRITE);
}
static __inline void
mly_outw(struct mly_softc *mly, int off, u_int16_t val)
{
bus_space_write_2(mly->mly_iot, mly->mly_ioh, off, val);
bus_space_barrier(mly->mly_iot, mly->mly_ioh, off, 2,
BUS_SPACE_BARRIER_WRITE);
}
static __inline void
mly_outl(struct mly_softc *mly, int off, u_int32_t val)
{
bus_space_write_4(mly->mly_iot, mly->mly_ioh, off, val);
bus_space_barrier(mly->mly_iot, mly->mly_ioh, off, 4,
BUS_SPACE_BARRIER_WRITE);
}
static __inline int
mly_idbr_true(struct mly_softc *mly, u_int8_t mask)
{
u_int8_t val;
val = mly_inb(mly, mly->mly_idbr) ^ mly->mly_doorbell_true;
return ((val & mask) == mask);
}
static __inline int
mly_odbr_true(struct mly_softc *mly, u_int8_t mask)
{
return ((mly_inb(mly, mly->mly_odbr) & mask) == mask);
}
static __inline int
mly_error_valid(struct mly_softc *mly)
{
u_int8_t val;
val = mly_inb(mly, mly->mly_error_status) ^ mly->mly_doorbell_true;
return ((val & MLY_MSG_EMPTY) == 0);
}
#define MLY_LOGDEV_ID(mly, bus, target) \
(((bus) - (mly)->mly_controllerinfo->physical_channels_present) * \
MLY_MAX_TARGETS + (target))
#define MLY_LOGDEV_BUS(mly, logdev) \
(((logdev) / MLY_MAX_TARGETS) + \
(mly)->mly_controllerinfo->physical_channels_present)
#define MLY_LOGDEV_TARGET(mly, logdev) \
((logdev) % MLY_MAX_TARGETS)
#define MLY_BUS_IS_VIRTUAL(mly, bus) \
((bus) >= (mly)->mly_controllerinfo->physical_channels_present)
#define MLY_BUS_IS_VALID(mly, bus) \
(((bus) < (mly)->mly_nchans))
#endif