aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/cxl/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/cxl/pci.c')
-rw-r--r--drivers/misc/cxl/pci.c259
1 files changed, 242 insertions, 17 deletions
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 4a1b407ca514..976956f3fc9e 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -60,7 +60,7 @@
60#define CXL_VSEC_PROTOCOL_MASK 0xe0 60#define CXL_VSEC_PROTOCOL_MASK 0xe0
61#define CXL_VSEC_PROTOCOL_1024TB 0x80 61#define CXL_VSEC_PROTOCOL_1024TB 0x80
62#define CXL_VSEC_PROTOCOL_512TB 0x40 62#define CXL_VSEC_PROTOCOL_512TB 0x40
63#define CXL_VSEC_PROTOCOL_256TB 0x20 /* Power 8 uses this */ 63#define CXL_VSEC_PROTOCOL_256TB 0x20 /* Power 8/9 uses this */
64#define CXL_VSEC_PROTOCOL_ENABLE 0x01 64#define CXL_VSEC_PROTOCOL_ENABLE 0x01
65 65
66#define CXL_READ_VSEC_PSL_REVISION(dev, vsec, dest) \ 66#define CXL_READ_VSEC_PSL_REVISION(dev, vsec, dest) \
@@ -326,14 +326,18 @@ static void dump_afu_descriptor(struct cxl_afu *afu)
326 326
327#define P8_CAPP_UNIT0_ID 0xBA 327#define P8_CAPP_UNIT0_ID 0xBA
328#define P8_CAPP_UNIT1_ID 0XBE 328#define P8_CAPP_UNIT1_ID 0XBE
329#define P9_CAPP_UNIT0_ID 0xC0
330#define P9_CAPP_UNIT1_ID 0xE0
329 331
330static u64 get_capp_unit_id(struct device_node *np) 332static int get_phb_index(struct device_node *np, u32 *phb_index)
331{ 333{
332 u32 phb_index; 334 if (of_property_read_u32(np, "ibm,phb-index", phb_index))
333 335 return -ENODEV;
334 if (of_property_read_u32(np, "ibm,phb-index", &phb_index)) 336 return 0;
335 return 0; 337}
336 338
339static u64 get_capp_unit_id(struct device_node *np, u32 phb_index)
340{
337 /* 341 /*
338 * POWER 8: 342 * POWER 8:
339 * - For chips other than POWER8NVL, we only have CAPP 0, 343 * - For chips other than POWER8NVL, we only have CAPP 0,
@@ -352,11 +356,27 @@ static u64 get_capp_unit_id(struct device_node *np)
352 return P8_CAPP_UNIT1_ID; 356 return P8_CAPP_UNIT1_ID;
353 } 357 }
354 358
359 /*
360 * POWER 9:
361 * PEC0 (PHB0). Capp ID = CAPP0 (0b1100_0000)
362 * PEC1 (PHB1 - PHB2). No capi mode
363 * PEC2 (PHB3 - PHB4 - PHB5): Capi mode on PHB3 only. Capp ID = CAPP1 (0b1110_0000)
364 */
365 if (cxl_is_power9()) {
366 if (phb_index == 0)
367 return P9_CAPP_UNIT0_ID;
368
369 if (phb_index == 3)
370 return P9_CAPP_UNIT1_ID;
371 }
372
355 return 0; 373 return 0;
356} 374}
357 375
358static int calc_capp_routing(struct pci_dev *dev, u64 *chipid, u64 *capp_unit_id) 376static int calc_capp_routing(struct pci_dev *dev, u64 *chipid,
377 u32 *phb_index, u64 *capp_unit_id)
359{ 378{
379 int rc;
360 struct device_node *np; 380 struct device_node *np;
361 const __be32 *prop; 381 const __be32 *prop;
362 382
@@ -367,8 +387,16 @@ static int calc_capp_routing(struct pci_dev *dev, u64 *chipid, u64 *capp_unit_id
367 np = of_get_next_parent(np); 387 np = of_get_next_parent(np);
368 if (!np) 388 if (!np)
369 return -ENODEV; 389 return -ENODEV;
390
370 *chipid = be32_to_cpup(prop); 391 *chipid = be32_to_cpup(prop);
371 *capp_unit_id = get_capp_unit_id(np); 392
393 rc = get_phb_index(np, phb_index);
394 if (rc) {
395 pr_err("cxl: invalid phb index\n");
396 return rc;
397 }
398
399 *capp_unit_id = get_capp_unit_id(np, *phb_index);
372 of_node_put(np); 400 of_node_put(np);
373 if (!*capp_unit_id) { 401 if (!*capp_unit_id) {
374 pr_err("cxl: invalid capp unit id\n"); 402 pr_err("cxl: invalid capp unit id\n");
@@ -378,14 +406,104 @@ static int calc_capp_routing(struct pci_dev *dev, u64 *chipid, u64 *capp_unit_id
378 return 0; 406 return 0;
379} 407}
380 408
409static int init_implementation_adapter_regs_psl9(struct cxl *adapter, struct pci_dev *dev)
410{
411 u64 xsl_dsnctl, psl_fircntl;
412 u64 chipid;
413 u32 phb_index;
414 u64 capp_unit_id;
415 int rc;
416
417 rc = calc_capp_routing(dev, &chipid, &phb_index, &capp_unit_id);
418 if (rc)
419 return rc;
420
421 /*
422 * CAPI Identifier bits [0:7]
423 * bit 61:60 MSI bits --> 0
424 * bit 59 TVT selector --> 0
425 */
426
427 /*
428 * Tell XSL where to route data to.
429 * The field chipid should match the PHB CAPI_CMPM register
430 */
431 xsl_dsnctl = ((u64)0x2 << (63-7)); /* Bit 57 */
432 xsl_dsnctl |= (capp_unit_id << (63-15));
433
434 /* nMMU_ID Defaults to: b’000001001’*/
435 xsl_dsnctl |= ((u64)0x09 << (63-28));
436
437 if (cxl_is_power9() && !cpu_has_feature(CPU_FTR_POWER9_DD1)) {
438 /*
439 * Used to identify CAPI packets which should be sorted into
440 * the Non-Blocking queues by the PHB. This field should match
441 * the PHB PBL_NBW_CMPM register
442 * nbwind=0x03, bits [57:58], must include capi indicator.
443 * Not supported on P9 DD1.
444 */
445 xsl_dsnctl |= ((u64)0x03 << (63-47));
446
447 /*
448 * Upper 16b address bits of ASB_Notify messages sent to the
449 * system. Need to match the PHB’s ASN Compare/Mask Register.
450 * Not supported on P9 DD1.
451 */
452 xsl_dsnctl |= ((u64)0x04 << (63-55));
453 }
454
455 cxl_p1_write(adapter, CXL_XSL9_DSNCTL, xsl_dsnctl);
456
457 /* Set fir_cntl to recommended value for production env */
458 psl_fircntl = (0x2ULL << (63-3)); /* ce_report */
459 psl_fircntl |= (0x1ULL << (63-6)); /* FIR_report */
460 psl_fircntl |= 0x1ULL; /* ce_thresh */
461 cxl_p1_write(adapter, CXL_PSL9_FIR_CNTL, psl_fircntl);
462
463 /* vccredits=0x1 pcklat=0x4 */
464 cxl_p1_write(adapter, CXL_PSL9_DSNDCTL, 0x0000000000001810ULL);
465
466 /*
467 * For debugging with trace arrays.
468 * Configure RX trace 0 segmented mode.
469 * Configure CT trace 0 segmented mode.
470 * Configure LA0 trace 0 segmented mode.
471 * Configure LA1 trace 0 segmented mode.
472 */
473 cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x8040800080000000ULL);
474 cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x8040800080000003ULL);
475 cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x8040800080000005ULL);
476 cxl_p1_write(adapter, CXL_PSL9_TRACECFG, 0x8040800080000006ULL);
477
478 /*
479 * A response to an ASB_Notify request is returned by the
480 * system as an MMIO write to the address defined in
481 * the PSL_TNR_ADDR register
482 */
483 /* PSL_TNR_ADDR */
484
485 /* NORST */
486 cxl_p1_write(adapter, CXL_PSL9_DEBUG, 0x8000000000000000ULL);
487
488 /* allocate the apc machines */
489 cxl_p1_write(adapter, CXL_PSL9_APCDEDTYPE, 0x40000003FFFF0000ULL);
490
491 /* Disable vc dd1 fix */
492 if ((cxl_is_power9() && cpu_has_feature(CPU_FTR_POWER9_DD1)))
493 cxl_p1_write(adapter, CXL_PSL9_GP_CT, 0x0400000000000001ULL);
494
495 return 0;
496}
497
381static int init_implementation_adapter_regs_psl8(struct cxl *adapter, struct pci_dev *dev) 498static int init_implementation_adapter_regs_psl8(struct cxl *adapter, struct pci_dev *dev)
382{ 499{
383 u64 psl_dsnctl, psl_fircntl; 500 u64 psl_dsnctl, psl_fircntl;
384 u64 chipid; 501 u64 chipid;
502 u32 phb_index;
385 u64 capp_unit_id; 503 u64 capp_unit_id;
386 int rc; 504 int rc;
387 505
388 rc = calc_capp_routing(dev, &chipid, &capp_unit_id); 506 rc = calc_capp_routing(dev, &chipid, &phb_index, &capp_unit_id);
389 if (rc) 507 if (rc)
390 return rc; 508 return rc;
391 509
@@ -414,10 +532,11 @@ static int init_implementation_adapter_regs_xsl(struct cxl *adapter, struct pci_
414{ 532{
415 u64 xsl_dsnctl; 533 u64 xsl_dsnctl;
416 u64 chipid; 534 u64 chipid;
535 u32 phb_index;
417 u64 capp_unit_id; 536 u64 capp_unit_id;
418 int rc; 537 int rc;
419 538
420 rc = calc_capp_routing(dev, &chipid, &capp_unit_id); 539 rc = calc_capp_routing(dev, &chipid, &phb_index, &capp_unit_id);
421 if (rc) 540 if (rc)
422 return rc; 541 return rc;
423 542
@@ -435,6 +554,12 @@ static int init_implementation_adapter_regs_xsl(struct cxl *adapter, struct pci_
435/* For the PSL this is a multiple for 0 < n <= 7: */ 554/* For the PSL this is a multiple for 0 < n <= 7: */
436#define PSL_2048_250MHZ_CYCLES 1 555#define PSL_2048_250MHZ_CYCLES 1
437 556
557static void write_timebase_ctrl_psl9(struct cxl *adapter)
558{
559 cxl_p1_write(adapter, CXL_PSL9_TB_CTLSTAT,
560 TBSYNC_CNT(2 * PSL_2048_250MHZ_CYCLES));
561}
562
438static void write_timebase_ctrl_psl8(struct cxl *adapter) 563static void write_timebase_ctrl_psl8(struct cxl *adapter)
439{ 564{
440 cxl_p1_write(adapter, CXL_PSL_TB_CTLSTAT, 565 cxl_p1_write(adapter, CXL_PSL_TB_CTLSTAT,
@@ -456,6 +581,11 @@ static void write_timebase_ctrl_xsl(struct cxl *adapter)
456 TBSYNC_CNT(XSL_4000_CLOCKS)); 581 TBSYNC_CNT(XSL_4000_CLOCKS));
457} 582}
458 583
584static u64 timebase_read_psl9(struct cxl *adapter)
585{
586 return cxl_p1_read(adapter, CXL_PSL9_Timebase);
587}
588
459static u64 timebase_read_psl8(struct cxl *adapter) 589static u64 timebase_read_psl8(struct cxl *adapter)
460{ 590{
461 return cxl_p1_read(adapter, CXL_PSL_Timebase); 591 return cxl_p1_read(adapter, CXL_PSL_Timebase);
@@ -514,6 +644,11 @@ static void cxl_setup_psl_timebase(struct cxl *adapter, struct pci_dev *dev)
514 return; 644 return;
515} 645}
516 646
647static int init_implementation_afu_regs_psl9(struct cxl_afu *afu)
648{
649 return 0;
650}
651
517static int init_implementation_afu_regs_psl8(struct cxl_afu *afu) 652static int init_implementation_afu_regs_psl8(struct cxl_afu *afu)
518{ 653{
519 /* read/write masks for this slice */ 654 /* read/write masks for this slice */
@@ -612,7 +747,7 @@ static int setup_cxl_bars(struct pci_dev *dev)
612 /* 747 /*
613 * BAR 4/5 has a special meaning for CXL and must be programmed with a 748 * BAR 4/5 has a special meaning for CXL and must be programmed with a
614 * special value corresponding to the CXL protocol address range. 749 * special value corresponding to the CXL protocol address range.
615 * For POWER 8 that means bits 48:49 must be set to 10 750 * For POWER 8/9 that means bits 48:49 must be set to 10
616 */ 751 */
617 pci_write_config_dword(dev, PCI_BASE_ADDRESS_4, 0x00000000); 752 pci_write_config_dword(dev, PCI_BASE_ADDRESS_4, 0x00000000);
618 pci_write_config_dword(dev, PCI_BASE_ADDRESS_5, 0x00020000); 753 pci_write_config_dword(dev, PCI_BASE_ADDRESS_5, 0x00020000);
@@ -997,6 +1132,52 @@ static int cxl_afu_descriptor_looks_ok(struct cxl_afu *afu)
997 return 0; 1132 return 0;
998} 1133}
999 1134
1135static int sanitise_afu_regs_psl9(struct cxl_afu *afu)
1136{
1137 u64 reg;
1138
1139 /*
1140 * Clear out any regs that contain either an IVTE or address or may be
1141 * waiting on an acknowledgment to try to be a bit safer as we bring
1142 * it online
1143 */
1144 reg = cxl_p2n_read(afu, CXL_AFU_Cntl_An);
1145 if ((reg & CXL_AFU_Cntl_An_ES_MASK) != CXL_AFU_Cntl_An_ES_Disabled) {
1146 dev_warn(&afu->dev, "WARNING: AFU was not disabled: %#016llx\n", reg);
1147 if (cxl_ops->afu_reset(afu))
1148 return -EIO;
1149 if (cxl_afu_disable(afu))
1150 return -EIO;
1151 if (cxl_psl_purge(afu))
1152 return -EIO;
1153 }
1154 cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0x0000000000000000);
1155 cxl_p1n_write(afu, CXL_PSL_AMBAR_An, 0x0000000000000000);
1156 reg = cxl_p2n_read(afu, CXL_PSL_DSISR_An);
1157 if (reg) {
1158 dev_warn(&afu->dev, "AFU had pending DSISR: %#016llx\n", reg);
1159 if (reg & CXL_PSL9_DSISR_An_TF)
1160 cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_AE);
1161 else
1162 cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_A);
1163 }
1164 if (afu->adapter->native->sl_ops->register_serr_irq) {
1165 reg = cxl_p1n_read(afu, CXL_PSL_SERR_An);
1166 if (reg) {
1167 if (reg & ~0x000000007fffffff)
1168 dev_warn(&afu->dev, "AFU had pending SERR: %#016llx\n", reg);
1169 cxl_p1n_write(afu, CXL_PSL_SERR_An, reg & ~0xffff);
1170 }
1171 }
1172 reg = cxl_p2n_read(afu, CXL_PSL_ErrStat_An);
1173 if (reg) {
1174 dev_warn(&afu->dev, "AFU had pending error status: %#016llx\n", reg);
1175 cxl_p2n_write(afu, CXL_PSL_ErrStat_An, reg);
1176 }
1177
1178 return 0;
1179}
1180
1000static int sanitise_afu_regs_psl8(struct cxl_afu *afu) 1181static int sanitise_afu_regs_psl8(struct cxl_afu *afu)
1001{ 1182{
1002 u64 reg; 1183 u64 reg;
@@ -1254,10 +1435,10 @@ int cxl_pci_reset(struct cxl *adapter)
1254 1435
1255 /* 1436 /*
1256 * The adapter is about to be reset, so ignore errors. 1437 * The adapter is about to be reset, so ignore errors.
1257 * Not supported on P9 DD1 but don't forget to enable it 1438 * Not supported on P9 DD1
1258 * on P9 DD2
1259 */ 1439 */
1260 if (cxl_is_power8()) 1440 if ((cxl_is_power8()) ||
1441 ((cxl_is_power9() && !cpu_has_feature(CPU_FTR_POWER9_DD1))))
1261 cxl_data_cache_flush(adapter); 1442 cxl_data_cache_flush(adapter);
1262 1443
1263 /* pcie_warm_reset requests a fundamental pci reset which includes a 1444 /* pcie_warm_reset requests a fundamental pci reset which includes a
@@ -1393,6 +1574,9 @@ static bool cxl_compatible_caia_version(struct cxl *adapter)
1393 if (cxl_is_power8() && (adapter->caia_major == 1)) 1574 if (cxl_is_power8() && (adapter->caia_major == 1))
1394 return true; 1575 return true;
1395 1576
1577 if (cxl_is_power9() && (adapter->caia_major == 2))
1578 return true;
1579
1396 return false; 1580 return false;
1397} 1581}
1398 1582
@@ -1460,8 +1644,12 @@ static int sanitise_adapter_regs(struct cxl *adapter)
1460 /* Clear PSL tberror bit by writing 1 to it */ 1644 /* Clear PSL tberror bit by writing 1 to it */
1461 cxl_p1_write(adapter, CXL_PSL_ErrIVTE, CXL_PSL_ErrIVTE_tberror); 1645 cxl_p1_write(adapter, CXL_PSL_ErrIVTE, CXL_PSL_ErrIVTE_tberror);
1462 1646
1463 if (adapter->native->sl_ops->invalidate_all) 1647 if (adapter->native->sl_ops->invalidate_all) {
1648 /* do not invalidate ERAT entries when not reloading on PERST */
1649 if (cxl_is_power9() && (adapter->perst_loads_image))
1650 return 0;
1464 rc = adapter->native->sl_ops->invalidate_all(adapter); 1651 rc = adapter->native->sl_ops->invalidate_all(adapter);
1652 }
1465 1653
1466 return rc; 1654 return rc;
1467} 1655}
@@ -1546,6 +1734,30 @@ static void cxl_deconfigure_adapter(struct cxl *adapter)
1546 pci_disable_device(pdev); 1734 pci_disable_device(pdev);
1547} 1735}
1548 1736
1737static const struct cxl_service_layer_ops psl9_ops = {
1738 .adapter_regs_init = init_implementation_adapter_regs_psl9,
1739 .invalidate_all = cxl_invalidate_all_psl9,
1740 .afu_regs_init = init_implementation_afu_regs_psl9,
1741 .sanitise_afu_regs = sanitise_afu_regs_psl9,
1742 .register_serr_irq = cxl_native_register_serr_irq,
1743 .release_serr_irq = cxl_native_release_serr_irq,
1744 .handle_interrupt = cxl_irq_psl9,
1745 .fail_irq = cxl_fail_irq_psl,
1746 .activate_dedicated_process = cxl_activate_dedicated_process_psl9,
1747 .attach_afu_directed = cxl_attach_afu_directed_psl9,
1748 .attach_dedicated_process = cxl_attach_dedicated_process_psl9,
1749 .update_dedicated_ivtes = cxl_update_dedicated_ivtes_psl9,
1750 .debugfs_add_adapter_regs = cxl_debugfs_add_adapter_regs_psl9,
1751 .debugfs_add_afu_regs = cxl_debugfs_add_afu_regs_psl9,
1752 .psl_irq_dump_registers = cxl_native_irq_dump_regs_psl9,
1753 .err_irq_dump_registers = cxl_native_err_irq_dump_regs,
1754 .debugfs_stop_trace = cxl_stop_trace_psl9,
1755 .write_timebase_ctrl = write_timebase_ctrl_psl9,
1756 .timebase_read = timebase_read_psl9,
1757 .capi_mode = OPAL_PHB_CAPI_MODE_CAPI,
1758 .needs_reset_before_disable = true,
1759};
1760
1549static const struct cxl_service_layer_ops psl8_ops = { 1761static const struct cxl_service_layer_ops psl8_ops = {
1550 .adapter_regs_init = init_implementation_adapter_regs_psl8, 1762 .adapter_regs_init = init_implementation_adapter_regs_psl8,
1551 .invalidate_all = cxl_invalidate_all_psl8, 1763 .invalidate_all = cxl_invalidate_all_psl8,
@@ -1597,6 +1809,9 @@ static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev)
1597 if (cxl_is_power8()) { 1809 if (cxl_is_power8()) {
1598 dev_info(&dev->dev, "Device uses a PSL8\n"); 1810 dev_info(&dev->dev, "Device uses a PSL8\n");
1599 adapter->native->sl_ops = &psl8_ops; 1811 adapter->native->sl_ops = &psl8_ops;
1812 } else {
1813 dev_info(&dev->dev, "Device uses a PSL9\n");
1814 adapter->native->sl_ops = &psl9_ops;
1600 } 1815 }
1601 } 1816 }
1602} 1817}
@@ -1667,8 +1882,13 @@ static void cxl_pci_remove_adapter(struct cxl *adapter)
1667 cxl_sysfs_adapter_remove(adapter); 1882 cxl_sysfs_adapter_remove(adapter);
1668 cxl_debugfs_adapter_remove(adapter); 1883 cxl_debugfs_adapter_remove(adapter);
1669 1884
1670 /* Flush adapter datacache as its about to be removed */ 1885 /*
1671 cxl_data_cache_flush(adapter); 1886 * Flush adapter datacache as its about to be removed.
1887 * Not supported on P9 DD1.
1888 */
1889 if ((cxl_is_power8()) ||
1890 ((cxl_is_power9() && !cpu_has_feature(CPU_FTR_POWER9_DD1))))
1891 cxl_data_cache_flush(adapter);
1672 1892
1673 cxl_deconfigure_adapter(adapter); 1893 cxl_deconfigure_adapter(adapter);
1674 1894
@@ -1752,6 +1972,11 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
1752 return -ENODEV; 1972 return -ENODEV;
1753 } 1973 }
1754 1974
1975 if (cxl_is_power9() && !radix_enabled()) {
1976 dev_info(&dev->dev, "Only Radix mode supported\n");
1977 return -ENODEV;
1978 }
1979
1755 if (cxl_verbose) 1980 if (cxl_verbose)
1756 dump_cxl_config_space(dev); 1981 dump_cxl_config_space(dev);
1757 1982