Deleted Added
full compact
ctl.c (268683) ctl.c (268685)
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: stable/10/sys/cam/ctl/ctl.c 268683 2014-07-15 17:06:10Z mav $");
45__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl.c 268685 2014-07-15 17:08:04Z mav $");
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>

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

343static void ctl_ioctl_bbrread_callback(void *arg,struct cfi_metatask *metatask);
344static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
345 struct ctl_ooa *ooa_hdr,
346 struct ctl_ooa_entry *kern_entries);
347static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
348 struct thread *td);
349uint32_t ctl_get_resindex(struct ctl_nexus *nexus);
350uint32_t ctl_port_idx(int port_num);
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>

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

343static void ctl_ioctl_bbrread_callback(void *arg,struct cfi_metatask *metatask);
344static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
345 struct ctl_ooa *ooa_hdr,
346 struct ctl_ooa_entry *kern_entries);
347static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
348 struct thread *td);
349uint32_t ctl_get_resindex(struct ctl_nexus *nexus);
350uint32_t ctl_port_idx(int port_num);
351static uint32_t ctl_map_lun(int port_num, uint32_t lun);
351#ifdef unused
352static union ctl_io *ctl_malloc_io(ctl_io_type io_type, uint32_t targ_port,
353 uint32_t targ_target, uint32_t targ_lun,
354 int can_wait);
355static void ctl_kfree_io(union ctl_io *io);
356#endif /* unused */
357static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
358 struct ctl_be_lun *be_lun, struct ctl_id target_id);

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

3342ctl_port_idx(int port_num)
3343{
3344 if (port_num < CTL_MAX_PORTS)
3345 return(port_num);
3346 else
3347 return(port_num - CTL_MAX_PORTS);
3348}
3349
352#ifdef unused
353static union ctl_io *ctl_malloc_io(ctl_io_type io_type, uint32_t targ_port,
354 uint32_t targ_target, uint32_t targ_lun,
355 int can_wait);
356static void ctl_kfree_io(union ctl_io *io);
357#endif /* unused */
358static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
359 struct ctl_be_lun *be_lun, struct ctl_id target_id);

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

