#ifndef _CAM_CAM_SIM_H
#define _CAM_CAM_SIM_H 1
#ifdef _KERNEL
#ifndef _SYS_SPINLOCK_H_
#include <sys/spinlock.h>
#endif
struct cam_sim;
struct cam_devq;
typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
typedef void (*sim_poll_func)(struct cam_sim *sim);
typedef struct lock sim_lock;
extern sim_lock sim_mplock;
void cam_sim_lock(sim_lock *lock);
void cam_sim_unlock(sim_lock *lock);
int cam_sim_cond_lock(sim_lock *lock);
void cam_sim_cond_unlock(sim_lock *lock, int doun);
void sim_lock_assert_owned(sim_lock *lock);
void sim_lock_assert_unowned(sim_lock *lock);
int sim_lock_sleep(void *ident, int flags, const char *wmesg,
int timo, sim_lock *lock);
struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
void cam_simq_release(struct cam_devq *devq);
struct cam_sim * cam_sim_alloc(sim_action_func sim_action,
sim_poll_func sim_poll,
const char *sim_name,
void *softc,
u_int32_t unit,
sim_lock *lock,
int max_dev_transactions,
int max_tagged_dev_transactions,
struct cam_devq *queue);
void cam_sim_free(struct cam_sim *sim);
void cam_sim_release(struct cam_sim *sim, int flags);
void cam_sim_set_max_tags(struct cam_sim *sim, int max_tags);
#define CAM_SIM_SOFTC 0x0002
void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
static __inline u_int32_t cam_sim_path(struct cam_sim *sim);
static __inline const char *cam_sim_name(struct cam_sim *sim);
static __inline void * cam_sim_softc(struct cam_sim *sim);
static __inline u_int32_t cam_sim_unit(struct cam_sim *sim);
static __inline u_int32_t cam_sim_bus(struct cam_sim *sim);
#define spriv_ptr0 sim_priv.entries[0].ptr
#define spriv_ptr1 sim_priv.entries[1].ptr
#define spriv_field0 sim_priv.entries[0].field
#define spriv_field1 sim_priv.entries[1].field
struct cam_sim {
sim_action_func sim_action;
sim_poll_func sim_poll;
const char *sim_name;
void *softc;
sim_lock *lock;
struct spinlock sim_spin;
TAILQ_HEAD(, ccb_hdr) sim_doneq;
TAILQ_ENTRY(cam_sim) links;
u_int32_t path_id;
u_int32_t unit_number;
u_int32_t bus_id;
int max_tagged_dev_openings;
int max_dev_openings;
u_int32_t flags;
#define CAM_SIM_REL_TIMEOUT_PENDING 0x01
#define CAM_SIM_MPSAFE 0x02
#define CAM_SIM_ON_DONEQ 0x04
#define CAM_SIM_DEREGISTERED 0x08
struct callout callout;
struct cam_devq *devq;
int refcount;
SLIST_HEAD(,ccb_hdr) ccb_freeq;
u_int max_ccbs;
u_int ccb_count;
};
#define CAM_SIM_LOCK(sim) cam_sim_lock((sim)->lock)
#define CAM_SIM_UNLOCK(sim) cam_sim_unlock((sim)->lock)
#define CAM_SIM_COND_LOCK(sim) cam_sim_cond_lock((sim)->lock)
#define CAM_SIM_COND_UNLOCK(sim, doun) cam_sim_cond_unlock((sim)->lock, doun)
static __inline u_int32_t
cam_sim_path(struct cam_sim *sim)
{
return (sim->path_id);
}
static __inline const char *
cam_sim_name(struct cam_sim *sim)
{
return (sim->sim_name);
}
static __inline void *
cam_sim_softc(struct cam_sim *sim)
{
return (sim->softc);
}
static __inline u_int32_t
cam_sim_unit(struct cam_sim *sim)
{
return (sim->unit_number);
}
static __inline u_int32_t
cam_sim_bus(struct cam_sim *sim)
{
return (sim->bus_id);
}
#endif
#endif