FreeBSD kernel CAM code
nvme_da.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bio.h>
#include <sys/sysctl.h>
#include <sys/taskqueue.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/eventhandler.h>
#include <sys/malloc.h>
#include <sys/cons.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/sbuf.h>
#include <geom/geom.h>
#include <geom/geom_disk.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/cam_iosched.h>
#include <cam/nvme/nvme_all.h>
Include dependency graph for nvme_da.c:

Go to the source code of this file.

Data Structures

struct  nda_softc
 
struct  nda_trim_request
 

Macros

#define NDA_FLAG_STRING
 
#define NDA_Q_BIT_STRING
 
#define ccb_state   ccb_h.ppriv_field0
 
#define ccb_bp   ccb_h.ppriv_ptr1 /* For NDA_CCB_BUFFER_IO */
 
#define ccb_trim   ccb_h.ppriv_ptr1 /* For NDA_CCB_TRIM */
 
#define NDA_DEFAULT_SEND_ORDERED   1
 
#define NDA_DEFAULT_TIMEOUT   30 /* Timeout in seconds */
 
#define NDA_DEFAULT_RETRY   4
 
#define NDA_MAX_TRIM_ENTRIES   (NVME_MAX_DSM_TRIM / sizeof(struct nvme_dsm_range))/* Number of DSM trims to use, max 256 */
 

Enumerations

enum  nda_state { NDA_STATE_NORMAL }
 
enum  nda_flags { NDA_FLAG_OPEN = 0x0001 , NDA_FLAG_DIRTY = 0x0002 , NDA_FLAG_SCTX_INIT = 0x0004 }
 
enum  nda_quirks { NDA_Q_4K = 0x01 , NDA_Q_NONE = 0x00 }
 
enum  nda_ccb_state {
  NDA_CCB_BUFFER_IO = 0x01 , NDA_CCB_DUMP = 0x02 , NDA_CCB_TRIM = 0x03 , NDA_CCB_PASS = 0x04 ,
  NDA_CCB_TYPE_MASK = 0x0F
}
 

Functions

 __FBSDID ("$FreeBSD$")
 
 _Static_assert (NVME_MAX_DSM_TRIM % sizeof(struct nvme_dsm_range)==0, "NVME_MAX_DSM_TRIM must be an integral number of ranges")
 
