Deleted Added
full compact
ctl.c (247814) ctl.c (249009)
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * Copyright (c) 2012 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Edward Tomasz Napierala
7 * under sponsorship from the FreeBSD Foundation.
8 *

--- 28 unchanged lines hidden (view full) ---

37 * CAM Target Layer, a SCSI device emulation subsystem.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#define _CTL_C
43
44#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3 * Copyright (c) 2012 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Edward Tomasz Napierala
7 * under sponsorship from the FreeBSD Foundation.
8 *

--- 28 unchanged lines hidden (view full) ---

37 * CAM Target Layer, a SCSI device emulation subsystem.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#define _CTL_C
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 247814 2013-03-04 21:18:45Z ken $");
45__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl.c 249009 2013-04-02 09:42:42Z trasz $");
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/types.h>
51#include <sys/kthread.h>
52#include <sys/bio.h>
53#include <sys/fcntl.h>
54#include <sys/lock.h>
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/types.h>
51#include <sys/kthread.h>
52#include <sys/bio.h>
53#include <sys/fcntl.h>
54#include <sys/lock.h>
55#include <sys/module.h>
55#include <sys/mutex.h>
56#include <sys/condvar.h>
57#include <sys/malloc.h>
58#include <sys/conf.h>
59#include <sys/ioccom.h>
60#include <sys/queue.h>
61#include <sys/sbuf.h>
62#include <sys/endian.h>

--- 270 unchanged lines hidden (view full) ---

333/*
334 * Serial number (0x80), device id (0x83), and supported pages (0x00)
335 */
336#define SCSI_EVPD_NUM_SUPPORTED_PAGES 3
337
338static void ctl_isc_event_handler(ctl_ha_channel chanel, ctl_ha_event event,
339 int param);
340static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest);
56#include <sys/mutex.h>
57#include <sys/condvar.h>
58#include <sys/malloc.h>
59#include <sys/conf.h>
60#include <sys/ioccom.h>
61#include <sys/queue.h>
62#include <sys/sbuf.h>
63#include <sys/endian.h>

--- 270 unchanged lines hidden (view full) ---

334/*
335 * Serial number (0x80), device id (0x83), and supported pages (0x00)
336 */
337#define SCSI_EVPD_NUM_SUPPORTED_PAGES 3
338
339static void ctl_isc_event_handler(ctl_ha_channel chanel, ctl_ha_event event,
340 int param);
341static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest);
341static void ctl_init(void);
342static int ctl_init(void);
342void ctl_shutdown(void);
343static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td);
344static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td);
345static void ctl_ioctl_online(void *arg);
346static void ctl_ioctl_offline(void *arg);
347static int ctl_ioctl_targ_enable(void *arg, struct ctl_id targ_id);
348static int ctl_ioctl_targ_disable(void *arg, struct ctl_id targ_id);
349static int ctl_ioctl_lun_enable(void *arg, struct ctl_id targ_id, int lun_id);

--- 103 unchanged lines hidden (view full) ---

453 .d_close = ctl_close,
454 .d_ioctl = ctl_ioctl,
455 .d_name = "ctl",
456};
457
458
459MALLOC_DEFINE(M_CTL, "ctlmem", "Memory used for CTL");
460
343void ctl_shutdown(void);
344static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td);
345static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td);
346static void ctl_ioctl_online(void *arg);
347static void ctl_ioctl_offline(void *arg);
348static int ctl_ioctl_targ_enable(void *arg, struct ctl_id targ_id);
349static int ctl_ioctl_targ_disable(void *arg, struct ctl_id targ_id);
350static int ctl_ioctl_lun_enable(void *arg, struct ctl_id targ_id, int lun_id);

--- 103 unchanged lines hidden (view full) ---

