diff mbox series

[v2] net/ncsi: Add NCSI OEM command support

Message ID 20180929010602.1025909-1-vijaykhemka@fb.com
State Not Applicable, archived
Headers show
Series [v2] net/ncsi: Add NCSI OEM command support | expand

Commit Message

Vijay Khemka Sept. 29, 2018, 1:06 a.m. UTC
This patch adds OEM commands and response handling. It also defines OEM
command and response structure as per NCSI specification along with its
handlers.

ncsi_cmd_handler_oem: This is a generic command request handler for OEM
commands
ncsi_rsp_handler_oem: This is a generic response handler for OEM commands

Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
---
 net/ncsi/internal.h |  4 ++++
 net/ncsi/ncsi-cmd.c | 31 ++++++++++++++++++++++++++++---
 net/ncsi/ncsi-pkt.h | 16 ++++++++++++++++
 net/ncsi/ncsi-rsp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 91 insertions(+), 4 deletions(-)

Comments

Vijay Khemka Sept. 29, 2018, 1:20 a.m. UTC | #1
> On 9/28/18, 6:07 PM, "Vijay Khemka" <vijaykhemka@fb.com> wrote:

 >   This patch adds OEM commands and response handling. It also defines OEM
 >   command and response structure as per NCSI specification along with its
 >   handlers.
 >   
 >   ncsi_cmd_handler_oem: This is a generic command request handler for OEM
 >   commands
 >   ncsi_rsp_handler_oem: This is a generic response handler for OEM commands
   
  This is a generic patch for OEM command handling, There will be another patch 
  following this to handle specific OEM commands for each vendor. Currently I have
  defined 2 vendor/manufacturer id below in internal.h, more can be added here for
  other vendors. I have not defined ncsi_rsp_oem_handler in this patch as they are 
  NULL, but there will be a defined handlers for each vendor in next patch. 
 
    Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
    ---
     net/ncsi/internal.h |  4 ++++
     net/ncsi/ncsi-cmd.c | 31 ++++++++++++++++++++++++++++---
     net/ncsi/ncsi-pkt.h | 16 ++++++++++++++++
     net/ncsi/ncsi-rsp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
     4 files changed, 91 insertions(+), 4 deletions(-)
    
    diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
    index 8055e3965cef..c16cb7223064 100644
    --- a/net/ncsi/internal.h
    +++ b/net/ncsi/internal.h
    @@ -68,6 +68,10 @@ enum {
     	NCSI_MODE_MAX
     };
     
    +/* OEM Vendor Manufacture ID */
    +#define NCSI_OEM_MFR_MLX_ID             0x8119
    +#define NCSI_OEM_MFR_BCM_ID             0x113d
    +
     struct ncsi_channel_version {
     	u32 version;		/* Supported BCD encoded NCSI version */
     	u32 alpha2;		/* Supported BCD encoded NCSI version */
    diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
    index 7567ca63aae2..2f98533eba46 100644
    --- a/net/ncsi/ncsi-cmd.c
    +++ b/net/ncsi/ncsi-cmd.c
    @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
     	return 0;
     }
     
    +static int ncsi_cmd_handler_oem(struct sk_buff *skb,
    +				struct ncsi_cmd_arg *nca)
    +{
    +	struct ncsi_cmd_oem_pkt *cmd;
    +	unsigned int len;
    +
    +	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
    +	if (nca->payload < 26)
    +		len += 26;
    +	else
    +		len += nca->payload;
    +
    +	cmd = skb_put_zero(skb, len);
    +	cmd->mfr_id = nca->dwords[0];
    +	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);
    +	ncsi_cmd_build_header(&cmd->cmd.common, nca);
    +
    +	return 0;
    +}
    +
     static struct ncsi_cmd_handler {
     	unsigned char type;
     	int           payload;
    @@ -244,7 +264,7 @@ static struct ncsi_cmd_handler {
     	{ NCSI_PKT_CMD_GNS,    0, ncsi_cmd_handler_default },
     	{ NCSI_PKT_CMD_GNPTS,  0, ncsi_cmd_handler_default },
     	{ NCSI_PKT_CMD_GPS,    0, ncsi_cmd_handler_default },
    -	{ NCSI_PKT_CMD_OEM,    0, NULL                     },
    +	{ NCSI_PKT_CMD_OEM,   -1, ncsi_cmd_handler_oem     },
     	{ NCSI_PKT_CMD_PLDM,   0, NULL                     },
     	{ NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }
     };
    @@ -316,8 +336,13 @@ int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)
     		return -ENOENT;
     	}
     
    -	/* Get packet payload length and allocate the request */
    -	nca->payload = nch->payload;
    +	/* Get packet payload length and allocate the request
    +	 * It is expected that if length set as negative in
    +	 * handler structure means caller is initializing it
    +	 * and setting length in nca before calling xmit function
    +	 */
    +	if (nch->payload >= 0)
    +		nca->payload = nch->payload;
     	nr = ncsi_alloc_command(nca);
     	if (!nr)
     		return -ENOMEM;
    diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
    index 91b4b66438df..1f338386810d 100644
    --- a/net/ncsi/ncsi-pkt.h
    +++ b/net/ncsi/ncsi-pkt.h
    @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {
     	unsigned char           pad[22];
     };
     
    +/* OEM Request Command as per NCSI Specification */
    +struct ncsi_cmd_oem_pkt {
    +	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
    +	__be32                  mfr_id;      /* Manufacture ID    */
    +	unsigned char           data[64];    /* OEM Payload Data  */
    +	__be32                  checksum;    /* Checksum          */
    +};
    +
    +/* OEM Response Packet as per NCSI Specification */
    +struct ncsi_rsp_oem_pkt {
    +	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
    +	__be32                  mfr_id;      /* Manufacture ID    */
    +	unsigned char           data[64];    /* Payload data      */
    +	__be32                  checksum;    /* Checksum          */
    +};
    +
     /* Get Link Status */
     struct ncsi_rsp_gls_pkt {
     	struct ncsi_rsp_pkt_hdr rsp;        /* Response header   */
    diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
    index 930c1d3796f0..22664ebdc93a 100644
    --- a/net/ncsi/ncsi-rsp.c
    +++ b/net/ncsi/ncsi-rsp.c
    @@ -596,6 +596,48 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
     	return 0;
     }
     
    +static struct ncsi_rsp_oem_handler {
    +	unsigned int	mfr_id;
    +	int		(*handler)(struct ncsi_request *nr);
    +} ncsi_rsp_oem_handlers[] = {
    +	{ NCSI_OEM_MFR_MLX_ID, NULL },
    +	{ NCSI_OEM_MFR_BCM_ID, NULL }
    +};
    +
    +
    +/* Response handler for OEM command */
    +static int ncsi_rsp_handler_oem(struct ncsi_request *nr)
    +{
    +	struct ncsi_rsp_oem_pkt *rsp;
    +	struct ncsi_rsp_oem_handler *nrh = NULL;
    +	unsigned int mfr_id, i;
    +
    +	/* Get the response header */
    +	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
    +	mfr_id = ntohl(rsp->mfr_id);
    +
    +	/* Check for manufacturer id and Find the handler */
    +	for (i = 0; i < ARRAY_SIZE(ncsi_rsp_oem_handlers); i++) {
    +		if (ncsi_rsp_oem_handlers[i].mfr_id == mfr_id) {
    +			if (ncsi_rsp_oem_handlers[i].handler)
    +				nrh = &ncsi_rsp_oem_handlers[i];
    +			else
    +				nrh = NULL;
    +
    +			break;
    +		}
    +	}
    +
    +	if (!nrh) {
    +		netdev_err(nr->ndp->ndev.dev, "Received unrecognized OEM packet with MFR-ID (0x%x)\n",
    +			   mfr_id);
    +		return -ENOENT;
    +	}
    +
    +	/* Process the packet */
    +	return nrh->handler(nr);
    +}
    +
     static int ncsi_rsp_handler_gvi(struct ncsi_request *nr)
     {
     	struct ncsi_rsp_gvi_pkt *rsp;
    @@ -932,7 +974,7 @@ static struct ncsi_rsp_handler {
     	{ NCSI_PKT_RSP_GNS,   172, ncsi_rsp_handler_gns     },
     	{ NCSI_PKT_RSP_GNPTS, 172, ncsi_rsp_handler_gnpts   },
     	{ NCSI_PKT_RSP_GPS,     8, ncsi_rsp_handler_gps     },
    -	{ NCSI_PKT_RSP_OEM,     0, NULL                     },
    +	{ NCSI_PKT_RSP_OEM,    -1, ncsi_rsp_handler_oem     },
     	{ NCSI_PKT_RSP_PLDM,    0, NULL                     },
     	{ NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid  }
     };
    -- 
    2.17.1
Sam Mendoza-Jonas Oct. 2, 2018, 1:20 a.m. UTC | #2
On Fri, 2018-09-28 at 18:06 -0700, Vijay Khemka wrote:
> This patch adds OEM commands and response handling. It also defines OEM
> command and response structure as per NCSI specification along with its
> handlers.
> 
> ncsi_cmd_handler_oem: This is a generic command request handler for OEM
> commands
> ncsi_rsp_handler_oem: This is a generic response handler for OEM commands
> 
> Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>

Hi Vijay - looks good to me, and should be a good common base for your
and Justin's changes.

Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>

> ---
>  net/ncsi/internal.h |  4 ++++
>  net/ncsi/ncsi-cmd.c | 31 ++++++++++++++++++++++++++++---
>  net/ncsi/ncsi-pkt.h | 16 ++++++++++++++++
>  net/ncsi/ncsi-rsp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
>  4 files changed, 91 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
> index 8055e3965cef..c16cb7223064 100644
> --- a/net/ncsi/internal.h
> +++ b/net/ncsi/internal.h
> @@ -68,6 +68,10 @@ enum {
>  	NCSI_MODE_MAX
>  };
>  
> +/* OEM Vendor Manufacture ID */
> +#define NCSI_OEM_MFR_MLX_ID             0x8119
> +#define NCSI_OEM_MFR_BCM_ID             0x113d
> +
>  struct ncsi_channel_version {
>  	u32 version;		/* Supported BCD encoded NCSI version */
>  	u32 alpha2;		/* Supported BCD encoded NCSI version */
> diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> index 7567ca63aae2..2f98533eba46 100644
> --- a/net/ncsi/ncsi-cmd.c
> +++ b/net/ncsi/ncsi-cmd.c
> @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
>  	return 0;
>  }
>  
> +static int ncsi_cmd_handler_oem(struct sk_buff *skb,
> +				struct ncsi_cmd_arg *nca)
> +{
> +	struct ncsi_cmd_oem_pkt *cmd;
> +	unsigned int len;
> +
> +	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
> +	if (nca->payload < 26)
> +		len += 26;
> +	else
> +		len += nca->payload;
> +
> +	cmd = skb_put_zero(skb, len);
> +	cmd->mfr_id = nca->dwords[0];
> +	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);
> +	ncsi_cmd_build_header(&cmd->cmd.common, nca);
> +
> +	return 0;
> +}
> +
>  static struct ncsi_cmd_handler {
>  	unsigned char type;
>  	int           payload;
> @@ -244,7 +264,7 @@ static struct ncsi_cmd_handler {
>  	{ NCSI_PKT_CMD_GNS,    0, ncsi_cmd_handler_default },
>  	{ NCSI_PKT_CMD_GNPTS,  0, ncsi_cmd_handler_default },
>  	{ NCSI_PKT_CMD_GPS,    0, ncsi_cmd_handler_default },
> -	{ NCSI_PKT_CMD_OEM,    0, NULL                     },
> +	{ NCSI_PKT_CMD_OEM,   -1, ncsi_cmd_handler_oem     },
>  	{ NCSI_PKT_CMD_PLDM,   0, NULL                     },
>  	{ NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }
>  };
> @@ -316,8 +336,13 @@ int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)
>  		return -ENOENT;
>  	}
>  
> -	/* Get packet payload length and allocate the request */
> -	nca->payload = nch->payload;
> +	/* Get packet payload length and allocate the request
> +	 * It is expected that if length set as negative in
> +	 * handler structure means caller is initializing it
> +	 * and setting length in nca before calling xmit function
> +	 */
> +	if (nch->payload >= 0)
> +		nca->payload = nch->payload;
>  	nr = ncsi_alloc_command(nca);
>  	if (!nr)
>  		return -ENOMEM;
> diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
> index 91b4b66438df..1f338386810d 100644
> --- a/net/ncsi/ncsi-pkt.h
> +++ b/net/ncsi/ncsi-pkt.h
> @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {
>  	unsigned char           pad[22];
>  };
>  
> +/* OEM Request Command as per NCSI Specification */
> +struct ncsi_cmd_oem_pkt {
> +	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
> +	__be32                  mfr_id;      /* Manufacture ID    */
> +	unsigned char           data[64];    /* OEM Payload Data  */
> +	__be32                  checksum;    /* Checksum          */
> +};
> +
> +/* OEM Response Packet as per NCSI Specification */
> +struct ncsi_rsp_oem_pkt {
> +	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
> +	__be32                  mfr_id;      /* Manufacture ID    */
> +	unsigned char           data[64];    /* Payload data      */
> +	__be32                  checksum;    /* Checksum          */
> +};
> +
>  /* Get Link Status */
>  struct ncsi_rsp_gls_pkt {
>  	struct ncsi_rsp_pkt_hdr rsp;        /* Response header   */
> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
> index 930c1d3796f0..22664ebdc93a 100644
> --- a/net/ncsi/ncsi-rsp.c
> +++ b/net/ncsi/ncsi-rsp.c
> @@ -596,6 +596,48 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
>  	return 0;
>  }
>  
> +static struct ncsi_rsp_oem_handler {
> +	unsigned int	mfr_id;
> +	int		(*handler)(struct ncsi_request *nr);
> +} ncsi_rsp_oem_handlers[] = {
> +	{ NCSI_OEM_MFR_MLX_ID, NULL },
> +	{ NCSI_OEM_MFR_BCM_ID, NULL }
> +};
> +
> +
> +/* Response handler for OEM command */
> +static int ncsi_rsp_handler_oem(struct ncsi_request *nr)
> +{
> +	struct ncsi_rsp_oem_pkt *rsp;
> +	struct ncsi_rsp_oem_handler *nrh = NULL;
> +	unsigned int mfr_id, i;
> +
> +	/* Get the response header */
> +	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
> +	mfr_id = ntohl(rsp->mfr_id);
> +
> +	/* Check for manufacturer id and Find the handler */
> +	for (i = 0; i < ARRAY_SIZE(ncsi_rsp_oem_handlers); i++) {
> +		if (ncsi_rsp_oem_handlers[i].mfr_id == mfr_id) {
> +			if (ncsi_rsp_oem_handlers[i].handler)
> +				nrh = &ncsi_rsp_oem_handlers[i];
> +			else
> +				nrh = NULL;
> +
> +			break;
> +		}
> +	}
> +
> +	if (!nrh) {
> +		netdev_err(nr->ndp->ndev.dev, "Received unrecognized OEM packet with MFR-ID (0x%x)\n",
> +			   mfr_id);
> +		return -ENOENT;
> +	}
> +
> +	/* Process the packet */
> +	return nrh->handler(nr);
> +}
> +
>  static int ncsi_rsp_handler_gvi(struct ncsi_request *nr)
>  {
>  	struct ncsi_rsp_gvi_pkt *rsp;
> @@ -932,7 +974,7 @@ static struct ncsi_rsp_handler {
>  	{ NCSI_PKT_RSP_GNS,   172, ncsi_rsp_handler_gns     },
>  	{ NCSI_PKT_RSP_GNPTS, 172, ncsi_rsp_handler_gnpts   },
>  	{ NCSI_PKT_RSP_GPS,     8, ncsi_rsp_handler_gps     },
> -	{ NCSI_PKT_RSP_OEM,     0, NULL                     },
> +	{ NCSI_PKT_RSP_OEM,    -1, ncsi_rsp_handler_oem     },
>  	{ NCSI_PKT_RSP_PLDM,    0, NULL                     },
>  	{ NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid  }
>  };
Christian Svensson Oct. 2, 2018, 6:29 a.m. UTC | #3
I'm just going to say that I'm very excited about these patches. Just what
I needed, thanks for contributing them :-).

