All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vikram Garhwal <fnu.vikram@xilinx.com>
To: pisa@cmp.felk.cvut.cz
Cc: Marek Vasut <marex@denx.de>, Jiri Novak <jnovak@fel.cvut.cz>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	Deniz Eren <deniz.eren@icloud.com>,
	qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Konrad Frederic <frederic.konrad@adacore.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Jan Charvat <charvj10@fel.cvut.cz>,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Ondrej Ille <ondrej.ille@gmail.com>
Subject: Re: [PATCH v1 2/6] hw/net/can: sja1000 ignore CAN FD frames
Date: Tue, 1 Sep 2020 10:07:39 -0700	[thread overview]
Message-ID: <20200901170733.GA151036@xilinx.com> (raw)
In-Reply-To: <e9a4847e46810282319bdde1a6ddd901eb8783fd.1594725647.git.pisa@cmp.felk.cvut.cz>

On Tue, Jul 14, 2020 at 02:20:15PM +0200, pisa@cmp.felk.cvut.cz wrote:
> From: Jan Charvat <charvj10@fel.cvut.cz>
>
> Signed-off-by: Jan Charvat <charvj10@fel.cvut.cz>
> Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>

Reviewed-by: Vikram Garhwal <fnu.vikram@xilinx.com>

> ---
>  hw/net/can/can_sja1000.c | 29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c
> index d83c550edc..382911560c 100644
> --- a/hw/net/can/can_sja1000.c
> +++ b/hw/net/can/can_sja1000.c
> @@ -323,11 +323,16 @@ static void buff2frame_bas(const uint8_t *buff, qemu_can_frame *frame)
>  static int frame2buff_pel(const qemu_can_frame *frame, uint8_t *buff)
>  {
>      int i;
> +    int dlen = frame->can_dlc;
>
>      if (frame->can_id & QEMU_CAN_ERR_FLAG) { /* error frame, NOT support now. */
>          return -1;
>      }
>
> +    if (dlen > 8) {
> +        return -1;
> +    }
> +
>      buff[0] = 0x0f & frame->can_dlc; /* DLC */
>      if (frame->can_id & QEMU_CAN_RTR_FLAG) { /* RTR */
>          buff[0] |= (1 << 6);
> @@ -338,18 +343,18 @@ static int frame2buff_pel(const qemu_can_frame *frame, uint8_t *buff)
>          buff[2] = extract32(frame->can_id, 13, 8); /* ID.20~ID.13 */
>          buff[3] = extract32(frame->can_id, 5, 8);  /* ID.12~ID.05 */
>          buff[4] = extract32(frame->can_id, 0, 5) << 3; /* ID.04~ID.00,xxx */
> -        for (i = 0; i < frame->can_dlc; i++) {
> +        for (i = 0; i < dlen; i++) {
>              buff[5 + i] = frame->data[i];
>          }
> -        return frame->can_dlc + 5;
> +        return dlen + 5;
>      } else { /* SFF */
>          buff[1] = extract32(frame->can_id, 3, 8); /* ID.10~ID.03 */
>          buff[2] = extract32(frame->can_id, 0, 3) << 5; /* ID.02~ID.00,xxxxx */
> -        for (i = 0; i < frame->can_dlc; i++) {
> +        for (i = 0; i < dlen; i++) {
>              buff[3 + i] = frame->data[i];
>          }
>
> -        return frame->can_dlc + 3;
> +        return dlen + 3;
>      }
>
>      return -1;
> @@ -358,6 +363,7 @@ static int frame2buff_pel(const qemu_can_frame *frame, uint8_t *buff)
>  static int frame2buff_bas(const qemu_can_frame *frame, uint8_t *buff)
>  {
>      int i;
> +    int dlen = frame->can_dlc;
>
>       /*
>        * EFF, no support for BasicMode
> @@ -369,17 +375,21 @@ static int frame2buff_bas(const qemu_can_frame *frame, uint8_t *buff)
>          return -1;
>      }
>
> +    if (dlen > 8) {
> +        return -1;
> +    }
> +
>      buff[0] = extract32(frame->can_id, 3, 8); /* ID.10~ID.03 */
>      buff[1] = extract32(frame->can_id, 0, 3) << 5; /* ID.02~ID.00,xxxxx */
>      if (frame->can_id & QEMU_CAN_RTR_FLAG) { /* RTR */
>          buff[1] |= (1 << 4);
>      }
>      buff[1] |= frame->can_dlc & 0x0f;
> -    for (i = 0; i < frame->can_dlc; i++) {
> +    for (i = 0; i < dlen; i++) {
>          buff[2 + i] = frame->data[i];
>      }
>
> -    return frame->can_dlc + 2;
> +    return dlen + 2;
>  }
>
>  static void can_sja_update_pel_irq(CanSJA1000State *s)
> @@ -764,6 +774,13 @@ ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,
>      if (frames_cnt <= 0) {
>          return 0;
>      }
> +    if (frame->flags && QEMU_CAN_FRMF_TYPE_FD) {
> +        if (DEBUG_FILTER) {
> +            can_display_msg("[cansja]: ignor fd frame ", frame);
> +        }
> +        return 1;
> +    }
> +
>      if (DEBUG_FILTER) {
>          can_display_msg("[cansja]: receive ", frame);
>      }


  reply	other threads:[~2020-09-01 17:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 12:20 [PATCH v1 0/6] CTU CAN FD core support pisa
2020-07-14 12:20 ` [PATCH v1 1/6] net/can: Initial host SocketCan support for CAN FD pisa
2020-09-01 20:01   ` Vikram Garhwal
2020-09-02  7:51     ` Pavel Pisa
2020-09-03  5:20       ` Vikram Garhwal
2020-09-03  5:29         ` Vikram Garhwal
2020-07-14 12:20 ` [PATCH v1 2/6] hw/net/can: sja1000 ignore CAN FD frames pisa
2020-09-01 17:07   ` Vikram Garhwal [this message]
2020-07-14 12:20 ` [PATCH v1 3/6] net/can: Add can_dlc2len and can_len2dlc for CAN FD pisa
2020-09-03  5:43   ` Vikram Garhwal
2020-09-03  6:12     ` Pavel Pisa
2020-09-03  6:38       ` Vikram Garhwal
2020-07-14 12:20 ` [PATCH v1 4/6] hw/net/can/ctucafd: Add CTU CAN FD core register definitions pisa
2020-07-14 12:20 ` [PATCH v1 5/6] hw/net/can: CTU CAN FD IP open hardware core emulation pisa
2020-07-24  9:46   ` Pavel Pisa
2020-07-14 12:20 ` [PATCH v1 6/6] hw/net/can: Documentation for " pisa
2020-07-14 12:47 ` [PATCH v1 0/6] CTU CAN FD core support no-reply
2020-07-14 13:45   ` [PATCH v1 0/6] CTU CAN FD core support - patchew report Pavel Pisa
2020-07-14 12:48 ` [PATCH v1 0/6] CTU CAN FD core support no-reply
2020-07-30 15:29 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200901170733.GA151036@xilinx.com \
    --to=fnu.vikram@xilinx.com \
    --cc=armbru@redhat.com \
    --cc=charvj10@fel.cvut.cz \
    --cc=deniz.eren@icloud.com \
    --cc=frederic.konrad@adacore.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jnovak@fel.cvut.cz \
    --cc=marex@denx.de \
    --cc=o.rempel@pengutronix.de \
    --cc=ondrej.ille@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=pisa@cmp.felk.cvut.cz \
    --cc=qemu-devel@nongnu.org \
    --cc=socketcan@hartkopp.net \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.