-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmlx3_ib.c
5724 lines (4551 loc) · 150 KB
/
mlx3_ib.c
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
/*
* This file is part of the Nautilus AeroKernel developed
* by the Hobbes and V3VEE Projects with funding from the
* United States National Science Foundation and the Department of Energy.
*
* The V3VEE Project is a joint project between Northwestern University
* and the University of New Mexico. The Hobbes Project is a collaboration
* led by Sandia National Laboratories that includes several national
* laboratories and universities. You can find out more at:
* http://www.v3vee.org and
* http://xstack.sandia.gov/hobbes
*
* Copyright (c) 2018, Kyle Hale
* Copyright (c) 2018, The V3VEE Project <http://www.v3vee.org>
* The Hobbes Project <http://xstack.sandia.gov/hobbes>
* All rights reserved.
*
* Authors: Brian Richard Tauro <[email protected]>
* Kyle Hale <[email protected]>
* Piyush Nath <[email protected]>
*
* This is free software. You are permitted to use,
* redistribute, and modify it as specified in the file "LICENSE.txt".
*/
#include <nautilus/nautilus.h>
#include <nautilus/macros.h>
#include <nautilus/cpu.h>
#include <nautilus/dev.h>
#include <nautilus/netdev.h>
#include <nautilus/mtrr.h>
#include <nautilus/math.h>
#include <dev/pci.h>
#include <dev/mlx3_ib.h>
#include <nautilus/irq.h>
#ifndef NAUT_CONFIG_DEBUG_MLX3_PCI
#undef DEBUG_PRINT
#define DEBUG_PRINT(fmt, args...)
#endif
#define __mzero_checked(ptr, size, msg, ret_expr) \
ptr = malloc(size); \
if (!ptr) { \
ERROR(msg); \
ret_expr; \
} \
memset(ptr, 0, size);
#define mzero_checked(ptr, size, desc) \
__mzero_checked(ptr, size, "Could not allocate " desc "\n", return -1)
static inline uint16_t
bswap16 (uint16_t x)
{
return __bswap16(x);
}
static inline uint32_t
bswap32 (uint32_t x)
{
return __bswap32(x);
}
static inline uint64_t
bswap64 (uint64_t x)
{
return __bswap64(x);
}
static inline uint16_t
bswap16p (const uint16_t * p)
{
return bswap16(*p);
}
static inline uint32_t
bswap32p (const uint32_t * p)
{
return bswap32(*p);
}
static inline uint64_t
bswap64p (const uint64_t * p)
{
return bswap64(*p);
}
#define MLX3_GET(dest, source, offset) \
do { \
void *__p = (char *) (source) + (offset); \
switch (sizeof(dest)) { \
case 1: (dest) = *(uint8_t *) __p; break; \
case 2: (dest) = bswap16p(__p); break; \
case 4: (dest) = bswap32p(__p); break; \
case 8: (dest) = bswap64p(__p); break; \
default: ERROR("Bad use of MLXGET\n"); break; \
} \
} while (0)
#define MLX3_PUT(dest, source, offset) \
do { \
void *__d = ((char *) (dest) + (offset)); \
switch (sizeof(source)) { \
case 1: *(uint8_t*) __d = (source); break; \
case 2: *(uint16_t *) __d = bswap16(source); break; \
case 4: *(uint32_t *) __d = bswap32(source); break; \
case 8: *(uint64_t *) __d = bswap64(source); break; \
default: ERROR("Bad use of MLXPUT\n"); break; \
} \
} while (0)
static inline void
unmarshal_area (uint32_t * dst, uint32_t * src, unsigned cnt)
{
int i;
for (i = 0; i < cnt; i++) {
dst[i] = bswap32(src[i]);
DEBUG("DW %02x: 0x%08x\n", i*4, dst[i]);
}
}
static inline void
marshal_area (uint32_t * dst, uint32_t * src, unsigned cnt)
{
unmarshal_area(dst, src, cnt);
}
static uint16_t
get_fw_rev_maj (struct mlx3_ib * mlx)
{
return READ_MEM(mlx, 0) & 0xffff;
}
static uint16_t
get_fw_rev_min (struct mlx3_ib * mlx)
{
return READ_MEM(mlx, 0) >> 16;
}
static uint16_t
get_fw_rev_submin (struct mlx3_ib * mlx)
{
return READ_MEM(mlx, 4) & 0xffff;
}
static uint16_t
get_cmd_ix_rev (struct mlx3_ib * mlx)
{
return READ_MEM(mlx, 4) >> 16;
}
static dma_addr_t
get_dma_page (void)
{
dma_addr_t a = (dma_addr_t)NULL;
/* pray that this is not in high memory for now */
a = (dma_addr_t)malloc(PAGE_SIZE_4KB);
if (!a) {
ERROR("Could not allocate DMA page\n");
}
memset((void*)a, 0, PAGE_SIZE_4KB);
return a;
}
static void
free_dma_page (dma_addr_t addr)
{
free((void*)addr);
}
static mlx3_cmd_box_t *
create_cmd_mailbox (struct mlx3_ib * m)
{
mlx3_cmd_box_t * ret = NULL;
ret = malloc(sizeof(mlx3_cmd_box_t));
if (!ret) {
ERROR("Could not create cmd mailbox\n");
return NULL;
}
memset(ret, 0, sizeof(mlx3_cmd_box_t));
ret->buf = get_dma_page();
if (!ret->buf) {
ERROR("Could not init cmd mailbox\n");
goto out;
}
return ret;
out:
free(ret);
return NULL;
}
static void
destroy_cmd_mailbox (mlx3_cmd_box_t * cmd)
{
free_dma_page(cmd->buf);
free(cmd);
}
// TODO: this should be part of a cmd context or something...
static uint8_t exp_toggle = 0;
static int
cmd_pending (struct mlx3_ib * m)
{
uint32_t status = READ_MEM(m, MLX_HCR_BASE + HCR_STATUS_OFFSET);
return ((bswap32(status) >> HCR_GO_BIT) & 1) ||
(((bswap32(status) >> HCR_T_BIT) & 1) != exp_toggle);
}
static int
mlx3_mailbox_cmd_post_in (struct mlx3_ib * m,
uint64_t in_param,
uint64_t out_param,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
uint16_t token,
int event)
{
while (cmd_pending(m)) {
udelay(1000);
}
WRITE_MEM(m, MLX_HCR_BASE, bswap32(((uint32_t)(in_param >> 32))));
WRITE_MEM(m, MLX_HCR_BASE + 4, bswap32(((uint32_t)(in_param & 0xfffffffful))));
WRITE_MEM(m, MLX_HCR_BASE + 8, bswap32(in_mod));
WRITE_MEM(m, MLX_HCR_BASE + 12, bswap32((((uint32_t)(out_param >> 32)))));
WRITE_MEM(m, MLX_HCR_BASE + 16, bswap32(((uint32_t)(out_param & 0xfffffffful))));
WRITE_MEM(m, MLX_HCR_BASE + 20, bswap32(((uint32_t)(token << 16))));
mbarrier();
exp_toggle ^= 1;
WRITE_MEM(m, MLX_HCR_BASE + 24,
bswap32((1 << HCR_GO_BIT) |
(exp_toggle << HCR_T_BIT) |
(event ? (1 << HCR_E_BIT) : 0) |
(op_mod << HCR_OPMOD_SHIFT) |
op));
mbarrier();
return 0;
}
static int
mlx3_mailbox_cmd_post (struct mlx3_ib * m,
uint64_t in_param,
uint64_t out_param,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
uint16_t token,
int event)
{
while (cmd_pending(m)) {
udelay(1000);
}
WRITE_MEM(m, MLX_HCR_BASE, bswap32(((uint32_t)(in_param >> 32))));
WRITE_MEM(m, MLX_HCR_BASE + 4, bswap32(((uint32_t)(in_param & 0xfffffffful))));
WRITE_MEM(m, MLX_HCR_BASE + 8, bswap32(in_mod));
WRITE_MEM(m, MLX_HCR_BASE + 12, bswap32((((uint32_t)(out_param >> 32)))));
WRITE_MEM(m, MLX_HCR_BASE + 16, bswap32(((uint32_t)(out_param & 0xfffffffful))));
WRITE_MEM(m, MLX_HCR_BASE + 20, bswap32(((uint32_t)(token << 16))));
mbarrier();
exp_toggle ^= 1;
WRITE_MEM(m, MLX_HCR_BASE + 24,
bswap32((1 << HCR_GO_BIT) |
(exp_toggle << HCR_T_BIT) |
(event ? (1 << HCR_E_BIT) : 0) |
(op_mod << HCR_OPMOD_SHIFT) |
op));
mbarrier();
return 0;
}
static int
mlx3_mailbox_cmd_poll_in (struct mlx3_ib * m,
uint64_t * in_param,
uint64_t * out_param,
int out_is_imm,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
int err = 0;
uint32_t stat;
// TODO: actually use timeout here
err = mlx3_mailbox_cmd_post(m, *in_param, out_param ? *out_param : 0,
in_mod, op_mod, op, CMD_POLL_TOKEN, 0);
if (err) {
ERROR("Could not poll mlx3\n");
return -1;
}
while (cmd_pending(m)) {
udelay(100);
}
if (out_is_imm) {
*out_param = (uint64_t)bswap32(READ_MEM(m, MLX_HCR_BASE + HCR_OUT_PARM_OFFSET)) << 32 |
(uint64_t)bswap32(READ_MEM(m, MLX_HCR_BASE + HCR_OUT_PARM_OFFSET + 4));
}
stat = bswap32(READ_MEM(m, MLX_HCR_BASE + HCR_STATUS_OFFSET)) >> HCR_STATUS_SHIFT;
if (stat) {
ERROR("Status failed with error %d\n", stat);
return -1;
}
return 0;
}
static int
mlx3_mailbox_cmd_poll_event (struct mlx3_ib * m,
uint64_t in_param,
uint64_t * out_param,
int out_is_imm,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
int err = 0;
uint32_t stat;
err = mlx3_mailbox_cmd_post(m, in_param, out_param ? *out_param : 0,
in_mod, op_mod, op, CMD_POLL_TOKEN, 1);
if (err) {
ERROR("Could not poll mlx3\n");
return -1;
}
return 0;
}
static int
mlx3_mailbox_cmd_poll (struct mlx3_ib * m,
uint64_t in_param,
uint64_t * out_param,
int out_is_imm,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
int err = 0;
uint32_t stat;
// TODO: actually use timeout here
err = mlx3_mailbox_cmd_post(m, in_param, out_param ? *out_param : 0,
in_mod, op_mod, op, CMD_POLL_TOKEN, 0);
if (err) {
ERROR("Could not poll mlx3\n");
return -1;
}
while (cmd_pending(m)) {
udelay(100);
}
if (out_is_imm) {
*out_param = (uint64_t)bswap32(READ_MEM(m, MLX_HCR_BASE + HCR_OUT_PARM_OFFSET)) << 32 |
(uint64_t)bswap32(READ_MEM(m, MLX_HCR_BASE + HCR_OUT_PARM_OFFSET + 4));
}
stat = bswap32(READ_MEM(m, MLX_HCR_BASE + HCR_STATUS_OFFSET)) >> HCR_STATUS_SHIFT;
if (stat) {
ERROR("Status failed with error %x\n", stat);
return -1;
}
return 0;
}
static int
__mlx3_cmd (struct mlx3_ib * m,
uint64_t in_param,
uint64_t *out_param,
int out_is_imm,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return mlx3_mailbox_cmd_poll(m, in_param, out_param, out_is_imm,
in_mod, op_mod, op, timeout);
}
static int
__mlx3_cmd_event (struct mlx3_ib * m,
uint64_t in_param,
uint64_t *out_param,
int out_is_imm,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return mlx3_mailbox_cmd_poll_event(m, in_param, out_param, out_is_imm,
in_mod, op_mod, op, timeout);
}
static int
__mlx3_cmd_in (struct mlx3_ib * m,
uint64_t *in_param,
uint64_t *out_param,
int out_is_imm,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return mlx3_mailbox_cmd_poll_in(m, in_param, out_param, out_is_imm,
in_mod, op_mod, op, timeout);
}
static int
mlx3_mailbox_cmd_event (struct mlx3_ib * m,
uint64_t in_param,
uint64_t out_param,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return __mlx3_cmd_event(m, in_param, &out_param, 0, in_mod, op_mod, op, timeout);
}
static int
mlx3_mailbox_cmd (struct mlx3_ib * m,
uint64_t in_param,
uint64_t out_param,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return __mlx3_cmd(m, in_param, &out_param, 0, in_mod, op_mod, op, timeout);
}
static int
mlx3_mailbox_cmd_imm (struct mlx3_ib * m,
uint64_t in_param,
uint64_t *out_param,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return __mlx3_cmd(m, in_param, out_param, 1, in_mod, op_mod, op, timeout);
}
static int
mlx3_mailbox_cmd_imm_in (struct mlx3_ib * m,
uint64_t *in_param,
uint64_t *out_param,
uint32_t in_mod,
uint8_t op_mod,
uint16_t op,
ulong_t timeout)
{
return __mlx3_cmd_in(m, in_param, out_param, 1, in_mod, op_mod, op, timeout);
}
static int
mlx3_reset (struct mlx3_ib * m)
{
int cnt = 1000;
uint32_t sem = 0;
DEBUG("Initiating card reset for ConnectX-3...\n");
// TODO: save config space
do {
sem = READ_MEM(m, MLX3_RESET_BASE + MLX3_SEM_OFF);
if (!sem) break;
udelay(1000);
} while (cnt--);
if (sem) {
ERROR("Failed to acquire HW semaphore, aborting\n");
return -1;
}
WRITE_MEM(m, MLX3_RESET_BASE + MLX3_RESET_OFF, MLX3_RESET_VAL);
// wait one second, says the hw docs
udelay(1000000);
cnt = 100;
uint16_t vendor = 0;
do {
// wait for it to respond to PCI cycles
if ((vendor = pci_dev_cfg_readw(m->dev, 0)) != 0xffff)
break;
udelay(1000);
} while (cnt--);
if (vendor == 0xffff) {
ERROR("Card failed to reset, aborting\n");
return -1;
}
// TODO: restore config headers
DEBUG("Device reset complete.\n");
return 0;
}
static int
get_mcg_log_entry_size (void)
{
// TODO: how do we actually choose this correctly?
return MLX3_DEFAULT_MGM_LOG_ENTRY_SIZE;
}
static void inline
swap (struct mlx3_rsrc* rtab_a, struct mlx3_rsrc* rtab_b)
{
struct mlx3_rsrc* tmp;
tmp = rtab_a;
rtab_a = rtab_b;
rtab_b = tmp;
}
static int
mlx3_get_icm_size (struct mlx3_ib * mlx,
uint64_t * icm_size,
struct mlx3_init_hca_param *init_hca)
{
struct mlx3_rsrc * rtab;
struct mlx3_rsrc tmp;
int i, j;
uint32_t nqp = MLX3_DEFAULT_NUM_QP;
int log_mtt_per_seg = 3;
uint64_t total_size = 0;
rtab = malloc(sizeof(struct mlx3_rsrc)*MLX3_RES_NUM);
if (!rtab) {
ERROR("Could not allocate resource table\n");
goto out_err;
}
memset(rtab, 0, sizeof(struct mlx3_rsrc) * MLX3_RES_NUM);
rtab[MLX3_RES_QP].size = mlx->caps->qpc_entry_sz;
rtab[MLX3_RES_RDMARC].size = mlx->caps->rdmardc_entry_sz;
rtab[MLX3_RES_ALTC].size = mlx->caps->altc_entry_size;
rtab[MLX3_RES_AUXC].size = mlx->caps->aux_entry_size;
rtab[MLX3_RES_SRQ].size = mlx->caps->srq_entry_sz;
rtab[MLX3_RES_CQ].size = mlx->caps->cqc_entry_sz;
rtab[MLX3_RES_EQ].size = mlx->caps->eqc_entry_sz;
rtab[MLX3_RES_DMPT].size = mlx->caps->d_mpt_entry_sz;
rtab[MLX3_RES_CMPT].size = mlx->caps->c_mpt_entry_sz;
rtab[MLX3_RES_MTT].size = mlx->caps->mtt_entry_sz;
rtab[MLX3_RES_MCG].size = 1 << get_mcg_log_entry_size();
rtab[MLX3_RES_QP].num = nqp;
rtab[MLX3_RES_RDMARC].num = nqp * MLX3_DEFAULT_RDMARC_PER_QP;
rtab[MLX3_RES_ALTC].num = nqp;
rtab[MLX3_RES_AUXC].num = nqp;
rtab[MLX3_RES_SRQ].num = MLX3_DEFAULT_NUM_SRQ;
rtab[MLX3_RES_CQ].num = MLX3_DEFAULT_NUM_CQ;
rtab[MLX3_RES_EQ].num = MLX3_MAX_NUM_EQS;
rtab[MLX3_RES_DMPT].num = MLX3_DEFAULT_NUM_MPT;
rtab[MLX3_RES_CMPT].num = MLX3_NUM_CMPTS;
rtab[MLX3_RES_MTT].num = MLX3_DEFAULT_NUM_MTT * (1<<log_mtt_per_seg);
rtab[MLX3_RES_MCG].num = MLX3_DEFAULT_NUM_MCG ;
for (i = 0; i < MLX3_RES_NUM; ++i) {
rtab[i].type = i;
rtab[i].num = roundup_pow_of_two(rtab[i].num);
rtab[i].lognum = ilog2(rtab[i].num);
rtab[i].size *= rtab[i].num;
rtab[i].size = max(rtab[i].size, (uint64_t)PAGE_SIZE_4KB);
}
/*
* Sort the resources in decreasing order of size. Since they
* all have sizes that are powers of 2, we'll be able to keep
* resources aligned to their size and pack them without gaps
* using the sorted order.
*/
for (i = 0; i < MLX3_RES_NUM; ++i) {
for (j = 1; j < MLX3_RES_NUM-i; ++j) {
if (rtab[j].size > rtab[j - 1].size) {
tmp = rtab[j];
rtab[j] = rtab[j-1];
rtab[j-1] = tmp;
}
}
}
for (i = 0; i < MLX3_RES_NUM; ++i) {
rtab[i].start = total_size;
total_size += rtab[i].size;
uint64_t max_icm_sz = mlx->caps->max_icm_sz;
if (total_size > max_icm_sz) {
ERROR("Total size (%ld) > maximum ICM size (%ld)\n", total_size, max_icm_sz);
return 0;
}
if (rtab[i].size) {
DEBUG(" resource[%2d] (%6s): 2^%02d entries @ 0x%10llx size %d KB\n",
i,
res_name[rtab[i].type],
rtab[i].lognum,
(uint64_t)rtab[i].start,
(uint64_t)rtab[i].size>>10);
}
}
for (i = 0; i < MLX3_RES_NUM; ++i) {
switch (rtab[i].type) {
case MLX3_RES_CMPT:
init_hca->cmpt_base = rtab[i].start;
break;
case MLX3_RES_CQ:
init_hca->num_cqs = rtab[i].num;
init_hca->cqc_base = rtab[i].start;
init_hca->log_num_cqs = rtab[i].lognum;
break;
case MLX3_RES_SRQ:
init_hca->num_srqs = rtab[i].num;
init_hca->srqc_base = rtab[i].start;
init_hca->log_num_srqs = rtab[i].lognum;
break;
case MLX3_RES_QP:
init_hca->num_qps = rtab[i].num;
init_hca->qpc_base = rtab[i].start;
init_hca->log_num_qps = rtab[i].lognum;
break;
case MLX3_RES_ALTC:
init_hca->altc_base = rtab[i].start;
break;
case MLX3_RES_AUXC:
init_hca->auxc_base = rtab[i].start;
break;
case MLX3_RES_MTT:
init_hca->num_mtts = rtab[i].num;
mlx->mr_table.mtt_base = rtab[i].start;
init_hca->mtt_base = rtab[i].start;
break;
case MLX3_RES_EQ:
init_hca->num_eqs = MLX3_MAX_NUM_EQS;
init_hca->eqc_base = rtab[i].start;
init_hca->log_num_eqs = ilog2(init_hca->num_eqs);
break;
case MLX3_RES_RDMARC:
for (mlx->qp_table.rdmarc_shift = 0;
MLX3_DEFAULT_NUM_QP << mlx->qp_table.rdmarc_shift < rtab[i].num;
++mlx->qp_table.rdmarc_shift) {
init_hca->max_qp_dest_rdma = 1 << mlx->qp_table.rdmarc_shift;
mlx->qp_table.rdmarc_base = (uint32_t) rtab[i].start;
init_hca->rdmarc_base = rtab[i].start;
init_hca->log_rd_per_qp = mlx->qp_table.rdmarc_shift;
}
break;
case MLX3_RES_DMPT:
init_hca->num_mpts = rtab[i].num;
mlx->mr_table.mpt_base = rtab[i].start;
init_hca->dmpt_base = rtab[i].start;
init_hca->log_mpt_sz = rtab[i].lognum;
break;
case MLX3_RES_MCG:
init_hca->mc_base = rtab[i].start;
init_hca->log_mc_entry_sz = ilog2(1 << get_mcg_log_entry_size());
init_hca->log_mc_table_sz = rtab[i].lognum;
init_hca->log_mc_hash_sz = rtab[i].lognum - 1;
init_hca->num_mgms = rtab[i].num >> 1;
init_hca->num_amgms = rtab[i].num >> 1;
break;
default:
break;
}
}
DEBUG("Max ICM Size: %ld GB\n", (mlx->caps->max_icm_sz>>30) );
DEBUG("ICM memory reserving %d GB\n", (int)(total_size>>30));
DEBUG("HCA Pages Required %d\n", (int)(total_size>>12));
*icm_size = total_size;
return 0;
out_err:
free(rtab);
return -1;
}
static int
mlx3_set_icm (struct mlx3_ib * mlx, uint64_t size, uint64_t* output)
{
uint64_t aux_pages;
int err = 0;
err = mlx3_mailbox_cmd_imm(mlx,
size,
&aux_pages,
0,
0,
CMD_SET_ICM_SIZE,
CMD_TIME_CLASS_A);
if (err) {
ERROR("Could not set ICM size\n");
return -1;
}
/*
* Round up number of system pages needed in case
* MLX3_ICM_PAGE_SIZE < PAGE_SIZE.
*/
aux_pages = ALIGN(aux_pages, PAGE_SIZE_4KB / MLX3_ICM_PAGE_SIZE) >>
(PAGE_SHIFT_4KB - MLX3_ICM_PAGE_SHIFT);
DEBUG("ICM auxilliary area requires %lu 4K pages\n", aux_pages);
*output = aux_pages;
return 0;
}
static void
dump_dev_cap_flags1 (uint64_t flags)
{
int i;
static const char * fl[32] = {
"Unicast loopback support",
"Multicast loopback support",
"", "",
"Header-data split support",
"Wake on LAN (port 1) support",
"Wake on LAN (port 2) support",
"Thermal warning event",
"UDP RSS support",
"Unicast VEP steering support",
"Multicast VEP steering support",
"VLAN steering support",
"EtherType steering support",
"WQE v1 support",
"",
"PTP1588 support",
"", "",
"QPC Ethernet user priority support",
"", "", "", "", "", "", "", "", "", "",
"64B EQE support",
"64B CQE support",
""
};
for (i = 0; i < 31; i++) {
if (i == 2 || i == 3 || i == 14 || i == 16 || i == 17 ||
(i > 18 && i < 29))
continue;
if (flags & (1<<i))
INFO(" [%s]\n", fl[i]);
}
}
static void
dump_dev_cap_flags2 (uint32_t flags)
{
int i;
static const char * fl[32] = {
"RC transport support",
"UC transport support",
"UD transport support",
"XRC transport support",
"Reliable Multicast support",
"FCoB support",
"SRQ support",
"IPoIB checksum support",
"PKey Violation Counter support",
"Qkey Violation Counter support",
"VMM support",
"FCoE support",
"DPDP support",
"Raw Ethertype support",
"Raw IPv6 support",
"LSO header support",
"Memory window support",
"Automatic Path Migration support",
"Atomic op support",
"Raw multicast support",
"AVP support",
"UD Multicast support",
"UD IPv4 Multicast support",
"DIF support",
"Paging on Demand support",
"Router mode support",
"L2 Multicast support",
"",
"UD transport SW parsing support",
"TCP checksum support for IPv6 support",
"Low Latency Ethernet support",
"FCoE T11 frame format support",
};
for (i = 0; i < 31; i++) {
if (i == 27)
continue;
if (flags & (1<<i))
INFO(" [%s]\n", fl[i]);
}
}
static void
dump_psid_entry (char * inp, int cnt, const char * desc)
{
char tmp[4] = {0,0,0,0};
int i;
if (cnt >= 4) return;
for (i = 0; i < cnt; i++)
tmp[i] = inp[i];
DEBUG("%s: %s\n", desc, tmp);
}
static void
mlx3_dump_query_adapter (struct mlx3_query_adapter * qw_adapter)
{
DEBUG("VSD ID %d\n", qw_adapter->vsd_vendor_id);
dump_psid_entry(qw_adapter->psid, 3, "Vendor Symbol");
dump_psid_entry(qw_adapter->psid + 3, 3, "Board Type Symbol");
dump_psid_entry(qw_adapter->psid + 6, 3, "Board Version Symbol");
dump_psid_entry(qw_adapter->psid + 9, 4, "Parameter Set Number");
}
static inline int
mlx3_to_hw_uar_index (struct mlx3_ib * mlx, int index)
{
return (index << (PAGE_SHIFT_4KB - DEFAULT_UAR_PAGE_SHIFT));
}
static inline int
mlx3_get_uar_eq_index (struct mlx3_ib * mlx)
{
return mlx->uar_ind_eq_db++;
}
static inline int
mlx3_alloc_uar_scq_idx (struct mlx3_ib * mlx)
{
return mlx->uar_ind_scq_db++;
}
static inline int
mlx3_alloc_dmpt (struct mlx3_ib * mlx)
{
int index = mlx->nt_rsvd_dmpt;
mlx->nt_rsvd_dmpt += 256;
return index;
}
static inline int
mlx3_alloc_qpn (struct mlx3_ib * mlx)
{
return mlx->nt_rsvd_qpn++;
}
static inline int
mlx3_alloc_cqn (struct mlx3_ib * mlx)
{
return mlx->nt_rsvd_cqn++;
}
static inline int
mlx3_alloc_eqn (struct mlx3_ib * mlx)
{
return mlx->nt_rsvd_eqn++;
}
static void
mlx3_dump_dev_cap (struct mlx3_dev_cap * cap)
{
// if (cap->log_bf_reg_size) {
// DEBUG("BlueFlame available (reg size %d, regs/page %d)\n",
// 1 << cap->log_bf_reg_size,
// 1 << cap->log_max_bf_regs_per_page);
// } else {
// DEBUG("BlueFlame unavailable\n");
// }
// DEBUG("Base MM extensions: flags : %08x, rsvd L_Key %08x\n",
// *(uint32_t*)((uint64_t)cap + 0x94),
// cap->resd_lkey);
DEBUG("Max ICM size %lld PB\n", cap->max_icm_sz>>50);
DEBUG("Max QPs: %d, reserved QPs: %d, QPC entry size: %d\n",
1<<cap->log_max_qp,
1<<cap->log2_rsvd_qps,
cap->qpc_entry_sz);
DEBUG("Max SRQs: %d, reserved SRQs: %d, entry size: %d\n",
1<<cap->log_max_srqs,
1<<cap->log2_rsvd_srqs,
cap->srq_entry_sz);
DEBUG("Max CQs: %d, reserved CQs: %d, CQC entry size: %d\n",