On Tue, Oct 2, 2018, 03:20 Samuel Mendoza-Jonas <sam@mendozajonas.com>
wrote:

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

Looks good. Please see my comment below.

Thanks,
Justin


> On Fri, 2018-09-28 at 18:06 -0700, Vijay Khemka wrote:
> > This patch adds OEM commands and response handling. It also defines OEM
> > command and response structure as per NCSI specification along with its
> > handlers.
> > 
> > ncsi_cmd_handler_oem: This is a generic command request handler for OEM
> > commands
> > ncsi_rsp_handler_oem: This is a generic response handler for OEM commands
> > 
> > Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
> 
> Hi Vijay - looks good to me, and should be a good common base for your
> and Justin's changes.
> 
> Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
> 
> > ---
> >  net/ncsi/internal.h |  4 ++++
> >  net/ncsi/ncsi-cmd.c | 31 ++++++++++++++++++++++++++++---
> >  net/ncsi/ncsi-pkt.h | 16 ++++++++++++++++
> >  net/ncsi/ncsi-rsp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
> >  4 files changed, 91 insertions(+), 4 deletions(-)
> > 
> > diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
> > index 8055e3965cef..c16cb7223064 100644
> > --- a/net/ncsi/internal.h
> > +++ b/net/ncsi/internal.h
> > @@ -68,6 +68,10 @@ enum {
> >  	NCSI_MODE_MAX
> >  };
> >  
> > +/* OEM Vendor Manufacture ID */
> > +#define NCSI_OEM_MFR_MLX_ID             0x8119
> > +#define NCSI_OEM_MFR_BCM_ID             0x113d
> > +
> >  struct ncsi_channel_version {
> >  	u32 version;		/* Supported BCD encoded NCSI version */
> >  	u32 alpha2;		/* Supported BCD encoded NCSI version */
> > diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> > index 7567ca63aae2..2f98533eba46 100644
> > --- a/net/ncsi/ncsi-cmd.c
> > +++ b/net/ncsi/ncsi-cmd.c
> > @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
> >  	return 0;
> >  }
> >  
> > +static int ncsi_cmd_handler_oem(struct sk_buff *skb,
> > +				struct ncsi_cmd_arg *nca)
> > +{
> > +	struct ncsi_cmd_oem_pkt *cmd;

OEM command doesn't not have the fixed data size. Should we use pointer instead?
struct ncsi_cmd_oem_pkt {
	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
	__be32                  mfr_id;      /* Manufacture ID    */
	unsigned char           *data;       /* OEM Payload Data  */
};

> > +	unsigned int len;
> > +
> > +	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
> > +	if (nca->payload < 26)
> > +		len += 26;

Why does it add 26? I knew the other place in ncsi_alloc_command() is also add 26.
If it is less than 26, then it should be a fixed size of structure ncsi_cmd_pkt (46), right?

> > +	else
> > +		len += nca->payload;
> > +
> > +	cmd = skb_put_zero(skb, len);
> > +	cmd->mfr_id = nca->dwords[0];
> > +	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);

Netlink request is using the new nca->data pointer to pass the data as the request payload
is not the same size and some command payload is bigger than 16 bytes.
Will you consider to use the same data pointer? So, we don't need to have a checking here.
If the command is used less than 16 bytes, we can simply assigned &nca->bytes[0] to it.

> > +	ncsi_cmd_build_header(&cmd->cmd.common, nca);
> > +
> > +	return 0;
> > +}
> > +
> >  static struct ncsi_cmd_handler {
> >  	unsigned char type;
> >  	int           payload;
> > @@ -244,7 +264,7 @@ static struct ncsi_cmd_handler {
> >  	{ NCSI_PKT_CMD_GNS,    0, ncsi_cmd_handler_default },
> >  	{ NCSI_PKT_CMD_GNPTS,  0, ncsi_cmd_handler_default },
> >  	{ NCSI_PKT_CMD_GPS,    0, ncsi_cmd_handler_default },
> > -	{ NCSI_PKT_CMD_OEM,    0, NULL                     },
> > +	{ NCSI_PKT_CMD_OEM,   -1, ncsi_cmd_handler_oem     },
> >  	{ NCSI_PKT_CMD_PLDM,   0, NULL                     },
> >  	{ NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }
> >  };
> > @@ -316,8 +336,13 @@ int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)
> >  		return -ENOENT;
> >  	}
> >  
> > -	/* Get packet payload length and allocate the request */
> > -	nca->payload = nch->payload;
> > +	/* Get packet payload length and allocate the request
> > +	 * It is expected that if length set as negative in
> > +	 * handler structure means caller is initializing it
> > +	 * and setting length in nca before calling xmit function
> > +	 */
> > +	if (nch->payload >= 0)
> > +		nca->payload = nch->payload;
> >  	nr = ncsi_alloc_command(nca);
> >  	if (!nr)
> >  		return -ENOMEM;
> > diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
> > index 91b4b66438df..1f338386810d 100644
> > --- a/net/ncsi/ncsi-pkt.h
> > +++ b/net/ncsi/ncsi-pkt.h
> > @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {
> >  	unsigned char           pad[22];
> >  };
> >  
> > +/* OEM Request Command as per NCSI Specification */
> > +struct ncsi_cmd_oem_pkt {
> > +	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
> > +	__be32                  mfr_id;      /* Manufacture ID    */
> > +	unsigned char           data[64];    /* OEM Payload Data  */
> > +	__be32                  checksum;    /* Checksum          */
> > +};
> > +
> > +/* OEM Response Packet as per NCSI Specification */
> > +struct ncsi_rsp_oem_pkt {
> > +	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
> > +	__be32                  mfr_id;      /* Manufacture ID    */
> > +	unsigned char           data[64];    /* Payload data      */
> > +	__be32                  checksum;    /* Checksum          */
> > +};
> > +

