raw/ioat: allow perform operations function to return error
[dpdk.git] / drivers / net / cxgbe / base / t4vf_hw.c
index 8e48588..561d759 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.
  */
 
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_ether.h>
 
 #include "common.h"
@@ -44,7 +44,7 @@ static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
                         u32 mbox_addr)
 {
        for ( ; nflit; nflit--, mbox_addr += 8)
-               *rpl++ = htobe64(t4_read_reg64(adap, mbox_addr));
+               *rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
 }
 
 /**
@@ -509,6 +509,77 @@ unsigned int t4vf_get_pf_from_vf(struct adapter *adapter)
                        G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami));
 }
 
+/**
+ * t4vf_get_rss_glb_config - retrieve adapter RSS Global Configuration
+ * @adapter: the adapter
+ *
+ * Retrieves global RSS mode and parameters with which we have to live
+ * and stores them in the @adapter's RSS parameters.
+ */
+int t4vf_get_rss_glb_config(struct adapter *adapter)
+{
+       struct rss_params *rss = &adapter->params.rss;
+       struct fw_rss_glb_config_cmd cmd, rpl;
+       int v;
+
+       /*
+        * Execute an RSS Global Configuration read command to retrieve
+        * our RSS configuration.
+        */
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
+                                     F_FW_CMD_REQUEST |
+                                     F_FW_CMD_READ);
+       cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
+       v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
+       if (v != FW_SUCCESS)
+               return v;
+
+       /*
+        * Translate the big-endian RSS Global Configuration into our
+        * cpu-endian format based on the RSS mode.  We also do first level
+        * filtering at this point to weed out modes which don't support
+        * VF Drivers ...
+        */
+       rss->mode = G_FW_RSS_GLB_CONFIG_CMD_MODE
+                       (be32_to_cpu(rpl.u.manual.mode_pkd));
+       switch (rss->mode) {
+       case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
+               u32 word = be32_to_cpu
+                               (rpl.u.basicvirtual.synmapen_to_hashtoeplitz);
+
+               rss->u.basicvirtual.synmapen =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_SYNMAPEN) != 0);
+               rss->u.basicvirtual.syn4tupenipv6 =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV6) != 0);
+               rss->u.basicvirtual.syn2tupenipv6 =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV6) != 0);
+               rss->u.basicvirtual.syn4tupenipv4 =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV4) != 0);
+               rss->u.basicvirtual.syn2tupenipv4 =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV4) != 0);
+               rss->u.basicvirtual.ofdmapen =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_OFDMAPEN) != 0);
+               rss->u.basicvirtual.tnlmapen =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_TNLMAPEN) != 0);
+               rss->u.basicvirtual.tnlalllookup =
+                       ((word  & F_FW_RSS_GLB_CONFIG_CMD_TNLALLLKP) != 0);
+               rss->u.basicvirtual.hashtoeplitz =
+                       ((word & F_FW_RSS_GLB_CONFIG_CMD_HASHTOEPLITZ) != 0);
+
+               /* we need at least Tunnel Map Enable to be set */
+               if (!rss->u.basicvirtual.tnlmapen)
+                       return -EINVAL;
+               break;
+       }
+
+       default:
+               /* all unknown/unsupported RSS modes result in an error */
+               return -EINVAL;
+       }
+       return 0;
+}
+
 /**
  * t4vf_get_vfres - retrieve VF resource limits
  * @adapter: the adapter
@@ -559,6 +630,117 @@ int t4vf_get_vfres(struct adapter *adapter)
        return 0;
 }
 
+/**
+ * t4vf_get_port_stats_fw - collect "port" statistics via Firmware
+ * @adapter: the adapter
+ * @pidx: the port index
+ * @s: the stats structure to fill
+ *
+ * Collect statistics for the "port"'s Virtual Interface via Firmware
+ * commands.
+ */
+static int t4vf_get_port_stats_fw(struct adapter *adapter, int pidx,
+                                 struct port_stats *p)
+{
+       struct port_info *pi = adap2pinfo(adapter, pidx);
+       unsigned int rem = VI_VF_NUM_STATS;
+       struct fw_vi_stats_vf fwstats;
+       __be64 *fwsp = (__be64 *)&fwstats;
+
+       /*
+        * Grab the Virtual Interface statistics a chunk at a time via mailbox
+        * commands.  We could use a Work Request and get all of them at once
+        * but that's an asynchronous interface which is awkward to use.
+        */
+       while (rem) {
+               unsigned int ix = VI_VF_NUM_STATS - rem;
+               unsigned int nstats = min(6U, rem);
+               struct fw_vi_stats_cmd cmd, rpl;
+               size_t len = (offsetof(struct fw_vi_stats_cmd, u) +
+                             sizeof(struct fw_vi_stats_ctl));
+               size_t len16 = DIV_ROUND_UP(len, 16);
+               int ret;
+
+               memset(&cmd, 0, sizeof(cmd));
+               cmd.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_STATS_CMD) |
+                                            V_FW_VI_STATS_CMD_VIID(pi->viid) |
+                                            F_FW_CMD_REQUEST |
+                                            F_FW_CMD_READ);
+               cmd.retval_len16 = cpu_to_be32(V_FW_CMD_LEN16(len16));
+               cmd.u.ctl.nstats_ix =
+                       cpu_to_be16(V_FW_VI_STATS_CMD_IX(ix) |
+                                   V_FW_VI_STATS_CMD_NSTATS(nstats));
+               ret = t4vf_wr_mbox_ns(adapter, &cmd, len, &rpl);
+               if (ret != FW_SUCCESS)
+                       return ret;
+
+               memcpy(fwsp, &rpl.u.ctl.stat0, sizeof(__be64) * nstats);
+
+               rem -= nstats;
+               fwsp += nstats;
+       }
+
+       /*
+        * Translate firmware statistics into host native statistics.
+        */
+       p->tx_octets = be64_to_cpu(fwstats.tx_bcast_bytes) +
+                      be64_to_cpu(fwstats.tx_mcast_bytes) +
+                      be64_to_cpu(fwstats.tx_ucast_bytes);
+       p->tx_bcast_frames = be64_to_cpu(fwstats.tx_bcast_frames);
+       p->tx_mcast_frames = be64_to_cpu(fwstats.tx_mcast_frames);
+       p->tx_ucast_frames = be64_to_cpu(fwstats.tx_ucast_frames);
+       p->tx_drop = be64_to_cpu(fwstats.tx_drop_frames);
+
+       p->rx_bcast_frames = be64_to_cpu(fwstats.rx_bcast_frames);
+       p->rx_mcast_frames = be64_to_cpu(fwstats.rx_mcast_frames);
+       p->rx_ucast_frames = be64_to_cpu(fwstats.rx_ucast_frames);
+       p->rx_len_err = be64_to_cpu(fwstats.rx_err_frames);
+
+       return 0;
+}
+
+/**
+ *      t4vf_get_port_stats - collect "port" statistics
+ *      @adapter: the adapter
+ *      @pidx: the port index
+ *      @s: the stats structure to fill
+ *
+ *      Collect statistics for the "port"'s Virtual Interface.
+ */
+void t4vf_get_port_stats(struct adapter *adapter, int pidx,
+                        struct port_stats *p)
+{
+       /*
+        * If this is not the first Virtual Interface for our Virtual
+        * Function, we need to use Firmware commands to retrieve its
+        * MPS statistics.
+        */
+       if (pidx != 0)
+               t4vf_get_port_stats_fw(adapter, pidx, p);
+
+       /*
+        * But for the first VI, we can grab its statistics via the MPS
+        * register mapped into the VF register space.
+        */
+#define GET_STAT(name) \
+       t4_read_reg64(adapter, \
+                       T4VF_MPS_BASE_ADDR + A_MPS_VF_STAT_##name##_L)
+       p->tx_octets = GET_STAT(TX_VF_BCAST_BYTES) +
+                      GET_STAT(TX_VF_MCAST_BYTES) +
+                      GET_STAT(TX_VF_UCAST_BYTES);
+       p->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
+       p->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
+       p->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
+       p->tx_drop = GET_STAT(TX_VF_DROP_FRAMES);
+
+       p->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
+       p->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
+       p->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
+
+       p->rx_len_err = GET_STAT(RX_VF_ERR_FRAMES);
+#undef GET_STAT
+}
+
 static int t4vf_alloc_vi(struct adapter *adapter, int port_id)
 {
        struct fw_vi_cmd cmd, rpl;
@@ -584,35 +766,23 @@ static int t4vf_alloc_vi(struct adapter *adapter, int port_id)
 
 int t4vf_port_init(struct adapter *adapter)
 {
-       unsigned int fw_caps = adapter->params.fw_caps_support;
-       struct fw_port_cmd port_cmd, port_rpl;
+       struct fw_port_cmd port_cmd, port_rpl, rpl;
        struct fw_vi_cmd vi_cmd, vi_rpl;
-       fw_port_cap32_t pcaps, acaps;
+       u32 param, val, pcaps, acaps;
        enum fw_port_type port_type;
        int mdio_addr;
        int ret, i;
 
+       param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) |
+                V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_PORT_CAPS32));
+       val = 1;
+       ret = t4vf_set_params(adapter, 1, &param, &val);
+       if (ret < 0)
+               return ret;
+
        for_each_port(adapter, i) {
                struct port_info *p = adap2pinfo(adapter, i);
-
-               /*
-                * If we haven't yet determined if we're talking to Firmware
-                * which knows the new 32-bit Port Caps, it's time to find
-                * out now.  This will also tell new Firmware to send us Port
-                * Status Updates using the new 32-bit Port Capabilities
-                * version of the Port Information message.
-                */
-               if (fw_caps == FW_CAPS_UNKNOWN) {
-                       u32 param, val;
-
-                       param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) |
-                                V_FW_PARAMS_PARAM_X
-                                        (FW_PARAMS_PARAM_PFVF_PORT_CAPS32));
-                       val = 1;
-                       ret = t4vf_set_params(adapter, 1, &param, &val);
-                       fw_caps = (ret == 0 ? FW_CAPS32 : FW_CAPS16);
-                       adapter->params.fw_caps_support = fw_caps;
-               }
+               u32 lstatus32;
 
                ret = t4vf_alloc_vi(adapter, p->port_id);
                if (ret < 0) {
@@ -648,15 +818,14 @@ int t4vf_port_init(struct adapter *adapter)
                        return 0;
 
                memset(&port_cmd, 0, sizeof(port_cmd));
-               port_cmd.op_to_portid = cpu_to_be32
-                               (V_FW_CMD_OP(FW_PORT_CMD) | F_FW_CMD_REQUEST |
-                               F_FW_CMD_READ |
-                               V_FW_PORT_CMD_PORTID(p->port_id));
-               port_cmd.action_to_len16 = cpu_to_be32
-                               (V_FW_PORT_CMD_ACTION(fw_caps == FW_CAPS16 ?
-                                       FW_PORT_ACTION_GET_PORT_INFO :
-                                       FW_PORT_ACTION_GET_PORT_INFO32) |
-                                       FW_LEN16(port_cmd));
+               port_cmd.op_to_portid =
+                       cpu_to_be32(V_FW_CMD_OP(FW_PORT_CMD) |
+                                   F_FW_CMD_REQUEST | F_FW_CMD_READ |
+                                   V_FW_PORT_CMD_PORTID(p->port_id));
+               val = FW_PORT_ACTION_GET_PORT_INFO32;
+               port_cmd.action_to_len16 =
+                       cpu_to_be32(V_FW_PORT_CMD_ACTION(val) |
+                                   FW_LEN16(port_cmd));
                ret = t4vf_wr_mbox(adapter, &port_cmd, sizeof(port_cmd),
                                   &port_rpl);
                if (ret != FW_SUCCESS)
@@ -665,34 +834,17 @@ int t4vf_port_init(struct adapter *adapter)
                /*
                 * Extract the various fields from the Port Information message.
                 */
-               if (fw_caps == FW_CAPS16) {
-                       u32 lstatus = be32_to_cpu
-                                       (port_rpl.u.info.lstatus_to_modtype);
-
-                       port_type = G_FW_PORT_CMD_PTYPE(lstatus);
-                       mdio_addr = ((lstatus & F_FW_PORT_CMD_MDIOCAP) ?
-                                     (int)G_FW_PORT_CMD_MDIOADDR(lstatus) :
-                                     -1);
-                       pcaps = fwcaps16_to_caps32
-                                       (be16_to_cpu(port_rpl.u.info.pcap));
-                       acaps = fwcaps16_to_caps32
-                                       (be16_to_cpu(port_rpl.u.info.acap));
-               } else {
-                       u32 lstatus32 = be32_to_cpu
-                               (port_rpl.u.info32.lstatus32_to_cbllen32);
-
-                       port_type = G_FW_PORT_CMD_PORTTYPE32(lstatus32);
-                       mdio_addr = ((lstatus32 & F_FW_PORT_CMD_MDIOCAP32) ?
-                                     (int)G_FW_PORT_CMD_MDIOADDR32(lstatus32) :
-                                     -1);
-                       pcaps = be32_to_cpu(port_rpl.u.info32.pcaps32);
-                       acaps = be32_to_cpu(port_rpl.u.info32.acaps32);
-               }
+               rpl = port_rpl;
+               lstatus32 = be32_to_cpu(rpl.u.info32.lstatus32_to_cbllen32);
+
+               port_type = G_FW_PORT_CMD_PORTTYPE32(lstatus32);
+               mdio_addr = (lstatus32 & F_FW_PORT_CMD_MDIOCAP32) ?
+                           (int)G_FW_PORT_CMD_MDIOADDR32(lstatus32) : -1;
+               pcaps = be32_to_cpu(port_rpl.u.info32.pcaps32);
+               acaps = be32_to_cpu(port_rpl.u.info32.acaps32);
 
-               p->port_type = port_type;
-               p->mdio_addr = mdio_addr;
-               p->mod_type = FW_PORT_MOD_TYPE_NA;
-               init_link_config(&p->link_cfg, pcaps, acaps);
+               t4_init_link_config(p, pcaps, acaps, mdio_addr, port_type,
+                                   FW_PORT_MOD_TYPE_NA);
        }
        return 0;
 }