net/mlx5: add C++ include guard to public header
[dpdk.git] / drivers / net / axgbe / axgbe_ethdev.c
index 7d40c18..951da5c 100644 (file)
@@ -10,6 +10,8 @@
 #include "axgbe_regs.h"
 #include "rte_time.h"
 
+#include "eal_filesystem.h"
+
 static int eth_axgbe_dev_init(struct rte_eth_dev *eth_dev);
 static int  axgbe_dev_configure(struct rte_eth_dev *dev);
 static int  axgbe_dev_start(struct rte_eth_dev *dev);
@@ -171,6 +173,8 @@ static const struct axgbe_xstats axgbe_xstats_strings[] = {
 /* The set of PCI devices this driver supports */
 #define AMD_PCI_VENDOR_ID       0x1022
 #define AMD_PCI_RV_ROOT_COMPLEX_ID     0x15d0
+#define AMD_PCI_YC_ROOT_COMPLEX_ID     0x14b5
+#define AMD_PCI_SNOWY_ROOT_COMPLEX_ID  0x1450
 #define AMD_PCI_AXGBE_DEVICE_V2A 0x1458
 #define AMD_PCI_AXGBE_DEVICE_V2B 0x1459
 
@@ -284,7 +288,7 @@ static int axgbe_phy_reset(struct axgbe_port *pdata)
  * @param handle
  *  Pointer to interrupt handle.
  * @param param
- *  The address of parameter (struct rte_eth_dev *) regsitered before.
+ *  The address of parameter (struct rte_eth_dev *) registered before.
  *
  * @return
  *  void
@@ -2117,28 +2121,27 @@ static void axgbe_default_config(struct axgbe_port *pdata)
        pdata->power_down = 0;
 }
 
-static int
-pci_device_cmp(const struct rte_device *dev, const void *_pci_id)
+/*
+ * Return PCI root complex device id on success else 0
+ */
+static uint16_t
+get_pci_rc_devid(void)
 {
-       const struct rte_pci_device *pdev = RTE_DEV_TO_PCI_CONST(dev);
-       const struct rte_pci_id *pcid = _pci_id;
+       char pci_sysfs[PATH_MAX];
+       const struct rte_pci_addr pci_rc_addr = {0, 0, 0, 0};
+       unsigned long device_id;
 
-       if (pdev->id.vendor_id == AMD_PCI_VENDOR_ID &&
-                       pdev->id.device_id == pcid->device_id)
-               return 0;
-       return 1;
-}
+       snprintf(pci_sysfs, sizeof(pci_sysfs), "%s/" PCI_PRI_FMT "/device",
+                rte_pci_get_sysfs_path(), pci_rc_addr.domain,
+                pci_rc_addr.bus, pci_rc_addr.devid, pci_rc_addr.function);
 
-static bool
-pci_search_device(int device_id)
-{
-       struct rte_bus *pci_bus;
-       struct rte_pci_id dev_id;
+       /* get device id */
+       if (eal_parse_sysfs_value(pci_sysfs, &device_id) < 0) {
+               PMD_INIT_LOG(ERR, "Error in reading PCI sysfs\n");
+               return 0;
+       }
 
-       dev_id.device_id = device_id;
-       pci_bus = rte_bus_find_by_name("pci");
-       return (pci_bus != NULL) &&
-               (pci_bus->find_device(NULL, pci_device_cmp, &dev_id) != NULL);
+       return (uint16_t)device_id;
 }
 
 /*
@@ -2177,17 +2180,6 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
        pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
        pdata->pci_dev = pci_dev;
 
-       /*
-        * Use root complex device ID to differentiate RV AXGBE vs SNOWY AXGBE
-        */
-       if (pci_search_device(AMD_PCI_RV_ROOT_COMPLEX_ID)) {
-               pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF;
-               pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT;
-       } else {
-               pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF;
-               pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT;
-       }
-
        pdata->xgmac_regs =
                (void *)pci_dev->mem_resource[AXGBE_AXGMAC_BAR].addr;
        pdata->xprop_regs = (void *)((uint8_t *)pdata->xgmac_regs
@@ -2202,6 +2194,29 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
        else
                pdata->vdata = &axgbe_v2b;
 
+       /*
+        * Use PCI root complex device ID to identify the CPU
+        */
+       switch (get_pci_rc_devid()) {
+       case AMD_PCI_RV_ROOT_COMPLEX_ID:
+               pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF;
+               pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT;
+               break;
+       case AMD_PCI_YC_ROOT_COMPLEX_ID:
+               pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF;
+               pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT;
+               /* Yellow Carp devices do not need cdr workaround */
+               pdata->vdata->an_cdr_workaround = 0;
+               break;
+       case AMD_PCI_SNOWY_ROOT_COMPLEX_ID:
+               pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF;
+               pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT;
+               break;
+       default:
+               PMD_DRV_LOG(ERR, "No supported devices found\n");
+               return -ENODEV;
+       }
+
        /* Configure the PCS indirect addressing support */
        reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg);
        pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET);