<div dir="auto">I'm just going to say that I'm very excited about these patches. Just what I needed, thanks for contributing them :-).</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 2, 2018, 03:20 Samuel Mendoza-Jonas <<a href="mailto:sam@mendozajonas.com">sam@mendozajonas.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, 2018-09-28 at 18:06 -0700, Vijay Khemka wrote:<br>
> This patch adds OEM commands and response handling. It also defines OEM<br>
> command and response structure as per NCSI specification along with its<br>
> handlers.<br>
> <br>
> ncsi_cmd_handler_oem: This is a generic command request handler for OEM<br>
> commands<br>
> ncsi_rsp_handler_oem: This is a generic response handler for OEM commands<br>
> <br>
> Signed-off-by: Vijay Khemka <<a href="mailto:vijaykhemka@fb.com" target="_blank" rel="noreferrer">vijaykhemka@fb.com</a>><br>
<br>
Hi Vijay - looks good to me, and should be a good common base for your<br>
and Justin's changes.<br>
<br>
Reviewed-by: Samuel Mendoza-Jonas <<a href="mailto:sam@mendozajonas.com" target="_blank" rel="noreferrer">sam@mendozajonas.com</a>><br>
<br>
> ---<br>
>Â net/ncsi/internal.h |Â 4 ++++<br>
>Â net/ncsi/ncsi-cmd.c | 31 ++++++++++++++++++++++++++++---<br>
>Â net/ncsi/ncsi-pkt.h | 16 ++++++++++++++++<br>
>Â net/ncsi/ncsi-rsp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-<br>
>Â 4 files changed, 91 insertions(+), 4 deletions(-)<br>
> <br>
> diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h<br>
> index 8055e3965cef..c16cb7223064 100644<br>
> --- a/net/ncsi/internal.h<br>
> +++ b/net/ncsi/internal.h<br>
> @@ -68,6 +68,10 @@ enum {<br>
>Â Â Â Â NCSI_MODE_MAX<br>
>Â };<br>
>Â <br>
> +/* OEM Vendor Manufacture ID */<br>
> +#define NCSI_OEM_MFR_MLX_IDÂ Â Â Â Â Â Â 0x8119<br>
> +#define NCSI_OEM_MFR_BCM_IDÂ Â Â Â Â Â Â 0x113d<br>
> +<br>
>Â struct ncsi_channel_version {<br>
>Â Â Â Â u32 version;Â Â Â Â Â Â /* Supported BCD encoded NCSI version */<br>
>Â Â Â Â u32 alpha2;Â Â Â Â Â Â Â /* Supported BCD encoded NCSI version */<br>
> diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c<br>
> index 7567ca63aae2..2f98533eba46 100644<br>
> --- a/net/ncsi/ncsi-cmd.c<br>
> +++ b/net/ncsi/ncsi-cmd.c<br>
> @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,<br>
>Â Â Â Â return 0;<br>
>Â }<br>
>Â <br>
> +static int ncsi_cmd_handler_oem(struct sk_buff *skb,<br>
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct ncsi_cmd_arg *nca)<br>
> +{<br>
> +Â Â Â struct ncsi_cmd_oem_pkt *cmd;<br>
> +Â Â Â unsigned int len;<br>
> +<br>
> +Â Â Â len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;<br>
> +Â Â Â if (nca->payload < 26)<br>
> +Â Â Â Â Â Â Â len += 26;<br>
> +Â Â Â else<br>
> +Â Â Â Â Â Â Â len += nca->payload;<br>
> +<br>
> +Â Â Â cmd = skb_put_zero(skb, len);<br>
> +Â Â Â cmd->mfr_id = nca->dwords[0];<br>
> +Â Â Â memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);<br>
> +Â Â Â ncsi_cmd_build_header(&cmd->cmd.common, nca);<br>
> +<br>
> +Â Â Â return 0;<br>
> +}<br>
> +<br>
>Â static struct ncsi_cmd_handler {<br>
>Â Â Â Â unsigned char type;<br>
>    int      payload;<br>
> @@ -244,7 +264,7 @@ static struct ncsi_cmd_handler {<br>
>    { NCSI_PKT_CMD_GNS,  0, ncsi_cmd_handler_default },<br>
>    { NCSI_PKT_CMD_GNPTS, 0, ncsi_cmd_handler_default },<br>
>    { NCSI_PKT_CMD_GPS,  0, ncsi_cmd_handler_default },<br>
> -   { NCSI_PKT_CMD_OEM,  0, NULL           },<br>
> +   { NCSI_PKT_CMD_OEM,  -1, ncsi_cmd_handler_oem   },<br>
>    { NCSI_PKT_CMD_PLDM,  0, NULL           },<br>
>Â Â Â Â { NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }<br>
>Â };<br>
> @@ -316,8 +336,13 @@ int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)<br>
>Â Â Â Â Â Â Â Â return -ENOENT;<br>
>Â Â Â Â }<br>
>Â <br>
> -Â Â Â /* Get packet payload length and allocate the request */<br>
> -Â Â Â nca->payload = nch->payload;<br>
> +Â Â Â /* Get packet payload length and allocate the request<br>
> +Â Â Â * It is expected that if length set as negative in<br>
> +Â Â Â * handler structure means caller is initializing it<br>
> +Â Â Â * and setting length in nca before calling xmit function<br>
> +Â Â Â */<br>
> +Â Â Â if (nch->payload >= 0)<br>
> +Â Â Â Â Â Â Â nca->payload = nch->payload;<br>
>Â Â Â Â nr = ncsi_alloc_command(nca);<br>
>Â Â Â Â if (!nr)<br>
>Â Â Â Â Â Â Â Â return -ENOMEM;<br>
> diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h<br>
> index 91b4b66438df..1f338386810d 100644<br>
> --- a/net/ncsi/ncsi-pkt.h<br>
> +++ b/net/ncsi/ncsi-pkt.h<br>
> @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {<br>
>    unsigned char      pad[22];<br>
>Â };<br>
>Â <br>
> +/* OEM Request Command as per NCSI Specification */<br>
> +struct ncsi_cmd_oem_pkt {<br>
> +   struct ncsi_cmd_pkt_hdr cmd;     /* Command header  */<br>
> +Â Â Â __be32Â Â Â Â Â Â Â Â Â mfr_id;Â Â Â /* Manufacture IDÂ Â */<br>
> +   unsigned char      data[64];  /* OEM Payload Data */<br>
> +   __be32         checksum;  /* Checksum     */<br>
> +};<br>
> +<br>
> +/* OEM Response Packet as per NCSI Specification */<br>
> +struct ncsi_rsp_oem_pkt {<br>
> +   struct ncsi_rsp_pkt_hdr rsp;     /* Command header  */<br>
> +Â Â Â __be32Â Â Â Â Â Â Â Â Â mfr_id;Â Â Â /* Manufacture IDÂ Â */<br>
> +   unsigned char      data[64];  /* Payload data   */<br>
> +   __be32         checksum;  /* Checksum     */<br>
> +};<br>
> +<br>
>Â /* Get Link Status */<br>
>Â struct ncsi_rsp_gls_pkt {<br>
>    struct ncsi_rsp_pkt_hdr rsp;    /* Response header  */<br>
> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c<br>
> index 930c1d3796f0..22664ebdc93a 100644<br>
> --- a/net/ncsi/ncsi-rsp.c<br>
> +++ b/net/ncsi/ncsi-rsp.c<br>
> @@ -596,6 +596,48 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)<br>
>Â Â Â Â return 0;<br>
>Â }<br>
>Â <br>
> +static struct ncsi_rsp_oem_handler {<br>
> +   unsigned int  mfr_id;<br>
> +   int       (*handler)(struct ncsi_request *nr);<br>
> +} ncsi_rsp_oem_handlers[] = {<br>
> +Â Â Â { NCSI_OEM_MFR_MLX_ID, NULL },<br>
> +Â Â Â { NCSI_OEM_MFR_BCM_ID, NULL }<br>
> +};<br>
> +<br>
> +<br>
> +/* Response handler for OEM command */<br>
> +static int ncsi_rsp_handler_oem(struct ncsi_request *nr)<br>
> +{<br>
> +Â Â Â struct ncsi_rsp_oem_pkt *rsp;<br>
> +Â Â Â struct ncsi_rsp_oem_handler *nrh = NULL;<br>
> +Â Â Â unsigned int mfr_id, i;<br>
> +<br>
> +Â Â Â /* Get the response header */<br>
> +Â Â Â rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);<br>
> +Â Â Â mfr_id = ntohl(rsp->mfr_id);<br>
> +<br>
> +Â Â Â /* Check for manufacturer id and Find the handler */<br>
> +Â Â Â for (i = 0; i < ARRAY_SIZE(ncsi_rsp_oem_handlers); i++) {<br>
> +Â Â Â Â Â Â Â if (ncsi_rsp_oem_handlers[i].mfr_id == mfr_id) {<br>
> +Â Â Â Â Â Â Â Â Â Â Â if (ncsi_rsp_oem_handlers[i].handler)<br>
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nrh = &ncsi_rsp_oem_handlers[i];<br>
> +Â Â Â Â Â Â Â Â Â Â Â else<br>
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nrh = NULL;<br>
> +<br>
> +Â Â Â Â Â Â Â Â Â Â Â break;<br>
> +Â Â Â Â Â Â Â }<br>
> +Â Â Â }<br>
> +<br>
> +Â Â Â if (!nrh) {<br>
> +Â Â Â Â Â Â Â netdev_err(nr->ndp->ndev.dev, "Received unrecognized OEM packet with MFR-ID (0x%x)\n",<br>
> +Â Â Â Â Â Â Â Â Â Â Â Â mfr_id);<br>
> +Â Â Â Â Â Â Â return -ENOENT;<br>
> +Â Â Â }<br>
> +<br>
> +Â Â Â /* Process the packet */<br>
> +Â Â Â return nrh->handler(nr);<br>
> +}<br>
> +<br>
>Â static int ncsi_rsp_handler_gvi(struct ncsi_request *nr)<br>
>Â {<br>
>Â Â Â Â struct ncsi_rsp_gvi_pkt *rsp;<br>
> @@ -932,7 +974,7 @@ static struct ncsi_rsp_handler {<br>
>    { NCSI_PKT_RSP_GNS,  172, ncsi_rsp_handler_gns   },<br>
>    { NCSI_PKT_RSP_GNPTS, 172, ncsi_rsp_handler_gnpts  },<br>
>    { NCSI_PKT_RSP_GPS,   8, ncsi_rsp_handler_gps   },<br>
> -   { NCSI_PKT_RSP_OEM,   0, NULL           },<br>
> +   { NCSI_PKT_RSP_OEM,  -1, ncsi_rsp_handler_oem   },<br>
>    { NCSI_PKT_RSP_PLDM,  0, NULL           },<br>
>    { NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid }<br>
>Â };<br>
<br>
<br>
</blockquote></div>