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 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/types.h> 29 #include <sys/sysmacros.h> 30 #include <sys/ddi.h> 31 #include <sys/async.h> 32 #include <sys/sunddi.h> 33 #include <sys/ddifm.h> 34 #include <sys/fm/protocol.h> 35 #include <sys/vmem.h> 36 #include <sys/intr.h> 37 #include <sys/ivintr.h> 38 #include <sys/errno.h> 39 #include <sys/hypervisor_api.h> 40 #include <px_obj.h> 41 #include <sys/machsystm.h> 42 #include <sys/hotplug/pci/pcihp.h> 43 #include "px_lib4v.h" 44 #include "px_err.h" 45 46 /* mask for the ranges property in calculating the real PFN range */ 47 uint_t px_ranges_phi_mask = ((1 << 28) -1); 48 49 int 50 px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl) 51 { 52 px_nexus_regspec_t *rp; 53 uint_t reglen; 54 int ret; 55 56 DBG(DBG_ATTACH, dip, "px_lib_dev_init: dip 0x%p\n", dip); 57 58 ret = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 59 "reg", (uchar_t **)&rp, ®len); 60 if (ret != DDI_PROP_SUCCESS) { 61 DBG(DBG_ATTACH, dip, "px_lib_dev_init failed ret=%d\n", ret); 62 return (DDI_FAILURE); 63 } 64 65 /* 66 * Initilize device handle. The device handle uniquely identifies 67 * a SUN4V device. It consists of the lower 28-bits of the hi-cell 68 * of the first entry of the SUN4V device's "reg" property as 69 * defined by the SUN4V Bus Binding to Open Firmware. 70 */ 71 *dev_hdl = (devhandle_t)((rp->phys_addr >> 32) & DEVHDLE_MASK); 72 73 ddi_prop_free(rp); 74 75 /* 76 * hotplug implementation requires this property to be associated with 77 * any indirect PCI config access services 78 */ 79 (void) ddi_prop_update_int(makedevice(ddi_driver_major(dip), 80 PCIHP_AP_MINOR_NUM(ddi_get_instance(dip), PCIHP_DEVCTL_MINOR)), dip, 81 PCI_BUS_CONF_MAP_PROP, 1); 82 83 DBG(DBG_ATTACH, dip, "px_lib_dev_init: dev_hdl 0x%llx\n", *dev_hdl); 84 85 return (DDI_SUCCESS); 86 } 87 88 /*ARGSUSED*/ 89 int 90 px_lib_dev_fini(dev_info_t *dip) 91 { 92 DBG(DBG_DETACH, dip, "px_lib_dev_fini: dip 0x%p\n", dip); 93 94 (void) ddi_prop_remove(makedevice(ddi_driver_major(dip), 95 PCIHP_AP_MINOR_NUM(ddi_get_instance(dip), PCIHP_DEVCTL_MINOR)), dip, 96 PCI_BUS_CONF_MAP_PROP); 97 98 return (DDI_SUCCESS); 99 } 100 101 /*ARGSUSED*/ 102 int 103 px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino, 104 sysino_t *sysino) 105 { 106 uint64_t ret; 107 108 DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: dip 0x%p " 109 "devino 0x%x\n", dip, devino); 110 111 if ((ret = hvio_intr_devino_to_sysino(DIP_TO_HANDLE(dip), 112 devino, sysino)) != H_EOK) { 113 DBG(DBG_LIB_INT, dip, 114 "hvio_intr_devino_to_sysino failed, ret 0x%lx\n", ret); 115 return (DDI_FAILURE); 116 } 117 118 DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: sysino 0x%llx\n", 119 *sysino); 120 121 return (DDI_SUCCESS); 122 } 123 124 /*ARGSUSED*/ 125 int 126 px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino, 127 intr_valid_state_t *intr_valid_state) 128 { 129 uint64_t ret; 130 131 DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: dip 0x%p sysino 0x%llx\n", 132 dip, sysino); 133 134 if ((ret = hvio_intr_getvalid(sysino, 135 (int *)intr_valid_state)) != H_EOK) { 136 DBG(DBG_LIB_INT, dip, "hvio_intr_getvalid failed, ret 0x%lx\n", 137 ret); 138 return (DDI_FAILURE); 139 } 140 141 DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: intr_valid_state 0x%x\n", 142 *intr_valid_state); 143 144 return (DDI_SUCCESS); 145 } 146 147 /*ARGSUSED*/ 148 int 149 px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino, 150 intr_valid_state_t intr_valid_state) 151 { 152 uint64_t ret; 153 154 DBG(DBG_LIB_INT, dip, "px_lib_intr_setvalid: dip 0x%p sysino 0x%llx " 155 "intr_valid_state 0x%x\n", dip, sysino, intr_valid_state); 156 157 if ((ret = hvio_intr_setvalid(sysino, intr_valid_state)) != H_EOK) { 158 DBG(DBG_LIB_INT, dip, "hvio_intr_setvalid failed, ret 0x%lx\n", 159 ret); 160 return (DDI_FAILURE); 161 } 162 163 return (DDI_SUCCESS); 164 } 165 166 /*ARGSUSED*/ 167 int 168 px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino, 169 intr_state_t *intr_state) 170 { 171 uint64_t ret; 172 173 DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: dip 0x%p sysino 0x%llx\n", 174 dip, sysino); 175 176 if ((ret = hvio_intr_getstate(sysino, (int *)intr_state)) != H_EOK) { 177 DBG(DBG_LIB_INT, dip, "hvio_intr_getstate failed, ret 0x%lx\n", 178 ret); 179 return (DDI_FAILURE); 180 } 181 182 DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: intr_state 0x%x\n", 183 *intr_state); 184 185 return (DDI_SUCCESS); 186 } 187 188 /*ARGSUSED*/ 189 int 190 px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino, 191 intr_state_t intr_state) 192 { 193 uint64_t ret; 194 195 DBG(DBG_LIB_INT, dip, "px_lib_intr_setstate: dip 0x%p sysino 0x%llx " 196 "intr_state 0x%x\n", dip, sysino, intr_state); 197 198 if ((ret = hvio_intr_setstate(sysino, intr_state)) != H_EOK) { 199 DBG(DBG_LIB_INT, dip, "hvio_intr_setstate failed, ret 0x%lx\n", 200 ret); 201 return (DDI_FAILURE); 202 } 203 204 return (DDI_SUCCESS); 205 } 206 207 /*ARGSUSED*/ 208 int 209 px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, cpuid_t *cpuid) 210 { 211 uint64_t ret; 212 213 DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: dip 0x%p sysino 0x%llx\n", 214 dip, sysino); 215 216 if ((ret = hvio_intr_gettarget(sysino, cpuid)) != H_EOK) { 217 DBG(DBG_LIB_INT, dip, 218 "hvio_intr_gettarget failed, ret 0x%lx\n", ret); 219 return (DDI_FAILURE); 220 } 221 222 DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: cpuid 0x%x\n", cpuid); 223 224 return (DDI_SUCCESS); 225 } 226 227 /*ARGSUSED*/ 228 int 229 px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, cpuid_t cpuid) 230 { 231 uint64_t ret; 232 233 DBG(DBG_LIB_INT, dip, "px_lib_intr_settarget: dip 0x%p sysino 0x%llx " 234 "cpuid 0x%x\n", dip, sysino, cpuid); 235 236 if ((ret = hvio_intr_settarget(sysino, cpuid)) != H_EOK) { 237 DBG(DBG_LIB_INT, dip, 238 "hvio_intr_settarget failed, ret 0x%lx\n", ret); 239 return (DDI_FAILURE); 240 } 241 242 return (DDI_SUCCESS); 243 } 244 245 /*ARGSUSED*/ 246 int 247 px_lib_intr_reset(dev_info_t *dip) 248 { 249 px_t *px_p = DIP_TO_STATE(dip); 250 px_ib_t *ib_p = px_p->px_ib_p; 251 px_ib_ino_info_t *ino_p; 252 253 DBG(DBG_LIB_INT, dip, "px_lib_intr_reset: dip 0x%p\n", dip); 254 255 mutex_enter(&ib_p->ib_ino_lst_mutex); 256 257 /* Reset all Interrupts */ 258 for (ino_p = ib_p->ib_ino_lst; ino_p; ino_p = ino_p->ino_next) { 259 if (px_lib_intr_setstate(dip, ino_p->ino_sysino, 260 INTR_IDLE_STATE) != DDI_SUCCESS) 261 return (BF_FATAL); 262 } 263 264 mutex_exit(&ib_p->ib_ino_lst_mutex); 265 266 return (BF_NONE); 267 } 268 269 /*ARGSUSED*/ 270 int 271 px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages, 272 io_attributes_t io_attr, void *addr, size_t pfn_index, 273 int flag) 274 { 275 tsbnum_t tsb_num = PCI_TSBID_TO_TSBNUM(tsbid); 276 tsbindex_t tsb_index = PCI_TSBID_TO_TSBINDEX(tsbid); 277 io_page_list_t *pfns, *pfn_p; 278 pages_t ttes_mapped = 0; 279 int i, err = DDI_SUCCESS; 280 281 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: dip 0x%p tsbid 0x%llx " 282 "pages 0x%x atrr 0x%x addr 0x%p pfn_index 0x%llx, flag 0x%x\n", 283 dip, tsbid, pages, io_attr, addr, pfn_index, flag); 284 285 if ((pfns = pfn_p = kmem_zalloc((pages * sizeof (io_page_list_t)), 286 KM_NOSLEEP)) == NULL) { 287 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: kmem_zalloc failed\n"); 288 return (DDI_FAILURE); 289 } 290 291 for (i = 0; i < pages; i++) 292 pfns[i] = MMU_PTOB(PX_ADDR2PFN(addr, pfn_index, flag, i)); 293 294 while ((ttes_mapped = pfn_p - pfns) < pages) { 295 uintptr_t ra = va_to_pa(pfn_p); 296 pages_t ttes2map; 297 uint64_t ret; 298 299 ttes2map = (MMU_PAGE_SIZE - P2PHASE(ra, MMU_PAGE_SIZE)) >> 3; 300 ra = MMU_PTOB(MMU_BTOP(ra)); 301 302 for (ttes2map = MIN(ttes2map, pages - ttes_mapped); ttes2map; 303 ttes2map -= ttes_mapped, pfn_p += ttes_mapped) { 304 305 ttes_mapped = 0; 306 if ((ret = hvio_iommu_map(DIP_TO_HANDLE(dip), 307 PCI_TSBID(tsb_num, tsb_index + (pfn_p - pfns)), 308 ttes2map, io_attr, (io_page_list_t *)(ra | 309 ((uintptr_t)pfn_p & MMU_PAGE_OFFSET)), 310 &ttes_mapped)) != H_EOK) { 311 DBG(DBG_LIB_DMA, dip, "hvio_iommu_map failed " 312 "ret 0x%lx\n", ret); 313 314 ttes_mapped = pfn_p - pfns; 315 err = DDI_FAILURE; 316 goto cleanup; 317 } 318 319 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: tsb_num 0x%x " 320 "tsb_index 0x%lx ttes_to_map 0x%lx attr 0x%x " 321 "ra 0x%p ttes_mapped 0x%x\n", tsb_num, 322 tsb_index + (pfn_p - pfns), ttes2map, io_attr, 323 ra | ((uintptr_t)pfn_p & MMU_PAGE_OFFSET), 324 ttes_mapped); 325 } 326 } 327 328 cleanup: 329 if ((err == DDI_FAILURE) && ttes_mapped) 330 (void) px_lib_iommu_demap(dip, tsbid, ttes_mapped); 331 332 kmem_free(pfns, pages * sizeof (io_page_list_t)); 333 return (err); 334 } 335 336 /*ARGSUSED*/ 337 int 338 px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages) 339 { 340 tsbnum_t tsb_num = PCI_TSBID_TO_TSBNUM(tsbid); 341 tsbindex_t tsb_index = PCI_TSBID_TO_TSBINDEX(tsbid); 342 pages_t ttes2demap, ttes_demapped = 0; 343 uint64_t ret; 344 345 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_demap: dip 0x%p tsbid 0x%llx " 346 "pages 0x%x\n", dip, tsbid, pages); 347 348 for (ttes2demap = pages; ttes2demap; 349 ttes2demap -= ttes_demapped, tsb_index += ttes_demapped) { 350 if ((ret = hvio_iommu_demap(DIP_TO_HANDLE(dip), 351 PCI_TSBID(tsb_num, tsb_index), ttes2demap, 352 &ttes_demapped)) != H_EOK) { 353 DBG(DBG_LIB_DMA, dip, "hvio_iommu_demap failed, " 354 "ret 0x%lx\n", ret); 355 356 return (DDI_FAILURE); 357 } 358 359 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_demap: tsb_num 0x%x " 360 "tsb_index 0x%lx ttes_to_demap 0x%lx ttes_demapped 0x%x\n", 361 tsb_num, tsb_index, ttes2demap, ttes_demapped); 362 } 363 364 return (DDI_SUCCESS); 365 } 366 367 /*ARGSUSED*/ 368 int 369 px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid, 370 io_attributes_t *attributes_p, r_addr_t *r_addr_p) 371 { 372 uint64_t ret; 373 374 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: dip 0x%p tsbid 0x%llx\n", 375 dip, tsbid); 376 377 if ((ret = hvio_iommu_getmap(DIP_TO_HANDLE(dip), tsbid, 378 attributes_p, r_addr_p)) != H_EOK) { 379 DBG(DBG_LIB_DMA, dip, 380 "hvio_iommu_getmap failed, ret 0x%lx\n", ret); 381 382 return ((ret == H_ENOMAP) ? DDI_DMA_NOMAPPING:DDI_FAILURE); 383 } 384 385 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: attr 0x%x r_addr 0x%llx\n", 386 *attributes_p, *r_addr_p); 387 388 return (DDI_SUCCESS); 389 } 390 391 392 /* 393 * Checks dma attributes against system bypass ranges 394 * A sun4v device must be capable of generating the entire 64-bit 395 * address in order to perform bypass DMA. 396 */ 397 /*ARGSUSED*/ 398 int 399 px_lib_dma_bypass_rngchk(ddi_dma_attr_t *attrp, uint64_t *lo_p, uint64_t *hi_p) 400 { 401 if ((attrp->dma_attr_addr_lo != 0ull) || 402 (attrp->dma_attr_addr_hi != UINT64_MAX)) { 403 404 return (DDI_DMA_BADATTR); 405 } 406 407 *lo_p = 0ull; 408 *hi_p = UINT64_MAX; 409 410 return (DDI_SUCCESS); 411 } 412 413 414 /*ARGSUSED*/ 415 int 416 px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra, 417 io_attributes_t io_attributes, io_addr_t *io_addr_p) 418 { 419 uint64_t ret; 420 421 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: dip 0x%p ra 0x%llx " 422 "attr 0x%x\n", dip, ra, io_attributes); 423 424 if ((ret = hvio_iommu_getbypass(DIP_TO_HANDLE(dip), ra, 425 io_attributes, io_addr_p)) != H_EOK) { 426 DBG(DBG_LIB_DMA, dip, 427 "hvio_iommu_getbypass failed, ret 0x%lx\n", ret); 428 return (ret == H_ENOTSUPPORTED ? DDI_ENOTSUP : DDI_FAILURE); 429 } 430 431 DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: io_addr 0x%llx\n", 432 *io_addr_p); 433 434 return (DDI_SUCCESS); 435 } 436 437 /*ARGSUSED*/ 438 int 439 px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, 440 off_t off, size_t len, uint_t cache_flags) 441 { 442 ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 443 uint64_t sync_dir; 444 px_dvma_addr_t dvma_addr, pg_off; 445 size_t num_sync; 446 uint64_t status = H_EOK; 447 448 DBG(DBG_LIB_DMA, dip, "px_lib_dma_sync: dip 0x%p rdip 0x%p " 449 "handle 0x%llx off 0x%x len 0x%x flags 0x%x\n", 450 dip, rdip, handle, off, len, cache_flags); 451 452 if (!(mp->dmai_flags & PX_DMAI_FLAGS_INUSE)) { 453 cmn_err(CE_WARN, "%s%d: Unbound dma handle %p.", 454 ddi_driver_name(rdip), ddi_get_instance(rdip), (void *)mp); 455 return (DDI_FAILURE); 456 } 457 458 if (mp->dmai_flags & PX_DMAI_FLAGS_NOSYNC) 459 return (DDI_SUCCESS); 460 461 if (!len) 462 len = mp->dmai_size; 463 464 pg_off = mp->dmai_offset; /* start min */ 465 dvma_addr = MAX(off, pg_off); /* lo */ 466 pg_off += mp->dmai_size; /* end max */ 467 pg_off = MIN(off + len, pg_off); /* hi */ 468 if (dvma_addr >= pg_off) { /* lo >= hi ? */ 469 cmn_err(CE_WARN, "%s%d: %lx + %lx out of window [%lx,%lx]", 470 ddi_driver_name(rdip), ddi_get_instance(rdip), 471 off, len, mp->dmai_offset, 472 mp->dmai_offset + mp->dmai_size); 473 return (DDI_FAILURE); 474 } 475 476 len = pg_off - dvma_addr; /* sz = hi - lo */ 477 dvma_addr += mp->dmai_mapping; /* start addr */ 478 479 if (mp->dmai_rflags & DDI_DMA_READ) 480 sync_dir = HVIO_DMA_SYNC_DIR_FROM_DEV; 481 else 482 sync_dir = HVIO_DMA_SYNC_DIR_TO_DEV; 483 484 for (; ((len > 0) && (status == H_EOK)); len -= num_sync) { 485 status = hvio_dma_sync(DIP_TO_HANDLE(dip), dvma_addr, len, 486 sync_dir, &num_sync); 487 dvma_addr += num_sync; 488 } 489 490 return ((status == H_EOK) ? DDI_SUCCESS : DDI_FAILURE); 491 } 492 493 494 /* 495 * MSIQ Functions: 496 */ 497 498 /*ARGSUSED*/ 499 int 500 px_lib_msiq_init(dev_info_t *dip) 501 { 502 px_t *px_p = DIP_TO_STATE(dip); 503 px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 504 uint64_t *msiq_addr, ra; 505 size_t msiq_size; 506 uint_t rec_cnt; 507 int i, err = DDI_SUCCESS; 508 uint64_t ret; 509 510 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_init: dip 0x%p\n", dip); 511 512 msiq_addr = (uint64_t *)(((uint64_t)msiq_state_p->msiq_buf_p + 513 (MMU_PAGE_SIZE - 1)) >> MMU_PAGE_SHIFT << MMU_PAGE_SHIFT); 514 515 msiq_size = msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t); 516 517 for (i = 0; i < msiq_state_p->msiq_cnt; i++) { 518 ra = (r_addr_t)va_to_pa((caddr_t)msiq_addr + (i * msiq_size)); 519 520 if ((ret = hvio_msiq_conf(DIP_TO_HANDLE(dip), 521 (i + msiq_state_p->msiq_1st_msiq_id), 522 ra, msiq_state_p->msiq_rec_cnt)) != H_EOK) { 523 DBG(DBG_LIB_MSIQ, dip, 524 "hvio_msiq_conf failed, ret 0x%lx\n", ret); 525 err = DDI_FAILURE; 526 break; 527 } 528 529 if ((err = px_lib_msiq_info(dip, 530 (i + msiq_state_p->msiq_1st_msiq_id), 531 &ra, &rec_cnt)) != DDI_SUCCESS) { 532 DBG(DBG_LIB_MSIQ, dip, 533 "px_lib_msiq_info failed, ret 0x%x\n", err); 534 err = DDI_FAILURE; 535 break; 536 } 537 538 DBG(DBG_LIB_MSIQ, dip, 539 "px_lib_msiq_init: ra 0x%p rec_cnt 0x%x\n", ra, rec_cnt); 540 } 541 542 return (err); 543 } 544 545 /*ARGSUSED*/ 546 int 547 px_lib_msiq_fini(dev_info_t *dip) 548 { 549 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_fini: dip 0x%p\n", dip); 550 551 return (DDI_SUCCESS); 552 } 553 554 /*ARGSUSED*/ 555 int 556 px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id, r_addr_t *ra_p, 557 uint_t *msiq_rec_cnt_p) 558 { 559 uint64_t ret; 560 561 DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: dip 0x%p msiq_id 0x%x\n", 562 dip, msiq_id); 563 564 if ((ret = hvio_msiq_info(DIP_TO_HANDLE(dip), 565 msiq_id, ra_p, msiq_rec_cnt_p)) != H_EOK) { 566 DBG(DBG_LIB_MSIQ, dip, 567 "hvio_msiq_info failed, ret 0x%lx\n", ret); 568 return (DDI_FAILURE); 569 } 570 571 DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: ra_p 0x%p msiq_rec_cnt 0x%x\n", 572 ra_p, *msiq_rec_cnt_p); 573 574 return (DDI_SUCCESS); 575 } 576 577 /*ARGSUSED*/ 578 int 579 px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id, 580 pci_msiq_valid_state_t *msiq_valid_state) 581 { 582 uint64_t ret; 583 584 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: dip 0x%p msiq_id 0x%x\n", 585 dip, msiq_id); 586 587 if ((ret = hvio_msiq_getvalid(DIP_TO_HANDLE(dip), 588 msiq_id, msiq_valid_state)) != H_EOK) { 589 DBG(DBG_LIB_MSIQ, dip, 590 "hvio_msiq_getvalid failed, ret 0x%lx\n", ret); 591 return (DDI_FAILURE); 592 } 593 594 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: msiq_valid_state 0x%x\n", 595 *msiq_valid_state); 596 597 return (DDI_SUCCESS); 598 } 599 600 /*ARGSUSED*/ 601 int 602 px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id, 603 pci_msiq_valid_state_t msiq_valid_state) 604 { 605 uint64_t ret; 606 607 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setvalid: dip 0x%p msiq_id 0x%x " 608 "msiq_valid_state 0x%x\n", dip, msiq_id, msiq_valid_state); 609 610 if ((ret = hvio_msiq_setvalid(DIP_TO_HANDLE(dip), 611 msiq_id, msiq_valid_state)) != H_EOK) { 612 DBG(DBG_LIB_MSIQ, dip, 613 "hvio_msiq_setvalid failed, ret 0x%lx\n", ret); 614 return (DDI_FAILURE); 615 } 616 617 return (DDI_SUCCESS); 618 } 619 620 /*ARGSUSED*/ 621 int 622 px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id, 623 pci_msiq_state_t *msiq_state) 624 { 625 uint64_t ret; 626 627 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: dip 0x%p msiq_id 0x%x\n", 628 dip, msiq_id); 629 630 if ((ret = hvio_msiq_getstate(DIP_TO_HANDLE(dip), 631 msiq_id, msiq_state)) != H_EOK) { 632 DBG(DBG_LIB_MSIQ, dip, 633 "hvio_msiq_getstate failed, ret 0x%lx\n", ret); 634 return (DDI_FAILURE); 635 } 636 637 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: msiq_state 0x%x\n", 638 *msiq_state); 639 640 return (DDI_SUCCESS); 641 } 642 643 /*ARGSUSED*/ 644 int 645 px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id, 646 pci_msiq_state_t msiq_state) 647 { 648 uint64_t ret; 649 650 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setstate: dip 0x%p msiq_id 0x%x " 651 "msiq_state 0x%x\n", dip, msiq_id, msiq_state); 652 653 if ((ret = hvio_msiq_setstate(DIP_TO_HANDLE(dip), 654 msiq_id, msiq_state)) != H_EOK) { 655 DBG(DBG_LIB_MSIQ, dip, 656 "hvio_msiq_setstate failed, ret 0x%lx\n", ret); 657 return (DDI_FAILURE); 658 } 659 660 return (DDI_SUCCESS); 661 } 662 663 /*ARGSUSED*/ 664 int 665 px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id, 666 msiqhead_t *msiq_head_p) 667 { 668 uint64_t ret; 669 670 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gethead: dip 0x%p msiq_id 0x%x\n", 671 dip, msiq_id); 672 673 if ((ret = hvio_msiq_gethead(DIP_TO_HANDLE(dip), 674 msiq_id, msiq_head_p)) != H_EOK) { 675 DBG(DBG_LIB_MSIQ, dip, 676 "hvio_msiq_gethead failed, ret 0x%lx\n", ret); 677 return (DDI_FAILURE); 678 } 679 680 *msiq_head_p = (*msiq_head_p / sizeof (msiq_rec_t)); 681 682 DBG(DBG_LIB_MSIQ, dip, "px_msiq_gethead: msiq_head 0x%x\n", 683 *msiq_head_p); 684 685 return (DDI_SUCCESS); 686 } 687 688 /*ARGSUSED*/ 689 int 690 px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id, 691 msiqhead_t msiq_head) 692 { 693 uint64_t ret; 694 695 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_sethead: dip 0x%p msiq_id 0x%x " 696 "msiq_head 0x%x\n", dip, msiq_id, msiq_head); 697 698 if ((ret = hvio_msiq_sethead(DIP_TO_HANDLE(dip), 699 msiq_id, msiq_head * sizeof (msiq_rec_t))) != H_EOK) { 700 DBG(DBG_LIB_MSIQ, dip, 701 "hvio_msiq_sethead failed, ret 0x%lx\n", ret); 702 return (DDI_FAILURE); 703 } 704 705 return (DDI_SUCCESS); 706 } 707 708 /*ARGSUSED*/ 709 int 710 px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id, 711 msiqtail_t *msiq_tail_p) 712 { 713 uint64_t ret; 714 715 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: dip 0x%p msiq_id 0x%x\n", 716 dip, msiq_id); 717 718 if ((ret = hvio_msiq_gettail(DIP_TO_HANDLE(dip), 719 msiq_id, msiq_tail_p)) != H_EOK) { 720 DBG(DBG_LIB_MSIQ, dip, 721 "hvio_msiq_gettail failed, ret 0x%lx\n", ret); 722 return (DDI_FAILURE); 723 } 724 725 *msiq_tail_p = (*msiq_tail_p / sizeof (msiq_rec_t)); 726 DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: msiq_tail 0x%x\n", 727 *msiq_tail_p); 728 729 return (DDI_SUCCESS); 730 } 731 732 /*ARGSUSED*/ 733 void 734 px_lib_get_msiq_rec(dev_info_t *dip, px_msiq_t *msiq_p, msiq_rec_t *msiq_rec_p) 735 { 736 msiq_rec_t *curr_msiq_rec_p = (msiq_rec_t *)msiq_p->msiq_curr; 737 738 DBG(DBG_LIB_MSIQ, dip, "px_lib_get_msiq_rec: dip 0x%p\n", dip); 739 740 if (!curr_msiq_rec_p->msiq_rec_type) 741 return; 742 743 *msiq_rec_p = *curr_msiq_rec_p; 744 745 /* Zero out msiq_rec_type field */ 746 curr_msiq_rec_p->msiq_rec_type = 0; 747 } 748 749 /* 750 * MSI Functions: 751 */ 752 753 /*ARGSUSED*/ 754 int 755 px_lib_msi_init(dev_info_t *dip) 756 { 757 DBG(DBG_LIB_MSI, dip, "px_lib_msi_init: dip 0x%p\n", dip); 758 759 /* Noop */ 760 return (DDI_SUCCESS); 761 } 762 763 /*ARGSUSED*/ 764 int 765 px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num, 766 msiqid_t *msiq_id) 767 { 768 uint64_t ret; 769 770 DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: dip 0x%p msi_num 0x%x\n", 771 dip, msi_num); 772 773 if ((ret = hvio_msi_getmsiq(DIP_TO_HANDLE(dip), 774 msi_num, msiq_id)) != H_EOK) { 775 DBG(DBG_LIB_MSI, dip, 776 "hvio_msi_getmsiq failed, ret 0x%lx\n", ret); 777 return (DDI_FAILURE); 778 } 779 780 DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: msiq_id 0x%x\n", 781 *msiq_id); 782 783 return (DDI_SUCCESS); 784 } 785 786 /*ARGSUSED*/ 787 int 788 px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num, 789 msiqid_t msiq_id, msi_type_t msitype) 790 { 791 uint64_t ret; 792 793 DBG(DBG_LIB_MSI, dip, "px_lib_msi_setmsiq: dip 0x%p msi_num 0x%x " 794 "msq_id 0x%x\n", dip, msi_num, msiq_id); 795 796 if ((ret = hvio_msi_setmsiq(DIP_TO_HANDLE(dip), 797 msi_num, msiq_id, msitype)) != H_EOK) { 798 DBG(DBG_LIB_MSI, dip, 799 "hvio_msi_setmsiq failed, ret 0x%lx\n", ret); 800 return (DDI_FAILURE); 801 } 802 803 return (DDI_SUCCESS); 804 } 805 806 /*ARGSUSED*/ 807 int 808 px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num, 809 pci_msi_valid_state_t *msi_valid_state) 810 { 811 uint64_t ret; 812 813 DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: dip 0x%p msi_num 0x%x\n", 814 dip, msi_num); 815 816 if ((ret = hvio_msi_getvalid(DIP_TO_HANDLE(dip), 817 msi_num, msi_valid_state)) != H_EOK) { 818 DBG(DBG_LIB_MSI, dip, 819 "hvio_msi_getvalid failed, ret 0x%lx\n", ret); 820 return (DDI_FAILURE); 821 } 822 823 DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: msiq_id 0x%x\n", 824 *msi_valid_state); 825 826 return (DDI_SUCCESS); 827 } 828 829 /*ARGSUSED*/ 830 int 831 px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num, 832 pci_msi_valid_state_t msi_valid_state) 833 { 834 uint64_t ret; 835 836 DBG(DBG_LIB_MSI, dip, "px_lib_msi_setvalid: dip 0x%p msi_num 0x%x " 837 "msi_valid_state 0x%x\n", dip, msi_num, msi_valid_state); 838 839 if ((ret = hvio_msi_setvalid(DIP_TO_HANDLE(dip), 840 msi_num, msi_valid_state)) != H_EOK) { 841 DBG(DBG_LIB_MSI, dip, 842 "hvio_msi_setvalid failed, ret 0x%lx\n", ret); 843 return (DDI_FAILURE); 844 } 845 846 return (DDI_SUCCESS); 847 } 848 849 /*ARGSUSED*/ 850 int 851 px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num, 852 pci_msi_state_t *msi_state) 853 { 854 uint64_t ret; 855 856 DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: dip 0x%p msi_num 0x%x\n", 857 dip, msi_num); 858 859 if ((ret = hvio_msi_getstate(DIP_TO_HANDLE(dip), 860 msi_num, msi_state)) != H_EOK) { 861 DBG(DBG_LIB_MSI, dip, 862 "hvio_msi_getstate failed, ret 0x%lx\n", ret); 863 return (DDI_FAILURE); 864 } 865 866 DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: msi_state 0x%x\n", 867 *msi_state); 868 869 return (DDI_SUCCESS); 870 } 871 872 /*ARGSUSED*/ 873 int 874 px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num, 875 pci_msi_state_t msi_state) 876 { 877 uint64_t ret; 878 879 DBG(DBG_LIB_MSI, dip, "px_lib_msi_setstate: dip 0x%p msi_num 0x%x " 880 "msi_state 0x%x\n", dip, msi_num, msi_state); 881 882 if ((ret = hvio_msi_setstate(DIP_TO_HANDLE(dip), 883 msi_num, msi_state)) != H_EOK) { 884 DBG(DBG_LIB_MSI, dip, 885 "hvio_msi_setstate failed, ret 0x%lx\n", ret); 886 return (DDI_FAILURE); 887 } 888 889 return (DDI_SUCCESS); 890 } 891 892 /* 893 * MSG Functions: 894 */ 895 896 /*ARGSUSED*/ 897 int 898 px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 899 msiqid_t *msiq_id) 900 { 901 uint64_t ret; 902 903 DBG(DBG_LIB_MSG, dip, "px_lib_msg_getmsiq: dip 0x%p msg_type 0x%x\n", 904 dip, msg_type); 905 906 if ((ret = hvio_msg_getmsiq(DIP_TO_HANDLE(dip), 907 msg_type, msiq_id)) != H_EOK) { 908 DBG(DBG_LIB_MSG, dip, 909 "hvio_msg_getmsiq failed, ret 0x%lx\n", ret); 910 return (DDI_FAILURE); 911 } 912 913 DBG(DBG_LIB_MSI, dip, "px_lib_msg_getmsiq: msiq_id 0x%x\n", 914 *msiq_id); 915 916 return (DDI_SUCCESS); 917 } 918 919 /*ARGSUSED*/ 920 int 921 px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 922 msiqid_t msiq_id) 923 { 924 uint64_t ret; 925 926 DBG(DBG_LIB_MSG, dip, "px_lib_msg_setmsiq: dip 0x%p msg_type 0x%x " 927 "msq_id 0x%x\n", dip, msg_type, msiq_id); 928 929 if ((ret = hvio_msg_setmsiq(DIP_TO_HANDLE(dip), 930 msg_type, msiq_id)) != H_EOK) { 931 DBG(DBG_LIB_MSG, dip, 932 "hvio_msg_setmsiq failed, ret 0x%lx\n", ret); 933 return (DDI_FAILURE); 934 } 935 936 return (DDI_SUCCESS); 937 } 938 939 /*ARGSUSED*/ 940 int 941 px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 942 pcie_msg_valid_state_t *msg_valid_state) 943 { 944 uint64_t ret; 945 946 DBG(DBG_LIB_MSG, dip, "px_lib_msg_getvalid: dip 0x%p msg_type 0x%x\n", 947 dip, msg_type); 948 949 if ((ret = hvio_msg_getvalid(DIP_TO_HANDLE(dip), msg_type, 950 msg_valid_state)) != H_EOK) { 951 DBG(DBG_LIB_MSG, dip, 952 "hvio_msg_getvalid failed, ret 0x%lx\n", ret); 953 return (DDI_FAILURE); 954 } 955 956 DBG(DBG_LIB_MSI, dip, "px_lib_msg_getvalid: msg_valid_state 0x%x\n", 957 *msg_valid_state); 958 959 return (DDI_SUCCESS); 960 } 961 962 /*ARGSUSED*/ 963 int 964 px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 965 pcie_msg_valid_state_t msg_valid_state) 966 { 967 uint64_t ret; 968 969 DBG(DBG_LIB_MSG, dip, "px_lib_msg_setvalid: dip 0x%p msg_type 0x%x " 970 "msg_valid_state 0x%x\n", dip, msg_type, msg_valid_state); 971 972 if ((ret = hvio_msg_setvalid(DIP_TO_HANDLE(dip), msg_type, 973 msg_valid_state)) != H_EOK) { 974 DBG(DBG_LIB_MSG, dip, 975 "hvio_msg_setvalid failed, ret 0x%lx\n", ret); 976 return (DDI_FAILURE); 977 } 978 979 return (DDI_SUCCESS); 980 } 981 982 /* 983 * Suspend/Resume Functions: 984 * Currently unsupported by hypervisor and all functions are noops. 985 */ 986 /*ARGSUSED*/ 987 int 988 px_lib_suspend(dev_info_t *dip) 989 { 990 DBG(DBG_ATTACH, dip, "px_lib_suspend: Not supported\n"); 991 992 /* Not supported */ 993 return (DDI_FAILURE); 994 } 995 996 /*ARGSUSED*/ 997 void 998 px_lib_resume(dev_info_t *dip) 999 { 1000 DBG(DBG_ATTACH, dip, "px_lib_resume: Not supported\n"); 1001 1002 /* Noop */ 1003 } 1004 1005 /* 1006 * Misc Functions: 1007 * Currently unsupported by hypervisor and all functions are noops. 1008 */ 1009 /*ARGSUSED*/ 1010 uint64_t 1011 px_lib_get_cb(dev_info_t *dip) 1012 { 1013 return (DDI_SUCCESS); 1014 } 1015 1016 /*ARGSUSED*/ 1017 void 1018 px_lib_set_cb(dev_info_t *dip, uint64_t val) 1019 { 1020 /* Noop */ 1021 } 1022 1023 /*ARGSUSED*/ 1024 static int 1025 px_lib_config_get(dev_info_t *dip, pci_device_t bdf, pci_config_offset_t off, 1026 uint8_t size, pci_cfg_data_t *data_p) 1027 { 1028 uint64_t ret; 1029 1030 DBG(DBG_LIB_CFG, dip, "px_lib_config_get: dip 0x%p, bdf 0x%llx " 1031 "off 0x%x size 0x%x\n", dip, bdf, off, size); 1032 1033 if ((ret = hvio_config_get(DIP_TO_HANDLE(dip), bdf, off, 1034 size, data_p)) != H_EOK) { 1035 DBG(DBG_LIB_CFG, dip, 1036 "hvio_config_get failed, ret 0x%lx\n", ret); 1037 return (DDI_FAILURE); 1038 } 1039 DBG(DBG_LIB_CFG, dip, "px_config_get: data 0x%x\n", data_p->dw); 1040 1041 return (DDI_SUCCESS); 1042 } 1043 1044 /*ARGSUSED*/ 1045 static int 1046 px_lib_config_put(dev_info_t *dip, pci_device_t bdf, pci_config_offset_t off, 1047 uint8_t size, pci_cfg_data_t data) 1048 { 1049 uint64_t ret; 1050 1051 DBG(DBG_LIB_CFG, dip, "px_lib_config_put: dip 0x%p, bdf 0x%llx " 1052 "off 0x%x size 0x%x data 0x%llx\n", dip, bdf, off, size, data.qw); 1053 1054 if ((ret = hvio_config_put(DIP_TO_HANDLE(dip), bdf, off, 1055 size, data)) != H_EOK) { 1056 DBG(DBG_LIB_CFG, dip, 1057 "hvio_config_put failed, ret 0x%lx\n", ret); 1058 return (DDI_FAILURE); 1059 } 1060 1061 return (DDI_SUCCESS); 1062 } 1063 1064 static uint32_t 1065 px_pci_config_get(ddi_acc_impl_t *handle, uint32_t *addr, int size) 1066 { 1067 px_config_acc_pvt_t *px_pvt = (px_config_acc_pvt_t *) 1068 handle->ahi_common.ah_bus_private; 1069 uint32_t pci_dev_addr = px_pvt->raddr; 1070 uint32_t vaddr = px_pvt->vaddr; 1071 uint16_t off = (uint16_t)(uintptr_t)(addr - vaddr) & 0xfff; 1072 uint32_t rdata = 0; 1073 1074 if (px_lib_config_get(px_pvt->dip, pci_dev_addr, off, 1075 size, (pci_cfg_data_t *)&rdata) != DDI_SUCCESS) 1076 /* XXX update error kstats */ 1077 return (0xffffffff); 1078 return (rdata); 1079 } 1080 1081 static void 1082 px_pci_config_put(ddi_acc_impl_t *handle, uint32_t *addr, 1083 int size, pci_cfg_data_t wdata) 1084 { 1085 px_config_acc_pvt_t *px_pvt = (px_config_acc_pvt_t *) 1086 handle->ahi_common.ah_bus_private; 1087 uint32_t pci_dev_addr = px_pvt->raddr; 1088 uint32_t vaddr = px_pvt->vaddr; 1089 uint16_t off = (uint16_t)(uintptr_t)(addr - vaddr) & 0xfff; 1090 1091 if (px_lib_config_put(px_pvt->dip, pci_dev_addr, off, 1092 size, wdata) != DDI_SUCCESS) { 1093 /*EMPTY*/ 1094 /* XXX update error kstats */ 1095 } 1096 } 1097 1098 static uint8_t 1099 px_pci_config_get8(ddi_acc_impl_t *handle, uint8_t *addr) 1100 { 1101 return ((uint8_t)px_pci_config_get(handle, (uint32_t *)addr, 1)); 1102 } 1103 1104 static uint16_t 1105 px_pci_config_get16(ddi_acc_impl_t *handle, uint16_t *addr) 1106 { 1107 return ((uint16_t)px_pci_config_get(handle, (uint32_t *)addr, 2)); 1108 } 1109 1110 static uint32_t 1111 px_pci_config_get32(ddi_acc_impl_t *handle, uint32_t *addr) 1112 { 1113 return ((uint32_t)px_pci_config_get(handle, (uint32_t *)addr, 4)); 1114 } 1115 1116 static uint64_t 1117 px_pci_config_get64(ddi_acc_impl_t *handle, uint64_t *addr) 1118 { 1119 uint32_t rdatah, rdatal; 1120 1121 rdatal = (uint32_t)px_pci_config_get(handle, (uint32_t *)addr, 4); 1122 rdatah = (uint32_t)px_pci_config_get(handle, 1123 (uint32_t *)((char *)addr+4), 4); 1124 return (((uint64_t)rdatah << 32) | rdatal); 1125 } 1126 1127 static void 1128 px_pci_config_put8(ddi_acc_impl_t *handle, uint8_t *addr, uint8_t data) 1129 { 1130 pci_cfg_data_t wdata = { 0 }; 1131 1132 wdata.qw = (uint8_t)data; 1133 px_pci_config_put(handle, (uint32_t *)addr, 1, wdata); 1134 } 1135 1136 static void 1137 px_pci_config_put16(ddi_acc_impl_t *handle, uint16_t *addr, uint16_t data) 1138 { 1139 pci_cfg_data_t wdata = { 0 }; 1140 1141 wdata.qw = (uint16_t)data; 1142 px_pci_config_put(handle, (uint32_t *)addr, 2, wdata); 1143 } 1144 1145 static void 1146 px_pci_config_put32(ddi_acc_impl_t *handle, uint32_t *addr, uint32_t data) 1147 { 1148 pci_cfg_data_t wdata = { 0 }; 1149 1150 wdata.qw = (uint32_t)data; 1151 px_pci_config_put(handle, (uint32_t *)addr, 4, wdata); 1152 } 1153 1154 static void 1155 px_pci_config_put64(ddi_acc_impl_t *handle, uint64_t *addr, uint64_t data) 1156 { 1157 pci_cfg_data_t wdata = { 0 }; 1158 1159 wdata.qw = (uint32_t)(data & 0xffffffff); 1160 px_pci_config_put(handle, (uint32_t *)addr, 4, wdata); 1161 wdata.qw = (uint32_t)((data >> 32) & 0xffffffff); 1162 px_pci_config_put(handle, (uint32_t *)((char *)addr+4), 4, wdata); 1163 } 1164 1165 static void 1166 px_pci_config_rep_get8(ddi_acc_impl_t *handle, uint8_t *host_addr, 1167 uint8_t *dev_addr, size_t repcount, uint_t flags) 1168 { 1169 if (flags == DDI_DEV_AUTOINCR) 1170 for (; repcount; repcount--) 1171 *host_addr++ = px_pci_config_get8(handle, dev_addr++); 1172 else 1173 for (; repcount; repcount--) 1174 *host_addr++ = px_pci_config_get8(handle, dev_addr); 1175 } 1176 1177 /* 1178 * Function to rep read 16 bit data off the PCI configuration space behind 1179 * the 21554's host interface. 1180 */ 1181 static void 1182 px_pci_config_rep_get16(ddi_acc_impl_t *handle, uint16_t *host_addr, 1183 uint16_t *dev_addr, size_t repcount, uint_t flags) 1184 { 1185 if (flags == DDI_DEV_AUTOINCR) 1186 for (; repcount; repcount--) 1187 *host_addr++ = px_pci_config_get16(handle, dev_addr++); 1188 else 1189 for (; repcount; repcount--) 1190 *host_addr++ = px_pci_config_get16(handle, dev_addr); 1191 } 1192 1193 /* 1194 * Function to rep read 32 bit data off the PCI configuration space behind 1195 * the 21554's host interface. 1196 */ 1197 static void 1198 px_pci_config_rep_get32(ddi_acc_impl_t *handle, uint32_t *host_addr, 1199 uint32_t *dev_addr, size_t repcount, uint_t flags) 1200 { 1201 if (flags == DDI_DEV_AUTOINCR) 1202 for (; repcount; repcount--) 1203 *host_addr++ = px_pci_config_get32(handle, dev_addr++); 1204 else 1205 for (; repcount; repcount--) 1206 *host_addr++ = px_pci_config_get32(handle, dev_addr); 1207 } 1208 1209 /* 1210 * Function to rep read 64 bit data off the PCI configuration space behind 1211 * the 21554's host interface. 1212 */ 1213 static void 1214 px_pci_config_rep_get64(ddi_acc_impl_t *handle, uint64_t *host_addr, 1215 uint64_t *dev_addr, size_t repcount, uint_t flags) 1216 { 1217 if (flags == DDI_DEV_AUTOINCR) 1218 for (; repcount; repcount--) 1219 *host_addr++ = px_pci_config_get64(handle, dev_addr++); 1220 else 1221 for (; repcount; repcount--) 1222 *host_addr++ = px_pci_config_get64(handle, dev_addr); 1223 } 1224 1225 /* 1226 * Function to rep write 8 bit data into the PCI configuration space behind 1227 * the 21554's host interface. 1228 */ 1229 static void 1230 px_pci_config_rep_put8(ddi_acc_impl_t *handle, uint8_t *host_addr, 1231 uint8_t *dev_addr, size_t repcount, uint_t flags) 1232 { 1233 if (flags == DDI_DEV_AUTOINCR) 1234 for (; repcount; repcount--) 1235 px_pci_config_put8(handle, dev_addr++, *host_addr++); 1236 else 1237 for (; repcount; repcount--) 1238 px_pci_config_put8(handle, dev_addr, *host_addr++); 1239 } 1240 1241 /* 1242 * Function to rep write 16 bit data into the PCI configuration space behind 1243 * the 21554's host interface. 1244 */ 1245 static void 1246 px_pci_config_rep_put16(ddi_acc_impl_t *handle, uint16_t *host_addr, 1247 uint16_t *dev_addr, size_t repcount, uint_t flags) 1248 { 1249 if (flags == DDI_DEV_AUTOINCR) 1250 for (; repcount; repcount--) 1251 px_pci_config_put16(handle, dev_addr++, *host_addr++); 1252 else 1253 for (; repcount; repcount--) 1254 px_pci_config_put16(handle, dev_addr, *host_addr++); 1255 } 1256 1257 /* 1258 * Function to rep write 32 bit data into the PCI configuration space behind 1259 * the 21554's host interface. 1260 */ 1261 static void 1262 px_pci_config_rep_put32(ddi_acc_impl_t *handle, uint32_t *host_addr, 1263 uint32_t *dev_addr, size_t repcount, uint_t flags) 1264 { 1265 if (flags == DDI_DEV_AUTOINCR) 1266 for (; repcount; repcount--) 1267 px_pci_config_put32(handle, dev_addr++, *host_addr++); 1268 else 1269 for (; repcount; repcount--) 1270 px_pci_config_put32(handle, dev_addr, *host_addr++); 1271 } 1272 1273 /* 1274 * Function to rep write 64 bit data into the PCI configuration space behind 1275 * the 21554's host interface. 1276 */ 1277 static void 1278 px_pci_config_rep_put64(ddi_acc_impl_t *handle, uint64_t *host_addr, 1279 uint64_t *dev_addr, size_t repcount, uint_t flags) 1280 { 1281 if (flags == DDI_DEV_AUTOINCR) 1282 for (; repcount; repcount--) 1283 px_pci_config_put64(handle, dev_addr++, *host_addr++); 1284 else 1285 for (; repcount; repcount--) 1286 px_pci_config_put64(handle, dev_addr, *host_addr++); 1287 } 1288 1289 /* 1290 * Provide a private access handle to route config access calls to Hypervisor. 1291 * Beware: Do all error checking for config space accesses before calling 1292 * this function. ie. do error checking from the calling function. 1293 * Due to a lack of meaningful error code in DDI, the gauranteed return of 1294 * DDI_SUCCESS from here makes the code organization readable/easier from 1295 * the generic code. 1296 */ 1297 /*ARGSUSED*/ 1298 int 1299 px_lib_map_vconfig(dev_info_t *dip, 1300 ddi_map_req_t *mp, pci_config_offset_t off, 1301 pci_regspec_t *rp, caddr_t *addrp) 1302 { 1303 ddi_acc_hdl_t *hp; 1304 ddi_acc_impl_t *ap; 1305 uchar_t busnum; /* bus number */ 1306 uchar_t devnum; /* device number */ 1307 uchar_t funcnum; /* function number */ 1308 px_config_acc_pvt_t *px_pvt; 1309 1310 hp = (ddi_acc_hdl_t *)mp->map_handlep; 1311 ap = (ddi_acc_impl_t *)hp->ah_platform_private; 1312 1313 /* Check for mapping teardown operation */ 1314 if ((mp->map_op == DDI_MO_UNMAP) || 1315 (mp->map_op == DDI_MO_UNLOCK)) { 1316 /* free up memory allocated for the private access handle. */ 1317 px_pvt = (px_config_acc_pvt_t *)hp->ah_bus_private; 1318 kmem_free((void *)px_pvt, sizeof (px_config_acc_pvt_t)); 1319 1320 /* unmap operation of PCI IO/config space. */ 1321 return (DDI_SUCCESS); 1322 } 1323 1324 ap->ahi_get8 = px_pci_config_get8; 1325 ap->ahi_get16 = px_pci_config_get16; 1326 ap->ahi_get32 = px_pci_config_get32; 1327 ap->ahi_get64 = px_pci_config_get64; 1328 ap->ahi_put8 = px_pci_config_put8; 1329 ap->ahi_put16 = px_pci_config_put16; 1330 ap->ahi_put32 = px_pci_config_put32; 1331 ap->ahi_put64 = px_pci_config_put64; 1332 ap->ahi_rep_get8 = px_pci_config_rep_get8; 1333 ap->ahi_rep_get16 = px_pci_config_rep_get16; 1334 ap->ahi_rep_get32 = px_pci_config_rep_get32; 1335 ap->ahi_rep_get64 = px_pci_config_rep_get64; 1336 ap->ahi_rep_put8 = px_pci_config_rep_put8; 1337 ap->ahi_rep_put16 = px_pci_config_rep_put16; 1338 ap->ahi_rep_put32 = px_pci_config_rep_put32; 1339 ap->ahi_rep_put64 = px_pci_config_rep_put64; 1340 1341 /* Initialize to default check/notify functions */ 1342 ap->ahi_fault = 0; 1343 ap->ahi_fault_check = i_ddi_acc_fault_check; 1344 ap->ahi_fault_notify = i_ddi_acc_fault_notify; 1345 1346 /* allocate memory for our private handle */ 1347 px_pvt = (px_config_acc_pvt_t *) 1348 kmem_zalloc(sizeof (px_config_acc_pvt_t), KM_SLEEP); 1349 hp->ah_bus_private = (void *)px_pvt; 1350 1351 busnum = PCI_REG_BUS_G(rp->pci_phys_hi); 1352 devnum = PCI_REG_DEV_G(rp->pci_phys_hi); 1353 funcnum = PCI_REG_FUNC_G(rp->pci_phys_hi); 1354 1355 /* set up private data for use during IO routines */ 1356 1357 /* addr needed by the HV APIs */ 1358 px_pvt->raddr = busnum << 16 | devnum << 11 | funcnum << 8; 1359 /* 1360 * Address that specifies the actual offset into the 256MB 1361 * memory mapped configuration space, 4K per device. 1362 * First 12bits form the offset into 4K config space. 1363 * This address is only used during the IO routines to calculate 1364 * the offset at which the transaction must be performed. 1365 * Drivers bypassing DDI functions to access PCI config space will 1366 * panic the system since the following is a bogus virtual address. 1367 */ 1368 px_pvt->vaddr = busnum << 20 | devnum << 15 | funcnum << 12 | off; 1369 px_pvt->dip = dip; 1370 1371 DBG(DBG_LIB_CFG, dip, "px_config_setup: raddr 0x%x, vaddr 0x%x\n", 1372 px_pvt->raddr, px_pvt->vaddr); 1373 *addrp = (caddr_t)(uintptr_t)px_pvt->vaddr; 1374 return (DDI_SUCCESS); 1375 } 1376 1377 /*ARGSUSED*/ 1378 void 1379 px_lib_map_attr_check(ddi_map_req_t *mp) 1380 { 1381 } 1382 1383 /* 1384 * px_lib_log_safeacc_err: 1385 * Imitate a cpu/mem trap call when a peek/poke fails. 1386 * This will initiate something similar to px_fm_callback. 1387 */ 1388 static void 1389 px_lib_log_safeacc_err(px_t *px_p, ddi_acc_handle_t handle, int fme_flag) 1390 { 1391 ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handle; 1392 px_cb_t *cb_p = px_p->px_cb_p; 1393 ddi_fm_error_t derr; 1394 1395 derr.fme_status = DDI_FM_NONFATAL; 1396 derr.fme_version = DDI_FME_VERSION; 1397 derr.fme_flag = fme_flag; 1398 derr.fme_ena = fm_ena_generate(0, FM_ENA_FMT1); 1399 derr.fme_acc_handle = handle; 1400 if (hp) 1401 hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED; 1402 1403 mutex_enter(&cb_p->xbc_fm_mutex); 1404 1405 (void) ndi_fm_handler_dispatch(px_p->px_dip, NULL, &derr); 1406 1407 mutex_exit(&cb_p->xbc_fm_mutex); 1408 } 1409 1410 1411 #ifdef DEBUG 1412 int px_peekfault_cnt = 0; 1413 int px_pokefault_cnt = 0; 1414 #endif /* DEBUG */ 1415 1416 static int 1417 px_lib_bdf_from_dip(dev_info_t *rdip, uint32_t *bdf) 1418 { 1419 /* Start with an array of 8 reg spaces for now to cover most devices. */ 1420 pci_regspec_t regspec_array[8]; 1421 pci_regspec_t *regspec = regspec_array; 1422 int buflen = sizeof (regspec_array); 1423 boolean_t kmalloced = B_FALSE; 1424 int status; 1425 1426 status = ddi_getlongprop_buf(DDI_DEV_T_ANY, rdip, 1427 DDI_PROP_DONTPASS, "reg", (caddr_t)regspec, &buflen); 1428 1429 /* If need more space, fallback to kmem_alloc. */ 1430 if (status == DDI_PROP_BUF_TOO_SMALL) { 1431 regspec = kmem_alloc(buflen, KM_SLEEP); 1432 1433 status = ddi_getlongprop_buf(DDI_DEV_T_ANY, rdip, 1434 DDI_PROP_DONTPASS, "reg", (caddr_t)regspec, &buflen); 1435 1436 kmalloced = B_TRUE; 1437 } 1438 1439 /* Get phys_hi from first element. All have same bdf. */ 1440 if (status == DDI_PROP_SUCCESS) 1441 *bdf = regspec->pci_phys_hi & (PCI_REG_BDFR_M ^ PCI_REG_REG_M); 1442 1443 if (kmalloced) 1444 kmem_free(regspec, buflen); 1445 1446 return ((status == DDI_PROP_SUCCESS) ? DDI_SUCCESS : DDI_FAILURE); 1447 } 1448 1449 /* 1450 * Do a safe write to a device. 1451 * 1452 * When this function is given a handle (cautious access), all errors are 1453 * suppressed. 1454 * 1455 * When this function is not given a handle (poke), only Unsupported Request 1456 * and Completer Abort errors are suppressed. 1457 * 1458 * In all cases, all errors are returned in the function return status. 1459 */ 1460 1461 int 1462 px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip, 1463 peekpoke_ctlops_t *in_args) 1464 { 1465 px_t *px_p = DIP_TO_STATE(dip); 1466 px_pec_t *pec_p = px_p->px_pec_p; 1467 ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 1468 1469 size_t repcount = in_args->repcount; 1470 size_t size = in_args->size; 1471 uintptr_t dev_addr = in_args->dev_addr; 1472 uintptr_t host_addr = in_args->host_addr; 1473 1474 int err = DDI_SUCCESS; 1475 uint64_t hvio_poke_status; 1476 uint32_t bdf; 1477 uint32_t wrt_stat; 1478 1479 r_addr_t ra; 1480 uint64_t pokeval; 1481 1482 /* 1483 * Used only to notify error handling peek/poke is occuring 1484 * One scenario is when a fabric err as a result of peek/poke. 1485 * However there is no way to guarantee that the fabric error 1486 * handler will occur in the window where otd is set. 1487 */ 1488 on_trap_data_t otd; 1489 1490 if (px_lib_bdf_from_dip(rdip, &bdf) != DDI_SUCCESS) { 1491 DBG(DBG_LIB_DMA, px_p->px_dip, 1492 "poke: px_lib_bdf_from_dip failed\n"); 1493 err = DDI_FAILURE; 1494 goto done; 1495 } 1496 1497 ra = (r_addr_t)va_to_pa((void *)dev_addr); 1498 for (; repcount; repcount--) { 1499 1500 switch (size) { 1501 case sizeof (uint8_t): 1502 pokeval = *(uint8_t *)host_addr; 1503 break; 1504 case sizeof (uint16_t): 1505 pokeval = *(uint16_t *)host_addr; 1506 break; 1507 case sizeof (uint32_t): 1508 pokeval = *(uint32_t *)host_addr; 1509 break; 1510 case sizeof (uint64_t): 1511 pokeval = *(uint64_t *)host_addr; 1512 break; 1513 default: 1514 DBG(DBG_MAP, px_p->px_dip, 1515 "poke: invalid size %d passed\n", size); 1516 err = DDI_FAILURE; 1517 goto done; 1518 } 1519 1520 /* 1521 * Grab pokefault mutex since hypervisor does not guarantee 1522 * poke serialization. 1523 */ 1524 if (hp) { 1525 i_ndi_busop_access_enter(hp->ahi_common.ah_dip, 1526 (ddi_acc_handle_t)hp); 1527 pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED; 1528 } else { 1529 mutex_enter(&pec_p->pec_pokefault_mutex); 1530 pec_p->pec_safeacc_type = DDI_FM_ERR_POKE; 1531 } 1532 pec_p->pec_ontrap_data = &otd; 1533 1534 hvio_poke_status = hvio_poke(px_p->px_dev_hdl, ra, size, 1535 pokeval, bdf, &wrt_stat); 1536 1537 if (otd.ot_trap & OT_DATA_ACCESS) 1538 err = DDI_FAILURE; 1539 1540 if ((hvio_poke_status != H_EOK) || (wrt_stat != H_EOK)) { 1541 err = DDI_FAILURE; 1542 #ifdef DEBUG 1543 px_pokefault_cnt++; 1544 #endif 1545 /* 1546 * For CAUTIOUS and POKE access, notify FMA to 1547 * cleanup. Imitate a cpu/mem trap call like in sun4u. 1548 */ 1549 px_lib_log_safeacc_err(px_p, (ddi_acc_handle_t)hp, 1550 (hp ? DDI_FM_ERR_EXPECTED : 1551 DDI_FM_ERR_POKE)); 1552 1553 pec_p->pec_ontrap_data = NULL; 1554 pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 1555 if (hp) { 1556 i_ndi_busop_access_exit(hp->ahi_common.ah_dip, 1557 (ddi_acc_handle_t)hp); 1558 } else { 1559 mutex_exit(&pec_p->pec_pokefault_mutex); 1560 } 1561 goto done; 1562 } 1563 1564 pec_p->pec_ontrap_data = NULL; 1565 pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 1566 if (hp) { 1567 i_ndi_busop_access_exit(hp->ahi_common.ah_dip, 1568 (ddi_acc_handle_t)hp); 1569 } else { 1570 mutex_exit(&pec_p->pec_pokefault_mutex); 1571 } 1572 1573 host_addr += size; 1574 1575 if (in_args->flags == DDI_DEV_AUTOINCR) { 1576 dev_addr += size; 1577 ra = (r_addr_t)va_to_pa((void *)dev_addr); 1578 } 1579 } 1580 1581 done: 1582 return (err); 1583 } 1584 1585 1586 /*ARGSUSED*/ 1587 int 1588 px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip, 1589 peekpoke_ctlops_t *in_args, void *result) 1590 { 1591 px_t *px_p = DIP_TO_STATE(dip); 1592 px_pec_t *pec_p = px_p->px_pec_p; 1593 ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 1594 1595 size_t repcount = in_args->repcount; 1596 uintptr_t dev_addr = in_args->dev_addr; 1597 uintptr_t host_addr = in_args->host_addr; 1598 1599 r_addr_t ra; 1600 uint32_t read_status; 1601 uint64_t hvio_peek_status; 1602 uint64_t peekval; 1603 int err = DDI_SUCCESS; 1604 1605 /* 1606 * Used only to notify error handling peek/poke is occuring 1607 * One scenario is when a fabric err as a result of peek/poke. 1608 * However there is no way to guarantee that the fabric error 1609 * handler will occur in the window where otd is set. 1610 */ 1611 on_trap_data_t otd; 1612 1613 result = (void *)in_args->host_addr; 1614 1615 ra = (r_addr_t)va_to_pa((void *)dev_addr); 1616 for (; repcount; repcount--) { 1617 1618 /* Lock pokefault mutex so read doesn't mask a poke fault. */ 1619 if (hp) { 1620 i_ndi_busop_access_enter(hp->ahi_common.ah_dip, 1621 (ddi_acc_handle_t)hp); 1622 pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED; 1623 } else { 1624 mutex_enter(&pec_p->pec_pokefault_mutex); 1625 pec_p->pec_safeacc_type = DDI_FM_ERR_PEEK; 1626 } 1627 pec_p->pec_ontrap_data = &otd; 1628 1629 hvio_peek_status = hvio_peek(px_p->px_dev_hdl, ra, 1630 in_args->size, &read_status, &peekval); 1631 1632 if ((hvio_peek_status != H_EOK) || (read_status != H_EOK)) { 1633 err = DDI_FAILURE; 1634 1635 /* 1636 * For CAUTIOUS and PEEK access, notify FMA to 1637 * cleanup. Imitate a cpu/mem trap call like in sun4u. 1638 */ 1639 px_lib_log_safeacc_err(px_p, (ddi_acc_handle_t)hp, 1640 (hp ? DDI_FM_ERR_EXPECTED : 1641 DDI_FM_ERR_PEEK)); 1642 1643 /* Stuff FFs in host addr if peek. */ 1644 if (hp == NULL) { 1645 int i; 1646 uint8_t *ff_addr = (uint8_t *)host_addr; 1647 for (i = 0; i < in_args->size; i++) 1648 *ff_addr++ = 0xff; 1649 } 1650 #ifdef DEBUG 1651 px_peekfault_cnt++; 1652 #endif 1653 pec_p->pec_ontrap_data = NULL; 1654 pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 1655 if (hp) { 1656 i_ndi_busop_access_exit(hp->ahi_common.ah_dip, 1657 (ddi_acc_handle_t)hp); 1658 } else { 1659 mutex_exit(&pec_p->pec_pokefault_mutex); 1660 } 1661 goto done; 1662 1663 } 1664 pec_p->pec_ontrap_data = NULL; 1665 pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 1666 if (hp) { 1667 i_ndi_busop_access_exit(hp->ahi_common.ah_dip, 1668 (ddi_acc_handle_t)hp); 1669 } else { 1670 mutex_exit(&pec_p->pec_pokefault_mutex); 1671 } 1672 1673 switch (in_args->size) { 1674 case sizeof (uint8_t): 1675 *(uint8_t *)host_addr = (uint8_t)peekval; 1676 break; 1677 case sizeof (uint16_t): 1678 *(uint16_t *)host_addr = (uint16_t)peekval; 1679 break; 1680 case sizeof (uint32_t): 1681 *(uint32_t *)host_addr = (uint32_t)peekval; 1682 break; 1683 case sizeof (uint64_t): 1684 *(uint64_t *)host_addr = (uint64_t)peekval; 1685 break; 1686 default: 1687 DBG(DBG_MAP, px_p->px_dip, 1688 "peek: invalid size %d passed\n", 1689 in_args->size); 1690 err = DDI_FAILURE; 1691 goto done; 1692 } 1693 1694 host_addr += in_args->size; 1695 1696 if (in_args->flags == DDI_DEV_AUTOINCR) { 1697 dev_addr += in_args->size; 1698 ra = (r_addr_t)va_to_pa((void *)dev_addr); 1699 } 1700 } 1701 done: 1702 return (err); 1703 } 1704 1705 1706 /* add interrupt vector */ 1707 int 1708 px_err_add_intr(px_fault_t *px_fault_p) 1709 { 1710 int ret; 1711 px_t *px_p = DIP_TO_STATE(px_fault_p->px_fh_dip); 1712 1713 DBG(DBG_LIB_INT, px_p->px_dip, 1714 "px_err_add_intr: calling add_ivintr"); 1715 ret = add_ivintr(px_fault_p->px_fh_sysino, PX_ERR_PIL, 1716 px_fault_p->px_err_func, (caddr_t)px_fault_p, 1717 (caddr_t)&px_fault_p->px_intr_payload[0]); 1718 1719 if (ret != DDI_SUCCESS) { 1720 DBG(DBG_LIB_INT, px_p->px_dip, 1721 "add_ivintr returns %d, faultp: %p", ret, px_fault_p); 1722 1723 return (ret); 1724 } 1725 DBG(DBG_LIB_INT, px_p->px_dip, 1726 "px_err_add_intr: ib_intr_enable "); 1727 1728 px_ib_intr_enable(px_p, intr_dist_cpuid(), px_fault_p->px_intr_ino); 1729 1730 return (ret); 1731 } 1732 1733 1734 /* remove interrupt vector */ 1735 void 1736 px_err_rem_intr(px_fault_t *px_fault_p) 1737 { 1738 px_t *px_p = DIP_TO_STATE(px_fault_p->px_fh_dip); 1739 1740 px_ib_intr_disable(px_p->px_ib_p, px_fault_p->px_intr_ino, 1741 IB_INTR_WAIT); 1742 1743 rem_ivintr(px_fault_p->px_fh_sysino, NULL); 1744 } 1745 1746 1747 #ifdef FMA 1748 void 1749 px_fill_rc_status(px_fault_t *px_fault_p, pciex_rc_error_regs_t *rc_status) 1750 { 1751 px_pec_err_t *err_pkt; 1752 1753 err_pkt = (px_pec_err_t *)px_fault_p->px_intr_payload; 1754 1755 /* initialise all the structure members */ 1756 rc_status->status_valid = 0; 1757 1758 if (err_pkt->pec_descr.P) { 1759 /* PCI Status Register */ 1760 rc_status->pci_err_status = err_pkt->pci_err_status; 1761 rc_status->status_valid |= PCI_ERR_STATUS_VALID; 1762 } 1763 1764 if (err_pkt->pec_descr.E) { 1765 /* PCIe Status Register */ 1766 rc_status->pcie_err_status = err_pkt->pcie_err_status; 1767 rc_status->status_valid |= PCIE_ERR_STATUS_VALID; 1768 } 1769 1770 if (err_pkt->pec_descr.U) { 1771 rc_status->ue_status = err_pkt->ue_reg_status; 1772 rc_status->status_valid |= UE_STATUS_VALID; 1773 } 1774 1775 if (err_pkt->pec_descr.H) { 1776 rc_status->ue_hdr1 = err_pkt->hdr[0]; 1777 rc_status->status_valid |= UE_HDR1_VALID; 1778 } 1779 1780 if (err_pkt->pec_descr.I) { 1781 rc_status->ue_hdr2 = err_pkt->hdr[1]; 1782 rc_status->status_valid |= UE_HDR2_VALID; 1783 } 1784 1785 /* ue_fst_err_ptr - not available for sun4v?? */ 1786 1787 1788 if (err_pkt->pec_descr.S) { 1789 rc_status->source_id = err_pkt->err_src_reg; 1790 rc_status->status_valid |= SOURCE_ID_VALID; 1791 } 1792 1793 if (err_pkt->pec_descr.R) { 1794 rc_status->root_err_status = err_pkt->root_err_status; 1795 rc_status->status_valid |= CE_STATUS_VALID; 1796 } 1797 } 1798 #endif 1799 1800 /*ARGSUSED*/ 1801 int 1802 px_lib_pmctl(int cmd, px_t *px_p) 1803 { 1804 return (DDI_FAILURE); 1805 } 1806 1807 /*ARGSUSED*/ 1808 uint_t 1809 px_pmeq_intr(caddr_t arg) 1810 { 1811 return (DDI_INTR_CLAIMED); 1812 } 1813 1814 /* 1815 * Unprotected raw reads/writes of fabric device's config space. 1816 * Only used for temporary PCI-E Fabric Error Handling. 1817 */ 1818 uint32_t 1819 px_fab_get(px_t *px_p, pcie_req_id_t bdf, uint16_t offset) { 1820 uint32_t data = 0; 1821 1822 (void) hvio_config_get(px_p->px_dev_hdl, 1823 (bdf << PX_RA_BDF_SHIFT), offset, 4, 1824 (pci_cfg_data_t *)&data); 1825 1826 return (data); 1827 } 1828 1829 void 1830 px_fab_set(px_t *px_p, pcie_req_id_t bdf, uint16_t offset, 1831 uint32_t val) { 1832 pci_cfg_data_t wdata = { 0 }; 1833 1834 wdata.qw = (uint32_t)val; 1835 (void) hvio_config_put(px_p->px_dev_hdl, 1836 (bdf << PX_RA_BDF_SHIFT), offset, 4, wdata); 1837 } 1838 1839 /*ARGSUSED*/ 1840 int 1841 px_lib_hotplug_init(dev_info_t *dip, void *arg) 1842 { 1843 return (DDI_ENOTSUP); 1844 } 1845 1846 /*ARGSUSED*/ 1847 void 1848 px_lib_hotplug_uninit(dev_info_t *dip) 1849 { 1850 } 1851 1852 /* Dummy cpr add callback */ 1853 /*ARGSUSED*/ 1854 void 1855 px_cpr_add_callb(px_t *px_p) 1856 { 1857 } 1858 1859 /* Dummy cpr rem callback */ 1860 /*ARGSUSED*/ 1861 void 1862 px_cpr_rem_callb(px_t *px_p) 1863 { 1864 } 1865