Skip to content

Commit 86c8fb4

Browse files
Saurabh Sengarliuw
authored andcommitted
scsi: storvsc: Removing Pre Win8 related logic
The latest storvsc code has already removed the support for windows 7 and earlier. There is still some code logic remaining which is there to support pre Windows 8 OS. This patch removes these stale logic. This patch majorly does three things : 1. Removes vmscsi_size_delta and its logic, as the vmscsi_request struct is same for all the OS post windows 8 there is no need of delta. 2. Simplify sense_buffer_size logic, as there is single buffer size for all the post windows 8 OS. 3. Embed the vmscsi_win8_extension structure inside the vmscsi_request, as there is no separate handling required for different OS. Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/1653478022-26621-1-git-send-email-ssengar@linux.microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 1940f9f commit 86c8fb4

1 file changed

Lines changed: 39 additions & 116 deletions

File tree

drivers/scsi/storvsc_drv.c

Lines changed: 39 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454

5555
#define VMSTOR_PROTO_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
5656
(((MINOR_) & 0xff)))
57-
5857
#define VMSTOR_PROTO_VERSION_WIN6 VMSTOR_PROTO_VERSION(2, 0)
5958
#define VMSTOR_PROTO_VERSION_WIN7 VMSTOR_PROTO_VERSION(4, 2)
6059
#define VMSTOR_PROTO_VERSION_WIN8 VMSTOR_PROTO_VERSION(5, 1)
@@ -136,20 +135,10 @@ struct hv_fc_wwn_packet {
136135
*/
137136
#define STORVSC_MAX_CMD_LEN 0x10
138137

139-
#define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
140-
#define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
141-
138+
/* Sense buffer size is the same for all versions since Windows 8 */
142139
#define STORVSC_SENSE_BUFFER_SIZE 0x14
143140
#define STORVSC_MAX_BUF_LEN_WITH_PADDING 0x14
144141

145-
/*
146-
* Sense buffer size changed in win8; have a run-time
147-
* variable to track the size we should use. This value will
148-
* likely change during protocol negotiation but it is valid
149-
* to start by assuming pre-Win8.
150-
*/
151-
static int sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
152-
153142
/*
154143
* The storage protocol version is determined during the
155144
* initial exchange with the host. It will indicate which
@@ -177,18 +166,6 @@ do { \
177166
dev_warn(&(dev)->device, fmt, ##__VA_ARGS__); \
178167
} while (0)
179168

180-
struct vmscsi_win8_extension {
181-
/*
182-
* The following were added in Windows 8
183-
*/
184-
u16 reserve;
185-
u8 queue_tag;
186-
u8 queue_action;
187-
u32 srb_flags;
188-
u32 time_out_value;
189-
u32 queue_sort_ey;
190-
} __packed;
191-
192169
struct vmscsi_request {
193170
u16 length;
194171
u8 srb_status;
@@ -214,46 +191,23 @@ struct vmscsi_request {
214191
/*
215192
* The following was added in win8.
216193
*/
217-
struct vmscsi_win8_extension win8_extension;
194+
u16 reserve;
195+
u8 queue_tag;
196+
u8 queue_action;
197+
u32 srb_flags;
198+
u32 time_out_value;
199+
u32 queue_sort_ey;
218200

219201
} __attribute((packed));
220202

221203
/*
222-
* The list of storage protocols in order of preference.
204+
* The list of windows version in order of preference.
223205
*/
224-
struct vmstor_protocol {
225-
int protocol_version;
226-
int sense_buffer_size;
227-
int vmscsi_size_delta;
228-
};
229-
230206

231-
static const struct vmstor_protocol vmstor_protocols[] = {
232-
{
207+
static const int protocol_version[] = {
233208
VMSTOR_PROTO_VERSION_WIN10,
234-
POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
235-
0
236-
},
237-
{
238209
VMSTOR_PROTO_VERSION_WIN8_1,
239-
POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
240-
0
241-
},
242-
{
243210
VMSTOR_PROTO_VERSION_WIN8,
244-
POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
245-
0
246-
},
247-
{
248-
VMSTOR_PROTO_VERSION_WIN7,
249-
PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
250-
sizeof(struct vmscsi_win8_extension),
251-
},
252-
{
253-
VMSTOR_PROTO_VERSION_WIN6,
254-
PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
255-
sizeof(struct vmscsi_win8_extension),
256-
}
257211
};
258212

259213

@@ -409,9 +363,7 @@ static void storvsc_on_channel_callback(void *context);
409363
#define STORVSC_IDE_MAX_CHANNELS 1
410364

411365
/*
412-
* Upper bound on the size of a storvsc packet. vmscsi_size_delta is not
413-
* included in the calculation because it is set after STORVSC_MAX_PKT_SIZE
414-
* is used in storvsc_connect_to_vsp
366+
* Upper bound on the size of a storvsc packet.
415367
*/
416368
#define STORVSC_MAX_PKT_SIZE (sizeof(struct vmpacket_descriptor) +\
417369
sizeof(struct vstor_packet))
@@ -452,17 +404,6 @@ struct storvsc_device {
452404
unsigned char path_id;
453405
unsigned char target_id;
454406

455-
/*
456-
* The size of the vmscsi_request has changed in win8. The
457-
* additional size is because of new elements added to the
458-
* structure. These elements are valid only when we are talking
459-
* to a win8 host.
460-
* Track the correction to size we need to apply. This value
461-
* will likely change during protocol negotiation but it is
462-
* valid to start by assuming pre-Win8.
463-
*/
464-
int vmscsi_size_delta;
465-
466407
/*
467408
* Max I/O, the device can support.
468409
*/
@@ -795,8 +736,7 @@ static void handle_multichannel_storage(struct hv_device *device, int max_chns)
795736
vstor_packet->sub_channel_count = num_sc;
796737

797738
ret = vmbus_sendpacket(device->channel, vstor_packet,
798-
(sizeof(struct vstor_packet) -
799-
stor_device->vmscsi_size_delta),
739+
sizeof(struct vstor_packet),
800740
VMBUS_RQST_INIT,
801741
VM_PKT_DATA_INBAND,
802742
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -864,8 +804,7 @@ static int storvsc_execute_vstor_op(struct hv_device *device,
864804
vstor_packet->flags = REQUEST_COMPLETION_FLAG;
865805

866806
ret = vmbus_sendpacket(device->channel, vstor_packet,
867-
(sizeof(struct vstor_packet) -
868-
stor_device->vmscsi_size_delta),
807+
sizeof(struct vstor_packet),
869808
VMBUS_RQST_INIT,
870809
VM_PKT_DATA_INBAND,
871810
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -915,14 +854,13 @@ static int storvsc_channel_init(struct hv_device *device, bool is_fc)
915854
* Query host supported protocol version.
916855
*/
917856

918-
for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
857+
for (i = 0; i < ARRAY_SIZE(protocol_version); i++) {
919858
/* reuse the packet for version range supported */
920859
memset(vstor_packet, 0, sizeof(struct vstor_packet));
921860
vstor_packet->operation =
922861
VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
923862

924-
vstor_packet->version.major_minor =
925-
vmstor_protocols[i].protocol_version;
863+
vstor_packet->version.major_minor = protocol_version[i];
926864

927865
/*
928866
* The revision number is only used in Windows; set it to 0.
@@ -936,21 +874,16 @@ static int storvsc_channel_init(struct hv_device *device, bool is_fc)
936874
return -EINVAL;
937875

938876
if (vstor_packet->status == 0) {
939-
vmstor_proto_version =
940-
vmstor_protocols[i].protocol_version;
941-
942-
sense_buffer_size =
943-
vmstor_protocols[i].sense_buffer_size;
944-
945-
stor_device->vmscsi_size_delta =
946-
vmstor_protocols[i].vmscsi_size_delta;
877+
vmstor_proto_version = protocol_version[i];
947878

948879
break;
949880
}
950881
}
951882

952-
if (vstor_packet->status != 0)
883+
if (vstor_packet->status != 0) {
884+
dev_err(&device->device, "Obsolete Hyper-V version\n");
953885
return -EINVAL;
886+
}
954887

955888

956889
memset(vstor_packet, 0, sizeof(struct vstor_packet));
@@ -986,11 +919,10 @@ static int storvsc_channel_init(struct hv_device *device, bool is_fc)
986919
cpumask_set_cpu(device->channel->target_cpu,
987920
&stor_device->alloced_cpus);
988921

989-
if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
990-
if (vstor_packet->storage_channel_properties.flags &
991-
STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
992-
process_sub_channels = true;
993-
}
922+
if (vstor_packet->storage_channel_properties.flags &
923+
STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
924+
process_sub_channels = true;
925+
994926
stor_device->max_transfer_bytes =
995927
vstor_packet->storage_channel_properties.max_transfer_bytes;
996928

@@ -1197,7 +1129,7 @@ static void storvsc_on_io_completion(struct storvsc_device *stor_device,
11971129
* Copy over the sense_info_length, but limit to the known max
11981130
* size if Hyper-V returns a bad value.
11991131
*/
1200-
stor_pkt->vm_srb.sense_info_length = min_t(u8, sense_buffer_size,
1132+
stor_pkt->vm_srb.sense_info_length = min_t(u8, STORVSC_SENSE_BUFFER_SIZE,
12011133
vstor_packet->vm_srb.sense_info_length);
12021134

12031135
if (vstor_packet->vm_srb.scsi_status != 0 ||
@@ -1289,8 +1221,8 @@ static void storvsc_on_channel_callback(void *context)
12891221
struct storvsc_cmd_request *request = NULL;
12901222
u32 pktlen = hv_pkt_datalen(desc);
12911223
u64 rqst_id = desc->trans_id;
1292-
u32 minlen = rqst_id ? sizeof(struct vstor_packet) -
1293-
stor_device->vmscsi_size_delta : sizeof(enum vstor_packet_operation);
1224+
u32 minlen = rqst_id ? sizeof(struct vstor_packet) :
1225+
sizeof(enum vstor_packet_operation);
12941226

12951227
if (pktlen < minlen) {
12961228
dev_err(&device->device,
@@ -1346,7 +1278,7 @@ static void storvsc_on_channel_callback(void *context)
13461278
}
13471279

13481280
memcpy(&request->vstor_packet, packet,
1349-
(sizeof(struct vstor_packet) - stor_device->vmscsi_size_delta));
1281+
sizeof(struct vstor_packet));
13501282
complete(&request->wait_event);
13511283
}
13521284
}
@@ -1557,11 +1489,10 @@ static int storvsc_do_io(struct hv_device *device,
15571489
found_channel:
15581490
vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
15591491

1560-
vstor_packet->vm_srb.length = (sizeof(struct vmscsi_request) -
1561-
stor_device->vmscsi_size_delta);
1492+
vstor_packet->vm_srb.length = sizeof(struct vmscsi_request);
15621493

15631494

1564-
vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
1495+
vstor_packet->vm_srb.sense_info_length = STORVSC_SENSE_BUFFER_SIZE;
15651496

15661497

15671498
vstor_packet->vm_srb.data_transfer_length =
@@ -1574,13 +1505,11 @@ static int storvsc_do_io(struct hv_device *device,
15741505
ret = vmbus_sendpacket_mpb_desc(outgoing_channel,
15751506
request->payload, request->payload_sz,
15761507
vstor_packet,
1577-
(sizeof(struct vstor_packet) -
1578-
stor_device->vmscsi_size_delta),
1508+
sizeof(struct vstor_packet),
15791509
(unsigned long)request);
15801510
} else {
15811511
ret = vmbus_sendpacket(outgoing_channel, vstor_packet,
1582-
(sizeof(struct vstor_packet) -
1583-
stor_device->vmscsi_size_delta),
1512+
sizeof(struct vstor_packet),
15841513
(unsigned long)request,
15851514
VM_PKT_DATA_INBAND,
15861515
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -1684,8 +1613,7 @@ static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
16841613
vstor_packet->vm_srb.path_id = stor_device->path_id;
16851614

16861615
ret = vmbus_sendpacket(device->channel, vstor_packet,
1687-
(sizeof(struct vstor_packet) -
1688-
stor_device->vmscsi_size_delta),
1616+
sizeof(struct vstor_packet),
16891617
VMBUS_RQST_RESET,
16901618
VM_PKT_DATA_INBAND,
16911619
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -1778,31 +1706,31 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
17781706

17791707
memset(&cmd_request->vstor_packet, 0, sizeof(struct vstor_packet));
17801708
vm_srb = &cmd_request->vstor_packet.vm_srb;
1781-
vm_srb->win8_extension.time_out_value = 60;
1709+
vm_srb->time_out_value = 60;
17821710

1783-
vm_srb->win8_extension.srb_flags |=
1711+
vm_srb->srb_flags |=
17841712
SRB_FLAGS_DISABLE_SYNCH_TRANSFER;
17851713

17861714
if (scmnd->device->tagged_supported) {
1787-
vm_srb->win8_extension.srb_flags |=
1715+
vm_srb->srb_flags |=
17881716
(SRB_FLAGS_QUEUE_ACTION_ENABLE | SRB_FLAGS_NO_QUEUE_FREEZE);
1789-
vm_srb->win8_extension.queue_tag = SP_UNTAGGED;
1790-
vm_srb->win8_extension.queue_action = SRB_SIMPLE_TAG_REQUEST;
1717+
vm_srb->queue_tag = SP_UNTAGGED;
1718+
vm_srb->queue_action = SRB_SIMPLE_TAG_REQUEST;
17911719
}
17921720

17931721
/* Build the SRB */
17941722
switch (scmnd->sc_data_direction) {
17951723
case DMA_TO_DEVICE:
17961724
vm_srb->data_in = WRITE_TYPE;
1797-
vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_OUT;
1725+
vm_srb->srb_flags |= SRB_FLAGS_DATA_OUT;
17981726
break;
17991727
case DMA_FROM_DEVICE:
18001728
vm_srb->data_in = READ_TYPE;
1801-
vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
1729+
vm_srb->srb_flags |= SRB_FLAGS_DATA_IN;
18021730
break;
18031731
case DMA_NONE:
18041732
vm_srb->data_in = UNKNOWN_TYPE;
1805-
vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
1733+
vm_srb->srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
18061734
break;
18071735
default:
18081736
/*
@@ -2004,7 +1932,6 @@ static int storvsc_probe(struct hv_device *device,
20041932
init_waitqueue_head(&stor_device->waiting_to_drain);
20051933
stor_device->device = device;
20061934
stor_device->host = host;
2007-
stor_device->vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
20081935
spin_lock_init(&stor_device->lock);
20091936
hv_set_drvdata(device, stor_device);
20101937
dma_set_min_align_mask(&device->device, HV_HYP_PAGE_SIZE - 1);
@@ -2217,10 +2144,6 @@ static int __init storvsc_drv_init(void)
22172144
* than the ring buffer size since that page is reserved for
22182145
* the ring buffer indices) by the max request size (which is
22192146
* vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
2220-
*
2221-
* The computation underestimates max_outstanding_req_per_channel
2222-
* for Win7 and older hosts because it does not take into account
2223-
* the vmscsi_size_delta correction to the max request size.
22242147
*/
22252148
max_outstanding_req_per_channel =
22262149
((storvsc_ringbuffer_size - PAGE_SIZE) /

0 commit comments

Comments
 (0)