OEM command doesn't not have the fixed response data size too.
Should we use pointer instead?

> >  /* Get Link Status */
> >  struct ncsi_rsp_gls_pkt {
> >  	struct ncsi_rsp_pkt_hdr rsp;        /* Response header   */
> > diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
> > index 930c1d3796f0..22664ebdc93a 100644
> > --- a/net/ncsi/ncsi-rsp.c
> > +++ b/net/ncsi/ncsi-rsp.c
> > @@ -596,6 +596,48 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
> >  	return 0;
> >  }
> >  
> > +static struct ncsi_rsp_oem_handler {
> > +	unsigned int	mfr_id;
> > +	int		(*handler)(struct ncsi_request *nr);
> > +} ncsi_rsp_oem_handlers[] = {
> > +	{ NCSI_OEM_MFR_MLX_ID, NULL },
> > +	{ NCSI_OEM_MFR_BCM_ID, NULL }
> > +};
> > +
> > +
> > +/* Response handler for OEM command */
> > +static int ncsi_rsp_handler_oem(struct ncsi_request *nr)
> > +{
> > +	struct ncsi_rsp_oem_pkt *rsp;
> > +	struct ncsi_rsp_oem_handler *nrh = NULL;
> > +	unsigned int mfr_id, i;
> > +
> > +	/* Get the response header */
> > +	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
> > +	mfr_id = ntohl(rsp->mfr_id);
> > +
> > +	/* Check for manufacturer id and Find the handler */
> > +	for (i = 0; i < ARRAY_SIZE(ncsi_rsp_oem_handlers); i++) {
> > +		if (ncsi_rsp_oem_handlers[i].mfr_id == mfr_id) {
> > +			if (ncsi_rsp_oem_handlers[i].handler)
> > +				nrh = &ncsi_rsp_oem_handlers[i];
> > +			else
> > +				nrh = NULL;
> > +
> > +			break;
> > +		}
> > +	}
> > +
> > +	if (!nrh) {
> > +		netdev_err(nr->ndp->ndev.dev, "Received unrecognized OEM packet with MFR-ID (0x%x)\n",
> > +			   mfr_id);
> > +		return -ENOENT;
> > +	}
> > +
> > +	/* Process the packet */
> > +	return nrh->handler(nr);
> > +}
> > +
> >  static int ncsi_rsp_handler_gvi(struct ncsi_request *nr)
> >  {
> >  	struct ncsi_rsp_gvi_pkt *rsp;
> > @@ -932,7 +974,7 @@ static struct ncsi_rsp_handler {
> >  	{ NCSI_PKT_RSP_GNS,   172, ncsi_rsp_handler_gns     },
> >  	{ NCSI_PKT_RSP_GNPTS, 172, ncsi_rsp_handler_gnpts   },
> >  	{ NCSI_PKT_RSP_GPS,     8, ncsi_rsp_handler_gps     },
> > -	{ NCSI_PKT_RSP_OEM,     0, NULL                     },
> > +	{ NCSI_PKT_RSP_OEM,    -1, ncsi_rsp_handler_oem     },
> >  	{ NCSI_PKT_RSP_PLDM,    0, NULL                     },
> >  	{ NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid  }
> >  };
Vijay Khemka Oct. 2, 2018, 6:56 p.m. UTC | #5
Hi Justin,
Thanks for response. Please see my comments below.

-Vijay
    > > diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
    > > index 7567ca63aae2..2f98533eba46 100644
    > > --- a/net/ncsi/ncsi-cmd.c
    > > +++ b/net/ncsi/ncsi-cmd.c
    > > @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
    > >  	return 0;
    > >  }
    > >  
    > > +static int ncsi_cmd_handler_oem(struct sk_buff *skb,
    > > +				struct ncsi_cmd_arg *nca)
    > > +{
    > > +	struct ncsi_cmd_oem_pkt *cmd;
    
    >OEM command doesn't not have the fixed data size. Should we use pointer instead?
    >struct ncsi_cmd_oem_pkt {
    >	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
    >	__be32                  mfr_id;      /* Manufacture ID    */
    >	unsigned char           *data;       /* OEM Payload Data  */
    >};
    Yes, I agree that OEM command doesn't have fixed data but to map to skbuff structure, 
    I have defined above structure as per NCSI spec, We can certainly have a MAX_DATA_LEN define.

    > > +	unsigned int len;
    > > +
    > > +	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
    > > +	if (nca->payload < 26)
    > > +		len += 26;
    
    >Why does it add 26? I knew the other place in ncsi_alloc_command() is also add 26.
    >If it is less than 26, then it should be a fixed size of structure ncsi_cmd_pkt (46), right?
    It adds 26 because It has already assigned len to hdr+4 which is 16+4 = 20 bytes. By 
    adding 26 it makes it to 46. I am just being consistent with other portion of code.

    > > +	else
    > > +		len += nca->payload;
    > > +
    > > +	cmd = skb_put_zero(skb, len);
    > > +	cmd->mfr_id = nca->dwords[0];
    > > +	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);
    
    >Netlink request is using the new nca->data pointer to pass the data as the request payload
    >is not the same size and some command payload is bigger than 16 bytes.
    >Will you consider to use the same data pointer? So, we don't need to have a checking here.
    >If the command is used less than 16 bytes, we can simply assigned &nca->bytes[0] to it.
    To keep original structure, we can change 16 bytes to MAX_DATA_LEN. Or I don't see any issue in 
    Copying data from data pointer from nca but user needs to be aware if it is less than 16 bytes then 
    use bytes or use data pointer. To keep it simple, we should simply define MAX_LEN.
    
    > > diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
    > > index 91b4b66438df..1f338386810d 100644
    > > --- a/net/ncsi/ncsi-pkt.h
    > > +++ b/net/ncsi/ncsi-pkt.h
    > > @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {
    > >  	unsigned char           pad[22];
    > >  };
    > >  
    > > +/* OEM Request Command as per NCSI Specification */
    > > +struct ncsi_cmd_oem_pkt {
    > > +	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
    > > +	__be32                  mfr_id;      /* Manufacture ID    */
    > > +	unsigned char           data[64];    /* OEM Payload Data  */
    > > +	__be32                  checksum;    /* Checksum          */
    > > +};
    > > +
    > > +/* OEM Response Packet as per NCSI Specification */
    > > +struct ncsi_rsp_oem_pkt {
    > > +	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
    > > +	__be32                  mfr_id;      /* Manufacture ID    */
    > > +	unsigned char           data[64];    /* Payload data      */
    > > +	__be32                  checksum;    /* Checksum          */
    > > +};
    > > +
    
    >OEM command doesn't not have the fixed response data size too.
    >Should we use pointer instead?

    Here also we can define MAX_DATA_LEN because data pointer won't map to skb directly.
