-
Notifications
You must be signed in to change notification settings - Fork 652
/
qp.pyx
executable file
·1390 lines (1249 loc) · 52.1 KB
/
qp.pyx
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
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved.
from libc.stdlib cimport malloc, free
from libc.string cimport memcpy
import weakref
from pyverbs.pyverbs_error import PyverbsUserError, PyverbsError, PyverbsRDMAError
from pyverbs.utils import gid_str, qp_type_to_str, qp_state_to_str, mtu_to_str
from pyverbs.utils import access_flags_to_str, mig_state_to_str
from pyverbs.mr cimport MW, MWBindInfo, MWBind
from pyverbs.wr cimport RecvWR, SendWR, SGE
from pyverbs.base import PyverbsRDMAErrno
from pyverbs.addr cimport AHAttr, GID, AH
from pyverbs.base cimport close_weakrefs
cimport pyverbs.libibverbs_enums as e
from pyverbs.addr cimport GlobalRoute
from pyverbs.device cimport Context
from cpython.ref cimport PyObject
from pyverbs.cq cimport CQ, CQEX
cimport pyverbs.libibverbs as v
from pyverbs.xrcd cimport XRCD
from pyverbs.srq cimport SRQ
from pyverbs.pd cimport PD
cdef extern from 'Python.h':
void* PyLong_AsVoidPtr(object)
cdef extern from 'endian.h':
unsigned long htobe32(unsigned long host_32bits)
cdef class QPCap(PyverbsObject):
def __init__(self, max_send_wr=1, max_recv_wr=10, max_send_sge=1,
max_recv_sge=1, max_inline_data=0):
"""
Initializes a QPCap object with user-provided or default values.
:param max_send_wr: max number of outstanding WRs in the SQ
:param max_recv_wr: max number of outstanding WRs in the RQ
:param max_send_sge: Requested max number of scatter-gather elements in
a WR in the SQ
:param max_recv_sge: Requested max number of scatter-gather elements in
a WR in the RQ
:param max_inline_data: max number of data (bytes) that can be posted
inline to the SQ, otherwise 0
:return:
"""
super().__init__()
self.cap.max_send_wr = max_send_wr
self.cap.max_recv_wr = max_recv_wr
self.cap.max_send_sge = max_send_sge
self.cap.max_recv_sge = max_recv_sge
self.cap.max_inline_data = max_inline_data
@property
def max_send_wr(self):
return self.cap.max_send_wr
@max_send_wr.setter
def max_send_wr(self, val):
self.cap.max_send_wr = val
@property
def max_recv_wr(self):
return self.cap.max_recv_wr
@max_recv_wr.setter
def max_recv_wr(self, val):
self.cap.max_recv_wr = val
@property
def max_send_sge(self):
return self.cap.max_send_sge
@max_send_sge.setter
def max_send_sge(self, val):
self.cap.max_send_sge = val
@property
def max_recv_sge(self):
return self.cap.max_recv_sge
@max_recv_sge.setter
def max_recv_sge(self, val):
self.cap.max_recv_sge = val
@property
def max_inline_data(self):
return self.cap.max_inline_data
@max_inline_data.setter
def max_inline_data(self, val):
self.cap.max_inline_data = val
def __str__(self):
print_format = '{:20}: {:<20}\n'
return print_format.format('max send wrs', self.cap.max_send_wr) +\
print_format.format('max recv wrs', self.cap.max_recv_wr) +\
print_format.format('max send sges', self.cap.max_send_sge) +\
print_format.format('max recv sges', self.cap.max_recv_sge) +\
print_format.format('max inline data', self.cap.max_inline_data)
cdef class QPInitAttr(PyverbsObject):
def __init__(self, qp_type=e.IBV_QPT_UD, qp_context=None,
PyverbsObject scq=None, PyverbsObject rcq=None,
SRQ srq=None, QPCap cap=None, sq_sig_all=1):
"""
Initializes a QpInitAttr object representing ibv_qp_init_attr struct.
Note that SRQ object is not yet supported in pyverbs so can't be passed
as a parameter. None should be used until such support is added.
:param qp_type: The desired QP type (see enum ibv_qp_type)
:param qp_context: Associated QP context
:param scq: Send CQ to be used for this QP
:param rcq: Receive CQ to be used for this QP
:param srq: Shared receive queue to be used as RQ in QP
:param cap: A QPCap object
:param sq_sig_all: If set, each send WR will generate a completion
entry
:return: A QpInitAttr object
"""
super().__init__()
_copy_caps(cap, self)
self.attr.qp_context = <void*>qp_context
if scq is not None:
if type(scq) is CQ:
self.attr.send_cq = (<CQ>scq).cq
elif type(scq) is CQEX:
self.attr.send_cq = (<CQEX>scq).ibv_cq
else:
raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
format(t=type(scq)))
self.scq = scq
if rcq is not None:
if type(rcq) is CQ:
self.attr.recv_cq = (<CQ>rcq).cq
elif type(rcq) is CQEX:
self.attr.recv_cq = (<CQEX>rcq).ibv_cq
else:
raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
format(t=type(rcq)))
self.rcq = rcq
self.attr.qp_type = qp_type
self.attr.sq_sig_all = sq_sig_all
self.srq = srq
self.attr.srq = srq.srq if srq else NULL
@property
def send_cq(self):
return self.scq
@send_cq.setter
def send_cq(self, val):
if type(val) is CQ:
self.attr.send_cq = (<CQ>val).cq
elif type(val) is CQEX:
self.attr.send_cq = (<CQEX>val).ibv_cq
self.scq = val
@property
def srq(self):
return self.srq
@srq.setter
def srq(self, SRQ val):
self.attr.srq = <v.ibv_srq*>val.srq
self.srq = val
@property
def recv_cq(self):
return self.rcq
@recv_cq.setter
def recv_cq(self, val):
if type(val) is CQ:
self.attr.recv_cq = (<CQ>val).cq
elif type(val) is CQEX:
self.attr.recv_cq = (<CQEX>val).ibv_cq
self.rcq = val
@property
def cap(self):
return QPCap(max_send_wr=self.attr.cap.max_send_wr,
max_recv_wr=self.attr.cap.max_recv_wr,
max_send_sge=self.attr.cap.max_send_sge,
max_recv_sge=self.attr.cap.max_recv_sge,
max_inline_data=self.attr.cap.max_inline_data)
@cap.setter
def cap(self, val):
_copy_caps(val, self)
@property
def qp_type(self):
return self.attr.qp_type
@qp_type.setter
def qp_type(self, val):
self.attr.qp_type = val
@property
def sq_sig_all(self):
return self.attr.sq_sig_all
@sq_sig_all.setter
def sq_sig_all(self, val):
self.attr.sq_sig_all = val
@property
def max_send_wr(self):
return self.attr.cap.max_send_wr
@max_send_wr.setter
def max_send_wr(self, val):
self.attr.cap.max_send_wr = val
@property
def max_recv_wr(self):
return self.attr.cap.max_recv_wr
@max_recv_wr.setter
def max_recv_wr(self, val):
self.attr.cap.max_recv_wr = val
@property
def max_send_sge(self):
return self.attr.cap.max_send_sge
@max_send_sge.setter
def max_send_sge(self, val):
self.attr.cap.max_send_sge = val
@property
def max_recv_sge(self):
return self.attr.cap.max_recv_sge
@max_recv_sge.setter
def max_recv_sge(self, val):
self.attr.cap.max_recv_sge = val
@property
def max_inline_data(self):
return self.attr.cap.max_inline_data
@max_inline_data.setter
def max_inline_data(self, val):
self.attr.cap.max_inline_data = val
def __str__(self):
print_format = '{:20}: {:<20}\n'
ident_format = ' {:20}: {:<20}\n'
return print_format.format('QP type', qp_type_to_str(self.qp_type)) +\
print_format.format('SQ sig. all', self.sq_sig_all) +\
'QP caps:\n' +\
ident_format.format('max send WR', self.attr.cap.max_send_wr) +\
ident_format.format('max recv WR', self.attr.cap.max_recv_wr) +\
ident_format.format('max send SGE',
self.attr.cap.max_send_sge) +\
ident_format.format('max recv SGE',
self.attr.cap.max_recv_sge) +\
ident_format.format('max inline data',
self.attr.cap.max_inline_data)
cdef class QPInitAttrEx(PyverbsObject):
def __init__(self, qp_type=e.IBV_QPT_UD, qp_context=None,
PyverbsObject scq=None, PyverbsObject rcq=None,
SRQ srq=None, QPCap cap=None, sq_sig_all=0, comp_mask=0,
PD pd=None, XRCD xrcd=None, create_flags=0,
max_tso_header=0, source_qpn=0, object hash_conf=None,
object ind_table=None, send_ops_flags=0):
"""
Initialize a QPInitAttrEx object with user-defined or default values.
:param qp_type: QP type to be created
:param qp_context: Associated user context
:param scq: Send CQ to be used for this QP
:param rcq: Recv CQ to be used for this QP
:param srq: Shared receive queue to be used as RQ in QP
:param cap: A QPCap object
:param sq_sig_all: If set, each send WR will generate a completion
entry
:param comp_mask: bit mask to determine which of the following fields
are valid
:param pd: A PD object to be associated with this QP
:param xrcd: XRC domain to be used for XRC QPs
:param create_flags: Creation flags for this QP
:param max_tso_header: Maximum TSO header size
:param source_qpn: Source QP number (requires IBV_QP_CREATE_SOURCE_QPN
set in create_flags)
:param hash_conf: Not yet supported
:param ind_table: Not yet supported
:param send_ops_flags: Send opcodes to be supported by the extended QP.
Use ibv_qp_create_send_ops_flags enum
:return: An initialized QPInitAttrEx object
"""
super().__init__()
_copy_caps(cap, self)
if scq is not None:
if type(scq) is CQ:
self.attr.send_cq = (<CQ>scq).cq
elif type(scq) is CQEX:
self.attr.send_cq = (<CQEX>scq).ibv_cq
else:
raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
format(t=type(scq)))
self.scq = scq
if rcq is not None:
if type(rcq) is CQ:
self.attr.recv_cq = (<CQ>rcq).cq
elif type(rcq) is CQEX:
self.attr.recv_cq = (<CQEX>rcq).ibv_cq
else:
raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
format(t=type(rcq)))
self.rcq = rcq
self.srq = srq
self.attr.srq = srq.srq if srq else NULL
self.xrcd = xrcd
self.attr.xrcd = xrcd.xrcd if xrcd else NULL
self.attr.rwq_ind_tbl = NULL # Until RSS support is added
self.attr.qp_type = qp_type
self.attr.sq_sig_all = sq_sig_all
unsupp_flags = e.IBV_QP_INIT_ATTR_IND_TABLE | e.IBV_QP_INIT_ATTR_RX_HASH
if comp_mask & unsupp_flags:
raise PyverbsUserError('RSS is not yet supported in pyverbs')
self.attr.comp_mask = comp_mask
if pd is not None:
self._pd = pd
self.attr.pd = pd.pd
self.attr.create_flags = create_flags
self.attr.max_tso_header = max_tso_header
self.attr.source_qpn = source_qpn
self.attr.send_ops_flags = send_ops_flags
@property
def send_cq(self):
return self.scq
@send_cq.setter
def send_cq(self, val):
if type(val) is CQ:
self.attr.send_cq = (<CQ>val).cq
elif type(val) is CQEX:
self.attr.send_cq = (<CQEX>val).ibv_cq
self.scq = val
@property
def recv_cq(self):
return self.rcq
@recv_cq.setter
def recv_cq(self, val):
if type(val) is CQ:
self.attr.recv_cq = (<CQ>val).cq
elif type(val) is CQEX:
self.attr.recv_cq = (<CQEX>val).ibv_cq
self.rcq = val
@property
def cap(self):
return QPCap(max_send_wr=self.attr.cap.max_send_wr,
max_recv_wr=self.attr.cap.max_recv_wr,
max_send_sge=self.attr.cap.max_send_sge,
max_recv_sge=self.attr.cap.max_recv_sge,
max_inline_data=self.attr.cap.max_inline_data)
@cap.setter
def cap(self, val):
_copy_caps(val, self)
@property
def qp_type(self):
return self.attr.qp_type
@qp_type.setter
def qp_type(self, val):
self.attr.qp_type = val
@property
def sq_sig_all(self):
return self.attr.sq_sig_all
@sq_sig_all.setter
def sq_sig_all(self, val):
self.attr.sq_sig_all = val
@property
def comp_mask(self):
return self.attr.comp_mask
@comp_mask.setter
def comp_mask(self, val):
self.attr.comp_mask = val
@property
def pd(self):
return self._pd
@pd.setter
def pd(self, PD val):
self.attr.pd = <v.ibv_pd*>val.pd
self._pd = val
@property
def xrcd(self):
return self.xrcd
@xrcd.setter
def xrcd(self, XRCD val):
self.attr.xrcd = <v.ibv_xrcd*>val.xrcd
self.xrcd = val
@property
def srq(self):
return self.srq
@srq.setter
def srq(self, SRQ val):
self.attr.srq = <v.ibv_srq*>val.srq
self.srq = val
@property
def create_flags(self):
return self.attr.create_flags
@create_flags.setter
def create_flags(self, val):
self.attr.create_flags = val
@property
def max_tso_header(self):
return self.attr.max_tso_header
@max_tso_header.setter
def max_tso_header(self, val):
self.attr.max_tso_header = val
@property
def source_qpn(self):
return self.attr.source_qpn
@source_qpn.setter
def source_qpn(self, val):
self.attr.source_qpn = val
@property
def max_send_wr(self):
return self.attr.cap.max_send_wr
@max_send_wr.setter
def max_send_wr(self, val):
self.attr.cap.max_send_wr = val
@property
def max_recv_wr(self):
return self.attr.cap.max_recv_wr
@max_recv_wr.setter
def max_recv_wr(self, val):
self.attr.cap.max_recv_wr = val
@property
def max_send_sge(self):
return self.attr.cap.max_send_sge
@max_send_sge.setter
def max_send_sge(self, val):
self.attr.cap.max_send_sge = val
@property
def max_recv_sge(self):
return self.attr.cap.max_recv_sge
@max_recv_sge.setter
def max_recv_sge(self, val):
self.attr.cap.max_recv_sge = val
@property
def max_inline_data(self):
return self.attr.cap.max_inline_data
@max_inline_data.setter
def max_inline_data(self, val):
self.attr.cap.max_inline_data = val
def mask_to_str(self, mask):
comp_masks = {1: 'PD', 2: 'XRCD', 4: 'Create Flags',
8: 'Max TSO header', 16: 'Indirection Table',
32: 'RX hash'}
mask_str = ''
for f in comp_masks:
if mask & f:
mask_str += comp_masks[f]
mask_str += ' '
return mask_str
def flags_to_str(self, flags):
create_flags = {1: 'Block self mcast loopback', 2: 'Scatter FCS',
4: 'CVLAN stripping', 8: 'Source QPN',
16: 'PCI write end padding'}
create_str = ''
for f in create_flags:
if flags & f:
create_str += create_flags[f]
create_str += ' '
return create_str
def __str__(self):
print_format = '{:20}: {:<20}\n'
return print_format.format('QP type', qp_type_to_str(self.qp_type)) +\
print_format.format('SQ sig. all', self.sq_sig_all) +\
'QP caps:\n' +\
print_format.format(' max send WR',
self.attr.cap.max_send_wr) +\
print_format.format(' max recv WR',
self.attr.cap.max_recv_wr) +\
print_format.format(' max send SGE',
self.attr.cap.max_send_sge) +\
print_format.format(' max recv SGE',
self.attr.cap.max_recv_sge) +\
print_format.format(' max inline data',
self.attr.cap.max_inline_data) +\
print_format.format('comp mask',
self.mask_to_str(self.attr.comp_mask)) +\
print_format.format('create flags',
self.flags_to_str(self.attr.create_flags)) +\
print_format.format('max TSO header',
self.attr.max_tso_header) +\
print_format.format('Source QPN', self.attr.source_qpn)
cdef class QPAttr(PyverbsObject):
def __init__(self, qp_state=e.IBV_QPS_INIT, cur_qp_state=e.IBV_QPS_RESET,
port_num=1, path_mtu=e.IBV_MTU_1024):
"""
Initializes a QPQttr object which represents ibv_qp_attr structs. It
can be used to modify a QP.
This function initializes default values for reset-to-init transition.
:param qp_state: Desired QP state
:param cur_qp_state: Current QP state
:return: An initialized QpAttr object
"""
super().__init__()
self.attr.qp_state = qp_state
self.attr.cur_qp_state = cur_qp_state
self.attr.port_num = port_num
self.attr.path_mtu = path_mtu
@property
def qp_state(self):
return self.attr.qp_state
@qp_state.setter
def qp_state(self, val):
self.attr.qp_state = val
@property
def cur_qp_state(self):
return self.attr.cur_qp_state
@cur_qp_state.setter
def cur_qp_state(self, val):
self.attr.cur_qp_state = val
@property
def path_mtu(self):
return self.attr.path_mtu
@path_mtu.setter
def path_mtu(self, val):
self.attr.path_mtu = val
@property
def path_mig_state(self):
return self.attr.path_mig_state
@path_mig_state.setter
def path_mig_state(self, val):
self.attr.path_mig_state = val
@property
def qkey(self):
return self.attr.qkey
@qkey.setter
def qkey(self, val):
self.attr.qkey = val
@property
def rq_psn(self):
return self.attr.rq_psn
@rq_psn.setter
def rq_psn(self, val):
self.attr.rq_psn = val
@property
def sq_psn(self):
return self.attr.sq_psn
@sq_psn.setter
def sq_psn(self, val):
self.attr.sq_psn = val
@property
def dest_qp_num(self):
return self.attr.dest_qp_num
@dest_qp_num.setter
def dest_qp_num(self, val):
self.attr.dest_qp_num = val
@property
def qp_access_flags(self):
return self.attr.qp_access_flags
@qp_access_flags.setter
def qp_access_flags(self, val):
self.attr.qp_access_flags = val
@property
def cap(self):
return QPCap(max_send_wr=self.attr.cap.max_send_wr,
max_recv_wr=self.attr.cap.max_recv_wr,
max_send_sge=self.attr.cap.max_send_sge,
max_recv_sge=self.attr.cap.max_recv_sge,
max_inline_data=self.attr.cap.max_inline_data)
@cap.setter
def cap(self, val):
_copy_caps(val, self)
@property
def ah_attr(self):
if self.attr.ah_attr.is_global:
gid = gid_str(self.attr.ah_attr.grh.dgid._global.subnet_prefix,
self.attr.ah_attr.grh.dgid._global.interface_id)
g = GID(gid)
gr = GlobalRoute(flow_label=self.attr.ah_attr.grh.flow_label,
sgid_index=self.attr.ah_attr.grh.sgid_index,
hop_limit=self.attr.ah_attr.grh.hop_limit, dgid=g,
traffic_class=self.attr.ah_attr.grh.traffic_class)
else:
gr = None
ah = AHAttr(dlid=self.attr.ah_attr.dlid, sl=self.attr.ah_attr.sl,
port_num=self.attr.ah_attr.port_num,
src_path_bits=self.attr.ah_attr.src_path_bits,
static_rate=self.attr.ah_attr.static_rate,
is_global=self.attr.ah_attr.is_global, gr=gr)
return ah
@ah_attr.setter
def ah_attr(self, val):
self._copy_ah(val)
@property
def alt_ah_attr(self):
if self.attr.alt_ah_attr.is_global:
gid = gid_str(self.attr.alt_ah_attr.grh.dgid._global.subnet_prefix,
self.attr.alt_ah_attr.grh.dgid._global.interface_id)
g = GID(gid)
gr = GlobalRoute(flow_label=self.attr.alt_ah_attr.grh.flow_label,
sgid_index=self.attr.alt_ah_attr.grh.sgid_index,
hop_limit=self.attr.alt_ah_attr.grh.hop_limit,
dgid=g,
traffic_class=self.attr.alt_ah_attr.grh.traffic_class)
else:
gr = None
ah = AHAttr(dlid=self.attr.alt_ah_attr.dlid,
port_num=self.attr.ah_attr.port_num,
sl=self.attr.alt_ah_attr.sl,
src_path_bits=self.attr.alt_ah_attr.src_path_bits,
static_rate=self.attr.alt_ah_attr.static_rate,
is_global=self.attr.alt_ah_attr.is_global, gr=gr)
return ah
@alt_ah_attr.setter
def alt_ah_attr(self, val):
self._copy_ah(val, True)
def _copy_ah(self, AHAttr ah_attr, is_alt=False):
if ah_attr is None:
return
if not is_alt:
for i in range(16):
self.attr.ah_attr.grh.dgid.raw[i] = \
ah_attr.ah_attr.grh.dgid.raw[i]
self.attr.ah_attr.grh.flow_label = ah_attr.ah_attr.grh.flow_label
self.attr.ah_attr.grh.sgid_index = ah_attr.ah_attr.grh.sgid_index
self.attr.ah_attr.grh.hop_limit = ah_attr.ah_attr.grh.hop_limit
self.attr.ah_attr.grh.traffic_class = \
ah_attr.ah_attr.grh.traffic_class
self.attr.ah_attr.dlid = ah_attr.ah_attr.dlid
self.attr.ah_attr.sl = ah_attr.ah_attr.sl
self.attr.ah_attr.src_path_bits = ah_attr.ah_attr.src_path_bits
self.attr.ah_attr.static_rate = ah_attr.ah_attr.static_rate
self.attr.ah_attr.is_global = ah_attr.ah_attr.is_global
self.attr.ah_attr.port_num = ah_attr.ah_attr.port_num
else:
for i in range(16):
self.attr.alt_ah_attr.grh.dgid.raw[i] = \
ah_attr.ah_attr.grh.dgid.raw[i]
self.attr.alt_ah_attr.grh.flow_label = \
ah_attr.ah_attr.grh.flow_label
self.attr.alt_ah_attr.grh.sgid_index = \
ah_attr.ah_attr.grh.sgid_index
self.attr.alt_ah_attr.grh.hop_limit = ah_attr.ah_attr.grh.hop_limit
self.attr.alt_ah_attr.grh.traffic_class = \
ah_attr.ah_attr.grh.traffic_class
self.attr.alt_ah_attr.dlid = ah_attr.ah_attr.dlid
self.attr.alt_ah_attr.sl = ah_attr.ah_attr.sl
self.attr.alt_ah_attr.src_path_bits = ah_attr.ah_attr.src_path_bits
self.attr.alt_ah_attr.static_rate = ah_attr.ah_attr.static_rate
self.attr.alt_ah_attr.is_global = ah_attr.ah_attr.is_global
self.attr.alt_ah_attr.port_num = ah_attr.ah_attr.port_num
@property
def pkey_index(self):
return self.attr.pkey_index
@pkey_index.setter
def pkey_index(self, val):
self.attr.pkey_index = val
@property
def alt_pkey_index(self):
return self.attr.alt_pkey_index
@alt_pkey_index.setter
def alt_pkey_index(self, val):
self.attr.alt_pkey_index = val
@property
def en_sqd_async_notify(self):
return self.attr.en_sqd_async_notify
@en_sqd_async_notify.setter
def en_sqd_async_notify(self, val):
self.attr.en_sqd_async_notify = val
@property
def sq_draining(self):
return self.attr.sq_draining
@sq_draining.setter
def sq_draining(self, val):
self.attr.sq_draining = val
@property
def max_rd_atomic(self):
return self.attr.max_rd_atomic
@max_rd_atomic.setter
def max_rd_atomic(self, val):
self.attr.max_rd_atomic = val
@property
def max_dest_rd_atomic(self):
return self.attr.max_dest_rd_atomic
@max_dest_rd_atomic.setter
def max_dest_rd_atomic(self, val):
self.attr.max_dest_rd_atomic = val
@property
def min_rnr_timer(self):
return self.attr.min_rnr_timer
@min_rnr_timer.setter
def min_rnr_timer(self, val):
self.attr.min_rnr_timer = val
@property
def port_num(self):
return self.attr.port_num
@port_num.setter
def port_num(self, val):
self.attr.port_num = val
@property
def timeout(self):
return self.attr.timeout
@timeout.setter
def timeout(self, val):
self.attr.timeout = val
@property
def retry_cnt(self):
return self.attr.retry_cnt
@retry_cnt.setter
def retry_cnt(self, val):
self.attr.retry_cnt = val
@property
def rnr_retry(self):
return self.attr.rnr_retry
@rnr_retry.setter
def rnr_retry(self, val):
self.attr.rnr_retry = val
@property
def alt_port_num(self):
return self.attr.alt_port_num
@alt_port_num.setter
def alt_port_num(self, val):
self.attr.alt_port_num = val
@property
def alt_timeout(self):
return self.attr.alt_timeout
@alt_timeout.setter
def alt_timeout(self, val):
self.attr.alt_timeout = val
@property
def rate_limit(self):
return self.attr.rate_limit
@rate_limit.setter
def rate_limit(self, val):
self.attr.rate_limit = val
def __str__(self):
print_format = '{:22}: {:<20}\n'
ah_format = ' {:22}: {:<20}\n'
ident_format = ' {:22}: {:<20}\n'
if self.attr.ah_attr.is_global:
global_ah = ah_format.format('dgid',
gid_str(self.attr.ah_attr.grh.dgid._global.subnet_prefix,
self.attr.ah_attr.grh.dgid._global.interface_id)) +\
ah_format.format('flow label',
self.attr.ah_attr.grh.flow_label) +\
ah_format.format('sgid index',
self.attr.ah_attr.grh.sgid_index) +\
ah_format.format('hop limit',
self.attr.ah_attr.grh.hop_limit) +\
ah_format.format('traffic_class',
self.attr.ah_attr.grh.traffic_class)
else:
global_ah = ''
if self.attr.alt_ah_attr.is_global:
alt_global_ah = ah_format.format('dgid',
gid_str(self.attr.alt_ah_attr.grh.dgid._global.subnet_prefix,
self.attr.alt_ah_attr.grh.dgid._global.interface_id)) +\
ah_format.format('flow label',
self.attr.alt_ah_attr.grh.flow_label) +\
ah_format.format('sgid index',
self.attr.alt_ah_attr.grh.sgid_index) +\
ah_format.format('hop limit',
self.attr.alt_ah_attr.grh.hop_limit) +\
ah_format.format('traffic_class',
self.attr.alt_ah_attr.grh.traffic_class)
else:
alt_global_ah = ''
return print_format.format('QP state',
qp_state_to_str(self.attr.qp_state)) +\
print_format.format('QP current state',
qp_state_to_str(self.attr.cur_qp_state)) +\
print_format.format('Path MTU',
mtu_to_str(self.attr.path_mtu)) +\
print_format.format('Path mig. state',
mig_state_to_str(self.attr.path_mig_state)) +\
print_format.format('QKey', self.attr.qkey) +\
print_format.format('RQ PSN', self.attr.rq_psn) +\
print_format.format('SQ PSN', self.attr.sq_psn) +\
print_format.format('Dest QP number', self.attr.dest_qp_num) +\
print_format.format('QP access flags',
access_flags_to_str(self.attr.qp_access_flags)) +\
'QP caps:\n' +\
ident_format.format('max send WR',
self.attr.cap.max_send_wr) +\
ident_format.format('max recv WR',
self.attr.cap.max_recv_wr) +\
ident_format.format('max send SGE',
self.attr.cap.max_send_sge) +\
ident_format.format('max recv SGE',
self.attr.cap.max_recv_sge) +\
ident_format.format('max inline data',
self.attr.cap.max_inline_data) +\
'AH Attr:\n' +\
ident_format.format('port num', self.attr.ah_attr.port_num) +\
ident_format.format('sl', self.attr.ah_attr.sl) +\
ident_format.format('source path bits',
self.attr.ah_attr.src_path_bits) +\
ident_format.format('dlid', self.attr.ah_attr.dlid) +\
ident_format.format('port num', self.attr.ah_attr.port_num) +\
ident_format.format('static rate',
self.attr.ah_attr.static_rate) +\
ident_format.format('is global',
self.attr.ah_attr.is_global) +\
global_ah +\
'Alt. AH Attr:\n' +\
ident_format.format('port num', self.attr.alt_ah_attr.port_num) +\
ident_format.format('sl', self.attr.alt_ah_attr.sl) +\
ident_format.format('source path bits',
self.attr.alt_ah_attr.src_path_bits) +\
ident_format.format('dlid', self.attr.alt_ah_attr.dlid) +\
ident_format.format('port num', self.attr.alt_ah_attr.port_num) +\
ident_format.format('static rate',
self.attr.alt_ah_attr.static_rate) +\
ident_format.format('is global',
self.attr.alt_ah_attr.is_global) +\
alt_global_ah +\
print_format.format('PKey index', self.attr.pkey_index) +\
print_format.format('Alt. PKey index',
self.attr.alt_pkey_index) +\
print_format.format('En. SQD async notify',
self.attr.en_sqd_async_notify) +\
print_format.format('SQ draining', self.attr.sq_draining) +\
print_format.format('Max RD atomic', self.attr.max_rd_atomic) +\
print_format.format('Max dest. RD atomic',
self.attr.max_dest_rd_atomic) +\
print_format.format('Min RNR timer', self.attr.min_rnr_timer) +\
print_format.format('Port number', self.attr.port_num) +\
print_format.format('Timeout', self.attr.timeout) +\
print_format.format('Retry counter', self.attr.retry_cnt) +\
print_format.format('RNR retry', self.attr.rnr_retry) +\
print_format.format('Alt. port number',
self.attr.alt_port_num) +\
print_format.format('Alt. timeout', self.attr.alt_timeout) +\
print_format.format('Rate limit', self.attr.rate_limit)
cdef class ECE(PyverbsCM):
def __init__(self, vendor_id=0, options=0, comp_mask=0):
"""
:param vendor_id: Unique identifier of the provider vendor.
:param options: Provider specific attributes which are supported or
needed to be enabled by ECE users.
:param comp_mask: A bitmask specifying which ECE options should be
valid.
"""
super().__init__()
self.ece.vendor_id = vendor_id
self.ece.options = options
self.ece.comp_mask = comp_mask
def __str__(self):
print_format = '{:22}: 0x{:<20x}\n'
return 'ECE:\n' +\
print_format.format('Vendor ID', self.ece.vendor_id) +\
print_format.format('Options', self.ece.options) +\
print_format.format('Comp Mask', self.ece.comp_mask)
cdef class QP(PyverbsCM):
def __init__(self, object creator not None, object init_attr not None,
QPAttr qp_attr=None):
"""
Initializes a QP object and performs state transitions according to
user request.
A C ibv_qp object will be created using the provided init_attr.
If a qp_attr object is provided, pyverbs will consider this a hint to
transit the QP's state as far as possible towards RTS:
- In case of UD and Raw Packet QP types, if a qp_attr is provided the
QP will be returned in RTS state.
- In case of connected QPs (RC, UC), remote QPN is needed for INIT2RTR
transition, so if a qp_attr is provided, the QP will be returned in
INIT state.
:param creator: The object creating the QP. Can be of type PD so
ibv_create_qp will be used or of type Context, so
ibv_create_qp_ex will be used.
:param init_attr: QP initial attributes of type QPInitAttr (when
created using PD) or QPInitAttrEx (when created
using Context).
:param qp_attr: Optional QPAttr object. Will be used for QP state
transitions after creation.
:return: An initialized QP object
"""
cdef PD pd
cdef Context ctx
super().__init__()
self.mws = weakref.WeakSet()
self.update_cqs(init_attr)
# QP initialization was not done by the provider, we should do it here
if self.qp == NULL:
# In order to use cdef'd methods, a proper casting must be done,
# let's infer the type.
if issubclass(type(creator), Context):
self._create_qp_ex(creator, init_attr)
if self.qp == NULL:
raise PyverbsRDMAErrno('Failed to create QP')
ctx = <Context>creator
self.context = ctx
ctx.add_ref(self)
if init_attr.pd is not None:
pd = <PD>init_attr.pd
pd.add_ref(self)
self.pd = pd
if init_attr.xrcd is not None:
xrcd = <XRCD>init_attr.xrcd
xrcd.add_ref(self)
self.xrcd = xrcd
else:
self._create_qp(creator, init_attr)
if self.qp == NULL:
raise PyverbsRDMAErrno('Failed to create QP')
pd = <PD>creator
self.pd = pd
pd.add_ref(self)
self.context = None
if qp_attr is not None:
funcs = {e.IBV_QPT_RC: self.to_init, e.IBV_QPT_UC: self.to_init,
e.IBV_QPT_UD: self.to_rts,
e.IBV_QPT_XRC_RECV: self.to_init,
e.IBV_QPT_XRC_SEND: self.to_init,
e.IBV_QPT_RAW_PACKET: self.to_rts}
funcs[self.qp.qp_type](qp_attr)
cdef update_cqs(self, init_attr):
cdef CQ cq
cdef CQEX cqex
if init_attr.send_cq is not None:
if type(init_attr.send_cq) == CQ:
cq = <CQ>init_attr.send_cq
cq.add_ref(self)
self.scq = cq
else:
cqex = <CQEX>init_attr.send_cq
cqex.add_ref(self)
self.scq = cqex
if init_attr.send_cq != init_attr.recv_cq and init_attr.recv_cq is not None:
if type(init_attr.recv_cq) == CQ:
cq = <CQ>init_attr.recv_cq
cq.add_ref(self)
self.rcq = cq
else:
cqex = <CQEX>init_attr.recv_cq
cqex.add_ref(self)
self.rcq = cqex
def _create_qp(self, PD pd, QPInitAttr attr):
self.qp = v.ibv_create_qp(pd.pd, &attr.attr)
def _create_qp_ex(self, Context ctx, QPInitAttrEx attr):
self.qp = v.ibv_create_qp_ex(ctx.context, &attr.attr)
cdef add_ref(self, obj):
if isinstance(obj, MW):
self.mws.add(obj)
else:
raise PyverbsError('Unrecognized object type')
def __dealloc__(self):
self.close()
cpdef close(self):