1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
|
/*-
* Copyright (c) 2009-2012,2016 Microsoft Corp.
* Copyright (c) 2010-2012 Citrix Inc.
* Copyright (c) 2012 NetApp Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_var.h>
#include <net/ethernet.h>
#include <sys/types.h>
#include <machine/atomic.h>
#include <sys/sema.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/vmbus_xact.h>
#include <dev/hyperv/netvsc/hv_net_vsc.h>
#include <dev/hyperv/netvsc/hv_rndis.h>
#include <dev/hyperv/netvsc/hv_rndis_filter.h>
#include <dev/hyperv/netvsc/if_hnreg.h>
#include <dev/hyperv/netvsc/ndis.h>
#define HV_RF_RECVINFO_VLAN 0x1
#define HV_RF_RECVINFO_CSUM 0x2
#define HV_RF_RECVINFO_HASHINF 0x4
#define HV_RF_RECVINFO_HASHVAL 0x8
#define HV_RF_RECVINFO_ALL \
(HV_RF_RECVINFO_VLAN | \
HV_RF_RECVINFO_CSUM | \
HV_RF_RECVINFO_HASHINF | \
HV_RF_RECVINFO_HASHVAL)
#define HN_RNDIS_RID_COMPAT_MASK 0xffff
#define HN_RNDIS_RID_COMPAT_MAX HN_RNDIS_RID_COMPAT_MASK
#define HN_RNDIS_XFER_SIZE 2048
/*
* Forward declarations
*/
static int hv_rf_send_request(rndis_device *device, rndis_request *request,
uint32_t message_type);
static void hv_rf_receive_response(rndis_device *device,
const rndis_msg *response);
static void hv_rf_receive_indicate_status(rndis_device *device,
const rndis_msg *response);
static void hv_rf_receive_data(struct hn_rx_ring *rxr,
const void *data, int dlen);
static inline int hv_rf_query_device_mac(rndis_device *device);
static inline int hv_rf_query_device_link_status(rndis_device *device);
static int hv_rf_init_device(rndis_device *device);
static void hn_rndis_sent_halt(struct hn_send_ctx *sndc,
struct hn_softc *sc, struct vmbus_channel *chan,
const void *data, int dlen);
static void hn_rndis_sent_cb(struct hn_send_ctx *sndc,
struct hn_softc *sc, struct vmbus_channel *chan,
const void *data, int dlen);
static int hn_rndis_query(struct hn_softc *sc, uint32_t oid,
const void *idata, size_t idlen, void *odata, size_t *odlen0);
static int hn_rndis_set(struct hn_softc *sc, uint32_t oid, const void *data,
size_t dlen);
static int hn_rndis_conf_offload(struct hn_softc *sc);
static int hn_rndis_get_rsscaps(struct hn_softc *sc, int *rxr_cnt);
static int hn_rndis_conf_rss(struct hn_softc *sc, int nchan);
static __inline uint32_t
hn_rndis_rid(struct hn_softc *sc)
{
uint32_t rid;
again:
rid = atomic_fetchadd_int(&sc->hn_rndis_rid, 1);
if (rid == 0)
goto again;
/* Use upper 16 bits for non-compat RNDIS messages. */
return ((rid & 0xffff) << 16);
}
/*
* Set the Per-Packet-Info with the specified type
*/
void *
hv_set_rppi_data(rndis_msg *rndis_mesg, uint32_t rppi_size,
int pkt_type)
{
rndis_packet *rndis_pkt;
rndis_per_packet_info *rppi;
rndis_pkt = &rndis_mesg->msg.packet;
rndis_pkt->data_offset += rppi_size;
rppi = (rndis_per_packet_info *)((char *)rndis_pkt +
rndis_pkt->per_pkt_info_offset + rndis_pkt->per_pkt_info_length);
rppi->size = rppi_size;
rppi->type = pkt_type;
rppi->per_packet_info_offset = sizeof(rndis_per_packet_info);
rndis_pkt->per_pkt_info_length += rppi_size;
return (rppi);
}
/*
* Get the Per-Packet-Info with the specified type
* return NULL if not found.
*/
void *
hv_get_ppi_data(rndis_packet *rpkt, uint32_t type)
{
rndis_per_packet_info *ppi;
int len;
if (rpkt->per_pkt_info_offset == 0)
return (NULL);
ppi = (rndis_per_packet_info *)((unsigned long)rpkt +
rpkt->per_pkt_info_offset);
len = rpkt->per_pkt_info_length;
while (len > 0) {
if (ppi->type == type)
return (void *)((unsigned long)ppi +
ppi->per_packet_info_offset);
len -= ppi->size;
ppi = (rndis_per_packet_info *)((unsigned long)ppi + ppi->size);
}
return (NULL);
}
/*
* Allow module_param to work and override to switch to promiscuous mode.
*/
static inline rndis_device *
hv_get_rndis_device(void)
{
rndis_device *device;
device = malloc(sizeof(rndis_device), M_NETVSC, M_WAITOK | M_ZERO);
mtx_init(&device->req_lock, "HV-FRL", NULL, MTX_DEF);
/* Same effect as STAILQ_HEAD_INITIALIZER() static initializer */
STAILQ_INIT(&device->myrequest_list);
device->state = RNDIS_DEV_UNINITIALIZED;
return (device);
}
/*
*
*/
static inline void
hv_put_rndis_device(rndis_device *device)
{
mtx_destroy(&device->req_lock);
free(device, M_NETVSC);
}
/*
*
*/
static inline rndis_request *
hv_rndis_request(rndis_device *device, uint32_t message_type,
uint32_t message_length)
{
rndis_request *request;
rndis_msg *rndis_mesg;
rndis_set_request *set;
request = malloc(sizeof(rndis_request), M_NETVSC, M_WAITOK | M_ZERO);
sema_init(&request->wait_sema, 0, "rndis sema");
rndis_mesg = &request->request_msg;
rndis_mesg->ndis_msg_type = message_type;
rndis_mesg->msg_len = message_length;
/*
* Set the request id. This field is always after the rndis header
* for request/response packet types so we just use the set_request
* as a template.
*/
set = &rndis_mesg->msg.set_request;
set->request_id = atomic_fetchadd_int(&device->new_request_id, 1) &
HN_RNDIS_RID_COMPAT_MASK;
/* Add to the request list */
mtx_lock(&device->req_lock);
STAILQ_INSERT_TAIL(&device->myrequest_list, request, mylist_entry);
mtx_unlock(&device->req_lock);
return (request);
}
/*
*
*/
static inline void
hv_put_rndis_request(rndis_device *device, rndis_request *request)
{
mtx_lock(&device->req_lock);
/* Fixme: Has O(n) performance */
/*
* XXXKYS: Use Doubly linked lists.
*/
STAILQ_REMOVE(&device->myrequest_list, request, rndis_request_,
mylist_entry);
mtx_unlock(&device->req_lock);
sema_destroy(&request->wait_sema);
free(request, M_NETVSC);
}
/*
*
*/
static int
hv_rf_send_request(rndis_device *device, rndis_request *request,
uint32_t message_type)
{
struct hn_softc *sc = device->sc;
uint32_t send_buf_section_idx, tot_data_buf_len;
struct vmbus_gpa gpa[2];
int gpa_cnt, send_buf_section_size;
hn_sent_callback_t cb;
/* Set up the packet to send it */
tot_data_buf_len = request->request_msg.msg_len;
gpa_cnt = 1;
gpa[0].gpa_page = hv_get_phys_addr(&request->request_msg) >> PAGE_SHIFT;
gpa[0].gpa_len = request->request_msg.msg_len;
gpa[0].gpa_ofs = (unsigned long)&request->request_msg & (PAGE_SIZE - 1);
if (gpa[0].gpa_ofs + gpa[0].gpa_len > PAGE_SIZE) {
gpa_cnt = 2;
gpa[0].gpa_len = PAGE_SIZE - gpa[0].gpa_ofs;
gpa[1].gpa_page =
hv_get_phys_addr((char*)&request->request_msg +
gpa[0].gpa_len) >> PAGE_SHIFT;
gpa[1].gpa_ofs = 0;
gpa[1].gpa_len = request->request_msg.msg_len - gpa[0].gpa_len;
}
if (message_type != REMOTE_NDIS_HALT_MSG)
cb = hn_rndis_sent_cb;
else
cb = hn_rndis_sent_halt;
if (tot_data_buf_len < sc->hn_chim_szmax) {
send_buf_section_idx = hn_chim_alloc(sc);
if (send_buf_section_idx != HN_NVS_CHIM_IDX_INVALID) {
uint8_t *dest = sc->hn_chim +
(send_buf_section_idx * sc->hn_chim_szmax);
memcpy(dest, &request->request_msg, request->request_msg.msg_len);
send_buf_section_size = tot_data_buf_len;
gpa_cnt = 0;
goto sendit;
}
/* Failed to allocate chimney send buffer; move on */
}
send_buf_section_idx = HN_NVS_CHIM_IDX_INVALID;
send_buf_section_size = 0;
sendit:
hn_send_ctx_init(&request->send_ctx, cb, request,
send_buf_section_idx, send_buf_section_size);
return hv_nv_on_send(sc->hn_prichan, HN_NVS_RNDIS_MTYPE_CTRL,
&request->send_ctx, gpa, gpa_cnt);
}
/*
* RNDIS filter receive response
*/
static void
hv_rf_receive_response(rndis_device *device, const rndis_msg *response)
{
rndis_request *request = NULL;
rndis_request *next_request;
boolean_t found = FALSE;
mtx_lock(&device->req_lock);
request = STAILQ_FIRST(&device->myrequest_list);
while (request != NULL) {
/*
* All request/response message contains request_id as the
* first field
*/
if (request->request_msg.msg.init_request.request_id ==
response->msg.init_complete.request_id) {
found = TRUE;
break;
}
next_request = STAILQ_NEXT(request, mylist_entry);
request = next_request;
}
mtx_unlock(&device->req_lock);
if (found) {
if (response->msg_len <= sizeof(rndis_msg)) {
memcpy(&request->response_msg, response,
response->msg_len);
} else {
request->response_msg.msg.init_complete.status =
RNDIS_STATUS_BUFFER_OVERFLOW;
}
sema_post(&request->wait_sema);
}
}
/*
* RNDIS filter receive indicate status
*/
static void
hv_rf_receive_indicate_status(rndis_device *device, const rndis_msg *response)
{
const rndis_indicate_status *indicate = &response->msg.indicate_status;
switch(indicate->status) {
case RNDIS_STATUS_MEDIA_CONNECT:
netvsc_linkstatus_callback(device->sc, 1);
break;
case RNDIS_STATUS_MEDIA_DISCONNECT:
netvsc_linkstatus_callback(device->sc, 0);
break;
default:
/* TODO: */
device_printf(device->sc->hn_dev,
"unknown status %d received\n", indicate->status);
break;
}
}
static int
hv_rf_find_recvinfo(const rndis_packet *rpkt, struct hn_recvinfo *info)
{
const rndis_per_packet_info *ppi;
uint32_t mask, len;
info->vlan_info = NULL;
info->csum_info = NULL;
info->hash_info = NULL;
info->hash_value = NULL;
if (rpkt->per_pkt_info_offset == 0)
return 0;
ppi = (const rndis_per_packet_info *)
((const uint8_t *)rpkt + rpkt->per_pkt_info_offset);
len = rpkt->per_pkt_info_length;
mask = 0;
while (len != 0) {
const void *ppi_dptr;
uint32_t ppi_dlen;
if (__predict_false(ppi->size < ppi->per_packet_info_offset))
return EINVAL;
ppi_dlen = ppi->size - ppi->per_packet_info_offset;
ppi_dptr = (const uint8_t *)ppi + ppi->per_packet_info_offset;
switch (ppi->type) {
case ieee_8021q_info:
if (__predict_false(ppi_dlen < sizeof(ndis_8021q_info)))
return EINVAL;
info->vlan_info = ppi_dptr;
mask |= HV_RF_RECVINFO_VLAN;
break;
case tcpip_chksum_info:
if (__predict_false(ppi_dlen <
sizeof(rndis_tcp_ip_csum_info)))
return EINVAL;
info->csum_info = ppi_dptr;
mask |= HV_RF_RECVINFO_CSUM;
break;
case nbl_hash_value:
if (__predict_false(ppi_dlen <
sizeof(struct rndis_hash_value)))
return EINVAL;
info->hash_value = ppi_dptr;
mask |= HV_RF_RECVINFO_HASHVAL;
break;
case nbl_hash_info:
if (__predict_false(ppi_dlen <
sizeof(struct rndis_hash_info)))
return EINVAL;
info->hash_info = ppi_dptr;
mask |= HV_RF_RECVINFO_HASHINF;
break;
default:
goto skip;
}
if (mask == HV_RF_RECVINFO_ALL) {
/* All found; done */
break;
}
skip:
if (__predict_false(len < ppi->size))
return EINVAL;
len -= ppi->size;
ppi = (const rndis_per_packet_info *)
((const uint8_t *)ppi + ppi->size);
}
return 0;
}
/*
* RNDIS filter receive data
*/
static void
hv_rf_receive_data(struct hn_rx_ring *rxr, const void *data, int dlen)
{
const rndis_msg *message = data;
const rndis_packet *rndis_pkt;
uint32_t data_offset;
struct hn_recvinfo info;
rndis_pkt = &message->msg.packet;
/*
* Fixme: Handle multiple rndis pkt msgs that may be enclosed in this
* netvsc packet (ie tot_data_buf_len != message_length)
*/
/* Remove rndis header, then pass data packet up the stack */
data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
dlen -= data_offset;
if (dlen < rndis_pkt->data_length) {
if_printf(rxr->hn_ifp,
"total length %u is less than data length %u\n",
dlen, rndis_pkt->data_length);
return;
}
dlen = rndis_pkt->data_length;
data = (const uint8_t *)data + data_offset;
if (hv_rf_find_recvinfo(rndis_pkt, &info)) {
if_printf(rxr->hn_ifp, "recvinfo parsing failed\n");
return;
}
netvsc_recv(rxr, data, dlen, &info);
}
/*
* RNDIS filter on receive
*/
int
hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
const void *data, int dlen)
{
rndis_device *rndis_dev;
const rndis_msg *rndis_hdr;
const struct rndis_comp_hdr *comp;
rndis_dev = sc->rndis_dev;
if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED)
return (EINVAL);
rndis_hdr = data;
switch (rndis_hdr->ndis_msg_type) {
/* data message */
case REMOTE_NDIS_PACKET_MSG:
hv_rf_receive_data(rxr, data, dlen);
break;
/* completion messages */
case REMOTE_NDIS_INITIALIZE_CMPLT:
case REMOTE_NDIS_QUERY_CMPLT:
case REMOTE_NDIS_SET_CMPLT:
case REMOTE_NDIS_KEEPALIVE_CMPLT:
comp = data;
if (comp->rm_rid <= HN_RNDIS_RID_COMPAT_MAX) {
/* Transition time compat code */
hv_rf_receive_response(rndis_dev, rndis_hdr);
} else {
vmbus_xact_ctx_wakeup(sc->hn_xact, data, dlen);
}
break;
/* notification message */
case REMOTE_NDIS_INDICATE_STATUS_MSG:
hv_rf_receive_indicate_status(rndis_dev, rndis_hdr);
break;
case REMOTE_NDIS_RESET_CMPLT:
/*
* Reset completed, no rid.
*
* NOTE:
* RESET is not issued by hn(4), so this message should
* _not_ be observed.
*/
if_printf(sc->hn_ifp, "RESET CMPLT received\n");
break;
default:
if_printf(sc->hn_ifp, "unknown RNDIS message 0x%x\n",
rndis_hdr->ndis_msg_type);
break;
}
return (0);
}
/*
* RNDIS filter query device MAC address
*/
static int
hv_rf_query_device_mac(rndis_device *device)
{
struct hn_softc *sc = device->sc;
size_t hwaddr_len;
int error;
hwaddr_len = ETHER_ADDR_LEN;
error = hn_rndis_query(sc, OID_802_3_PERMANENT_ADDRESS, NULL, 0,
device->hw_mac_addr, &hwaddr_len);
if (error)
return (error);
if (hwaddr_len != ETHER_ADDR_LEN) {
if_printf(sc->hn_ifp, "invalid hwaddr len %zu\n", hwaddr_len);
return (EINVAL);
}
return (0);
}
/*
* RNDIS filter query device link status
*/
static inline int
hv_rf_query_device_link_status(rndis_device *device)
{
struct hn_softc *sc = device->sc;
size_t size;
int error;
size = sizeof(uint32_t);
error = hn_rndis_query(sc, OID_GEN_MEDIA_CONNECT_STATUS, NULL, 0,
&device->link_status, &size);
if (error)
return (error);
if (size != sizeof(uint32_t)) {
if_printf(sc->hn_ifp, "invalid link status len %zu\n", size);
return (EINVAL);
}
return (0);
}
static uint8_t netvsc_hash_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
};
static const void *
hn_rndis_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact, uint32_t rid,
size_t reqlen, size_t *comp_len0, uint32_t comp_type)
{
struct vmbus_gpa gpa[HN_XACT_REQ_PGCNT];
const struct rndis_comp_hdr *comp;
bus_addr_t paddr;
size_t comp_len, min_complen = *comp_len0;
int gpa_cnt, error;
KASSERT(rid > HN_RNDIS_RID_COMPAT_MAX, ("invalid rid %u\n", rid));
KASSERT(reqlen <= HN_XACT_REQ_SIZE && reqlen > 0,
("invalid request length %zu", reqlen));
KASSERT(min_complen >= sizeof(*comp),
("invalid minimum complete len %zu", min_complen));
/*
* Setup the SG list.
*/
paddr = vmbus_xact_req_paddr(xact);
KASSERT((paddr & PAGE_MASK) == 0,
("vmbus xact request is not page aligned 0x%jx", (uintmax_t)paddr));
for (gpa_cnt = 0; gpa_cnt < HN_XACT_REQ_PGCNT; ++gpa_cnt) {
int len = PAGE_SIZE;
if (reqlen == 0)
break;
if (reqlen < len)
len = reqlen;
gpa[gpa_cnt].gpa_page = atop(paddr) + gpa_cnt;
gpa[gpa_cnt].gpa_len = len;
gpa[gpa_cnt].gpa_ofs = 0;
reqlen -= len;
}
KASSERT(reqlen == 0, ("still have %zu request data left", reqlen));
/*
* Send this RNDIS control message and wait for its completion
* message.
*/
vmbus_xact_activate(xact);
error = hv_nv_on_send(sc->hn_prichan, HN_NVS_RNDIS_MTYPE_CTRL,
&hn_send_ctx_none, gpa, gpa_cnt);
if (error) {
vmbus_xact_deactivate(xact);
if_printf(sc->hn_ifp, "RNDIS ctrl send failed: %d\n", error);
return (NULL);
}
comp = vmbus_xact_wait(xact, &comp_len);
/*
* Check this RNDIS complete message.
*/
if (comp_len < min_complen) {
if (comp_len >= sizeof(*comp)) {
/* rm_status field is valid */
if_printf(sc->hn_ifp, "invalid RNDIS comp len %zu, "
"status 0x%08x\n", comp_len, comp->rm_status);
} else {
if_printf(sc->hn_ifp, "invalid RNDIS comp len %zu\n",
comp_len);
}
return (NULL);
}
if (comp->rm_len < min_complen) {
if_printf(sc->hn_ifp, "invalid RNDIS comp msglen %u\n",
comp->rm_len);
return (NULL);
}
if (comp->rm_type != comp_type) {
if_printf(sc->hn_ifp, "unexpected RNDIS comp 0x%08x, "
"expect 0x%08x\n", comp->rm_type, comp_type);
return (NULL);
}
if (comp->rm_rid != rid) {
if_printf(sc->hn_ifp, "RNDIS comp rid mismatch %u, "
"expect %u\n", comp->rm_rid, rid);
return (NULL);
}
/* All pass! */
*comp_len0 = comp_len;
return (comp);
}
static int
hn_rndis_query(struct hn_softc *sc, uint32_t oid,
const void *idata, size_t idlen, void *odata, size_t *odlen0)
{
struct rndis_query_req *req;
const struct rndis_query_comp *comp;
struct vmbus_xact *xact;
size_t reqlen, odlen = *odlen0, comp_len;
int error, ofs;
uint32_t rid;
reqlen = sizeof(*req) + idlen;
xact = vmbus_xact_get(sc->hn_xact, reqlen);
if (xact == NULL) {
if_printf(sc->hn_ifp, "no xact for RNDIS query 0x%08x\n", oid);
return (ENXIO);
}
rid = hn_rndis_rid(sc);
req = vmbus_xact_req_data(xact);
req->rm_type = REMOTE_NDIS_QUERY_MSG;
req->rm_len = reqlen;
req->rm_rid = rid;
req->rm_oid = oid;
/*
* XXX
* This is _not_ RNDIS Spec conforming:
* "This MUST be set to 0 when there is no input data
* associated with the OID."
*
* If this field was set to 0 according to the RNDIS Spec,
* Hyper-V would set non-SUCCESS status in the query
* completion.
*/
req->rm_infobufoffset = RNDIS_QUERY_REQ_INFOBUFOFFSET;
if (idlen > 0) {
req->rm_infobuflen = idlen;
/* Input data immediately follows RNDIS query. */
memcpy(req + 1, idata, idlen);
}
comp_len = sizeof(*comp) + odlen;
comp = hn_rndis_xact_execute(sc, xact, rid, reqlen, &comp_len,
REMOTE_NDIS_QUERY_CMPLT);
if (comp == NULL) {
if_printf(sc->hn_ifp, "exec RNDIS query 0x%08x failed\n", oid);
error = EIO;
goto done;
}
if (comp->rm_status != RNDIS_STATUS_SUCCESS) {
if_printf(sc->hn_ifp, "RNDIS query 0x%08x failed: "
"status 0x%08x\n", oid, comp->rm_status);
error = EIO;
goto done;
}
if (comp->rm_infobuflen == 0 || comp->rm_infobufoffset == 0) {
/* No output data! */
if_printf(sc->hn_ifp, "RNDIS query 0x%08x, no data\n", oid);
*odlen0 = 0;
error = 0;
goto done;
}
/*
* Check output data length and offset.
*/
/* ofs is the offset from the beginning of comp. */
ofs = RNDIS_QUERY_COMP_INFOBUFABS(comp->rm_infobufoffset);
if (ofs < sizeof(*comp) || ofs + comp->rm_infobuflen > comp_len) {
if_printf(sc->hn_ifp, "RNDIS query invalid comp ib off/len, "
"%u/%u\n", comp->rm_infobufoffset, comp->rm_infobuflen);
error = EINVAL;
goto done;
}
/*
* Save output data.
*/
if (comp->rm_infobuflen < odlen)
odlen = comp->rm_infobuflen;
memcpy(odata, ((const uint8_t *)comp) + ofs, odlen);
*odlen0 = odlen;
error = 0;
done:
vmbus_xact_put(xact);
return (error);
}
static int
hn_rndis_get_rsscaps(struct hn_softc *sc, int *rxr_cnt)
{
struct ndis_rss_caps in, caps;
size_t caps_len;
int error;
/*
* Only NDIS 6.30+ is supported.
*/
KASSERT(sc->hn_ndis_ver >= NDIS_VERSION_6_30,
("NDIS 6.30+ is required, NDIS version 0x%08x", sc->hn_ndis_ver));
*rxr_cnt = 0;
memset(&in, 0, sizeof(in));
in.ndis_hdr.ndis_type = NDIS_OBJTYPE_RSS_CAPS;
in.ndis_hdr.ndis_rev = NDIS_RSS_CAPS_REV_2;
in.ndis_hdr.ndis_size = NDIS_RSS_CAPS_SIZE;
caps_len = NDIS_RSS_CAPS_SIZE;
error = hn_rndis_query(sc, OID_GEN_RECEIVE_SCALE_CAPABILITIES,
&in, NDIS_RSS_CAPS_SIZE, &caps, &caps_len);
if (error)
return (error);
if (caps_len < NDIS_RSS_CAPS_SIZE_6_0) {
if_printf(sc->hn_ifp, "invalid NDIS RSS caps len %zu",
caps_len);
return (EINVAL);
}
if (caps.ndis_nrxr == 0) {
if_printf(sc->hn_ifp, "0 RX rings!?\n");
return (EINVAL);
}
*rxr_cnt = caps.ndis_nrxr;
if (caps_len == NDIS_RSS_CAPS_SIZE) {
if (bootverbose) {
if_printf(sc->hn_ifp, "RSS indirect table size %u\n",
caps.ndis_nind);
}
}
return (0);
}
static int
hn_rndis_set(struct hn_softc *sc, uint32_t oid, const void *data, size_t dlen)
{
struct rndis_set_req *req;
const struct rndis_set_comp *comp;
struct vmbus_xact *xact;
size_t reqlen, comp_len;
uint32_t rid;
int error;
KASSERT(dlen > 0, ("invalid dlen %zu", dlen));
reqlen = sizeof(*req) + dlen;
xact = vmbus_xact_get(sc->hn_xact, reqlen);
if (xact == NULL) {
if_printf(sc->hn_ifp, "no xact for RNDIS set 0x%08x\n", oid);
return (ENXIO);
}
rid = hn_rndis_rid(sc);
req = vmbus_xact_req_data(xact);
req->rm_type = REMOTE_NDIS_SET_MSG;
req->rm_len = reqlen;
req->rm_rid = rid;
req->rm_oid = oid;
req->rm_infobuflen = dlen;
req->rm_infobufoffset = RNDIS_SET_REQ_INFOBUFOFFSET;
/* Data immediately follows RNDIS set. */
memcpy(req + 1, data, dlen);
comp_len = sizeof(*comp);
comp = hn_rndis_xact_execute(sc, xact, rid, reqlen, &comp_len,
REMOTE_NDIS_SET_CMPLT);
if (comp == NULL) {
if_printf(sc->hn_ifp, "exec RNDIS set 0x%08x failed\n", oid);
error = EIO;
goto done;
}
if (comp->rm_status != RNDIS_STATUS_SUCCESS) {
if_printf(sc->hn_ifp, "RNDIS set 0x%08x failed: "
"status 0x%08x\n", oid, comp->rm_status);
error = EIO;
goto done;
}
error = 0;
done:
vmbus_xact_put(xact);
return (error);
}
static int
hn_rndis_conf_offload(struct hn_softc *sc)
{
struct ndis_offload_params params;
size_t paramsz;
int error;
/* NOTE: 0 means "no change" */
memset(¶ms, 0, sizeof(params));
params.ndis_hdr.ndis_type = NDIS_OBJTYPE_DEFAULT;
if (sc->hn_ndis_ver < NDIS_VERSION_6_30) {
params.ndis_hdr.ndis_rev = NDIS_OFFLOAD_PARAMS_REV_2;
paramsz = NDIS_OFFLOAD_PARAMS_SIZE_6_1;
} else {
params.ndis_hdr.ndis_rev = NDIS_OFFLOAD_PARAMS_REV_3;
paramsz = NDIS_OFFLOAD_PARAMS_SIZE;
}
params.ndis_hdr.ndis_size = paramsz;
params.ndis_ip4csum = NDIS_OFFLOAD_PARAM_TXRX;
params.ndis_tcp4csum = NDIS_OFFLOAD_PARAM_TXRX;
params.ndis_tcp6csum = NDIS_OFFLOAD_PARAM_TXRX;
if (sc->hn_ndis_ver >= NDIS_VERSION_6_30) {
params.ndis_udp4csum = NDIS_OFFLOAD_PARAM_TXRX;
params.ndis_udp6csum = NDIS_OFFLOAD_PARAM_TXRX;
}
params.ndis_lsov2_ip4 = NDIS_OFFLOAD_LSOV2_ON;
/* XXX ndis_lsov2_ip6 = NDIS_OFFLOAD_LSOV2_ON */
error = hn_rndis_set(sc, OID_TCP_OFFLOAD_PARAMETERS, ¶ms, paramsz);
if (error) {
if_printf(sc->hn_ifp, "offload config failed: %d\n", error);
} else {
if (bootverbose)
if_printf(sc->hn_ifp, "offload config done\n");
}
return (error);
}
static int
hn_rndis_conf_rss(struct hn_softc *sc, int nchan)
{
struct ndis_rssprm_toeplitz *rss = &sc->hn_rss;
struct ndis_rss_params *prm = &rss->rss_params;
int i, error;
/*
* Only NDIS 6.30+ is supported.
*/
KASSERT(sc->hn_ndis_ver >= NDIS_VERSION_6_30,
("NDIS 6.30+ is required, NDIS version 0x%08x", sc->hn_ndis_ver));
memset(rss, 0, sizeof(*rss));
prm->ndis_hdr.ndis_type = NDIS_OBJTYPE_RSS_PARAMS;
prm->ndis_hdr.ndis_rev = NDIS_RSS_PARAMS_REV_2;
prm->ndis_hdr.ndis_size = sizeof(*rss);
prm->ndis_hash = NDIS_HASH_FUNCTION_TOEPLITZ |
NDIS_HASH_IPV4 | NDIS_HASH_TCP_IPV4 |
NDIS_HASH_IPV6 | NDIS_HASH_TCP_IPV6;
/* TODO: Take ndis_rss_caps.ndis_nind into account */
prm->ndis_indsize = sizeof(rss->rss_ind);
prm->ndis_indoffset =
__offsetof(struct ndis_rssprm_toeplitz, rss_ind[0]);
prm->ndis_keysize = sizeof(rss->rss_key);
prm->ndis_keyoffset =
__offsetof(struct ndis_rssprm_toeplitz, rss_key[0]);
/* Setup RSS key */
memcpy(rss->rss_key, netvsc_hash_key, sizeof(rss->rss_key));
/* Setup RSS indirect table */
/* TODO: Take ndis_rss_caps.ndis_nind into account */
for (i = 0; i < NDIS_HASH_INDCNT; ++i)
rss->rss_ind[i] = i % nchan;
error = hn_rndis_set(sc, OID_GEN_RECEIVE_SCALE_PARAMETERS,
rss, sizeof(*rss));
if (error) {
if_printf(sc->hn_ifp, "RSS config failed: %d\n", error);
} else {
if (bootverbose)
if_printf(sc->hn_ifp, "RSS config done\n");
}
return (error);
}
static int
hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter)
{
int error;
error = hn_rndis_set(sc, OID_GEN_CURRENT_PACKET_FILTER,
&filter, sizeof(filter));
if (error) {
if_printf(sc->hn_ifp, "set RX filter 0x%08x failed: %d\n",
filter, error);
} else {
if (bootverbose) {
if_printf(sc->hn_ifp, "set RX filter 0x%08x done\n",
filter);
}
}
return (error);
}
/*
* RNDIS filter init device
*/
static int
hv_rf_init_device(rndis_device *device)
{
struct hn_softc *sc = device->sc;
struct rndis_init_req *req;
const struct rndis_init_comp *comp;
struct vmbus_xact *xact;
size_t comp_len;
uint32_t rid;
int error;
/* XXX */
device->state = RNDIS_DEV_INITIALIZED;
xact = vmbus_xact_get(sc->hn_xact, sizeof(*req));
if (xact == NULL) {
if_printf(sc->hn_ifp, "no xact for RNDIS init\n");
return (ENXIO);
}
rid = hn_rndis_rid(sc);
req = vmbus_xact_req_data(xact);
req->rm_type = REMOTE_NDIS_INITIALIZE_MSG;
req->rm_len = sizeof(*req);
req->rm_rid = rid;
req->rm_ver_major = RNDIS_VERSION_MAJOR;
req->rm_ver_minor = RNDIS_VERSION_MINOR;
req->rm_max_xfersz = HN_RNDIS_XFER_SIZE;
comp_len = RNDIS_INIT_COMP_SIZE_MIN;
comp = hn_rndis_xact_execute(sc, xact, rid, sizeof(*req), &comp_len,
REMOTE_NDIS_INITIALIZE_CMPLT);
if (comp == NULL) {
if_printf(sc->hn_ifp, "exec RNDIS init failed\n");
error = EIO;
goto done;
}
if (comp->rm_status != RNDIS_STATUS_SUCCESS) {
if_printf(sc->hn_ifp, "RNDIS init failed: status 0x%08x\n",
comp->rm_status);
error = EIO;
goto done;
}
if (bootverbose) {
if_printf(sc->hn_ifp, "RNDIS ver %u.%u, pktsz %u, pktcnt %u\n",
comp->rm_ver_major, comp->rm_ver_minor,
comp->rm_pktmaxsz, comp->rm_pktmaxcnt);
}
error = 0;
done:
if (xact != NULL)
vmbus_xact_put(xact);
return (error);
}
#define HALT_COMPLETION_WAIT_COUNT 25
/*
* RNDIS filter halt device
*/
static int
hv_rf_halt_device(rndis_device *device)
{
rndis_request *request;
int i, ret;
/* Attempt to do a rndis device halt */
request = hv_rndis_request(device, REMOTE_NDIS_HALT_MSG,
RNDIS_MESSAGE_SIZE(rndis_halt_request));
if (request == NULL) {
return (-1);
}
/* initialize "poor man's semaphore" */
request->halt_complete_flag = 0;
ret = hv_rf_send_request(device, request, REMOTE_NDIS_HALT_MSG);
if (ret != 0) {
return (-1);
}
/*
* Wait for halt response from halt callback. We must wait for
* the transaction response before freeing the request and other
* resources.
*/
for (i=HALT_COMPLETION_WAIT_COUNT; i > 0; i--) {
if (request->halt_complete_flag != 0) {
break;
}
DELAY(400);
}
if (i == 0) {
return (-1);
}
device->state = RNDIS_DEV_UNINITIALIZED;
hv_put_rndis_request(device, request);
return (0);
}
/*
* RNDIS filter on device add
*/
int
hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
int *nchan0, struct hn_rx_ring *rxr)
{
int ret;
rndis_device *rndis_dev;
netvsc_device_info *dev_info = (netvsc_device_info *)additl_info;
device_t dev = sc->hn_dev;
struct hn_nvs_subch_req *req;
const struct hn_nvs_subch_resp *resp;
size_t resp_len;
struct vmbus_xact *xact = NULL;
uint32_t status, nsubch;
int nchan = *nchan0;
int rxr_cnt;
rndis_dev = hv_get_rndis_device();
if (rndis_dev == NULL) {
return (ENOMEM);
}
sc->rndis_dev = rndis_dev;
rndis_dev->sc = sc;
/*
* Let the inner driver handle this first to create the netvsc channel
* NOTE! Once the channel is created, we may get a receive callback
* (hv_rf_on_receive()) before this call is completed.
* Note: Earlier code used a function pointer here.
*/
ret = hv_nv_on_device_add(sc, rxr);
if (ret != 0) {
hv_put_rndis_device(rndis_dev);
return (ret);
}
/*
* Initialize the rndis device
*/
/* Send the rndis initialization message */
ret = hv_rf_init_device(rndis_dev);
if (ret != 0) {
/*
* TODO: If rndis init failed, we will need to shut down
* the channel
*/
}
/* Get the mac address */
ret = hv_rf_query_device_mac(rndis_dev);
if (ret != 0) {
/* TODO: shut down rndis device and the channel */
}
/* Configure NDIS offload settings */
hn_rndis_conf_offload(sc);
memcpy(dev_info->mac_addr, rndis_dev->hw_mac_addr, ETHER_ADDR_LEN);
hv_rf_query_device_link_status(rndis_dev);
dev_info->link_state = rndis_dev->link_status;
if (sc->hn_ndis_ver < NDIS_VERSION_6_30 || nchan == 1) {
/*
* Either RSS is not supported, or multiple RX/TX rings
* are not requested.
*/
*nchan0 = 1;
return (0);
}
/*
* Get RSS capabilities, e.g. # of RX rings, and # of indirect
* table entries.
*/
ret = hn_rndis_get_rsscaps(sc, &rxr_cnt);
if (ret) {
/* No RSS; this is benign. */
*nchan0 = 1;
return (0);
}
if (nchan > rxr_cnt)
nchan = rxr_cnt;
if_printf(sc->hn_ifp, "RX rings offered %u, requested %d\n",
rxr_cnt, nchan);
if (nchan == 1) {
device_printf(dev, "only 1 channel is supported, no vRSS\n");
goto out;
}
/*
* Ask NVS to allocate sub-channels.
*/
xact = vmbus_xact_get(sc->hn_xact, sizeof(*req));
if (xact == NULL) {
if_printf(sc->hn_ifp, "no xact for nvs subch req\n");
ret = ENXIO;
goto out;
}
req = vmbus_xact_req_data(xact);
req->nvs_type = HN_NVS_TYPE_SUBCH_REQ;
req->nvs_op = HN_NVS_SUBCH_OP_ALLOC;
req->nvs_nsubch = nchan - 1;
resp = hn_nvs_xact_execute(sc, xact, req, sizeof(*req), &resp_len);
if (resp == NULL) {
if_printf(sc->hn_ifp, "exec subch failed\n");
ret = EIO;
goto out;
}
if (resp_len < sizeof(*resp)) {
if_printf(sc->hn_ifp, "invalid subch resp length %zu\n",
resp_len);
ret = EINVAL;
goto out;
}
if (resp->nvs_type != HN_NVS_TYPE_SUBCH_RESP) {
if_printf(sc->hn_ifp, "not subch resp, type %u\n",
resp->nvs_type);
ret = EINVAL;
goto out;
}
status = resp->nvs_status;
nsubch = resp->nvs_nsubch;
vmbus_xact_put(xact);
xact = NULL;
if (status != HN_NVS_STATUS_OK) {
if_printf(sc->hn_ifp, "subch req failed: %x\n", status);
ret = EIO;
goto out;
}
if (nsubch > nchan - 1) {
if_printf(sc->hn_ifp, "%u subchans are allocated, requested %u\n",
nsubch, nchan - 1);
nsubch = nchan - 1;
}
nchan = nsubch + 1;
ret = hn_rndis_conf_rss(sc, nchan);
if (ret != 0)
*nchan0 = 1;
else
*nchan0 = nchan;
out:
if (xact != NULL)
vmbus_xact_put(xact);
return (ret);
}
/*
* RNDIS filter on device remove
*/
int
hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
{
rndis_device *rndis_dev = sc->rndis_dev;
int ret;
/* Halt and release the rndis device */
ret = hv_rf_halt_device(rndis_dev);
sc->rndis_dev = NULL;
hv_put_rndis_device(rndis_dev);
/* Pass control to inner driver to remove the device */
ret |= hv_nv_on_device_remove(sc, destroy_channel);
return (ret);
}
/*
* RNDIS filter on open
*/
int
hv_rf_on_open(struct hn_softc *sc)
{
uint32_t filter;
/* XXX */
if (hv_promisc_mode != 1) {
filter = NDIS_PACKET_TYPE_BROADCAST |
NDIS_PACKET_TYPE_ALL_MULTICAST |
NDIS_PACKET_TYPE_DIRECTED;
} else {
filter = NDIS_PACKET_TYPE_PROMISCUOUS;
}
return (hn_rndis_set_rxfilter(sc, filter));
}
/*
* RNDIS filter on close
*/
int
hv_rf_on_close(struct hn_softc *sc)
{
return (hn_rndis_set_rxfilter(sc, 0));
}
static void
hn_rndis_sent_cb(struct hn_send_ctx *sndc, struct hn_softc *sc,
struct vmbus_channel *chan __unused, const void *data __unused,
int dlen __unused)
{
if (sndc->hn_chim_idx != HN_NVS_CHIM_IDX_INVALID)
hn_chim_free(sc, sndc->hn_chim_idx);
}
static void
hn_rndis_sent_halt(struct hn_send_ctx *sndc, struct hn_softc *sc,
struct vmbus_channel *chan __unused, const void *data __unused,
int dlen __unused)
{
rndis_request *request = sndc->hn_cbarg;
if (sndc->hn_chim_idx != HN_NVS_CHIM_IDX_INVALID)
hn_chim_free(sc, sndc->hn_chim_idx);
/*
* Notify hv_rf_halt_device() about halt completion.
* The halt code must wait for completion before freeing
* the transaction resources.
*/
request->halt_complete_flag = 1;
}
void
hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr)
{
netvsc_channel_rollup(rxr, txr);
}
|