454 .d_close = ctl_close,
455 .d_ioctl = ctl_ioctl,
456 .d_name = "ctl",
457};
458
459
460MALLOC_DEFINE(M_CTL, "ctlmem", "Memory used for CTL");
461
461/*
462 * If we have the CAM SIM, we may or may not have another SIM that will
463 * cause CTL to get initialized. If not, we need to initialize it.
464 */
465SYSINIT(ctl_init, SI_SUB_CONFIGURE, SI_ORDER_THIRD, ctl_init, NULL);
462static int ctl_module_event_handler(module_t, int /*modeventtype_t*/, void *);
466
463
464static moduledata_t ctl_moduledata = {
465 "ctl",
466 ctl_module_event_handler,
467 NULL
468};
469
470DECLARE_MODULE(ctl, ctl_moduledata, SI_SUB_CONFIGURE, SI_ORDER_THIRD);
471MODULE_VERSION(ctl, 1);
472
467static void
468ctl_isc_handler_finish_xfer(struct ctl_softc *ctl_softc,
469 union ctl_ha_msg *msg_info)
470{
471 struct ctl_scsiio *ctsio;
472
473 if (msg_info->hdr.original_sc == NULL) {
474 printf("%s: original_sc == NULL!\n", __func__);

--- 462 unchanged lines hidden (view full) ---

937
938 sense = &dest->scsiio.sense_data;
939 bcopy(&src->scsi.sense_data, sense, sizeof(*sense));
940 dest->scsiio.scsi_status = src->scsi.scsi_status;
941 dest->scsiio.sense_len = src->scsi.sense_len;
942 dest->io_hdr.status = src->hdr.status;
943}
944
473static void
474ctl_isc_handler_finish_xfer(struct ctl_softc *ctl_softc,
475 union ctl_ha_msg *msg_info)
476{
477 struct ctl_scsiio *ctsio;
478
479 if (msg_info->hdr.original_sc == NULL) {
480 printf("%s: original_sc == NULL!\n", __func__);

--- 462 unchanged lines hidden (view full) ---

943
944 sense = &dest->scsiio.sense_data;
945 bcopy(&src->scsi.sense_data, sense, sizeof(*sense));
946 dest->scsiio.scsi_status = src->scsi.scsi_status;
947 dest->scsiio.sense_len = src->scsi.sense_len;
948 dest->io_hdr.status = src->hdr.status;
949}
950
945static void
951static int
946ctl_init(void)
947{
948 struct ctl_softc *softc;
949 struct ctl_io_pool *internal_pool, *emergency_pool, *other_pool;
950 struct ctl_frontend *fe;
951 struct ctl_lun *lun;
952 uint8_t sc_id =0;
953#if 0
954 int i;
955#endif
952ctl_init(void)
953{
954 struct ctl_softc *softc;
955 struct ctl_io_pool *internal_pool, *emergency_pool, *other_pool;
956 struct ctl_frontend *fe;
957 struct ctl_lun *lun;
958 uint8_t sc_id =0;
959#if 0
960 int i;
961#endif
956 int retval;
962 int error, retval;
957 //int isc_retval;
958
959 retval = 0;
960 ctl_pause_rtr = 0;
961 rcv_sync_msg = 0;
962
963 /* If we're disabled, don't initialize. */
964 if (ctl_disable != 0)
963 //int isc_retval;
964
965 retval = 0;
966 ctl_pause_rtr = 0;
967 rcv_sync_msg = 0;
968
969 /* If we're disabled, don't initialize. */
970 if (ctl_disable != 0)
965 return;
971 return (0);
966
967 control_softc = malloc(sizeof(*control_softc), M_DEVBUF,
968 M_WAITOK | M_ZERO);
969 softc = control_softc;
970
971 softc->dev = make_dev(&ctl_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600,
972 "cam/ctl");
973

--- 12 unchanged lines hidden (view full) ---

986 SYSCTL_STATIC_CHILDREN(_kern_cam), OID_AUTO, "ctl",
987 CTLFLAG_RD, 0, "CAM Target Layer");
988
989 if (softc->sysctl_tree == NULL) {
990 printf("%s: unable to allocate sysctl tree\n", __func__);
991 destroy_dev(softc->dev);
992 free(control_softc, M_DEVBUF);
993 control_softc = NULL;
972
973 control_softc = malloc(sizeof(*control_softc), M_DEVBUF,
974 M_WAITOK | M_ZERO);
975 softc = control_softc;
976
977 softc->dev = make_dev(&ctl_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600,
978 "cam/ctl");
979

--- 12 unchanged lines hidden (view full) ---

992 SYSCTL_STATIC_CHILDREN(_kern_cam), OID_AUTO, "ctl",
993 CTLFLAG_RD, 0, "CAM Target Layer");
994
995 if (softc->sysctl_tree == NULL) {
996 printf("%s: unable to allocate sysctl tree\n", __func__);
997 destroy_dev(softc->dev);
998 free(control_softc, M_DEVBUF);
999 control_softc = NULL;
994 return;
1000 return (ENOMEM);
995 }
996
997 SYSCTL_ADD_INT(&softc->sysctl_ctx,
998 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
999 "inquiry_pq_no_lun", CTLFLAG_RW,
1000 &softc->inquiry_pq_no_lun, 0,
1001 "Report no lun possible for invalid LUNs");
1002

--- 45 unchanged lines hidden (view full) ---

1048 * We don't bother calling these with ctl_lock held here, because,
1049 * in theory, no one else can try to do anything while we're in our
1050 * module init routine.
1051 */
1052 if (ctl_pool_create(softc, CTL_POOL_INTERNAL, CTL_POOL_ENTRIES_INTERNAL,
1053 &internal_pool)!= 0){
1054 printf("ctl: can't allocate %d entry internal pool, "
1055 "exiting\n", CTL_POOL_ENTRIES_INTERNAL);
1001 }
1002
1003 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1004 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1005 "inquiry_pq_no_lun", CTLFLAG_RW,
1006 &softc->inquiry_pq_no_lun, 0,
1007 "Report no lun possible for invalid LUNs");
1008

--- 45 unchanged lines hidden (view full) ---

1054 * We don't bother calling these with ctl_lock held here, because,
1055 * in theory, no one else can try to do anything while we're in our
1056 * module init routine.
1057 */
1058 if (ctl_pool_create(softc, CTL_POOL_INTERNAL, CTL_POOL_ENTRIES_INTERNAL,
1059 &internal_pool)!= 0){
1060 printf("ctl: can't allocate %d entry internal pool, "
1061 "exiting\n", CTL_POOL_ENTRIES_INTERNAL);
1056 return;
1062 return (ENOMEM);
1057 }
1058
1059 if (ctl_pool_create(softc, CTL_POOL_EMERGENCY,
1060 CTL_POOL_ENTRIES_EMERGENCY, &emergency_pool) != 0) {
1061 printf("ctl: can't allocate %d entry emergency pool, "
1062 "exiting\n", CTL_POOL_ENTRIES_EMERGENCY);
1063 ctl_pool_free(softc, internal_pool);
1063 }
1064
1065 if (ctl_pool_create(softc, CTL_POOL_EMERGENCY,
1066 CTL_POOL_ENTRIES_EMERGENCY, &emergency_pool) != 0) {
1067 printf("ctl: can't allocate %d entry emergency pool, "
1068 "exiting\n", CTL_POOL_ENTRIES_EMERGENCY);
1069 ctl_pool_free(softc, internal_pool);
1064 return;
1070 return (ENOMEM);
1065 }
1066
1067 if (ctl_pool_create(softc, CTL_POOL_4OTHERSC, CTL_POOL_ENTRIES_OTHER_SC,
1068 &other_pool) != 0)
1069 {
1070 printf("ctl: can't allocate %d entry other SC pool, "
1071 "exiting\n", CTL_POOL_ENTRIES_OTHER_SC);
1072 ctl_pool_free(softc, internal_pool);
1073 ctl_pool_free(softc, emergency_pool);
1071 }
1072
1073 if (ctl_pool_create(softc, CTL_POOL_4OTHERSC, CTL_POOL_ENTRIES_OTHER_SC,
1074 &other_pool) != 0)
1075 {
1076 printf("ctl: can't allocate %d entry other SC pool, "
1077 "exiting\n", CTL_POOL_ENTRIES_OTHER_SC);
1078 ctl_pool_free(softc, internal_pool);
1079 ctl_pool_free(softc, emergency_pool);
1074 return;
1080 return (ENOMEM);
1075 }
1076
1077 softc->internal_pool = internal_pool;
1078 softc->emergency_pool = emergency_pool;
1079 softc->othersc_pool = other_pool;
1080
1081 ctl_pool_acquire(internal_pool);
1082 ctl_pool_acquire(emergency_pool);

--- 4 unchanged lines hidden (view full) ---

1087 * just let the user allocate LUNs as he sees fit.
1088 */
1089#if 0
1090 mtx_lock(&softc->ctl_lock);
1091 ctl_alloc_lun(softc, lun, /*be_lun*/NULL, /*target*/softc->target);
1092 mtx_unlock(&softc->ctl_lock);
1093#endif
1094
1081 }
1082
1083 softc->internal_pool = internal_pool;
1084 softc->emergency_pool = emergency_pool;
1085 softc->othersc_pool = other_pool;
1086
1087 ctl_pool_acquire(internal_pool);
1088 ctl_pool_acquire(emergency_pool);

--- 4 unchanged lines hidden (view full) ---

1093 * just let the user allocate LUNs as he sees fit.
1094 */
1095#if 0
1096 mtx_lock(&softc->ctl_lock);
1097 ctl_alloc_lun(softc, lun, /*be_lun*/NULL, /*target*/softc->target);
1098 mtx_unlock(&softc->ctl_lock);
1099#endif
1100
1095 if (kproc_create(ctl_work_thread, softc, &softc->work_thread, 0, 0,
1096 "ctl_thrd") != 0) {
1101 error = kproc_create(ctl_work_thread, softc, &softc->work_thread, 0, 0,
1102 "ctl_thrd");
1103 if (error != 0) {
1097 printf("error creating CTL work thread!\n");
1098 ctl_free_lun(lun);
1099 ctl_pool_free(softc, internal_pool);
1100 ctl_pool_free(softc, emergency_pool);
1101 ctl_pool_free(softc, other_pool);
1104 printf("error creating CTL work thread!\n");
1105 ctl_free_lun(lun);
1106 ctl_pool_free(softc, internal_pool);
1107 ctl_pool_free(softc, emergency_pool);
1108 ctl_pool_free(softc, other_pool);
1102 return;
1109 return (error);
1103 }
1104 printf("ctl: CAM Target Layer loaded\n");
1105
1106 /*
1107 * Initialize the initiator and portname mappings
1108 */
1109 memset(softc->wwpn_iid, 0, sizeof(softc->wwpn_iid));
1110

--- 23 unchanged lines hidden (view full) ---

1134 printf("ctl: ioctl front end registration failed, will "
1135 "continue anyway\n");
1136 }
1137
1138#ifdef CTL_IO_DELAY
1139 if (sizeof(struct callout) > CTL_TIMER_BYTES) {
1140 printf("sizeof(struct callout) %zd > CTL_TIMER_BYTES %zd\n",
1141 sizeof(struct callout), CTL_TIMER_BYTES);
1110 }
1111 printf("ctl: CAM Target Layer loaded\n");
1112
1113 /*
1114 * Initialize the initiator and portname mappings
1115 */
1116 memset(softc->wwpn_iid, 0, sizeof(softc->wwpn_iid));
1117

--- 23 unchanged lines hidden (view full) ---

1141 printf("ctl: ioctl front end registration failed, will "
1142 "continue anyway\n");
1143 }
1144
1145#ifdef CTL_IO_DELAY
1146 if (sizeof(struct callout) > CTL_TIMER_BYTES) {
1147 printf("sizeof(struct callout) %zd > CTL_TIMER_BYTES %zd\n",
1148 sizeof(struct callout), CTL_TIMER_BYTES);
1142 return;
1149 return (EINVAL);
1143 }
1144#endif /* CTL_IO_DELAY */
1145
1150 }
1151#endif /* CTL_IO_DELAY */
1152
1153 return (0);
1146}
1147
1148void
1149ctl_shutdown(void)
1150{
1151 struct ctl_softc *softc;
1152 struct ctl_lun *lun, *next_lun;
1153 struct ctl_io_pool *pool, *next_pool;

--- 40 unchanged lines hidden (view full) ---

1194 sysctl_ctx_free(&softc->sysctl_ctx);
1195
1196 free(control_softc, M_DEVBUF);
1197 control_softc = NULL;
1198
1199 printf("ctl: CAM Target Layer unloaded\n");
1200}
1201
1154}
1155
1156void
1157ctl_shutdown(void)
1158{
1159 struct ctl_softc *softc;
1160 struct ctl_lun *lun, *next_lun;
1161 struct ctl_io_pool *pool, *next_pool;

--- 40 unchanged lines hidden (view full) ---

1202 sysctl_ctx_free(&softc->sysctl_ctx);
1203
1204 free(control_softc, M_DEVBUF);
1205 control_softc = NULL;
1206
1207 printf("ctl: CAM Target Layer unloaded\n");
1208}
1209
1210static int
1211ctl_module_event_handler(module_t mod, int what, void *arg)
1212{
1213
1214 switch (what) {
1215 case MOD_LOAD:
1216 return (ctl_init());
1217 case MOD_UNLOAD:
1218 return (EBUSY);
1219 default:
1220 return (EOPNOTSUPP);
1221 }
1222}
1223
1202/*
1203 * XXX KDM should we do some access checks here? Bump a reference count to
1204 * prevent a CTL module from being unloaded while someone has it open?
1205 */
1206static int
1207ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td)
1208{
1209 return (0);

--- 11909 unchanged lines hidden ---
1224/*
1225 * XXX KDM should we do some access checks here? Bump a reference count to
1226 * prevent a CTL module from being unloaded while someone has it open?
1227 */
1228static int
1229ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td)
1230{
1231 return (0);

--- 11909 unchanged lines hidden ---