diff options
author | Dave Jiang <dave.jiang@intel.com> | 2014-08-28 16:53:13 -0400 |
---|---|---|
committer | Jon Mason <jdmason@kudzu.us> | 2014-10-17 07:08:50 -0400 |
commit | 1db97f258966878317ece10868eaca99201d5884 (patch) | |
tree | 3e4449c9c4eda5aaeeca60cbf4d0a10875e4cf14 /drivers/ntb | |
parent | b775e85bdb0395077a23bc072c4a62986883e276 (diff) |
ntb: conslidate reading of PPD to move platform detection earlier
To simplify some of the platform detection code. Move the platform detection
to a function to be called earlier.
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
Diffstat (limited to 'drivers/ntb')
-rw-r--r-- | drivers/ntb/ntb_hw.c | 126 |
1 files changed, 98 insertions, 28 deletions
diff --git a/drivers/ntb/ntb_hw.c b/drivers/ntb/ntb_hw.c index 7567452250df..6f1c92182f35 100644 --- a/drivers/ntb/ntb_hw.c +++ b/drivers/ntb/ntb_hw.c | |||
@@ -702,24 +702,8 @@ static void bwd_link_poll(struct work_struct *work) | |||
702 | 702 | ||
703 | static int ntb_xeon_setup(struct ntb_device *ndev) | 703 | static int ntb_xeon_setup(struct ntb_device *ndev) |
704 | { | 704 | { |
705 | int rc; | 705 | switch (ndev->conn_type) { |
706 | u8 val; | ||
707 | |||
708 | ndev->hw_type = SNB_HW; | ||
709 | |||
710 | rc = pci_read_config_byte(ndev->pdev, NTB_PPD_OFFSET, &val); | ||
711 | if (rc) | ||
712 | return rc; | ||
713 | |||
714 | if (val & SNB_PPD_DEV_TYPE) | ||
715 | ndev->dev_type = NTB_DEV_USD; | ||
716 | else | ||
717 | ndev->dev_type = NTB_DEV_DSD; | ||
718 | |||
719 | switch (val & SNB_PPD_CONN_TYPE) { | ||
720 | case NTB_CONN_B2B: | 706 | case NTB_CONN_B2B: |
721 | dev_info(&ndev->pdev->dev, "Conn Type = B2B\n"); | ||
722 | ndev->conn_type = NTB_CONN_B2B; | ||
723 | ndev->reg_ofs.ldb = ndev->reg_base + SNB_PDOORBELL_OFFSET; | 707 | ndev->reg_ofs.ldb = ndev->reg_base + SNB_PDOORBELL_OFFSET; |
724 | ndev->reg_ofs.ldb_mask = ndev->reg_base + SNB_PDBMSK_OFFSET; | 708 | ndev->reg_ofs.ldb_mask = ndev->reg_base + SNB_PDBMSK_OFFSET; |
725 | ndev->reg_ofs.spad_read = ndev->reg_base + SNB_SPAD_OFFSET; | 709 | ndev->reg_ofs.spad_read = ndev->reg_base + SNB_SPAD_OFFSET; |
@@ -835,9 +819,6 @@ static int ntb_xeon_setup(struct ntb_device *ndev) | |||
835 | } | 819 | } |
836 | break; | 820 | break; |
837 | case NTB_CONN_RP: | 821 | case NTB_CONN_RP: |
838 | dev_info(&ndev->pdev->dev, "Conn Type = RP\n"); | ||
839 | ndev->conn_type = NTB_CONN_RP; | ||
840 | |||
841 | if (xeon_errata_workaround) { | 822 | if (xeon_errata_workaround) { |
842 | dev_err(&ndev->pdev->dev, | 823 | dev_err(&ndev->pdev->dev, |
843 | "NTB-RP disabled due to hardware errata. To disregard this warning and potentially lock-up the system, add the parameter 'xeon_errata_workaround=0'.\n"); | 824 | "NTB-RP disabled due to hardware errata. To disregard this warning and potentially lock-up the system, add the parameter 'xeon_errata_workaround=0'.\n"); |
@@ -867,8 +848,6 @@ static int ntb_xeon_setup(struct ntb_device *ndev) | |||
867 | ndev->limits.max_mw = SNB_MAX_MW; | 848 | ndev->limits.max_mw = SNB_MAX_MW; |
868 | break; | 849 | break; |
869 | case NTB_CONN_TRANSPARENT: | 850 | case NTB_CONN_TRANSPARENT: |
870 | dev_info(&ndev->pdev->dev, "Conn Type = TRANSPARENT\n"); | ||
871 | ndev->conn_type = NTB_CONN_TRANSPARENT; | ||
872 | /* Scratch pads need to have exclusive access from the primary | 851 | /* Scratch pads need to have exclusive access from the primary |
873 | * or secondary side. Halve the num spads so that each side can | 852 | * or secondary side. Halve the num spads so that each side can |
874 | * have an equal amount. | 853 | * have an equal amount. |
@@ -890,10 +869,10 @@ static int ntb_xeon_setup(struct ntb_device *ndev) | |||
890 | ndev->limits.max_mw = SNB_MAX_MW; | 869 | ndev->limits.max_mw = SNB_MAX_MW; |
891 | break; | 870 | break; |
892 | default: | 871 | default: |
893 | /* Most likely caused by the remote NTB-RP device not being | 872 | /* |
894 | * configured | 873 | * we should never hit this. the detect function should've |
874 | * take cared of everything. | ||
895 | */ | 875 | */ |
896 | dev_err(&ndev->pdev->dev, "Unknown PPD %x\n", val); | ||
897 | return -EINVAL; | 876 | return -EINVAL; |
898 | } | 877 | } |
899 | 878 | ||
@@ -977,9 +956,6 @@ static int ntb_device_setup(struct ntb_device *ndev) | |||
977 | if (rc) | 956 | if (rc) |
978 | return rc; | 957 | return rc; |
979 | 958 | ||
980 | dev_info(&ndev->pdev->dev, "Device Type = %s\n", | ||
981 | ndev->dev_type == NTB_DEV_USD ? "USD/DSP" : "DSD/USP"); | ||
982 | |||
983 | if (ndev->conn_type == NTB_CONN_B2B) | 959 | if (ndev->conn_type == NTB_CONN_B2B) |
984 | /* Enable Bus Master and Memory Space on the secondary side */ | 960 | /* Enable Bus Master and Memory Space on the secondary side */ |
985 | writew(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, | 961 | writew(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER, |
@@ -1519,6 +1495,96 @@ static void ntb_hw_link_down(struct ntb_device *ndev) | |||
1519 | writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); | 1495 | writel(ntb_cntl, ndev->reg_ofs.lnk_cntl); |
1520 | } | 1496 | } |
1521 | 1497 | ||
1498 | static int ntb_xeon_detect(struct ntb_device *ndev) | ||
1499 | { | ||
1500 | int rc; | ||
1501 | u8 ppd; | ||
1502 | |||
1503 | ndev->hw_type = SNB_HW; | ||
1504 | |||
1505 | rc = pci_read_config_byte(ndev->pdev, NTB_PPD_OFFSET, &ppd); | ||
1506 | if (rc) | ||
1507 | return -EIO; | ||
1508 | |||
1509 | if (ppd & SNB_PPD_DEV_TYPE) | ||
1510 | ndev->dev_type = NTB_DEV_USD; | ||
1511 | else | ||
1512 | ndev->dev_type = NTB_DEV_DSD; | ||
1513 | |||
1514 | switch (ppd & SNB_PPD_CONN_TYPE) { | ||
1515 | case NTB_CONN_B2B: | ||
1516 | dev_info(&ndev->pdev->dev, "Conn Type = B2B\n"); | ||
1517 | ndev->conn_type = NTB_CONN_B2B; | ||
1518 | break; | ||
1519 | case NTB_CONN_RP: | ||
1520 | dev_info(&ndev->pdev->dev, "Conn Type = RP\n"); | ||
1521 | ndev->conn_type = NTB_CONN_RP; | ||
1522 | break; | ||
1523 | case NTB_CONN_TRANSPARENT: | ||
1524 | dev_info(&ndev->pdev->dev, "Conn Type = TRANSPARENT\n"); | ||
1525 | ndev->conn_type = NTB_CONN_TRANSPARENT; | ||
1526 | /* | ||
1527 | * This mode is default to USD/DSP. HW does not report | ||
1528 | * properly in transparent mode as it has no knowledge of | ||
1529 | * NTB. We will just force correct here. | ||
1530 | */ | ||
1531 | ndev->dev_type = NTB_DEV_USD; | ||
1532 | break; | ||
1533 | default: | ||
1534 | dev_err(&ndev->pdev->dev, "Unknown PPD %x\n", ppd); | ||
1535 | return -ENODEV; | ||
1536 | } | ||
1537 | |||
1538 | return 0; | ||
1539 | } | ||
1540 | |||
1541 | static int ntb_atom_detect(struct ntb_device *ndev) | ||
1542 | { | ||
1543 | int rc; | ||
1544 | u32 ppd; | ||
1545 | |||
1546 | ndev->hw_type = BWD_HW; | ||
1547 | |||
1548 | rc = pci_read_config_dword(ndev->pdev, NTB_PPD_OFFSET, &ppd); | ||
1549 | if (rc) | ||
1550 | return rc; | ||
1551 | |||
1552 | switch ((ppd & BWD_PPD_CONN_TYPE) >> 8) { | ||
1553 | case NTB_CONN_B2B: | ||
1554 | dev_info(&ndev->pdev->dev, "Conn Type = B2B\n"); | ||
1555 | ndev->conn_type = NTB_CONN_B2B; | ||
1556 | break; | ||
1557 | case NTB_CONN_RP: | ||
1558 | default: | ||
1559 | dev_err(&ndev->pdev->dev, "Unsupported NTB configuration\n"); | ||
1560 | return -EINVAL; | ||
1561 | } | ||
1562 | |||
1563 | if (ppd & BWD_PPD_DEV_TYPE) | ||
1564 | ndev->dev_type = NTB_DEV_DSD; | ||
1565 | else | ||
1566 | ndev->dev_type = NTB_DEV_USD; | ||
1567 | |||
1568 | return 0; | ||
1569 | } | ||
1570 | |||
1571 | static int ntb_device_detect(struct ntb_device *ndev) | ||
1572 | { | ||
1573 | int rc; | ||
1574 | |||
1575 | if (is_ntb_xeon(ndev)) | ||
1576 | rc = ntb_xeon_detect(ndev); | ||
1577 | else if (is_ntb_atom(ndev)) | ||
1578 | rc = ntb_atom_detect(ndev); | ||
1579 | else | ||
1580 | rc = -ENODEV; | ||
1581 | |||
1582 | dev_info(&ndev->pdev->dev, "Device Type = %s\n", | ||
1583 | ndev->dev_type == NTB_DEV_USD ? "USD/DSP" : "DSD/USP"); | ||
1584 | |||
1585 | return 0; | ||
1586 | } | ||
1587 | |||
1522 | static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) | 1588 | static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
1523 | { | 1589 | { |
1524 | struct ntb_device *ndev; | 1590 | struct ntb_device *ndev; |
@@ -1539,6 +1605,10 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1539 | 1605 | ||
1540 | pci_set_master(ndev->pdev); | 1606 | pci_set_master(ndev->pdev); |
1541 | 1607 | ||
1608 | rc = ntb_device_detect(ndev); | ||
1609 | if (rc) | ||
1610 | goto err; | ||
1611 | |||
1542 | rc = pci_request_selected_regions(pdev, NTB_BAR_MASK, KBUILD_MODNAME); | 1612 | rc = pci_request_selected_regions(pdev, NTB_BAR_MASK, KBUILD_MODNAME); |
1543 | if (rc) | 1613 | if (rc) |
1544 | goto err1; | 1614 | goto err1; |