Justin.Lee1@Dell.com Oct. 2, 2018, 8:53 p.m. UTC | #6
Hi Vijay,

Please see the comments below.

Thanks,
Justin


> Hi Justin,
> Thanks for response. Please see my comments below.
> 
> -Vijay
>     
> > > diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> > > index 7567ca63aae2..2f98533eba46 100644
> > > --- a/net/ncsi/ncsi-cmd.c
> > > +++ b/net/ncsi/ncsi-cmd.c
> > > @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
> > >  	return 0;
> > >  }
> > >  
> > > +static int ncsi_cmd_handler_oem(struct sk_buff *skb,
> > > +				struct ncsi_cmd_arg *nca)
> > > +{
> > > +	struct ncsi_cmd_oem_pkt *cmd;
> 
> >OEM command doesn't not have the fixed data size. Should we use pointer instead?
> >struct ncsi_cmd_oem_pkt {
> >	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
> >	__be32                  mfr_id;      /* Manufacture ID    */
> >	unsigned char           *data;       /* OEM Payload Data  */
> >};
> Yes, I agree that OEM command doesn't have fixed data but to map to skbuff structure, 
> I have defined above structure as per NCSI spec, We can certainly have a MAX_DATA_LEN define.

The spec only defines manufacture ID field and the start offset of vendor data. 
If we just want to point to the vendor data, we don't need to specify the max length and
we can use flexible array as the last member (correct the typo above).

struct ncsi_cmd_oem_pkt {
	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
	__be32                  mfr_id;      /* Manufacture ID    */
	unsigned char           data[];       /* OEM Payload Data  */
};

> > > +	unsigned int len;
> > > +
> > > +	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
> > > +	if (nca->payload < 26)
> > > +		len += 26;
> 
> >Why does it add 26? I knew the other place in ncsi_alloc_command() is also add 26.
> >If it is less than 26, then it should be a fixed size of structure ncsi_cmd_pkt (46), right?
> It adds 26 because It has already assigned len to hdr+4 which is 16+4 = 20 bytes. By 
> adding 26 it makes it to 46. I am just being consistent with other portion of code.
> 
> > > +	else
> > > +		len += nca->payload;
> > > +
> > > +	cmd = skb_put_zero(skb, len);
> > > +	cmd->mfr_id = nca->dwords[0];
> > > +	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);
> 
> >Netlink request is using the new nca->data pointer to pass the data as the request payload
> >is not the same size and some command payload is bigger than 16 bytes.
> >Will you consider to use the same data pointer? So, we don't need to have a checking here.
> >If the command is used less than 16 bytes, we can simply assigned &nca->bytes[0] to it.
> To keep original structure, we can change 16 bytes to MAX_DATA_LEN. Or I don't see any issue in 
> Copying data from data pointer from nca but user needs to be aware if it is less than 16 bytes then 
> use bytes or use data pointer. To keep it simple, we should simply define MAX_LEN.

