46#include <sys/kernel.h>
48#include <sys/malloc.h>
50#include <sys/sysctl.h>
51#include <machine/atomic.h>
52#include <machine/bus.h>
68#define io_ptr spriv_ptr1
91#define CFCS_BAD_CCB_FLAGS (CAM_DATA_ISPHYS | CAM_CDB_PHYS | CAM_SENSE_PTR | \
111SYSCTL_NODE(_kern_cam, OID_AUTO, ctl2cam, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
112 "CAM Target Layer SIM frontend");
113SYSCTL_INT(_kern_cam_ctl2cam, OID_AUTO, max_sense, CTLFLAG_RW,
132 bzero(softc,
sizeof(*softc));
150 printf(
"%s: ctl_port_register() failed with error %d!\n",
159 if (port->
wwnn == 0) {
160 uint64_t random_bits;
162 arc4rand(&random_bits,
sizeof(random_bits), 0);
163 softc->
wwnn = (random_bits & 0x0000000fffffff00ULL) |
164 0x5000000000000000ULL |
174 if (softc->
devq == NULL) {
175 printf(
"%s: error allocating devq\n", __func__);
183 if (softc->
sim == NULL) {
184 printf(
"%s: error allocating SIM\n", __func__);
190 printf(
"%s: error registering SIM\n", __func__);
199 printf(
"%s: error creating path\n", __func__);
210 else if (softc->
devq)
229 printf(
"%s: cam_sim port deregistration failed\n", __func__);
249 printf(
"%s: unable to allocate CCB for rescan\n", __func__);
256 printf(
"%s: can't allocate path for rescan\n", __func__);
287 bus_dma_segment_t cam_sg_entry, *cam_sglist;
289 int cam_sg_count, ctl_sg_count, cam_sg_start;
292 int ctl_watermark, cam_watermark;
317 cam_sg_start = cam_sg_count;
320 for (i = 0, len_seen = 0; i < cam_sg_count; i++) {
321 if ((len_seen + cam_sglist[i].ds_len) >=
328 len_seen += cam_sglist[i].ds_len;
333 cam_sglist = &cam_sg_entry;
355 cam_watermark = cam_sg_offset;
356 for (i = cam_sg_start, j = 0;
357 i < cam_sg_count && j < ctl_sg_count;) {
358 uint8_t *cam_ptr, *ctl_ptr;
360 len_to_copy = MIN(cam_sglist[i].ds_len - cam_watermark,
361 ctl_sglist[j].
len - ctl_watermark);
363 cam_ptr = (uint8_t *)(uintptr_t)cam_sglist[i].ds_addr;
364 cam_ptr = cam_ptr + cam_watermark;
369 panic(
"need to implement bus address support");
371 kern_ptr = bus_to_virt(kern_sglist[j].
addr);
374 ctl_ptr = (uint8_t *)ctl_sglist[j].
addr;
375 ctl_ptr = ctl_ptr + ctl_watermark;
380 __func__, len_to_copy));
383 bcopy(ctl_ptr, cam_ptr, len_to_copy);
386 __func__, len_to_copy));
389 bcopy(cam_ptr, ctl_ptr, len_to_copy);
395 cam_watermark += len_to_copy;
396 if (cam_sglist[i].ds_len == cam_watermark) {
401 ctl_watermark += len_to_copy;
402 if (ctl_sglist[j].
len == ctl_watermark) {
504 printf(
"%s: bad CCB flags %#x (all flags %#x)\n",
522 printf(
"%s: can't allocate ctl_io\n", __func__);
570 printf(
"%s: unhandled tag type %#x!!\n", __func__,
575 printf(
"%s: WARNING: CDB len %d > ctl_io space %zd\n",
584 printf(
"%s: func %d: error %d returned by "
585 "ctl_queue()!\n", __func__,
596 union ccb *abort_ccb;
652 printf(
"%s: unhandled tag type %#x!!\n", __func__,
658 printf(
"%s func %d: error %d returned by "
659 "ctl_queue()!\n", __func__,
671 scsi = &
cts->proto_specific.scsi;
672 fc = &
cts->xport_specific.fc;
678 cts->transport_version = 0;
735 printf(
"%s func %d: error %d returned by "
736 "ctl_queue()!\n", __func__,
759 cpi->
maxio = 1024 * 1024;
786 printf(
"%s: unsupported CCB type %#x\n", __func__,
void cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended)
#define CAM_TARGET_WILDCARD
#define CAM_EXTLUN_BYTE_SWIZZLE(lun)
#define CTS_FC_VALID_PORT
#define CTS_SCSI_FLAGS_TAG_ENB
#define CTS_SCSI_VALID_TQ
#define CTS_FC_VALID_WWNN
#define CAM_TAG_ACTION_NONE
#define CTS_FC_VALID_WWPN
static __inline uint8_t * scsiio_cdb_ptr(struct ccb_scsiio *ccb)
#define CTS_FC_VALID_SPEED
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, struct mtx *mtx, int max_dev_transactions, int max_tagged_dev_transactions, struct cam_devq *queue)
allocate a new sim and fill in the details
struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions)
void cam_sim_free(struct cam_sim *sim, int free_devq)
frees up the sim
void cam_simq_free(struct cam_devq *devq)
static __inline u_int32_t cam_sim_path(const struct cam_sim *sim)
static __inline void * cam_sim_softc(const struct cam_sim *sim)
static __inline const char * cam_sim_name(const struct cam_sim *sim)
int xpt_bus_deregister(path_id_t pathid)
cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
u_int32_t xpt_freeze_devq(struct cam_path *path, u_int count)
void xpt_rescan(union ccb *ccb)
void xpt_done(union ccb *done_ccb)
union ccb * xpt_alloc_ccb_nowait(void)
void xpt_free_path(struct cam_path *path)
int xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus)
void xpt_free_ccb(union ccb *free_ccb)
uint32_t ctl_decode_lun(uint64_t encoded)
void ctl_free_io(union ctl_io *io)
union ctl_io * ctl_alloc_io_nowait(void *pool_ref)
void ctl_datamove_done(union ctl_io *io, bool samethr)
int ctl_queue(union ctl_io *io)
void ctl_zero_io(union ctl_io *io)
#define CTL_RETVAL_COMPLETE
#define CTL_DEBUG_PRINT(X)
int ctl_port_deregister(struct ctl_port *port)
void ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid, uint64_t wwnn, int wwpn_valid, uint64_t wwpn)
void ctl_port_offline(struct ctl_port *port)
int ctl_port_register(struct ctl_port *port)
CTL_FRONTEND_DECLARE(ctlcfcs, cfcs_frontend)
static void cfcs_online(void *arg)
SYSCTL_NODE(_kern_cam, OID_AUTO, ctl2cam, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "CAM Target Layer SIM frontend")
static void cfcs_datamove(union ctl_io *io)
void cfcs_action(struct cam_sim *sim, union ccb *ccb)
SYSCTL_INT(_kern_cam_ctl2cam, OID_AUTO, max_sense, CTLFLAG_RW, &cfcs_max_sense, 0, "Maximum sense data size")
static int cfcs_init(void)
static int cfcs_max_sense
static void cfcs_offline(void *arg)
struct cfcs_softc cfcs_softc
static void cfcs_onoffline(void *arg, int online)
static int cfcs_shutdown(void)
static struct ctl_frontend cfcs_frontend
static void cfcs_poll(struct cam_sim *sim)
static void cfcs_done(union ctl_io *io)
#define CFCS_BAD_CCB_FLAGS
#define CTL_PRIV_FRONTEND
struct ccb_trans_settings_mmc * cts
#define MSG_HEAD_OF_QUEUE_TASK
union ccb_pathinq::@2 xport_specific
struct ccb_pathinq_settings_fc fc
u_int32_t base_transfer_speed
struct scsi_sense_data sense_data
char name[CTL_DRIVER_NAME_LEN]
union ctl_priv ctl_private[CTL_NUM_PRIV]
struct ctl_frontend * frontend
void(* fe_datamove)(union ctl_io *io)
void(* fe_done)(union ctl_io *io)
struct scsi_sense_data sense_data
uint8_t cdb[CTL_MAX_CDBLEN]
ctl_task_type task_action
struct ccb_trans_settings cts
struct ccb_calc_geometry ccg