Lines Matching +full:sub +full:- +full:messages
1 // SPDX-License-Identifier: GPL-2.0-only
24 #include <linux/dma-mapping.h>
135 * Platform neutral description of a scsi request -
161 "Logging level, 0 - None, 1 - Error (default), 2 - Warning.");
171 dev_warn(&(dev)->device, fmt, ##__VA_ARGS__); \
177 dev_warn_ratelimited(&(dev)->device, fmt, ##__VA_ARGS__); \
249 * Revision number is auto-incremented whenever this file is changed
251 * definitely indicate incompatibility--but it does indicate mismatched
266 /* Flags - see below for values */
289 /* Number of sub-channels to create */
306 /* Matches Windows-end */
314 * SRB status codes and masks. In the 8-bit field, the two high order bits
434 * Number of sub-channels we will open.
484 sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun); in storvsc_device_scan()
501 host = host_device->host; in storvsc_host_scan()
513 mutex_lock(&host->scan_mutex); in storvsc_host_scan()
516 mutex_unlock(&host->scan_mutex); in storvsc_host_scan()
529 if (!scsi_host_get(wrk->host)) in storvsc_remove_lun()
532 sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun); in storvsc_remove_lun()
538 scsi_host_put(wrk->host); in storvsc_remove_lun()
546 * We can get incoming messages from the host that are not in response to
547 * messages that we have sent out. An example of this would be messages
555 * outgoing messages.
556 * 2) We permit incoming messages when the device is being destroyed,
557 * only to properly account for messages already sent out.
567 if (stor_device && stor_device->destroy) in get_out_stor_device()
576 dev->drain_notify = true; in storvsc_wait_to_drain()
577 wait_event(dev->waiting_to_drain, in storvsc_wait_to_drain()
578 atomic_read(&dev->num_outstanding_req) == 0); in storvsc_wait_to_drain()
579 dev->drain_notify = false; in storvsc_wait_to_drain()
597 if (stor_device->destroy && in get_in_stor_device()
598 (atomic_read(&stor_device->num_outstanding_req) == 0)) in get_in_stor_device()
616 device = channel->primary_channel ? in storvsc_change_target_cpu()
617 channel->primary_channel->device_obj in storvsc_change_target_cpu()
618 : channel->device_obj; in storvsc_change_target_cpu()
623 /* See storvsc_do_io() -> get_og_chn(). */ in storvsc_change_target_cpu()
624 spin_lock_irqsave(&stor_device->lock, flags); in storvsc_change_target_cpu()
631 if (device->channel != channel && device->channel->target_cpu == old) { in storvsc_change_target_cpu()
632 cur_chn = device->channel; in storvsc_change_target_cpu()
636 list_for_each_entry(cur_chn, &device->channel->sc_list, sc_list) { in storvsc_change_target_cpu()
639 if (cur_chn->target_cpu == old) { in storvsc_change_target_cpu()
647 WRITE_ONCE(stor_device->stor_chns[old], cur_chn); in storvsc_change_target_cpu()
649 cpumask_clear_cpu(old, &stor_device->alloced_cpus); in storvsc_change_target_cpu()
653 if (stor_device->stor_chns[cpu] && !cpumask_test_cpu( in storvsc_change_target_cpu()
654 cpu, &stor_device->alloced_cpus)) in storvsc_change_target_cpu()
655 WRITE_ONCE(stor_device->stor_chns[cpu], NULL); in storvsc_change_target_cpu()
658 WRITE_ONCE(stor_device->stor_chns[new], channel); in storvsc_change_target_cpu()
659 cpumask_set_cpu(new, &stor_device->alloced_cpus); in storvsc_change_target_cpu()
661 spin_unlock_irqrestore(&stor_device->lock, flags); in storvsc_change_target_cpu()
676 * message from Hyper-V. in storvsc_next_request_id()
678 return (u64)blk_mq_unique_tag(scsi_cmd_to_rq(request->cmd)) + 1; in storvsc_next_request_id()
683 struct hv_device *device = new_sc->primary_channel->device_obj; in handle_sc_creation()
684 struct device *dev = &device->device; in handle_sc_creation()
694 new_sc->max_pkt_size = STORVSC_MAX_PKT_SIZE; in handle_sc_creation()
696 new_sc->next_request_id_callback = storvsc_next_request_id; in handle_sc_creation()
705 /* In case vmbus_open() fails, we don't use the sub-channel. */ in handle_sc_creation()
707 dev_err(dev, "Failed to open sub-channel: err=%d\n", ret); in handle_sc_creation()
711 new_sc->change_target_cpu_callback = storvsc_change_target_cpu; in handle_sc_creation()
713 /* Add the sub-channel to the array of available channels. */ in handle_sc_creation()
714 stor_device->stor_chns[new_sc->target_cpu] = new_sc; in handle_sc_creation()
715 cpumask_set_cpu(new_sc->target_cpu, &stor_device->alloced_cpus); in handle_sc_creation()
720 struct device *dev = &device->device; in handle_multichannel_storage()
729 * with maxcpus=1 on the kernel boot line, Hyper-V could offer in handle_multichannel_storage()
730 * sub-channels >= the number of CPUs. These sub-channels in handle_multichannel_storage()
732 * and assigned to one CPU, so check against # CPUs - 1. in handle_multichannel_storage()
734 num_sc = min((int)(num_online_cpus() - 1), max_chns); in handle_multichannel_storage()
742 stor_device->num_sc = num_sc; in handle_multichannel_storage()
743 request = &stor_device->init_request; in handle_multichannel_storage()
744 vstor_packet = &request->vstor_packet; in handle_multichannel_storage()
749 vmbus_set_sc_create_callback(device->channel, handle_sc_creation); in handle_multichannel_storage()
752 * Request the host to create sub-channels. in handle_multichannel_storage()
755 init_completion(&request->wait_event); in handle_multichannel_storage()
756 vstor_packet->operation = VSTOR_OPERATION_CREATE_SUB_CHANNELS; in handle_multichannel_storage()
757 vstor_packet->flags = REQUEST_COMPLETION_FLAG; in handle_multichannel_storage()
758 vstor_packet->sub_channel_count = num_sc; in handle_multichannel_storage()
760 ret = vmbus_sendpacket(device->channel, vstor_packet, in handle_multichannel_storage()
767 dev_err(dev, "Failed to create sub-channel: err=%d\n", ret); in handle_multichannel_storage()
771 t = wait_for_completion_timeout(&request->wait_event, 10*HZ); in handle_multichannel_storage()
773 dev_err(dev, "Failed to create sub-channel: timed out\n"); in handle_multichannel_storage()
777 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || in handle_multichannel_storage()
778 vstor_packet->status != 0) { in handle_multichannel_storage()
779 dev_err(dev, "Failed to create sub-channel: op=%d, sts=%d\n", in handle_multichannel_storage()
780 vstor_packet->operation, vstor_packet->status); in handle_multichannel_storage()
786 * invokes channel->sc_creation_callback, which will open and use in handle_multichannel_storage()
787 * the sub-channel(s). in handle_multichannel_storage()
797 if (vstor_packet->wwn_packet.primary_active) { in cache_wwn()
798 stor_device->node_name = in cache_wwn()
799 wwn_to_u64(vstor_packet->wwn_packet.primary_node_wwn); in cache_wwn()
800 stor_device->port_name = in cache_wwn()
801 wwn_to_u64(vstor_packet->wwn_packet.primary_port_wwn); in cache_wwn()
803 stor_device->node_name = in cache_wwn()
804 wwn_to_u64(vstor_packet->wwn_packet.secondary_node_wwn); in cache_wwn()
805 stor_device->port_name = in cache_wwn()
806 wwn_to_u64(vstor_packet->wwn_packet.secondary_port_wwn); in cache_wwn()
821 return -ENODEV; in storvsc_execute_vstor_op()
823 vstor_packet = &request->vstor_packet; in storvsc_execute_vstor_op()
825 init_completion(&request->wait_event); in storvsc_execute_vstor_op()
826 vstor_packet->flags = REQUEST_COMPLETION_FLAG; in storvsc_execute_vstor_op()
828 ret = vmbus_sendpacket(device->channel, vstor_packet, in storvsc_execute_vstor_op()
836 t = wait_for_completion_timeout(&request->wait_event, 5*HZ); in storvsc_execute_vstor_op()
838 return -ETIMEDOUT; in storvsc_execute_vstor_op()
843 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || in storvsc_execute_vstor_op()
844 vstor_packet->status != 0) in storvsc_execute_vstor_op()
845 return -EINVAL; in storvsc_execute_vstor_op()
861 return -ENODEV; in storvsc_channel_init()
863 request = &stor_device->init_request; in storvsc_channel_init()
864 vstor_packet = &request->vstor_packet; in storvsc_channel_init()
871 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION; in storvsc_channel_init()
882 vstor_packet->operation = in storvsc_channel_init()
885 vstor_packet->version.major_minor = protocol_version[i]; in storvsc_channel_init()
890 vstor_packet->version.revision = 0; in storvsc_channel_init()
895 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO) in storvsc_channel_init()
896 return -EINVAL; in storvsc_channel_init()
898 if (vstor_packet->status == 0) { in storvsc_channel_init()
905 if (vstor_packet->status != 0) { in storvsc_channel_init()
906 dev_err(&device->device, "Obsolete Hyper-V version\n"); in storvsc_channel_init()
907 return -EINVAL; in storvsc_channel_init()
912 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES; in storvsc_channel_init()
918 * Check to see if multi-channel support is there. in storvsc_channel_init()
920 * support multi-channel. in storvsc_channel_init()
922 max_chns = vstor_packet->storage_channel_properties.max_channel_cnt; in storvsc_channel_init()
925 * Allocate state to manage the sub-channels. in storvsc_channel_init()
928 * primary + sub-channels. As I/Os are initiated by different CPUs, in storvsc_channel_init()
932 stor_device->stor_chns = kcalloc(nr_cpu_ids, sizeof(void *), in storvsc_channel_init()
934 if (stor_device->stor_chns == NULL) in storvsc_channel_init()
935 return -ENOMEM; in storvsc_channel_init()
937 device->channel->change_target_cpu_callback = storvsc_change_target_cpu; in storvsc_channel_init()
939 stor_device->stor_chns[device->channel->target_cpu] = device->channel; in storvsc_channel_init()
940 cpumask_set_cpu(device->channel->target_cpu, in storvsc_channel_init()
941 &stor_device->alloced_cpus); in storvsc_channel_init()
943 if (vstor_packet->storage_channel_properties.flags & in storvsc_channel_init()
947 stor_device->max_transfer_bytes = in storvsc_channel_init()
948 vstor_packet->storage_channel_properties.max_transfer_bytes; in storvsc_channel_init()
957 vstor_packet->operation = VSTOR_OPERATION_FCHBA_DATA; in storvsc_channel_init()
970 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION; in storvsc_channel_init()
990 switch (SRB_STATUS(vm_srb->srb_status)) { in storvsc_handle_error()
999 if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID) { in storvsc_handle_error()
1010 * due to Hyper-V changing the VHD/VHDX BlockSize in storvsc_handle_error()
1035 * were a pass-through command deal with it appropriately. in storvsc_handle_error()
1037 switch (scmnd->cmnd[0]) { in storvsc_handle_error()
1043 * On some Hyper-V hosts TEST_UNIT_READY command can in storvsc_handle_error()
1072 wrk->host = host; in storvsc_handle_error()
1073 wrk->lun = vm_srb->lun; in storvsc_handle_error()
1074 wrk->tgt_id = vm_srb->target_id; in storvsc_handle_error()
1075 INIT_WORK(&wrk->work, process_err_fn); in storvsc_handle_error()
1076 queue_work(host_dev->handle_error_wq, &wrk->work); in storvsc_handle_error()
1083 struct scsi_cmnd *scmnd = cmd_request->cmd; in storvsc_command_completion()
1088 u32 payload_sz = cmd_request->payload_sz; in storvsc_command_completion()
1089 void *payload = cmd_request->payload; in storvsc_command_completion()
1092 host = stor_dev->host; in storvsc_command_completion()
1094 vm_srb = &cmd_request->vstor_packet.vm_srb; in storvsc_command_completion()
1095 data_transfer_length = vm_srb->data_transfer_length; in storvsc_command_completion()
1097 scmnd->result = vm_srb->scsi_status; in storvsc_command_completion()
1099 if (scmnd->result) { in storvsc_command_completion()
1100 sense_ok = scsi_normalize_sense(scmnd->sense_buffer, in storvsc_command_completion()
1104 scsi_print_sense_hdr(scmnd->device, "storvsc", in storvsc_command_completion()
1108 if (vm_srb->srb_status != SRB_STATUS_SUCCESS) { in storvsc_command_completion()
1116 if (vm_srb->srb_status != SRB_STATUS_DATA_OVERRUN) in storvsc_command_completion()
1120 /* Validate data_transfer_length (from Hyper-V) */ in storvsc_command_completion()
1121 if (data_transfer_length > cmd_request->payload->range.len) in storvsc_command_completion()
1122 data_transfer_length = cmd_request->payload->range.len; in storvsc_command_completion()
1125 cmd_request->payload->range.len - data_transfer_length); in storvsc_command_completion()
1139 struct hv_device *device = stor_device->device; in storvsc_on_io_completion()
1141 stor_pkt = &request->vstor_packet; in storvsc_on_io_completion()
1152 * (srb status == 0x4) and off-line the device in that case. in storvsc_on_io_completion()
1155 if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) || in storvsc_on_io_completion()
1156 (stor_pkt->vm_srb.cdb[0] == MODE_SENSE) || in storvsc_on_io_completion()
1157 (stor_pkt->vm_srb.cdb[0] == MAINTENANCE_IN && in storvsc_on_io_completion()
1159 vstor_packet->vm_srb.scsi_status = 0; in storvsc_on_io_completion()
1160 vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS; in storvsc_on_io_completion()
1164 stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status; in storvsc_on_io_completion()
1165 stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status; in storvsc_on_io_completion()
1169 * size if Hyper-V returns a bad value. in storvsc_on_io_completion()
1171 stor_pkt->vm_srb.sense_info_length = min_t(u8, STORVSC_SENSE_BUFFER_SIZE, in storvsc_on_io_completion()
1172 vstor_packet->vm_srb.sense_info_length); in storvsc_on_io_completion()
1174 if (vstor_packet->vm_srb.scsi_status != 0 || in storvsc_on_io_completion()
1175 vstor_packet->vm_srb.srb_status != SRB_STATUS_SUCCESS) { in storvsc_on_io_completion()
1178 * Log TEST_UNIT_READY errors only as warnings. Hyper-V can in storvsc_on_io_completion()
1182 int loglevel = (stor_pkt->vm_srb.cdb[0] == TEST_UNIT_READY) ? in storvsc_on_io_completion()
1187 scsi_cmd_to_rq(request->cmd)->tag, in storvsc_on_io_completion()
1188 stor_pkt->vm_srb.cdb[0], in storvsc_on_io_completion()
1189 vstor_packet->vm_srb.scsi_status, in storvsc_on_io_completion()
1190 vstor_packet->vm_srb.srb_status, in storvsc_on_io_completion()
1191 vstor_packet->status); in storvsc_on_io_completion()
1194 if (vstor_packet->vm_srb.scsi_status == SAM_STAT_CHECK_CONDITION && in storvsc_on_io_completion()
1195 (vstor_packet->vm_srb.srb_status & SRB_STATUS_AUTOSENSE_VALID)) in storvsc_on_io_completion()
1196 memcpy(request->cmd->sense_buffer, in storvsc_on_io_completion()
1197 vstor_packet->vm_srb.sense_data, in storvsc_on_io_completion()
1198 stor_pkt->vm_srb.sense_info_length); in storvsc_on_io_completion()
1200 stor_pkt->vm_srb.data_transfer_length = in storvsc_on_io_completion()
1201 vstor_packet->vm_srb.data_transfer_length; in storvsc_on_io_completion()
1205 if (atomic_dec_and_test(&stor_device->num_outstanding_req) && in storvsc_on_io_completion()
1206 stor_device->drain_notify) in storvsc_on_io_completion()
1207 wake_up(&stor_device->waiting_to_drain); in storvsc_on_io_completion()
1215 switch (vstor_packet->operation) { in storvsc_on_receive()
1222 host_dev = shost_priv(stor_device->host); in storvsc_on_receive()
1224 host_dev->handle_error_wq, &host_dev->host_scan_work); in storvsc_on_receive()
1230 fc_host_node_name(stor_device->host) = stor_device->node_name; in storvsc_on_receive()
1231 fc_host_port_name(stor_device->host) = stor_device->port_name; in storvsc_on_receive()
1248 if (channel->primary_channel != NULL) in storvsc_on_channel_callback()
1249 device = channel->primary_channel->device_obj; in storvsc_on_channel_callback()
1251 device = channel->device_obj; in storvsc_on_channel_callback()
1257 shost = stor_device->host; in storvsc_on_channel_callback()
1263 u64 rqst_id = desc->trans_id; in storvsc_on_channel_callback()
1273 dev_err(&device->device, in storvsc_on_channel_callback()
1280 request = &stor_device->init_request; in storvsc_on_channel_callback()
1282 request = &stor_device->reset_request; in storvsc_on_channel_callback()
1284 /* Hyper-V can send an unsolicited message with ID of 0 */ in storvsc_on_channel_callback()
1290 * - If the operation in the vstor_packet is COMPLETE_IO, then in storvsc_on_channel_callback()
1294 * that is zero if Hyper-V were to construct and send such in storvsc_on_channel_callback()
1297 * - If the operation in the vstor_packet is FCHBA_DATA, then in storvsc_on_channel_callback()
1301 * Future-proof the code by rejecting such a bogus packet. in storvsc_on_channel_callback()
1303 if (packet->operation == VSTOR_OPERATION_COMPLETE_IO || in storvsc_on_channel_callback()
1304 packet->operation == VSTOR_OPERATION_FCHBA_DATA) { in storvsc_on_channel_callback()
1305 dev_err(&device->device, "Invalid packet with ID of 0\n"); in storvsc_on_channel_callback()
1311 /* Transaction 'rqst_id' corresponds to tag 'rqst_id - 1' */ in storvsc_on_channel_callback()
1312 scmnd = scsi_host_find_tag(shost, rqst_id - 1); in storvsc_on_channel_callback()
1314 dev_err(&device->device, "Incorrect transaction ID\n"); in storvsc_on_channel_callback()
1325 memcpy(&request->vstor_packet, packet, in storvsc_on_channel_callback()
1327 complete(&request->wait_event); in storvsc_on_channel_callback()
1339 device->channel->max_pkt_size = STORVSC_MAX_PKT_SIZE; in storvsc_connect_to_vsp()
1340 device->channel->next_request_id_callback = storvsc_next_request_id; in storvsc_connect_to_vsp()
1342 ret = vmbus_open(device->channel, in storvsc_connect_to_vsp()
1347 storvsc_on_channel_callback, device->channel); in storvsc_connect_to_vsp()
1363 stor_device->destroy = true; in storvsc_dev_remove()
1380 * we have drained - to drain the outgoing packets, we need to in storvsc_dev_remove()
1386 vmbus_close(device->channel); in storvsc_dev_remove()
1388 kfree(stor_device->stor_chns); in storvsc_dev_remove()
1401 if (stor_device->num_sc == 0) { in get_og_chn()
1402 stor_device->stor_chns[q_num] = stor_device->device->channel; in get_og_chn()
1403 return stor_device->device->channel; in get_og_chn()
1408 * initiated I/O on a processor/hw-q that does not in get_og_chn()
1418 for_each_cpu(tgt_cpu, &stor_device->alloced_cpus) { in get_og_chn()
1423 stor_device->stor_chns[q_num] = stor_device->device->channel; in get_og_chn()
1424 return stor_device->device->channel; in get_og_chn()
1429 hash_qnum -= num_channels; in get_og_chn()
1431 for_each_cpu(tgt_cpu, &stor_device->alloced_cpus) { in get_og_chn()
1439 stor_device->stor_chns[q_num] = stor_device->stor_chns[tgt_cpu]; in get_og_chn()
1441 return stor_device->stor_chns[q_num]; in get_og_chn()
1456 vstor_packet = &request->vstor_packet; in storvsc_do_io()
1460 return -ENODEV; in storvsc_do_io()
1463 request->device = device; in storvsc_do_io()
1468 outgoing_channel = READ_ONCE(stor_device->stor_chns[q_num]); in storvsc_do_io()
1470 if (outgoing_channel->target_cpu == q_num) { in storvsc_do_io()
1477 &stor_device->alloced_cpus, q_num + 1) { in storvsc_do_io()
1483 stor_device->stor_chns[tgt_cpu]); in storvsc_do_io()
1487 &channel->outbound) in storvsc_do_io()
1499 &outgoing_channel->outbound) in storvsc_do_io()
1508 for_each_cpu(tgt_cpu, &stor_device->alloced_cpus) { in storvsc_do_io()
1512 stor_device->stor_chns[tgt_cpu]); in storvsc_do_io()
1516 &channel->outbound) in storvsc_do_io()
1524 spin_lock_irqsave(&stor_device->lock, flags); in storvsc_do_io()
1525 outgoing_channel = stor_device->stor_chns[q_num]; in storvsc_do_io()
1527 spin_unlock_irqrestore(&stor_device->lock, flags); in storvsc_do_io()
1531 spin_unlock_irqrestore(&stor_device->lock, flags); in storvsc_do_io()
1535 vstor_packet->flags |= REQUEST_COMPLETION_FLAG; in storvsc_do_io()
1537 vstor_packet->vm_srb.length = sizeof(struct vmscsi_request); in storvsc_do_io()
1540 vstor_packet->vm_srb.sense_info_length = STORVSC_SENSE_BUFFER_SIZE; in storvsc_do_io()
1543 vstor_packet->vm_srb.data_transfer_length = in storvsc_do_io()
1544 request->payload->range.len; in storvsc_do_io()
1546 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB; in storvsc_do_io()
1548 if (request->payload->range.len) { in storvsc_do_io()
1551 request->payload, request->payload_sz, in storvsc_do_io()
1566 atomic_inc(&stor_device->num_outstanding_req); in storvsc_do_io()
1575 * the target may claim SPC-2 compliance. MSFT targets currently in storvsc_device_alloc()
1576 * claim SPC-2 compliance while they implement post SPC-2 features. in storvsc_device_alloc()
1582 sdevice->sdev_bflags = BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES; in storvsc_device_alloc()
1590 blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ)); in storvsc_sdev_configure()
1593 sdevice->no_report_opcodes = 1; in storvsc_sdev_configure()
1594 sdevice->no_write_same = 1; in storvsc_sdev_configure()
1597 * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3 in storvsc_sdev_configure()
1601 if (!strncmp(sdevice->vendor, "Msft", 4)) { in storvsc_sdev_configure()
1605 sdevice->scsi_level = SCSI_SPC_3; in storvsc_sdev_configure()
1610 sdevice->no_write_same = 0; in storvsc_sdev_configure()
1641 struct hv_host_device *host_dev = shost_priv(scmnd->device->host); in storvsc_host_reset_handler()
1642 struct hv_device *device = host_dev->dev; in storvsc_host_reset_handler()
1653 request = &stor_device->reset_request; in storvsc_host_reset_handler()
1654 vstor_packet = &request->vstor_packet; in storvsc_host_reset_handler()
1657 init_completion(&request->wait_event); in storvsc_host_reset_handler()
1659 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS; in storvsc_host_reset_handler()
1660 vstor_packet->flags = REQUEST_COMPLETION_FLAG; in storvsc_host_reset_handler()
1661 vstor_packet->vm_srb.path_id = stor_device->path_id; in storvsc_host_reset_handler()
1663 ret = vmbus_sendpacket(device->channel, vstor_packet, in storvsc_host_reset_handler()
1671 t = wait_for_completion_timeout(&request->wait_event, 5*HZ); in storvsc_host_reset_handler()
1681 * Just wait for all in-transit packets to be accounted for in storvsc_host_reset_handler()
1702 u8 scsi_op = scmnd->cmnd[0]; in storvsc_scsi_cmd_ok()
1725 struct hv_device *dev = host_dev->dev; in storvsc_queuecommand()
1749 cmd_request->cmd = scmnd; in storvsc_queuecommand()
1751 memset(&cmd_request->vstor_packet, 0, sizeof(struct vstor_packet)); in storvsc_queuecommand()
1752 vm_srb = &cmd_request->vstor_packet.vm_srb; in storvsc_queuecommand()
1753 vm_srb->time_out_value = 60; in storvsc_queuecommand()
1755 vm_srb->srb_flags |= in storvsc_queuecommand()
1758 if (scmnd->device->tagged_supported) { in storvsc_queuecommand()
1759 vm_srb->srb_flags |= in storvsc_queuecommand()
1761 vm_srb->queue_tag = SP_UNTAGGED; in storvsc_queuecommand()
1762 vm_srb->queue_action = SRB_SIMPLE_TAG_REQUEST; in storvsc_queuecommand()
1766 switch (scmnd->sc_data_direction) { in storvsc_queuecommand()
1768 vm_srb->data_in = WRITE_TYPE; in storvsc_queuecommand()
1769 vm_srb->srb_flags |= SRB_FLAGS_DATA_OUT; in storvsc_queuecommand()
1772 vm_srb->data_in = READ_TYPE; in storvsc_queuecommand()
1773 vm_srb->srb_flags |= SRB_FLAGS_DATA_IN; in storvsc_queuecommand()
1776 vm_srb->data_in = UNKNOWN_TYPE; in storvsc_queuecommand()
1777 vm_srb->srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER; in storvsc_queuecommand()
1785 scmnd->sc_data_direction); in storvsc_queuecommand()
1786 return -EINVAL; in storvsc_queuecommand()
1790 vm_srb->port_number = host_dev->port; in storvsc_queuecommand()
1791 vm_srb->path_id = scmnd->device->channel; in storvsc_queuecommand()
1792 vm_srb->target_id = scmnd->device->id; in storvsc_queuecommand()
1793 vm_srb->lun = scmnd->device->lun; in storvsc_queuecommand()
1795 vm_srb->cdb_length = scmnd->cmd_len; in storvsc_queuecommand()
1797 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length); in storvsc_queuecommand()
1802 payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb; in storvsc_queuecommand()
1803 payload->range.len = 0; in storvsc_queuecommand()
1807 unsigned long offset_in_hvpg = offset_in_hvpage(sgl->offset); in storvsc_queuecommand()
1822 payload->range.len = length; in storvsc_queuecommand()
1823 payload->range.offset = offset_in_hvpg; in storvsc_queuecommand()
1834 * is in units of Hyper-V size pages. Handling the in storvsc_queuecommand()
1836 * values of sgl->offset that are larger than PAGE_SIZE. in storvsc_queuecommand()
1842 sg_dma_len(sg)) - hvpfn; in storvsc_queuecommand()
1846 * sequential Hyper-V PFNs for the continguous physical in storvsc_queuecommand()
1851 while (hvpfns_to_add--) in storvsc_queuecommand()
1852 payload->range.pfn_array[i++] = hvpfn++; in storvsc_queuecommand()
1856 cmd_request->payload = payload; in storvsc_queuecommand()
1857 cmd_request->payload_sz = payload_sz; in storvsc_queuecommand()
1866 if (ret == -EAGAIN) { in storvsc_queuecommand()
1875 if (payload_sz > sizeof(cmd_request->mpb)) in storvsc_queuecommand()
1893 .this_id = -1,
1895 .virt_boundary_mask = HV_HYP_PAGE_SIZE - 1,
1930 return guid_equal(&fc_guid.guid, &hv_dev->dev_type); in hv_dev_is_fc()
1941 bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false); in storvsc_probe()
1942 bool is_fc = ((dev_id->driver_data == SFC_GUID) ? true : false); in storvsc_probe()
1949 * We support sub-channels for storage on SCSI and FC controllers. in storvsc_probe()
1950 * The number of sub-channels offerred is based on the number of in storvsc_probe()
1955 (num_cpus - 1) / storvsc_vcpus_per_sub_channel; in storvsc_probe()
1959 (100 - ring_avail_percent_lowater) / 100; in storvsc_probe()
1964 return -ENOMEM; in storvsc_probe()
1969 host_dev->port = host->host_no; in storvsc_probe()
1970 host_dev->dev = device; in storvsc_probe()
1971 host_dev->host = host; in storvsc_probe()
1976 ret = -ENOMEM; in storvsc_probe()
1980 stor_device->destroy = false; in storvsc_probe()
1981 init_waitqueue_head(&stor_device->waiting_to_drain); in storvsc_probe()
1982 stor_device->device = device; in storvsc_probe()
1983 stor_device->host = host; in storvsc_probe()
1984 spin_lock_init(&stor_device->lock); in storvsc_probe()
1986 dma_set_min_align_mask(&device->device, HV_HYP_PAGE_SIZE - 1); in storvsc_probe()
1988 stor_device->port_number = host->host_no; in storvsc_probe()
1993 host_dev->path = stor_device->path_id; in storvsc_probe()
1994 host_dev->target = stor_device->target_id; in storvsc_probe()
1996 switch (dev_id->driver_data) { in storvsc_probe()
1998 host->max_lun = STORVSC_FC_MAX_LUNS_PER_TARGET; in storvsc_probe()
1999 host->max_id = STORVSC_FC_MAX_TARGETS; in storvsc_probe()
2000 host->max_channel = STORVSC_FC_MAX_CHANNELS - 1; in storvsc_probe()
2002 host->transportt = fc_transport_template; in storvsc_probe()
2007 host->max_lun = STORVSC_MAX_LUNS_PER_TARGET; in storvsc_probe()
2008 host->max_id = STORVSC_MAX_TARGETS; in storvsc_probe()
2009 host->max_channel = STORVSC_MAX_CHANNELS - 1; in storvsc_probe()
2013 host->max_lun = STORVSC_IDE_MAX_LUNS_PER_TARGET; in storvsc_probe()
2014 host->max_id = STORVSC_IDE_MAX_TARGETS; in storvsc_probe()
2015 host->max_channel = STORVSC_IDE_MAX_CHANNELS - 1; in storvsc_probe()
2019 host->max_cmd_len = STORVSC_MAX_CMD_LEN; in storvsc_probe()
2021 * Any reasonable Hyper-V configuration should provide in storvsc_probe()
2025 max_xfer_bytes = round_down(stor_device->max_transfer_bytes, HV_HYP_PAGE_SIZE); in storvsc_probe()
2030 host->max_sectors = max_xfer_bytes >> 9; in storvsc_probe()
2032 * There are 2 requirements for Hyper-V storvsc sgl segments, in storvsc_probe()
2044 host->sg_tablesize = (max_xfer_bytes >> HV_HYP_PAGE_SHIFT) + 1; in storvsc_probe()
2046 * For non-IDE disks, the host supports multiple channels. in storvsc_probe()
2056 host->nr_hw_queues = storvsc_max_hw_queues; in storvsc_probe()
2058 host->nr_hw_queues = num_present_cpus; in storvsc_probe()
2064 host_dev->handle_error_wq = in storvsc_probe()
2067 host->host_no); in storvsc_probe()
2068 if (!host_dev->handle_error_wq) { in storvsc_probe()
2069 ret = -ENOMEM; in storvsc_probe()
2072 INIT_WORK(&host_dev->host_scan_work, storvsc_host_scan); in storvsc_probe()
2074 ret = scsi_add_host(host, &device->device); in storvsc_probe()
2081 target = (device->dev_instance.b[5] << 8 | in storvsc_probe()
2082 device->dev_instance.b[4]); in storvsc_probe()
2088 if (host->transportt == fc_transport_template) { in storvsc_probe()
2093 fc_host_node_name(host) = stor_device->node_name; in storvsc_probe()
2094 fc_host_port_name(host) = stor_device->port_name; in storvsc_probe()
2095 stor_device->rport = fc_remote_port_add(host, 0, &ids); in storvsc_probe()
2096 if (!stor_device->rport) { in storvsc_probe()
2097 ret = -ENOMEM; in storvsc_probe()
2108 destroy_workqueue(host_dev->handle_error_wq); in storvsc_probe()
2121 kfree(stor_device->stor_chns); in storvsc_probe()
2141 struct Scsi_Host *host = stor_device->host; in storvsc_remove()
2145 if (host->transportt == fc_transport_template) { in storvsc_remove()
2146 fc_remote_port_delete(stor_device->rport); in storvsc_remove()
2150 destroy_workqueue(host_dev->handle_error_wq); in storvsc_remove()
2159 struct Scsi_Host *host = stor_device->host; in storvsc_suspend()
2164 drain_workqueue(host_dev->handle_error_wq); in storvsc_suspend()
2166 vmbus_close(hv_dev->channel); in storvsc_suspend()
2168 kfree(stor_device->stor_chns); in storvsc_suspend()
2169 stor_device->stor_chns = NULL; in storvsc_suspend()
2171 cpumask_clear(&stor_device->alloced_cpus); in storvsc_suspend()
2216 ((aligned_ringbuffer_size - PAGE_SIZE) / in storvsc_drv_init()
2224 return -ENODEV; in storvsc_drv_init()
2246 MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");