I use the pointer to avoid copying the data again. OEM handler can always process the flexible payload
through the data pointer. It can depend on the caller to use stack/allocated buffer/nca buffer and
it will be straight forward if all OEM stuff is using the data pointer to process the flexible
payload.

> 
> > > diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
> > > index 91b4b66438df..1f338386810d 100644
> > > --- a/net/ncsi/ncsi-pkt.h
> > > +++ b/net/ncsi/ncsi-pkt.h
> > > @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {
> > >  	unsigned char           pad[22];
> > >  };
> > >  
> > > +/* OEM Request Command as per NCSI Specification */
> > > +struct ncsi_cmd_oem_pkt {
> > > +	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
> > > +	__be32                  mfr_id;      /* Manufacture ID    */
> > > +	unsigned char           data[64];    /* OEM Payload Data  */
> > > +	__be32                  checksum;    /* Checksum          */
> > > +};
> > > +
> > > +/* OEM Response Packet as per NCSI Specification */
> > > +struct ncsi_rsp_oem_pkt {
> > > +	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
> > > +	__be32                  mfr_id;      /* Manufacture ID    */
> > > +	unsigned char           data[64];    /* Payload data      */
> > > +	__be32                  checksum;    /* Checksum          */
> > > +};
> > > +
> 
> >OEM command doesn't not have the fixed response data size too.
> >Should we use pointer instead?
> 
> Here also we can define MAX_DATA_LEN because data pointer won't map to skb directly.

Suggest to change as below due to the flexible response.
struct ncsi_rsp_oem_pkt {
	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
	__be32                  mfr_id;      /* Manufacture ID    */
	unsigned char           data[];    /* Payload data      */
};
Vijay Khemka Oct. 2, 2018, 9:34 p.m. UTC | #7
Hi Justin,
Please see comments below

