/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003 Silicon Graphics International Corp.4* Copyright (c) 2014-2017 Alexander Motin <[email protected]>5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions, and the following disclaimer,12* without modification.13* 2. Redistributions in binary form must reproduce at minimum a disclaimer14* substantially similar to the "NO WARRANTY" disclaimer below15* ("Disclaimer") and any redistribution must be conditioned upon16* including a substantially similar Disclaimer requirement for further17* binary redistribution.18*19* NO WARRANTY20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR23* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,28* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING29* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE30* POSSIBILITY OF SUCH DAMAGES.31*32* $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend.h#2 $33*/34/*35* CTL backend driver definitions36*37* Author: Ken Merry <[email protected]>38*/3940#ifndef _CTL_BACKEND_H_41#define _CTL_BACKEND_H_4243#include <cam/ctl/ctl_ioctl.h>44#include <sys/nv.h>4546typedef enum {47CTL_LUN_SERSEQ_OFF,48CTL_LUN_SERSEQ_SOFT,49CTL_LUN_SERSEQ_READ,50CTL_LUN_SERSEQ_ON51} ctl_lun_serseq;5253#ifdef _KERNEL5455#define CTL_BACKEND_DECLARE(name, driver) \56static int name ## _modevent(module_t mod, int type, void *data) \57{ \58switch (type) { \59case MOD_LOAD: \60return (ctl_backend_register( \61(struct ctl_backend_driver *)data)); \62break; \63case MOD_UNLOAD: \64return (ctl_backend_deregister( \65(struct ctl_backend_driver *)data)); \66break; \67default: \68return EOPNOTSUPP; \69} \70return 0; \71} \72static moduledata_t name ## _mod = { \73#name, \74name ## _modevent, \75(void *)&driver \76}; \77DECLARE_MODULE(name, name ## _mod, SI_SUB_CONFIGURE, SI_ORDER_FOURTH); \78MODULE_DEPEND(name, ctl, 1, 1, 1); \79MODULE_DEPEND(name, cam, 1, 1, 1)8081struct ctl_be_lun;82typedef void (*be_callback_t)(struct ctl_be_lun *be_lun);8384/*85* The lun_type field is the SCSI device type of this particular LUN. In86* general, this should be T_DIRECT, although backends will want to create87* a processor LUN, typically at LUN 0. See scsi_all.h for the defines for88* the various SCSI device types.89*90* The flags are described above.91*92* The be_lun field is the backend driver's own context that will get93* passsed back so that it can tell which LUN CTL is referencing.94*95* maxlba is the maximum accessible LBA on the LUN. Note that this is96* different from the capacity of the array. capacity = maxlba + 197*98* blocksize is the size, in bytes, of each LBA on the LUN. In general99* this should be 512. In theory CTL should be able to handle other block100* sizes. Host application software may not deal with it very well, though.101*102* pblockexp is the log2() of number of LBAs on the LUN per physical sector.103*104* pblockoff is the lowest LBA on the LUN aligned to physical sector.105*106* ublockexp is the log2() of number of LBAs on the LUN per UNMAP block.107*108* ublockoff is the lowest LBA on the LUN aligned to UNMAP block.109*110* atomicblock is the number of blocks that can be written atomically.111*112* opttxferlen is the number of blocks that can be written in one operation.113*114* req_lun_id is the requested LUN ID. CTL only pays attention to this115* field if the CTL_LUN_FLAG_ID_REQ flag is set. If the requested LUN ID is116* not available, the LUN addition will fail. If a particular LUN ID isn't117* requested, the first available LUN ID will be allocated.118*119* serial_num is the device serial number returned in the SCSI INQUIRY VPD120* page 0x80. This should be a unique, per-shelf value. The data inside121* this field should be ASCII only, left aligned, and any unused space122* should be padded out with ASCII spaces. This field should NOT be NULL123* terminated.124*125* device_id is the T10 device identifier returned in the SCSI INQUIRY VPD126* page 0x83. This should be a unique, per-LUN value. The data inside127* this field should be ASCII only, left aligned, and any unused space128* should be padded with ASCII spaces. This field should NOT be NULL129* terminated.130*131* The lun_shutdown() method is the callback for the ctl_remove_lun()132* call. It is called when all outstanding I/O for that LUN has been133* completed and CTL has deleted the resources for that LUN. When the CTL134* backend gets this call, it can safely free its per-LUN resources.135*136* The be field is a pointer to the ctl_backend_driver structure, which137* contains the backend methods to be called by CTL.138*139* The ctl_lun field is for CTL internal use only, and should not be used140* by the backend.141*142* The links field is for CTL internal use only, and should not be used by143* the backend.144*/145struct ctl_be_lun {146uint8_t lun_type; /* passed to CTL */147ctl_backend_lun_flags flags; /* passed to CTL */148ctl_lun_serseq serseq; /* passed to CTL */149uint64_t maxlba; /* passed to CTL */150uint32_t blocksize; /* passed to CTL */151uint16_t pblockexp; /* passed to CTL */152uint16_t pblockoff; /* passed to CTL */153uint16_t ublockexp; /* passed to CTL */154uint16_t ublockoff; /* passed to CTL */155uint32_t atomicblock; /* passed to CTL */156uint32_t opttxferlen; /* passed to CTL */157uint32_t req_lun_id; /* passed to CTL */158uint32_t lun_id; /* returned from CTL */159uint8_t serial_num[CTL_SN_LEN]; /* passed to CTL */160uint8_t device_id[CTL_DEVID_LEN];/* passed to CTL */161be_callback_t lun_shutdown; /* passed to CTL */162struct ctl_backend_driver *be; /* passed to CTL */163void *ctl_lun; /* used by CTL */164nvlist_t *options; /* passed to CTL */165STAILQ_ENTRY(ctl_be_lun) links; /* used by CTL */166};167168typedef enum {169CTL_BE_FLAG_NONE = 0x00, /* no flags */170CTL_BE_FLAG_HAS_CONFIG = 0x01, /* can do config reads, writes */171} ctl_backend_flags;172173typedef int (*be_init_t)(void);174typedef int (*be_shutdown_t)(void);175typedef int (*be_func_t)(union ctl_io *io);176typedef void (*be_vfunc_t)(union ctl_io *io);177typedef int (*be_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag,178struct thread *td);179typedef int (*be_luninfo_t)(struct ctl_be_lun *be_lun, struct sbuf *sb);180typedef uint64_t (*be_lunattr_t)(struct ctl_be_lun *be_lun, const char *attrname);181182struct ctl_backend_driver {183char name[CTL_BE_NAME_LEN]; /* passed to CTL */184ctl_backend_flags flags; /* passed to CTL */185be_init_t init; /* passed to CTL */186be_shutdown_t shutdown; /* passed to CTL */187be_func_t data_submit; /* passed to CTL */188be_func_t config_read; /* passed to CTL */189be_func_t config_write; /* passed to CTL */190be_ioctl_t ioctl; /* passed to CTL */191be_luninfo_t lun_info; /* passed to CTL */192be_lunattr_t lun_attr; /* passed to CTL */193#ifdef CS_BE_CONFIG_MOVE_DONE_IS_NOT_USED194be_func_t config_move_done; /* passed to backend */195#endif196#if 0197be_vfunc_t config_write_done; /* passed to backend */198#endif199STAILQ_ENTRY(ctl_backend_driver) links; /* used by CTL */200};201202int ctl_backend_register(struct ctl_backend_driver *be);203int ctl_backend_deregister(struct ctl_backend_driver *be);204struct ctl_backend_driver *ctl_backend_find(char *backend_name);205206/*207* To add a LUN, call ctl_add_lun().208*/209int ctl_add_lun(struct ctl_be_lun *be_lun);210211/*212* To remove a LUN, first call ctl_remove_lun().213* You will get the lun_shutdown() callback when all214* I/O to the LUN has completed and the LUN has been deleted.215*/216int ctl_remove_lun(struct ctl_be_lun *be_lun);217218/*219* To start a LUN (transition from powered off to powered on state) call220* ctl_start_lun(). To stop a LUN (transition from powered on to powered221* off state) call ctl_stop_lun().222*/223int ctl_start_lun(struct ctl_be_lun *be_lun);224int ctl_stop_lun(struct ctl_be_lun *be_lun);225226/*227* Methods to notify about media and tray status changes.228*/229int ctl_lun_no_media(struct ctl_be_lun *be_lun);230int ctl_lun_has_media(struct ctl_be_lun *be_lun);231int ctl_lun_ejected(struct ctl_be_lun *be_lun);232233/*234* Called on LUN HA role change.235*/236int ctl_lun_primary(struct ctl_be_lun *be_lun);237int ctl_lun_secondary(struct ctl_be_lun *be_lun);238239/*240* Let the backend notify the initiators about changes.241*/242void ctl_lun_capacity_changed(struct ctl_be_lun *be_lun);243244/*245* Populate unique ID fields in NVMe namespace data for a LUN.246*/247void ctl_lun_nsdata_ids(struct ctl_be_lun *be_lun,248struct nvme_namespace_data *nsdata);249250/*251* Populate the NVMe namespace identification descriptor list for a LUN.252*/253void ctl_lun_nvme_ids(struct ctl_be_lun *be_lun, void *data);254255#endif /* _KERNEL */256#endif /* _CTL_BACKEND_H_ */257258/*259* vim: ts=8260*/261262263