* [PATCH net] cxgb4: Add a check for flashing FW using ethtool
@ 2014-12-02 12:09 Hariprasad Shenai
2014-12-02 14:18 ` Sergei Shtylyov
0 siblings, 1 reply; 3+ messages in thread
From: Hariprasad Shenai @ 2014-12-02 12:09 UTC (permalink / raw)
To: netdev; +Cc: davem, leedom, anish, nirranjan, kumaras, Hariprasad Shenai
Don't let T4 firmware flash on a T5 adapter and vice-versa
using ethtool
Based on original work by Casey Leedom <leedom@chelsio.com>
Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
---
drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index 163a2a1..fae205a 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -1131,6 +1131,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 int 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 1;
+
+ 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 0;
+}
+
/**
* t4_load_fw - download firmware
* @adap: the adapter
@@ -1170,6 +1191,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]);
@@ -3080,6 +3103,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;
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net] cxgb4: Add a check for flashing FW using ethtool
2014-12-02 12:09 [PATCH net] cxgb4: Add a check for flashing FW using ethtool Hariprasad Shenai
@ 2014-12-02 14:18 ` Sergei Shtylyov
2014-12-03 8:07 ` Hariprasad S
0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2014-12-02 14:18 UTC (permalink / raw)
To: Hariprasad Shenai, netdev; +Cc: davem, leedom, anish, nirranjan, kumaras
Hello.
On 12/2/2014 3:09 PM, Hariprasad Shenai wrote:
> Don't let T4 firmware flash on a T5 adapter and vice-versa
> using ethtool
> Based on original work by Casey Leedom <leedom@chelsio.com>
> Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
> ---
> drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 26 ++++++++++++++++++++++++++
> 1 files changed, 26 insertions(+), 0 deletions(-)
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> index 163a2a1..fae205a 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> @@ -1131,6 +1131,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 int t4_fw_matches_chip(const struct adapter *adap,
s/int/bool/?
> + 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 1;
s/1/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 0;
s/0/false/?
[...]
WBR, Sergei
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] cxgb4: Add a check for flashing FW using ethtool
2014-12-02 14:18 ` Sergei Shtylyov
@ 2014-12-03 8:07 ` Hariprasad S
0 siblings, 0 replies; 3+ messages in thread
From: Hariprasad S @ 2014-12-03 8:07 UTC (permalink / raw)
To: Sergei Shtylyov; +Cc: netdev, davem, leedom, anish, nirranjan, kumaras
On Tue, Dec 02, 2014 at 17:18:45 +0300, Sergei Shtylyov wrote:
> Hello.
>
> On 12/2/2014 3:09 PM, Hariprasad Shenai wrote:
>
> >Don't let T4 firmware flash on a T5 adapter and vice-versa
> >using ethtool
>
> >Based on original work by Casey Leedom <leedom@chelsio.com>
>
> >Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
> >---
> > drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 26 ++++++++++++++++++++++++++
> > 1 files changed, 26 insertions(+), 0 deletions(-)
>
> >diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> >index 163a2a1..fae205a 100644
> >--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> >+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
> >@@ -1131,6 +1131,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 int t4_fw_matches_chip(const struct adapter *adap,
>
> s/int/bool/?
>
> >+ 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 1;
>
> s/1/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 0;
>
> s/0/false/?
>
> [...]
>
> WBR, Sergei
>
Thanks for the review comment, have sent a V2 based on your comments.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-12-03 8:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 12:09 [PATCH net] cxgb4: Add a check for flashing FW using ethtool Hariprasad Shenai
2014-12-02 14:18 ` Sergei Shtylyov
2014-12-03 8:07 ` Hariprasad S
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).