-Vijay
 
    > > > diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
    > > > index 7567ca63aae2..2f98533eba46 100644
    > > > --- a/net/ncsi/ncsi-cmd.c
    > > > +++ b/net/ncsi/ncsi-cmd.c
    > > > @@ -211,6 +211,26 @@ static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
    > > >  	return 0;
    > > >  }
    > > >  
    > > > +static int ncsi_cmd_handler_oem(struct sk_buff *skb,
    > > > +				struct ncsi_cmd_arg *nca)
    > > > +{
    > > > +	struct ncsi_cmd_oem_pkt *cmd;
    > 
    > >OEM command doesn't not have the fixed data size. Should we use pointer instead?
    > >struct ncsi_cmd_oem_pkt {
    > >	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
    > >	__be32                  mfr_id;      /* Manufacture ID    */
    > >	unsigned char           *data;       /* OEM Payload Data  */
    > >};
    > Yes, I agree that OEM command doesn't have fixed data but to map to skbuff structure, 
    > I have defined above structure as per NCSI spec, We can certainly have a MAX_DATA_LEN define.
    
    The spec only defines manufacture ID field and the start offset of vendor data. 
    If we just want to point to the vendor data, we don't need to specify the max length and
    we can use flexible array as the last member (correct the typo above).
    
    struct ncsi_cmd_oem_pkt {
    	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
    	__be32                  mfr_id;      /* Manufacture ID    */
    	unsigned char           data[];       /* OEM Payload Data  */
    };

I agree and will add this change.
     
    > > > +	unsigned int len;
    > > > +
    > > > +	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
    > > > +	if (nca->payload < 26)
    > > > +		len += 26;
    > 
    > >Why does it add 26? I knew the other place in ncsi_alloc_command() is also add 26.
    > >If it is less than 26, then it should be a fixed size of structure ncsi_cmd_pkt (46), right?
    > It adds 26 because It has already assigned len to hdr+4 which is 16+4 = 20 bytes. By 
    > adding 26 it makes it to 46. I am just being consistent with other portion of code.
    > 
    > > > +	else
    > > > +		len += nca->payload;
    > > > +
    > > > +	cmd = skb_put_zero(skb, len);
    > > > +	cmd->mfr_id = nca->dwords[0];
    > > > +	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);
    > 
    > >Netlink request is using the new nca->data pointer to pass the data as the request payload
    > >is not the same size and some command payload is bigger than 16 bytes.
    > >Will you consider to use the same data pointer? So, we don't need to have a checking here.
    > >If the command is used less than 16 bytes, we can simply assigned &nca->bytes[0] to it.
    > To keep original structure, we can change 16 bytes to MAX_DATA_LEN. Or I don't see any issue in 
    > Copying data from data pointer from nca but user needs to be aware if it is less than 16 bytes then 
    > use bytes or use data pointer. To keep it simple, we should simply define MAX_LEN.
    
    I use the pointer to avoid copying the data again. OEM handler can always process the flexible payload
    through the data pointer. It can depend on the caller to use stack/allocated buffer/nca buffer and
    it will be straight forward if all OEM stuff is using the data pointer to process the flexible
    payload.

Do we use data pointer for payload less than 16 bytes as well in OEM. We copy data only once while adding to skbuff. 
I have no issue, I will make this change but wait for other comments.
    
    > 
    > > > diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
    > > > index 91b4b66438df..1f338386810d 100644
    > > > --- a/net/ncsi/ncsi-pkt.h
    > > > +++ b/net/ncsi/ncsi-pkt.h
    > > > @@ -151,6 +151,22 @@ struct ncsi_cmd_snfc_pkt {
    > > >  	unsigned char           pad[22];
    > > >  };
    > > >  
    > > > +/* OEM Request Command as per NCSI Specification */
    > > > +struct ncsi_cmd_oem_pkt {
    > > > +	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
    > > > +	__be32                  mfr_id;      /* Manufacture ID    */
    > > > +	unsigned char           data[64];    /* OEM Payload Data  */
    > > > +	__be32                  checksum;    /* Checksum          */
    > > > +};
    > > > +
    > > > +/* OEM Response Packet as per NCSI Specification */
    > > > +struct ncsi_rsp_oem_pkt {
    > > > +	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
    > > > +	__be32                  mfr_id;      /* Manufacture ID    */
    > > > +	unsigned char           data[64];    /* Payload data      */
    > > > +	__be32                  checksum;    /* Checksum          */
    > > > +};
    > > > +
    > 
    > >OEM command doesn't not have the fixed response data size too.
    > >Should we use pointer instead?
    > 
    > Here also we can define MAX_DATA_LEN because data pointer won't map to skb directly.
    
    Suggest to change as below due to the flexible response.
    struct ncsi_rsp_oem_pkt {
    	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
    	__be32                  mfr_id;      /* Manufacture ID    */
    	unsigned char           data[];    /* Payload data      */
    };
    
Sure done.
diff mbox series

Patch

diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
index 8055e3965cef..c16cb7223064 100644
--- a/net/ncsi/internal.h
+++ b/net/ncsi/internal.h
@@ -68,6 +68,10 @@  enum {
 	NCSI_MODE_MAX
 };
 
+/* OEM Vendor Manufacture ID */
+#define NCSI_OEM_MFR_MLX_ID             0x8119
+#define NCSI_OEM_MFR_BCM_ID             0x113d
+
 struct ncsi_channel_version {
 	u32 version;		/* Supported BCD encoded NCSI version */
 	u32 alpha2;		/* Supported BCD encoded NCSI version */
diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
index 7567ca63aae2..2f98533eba46 100644
--- a/net/ncsi/ncsi-cmd.c
+++ b/net/ncsi/ncsi-cmd.c
@@ -211,6 +211,26 @@  static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
 	return 0;
 }
 