3343ctl_port_idx(int port_num)
3344{
3345 if (port_num < CTL_MAX_PORTS)
3346 return(port_num);
3347 else
3348 return(port_num - CTL_MAX_PORTS);
3349}
3350
3351static uint32_t
3352ctl_map_lun(int port_num, uint32_t lun_id)
3353{
3354 struct ctl_port *port;
3355
3356 port = control_softc->ctl_ports[ctl_port_idx(port_num)];
3357 if (port == NULL)
3358 return (UINT32_MAX);
3359 if (port->lun_map == NULL)
3360 return (lun_id);
3361 return (port->lun_map(port->targ_lun_arg, lun_id));
3362}
3363
3350/*
3351 * Note: This only works for bitmask sizes that are at least 32 bits, and
3352 * that are a power of 2.
3353 */
3354int
3355ctl_ffz(uint32_t *mask, uint32_t size)
3356{
3357 uint32_t num_chunks, num_pieces;

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

9253 ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK | M_ZERO);
9254 lun_data = (struct scsi_report_luns_data *)ctsio->kern_data_ptr;
9255 ctsio->kern_sg_entries = 0;
9256
9257 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
9258
9259 mtx_lock(&control_softc->ctl_lock);
9260 for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) {
3364/*
3365 * Note: This only works for bitmask sizes that are at least 32 bits, and
3366 * that are a power of 2.
3367 */
3368int
3369ctl_ffz(uint32_t *mask, uint32_t size)
3370{
3371 uint32_t num_chunks, num_pieces;

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

9267 ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK | M_ZERO);
9268 lun_data = (struct scsi_report_luns_data *)ctsio->kern_data_ptr;
9269 ctsio->kern_sg_entries = 0;
9270
9271 initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
9272
9273 mtx_lock(&control_softc->ctl_lock);
9274 for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) {
9261 lun_id = targ_lun_id;
9262 if (ctsio->io_hdr.nexus.lun_map_fn != NULL)
9263 lun_id = ctsio->io_hdr.nexus.lun_map_fn(ctsio->io_hdr.nexus.lun_map_arg, lun_id);
9275 lun_id = ctl_map_lun(ctsio->io_hdr.nexus.targ_port, targ_lun_id);
9264 if (lun_id >= CTL_MAX_LUNS)
9265 continue;
9266 lun = control_softc->ctl_luns[lun_id];
9267 if (lun == NULL)
9268 continue;
9269
9270 if (targ_lun_id <= 0xff) {
9271 /*

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

13233 */
13234 mtx_lock(&ctl_softc->ctl_lock);
13235
13236 /*
13237 * If we don't have a LUN for this, just toss the sense
13238 * information.
13239 */
13240 targ_lun = io->io_hdr.nexus.targ_lun;
9276 if (lun_id >= CTL_MAX_LUNS)
9277 continue;
9278 lun = control_softc->ctl_luns[lun_id];
9279 if (lun == NULL)
9280 continue;
9281
9282 if (targ_lun_id <= 0xff) {
9283 /*

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

13245 */
13246 mtx_lock(&ctl_softc->ctl_lock);
13247
13248 /*
13249 * If we don't have a LUN for this, just toss the sense
13250 * information.
13251 */
13252 targ_lun = io->io_hdr.nexus.targ_lun;
13241 if (io->io_hdr.nexus.lun_map_fn != NULL)
13242 targ_lun = io->io_hdr.nexus.lun_map_fn(io->io_hdr.nexus.lun_map_arg, targ_lun);
13253 targ_lun = ctl_map_lun(io->io_hdr.nexus.targ_port, targ_lun);
13243 if ((targ_lun < CTL_MAX_LUNS)
13244 && (ctl_softc->ctl_luns[targ_lun] != NULL))
13245 lun = ctl_softc->ctl_luns[targ_lun];
13246 else
13247 goto bailout;
13248
13249 initidx = ctl_get_initindex(&io->io_hdr.nexus);
13250

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

13285 ctl_softc = control_softc;
13286
13287#ifdef CTL_TIME_IO
13288 io->io_hdr.start_time = time_uptime;
13289 getbintime(&io->io_hdr.start_bt);
13290#endif /* CTL_TIME_IO */
13291
13292 /* Map FE-specific LUN ID into global one. */
13254 if ((targ_lun < CTL_MAX_LUNS)
13255 && (ctl_softc->ctl_luns[targ_lun] != NULL))
13256 lun = ctl_softc->ctl_luns[targ_lun];
13257 else
13258 goto bailout;
13259
13260 initidx = ctl_get_initindex(&io->io_hdr.nexus);
13261

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

13296 ctl_softc = control_softc;
13297
13298#ifdef CTL_TIME_IO
13299 io->io_hdr.start_time = time_uptime;
13300 getbintime(&io->io_hdr.start_bt);
13301#endif /* CTL_TIME_IO */
13302
13303 /* Map FE-specific LUN ID into global one. */
13293 if (io->io_hdr.nexus.lun_map_fn != NULL)
13294 io->io_hdr.nexus.targ_mapped_lun = io->io_hdr.nexus.lun_map_fn(
13295 io->io_hdr.nexus.lun_map_arg, io->io_hdr.nexus.targ_lun);
13296 else
13297 io->io_hdr.nexus.targ_mapped_lun = io->io_hdr.nexus.targ_lun;
13304 io->io_hdr.nexus.targ_mapped_lun =
13305 ctl_map_lun(io->io_hdr.nexus.targ_port, io->io_hdr.nexus.targ_lun);
13298
13299 switch (io->io_hdr.io_type) {
13300 case CTL_IO_SCSI:
13301 case CTL_IO_TASK:
13302 ctl_enqueue_incoming(io);
13303 break;
13304 default:
13305 printf("ctl_queue: unknown I/O type %d\n", io->io_hdr.io_type);

--- 376 unchanged lines hidden ---
13306
13307 switch (io->io_hdr.io_type) {
13308 case CTL_IO_SCSI:
13309 case CTL_IO_TASK:
13310 ctl_enqueue_incoming(io);
13311 break;
13312 default:
13313 printf("ctl_queue: unknown I/O type %d\n", io->io_hdr.io_type);

--- 376 unchanged lines hidden ---