^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2009, Microsoft Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Haiyang Zhang <haiyangz@microsoft.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Hank Janssen <hjanssen@microsoft.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * K. Y. Srinivasan <kys@microsoft.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/hyperv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <scsi/scsi_devinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <scsi/scsi_dbg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <scsi/scsi_transport_fc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * All wire protocol details (storage protocol between the guest and the host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * are consolidated here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Begin protocol definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Version history:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * V1 Beta: 0.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * V1 RC < 2008/1/31: 1.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * V1 RC > 2008/1/31: 2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Win7: 4.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Win8: 5.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Win8.1: 6.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Win10: 6.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define VMSTOR_PROTO_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) (((MINOR_) & 0xff)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define VMSTOR_PROTO_VERSION_WIN6 VMSTOR_PROTO_VERSION(2, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define VMSTOR_PROTO_VERSION_WIN7 VMSTOR_PROTO_VERSION(4, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define VMSTOR_PROTO_VERSION_WIN8 VMSTOR_PROTO_VERSION(5, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Packet structure describing virtual storage requests. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) enum vstor_packet_operation {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) VSTOR_OPERATION_COMPLETE_IO = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) VSTOR_OPERATION_REMOVE_DEVICE = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) VSTOR_OPERATION_EXECUTE_SRB = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) VSTOR_OPERATION_RESET_LUN = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) VSTOR_OPERATION_RESET_ADAPTER = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) VSTOR_OPERATION_RESET_BUS = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) VSTOR_OPERATION_END_INITIALIZATION = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) VSTOR_OPERATION_QUERY_PROPERTIES = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) VSTOR_OPERATION_ENUMERATE_BUS = 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) VSTOR_OPERATION_FCHBA_DATA = 12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) VSTOR_OPERATION_CREATE_SUB_CHANNELS = 13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) VSTOR_OPERATION_MAXIMUM = 13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * WWN packet for Fibre Channel HBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct hv_fc_wwn_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u8 primary_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u8 reserved1[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 primary_port_wwn[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u8 primary_node_wwn[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u8 secondary_port_wwn[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u8 secondary_node_wwn[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * SRB Flag Bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define SRB_FLAGS_DATA_IN 0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define SRB_FLAGS_DATA_OUT 0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * This flag indicates the request is part of the workflow for processing a D3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define SRB_FLAGS_D3_PROCESSING 0x00000800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define SRB_FLAGS_IS_ACTIVE 0x00010000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define SRB_FLAGS_ALLOCATED_FROM_ZONE 0x00020000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define SRB_FLAGS_SGLIST_FROM_POOL 0x00040000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define SRB_FLAGS_BYPASS_LOCKED_QUEUE 0x00080000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define SRB_FLAGS_NO_KEEP_AWAKE 0x00100000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define SRB_FLAGS_PORT_DRIVER_ALLOCSENSE 0x00200000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define SRB_FLAGS_PORT_DRIVER_SENSEHASPORT 0x00400000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define SRB_FLAGS_DONT_START_NEXT_PACKET 0x00800000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define SRB_FLAGS_PORT_DRIVER_RESERVED 0x0F000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define SRB_FLAGS_CLASS_DRIVER_RESERVED 0xF0000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define SP_UNTAGGED ((unsigned char) ~0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define SRB_SIMPLE_TAG_REQUEST 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Platform neutral description of a scsi request -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * this remains the same across the write regardless of 32/64 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * note: it's patterned off the SCSI_PASS_THROUGH structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define STORVSC_MAX_CMD_LEN 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define STORVSC_SENSE_BUFFER_SIZE 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define STORVSC_MAX_BUF_LEN_WITH_PADDING 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * Sense buffer size changed in win8; have a run-time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * variable to track the size we should use. This value will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * likely change during protocol negotiation but it is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * to start by assuming pre-Win8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * The storage protocol version is determined during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * initial exchange with the host. It will indicate which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * storage functionality is available in the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static int vmstor_proto_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define STORVSC_LOGGING_NONE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define STORVSC_LOGGING_ERROR 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define STORVSC_LOGGING_WARN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int logging_level = STORVSC_LOGGING_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) module_param(logging_level, int, S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) MODULE_PARM_DESC(logging_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) "Logging level, 0 - None, 1 - Error (default), 2 - Warning.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static inline bool do_logging(int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return logging_level >= level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define storvsc_log(dev, level, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (do_logging(level)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) dev_warn(&(dev)->device, fmt, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct vmscsi_win8_extension {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * The following were added in Windows 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) u16 reserve;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) u8 queue_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u8 queue_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u32 srb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u32 time_out_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) u32 queue_sort_ey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct vmscsi_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) u16 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) u8 srb_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u8 scsi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) u8 port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u8 path_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) u8 target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u8 lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) u8 cdb_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) u8 sense_info_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) u8 data_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u8 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u32 data_transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) u8 cdb[STORVSC_MAX_CMD_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u8 sense_data[STORVSC_SENSE_BUFFER_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u8 reserved_array[STORVSC_MAX_BUF_LEN_WITH_PADDING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * The following was added in win8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct vmscsi_win8_extension win8_extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) } __attribute((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * The size of the vmscsi_request has changed in win8. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * additional size is because of new elements added to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * structure. These elements are valid only when we are talking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * to a win8 host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Track the correction to size we need to apply. This value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * will likely change during protocol negotiation but it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * valid to start by assuming pre-Win8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * The list of storage protocols in order of preference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct vmstor_protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int sense_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int vmscsi_size_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct vmstor_protocol vmstor_protocols[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) VMSTOR_PROTO_VERSION_WIN10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) VMSTOR_PROTO_VERSION_WIN8_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) VMSTOR_PROTO_VERSION_WIN8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) VMSTOR_PROTO_VERSION_WIN7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) sizeof(struct vmscsi_win8_extension),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) VMSTOR_PROTO_VERSION_WIN6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) sizeof(struct vmscsi_win8_extension),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * This structure is sent during the initialization phase to get the different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * properties of the channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct vmstorage_channel_properties {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) u32 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u16 max_channel_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) u16 reserved1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) u32 max_transfer_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) u64 reserved2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* This structure is sent during the storage protocol negotiations. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct vmstorage_protocol_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* Major (MSW) and minor (LSW) version numbers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u16 major_minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Revision number is auto-incremented whenever this file is changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * (See FILL_VMSTOR_REVISION macro above). Mismatch does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * definitely indicate incompatibility--but it does indicate mismatched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * builds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * This is only used on the windows side. Just set it to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) u16 revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* Channel Property Flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct vstor_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* Requested operation type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) enum vstor_packet_operation operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Flags - see below for values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* Status of the request returned from the server side. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* Data payload area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * Structure used to forward SCSI commands from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * client to the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct vmscsi_request vm_srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /* Structure used to query channel properties. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct vmstorage_channel_properties storage_channel_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* Used during version negotiations. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct vmstorage_protocol_version version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Fibre channel address packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct hv_fc_wwn_packet wwn_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Number of sub-channels to create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) u16 sub_channel_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* This will be the maximum of the union members */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) u8 buffer[0x34];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * Packet Flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * This flag indicates that the server should send back a completion for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #define REQUEST_COMPLETION_FLAG 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Matches Windows-end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) enum storvsc_request_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) WRITE_TYPE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) READ_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) UNKNOWN_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * SRB status codes and masks; a subset of the codes used here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #define SRB_STATUS_AUTOSENSE_VALID 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) #define SRB_STATUS_QUEUE_FROZEN 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #define SRB_STATUS_INVALID_LUN 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #define SRB_STATUS_SUCCESS 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) #define SRB_STATUS_ABORTED 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) #define SRB_STATUS_ERROR 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #define SRB_STATUS_DATA_OVERRUN 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define SRB_STATUS(status) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) (status & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * This is the end of Protocol specific defines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static int storvsc_ringbuffer_size = (128 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static u32 max_outstanding_req_per_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static int storvsc_change_queue_depth(struct scsi_device *sdev, int queue_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int storvsc_vcpus_per_sub_channel = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) module_param(storvsc_ringbuffer_size, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) module_param(storvsc_vcpus_per_sub_channel, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) MODULE_PARM_DESC(storvsc_vcpus_per_sub_channel, "Ratio of VCPUs to subchannels");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static int ring_avail_percent_lowater = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) module_param(ring_avail_percent_lowater, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) MODULE_PARM_DESC(ring_avail_percent_lowater,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) "Select a channel if available ring size > this in percent");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * Timeout in seconds for all devices managed by this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int storvsc_timeout = 180;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static struct scsi_transport_template *fc_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static void storvsc_on_channel_callback(void *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) #define STORVSC_MAX_LUNS_PER_TARGET 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) #define STORVSC_MAX_TARGETS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) #define STORVSC_MAX_CHANNELS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #define STORVSC_FC_MAX_LUNS_PER_TARGET 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) #define STORVSC_FC_MAX_TARGETS 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) #define STORVSC_FC_MAX_CHANNELS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define STORVSC_IDE_MAX_LUNS_PER_TARGET 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) #define STORVSC_IDE_MAX_TARGETS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #define STORVSC_IDE_MAX_CHANNELS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct storvsc_cmd_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct hv_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* Synchronize the request/response if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct completion wait_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct vmbus_channel_packet_multipage_buffer mpb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct vmbus_packet_mpb_array *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) u32 payload_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct vstor_packet vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* A storvsc device is a device object that contains a vmbus channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct storvsc_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct hv_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) bool destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) bool drain_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) atomic_t num_outstanding_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) wait_queue_head_t waiting_to_drain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * Each unique Port/Path/Target represents 1 channel ie scsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * controller. In reality, the pathid, targetid is always 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * and the port is set by us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) unsigned int port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) unsigned char path_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) unsigned char target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * Max I/O, the device can support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) u32 max_transfer_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * Number of sub-channels we will open.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) u16 num_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct vmbus_channel **stor_chns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * Mask of CPUs bound to subchannels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct cpumask alloced_cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * Serializes modifications of stor_chns[] from storvsc_do_io()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * and storvsc_change_target_cpu().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /* Used for vsc/vsp channel reset process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct storvsc_cmd_request init_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct storvsc_cmd_request reset_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * Currently active port and node names for FC devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) u64 node_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) u64 port_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct fc_rport *rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct hv_host_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct hv_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) unsigned int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) unsigned char path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) unsigned char target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct workqueue_struct *handle_error_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct work_struct host_scan_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct storvsc_scan_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) u8 lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) u8 tgt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static void storvsc_device_scan(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct storvsc_scan_work *wrk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) wrk = container_of(work, struct storvsc_scan_work, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (!sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) scsi_rescan_device(&sdev->sdev_gendev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) scsi_device_put(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) kfree(wrk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static void storvsc_host_scan(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct hv_host_device *host_device =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) container_of(work, struct hv_host_device, host_scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) host = host_device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * Before scanning the host, first check to see if any of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * currrently known devices have been hot removed. We issue a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * "unit ready" command against all currently known devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * This I/O will result in an error for devices that have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * removed. As part of handling the I/O error, we remove the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * When a LUN is added or removed, the host sends us a signal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * scan the host. Thus we are forced to discover the LUNs that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * may have been removed this way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) mutex_lock(&host->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) shost_for_each_device(sdev, host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) scsi_test_unit_ready(sdev, 1, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) mutex_unlock(&host->scan_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * Now scan the host to discover LUNs that may have been added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) scsi_scan_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static void storvsc_remove_lun(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct storvsc_scan_work *wrk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) wrk = container_of(work, struct storvsc_scan_work, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (!scsi_host_get(wrk->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) sdev = scsi_device_lookup(wrk->host, 0, wrk->tgt_id, wrk->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (sdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) scsi_remove_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) scsi_device_put(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) scsi_host_put(wrk->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) kfree(wrk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * We can get incoming messages from the host that are not in response to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * messages that we have sent out. An example of this would be messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * received by the guest to notify dynamic addition/removal of LUNs. To
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * deal with potential race conditions where the driver may be in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * midst of being unloaded when we might receive an unsolicited message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * from the host, we have implemented a mechanism to gurantee sequential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * consistency:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * 1) Once the device is marked as being destroyed, we will fail all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * outgoing messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * 2) We permit incoming messages when the device is being destroyed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * only to properly account for messages already sent out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static inline struct storvsc_device *get_out_stor_device(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct hv_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) stor_device = hv_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (stor_device && stor_device->destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) stor_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) dev->drain_notify = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) wait_event(dev->waiting_to_drain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) atomic_read(&dev->num_outstanding_req) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) dev->drain_notify = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static inline struct storvsc_device *get_in_stor_device(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct hv_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) stor_device = hv_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) goto get_in_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * If the device is being destroyed; allow incoming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * traffic only to cleanup outstanding requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (stor_device->destroy &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) (atomic_read(&stor_device->num_outstanding_req) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) stor_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) get_in_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) u32 new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct vmbus_channel *cur_chn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) bool old_is_alloced = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) struct hv_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) device = channel->primary_channel ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) channel->primary_channel->device_obj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) : channel->device_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) stor_device = get_out_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* See storvsc_do_io() -> get_og_chn(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) spin_lock_irqsave(&stor_device->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * Determines if the storvsc device has other channels assigned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * the "old" CPU to update the alloced_cpus mask and the stor_chns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (device->channel != channel && device->channel->target_cpu == old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) cur_chn = device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) old_is_alloced = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) goto old_is_alloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) list_for_each_entry(cur_chn, &device->channel->sc_list, sc_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (cur_chn == channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (cur_chn->target_cpu == old) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) old_is_alloced = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) goto old_is_alloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) old_is_alloced:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (old_is_alloced)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) WRITE_ONCE(stor_device->stor_chns[old], cur_chn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) cpumask_clear_cpu(old, &stor_device->alloced_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* "Flush" the stor_chns array. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (stor_device->stor_chns[cpu] && !cpumask_test_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) cpu, &stor_device->alloced_cpus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) WRITE_ONCE(stor_device->stor_chns[cpu], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) WRITE_ONCE(stor_device->stor_chns[new], channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) cpumask_set_cpu(new, &stor_device->alloced_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) spin_unlock_irqrestore(&stor_device->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static void handle_sc_creation(struct vmbus_channel *new_sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) struct hv_device *device = new_sc->primary_channel->device_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct device *dev = &device->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) struct vmstorage_channel_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) stor_device = get_out_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) memset(&props, 0, sizeof(struct vmstorage_channel_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) ret = vmbus_open(new_sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) storvsc_ringbuffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) storvsc_ringbuffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) (void *)&props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) sizeof(struct vmstorage_channel_properties),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) storvsc_on_channel_callback, new_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /* In case vmbus_open() fails, we don't use the sub-channel. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) dev_err(dev, "Failed to open sub-channel: err=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) new_sc->change_target_cpu_callback = storvsc_change_target_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) /* Add the sub-channel to the array of available channels. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) stor_device->stor_chns[new_sc->target_cpu] = new_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) cpumask_set_cpu(new_sc->target_cpu, &stor_device->alloced_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static void handle_multichannel_storage(struct hv_device *device, int max_chns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct device *dev = &device->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) int num_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) struct storvsc_cmd_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) struct vstor_packet *vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) int ret, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * If the number of CPUs is artificially restricted, such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * with maxcpus=1 on the kernel boot line, Hyper-V could offer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * sub-channels >= the number of CPUs. These sub-channels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * should not be created. The primary channel is already created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * and assigned to one CPU, so check against # CPUs - 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) num_sc = min((int)(num_online_cpus() - 1), max_chns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (!num_sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) stor_device = get_out_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) stor_device->num_sc = num_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) request = &stor_device->init_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) vstor_packet = &request->vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) * Establish a handler for dealing with subchannels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) vmbus_set_sc_create_callback(device->channel, handle_sc_creation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * Request the host to create sub-channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) memset(request, 0, sizeof(struct storvsc_cmd_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) init_completion(&request->wait_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) vstor_packet->operation = VSTOR_OPERATION_CREATE_SUB_CHANNELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) vstor_packet->flags = REQUEST_COMPLETION_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) vstor_packet->sub_channel_count = num_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) ret = vmbus_sendpacket(device->channel, vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) (sizeof(struct vstor_packet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) vmscsi_size_delta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) (unsigned long)request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) VM_PKT_DATA_INBAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) dev_err(dev, "Failed to create sub-channel: err=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) t = wait_for_completion_timeout(&request->wait_event, 10*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (t == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) dev_err(dev, "Failed to create sub-channel: timed out\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) vstor_packet->status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) dev_err(dev, "Failed to create sub-channel: op=%d, sts=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) vstor_packet->operation, vstor_packet->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) * We need to do nothing here, because vmbus_process_offer()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) * invokes channel->sc_creation_callback, which will open and use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * the sub-channel(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) static void cache_wwn(struct storvsc_device *stor_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct vstor_packet *vstor_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * Cache the currently active port and node ww names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (vstor_packet->wwn_packet.primary_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) stor_device->node_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) wwn_to_u64(vstor_packet->wwn_packet.primary_node_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) stor_device->port_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) wwn_to_u64(vstor_packet->wwn_packet.primary_port_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) stor_device->node_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) wwn_to_u64(vstor_packet->wwn_packet.secondary_node_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) stor_device->port_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) wwn_to_u64(vstor_packet->wwn_packet.secondary_port_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static int storvsc_execute_vstor_op(struct hv_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct storvsc_cmd_request *request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) bool status_check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct vstor_packet *vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) int ret, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) vstor_packet = &request->vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) init_completion(&request->wait_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) vstor_packet->flags = REQUEST_COMPLETION_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ret = vmbus_sendpacket(device->channel, vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) (sizeof(struct vstor_packet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) vmscsi_size_delta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) (unsigned long)request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) VM_PKT_DATA_INBAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (t == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (!status_check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) vstor_packet->status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static int storvsc_channel_init(struct hv_device *device, bool is_fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct storvsc_cmd_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct vstor_packet *vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) int max_chns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) bool process_sub_channels = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) stor_device = get_out_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) request = &stor_device->init_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) vstor_packet = &request->vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) * Now, initiate the vsc/vsp initialization protocol on the open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) * channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) memset(request, 0, sizeof(struct storvsc_cmd_request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) ret = storvsc_execute_vstor_op(device, request, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * Query host supported protocol version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) /* reuse the packet for version range supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) memset(vstor_packet, 0, sizeof(struct vstor_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) vstor_packet->operation =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) vstor_packet->version.major_minor =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) vmstor_protocols[i].protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * The revision number is only used in Windows; set it to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) vstor_packet->version.revision = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) ret = storvsc_execute_vstor_op(device, request, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (vstor_packet->status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) vmstor_proto_version =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) vmstor_protocols[i].protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) sense_buffer_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) vmstor_protocols[i].sense_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) vmscsi_size_delta =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) vmstor_protocols[i].vmscsi_size_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) if (vstor_packet->status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) memset(vstor_packet, 0, sizeof(struct vstor_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) ret = storvsc_execute_vstor_op(device, request, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) * Check to see if multi-channel support is there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * Hosts that implement protocol version of 5.1 and above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * support multi-channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) * Allocate state to manage the sub-channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * We allocate an array based on the numbers of possible CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) * (Hyper-V does not support cpu online/offline).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) * This Array will be sparseley populated with unique
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) * channels - primary + sub-channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * We will however populate all the slots to evenly distribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * the load.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) stor_device->stor_chns = kcalloc(num_possible_cpus(), sizeof(void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (stor_device->stor_chns == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) device->channel->change_target_cpu_callback = storvsc_change_target_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) stor_device->stor_chns[device->channel->target_cpu] = device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) cpumask_set_cpu(device->channel->target_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) &stor_device->alloced_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (vstor_packet->storage_channel_properties.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) process_sub_channels = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) stor_device->max_transfer_bytes =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) vstor_packet->storage_channel_properties.max_transfer_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) if (!is_fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) * For FC devices retrieve FC HBA data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) memset(vstor_packet, 0, sizeof(struct vstor_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) vstor_packet->operation = VSTOR_OPERATION_FCHBA_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) ret = storvsc_execute_vstor_op(device, request, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) * Cache the currently active port and node ww names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) cache_wwn(stor_device, vstor_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) memset(vstor_packet, 0, sizeof(struct vstor_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) ret = storvsc_execute_vstor_op(device, request, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (process_sub_channels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) handle_multichannel_storage(device, max_chns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) static void storvsc_handle_error(struct vmscsi_request *vm_srb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct scsi_cmnd *scmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) struct Scsi_Host *host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) u8 asc, u8 ascq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) struct storvsc_scan_work *wrk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) void (*process_err_fn)(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct hv_host_device *host_dev = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) * In some situations, Hyper-V sets multiple bits in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) * srb_status, such as ABORTED and ERROR. So process them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * individually, with the most specific bits first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (vm_srb->srb_status & SRB_STATUS_INVALID_LUN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) set_host_byte(scmnd, DID_NO_CONNECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) process_err_fn = storvsc_remove_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) goto do_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (vm_srb->srb_status & SRB_STATUS_ABORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /* Capacity data has changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) (asc == 0x2a) && (ascq == 0x9)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) process_err_fn = storvsc_device_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) * Retry the I/O that triggered this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) set_host_byte(scmnd, DID_REQUEUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) goto do_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) if (vm_srb->srb_status & SRB_STATUS_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * Let upper layer deal with error when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * sense message is present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) * If there is an error; offline the device since all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) * error recovery strategies would have already been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) * deployed on the host side. However, if the command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * were a pass-through command deal with it appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) switch (scmnd->cmnd[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) case ATA_16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) case ATA_12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) set_host_byte(scmnd, DID_PASSTHROUGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) * On some Hyper-V hosts TEST_UNIT_READY command can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * return SRB_STATUS_ERROR. Let the upper level code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * deal with it based on the sense information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) case TEST_UNIT_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) set_host_byte(scmnd, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) do_work:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) * We need to schedule work to process this error; schedule it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) wrk = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (!wrk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) set_host_byte(scmnd, DID_TARGET_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) wrk->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) wrk->lun = vm_srb->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) wrk->tgt_id = vm_srb->target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) INIT_WORK(&wrk->work, process_err_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) queue_work(host_dev->handle_error_wq, &wrk->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) struct storvsc_device *stor_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) struct scsi_cmnd *scmnd = cmd_request->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct scsi_sense_hdr sense_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) struct vmscsi_request *vm_srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) u32 data_transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) u32 payload_sz = cmd_request->payload_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) void *payload = cmd_request->payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) host = stor_dev->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) vm_srb = &cmd_request->vstor_packet.vm_srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) data_transfer_length = vm_srb->data_transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) scmnd->result = vm_srb->scsi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (scmnd->result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (scsi_normalize_sense(scmnd->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) SCSI_SENSE_BUFFERSIZE, &sense_hdr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) !(sense_hdr.sense_key == NOT_READY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) sense_hdr.asc == 0x03A) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) do_logging(STORVSC_LOGGING_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) scsi_print_sense_hdr(scmnd->device, "storvsc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) &sense_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (vm_srb->srb_status != SRB_STATUS_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) storvsc_handle_error(vm_srb, scmnd, host, sense_hdr.asc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) sense_hdr.ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) * The Windows driver set data_transfer_length on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) * SRB_STATUS_DATA_OVERRUN. On other errors, this value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) * is untouched. In these cases we set it to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) if (vm_srb->srb_status != SRB_STATUS_DATA_OVERRUN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) data_transfer_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /* Validate data_transfer_length (from Hyper-V) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (data_transfer_length > cmd_request->payload->range.len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) data_transfer_length = cmd_request->payload->range.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) scsi_set_resid(scmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) cmd_request->payload->range.len - data_transfer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) scmnd->scsi_done(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) if (payload_sz >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) sizeof(struct vmbus_channel_packet_multipage_buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) kfree(payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static void storvsc_on_io_completion(struct storvsc_device *stor_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) struct vstor_packet *vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct storvsc_cmd_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) struct vstor_packet *stor_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct hv_device *device = stor_device->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) stor_pkt = &request->vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) * The current SCSI handling on the host side does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) * not correctly handle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) * INQUIRY command with page code parameter set to 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) * MODE_SENSE command with cmd[2] == 0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) * Setup srb and scsi status so this won't be fatal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * We do this so we can distinguish truly fatal failues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * (srb status == 0x4) and off-line the device in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) (stor_pkt->vm_srb.cdb[0] == MODE_SENSE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) vstor_packet->vm_srb.scsi_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) /* Copy over the status...etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) /* Validate sense_info_length (from Hyper-V) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (vstor_packet->vm_srb.sense_info_length > sense_buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) stor_pkt->vm_srb.sense_info_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) vstor_packet->vm_srb.sense_info_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (vstor_packet->vm_srb.scsi_status != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) vstor_packet->vm_srb.srb_status != SRB_STATUS_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) storvsc_log(device, STORVSC_LOGGING_WARN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) stor_pkt->vm_srb.cdb[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) vstor_packet->vm_srb.scsi_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) vstor_packet->vm_srb.srb_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) /* CHECK_CONDITION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (vstor_packet->vm_srb.srb_status &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) SRB_STATUS_AUTOSENSE_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) /* autosense data available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) storvsc_log(device, STORVSC_LOGGING_WARN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) "stor pkt %p autosense data valid - len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) request, vstor_packet->vm_srb.sense_info_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) memcpy(request->cmd->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) vstor_packet->vm_srb.sense_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) vstor_packet->vm_srb.sense_info_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) stor_pkt->vm_srb.data_transfer_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) vstor_packet->vm_srb.data_transfer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) storvsc_command_completion(request, stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) stor_device->drain_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) wake_up(&stor_device->waiting_to_drain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) static void storvsc_on_receive(struct storvsc_device *stor_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct vstor_packet *vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) struct storvsc_cmd_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) struct hv_host_device *host_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) switch (vstor_packet->operation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) case VSTOR_OPERATION_COMPLETE_IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) storvsc_on_io_completion(stor_device, vstor_packet, request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) case VSTOR_OPERATION_REMOVE_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) case VSTOR_OPERATION_ENUMERATE_BUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) host_dev = shost_priv(stor_device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) queue_work(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) host_dev->handle_error_wq, &host_dev->host_scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) case VSTOR_OPERATION_FCHBA_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) cache_wwn(stor_device, vstor_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) fc_host_node_name(stor_device->host) = stor_device->node_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) fc_host_port_name(stor_device->host) = stor_device->port_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) static void storvsc_on_channel_callback(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) struct vmbus_channel *channel = (struct vmbus_channel *)context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) const struct vmpacket_descriptor *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) struct hv_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (channel->primary_channel != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) device = channel->primary_channel->device_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) device = channel->device_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) stor_device = get_in_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) foreach_vmbus_pkt(desc, channel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) void *packet = hv_pkt_data(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) struct storvsc_cmd_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) request = (struct storvsc_cmd_request *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) ((unsigned long)desc->trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) if (request == &stor_device->init_request ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) request == &stor_device->reset_request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) memcpy(&request->vstor_packet, packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) (sizeof(struct vstor_packet) - vmscsi_size_delta));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) complete(&request->wait_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) storvsc_on_receive(stor_device, packet, request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) bool is_fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) struct vmstorage_channel_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) memset(&props, 0, sizeof(struct vmstorage_channel_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) ret = vmbus_open(device->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) ring_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) (void *)&props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) sizeof(struct vmstorage_channel_properties),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) storvsc_on_channel_callback, device->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) ret = storvsc_channel_init(device, is_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static int storvsc_dev_remove(struct hv_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) stor_device = hv_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) stor_device->destroy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) /* Make sure flag is set before waiting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) * At this point, all outbound traffic should be disable. We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) * only allow inbound traffic (responses) to proceed so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) * outstanding requests can be completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) storvsc_wait_to_drain(stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) * Since we have already drained, we don't need to busy wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) * as was done in final_release_stor_device()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) * Note that we cannot set the ext pointer to NULL until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) * we have drained - to drain the outgoing packets, we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) * allow incoming packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) hv_set_drvdata(device, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) /* Close the channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) vmbus_close(device->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) kfree(stor_device->stor_chns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) kfree(stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) static struct vmbus_channel *get_og_chn(struct storvsc_device *stor_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) u16 q_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) u16 slot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) u16 hash_qnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) const struct cpumask *node_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) int num_channels, tgt_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) if (stor_device->num_sc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) stor_device->stor_chns[q_num] = stor_device->device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) return stor_device->device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) * Our channel array is sparsley populated and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) * initiated I/O on a processor/hw-q that does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * currently have a designated channel. Fix this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) * The strategy is simple:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * I. Ensure NUMA locality
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * II. Distribute evenly (best effort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) node_mask = cpumask_of_node(cpu_to_node(q_num));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) num_channels = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) for_each_cpu(tgt_cpu, &stor_device->alloced_cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (cpumask_test_cpu(tgt_cpu, node_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) num_channels++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) if (num_channels == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) stor_device->stor_chns[q_num] = stor_device->device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) return stor_device->device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) hash_qnum = q_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) while (hash_qnum >= num_channels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) hash_qnum -= num_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) for_each_cpu(tgt_cpu, &stor_device->alloced_cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (!cpumask_test_cpu(tgt_cpu, node_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) if (slot == hash_qnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) slot++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) stor_device->stor_chns[q_num] = stor_device->stor_chns[tgt_cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) return stor_device->stor_chns[q_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) static int storvsc_do_io(struct hv_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) struct storvsc_cmd_request *request, u16 q_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) struct vstor_packet *vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) struct vmbus_channel *outgoing_channel, *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) const struct cpumask *node_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) int tgt_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) vstor_packet = &request->vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) stor_device = get_out_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) request->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) * Select an appropriate channel to send the request out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) /* See storvsc_change_target_cpu(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) outgoing_channel = READ_ONCE(stor_device->stor_chns[q_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (outgoing_channel != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) if (outgoing_channel->target_cpu == q_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) * Ideally, we want to pick a different channel if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) * available on the same NUMA node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) node_mask = cpumask_of_node(cpu_to_node(q_num));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) for_each_cpu_wrap(tgt_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) &stor_device->alloced_cpus, q_num + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) if (!cpumask_test_cpu(tgt_cpu, node_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (tgt_cpu == q_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) channel = READ_ONCE(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) stor_device->stor_chns[tgt_cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (channel == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) if (hv_get_avail_to_write_percent(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) &channel->outbound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) > ring_avail_percent_lowater) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) outgoing_channel = channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) goto found_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) * All the other channels on the same NUMA node are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) * busy. Try to use the channel on the current CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (hv_get_avail_to_write_percent(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) &outgoing_channel->outbound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) > ring_avail_percent_lowater)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) goto found_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) * If we reach here, all the channels on the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) * NUMA node are busy. Try to find a channel in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) * other NUMA nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) for_each_cpu(tgt_cpu, &stor_device->alloced_cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (cpumask_test_cpu(tgt_cpu, node_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) channel = READ_ONCE(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) stor_device->stor_chns[tgt_cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) if (channel == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) if (hv_get_avail_to_write_percent(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) &channel->outbound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) > ring_avail_percent_lowater) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) outgoing_channel = channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) goto found_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) spin_lock_irqsave(&stor_device->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) outgoing_channel = stor_device->stor_chns[q_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) if (outgoing_channel != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) spin_unlock_irqrestore(&stor_device->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) goto found_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) outgoing_channel = get_og_chn(stor_device, q_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) spin_unlock_irqrestore(&stor_device->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) found_channel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) vstor_packet->vm_srb.length = (sizeof(struct vmscsi_request) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) vmscsi_size_delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) vstor_packet->vm_srb.data_transfer_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) request->payload->range.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) if (request->payload->range.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) ret = vmbus_sendpacket_mpb_desc(outgoing_channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) request->payload, request->payload_sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) (sizeof(struct vstor_packet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) vmscsi_size_delta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) (unsigned long)request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) ret = vmbus_sendpacket(outgoing_channel, vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) (sizeof(struct vstor_packet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) vmscsi_size_delta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) (unsigned long)request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) VM_PKT_DATA_INBAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) atomic_inc(&stor_device->num_outstanding_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) static int storvsc_device_alloc(struct scsi_device *sdevice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) * Set blist flag to permit the reading of the VPD pages even when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) * the target may claim SPC-2 compliance. MSFT targets currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) * claim SPC-2 compliance while they implement post SPC-2 features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) * With this flag we can correctly handle WRITE_SAME_16 issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * Hypervisor reports SCSI_UNKNOWN type for DVD ROM device but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) * still supports REPORT LUN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) sdevice->sdev_bflags = BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) static int storvsc_device_configure(struct scsi_device *sdevice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) sdevice->no_write_same = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) * if the device is a MSFT virtual device. If the host is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) * WIN10 or newer, allow write_same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) if (!strncmp(sdevice->vendor, "Msft", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) switch (vmstor_proto_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) case VMSTOR_PROTO_VERSION_WIN8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) case VMSTOR_PROTO_VERSION_WIN8_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) sdevice->scsi_level = SCSI_SPC_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) sdevice->no_write_same = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) sector_t capacity, int *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) sector_t nsect = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) sector_t cylinders = nsect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) int heads, sectors_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) * We are making up these values; let us keep it simple.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) heads = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) sectors_pt = 0x3f; /* Sectors per track */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) sector_div(cylinders, heads * sectors_pt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) cylinders = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) info[0] = heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) info[1] = sectors_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) info[2] = (int)cylinders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) struct hv_device *device = host_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) struct storvsc_cmd_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) struct vstor_packet *vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) int ret, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) stor_device = get_out_stor_device(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) if (!stor_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) request = &stor_device->reset_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) vstor_packet = &request->vstor_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) memset(vstor_packet, 0, sizeof(struct vstor_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) init_completion(&request->wait_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) vstor_packet->flags = REQUEST_COMPLETION_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) vstor_packet->vm_srb.path_id = stor_device->path_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) ret = vmbus_sendpacket(device->channel, vstor_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) (sizeof(struct vstor_packet) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) vmscsi_size_delta),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) (unsigned long)&stor_device->reset_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) VM_PKT_DATA_INBAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) if (t == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) return TIMEOUT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) * At this point, all outstanding requests in the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) * should have been flushed out and return to us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) * There is a potential race here where the host may be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) * the process of responding when we return from here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) * Just wait for all in-transit packets to be accounted for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) * before we return from here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) storvsc_wait_to_drain(stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) * The host guarantees to respond to each command, although I/O latencies might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) * be unbounded on Azure. Reset the timer unconditionally to give the host a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) * chance to perform EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) if (scmnd->device->host->transportt == fc_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) return fc_eh_timed_out(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) return BLK_EH_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) bool allowed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) u8 scsi_op = scmnd->cmnd[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) switch (scsi_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) /* the host does not handle WRITE_SAME, log accident usage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) case WRITE_SAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) * smartd sends this command and the host does not handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) * this. So, don't send it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) case SET_WINDOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) scmnd->result = ILLEGAL_REQUEST << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) allowed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) return allowed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) struct hv_host_device *host_dev = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) struct hv_device *dev = host_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) struct scatterlist *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) unsigned int sg_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) struct vmscsi_request *vm_srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) struct scatterlist *cur_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) struct vmbus_packet_mpb_array *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) u32 payload_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) if (vmstor_proto_version <= VMSTOR_PROTO_VERSION_WIN8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) * On legacy hosts filter unimplemented commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) * Future hosts are expected to correctly handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) * unsupported commands. Furthermore, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) * possible that some of the currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) * unsupported commands maybe supported in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) * future versions of the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) if (!storvsc_scsi_cmd_ok(scmnd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) scmnd->scsi_done(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) /* Setup the cmd request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) cmd_request->cmd = scmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) memset(&cmd_request->vstor_packet, 0, sizeof(struct vstor_packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) vm_srb = &cmd_request->vstor_packet.vm_srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) vm_srb->win8_extension.time_out_value = 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) vm_srb->win8_extension.srb_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) SRB_FLAGS_DISABLE_SYNCH_TRANSFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) if (scmnd->device->tagged_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) vm_srb->win8_extension.srb_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) (SRB_FLAGS_QUEUE_ACTION_ENABLE | SRB_FLAGS_NO_QUEUE_FREEZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) vm_srb->win8_extension.queue_tag = SP_UNTAGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) vm_srb->win8_extension.queue_action = SRB_SIMPLE_TAG_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) /* Build the SRB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) switch (scmnd->sc_data_direction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) case DMA_TO_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) vm_srb->data_in = WRITE_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) case DMA_FROM_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) vm_srb->data_in = READ_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) case DMA_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) vm_srb->data_in = UNKNOWN_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) * This is DMA_BIDIRECTIONAL or something else we are never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) * supposed to see here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) WARN(1, "Unexpected data direction: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) scmnd->sc_data_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) vm_srb->port_number = host_dev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) vm_srb->path_id = scmnd->device->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) vm_srb->target_id = scmnd->device->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) vm_srb->lun = scmnd->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) vm_srb->cdb_length = scmnd->cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) sgl = (struct scatterlist *)scsi_sglist(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) sg_count = scsi_sg_count(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) length = scsi_bufflen(scmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) payload_sz = sizeof(cmd_request->mpb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) if (sg_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) unsigned int hvpgoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) unsigned long offset_in_hvpg = sgl->offset & ~HV_HYP_PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) unsigned int hvpg_count = HVPFN_UP(offset_in_hvpg + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) u64 hvpfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) if (hvpg_count > MAX_PAGE_BUFFER_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) payload_sz = (hvpg_count * sizeof(u64) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) sizeof(struct vmbus_packet_mpb_array));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) payload = kzalloc(payload_sz, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (!payload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) return SCSI_MLQUEUE_DEVICE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) * sgl is a list of PAGEs, and payload->range.pfn_array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) * expects the page number in the unit of HV_HYP_PAGE_SIZE (the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) * page size that Hyper-V uses, so here we need to divide PAGEs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) * into HV_HYP_PAGE in case that PAGE_SIZE > HV_HYP_PAGE_SIZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) * Besides, payload->range.offset should be the offset in one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) * HV_HYP_PAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) payload->range.len = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) payload->range.offset = offset_in_hvpg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) hvpgoff = sgl->offset >> HV_HYP_PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) cur_sgl = sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) for (i = 0; i < hvpg_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) * 'i' is the index of hv pages in the payload and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) * 'hvpgoff' is the offset (in hv pages) of the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) * hv page in the the first page. The relationship
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) * between the sum of 'i' and 'hvpgoff' and the offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) * (in hv pages) in a payload page ('hvpgoff_in_page')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) * is as follow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) * |------------------ PAGE -------------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) * | NR_HV_HYP_PAGES_IN_PAGE hvpgs in total |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) * |hvpg|hvpg| ... |hvpg|... |hvpg|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) * ^ ^ ^ ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) * +-hvpgoff-+ +-hvpgoff_in_page-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) * ^ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) * +--------------------- i ---------------------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) unsigned int hvpgoff_in_page =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) (i + hvpgoff) % NR_HV_HYP_PAGES_IN_PAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) * Two cases that we need to fetch a page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) * 1) i == 0, the first step or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) * 2) hvpgoff_in_page == 0, when we reach the boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) * of a page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (hvpgoff_in_page == 0 || i == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) hvpfn = page_to_hvpfn(sg_page(cur_sgl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) cur_sgl = sg_next(cur_sgl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) payload->range.pfn_array[i] = hvpfn + hvpgoff_in_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) cmd_request->payload = payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) cmd_request->payload_sz = payload_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) /* Invokes the vsc to start an IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) ret = storvsc_do_io(dev, cmd_request, get_cpu());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) put_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) if (payload_sz > sizeof(cmd_request->mpb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) kfree(payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) /* no more space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) return SCSI_MLQUEUE_DEVICE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) static struct scsi_host_template scsi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) .name = "storvsc_host_t",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) .cmd_size = sizeof(struct storvsc_cmd_request),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) .bios_param = storvsc_get_chs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) .queuecommand = storvsc_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) .eh_host_reset_handler = storvsc_host_reset_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) .proc_name = "storvsc_host",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) .eh_timed_out = storvsc_eh_timed_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) .slave_alloc = storvsc_device_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) .slave_configure = storvsc_device_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) .cmd_per_lun = 2048,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) .this_id = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) /* Make sure we dont get a sg segment crosses a page boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) .dma_boundary = PAGE_SIZE-1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) /* Ensure there are no gaps in presented sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) .virt_boundary_mask = PAGE_SIZE-1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) .no_write_same = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) .track_queue_depth = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) .change_queue_depth = storvsc_change_queue_depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) SCSI_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) IDE_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) SFC_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) static const struct hv_vmbus_device_id id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) /* SCSI guid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) { HV_SCSI_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) .driver_data = SCSI_GUID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) /* IDE guid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) { HV_IDE_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) .driver_data = IDE_GUID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) /* Fibre Channel GUID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) HV_SYNTHFC_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) .driver_data = SFC_GUID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) MODULE_DEVICE_TABLE(vmbus, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) static const struct { guid_t guid; } fc_guid = { HV_SYNTHFC_GUID };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) static bool hv_dev_is_fc(struct hv_device *hv_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) return guid_equal(&fc_guid.guid, &hv_dev->dev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) static int storvsc_probe(struct hv_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) const struct hv_vmbus_device_id *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) int num_cpus = num_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) struct hv_host_device *host_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) bool is_fc = ((dev_id->driver_data == SFC_GUID) ? true : false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) int target = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) struct storvsc_device *stor_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) int max_luns_per_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) int max_targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) int max_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) int max_sub_channels = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) * Based on the windows host we are running on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) * set state to properly communicate with the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) if (vmbus_proto_version < VERSION_WIN8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) max_luns_per_target = STORVSC_IDE_MAX_LUNS_PER_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) max_targets = STORVSC_IDE_MAX_TARGETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) max_channels = STORVSC_IDE_MAX_CHANNELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) max_luns_per_target = STORVSC_MAX_LUNS_PER_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) max_targets = STORVSC_MAX_TARGETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) max_channels = STORVSC_MAX_CHANNELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) * On Windows8 and above, we support sub-channels for storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) * on SCSI and FC controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) * The number of sub-channels offerred is based on the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) * VCPUs in the guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) if (!dev_is_ide)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) max_sub_channels =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) (num_cpus - 1) / storvsc_vcpus_per_sub_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) scsi_driver.can_queue = max_outstanding_req_per_channel *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) (max_sub_channels + 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) (100 - ring_avail_percent_lowater) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) host = scsi_host_alloc(&scsi_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) sizeof(struct hv_host_device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) host_dev = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) memset(host_dev, 0, sizeof(struct hv_host_device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) host_dev->port = host->host_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) host_dev->dev = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) host_dev->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) if (!stor_device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) goto err_out0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) stor_device->destroy = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) init_waitqueue_head(&stor_device->waiting_to_drain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) stor_device->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) stor_device->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) spin_lock_init(&stor_device->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) hv_set_drvdata(device, stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) stor_device->port_number = host->host_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size, is_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) goto err_out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) host_dev->path = stor_device->path_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) host_dev->target = stor_device->target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) switch (dev_id->driver_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) case SFC_GUID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) host->max_lun = STORVSC_FC_MAX_LUNS_PER_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) host->max_id = STORVSC_FC_MAX_TARGETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) host->max_channel = STORVSC_FC_MAX_CHANNELS - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) host->transportt = fc_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) case SCSI_GUID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) host->max_lun = max_luns_per_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) host->max_id = max_targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) host->max_channel = max_channels - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) host->max_lun = STORVSC_IDE_MAX_LUNS_PER_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) host->max_id = STORVSC_IDE_MAX_TARGETS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) host->max_channel = STORVSC_IDE_MAX_CHANNELS - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) /* max cmd length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) host->max_cmd_len = STORVSC_MAX_CMD_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) * set the table size based on the info we got
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) * from the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) host->sg_tablesize = (stor_device->max_transfer_bytes >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) * For non-IDE disks, the host supports multiple channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) * Set the number of HW queues we are supporting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) if (!dev_is_ide)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) host->nr_hw_queues = num_present_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) * Set the error handler work queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) host_dev->handle_error_wq =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) alloc_ordered_workqueue("storvsc_error_wq_%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) WQ_MEM_RECLAIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) if (!host_dev->handle_error_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) goto err_out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) INIT_WORK(&host_dev->host_scan_work, storvsc_host_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) /* Register the HBA and start the scsi bus scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) ret = scsi_add_host(host, &device->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) goto err_out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) if (!dev_is_ide) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) scsi_scan_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) target = (device->dev_instance.b[5] << 8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) device->dev_instance.b[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) ret = scsi_add_device(host, 0, target, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) goto err_out4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) if (host->transportt == fc_transport_template) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) struct fc_rport_identifiers ids = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) .roles = FC_PORT_ROLE_FCP_DUMMY_INITIATOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) fc_host_node_name(host) = stor_device->node_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) fc_host_port_name(host) = stor_device->port_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) stor_device->rport = fc_remote_port_add(host, 0, &ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) if (!stor_device->rport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) goto err_out4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) err_out4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) scsi_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) err_out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) destroy_workqueue(host_dev->handle_error_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) err_out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) * Once we have connected with the host, we would need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) * to invoke storvsc_dev_remove() to rollback this state and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) * this call also frees up the stor_device; hence the jump around
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) * err_out1 label.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) storvsc_dev_remove(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) goto err_out0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) err_out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) kfree(stor_device->stor_chns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) kfree(stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) err_out0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) /* Change a scsi target's queue depth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) static int storvsc_change_queue_depth(struct scsi_device *sdev, int queue_depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) if (queue_depth > scsi_driver.can_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) queue_depth = scsi_driver.can_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) return scsi_change_queue_depth(sdev, queue_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) static int storvsc_remove(struct hv_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) struct storvsc_device *stor_device = hv_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) struct Scsi_Host *host = stor_device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) struct hv_host_device *host_dev = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) if (host->transportt == fc_transport_template) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) fc_remote_port_delete(stor_device->rport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) fc_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) destroy_workqueue(host_dev->handle_error_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) scsi_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) storvsc_dev_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) static int storvsc_suspend(struct hv_device *hv_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) struct storvsc_device *stor_device = hv_get_drvdata(hv_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) struct Scsi_Host *host = stor_device->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) struct hv_host_device *host_dev = shost_priv(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) storvsc_wait_to_drain(stor_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) drain_workqueue(host_dev->handle_error_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) vmbus_close(hv_dev->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) kfree(stor_device->stor_chns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) stor_device->stor_chns = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) cpumask_clear(&stor_device->alloced_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) static int storvsc_resume(struct hv_device *hv_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) ret = storvsc_connect_to_vsp(hv_dev, storvsc_ringbuffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) hv_dev_is_fc(hv_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) static struct hv_driver storvsc_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) .id_table = id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) .probe = storvsc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) .remove = storvsc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) .suspend = storvsc_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) .resume = storvsc_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) .probe_type = PROBE_PREFER_ASYNCHRONOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) static struct fc_function_template fc_transport_functions = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) .show_host_node_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) .show_host_port_name = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) static int __init storvsc_drv_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) * Divide the ring buffer data size (which is 1 page less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) * than the ring buffer size since that page is reserved for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) * the ring buffer indices) by the max request size (which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) max_outstanding_req_per_channel =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) ((storvsc_ringbuffer_size - PAGE_SIZE) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) sizeof(struct vstor_packet) + sizeof(u64) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) vmscsi_size_delta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) sizeof(u64)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) fc_transport_template = fc_attach_transport(&fc_transport_functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) if (!fc_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) ret = vmbus_driver_register(&storvsc_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) fc_release_transport(fc_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) static void __exit storvsc_drv_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) vmbus_driver_unregister(&storvsc_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) #if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) fc_release_transport(fc_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) module_init(storvsc_drv_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) module_exit(storvsc_drv_exit);