+static int ncsi_cmd_handler_oem(struct sk_buff *skb,
+				struct ncsi_cmd_arg *nca)
+{
+	struct ncsi_cmd_oem_pkt *cmd;
+	unsigned int len;
+
+	len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
+	if (nca->payload < 26)
+		len += 26;
+	else
+		len += nca->payload;
+
+	cmd = skb_put_zero(skb, len);
+	cmd->mfr_id = nca->dwords[0];
+	memcpy(cmd->data, &nca->dwords[1], nca->payload - 4);
+	ncsi_cmd_build_header(&cmd->cmd.common, nca);
+
+	return 0;
+}
+
 static struct ncsi_cmd_handler {
 	unsigned char type;
 	int           payload;
@@ -244,7 +264,7 @@  static struct ncsi_cmd_handler {
 	{ NCSI_PKT_CMD_GNS,    0, ncsi_cmd_handler_default },
 	{ NCSI_PKT_CMD_GNPTS,  0, ncsi_cmd_handler_default },
 	{ NCSI_PKT_CMD_GPS,    0, ncsi_cmd_handler_default },
-	{ NCSI_PKT_CMD_OEM,    0, NULL                     },
+	{ NCSI_PKT_CMD_OEM,   -1, ncsi_cmd_handler_oem     },
 	{ NCSI_PKT_CMD_PLDM,   0, NULL                     },
 	{ NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }
 };
@@ -316,8 +336,13 @@  int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)
 		return -ENOENT;
 	}
 
-	/* Get packet payload length and allocate the request */
-	nca->payload = nch->payload;
+	/* Get packet payload length and allocate the request
+	 * It is expected that if length set as negative in
+	 * handler structure means caller is initializing it
+	 * and setting length in nca before calling xmit function
+	 */
+	if (nch->payload >= 0)
+		nca->payload = nch->payload;
 	nr = ncsi_alloc_command(nca);
 	if (!nr)
 		return -ENOMEM;
diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
index 91b4b66438df..1f338386810d 100644
--- a/net/ncsi/ncsi-pkt.h
+++ b/net/ncsi/ncsi-pkt.h
@@ -151,6 +151,22 @@  struct ncsi_cmd_snfc_pkt {
 	unsigned char           pad[22];
 };
 
+/* OEM Request Command as per NCSI Specification */
+struct ncsi_cmd_oem_pkt {
+	struct ncsi_cmd_pkt_hdr cmd;         /* Command header    */
+	__be32                  mfr_id;      /* Manufacture ID    */
+	unsigned char           data[64];    /* OEM Payload Data  */
+	__be32                  checksum;    /* Checksum          */
+};
+
+/* OEM Response Packet as per NCSI Specification */
+struct ncsi_rsp_oem_pkt {
+	struct ncsi_rsp_pkt_hdr rsp;         /* Command header    */
+	__be32                  mfr_id;      /* Manufacture ID    */
+	unsigned char           data[64];    /* Payload data      */
+	__be32                  checksum;    /* Checksum          */
+};
+
 /* Get Link Status */
 struct ncsi_rsp_gls_pkt {
 	struct ncsi_rsp_pkt_hdr rsp;        /* Response header   */
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index 930c1d3796f0..22664ebdc93a 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -596,6 +596,48 @@  static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
 	return 0;
 }
 
+static struct ncsi_rsp_oem_handler {
+	unsigned int	mfr_id;
+	int		(*handler)(struct ncsi_request *nr);
+} ncsi_rsp_oem_handlers[] = {
+	{ NCSI_OEM_MFR_MLX_ID, NULL },
+	{ NCSI_OEM_MFR_BCM_ID, NULL }
+};
+
+
+/* Response handler for OEM command */
+static int ncsi_rsp_handler_oem(struct ncsi_request *nr)
+{
+	struct ncsi_rsp_oem_pkt *rsp;
+	struct ncsi_rsp_oem_handler *nrh = NULL;
+	unsigned int mfr_id, i;
+
+	/* Get the response header */
+	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
+	mfr_id = ntohl(rsp->mfr_id);
+
+	/* Check for manufacturer id and Find the handler */
+	for (i = 0; i < ARRAY_SIZE(ncsi_rsp_oem_handlers); i++) {
+		if (ncsi_rsp_oem_handlers[i].mfr_id == mfr_id) {
+			if (ncsi_rsp_oem_handlers[i].handler)
+				nrh = &ncsi_rsp_oem_handlers[i];
+			else
+				nrh = NULL;
+
+			break;
+		}
+	}
+
+	if (!nrh) {
+		netdev_err(nr->ndp->ndev.dev, "Received unrecognized OEM packet with MFR-ID (0x%x)\n",
+			   mfr_id);
+		return -ENOENT;
+	}
+
+	/* Process the packet */
+	return nrh->handler(nr);
+}
+
 static int ncsi_rsp_handler_gvi(struct ncsi_request *nr)
 {
 	struct ncsi_rsp_gvi_pkt *rsp;
@@ -932,7 +974,7 @@  static struct ncsi_rsp_handler {
 	{ NCSI_PKT_RSP_GNS,   172, ncsi_rsp_handler_gns     },
 	{ NCSI_PKT_RSP_GNPTS, 172, ncsi_rsp_handler_gnpts   },
 	{ NCSI_PKT_RSP_GPS,     8, ncsi_rsp_handler_gps     },
-	{ NCSI_PKT_RSP_OEM,     0, NULL                     },
+	{ NCSI_PKT_RSP_OEM,    -1, ncsi_rsp_handler_oem     },
 	{ NCSI_PKT_RSP_PLDM,    0, NULL                     },
 	{ NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid  }
 };