FreeBSD kernel CAM code
scsi_target.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <sys/poll.h>
#include <sys/vnode.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/devicestat.h>
#include <sys/proc.h>
#include <sys/types.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_periph.h>
#include <cam/cam_xpt_periph.h>
#include <cam/cam_sim.h>
#include <cam/scsi/scsi_targetio.h>
Include dependency graph for scsi_target.c:

Go to the source code of this file.

Data Structures

struct  targ_cmd_descr
 
struct  targ_softc
 

Macros

#define targ_descr   periph_priv.entries[1].ptr
 

Enumerations

enum  targ_state { TARG_STATE_RESV = 0x00 , TARG_STATE_OPENED = 0x01 , TARG_STATE_LUN_ENABLED = 0x02 }
 

Functions

 __FBSDID ("$FreeBSD$")
 
 TAILQ_HEAD (descr_queue, targ_cmd_descr)
 
static void targreadfiltdetach (struct knote *kn)
 
static int targreadfilt (struct knote *kn, long hint)
 
static cam_status targendislun (struct cam_path *path, int enable, int grp6_len, int grp7_len)
 
static cam_status targenable (struct targ_softc *softc, struct cam_path *path, int grp6_len, int grp7_len)
 
static cam_status targdisable (struct targ_softc *softc)
 
static int targusermerge (struct targ_softc *softc, struct targ_cmd_descr *descr, union ccb *ccb)
 
static int targsendccb (struct targ_softc *softc, union ccb *ccb, struct targ_cmd_descr *descr)
 
static void targdone (struct cam_periph *periph, union ccb *done_ccb)
 
static int targreturnccb (struct targ_softc *softc, union ccb *ccb)
 
static union ccbtarggetccb (struct targ_softc *softc, xpt_opcode type, int priority)
 
static void targfreeccb (struct targ_softc *softc, union ccb *ccb)
 
static struct targ_cmd_descrtarggetdescr (struct targ_softc *softc)
 
