-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmbus_rdma.h
2176 lines (1744 loc) · 48.2 KB
/
vmbus_rdma.h
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
/*
* Copyright (c) 2014, Microsoft Corporation.
*
* Author:
* K. Y. Srinivasan <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
* NON INFRINGEMENT. See the GNU General Public License for more
* details.
*
* Bug fixes/enhancements: Long Li <[email protected]>
*/
#ifndef _VMBUS_RDMA_H
#define _VMBUS_RDMA_H
#include <linux/in.h>
#include <linux/in6.h>
#include <rdma/ib_verbs.h>
#include <linux/idr.h>
/* NetworkDirect version Numbers.
*/
#define ND_VERSION_1 0x1
#define ND_VERSION_2 0x20000
#ifndef NDVER
#define NDVER ND_VERSION_2
#endif
#define ND_ADAPTER_FLAG_IN_ORDER_DMA_SUPPORTED 0x00000001
#define ND_ADAPTER_FLAG_CQ_INTERRUPT_MODERATION_SUPPORTED 0x00000004
#define ND_ADAPTER_FLAG_MULTI_ENGINE_SUPPORTED 0x00000008
#define ND_ADAPTER_FLAG_CQ_RESIZE_SUPPORTED 0x00000100
#define ND_ADAPTER_FLAG_LOOPBACK_CONNECTIONS_SUPPORTED 0x00010000
#define ND_CQ_NOTIFY_ERRORS 0
#define ND_CQ_NOTIFY_ANY 1
#define ND_CQ_NOTIFY_SOLICITED 2
#define ND_MR_FLAG_ALLOW_LOCAL_WRITE 0x00000001
#define ND_MR_FLAG_ALLOW_REMOTE_READ 0x00000002
#define ND_MR_FLAG_ALLOW_REMOTE_WRITE 0x00000005
#define ND_MR_FLAG_RDMA_READ_SINK 0x00000008
#define ND_MR_FLAG_DO_NOT_SECURE_VM 0x80000000
#define ND_OP_FLAG_SILENT_SUCCESS 0x00000001
#define ND_OP_FLAG_READ_FENCE 0x00000002
#define ND_OP_FLAG_SEND_AND_SOLICIT_EVENT 0x00000004
#define ND_OP_FLAG_ALLOW_READ 0x00000008
#define ND_OP_FLAG_ALLOW_WRITE 0x00000010
#if NDVER >= ND_VERSION_2
#define ND_OP_FLAG_INLINE 0x00000020
#endif
#define ND_AF_INET6 23
#define IF_MAX_ADDR_LENGTH 32
struct group_affinity {
u64 mask; //KYS: usually 0
u16 group; // KYS usually -1
u16 reserved[3];
};
struct if_physical_addr {
u16 length;
u8 addr[IF_MAX_ADDR_LENGTH];
};
struct adapter_info_v2 {
u32 info_version;
u16 vendor_id;
u16 device_id;
u64 adapter_id;
size_t max_registration_size;
size_t max_window_size;
u32 max_initiator_sge;
u32 max_recv_sge;
u32 max_read_sge;
u32 max_transfer_length;
u32 max_inline_data_size;
u32 max_inbound_read_limit;
u32 max_outbound_read_limit;
u32 max_recv_q_depth;
u32 max_initiator_q_depth;
u32 max_shared_recv_q_depth;
u32 max_completion_q_depth;
u32 inline_request_threshold;
u32 large_request_threshold;
u32 max_caller_data;
u32 max_callee_data;
u32 adapter_flags;
} __packed;
struct nd2_adapter_info_32 { //KYS: Check what this is
u32 info_version;
u16 vendor_id;
u16 devic_id;
u64 adapter_id;
u32 max_registration_size;
u32 max_window_size;
u32 max_initiator_sge;
u32 max_recv_sge;
u32 max_read_sge;
u32 max_transfer_length;
u32 max_inline_data_size;
u32 max_inbound_read_limit;
u32 max_outbound_read_limit;
u32 max_recv_q_depth;
u32 max_initiator_q_depth;
u32 max_shared_recv_q_depth;
u32 max_completion_q_depth;
u32 inline_request_threshold;
u32 large_request_threshold;
u32 max_caller_data;
u32 max_callee_data;
u32 adapter_flags;
} __packed;
enum nd2_request_type {
ND2_RT_RECEIVE,
ND2_RT_SEND,
ND2_RT_BIND,
ND2_RT_INVALIDATE,
ND2_RT_READ,
ND2_RT_WRITE
};
struct nd2_result {
u32 status;
u32 bytes_transferred;
void *qp_ctx;
void *request_ctx;
enum nd2_request_type request_type;
} __packed;
struct nd2_sge {
void *buffer;
u32 buffer_length;
u32 mr_token;
} __packed;
/*
* The communication with the host via ioctls using VMBUS
* as the transport.
*/
#define ND_IOCTL_VERSION 1
enum nd_mapping_type {
ND_MAP_IOSPACE,
ND_MAP_MEMORY,
ND_MAP_MEMORY_COALLESCE,
ND_MAP_PAGES,
ND_MAP_PAGES_COALLESCE,
ND_UNMAP_IOSPACE,
ND_UNMAP_MEMORY,
ND_MAX_MAP_TYPE
};
enum nd_caching_type {
ND_NON_CACHED = 0,
ND_CACHED,
ND_WRITE_COMBINED,
ND_MAX_CACHE_TYPE
};
enum nd_aceess_type {
ND_READ_ACCESS = 0,
ND_WRITE_ACCESS,
ND_MODIFY_ACCESS
};
struct nd_map_io_space {
enum nd_mapping_type map_type;
enum nd_caching_type cache_type;
u32 cb_length;
};
struct nd_map_memory {
enum nd_mapping_type map_type;
enum nd_aceess_type access_type;
u64 address;
u32 cb_length;
};
struct nd_mapping_id {
enum nd_mapping_type map_type;
u64 id;
};
struct ndk_map_pages {
struct nd_map_memory header;
u32 page_offset;
};
union nd_mapping {
enum nd_mapping_type map_type;
struct nd_map_io_space map_io_space;
struct nd_map_memory map_memory;
struct nd_mapping_id mapping_id;
struct ndk_map_pages map_pages;
};
struct nd_mapping_result {
u64 id;
u64 info;
};
struct nd_resource_descriptor {
u64 handle;
u32 ce_mapping_results;
u32 cb_mapping_results_offset;
};
struct nd_handle {
u32 version;
u32 reserved;
u64 handle;
};
union nd_sockaddr_inet {
struct sockaddr_in ipv4;
struct sockaddr_in6 ipv6;
u16 address_family; //KYS how is this supposed to work?
};
struct nd_address_element {
union nd_sockaddr_inet addr;
char mac_addr[ETH_ALEN];
};
struct nd_resolve_address {
u32 version;
u32 reserved;
union nd_sockaddr_inet address;
};
struct nd_open_adapter {
u32 version;
u32 reserved;
u32 ce_mapping_cnt;
u32 cb_mapping_offset;
u64 adapter_id;
};
struct nd_adapter_query {
u32 version;
u32 info_version;
u64 adapter_handle;
};
struct nd_create_cq {
u32 version;
u32 queue_depth;
u32 ce_mapping_cnt;
u32 cb_mapping_offset;
u64 adapter_handle;
struct group_affinity affinity;
};
struct nd_create_srq {
u32 version;
u32 queue_depth;
u32 ce_mapping_cnt;
u32 cb_mapping_offset;
u32 max_request_sge;
u32 notify_threshold;
u64 pd_handle;
struct group_affinity affinity;
};
struct nd_create_qp_hdr {
u32 version;
u32 cb_max_inline_data;
u32 ce_mapping_cnt;
u32 cb_mapping_offset; //KYS: what is this prefix - ce/cb
u32 initiator_queue_depth;
u32 max_initiator_request_sge;
u64 receive_cq_handle;
u64 initiator_cq_handle;
u64 pd_handle;
};
struct nd_create_qp {
struct nd_create_qp_hdr hdr;
u32 receive_queue_depth;
u32 max_receive_request_sge;
};
struct nd_create_qp_with_srq {
struct nd_create_qp_hdr header;
u64 srq_handle;
};
struct nd_srq_modify {
u32 version;
u32 queue_depth;
u32 ce_mapping_cnt;
u32 cb_mapping_offset;
u32 notify_threshold;
u32 reserved;
u64 srq_handle;
};
struct nd_cq_modify {
u32 version;
u32 queue_depth;
u32 ce_mapping_count;
u32 cb_mappings_offset;
u64 cq_handle;
};
struct nd_cq_notify {
u32 version;
u32 type;
u64 cq_handle;
};
struct nd_mr_register_hdr {
u32 version;
u32 flags;
u64 cb_length;
u64 target_addr;
u64 mr_handle;
};
struct nd_mr_register {
struct nd_mr_register_hdr header;
u64 address;
};
struct nd_bind {
u32 version;
u32 reserved;
u64 handle;
union nd_sockaddr_inet address;
};
struct nd_read_limits {
u32 inbound;
u32 outbound;
};
struct nd_connect {
u32 version;
u32 reserved;
struct nd_read_limits read_limits;
u32 cb_private_data_length;
u32 cb_private_data_offset;
u64 connector_handle;
u64 qp_handle;
union nd_sockaddr_inet destination_address;
struct if_physical_addr phys_addr;
};
struct nd_accept {
u32 version;
u32 reserved;
struct nd_read_limits read_limits;
u32 cb_private_data_length;
u32 cb_private_data_offset;
u64 connector_handle;
u64 qp_handle;
};
struct nd_reject {
u32 version;
u32 reserved;
u32 cb_private_data_length;
u32 cb_private_data_offset;
u64 connector_handle;
};
struct nd_listen {
u32 version;
u32 back_log;
u64 listener_handle;
};
struct nd_get_connection_request {
u32 version;
u32 reserved;
u64 listener_handle;
u64 connector_handle;
};
enum ndv_mmio_type {
ND_PARTITION_KERNEL_VIRTUAL,
ND_PARTITION_SYSTEM_PHYSICAL,
ND_PARTITION_GUEST_PHYSICAL,
ND_MAXIMUM_MMIO_TYPE
};
struct ndv_resolve_adapter_id {
u32 version;
struct if_physical_addr phys_addr;
};
struct ndv_partition_create {
u32 version;
enum ndv_mmio_type mmio_type;
u64 adapter_id;
u64 xmit_cap;
};
struct ndv_partition_bind_luid {
u32 version;
u32 reserved;
u64 partition_handle;
struct if_physical_addr phys_addr;
//IF_LUID luid; //KYS?
};
struct ndv_partition_bind_address {
u32 version;
u32 reserved;
u64 partition_handle;
union nd_sockaddr_inet address;
struct if_physical_addr guest_phys_addr;
struct if_physical_addr phys_addr;
};
struct ndk_mr_register {
struct nd_mr_register_hdr hdr;
u32 cb_logical_page_addresses_offset;
};
struct ndk_bind {
struct nd_bind hdr;
u64 authentication_id;
bool is_admin;
};
#define FDN 0x12
#define METHOD_BUFFERED 0x0
#define FAA 0x0
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
#define ND_FUNCTION(r_, i_) ((r_) << 6 | (i_))
#define IOCTL_ND(r_, i_) \
CTL_CODE( FDN, ND_FUNCTION((r_), (i_)), METHOD_BUFFERED, FAA )
#define ND_FUNCTION_FROM_CTL_CODE(ctrlCode_) ((ctrlCode_ >> 2) & 0xFFF)
#define ND_RESOURCE_FROM_CTL_CODE(ctrlCode_) (ND_FUNCTION_FROM_CTL_CODE(ctrlCode_) >> 6)
#define ND_OPERATION_FROM_CTRL_CODE(ctrlCode_) (ND_FUNCTION_FROM_CTL_CODE(ctrlCode_) & 0x3F)
#define ND_DOS_DEVICE_NAME L"\\DosDevices\\Global\\NetworkDirect"
#define ND_WIN32_DEVICE_NAME L"\\\\.\\NetworkDirect"
enum nd_resource_type {
ND_PROVIDER = 0,
ND_ADAPTER,
ND_PD,
ND_CQ,
ND_MR,
ND_MW,
ND_SRQ,
ND_CONNECTOR,
ND_LISTENER,
ND_QP,
ND_VIRTUAL_PARTITION,
ND_RESOURCE_TYPE_COUNT
};
#define ND_OPERATION_COUNT 14
#define IOCTL_ND_PROVIDER(i_) IOCTL_ND(ND_PROVIDER, i_)
#define IOCTL_ND_ADAPTER(i_) IOCTL_ND(ND_ADAPTER, i_)
#define IOCTL_ND_PD(i_) IOCTL_ND(ND_PD, i_)
#define IOCTL_ND_CQ(i_) IOCTL_ND(ND_CQ, i_)
#define IOCTL_ND_MR(i_) IOCTL_ND(ND_MR, i_)
#define IOCTL_ND_MW(i_) IOCTL_ND(ND_MW, i_)
#define IOCTL_ND_SRQ(i_) IOCTL_ND(ND_SRQ, i_)
#define IOCTL_ND_CONNECTOR(i_) IOCTL_ND(ND_CONNECTOR, i_)
#define IOCTL_ND_LISTENER(i_) IOCTL_ND(ND_LISTENER, i_)
#define IOCTL_ND_QP(i_) IOCTL_ND(ND_QP, i_)
#define IOCTL_ND_VIRTUAL_PARTITION(i_) IOCTL_ND(ND_VIRTUAL_PARTITION, i_)
/* Provider IOCTLs */
#define IOCTL_ND_PROVIDER_INIT IOCTL_ND_PROVIDER( 0 )
#define IOCTL_ND_PROVIDER_BIND_FILE IOCTL_ND_PROVIDER( 1 )
#define IOCTL_ND_PROVIDER_QUERY_ADDRESS_LIST IOCTL_ND_PROVIDER( 2 )
#define IOCTL_ND_PROVIDER_RESOLVE_ADDRESS IOCTL_ND_PROVIDER( 3 )
#define IOCTL_ND_PROVIDER_MAX_OPERATION 4
/* Adapter IOCTLs */
#define IOCTL_ND_ADAPTER_OPEN IOCTL_ND_ADAPTER( 0 )
#define IOCTL_ND_ADAPTER_CLOSE IOCTL_ND_ADAPTER( 1 )
#define IOCTL_ND_ADAPTER_QUERY IOCTL_ND_ADAPTER( 2 )
#define IOCTL_ND_ADAPTER_QUERY_ADDRESS_LIST IOCTL_ND_ADAPTER( 3 )
#define IOCTL_ND_ADAPTER_MAX_OPERATION 4
/* Protection Domain IOCTLs */
#define IOCTL_ND_PD_CREATE IOCTL_ND_PD( 0 )
#define IOCTL_ND_PD_FREE IOCTL_ND_PD( 1 )
#define IOCTL_ND_PD_MAX_OPERATION 2
/* Completion Queue IOCTLs */
#define IOCTL_ND_CQ_CREATE IOCTL_ND_CQ( 0 )
#define IOCTL_ND_CQ_FREE IOCTL_ND_CQ( 1 )
#define IOCTL_ND_CQ_CANCEL_IO IOCTL_ND_CQ( 2 )
#define IOCTL_ND_CQ_GET_AFFINITY IOCTL_ND_CQ( 3 )
#define IOCTL_ND_CQ_MODIFY IOCTL_ND_CQ( 4 )
#define IOCTL_ND_CQ_NOTIFY IOCTL_ND_CQ( 5 )
#define IOCTL_ND_CQ_MAX_OPERATION 6
/* Memory Region IOCTLs */
#define IOCTL_ND_MR_CREATE IOCTL_ND_MR( 0 )
#define IOCTL_ND_MR_FREE IOCTL_ND_MR( 1 )
#define IOCTL_ND_MR_CANCEL_IO IOCTL_ND_MR( 2 )
#define IOCTL_ND_MR_REGISTER IOCTL_ND_MR( 3 )
#define IOCTL_ND_MR_DEREGISTER IOCTL_ND_MR( 4 )
#define IOCTL_NDK_MR_REGISTER IOCTL_ND_MR( 5 )
#define IOCTL_ND_MR_MAX_OPERATION 6
/* Memory Window IOCTLs */
#define IOCTL_ND_MW_CREATE IOCTL_ND_MW( 0 )
#define IOCTL_ND_MW_FREE IOCTL_ND_MW( 1 )
#define IOCTL_ND_MW_MAX_OPERATION 2
/* Shared Receive Queue IOCTLs */
#define IOCTL_ND_SRQ_CREATE IOCTL_ND_SRQ( 0 )
#define IOCTL_ND_SRQ_FREE IOCTL_ND_SRQ( 1 )
#define IOCTL_ND_SRQ_CANCEL_IO IOCTL_ND_SRQ( 2 )
#define IOCTL_ND_SRQ_GET_AFFINITY IOCTL_ND_SRQ( 3 )
#define IOCTL_ND_SRQ_MODIFY IOCTL_ND_SRQ( 4 )
#define IOCTL_ND_SRQ_NOTIFY IOCTL_ND_SRQ( 5 )
#define IOCTL_ND_SRQ_MAX_OPERATION 6
/* Connector IOCTLs */
#define IOCTL_ND_CONNECTOR_CREATE IOCTL_ND_CONNECTOR( 0 )
#define IOCTL_ND_CONNECTOR_FREE IOCTL_ND_CONNECTOR( 1 )
#define IOCTL_ND_CONNECTOR_CANCEL_IO IOCTL_ND_CONNECTOR( 2 )
#define IOCTL_ND_CONNECTOR_BIND IOCTL_ND_CONNECTOR( 3 )
#define IOCTL_ND_CONNECTOR_CONNECT IOCTL_ND_CONNECTOR( 4 )
#define IOCTL_ND_CONNECTOR_COMPLETE_CONNECT IOCTL_ND_CONNECTOR( 5 )
#define IOCTL_ND_CONNECTOR_ACCEPT IOCTL_ND_CONNECTOR( 6 )
#define IOCTL_ND_CONNECTOR_REJECT IOCTL_ND_CONNECTOR( 7 )
#define IOCTL_ND_CONNECTOR_GET_READ_LIMITS IOCTL_ND_CONNECTOR( 8 )
#define IOCTL_ND_CONNECTOR_GET_PRIVATE_DATA IOCTL_ND_CONNECTOR( 9 )
#define IOCTL_ND_CONNECTOR_GET_PEER_ADDRESS IOCTL_ND_CONNECTOR( 10 )
#define IOCTL_ND_CONNECTOR_GET_ADDRESS IOCTL_ND_CONNECTOR( 11 )
#define IOCTL_ND_CONNECTOR_NOTIFY_DISCONNECT IOCTL_ND_CONNECTOR( 12 )
#define IOCTL_ND_CONNECTOR_DISCONNECT IOCTL_ND_CONNECTOR( 13 )
#define IOCTL_ND_CONNECTOR_MAX_OPERATION 14
/* Listener IOCTLs */
#define IOCTL_ND_LISTENER_CREATE IOCTL_ND_LISTENER( 0 )
#define IOCTL_ND_LISTENER_FREE IOCTL_ND_LISTENER( 1 )
#define IOCTL_ND_LISTENER_CANCEL_IO IOCTL_ND_LISTENER( 2 )
#define IOCTL_ND_LISTENER_BIND IOCTL_ND_LISTENER( 3 )
#define IOCTL_ND_LISTENER_LISTEN IOCTL_ND_LISTENER( 4 )
#define IOCTL_ND_LISTENER_GET_ADDRESS IOCTL_ND_LISTENER( 5 )
#define IOCTL_ND_LISTENER_GET_CONNECTION_REQUEST IOCTL_ND_LISTENER( 6 )
#define IOCTL_ND_LISTENER_MAX_OPERATION 7
/* Queue Pair IOCTLs */
#define IOCTL_ND_QP_CREATE IOCTL_ND_QP( 0 )
#define IOCTL_ND_QP_CREATE_WITH_SRQ IOCTL_ND_QP( 1 )
#define IOCTL_ND_QP_FREE IOCTL_ND_QP( 2 )
#define IOCTL_ND_QP_FLUSH IOCTL_ND_QP( 3 )
#define IOCTL_ND_QP_MAX_OPERATION 4
/* Kernel-mode only IOCTLs (IRP_MJ_INTERNAL_DEVICE_CONTROL) */
#define IOCTL_NDV_PARTITION_RESOLVE_ADAPTER_ID IOCTL_ND_VIRTUAL_PARTITION( 0 )
#define IOCTL_NDV_PARTITION_CREATE IOCTL_ND_VIRTUAL_PARTITION( 1 )
#define IOCTL_NDV_PARTITION_FREE IOCTL_ND_VIRTUAL_PARTITION( 2 )
#define IOCTL_NDV_PARTITION_BIND IOCTL_ND_VIRTUAL_PARTITION( 3 )
#define IOCTL_NDV_PARTITION_UNBIND IOCTL_ND_VIRTUAL_PARTITION( 4 )
#define IOCTL_NDV_PARTITION_BIND_LUID IOCTL_ND_VIRTUAL_PARTITION( 5 )
#define IOCTL_NDV_PARTITION_MAX_OPERATION 6
#define MB_SHIFT 20
/* Ringbuffer size for the channel */
#define NDV_NUM_PAGES_IN_RING_BUFFER 64
#define NDV_MAX_PACKETS_PER_RECEIVE 8
#define NDV_MAX_PACKET_COUNT 16304
#define NDV_MAX_NUM_OUTSTANDING_RECEIVED_PACKETS (16304)
#define NDV_MAX_HANDLE_TABLE_SIZE (16304)
#define NDV_HOST_MAX_HANDLE_TABLE_SIZE (NDV_MAX_HANDLE_TABLE_SIZE * 16)
#define NDV_MAX_MAPPINGS 4
#define NDV_STATE_NONE 0x00000000
#define NDV_STATE_CREATED 0x00000001
#define NDV_STATE_CONNECTING 0x00000002
#define NDV_STATE_INITIALIZING 0x00000003
#define NDV_STATE_OPERATIONAL 0xEFFFFFFF
#define NDV_STATE_FAILED 0xFFFFFFFF
#define NDV_MAX_PRIVATE_DATA_SIZE 64
#define NDV_MAX_IOCTL_SIZE 256
/* max size of buffer for vector of ND_MAPPING */
#define NDV_MAX_MAPPING_BUFFER_SIZE \
(NDV_MAX_MAPPINGS * sizeof(union nd_mapping))
/* max expected ioctl buffer size from users */
#define NDV_MAX_IOCTL_BUFFER_SIZE \
(NDV_MAX_IOCTL_SIZE + \
NDV_MAX_MAPPING_BUFFER_SIZE + \
NDV_MAX_PRIVATE_DATA_SIZE)
/* max PFN array for inline buffers */
#define NDV_MAX_INLINE_PFN_ARRAY_LENGTH 32
/* Field header size for inline buffer */
#define NDV_MAX_MAPPING_PACKET_FILED_BUFFER_SIZE \
(NDV_MAX_MAPPINGS * sizeof(NDV_PACKET_FIELD))
/* Max for a single field */
#define NDV_MAX_SINGLE_MAPPING_FIELD ( sizeof(GPA_RANGE) + \
(sizeof(PFN_NUMBER) * NDV_MAX_INLINE_PFN_ARRAY_LENGTH))
/* Max for all inine data */
#define NDV_MAX_MAPPING_DATA_SIZE (NDV_MAX_MAPPING_PACKET_FILED_BUFFER_SIZE + \
(NDV_MAX_MAPPINGS * NDV_MAX_SINGLE_MAPPING_FIELD))
#define NDV_MAX_PACKET_HEADER_SIZE 256
#define NDV_MAX_PACKET_SIZE (NDV_MAX_PACKET_HEADER_SIZE + \
NDV_MAX_IOCTL_BUFFER_SIZE + \
NDV_MAX_MAPPING_DATA_SIZE)
/* Well known message type INIT is defined for the channel
* not for the protocol.
*/
#define NDV_PACKET_TYPE_INIT 0xFFFFFFFF
/* Invalid protocol version to to identify uninitialized channels */
#define NDV_PROTOCOL_VERSION_INVALID 0xFFFFFFFF
/* Flags that control the bahavior of packet handling */
enum ndv_packet_options {
NDV_PACKET_OPTION_NONE = 0x00,
/* Indicates that the ExternalDataMdl parameter is expectected to be
* passed and must be handled in the reciever. This call must be
* handled specially to ensure that the MDL can be created correctly.
*/
NDV_PACKET_OPTION_EXTERNAL_DATA = 0x01,
/* Inicates that the reciever must execution the handler at passive. */
NDV_PACKET_OPTIONS_REQUIRES_PASSIVE = 0x02,
/* Indicates that the sender does not expect and is not waiting for a
* response packet.
*/
NDV_PACKET_OPTIONS_POST = 0x04,
};
#define NDV_PACKET_TYPE(id_, opt_) \
(((opt_)<<24) | (id_))
#define NDV_PACKET_TYPE_OPTIONS(type_) \
(((type_) >> 24) & 0xFF)
#define NDV_PACKET_TYPE_ID(type_) \
((type_) & 0xFFFFFF) \
#define NDV_ADD_PACKET_OPTION(type_, opt_) \
(type_) |= (opt_<<24)
/* The header value sent on all packets */
union ndv_packet_hdr {
struct {
/* The type of packet.
* This value should be created with the NDV_PACKET_TYPE macro
* to include all packet options within the packet type.
*/
u32 packet_type;
/* The size of the entire fixed message structure that exists
* before the data. This must be >= sizeof(NDV_PACKET_HEADER)
*/
u32 hdr_sz;
/* This size of the data that follows the message
* data_sz + hdr_sz size gives the total size of
* the buffer that is used.
*/
u32 data_sz;
/* The status code used to indicate success or failure.
* It is only used in completions and during responses.
*/
u32 status; //KYS: NTSTATUS?
};
u64 padding[2]; //KYS: why?
};
/* The core INIT packet. This message is defined in the channel
* not in the protocol. This message should never change size
* or behavior, as it could impact compatibility in the future.
* This packet is used to negotiate the protocol version, so chaning
* this size could break backward compat.
*/
union ndv_packet_init {
struct {
u32 packet_type;
u32 protocol_version;
u32 flags;
};
u64 padding[2];
} __packed;
#define NDV_PACKET_INIT_SIZE 16
/* Data packing flags used for accessing the dynamic fields inside a packet */
#define NDV_DATA_PACKING_2 0x1
#define NDV_DATA_PACKING_4 0x3
#define NDV_DATA_PACKING_8 0x7
#define NDV_PROTOCOL_VERSION_1 0x0100
#define NDV_PROTOCOL_VERSION_CURRENT NDV_PROTOCOL_VERSION_1
#define NDV_PROTOCOL_VERSION_COUNT 1
struct ndv_pkt_field {
u32 size;
u32 offset;
};
enum ndv_pkt_id {
NDV_PKT_UNKNOWN = 0,
/* Version 1 Message ID's */
NDV_PKT_ID1_BIND,
NDV_PKT_ID1_CREATE,
NDV_PKT_ID1_CLEANUP,
NDV_PKT_ID1_CANCEL,
NDV_PKT_ID1_CONTROL,
NDV_PKT_ID1_COMPLETE,
NDV_PKT_ID1_INIT_RESOURCES,
};
/* The guest will send this as the first messages just after init
* The resources are reserved per channel.
*/
struct ndv_pkt_hdr_init_resources_1 {
union ndv_packet_hdr pkt_hdr;
u16 io_space_sz_mb;
u64 io_space_start;
};
/* The guest will send this packet to the host after channel init
* to query support for the adapters that are registered.
*/
struct ndv_pkt_hdr_bind_1 {
union ndv_packet_hdr pkt_hdr;
bool unbind;
union nd_sockaddr_inet ip_address;
struct if_physical_addr phys_addr;
u64 guest_id;
};
union ndv_context_handle {
u64 val64;
struct {
u32 local;
u32 remote;
};
};
struct ndv_pkt_hdr_create_1 {
union ndv_packet_hdr pkt_hdr;
/* Identifies the object used to track this file handle on both
* the guest and the host. When sent from the guest, it will contain
* the guest handle. On success, the host will populate and return
* it's handle value as well.
*/
union ndv_context_handle handle;
/* The parameters sent to the CreateFile call */
u32 access_mask;
u32 open_options;
u16 file_attributes; //KYS: This field must be 64 bit aligned
u16 share_access; //KYS
u32 kys_padding; //KYS
u16 ea_length; //KYS; needs to be 64 bit aligned; what is ea length - unused
};
struct ndv_pkt_hdr_cleanup_1 {
union ndv_packet_hdr pkt_hdr;
/* Identifies the object used to track this file handle on both
* the guest and the host. When sent from the guest, it will contain
* the both the guest and host handle values. The host will use this
* value to cleanup its resource, then update its portion of the handle
* to NDV_HANDLE_NULL before returning the data back to the guest.
*/
union ndv_context_handle handle;
};
struct ndv_pkt_hdr_cancel_1 {
union ndv_packet_hdr pkt_hdr;
union ndv_context_handle file_handle;
union ndv_context_handle irp_handle;
};
struct ndv_bind_port_info {
//LUID authentication_id; //KYS: LUID?
bool is_admin;
};
struct ndv_extended_data_flds {
union {
u32 field_count;
u64 padding;
};
//struct ndv_pkt_field fields[ANYSIZE_ARRAY]; //KYS?
};
struct ndv_packet_hdr_control_1 {
union ndv_packet_hdr pkt_hdr;
/* Identifies the object used to track this file handle on both
* the guest and the host. This should always have both guest
* and host handle values inside it.
*/
union ndv_context_handle file_handle;
/* The handle information for the allocated irp context object.
* This information is used when the host/guest starts the cancelation
*/
union ndv_context_handle irp_handle;
/* The input data describing in the IO control parameters */
u32 io_cntrl_code;
u32 output_buf_sz;
u32 input_buf_sz;
u32 input_output_buf_offset;
/* These are used in the return message to indicate the status of the IO
* operation and the amount of data written to the output buffer.
*/
u32 io_status; //KYS: NTSTATUS?
u32 bytes_returned;
/* This contains the field information for additional data that is sent
* with the packet that is IOCTL specific.
*/
struct ndv_pkt_field extended_data;
};
/*
* Include MLX specific defines.
*/
#include "mx_abi.h"
/* Driver specific state.
*/
/*
* We need to have host open a file; some
* Windows constants for open.
*/
#define STANDARD_RIGHTS_ALL (0x001F0000L)
#define FILE_ATTRIBUTE_NORMAL (0x80)
#define FILE_SHARE_READ (0x00000001)
#define FILE_SHARE_WRITE (0x00000002)
#define FILE_SHARE_DELETE (0x00000004)
#define FILE_FLAG_OVERLAPPED (0x40000000)
#define FILE_SHARE_ALL (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
#define CREATE_ALWAYS (2)
#define OPEN_EXISTING (3)
#define RTL_NUMBER_OF(_x) \
sizeof(_x)/sizeof(_x[0])
/*
* The context structure tracks the open state.
*/
/*
* Packet layout for open adaptor.
*/
/*
* Packet for querying the address list.
*/
union query_addr_list_ioctl {
struct nd_handle in;
union nd_sockaddr_inet out[16]; //KYS a max of 16 addresses
};
struct pkt_query_addr_list {
struct ndv_packet_hdr_control_1 hdr;
union query_addr_list_ioctl ioctl;
};
struct pkt_fld {
u32 size;
u32 offset;
};
struct fld_data {
union {
u64 padding;
};
};
struct extended_data_oad {
union {
u32 cnt;
u64 padding;
};
/* offsets are from start of extended data struct
* and should start on 8 byte boundary
*/
struct pkt_fld fields[IBV_GET_CONTEXT_MAPPING_MAX];
};
union oad_ioctl {
struct nd_open_adapter input;
struct nd_resource_descriptor resrc_desc;
};
union oad_mappings {
struct ibv_get_context_req ctx_input;
struct ibv_get_context_resp ctx_output;
};
struct pkt_nd_open_adapter {
struct ndv_packet_hdr_control_1 hdr;
union oad_ioctl ioctl;
union oad_mappings mappings;
/*
* Extended data.
*/
struct extended_data_oad ext_data;
};
/*
* Create CQ IOCTL.
*/
struct cq_db_gpa {
u32 byte_count;
u32 byte_offset;
u64 pfn_array[2];
};
struct cq_sn_gpa {
u32 byte_count;
u32 byte_offset;
u64 pfn_array[2];
};
struct create_cq_ext_data {
union {
u32 cnt;
u64 padding;