static void ndaasync (void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
 
static void ndasysctlinit (void *context, int pending)
 
static int ndaflagssysctl (SYSCTL_HANDLER_ARGS)
 
static void ndadone (struct cam_periph *periph, union ccb *done_ccb)
 
static int ndaerror (union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
 
static void ndashutdown (void *arg, int howto)
 
static void ndasuspend (void *arg)
 
static SYSCTL_NODE (_kern_cam, OID_AUTO, nda, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "CAM Direct Access Disk driver")
 
 SYSCTL_INT (_kern_cam_nda, OID_AUTO, max_trim, CTLFLAG_RDTUN, &nda_max_trim_entries, NDA_MAX_TRIM_ENTRIES, "Maximum number of BIO_DELETE to send down as a DSM TRIM.")
 
 SYSCTL_INT (_kern_cam_nda, OID_AUTO, enable_biospeedup, CTLFLAG_RDTUN, &nda_enable_biospeedup, 0, "Enable BIO_SPEEDUP processing.")
 
 SYSCTL_INT (_kern_cam_nda, OID_AUTO, nvd_compat, CTLFLAG_RDTUN, &nda_nvd_compat, 1, "Enable creation of nvd aliases.")
 
 PERIPHDRIVER_DECLARE (nda, ndadriver)
 
static MALLOC_DEFINE (M_NVMEDA, "nvme_da", "nvme_da buffers")
 
static void nda_nvme_flush (struct nda_softc *softc, struct ccb_nvmeio *nvmeio)
 
static void nda_nvme_trim (struct nda_softc *softc, struct ccb_nvmeio *nvmeio, void *payload, uint32_t num_ranges)
 
static void nda_nvme_write (struct nda_softc *softc, struct ccb_nvmeio *nvmeio, void *payload, uint64_t lba, uint32_t len, uint32_t count)
 
static void nda_nvme_rw_bio (struct nda_softc *softc, struct ccb_nvmeio *nvmeio, struct bio *bp, uint32_t rwcmd)
 
static int ndaopen (struct disk *dp)
 
static int ndaclose (struct disk *dp)
 
static void ndaschedule (struct cam_periph *periph)
 
static int ndaioctl (struct disk *dp, u_long cmd, void *data, int fflag, struct thread *td)
 
static void ndastrategy (struct bio *bp)
 
static int ndadump (void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
 
static void ndadiskgonecb (struct disk *dp)
 
static void ndaoninvalidate (struct cam_periph *periph)
 
static void ndacleanup (struct cam_periph *periph)
 
static int ndagetattr (struct bio *bp)
 
static cam_status ndaregister (struct cam_periph *periph, void *arg)
 
static void ndastart (struct cam_periph *periph, union ccb *start_ccb)
 
static void ndaflush (void)
 

Variables

static disk_ioctl_t ndaioctl
 
static disk_strategy_t ndastrategy
 
static dumper_t ndadump
 
static periph_init_t ndainit
 
static periph_ctor_t ndaregister
 
static periph_dtor_t ndacleanup
 
static periph_start_t ndastart
 
static periph_oninv_t ndaoninvalidate
 
static int nda_send_ordered = NDA_DEFAULT_SEND_ORDERED
 
static int nda_default_timeout = NDA_DEFAULT_TIMEOUT
 
static int nda_max_trim_entries = NDA_MAX_TRIM_ENTRIES
 
static int nda_enable_biospeedup = 1
 
static int nda_nvd_compat = 1
 
static int nda_rotating_media = 0
 
static struct periph_driver ndadriver
 

Macro Definition Documentation

◆ ccb_bp

#define ccb_bp   ccb_h.ppriv_ptr1 /* For NDA_CCB_BUFFER_IO */

Definition at line 104 of file nvme_da.c.

◆ ccb_state

#define ccb_state   ccb_h.ppriv_field0

Definition at line 103 of file nvme_da.c.

◆ ccb_trim

#define ccb_trim   ccb_h.ppriv_ptr1 /* For NDA_CCB_TRIM */

Definition at line 105 of file nvme_da.c.

◆ NDA_DEFAULT_RETRY

#define NDA_DEFAULT_RETRY   4

Definition at line 174 of file nvme_da.c.

◆ NDA_DEFAULT_SEND_ORDERED

#define NDA_DEFAULT_SEND_ORDERED   1

Definition at line 168 of file nvme_da.c.

◆ NDA_DEFAULT_TIMEOUT

#define NDA_DEFAULT_TIMEOUT   30 /* Timeout in seconds */

Definition at line 171 of file nvme_da.c.

◆ NDA_FLAG_STRING

#define NDA_FLAG_STRING
Value:
"\020" \
"\001OPEN" \
"\002DIRTY" \
"\003SCTX_INIT"

Definition at line 79 of file nvme_da.c.

◆ NDA_MAX_TRIM_ENTRIES

#define NDA_MAX_TRIM_ENTRIES   (NVME_MAX_DSM_TRIM / sizeof(struct nvme_dsm_range))/* Number of DSM trims to use, max 256 */

Definition at line 177 of file nvme_da.c.

◆ NDA_Q_BIT_STRING

#define NDA_Q_BIT_STRING
Value:
"\020" \
"\001Bit 0"

Definition at line 90 of file nvme_da.c.

Enumeration Type Documentation

◆ nda_ccb_state

Enumerator
NDA_CCB_BUFFER_IO 
NDA_CCB_DUMP 
NDA_CCB_TRIM 
NDA_CCB_PASS 
NDA_CCB_TYPE_MASK 

Definition at line 94 of file nvme_da.c.

◆ nda_flags

enum nda_flags
Enumerator
NDA_FLAG_OPEN 
NDA_FLAG_DIRTY 
NDA_FLAG_SCTX_INIT 

Definition at line 74 of file nvme_da.c.

◆ nda_quirks

enum nda_quirks
Enumerator
NDA_Q_4K 
NDA_Q_NONE 

Definition at line 85 of file nvme_da.c.

◆ nda_state

enum nda_state
Enumerator
NDA_STATE_NORMAL 

Definition at line 70 of file nvme_da.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _Static_assert()

_Static_assert ( NVME_MAX_DSM_TRIM %   sizeofstruct nvme_dsm_range = =0,
"NVME_MAX_DSM_TRIM must be an integral number of ranges"   
)

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_NVMEDA  ,
"nvme_da"  ,
"nvme_da buffers"   
)
static

◆ nda_nvme_flush()

static void nda_nvme_flush ( struct nda_softc softc,
struct ccb_nvmeio nvmeio 
)
static

Definition at line 221 of file nvme_da.c.

References CAM_DIR_NONE, cam_fill_nvmeio(), ccb_nvmeio::cmd, nda_default_timeout, ndadone(), and nda_softc::nsid.

Referenced by ndaclose(), ndadump(), ndaflush(), and ndastart().

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

◆ nda_nvme_rw_bio()

static void nda_nvme_rw_bio ( struct nda_softc softc,
struct ccb_nvmeio nvmeio,
struct bio *  bp,
uint32_t  rwcmd 
)
static

Definition at line 262 of file nvme_da.c.

References CAM_DATA_BIO, CAM_DIR_IN, CAM_DIR_OUT, cam_fill_nvmeio(), ccb_nvmeio::cmd, nda_softc::disk, periph_driver::flags, nda_default_timeout, ndadone(), and nda_softc::nsid.

Referenced by ndastart().

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

◆ nda_nvme_trim()

static void nda_nvme_trim ( struct nda_softc softc,
struct ccb_nvmeio nvmeio,
void *  payload,
uint32_t  num_ranges 
)
static

Definition at line 234 of file nvme_da.c.

References CAM_DIR_OUT, cam_fill_nvmeio(), ccb_nvmeio::cmd, nda_default_timeout, ndadone(), and nda_softc::nsid.

Referenced by ndastart().

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

◆ nda_nvme_write()

static void nda_nvme_write ( struct nda_softc softc,
struct ccb_nvmeio nvmeio,
void *  payload,
uint64_t  lba,
uint32_t  len,
uint32_t  count 
)
static

Definition at line 248 of file nvme_da.c.

References CAM_DIR_OUT, cam_fill_nvmeio(), ccb_nvmeio::cmd, nda_default_timeout, ndadone(), and nda_softc::nsid.

Referenced by ndadump().

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

◆ ndaasync()

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

◆ ndacleanup()

static void ndacleanup ( struct cam_periph periph)
static

◆ ndaclose()

◆ ndadiskgonecb()

static void ndadiskgonecb ( struct disk *  dp)
static

Definition at line 579 of file nvme_da.c.

References cam_periph_release().

Referenced by ndaregister().

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

◆ ndadone()

◆ ndadump()

static int ndadump ( void *  arg,
void *  virtual,
vm_offset_t  physical,
off_t  offset,
size_t  length 
)
static

◆ ndaerror()

static int ndaerror ( union ccb ccb,
u_int32_t  cam_flags,
u_int32_t  sense_flags 
)
static

Definition at line 1270 of file nvme_da.c.

References CAM_ATA_STATUS_ERROR, CAM_CMD_TIMEOUT, CAM_DATA_RUN_ERR, cam_periph_error(), CAM_REQ_ABORTED, CAM_REQ_CMP_ERR, CAM_REQ_TERMIO, CAM_STATUS_MASK, CAM_UNREC_HBA_ERROR, ccb::ccb_h, ccb_hdr::path, cam_periph::softc, ccb_hdr::status, and xpt_path_periph().

Referenced by ndaclose(), ndadone(), and ndaflush().

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

◆ ndaflagssysctl()

static int ndaflagssysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 801 of file nvme_da.c.

References nda_softc::flags, and NDA_FLAG_STRING.

Referenced by ndasysctlinit().

Here is the caller graph for this function:

◆ ndaflush()

static void ndaflush ( void  )
static

◆ ndagetattr()

static int ndagetattr ( struct bio *  bp)
static

Definition at line 819 of file nvme_da.c.

References cam_periph_lock, cam_periph_unlock, nda_enable_biospeedup, cam_periph::path, and xpt_getattr().

Referenced by ndaregister().

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

◆ ndaioctl()

◆ ndaoninvalidate()

static void ndaoninvalidate ( struct cam_periph periph)
static

Definition at line 589 of file nvme_da.c.

References nda_softc::cam_iosched, cam_iosched_flush(), nda_softc::disk, ndaasync(), cam_periph::path, cam_periph::softc, and xpt_register_async().

Here is the call graph for this function:

◆ ndaopen()

static int ndaopen ( struct disk *  dp)
static

Definition at line 291 of file nvme_da.c.

References CAM_DEBUG, CAM_DEBUG_PERIPH, CAM_DEBUG_TRACE, cam_periph_acquire(), cam_periph_hold(), cam_periph_lock, cam_periph_release(), cam_periph_unhold(), cam_periph_unlock, nda_softc::flags, NDA_FLAG_OPEN, cam_periph::path, and cam_periph::softc.

Referenced by ndaregister().

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

◆ ndaregister()

◆ ndaschedule()

static void ndaschedule ( struct cam_periph periph)
static

Definition at line 363 of file nvme_da.c.

References nda_softc::cam_iosched, cam_iosched_schedule(), NDA_STATE_NORMAL, cam_periph::softc, and nda_softc::state.

Referenced by ndadone(), ndastart(), and ndastrategy().

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

◆ ndashutdown()

static void ndashutdown ( void *  arg,
int  howto 
)
static

Definition at line 1354 of file nvme_da.c.

References ndaflush().

Here is the call graph for this function:

◆ ndastart()

◆ ndastrategy()

static void ndastrategy ( struct bio *  bp)
static

◆ ndasuspend()

static void ndasuspend ( void *  arg)
static

Definition at line 1361 of file nvme_da.c.

References ndaflush().

Here is the call graph for this function:

◆ ndasysctlinit()

◆ PERIPHDRIVER_DECLARE()

PERIPHDRIVER_DECLARE ( nda  ,
ndadriver   
)

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _kern_cam_nda  ,
OID_AUTO  ,
enable_biospeedup  ,
CTLFLAG_RDTUN  ,
nda_enable_biospeedup,
,
"Enable BIO_SPEEDUP processing."   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _kern_cam_nda  ,
OID_AUTO  ,
max_trim  ,
CTLFLAG_RDTUN  ,
nda_max_trim_entries,
NDA_MAX_TRIM_ENTRIES  ,
"Maximum number of BIO_DELETE to send down as a DSM TRIM."   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _kern_cam_nda  ,
OID_AUTO  ,
nvd_compat  ,
CTLFLAG_RDTUN  ,
nda_nvd_compat,
,
"Enable creation of nvd aliases."   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _kern_cam  ,
OID_AUTO  ,
nda  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"CAM Direct Access Disk driver"   
)
static

Variable Documentation

◆ nda_default_timeout

int nda_default_timeout = NDA_DEFAULT_TIMEOUT
static

Definition at line 185 of file nvme_da.c.

Referenced by nda_nvme_flush(), nda_nvme_rw_bio(), nda_nvme_trim(), nda_nvme_write(), and ndaioctl().

◆ nda_enable_biospeedup

int nda_enable_biospeedup = 1
static

Definition at line 187 of file nvme_da.c.

Referenced by ndagetattr().

◆ nda_max_trim_entries

int nda_max_trim_entries = NDA_MAX_TRIM_ENTRIES
static

Definition at line 186 of file nvme_da.c.

Referenced by ndastart().

◆ nda_nvd_compat

int nda_nvd_compat = 1
static

Definition at line 188 of file nvme_da.c.

Referenced by ndaregister().

◆ nda_rotating_media

int nda_rotating_media = 0
static

Definition at line 201 of file nvme_da.c.

Referenced by ndasysctlinit().

◆ nda_send_ordered

int nda_send_ordered = NDA_DEFAULT_SEND_ORDERED
static

Definition at line 184 of file nvme_da.c.

◆ ndacleanup

periph_dtor_t ndacleanup
static

Definition at line 157 of file nvme_da.c.

Referenced by ndaasync().

◆ ndadriver

struct periph_driver ndadriver
static
Initial value:
=
{
ndainit, "nda",
TAILQ_HEAD_INITIALIZER(ndadriver.units), 0
}
static periph_init_t ndainit
Definition: nvme_da.c:151
static struct periph_driver ndadriver
Definition: nvme_da.c:203

Definition at line 203 of file nvme_da.c.

Referenced by ndaflush().

◆ ndadump

dumper_t ndadump
static

Definition at line 150 of file nvme_da.c.

Referenced by ndaflush(), and ndaregister().

◆ ndainit

static void ndainit ( void  )
static

Definition at line 151 of file nvme_da.c.

◆ ndaioctl

disk_ioctl_t ndaioctl
static

Definition at line 148 of file nvme_da.c.

Referenced by ndaregister().

◆ ndaoninvalidate

periph_oninv_t ndaoninvalidate
static

Definition at line 159 of file nvme_da.c.

Referenced by ndaasync().

◆ ndaregister

periph_ctor_t ndaregister
static

Definition at line 156 of file nvme_da.c.

Referenced by ndaasync().

◆ ndastart

periph_start_t ndastart
static

Definition at line 158 of file nvme_da.c.

Referenced by ndaasync().

◆ ndastrategy

disk_strategy_t ndastrategy
static

Definition at line 149 of file nvme_da.c.

Referenced by ndaregister().