New upstream version 17.08
[deb_dpdk.git] / drivers / net / cxgbe / cxgbe_main.c
index 71c3671..b709fe2 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2014-2016 Chelsio Communications.
+ *   Copyright(c) 2014-2017 Chelsio Communications.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_ethdev_pci.h>
-#include <rte_atomic.h>
 #include <rte_malloc.h>
 #include <rte_random.h>
 #include <rte_dev.h>
@@ -206,9 +205,12 @@ static inline bool is_x_1g_port(const struct link_config *lc)
 
 static inline bool is_x_10g_port(const struct link_config *lc)
 {
-       return ((lc->supported & FW_PORT_CAP_SPEED_10G) != 0 ||
-               (lc->supported & FW_PORT_CAP_SPEED_40G) != 0 ||
-               (lc->supported & FW_PORT_CAP_SPEED_100G) != 0);
+       unsigned int speeds, high_speeds;
+
+       speeds = V_FW_PORT_CAP_SPEED(G_FW_PORT_CAP_SPEED(lc->supported));
+       high_speeds = speeds & ~(FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G);
+
+       return high_speeds != 0;
 }
 
 inline void init_rspq(struct adapter *adap, struct sge_rspq *q,
@@ -298,7 +300,7 @@ void cfg_queues(struct rte_eth_dev *eth_dev)
                for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
                        struct sge_eth_rxq *r = &s->ethrxq[i];
 
-                       init_rspq(adap, &r->rspq, 0, 0, 1024, 64);
+                       init_rspq(adap, &r->rspq, 5, 32, 1024, 64);
                        r->usembufs = 1;
                        r->fl.size = (r->usembufs ? 1024 : 72);
                }
@@ -363,6 +365,17 @@ static int init_rss(struct adapter *adap)
        return 0;
 }
 
+/**
+ * Dump basic information about the adapter.
+ */
+static void print_adapter_info(struct adapter *adap)
+{
+       /**
+        * Hardware/Firmware/etc. Version/Revision IDs.
+        */
+       t4_dump_version_info(adap);
+}
+
 static void print_port_info(struct adapter *adap)
 {
        int i;
@@ -374,13 +387,17 @@ static void print_port_info(struct adapter *adap)
                char *bufp = buf;
 
                if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100M)
-                       bufp += sprintf(bufp, "100/");
+                       bufp += sprintf(bufp, "100M/");
                if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
-                       bufp += sprintf(bufp, "1000/");
+                       bufp += sprintf(bufp, "1G/");
                if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
                        bufp += sprintf(bufp, "10G/");
+               if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_25G)
+                       bufp += sprintf(bufp, "25G/");
                if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
                        bufp += sprintf(bufp, "40G/");
+               if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100G)
+                       bufp += sprintf(bufp, "100G/");
                if (bufp != buf)
                        --bufp;
                sprintf(bufp, "BASE-%s",
@@ -396,6 +413,36 @@ static void print_port_info(struct adapter *adap)
        }
 }
 
+static void configure_pcie_ext_tag(struct adapter *adapter)
+{
+       u16 v;
+       int pos = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
+
+       if (!pos)
+               return;
+
+       if (pos > 0) {
+               t4_os_pci_read_cfg2(adapter, pos + PCI_EXP_DEVCTL, &v);
+               v |= PCI_EXP_DEVCTL_EXT_TAG;
+               t4_os_pci_write_cfg2(adapter, pos + PCI_EXP_DEVCTL, v);
+               if (is_t6(adapter->params.chip)) {
+                       t4_set_reg_field(adapter, A_PCIE_CFG2,
+                                        V_T6_TOTMAXTAG(M_T6_TOTMAXTAG),
+                                        V_T6_TOTMAXTAG(7));
+                       t4_set_reg_field(adapter, A_PCIE_CMD_CFG,
+                                        V_T6_MINTAG(M_T6_MINTAG),
+                                        V_T6_MINTAG(8));
+               } else {
+                       t4_set_reg_field(adapter, A_PCIE_CFG2,
+                                        V_TOTMAXTAG(M_TOTMAXTAG),
+                                        V_TOTMAXTAG(3));
+                       t4_set_reg_field(adapter, A_PCIE_CMD_CFG,
+                                        V_MINTAG(M_MINTAG),
+                                        V_MINTAG(8));
+               }
+       }
+}
+
 /*
  * Tweak configuration based on system architecture, etc.  Most of these have
  * defaults assigned to them by Firmware Configuration Files (if we're using
@@ -427,6 +474,9 @@ static int adap_init0_tweaks(struct adapter *adapter)
                         V_CREDITCNT(M_CREDITCNT) | M_CREDITCNTPACKING,
                         V_CREDITCNT(3) | V_CREDITCNTPACKING(1));
 
+       t4_set_reg_field(adapter, A_SGE_INGRESS_RX_THRESHOLD,
+                        V_THRESHOLD_3(M_THRESHOLD_3), V_THRESHOLD_3(32U));
+
        t4_set_reg_field(adapter, A_SGE_CONTROL2, V_IDMAARBROUNDROBIN(1U),
                         V_IDMAARBROUNDROBIN(1U));
 
@@ -575,7 +625,7 @@ static int adap_init0_config(struct adapter *adapter, int reset)
        /*
         * Return successfully and note that we're operating with parameters
         * not supplied by the driver, rather than from hard-wired
-        * initialization constants burried in the driver.
+        * initialization constants buried in the driver.
         */
        dev_info(adapter,
                 "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n",
@@ -641,18 +691,7 @@ static int adap_init0(struct adapter *adap)
                state = (enum dev_state)((unsigned)state & ~DEV_STATE_INIT);
        }
 
