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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012 Milan Jurik. All rights reserved.
*/
#include <hxge_impl.h>
#include <hxge_vmac.h>
#include <hxge_pfc.h>
#include <hpi_pfc.h>
static hxge_status_t hxge_get_mac_addr_properties(p_hxge_t);
static void hxge_use_cfg_hydra_properties(p_hxge_t);
static void hxge_use_cfg_dma_config(p_hxge_t);
static void hxge_use_cfg_class_config(p_hxge_t);
static void hxge_set_hw_dma_config(p_hxge_t);
static void hxge_set_hw_class_config(p_hxge_t);
static void hxge_ldgv_setup(p_hxge_ldg_t *ldgp, p_hxge_ldv_t *ldvp, uint8_t ldv,
uint8_t endldg, int *ngrps);
extern uint16_t hxge_rcr_timeout;
extern uint16_t hxge_rcr_threshold;
extern uint32_t hxge_rbr_size;
extern uint32_t hxge_rcr_size;
extern uint_t hxge_rx_intr(caddr_t, caddr_t);
extern uint_t hxge_tx_intr(caddr_t, caddr_t);
extern uint_t hxge_vmac_intr(caddr_t, caddr_t);
extern uint_t hxge_syserr_intr(caddr_t, caddr_t);
extern uint_t hxge_pfc_intr(caddr_t, caddr_t);
/*
* Entry point to populate configuration parameters into the master hxge
* data structure and to update the NDD parameter list.
*/
hxge_status_t
hxge_get_config_properties(p_hxge_t hxgep)
{
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, VPD_CTL, " ==> hxge_get_config_properties"));
if (hxgep->hxge_hw_p == NULL) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
" hxge_get_config_properties: common hardware not set"));
return (HXGE_ERROR);
}
hxgep->classifier.tcam_size = TCAM_HXGE_TCAM_MAX_ENTRY;
status = hxge_get_mac_addr_properties(hxgep);
if (status != HXGE_OK) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
" hxge_get_config_properties: mac addr properties failed"));
return (status);
}
HXGE_DEBUG_MSG((hxgep, VPD_CTL,
" ==> hxge_get_config_properties: Hydra"));
hxge_use_cfg_hydra_properties(hxgep);
HXGE_DEBUG_MSG((hxgep, VPD_CTL, " <== hxge_get_config_properties"));
return (HXGE_OK);
}
static void
hxge_set_hw_vlan_class_config(p_hxge_t hxgep)
{
int i;
p_hxge_param_t param_arr;
uint_t vlan_cnt;
int *vlan_cfg_val;
hxge_param_map_t *vmap;
char *prop;
p_hxge_class_pt_cfg_t p_class_cfgp;
uint32_t good_cfg[32];
int good_count = 0;
hxge_mv_cfg_t *vlan_tbl;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " ==> hxge_set_hw_vlan_config"));
p_class_cfgp = (p_hxge_class_pt_cfg_t)&hxgep->class_config;
param_arr = hxgep->param_arr;
prop = param_arr[param_vlan_ids].fcode_name;
/*
* uint32_t array, each array entry specifying a VLAN id
*/
for (i = 0; i <= VLAN_ID_MAX; i++) {
p_class_cfgp->vlan_tbl[i].flag = 0;
}
vlan_tbl = (hxge_mv_cfg_t *)&p_class_cfgp->vlan_tbl[0];
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, hxgep->dip, 0, prop,
&vlan_cfg_val, &vlan_cnt) != DDI_PROP_SUCCESS) {
return;
}
for (i = 0; i < vlan_cnt; i++) {
vmap = (hxge_param_map_t *)&vlan_cfg_val[i];
if ((vmap->param_id) && (vmap->param_id <= VLAN_ID_MAX)) {
HXGE_DEBUG_MSG((hxgep, CFG2_CTL,
" hxge_vlan_config vlan id %d", vmap->param_id));
good_cfg[good_count] = vlan_cfg_val[i];
if (vlan_tbl[vmap->param_id].flag == 0)
good_count++;
vlan_tbl[vmap->param_id].flag = 1;
}
}
ddi_prop_free(vlan_cfg_val);
if (good_count != vlan_cnt) {
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
hxgep->dip, prop, (int *)good_cfg, good_count);
}
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " <== hxge_set_hw_vlan_config"));
}
/*
* Read param_vlan_ids and param_implicit_vlan_id properties from either
* hxge.conf or OBP. Update the soft properties. Populate these
* properties into the hxge data structure.
*/
static void
hxge_use_cfg_vlan_class_config(p_hxge_t hxgep)
{
uint_t vlan_cnt;
int *vlan_cfg_val;
int status;
p_hxge_param_t param_arr;
char *prop;
uint32_t implicit_vlan_id = 0;
int *int_prop_val;
uint_t prop_len;
p_hxge_param_t pa;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " ==> hxge_use_cfg_vlan_config"));
param_arr = hxgep->param_arr;
prop = param_arr[param_vlan_ids].fcode_name;
status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, hxgep->dip, 0, prop,
&vlan_cfg_val, &vlan_cnt);
if (status == DDI_PROP_SUCCESS) {
status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
hxgep->dip, prop, vlan_cfg_val, vlan_cnt);
ddi_prop_free(vlan_cfg_val);
}
pa = ¶m_arr[param_implicit_vlan_id];
prop = pa->fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, hxgep->dip, 0, prop,
&int_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
implicit_vlan_id = (uint32_t)*int_prop_val;
if ((implicit_vlan_id >= pa->minimum) ||
(implicit_vlan_id <= pa->maximum)) {
status = ddi_prop_update_int(DDI_DEV_T_NONE, hxgep->dip,
prop, (int)implicit_vlan_id);
}
ddi_prop_free(int_prop_val);
}
hxge_set_hw_vlan_class_config(hxgep);
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " <== hxge_use_cfg_vlan_config"));
}
/*
* Read in the configuration parameters from either hxge.conf or OBP and
* populate the master data structure hxge.
* Use these parameters to update the soft properties and the ndd array.
*/
static void
hxge_use_cfg_hydra_properties(p_hxge_t hxgep)
{
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " ==> hxge_use_cfg_hydra_properties"));
(void) hxge_use_cfg_dma_config(hxgep);
(void) hxge_use_cfg_vlan_class_config(hxgep);
(void) hxge_use_cfg_class_config(hxgep);
/*
* Read in the hardware (fcode) properties and use these properties
* to update the ndd array.
*/
(void) hxge_get_param_soft_properties(hxgep);
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " <== hxge_use_cfg_hydra_properties"));
}
/*
* Read param_accept_jumbo, param_rxdma_intr_time, and param_rxdma_intr_pkts
* from either hxge.conf or OBP.
* Update the soft properties.
* Populate these properties into the hxge data structure for latter use.
*/
static void
hxge_use_cfg_dma_config(p_hxge_t hxgep)
{
int tx_ndmas, rx_ndmas;
p_hxge_dma_pt_cfg_t p_dma_cfgp;
p_hxge_hw_pt_cfg_t p_cfgp;
dev_info_t *dip;
p_hxge_param_t param_arr;
char *prop;
int *prop_val;
uint_t prop_len;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " ==> hxge_use_cfg_dma_config"));
param_arr = hxgep->param_arr;
p_dma_cfgp = (p_hxge_dma_pt_cfg_t)&hxgep->pt_config;
p_cfgp = (p_hxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
dip = hxgep->dip;
tx_ndmas = 4;
p_cfgp->start_tdc = 0;
p_cfgp->max_tdcs = hxgep->max_tdcs = tx_ndmas;
hxgep->tdc_mask = (tx_ndmas - 1);
HXGE_DEBUG_MSG((hxgep, CFG_CTL, "==> hxge_use_cfg_dma_config: "
"p_cfgp 0x%llx max_tdcs %d hxgep->max_tdcs %d",
p_cfgp, p_cfgp->max_tdcs, hxgep->max_tdcs));
rx_ndmas = 4;
p_cfgp->start_rdc = 0;
p_cfgp->max_rdcs = hxgep->max_rdcs = rx_ndmas;
p_cfgp->start_ldg = 0;
p_cfgp->max_ldgs = HXGE_INT_MAX_LDG;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, "==> hxge_use_default_dma_config: "
"p_cfgp 0x%llx max_rdcs %d hxgep->max_rdcs %d",
p_cfgp, p_cfgp->max_rdcs, hxgep->max_rdcs));
HXGE_DEBUG_MSG((hxgep, CFG_CTL, "==> hxge_use_cfg_dma_config: "
"p_cfgp 0x%016llx start_ldg %d hxgep->max_ldgs %d ",
p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs));
/*
* add code for individual rdc properties
*/
prop = param_arr[param_accept_jumbo].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
hxgep->dip, prop, prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
prop = param_arr[param_rxdma_intr_time].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
hxgep->dip, prop, prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
prop = param_arr[param_rxdma_intr_pkts].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
hxgep->dip, prop, prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
hxge_set_hw_dma_config(hxgep);
HXGE_DEBUG_MSG((hxgep, CFG_CTL, "<== hxge_use_cfg_dma_config"));
}
static void
hxge_use_cfg_class_config(p_hxge_t hxgep)
{
hxge_set_hw_class_config(hxgep);
}
static void
hxge_set_hw_dma_config(p_hxge_t hxgep)
{
p_hxge_dma_pt_cfg_t p_dma_cfgp;
p_hxge_hw_pt_cfg_t p_cfgp;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, "==> hxge_set_hw_dma_config"));
p_dma_cfgp = (p_hxge_dma_pt_cfg_t)&hxgep->pt_config;
p_cfgp = (p_hxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
/* Transmit DMA Channels */
hxgep->ntdc = p_cfgp->max_tdcs;
/* Receive DMA Channels */
hxgep->nrdc = p_cfgp->max_rdcs;
p_dma_cfgp->rbr_size = hxge_rbr_size;
if (hxge_rcr_size > HXGE_RCR_MAX)
hxge_rcr_size = HXGE_RCR_MAX;
p_dma_cfgp->rcr_size = hxge_rcr_size;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " <== hxge_set_hw_dma_config"));
}
boolean_t
hxge_check_rxdma_port_member(p_hxge_t hxgep, uint8_t rdc)
{
p_hxge_dma_pt_cfg_t p_dma_cfgp;
p_hxge_hw_pt_cfg_t p_cfgp;
int status = B_TRUE;
HXGE_DEBUG_MSG((hxgep, CFG2_CTL, "==> hxge_check_rxdma_port_member"));
p_dma_cfgp = (p_hxge_dma_pt_cfg_t)&hxgep->pt_config;
p_cfgp = (p_hxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
/* Receive DMA Channels */
if (rdc < p_cfgp->max_rdcs)
status = B_TRUE;
HXGE_DEBUG_MSG((hxgep, CFG2_CTL, " <== hxge_check_rxdma_port_member"));
return (status);
}
boolean_t
hxge_check_txdma_port_member(p_hxge_t hxgep, uint8_t tdc)
{
p_hxge_dma_pt_cfg_t p_dma_cfgp;
p_hxge_hw_pt_cfg_t p_cfgp;
int status = B_FALSE;
HXGE_DEBUG_MSG((hxgep, CFG2_CTL, "==> hxge_check_txdma_port_member"));
p_dma_cfgp = (p_hxge_dma_pt_cfg_t)&hxgep->pt_config;
p_cfgp = (p_hxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
/* Receive DMA Channels */
if (tdc < p_cfgp->max_tdcs)
status = B_TRUE;
HXGE_DEBUG_MSG((hxgep, CFG2_CTL, " <== hxge_check_txdma_port_member"));
return (status);
}
/*
* Read the L2 classes, L3 classes, and initial hash from either hxge.conf
* or OBP. Populate these properties into the hxge data structure for latter
* use. Note that we are not updating these soft properties.
*/
static void
hxge_set_hw_class_config(p_hxge_t hxgep)
{
int i, j;
p_hxge_param_t param_arr;
int *int_prop_val;
uint32_t cfg_value;
char *prop;
p_hxge_class_pt_cfg_t p_class_cfgp;
int start_prop, end_prop;
uint_t prop_cnt;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " ==> hxge_set_hw_class_config"));
p_class_cfgp = (p_hxge_class_pt_cfg_t)&hxgep->class_config;
param_arr = hxgep->param_arr;
/*
* L2 class configuration. User configurable ether types
*/
start_prop = param_class_cfg_ether_usr1;
end_prop = param_class_cfg_ether_usr2;
for (i = start_prop; i <= end_prop; i++) {
prop = param_arr[i].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, hxgep->dip,
0, prop, &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
cfg_value = (uint32_t)*int_prop_val;
ddi_prop_free(int_prop_val);
} else {
cfg_value = (uint32_t)param_arr[i].value;
}
j = (i - start_prop) + TCAM_CLASS_ETYPE_1;
p_class_cfgp->class_cfg[j] = cfg_value;
}
/*
* Use properties from either .conf or the NDD param array. Only bits
* 2 and 3 are significant
*/
start_prop = param_class_opt_ipv4_tcp;
end_prop = param_class_opt_ipv6_sctp;
for (i = start_prop; i <= end_prop; i++) {
prop = param_arr[i].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, hxgep->dip,
0, prop, &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
cfg_value = (uint32_t)*int_prop_val;
ddi_prop_free(int_prop_val);
} else {
cfg_value = (uint32_t)param_arr[i].value;
}
j = (i - start_prop) + TCAM_CLASS_TCP_IPV4;
p_class_cfgp->class_cfg[j] = cfg_value;
}
prop = param_arr[param_hash_init_value].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, hxgep->dip, 0, prop,
&int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
cfg_value = (uint32_t)*int_prop_val;
ddi_prop_free(int_prop_val);
} else {
cfg_value = (uint32_t)param_arr[param_hash_init_value].value;
}
p_class_cfgp->init_hash = (uint32_t)cfg_value;
HXGE_DEBUG_MSG((hxgep, CFG_CTL, " <== hxge_set_hw_class_config"));
}
/*
* Interrupts related interface functions.
*/
hxge_status_t
hxge_ldgv_init(p_hxge_t hxgep, int *navail_p, int *nrequired_p)
{
uint8_t ldv, i, maxldvs, maxldgs, start, end, nldvs;
int ldg, endldg, ngrps;
uint8_t channel;
p_hxge_dma_pt_cfg_t p_dma_cfgp;
p_hxge_hw_pt_cfg_t p_cfgp;
p_hxge_ldgv_t ldgvp;
p_hxge_ldg_t ldgp, ptr;
p_hxge_ldv_t ldvp;
hxge_status_t status = HXGE_OK;
peu_intr_mask_t parity_err_mask;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_ldgv_init"));
if (!*navail_p) {
*nrequired_p = 0;
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_ldgv_init:no avail"));
return (HXGE_ERROR);
}
p_dma_cfgp = (p_hxge_dma_pt_cfg_t)&hxgep->pt_config;
p_cfgp = (p_hxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
/* each DMA channels */
nldvs = p_cfgp->max_tdcs + p_cfgp->max_rdcs;
/* vmac */
nldvs++;
/* pfc */
nldvs++;
/* system error interrupts. */
nldvs++;
maxldvs = nldvs;
maxldgs = p_cfgp->max_ldgs;
if (!maxldvs || !maxldgs) {
/* No devices configured. */
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "<== hxge_ldgv_init: "
"no logical devices or groups configured."));
return (HXGE_ERROR);
}
ldgvp = hxgep->ldgvp;
if (ldgvp == NULL) {
ldgvp = KMEM_ZALLOC(sizeof (hxge_ldgv_t), KM_SLEEP);
hxgep->ldgvp = ldgvp;
ldgvp->maxldgs = maxldgs;
ldgvp->maxldvs = maxldvs;
ldgp = ldgvp->ldgp =
KMEM_ZALLOC(sizeof (hxge_ldg_t) * maxldgs, KM_SLEEP);
ldvp = ldgvp->ldvp =
KMEM_ZALLOC(sizeof (hxge_ldv_t) * maxldvs, KM_SLEEP);
}
ldgvp->ndma_ldvs = p_cfgp->max_tdcs + p_cfgp->max_rdcs;
ldgvp->tmres = HXGE_TIMER_RESO;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_ldgv_init: maxldvs %d maxldgs %d nldvs %d",
maxldvs, maxldgs, nldvs));
ldg = p_cfgp->start_ldg;
ptr = ldgp;
for (i = 0; i < maxldgs; i++) {
ptr->arm = B_TRUE;
ptr->vldg_index = i;
ptr->ldg_timer = HXGE_TIMER_LDG;
ptr->ldg = ldg++;
ptr->sys_intr_handler = hxge_intr;
ptr->nldvs = 0;
ptr->hxgep = hxgep;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_ldgv_init: maxldvs %d maxldgs %d ldg %d",
maxldvs, maxldgs, ptr->ldg));
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_ldv_init: timer %d", ptr->ldg_timer));
ptr++;
}
ldg = p_cfgp->start_ldg;
if (maxldgs > *navail_p) {
ngrps = *navail_p;
} else {
ngrps = maxldgs;
}
endldg = ldg + ngrps;
/*
* Receive DMA channels.
*/
channel = p_cfgp->start_rdc;
start = p_cfgp->start_rdc + HXGE_RDMA_LD_START;
end = start + p_cfgp->max_rdcs;
nldvs = 0;
ldgvp->nldvs = 0;
ldgp->ldvp = NULL;
*nrequired_p = 0;
ptr = ldgp;
/*
* Start with RDC to configure logical devices for each group.
*/
for (i = 0, ldv = start; ldv < end; i++, ldv++) {
ldvp->is_rxdma = B_TRUE;
ldvp->ldv = ldv;
/*
* If non-seq needs to change the following code
*/
ldvp->channel = channel++;
ldvp->vdma_index = i;
ldvp->ldv_intr_handler = hxge_rx_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->use_timer = B_FALSE;
ldvp->hxgep = hxgep;
hxge_ldgv_setup(&ptr, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
}
/*
* Transmit DMA channels.
*/
channel = p_cfgp->start_tdc;
start = p_cfgp->start_tdc + HXGE_TDMA_LD_START;
end = start + p_cfgp->max_tdcs;
for (i = 0, ldv = start; ldv < end; i++, ldv++) {
ldvp->is_txdma = B_TRUE;
ldvp->ldv = ldv;
ldvp->channel = channel++;
ldvp->vdma_index = i;
ldvp->ldv_intr_handler = hxge_tx_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->use_timer = B_FALSE;
ldvp->hxgep = hxgep;
hxge_ldgv_setup(&ptr, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
}
/*
* VMAC
*/
ldvp->is_vmac = B_TRUE;
ldvp->ldv_intr_handler = hxge_vmac_intr;
ldvp->ldv_ldf_masks = 0;
ldv = HXGE_VMAC_LD;
ldvp->ldv = ldv;
ldvp->use_timer = B_FALSE;
ldvp->hxgep = hxgep;
hxge_ldgv_setup(&ptr, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_ldgv_init: nldvs %d navail %d nrequired %d",
nldvs, *navail_p, *nrequired_p));
/*
* PFC
*/
ldvp->is_pfc = B_TRUE;
ldvp->ldv_intr_handler = hxge_pfc_intr;
ldvp->ldv_ldf_masks = 0;
ldv = HXGE_PFC_LD;
ldvp->ldv = ldv;
ldvp->use_timer = B_FALSE;
ldvp->hxgep = hxgep;
hxge_ldgv_setup(&ptr, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_ldgv_init: nldvs %d navail %d nrequired %d",
nldvs, *navail_p, *nrequired_p));
/*
* System error interrupts.
*/
ldv = HXGE_SYS_ERROR_LD;
ldvp->ldv = ldv;
ldvp->is_syserr = B_TRUE;
ldvp->ldv_intr_handler = hxge_syserr_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->hxgep = hxgep;
ldvp->use_timer = B_FALSE;
ldgvp->ldvp_syserr = ldvp;
/* Reset PEU error mask to allow PEU error interrupts */
/*
* Keep the msix parity error mask here and remove it
* after ddi_intr_enable call to avoid a msix par err
*/
parity_err_mask.value = 0;
parity_err_mask.bits.eic_msix_parerr_mask = 1;
HXGE_REG_WR32(hxgep->hpi_handle, PEU_INTR_MASK, parity_err_mask.value);
/*
* Unmask the system interrupt states.
*/
(void) hxge_fzc_sys_err_mask_set(hxgep, B_FALSE);
(void) hxge_ldgv_setup(&ptr, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
ldgvp->ldg_intrs = *nrequired_p;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_ldgv_init: nldvs %d navail %d nrequired %d",
nldvs, *navail_p, *nrequired_p));
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_ldgv_init"));
return (status);
}
hxge_status_t
hxge_ldgv_uninit(p_hxge_t hxgep)
{
p_hxge_ldgv_t ldgvp;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_ldgv_uninit"));
ldgvp = hxgep->ldgvp;
if (ldgvp == NULL) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_ldgv_uninit: no logical group configured."));
return (HXGE_OK);
}
if (ldgvp->ldgp) {
KMEM_FREE(ldgvp->ldgp, sizeof (hxge_ldg_t) * ldgvp->maxldgs);
}
if (ldgvp->ldvp) {
KMEM_FREE(ldgvp->ldvp, sizeof (hxge_ldv_t) * ldgvp->maxldvs);
}
KMEM_FREE(ldgvp, sizeof (hxge_ldgv_t));
hxgep->ldgvp = NULL;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_ldgv_uninit"));
return (HXGE_OK);
}
hxge_status_t
hxge_intr_ldgv_init(p_hxge_t hxgep)
{
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr_ldgv_init"));
/*
* Configure the logical device group numbers, state vectors
* and interrupt masks for each logical device.
*/
status = hxge_fzc_intr_init(hxgep);
/*
* Configure logical device masks and timers.
*/
status = hxge_intr_mask_mgmt(hxgep);
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_intr_ldgv_init"));
return (status);
}
hxge_status_t
hxge_intr_mask_mgmt(p_hxge_t hxgep)
{
p_hxge_ldgv_t ldgvp;
p_hxge_ldg_t ldgp;
p_hxge_ldv_t ldvp;
hpi_handle_t handle;
int i, j;
hpi_status_t rs = HPI_SUCCESS;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr_mask_mgmt"));
if ((ldgvp = hxgep->ldgvp) == NULL) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_intr_mask_mgmt: Null ldgvp"));
return (HXGE_ERROR);
}
handle = HXGE_DEV_HPI_HANDLE(hxgep);
ldgp = ldgvp->ldgp;
ldvp = ldgvp->ldvp;
if (ldgp == NULL || ldvp == NULL) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_intr_mask_mgmt: Null ldgp or ldvp"));
return (HXGE_ERROR);
}
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt: # of intrs %d ", ldgvp->ldg_intrs));
/* Initialize masks. */
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt(Hydra): # intrs %d ", ldgvp->ldg_intrs));
for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt(Hydra): # ldv %d in group %d",
ldgp->nldvs, ldgp->ldg));
for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt: set ldv # %d "
"for ldg %d", ldvp->ldv, ldgp->ldg));
rs = hpi_intr_mask_set(handle, ldvp->ldv,
ldvp->ldv_ldf_masks);
if (rs != HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_intr_mask_mgmt: set mask failed "
" rs 0x%x ldv %d mask 0x%x",
rs, ldvp->ldv, ldvp->ldv_ldf_masks));
return (HXGE_ERROR | rs);
}
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt: set mask OK "
" rs 0x%x ldv %d mask 0x%x",
rs, ldvp->ldv, ldvp->ldv_ldf_masks));
}
}
ldgp = ldgvp->ldgp;
/* Configure timer and arm bit */
for (i = 0; i < hxgep->ldgvp->ldg_intrs; i++, ldgp++) {
rs = hpi_intr_ldg_mgmt_set(handle, ldgp->ldg,
ldgp->arm, ldgp->ldg_timer);
if (rs != HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_intr_mask_mgmt: set timer failed "
" rs 0x%x dg %d timer 0x%x",
rs, ldgp->ldg, ldgp->ldg_timer));
return (HXGE_ERROR | rs);
}
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt: set timer OK "
" rs 0x%x ldg %d timer 0x%x",
rs, ldgp->ldg, ldgp->ldg_timer));
}
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_fzc_intr_mask_mgmt"));
return (HXGE_OK);
}
hxge_status_t
hxge_intr_mask_mgmt_set(p_hxge_t hxgep, boolean_t on)
{
p_hxge_ldgv_t ldgvp;
p_hxge_ldg_t ldgp;
p_hxge_ldv_t ldvp;
hpi_handle_t handle;
int i, j;
hpi_status_t rs = HPI_SUCCESS;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set (%d)", on));
if ((ldgvp = hxgep->ldgvp) == NULL) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_intr_mask_mgmt_set: Null ldgvp"));
return (HXGE_ERROR);
}
handle = HXGE_DEV_HPI_HANDLE(hxgep);
ldgp = ldgvp->ldgp;
ldvp = ldgvp->ldvp;
if (ldgp == NULL || ldvp == NULL) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_intr_mask_mgmt_set: Null ldgp or ldvp"));
return (HXGE_ERROR);
}
/* set masks. */
for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set: flag %d ldg %d"
"set mask nldvs %d", on, ldgp->ldg, ldgp->nldvs));
for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set: "
"for %d %d flag %d", i, j, on));
if (on) {
ldvp->ldv_ldf_masks = 0;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set: "
"ON mask off"));
} else {
ldvp->ldv_ldf_masks = (uint8_t)LD_IM_MASK;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set:mask on"));
}
rs = hpi_intr_mask_set(handle, ldvp->ldv,
ldvp->ldv_ldf_masks);
if (rs != HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_intr_mask_mgmt_set: "
"set mask failed rs 0x%x ldv %d mask 0x%x",
rs, ldvp->ldv, ldvp->ldv_ldf_masks));
return (HXGE_ERROR | rs);
}
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set: flag %d"
"set mask OK ldv %d mask 0x%x",
on, ldvp->ldv, ldvp->ldv_ldf_masks));
}
}
ldgp = ldgvp->ldgp;
/* set the arm bit */
for (i = 0; i < hxgep->ldgvp->ldg_intrs; i++, ldgp++) {
if (on && !ldgp->arm) {
ldgp->arm = B_TRUE;
} else if (!on && ldgp->arm) {
ldgp->arm = B_FALSE;
}
rs = hpi_intr_ldg_mgmt_set(handle, ldgp->ldg,
ldgp->arm, ldgp->ldg_timer);
if (rs != HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_intr_mask_mgmt_set: "
"set timer failed rs 0x%x ldg %d timer 0x%x",
rs, ldgp->ldg, ldgp->ldg_timer));
return (HXGE_ERROR | rs);
}
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_intr_mask_mgmt_set: OK (flag %d) "
"set timer ldg %d timer 0x%x",
on, ldgp->ldg, ldgp->ldg_timer));
}
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_intr_mask_mgmt_set"));
return (HXGE_OK);
}
/*
* For Big Endian systems, the mac address will be from OBP. For Little
* Endian (x64) systems, it will be retrieved from the card since it cannot
* be programmed into PXE.
* This function also populates the MMAC parameters.
*/
static hxge_status_t
hxge_get_mac_addr_properties(p_hxge_t hxgep)
{
HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_get_mac_addr_properties "));
(void) hxge_pfc_mac_addrs_get(hxgep);
hxgep->ouraddr = hxgep->factaddr;
HXGE_DEBUG_MSG((hxgep, DDI_CTL, "<== hxge_get_mac_addr_properties "));
return (HXGE_OK);
}
static void
hxge_ldgv_setup(p_hxge_ldg_t *ldgp, p_hxge_ldv_t *ldvp, uint8_t ldv,
uint8_t endldg, int *ngrps)
{
HXGE_DEBUG_MSG((NULL, INT_CTL, "==> hxge_ldgv_setup"));
/* Assign the group number for each device. */
(*ldvp)->ldg_assigned = (*ldgp)->ldg;
(*ldvp)->ldgp = *ldgp;
(*ldvp)->ldv = ldv;
HXGE_DEBUG_MSG((NULL, INT_CTL,
"==> hxge_ldgv_setup: ldv %d endldg %d ldg %d, ldvp $%p",
ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
(*ldgp)->nldvs++;
if ((*ldgp)->ldg == (endldg - 1)) {
if ((*ldgp)->ldvp == NULL) {
(*ldgp)->ldvp = *ldvp;
*ngrps += 1;
HXGE_DEBUG_MSG((NULL, INT_CTL,
"==> hxge_ldgv_setup: ngrps %d", *ngrps));
}
HXGE_DEBUG_MSG((NULL, INT_CTL,
"==> hxge_ldgv_setup: ldvp $%p ngrps %d",
*ldvp, *ngrps));
++*ldvp;
} else {
(*ldgp)->ldvp = *ldvp;
*ngrps += 1;
HXGE_DEBUG_MSG((NULL, INT_CTL, "==> hxge_ldgv_setup(done): "
"ldv %d endldg %d ldg %d, ldvp $%p",
ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
++*ldvp;
++*ldgp;
HXGE_DEBUG_MSG((NULL, INT_CTL,
"==> hxge_ldgv_setup: new ngrps %d", *ngrps));
}
HXGE_DEBUG_MSG((NULL, INT_CTL, "==> hxge_ldgv_setup: "
"ldg %d nldvs %d ldv %d ldvp $%p endldg %d ngrps %d",
(*ldgp)->ldg, (*ldgp)->nldvs, ldv, ldvp, endldg, *ngrps));
HXGE_DEBUG_MSG((NULL, INT_CTL, "<== hxge_ldgv_setup"));
}
|