static void targasync (void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
 
static void abort_all_pending (struct targ_softc *softc)
 
static void notify_user (struct targ_softc *softc)
 
static int targcamstatus (cam_status status)
 
static size_t targccblen (xpt_opcode func_code)
 
 PERIPHDRIVER_DECLARE (targ, targdriver)
 
static MALLOC_DEFINE (M_TARG, "TARG", "TARG data")
 
static void targcdevdtor (void *data)
 
static int targopen (struct cdev *dev, int flags, int fmt, struct thread *td)
 
static int targioctl (struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
static int targpoll (struct cdev *dev, int poll_events, struct thread *td)
 
static int targkqfilter (struct cdev *dev, struct knote *kn)
 
static cam_status targctor (struct cam_periph *periph, void *arg)
 
static void targdtor (struct cam_periph *periph)
 
static int targwrite (struct cdev *dev, struct uio *uio, int ioflag)
 
static void targstart (struct cam_periph *periph, union ccb *start_ccb)
 
static int targread (struct cdev *dev, struct uio *uio, int ioflag)
 

Variables

static d_open_t targopen
 
static d_read_t targread
 
static d_write_t targwrite
 
static d_ioctl_t targioctl
 
static d_poll_t targpoll
 
static d_kqfilter_t targkqfilter
 
static struct filterops targread_filtops
 
static struct cdevsw targ_cdevsw
 
static periph_ctor_t targctor
 
static periph_dtor_t targdtor
 
static periph_start_t targstart
 
static periph_init_t targinit
 
static struct periph_driver targdriver
 

Macro Definition Documentation

◆ targ_descr

#define targ_descr   periph_priv.entries[1].ptr

Definition at line 67 of file scsi_target.c.

Enumeration Type Documentation

◆ targ_state

enum targ_state
Enumerator
TARG_STATE_RESV 
TARG_STATE_OPENED 
TARG_STATE_LUN_ENABLED 

Definition at line 71 of file scsi_target.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ abort_all_pending()

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_TARG  ,
"TARG"  ,
"TARG data"   
)
static

◆ notify_user()

static void notify_user ( struct targ_softc softc)
static

Definition at line 1067 of file scsi_target.c.

References targ_softc::read_select, and targ_softc::user_ccb_queue.

Referenced by abort_all_pending(), targdone(), and targstart().

Here is the caller graph for this function:

◆ PERIPHDRIVER_DECLARE()

PERIPHDRIVER_DECLARE ( targ  ,
targdriver   
)

◆ TAILQ_HEAD()

TAILQ_HEAD ( descr_queue  ,
targ_cmd_descr   
)

◆ targasync()

static void targasync ( void *  callback_arg,
u_int32_t  code,
struct cam_path path,
void *  arg 
)
static

Definition at line 1006 of file scsi_target.c.

Referenced by targenable().

Here is the caller graph for this function:

◆ targcamstatus()

static int targcamstatus ( cam_status  status)
static

◆ targccblen()

static size_t targccblen ( xpt_opcode  func_code)
static

Definition at line 1117 of file scsi_target.c.

References XPT_ABORT, XPT_ACCEPT_TARGET_IO, XPT_CONT_TARGET_IO, XPT_DEBUG, XPT_EN_LUN, XPT_IMMED_NOTIFY, XPT_IMMEDIATE_NOTIFY, XPT_PATH_INQ, XPT_REL_SIMQ, and XPT_SCSI_IO.

Referenced by targgetccb(), targreturnccb(), and targusermerge().

Here is the caller graph for this function:

◆ targcdevdtor()

static void targcdevdtor ( void *  data)
static

Definition at line 169 of file scsi_target.c.

References cam_periph_acquire(), cam_periph_invalidate(), cam_periph_lock, cam_periph_release(), cam_periph_unlock, cam_periph::softc, and targdisable().

Referenced by targopen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targctor()

static cam_status targctor ( struct cam_periph periph,
void *  arg 
)
static

◆ targdisable()

static cam_status targdisable ( struct targ_softc softc)
static

Definition at line 457 of file scsi_target.c.

References abort_all_pending(), CAM_DEBUG, CAM_DEBUG_PERIPH, CAM_REQ_CMP, targ_softc::path, targ_softc::state, TARG_STATE_LUN_ENABLED, and targendislun().

Referenced by targcdevdtor(), and targioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targdone()

static void targdone ( struct cam_periph periph,
union ccb done_ccb 
)
static

◆ targdtor()

static void targdtor ( struct cam_periph periph)
static

Definition at line 495 of file scsi_target.c.

References targ_softc::abort_queue, targ_softc::path, targ_softc::periph, cam_periph::softc, targfreeccb(), and targ_softc::user_ccb_queue.

Here is the call graph for this function:

◆ targenable()

◆ targendislun()

static cam_status targendislun ( struct cam_path path,
int  enable,
int  grp6_len,
int  grp7_len 
)
static

Definition at line 359 of file scsi_target.c.

References CAM_PRIORITY_NORMAL, CAM_REQ_CMP, CAM_STATUS_MASK, ccb_en_lun::ccb_h, ccb_en_lun::enable, ccb_hdr::func_code, ccb_en_lun::grp6_len, ccb_en_lun::grp7_len, ccb_hdr::status, xpt_action(), XPT_EN_LUN, xpt_print(), and xpt_setup_ccb().

Referenced by targdisable(), and targenable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targfreeccb()

static void targfreeccb ( struct targ_softc softc,
union ccb ccb 
)
static

Definition at line 954 of file scsi_target.c.

References CAM_DEBUG_PERIPH, CAM_DEBUG_PRINT, ccb::ccb_h, ccb_hdr::func_code, XPT_ACCEPT_TARGET_IO, XPT_FC_IS_QUEUED, XPT_IMMED_NOTIFY, XPT_IMMEDIATE_NOTIFY, and xpt_release_ccb().

Referenced by targdone(), targdtor(), and targreturnccb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targgetccb()

static union ccb * targgetccb ( struct targ_softc softc,
xpt_opcode  type,
int  priority 
)
static

Definition at line 931 of file scsi_target.c.

References CAM_DEBUG, CAM_DEBUG_PERIPH, ccb_hdr::cbfcnp, ccb, ccb::ccb_h, ccb_hdr::func_code, targ_softc::path, targccblen(), targdone(), targgetdescr(), and xpt_setup_ccb().

Referenced by targwrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targgetdescr()

static struct targ_cmd_descr * targgetdescr ( struct targ_softc softc)
static

Definition at line 983 of file scsi_target.c.

References targ_cmd_descr::mapinfo, and cam_periph_map_info::num_bufs_used.

Referenced by targgetccb(), and targwrite().

Here is the caller graph for this function:

◆ targioctl()

◆ targkqfilter()

static int targkqfilter ( struct cdev *  dev,
struct knote *  kn 
)
static

Definition at line 322 of file scsi_target.c.

References targ_softc::read_select, and targread_filtops.

◆ targopen()

static int targopen ( struct cdev *  dev,
int  flags,
int  fmt,
struct thread *  td 
)
static

◆ targpoll()

static int targpoll ( struct cdev *  dev,
int  poll_events,
struct thread *  td 
)
static

◆ targread()

static int targread ( struct cdev *  dev,
struct uio *  uio,
int  ioflag 
)
static

◆ targreadfilt()

static int targreadfilt ( struct knote *  kn,
long  hint 
)
static

◆ targreadfiltdetach()

static void targreadfiltdetach ( struct knote *  kn)
static

Definition at line 334 of file scsi_target.c.

References targ_softc::read_select.

◆ targreturnccb()

static int targreturnccb ( struct targ_softc softc,
union ccb ccb 
)
static

Definition at line 899 of file scsi_target.c.

References CAM_DEBUG, CAM_DEBUG_PERIPH, cam_periph_unmapmem(), ccb::ccb_h, ccb_hdr::func_code, targ_cmd_descr::mapinfo, cam_periph_map_info::num_bufs_used, targ_softc::path, ccb_hdr::retry_count, targccblen(), targfreeccb(), and xpt_print().

Referenced by targread(), and targwrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targsendccb()

static int targsendccb ( struct targ_softc softc,
union ccb ccb,
struct targ_cmd_descr descr 
)
static

◆ targstart()

static void targstart ( struct cam_periph periph,
union ccb start_ccb 
)
static

◆ targusermerge()

static int targusermerge ( struct targ_softc softc,
struct targ_cmd_descr descr,
union ccb ccb 
)
static

◆ targwrite()

Variable Documentation

◆ targ_cdevsw

struct cdevsw targ_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_open = targopen,
.d_read = targread,
.d_write = targwrite,
.d_ioctl = targioctl,
.d_poll = targpoll,
.d_name = "targ",
.d_kqfilter = targkqfilter
}
static d_kqfilter_t targkqfilter
Definition: scsi_target.c:107
static d_poll_t targpoll
Definition: scsi_target.c:106
static d_open_t targopen
Definition: scsi_target.c:102
static d_ioctl_t targioctl
Definition: scsi_target.c:105
static d_write_t targwrite
Definition: scsi_target.c:104
static d_read_t targread
Definition: scsi_target.c:103

