1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include <sys/nxge/nxge_impl.h>
26 #include <sys/nxge/nxge_mac.h>
27 #include <sys/nxge/nxge_hio.h>
28
29 /*
30 * Local defines for FWARC 2006/556
31 */
32 #define NXGE_NIU_TDMA_PROP_LEN 2
33 #define NXGE_NIU_RDMA_PROP_LEN 2
34 #define NXGE_NIU_0_INTR_PROP_LEN 19
35 #define NXGE_NIU_1_INTR_PROP_LEN 17
36
37 /*
38 * Local functions.
39 */
40 static void nxge_get_niu_property(dev_info_t *, niu_type_t *);
41 static nxge_status_t nxge_get_mac_addr_properties(p_nxge_t);
42 static nxge_status_t nxge_use_cfg_n2niu_properties(p_nxge_t);
43 static void nxge_use_cfg_neptune_properties(p_nxge_t);
44 static void nxge_use_cfg_dma_config(p_nxge_t);
45 static void nxge_use_cfg_vlan_class_config(p_nxge_t);
46 static void nxge_use_cfg_mac_class_config(p_nxge_t);
47 static void nxge_use_cfg_class_config(p_nxge_t);
48 static void nxge_use_cfg_link_cfg(p_nxge_t);
49 static void nxge_set_hw_dma_config(p_nxge_t);
50 static void nxge_set_hw_vlan_class_config(p_nxge_t);
51 static void nxge_set_hw_mac_class_config(p_nxge_t);
52 static void nxge_set_hw_class_config(p_nxge_t);
53 static nxge_status_t nxge_use_default_dma_config_n2(p_nxge_t);
54 static void nxge_ldgv_setup(p_nxge_ldg_t *, p_nxge_ldv_t *, uint8_t,
55 uint8_t, int *);
56 static void nxge_init_mmac(p_nxge_t, boolean_t);
57 static void nxge_set_rdc_intr_property(p_nxge_t);
58
59 uint32_t nxge_use_hw_property = 1;
60 uint32_t nxge_groups_per_port = 2;
61
62 extern uint32_t nxge_use_partition;
63 extern uint32_t nxge_dma_obp_props_only;
64
65 extern uint_t nxge_rx_intr(char *, char *);
66 extern uint_t nxge_tx_intr(char *, char *);
67 extern uint_t nxge_mif_intr(char *, char *);
68 extern uint_t nxge_mac_intr(char *, char *);
69 extern uint_t nxge_syserr_intr(char *, char *);
70 extern void *nxge_list;
71
72 #define NXGE_SHARED_REG_SW_SIM
73
74 #ifdef NXGE_SHARED_REG_SW_SIM
75 uint64_t global_dev_ctrl = 0;
76 #endif
77
78 #define MAX_SIBLINGS NXGE_MAX_PORTS
79
80 extern uint32_t nxge_rbr_size;
81 extern uint32_t nxge_rcr_size;
82 extern uint32_t nxge_tx_ring_size;
83 extern uint32_t nxge_rbr_spare_size;
84
85 extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t);
86
87 static uint8_t p2_tx_fair[2] = {12, 12};
88 static uint8_t p2_tx_equal[2] = {12, 12};
89 static uint8_t p4_tx_fair[4] = {6, 6, 6, 6};
90 static uint8_t p4_tx_equal[4] = {6, 6, 6, 6};
91 static uint8_t p2_rx_fair[2] = {8, 8};
92 static uint8_t p2_rx_equal[2] = {8, 8};
93 static uint8_t p4_rx_fair[4] = {4, 4, 4, 4};
94 static uint8_t p4_rx_equal[4] = {4, 4, 4, 4};
95
96 static uint8_t p2_rdcgrp_fair[2] = {4, 4};
97 static uint8_t p2_rdcgrp_equal[2] = {4, 4};
98 static uint8_t p4_rdcgrp_fair[4] = {2, 2, 1, 1};
99 static uint8_t p4_rdcgrp_equal[4] = {2, 2, 2, 2};
100 static uint8_t p2_rdcgrp_cls[2] = {1, 1};
101 static uint8_t p4_rdcgrp_cls[4] = {1, 1, 1, 1};
102
103 static uint8_t rx_4_1G[4] = {4, 4, 4, 4};
104 static uint8_t rx_2_10G[2] = {8, 8};
105 static uint8_t rx_2_10G_2_1G[4] = {6, 6, 2, 2};
106 static uint8_t rx_1_10G_3_1G[4] = {10, 2, 2, 2};
107 static uint8_t rx_1_1G_1_10G_2_1G[4] = {2, 10, 2, 2};
108
109 static uint8_t tx_4_1G[4] = {6, 6, 6, 6};
110 static uint8_t tx_2_10G[2] = {12, 12};
111 static uint8_t tx_2_10G_2_1G[4] = {10, 10, 2, 2};
112 static uint8_t tx_1_10G_3_1G[4] = {12, 4, 4, 4};
113 static uint8_t tx_1_1G_1_10G_2_1G[4] = {4, 12, 4, 4};
114
115 typedef enum {
116 DEFAULT = 0,
117 EQUAL,
118 FAIR,
119 CUSTOM,
120 CLASSIFY,
121 L2_CLASSIFY,
122 L3_DISTRIBUTE,
123 L3_CLASSIFY,
124 L3_TCAM,
125 CONFIG_TOKEN_NONE
126 } config_token_t;
127
128 static char *token_names[] = {
129 "default",
130 "equal",
131 "fair",
132 "custom",
133 "classify",
134 "l2_classify",
135 "l3_distribute",
136 "l3_classify",
137 "l3_tcam",
138 "none",
139 };
140
141 void nxge_virint_regs_dump(p_nxge_t nxgep);
142
143 void
nxge_virint_regs_dump(p_nxge_t nxgep)144 nxge_virint_regs_dump(p_nxge_t nxgep)
145 {
146 npi_handle_t handle;
147
148 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_virint_regs_dump"));
149 handle = NXGE_DEV_NPI_HANDLE(nxgep);
150 (void) npi_vir_dump_pio_fzc_regs_one(handle);
151 (void) npi_vir_dump_ldgnum(handle);
152 (void) npi_vir_dump_ldsv(handle);
153 (void) npi_vir_dump_imask0(handle);
154 (void) npi_vir_dump_sid(handle);
155 (void) npi_mac_dump_regs(handle, nxgep->function_num);
156 (void) npi_ipp_dump_regs(handle, nxgep->function_num);
157 (void) npi_fflp_dump_regs(handle);
158 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_virint_regs_dump"));
159 }
160
161 /*
162 * For now: we hard coded the DMA configurations.
163 * and assume for one partition only.
164 *
165 * OBP. Then OBP will pass this partition's
166 * Neptune configurations to fcode to create
167 * properties for them.
168 *
169 * Since Neptune(PCI-E) and NIU (Niagara-2) has
170 * different bus interfaces, the driver needs
171 * to know which bus it is connected to.
172 * Ravinder suggested: create a device property.
173 * In partitioning environment, we cannot
174 * use .conf file (need to check). If conf changes,
175 * need to reboot the system.
176 * The following function assumes that we will
177 * retrieve its properties from a virtualized nexus driver.
178 */
179
180 nxge_status_t
nxge_cntlops(dev_info_t * dip,nxge_ctl_enum_t ctlop,void * arg,void * result)181 nxge_cntlops(dev_info_t *dip, nxge_ctl_enum_t ctlop, void *arg, void *result)
182 {
183 nxge_status_t status = NXGE_OK;
184 int instance;
185 p_nxge_t nxgep;
186
187 #ifndef NXGE_SHARED_REG_SW_SIM
188 npi_handle_t handle;
189 uint16_t sr16, cr16;
190 #endif
191 instance = ddi_get_instance(dip);
192 NXGE_DEBUG_MSG((NULL, VIR_CTL, "Instance %d ", instance));
193
194 if (nxge_list == NULL) {
195 NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
196 "nxge_cntlops: nxge_list null"));
197 return (NXGE_ERROR);
198 }
199 nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance);
200 if (nxgep == NULL) {
201 NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
202 "nxge_cntlops: nxgep null"));
203 return (NXGE_ERROR);
204 }
205 #ifndef NXGE_SHARED_REG_SW_SIM
206 handle = nxgep->npi_reg_handle;
207 #endif
208 switch (ctlop) {
209 case NXGE_CTLOPS_NIUTYPE:
210 nxge_get_niu_property(dip, (niu_type_t *)result);
211 return (status);
212
213 case NXGE_CTLOPS_GET_SHARED_REG:
214 #ifdef NXGE_SHARED_REG_SW_SIM
215 *(uint64_t *)result = global_dev_ctrl;
216 return (0);
217 #else
218 status = npi_dev_func_sr_sr_get(handle, &sr16);
219 *(uint16_t *)result = sr16;
220 NXGE_DEBUG_MSG((NULL, VIR_CTL,
221 "nxge_cntlops: NXGE_CTLOPS_GET_SHARED_REG"));
222 return (0);
223 #endif
224
225 case NXGE_CTLOPS_SET_SHARED_REG_LOCK:
226 #ifdef NXGE_SHARED_REG_SW_SIM
227 global_dev_ctrl = *(uint64_t *)arg;
228 return (0);
229 #else
230 status = NPI_FAILURE;
231 while (status != NPI_SUCCESS)
232 status = npi_dev_func_sr_lock_enter(handle);
233
234 sr16 = *(uint16_t *)arg;
235 status = npi_dev_func_sr_sr_set_only(handle, &sr16);
236 status = npi_dev_func_sr_lock_free(handle);
237 NXGE_DEBUG_MSG((NULL, VIR_CTL,
238 "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
239 return (0);
240 #endif
241
242 case NXGE_CTLOPS_UPDATE_SHARED_REG:
243 #ifdef NXGE_SHARED_REG_SW_SIM
244 global_dev_ctrl |= *(uint64_t *)arg;
245 return (0);
246 #else
247 status = NPI_FAILURE;
248 while (status != NPI_SUCCESS)
249 status = npi_dev_func_sr_lock_enter(handle);
250 status = npi_dev_func_sr_sr_get(handle, &sr16);
251 sr16 |= *(uint16_t *)arg;
252 status = npi_dev_func_sr_sr_set_only(handle, &sr16);
253 status = npi_dev_func_sr_lock_free(handle);
254 NXGE_DEBUG_MSG((NULL, VIR_CTL,
255 "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
256 return (0);
257 #endif
258
259 case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG_UL:
260 #ifdef NXGE_SHARED_REG_SW_SIM
261 global_dev_ctrl |= *(uint64_t *)arg;
262 return (0);
263 #else
264 status = npi_dev_func_sr_sr_get(handle, &sr16);
265 cr16 = *(uint16_t *)arg;
266 sr16 &= ~cr16;
267 status = npi_dev_func_sr_sr_set_only(handle, &sr16);
268 NXGE_DEBUG_MSG((NULL, VIR_CTL,
269 "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
270 return (0);
271 #endif
272
273 case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG:
274 #ifdef NXGE_SHARED_REG_SW_SIM
275 global_dev_ctrl |= *(uint64_t *)arg;
276 return (0);
277 #else
278 status = NPI_FAILURE;
279 while (status != NPI_SUCCESS)
280 status = npi_dev_func_sr_lock_enter(handle);
281 status = npi_dev_func_sr_sr_get(handle, &sr16);
282 cr16 = *(uint16_t *)arg;
283 sr16 &= ~cr16;
284 status = npi_dev_func_sr_sr_set_only(handle, &sr16);
285 status = npi_dev_func_sr_lock_free(handle);
286 NXGE_DEBUG_MSG((NULL, VIR_CTL,
287 "nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
288 return (0);
289 #endif
290
291 case NXGE_CTLOPS_GET_LOCK_BLOCK:
292 #ifdef NXGE_SHARED_REG_SW_SIM
293 global_dev_ctrl |= *(uint64_t *)arg;
294 return (0);
295 #else
296 status = NPI_FAILURE;
297 while (status != NPI_SUCCESS)
298 status = npi_dev_func_sr_lock_enter(handle);
299 NXGE_DEBUG_MSG((NULL, VIR_CTL,
300 "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_BLOCK"));
301 return (0);
302 #endif
303 case NXGE_CTLOPS_GET_LOCK_TRY:
304 #ifdef NXGE_SHARED_REG_SW_SIM
305 global_dev_ctrl |= *(uint64_t *)arg;
306 return (0);
307 #else
308 status = npi_dev_func_sr_lock_enter(handle);
309 NXGE_DEBUG_MSG((NULL, VIR_CTL,
310 "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_TRY"));
311 if (status == NPI_SUCCESS)
312 return (NXGE_OK);
313 else
314 return (NXGE_ERROR);
315 #endif
316 case NXGE_CTLOPS_FREE_LOCK:
317 #ifdef NXGE_SHARED_REG_SW_SIM
318 global_dev_ctrl |= *(uint64_t *)arg;
319 return (0);
320 #else
321 status = npi_dev_func_sr_lock_free(handle);
322 NXGE_DEBUG_MSG((NULL, VIR_CTL,
323 "nxge_cntlops: NXGE_CTLOPS_GET_LOCK_FREE"));
324 if (status == NPI_SUCCESS)
325 return (NXGE_OK);
326 else
327 return (NXGE_ERROR);
328 #endif
329
330 default:
331 status = NXGE_ERROR;
332 }
333
334 return (status);
335 }
336
337 void
nxge_common_lock_get(p_nxge_t nxgep)338 nxge_common_lock_get(p_nxge_t nxgep)
339 {
340 uint32_t status = NPI_FAILURE;
341 npi_handle_t handle;
342
343 #if defined(NXGE_SHARE_REG_SW_SIM)
344 return;
345 #endif
346 handle = nxgep->npi_reg_handle;
347 while (status != NPI_SUCCESS)
348 status = npi_dev_func_sr_lock_enter(handle);
349 }
350
351 void
nxge_common_lock_free(p_nxge_t nxgep)352 nxge_common_lock_free(p_nxge_t nxgep)
353 {
354 npi_handle_t handle;
355
356 #if defined(NXGE_SHARE_REG_SW_SIM)
357 return;
358 #endif
359 handle = nxgep->npi_reg_handle;
360 (void) npi_dev_func_sr_lock_free(handle);
361 }
362
363
364 static void
nxge_get_niu_property(dev_info_t * dip,niu_type_t * niu_type)365 nxge_get_niu_property(dev_info_t *dip, niu_type_t *niu_type)
366 {
367 uchar_t *prop_val;
368 uint_t prop_len;
369
370 *niu_type = NIU_TYPE_NONE;
371 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0,
372 "niu-type", (uchar_t **)&prop_val,
373 &prop_len) == DDI_PROP_SUCCESS) {
374 if (strncmp("niu", (caddr_t)prop_val, (size_t)prop_len) == 0) {
375 *niu_type = N2_NIU;
376 }
377 ddi_prop_free(prop_val);
378 }
379 }
380
381 static config_token_t
nxge_get_config_token(char * prop)382 nxge_get_config_token(char *prop)
383 {
384 config_token_t token = DEFAULT;
385
386 while (token < CONFIG_TOKEN_NONE) {
387 if (strncmp(prop, token_names[token], 4) == 0)
388 break;
389 token++;
390 }
391 return (token);
392 }
393
394 /* per port */
395
396 static nxge_status_t
nxge_update_rxdma_grp_properties(p_nxge_t nxgep,config_token_t token,dev_info_t * s_dip[])397 nxge_update_rxdma_grp_properties(p_nxge_t nxgep, config_token_t token,
398 dev_info_t *s_dip[])
399 {
400 nxge_status_t status = NXGE_OK;
401 int ddi_status;
402 int num_ports = nxgep->nports;
403 int port, bits, j;
404 uint8_t start_grp = 0, num_grps = 0;
405 p_nxge_param_t param_arr;
406 uint32_t grp_bitmap[MAX_SIBLINGS];
407 int custom_start_grp[MAX_SIBLINGS];
408 int custom_num_grp[MAX_SIBLINGS];
409 uint8_t bad_config = B_FALSE;
410 char *start_prop, *num_prop, *cfg_prop;
411
412 start_grp = 0;
413 param_arr = nxgep->param_arr;
414 start_prop = param_arr[param_rdc_grps_start].fcode_name;
415 num_prop = param_arr[param_rx_rdc_grps].fcode_name;
416
417 switch (token) {
418 case FAIR:
419 cfg_prop = "fair";
420 for (port = 0; port < num_ports; port++) {
421 custom_num_grp[port] =
422 (num_ports == 4) ?
423 p4_rdcgrp_fair[port] :
424 p2_rdcgrp_fair[port];
425 custom_start_grp[port] = start_grp;
426 start_grp += custom_num_grp[port];
427 }
428 break;
429
430 case EQUAL:
431 cfg_prop = "equal";
432 for (port = 0; port < num_ports; port++) {
433 custom_num_grp[port] =
434 (num_ports == 4) ?
435 p4_rdcgrp_equal[port] :
436 p2_rdcgrp_equal[port];
437 custom_start_grp[port] = start_grp;
438 start_grp += custom_num_grp[port];
439 }
440 break;
441
442
443 case CLASSIFY:
444 cfg_prop = "classify";
445 for (port = 0; port < num_ports; port++) {
446 custom_num_grp[port] = (num_ports == 4) ?
447 p4_rdcgrp_cls[port] : p2_rdcgrp_cls[port];
448 custom_start_grp[port] = start_grp;
449 start_grp += custom_num_grp[port];
450 }
451 break;
452
453 case CUSTOM:
454 cfg_prop = "custom";
455 /* See if it is good config */
456 num_grps = 0;
457 for (port = 0; port < num_ports; port++) {
458 custom_start_grp[port] =
459 ddi_prop_get_int(DDI_DEV_T_NONE, s_dip[port],
460 DDI_PROP_DONTPASS, start_prop, -1);
461 if ((custom_start_grp[port] == -1) ||
462 (custom_start_grp[port] >=
463 NXGE_MAX_RDC_GRPS)) {
464 bad_config = B_TRUE;
465 break;
466 }
467 custom_num_grp[port] = ddi_prop_get_int(
468 DDI_DEV_T_NONE,
469 s_dip[port],
470 DDI_PROP_DONTPASS,
471 num_prop, -1);
472
473 if ((custom_num_grp[port] == -1) ||
474 (custom_num_grp[port] >
475 NXGE_MAX_RDC_GRPS) ||
476 ((custom_num_grp[port] +
477 custom_start_grp[port]) >=
478 NXGE_MAX_RDC_GRPS)) {
479 bad_config = B_TRUE;
480 break;
481 }
482 num_grps += custom_num_grp[port];
483 if (num_grps > NXGE_MAX_RDC_GRPS) {
484 bad_config = B_TRUE;
485 break;
486 }
487 grp_bitmap[port] = 0;
488 for (bits = 0;
489 bits < custom_num_grp[port];
490 bits++) {
491 grp_bitmap[port] |=
492 (1 << (bits + custom_start_grp[port]));
493 }
494
495 }
496
497 if (bad_config == B_FALSE) {
498 /* check for overlap */
499 for (port = 0; port < num_ports - 1; port++) {
500 for (j = port + 1; j < num_ports; j++) {
501 if (grp_bitmap[port] &
502 grp_bitmap[j]) {
503 bad_config = B_TRUE;
504 break;
505 }
506 }
507 if (bad_config == B_TRUE)
508 break;
509 }
510 }
511 if (bad_config == B_TRUE) {
512 /* use default config */
513 for (port = 0; port < num_ports; port++) {
514 custom_num_grp[port] =
515 (num_ports == 4) ?
516 p4_rx_fair[port] : p2_rx_fair[port];
517 custom_start_grp[port] = start_grp;
518 start_grp += custom_num_grp[port];
519 }
520 }
521 break;
522
523 default:
524 /* use default config */
525 cfg_prop = "fair";
526 for (port = 0; port < num_ports; port++) {
527 custom_num_grp[port] = (num_ports == 4) ?
528 p4_rx_fair[port] : p2_rx_fair[port];
529 custom_start_grp[port] = start_grp;
530 start_grp += custom_num_grp[port];
531 }
532 break;
533 }
534
535 /* Now Update the rx properties */
536 for (port = 0; port < num_ports; port++) {
537 ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
538 "rxdma-grp-cfg", cfg_prop);
539 if (ddi_status != DDI_PROP_SUCCESS) {
540 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
541 " property %s not updating",
542 cfg_prop));
543 status |= NXGE_DDI_FAILED;
544 }
545 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
546 num_prop, custom_num_grp[port]);
547
548 if (ddi_status != DDI_PROP_SUCCESS) {
549 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
550 " property %s not updating",
551 num_prop));
552 status |= NXGE_DDI_FAILED;
553 }
554 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
555 start_prop, custom_start_grp[port]);
556
557 if (ddi_status != DDI_PROP_SUCCESS) {
558 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
559 " property %s not updating",
560 start_prop));
561 status |= NXGE_DDI_FAILED;
562 }
563 }
564 if (status & NXGE_DDI_FAILED)
565 status |= NXGE_ERROR;
566
567 return (status);
568 }
569
570 static nxge_status_t
nxge_update_rxdma_properties(p_nxge_t nxgep,config_token_t token,dev_info_t * s_dip[])571 nxge_update_rxdma_properties(p_nxge_t nxgep, config_token_t token,
572 dev_info_t *s_dip[])
573 {
574 nxge_status_t status = NXGE_OK;
575 int ddi_status;
576 int num_ports = nxgep->nports;
577 int port, bits, j;
578 uint8_t start_rdc = 0, num_rdc = 0;
579 p_nxge_param_t param_arr;
580 uint32_t rdc_bitmap[MAX_SIBLINGS];
581 int custom_start_rdc[MAX_SIBLINGS];
582 int custom_num_rdc[MAX_SIBLINGS];
583 uint8_t bad_config = B_FALSE;
584 int *prop_val;
585 uint_t prop_len;
586 char *start_rdc_prop, *num_rdc_prop, *cfg_prop;
587
588 start_rdc = 0;
589 param_arr = nxgep->param_arr;
590 start_rdc_prop = param_arr[param_rxdma_channels_begin].fcode_name;
591 num_rdc_prop = param_arr[param_rxdma_channels].fcode_name;
592
593 switch (token) {
594 case FAIR:
595 cfg_prop = "fair";
596 for (port = 0; port < num_ports; port++) {
597 custom_num_rdc[port] = (num_ports == 4) ?
598 p4_rx_fair[port] : p2_rx_fair[port];
599 custom_start_rdc[port] = start_rdc;
600 start_rdc += custom_num_rdc[port];
601 }
602 break;
603
604 case EQUAL:
605 cfg_prop = "equal";
606 for (port = 0; port < num_ports; port++) {
607 custom_num_rdc[port] = (num_ports == 4) ?
608 p4_rx_equal[port] :
609 p2_rx_equal[port];
610 custom_start_rdc[port] = start_rdc;
611 start_rdc += custom_num_rdc[port];
612 }
613 break;
614
615 case CUSTOM:
616 cfg_prop = "custom";
617 /* See if it is good config */
618 num_rdc = 0;
619 for (port = 0; port < num_ports; port++) {
620 ddi_status = ddi_prop_lookup_int_array(
621 DDI_DEV_T_ANY,
622 s_dip[port], 0,
623 start_rdc_prop,
624 &prop_val,
625 &prop_len);
626 if (ddi_status == DDI_SUCCESS)
627 custom_start_rdc[port] = *prop_val;
628 else {
629 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
630 " %s custom start port %d"
631 " read failed ",
632 " rxdma-cfg", port));
633 bad_config = B_TRUE;
634 status |= NXGE_DDI_FAILED;
635 }
636 if ((custom_start_rdc[port] == -1) ||
637 (custom_start_rdc[port] >=
638 NXGE_MAX_RDCS)) {
639 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
640 " %s custom start %d"
641 " out of range %x ",
642 " rxdma-cfg",
643 port,
644 custom_start_rdc[port]));
645 bad_config = B_TRUE;
646 break;
647 }
648 ddi_status = ddi_prop_lookup_int_array(
649 DDI_DEV_T_ANY,
650 s_dip[port],
651 0,
652 num_rdc_prop,
653 &prop_val,
654 &prop_len);
655
656 if (ddi_status == DDI_SUCCESS)
657 custom_num_rdc[port] = *prop_val;
658 else {
659 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
660 " %s custom num port %d"
661 " read failed ",
662 "rxdma-cfg", port));
663 bad_config = B_TRUE;
664 status |= NXGE_DDI_FAILED;
665 }
666
667 if ((custom_num_rdc[port] == -1) ||
668 (custom_num_rdc[port] >
669 NXGE_MAX_RDCS) ||
670 ((custom_num_rdc[port] +
671 custom_start_rdc[port]) >
672 NXGE_MAX_RDCS)) {
673 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
674 " %s custom num %d"
675 " out of range %x ",
676 " rxdma-cfg",
677 port, custom_num_rdc[port]));
678 bad_config = B_TRUE;
679 break;
680 }
681 num_rdc += custom_num_rdc[port];
682 if (num_rdc > NXGE_MAX_RDCS) {
683 bad_config = B_TRUE;
684 break;
685 }
686 rdc_bitmap[port] = 0;
687 for (bits = 0;
688 bits < custom_num_rdc[port]; bits++) {
689 rdc_bitmap[port] |=
690 (1 << (bits + custom_start_rdc[port]));
691 }
692 }
693
694 if (bad_config == B_FALSE) {
695 /* check for overlap */
696 for (port = 0; port < num_ports - 1; port++) {
697 for (j = port + 1; j < num_ports; j++) {
698 if (rdc_bitmap[port] &
699 rdc_bitmap[j]) {
700 NXGE_DEBUG_MSG((nxgep,
701 CFG_CTL,
702 " rxdma-cfg"
703 " property custom"
704 " bit overlap"
705 " %d %d ",
706 port, j));
707 bad_config = B_TRUE;
708 break;
709 }
710 }
711 if (bad_config == B_TRUE)
712 break;
713 }
714 }
715 if (bad_config == B_TRUE) {
716 /* use default config */
717 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
718 " rxdma-cfg property:"
719 " bad custom config:"
720 " use default"));
721 for (port = 0; port < num_ports; port++) {
722 custom_num_rdc[port] =
723 (num_ports == 4) ?
724 p4_rx_fair[port] :
725 p2_rx_fair[port];
726 custom_start_rdc[port] = start_rdc;
727 start_rdc += custom_num_rdc[port];
728 }
729 }
730 break;
731
732 default:
733 /* use default config */
734 cfg_prop = "fair";
735 for (port = 0; port < num_ports; port++) {
736 custom_num_rdc[port] = (num_ports == 4) ?
737 p4_rx_fair[port] : p2_rx_fair[port];
738 custom_start_rdc[port] = start_rdc;
739 start_rdc += custom_num_rdc[port];
740 }
741 break;
742 }
743
744 /* Now Update the rx properties */
745 for (port = 0; port < num_ports; port++) {
746 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
747 " update property rxdma-cfg with %s ", cfg_prop));
748 ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
749 "rxdma-cfg", cfg_prop);
750 if (ddi_status != DDI_PROP_SUCCESS) {
751 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
752 " property rxdma-cfg is not updating to %s",
753 cfg_prop));
754 status |= NXGE_DDI_FAILED;
755 }
756 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
757 num_rdc_prop, custom_num_rdc[port]));
758
759 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
760 num_rdc_prop, custom_num_rdc[port]);
761
762 if (ddi_status != DDI_PROP_SUCCESS) {
763 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
764 " property %s not updating with %d",
765 num_rdc_prop, custom_num_rdc[port]));
766 status |= NXGE_DDI_FAILED;
767 }
768 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
769 start_rdc_prop, custom_start_rdc[port]));
770 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
771 start_rdc_prop, custom_start_rdc[port]);
772
773 if (ddi_status != DDI_PROP_SUCCESS) {
774 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
775 " property %s not updating with %d ",
776 start_rdc_prop, custom_start_rdc[port]));
777 status |= NXGE_DDI_FAILED;
778 }
779 }
780 if (status & NXGE_DDI_FAILED)
781 status |= NXGE_ERROR;
782 return (status);
783 }
784
785 static nxge_status_t
nxge_update_txdma_properties(p_nxge_t nxgep,config_token_t token,dev_info_t * s_dip[])786 nxge_update_txdma_properties(p_nxge_t nxgep, config_token_t token,
787 dev_info_t *s_dip[])
788 {
789 nxge_status_t status = NXGE_OK;
790 int ddi_status = DDI_SUCCESS;
791 int num_ports = nxgep->nports;
792 int port, bits, j;
793 uint8_t start_tdc, num_tdc = 0;
794 p_nxge_param_t param_arr;
795 uint32_t tdc_bitmap[MAX_SIBLINGS];
796 int custom_start_tdc[MAX_SIBLINGS];
797 int custom_num_tdc[MAX_SIBLINGS];
798 uint8_t bad_config = B_FALSE;
799 int *prop_val;
800 uint_t prop_len;
801 char *start_tdc_prop, *num_tdc_prop, *cfg_prop;
802
803 start_tdc = 0;
804 param_arr = nxgep->param_arr;
805 start_tdc_prop = param_arr[param_txdma_channels_begin].fcode_name;
806 num_tdc_prop = param_arr[param_txdma_channels].fcode_name;
807
808 switch (token) {
809 case FAIR:
810 cfg_prop = "fair";
811 for (port = 0; port < num_ports; port++) {
812 custom_num_tdc[port] = (num_ports == 4) ?
813 p4_tx_fair[port] : p2_tx_fair[port];
814 custom_start_tdc[port] = start_tdc;
815 start_tdc += custom_num_tdc[port];
816 }
817 break;
818
819 case EQUAL:
820 cfg_prop = "equal";
821 for (port = 0; port < num_ports; port++) {
822 custom_num_tdc[port] = (num_ports == 4) ?
823 p4_tx_equal[port] : p2_tx_equal[port];
824 custom_start_tdc[port] = start_tdc;
825 start_tdc += custom_num_tdc[port];
826 }
827 break;
828
829 case CUSTOM:
830 cfg_prop = "custom";
831 /* See if it is good config */
832 num_tdc = 0;
833 for (port = 0; port < num_ports; port++) {
834 ddi_status = ddi_prop_lookup_int_array(
835 DDI_DEV_T_ANY, s_dip[port], 0, start_tdc_prop,
836 &prop_val, &prop_len);
837 if (ddi_status == DDI_SUCCESS)
838 custom_start_tdc[port] = *prop_val;
839 else {
840 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
841 " %s custom start port %d"
842 " read failed ", " txdma-cfg", port));
843 bad_config = B_TRUE;
844 status |= NXGE_DDI_FAILED;
845 }
846
847 if ((custom_start_tdc[port] == -1) ||
848 (custom_start_tdc[port] >=
849 NXGE_MAX_RDCS)) {
850 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
851 " %s custom start %d"
852 " out of range %x ", " txdma-cfg",
853 port, custom_start_tdc[port]));
854 bad_config = B_TRUE;
855 break;
856 }
857
858 ddi_status = ddi_prop_lookup_int_array(
859 DDI_DEV_T_ANY, s_dip[port], 0, num_tdc_prop,
860 &prop_val, &prop_len);
861 if (ddi_status == DDI_SUCCESS)
862 custom_num_tdc[port] = *prop_val;
863 else {
864 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
865 " %s custom num port %d"
866 " read failed ", " txdma-cfg", port));
867 bad_config = B_TRUE;
868 status |= NXGE_DDI_FAILED;
869 }
870
871 if ((custom_num_tdc[port] == -1) ||
872 (custom_num_tdc[port] >
873 NXGE_MAX_TDCS) ||
874 ((custom_num_tdc[port] +
875 custom_start_tdc[port]) >
876 NXGE_MAX_TDCS)) {
877 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
878 " %s custom num %d"
879 " out of range %x ", " rxdma-cfg",
880 port, custom_num_tdc[port]));
881 bad_config = B_TRUE;
882 break;
883 }
884 num_tdc += custom_num_tdc[port];
885 if (num_tdc > NXGE_MAX_TDCS) {
886 bad_config = B_TRUE;
887 break;
888 }
889 tdc_bitmap[port] = 0;
890 for (bits = 0;
891 bits < custom_num_tdc[port]; bits++) {
892 tdc_bitmap[port] |=
893 (1 <<
894 (bits + custom_start_tdc[port]));
895 }
896
897 }
898
899 if (bad_config == B_FALSE) {
900 /* check for overlap */
901 for (port = 0; port < num_ports - 1; port++) {
902 for (j = port + 1; j < num_ports; j++) {
903 if (tdc_bitmap[port] &
904 tdc_bitmap[j]) {
905 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
906 " rxdma-cfg"
907 " property custom"
908 " bit overlap"
909 " %d %d ",
910 port, j));
911 bad_config = B_TRUE;
912 break;
913 }
914 }
915 if (bad_config == B_TRUE)
916 break;
917 }
918 }
919 if (bad_config == B_TRUE) {
920 /* use default config */
921 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
922 " txdma-cfg property:"
923 " bad custom config:" " use default"));
924
925 for (port = 0; port < num_ports; port++) {
926 custom_num_tdc[port] = (num_ports == 4) ?
927 p4_tx_fair[port] : p2_tx_fair[port];
928 custom_start_tdc[port] = start_tdc;
929 start_tdc += custom_num_tdc[port];
930 }
931 }
932 break;
933
934 default:
935 /* use default config */
936 cfg_prop = "fair";
937 for (port = 0; port < num_ports; port++) {
938 custom_num_tdc[port] = (num_ports == 4) ?
939 p4_tx_fair[port] : p2_tx_fair[port];
940 custom_start_tdc[port] = start_tdc;
941 start_tdc += custom_num_tdc[port];
942 }
943 break;
944 }
945
946 /* Now Update the tx properties */
947 for (port = 0; port < num_ports; port++) {
948 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
949 " update property txdma-cfg with %s ", cfg_prop));
950 ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
951 "txdma-cfg", cfg_prop);
952 if (ddi_status != DDI_PROP_SUCCESS) {
953 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
954 " property txdma-cfg is not updating to %s",
955 cfg_prop));
956 status |= NXGE_DDI_FAILED;
957 }
958 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
959 num_tdc_prop, custom_num_tdc[port]));
960
961 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
962 num_tdc_prop, custom_num_tdc[port]);
963
964 if (ddi_status != DDI_PROP_SUCCESS) {
965 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
966 " property %s not updating with %d",
967 num_tdc_prop,
968 custom_num_tdc[port]));
969 status |= NXGE_DDI_FAILED;
970 }
971
972 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
973 start_tdc_prop, custom_start_tdc[port]));
974
975 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
976 start_tdc_prop, custom_start_tdc[port]);
977 if (ddi_status != DDI_PROP_SUCCESS) {
978 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
979 " property %s not updating with %d ",
980 start_tdc_prop, custom_start_tdc[port]));
981 status |= NXGE_DDI_FAILED;
982 }
983 }
984 if (status & NXGE_DDI_FAILED)
985 status |= NXGE_ERROR;
986 return (status);
987 }
988
989 static nxge_status_t
nxge_update_cfg_properties(p_nxge_t nxgep,uint32_t flags,config_token_t token,dev_info_t * s_dip[])990 nxge_update_cfg_properties(p_nxge_t nxgep, uint32_t flags,
991 config_token_t token, dev_info_t *s_dip[])
992 {
993 nxge_status_t status = NXGE_OK;
994
995 switch (flags) {
996 case COMMON_TXDMA_CFG:
997 if (nxge_dma_obp_props_only == 0)
998 status = nxge_update_txdma_properties(nxgep,
999 token, s_dip);
1000 break;
1001 case COMMON_RXDMA_CFG:
1002 if (nxge_dma_obp_props_only == 0)
1003 status = nxge_update_rxdma_properties(nxgep,
1004 token, s_dip);
1005
1006 break;
1007 case COMMON_RXDMA_GRP_CFG:
1008 status = nxge_update_rxdma_grp_properties(nxgep,
1009 token, s_dip);
1010 break;
1011 default:
1012 return (NXGE_ERROR);
1013 }
1014 return (status);
1015 }
1016
1017 /*
1018 * verify consistence.
1019 * (May require publishing the properties on all the ports.
1020 *
1021 * What if properties are published on function 0 device only?
1022 *
1023 *
1024 * rxdma-cfg, txdma-cfg, rxdma-grp-cfg (required )
1025 * What about class configs?
1026 *
1027 * If consistent, update the property on all the siblings.
1028 * set a flag on hardware shared register
1029 * The rest of the siblings will check the flag
1030 * if the flag is set, they will use the updated property
1031 * without doing any validation.
1032 */
1033
1034 nxge_status_t
nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep,char * prop,uint64_t known_cfg,uint32_t override,dev_info_t * c_dip[])1035 nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep, char *prop,
1036 uint64_t known_cfg, uint32_t override, dev_info_t *c_dip[])
1037 {
1038 nxge_status_t status = NXGE_OK;
1039 int ddi_status = DDI_SUCCESS;
1040 int i = 0, found = 0, update_prop = B_TRUE;
1041 int *cfg_val;
1042 uint_t new_value, cfg_value[MAX_SIBLINGS];
1043 uint_t prop_len;
1044 uint_t known_cfg_value;
1045
1046 new_value = 0;
1047 known_cfg_value = (uint_t)known_cfg;
1048
1049 if (override == B_TRUE) {
1050 new_value = known_cfg_value;
1051 for (i = 0; i < nxgep->nports; i++) {
1052 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
1053 c_dip[i], prop, new_value);
1054 #ifdef NXGE_DEBUG_ERROR
1055 if (ddi_status != DDI_PROP_SUCCESS)
1056 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1057 " property %s failed update ", prop));
1058 #endif
1059 }
1060 if (ddi_status != DDI_PROP_SUCCESS)
1061 return (NXGE_ERROR | NXGE_DDI_FAILED);
1062 }
1063 for (i = 0; i < nxgep->nports; i++) {
1064 cfg_value[i] = known_cfg_value;
1065 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, c_dip[i], 0,
1066 prop, &cfg_val,
1067 &prop_len) == DDI_PROP_SUCCESS) {
1068 cfg_value[i] = *cfg_val;
1069 ddi_prop_free(cfg_val);
1070 found++;
1071 }
1072 }
1073
1074 if (found != i) {
1075 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1076 " property %s not specified on all ports", prop));
1077 if (found == 0) {
1078 /* not specified: Use default */
1079 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1080 " property %s not specified on any port:"
1081 " Using default", prop));
1082 new_value = known_cfg_value;
1083 } else {
1084 /* specified on some */
1085 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1086 " property %s not specified"
1087 " on some ports: Using default", prop));
1088 /* ? use p0 value instead ? */
1089 new_value = known_cfg_value;
1090 }
1091 } else {
1092 /* check type and consistence */
1093 /* found on all devices */
1094 for (i = 1; i < found; i++) {
1095 if (cfg_value[i] != cfg_value[i - 1]) {
1096 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1097 " property %s inconsistent:"
1098 " Using default", prop));
1099 new_value = known_cfg_value;
1100 break;
1101 }
1102 /*
1103 * Found on all the ports and consistent. Nothing to
1104 * do.
1105 */
1106 update_prop = B_FALSE;
1107 }
1108 }
1109
1110 if (update_prop == B_TRUE) {
1111 for (i = 0; i < nxgep->nports; i++) {
1112 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
1113 c_dip[i], prop, new_value);
1114 #ifdef NXGE_DEBUG_ERROR
1115 if (ddi_status != DDI_SUCCESS)
1116 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1117 " property %s not updating with %d"
1118 " Using default",
1119 prop, new_value));
1120 #endif
1121 if (ddi_status != DDI_PROP_SUCCESS)
1122 status |= NXGE_DDI_FAILED;
1123 }
1124 }
1125 if (status & NXGE_DDI_FAILED)
1126 status |= NXGE_ERROR;
1127
1128 return (status);
1129 }
1130
1131 static uint64_t
nxge_class_get_known_cfg(p_nxge_t nxgep,int class_prop,int rx_quick_cfg)1132 nxge_class_get_known_cfg(p_nxge_t nxgep, int class_prop, int rx_quick_cfg)
1133 {
1134 int start_prop;
1135 uint64_t cfg_value;
1136 p_nxge_param_t param_arr;
1137
1138 param_arr = nxgep->param_arr;
1139 cfg_value = param_arr[class_prop].value;
1140 start_prop = param_h1_init_value;
1141
1142 /* update the properties per quick config */
1143 switch (rx_quick_cfg) {
1144 case CFG_L3_WEB:
1145 case CFG_L3_DISTRIBUTE:
1146 cfg_value = nxge_classify_get_cfg_value(nxgep,
1147 rx_quick_cfg, class_prop - start_prop);
1148 break;
1149 default:
1150 cfg_value = param_arr[class_prop].value;
1151 break;
1152 }
1153 return (cfg_value);
1154 }
1155
1156 static nxge_status_t
nxge_cfg_verify_set_classify(p_nxge_t nxgep,dev_info_t * c_dip[])1157 nxge_cfg_verify_set_classify(p_nxge_t nxgep, dev_info_t *c_dip[])
1158 {
1159 nxge_status_t status = NXGE_OK;
1160 int rx_quick_cfg, class_prop, start_prop, end_prop;
1161 char *prop_name;
1162 int override = B_TRUE;
1163 uint64_t cfg_value;
1164 p_nxge_param_t param_arr;
1165
1166 param_arr = nxgep->param_arr;
1167 rx_quick_cfg = param_arr[param_rx_quick_cfg].value;
1168 start_prop = param_h1_init_value;
1169 end_prop = param_class_opt_ipv6_sctp;
1170
1171 /* update the properties per quick config */
1172 if (rx_quick_cfg == CFG_NOT_SPECIFIED)
1173 override = B_FALSE;
1174
1175 /*
1176 * these parameter affect the classification outcome.
1177 * these parameters are used to configure the Flow key and
1178 * the TCAM key for each of the IP classes.
1179 * Included here are also the H1 and H2 initial values
1180 * which affect the distribution as well as final hash value
1181 * (hence the offset into RDC table and FCRAM bucket location)
1182 *
1183 */
1184 for (class_prop = start_prop; class_prop <= end_prop; class_prop++) {
1185 prop_name = param_arr[class_prop].fcode_name;
1186 cfg_value = nxge_class_get_known_cfg(nxgep,
1187 class_prop, rx_quick_cfg);
1188 status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
1189 cfg_value, override, c_dip);
1190 }
1191
1192 /*
1193 * these properties do not affect the actual classification outcome.
1194 * used to enable/disable or tune the fflp hardware
1195 *
1196 * fcram_access_ratio, tcam_access_ratio, tcam_enable, llc_snap_enable
1197 *
1198 */
1199 override = B_FALSE;
1200 for (class_prop = param_fcram_access_ratio;
1201 class_prop <= param_llc_snap_enable; class_prop++) {
1202 prop_name = param_arr[class_prop].fcode_name;
1203 cfg_value = param_arr[class_prop].value;
1204 status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
1205 cfg_value, override, c_dip);
1206 }
1207
1208 return (status);
1209 }
1210
1211 nxge_status_t
nxge_cfg_verify_set(p_nxge_t nxgep,uint32_t flag)1212 nxge_cfg_verify_set(p_nxge_t nxgep, uint32_t flag)
1213 {
1214 nxge_status_t status = NXGE_OK;
1215 int i = 0, found = 0;
1216 int num_siblings;
1217 dev_info_t *c_dip[MAX_SIBLINGS + 1];
1218 char *prop_val[MAX_SIBLINGS];
1219 config_token_t c_token[MAX_SIBLINGS];
1220 char *prop;
1221
1222 if (nxge_dma_obp_props_only)
1223 return (NXGE_OK);
1224
1225 num_siblings = 0;
1226 c_dip[num_siblings] = ddi_get_child(nxgep->p_dip);
1227 while (c_dip[num_siblings]) {
1228 c_dip[num_siblings + 1] =
1229 ddi_get_next_sibling(c_dip[num_siblings]);
1230 num_siblings++;
1231 }
1232
1233 switch (flag) {
1234 case COMMON_TXDMA_CFG:
1235 prop = "txdma-cfg";
1236 break;
1237 case COMMON_RXDMA_CFG:
1238 prop = "rxdma-cfg";
1239 break;
1240 case COMMON_RXDMA_GRP_CFG:
1241 prop = "rxdma-grp-cfg";
1242 break;
1243 case COMMON_CLASS_CFG:
1244 status = nxge_cfg_verify_set_classify(nxgep, c_dip);
1245 return (status);
1246 default:
1247 return (NXGE_ERROR);
1248 }
1249
1250 i = 0;
1251 while (i < num_siblings) {
1252 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, c_dip[i], 0, prop,
1253 (char **)&prop_val[i]) == DDI_PROP_SUCCESS) {
1254 c_token[i] = nxge_get_config_token(prop_val[i]);
1255 ddi_prop_free(prop_val[i]);
1256 found++;
1257 } else
1258 c_token[i] = CONFIG_TOKEN_NONE;
1259 i++;
1260 }
1261
1262 if (found != i) {
1263 if (found == 0) {
1264 /* not specified: Use default */
1265 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1266 " property %s not specified on any port:"
1267 " Using default", prop));
1268
1269 status = nxge_update_cfg_properties(nxgep,
1270 flag, FAIR, c_dip);
1271 return (status);
1272 } else {
1273 /*
1274 * if the convention is to use function 0 device then
1275 * populate the other devices with this configuration.
1276 *
1277 * The other alternative is to use the default config.
1278 */
1279 /* not specified: Use default */
1280 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1281 " property %s not specified on some ports:"
1282 " Using default", prop));
1283 status = nxge_update_cfg_properties(nxgep,
1284 flag, FAIR, c_dip);
1285 return (status);
1286 }
1287 }
1288
1289 /* check type and consistence */
1290 /* found on all devices */
1291 for (i = 1; i < found; i++) {
1292 if (c_token[i] != c_token[i - 1]) {
1293 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1294 " property %s inconsistent:"
1295 " Using default", prop));
1296 status = nxge_update_cfg_properties(nxgep,
1297 flag, FAIR, c_dip);
1298 return (status);
1299 }
1300 }
1301
1302 /*
1303 * Found on all the ports check if it is custom configuration. if
1304 * custom, then verify consistence
1305 *
1306 * finally create soft properties
1307 */
1308 status = nxge_update_cfg_properties(nxgep, flag, c_token[0], c_dip);
1309 return (status);
1310 }
1311
1312 nxge_status_t
nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)1313 nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)
1314 {
1315 nxge_status_t status = NXGE_OK;
1316 int ddi_status = DDI_SUCCESS;
1317 char *prop_val;
1318 char *rx_prop;
1319 char *prop;
1320 uint32_t cfg_value = CFG_NOT_SPECIFIED;
1321 p_nxge_param_t param_arr;
1322
1323 param_arr = nxgep->param_arr;
1324 rx_prop = param_arr[param_rx_quick_cfg].fcode_name;
1325
1326 prop = "rx-quick-cfg";
1327
1328 /*
1329 * good value are
1330 *
1331 * "web-server" "generic-server" "l3-classify" "flow-classify"
1332 */
1333 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, nxgep->dip, 0,
1334 prop, (char **)&prop_val) != DDI_PROP_SUCCESS) {
1335 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1336 " property %s not specified: using default ", prop));
1337 cfg_value = CFG_NOT_SPECIFIED;
1338 } else {
1339 cfg_value = CFG_L3_DISTRIBUTE;
1340 if (strncmp("web-server", (caddr_t)prop_val, 8) == 0) {
1341 cfg_value = CFG_L3_WEB;
1342 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1343 " %s: web server ", prop));
1344 }
1345 if (strncmp("generic-server", (caddr_t)prop_val, 8) == 0) {
1346 cfg_value = CFG_L3_DISTRIBUTE;
1347 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
1348 " %s: distribute ", prop));
1349 }
1350 /* more */
1351 ddi_prop_free(prop_val);
1352 }
1353
1354 ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
1355 rx_prop, cfg_value);
1356 if (ddi_status != DDI_PROP_SUCCESS)
1357 status |= NXGE_DDI_FAILED;
1358
1359 /* now handle specified cases: */
1360 if (status & NXGE_DDI_FAILED)
1361 status |= NXGE_ERROR;
1362 return (status);
1363 }
1364
1365 /*
1366 * Device properties adv-autoneg-cap etc are defined by FWARC
1367 * http://sac.sfbay/FWARC/2002/345/20020610_asif.haswarey
1368 */
1369 static void
nxge_use_cfg_link_cfg(p_nxge_t nxgep)1370 nxge_use_cfg_link_cfg(p_nxge_t nxgep)
1371 {
1372 int *prop_val;
1373 uint_t prop_len;
1374 dev_info_t *dip;
1375 int speed;
1376 int duplex;
1377 int adv_autoneg_cap;
1378 int adv_10gfdx_cap;
1379 int adv_10ghdx_cap;
1380 int adv_1000fdx_cap;
1381 int adv_1000hdx_cap;
1382 int adv_100fdx_cap;
1383 int adv_100hdx_cap;
1384 int adv_10fdx_cap;
1385 int adv_10hdx_cap;
1386 int status = DDI_SUCCESS;
1387
1388 dip = nxgep->dip;
1389
1390 /*
1391 * first find out the card type and the supported link speeds and
1392 * features
1393 */
1394 /* add code for card type */
1395 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-autoneg-cap",
1396 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1397 ddi_prop_free(prop_val);
1398 return;
1399 }
1400
1401 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10gfdx-cap",
1402 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1403 ddi_prop_free(prop_val);
1404 return;
1405 }
1406
1407 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000hdx-cap",
1408 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1409 ddi_prop_free(prop_val);
1410 return;
1411 }
1412
1413 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000fdx-cap",
1414 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1415 ddi_prop_free(prop_val);
1416 return;
1417 }
1418
1419 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100fdx-cap",
1420 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1421 ddi_prop_free(prop_val);
1422 return;
1423 }
1424
1425 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100hdx-cap",
1426 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1427 ddi_prop_free(prop_val);
1428 return;
1429 }
1430
1431 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10fdx-cap",
1432 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1433 ddi_prop_free(prop_val);
1434 return;
1435 }
1436
1437 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10hdx-cap",
1438 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1439 ddi_prop_free(prop_val);
1440 return;
1441 }
1442
1443 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "speed",
1444 (uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1445 if (strncmp("10000", (caddr_t)prop_val,
1446 (size_t)prop_len) == 0) {
1447 speed = 10000;
1448 } else if (strncmp("1000", (caddr_t)prop_val,
1449 (size_t)prop_len) == 0) {
1450 speed = 1000;
1451 } else if (strncmp("100", (caddr_t)prop_val,
1452 (size_t)prop_len) == 0) {
1453 speed = 100;
1454 } else if (strncmp("10", (caddr_t)prop_val,
1455 (size_t)prop_len) == 0) {
1456 speed = 10;
1457 } else if (strncmp("auto", (caddr_t)prop_val,
1458 (size_t)prop_len) == 0) {
1459 speed = 0;
1460 } else {
1461 NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
1462 "speed property is invalid reverting to auto"));
1463 speed = 0;
1464 }
1465 ddi_prop_free(prop_val);
1466 } else
1467 speed = 0;
1468
1469 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "duplex",
1470 (uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1471 if (strncmp("full", (caddr_t)prop_val,
1472 (size_t)prop_len) == 0) {
1473 duplex = 2;
1474 } else if (strncmp("half", (caddr_t)prop_val,
1475 (size_t)prop_len) == 0) {
1476 duplex = 1;
1477 } else if (strncmp("auto", (caddr_t)prop_val,
1478 (size_t)prop_len) == 0) {
1479 duplex = 0;
1480 } else {
1481 NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
1482 "duplex property is invalid"
1483 " reverting to auto"));
1484 duplex = 0;
1485 }
1486 ddi_prop_free(prop_val);
1487 } else
1488 duplex = 0;
1489
1490 /* speed == 0 or duplex == 0 means auto negotiation. */
1491 adv_autoneg_cap = (speed == 0) || (duplex == 0);
1492 if (adv_autoneg_cap == 0) {
1493 adv_10gfdx_cap = ((speed == 10000) && (duplex == 2));
1494 adv_10ghdx_cap = adv_10gfdx_cap;
1495 adv_10ghdx_cap |= ((speed == 10000) && (duplex == 1));
1496 adv_1000fdx_cap = adv_10ghdx_cap;
1497 adv_1000fdx_cap |= ((speed == 1000) && (duplex == 2));
1498 adv_1000hdx_cap = adv_1000fdx_cap;
1499 adv_1000hdx_cap |= ((speed == 1000) && (duplex == 1));
1500 adv_100fdx_cap = adv_1000hdx_cap;
1501 adv_100fdx_cap |= ((speed == 100) && (duplex == 2));
1502 adv_100hdx_cap = adv_100fdx_cap;
1503 adv_100hdx_cap |= ((speed == 100) && (duplex == 1));
1504 adv_10fdx_cap = adv_100hdx_cap;
1505 adv_10fdx_cap |= ((speed == 10) && (duplex == 2));
1506 adv_10hdx_cap = adv_10fdx_cap;
1507 adv_10hdx_cap |= ((speed == 10) && (duplex == 1));
1508 } else if (speed == 0) {
1509 adv_10gfdx_cap = (duplex == 2);
1510 adv_10ghdx_cap = (duplex == 1);
1511 adv_1000fdx_cap = (duplex == 2);
1512 adv_1000hdx_cap = (duplex == 1);
1513 adv_100fdx_cap = (duplex == 2);
1514 adv_100hdx_cap = (duplex == 1);
1515 adv_10fdx_cap = (duplex == 2);
1516 adv_10hdx_cap = (duplex == 1);
1517 }
1518 if (duplex == 0) {
1519 adv_10gfdx_cap = (speed == 0);
1520 adv_10gfdx_cap |= (speed == 10000);
1521 adv_10ghdx_cap = adv_10gfdx_cap;
1522 adv_10ghdx_cap |= (speed == 10000);
1523 adv_1000fdx_cap = adv_10ghdx_cap;
1524 adv_1000fdx_cap |= (speed == 1000);
1525 adv_1000hdx_cap = adv_1000fdx_cap;
1526 adv_1000hdx_cap |= (speed == 1000);
1527 adv_100fdx_cap = adv_1000hdx_cap;
1528 adv_100fdx_cap |= (speed == 100);
1529 adv_100hdx_cap = adv_100fdx_cap;
1530 adv_100hdx_cap |= (speed == 100);
1531 adv_10fdx_cap = adv_100hdx_cap;
1532 adv_10fdx_cap |= (speed == 10);
1533 adv_10hdx_cap = adv_10fdx_cap;
1534 adv_10hdx_cap |= (speed == 10);
1535 }
1536 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1537 "adv-autoneg-cap", &adv_autoneg_cap, 1);
1538 if (status)
1539 return;
1540
1541 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1542 "adv-10gfdx-cap", &adv_10gfdx_cap, 1);
1543 if (status)
1544 goto nxge_map_myargs_to_gmii_fail1;
1545
1546 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1547 "adv-10ghdx-cap", &adv_10ghdx_cap, 1);
1548 if (status)
1549 goto nxge_map_myargs_to_gmii_fail2;
1550
1551 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1552 "adv-1000fdx-cap", &adv_1000fdx_cap, 1);
1553 if (status)
1554 goto nxge_map_myargs_to_gmii_fail3;
1555
1556 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1557 "adv-1000hdx-cap", &adv_1000hdx_cap, 1);
1558 if (status)
1559 goto nxge_map_myargs_to_gmii_fail4;
1560
1561 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1562 "adv-100fdx-cap", &adv_100fdx_cap, 1);
1563 if (status)
1564 goto nxge_map_myargs_to_gmii_fail5;
1565
1566 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1567 "adv-100hdx-cap", &adv_100hdx_cap, 1);
1568 if (status)
1569 goto nxge_map_myargs_to_gmii_fail6;
1570
1571 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1572 "adv-10fdx-cap", &adv_10fdx_cap, 1);
1573 if (status)
1574 goto nxge_map_myargs_to_gmii_fail7;
1575
1576 status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
1577 "adv-10hdx-cap", &adv_10hdx_cap, 1);
1578 if (status)
1579 goto nxge_map_myargs_to_gmii_fail8;
1580
1581 return;
1582
1583 nxge_map_myargs_to_gmii_fail8:
1584 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10fdx-cap");
1585
1586 nxge_map_myargs_to_gmii_fail7:
1587 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100hdx-cap");
1588
1589 nxge_map_myargs_to_gmii_fail6:
1590 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100fdx-cap");
1591
1592 nxge_map_myargs_to_gmii_fail5:
1593 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000hdx-cap");
1594
1595 nxge_map_myargs_to_gmii_fail4:
1596 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000fdx-cap");
1597
1598 nxge_map_myargs_to_gmii_fail3:
1599 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10ghdx-cap");
1600
1601 nxge_map_myargs_to_gmii_fail2:
1602 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10gfdx-cap");
1603
1604 nxge_map_myargs_to_gmii_fail1:
1605 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-autoneg-cap");
1606 }
1607
1608 nxge_status_t
nxge_get_config_properties(p_nxge_t nxgep)1609 nxge_get_config_properties(p_nxge_t nxgep)
1610 {
1611 nxge_status_t status = NXGE_OK;
1612 p_nxge_hw_list_t hw_p;
1613 char **prop_val;
1614 uint_t prop_len;
1615 uint_t i;
1616
1617 NXGE_DEBUG_MSG((nxgep, VPD_CTL, " ==> nxge_get_config_properties"));
1618
1619 if ((hw_p = nxgep->nxge_hw_p) == NULL) {
1620 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1621 " nxge_get_config_properties:"
1622 " common hardware not set", nxgep->niu_type));
1623 return (NXGE_ERROR);
1624 }
1625
1626 /*
1627 * Get info on how many ports Neptune card has.
1628 */
1629 nxgep->nports = nxge_get_nports(nxgep);
1630 if (nxgep->nports <= 0) {
1631 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1632 "<==nxge_get_config_properties: Invalid Neptune type 0x%x",
1633 nxgep->niu_type));
1634 return (NXGE_ERROR);
1635 }
1636 nxgep->classifier.tcam_size = TCAM_NIU_TCAM_MAX_ENTRY;
1637 if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
1638 nxgep->classifier.tcam_size = TCAM_NXGE_TCAM_MAX_ENTRY;
1639 }
1640 if (nxgep->function_num >= nxgep->nports) {
1641 return (NXGE_ERROR);
1642 }
1643
1644 status = nxge_get_mac_addr_properties(nxgep);
1645 if (status != NXGE_OK)
1646 return (NXGE_ERROR);
1647
1648 /*
1649 * read the configuration type. If none is specified, used default.
1650 * Config types: equal: (default) DMA channels, RDC groups, TCAM, FCRAM
1651 * are shared equally across all the ports.
1652 *
1653 * Fair: DMA channels, RDC groups, TCAM, FCRAM are shared proportional
1654 * to the port speed.
1655 *
1656 *
1657 * custom: DMA channels, RDC groups, TCAM, FCRAM partition is
1658 * specified in nxge.conf. Need to read each parameter and set
1659 * up the parameters in nxge structures.
1660 *
1661 */
1662 switch (nxgep->niu_type) {
1663 case N2_NIU:
1664 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1665 " ==> nxge_get_config_properties: N2"));
1666 MUTEX_ENTER(&hw_p->nxge_cfg_lock);
1667 if ((hw_p->flags & COMMON_CFG_VALID) !=
1668 COMMON_CFG_VALID) {
1669 status = nxge_cfg_verify_set(nxgep,
1670 COMMON_RXDMA_GRP_CFG);
1671 status = nxge_cfg_verify_set(nxgep,
1672 COMMON_CLASS_CFG);
1673 hw_p->flags |= COMMON_CFG_VALID;
1674 }
1675 MUTEX_EXIT(&hw_p->nxge_cfg_lock);
1676 status = nxge_use_cfg_n2niu_properties(nxgep);
1677 break;
1678 default:
1679 if (!NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
1680 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1681 " nxge_get_config_properties:"
1682 " unknown NIU type 0x%x", nxgep->niu_type));
1683 return (NXGE_ERROR);
1684 }
1685
1686 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1687 " ==> nxge_get_config_properties: Neptune"));
1688 status = nxge_cfg_verify_set_quick_config(nxgep);
1689 MUTEX_ENTER(&hw_p->nxge_cfg_lock);
1690 if ((hw_p->flags & COMMON_CFG_VALID) !=
1691 COMMON_CFG_VALID) {
1692 status = nxge_cfg_verify_set(nxgep,
1693 COMMON_TXDMA_CFG);
1694 status = nxge_cfg_verify_set(nxgep,
1695 COMMON_RXDMA_CFG);
1696 status = nxge_cfg_verify_set(nxgep,
1697 COMMON_RXDMA_GRP_CFG);
1698 status = nxge_cfg_verify_set(nxgep,
1699 COMMON_CLASS_CFG);
1700 hw_p->flags |= COMMON_CFG_VALID;
1701 }
1702 MUTEX_EXIT(&hw_p->nxge_cfg_lock);
1703 nxge_use_cfg_neptune_properties(nxgep);
1704 status = NXGE_OK;
1705 break;
1706 }
1707
1708 /*
1709 * Get the software LSO enable flag property from the
1710 * driver configuration file (nxge.conf).
1711 * This flag will be set to disable (0) if this property
1712 * does not exist.
1713 */
1714 nxgep->soft_lso_enable = ddi_prop_get_int(DDI_DEV_T_ANY, nxgep->dip,
1715 DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "soft-lso-enable", 0);
1716 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1717 "nxge_get_config_properties: software lso %d\n",
1718 nxgep->soft_lso_enable));
1719
1720 nxgep->niu_hw_type = NIU_HW_TYPE_DEFAULT;
1721 if (nxgep->niu_type == N2_NIU) {
1722
1723 uchar_t *s_prop_val;
1724
1725 /*
1726 * For NIU, the next generation KT has
1727 * a few differences in features that the
1728 * driver needs to handle them
1729 * accordingly.
1730 */
1731 if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1732 "compatible", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1733 for (i = 0; i < prop_len; i++) {
1734 if ((strcmp((caddr_t)prop_val[i],
1735 KT_NIU_COMPATIBLE) == 0)) {
1736 nxgep->niu_hw_type = NIU_HW_TYPE_RF;
1737 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1738 "NIU type %d", nxgep->niu_hw_type));
1739 break;
1740 }
1741 }
1742 }
1743
1744 ddi_prop_free(prop_val);
1745 /*
1746 * Some Serdes and PHY properties may also be provided as OBP
1747 * properties
1748 */
1749 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1750 "tx-cfg-l", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1751 nxgep->srds_prop.tx_cfg_l =
1752 (uint16_t)(*(uint32_t *)s_prop_val);
1753 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1754 "nxge_get_config_properties: "
1755 "tx_cfg_l 0x%x, Read from OBP",
1756 nxgep->srds_prop.tx_cfg_l));
1757 nxgep->srds_prop.prop_set |= NXGE_SRDS_TXCFGL;
1758 ddi_prop_free(s_prop_val);
1759 }
1760 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1761 "tx-cfg-h", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1762 nxgep->srds_prop.tx_cfg_h =
1763 (uint16_t)(*(uint32_t *)s_prop_val);
1764 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1765 "nxge_get_config_properties: "
1766 "tx_cfg_h 0x%x, Read from OBP",
1767 nxgep->srds_prop.tx_cfg_h));
1768 nxgep->srds_prop.prop_set |= NXGE_SRDS_TXCFGH;
1769 ddi_prop_free(s_prop_val);
1770 }
1771 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1772 "rx-cfg-l", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1773 nxgep->srds_prop.rx_cfg_l =
1774 (uint16_t)(*(uint32_t *)s_prop_val);
1775 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1776 "nxge_get_config_properties: "
1777 "rx_cfg_l 0x%x, Read from OBP",
1778 nxgep->srds_prop.rx_cfg_l));
1779 nxgep->srds_prop.prop_set |= NXGE_SRDS_RXCFGL;
1780 ddi_prop_free(s_prop_val);
1781 }
1782 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1783 "rx-cfg-h", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1784 nxgep->srds_prop.rx_cfg_h =
1785 (uint16_t)(*(uint32_t *)s_prop_val);
1786 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1787 "nxge_get_config_properties: "
1788 "rx_cfg_h 0x%x, Read from OBP",
1789 nxgep->srds_prop.rx_cfg_h));
1790 nxgep->srds_prop.prop_set |= NXGE_SRDS_RXCFGH;
1791 ddi_prop_free(s_prop_val);
1792 }
1793 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1794 "pll-cfg", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
1795 nxgep->srds_prop.pll_cfg_l =
1796 (uint16_t)(*(uint32_t *)s_prop_val);
1797 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1798 "nxge_get_config_properties: "
1799 "pll_cfg_l 0x%x, Read from OBP",
1800 nxgep->srds_prop.pll_cfg_l));
1801 nxgep->srds_prop.prop_set |= NXGE_SRDS_PLLCFGL;
1802 ddi_prop_free(s_prop_val);
1803 }
1804 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1805 "phy-reg-values", &s_prop_val, &prop_len) ==
1806 DDI_PROP_SUCCESS) {
1807
1808 int tun_cnt, i;
1809 uchar_t *arr = s_prop_val;
1810
1811 tun_cnt = prop_len / 6; /* 3 values, 2 bytes each */
1812 nxgep->phy_prop.arr =
1813 KMEM_ZALLOC(sizeof (nxge_phy_mdio_val_t) * tun_cnt,
1814 KM_SLEEP);
1815 nxgep->phy_prop.cnt = tun_cnt;
1816 for (i = 0; i < tun_cnt; i++) {
1817 nxgep->phy_prop.arr[i].dev = *(uint16_t *)arr;
1818 arr += 2;
1819 nxgep->phy_prop.arr[i].reg = *(uint16_t *)arr;
1820 arr += 2;
1821 nxgep->phy_prop.arr[i].val = *(uint16_t *)arr;
1822 arr += 2;
1823 NXGE_DEBUG_MSG((nxgep, VPD_CTL,
1824 "nxge_get_config_properties: From OBP, "
1825 "read PHY <dev.reg.val> = "
1826 "<0x%x.0x%x.0x%x>",
1827 nxgep->phy_prop.arr[i].dev,
1828 nxgep->phy_prop.arr[i].reg,
1829 nxgep->phy_prop.arr[i].val));
1830 }
1831 ddi_prop_free(s_prop_val);
1832 }
1833 }
1834
1835 NXGE_DEBUG_MSG((nxgep, VPD_CTL, " <== nxge_get_config_properties"));
1836 return (status);
1837 }
1838
1839 static nxge_status_t
nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)1840 nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)
1841 {
1842 nxge_status_t status = NXGE_OK;
1843
1844 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_n2niu_properties"));
1845
1846 status = nxge_use_default_dma_config_n2(nxgep);
1847 if (status != NXGE_OK) {
1848 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1849 " ==> nxge_use_cfg_n2niu_properties (err 0x%x)",
1850 status));
1851 return (status | NXGE_ERROR);
1852 }
1853
1854 (void) nxge_use_cfg_vlan_class_config(nxgep);
1855 (void) nxge_use_cfg_mac_class_config(nxgep);
1856 (void) nxge_use_cfg_class_config(nxgep);
1857 (void) nxge_use_cfg_link_cfg(nxgep);
1858
1859 /*
1860 * Read in the hardware (fcode) properties. Use the ndd array to read
1861 * each property.
1862 */
1863 (void) nxge_get_param_soft_properties(nxgep);
1864 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_n2niu_properties"));
1865
1866 return (status);
1867 }
1868
1869 static void
nxge_use_cfg_neptune_properties(p_nxge_t nxgep)1870 nxge_use_cfg_neptune_properties(p_nxge_t nxgep)
1871 {
1872 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_neptune_properties"));
1873
1874 (void) nxge_use_cfg_dma_config(nxgep);
1875 (void) nxge_use_cfg_vlan_class_config(nxgep);
1876 (void) nxge_use_cfg_mac_class_config(nxgep);
1877 (void) nxge_use_cfg_class_config(nxgep);
1878 (void) nxge_use_cfg_link_cfg(nxgep);
1879
1880 /*
1881 * Read in the hardware (fcode) properties. Use the ndd array to read
1882 * each property.
1883 */
1884 (void) nxge_get_param_soft_properties(nxgep);
1885 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_neptune_properties"));
1886 }
1887
1888 /*
1889 * FWARC 2006/556 for N2 NIU. Get the properties
1890 * from the prom.
1891 */
1892 static nxge_status_t
nxge_use_default_dma_config_n2(p_nxge_t nxgep)1893 nxge_use_default_dma_config_n2(p_nxge_t nxgep)
1894 {
1895 int ndmas;
1896 uint8_t func;
1897 p_nxge_dma_pt_cfg_t p_dma_cfgp;
1898 p_nxge_hw_pt_cfg_t p_cfgp;
1899 int *prop_val;
1900 uint_t prop_len;
1901 int i;
1902 nxge_status_t status = NXGE_OK;
1903
1904 NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2"));
1905
1906 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
1907 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
1908
1909 func = nxgep->function_num;
1910 p_cfgp->function_number = func;
1911 ndmas = NXGE_TDMA_PER_NIU_PORT;
1912 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1913 "tx-dma-channels", (int **)&prop_val,
1914 &prop_len) == DDI_PROP_SUCCESS) {
1915 if (prop_len != NXGE_NIU_TDMA_PROP_LEN) {
1916 ddi_prop_free(prop_val);
1917 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1918 "==> nxge_use_default_dma_config_n2: "
1919 "invalid tx-dma-channels property for the NIU, "
1920 "using defaults"));
1921 /*
1922 * Just failover to defaults
1923 */
1924 p_cfgp->tdc.start = (func * NXGE_TDMA_PER_NIU_PORT);
1925 ndmas = NXGE_TDMA_PER_NIU_PORT;
1926 } else {
1927 p_cfgp->tdc.start = prop_val[0];
1928 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
1929 "==> nxge_use_default_dma_config_n2: tdc starts %d "
1930 "(#%d)", p_cfgp->tdc.start, prop_len));
1931
1932 ndmas = prop_val[1];
1933 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
1934 "==> nxge_use_default_dma_config_n2: #tdc %d (#%d)",
1935 ndmas, prop_len));
1936 ddi_prop_free(prop_val);
1937 }
1938 } else {
1939 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1940 "==> nxge_use_default_dma_config_n2: "
1941 "get tx-dma-channels failed"));
1942 return (NXGE_DDI_FAILED);
1943 }
1944
1945 p_cfgp->tdc.count = ndmas;
1946 p_cfgp->tdc.owned = p_cfgp->tdc.count;
1947
1948 NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
1949 "p_cfgp 0x%llx max_tdcs %d start %d",
1950 p_cfgp, p_cfgp->tdc.count, p_cfgp->tdc.start));
1951
1952 /* Receive DMA */
1953 ndmas = NXGE_RDMA_PER_NIU_PORT;
1954 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1955 "rx-dma-channels", (int **)&prop_val,
1956 &prop_len) == DDI_PROP_SUCCESS) {
1957 if (prop_len != NXGE_NIU_RDMA_PROP_LEN) {
1958 ddi_prop_free(prop_val);
1959 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1960 "==> nxge_use_default_dma_config_n2: "
1961 "invalid rx-dma-channels property for the NIU, "
1962 "using defaults"));
1963 /*
1964 * Just failover to defaults
1965 */
1966 p_cfgp->start_rdc = (func * NXGE_RDMA_PER_NIU_PORT);
1967 ndmas = NXGE_RDMA_PER_NIU_PORT;
1968 } else {
1969 p_cfgp->start_rdc = prop_val[0];
1970 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
1971 "==> nxge_use_default_dma_config_n2(obp):"
1972 " rdc start %d (#%d)",
1973 p_cfgp->start_rdc, prop_len));
1974 ndmas = prop_val[1];
1975 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
1976 "==> nxge_use_default_dma_config_n2(obp): "
1977 "#rdc %d (#%d)", ndmas, prop_len));
1978 ddi_prop_free(prop_val);
1979 }
1980 } else {
1981 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1982 "==> nxge_use_default_dma_config_n2: "
1983 "get rx-dma-channel failed"));
1984 return (NXGE_DDI_FAILED);
1985 }
1986
1987 p_cfgp->max_rdcs = ndmas;
1988 nxgep->rdc_mask = (ndmas - 1);
1989
1990 /* Hypervisor: rdc # and group # use the same # !! */
1991 p_cfgp->max_grpids = p_cfgp->max_rdcs + p_cfgp->tdc.owned;
1992 p_cfgp->mif_ldvid = p_cfgp->mac_ldvid = p_cfgp->ser_ldvid = 0;
1993
1994 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
1995 "interrupts", (int **)&prop_val,
1996 &prop_len) == DDI_PROP_SUCCESS) {
1997 if ((prop_len != NXGE_NIU_0_INTR_PROP_LEN) &&
1998 (prop_len != NXGE_NIU_1_INTR_PROP_LEN)) {
1999 ddi_prop_free(prop_val);
2000 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2001 "==> nxge_use_default_dma_config_n2: "
2002 "get interrupts failed"));
2003 return (NXGE_DDI_FAILED);
2004 }
2005
2006 /*
2007 * For each device assigned, the content of each interrupts
2008 * property is its logical device group.
2009 *
2010 * Assignment of interrupts property is in the the following
2011 * order:
2012 *
2013 * MAC MIF (if configured) SYSTEM ERROR (if configured) first
2014 * receive channel next channel...... last receive channel
2015 * first transmit channel next channel...... last transmit
2016 * channel
2017 *
2018 * prop_len should be at least for one mac and total # of rx and
2019 * tx channels. Function 0 owns MIF and ERROR
2020 */
2021 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
2022 "==> nxge_use_default_dma_config_n2(obp): "
2023 "# interrupts %d", prop_len));
2024
2025 switch (func) {
2026 case 0:
2027 p_cfgp->ldg_chn_start = 3;
2028 p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT0;
2029 p_cfgp->mif_ldvid = NXGE_MIF_LD;
2030 p_cfgp->ser_ldvid = NXGE_SYS_ERROR_LD;
2031
2032 break;
2033 case 1:
2034 p_cfgp->ldg_chn_start = 1;
2035 p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT1;
2036
2037 break;
2038 default:
2039 status = NXGE_DDI_FAILED;
2040 break;
2041 }
2042
2043 if (status != NXGE_OK)
2044 return (status);
2045
2046 for (i = 0; i < prop_len; i++) {
2047 p_cfgp->ldg[i] = prop_val[i];
2048 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
2049 "==> nxge_use_default_dma_config_n2(obp): "
2050 "F%d: interrupt #%d, ldg %d",
2051 nxgep->function_num, i, p_cfgp->ldg[i]));
2052 }
2053
2054 p_cfgp->max_grpids = prop_len;
2055 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
2056 "==> nxge_use_default_dma_config_n2(obp): %d "
2057 "(#%d) maxgrpids %d channel starts %d",
2058 p_cfgp->mac_ldvid, i, p_cfgp->max_grpids,
2059 p_cfgp->ldg_chn_start));
2060 ddi_prop_free(prop_val);
2061 } else {
2062 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2063 "==> nxge_use_default_dma_config_n2: "
2064 "get interrupts failed"));
2065 return (NXGE_DDI_FAILED);
2066 }
2067
2068 p_cfgp->max_ldgs = p_cfgp->max_grpids;
2069 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
2070 "==> nxge_use_default_dma_config_n2: p_cfgp 0x%llx max_rdcs %d "
2071 "max_grpids %d macid %d mifid %d serrid %d",
2072 p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
2073 p_cfgp->mac_ldvid, p_cfgp->mif_ldvid, p_cfgp->ser_ldvid));
2074
2075
2076 NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
2077 "p_cfgp p%p start_ldg %d nxgep->max_ldgs %d",
2078 p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs));
2079
2080 /*
2081 * RDC groups and the beginning RDC group assigned to this function.
2082 */
2083 p_cfgp->max_rdc_grpids = NXGE_MAX_RDC_GROUPS / nxgep->nports;
2084 p_cfgp->def_mac_rxdma_grpid =
2085 nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
2086 p_cfgp->def_mac_txdma_grpid =
2087 nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
2088
2089 if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
2090 p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
2091 NXGE_ERROR_MSG((nxgep, CFG_CTL,
2092 "nxge_use_default_dma_config_n2(): "
2093 "nxge_fzc_rdc_tbl_bind failed"));
2094 return (NXGE_DDI_FAILED);
2095 }
2096
2097 status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2098 "rx-rdc-grps", p_cfgp->max_rdc_grpids);
2099 if (status) {
2100 return (NXGE_DDI_FAILED);
2101 }
2102 status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2103 "rx-rdc-grps-begin", p_cfgp->def_mac_rxdma_grpid);
2104 if (status) {
2105 (void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip,
2106 "rx-rdc-grps");
2107 return (NXGE_DDI_FAILED);
2108 }
2109 NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
2110 "p_cfgp $%p # rdc groups %d start rdc group id %d",
2111 p_cfgp, p_cfgp->max_rdc_grpids,
2112 p_cfgp->def_mac_rxdma_grpid));
2113
2114 nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
2115 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
2116 "rxdma-intr-time", (int **)&prop_val, &prop_len) ==
2117 DDI_PROP_SUCCESS) {
2118 if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
2119 nxgep->intr_timeout = prop_val[0];
2120 (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
2121 nxgep->dip, "rxdma-intr-time", prop_val, prop_len);
2122 }
2123 ddi_prop_free(prop_val);
2124 }
2125
2126 nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
2127 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
2128 "rxdma-intr-pkts", (int **)&prop_val, &prop_len) ==
2129 DDI_PROP_SUCCESS) {
2130 if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
2131 nxgep->intr_threshold = prop_val[0];
2132 (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
2133 nxgep->dip, "rxdma-intr-pkts", prop_val, prop_len);
2134 }
2135 ddi_prop_free(prop_val);
2136 }
2137
2138 nxge_set_hw_dma_config(nxgep);
2139 NXGE_DEBUG_MSG((nxgep, OBP_CTL, "<== nxge_use_default_dma_config_n2"));
2140 return (status);
2141 }
2142
2143 static void
nxge_use_cfg_dma_config(p_nxge_t nxgep)2144 nxge_use_cfg_dma_config(p_nxge_t nxgep)
2145 {
2146 int tx_ndmas, rx_ndmas, nrxgp, st_txdma, st_rxdma;
2147 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2148 p_nxge_hw_pt_cfg_t p_cfgp;
2149 dev_info_t *dip;
2150 p_nxge_param_t param_arr;
2151 char *prop;
2152 int *prop_val;
2153 uint_t prop_len;
2154 int i;
2155 uint8_t *ch_arr_p;
2156
2157 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_dma_config"));
2158 param_arr = nxgep->param_arr;
2159
2160 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2161 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2162 dip = nxgep->dip;
2163 p_cfgp->function_number = nxgep->function_num;
2164 prop = param_arr[param_txdma_channels_begin].fcode_name;
2165
2166 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2167 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2168 p_cfgp->tdc.start = *prop_val;
2169 ddi_prop_free(prop_val);
2170 } else {
2171 switch (nxgep->niu_type) {
2172 case NEPTUNE_4_1GC:
2173 ch_arr_p = &tx_4_1G[0];
2174 break;
2175 case NEPTUNE_2_10GF:
2176 ch_arr_p = &tx_2_10G[0];
2177 break;
2178 case NEPTUNE_2_10GF_2_1GC:
2179 case NEPTUNE_2_10GF_2_1GRF:
2180 ch_arr_p = &tx_2_10G_2_1G[0];
2181 break;
2182 case NEPTUNE_1_10GF_3_1GC:
2183 ch_arr_p = &tx_1_10G_3_1G[0];
2184 break;
2185 case NEPTUNE_1_1GC_1_10GF_2_1GC:
2186 ch_arr_p = &tx_1_1G_1_10G_2_1G[0];
2187 break;
2188 default:
2189 switch (nxgep->platform_type) {
2190 case P_NEPTUNE_ALONSO:
2191 ch_arr_p = &tx_2_10G_2_1G[0];
2192 break;
2193 default:
2194 ch_arr_p = &p4_tx_equal[0];
2195 break;
2196 }
2197 break;
2198 }
2199 st_txdma = 0;
2200 for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
2201 st_txdma += *ch_arr_p;
2202
2203 (void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2204 prop, st_txdma);
2205 p_cfgp->tdc.start = st_txdma;
2206 }
2207
2208 prop = param_arr[param_txdma_channels].fcode_name;
2209 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2210 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2211 tx_ndmas = *prop_val;
2212 ddi_prop_free(prop_val);
2213 } else {
2214 switch (nxgep->niu_type) {
2215 case NEPTUNE_4_1GC:
2216 tx_ndmas = tx_4_1G[nxgep->function_num];
2217 break;
2218 case NEPTUNE_2_10GF:
2219 tx_ndmas = tx_2_10G[nxgep->function_num];
2220 break;
2221 case NEPTUNE_2_10GF_2_1GC:
2222 case NEPTUNE_2_10GF_2_1GRF:
2223 tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
2224 break;
2225 case NEPTUNE_1_10GF_3_1GC:
2226 tx_ndmas = tx_1_10G_3_1G[nxgep->function_num];
2227 break;
2228 case NEPTUNE_1_1GC_1_10GF_2_1GC:
2229 tx_ndmas = tx_1_1G_1_10G_2_1G[nxgep->function_num];
2230 break;
2231 default:
2232 switch (nxgep->platform_type) {
2233 case P_NEPTUNE_ALONSO:
2234 tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
2235 break;
2236 default:
2237 tx_ndmas = p4_tx_equal[nxgep->function_num];
2238 break;
2239 }
2240 break;
2241 }
2242 (void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2243 prop, tx_ndmas);
2244 }
2245
2246 p_cfgp->tdc.count = tx_ndmas;
2247 p_cfgp->tdc.owned = p_cfgp->tdc.count;
2248 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
2249 "p_cfgp 0x%llx max_tdcs %d", p_cfgp, p_cfgp->tdc.count));
2250
2251 prop = param_arr[param_rxdma_channels_begin].fcode_name;
2252
2253 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2254 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2255 p_cfgp->start_rdc = *prop_val;
2256 ddi_prop_free(prop_val);
2257 } else {
2258 switch (nxgep->niu_type) {
2259 case NEPTUNE_4_1GC:
2260 ch_arr_p = &rx_4_1G[0];
2261 break;
2262 case NEPTUNE_2_10GF:
2263 ch_arr_p = &rx_2_10G[0];
2264 break;
2265 case NEPTUNE_2_10GF_2_1GC:
2266 case NEPTUNE_2_10GF_2_1GRF:
2267 ch_arr_p = &rx_2_10G_2_1G[0];
2268 break;
2269 case NEPTUNE_1_10GF_3_1GC:
2270 ch_arr_p = &rx_1_10G_3_1G[0];
2271 break;
2272 case NEPTUNE_1_1GC_1_10GF_2_1GC:
2273 ch_arr_p = &rx_1_1G_1_10G_2_1G[0];
2274 break;
2275 default:
2276 switch (nxgep->platform_type) {
2277 case P_NEPTUNE_ALONSO:
2278 ch_arr_p = &rx_2_10G_2_1G[0];
2279 break;
2280 default:
2281 ch_arr_p = &p4_rx_equal[0];
2282 break;
2283 }
2284 break;
2285 }
2286 st_rxdma = 0;
2287 for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
2288 st_rxdma += *ch_arr_p;
2289
2290 (void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2291 prop, st_rxdma);
2292 p_cfgp->start_rdc = st_rxdma;
2293 }
2294
2295 prop = param_arr[param_rxdma_channels].fcode_name;
2296
2297 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2298 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2299 rx_ndmas = *prop_val;
2300 ddi_prop_free(prop_val);
2301 } else {
2302 switch (nxgep->niu_type) {
2303 case NEPTUNE_4_1GC:
2304 rx_ndmas = rx_4_1G[nxgep->function_num];
2305 break;
2306 case NEPTUNE_2_10GF:
2307 rx_ndmas = rx_2_10G[nxgep->function_num];
2308 break;
2309 case NEPTUNE_2_10GF_2_1GC:
2310 case NEPTUNE_2_10GF_2_1GRF:
2311 rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
2312 break;
2313 case NEPTUNE_1_10GF_3_1GC:
2314 rx_ndmas = rx_1_10G_3_1G[nxgep->function_num];
2315 break;
2316 case NEPTUNE_1_1GC_1_10GF_2_1GC:
2317 rx_ndmas = rx_1_1G_1_10G_2_1G[nxgep->function_num];
2318 break;
2319 default:
2320 switch (nxgep->platform_type) {
2321 case P_NEPTUNE_ALONSO:
2322 rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
2323 break;
2324 default:
2325 rx_ndmas = p4_rx_equal[nxgep->function_num];
2326 break;
2327 }
2328 break;
2329 }
2330 (void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2331 prop, rx_ndmas);
2332 }
2333
2334 p_cfgp->max_rdcs = rx_ndmas;
2335
2336 /*
2337 * RDC groups and the beginning RDC group assigned to this function.
2338 * XXX: this may be wrong if prop value is used.
2339 */
2340 p_cfgp->def_mac_rxdma_grpid =
2341 nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
2342 p_cfgp->def_mac_txdma_grpid =
2343 nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
2344
2345 if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
2346 p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
2347 NXGE_ERROR_MSG((nxgep, CFG_CTL,
2348 "nxge_use_default_dma_config2(): "
2349 "nxge_fzc_rdc_tbl_bind failed"));
2350 goto nxge_use_cfg_dma_config_exit;
2351 }
2352
2353 prop = param_arr[param_rx_rdc_grps].fcode_name;
2354 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2355 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2356 nrxgp = *prop_val;
2357 ddi_prop_free(prop_val);
2358 } else {
2359 nrxgp = NXGE_MAX_RDC_GRPS / nxgep->nports;
2360 (void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
2361 prop, nrxgp);
2362 NXGE_DEBUG_MSG((nxgep, CFG_CTL,
2363 "==> nxge_use_default_dma_config: "
2364 "num_rdc_grpid not found: use def:# of "
2365 "rdc groups %d\n", nrxgp));
2366 }
2367 p_cfgp->max_rdc_grpids = nrxgp;
2368
2369 /*
2370 * 2/4 ports have the same hard-wired logical groups assigned.
2371 */
2372 p_cfgp->start_ldg = nxgep->function_num * NXGE_LDGRP_PER_4PORTS;
2373 p_cfgp->max_ldgs = NXGE_LDGRP_PER_4PORTS;
2374
2375 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_default_dma_config: "
2376 "p_cfgp 0x%llx max_rdcs %d max_grpids %d default_grpid %d",
2377 p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
2378 p_cfgp->def_mac_rxdma_grpid));
2379
2380 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
2381 "p_cfgp 0x%016llx start_ldg %d nxgep->max_ldgs %d "
2382 "def_mac_rxdma_grpid %d",
2383 p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs,
2384 p_cfgp->def_mac_rxdma_grpid));
2385
2386 nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
2387 prop = param_arr[param_rxdma_intr_time].fcode_name;
2388
2389 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2390 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2391 if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
2392 nxgep->intr_timeout = prop_val[0];
2393 (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
2394 nxgep->dip, prop, prop_val, prop_len);
2395 }
2396 ddi_prop_free(prop_val);
2397 }
2398
2399 nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
2400 prop = param_arr[param_rxdma_intr_pkts].fcode_name;
2401
2402 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
2403 &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
2404 if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
2405 nxgep->intr_threshold = prop_val[0];
2406 (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
2407 nxgep->dip, prop, prop_val, prop_len);
2408 }
2409 ddi_prop_free(prop_val);
2410 }
2411 nxge_set_hw_dma_config(nxgep);
2412
2413 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config: "
2414 "sTDC[%d] nTDC[%d] sRDC[%d] nRDC[%d]",
2415 p_cfgp->tdc.start, p_cfgp->tdc.count,
2416 p_cfgp->start_rdc, p_cfgp->max_rdcs));
2417
2418 nxge_use_cfg_dma_config_exit:
2419 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config"));
2420 }
2421
2422 void
nxge_get_logical_props(p_nxge_t nxgep)2423 nxge_get_logical_props(p_nxge_t nxgep)
2424 {
2425 nxge_dma_pt_cfg_t *port = &nxgep->pt_config;
2426 nxge_hw_pt_cfg_t *hardware;
2427 nxge_rdc_grp_t *group;
2428
2429 (void) memset(port, 0, sizeof (*port));
2430
2431 port->mac_port = nxgep->function_num; /* := function number */
2432
2433 /*
2434 * alloc_buf_size:
2435 * dead variables.
2436 */
2437 port->rbr_size = nxge_rbr_size;
2438 port->rcr_size = nxge_rcr_size;
2439
2440 port->tx_dma_map = 0; /* Transmit DMA channel bit map */
2441
2442 nxge_set_rdc_intr_property(nxgep);
2443
2444 port->rcr_full_header = NXGE_RCR_FULL_HEADER;
2445 port->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
2446
2447 /* ----------------------------------------------------- */
2448 hardware = &port->hw_config;
2449
2450 (void) memset(hardware, 0, sizeof (*hardware));
2451
2452 /*
2453 * partition_id, read_write_mode:
2454 * dead variables.
2455 */
2456
2457 /*
2458 * drr_wt, rx_full_header, *_ldg?, start_mac_entry,
2459 * mac_pref, def_mac_rxdma_grpid, start_vlan, max_vlans,
2460 * start_ldgs, max_ldgs, max_ldvs,
2461 * vlan_pref, def_vlan_rxdma_grpid are meaningful only
2462 * in the service domain.
2463 */
2464
2465 group = &port->rdc_grps[0];
2466
2467 group->flag = B_TRUE; /* configured */
2468 group->config_method = RDC_TABLE_ENTRY_METHOD_REP;
2469 group->port = NXGE_GET_PORT_NUM(nxgep->function_num);
2470
2471 /* HIO futures: this is still an open question. */
2472 hardware->max_macs = 1;
2473 }
2474
2475 static void
nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)2476 nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)
2477 {
2478 uint_t vlan_cnt;
2479 int *vlan_cfg_val;
2480 int status;
2481 p_nxge_param_t param_arr;
2482 char *prop;
2483
2484 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_vlan_config"));
2485 param_arr = nxgep->param_arr;
2486 prop = param_arr[param_vlan_2rdc_grp].fcode_name;
2487
2488 status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
2489 &vlan_cfg_val, &vlan_cnt);
2490 if (status == DDI_PROP_SUCCESS) {
2491 status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
2492 nxgep->dip, prop, vlan_cfg_val, vlan_cnt);
2493 ddi_prop_free(vlan_cfg_val);
2494 }
2495 nxge_set_hw_vlan_class_config(nxgep);
2496 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_vlan_config"));
2497 }
2498
2499 static void
nxge_use_cfg_mac_class_config(p_nxge_t nxgep)2500 nxge_use_cfg_mac_class_config(p_nxge_t nxgep)
2501 {
2502 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2503 p_nxge_hw_pt_cfg_t p_cfgp;
2504 uint_t mac_cnt;
2505 int *mac_cfg_val;
2506 int status;
2507 p_nxge_param_t param_arr;
2508 char *prop;
2509
2510 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_mac_class_config"));
2511 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2512 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2513 p_cfgp->start_mac_entry = 0;
2514 param_arr = nxgep->param_arr;
2515 prop = param_arr[param_mac_2rdc_grp].fcode_name;
2516
2517 switch (nxgep->function_num) {
2518 case 0:
2519 case 1:
2520 /* 10G ports */
2521 p_cfgp->max_macs = NXGE_MAX_MACS_XMACS;
2522 break;
2523 case 2:
2524 case 3:
2525 /* 1G ports */
2526 default:
2527 p_cfgp->max_macs = NXGE_MAX_MACS_BMACS;
2528 break;
2529 }
2530
2531 p_cfgp->mac_pref = 1;
2532 NXGE_DEBUG_MSG((nxgep, OBP_CTL,
2533 "== nxge_use_cfg_mac_class_config: "
2534 " mac_pref bit set def_mac_rxdma_grpid %d",
2535 p_cfgp->def_mac_rxdma_grpid));
2536
2537 status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
2538 &mac_cfg_val, &mac_cnt);
2539 if (status == DDI_PROP_SUCCESS) {
2540 if (mac_cnt <= p_cfgp->max_macs)
2541 status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
2542 nxgep->dip, prop, mac_cfg_val, mac_cnt);
2543 ddi_prop_free(mac_cfg_val);
2544 }
2545 nxge_set_hw_mac_class_config(nxgep);
2546 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_mac_class_config"));
2547 }
2548
2549 static void
nxge_use_cfg_class_config(p_nxge_t nxgep)2550 nxge_use_cfg_class_config(p_nxge_t nxgep)
2551 {
2552 nxge_set_hw_class_config(nxgep);
2553 }
2554
2555 static void
nxge_set_rdc_intr_property(p_nxge_t nxgep)2556 nxge_set_rdc_intr_property(p_nxge_t nxgep)
2557 {
2558 int i;
2559 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2560
2561 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_rdc_intr_property"));
2562 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2563
2564 for (i = 0; i < NXGE_MAX_RDCS; i++) {
2565 p_dma_cfgp->rcr_timeout[i] = nxgep->intr_timeout;
2566 p_dma_cfgp->rcr_threshold[i] = nxgep->intr_threshold;
2567 }
2568
2569 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_rdc_intr_property"));
2570 }
2571
2572 static void
nxge_set_hw_dma_config(p_nxge_t nxgep)2573 nxge_set_hw_dma_config(p_nxge_t nxgep)
2574 {
2575 int i, j, ngrps, bitmap, end, st_rdc;
2576 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2577 p_nxge_hw_pt_cfg_t p_cfgp;
2578 p_nxge_rdc_grp_t rdc_grp_p;
2579 p_nxge_tdc_grp_t tdc_grp_p;
2580 nxge_grp_t *group;
2581 uint8_t nrdcs;
2582 dc_map_t map = 0;
2583
2584 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_dma_config"));
2585
2586 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2587 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2588
2589 switch (nxgep->niu_type) {
2590 case NEPTUNE_4_1GC:
2591 case NEPTUNE_2_10GF_2_1GC:
2592 case NEPTUNE_1_10GF_3_1GC:
2593 case NEPTUNE_1_1GC_1_10GF_2_1GC:
2594 case NEPTUNE_2_10GF_2_1GRF:
2595 default:
2596 ngrps = 2;
2597 break;
2598 case NEPTUNE_2_10GF:
2599 case NEPTUNE_2_1GRF:
2600 case N2_NIU:
2601 ngrps = 4;
2602 break;
2603 }
2604
2605 /*
2606 * Setup TDC groups
2607 */
2608 bitmap = 0;
2609 end = p_cfgp->tdc.start + p_cfgp->tdc.owned;
2610 for (i = p_cfgp->tdc.start; i < end; i++) {
2611 bitmap |= (1 << i);
2612 }
2613
2614 nxgep->tx_set.owned.map |= bitmap; /* Owned, & not shared. */
2615 nxgep->tx_set.owned.count = p_cfgp->tdc.owned;
2616 p_dma_cfgp->tx_dma_map = bitmap;
2617
2618 for (i = 0; i < ngrps; i++) {
2619 group = (nxge_grp_t *)nxge_grp_add(nxgep,
2620 NXGE_TRANSMIT_GROUP);
2621 tdc_grp_p = &p_dma_cfgp->tdc_grps[
2622 p_cfgp->def_mac_txdma_grpid + i];
2623 if (i == 0)
2624 tdc_grp_p->map = bitmap;
2625 else
2626 tdc_grp_p->map = 0;
2627 /* no ring is associated with a group initially */
2628 tdc_grp_p->start_tdc = 0;
2629 tdc_grp_p->max_tdcs = 0;
2630 tdc_grp_p->grp_index = group->index;
2631 }
2632
2633 /*
2634 * Setup RDC groups
2635 */
2636 st_rdc = p_cfgp->start_rdc;
2637 for (i = 0; i < ngrps; i++) {
2638 /*
2639 * All rings are associated with the default group initially
2640 */
2641 if (i == 0) {
2642 /* default group */
2643 switch (nxgep->niu_type) {
2644 case NEPTUNE_4_1GC:
2645 nrdcs = rx_4_1G[nxgep->function_num];
2646 break;
2647 case N2_NIU:
2648 case NEPTUNE_2_10GF:
2649 nrdcs = rx_2_10G[nxgep->function_num];
2650 break;
2651 case NEPTUNE_2_10GF_2_1GC:
2652 nrdcs = rx_2_10G_2_1G[nxgep->function_num];
2653 break;
2654 case NEPTUNE_1_10GF_3_1GC:
2655 nrdcs = rx_1_10G_3_1G[nxgep->function_num];
2656 break;
2657 case NEPTUNE_1_1GC_1_10GF_2_1GC:
2658 nrdcs = rx_1_1G_1_10G_2_1G[nxgep->function_num];
2659 break;
2660 default:
2661 switch (nxgep->platform_type) {
2662 case P_NEPTUNE_ALONSO:
2663 nrdcs =
2664 rx_2_10G_2_1G[nxgep->function_num];
2665 break;
2666 default:
2667 nrdcs = rx_4_1G[nxgep->function_num];
2668 break;
2669 }
2670 break;
2671 }
2672
2673 if (p_cfgp->max_rdcs < nrdcs)
2674 nrdcs = p_cfgp->max_rdcs;
2675 } else {
2676 nrdcs = 0;
2677 }
2678
2679 rdc_grp_p = &p_dma_cfgp->rdc_grps[
2680 p_cfgp->def_mac_rxdma_grpid + i];
2681 rdc_grp_p->start_rdc = st_rdc;
2682 rdc_grp_p->max_rdcs = nrdcs;
2683 rdc_grp_p->def_rdc = rdc_grp_p->start_rdc;
2684
2685 /* default to: 0, 1, 2, 3, ...., 0, 1, 2, 3.... */
2686 if (nrdcs != 0) {
2687 for (j = 0; j < nrdcs; j++) {
2688 map |= (1 << j);
2689 }
2690 map <<= rdc_grp_p->start_rdc;
2691 } else
2692 map = 0;
2693 rdc_grp_p->map = map;
2694
2695 nxgep->rx_set.owned.map |= map; /* Owned, & not shared. */
2696 nxgep->rx_set.owned.count = nrdcs;
2697
2698 group = (nxge_grp_t *)nxge_grp_add(nxgep, NXGE_RECEIVE_GROUP);
2699
2700 rdc_grp_p->config_method = RDC_TABLE_ENTRY_METHOD_SEQ;
2701 rdc_grp_p->flag = B_TRUE; /* This group has been configured. */
2702 rdc_grp_p->grp_index = group->index;
2703 rdc_grp_p->port = NXGE_GET_PORT_NUM(nxgep->function_num);
2704
2705 map = 0;
2706 }
2707
2708
2709 /* default RDC */
2710 p_cfgp->def_rdc = p_cfgp->start_rdc;
2711 nxgep->def_rdc = p_cfgp->start_rdc;
2712
2713 /* full 18 byte header ? */
2714 p_dma_cfgp->rcr_full_header = NXGE_RCR_FULL_HEADER;
2715 p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
2716 if (nxgep->function_num > 1)
2717 p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_1G;
2718 p_dma_cfgp->rbr_size = nxge_rbr_size;
2719 p_dma_cfgp->rcr_size = nxge_rcr_size;
2720
2721 nxge_set_rdc_intr_property(nxgep);
2722 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_dma_config"));
2723 }
2724
2725 boolean_t
nxge_check_rxdma_port_member(p_nxge_t nxgep,uint8_t rdc)2726 nxge_check_rxdma_port_member(p_nxge_t nxgep, uint8_t rdc)
2727 {
2728 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2729 p_nxge_hw_pt_cfg_t p_cfgp;
2730 int status = B_TRUE;
2731
2732 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rxdma_port_member"));
2733
2734 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2735 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2736
2737 /* Receive DMA Channels */
2738 if (rdc < p_cfgp->max_rdcs)
2739 status = B_TRUE;
2740 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rxdma_port_member"));
2741 return (status);
2742 }
2743
2744 boolean_t
nxge_check_txdma_port_member(p_nxge_t nxgep,uint8_t tdc)2745 nxge_check_txdma_port_member(p_nxge_t nxgep, uint8_t tdc)
2746 {
2747 int status = B_FALSE;
2748
2749 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_txdma_port_member"));
2750
2751 if (tdc >= nxgep->pt_config.hw_config.tdc.start &&
2752 tdc < nxgep->pt_config.hw_config.tdc.count)
2753 status = B_TRUE;
2754
2755 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_txdma_port_member"));
2756 return (status);
2757 }
2758
2759 boolean_t
nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep,uint8_t rdc_grp,uint8_t rdc)2760 nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep, uint8_t rdc_grp, uint8_t rdc)
2761 {
2762 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2763 int status = B_TRUE;
2764 p_nxge_rdc_grp_t rdc_grp_p;
2765
2766 NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
2767 " ==> nxge_check_rxdma_rdcgrp_member"));
2768 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " nxge_check_rxdma_rdcgrp_member"
2769 " rdc %d group %d", rdc, rdc_grp));
2770 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2771
2772 rdc_grp_p = &p_dma_cfgp->rdc_grps[rdc_grp];
2773 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " max %d ", rdc_grp_p->max_rdcs));
2774 if (rdc >= rdc_grp_p->max_rdcs) {
2775 status = B_FALSE;
2776 }
2777 NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
2778 " <== nxge_check_rxdma_rdcgrp_member"));
2779 return (status);
2780 }
2781
2782 boolean_t
nxge_check_rdcgrp_port_member(p_nxge_t nxgep,uint8_t rdc_grp)2783 nxge_check_rdcgrp_port_member(p_nxge_t nxgep, uint8_t rdc_grp)
2784 {
2785 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2786 p_nxge_hw_pt_cfg_t p_cfgp;
2787 int status = B_TRUE;
2788
2789 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rdcgrp_port_member"));
2790
2791 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2792 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2793
2794 if (rdc_grp >= p_cfgp->max_rdc_grpids)
2795 status = B_FALSE;
2796 NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rdcgrp_port_member"));
2797 return (status);
2798 }
2799
2800 static void
nxge_set_hw_vlan_class_config(p_nxge_t nxgep)2801 nxge_set_hw_vlan_class_config(p_nxge_t nxgep)
2802 {
2803 int i;
2804 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2805 p_nxge_hw_pt_cfg_t p_cfgp;
2806 p_nxge_param_t param_arr;
2807 uint_t vlan_cnt;
2808 int *vlan_cfg_val;
2809 nxge_param_map_t *vmap;
2810 char *prop;
2811 p_nxge_class_pt_cfg_t p_class_cfgp;
2812 uint32_t good_cfg[32];
2813 int good_count = 0;
2814 nxge_mv_cfg_t *vlan_tbl;
2815
2816 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_vlan_config"));
2817 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2818 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2819 p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
2820
2821 param_arr = nxgep->param_arr;
2822 prop = param_arr[param_vlan_2rdc_grp].fcode_name;
2823
2824 /*
2825 * By default, VLAN to RDC group mapping is disabled Need to read HW or
2826 * .conf properties to find out if mapping is required
2827 *
2828 * Format
2829 *
2830 * uint32_t array, each array entry specifying the VLAN id and the
2831 * mapping
2832 *
2833 * bit[30] = add bit[29] = remove bit[28] = preference bits[23-16] =
2834 * rdcgrp bits[15-0] = VLAN ID ( )
2835 */
2836
2837 for (i = 0; i < NXGE_MAX_VLANS; i++) {
2838 p_class_cfgp->vlan_tbl[i].flag = 0;
2839 }
2840
2841 vlan_tbl = (nxge_mv_cfg_t *)&p_class_cfgp->vlan_tbl[0];
2842 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
2843 &vlan_cfg_val, &vlan_cnt) == DDI_PROP_SUCCESS) {
2844 for (i = 0; i < vlan_cnt; i++) {
2845 vmap = (nxge_param_map_t *)&vlan_cfg_val[i];
2846 if ((vmap->param_id) &&
2847 (vmap->param_id < NXGE_MAX_VLANS) &&
2848 (vmap->map_to < p_cfgp->max_rdc_grpids)) {
2849 NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
2850 " nxge_vlan_config mapping"
2851 " id %d grp %d",
2852 vmap->param_id, vmap->map_to));
2853 good_cfg[good_count] = vlan_cfg_val[i];
2854 if (vlan_tbl[vmap->param_id].flag == 0)
2855 good_count++;
2856 vlan_tbl[vmap->param_id].flag = 1;
2857 vlan_tbl[vmap->param_id].rdctbl =
2858 vmap->map_to + p_cfgp->def_mac_rxdma_grpid;
2859 vlan_tbl[vmap->param_id].mpr_npr = vmap->pref;
2860 }
2861 }
2862 ddi_prop_free(vlan_cfg_val);
2863 if (good_count != vlan_cnt) {
2864 (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
2865 nxgep->dip, prop, (int *)good_cfg, good_count);
2866 }
2867 }
2868 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_vlan_config"));
2869 }
2870
2871 static void
nxge_set_hw_mac_class_config(p_nxge_t nxgep)2872 nxge_set_hw_mac_class_config(p_nxge_t nxgep)
2873 {
2874 int i;
2875 p_nxge_dma_pt_cfg_t p_dma_cfgp;
2876 p_nxge_hw_pt_cfg_t p_cfgp;
2877 p_nxge_param_t param_arr;
2878 uint_t mac_cnt;
2879 int *mac_cfg_val;
2880 nxge_param_map_t *mac_map;
2881 char *prop;
2882 p_nxge_class_pt_cfg_t p_class_cfgp;
2883 int good_count = 0;
2884 int good_cfg[NXGE_MAX_MACS];
2885 nxge_mv_cfg_t *mac_host_info;
2886
2887 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_mac_config"));
2888
2889 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
2890 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
2891 p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
2892 mac_host_info = (nxge_mv_cfg_t *)&p_class_cfgp->mac_host_info[0];
2893
2894 param_arr = nxgep->param_arr;
2895 prop = param_arr[param_mac_2rdc_grp].fcode_name;
2896
2897 for (i = 0; i < NXGE_MAX_MACS; i++) {
2898 p_class_cfgp->mac_host_info[i].flag = 0;
2899 p_class_cfgp->mac_host_info[i].rdctbl =
2900 p_cfgp->def_mac_rxdma_grpid;
2901 }
2902
2903 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
2904 &mac_cfg_val, &mac_cnt) == DDI_PROP_SUCCESS) {
2905 for (i = 0; i < mac_cnt; i++) {
2906 mac_map = (nxge_param_map_t *)&mac_cfg_val[i];
2907 if ((mac_map->param_id < p_cfgp->max_macs) &&
2908 (mac_map->map_to < p_cfgp->max_rdc_grpids)) {
2909 NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
2910 " nxge_mac_config mapping"
2911 " id %d grp %d",
2912 mac_map->param_id, mac_map->map_to));
2913 mac_host_info[mac_map->param_id].mpr_npr =
2914 p_cfgp->mac_pref;
2915 mac_host_info[mac_map->param_id].rdctbl =
2916 mac_map->map_to +
2917 p_cfgp->def_mac_rxdma_grpid;
2918 good_cfg[good_count] = mac_cfg_val[i];
2919 if (mac_host_info[mac_map->param_id].flag == 0)
2920 good_count++;
2921 mac_host_info[mac_map->param_id].flag = 1;
2922 }
2923 }
2924 ddi_prop_free(mac_cfg_val);
2925 if (good_count != mac_cnt) {
2926 (void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
2927 nxgep->dip, prop, good_cfg, good_count);
2928 }
2929 }
2930 NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_mac_config"));
2931 }
2932
2933 static void
nxge_set_hw_class_config(p_nxge_t nxgep)2934 nxge_set_hw_class_config(p_nxge_t nxgep)
2935 {
2936 int i;
2937 p_nxge_param_t param_arr;
2938 int *int_prop_val;
2939 uint32_t cfg_value;
2940 char *prop;
2941 p_nxge_class_pt_cfg_t p_class_cfgp;
2942 int start_prop, end_prop;
2943 uint_t prop_cnt;
2944 int start_class, j = 0;
2945
2946 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_class_config"));
2947
2948 p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
2949 param_arr = nxgep->param_arr;
2950 start_prop = param_class_opt_ipv4_tcp;
2951 end_prop = param_class_opt_ipv6_sctp;
2952 start_class = TCAM_CLASS_TCP_IPV4;
2953
2954 for (i = start_prop, j = 0; i <= end_prop; i++, j++) {
2955 prop = param_arr[i].fcode_name;
2956 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip,
2957 0, prop, &int_prop_val,
2958 &prop_cnt) == DDI_PROP_SUCCESS) {
2959 cfg_value = (uint32_t)*int_prop_val;
2960 ddi_prop_free(int_prop_val);
2961 } else {
2962 cfg_value = (uint32_t)param_arr[i].value;
2963 }
2964 p_class_cfgp->class_cfg[start_class + j] = cfg_value;
2965 }
2966
2967 prop = param_arr[param_h1_init_value].fcode_name;
2968
2969 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
2970 &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
2971 cfg_value = (uint32_t)*int_prop_val;
2972 ddi_prop_free(int_prop_val);
2973 } else {
2974 cfg_value = (uint32_t)param_arr[param_h1_init_value].value;
2975 }
2976
2977 p_class_cfgp->init_h1 = (uint32_t)cfg_value;
2978 prop = param_arr[param_h2_init_value].fcode_name;
2979
2980 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
2981 &int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
2982 cfg_value = (uint32_t)*int_prop_val;
2983 ddi_prop_free(int_prop_val);
2984 } else {
2985 cfg_value = (uint32_t)param_arr[param_h2_init_value].value;
2986 }
2987
2988 p_class_cfgp->init_h2 = (uint16_t)cfg_value;
2989 NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_class_config"));
2990 }
2991
2992 nxge_status_t
nxge_ldgv_init_n2(p_nxge_t nxgep,int * navail_p,int * nrequired_p)2993 nxge_ldgv_init_n2(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
2994 {
2995 int i, maxldvs, maxldgs, nldvs;
2996 int ldv, endldg;
2997 uint8_t func;
2998 uint8_t channel;
2999 uint8_t chn_start;
3000 boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
3001 p_nxge_dma_pt_cfg_t p_dma_cfgp;
3002 p_nxge_hw_pt_cfg_t p_cfgp;
3003 p_nxge_ldgv_t ldgvp;
3004 p_nxge_ldg_t ldgp, ptr;
3005 p_nxge_ldv_t ldvp, sysldvp;
3006 nxge_status_t status = NXGE_OK;
3007 nxge_grp_set_t *set;
3008
3009 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2"));
3010 if (!*navail_p) {
3011 *nrequired_p = 0;
3012 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3013 "<== nxge_ldgv_init:no avail"));
3014 return (NXGE_ERROR);
3015 }
3016 /*
3017 * N2/NIU: one logical device owns one logical group. and each
3018 * device/group will be assigned one vector by Hypervisor.
3019 */
3020 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
3021 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
3022 maxldgs = p_cfgp->max_ldgs;
3023 if (!maxldgs) {
3024 /* No devices configured. */
3025 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init_n2: "
3026 "no logical groups configured."));
3027 return (NXGE_ERROR);
3028 } else {
3029 maxldvs = maxldgs + 1;
3030 }
3031
3032 /*
3033 * If function zero instance, it needs to handle the system and MIF
3034 * error interrupts. MIF interrupt may not be needed for N2/NIU.
3035 */
3036 func = nxgep->function_num;
3037 if (func == 0) {
3038 own_sys_err = B_TRUE;
3039 if (!p_cfgp->ser_ldvid) {
3040 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3041 "nxge_ldgv_init_n2: func 0, ERR ID not set!"));
3042 }
3043 /* MIF interrupt */
3044 if (!p_cfgp->mif_ldvid) {
3045 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3046 "nxge_ldgv_init_n2: func 0, MIF ID not set!"));
3047 }
3048 }
3049
3050 /*
3051 * Assume single partition, each function owns mac.
3052 */
3053 if (!nxge_use_partition)
3054 own_fzc = B_TRUE;
3055
3056 ldgvp = nxgep->ldgvp;
3057 if (ldgvp == NULL) {
3058 ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
3059 nxgep->ldgvp = ldgvp;
3060 ldgvp->maxldgs = (uint8_t)maxldgs;
3061 ldgvp->maxldvs = (uint8_t)maxldvs;
3062 ldgp = ldgvp->ldgp = KMEM_ZALLOC(
3063 sizeof (nxge_ldg_t) * maxldgs, KM_SLEEP);
3064 ldvp = ldgvp->ldvp = KMEM_ZALLOC(
3065 sizeof (nxge_ldv_t) * maxldvs, KM_SLEEP);
3066 } else {
3067 ldgp = ldgvp->ldgp;
3068 ldvp = ldgvp->ldvp;
3069 }
3070
3071 ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
3072 ldgvp->tmres = NXGE_TIMER_RESO;
3073
3074 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3075 "==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d",
3076 maxldvs, maxldgs));
3077
3078 /* logical start_ldg is ldv */
3079 ptr = ldgp;
3080 for (i = 0; i < maxldgs; i++) {
3081 ptr->func = func;
3082 ptr->arm = B_TRUE;
3083 ptr->vldg_index = (uint8_t)i;
3084 ptr->ldg_timer = NXGE_TIMER_LDG;
3085 ptr->ldg = p_cfgp->ldg[i];
3086 ptr->sys_intr_handler = nxge_intr;
3087 ptr->nldvs = 0;
3088 ptr->ldvp = NULL;
3089 ptr->nxgep = nxgep;
3090 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3091 "==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d "
3092 "ldg %d ldgptr $%p",
3093 maxldvs, maxldgs, ptr->ldg, ptr));
3094 ptr++;
3095 }
3096
3097 endldg = NXGE_INT_MAX_LDG;
3098 nldvs = 0;
3099 ldgvp->nldvs = 0;
3100 ldgp->ldvp = NULL;
3101 *nrequired_p = 0;
3102
3103 /*
3104 * logical device group table is organized in the following order (same
3105 * as what interrupt property has). function 0: owns MAC, MIF, error,
3106 * rx, tx. function 1: owns MAC, rx, tx.
3107 */
3108
3109 if (own_fzc && p_cfgp->mac_ldvid) {
3110 /* Each function should own MAC interrupt */
3111 ldv = p_cfgp->mac_ldvid;
3112 ldvp->ldv = (uint8_t)ldv;
3113 ldvp->is_mac = B_TRUE;
3114 ldvp->ldv_intr_handler = nxge_mac_intr;
3115 ldvp->ldv_ldf_masks = 0;
3116 ldvp->nxgep = nxgep;
3117 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3118 "==> nxge_ldgv_init_n2(mac): maxldvs %d ldv %d "
3119 "ldg %d ldgptr $%p ldvptr $%p",
3120 maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
3121 nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
3122 nldvs++;
3123 }
3124
3125 if (own_fzc && p_cfgp->mif_ldvid) {
3126 ldv = p_cfgp->mif_ldvid;
3127 ldvp->ldv = (uint8_t)ldv;
3128 ldvp->is_mif = B_TRUE;
3129 ldvp->ldv_intr_handler = nxge_mif_intr;
3130 ldvp->ldv_ldf_masks = 0;
3131 ldvp->nxgep = nxgep;
3132 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3133 "==> nxge_ldgv_init_n2(mif): maxldvs %d ldv %d "
3134 "ldg %d ldgptr $%p ldvptr $%p",
3135 maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
3136 nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
3137 nldvs++;
3138 }
3139
3140 /*
3141 * HW based syserr interrupt for port0, and SW based syserr interrupt
3142 * for port1
3143 */
3144 if (own_sys_err && p_cfgp->ser_ldvid) {
3145 ldv = p_cfgp->ser_ldvid;
3146 /*
3147 * Unmask the system interrupt states.
3148 */
3149 (void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
3150 SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
3151 SYS_ERR_ZCP_MASK);
3152
3153 ldvp->use_timer = B_TRUE;
3154 ldvp->ldv = (uint8_t)ldv;
3155 ldvp->is_syserr = B_TRUE;
3156 ldvp->ldv_intr_handler = nxge_syserr_intr;
3157 ldvp->ldv_ldf_masks = 0;
3158 ldvp->nxgep = nxgep;
3159 ldgvp->ldvp_syserr = ldvp;
3160
3161 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3162 "==> nxge_ldgv_init_n2(syserr): maxldvs %d ldv %d "
3163 "ldg %d ldgptr $%p ldvptr p%p",
3164 maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
3165 nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
3166 nldvs++;
3167 } else {
3168 /*
3169 * SW based: allocate the ldv for the syserr since the vector
3170 * should not be consumed for port1
3171 */
3172 sysldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t), KM_SLEEP);
3173 sysldvp->use_timer = B_TRUE;
3174 sysldvp->ldv = NXGE_SYS_ERROR_LD;
3175 sysldvp->is_syserr = B_TRUE;
3176 sysldvp->ldv_intr_handler = nxge_syserr_intr;
3177 sysldvp->ldv_ldf_masks = 0;
3178 sysldvp->nxgep = nxgep;
3179 ldgvp->ldvp_syserr = sysldvp;
3180 ldgvp->ldvp_syserr_alloced = B_TRUE;
3181 }
3182
3183
3184 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
3185 "(before rx) func %d nldvs %d navail %d nrequired %d",
3186 func, nldvs, *navail_p, *nrequired_p));
3187
3188 /*
3189 * Start with RDC to configure logical devices for each group.
3190 */
3191 chn_start = p_cfgp->ldg_chn_start;
3192 set = &nxgep->rx_set;
3193 for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
3194 if ((1 << channel) & set->owned.map) {
3195 ldvp->is_rxdma = B_TRUE;
3196 ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
3197 ldvp->channel = channel;
3198 ldvp->vdma_index = (uint8_t)channel;
3199 ldvp->ldv_intr_handler = nxge_rx_intr;
3200 ldvp->ldv_ldf_masks = 0;
3201 ldvp->nxgep = nxgep;
3202 ldgp->ldg = p_cfgp->ldg[chn_start];
3203
3204 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3205 "==> nxge_ldgv_init_n2(rx%d): maxldvs %d ldv %d "
3206 "ldg %d ldgptr 0x%016llx ldvptr 0x%016llx",
3207 i, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
3208 nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
3209 endldg, nrequired_p);
3210 nldvs++;
3211 chn_start++;
3212 }
3213 }
3214
3215 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
3216 "func %d nldvs %d navail %d nrequired %d",
3217 func, nldvs, *navail_p, *nrequired_p));
3218
3219 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
3220 "func %d nldvs %d navail %d nrequired %d ldgp 0x%llx "
3221 "ldvp 0x%llx",
3222 func, nldvs, *navail_p, *nrequired_p, ldgp, ldvp));
3223 /*
3224 * Transmit DMA channels.
3225 */
3226 chn_start = p_cfgp->ldg_chn_start + 8;
3227 set = &nxgep->tx_set;
3228 for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
3229 if ((1 << channel) & set->owned.map) {
3230 ldvp->is_txdma = B_TRUE;
3231 ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
3232 ldvp->channel = channel;
3233 ldvp->vdma_index = (uint8_t)channel;
3234 ldvp->ldv_intr_handler = nxge_tx_intr;
3235 ldvp->ldv_ldf_masks = 0;
3236 ldgp->ldg = p_cfgp->ldg[chn_start];
3237 ldvp->nxgep = nxgep;
3238 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3239 "==> nxge_ldgv_init_n2(tx%d): maxldvs %d ldv %d "
3240 "ldg %d ldgptr %p ldvptr %p",
3241 channel, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
3242 nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
3243 endldg, nrequired_p);
3244 nldvs++;
3245 chn_start++;
3246 }
3247 }
3248
3249 ldgvp->ldg_intrs = *nrequired_p;
3250 ldgvp->nldvs = (uint8_t)nldvs;
3251
3252 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
3253 "func %d nldvs %d maxgrps %d navail %d nrequired %d",
3254 func, nldvs, maxldgs, *navail_p, *nrequired_p));
3255
3256 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init_n2"));
3257 return (status);
3258 }
3259
3260 /*
3261 * Interrupts related interface functions.
3262 */
3263
3264 nxge_status_t
nxge_ldgv_init(p_nxge_t nxgep,int * navail_p,int * nrequired_p)3265 nxge_ldgv_init(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
3266 {
3267 int i, maxldvs, maxldgs, nldvs;
3268 int ldv, ldg, endldg, ngrps;
3269 uint8_t func;
3270 uint8_t channel;
3271 boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
3272 p_nxge_dma_pt_cfg_t p_dma_cfgp;
3273 p_nxge_hw_pt_cfg_t p_cfgp;
3274 p_nxge_ldgv_t ldgvp;
3275 p_nxge_ldg_t ldgp, ptr;
3276 p_nxge_ldv_t ldvp;
3277 nxge_grp_set_t *set;
3278
3279 nxge_status_t status = NXGE_OK;
3280
3281 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init"));
3282 if (!*navail_p) {
3283 *nrequired_p = 0;
3284 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3285 "<== nxge_ldgv_init:no avail"));
3286 return (NXGE_ERROR);
3287 }
3288 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
3289 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
3290
3291 nldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
3292
3293 /*
3294 * If function zero instance, it needs to handle the system error
3295 * interrupts.
3296 */
3297 func = nxgep->function_num;
3298 if (func == 0) {
3299 nldvs++;
3300 own_sys_err = B_TRUE;
3301 } else {
3302 /* use timer */
3303 nldvs++;
3304 }
3305
3306 /*
3307 * Assume single partition, each function owns mac.
3308 */
3309 if (!nxge_use_partition) {
3310 /* mac */
3311 nldvs++;
3312 /* MIF */
3313 nldvs++;
3314 own_fzc = B_TRUE;
3315 }
3316 maxldvs = nldvs;
3317 maxldgs = p_cfgp->max_ldgs;
3318 if (!maxldvs || !maxldgs) {
3319 /* No devices configured. */
3320 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init: "
3321 "no logical devices or groups configured."));
3322 return (NXGE_ERROR);
3323 }
3324 ldgvp = nxgep->ldgvp;
3325 if (ldgvp == NULL) {
3326 ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
3327 nxgep->ldgvp = ldgvp;
3328 ldgvp->maxldgs = (uint8_t)maxldgs;
3329 ldgvp->maxldvs = (uint8_t)maxldvs;
3330 ldgp = ldgvp->ldgp = KMEM_ZALLOC(sizeof (nxge_ldg_t) * maxldgs,
3331 KM_SLEEP);
3332 ldvp = ldgvp->ldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t) * maxldvs,
3333 KM_SLEEP);
3334 }
3335 ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
3336 ldgvp->tmres = NXGE_TIMER_RESO;
3337
3338 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3339 "==> nxge_ldgv_init: maxldvs %d maxldgs %d nldvs %d",
3340 maxldvs, maxldgs, nldvs));
3341 ldg = p_cfgp->start_ldg;
3342 ptr = ldgp;
3343 for (i = 0; i < maxldgs; i++) {
3344 ptr->func = func;
3345 ptr->arm = B_TRUE;
3346 ptr->vldg_index = (uint8_t)i;
3347 ptr->ldg_timer = NXGE_TIMER_LDG;
3348 ptr->ldg = ldg++;
3349 ptr->sys_intr_handler = nxge_intr;
3350 ptr->nldvs = 0;
3351 ptr->nxgep = nxgep;
3352 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3353 "==> nxge_ldgv_init: maxldvs %d maxldgs %d ldg %d",
3354 maxldvs, maxldgs, ptr->ldg));
3355 ptr++;
3356 }
3357
3358 ldg = p_cfgp->start_ldg;
3359 if (maxldgs > *navail_p) {
3360 ngrps = *navail_p;
3361 } else {
3362 ngrps = maxldgs;
3363 }
3364 endldg = ldg + ngrps;
3365
3366 /*
3367 * Receive DMA channels.
3368 */
3369 nldvs = 0;
3370 ldgvp->nldvs = 0;
3371 ldgp->ldvp = NULL;
3372 *nrequired_p = 0;
3373
3374 /*
3375 * Start with RDC to configure logical devices for each group.
3376 */
3377 set = &nxgep->rx_set;
3378 for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
3379 if ((1 << channel) & set->owned.map) {
3380 /* For now, <channel & <vdma_index> are the same. */
3381 ldvp->is_rxdma = B_TRUE;
3382 ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
3383 ldvp->channel = channel;
3384 ldvp->vdma_index = (uint8_t)channel;
3385 ldvp->ldv_intr_handler = nxge_rx_intr;
3386 ldvp->ldv_ldf_masks = 0;
3387 ldvp->use_timer = B_FALSE;
3388 ldvp->nxgep = nxgep;
3389 nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
3390 endldg, nrequired_p);
3391 nldvs++;
3392 }
3393 }
3394
3395 /*
3396 * Transmit DMA channels.
3397 */
3398 set = &nxgep->tx_set;
3399 for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
3400 if ((1 << channel) & set->owned.map) {
3401 /* For now, <channel & <vdma_index> are the same. */
3402 ldvp->is_txdma = B_TRUE;
3403 ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
3404 ldvp->channel = channel;
3405 ldvp->vdma_index = (uint8_t)channel;
3406 ldvp->ldv_intr_handler = nxge_tx_intr;
3407 ldvp->ldv_ldf_masks = 0;
3408 ldvp->use_timer = B_FALSE;
3409 ldvp->nxgep = nxgep;
3410 nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
3411 endldg, nrequired_p);
3412 nldvs++;
3413 }
3414 }
3415
3416 if (own_fzc) {
3417 ldv = NXGE_MIF_LD;
3418 ldvp->ldv = (uint8_t)ldv;
3419 ldvp->is_mif = B_TRUE;
3420 ldvp->ldv_intr_handler = nxge_mif_intr;
3421 ldvp->ldv_ldf_masks = 0;
3422 ldvp->use_timer = B_FALSE;
3423 ldvp->nxgep = nxgep;
3424 nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
3425 nldvs++;
3426 }
3427 /*
3428 * MAC port (function zero control)
3429 */
3430 if (own_fzc) {
3431 ldvp->is_mac = B_TRUE;
3432 ldvp->ldv_intr_handler = nxge_mac_intr;
3433 ldvp->ldv_ldf_masks = 0;
3434 ldv = func + NXGE_MAC_LD_START;
3435 ldvp->ldv = (uint8_t)ldv;
3436 ldvp->use_timer = B_FALSE;
3437 ldvp->nxgep = nxgep;
3438 nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
3439 nldvs++;
3440 }
3441 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
3442 "func %d nldvs %d navail %d nrequired %d",
3443 func, nldvs, *navail_p, *nrequired_p));
3444 /*
3445 * Function 0 owns system error interrupts.
3446 */
3447 ldvp->use_timer = B_TRUE;
3448 if (own_sys_err) {
3449 ldv = NXGE_SYS_ERROR_LD;
3450 ldvp->ldv = (uint8_t)ldv;
3451 ldvp->is_syserr = B_TRUE;
3452 ldvp->ldv_intr_handler = nxge_syserr_intr;
3453 ldvp->ldv_ldf_masks = 0;
3454 ldvp->nxgep = nxgep;
3455 ldgvp->ldvp_syserr = ldvp;
3456 /*
3457 * Unmask the system interrupt states.
3458 */
3459 (void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
3460 SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
3461 SYS_ERR_ZCP_MASK);
3462
3463 (void) nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
3464 nldvs++;
3465 } else {
3466 ldv = NXGE_SYS_ERROR_LD;
3467 ldvp->ldv = (uint8_t)ldv;
3468 ldvp->is_syserr = B_TRUE;
3469 ldvp->ldv_intr_handler = nxge_syserr_intr;
3470 ldvp->nxgep = nxgep;
3471 ldvp->ldv_ldf_masks = 0;
3472 ldgvp->ldvp_syserr = ldvp;
3473 }
3474
3475 ldgvp->ldg_intrs = *nrequired_p;
3476
3477 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
3478 "func %d nldvs %d navail %d nrequired %d",
3479 func, nldvs, *navail_p, *nrequired_p));
3480
3481 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init"));
3482 return (status);
3483 }
3484
3485 nxge_status_t
nxge_ldgv_uninit(p_nxge_t nxgep)3486 nxge_ldgv_uninit(p_nxge_t nxgep)
3487 {
3488 p_nxge_ldgv_t ldgvp;
3489
3490 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_uninit"));
3491 ldgvp = nxgep->ldgvp;
3492 if (ldgvp == NULL) {
3493 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_uninit: "
3494 "no logical group configured."));
3495 return (NXGE_OK);
3496 }
3497 if (ldgvp->ldvp_syserr_alloced == B_TRUE) {
3498 KMEM_FREE(ldgvp->ldvp_syserr, sizeof (nxge_ldv_t));
3499 }
3500 if (ldgvp->ldgp) {
3501 KMEM_FREE(ldgvp->ldgp, sizeof (nxge_ldg_t) * ldgvp->maxldgs);
3502 }
3503 if (ldgvp->ldvp) {
3504 KMEM_FREE(ldgvp->ldvp, sizeof (nxge_ldv_t) * ldgvp->maxldvs);
3505 }
3506 KMEM_FREE(ldgvp, sizeof (nxge_ldgv_t));
3507 nxgep->ldgvp = NULL;
3508
3509 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_uninit"));
3510 return (NXGE_OK);
3511 }
3512
3513 nxge_status_t
nxge_intr_ldgv_init(p_nxge_t nxgep)3514 nxge_intr_ldgv_init(p_nxge_t nxgep)
3515 {
3516 nxge_status_t status = NXGE_OK;
3517
3518 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_ldgv_init"));
3519 /*
3520 * Configure the logical device group numbers, state vectors and
3521 * interrupt masks for each logical device.
3522 */
3523 status = nxge_fzc_intr_init(nxgep);
3524
3525 /*
3526 * Configure logical device masks and timers.
3527 */
3528 status = nxge_intr_mask_mgmt(nxgep);
3529
3530 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_ldgv_init"));
3531 return (status);
3532 }
3533
3534 nxge_status_t
nxge_intr_mask_mgmt(p_nxge_t nxgep)3535 nxge_intr_mask_mgmt(p_nxge_t nxgep)
3536 {
3537 p_nxge_ldgv_t ldgvp;
3538 p_nxge_ldg_t ldgp;
3539 p_nxge_ldv_t ldvp;
3540 npi_handle_t handle;
3541 int i, j;
3542 npi_status_t rs = NPI_SUCCESS;
3543
3544 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_mask_mgmt"));
3545
3546 if ((ldgvp = nxgep->ldgvp) == NULL) {
3547 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3548 "<== nxge_intr_mask_mgmt: Null ldgvp"));
3549 return (NXGE_ERROR);
3550 }
3551 handle = NXGE_DEV_NPI_HANDLE(nxgep);
3552 ldgp = ldgvp->ldgp;
3553 ldvp = ldgvp->ldvp;
3554 if (ldgp == NULL || ldvp == NULL) {
3555 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3556 "<== nxge_intr_mask_mgmt: Null ldgp or ldvp"));
3557 return (NXGE_ERROR);
3558 }
3559 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3560 "==> nxge_intr_mask_mgmt: # of intrs %d ", ldgvp->ldg_intrs));
3561 /* Initialize masks. */
3562 if (nxgep->niu_type != N2_NIU) {
3563 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3564 "==> nxge_intr_mask_mgmt(Neptune): # intrs %d ",
3565 ldgvp->ldg_intrs));
3566 for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
3567 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3568 "==> nxge_intr_mask_mgmt(Neptune): # ldv %d "
3569 "in group %d", ldgp->nldvs, ldgp->ldg));
3570 for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
3571 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3572 "==> nxge_intr_mask_mgmt: set ldv # %d "
3573 "for ldg %d", ldvp->ldv, ldgp->ldg));
3574 rs = npi_intr_mask_set(handle, ldvp->ldv,
3575 ldvp->ldv_ldf_masks);
3576 if (rs != NPI_SUCCESS) {
3577 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3578 "<== nxge_intr_mask_mgmt: "
3579 "set mask failed "
3580 " rs 0x%x ldv %d mask 0x%x",
3581 rs, ldvp->ldv,
3582 ldvp->ldv_ldf_masks));
3583 return (NXGE_ERROR | rs);
3584 }
3585 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3586 "==> nxge_intr_mask_mgmt: "
3587 "set mask OK "
3588 " rs 0x%x ldv %d mask 0x%x",
3589 rs, ldvp->ldv,
3590 ldvp->ldv_ldf_masks));
3591 }
3592 }
3593 }
3594 ldgp = ldgvp->ldgp;
3595 /* Configure timer and arm bit */
3596 for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
3597 rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
3598 ldgp->arm, ldgp->ldg_timer);
3599 if (rs != NPI_SUCCESS) {
3600 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3601 "<== nxge_intr_mask_mgmt: "
3602 "set timer failed "
3603 " rs 0x%x dg %d timer 0x%x",
3604 rs, ldgp->ldg, ldgp->ldg_timer));
3605 return (NXGE_ERROR | rs);
3606 }
3607 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3608 "==> nxge_intr_mask_mgmt: "
3609 "set timer OK "
3610 " rs 0x%x ldg %d timer 0x%x",
3611 rs, ldgp->ldg, ldgp->ldg_timer));
3612 }
3613
3614 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_mask_mgmt"));
3615 return (NXGE_OK);
3616 }
3617
3618 nxge_status_t
nxge_intr_mask_mgmt_set(p_nxge_t nxgep,boolean_t on)3619 nxge_intr_mask_mgmt_set(p_nxge_t nxgep, boolean_t on)
3620 {
3621 p_nxge_ldgv_t ldgvp;
3622 p_nxge_ldg_t ldgp;
3623 p_nxge_ldv_t ldvp;
3624 npi_handle_t handle;
3625 int i, j;
3626 npi_status_t rs = NPI_SUCCESS;
3627
3628 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3629 "==> nxge_intr_mask_mgmt_set (%d)", on));
3630
3631 if (nxgep->niu_type == N2_NIU) {
3632 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3633 "<== nxge_intr_mask_mgmt_set (%d) not set (N2/NIU)",
3634 on));
3635 return (NXGE_ERROR);
3636 }
3637
3638 if ((ldgvp = nxgep->ldgvp) == NULL) {
3639 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3640 "==> nxge_intr_mask_mgmt_set: Null ldgvp"));
3641 return (NXGE_ERROR);
3642 }
3643
3644 handle = NXGE_DEV_NPI_HANDLE(nxgep);
3645 ldgp = ldgvp->ldgp;
3646 ldvp = ldgvp->ldvp;
3647 if (ldgp == NULL || ldvp == NULL) {
3648 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3649 "<== nxge_intr_mask_mgmt_set: Null ldgp or ldvp"));
3650 return (NXGE_ERROR);
3651 }
3652 /* set masks. */
3653 for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
3654 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3655 "==> nxge_intr_mask_mgmt_set: flag %d ldg %d"
3656 "set mask nldvs %d", on, ldgp->ldg, ldgp->nldvs));
3657 for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
3658 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3659 "==> nxge_intr_mask_mgmt_set: "
3660 "for %d %d flag %d", i, j, on));
3661 if (on) {
3662 ldvp->ldv_ldf_masks = 0;
3663 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3664 "==> nxge_intr_mask_mgmt_set: "
3665 "ON mask off"));
3666 } else if (!on) {
3667 ldvp->ldv_ldf_masks = (uint8_t)LD_IM1_MASK;
3668 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3669 "==> nxge_intr_mask_mgmt_set:mask on"));
3670 }
3671 rs = npi_intr_mask_set(handle, ldvp->ldv,
3672 ldvp->ldv_ldf_masks);
3673 if (rs != NPI_SUCCESS) {
3674 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3675 "==> nxge_intr_mask_mgmt_set: "
3676 "set mask failed "
3677 " rs 0x%x ldv %d mask 0x%x",
3678 rs, ldvp->ldv, ldvp->ldv_ldf_masks));
3679 return (NXGE_ERROR | rs);
3680 }
3681 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3682 "==> nxge_intr_mask_mgmt_set: flag %d"
3683 "set mask OK "
3684 " ldv %d mask 0x%x",
3685 on, ldvp->ldv, ldvp->ldv_ldf_masks));
3686 }
3687 }
3688
3689 ldgp = ldgvp->ldgp;
3690 /* set the arm bit */
3691 for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
3692 if (on && !ldgp->arm) {
3693 ldgp->arm = B_TRUE;
3694 } else if (!on && ldgp->arm) {
3695 ldgp->arm = B_FALSE;
3696 }
3697 rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
3698 ldgp->arm, ldgp->ldg_timer);
3699 if (rs != NPI_SUCCESS) {
3700 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3701 "<== nxge_intr_mask_mgmt_set: "
3702 "set timer failed "
3703 " rs 0x%x ldg %d timer 0x%x",
3704 rs, ldgp->ldg, ldgp->ldg_timer));
3705 return (NXGE_ERROR | rs);
3706 }
3707 NXGE_DEBUG_MSG((nxgep, INT_CTL,
3708 "==> nxge_intr_mask_mgmt_set: OK (flag %d) "
3709 "set timer "
3710 " ldg %d timer 0x%x",
3711 on, ldgp->ldg, ldgp->ldg_timer));
3712 }
3713
3714 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_mask_mgmt_set"));
3715 return (NXGE_OK);
3716 }
3717
3718 static nxge_status_t
nxge_get_mac_addr_properties(p_nxge_t nxgep)3719 nxge_get_mac_addr_properties(p_nxge_t nxgep)
3720 {
3721 #if defined(_BIG_ENDIAN)
3722 uchar_t *prop_val;
3723 uint_t prop_len;
3724 uint_t j;
3725 #endif
3726 uint_t i;
3727 uint8_t func_num;
3728 boolean_t compute_macs = B_TRUE;
3729
3730 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_mac_addr_properties "));
3731
3732 #if defined(_BIG_ENDIAN)
3733 /*
3734 * Get the ethernet address.
3735 */
3736 (void) localetheraddr((struct ether_addr *)NULL, &nxgep->ouraddr);
3737
3738 /*
3739 * Check if it is an adapter with its own local mac address If it is
3740 * present, override the system mac address.
3741 */
3742 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
3743 "local-mac-address", &prop_val,
3744 &prop_len) == DDI_PROP_SUCCESS) {
3745 if (prop_len == ETHERADDRL) {
3746 nxgep->factaddr = *(p_ether_addr_t)prop_val;
3747 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Local mac address = "
3748 "%02x:%02x:%02x:%02x:%02x:%02x",
3749 prop_val[0], prop_val[1], prop_val[2],
3750 prop_val[3], prop_val[4], prop_val[5]));
3751 }
3752 ddi_prop_free(prop_val);
3753 }
3754 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
3755 "local-mac-address?", &prop_val,
3756 &prop_len) == DDI_PROP_SUCCESS) {
3757 if (strncmp("true", (caddr_t)prop_val, (size_t)prop_len) == 0) {
3758 nxgep->ouraddr = nxgep->factaddr;
3759 NXGE_DEBUG_MSG((nxgep, DDI_CTL,
3760 "Using local MAC address"));
3761 }
3762 ddi_prop_free(prop_val);
3763 } else {
3764 nxgep->ouraddr = nxgep->factaddr;
3765 }
3766
3767 if ((!nxgep->vpd_info.present) ||
3768 (nxge_is_valid_local_mac(nxgep->factaddr)))
3769 goto got_mac_addr;
3770
3771 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_get_mac_addr_properties: "
3772 "MAC address from properties is not valid...reading from PROM"));
3773
3774 #endif
3775 if (!nxgep->vpd_info.ver_valid) {
3776 (void) nxge_espc_mac_addrs_get(nxgep);
3777 if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
3778 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
3779 "MAC address"));
3780 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
3781 "[%s] invalid...please update",
3782 nxgep->vpd_info.ver));
3783 return (NXGE_ERROR);
3784 }
3785 nxgep->ouraddr = nxgep->factaddr;
3786 goto got_mac_addr;
3787 }
3788 /*
3789 * First get the MAC address from the info in the VPD data read
3790 * from the EEPROM.
3791 */
3792 nxge_espc_get_next_mac_addr(nxgep->vpd_info.mac_addr,
3793 nxgep->function_num, &nxgep->factaddr);
3794
3795 if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
3796 NXGE_DEBUG_MSG((nxgep, DDI_CTL,
3797 "nxge_get_mac_addr_properties: "
3798 "MAC address in EEPROM VPD data not valid"
3799 "...reading from NCR registers"));
3800 (void) nxge_espc_mac_addrs_get(nxgep);
3801 if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
3802 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
3803 "MAC address"));
3804 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
3805 "[%s] invalid...please update",
3806 nxgep->vpd_info.ver));
3807 return (NXGE_ERROR);
3808 }
3809 }
3810
3811 nxgep->ouraddr = nxgep->factaddr;
3812
3813 got_mac_addr:
3814 func_num = nxgep->function_num;
3815
3816 /*
3817 * Note: mac-addresses property is the list of mac addresses for a
3818 * port. NXGE_MAX_MMAC_ADDRS is the total number of MAC addresses
3819 * allocated for a board.
3820 */
3821 nxgep->nxge_mmac_info.total_factory_macs = NXGE_MAX_MMAC_ADDRS;
3822
3823 #if defined(_BIG_ENDIAN)
3824 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
3825 "mac-addresses", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
3826 /*
3827 * XAUI may have up to 18 MACs, more than the XMAC can
3828 * use (1 unique MAC plus 16 alternate MACs)
3829 */
3830 nxgep->nxge_mmac_info.num_factory_mmac =
3831 prop_len / ETHERADDRL - 1;
3832 if (nxgep->nxge_mmac_info.num_factory_mmac >
3833 XMAC_MAX_ALT_ADDR_ENTRY) {
3834 nxgep->nxge_mmac_info.num_factory_mmac =
3835 XMAC_MAX_ALT_ADDR_ENTRY;
3836 }
3837
3838 for (i = 1; i <= nxgep->nxge_mmac_info.num_factory_mmac; i++) {
3839 for (j = 0; j < ETHERADDRL; j++) {
3840 nxgep->nxge_mmac_info.factory_mac_pool[i][j] =
3841 *(prop_val + (i * ETHERADDRL) + j);
3842 }
3843 NXGE_DEBUG_MSG((nxgep, DDI_CTL,
3844 "nxge_get_mac_addr_properties: Alt mac[%d] from "
3845 "mac-addresses property[%2x:%2x:%2x:%2x:%2x:%2x]",
3846 i, nxgep->nxge_mmac_info.factory_mac_pool[i][0],
3847 nxgep->nxge_mmac_info.factory_mac_pool[i][1],
3848 nxgep->nxge_mmac_info.factory_mac_pool[i][2],
3849 nxgep->nxge_mmac_info.factory_mac_pool[i][3],
3850 nxgep->nxge_mmac_info.factory_mac_pool[i][4],
3851 nxgep->nxge_mmac_info.factory_mac_pool[i][5]));
3852 }
3853
3854 compute_macs = B_FALSE;
3855 ddi_prop_free(prop_val);
3856 goto got_mmac_info;
3857 }
3858 #endif
3859 /*
3860 * total_factory_macs = 32
3861 * num_factory_mmac = (32 >> (nports/2)) - 1
3862 * So if nports = 4, then num_factory_mmac = 7
3863 * if nports = 2, then num_factory_mmac = 15
3864 */
3865 nxgep->nxge_mmac_info.num_factory_mmac =
3866 ((nxgep->nxge_mmac_info.total_factory_macs >>
3867 (nxgep->nports >> 1))) - 1;
3868
3869 if ((nxgep->function_num < 2) &&
3870 (nxgep->nxge_mmac_info.num_factory_mmac >
3871 XMAC_MAX_ALT_ADDR_ENTRY)) {
3872 nxgep->nxge_mmac_info.num_factory_mmac =
3873 XMAC_MAX_ALT_ADDR_ENTRY;
3874 } else if ((nxgep->function_num > 1) &&
3875 (nxgep->nxge_mmac_info.num_factory_mmac >
3876 BMAC_MAX_ALT_ADDR_ENTRY)) {
3877 nxgep->nxge_mmac_info.num_factory_mmac =
3878 BMAC_MAX_ALT_ADDR_ENTRY;
3879 }
3880
3881 for (i = 0; i <= nxgep->nxge_mmac_info.num_mmac; i++) {
3882 (void) npi_mac_altaddr_disable(nxgep->npi_handle,
3883 NXGE_GET_PORT_NUM(func_num), i);
3884 }
3885
3886 (void) nxge_init_mmac(nxgep, compute_macs);
3887 return (NXGE_OK);
3888 }
3889
3890 void
nxge_get_xcvr_properties(p_nxge_t nxgep)3891 nxge_get_xcvr_properties(p_nxge_t nxgep)
3892 {
3893 uchar_t *prop_val;
3894 uint_t prop_len;
3895
3896 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_xcvr_properties"));
3897
3898 /*
3899 * Read the type of physical layer interface being used.
3900 */
3901 nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
3902 if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
3903 "phy-type", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
3904 if (strncmp("pcs", (caddr_t)prop_val,
3905 (size_t)prop_len) == 0) {
3906 nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
3907 } else {
3908 nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
3909 }
3910 ddi_prop_free(prop_val);
3911 } else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
3912 "phy-interface", &prop_val,
3913 &prop_len) == DDI_PROP_SUCCESS) {
3914 if (strncmp("pcs", (caddr_t)prop_val, (size_t)prop_len) == 0) {
3915 nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
3916 } else {
3917 nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
3918 }
3919 ddi_prop_free(prop_val);
3920 }
3921 }
3922
3923 /*
3924 * Static functions start here.
3925 */
3926
3927 static void
nxge_ldgv_setup(p_nxge_ldg_t * ldgp,p_nxge_ldv_t * ldvp,uint8_t ldv,uint8_t endldg,int * ngrps)3928 nxge_ldgv_setup(p_nxge_ldg_t *ldgp, p_nxge_ldv_t *ldvp, uint8_t ldv,
3929 uint8_t endldg, int *ngrps)
3930 {
3931 NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup"));
3932 /* Assign the group number for each device. */
3933 (*ldvp)->ldg_assigned = (*ldgp)->ldg;
3934 (*ldvp)->ldgp = *ldgp;
3935 (*ldvp)->ldv = ldv;
3936
3937 NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
3938 "ldv %d endldg %d ldg %d, ldvp $%p",
3939 ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
3940
3941 (*ldgp)->nldvs++;
3942 if ((*ldgp)->ldg == (endldg - 1)) {
3943 if ((*ldgp)->ldvp == NULL) {
3944 (*ldgp)->ldvp = *ldvp;
3945 *ngrps += 1;
3946 NXGE_DEBUG_MSG((NULL, INT_CTL,
3947 "==> nxge_ldgv_setup: ngrps %d", *ngrps));
3948 }
3949 NXGE_DEBUG_MSG((NULL, INT_CTL,
3950 "==> nxge_ldgv_setup: ldvp $%p ngrps %d",
3951 *ldvp, *ngrps));
3952 ++*ldvp;
3953 } else {
3954 (*ldgp)->ldvp = *ldvp;
3955 *ngrps += 1;
3956 NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup(done): "
3957 "ldv %d endldg %d ldg %d, ldvp $%p",
3958 ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
3959 ++*ldvp;
3960 ++*ldgp;
3961 NXGE_DEBUG_MSG((NULL, INT_CTL,
3962 "==> nxge_ldgv_setup: new ngrps %d", *ngrps));
3963 }
3964
3965 NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
3966 "ldv %d ldvp $%p endldg %d ngrps %d",
3967 ldv, ldvp, endldg, *ngrps));
3968
3969 NXGE_DEBUG_MSG((NULL, INT_CTL, "<== nxge_ldgv_setup"));
3970 }
3971
3972 /*
3973 * Note: This function assumes the following distribution of mac
3974 * addresses among 4 ports in neptune:
3975 *
3976 * -------------
3977 * 0| |0 - local-mac-address for fn 0
3978 * -------------
3979 * 1| |1 - local-mac-address for fn 1
3980 * -------------
3981 * 2| |2 - local-mac-address for fn 2
3982 * -------------
3983 * 3| |3 - local-mac-address for fn 3
3984 * -------------
3985 * | |4 - Start of alt. mac addr. for fn 0
3986 * | |
3987 * | |
3988 * | |10
3989 * --------------
3990 * | |11 - Start of alt. mac addr. for fn 1
3991 * | |
3992 * | |
3993 * | |17
3994 * --------------
3995 * | |18 - Start of alt. mac addr. for fn 2
3996 * | |
3997 * | |
3998 * | |24
3999 * --------------
4000 * | |25 - Start of alt. mac addr. for fn 3
4001 * | |
4002 * | |
4003 * | |31
4004 * --------------
4005 *
4006 * For N2/NIU the mac addresses is from XAUI card.
4007 *
4008 * When 'compute_addrs' is true, the alternate mac addresses are computed
4009 * using the unique mac address as base. Otherwise the alternate addresses
4010 * are assigned from the list read off the 'mac-addresses' property.
4011 */
4012
4013 static void
nxge_init_mmac(p_nxge_t nxgep,boolean_t compute_addrs)4014 nxge_init_mmac(p_nxge_t nxgep, boolean_t compute_addrs)
4015 {
4016 int slot;
4017 uint8_t func_num;
4018 uint16_t *base_mmac_addr;
4019 uint32_t alt_mac_ls4b;
4020 uint16_t *mmac_addr;
4021 uint32_t base_mac_ls4b; /* least significant 4 bytes */
4022 nxge_mmac_t *mmac_info;
4023 npi_mac_addr_t mac_addr;
4024
4025 alt_mac_ls4b = 0;
4026 func_num = nxgep->function_num;
4027 base_mmac_addr = (uint16_t *)&nxgep->factaddr;
4028 mmac_info = (nxge_mmac_t *)&nxgep->nxge_mmac_info;
4029
4030 if (compute_addrs) {
4031 base_mac_ls4b = ((uint32_t)base_mmac_addr[1]) << 16 |
4032 base_mmac_addr[2];
4033
4034 if (nxgep->niu_type == N2_NIU) {
4035 /* ls4b of 1st altmac */
4036 alt_mac_ls4b = base_mac_ls4b + 1;
4037 } else { /* Neptune */
4038 alt_mac_ls4b = base_mac_ls4b +
4039 (nxgep->nports - func_num) +
4040 (func_num * (mmac_info->num_factory_mmac));
4041 }
4042 }
4043
4044 /* Set flags for unique MAC */
4045 mmac_info->mac_pool[0].flags |= MMAC_SLOT_USED | MMAC_VENDOR_ADDR;
4046
4047 /* Clear flags of all alternate MAC slots */
4048 for (slot = 1; slot <= mmac_info->num_mmac; slot++) {
4049 if (slot <= mmac_info->num_factory_mmac)
4050 mmac_info->mac_pool[slot].flags = MMAC_VENDOR_ADDR;
4051 else
4052 mmac_info->mac_pool[slot].flags = 0;
4053 }
4054
4055 /* Generate and store factory alternate MACs */
4056 for (slot = 1; slot <= mmac_info->num_factory_mmac; slot++) {
4057 mmac_addr = (uint16_t *)&mmac_info->factory_mac_pool[slot];
4058 if (compute_addrs) {
4059 mmac_addr[0] = base_mmac_addr[0];
4060 mac_addr.w2 = mmac_addr[0];
4061
4062 mmac_addr[1] = (alt_mac_ls4b >> 16) & 0x0FFFF;
4063 mac_addr.w1 = mmac_addr[1];
4064
4065 mmac_addr[2] = alt_mac_ls4b & 0x0FFFF;
4066 mac_addr.w0 = mmac_addr[2];
4067
4068 alt_mac_ls4b++;
4069 } else {
4070 mac_addr.w2 = mmac_addr[0];
4071 mac_addr.w1 = mmac_addr[1];
4072 mac_addr.w0 = mmac_addr[2];
4073 }
4074
4075 NXGE_DEBUG_MSG((nxgep, DDI_CTL,
4076 "mac_pool_addr[%2x:%2x:%2x:%2x:%2x:%2x] npi_addr[%x%x%x]",
4077 mmac_info->factory_mac_pool[slot][0],
4078 mmac_info->factory_mac_pool[slot][1],
4079 mmac_info->factory_mac_pool[slot][2],
4080 mmac_info->factory_mac_pool[slot][3],
4081 mmac_info->factory_mac_pool[slot][4],
4082 mmac_info->factory_mac_pool[slot][5],
4083 mac_addr.w0, mac_addr.w1, mac_addr.w2));
4084 /*
4085 * slot minus 1 because npi_mac_altaddr_entry expects 0
4086 * for the first alternate mac address.
4087 */
4088 (void) npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET,
4089 NXGE_GET_PORT_NUM(func_num), slot - 1, &mac_addr);
4090 }
4091 /* Initialize the first two parameters for mmac kstat */
4092 nxgep->statsp->mmac_stats.mmac_max_cnt = mmac_info->num_mmac;
4093 nxgep->statsp->mmac_stats.mmac_avail_cnt = mmac_info->num_mmac;
4094 }
4095
4096 /*
4097 * Convert an RDC group index into a port ring index. That is, map
4098 * <groupid> to an index into nxgep->rx_ring_handles.
4099 * (group ring index -> port ring index)
4100 */
4101 int
nxge_get_rxring_index(p_nxge_t nxgep,int groupid,int ringidx)4102 nxge_get_rxring_index(p_nxge_t nxgep, int groupid, int ringidx)
4103 {
4104 int i;
4105 int index = 0;
4106 p_nxge_rdc_grp_t rdc_grp_p;
4107 p_nxge_dma_pt_cfg_t p_dma_cfgp;
4108 p_nxge_hw_pt_cfg_t p_cfgp;
4109
4110 p_dma_cfgp = &nxgep->pt_config;
4111 p_cfgp = &p_dma_cfgp->hw_config;
4112
4113 if (isLDOMguest(nxgep))
4114 return (ringidx);
4115
4116 for (i = 0; i < groupid; i++) {
4117 rdc_grp_p =
4118 &p_dma_cfgp->rdc_grps[p_cfgp->def_mac_rxdma_grpid + i];
4119 index += rdc_grp_p->max_rdcs;
4120 }
4121
4122 return (index + ringidx);
4123 }
4124