Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[cascardo/linux.git] / drivers / net / ethernet / chelsio / cxgb4 / t4_hw.c
index 9f1b304..67345c7 100644 (file)
@@ -188,9 +188,9 @@ static void t4_report_fw_error(struct adapter *adap)
        u32 pcie_fw;
 
        pcie_fw = t4_read_reg(adap, MA_PCIE_FW);
-       if (pcie_fw & FW_PCIE_FW_ERR)
+       if (pcie_fw & PCIE_FW_ERR)
                dev_err(adap->pdev_dev, "Firmware reports adapter error: %s\n",
-                       reason[FW_PCIE_FW_EVAL_GET(pcie_fw)]);
+                       reason[PCIE_FW_EVAL_G(pcie_fw)]);
 }
 
 /*
@@ -993,10 +993,10 @@ static int should_install_fs_fw(struct adapter *adap, int card_fw_usable,
 install:
        dev_err(adap->pdev_dev, "firmware on card (%u.%u.%u.%u) is %s, "
                "installing firmware %u.%u.%u.%u on card.\n",
-               FW_HDR_FW_VER_MAJOR_GET(c), FW_HDR_FW_VER_MINOR_GET(c),
-               FW_HDR_FW_VER_MICRO_GET(c), FW_HDR_FW_VER_BUILD_GET(c), reason,
-               FW_HDR_FW_VER_MAJOR_GET(k), FW_HDR_FW_VER_MINOR_GET(k),
-               FW_HDR_FW_VER_MICRO_GET(k), FW_HDR_FW_VER_BUILD_GET(k));
+               FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
+               FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c), reason,
+               FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
+               FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
 
        return 1;
 }
@@ -1068,12 +1068,12 @@ int t4_prep_fw(struct adapter *adap, struct fw_info *fw_info,
                        "driver compiled with %d.%d.%d.%d, "
                        "card has %d.%d.%d.%d, filesystem has %d.%d.%d.%d\n",
                        state,
-                       FW_HDR_FW_VER_MAJOR_GET(d), FW_HDR_FW_VER_MINOR_GET(d),
-                       FW_HDR_FW_VER_MICRO_GET(d), FW_HDR_FW_VER_BUILD_GET(d),
-                       FW_HDR_FW_VER_MAJOR_GET(c), FW_HDR_FW_VER_MINOR_GET(c),
-                       FW_HDR_FW_VER_MICRO_GET(c), FW_HDR_FW_VER_BUILD_GET(c),
-                       FW_HDR_FW_VER_MAJOR_GET(k), FW_HDR_FW_VER_MINOR_GET(k),
-                       FW_HDR_FW_VER_MICRO_GET(k), FW_HDR_FW_VER_BUILD_GET(k));
+                       FW_HDR_FW_VER_MAJOR_G(d), FW_HDR_FW_VER_MINOR_G(d),
+                       FW_HDR_FW_VER_MICRO_G(d), FW_HDR_FW_VER_BUILD_G(d),
+                       FW_HDR_FW_VER_MAJOR_G(c), FW_HDR_FW_VER_MINOR_G(c),
+                       FW_HDR_FW_VER_MICRO_G(c), FW_HDR_FW_VER_BUILD_G(c),
+                       FW_HDR_FW_VER_MAJOR_G(k), FW_HDR_FW_VER_MINOR_G(k),
+                       FW_HDR_FW_VER_MICRO_G(k), FW_HDR_FW_VER_BUILD_G(k));
                ret = EINVAL;
                goto bye;
        }
@@ -1132,6 +1132,27 @@ unsigned int t4_flash_cfg_addr(struct adapter *adapter)
                return FLASH_CFG_START;
 }
 
+/* Return TRUE if the specified firmware matches the adapter.  I.e. T4
+ * firmware for T4 adapters, T5 firmware for T5 adapters, etc.  We go ahead
+ * and emit an error message for mismatched firmware to save our caller the
+ * effort ...
+ */
+static bool t4_fw_matches_chip(const struct adapter *adap,
+                              const struct fw_hdr *hdr)
+{
+       /* The expression below will return FALSE for any unsupported adapter
+        * which will keep us "honest" in the future ...
+        */
+       if ((is_t4(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T4) ||
+           (is_t5(adap->params.chip) && hdr->chip == FW_HDR_CHIP_T5))
+               return true;
+
+       dev_err(adap->pdev_dev,
+               "FW image (%d) is not suitable for this adapter (%d)\n",
+               hdr->chip, CHELSIO_CHIP_VERSION(adap->params.chip));
+       return false;
+}
+
 /**
  *     t4_load_fw - download firmware
  *     @adap: the adapter
@@ -1171,6 +1192,8 @@ int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
                        FW_MAX_SIZE);
                return -EFBIG;
        }
+       if (!t4_fw_matches_chip(adap, hdr))
+               return -EINVAL;
 
        for (csum = 0, i = 0; i < size / sizeof(csum); i++)
                csum += ntohl(p[i]);
@@ -1213,6 +1236,8 @@ out:
        if (ret)
                dev_err(adap->pdev_dev, "firmware download failed, error %d\n",
                        ret);
+       else
+               ret = t4_get_fw_version(adap, &adap->params.fw_vers);
        return ret;
 }
 
@@ -1237,7 +1262,7 @@ int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
                  struct link_config *lc)
 {
        struct fw_port_cmd c;
-       unsigned int fc = 0, mdi = FW_PORT_MDI(FW_PORT_MDI_AUTO);
+       unsigned int fc = 0, mdi = FW_PORT_CAP_MDI_V(FW_PORT_CAP_MDI_AUTO);
 
        lc->link_ok = 0;
        if (lc->requested_fc & PAUSE_RX)
@@ -1247,8 +1272,8 @@ int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
 
        memset(&c, 0, sizeof(c));
        c.op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) | FW_CMD_REQUEST_F |
-                              FW_CMD_EXEC_F | FW_PORT_CMD_PORTID(port));
-       c.action_to_len16 = htonl(FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
+                              FW_CMD_EXEC_F | FW_PORT_CMD_PORTID_V(port));
+       c.action_to_len16 = htonl(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
                                  FW_LEN16(c));
 
        if (!(lc->supported & FW_PORT_CAP_ANEG)) {
@@ -1277,8 +1302,8 @@ int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
 
        memset(&c, 0, sizeof(c));
        c.op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) | FW_CMD_REQUEST_F |
-                              FW_CMD_EXEC_F | FW_PORT_CMD_PORTID(port));
-       c.action_to_len16 = htonl(FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
+                              FW_CMD_EXEC_F | FW_PORT_CMD_PORTID_V(port));
+       c.action_to_len16 = htonl(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_L1_CFG) |
                                  FW_LEN16(c));
        c.u.l1cfg.rcap = htonl(FW_PORT_CAP_ANEG);
        return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
@@ -1564,7 +1589,7 @@ static void cim_intr_handler(struct adapter *adapter)
 
        int fat;
 
-       if (t4_read_reg(adapter, MA_PCIE_FW) & FW_PCIE_FW_ERR)
+       if (t4_read_reg(adapter, MA_PCIE_FW) & PCIE_FW_ERR)
                t4_report_fw_error(adapter);
 
        fat = t4_handle_intr_status(adapter, CIM_HOST_INT_CAUSE,
@@ -2074,7 +2099,7 @@ int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
        memset(&cmd, 0, sizeof(cmd));
        cmd.op_to_viid = htonl(FW_CMD_OP_V(FW_RSS_IND_TBL_CMD) |
                               FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
-                              FW_RSS_IND_TBL_CMD_VIID(viid));
+                              FW_RSS_IND_TBL_CMD_VIID_V(viid));
        cmd.retval_len16 = htonl(FW_LEN16(cmd));
 
        /* each fw_rss_ind_tbl_cmd takes up to 32 entries */
@@ -2091,13 +2116,13 @@ int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
                while (nq > 0) {
                        unsigned int v;
 
-                       v = FW_RSS_IND_TBL_CMD_IQ0(*rsp);
+                       v = FW_RSS_IND_TBL_CMD_IQ0_V(*rsp);
                        if (++rsp >= rsp_end)
                                rsp = rspq;
-                       v |= FW_RSS_IND_TBL_CMD_IQ1(*rsp);
+                       v |= FW_RSS_IND_TBL_CMD_IQ1_V(*rsp);
                        if (++rsp >= rsp_end)
                                rsp = rspq;
-                       v |= FW_RSS_IND_TBL_CMD_IQ2(*rsp);
+                       v |= FW_RSS_IND_TBL_CMD_IQ2_V(*rsp);
                        if (++rsp >= rsp_end)
                                rsp = rspq;
 
@@ -2131,10 +2156,10 @@ int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
                              FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
        c.retval_len16 = htonl(FW_LEN16(c));
        if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
-               c.u.manual.mode_pkd = htonl(FW_RSS_GLB_CONFIG_CMD_MODE(mode));
+               c.u.manual.mode_pkd = htonl(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
        } else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
                c.u.basicvirtual.mode_pkd =
-                       htonl(FW_RSS_GLB_CONFIG_CMD_MODE(mode));
+                       htonl(FW_RSS_GLB_CONFIG_CMD_MODE_V(mode));
                c.u.basicvirtual.synmapen_to_hashtoeplitz = htonl(flags);
        } else
                return -EINVAL;
@@ -2793,7 +2818,7 @@ retry:
        if (ret < 0) {
                if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
                        goto retry;
-               if (t4_read_reg(adap, MA_PCIE_FW) & FW_PCIE_FW_ERR)
+               if (t4_read_reg(adap, MA_PCIE_FW) & PCIE_FW_ERR)
                        t4_report_fw_error(adap);
                return ret;
        }
@@ -2818,7 +2843,7 @@ retry:
         * and we wouldn't want to fail pointlessly.  (This can happen when an
         * OS loads lots of different drivers rapidly at the same time).  In
         * this case, the Master PF returned by the firmware will be
