]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[karo-tx-linux.git] / drivers / net / ethernet / chelsio / cxgb4 / t4_hw.c
index 7975d26f50df84218e4fe9778f7ae27374399089..67345c73e57017db375b4de1ed4aa62192757fec 100644 (file)
@@ -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;
 }
 
@@ -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;
@@ -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