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 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #include <hxge_impl.h> 27 28 lb_property_t lb_normal = {normal, "normal", hxge_lb_normal}; 29 lb_property_t lb_mac10g = {internal, "mac10g", hxge_lb_mac10g}; 30 31 uint32_t hxge_lb_dbg = 1; 32 33 extern uint32_t hxge_jumbo_frame_size; 34 35 static void hxge_rtrace_ioctl(p_hxge_t, queue_t *, mblk_t *, struct iocblk *); 36 37 void 38 hxge_global_reset(p_hxge_t hxgep) 39 { 40 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_global_reset")); 41 42 (void) hxge_intr_hw_disable(hxgep); 43 44 if (hxgep->suspended) 45 (void) hxge_link_init(hxgep); 46 47 (void) hxge_vmac_init(hxgep); 48 49 (void) hxge_intr_hw_enable(hxgep); 50 51 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "<== hxge_global_reset")); 52 } 53 54 55 void 56 hxge_hw_id_init(p_hxge_t hxgep) 57 { 58 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_hw_id_init")); 59 60 /* 61 * Initialize the frame size to either standard "1500 + 38" or 62 * jumbo. The user may tune the frame size through the "mtu" parameter 63 * using "dladm set-linkprop" 64 */ 65 hxgep->vmac.minframesize = MIN_FRAME_SIZE; 66 hxgep->vmac.maxframesize = HXGE_DEFAULT_MTU + MTU_TO_FRAME_SIZE; 67 if (hxgep->param_arr[param_accept_jumbo].value) 68 hxgep->vmac.maxframesize = (uint16_t)hxge_jumbo_frame_size; 69 70 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_hw_id_init: maxframesize %d", 71 hxgep->vmac.maxframesize)); 72 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "<== hxge_hw_id_init")); 73 } 74 75 void 76 hxge_hw_init_niu_common(p_hxge_t hxgep) 77 { 78 p_hxge_hw_list_t hw_p; 79 80 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_hw_init_niu_common")); 81 82 if ((hw_p = hxgep->hxge_hw_p) == NULL) { 83 return; 84 } 85 86 MUTEX_ENTER(&hw_p->hxge_cfg_lock); 87 if (hw_p->flags & COMMON_INIT_DONE) { 88 HXGE_DEBUG_MSG((hxgep, MOD_CTL, "hxge_hw_init_niu_common" 89 " already done for dip $%p exiting", hw_p->parent_devp)); 90 MUTEX_EXIT(&hw_p->hxge_cfg_lock); 91 return; 92 } 93 94 hw_p->flags = COMMON_INIT_START; 95 HXGE_DEBUG_MSG((hxgep, MOD_CTL, 96 "hxge_hw_init_niu_common Started for device id %x", 97 hw_p->parent_devp)); 98 99 (void) hxge_pfc_hw_reset(hxgep); 100 hw_p->flags = COMMON_INIT_DONE; 101 MUTEX_EXIT(&hw_p->hxge_cfg_lock); 102 103 HXGE_DEBUG_MSG((hxgep, MOD_CTL, 104 "hxge_hw_init_niu_common Done for device id %x", 105 hw_p->parent_devp)); 106 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "<== hxge_hw_init_niu_common")); 107 } 108 109 uint_t 110 hxge_intr(caddr_t arg1, caddr_t arg2) 111 { 112 p_hxge_ldv_t ldvp = (p_hxge_ldv_t)arg1; 113 p_hxge_t hxgep = (p_hxge_t)arg2; 114 uint_t serviced = DDI_INTR_UNCLAIMED; 115 uint8_t ldv; 116 hpi_handle_t handle; 117 p_hxge_ldgv_t ldgvp; 118 p_hxge_ldg_t ldgp, t_ldgp; 119 p_hxge_ldv_t t_ldvp; 120 uint32_t vector0 = 0, vector1 = 0; 121 int i, j, nldvs, nintrs = 1; 122 hpi_status_t rs = HPI_SUCCESS; 123 124 /* 125 * DDI interface returns second arg as NULL 126 */ 127 if ((arg2 == NULL) || ((void *) ldvp->hxgep != arg2)) { 128 hxgep = ldvp->hxgep; 129 } 130 131 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr")); 132 133 if (!(hxgep->drv_state & STATE_HW_INITIALIZED)) { 134 HXGE_ERROR_MSG((hxgep, INT_CTL, 135 "<== hxge_intr: not initialized 0x%x", serviced)); 136 return (serviced); 137 } 138 139 ldgvp = hxgep->ldgvp; 140 141 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr: ldgvp $%p", ldgvp)); 142 143 if (ldvp == NULL && ldgvp) { 144 t_ldvp = ldvp = ldgvp->ldvp; 145 } 146 147 if (ldvp) { 148 ldgp = t_ldgp = ldvp->ldgp; 149 } 150 151 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr: " 152 "ldgvp $%p ldvp $%p ldgp $%p", ldgvp, ldvp, ldgp)); 153 154 if (ldgvp == NULL || ldvp == NULL || ldgp == NULL) { 155 HXGE_ERROR_MSG((hxgep, INT_CTL, "==> hxge_intr: " 156 "ldgvp $%p ldvp $%p ldgp $%p", ldgvp, ldvp, ldgp)); 157 HXGE_ERROR_MSG((hxgep, INT_CTL, "<== hxge_intr: not ready")); 158 return (DDI_INTR_UNCLAIMED); 159 } 160 161 /* 162 * This interrupt handler will have to go through 163 * all the logical devices to find out which 164 * logical device interrupts us and then call 165 * its handler to process the events. 166 */ 167 handle = HXGE_DEV_HPI_HANDLE(hxgep); 168 t_ldgp = ldgp; 169 t_ldvp = ldgp->ldvp; 170 171 nldvs = ldgp->nldvs; 172 173 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr: #ldvs %d #intrs %d", 174 nldvs, ldgvp->ldg_intrs)); 175 176 serviced = DDI_INTR_CLAIMED; 177 for (i = 0; i < nintrs; i++, t_ldgp++) { 178 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr(%d): #ldvs %d " 179 " #intrs %d", i, nldvs, nintrs)); 180 181 /* Get this group's flag bits. */ 182 t_ldgp->interrupted = B_FALSE; 183 rs = hpi_ldsv_ldfs_get(handle, t_ldgp->ldg, &vector0, &vector1); 184 if (rs) { 185 continue; 186 } 187 188 if (!vector0 && !vector1) { 189 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr: " 190 "no interrupts on group %d", t_ldgp->ldg)); 191 continue; 192 } 193 194 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr: " 195 "vector0 0x%llx vector1 0x%llx", vector0, vector1)); 196 197 t_ldgp->interrupted = B_TRUE; 198 nldvs = t_ldgp->nldvs; 199 200 for (j = 0; j < nldvs; j++, t_ldvp++) { 201 /* 202 * Call device's handler if flag bits are on. 203 */ 204 ldv = t_ldvp->ldv; 205 if ((LDV_ON(ldv, vector0) | (LDV_ON(ldv, vector1)))) { 206 HXGE_DEBUG_MSG((hxgep, INT_CTL, 207 "==> hxge_intr: calling device %d" 208 " #ldvs %d #intrs %d", j, nldvs, nintrs)); 209 (void) (t_ldvp->ldv_intr_handler)( 210 (caddr_t)t_ldvp, arg2); 211 } 212 } 213 } 214 215 t_ldgp = ldgp; 216 for (i = 0; i < nintrs; i++, t_ldgp++) { 217 /* rearm group interrupts */ 218 if (t_ldgp->interrupted) { 219 HXGE_DEBUG_MSG((hxgep, INT_CTL, 220 "==> hxge_intr: arm group %d", t_ldgp->ldg)); 221 (void) hpi_intr_ldg_mgmt_set(handle, t_ldgp->ldg, 222 t_ldgp->arm, t_ldgp->ldg_timer); 223 } 224 } 225 226 HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_intr: serviced 0x%x", 227 serviced)); 228 return (serviced); 229 } 230 231 hxge_status_t 232 hxge_peu_handle_sys_errors(p_hxge_t hxgep) 233 { 234 hpi_handle_t handle; 235 p_hxge_peu_sys_stats_t statsp; 236 peu_intr_stat_t stat; 237 238 handle = hxgep->hpi_handle; 239 statsp = (p_hxge_peu_sys_stats_t)&hxgep->statsp->peu_sys_stats; 240 241 HXGE_REG_RD32(handle, PEU_INTR_STAT, &stat.value); 242 243 /* 244 * The PCIE errors are unrecoverrable and cannot be cleared. 245 * The only thing we can do here is to mask them off to prevent 246 * continued interrupts. 247 */ 248 HXGE_REG_WR32(handle, PEU_INTR_MASK, 0xffffffff); 249 250 if (stat.bits.spc_acc_err) { 251 statsp->spc_acc_err++; 252 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 253 "==> hxge_peu_handle_sys_errors: spc_acc_err")); 254 } 255 256 if (stat.bits.tdc_pioacc_err) { 257 statsp->tdc_pioacc_err++; 258 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 259 "==> hxge_peu_handle_sys_errors: tdc_pioacc_err")); 260 } 261 262 if (stat.bits.rdc_pioacc_err) { 263 statsp->rdc_pioacc_err++; 264 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 265 "==> hxge_peu_handle_sys_errors: rdc_pioacc_err")); 266 } 267 268 if (stat.bits.pfc_pioacc_err) { 269 statsp->pfc_pioacc_err++; 270 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 271 "==> hxge_peu_handle_sys_errors: pfc_pioacc_err")); 272 } 273 274 if (stat.bits.vmac_pioacc_err) { 275 statsp->vmac_pioacc_err++; 276 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 277 "==> hxge_peu_handle_sys_errors: vmac_pioacc_err")); 278 } 279 280 if (stat.bits.cpl_hdrq_parerr) { 281 statsp->cpl_hdrq_parerr++; 282 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 283 "==> hxge_peu_handle_sys_errors: cpl_hdrq_parerr")); 284 } 285 286 if (stat.bits.cpl_dataq_parerr) { 287 statsp->cpl_dataq_parerr++; 288 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 289 "==> hxge_peu_handle_sys_errors: cpl_dataq_parerr")); 290 } 291 292 if (stat.bits.retryram_xdlh_parerr) { 293 statsp->retryram_xdlh_parerr++; 294 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 295 "==> hxge_peu_handle_sys_errors: retryram_xdlh_parerr")); 296 } 297 298 if (stat.bits.retrysotram_xdlh_parerr) { 299 statsp->retrysotram_xdlh_parerr++; 300 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 301 "==> hxge_peu_handle_sys_errors: retrysotram_xdlh_parerr")); 302 } 303 304 if (stat.bits.p_hdrq_parerr) { 305 statsp->p_hdrq_parerr++; 306 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 307 "==> hxge_peu_handle_sys_errors: p_hdrq_parerr")); 308 } 309 310 if (stat.bits.p_dataq_parerr) { 311 statsp->p_dataq_parerr++; 312 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 313 "==> hxge_peu_handle_sys_errors: p_dataq_parerr")); 314 } 315 316 if (stat.bits.np_hdrq_parerr) { 317 statsp->np_hdrq_parerr++; 318 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 319 "==> hxge_peu_handle_sys_errors: np_hdrq_parerr")); 320 } 321 322 if (stat.bits.np_dataq_parerr) { 323 statsp->np_dataq_parerr++; 324 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 325 "==> hxge_peu_handle_sys_errors: np_dataq_parerr")); 326 } 327 328 if (stat.bits.eic_msix_parerr) { 329 statsp->eic_msix_parerr++; 330 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 331 "==> hxge_peu_handle_sys_errors: eic_msix_parerr")); 332 } 333 334 if (stat.bits.hcr_parerr) { 335 statsp->hcr_parerr++; 336 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 337 "==> hxge_peu_handle_sys_errors: hcr_parerr")); 338 } 339 340 return (HXGE_OK); 341 } 342 343 /*ARGSUSED*/ 344 uint_t 345 hxge_syserr_intr(caddr_t arg1, caddr_t arg2) 346 { 347 p_hxge_ldv_t ldvp = (p_hxge_ldv_t)arg1; 348 p_hxge_t hxgep = (p_hxge_t)arg2; 349 p_hxge_ldg_t ldgp = NULL; 350 hpi_handle_t handle; 351 dev_err_stat_t estat; 352 uint_t serviced = DDI_INTR_UNCLAIMED; 353 354 if ((arg1 == NULL) && (arg2 == NULL)) { 355 return (serviced); 356 } 357 358 if ((arg2 == NULL) || 359 ((ldvp != NULL) && ((void *)ldvp->hxgep != arg2))) { 360 if (ldvp != NULL) { 361 hxgep = ldvp->hxgep; 362 } 363 } 364 365 HXGE_DEBUG_MSG((hxgep, SYSERR_CTL, 366 "==> hxge_syserr_intr: arg2 $%p arg1 $%p", hxgep, ldvp)); 367 368 if (ldvp != NULL && ldvp->use_timer == B_FALSE) { 369 ldgp = ldvp->ldgp; 370 if (ldgp == NULL) { 371 HXGE_ERROR_MSG((hxgep, SYSERR_CTL, 372 "<== hxge_syserrintr(no logical group): " 373 "arg2 $%p arg1 $%p", hxgep, ldvp)); 374 return (DDI_INTR_UNCLAIMED); 375 } 376 /* 377 * Get the logical device state if the function uses interrupt. 378 */ 379 } 380 381 /* This interrupt handler is for system error interrupts. */ 382 handle = HXGE_DEV_HPI_HANDLE(hxgep); 383 estat.value = 0; 384 (void) hpi_fzc_sys_err_stat_get(handle, &estat); 385 HXGE_DEBUG_MSG((hxgep, SYSERR_CTL, 386 "==> hxge_syserr_intr: device error 0x%016llx", estat.value)); 387 388 if (estat.bits.tdc_err0 || estat.bits.tdc_err1) { 389 /* TDMC */ 390 (void) hxge_txdma_handle_sys_errors(hxgep); 391 } else if (estat.bits.rdc_err0 || estat.bits.rdc_err1) { 392 /* RDMC */ 393 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 394 "==> hxge_syserr_intr: device error - RDMC")); 395 (void) hxge_rxdma_handle_sys_errors(hxgep); 396 } else if (estat.bits.vnm_pio_err1 || estat.bits.peu_err1) { 397 /* PCI-E */ 398 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 399 "==> hxge_syserr_intr: device error - PCI-E")); 400 401 /* kstats are updated here */ 402 (void) hxge_peu_handle_sys_errors(hxgep); 403 404 if (estat.bits.peu_err1) 405 HXGE_FM_REPORT_ERROR(hxgep, NULL, 406 HXGE_FM_EREPORT_PEU_ERR); 407 408 if (estat.bits.vnm_pio_err1) 409 HXGE_FM_REPORT_ERROR(hxgep, NULL, 410 HXGE_FM_EREPORT_PEU_VNM_PIO_ERR); 411 } else if (estat.value != 0) { 412 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 413 "==> hxge_syserr_intr: device error - unknown")); 414 } 415 416 serviced = DDI_INTR_CLAIMED; 417 418 if ((ldgp != NULL) && (ldvp != NULL) && 419 (ldgp->nldvs == 1) && !ldvp->use_timer) { 420 (void) hpi_intr_ldg_mgmt_set(handle, ldgp->ldg, 421 B_TRUE, ldgp->ldg_timer); 422 } 423 424 HXGE_DEBUG_MSG((hxgep, SYSERR_CTL, "<== hxge_syserr_intr")); 425 return (serviced); 426 } 427 428 void 429 hxge_intr_hw_enable(p_hxge_t hxgep) 430 { 431 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr_hw_enable")); 432 433 (void) hxge_intr_mask_mgmt_set(hxgep, B_TRUE); 434 435 HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_intr_hw_enable")); 436 } 437 438 void 439 hxge_intr_hw_disable(p_hxge_t hxgep) 440 { 441 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_intr_hw_disable")); 442 443 (void) hxge_intr_mask_mgmt_set(hxgep, B_FALSE); 444 445 HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_intr_hw_disable")); 446 } 447 448 void 449 hxge_rx_hw_blank(void *arg, time_t ticks, uint_t count) 450 { 451 p_hxge_t hxgep = (p_hxge_t)arg; 452 453 HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_rx_hw_blank")); 454 455 /* 456 * Replace current ticks and counts for later 457 * processing by the receive packet interrupt routines. 458 */ 459 hxgep->intr_timeout = (uint16_t)ticks; 460 hxgep->intr_threshold = (uint16_t)count; 461 462 HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_rx_hw_blank")); 463 } 464 465 void 466 hxge_hw_stop(p_hxge_t hxgep) 467 { 468 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_hw_stop")); 469 470 (void) hxge_tx_vmac_disable(hxgep); 471 (void) hxge_rx_vmac_disable(hxgep); 472 (void) hxge_txdma_hw_mode(hxgep, HXGE_DMA_STOP); 473 (void) hxge_rxdma_hw_mode(hxgep, HXGE_DMA_STOP); 474 475 HXGE_DEBUG_MSG((hxgep, DDI_CTL, "<== hxge_hw_stop")); 476 } 477 478 void 479 hxge_hw_ioctl(p_hxge_t hxgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 480 { 481 int cmd; 482 483 HXGE_DEBUG_MSG((hxgep, IOC_CTL, "==> hxge_hw_ioctl")); 484 485 if (hxgep == NULL) { 486 miocnak(wq, mp, 0, EINVAL); 487 return; 488 } 489 490 iocp->ioc_error = 0; 491 cmd = iocp->ioc_cmd; 492 493 switch (cmd) { 494 default: 495 miocnak(wq, mp, 0, EINVAL); 496 return; 497 498 case HXGE_GET64: 499 hxge_get64(hxgep, mp->b_cont); 500 miocack(wq, mp, sizeof (uint32_t), 0); 501 break; 502 503 case HXGE_PUT64: 504 hxge_put64(hxgep, mp->b_cont); 505 miocack(wq, mp, 0, 0); 506 break; 507 508 case HXGE_PUT_TCAM: 509 hxge_put_tcam(hxgep, mp->b_cont); 510 miocack(wq, mp, 0, 0); 511 break; 512 513 case HXGE_GET_TCAM: 514 hxge_get_tcam(hxgep, mp->b_cont); 515 miocack(wq, mp, 0, 0); 516 break; 517 518 case HXGE_RTRACE: 519 hxge_rtrace_ioctl(hxgep, wq, mp, iocp); 520 break; 521 } 522 } 523 524 /* 525 * 10G is the only loopback mode for Hydra. 526 */ 527 void 528 hxge_loopback_ioctl(p_hxge_t hxgep, queue_t *wq, mblk_t *mp, 529 struct iocblk *iocp) 530 { 531 p_lb_property_t lb_props; 532 size_t size; 533 int i; 534 535 if (mp->b_cont == NULL) { 536 miocnak(wq, mp, 0, EINVAL); 537 } 538 539 switch (iocp->ioc_cmd) { 540 case LB_GET_MODE: 541 HXGE_DEBUG_MSG((hxgep, IOC_CTL, "HXGE_GET_LB_MODE command")); 542 if (hxgep != NULL) { 543 *(lb_info_sz_t *)mp->b_cont->b_rptr = 544 hxgep->statsp->port_stats.lb_mode; 545 miocack(wq, mp, sizeof (hxge_lb_t), 0); 546 } else 547 miocnak(wq, mp, 0, EINVAL); 548 break; 549 550 case LB_SET_MODE: 551 HXGE_DEBUG_MSG((hxgep, IOC_CTL, "HXGE_SET_LB_MODE command")); 552 if (iocp->ioc_count != sizeof (uint32_t)) { 553 miocack(wq, mp, 0, 0); 554 break; 555 } 556 if ((hxgep != NULL) && hxge_set_lb(hxgep, wq, mp->b_cont)) { 557 miocack(wq, mp, 0, 0); 558 } else { 559 miocnak(wq, mp, 0, EPROTO); 560 } 561 break; 562 563 case LB_GET_INFO_SIZE: 564 HXGE_DEBUG_MSG((hxgep, IOC_CTL, "LB_GET_INFO_SIZE command")); 565 if (hxgep != NULL) { 566 size = sizeof (lb_normal) + sizeof (lb_mac10g); 567 568 *(lb_info_sz_t *)mp->b_cont->b_rptr = size; 569 570 HXGE_DEBUG_MSG((hxgep, IOC_CTL, 571 "HXGE_GET_LB_INFO command: size %d", size)); 572 miocack(wq, mp, sizeof (lb_info_sz_t), 0); 573 } else 574 miocnak(wq, mp, 0, EINVAL); 575 break; 576 577 case LB_GET_INFO: 578 HXGE_DEBUG_MSG((hxgep, IOC_CTL, "HXGE_GET_LB_INFO command")); 579 if (hxgep != NULL) { 580 size = sizeof (lb_normal) + sizeof (lb_mac10g); 581 HXGE_DEBUG_MSG((hxgep, IOC_CTL, 582 "HXGE_GET_LB_INFO command: size %d", size)); 583 if (size == iocp->ioc_count) { 584 i = 0; 585 lb_props = (p_lb_property_t)mp->b_cont->b_rptr; 586 lb_props[i++] = lb_normal; 587 lb_props[i++] = lb_mac10g; 588 589 miocack(wq, mp, size, 0); 590 } else 591 miocnak(wq, mp, 0, EINVAL); 592 } else { 593 miocnak(wq, mp, 0, EINVAL); 594 cmn_err(CE_NOTE, "hxge_hw_ioctl: invalid command 0x%x", 595 iocp->ioc_cmd); 596 } 597 598 break; 599 } 600 } 601 602 /*ARGSUSED*/ 603 boolean_t 604 hxge_set_lb(p_hxge_t hxgep, queue_t *wq, p_mblk_t mp) 605 { 606 boolean_t status = B_TRUE; 607 uint32_t lb_mode; 608 lb_property_t *lb_info; 609 610 HXGE_DEBUG_MSG((hxgep, IOC_CTL, "<== hxge_set_lb")); 611 lb_mode = hxgep->statsp->port_stats.lb_mode; 612 if (lb_mode == *(uint32_t *)mp->b_rptr) { 613 cmn_err(CE_NOTE, 614 "hxge%d: Loopback mode already set (lb_mode %d).\n", 615 hxgep->instance, lb_mode); 616 status = B_FALSE; 617 goto hxge_set_lb_exit; 618 } 619 620 lb_mode = *(uint32_t *)mp->b_rptr; 621 lb_info = NULL; 622 623 /* 10G is the only loopback mode for Hydra */ 624 if (lb_mode == lb_normal.value) 625 lb_info = &lb_normal; 626 else if (lb_mode == lb_mac10g.value) 627 lb_info = &lb_mac10g; 628 else { 629 cmn_err(CE_NOTE, 630 "hxge%d: Loopback mode not supported(mode %d).\n", 631 hxgep->instance, lb_mode); 632 status = B_FALSE; 633 goto hxge_set_lb_exit; 634 } 635 636 if (lb_mode == hxge_lb_normal) { 637 if (hxge_lb_dbg) { 638 cmn_err(CE_NOTE, 639 "!hxge%d: Returning to normal operation", 640 hxgep->instance); 641 } 642 643 hxgep->statsp->port_stats.lb_mode = hxge_lb_normal; 644 hxge_global_reset(hxgep); 645 646 goto hxge_set_lb_exit; 647 } 648 649 hxgep->statsp->port_stats.lb_mode = lb_mode; 650 651 if (hxge_lb_dbg) 652 cmn_err(CE_NOTE, "!hxge%d: Adapter now in %s loopback mode", 653 hxgep->instance, lb_info->key); 654 655 if (lb_info->lb_type == internal) { 656 if ((hxgep->statsp->port_stats.lb_mode == hxge_lb_mac10g)) 657 hxgep->statsp->mac_stats.link_speed = 10000; 658 else { 659 cmn_err(CE_NOTE, 660 "hxge%d: Loopback mode not supported(mode %d).\n", 661 hxgep->instance, lb_mode); 662 status = B_FALSE; 663 goto hxge_set_lb_exit; 664 } 665 hxgep->statsp->mac_stats.link_duplex = 2; 666 hxgep->statsp->mac_stats.link_up = 1; 667 } 668 669 hxge_global_reset(hxgep); 670 671 hxge_set_lb_exit: 672 HXGE_DEBUG_MSG((hxgep, DDI_CTL, 673 "<== hxge_set_lb status = 0x%08x", status)); 674 675 return (status); 676 } 677 678 void 679 hxge_check_hw_state(p_hxge_t hxgep) 680 { 681 p_hxge_ldgv_t ldgvp; 682 p_hxge_ldv_t t_ldvp; 683 684 HXGE_DEBUG_MSG((hxgep, SYSERR_CTL, "==> hxge_check_hw_state")); 685 686 MUTEX_ENTER(hxgep->genlock); 687 688 hxgep->hxge_timerid = 0; 689 if (!(hxgep->drv_state & STATE_HW_INITIALIZED)) { 690 goto hxge_check_hw_state_exit; 691 } 692 693 hxge_check_tx_hang(hxgep); 694 695 ldgvp = hxgep->ldgvp; 696 if (ldgvp == NULL || (ldgvp->ldvp_syserr == NULL)) { 697 HXGE_ERROR_MSG((hxgep, SYSERR_CTL, "<== hxge_check_hw_state: " 698 "NULL ldgvp (interrupt not ready).")); 699 goto hxge_check_hw_state_exit; 700 } 701 702 t_ldvp = ldgvp->ldvp_syserr; 703 if (!t_ldvp->use_timer) { 704 HXGE_DEBUG_MSG((hxgep, SYSERR_CTL, "<== hxge_check_hw_state: " 705 "ldgvp $%p t_ldvp $%p use_timer flag %d", 706 ldgvp, t_ldvp, t_ldvp->use_timer)); 707 goto hxge_check_hw_state_exit; 708 } 709 710 if (fm_check_acc_handle(hxgep->dev_regs->hxge_regh) != DDI_FM_OK) { 711 HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, 712 "Bad register acc handle")); 713 } 714 715 (void) hxge_syserr_intr((caddr_t)t_ldvp, (caddr_t)hxgep); 716 717 hxgep->hxge_timerid = hxge_start_timer(hxgep, hxge_check_hw_state, 718 HXGE_CHECK_TIMER); 719 720 hxge_check_hw_state_exit: 721 MUTEX_EXIT(hxgep->genlock); 722 723 HXGE_DEBUG_MSG((hxgep, SYSERR_CTL, "<== hxge_check_hw_state")); 724 } 725 726 /*ARGSUSED*/ 727 static void 728 hxge_rtrace_ioctl(p_hxge_t hxgep, queue_t *wq, mblk_t *mp, 729 struct iocblk *iocp) 730 { 731 ssize_t size; 732 rtrace_t *rtp; 733 mblk_t *nmp; 734 uint32_t i, j; 735 uint32_t start_blk; 736 uint32_t base_entry; 737 uint32_t num_entries; 738 739 HXGE_DEBUG_MSG((hxgep, STR_CTL, "==> hxge_rtrace_ioctl")); 740 741 size = 1024; 742 if (mp->b_cont == NULL || MBLKL(mp->b_cont) < size) { 743 HXGE_DEBUG_MSG((hxgep, STR_CTL, 744 "malformed M_IOCTL MBLKL = %d size = %d", 745 MBLKL(mp->b_cont), size)); 746 miocnak(wq, mp, 0, EINVAL); 747 return; 748 } 749 750 nmp = mp->b_cont; 751 rtp = (rtrace_t *)nmp->b_rptr; 752 start_blk = rtp->next_idx; 753 num_entries = rtp->last_idx; 754 base_entry = start_blk * MAX_RTRACE_IOC_ENTRIES; 755 756 HXGE_DEBUG_MSG((hxgep, STR_CTL, "start_blk = %d\n", start_blk)); 757 HXGE_DEBUG_MSG((hxgep, STR_CTL, "num_entries = %d\n", num_entries)); 758 HXGE_DEBUG_MSG((hxgep, STR_CTL, "base_entry = %d\n", base_entry)); 759 760 rtp->next_idx = hpi_rtracebuf.next_idx; 761 rtp->last_idx = hpi_rtracebuf.last_idx; 762 rtp->wrapped = hpi_rtracebuf.wrapped; 763 for (i = 0, j = base_entry; i < num_entries; i++, j++) { 764 rtp->buf[i].ctl_addr = hpi_rtracebuf.buf[j].ctl_addr; 765 rtp->buf[i].val_l32 = hpi_rtracebuf.buf[j].val_l32; 766 rtp->buf[i].val_h32 = hpi_rtracebuf.buf[j].val_h32; 767 } 768 769 nmp->b_wptr = nmp->b_rptr + size; 770 HXGE_DEBUG_MSG((hxgep, STR_CTL, "<== hxge_rtrace_ioctl")); 771 miocack(wq, mp, (int)size, 0); 772 } 773