-        * FW_PCIE_FW_MASTER_MASK so the test below will work ...
+        * PCIE_FW_MASTER_M so the test below will work ...
         */
        if ((v & (FW_HELLO_CMD_ERR_F|FW_HELLO_CMD_INIT_F)) == 0 &&
            master_mbox != mbox) {
@@ -2844,7 +2869,7 @@ retry:
                         * our retries ...
                         */
                        pcie_fw = t4_read_reg(adap, MA_PCIE_FW);
-                       if (!(pcie_fw & (FW_PCIE_FW_ERR|FW_PCIE_FW_INIT))) {
+                       if (!(pcie_fw & (PCIE_FW_ERR|PCIE_FW_INIT))) {
                                if (waiting <= 0) {
                                        if (retries-- > 0)
                                                goto retry;
@@ -2859,9 +2884,9 @@ retry:
                         * report errors preferentially.
                         */
                        if (state) {
-                               if (pcie_fw & FW_PCIE_FW_ERR)
+                               if (pcie_fw & PCIE_FW_ERR)
                                        *state = DEV_STATE_ERR;
-                               else if (pcie_fw & FW_PCIE_FW_INIT)
+                               else if (pcie_fw & PCIE_FW_INIT)
                                        *state = DEV_STATE_INIT;
                        }
 
@@ -2870,9 +2895,9 @@ retry:
                         * there's not a valid Master PF, grab its identity
                         * for our caller.
                         */
-                       if (master_mbox == FW_PCIE_FW_MASTER_MASK &&
-                           (pcie_fw & FW_PCIE_FW_MASTER_VLD))
-                               master_mbox = FW_PCIE_FW_MASTER_GET(pcie_fw);
+                       if (master_mbox == PCIE_FW_MASTER_M &&
+                           (pcie_fw & PCIE_FW_MASTER_VLD))
+                               master_mbox = PCIE_FW_MASTER_G(pcie_fw);
                        break;
                }
        }
@@ -2940,7 +2965,7 @@ int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
  *     Issues a RESET command to firmware (if desired) with a HALT indication
  *     and then puts the microprocessor into RESET state.  The RESET command
  *     will only be issued if a legitimate mailbox is provided (mbox <=
- *     FW_PCIE_FW_MASTER_MASK).
+ *     PCIE_FW_MASTER_M).
  *
  *     This is generally used in order for the host to safely manipulate the
  *     adapter without fear of conflicting with whatever the firmware might
@@ -2955,7 +2980,7 @@ static int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
         * If a legitimate mailbox is provided, issue a RESET command
         * with a HALT indication.
         */
-       if (mbox <= FW_PCIE_FW_MASTER_MASK) {
+       if (mbox <= PCIE_FW_MASTER_M) {
                struct fw_reset_cmd c;
 
                memset(&c, 0, sizeof(c));
@@ -2980,8 +3005,8 @@ static int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
         */
        if (ret == 0 || force) {
                t4_set_reg_field(adap, CIM_BOOT_CFG, UPCRST, UPCRST);
-               t4_set_reg_field(adap, PCIE_FW, FW_PCIE_FW_HALT,
-                                FW_PCIE_FW_HALT);
+               t4_set_reg_field(adap, PCIE_FW, PCIE_FW_HALT_F,
+                                PCIE_FW_HALT_F);
        }
 
        /*
@@ -3020,7 +3045,7 @@ static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
                 * doing it automatically, we need to clear the PCIE_FW.HALT
                 * bit.
                 */
-               t4_set_reg_field(adap, PCIE_FW, FW_PCIE_FW_HALT, 0);
+               t4_set_reg_field(adap, PCIE_FW, PCIE_FW_HALT_F, 0);
 
                /*
                 * If we've been given a valid mailbox, first try to get the
@@ -3029,7 +3054,7 @@ static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
                 * valid mailbox or the RESET command failed, fall back to
                 * hitting the chip with a hammer.
                 */
-               if (mbox <= FW_PCIE_FW_MASTER_MASK) {
+               if (mbox <= PCIE_FW_MASTER_M) {
                        t4_set_reg_field(adap, CIM_BOOT_CFG, UPCRST, 0);
                        msleep(100);
                        if (t4_fw_reset(adap, mbox,
@@ -3044,7 +3069,7 @@ static int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset)
 
                t4_set_reg_field(adap, CIM_BOOT_CFG, UPCRST, 0);
                for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
-                       if (!(t4_read_reg(adap, PCIE_FW) & FW_PCIE_FW_HALT))
+                       if (!(t4_read_reg(adap, PCIE_FW) & PCIE_FW_HALT_F))
                                return 0;
                        msleep(100);
                        ms += 100;
@@ -3081,6 +3106,9 @@ int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
        const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
        int reset, ret;
 
+       if (!t4_fw_matches_chip(adap, fw_hdr))
+               return -EINVAL;
+
        ret = t4_fw_halt(adap, mbox, force);
        if (ret < 0 && !force)
                return ret;
@@ -3415,9 +3443,9 @@ int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
        memset(&c, 0, sizeof(c));
        c.op_to_vfn = htonl(FW_CMD_OP_V(FW_VI_CMD) | FW_CMD_REQUEST_F |
                            FW_CMD_WRITE_F | FW_CMD_EXEC_F |
-                           FW_VI_CMD_PFN(pf) | FW_VI_CMD_VFN(vf));
-       c.alloc_to_len16 = htonl(FW_VI_CMD_ALLOC | FW_LEN16(c));
-       c.portid_pkd = FW_VI_CMD_PORTID(port);
+                           FW_VI_CMD_PFN_V(pf) | FW_VI_CMD_VFN_V(vf));
+       c.alloc_to_len16 = htonl(FW_VI_CMD_ALLOC_F | FW_LEN16(c));
+       c.portid_pkd = FW_VI_CMD_PORTID_V(port);
        c.nmac = nmac - 1;
 
        ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
@@ -3438,8 +3466,8 @@ int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
                }
        }
        if (rss_size)
-               *rss_size = FW_VI_CMD_RSSSIZE_GET(ntohs(c.rsssize_pkd));
-       return FW_VI_CMD_VIID_GET(ntohs(c.type_viid));
+               *rss_size = FW_VI_CMD_RSSSIZE_G(ntohs(c.rsssize_pkd));
+       return FW_VI_CMD_VIID_G(ntohs(c.type_viid));
 }
 
 /**
@@ -3466,23 +3494,23 @@ int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
        if (mtu < 0)
                mtu = FW_RXMODE_MTU_NO_CHG;
        if (promisc < 0)
-               promisc = FW_VI_RXMODE_CMD_PROMISCEN_MASK;
+               promisc = FW_VI_RXMODE_CMD_PROMISCEN_M;
        if (all_multi < 0)
-               all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_MASK;
+               all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_M;
        if (bcast < 0)
-               bcast = FW_VI_RXMODE_CMD_BROADCASTEN_MASK;
+               bcast = FW_VI_RXMODE_CMD_BROADCASTEN_M;
        if (vlanex < 0)
-               vlanex = FW_VI_RXMODE_CMD_VLANEXEN_MASK;
+               vlanex = FW_VI_RXMODE_CMD_VLANEXEN_M;
 
        memset(&c, 0, sizeof(c));
        c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_RXMODE_CMD) | FW_CMD_REQUEST_F |
-                            FW_CMD_WRITE_F | FW_VI_RXMODE_CMD_VIID(viid));
+                            FW_CMD_WRITE_F | FW_VI_RXMODE_CMD_VIID_V(viid));
        c.retval_len16 = htonl(FW_LEN16(c));
-       c.mtu_to_vlanexen = htonl(FW_VI_RXMODE_CMD_MTU(mtu) |
-                                 FW_VI_RXMODE_CMD_PROMISCEN(promisc) |
-                                 FW_VI_RXMODE_CMD_ALLMULTIEN(all_multi) |
-                                 FW_VI_RXMODE_CMD_BROADCASTEN(bcast) |
-                                 FW_VI_RXMODE_CMD_VLANEXEN(vlanex));
+       c.mtu_to_vlanexen = htonl(FW_VI_RXMODE_CMD_MTU_V(mtu) |
+                                 FW_VI_RXMODE_CMD_PROMISCEN_V(promisc) |
+                                 FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
+                                 FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
+                                 FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
        return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
 }
 
@@ -3525,13 +3553,13 @@ int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
        memset(&c, 0, sizeof(c));
        c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_MAC_CMD) | FW_CMD_REQUEST_F |
                             FW_CMD_WRITE_F | (free ? FW_CMD_EXEC_F : 0) |
-                            FW_VI_MAC_CMD_VIID(viid));
-       c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_FREEMACS(free) |
+                            FW_VI_MAC_CMD_VIID_V(viid));
+       c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_FREEMACS_V(free) |
                                    FW_CMD_LEN16_V((naddr + 2) / 2));
 
        for (i = 0, p = c.u.exact; i < naddr; i++, p++) {
-               p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID |
-                                     FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
+               p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID_F |
+                                     FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_ADD_MAC));
                memcpy(p->macaddr, addr[i], sizeof(p->macaddr));
        }
 
@@ -3540,7 +3568,7 @@ int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
                return ret;
 
        for (i = 0, p = c.u.exact; i < naddr; i++, p++) {
-               u16 index = FW_VI_MAC_CMD_IDX_GET(ntohs(p->valid_to_idx));
+               u16 index = FW_VI_MAC_CMD_IDX_G(ntohs(p->valid_to_idx));
 
                if (idx)
                        idx[i] = index >= max_naddr ? 0xffff : index;
@@ -3587,16 +3615,16 @@ int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
 
        memset(&c, 0, sizeof(c));
        c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_MAC_CMD) | FW_CMD_REQUEST_F |
-                            FW_CMD_WRITE_F | FW_VI_MAC_CMD_VIID(viid));
+                            FW_CMD_WRITE_F | FW_VI_MAC_CMD_VIID_V(viid));
        c.freemacs_to_len16 = htonl(FW_CMD_LEN16_V(1));
-       p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID |
-                               FW_VI_MAC_CMD_SMAC_RESULT(mode) |
-                               FW_VI_MAC_CMD_IDX(idx));
+       p->valid_to_idx = htons(FW_VI_MAC_CMD_VALID_F |
+                               FW_VI_MAC_CMD_SMAC_RESULT_V(mode) |
+                               FW_VI_MAC_CMD_IDX_V(idx));
        memcpy(p->macaddr, addr, sizeof(p->macaddr));
 
        ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
        if (ret == 0) {
-               ret = FW_VI_MAC_CMD_IDX_GET(ntohs(p->valid_to_idx));
+               ret = FW_VI_MAC_CMD_IDX_G(ntohs(p->valid_to_idx));
                if (ret >= max_mac_addr)
                        ret = -ENOMEM;
        }
@@ -3621,9 +3649,9 @@ int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
 
        memset(&c, 0, sizeof(c));
        c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_MAC_CMD) | FW_CMD_REQUEST_F |
-                            FW_CMD_WRITE_F | FW_VI_ENABLE_CMD_VIID(viid));
-       c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_HASHVECEN |
-                                   FW_VI_MAC_CMD_HASHUNIEN(ucast) |
+                            FW_CMD_WRITE_F | FW_VI_ENABLE_CMD_VIID_V(viid));
+       c.freemacs_to_len16 = htonl(FW_VI_MAC_CMD_HASHVECEN_F |
+                                   FW_VI_MAC_CMD_HASHUNIEN_V(ucast) |
                                    FW_CMD_LEN16_V(1));
        c.u.hash.hashvec = cpu_to_be64(vec);
        return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
@@ -3648,11 +3676,11 @@ int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
 
        memset(&c, 0, sizeof(c));
        c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_ENABLE_CMD) | FW_CMD_REQUEST_F |
-                            FW_CMD_EXEC_F | FW_VI_ENABLE_CMD_VIID(viid));
+                            FW_CMD_EXEC_F | FW_VI_ENABLE_CMD_VIID_V(viid));
 
-       c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_IEN(rx_en) |
-                              FW_VI_ENABLE_CMD_EEN(tx_en) | FW_LEN16(c) |
-                              FW_VI_ENABLE_CMD_DCB_INFO(dcb_en));
+       c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_IEN_V(rx_en) |
+                              FW_VI_ENABLE_CMD_EEN_V(tx_en) | FW_LEN16(c) |
+                              FW_VI_ENABLE_CMD_DCB_INFO_V(dcb_en));
        return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
 }
 
@@ -3688,8 +3716,8 @@ int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
 
        memset(&c, 0, sizeof(c));
        c.op_to_viid = htonl(FW_CMD_OP_V(FW_VI_ENABLE_CMD) | FW_CMD_REQUEST_F |
-                            FW_CMD_EXEC_F | FW_VI_ENABLE_CMD_VIID(viid));
-       c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_LED | FW_LEN16(c));
+                            FW_CMD_EXEC_F | FW_VI_ENABLE_CMD_VIID_V(viid));
+       c.ien_to_len16 = htonl(FW_VI_ENABLE_CMD_LED_F | FW_LEN16(c));
        c.blinkdur = htons(nblinks);
        return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
 }
@@ -3715,10 +3743,10 @@ int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
 
        memset(&c, 0, sizeof(c));
        c.op_to_vfn = htonl(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F |
-                           FW_CMD_EXEC_F | FW_IQ_CMD_PFN(pf) |
-                           FW_IQ_CMD_VFN(vf));
-       c.alloc_to_len16 = htonl(FW_IQ_CMD_FREE | FW_LEN16(c));
-       c.type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE(iqtype));
+                           FW_CMD_EXEC_F | FW_IQ_CMD_PFN_V(pf) |
+                           FW_IQ_CMD_VFN_V(vf));
+       c.alloc_to_len16 = htonl(FW_IQ_CMD_FREE_F | FW_LEN16(c));
+       c.type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE_V(iqtype));
        c.iqid = htons(iqid);
        c.fl0id = htons(fl0id);
        c.fl1id = htons(fl1id);
@@ -3742,10 +3770,10 @@ int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
 
        memset(&c, 0, sizeof(c));
        c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_ETH_CMD) | FW_CMD_REQUEST_F |
-                           FW_CMD_EXEC_F | FW_EQ_ETH_CMD_PFN(pf) |
-                           FW_EQ_ETH_CMD_VFN(vf));
-       c.alloc_to_len16 = htonl(FW_EQ_ETH_CMD_FREE | FW_LEN16(c));
-       c.eqid_pkd = htonl(FW_EQ_ETH_CMD_EQID(eqid));
+                           FW_CMD_EXEC_F | FW_EQ_ETH_CMD_PFN_V(pf) |
+                           FW_EQ_ETH_CMD_VFN_V(vf));
+       c.alloc_to_len16 = htonl(FW_EQ_ETH_CMD_FREE_F | FW_LEN16(c));
+       c.eqid_pkd = htonl(FW_EQ_ETH_CMD_EQID_V(eqid));
        return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
 }
 
@@ -3766,10 +3794,10 @@ int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
 
        memset(&c, 0, sizeof(c));
        c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_CTRL_CMD) | FW_CMD_REQUEST_F |
-                           FW_CMD_EXEC_F | FW_EQ_CTRL_CMD_PFN(pf) |
-                           FW_EQ_CTRL_CMD_VFN(vf));
-       c.alloc_to_len16 = htonl(FW_EQ_CTRL_CMD_FREE | FW_LEN16(c));
-       c.cmpliqid_eqid = htonl(FW_EQ_CTRL_CMD_EQID(eqid));
+                           FW_CMD_EXEC_F | FW_EQ_CTRL_CMD_PFN_V(pf) |
+                           FW_EQ_CTRL_CMD_VFN_V(vf));
+       c.alloc_to_len16 = htonl(FW_EQ_CTRL_CMD_FREE_F | FW_LEN16(c));
+       c.cmpliqid_eqid = htonl(FW_EQ_CTRL_CMD_EQID_V(eqid));
        return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
 }
 
@@ -3790,10 +3818,10 @@ int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
 
        memset(&c, 0, sizeof(c));
        c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_OFLD_CMD) | FW_CMD_REQUEST_F |
-                           FW_CMD_EXEC_F | FW_EQ_OFLD_CMD_PFN(pf) |
-                           FW_EQ_OFLD_CMD_VFN(vf));
-       c.alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_FREE | FW_LEN16(c));
-       c.eqid_pkd = htonl(FW_EQ_OFLD_CMD_EQID(eqid));
+                           FW_CMD_EXEC_F | FW_EQ_OFLD_CMD_PFN_V(pf) |
+                           FW_EQ_OFLD_CMD_VFN_V(vf));
+       c.alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_FREE_F | FW_LEN16(c));
+       c.eqid_pkd = htonl(FW_EQ_OFLD_CMD_EQID_V(eqid));
        return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
 }
 
@@ -3811,25 +3839,25 @@ int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
        if (opcode == FW_PORT_CMD) {    /* link/module state change message */
                int speed = 0, fc = 0;
                const struct fw_port_cmd *p = (void *)rpl;
-               int chan = FW_PORT_CMD_PORTID_GET(ntohl(p->op_to_portid));
+               int chan = FW_PORT_CMD_PORTID_G(ntohl(p->op_to_portid));
                int port = adap->chan_map[chan];
                struct port_info *pi = adap2pinfo(adap, port);
                struct link_config *lc = &pi->link_cfg;
                u32 stat = ntohl(p->u.info.lstatus_to_modtype);
-               int link_ok = (stat & FW_PORT_CMD_LSTATUS) != 0;
-               u32 mod = FW_PORT_CMD_MODTYPE_GET(stat);
+               int link_ok = (stat & FW_PORT_CMD_LSTATUS_F) != 0;
+               u32 mod = FW_PORT_CMD_MODTYPE_G(stat);
 
-               if (stat & FW_PORT_CMD_RXPAUSE)
+               if (stat & FW_PORT_CMD_RXPAUSE_F)
                        fc |= PAUSE_RX;
-               if (stat & FW_PORT_CMD_TXPAUSE)
+               if (stat & FW_PORT_CMD_TXPAUSE_F)
                        fc |= PAUSE_TX;
-               if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100M))
+               if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
                        speed = 100;