-       t4_get_fw_version(adap, &adap->params.fw_vers);
-       t4_get_tp_version(adap, &adap->params.tp_vers);
-
-       dev_info(adap, "fw: %u.%u.%u.%u, TP: %u.%u.%u.%u\n",
-                G_FW_HDR_FW_VER_MAJOR(adap->params.fw_vers),
-                G_FW_HDR_FW_VER_MINOR(adap->params.fw_vers),
-                G_FW_HDR_FW_VER_MICRO(adap->params.fw_vers),
-                G_FW_HDR_FW_VER_BUILD(adap->params.fw_vers),
-                G_FW_HDR_FW_VER_MAJOR(adap->params.tp_vers),
-                G_FW_HDR_FW_VER_MINOR(adap->params.tp_vers),
-                G_FW_HDR_FW_VER_MICRO(adap->params.tp_vers),
-                G_FW_HDR_FW_VER_BUILD(adap->params.tp_vers));
+       t4_get_version_info(adap);
 
        ret = t4_get_core_clock(adap, &adap->params.vpd);
        if (ret < 0) {
@@ -661,26 +700,6 @@ static int adap_init0(struct adapter *adap)
                goto bye;
        }
 
-       /*
-        * Find out what ports are available to us.  Note that we need to do
-        * this before calling adap_init0_no_config() since it needs nports
-        * and portvec ...
-        */
-       v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
-           V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC);
-       ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
-       if (ret < 0) {
-               dev_err(adap, "%s: failure in t4_queury_params; error = %d\n",
-                       __func__, ret);
-               goto bye;
-       }
-
-       adap->params.nports = hweight32(port_vec);
-       adap->params.portvec = port_vec;
-
-       dev_debug(adap, "%s: adap->params.nports = %u\n", __func__,
-                 adap->params.nports);
-
        /*
         * If the firmware is initialized already (and we're not forcing a
         * master initialization), note that we're living with existing
@@ -705,6 +724,22 @@ static int adap_init0(struct adapter *adap)
                goto bye;
        }
 
+       /* Find out what ports are available to us. */
+       v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
+           V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC);
+       ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
+       if (ret < 0) {
+               dev_err(adap, "%s: failure in t4_query_params; error = %d\n",
+                       __func__, ret);
+               goto bye;
+       }
+
+       adap->params.nports = hweight32(port_vec);
+       adap->params.portvec = port_vec;
+
+       dev_debug(adap, "%s: adap->params.nports = %u\n", __func__,
+                 adap->params.nports);
+
        /*
         * Give the SGE code a chance to pull in anything that it needs ...
         * Note that this must be called after we retrieve our VPD parameters
@@ -793,6 +828,7 @@ static int adap_init0(struct adapter *adap)
        }
        t4_init_sge_params(adap);
        t4_init_tp_params(adap);
+       configure_pcie_ext_tag(adap);
 
        adap->params.drv_memwin = MEMWIN_NIC;
        adap->flags |= FW_OK;
@@ -833,10 +869,10 @@ void t4_os_portmod_changed(const struct adapter *adap, int port_id)
                dev_info(adap, "Port%d: %s port module inserted\n", pi->port_id,
                         mod_str[pi->mod_type]);
        else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
-               dev_info(adap, "Port%d: unsupported optical port module inserted\n",
+               dev_info(adap, "Port%d: unsupported port module inserted\n",
                         pi->port_id);
        else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
-               dev_info(adap, "Port%d: unknown port module inserted, forcing TWINAX\n",
+               dev_info(adap, "Port%d: unknown port module inserted\n",
                         pi->port_id);
        else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
                dev_info(adap, "Port%d: transceiver module error\n",
@@ -996,6 +1032,110 @@ void cxgbe_enable_rx_queues(struct port_info *pi)
                enable_rx(adap, &s->ethrxq[pi->first_qset + i].rspq);
 }
 
+/**
+ * fw_caps_to_speed_caps - translate Firmware Port Caps to Speed Caps.
+ * @port_type: Firmware Port Type
+ * @fw_caps: Firmware Port Capabilities
+ * @speed_caps: Device Info Speed Capabilities
+ *
+ * Translate a Firmware Port Capabilities specification to Device Info
+ * Speed Capabilities.
+ */
+static void fw_caps_to_speed_caps(enum fw_port_type port_type,
+                                 unsigned int fw_caps,
+                                 u32 *speed_caps)
+{
+#define SET_SPEED(__speed_name) \
+       do { \
+               *speed_caps |= ETH_LINK_ ## __speed_name; \
+       } while (0)
+
+#define FW_CAPS_TO_SPEED(__fw_name) \
+       do { \
+               if (fw_caps & FW_PORT_CAP_ ## __fw_name) \
+                       SET_SPEED(__fw_name); \
+       } while (0)
+
+       switch (port_type) {
+       case FW_PORT_TYPE_BT_SGMII:
+       case FW_PORT_TYPE_BT_XFI:
+       case FW_PORT_TYPE_BT_XAUI:
+               FW_CAPS_TO_SPEED(SPEED_100M);
+               FW_CAPS_TO_SPEED(SPEED_1G);
+               FW_CAPS_TO_SPEED(SPEED_10G);
+               break;
+
+       case FW_PORT_TYPE_KX4:
+       case FW_PORT_TYPE_KX:
+       case FW_PORT_TYPE_FIBER_XFI:
+       case FW_PORT_TYPE_FIBER_XAUI:
+       case FW_PORT_TYPE_SFP:
+       case FW_PORT_TYPE_QSFP_10G:
+       case FW_PORT_TYPE_QSA:
+               FW_CAPS_TO_SPEED(SPEED_1G);
+               FW_CAPS_TO_SPEED(SPEED_10G);
+               break;
+
+       case FW_PORT_TYPE_KR:
+               SET_SPEED(SPEED_10G);
+               break;
+
+       case FW_PORT_TYPE_BP_AP:
+       case FW_PORT_TYPE_BP4_AP:
+               SET_SPEED(SPEED_1G);
+               SET_SPEED(SPEED_10G);
+               break;
+
+       case FW_PORT_TYPE_BP40_BA:
+       case FW_PORT_TYPE_QSFP:
+               SET_SPEED(SPEED_40G);
+               break;
+
+       case FW_PORT_TYPE_CR_QSFP:
+       case FW_PORT_TYPE_SFP28:
+       case FW_PORT_TYPE_KR_SFP28:
+               FW_CAPS_TO_SPEED(SPEED_1G);
+               FW_CAPS_TO_SPEED(SPEED_10G);
+               FW_CAPS_TO_SPEED(SPEED_25G);
+               break;
+
+       case FW_PORT_TYPE_CR2_QSFP:
+               SET_SPEED(SPEED_50G);
+               break;
+
+       case FW_PORT_TYPE_KR4_100G:
+       case FW_PORT_TYPE_CR4_QSFP:
+               FW_CAPS_TO_SPEED(SPEED_25G);
+               FW_CAPS_TO_SPEED(SPEED_40G);
+               FW_CAPS_TO_SPEED(SPEED_100G);
+               break;
+
+       default:
+               break;
+       }
+
+#undef FW_CAPS_TO_SPEED
+#undef SET_SPEED
+}
+
+/**
+ * cxgbe_get_speed_caps - Fetch supported speed capabilities
+ * @pi: Underlying port's info
+ * @speed_caps: Device Info speed capabilities
+ *
+ * Fetch supported speed capabilities of the underlying port.
+ */
+void cxgbe_get_speed_caps(struct port_info *pi, u32 *speed_caps)
+{
+       *speed_caps = 0;
+
+       fw_caps_to_speed_caps(pi->port_type, pi->link_cfg.supported,
+                             speed_caps);
+
+       if (!(pi->link_cfg.supported & FW_PORT_CAP_ANEG))
+               *speed_caps |= ETH_LINK_SPEED_FIXED;
+}
+
 /**
  * cxgb_up - enable the adapter
  * @adap: adapter being enabled
@@ -1062,10 +1202,20 @@ void cxgbe_close(struct adapter *adapter)
 int cxgbe_probe(struct adapter *adapter)
 {
        struct port_info *pi;
+       int chip;
        int func, i;
        int err = 0;
+       u32 whoami;
+
+       whoami = t4_read_reg(adapter, A_PL_WHOAMI);
+       chip = t4_get_chip_type(adapter,
+                       CHELSIO_PCI_ID_VER(adapter->pdev->id.device_id));
+       if (chip < 0)
+               return chip;
+
+       func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
+              G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami);
 
-       func = G_SOURCEPF(t4_read_reg(adapter, A_PL_WHOAMI));
        adapter->mbox = func;
        adapter->pf = func;
 
@@ -1182,6 +1332,7 @@ allocate_mac:
 
        cfg_queues(adapter->eth_dev);
 
+       print_adapter_info(adapter);
        print_port_info(adapter);
 
        err = init_rss(adapter);