FreeBSD kernel CAM code
cam_periph.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/bio.h>
#include <sys/conf.h>
#include <sys/devctl.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/devicestat.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_queue.h>
#include <cam/cam_xpt_periph.h>
#include <cam/cam_xpt_internal.h>
#include <cam/cam_periph.h>
#include <cam/cam_debug.h>
#include <cam/cam_sim.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_message.h>
#include <cam/scsi/scsi_pass.h>
Include dependency graph for cam_periph.c:

Go to the source code of this file.

Macros

#define saved_ccb_ptr   ppriv_ptr0
 
#define CAM_PERIPH_DEVD_MSG_SIZE   256
 

Functions

 __FBSDID ("$FreeBSD$")
 
static u_int camperiphnextunit (struct periph_driver *p_drv, u_int newunit, bool wired, path_id_t pathid, target_id_t target, lun_id_t lun)
 
static u_int camperiphunit (struct periph_driver *p_drv, path_id_t pathid, target_id_t target, lun_id_t lun, const char *sn)
 
static void camperiphdone (struct cam_periph *periph, union ccb *done_ccb)
 
static void camperiphfree (struct cam_periph *periph)
 
static int camperiphscsistatuserror (union ccb *ccb, union ccb **orig_ccb, cam_flags camflags, u_int32_t sense_flags, int *openings, u_int32_t *relsim_flags, u_int32_t *timeout, u_int32_t *action, const char **action_string)
 
static int camperiphscsisenseerror (union ccb *ccb, union ccb **orig_ccb, cam_flags camflags, u_int32_t sense_flags, int *openings, u_int32_t *relsim_flags, u_int32_t *timeout, u_int32_t *action, const char **action_string)
 
static void cam_periph_devctl_notify (union ccb *ccb)
 
static MALLOC_DEFINE (M_CAMPERIPH, "CAM periph", "CAM peripheral buffers")
 
 TUNABLE_INT ("kern.cam.periph_selto_delay", &periph_selto_delay)
 
 TUNABLE_INT ("kern.cam.periph_noresrc_delay", &periph_noresrc_delay)
 
 TUNABLE_INT ("kern.cam.periph_busy_delay", &periph_busy_delay)
 
 SYSCTL_UINT (_kern_cam, OID_AUTO, mapmem_thresh, CTLFLAG_RWTUN, &periph_mapmem_thresh, 0, "Threshold for user-space buffer mapping")
 
void periphdriver_register (void *data)
 
int periphdriver_unregister (void *data)
 
void periphdriver_init (int level)
 
cam_status cam_periph_alloc (periph_ctor_t *periph_ctor, periph_oninv_t *periph_oninvalidate, periph_dtor_t *periph_dtor, periph_start_t *periph_start, char *name, cam_periph_type type, struct cam_path *path, ac_callback_t *ac_callback, ac_code code, void *arg)
 
struct cam_periphcam_periph_find (struct cam_path *path, char *name)
 
int cam_periph_list (struct cam_path *path, struct sbuf *sb)
 
int cam_periph_acquire (struct cam_periph *periph)
 
void cam_periph_doacquire (struct cam_periph *periph)
 
void cam_periph_release_locked_buses (struct cam_periph *periph)
 
void cam_periph_release_locked (struct cam_periph *periph)
 
void cam_periph_release (struct cam_periph *periph)
 
int cam_periph_hold (struct cam_periph *periph, int priority)
 
void cam_periph_unhold (struct cam_periph *periph)
 
void cam_periph_invalidate (struct cam_periph *periph)
 
int cam_periph_mapmem (union ccb *ccb, struct cam_periph_map_info *mapinfo, u_int maxmap)
 
void cam_periph_unmapmem (union ccb *ccb, struct cam_periph_map_info *mapinfo)
 
int cam_periph_ioctl (struct cam_periph *periph, u_long cmd, caddr_t addr, int(*error_routine)(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags))
 
static void cam_periph_done_panic (struct cam_periph *periph, union ccb *done_ccb)
 
static void cam_periph_done (struct cam_periph *periph, union ccb *done_ccb)
 
static void cam_periph_ccbwait (union ccb *ccb)
 
int cam_periph_runccb (union ccb *ccb, int(*error_routine)(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags), cam_flags camflags, u_int32_t sense_flags, struct devstat *ds)
 
void cam_freeze_devq (struct cam_path *path)
 
u_int32_t cam_release_devq (struct cam_path *path, u_int32_t relsim_flags, u_int32_t openings, u_int32_t arg, int getcount_only)
 
void cam_periph_async (struct cam_periph *periph, u_int32_t code, struct cam_path *path, void *arg)
 
void cam_periph_bus_settle (struct cam_periph *periph, u_int bus_settle)
 
void cam_periph_freeze_after_event (struct cam_periph *periph, struct timeval *event_time, u_int duration_ms)
 
int cam_periph_error (union ccb *ccb, cam_flags camflags, u_int32_t sense_flags)
 
int cam_periph_invalidate_sysctl (SYSCTL_HANDLER_ARGS)
 

Variables

static int nperiph_drivers
 
static int initialized = 0
 
struct periph_driver ** periph_drivers
 
static int periph_selto_delay = 1000
 
static int periph_noresrc_delay = 500
 
static int periph_busy_delay = 500
 
static u_int periph_mapmem_thresh = 65536
 

Macro Definition Documentation

◆ CAM_PERIPH_DEVD_MSG_SIZE

#define CAM_PERIPH_DEVD_MSG_SIZE   256

Definition at line 2103 of file cam_periph.c.

◆ saved_ccb_ptr

#define saved_ccb_ptr   ppriv_ptr0

Definition at line 1361 of file cam_periph.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ cam_freeze_devq()

void cam_freeze_devq ( struct cam_path path)

Definition at line 1329 of file cam_periph.c.

References CAM_DEBUG, CAM_DEBUG_TRACE, CAM_DEV_QFREEZE, ccb_hdr::flags, ccb_hdr::func_code, ccb_hdr::path, xpt_action(), XPT_NOOP, and xpt_setup_ccb().

Referenced by cam_periph_freeze_after_event(), pmpdone(), pmpfreeze(), probestart(), and scsi_dev_async().

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

◆ cam_periph_acquire()

◆ cam_periph_alloc()

cam_status cam_periph_alloc ( periph_ctor_t periph_ctor,
periph_oninv_t periph_oninvalidate,
periph_dtor_t periph_dtor,
periph_start_t periph_start,
char *  name,
cam_periph_type  type,
struct cam_path path,
ac_callback_t ac_callback,
ac_code  code,
void *  arg 
)

◆ cam_periph_async()

void cam_periph_async ( struct cam_periph periph,
u_int32_t  code,
struct cam_path path,
void *  arg 
)

Definition at line 1471 of file cam_periph.c.

References AC_LOST_DEVICE, and cam_periph_invalidate().

Referenced by adaasync(), cdasync(), chasync(), daasync(), enc_async(), ndaasync(), passasync(), pmpasync(), ptasync(), saasync(), sddaasync(), and sgasync().

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

◆ cam_periph_bus_settle()

void cam_periph_bus_settle ( struct cam_periph periph,
u_int  bus_settle 
)

◆ cam_periph_ccbwait()

static void cam_periph_ccbwait ( union ccb ccb)
static

Definition at line 1187 of file cam_periph.c.

References cam_periph_done_panic(), CAM_REQ_INPROG, CAM_STATUS_MASK, CAM_UNQUEUED_INDEX, ccb_hdr::cbfcnp, ccb::ccb_h, ccb_hdr::func_code, cam_pinfo::index, ccb_hdr::path, ccb_hdr::pinfo, ccb_hdr::status, XPT_FC_QUEUED, and xpt_path_sleep.

Referenced by cam_periph_runccb().

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

◆ cam_periph_devctl_notify()

◆ cam_periph_doacquire()

void cam_periph_doacquire ( struct cam_periph periph)

Definition at line 432 of file cam_periph.c.

References cam_periph::refcount, xpt_lock_buses(), and xpt_unlock_buses().

Referenced by passclose(), passrejectios(), probestart(), and xpt_run_allocq().

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

◆ cam_periph_done()

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

Definition at line 1177 of file cam_periph.c.

References cam_periph_done_panic(), ccb_hdr::cbfcnp, ccb::ccb_h, ccb_hdr::path, and xpt_path_assert.

Referenced by cam_periph_runccb().

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

◆ cam_periph_done_panic()

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

Definition at line 1170 of file cam_periph.c.

Referenced by cam_periph_ccbwait(), and cam_periph_done().

Here is the caller graph for this function:

◆ cam_periph_error()

int cam_periph_error ( union ccb ccb,
cam_flags  camflags,
u_int32_t  sense_flags 
)

Definition at line 1864 of file cam_periph.c.

References AC_LOST_DEVICE, AC_UNIT_ATTENTION, CAM_ATA_STATUS_ERROR, CAM_AUTOSENSE_FAIL, CAM_BDR_SENT, CAM_BUSY, CAM_CMD_TIMEOUT, CAM_DATA_RUN_ERR, CAM_DEBUG_INFO, CAM_DEBUGGED, CAM_DEV_NOT_THERE, CAM_DEV_QFRZN, CAM_EPF_ALL, cam_error_print(), CAM_ESF_ALL, CAM_FUNC_NOTAVAIL, CAM_LUN_INVALID, CAM_LUN_WILDCARD, CAM_MSG_REJECT_REC, CAM_NO_HBA, CAM_PATH_INVALID, cam_periph_devctl_notify(), CAM_PERIPH_INVALID, CAM_PROVIDE_FAIL, cam_release_devq(), CAM_REQ_ABORTED, CAM_REQ_CMP, CAM_REQ_CMP_ERR, CAM_REQ_INVALID, CAM_REQ_TERMIO, CAM_REQ_TOO_BIG, CAM_REQUEUE_REQ, CAM_RESRC_UNAVAIL, CAM_RETRY_SELTO, CAM_SCSI_BUS_RESET, CAM_SCSI_STATUS_ERROR, CAM_SEL_TIMEOUT, CAM_SMP_STATUS_ERROR, CAM_STATUS_MASK, CAM_TID_INVALID, CAM_UA_ABORT, CAM_UA_TERMIO, CAM_UNCOR_PARITY, CAM_UNEXP_BUSFREE, CAM_UNREC_HBA_ERROR, camperiphscsistatuserror(), ccb, ccb::ccb_h, ccb::crcn, ccb_rescan::flags, cam_periph::flags, ccb_hdr::func_code, ccb_hdr::path, periph_busy_delay, periph_noresrc_delay, periph_selto_delay, RELSIM_RELEASE_AFTER_TIMEOUT, ccb_hdr::retry_count, SF_NO_PRINT, SF_NO_RETRY, SF_PRINT_ALWAYS, SSQ_LOST, SSQ_PRINT_SENSE, SSQ_RESCAN, SSQ_UA, ccb_hdr::status, xpt_action(), xpt_alloc_ccb_nowait(), xpt_async(), xpt_create_path(), xpt_free_path(), xpt_path_lun_id(), xpt_path_path_id(), xpt_path_periph(), xpt_path_target_id(), xpt_print(), xpt_rescan(), and XPT_SCAN_TGT.

Referenced by adaerror(), aprobedone(), camperiphdone(), cderror(), cherror(), dadump(), daerror(), enc_error(), ndadump(), ndaerror(), nvme_probe_done(), passerror(), pmpdone(), probedone(), pterror(), sadone(), saerror(), sddadump(), sddaerror(), and sgerror().

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

◆ cam_periph_find()

struct cam_periph * cam_periph_find ( struct cam_path path,
char *  name 
)

Definition at line 340 of file cam_periph.c.

References cam_periph_assert, cam_periph::path, periph_drivers, xpt_lock_buses(), xpt_path_comp(), and xpt_unlock_buses().

Referenced by ata_scan_lun(), cam_periph_alloc(), ctlfe_lun_enable(), ctlfe_offline(), ctlfe_online(), mmc_scan_lun(), nvme_scan_lun(), scsi_scan_lun(), targbhasync(), and targenable().

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

◆ cam_periph_freeze_after_event()

void cam_periph_freeze_after_event ( struct cam_periph periph,
struct timeval *  event_time,
u_int  duration_ms 
)

Definition at line 1496 of file cam_periph.c.

References cam_freeze_devq(), cam_release_devq(), cam_periph::path, and RELSIM_RELEASE_AFTER_TIMEOUT.

Referenced by cam_periph_bus_settle(), and proberegister().

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

◆ cam_periph_hold()

int cam_periph_hold ( struct cam_periph periph,
int  priority 
)

◆ cam_periph_invalidate()

◆ cam_periph_invalidate_sysctl()

int cam_periph_invalidate_sysctl ( SYSCTL_HANDLER_ARGS  )

Definition at line 2182 of file cam_periph.c.

References cam_periph_invalidate(), cam_periph_lock, and cam_periph_unlock.

Referenced by adasysctlinit(), dasysctlinit(), and ndasysctlinit().

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

◆ cam_periph_ioctl()

int cam_periph_ioctl ( struct cam_periph periph,
u_long  cmd,
caddr_t  addr,
int(*)(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags)  error_routine 
)

◆ cam_periph_list()

int cam_periph_list ( struct cam_path path,
struct sbuf *  sb 
)

Definition at line 370 of file cam_periph.c.

References cam_periph::path, periph_drivers, cam_periph::periph_name, cam_periph::unit_number, xpt_lock_buses(), xpt_path_comp(), and xpt_unlock_buses().

Referenced by ses_elmdevname_callback().

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

◆ cam_periph_mapmem()

◆ cam_periph_release()

◆ cam_periph_release_locked()

◆ cam_periph_release_locked_buses()

void cam_periph_release_locked_buses ( struct cam_periph periph)

Definition at line 443 of file cam_periph.c.

References cam_periph_assert, camperiphfree(), and cam_periph::refcount.

Referenced by cam_periph_release_locked().

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

◆ cam_periph_runccb()

int cam_periph_runccb ( union ccb ccb,
int(*)(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags)  error_routine,
cam_flags  camflags,
u_int32_t  sense_flags,
struct devstat *  ds 
)

◆ cam_periph_unhold()

void cam_periph_unhold ( struct cam_periph periph)

◆ cam_periph_unmapmem()

◆ cam_release_devq()

◆ camperiphdone()

◆ camperiphfree()

◆ camperiphnextunit()

static u_int camperiphnextunit ( struct periph_driver p_drv,
u_int  newunit,
bool  wired,
path_id_t  pathid,
target_id_t  target,
lun_id_t  lun 
)
static

Definition at line 542 of file cam_periph.c.

References periph_driver::driver_name, cam_periph::path, cam_periph::periph_name, cam_periph::unit_number, and xpt_print().

Referenced by camperiphunit().

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

◆ camperiphscsisenseerror()

◆ camperiphscsistatuserror()

static int camperiphscsistatuserror ( union ccb ccb,
union ccb **  orig_ccb,
cam_flags  camflags,
u_int32_t  sense_flags,
int *  openings,
u_int32_t *  relsim_flags,
u_int32_t *  timeout,
u_int32_t *  action,
const char **  action_string 
)
static

◆ camperiphunit()

static u_int camperiphunit ( struct periph_driver p_drv,
path_id_t  pathid,
target_id_t  target,
lun_id_t  lun,
const char *  sn 
)
static

Definition at line 600 of file cam_periph.c.

References camperiphnextunit(), periph_driver::driver_name, and cam_periph::periph_name.

Referenced by cam_periph_alloc().

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

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_CAMPERIPH  ,
"CAM periph"  ,
"CAM peripheral buffers"   
)
static

◆ periphdriver_init()

void periphdriver_init ( int  level)

Definition at line 184 of file cam_periph.c.

References CAM_PERIPH_DRV_EARLY, periph_driver::flags, periph_driver::init, initialized, and periph_drivers.

Referenced by xpt_config(), and xpt_finishconfig_task().

Here is the caller graph for this function:

◆ periphdriver_register()

void periphdriver_register ( void *  data)

Definition at line 115 of file cam_periph.c.

References CAM_PERIPH_DRV_EARLY, periph_driver::flags, periph_driver::init, initialized, nperiph_drivers, periph_drivers, xpt_lock_buses(), and xpt_unlock_buses().

Referenced by ctlfeinitialize().

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

◆ periphdriver_unregister()

int periphdriver_unregister ( void *  data)

Definition at line 152 of file cam_periph.c.

References CAM_PERIPH_DRV_EARLY, periph_driver::deinit, periph_driver::driver_name, periph_driver::flags, initialized, nperiph_drivers, periph_drivers, xpt_lock_buses(), and xpt_unlock_buses().

Referenced by ctlfeshutdown().

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

◆ SYSCTL_UINT()

SYSCTL_UINT ( _kern_cam  ,
OID_AUTO  ,
mapmem_thresh  ,
CTLFLAG_RWTUN  ,
periph_mapmem_thresh,
,
"Threshold for user-space buffer mapping"   
)

◆ TUNABLE_INT() [1/3]

TUNABLE_INT ( "kern.cam.periph_busy_delay"  ,
periph_busy_delay 
)

◆ TUNABLE_INT() [2/3]

TUNABLE_INT ( "kern.cam.periph_noresrc_delay"  ,
periph_noresrc_delay 
)

◆ TUNABLE_INT() [3/3]

TUNABLE_INT ( "kern.cam.periph_selto_delay"  ,
periph_selto_delay 
)

Variable Documentation

◆ initialized

int initialized = 0
static

Definition at line 98 of file cam_periph.c.

Referenced by periphdriver_init(), periphdriver_register(), and periphdriver_unregister().

◆ nperiph_drivers

int nperiph_drivers
static

Definition at line 97 of file cam_periph.c.

Referenced by periphdriver_register(), and periphdriver_unregister().

◆ periph_busy_delay

int periph_busy_delay = 500
static

Definition at line 107 of file cam_periph.c.

Referenced by cam_periph_error().

◆ periph_drivers

◆ periph_mapmem_thresh

u_int periph_mapmem_thresh = 65536
static

Definition at line 110 of file cam_periph.c.

Referenced by cam_periph_mapmem().

◆ periph_noresrc_delay

int periph_noresrc_delay = 500
static

Definition at line 105 of file cam_periph.c.

Referenced by cam_periph_error().

◆ periph_selto_delay

int periph_selto_delay = 1000
static

Definition at line 103 of file cam_periph.c.

Referenced by cam_periph_error().