hv_storvsc_drv_freebsd.c (255524) | hv_storvsc_drv_freebsd.c (256276) |
---|---|
1/*- 2 * Copyright (c) 2009-2012 Microsoft Corp. 3 * Copyright (c) 2012 NetApp Inc. 4 * Copyright (c) 2012 Citrix Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 18 unchanged lines hidden (view full) --- 27 */ 28 29/** 30 * StorVSC driver for Hyper-V. This driver presents a SCSI HBA interface 31 * to the Comman Access Method (CAM) layer. CAM control blocks (CCBs) are 32 * converted into VSCSI protocol messages which are delivered to the parent 33 * partition StorVSP driver over the Hyper-V VMBUS. 34 */ | 1/*- 2 * Copyright (c) 2009-2012 Microsoft Corp. 3 * Copyright (c) 2012 NetApp Inc. 4 * Copyright (c) 2012 Citrix Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 18 unchanged lines hidden (view full) --- 27 */ 28 29/** 30 * StorVSC driver for Hyper-V. This driver presents a SCSI HBA interface 31 * to the Comman Access Method (CAM) layer. CAM control blocks (CCBs) are 32 * converted into VSCSI protocol messages which are delivered to the parent 33 * partition StorVSP driver over the Hyper-V VMBUS. 34 */ |
35#include <sys/cdefs.h> 36__FBSDID("$FreeBSD: head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c 256276 2013-10-10 16:25:53Z dim $"); |
|
35 36#include <sys/param.h> 37#include <sys/proc.h> 38#include <sys/condvar.h> 39#include <sys/systm.h> 40#include <sys/sockio.h> 41#include <sys/mbuf.h> 42#include <sys/malloc.h> --- 274 unchanged lines hidden (view full) --- 317 } 318 319 /* reuse the packet for version range supported */ 320 321 memset(vstor_packet, 0, sizeof(struct vstor_packet)); 322 vstor_packet->operation = VSTOR_OPERATION_QUERYPROTOCOLVERSION; 323 vstor_packet->flags = REQUEST_COMPLETION_FLAG; 324 | 37 38#include <sys/param.h> 39#include <sys/proc.h> 40#include <sys/condvar.h> 41#include <sys/systm.h> 42#include <sys/sockio.h> 43#include <sys/mbuf.h> 44#include <sys/malloc.h> --- 274 unchanged lines hidden (view full) --- 319 } 320 321 /* reuse the packet for version range supported */ 322 323 memset(vstor_packet, 0, sizeof(struct vstor_packet)); 324 vstor_packet->operation = VSTOR_OPERATION_QUERYPROTOCOLVERSION; 325 vstor_packet->flags = REQUEST_COMPLETION_FLAG; 326 |
325 vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT; | 327 vstor_packet->u.version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT; |
326 327 /* revision is only significant for Windows guests */ | 328 329 /* revision is only significant for Windows guests */ |
328 vstor_packet->version.revision = 0; | 330 vstor_packet->u.version.revision = 0; |
329 330 ret = hv_vmbus_channel_send_packet( 331 dev->channel, 332 vstor_packet, 333 sizeof(struct vstor_packet), 334 (uint64_t)request, 335 HV_VMBUS_PACKET_TYPE_DATA_IN_BAND, 336 HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); --- 190 unchanged lines hidden (view full) --- 527 sc = get_stor_device(device, TRUE); 528 529 if (sc == NULL) { 530 return ENODEV; 531 } 532 533 vstor_packet->flags |= REQUEST_COMPLETION_FLAG; 534 | 331 332 ret = hv_vmbus_channel_send_packet( 333 dev->channel, 334 vstor_packet, 335 sizeof(struct vstor_packet), 336 (uint64_t)request, 337 HV_VMBUS_PACKET_TYPE_DATA_IN_BAND, 338 HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); --- 190 unchanged lines hidden (view full) --- 529 sc = get_stor_device(device, TRUE); 530 531 if (sc == NULL) { 532 return ENODEV; 533 } 534 535 vstor_packet->flags |= REQUEST_COMPLETION_FLAG; 536 |
535 vstor_packet->vm_srb.length = sizeof(struct vmscsi_req); | 537 vstor_packet->u.vm_srb.length = sizeof(struct vmscsi_req); |
536 | 538 |
537 vstor_packet->vm_srb.sense_info_len = SENSE_BUFFER_SIZE; | 539 vstor_packet->u.vm_srb.sense_info_len = SENSE_BUFFER_SIZE; |
538 | 540 |
539 vstor_packet->vm_srb.transfer_len = request->data_buf.length; | 541 vstor_packet->u.vm_srb.transfer_len = request->data_buf.length; |
540 541 vstor_packet->operation = VSTOR_OPERATION_EXECUTESRB; 542 543 544 mtx_unlock(&request->softc->hs_lock); 545 if (request->data_buf.length) { 546 ret = hv_vmbus_channel_send_packet_multipagebuffer( 547 device->channel, --- 30 unchanged lines hidden (view full) --- 578 */ 579static void 580hv_storvsc_on_iocompletion(struct storvsc_softc *sc, 581 struct vstor_packet *vstor_packet, 582 struct hv_storvsc_request *request) 583{ 584 struct vmscsi_req *vm_srb; 585 | 542 543 vstor_packet->operation = VSTOR_OPERATION_EXECUTESRB; 544 545 546 mtx_unlock(&request->softc->hs_lock); 547 if (request->data_buf.length) { 548 ret = hv_vmbus_channel_send_packet_multipagebuffer( 549 device->channel, --- 30 unchanged lines hidden (view full) --- 580 */ 581static void 582hv_storvsc_on_iocompletion(struct storvsc_softc *sc, 583 struct vstor_packet *vstor_packet, 584 struct hv_storvsc_request *request) 585{ 586 struct vmscsi_req *vm_srb; 587 |
586 vm_srb = &vstor_packet->vm_srb; | 588 vm_srb = &vstor_packet->u.vm_srb; |
587 588 request->sense_info_len = 0; 589 if (((vm_srb->scsi_status & 0xFF) == SCSI_STATUS_CHECK_COND) && 590 (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID)) { 591 /* Autosense data available */ 592 593 KASSERT(vm_srb->sense_info_len <= request->sense_info_len, 594 ("vm_srb->sense_info_len <= " 595 "request->sense_info_len")); 596 | 589 590 request->sense_info_len = 0; 591 if (((vm_srb->scsi_status & 0xFF) == SCSI_STATUS_CHECK_COND) && 592 (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID)) { 593 /* Autosense data available */ 594 595 KASSERT(vm_srb->sense_info_len <= request->sense_info_len, 596 ("vm_srb->sense_info_len <= " 597 "request->sense_info_len")); 598 |
597 memcpy(request->sense_data, vm_srb->sense_data, | 599 memcpy(request->sense_data, vm_srb->u.sense_data, |
598 vm_srb->sense_info_len); 599 600 request->sense_info_len = vm_srb->sense_info_len; 601 } 602 603 /* Complete request by passing to the CAM layer */ 604 storvsc_io_done(request); 605 atomic_subtract_int(&sc->hs_num_out_reqs, 1); --- 687 unchanged lines hidden (view full) --- 1293{ 1294 struct ccb_scsiio *csio = &ccb->csio; 1295 uint64_t phys_addr; 1296 uint32_t bytes_to_copy = 0; 1297 uint32_t pfn_num = 0; 1298 uint32_t pfn; 1299 1300 /* refer to struct vmscsi_req for meanings of these two fields */ | 600 vm_srb->sense_info_len); 601 602 request->sense_info_len = vm_srb->sense_info_len; 603 } 604 605 /* Complete request by passing to the CAM layer */ 606 storvsc_io_done(request); 607 atomic_subtract_int(&sc->hs_num_out_reqs, 1); --- 687 unchanged lines hidden (view full) --- 1295{ 1296 struct ccb_scsiio *csio = &ccb->csio; 1297 uint64_t phys_addr; 1298 uint32_t bytes_to_copy = 0; 1299 uint32_t pfn_num = 0; 1300 uint32_t pfn; 1301 1302 /* refer to struct vmscsi_req for meanings of these two fields */ |
1301 reqp->vstor_packet.vm_srb.port = | 1303 reqp->vstor_packet.u.vm_srb.port = |
1302 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)); | 1304 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)); |
1303 reqp->vstor_packet.vm_srb.path_id = | 1305 reqp->vstor_packet.u.vm_srb.path_id = |
1304 cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)); 1305 | 1306 cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)); 1307 |
1306 reqp->vstor_packet.vm_srb.target_id = ccb->ccb_h.target_id; 1307 reqp->vstor_packet.vm_srb.lun = ccb->ccb_h.target_lun; | 1308 reqp->vstor_packet.u.vm_srb.target_id = ccb->ccb_h.target_id; 1309 reqp->vstor_packet.u.vm_srb.lun = ccb->ccb_h.target_lun; |
1308 | 1310 |
1309 reqp->vstor_packet.vm_srb.cdb_len = csio->cdb_len; | 1311 reqp->vstor_packet.u.vm_srb.cdb_len = csio->cdb_len; |
1310 if(ccb->ccb_h.flags & CAM_CDB_POINTER) { | 1312 if(ccb->ccb_h.flags & CAM_CDB_POINTER) { |
1311 memcpy(&reqp->vstor_packet.vm_srb.cdb, csio->cdb_io.cdb_ptr, | 1313 memcpy(&reqp->vstor_packet.u.vm_srb.u.cdb, csio->cdb_io.cdb_ptr, |
1312 csio->cdb_len); 1313 } else { | 1314 csio->cdb_len); 1315 } else { |
1314 memcpy(&reqp->vstor_packet.vm_srb.cdb, csio->cdb_io.cdb_bytes, | 1316 memcpy(&reqp->vstor_packet.u.vm_srb.u.cdb, csio->cdb_io.cdb_bytes, |
1315 csio->cdb_len); 1316 } 1317 1318 switch (ccb->ccb_h.flags & CAM_DIR_MASK) { 1319 case CAM_DIR_OUT: | 1317 csio->cdb_len); 1318 } 1319 1320 switch (ccb->ccb_h.flags & CAM_DIR_MASK) { 1321 case CAM_DIR_OUT: |
1320 reqp->vstor_packet.vm_srb.data_in = WRITE_TYPE; | 1322 reqp->vstor_packet.u.vm_srb.data_in = WRITE_TYPE; |
1321 break; 1322 case CAM_DIR_IN: | 1323 break; 1324 case CAM_DIR_IN: |
1323 reqp->vstor_packet.vm_srb.data_in = READ_TYPE; | 1325 reqp->vstor_packet.u.vm_srb.data_in = READ_TYPE; |
1324 break; 1325 case CAM_DIR_NONE: | 1326 break; 1327 case CAM_DIR_NONE: |
1326 reqp->vstor_packet.vm_srb.data_in = UNKNOWN_TYPE; | 1328 reqp->vstor_packet.u.vm_srb.data_in = UNKNOWN_TYPE; |
1327 break; 1328 default: | 1329 break; 1330 default: |
1329 reqp->vstor_packet.vm_srb.data_in = UNKNOWN_TYPE; | 1331 reqp->vstor_packet.u.vm_srb.data_in = UNKNOWN_TYPE; |
1330 break; 1331 } 1332 1333 reqp->sense_data = &csio->sense_data; 1334 reqp->sense_info_len = csio->sense_len; 1335 1336 reqp->ccb = ccb; 1337 /* --- 32 unchanged lines hidden (view full) --- 1370 * @param reqp pointer to a request structure 1371 */ 1372static void 1373storvsc_io_done(struct hv_storvsc_request *reqp) 1374{ 1375 union ccb *ccb = reqp->ccb; 1376 struct ccb_scsiio *csio = &ccb->csio; 1377 struct storvsc_softc *sc = reqp->softc; | 1332 break; 1333 } 1334 1335 reqp->sense_data = &csio->sense_data; 1336 reqp->sense_info_len = csio->sense_len; 1337 1338 reqp->ccb = ccb; 1339 /* --- 32 unchanged lines hidden (view full) --- 1372 * @param reqp pointer to a request structure 1373 */ 1374static void 1375storvsc_io_done(struct hv_storvsc_request *reqp) 1376{ 1377 union ccb *ccb = reqp->ccb; 1378 struct ccb_scsiio *csio = &ccb->csio; 1379 struct storvsc_softc *sc = reqp->softc; |
1378 struct vmscsi_req *vm_srb = &reqp->vstor_packet.vm_srb; | 1380 struct vmscsi_req *vm_srb = &reqp->vstor_packet.u.vm_srb; |
1379 1380 if (reqp->retries > 0) { 1381 mtx_lock(&sc->hs_lock); 1382#if HVS_TIMEOUT_TEST 1383 xpt_print(ccb->ccb_h.path, 1384 "%u: IO returned after timeout, " 1385 "waking up timer handler if any.\n", ticks); 1386 mtx_lock(&reqp->event.mtx); --- 92 unchanged lines hidden --- | 1381 1382 if (reqp->retries > 0) { 1383 mtx_lock(&sc->hs_lock); 1384#if HVS_TIMEOUT_TEST 1385 xpt_print(ccb->ccb_h.path, 1386 "%u: IO returned after timeout, " 1387 "waking up timer handler if any.\n", ticks); 1388 mtx_lock(&reqp->event.mtx); --- 92 unchanged lines hidden --- |