ctl_frontend_internal.c (276616) | ctl_frontend_internal.c (284798) |
---|---|
1/*- 2 * Copyright (c) 2004, 2005 Silicon Graphics International Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 34 unchanged lines hidden (view full) --- 43 * To be able to fulfill the role of a full initiator layer, it would need 44 * a whole lot more functionality. 45 * 46 * Author: Ken Merry <ken@FreeBSD.org> 47 * 48 */ 49 50#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2004, 2005 Silicon Graphics International Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 34 unchanged lines hidden (view full) --- 43 * To be able to fulfill the role of a full initiator layer, it would need 44 * a whole lot more functionality. 45 * 46 * Author: Ken Merry <ken@FreeBSD.org> 47 * 48 */ 49 50#include <sys/cdefs.h> |
51__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_internal.c 276616 2015-01-03 13:11:39Z mav $"); | 51__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_internal.c 284798 2015-06-25 07:11:48Z mav $"); |
52 53#include <sys/param.h> 54#include <sys/systm.h> 55#include <sys/kernel.h> 56#include <sys/types.h> 57#include <sys/malloc.h> 58#include <sys/module.h> 59#include <sys/lock.h> --- 79 unchanged lines hidden (view full) --- 139typedef enum { 140 CFI_LUN_INQUIRY, 141 CFI_LUN_READCAPACITY, 142 CFI_LUN_READCAPACITY_16, 143 CFI_LUN_READY 144} cfi_lun_state; 145 146struct cfi_lun { | 52 53#include <sys/param.h> 54#include <sys/systm.h> 55#include <sys/kernel.h> 56#include <sys/types.h> 57#include <sys/malloc.h> 58#include <sys/module.h> 59#include <sys/lock.h> --- 79 unchanged lines hidden (view full) --- 139typedef enum { 140 CFI_LUN_INQUIRY, 141 CFI_LUN_READCAPACITY, 142 CFI_LUN_READCAPACITY_16, 143 CFI_LUN_READY 144} cfi_lun_state; 145 146struct cfi_lun { |
147 struct ctl_id target_id; | |
148 int lun_id; 149 struct scsi_inquiry_data inq_data; 150 uint64_t num_blocks; 151 uint32_t blocksize; 152 int blocksize_powerof2; 153 uint32_t cur_tag_num; 154 cfi_lun_state state; 155 struct cfi_softc *softc; --- 31 unchanged lines hidden (view full) --- 187static uma_zone_t cfi_metatask_zone; 188 189static struct cfi_softc fetd_internal_softc; 190 191int cfi_init(void); 192void cfi_shutdown(void) __unused; 193static void cfi_online(void *arg); 194static void cfi_offline(void *arg); | 147 int lun_id; 148 struct scsi_inquiry_data inq_data; 149 uint64_t num_blocks; 150 uint32_t blocksize; 151 int blocksize_powerof2; 152 uint32_t cur_tag_num; 153 cfi_lun_state state; 154 struct cfi_softc *softc; --- 31 unchanged lines hidden (view full) --- 186static uma_zone_t cfi_metatask_zone; 187 188static struct cfi_softc fetd_internal_softc; 189 190int cfi_init(void); 191void cfi_shutdown(void) __unused; 192static void cfi_online(void *arg); 193static void cfi_offline(void *arg); |
195static int cfi_lun_enable(void *arg, struct ctl_id target_id, int lun_id); 196static int cfi_lun_disable(void *arg, struct ctl_id target_id, int lun_id); | 194static int cfi_lun_enable(void *arg, int lun_id); 195static int cfi_lun_disable(void *arg, int lun_id); |
197static void cfi_datamove(union ctl_io *io); 198static cfi_error_action cfi_checkcond_parse(union ctl_io *io, 199 struct cfi_lun_io *lun_io); 200static cfi_error_action cfi_error_parse(union ctl_io *io, 201 struct cfi_lun_io *lun_io); 202static void cfi_init_io(union ctl_io *io, struct cfi_lun *lun, 203 struct cfi_metatask *metatask, cfi_error_policy policy, 204 int retries, struct cfi_lun_io *orig_lun_io, --- 114 unchanged lines hidden (view full) --- 319 struct cfi_softc *softc; 320 321 softc = (struct cfi_softc *)arg; 322 323 softc->flags &= ~CFI_ONLINE; 324} 325 326static int | 196static void cfi_datamove(union ctl_io *io); 197static cfi_error_action cfi_checkcond_parse(union ctl_io *io, 198 struct cfi_lun_io *lun_io); 199static cfi_error_action cfi_error_parse(union ctl_io *io, 200 struct cfi_lun_io *lun_io); 201static void cfi_init_io(union ctl_io *io, struct cfi_lun *lun, 202 struct cfi_metatask *metatask, cfi_error_policy policy, 203 int retries, struct cfi_lun_io *orig_lun_io, --- 114 unchanged lines hidden (view full) --- 318 struct cfi_softc *softc; 319 320 softc = (struct cfi_softc *)arg; 321 322 softc->flags &= ~CFI_ONLINE; 323} 324 325static int |
327cfi_lun_enable(void *arg, struct ctl_id target_id, int lun_id) | 326cfi_lun_enable(void *arg, int lun_id) |
328{ 329 struct cfi_softc *softc; 330 struct cfi_lun *lun; 331 int found; 332 333 softc = (struct cfi_softc *)arg; 334 335 found = 0; 336 mtx_lock(&softc->lock); 337 STAILQ_FOREACH(lun, &softc->lun_list, links) { | 327{ 328 struct cfi_softc *softc; 329 struct cfi_lun *lun; 330 int found; 331 332 softc = (struct cfi_softc *)arg; 333 334 found = 0; 335 mtx_lock(&softc->lock); 336 STAILQ_FOREACH(lun, &softc->lun_list, links) { |
338 if ((lun->target_id.id == target_id.id) 339 && (lun->lun_id == lun_id)) { | 337 if (lun->lun_id == lun_id) { |
340 found = 1; 341 break; 342 } 343 } 344 mtx_unlock(&softc->lock); 345 346 /* 347 * If we already have this target/LUN, there is no reason to add 348 * it to our lists again. 349 */ 350 if (found != 0) 351 return (0); 352 353 lun = uma_zalloc(cfi_lun_zone, M_NOWAIT | M_ZERO); 354 if (lun == NULL) { 355 printf("%s: unable to allocate LUN structure\n", __func__); 356 return (1); 357 } 358 | 338 found = 1; 339 break; 340 } 341 } 342 mtx_unlock(&softc->lock); 343 344 /* 345 * If we already have this target/LUN, there is no reason to add 346 * it to our lists again. 347 */ 348 if (found != 0) 349 return (0); 350 351 lun = uma_zalloc(cfi_lun_zone, M_NOWAIT | M_ZERO); 352 if (lun == NULL) { 353 printf("%s: unable to allocate LUN structure\n", __func__); 354 return (1); 355 } 356 |
359 lun->target_id = target_id; | |
360 lun->lun_id = lun_id; 361 lun->cur_tag_num = 0; 362 lun->state = CFI_LUN_INQUIRY; 363 lun->softc = softc; 364 STAILQ_INIT(&lun->io_list); 365 366 mtx_lock(&softc->lock); 367 STAILQ_INSERT_TAIL(&softc->lun_list, lun, links); 368 mtx_unlock(&softc->lock); 369 370 cfi_lun_probe(lun, /*have_lock*/ 0); 371 372 return (0); 373} 374 375static int | 357 lun->lun_id = lun_id; 358 lun->cur_tag_num = 0; 359 lun->state = CFI_LUN_INQUIRY; 360 lun->softc = softc; 361 STAILQ_INIT(&lun->io_list); 362 363 mtx_lock(&softc->lock); 364 STAILQ_INSERT_TAIL(&softc->lun_list, lun, links); 365 mtx_unlock(&softc->lock); 366 367 cfi_lun_probe(lun, /*have_lock*/ 0); 368 369 return (0); 370} 371 372static int |
376cfi_lun_disable(void *arg, struct ctl_id target_id, int lun_id) | 373cfi_lun_disable(void *arg, int lun_id) |
377{ 378 struct cfi_softc *softc; 379 struct cfi_lun *lun; 380 int found; 381 382 softc = (struct cfi_softc *)arg; 383 384 found = 0; 385 386 /* 387 * XXX KDM need to do an invalidate and then a free when any 388 * pending I/O has completed. Or do we? CTL won't free a LUN 389 * while any I/O is pending. So we won't get this notification 390 * unless any I/O we have pending on a LUN has completed. 391 */ 392 mtx_lock(&softc->lock); 393 STAILQ_FOREACH(lun, &softc->lun_list, links) { | 374{ 375 struct cfi_softc *softc; 376 struct cfi_lun *lun; 377 int found; 378 379 softc = (struct cfi_softc *)arg; 380 381 found = 0; 382 383 /* 384 * XXX KDM need to do an invalidate and then a free when any 385 * pending I/O has completed. Or do we? CTL won't free a LUN 386 * while any I/O is pending. So we won't get this notification 387 * unless any I/O we have pending on a LUN has completed. 388 */ 389 mtx_lock(&softc->lock); 390 STAILQ_FOREACH(lun, &softc->lun_list, links) { |
394 if ((lun->target_id.id == target_id.id) 395 && (lun->lun_id == lun_id)) { | 391 if (lun->lun_id == lun_id) { |
396 found = 1; 397 break; 398 } 399 } 400 if (found != 0) 401 STAILQ_REMOVE(&softc->lun_list, lun, cfi_lun, links); 402 403 mtx_unlock(&softc->lock); 404 405 if (found == 0) { | 392 found = 1; 393 break; 394 } 395 } 396 if (found != 0) 397 STAILQ_REMOVE(&softc->lun_list, lun, cfi_lun, links); 398 399 mtx_unlock(&softc->lock); 400 401 if (found == 0) { |
406 printf("%s: can't find target %ju lun %d\n", __func__, 407 (uintmax_t)target_id.id, lun_id); | 402 printf("%s: can't find lun %d\n", __func__, lun_id); |
408 return (1); 409 } 410 411 uma_zfree(cfi_lun_zone, lun); 412 413 return (0); 414} 415 --- 279 unchanged lines hidden (view full) --- 695 struct cfi_metatask *metatask, cfi_error_policy policy, int retries, 696 struct cfi_lun_io *orig_lun_io, 697 void (*done_function)(union ctl_io *io)) 698{ 699 struct cfi_lun_io *lun_io; 700 701 io->io_hdr.nexus.initid.id = 7; 702 io->io_hdr.nexus.targ_port = lun->softc->port.targ_port; | 403 return (1); 404 } 405 406 uma_zfree(cfi_lun_zone, lun); 407 408 return (0); 409} 410 --- 279 unchanged lines hidden (view full) --- 690 struct cfi_metatask *metatask, cfi_error_policy policy, int retries, 691 struct cfi_lun_io *orig_lun_io, 692 void (*done_function)(union ctl_io *io)) 693{ 694 struct cfi_lun_io *lun_io; 695 696 io->io_hdr.nexus.initid.id = 7; 697 io->io_hdr.nexus.targ_port = lun->softc->port.targ_port; |
703 io->io_hdr.nexus.targ_target.id = lun->target_id.id; | 698 io->io_hdr.nexus.targ_target.id = 0; |
704 io->io_hdr.nexus.targ_lun = lun->lun_id; 705 io->io_hdr.retries = retries; 706 lun_io = (struct cfi_lun_io *)io->io_hdr.port_priv; 707 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = lun_io; 708 lun_io->lun = lun; 709 lun_io->metatask = metatask; 710 lun_io->ctl_io = io; 711 lun_io->policy = policy; --- 291 unchanged lines hidden (view full) --- 1003 union ctl_io *io; 1004 1005 io = ctl_alloc_io(lun->softc->port.ctl_pool_ref); 1006 1007 dataptr = malloc(sizeof(struct scsi_read_capacity_data_long), 1008 M_CTL_CFI, M_NOWAIT); 1009 if (dataptr == NULL) { 1010 printf("%s: unable to allocate SCSI read capacity " | 699 io->io_hdr.nexus.targ_lun = lun->lun_id; 700 io->io_hdr.retries = retries; 701 lun_io = (struct cfi_lun_io *)io->io_hdr.port_priv; 702 io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr = lun_io; 703 lun_io->lun = lun; 704 lun_io->metatask = metatask; 705 lun_io->ctl_io = io; 706 lun_io->policy = policy; --- 291 unchanged lines hidden (view full) --- 998 union ctl_io *io; 999 1000 io = ctl_alloc_io(lun->softc->port.ctl_pool_ref); 1001 1002 dataptr = malloc(sizeof(struct scsi_read_capacity_data_long), 1003 M_CTL_CFI, M_NOWAIT); 1004 if (dataptr == NULL) { 1005 printf("%s: unable to allocate SCSI read capacity " |
1011 "buffer for target %ju lun %d\n", __func__, 1012 (uintmax_t)lun->target_id.id, lun->lun_id); | 1006 "buffer for lun %d\n", __func__, lun->lun_id); |
1013 return; 1014 } 1015 if (lun->state == CFI_LUN_READCAPACITY) { 1016 ctl_scsi_read_capacity(io, 1017 /*data_ptr*/ dataptr, 1018 /*data_len*/ 1019 sizeof(struct scsi_read_capacity_data_long), 1020 /*addr*/ 0, --- 598 unchanged lines hidden --- | 1007 return; 1008 } 1009 if (lun->state == CFI_LUN_READCAPACITY) { 1010 ctl_scsi_read_capacity(io, 1011 /*data_ptr*/ dataptr, 1012 /*data_len*/ 1013 sizeof(struct scsi_read_capacity_data_long), 1014 /*addr*/ 0, --- 598 unchanged lines hidden --- |