-               else if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_1G))
+               else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
                        speed = 1000;
-               else if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_10G))
+               else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
                        speed = 10000;
-               else if (stat & FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_40G))
+               else if (stat & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
                        speed = 40000;
 
                if (link_ok != lc->link_ok || speed != lc->speed ||
@@ -4002,6 +4030,126 @@ int t4_prep_adapter(struct adapter *adapter)
        return 0;
 }
 
+/**
+ *     t4_bar2_sge_qregs - return BAR2 SGE Queue register information
+ *     @adapter: the adapter
+ *     @qid: the Queue ID
+ *     @qtype: the Ingress or Egress type for @qid
+ *     @pbar2_qoffset: BAR2 Queue Offset
+ *     @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
+ *
+ *     Returns the BAR2 SGE Queue Registers information associated with the
+ *     indicated Absolute Queue ID.  These are passed back in return value
+ *     pointers.  @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
+ *     and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
+ *
+ *     This may return an error which indicates that BAR2 SGE Queue
+ *     registers aren't available.  If an error is not returned, then the
+ *     following values are returned:
+ *
+ *       *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
+ *       *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
+ *
+ *     If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
+ *     require the "Inferred Queue ID" ability may be used.  E.g. the
+ *     Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
+ *     then these "Inferred Queue ID" register may not be used.
+ */
+int t4_bar2_sge_qregs(struct adapter *adapter,
+                     unsigned int qid,
+                     enum t4_bar2_qtype qtype,
+                     u64 *pbar2_qoffset,
+                     unsigned int *pbar2_qid)
+{
+       unsigned int page_shift, page_size, qpp_shift, qpp_mask;
+       u64 bar2_page_offset, bar2_qoffset;
+       unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
+
+       /* T4 doesn't support BAR2 SGE Queue registers.
+        */
+       if (is_t4(adapter->params.chip))
+               return -EINVAL;
+
+       /* Get our SGE Page Size parameters.
+        */
+       page_shift = adapter->params.sge.hps + 10;
+       page_size = 1 << page_shift;
+
+       /* Get the right Queues per Page parameters for our Queue.
+        */
+       qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
+                    ? adapter->params.sge.eq_qpp
+                    : adapter->params.sge.iq_qpp);
+       qpp_mask = (1 << qpp_shift) - 1;
+
+       /*  Calculate the basics of the BAR2 SGE Queue register area:
+        *  o The BAR2 page the Queue registers will be in.
+        *  o The BAR2 Queue ID.
+        *  o The BAR2 Queue ID Offset into the BAR2 page.
+        */
+       bar2_page_offset = ((qid >> qpp_shift) << page_shift);
+       bar2_qid = qid & qpp_mask;
+       bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
+
+       /* If the BAR2 Queue ID Offset is less than the Page Size, then the
+        * hardware will infer the Absolute Queue ID simply from the writes to
+        * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
+        * BAR2 Queue ID of 0 for those writes).  Otherwise, we'll simply
+        * write to the first BAR2 SGE Queue Area within the BAR2 Page with
+        * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
+        * from the BAR2 Page and BAR2 Queue ID.
+        *
+        * One important censequence of this is that some BAR2 SGE registers
+        * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
+        * there.  But other registers synthesize the SGE Queue ID purely
+        * from the writes to the registers -- the Write Combined Doorbell
+        * Buffer is a good example.  These BAR2 SGE Registers are only
+        * available for those BAR2 SGE Register areas where the SGE Absolute
+        * Queue ID can be inferred from simple writes.
+        */
+       bar2_qoffset = bar2_page_offset;
+       bar2_qinferred = (bar2_qid_offset < page_size);
+       if (bar2_qinferred) {
+               bar2_qoffset += bar2_qid_offset;
+               bar2_qid = 0;
+       }
+
+       *pbar2_qoffset = bar2_qoffset;
+       *pbar2_qid = bar2_qid;
+       return 0;
+}
+
+/**
+ *     t4_init_sge_params - initialize adap->params.sge
+ *     @adapter: the adapter
+ *
+ *     Initialize various fields of the adapter's SGE Parameters structure.
+ */
+int t4_init_sge_params(struct adapter *adapter)
+{
+       struct sge_params *sge_params = &adapter->params.sge;
+       u32 hps, qpp;
+       unsigned int s_hps, s_qpp;
+
+       /* Extract the SGE Page Size for our PF.
+        */
+       hps = t4_read_reg(adapter, SGE_HOST_PAGE_SIZE);
+       s_hps = (HOSTPAGESIZEPF0_S +
+                (HOSTPAGESIZEPF1_S - HOSTPAGESIZEPF0_S) * adapter->fn);
+       sge_params->hps = ((hps >> s_hps) & HOSTPAGESIZEPF0_M);
+
+       /* Extract the SGE Egress and Ingess Queues Per Page for our PF.
+        */
+       s_qpp = (QUEUESPERPAGEPF0_S +
+               (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) * adapter->fn);
+       qpp = t4_read_reg(adapter, SGE_EGRESS_QUEUES_PER_PAGE_PF);
+       sge_params->eq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_MASK);
+       qpp = t4_read_reg(adapter, SGE_INGRESS_QUEUES_PER_PAGE_PF);
+       sge_params->iq_qpp = ((qpp >> s_qpp) & QUEUESPERPAGEPF0_MASK);
+
+       return 0;
+}
+
 /**
  *      t4_init_tp_params - initialize adap->params.tp
  *      @adap: the adapter
@@ -4124,9 +4272,9 @@ int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
 
                c.op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) |
                                       FW_CMD_REQUEST_F | FW_CMD_READ_F |
-                                      FW_PORT_CMD_PORTID(j));
+                                      FW_PORT_CMD_PORTID_V(j));
                c.action_to_len16 = htonl(
-                       FW_PORT_CMD_ACTION(FW_PORT_ACTION_GET_PORT_INFO) |
+                       FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
                        FW_LEN16(c));
                ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
                if (ret)
@@ -4144,9 +4292,9 @@ int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
                adap->port[i]->dev_port = j;
 
                ret = ntohl(c.u.info.lstatus_to_modtype);
-               p->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP) ?
-                       FW_PORT_CMD_MDIOADDR_GET(ret) : -1;
-               p->port_type = FW_PORT_CMD_PTYPE_GET(ret);
+               p->mdio_addr = (ret & FW_PORT_CMD_MDIOCAP_F) ?
+                       FW_PORT_CMD_MDIOADDR_G(ret) : -1;
+               p->port_type = FW_PORT_CMD_PTYPE_G(ret);
                p->mod_type = FW_PORT_MOD_TYPE_NA;
 
                rvc.op_to_viid = htonl(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |