/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003 Silicon Graphics International Corp.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions, and the following disclaimer,11* without modification.12* 2. Redistributions in binary form must reproduce at minimum a disclaimer13* substantially similar to the "NO WARRANTY" disclaimer below14* ("Disclaimer") and any redistribution must be conditioned upon15* including a substantially similar Disclaimer requirement for further16* binary redistribution.17*18* NO WARRANTY19* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS20* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT21* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR22* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT23* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING28* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE29* POSSIBILITY OF SUCH DAMAGES.30*31* $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend.c#3 $32*/33/*34* CTL backend driver registration routines35*36* Author: Ken Merry <[email protected]>37*/3839#include <sys/param.h>40#include <sys/systm.h>41#include <sys/kernel.h>42#include <sys/types.h>43#include <sys/malloc.h>44#include <sys/lock.h>45#include <sys/mutex.h>46#include <sys/condvar.h>47#include <sys/queue.h>48#include <sys/sysctl.h>4950#include <cam/scsi/scsi_all.h>51#include <cam/scsi/scsi_da.h>52#include <cam/ctl/ctl_io.h>53#include <cam/ctl/ctl.h>54#include <cam/ctl/ctl_frontend.h>55#include <cam/ctl/ctl_backend.h>56#include <cam/ctl/ctl_ioctl.h>57#include <cam/ctl/ctl_ha.h>58#include <cam/ctl/ctl_private.h>59#include <cam/ctl/ctl_debug.h>6061int62ctl_backend_register(struct ctl_backend_driver *be)63{64struct ctl_softc *softc = control_softc;65struct ctl_backend_driver *be_tmp;66int error;6768/* Sanity check, make sure this isn't a duplicate registration. */69mtx_lock(&softc->ctl_lock);70STAILQ_FOREACH(be_tmp, &softc->be_list, links) {71if (strcmp(be_tmp->name, be->name) == 0) {72mtx_unlock(&softc->ctl_lock);73return (-1);74}75}76mtx_unlock(&softc->ctl_lock);77#ifdef CS_BE_CONFIG_MOVE_DONE_IS_NOT_USED78be->config_move_done = ctl_config_move_done;79#endif8081/* Call the backend's initialization routine. */82if (be->init != NULL) {83if ((error = be->init()) != 0) {84printf("%s backend init error: %d\n",85be->name, error);86return (error);87}88}8990mtx_lock(&softc->ctl_lock);91STAILQ_INSERT_TAIL(&softc->be_list, be, links);92softc->num_backends++;93mtx_unlock(&softc->ctl_lock);94return (0);95}9697int98ctl_backend_deregister(struct ctl_backend_driver *be)99{100struct ctl_softc *softc = control_softc;101int error;102103/* Call the backend's shutdown routine. */104if (be->shutdown != NULL) {105if ((error = be->shutdown()) != 0) {106printf("%s backend shutdown error: %d\n",107be->name, error);108return (error);109}110}111112mtx_lock(&softc->ctl_lock);113STAILQ_REMOVE(&softc->be_list, be, ctl_backend_driver, links);114softc->num_backends--;115mtx_unlock(&softc->ctl_lock);116return (0);117}118119struct ctl_backend_driver *120ctl_backend_find(char *backend_name)121{122struct ctl_softc *softc = control_softc;123struct ctl_backend_driver *be_tmp;124125mtx_lock(&softc->ctl_lock);126STAILQ_FOREACH(be_tmp, &softc->be_list, links) {127if (strcmp(be_tmp->name, backend_name) == 0) {128mtx_unlock(&softc->ctl_lock);129return (be_tmp);130}131}132mtx_unlock(&softc->ctl_lock);133134return (NULL);135}136137138