1/*- 2 * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Silicon Graphics International Corp. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer, 11 * without modification, immediately at the beginning of the file. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Silicon Graphics International Corp. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer, 11 * without modification, immediately at the beginning of the file. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h>
|
67static struct tpcl_softc tpcl_softc; 68 69static int tpcl_init(void); 70static void tpcl_shutdown(void); 71static void tpcl_online(void *arg); 72static void tpcl_offline(void *arg); 73static int tpcl_lun_enable(void *arg, struct ctl_id target_id, int lun_id); 74static int tpcl_lun_disable(void *arg, struct ctl_id target_id, int lun_id); 75static void tpcl_datamove(union ctl_io *io); 76static void tpcl_done(union ctl_io *io); 77 78 79static struct ctl_frontend tpcl_frontend = 80{ 81 .name = "tpc", 82 .init = tpcl_init, 83 .shutdown = tpcl_shutdown, 84}; 85CTL_FRONTEND_DECLARE(ctltpc, tpcl_frontend); 86 87static int 88tpcl_init(void) 89{ 90 struct tpcl_softc *tsoftc = &tpcl_softc; 91 struct ctl_port *port; 92 struct scsi_transportid_spi *tid; 93 int len; 94 95 memset(tsoftc, 0, sizeof(*tsoftc)); 96 97 port = &tsoftc->port; 98 port->frontend = &tpcl_frontend; 99 port->port_type = CTL_PORT_INTERNAL; 100 port->num_requested_ctl_io = 100; 101 port->port_name = "tpc"; 102 port->port_online = tpcl_online; 103 port->port_offline = tpcl_offline; 104 port->onoff_arg = tsoftc; 105 port->lun_enable = tpcl_lun_enable; 106 port->lun_disable = tpcl_lun_disable; 107 port->targ_lun_arg = tsoftc; 108 port->fe_datamove = tpcl_datamove; 109 port->fe_done = tpcl_done; 110 port->max_targets = 1; 111 port->max_target_id = 0; 112 port->max_initiators = 1; 113 114 if (ctl_port_register(port) != 0) 115 { 116 printf("%s: tpc frontend registration failed\n", __func__); 117 return (0); 118 } 119 120 len = sizeof(struct scsi_transportid_spi); 121 port->init_devid = malloc(sizeof(struct ctl_devid) + len, 122 M_CTL, M_WAITOK | M_ZERO); 123 port->init_devid->len = len; 124 tid = (struct scsi_transportid_spi *)port->init_devid->data; 125 tid->format_protocol = SCSI_TRN_SPI_FORMAT_DEFAULT | SCSI_PROTO_SPI; 126 scsi_ulto2b(0, tid->scsi_addr); 127 scsi_ulto2b(port->targ_port, tid->rel_trgt_port_id); 128 129 ctl_port_online(port); 130 return (0); 131} 132 133void 134tpcl_shutdown(void) 135{ 136 struct tpcl_softc *tsoftc = &tpcl_softc; 137 struct ctl_port *port; 138 139 port = &tsoftc->port; 140 ctl_port_offline(port); 141 if (ctl_port_deregister(&tsoftc->port) != 0) 142 printf("%s: ctl_frontend_deregister() failed\n", __func__); 143} 144 145static void 146tpcl_online(void *arg) 147{ 148} 149 150static void 151tpcl_offline(void *arg) 152{ 153} 154 155static int 156tpcl_lun_enable(void *arg, struct ctl_id target_id, int lun_id) 157{ 158 159 return (0); 160} 161 162static int 163tpcl_lun_disable(void *arg, struct ctl_id target_id, int lun_id) 164{ 165 166 return (0); 167} 168 169static void 170tpcl_datamove(union ctl_io *io) 171{ 172 struct ctl_sg_entry *ext_sglist, *kern_sglist; 173 struct ctl_sg_entry ext_entry, kern_entry; 174 int ext_sg_entries, kern_sg_entries; 175 int ext_sg_start, ext_offset; 176 int len_to_copy, len_copied; 177 int kern_watermark, ext_watermark; 178 struct ctl_scsiio *ctsio; 179 int i, j; 180 181 ext_sg_start = 0; 182 ext_offset = 0; 183 ext_sglist = NULL; 184 185 CTL_DEBUG_PRINT(("%s\n", __func__)); 186 187 ctsio = &io->scsiio; 188 189 /* 190 * If this is the case, we're probably doing a BBR read and don't 191 * actually need to transfer the data. This will effectively 192 * bit-bucket the data. 193 */ 194 if (ctsio->ext_data_ptr == NULL) 195 goto bailout; 196 197 /* 198 * To simplify things here, if we have a single buffer, stick it in 199 * a S/G entry and just make it a single entry S/G list. 200 */ 201 if (ctsio->io_hdr.flags & CTL_FLAG_EDPTR_SGLIST) { 202 int len_seen; 203 204 ext_sglist = (struct ctl_sg_entry *)ctsio->ext_data_ptr; 205 ext_sg_entries = ctsio->ext_sg_entries; 206 ext_sg_start = 0; 207 ext_offset = 0; 208 len_seen = 0; 209 for (i = 0; i < ext_sg_entries; i++) { 210 if ((len_seen + ext_sglist[i].len) >= 211 ctsio->ext_data_filled) { 212 ext_sg_start = i; 213 ext_offset = ctsio->ext_data_filled - len_seen; 214 break; 215 } 216 len_seen += ext_sglist[i].len; 217 } 218 } else { 219 ext_sglist = &ext_entry; 220 ext_sglist->addr = ctsio->ext_data_ptr; 221 ext_sglist->len = ctsio->ext_data_len; 222 ext_sg_entries = 1; 223 ext_sg_start = 0; 224 ext_offset = ctsio->ext_data_filled; 225 } 226 227 if (ctsio->kern_sg_entries > 0) { 228 kern_sglist = (struct ctl_sg_entry *)ctsio->kern_data_ptr; 229 kern_sg_entries = ctsio->kern_sg_entries; 230 } else { 231 kern_sglist = &kern_entry; 232 kern_sglist->addr = ctsio->kern_data_ptr; 233 kern_sglist->len = ctsio->kern_data_len; 234 kern_sg_entries = 1; 235 } 236 237 kern_watermark = 0; 238 ext_watermark = ext_offset; 239 len_copied = 0; 240 for (i = ext_sg_start, j = 0; 241 i < ext_sg_entries && j < kern_sg_entries;) { 242 uint8_t *ext_ptr, *kern_ptr; 243 244 len_to_copy = min(ext_sglist[i].len - ext_watermark, 245 kern_sglist[j].len - kern_watermark); 246 247 ext_ptr = (uint8_t *)ext_sglist[i].addr; 248 ext_ptr = ext_ptr + ext_watermark; 249 if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) { 250 /* 251 * XXX KDM fix this! 252 */ 253 panic("need to implement bus address support"); 254#if 0 255 kern_ptr = bus_to_virt(kern_sglist[j].addr); 256#endif 257 } else 258 kern_ptr = (uint8_t *)kern_sglist[j].addr; 259 kern_ptr = kern_ptr + kern_watermark; 260 261 kern_watermark += len_to_copy; 262 ext_watermark += len_to_copy; 263 264 if ((ctsio->io_hdr.flags & CTL_FLAG_DATA_MASK) == 265 CTL_FLAG_DATA_IN) { 266 CTL_DEBUG_PRINT(("%s: copying %d bytes to user\n", 267 __func__, len_to_copy)); 268 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 269 kern_ptr, ext_ptr)); 270 memcpy(ext_ptr, kern_ptr, len_to_copy); 271 } else { 272 CTL_DEBUG_PRINT(("%s: copying %d bytes from user\n", 273 __func__, len_to_copy)); 274 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 275 ext_ptr, kern_ptr)); 276 memcpy(kern_ptr, ext_ptr, len_to_copy); 277 } 278 279 len_copied += len_to_copy; 280 281 if (ext_sglist[i].len == ext_watermark) { 282 i++; 283 ext_watermark = 0; 284 } 285 286 if (kern_sglist[j].len == kern_watermark) { 287 j++; 288 kern_watermark = 0; 289 } 290 } 291 292 ctsio->ext_data_filled += len_copied; 293 294 CTL_DEBUG_PRINT(("%s: ext_sg_entries: %d, kern_sg_entries: %d\n", 295 __func__, ext_sg_entries, kern_sg_entries)); 296 CTL_DEBUG_PRINT(("%s: ext_data_len = %d, kern_data_len = %d\n", 297 __func__, ctsio->ext_data_len, ctsio->kern_data_len)); 298 299 /* XXX KDM set residual?? */ 300bailout: 301 io->scsiio.be_move_done(io); 302} 303 304static void 305tpcl_done(union ctl_io *io) 306{ 307 308 tpc_done(io); 309} 310 311uint64_t
| 66static struct tpcl_softc tpcl_softc; 67 68static int tpcl_init(void); 69static void tpcl_shutdown(void); 70static void tpcl_online(void *arg); 71static void tpcl_offline(void *arg); 72static int tpcl_lun_enable(void *arg, struct ctl_id target_id, int lun_id); 73static int tpcl_lun_disable(void *arg, struct ctl_id target_id, int lun_id); 74static void tpcl_datamove(union ctl_io *io); 75static void tpcl_done(union ctl_io *io); 76 77 78static struct ctl_frontend tpcl_frontend = 79{ 80 .name = "tpc", 81 .init = tpcl_init, 82 .shutdown = tpcl_shutdown, 83}; 84CTL_FRONTEND_DECLARE(ctltpc, tpcl_frontend); 85 86static int 87tpcl_init(void) 88{ 89 struct tpcl_softc *tsoftc = &tpcl_softc; 90 struct ctl_port *port; 91 struct scsi_transportid_spi *tid; 92 int len; 93 94 memset(tsoftc, 0, sizeof(*tsoftc)); 95 96 port = &tsoftc->port; 97 port->frontend = &tpcl_frontend; 98 port->port_type = CTL_PORT_INTERNAL; 99 port->num_requested_ctl_io = 100; 100 port->port_name = "tpc"; 101 port->port_online = tpcl_online; 102 port->port_offline = tpcl_offline; 103 port->onoff_arg = tsoftc; 104 port->lun_enable = tpcl_lun_enable; 105 port->lun_disable = tpcl_lun_disable; 106 port->targ_lun_arg = tsoftc; 107 port->fe_datamove = tpcl_datamove; 108 port->fe_done = tpcl_done; 109 port->max_targets = 1; 110 port->max_target_id = 0; 111 port->max_initiators = 1; 112 113 if (ctl_port_register(port) != 0) 114 { 115 printf("%s: tpc frontend registration failed\n", __func__); 116 return (0); 117 } 118 119 len = sizeof(struct scsi_transportid_spi); 120 port->init_devid = malloc(sizeof(struct ctl_devid) + len, 121 M_CTL, M_WAITOK | M_ZERO); 122 port->init_devid->len = len; 123 tid = (struct scsi_transportid_spi *)port->init_devid->data; 124 tid->format_protocol = SCSI_TRN_SPI_FORMAT_DEFAULT | SCSI_PROTO_SPI; 125 scsi_ulto2b(0, tid->scsi_addr); 126 scsi_ulto2b(port->targ_port, tid->rel_trgt_port_id); 127 128 ctl_port_online(port); 129 return (0); 130} 131 132void 133tpcl_shutdown(void) 134{ 135 struct tpcl_softc *tsoftc = &tpcl_softc; 136 struct ctl_port *port; 137 138 port = &tsoftc->port; 139 ctl_port_offline(port); 140 if (ctl_port_deregister(&tsoftc->port) != 0) 141 printf("%s: ctl_frontend_deregister() failed\n", __func__); 142} 143 144static void 145tpcl_online(void *arg) 146{ 147} 148 149static void 150tpcl_offline(void *arg) 151{ 152} 153 154static int 155tpcl_lun_enable(void *arg, struct ctl_id target_id, int lun_id) 156{ 157 158 return (0); 159} 160 161static int 162tpcl_lun_disable(void *arg, struct ctl_id target_id, int lun_id) 163{ 164 165 return (0); 166} 167 168static void 169tpcl_datamove(union ctl_io *io) 170{ 171 struct ctl_sg_entry *ext_sglist, *kern_sglist; 172 struct ctl_sg_entry ext_entry, kern_entry; 173 int ext_sg_entries, kern_sg_entries; 174 int ext_sg_start, ext_offset; 175 int len_to_copy, len_copied; 176 int kern_watermark, ext_watermark; 177 struct ctl_scsiio *ctsio; 178 int i, j; 179 180 ext_sg_start = 0; 181 ext_offset = 0; 182 ext_sglist = NULL; 183 184 CTL_DEBUG_PRINT(("%s\n", __func__)); 185 186 ctsio = &io->scsiio; 187 188 /* 189 * If this is the case, we're probably doing a BBR read and don't 190 * actually need to transfer the data. This will effectively 191 * bit-bucket the data. 192 */ 193 if (ctsio->ext_data_ptr == NULL) 194 goto bailout; 195 196 /* 197 * To simplify things here, if we have a single buffer, stick it in 198 * a S/G entry and just make it a single entry S/G list. 199 */ 200 if (ctsio->io_hdr.flags & CTL_FLAG_EDPTR_SGLIST) { 201 int len_seen; 202 203 ext_sglist = (struct ctl_sg_entry *)ctsio->ext_data_ptr; 204 ext_sg_entries = ctsio->ext_sg_entries; 205 ext_sg_start = 0; 206 ext_offset = 0; 207 len_seen = 0; 208 for (i = 0; i < ext_sg_entries; i++) { 209 if ((len_seen + ext_sglist[i].len) >= 210 ctsio->ext_data_filled) { 211 ext_sg_start = i; 212 ext_offset = ctsio->ext_data_filled - len_seen; 213 break; 214 } 215 len_seen += ext_sglist[i].len; 216 } 217 } else { 218 ext_sglist = &ext_entry; 219 ext_sglist->addr = ctsio->ext_data_ptr; 220 ext_sglist->len = ctsio->ext_data_len; 221 ext_sg_entries = 1; 222 ext_sg_start = 0; 223 ext_offset = ctsio->ext_data_filled; 224 } 225 226 if (ctsio->kern_sg_entries > 0) { 227 kern_sglist = (struct ctl_sg_entry *)ctsio->kern_data_ptr; 228 kern_sg_entries = ctsio->kern_sg_entries; 229 } else { 230 kern_sglist = &kern_entry; 231 kern_sglist->addr = ctsio->kern_data_ptr; 232 kern_sglist->len = ctsio->kern_data_len; 233 kern_sg_entries = 1; 234 } 235 236 kern_watermark = 0; 237 ext_watermark = ext_offset; 238 len_copied = 0; 239 for (i = ext_sg_start, j = 0; 240 i < ext_sg_entries && j < kern_sg_entries;) { 241 uint8_t *ext_ptr, *kern_ptr; 242 243 len_to_copy = min(ext_sglist[i].len - ext_watermark, 244 kern_sglist[j].len - kern_watermark); 245 246 ext_ptr = (uint8_t *)ext_sglist[i].addr; 247 ext_ptr = ext_ptr + ext_watermark; 248 if (io->io_hdr.flags & CTL_FLAG_BUS_ADDR) { 249 /* 250 * XXX KDM fix this! 251 */ 252 panic("need to implement bus address support"); 253#if 0 254 kern_ptr = bus_to_virt(kern_sglist[j].addr); 255#endif 256 } else 257 kern_ptr = (uint8_t *)kern_sglist[j].addr; 258 kern_ptr = kern_ptr + kern_watermark; 259 260 kern_watermark += len_to_copy; 261 ext_watermark += len_to_copy; 262 263 if ((ctsio->io_hdr.flags & CTL_FLAG_DATA_MASK) == 264 CTL_FLAG_DATA_IN) { 265 CTL_DEBUG_PRINT(("%s: copying %d bytes to user\n", 266 __func__, len_to_copy)); 267 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 268 kern_ptr, ext_ptr)); 269 memcpy(ext_ptr, kern_ptr, len_to_copy); 270 } else { 271 CTL_DEBUG_PRINT(("%s: copying %d bytes from user\n", 272 __func__, len_to_copy)); 273 CTL_DEBUG_PRINT(("%s: from %p to %p\n", __func__, 274 ext_ptr, kern_ptr)); 275 memcpy(kern_ptr, ext_ptr, len_to_copy); 276 } 277 278 len_copied += len_to_copy; 279 280 if (ext_sglist[i].len == ext_watermark) { 281 i++; 282 ext_watermark = 0; 283 } 284 285 if (kern_sglist[j].len == kern_watermark) { 286 j++; 287 kern_watermark = 0; 288 } 289 } 290 291 ctsio->ext_data_filled += len_copied; 292 293 CTL_DEBUG_PRINT(("%s: ext_sg_entries: %d, kern_sg_entries: %d\n", 294 __func__, ext_sg_entries, kern_sg_entries)); 295 CTL_DEBUG_PRINT(("%s: ext_data_len = %d, kern_data_len = %d\n", 296 __func__, ctsio->ext_data_len, ctsio->kern_data_len)); 297 298 /* XXX KDM set residual?? */ 299bailout: 300 io->scsiio.be_move_done(io); 301} 302 303static void 304tpcl_done(union ctl_io *io) 305{ 306 307 tpc_done(io); 308} 309 310uint64_t
|
315 struct scsi_ec_cscd_id *cscdid; 316 struct ctl_port *port; 317 struct ctl_lun *lun; 318 uint64_t lunid = UINT64_MAX, l; 319 int i; 320 321 if (cscd->type_code != EC_CSCD_ID) 322 return (lunid); 323 324 cscdid = (struct scsi_ec_cscd_id *)cscd; 325 mtx_lock(&softc->ctl_lock); 326 if (init_port >= 0) { 327 port = softc->ctl_ports[ctl_port_idx(init_port)]; 328 if (port == NULL || port->lun_map == NULL) 329 init_port = -1; 330 } 331 if (init_port < 0) { 332 STAILQ_FOREACH(lun, &softc->lun_list, links) { 333 if (lun->lun_devid == NULL) 334 continue; 335 if (scsi_devid_match(lun->lun_devid->data, 336 lun->lun_devid->len, &cscdid->codeset, 337 cscdid->length + 4) == 0) { 338 lunid = lun->lun; 339 if (ss && lun->be_lun) 340 *ss = lun->be_lun->blocksize; 341 break; 342 } 343 } 344 } else { 345 for (i = 0; i < CTL_MAX_LUNS; i++) { 346 l = port->lun_map(port->targ_lun_arg, i); 347 if (l >= CTL_MAX_LUNS) 348 continue; 349 lun = softc->ctl_luns[l]; 350 if (lun == NULL || lun->lun_devid == NULL) 351 continue; 352 if (scsi_devid_match(lun->lun_devid->data, 353 lun->lun_devid->len, &cscdid->codeset, 354 cscdid->length + 4) == 0) { 355 lunid = lun->lun; 356 if (ss && lun->be_lun) 357 *ss = lun->be_lun->blocksize; 358 break; 359 } 360 } 361 } 362 mtx_unlock(&softc->ctl_lock); 363 return (lunid); 364}; 365 366union ctl_io * 367tpcl_alloc_io(void) 368{ 369 struct tpcl_softc *tsoftc = &tpcl_softc; 370 371 return (ctl_alloc_io(tsoftc->port.ctl_pool_ref)); 372}; 373 374int 375tpcl_queue(union ctl_io *io, uint64_t lun) 376{ 377 struct tpcl_softc *tsoftc = &tpcl_softc; 378 379 io->io_hdr.nexus.initid.id = 0; 380 io->io_hdr.nexus.targ_port = tsoftc->port.targ_port; 381 io->io_hdr.nexus.targ_target.id = 0; 382 io->io_hdr.nexus.targ_lun = lun; 383 io->scsiio.tag_num = atomic_fetchadd_int(&tsoftc->cur_tag_num, 1); 384 io->scsiio.ext_data_filled = 0; 385 return (ctl_queue(io)); 386}
| 314 struct scsi_ec_cscd_id *cscdid; 315 struct ctl_port *port; 316 struct ctl_lun *lun; 317 uint64_t lunid = UINT64_MAX, l; 318 int i; 319 320 if (cscd->type_code != EC_CSCD_ID) 321 return (lunid); 322 323 cscdid = (struct scsi_ec_cscd_id *)cscd; 324 mtx_lock(&softc->ctl_lock); 325 if (init_port >= 0) { 326 port = softc->ctl_ports[ctl_port_idx(init_port)]; 327 if (port == NULL || port->lun_map == NULL) 328 init_port = -1; 329 } 330 if (init_port < 0) { 331 STAILQ_FOREACH(lun, &softc->lun_list, links) { 332 if (lun->lun_devid == NULL) 333 continue; 334 if (scsi_devid_match(lun->lun_devid->data, 335 lun->lun_devid->len, &cscdid->codeset, 336 cscdid->length + 4) == 0) { 337 lunid = lun->lun; 338 if (ss && lun->be_lun) 339 *ss = lun->be_lun->blocksize; 340 break; 341 } 342 } 343 } else { 344 for (i = 0; i < CTL_MAX_LUNS; i++) { 345 l = port->lun_map(port->targ_lun_arg, i); 346 if (l >= CTL_MAX_LUNS) 347 continue; 348 lun = softc->ctl_luns[l]; 349 if (lun == NULL || lun->lun_devid == NULL) 350 continue; 351 if (scsi_devid_match(lun->lun_devid->data, 352 lun->lun_devid->len, &cscdid->codeset, 353 cscdid->length + 4) == 0) { 354 lunid = lun->lun; 355 if (ss && lun->be_lun) 356 *ss = lun->be_lun->blocksize; 357 break; 358 } 359 } 360 } 361 mtx_unlock(&softc->ctl_lock); 362 return (lunid); 363}; 364 365union ctl_io * 366tpcl_alloc_io(void) 367{ 368 struct tpcl_softc *tsoftc = &tpcl_softc; 369 370 return (ctl_alloc_io(tsoftc->port.ctl_pool_ref)); 371}; 372 373int 374tpcl_queue(union ctl_io *io, uint64_t lun) 375{ 376 struct tpcl_softc *tsoftc = &tpcl_softc; 377 378 io->io_hdr.nexus.initid.id = 0; 379 io->io_hdr.nexus.targ_port = tsoftc->port.targ_port; 380 io->io_hdr.nexus.targ_target.id = 0; 381 io->io_hdr.nexus.targ_lun = lun; 382 io->scsiio.tag_num = atomic_fetchadd_int(&tsoftc->cur_tag_num, 1); 383 io->scsiio.ext_data_filled = 0; 384 return (ctl_queue(io)); 385}
|