Definition at line 116 of file scsi_target.c.

◆ targctor

periph_ctor_t targctor
static

Definition at line 133 of file scsi_target.c.

Referenced by targenable().

◆ targdriver

struct periph_driver targdriver
static
Initial value:
=
{
targinit, "targ",
TAILQ_HEAD_INITIALIZER(targdriver.units), 0
}
static struct periph_driver targdriver
Definition: scsi_target.c:158
static periph_init_t targinit
Definition: scsi_target.c:150

Definition at line 158 of file scsi_target.c.

◆ targdtor

periph_dtor_t targdtor
static

Definition at line 134 of file scsi_target.c.

Referenced by targenable().

◆ targinit

static void targinit ( void  )
static

Definition at line 150 of file scsi_target.c.

◆ targioctl

d_ioctl_t targioctl
static

Definition at line 105 of file scsi_target.c.

◆ targkqfilter

d_kqfilter_t targkqfilter
static

Definition at line 107 of file scsi_target.c.

◆ targopen

d_open_t targopen
static

Definition at line 102 of file scsi_target.c.

◆ targpoll

d_poll_t targpoll
static

Definition at line 106 of file scsi_target.c.

◆ targread

d_read_t targread
static

Definition at line 103 of file scsi_target.c.

◆ targread_filtops

struct filterops targread_filtops
static
Initial value:
= {
.f_isfd = 1,
.f_detach = targreadfiltdetach,
.f_event = targreadfilt,
}
static int targreadfilt(struct knote *kn, long hint)
Definition: scsi_target.c:344
static void targreadfiltdetach(struct knote *kn)
Definition: scsi_target.c:334

Definition at line 110 of file scsi_target.c.

Referenced by targkqfilter().

◆ targstart

periph_start_t targstart
static

Definition at line 135 of file scsi_target.c.

Referenced by targenable().

◆ targwrite

d_write_t targwrite
static

Definition at line 104 of file scsi_target.c.