qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Sven Schnelle <svens@stackframe.org>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Fam Zheng <fam@euphon.net>,
	"open list:All patches CC here" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 3/5] lsi: use enum type for s->msg_action
Date: Tue, 5 Mar 2019 00:14:22 +0100	[thread overview]
Message-ID: <aedf9eef-8048-e5b3-10a0-eafe790caf5a@redhat.com> (raw)
In-Reply-To: <20190304180920.21534-3-svens@stackframe.org>

On 3/4/19 7:09 PM, Sven Schnelle wrote:
> This makes the code easier to read - no functional change.
> 
> Signed-off-by: Sven Schnelle <svens@stackframe.org>
> ---
>  hw/scsi/lsi53c895a.c | 27 ++++++++++++++++-----------
>  1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
> index fb9c6db4b2..d1eb2cf074 100644
> --- a/hw/scsi/lsi53c895a.c
> +++ b/hw/scsi/lsi53c895a.c
> @@ -201,6 +201,13 @@ enum {
>      LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
>  };
>  
> +enum {
Since someone unfamiliar with the device could add:

       LSI_MSG_ACTION_DEBUG,

> +    LSI_MSG_ACTION_COMMAND,
> +    LSI_MSG_ACTION_DISCONNECT,
> +    LSI_MSG_ACTION_DOUT,
> +    LSI_MSG_ACTION_DIN,

... it is safer to assign values when enum are not expected to change:

      LSI_MSG_ACTION_COMMAND = 0,
      LSI_MSG_ACTION_DISCONNECT = 1,
      LSI_MSG_ACTION_DOUT = 2,
      LSI_MSG_ACTION_DIN = 3,

With that change:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +};
> +
>  typedef struct {
>      /*< private >*/
>      PCIDevice parent_obj;
> @@ -214,8 +221,6 @@ typedef struct {
>  
>      int carry; /* ??? Should this be an a visible register somewhere?  */
>      int status;
> -    /* Action to take at the end of a MSG IN phase.
> -       0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN.  */
>      int msg_action;
>      int msg_len;
>      uint8_t msg[LSI_MAX_MSGIN_LEN];
> @@ -323,7 +328,7 @@ static void lsi_soft_reset(LSIState *s)
>      trace_lsi_reset();
>      s->carry = 0;
>  
> -    s->msg_action = 0;
> +    s->msg_action = LSI_MSG_ACTION_COMMAND;
>      s->msg_len = 0;
>      s->waiting = LSI_NOWAIT;
>      s->dsa = 0;
> @@ -686,7 +691,7 @@ static void lsi_reselect(LSIState *s, lsi_request *p)
>      trace_lsi_reselect(id);
>      s->scntl1 |= LSI_SCNTL1_CON;
>      lsi_set_phase(s, PHASE_MI);
> -    s->msg_action = p->out ? 2 : 3;
> +    s->msg_action = p->out ? LSI_MSG_ACTION_DOUT : LSI_MSG_ACTION_DIN;
>      s->current->dma_len = p->pending;
>      lsi_add_msg_byte(s, 0x80);
>      if (s->current->tag & LSI_TAG_VALID) {
> @@ -857,7 +862,7 @@ static void lsi_do_command(LSIState *s)
>              lsi_add_msg_byte(s, 4); /* DISCONNECT */
>              /* wait data */
>              lsi_set_phase(s, PHASE_MI);
> -            s->msg_action = 1;
> +            s->msg_action = LSI_MSG_ACTION_DISCONNECT;
>              lsi_queue_command(s);
>          } else {
>              /* wait command complete */
> @@ -878,7 +883,7 @@ static void lsi_do_status(LSIState *s)
>      s->sfbr = status;
>      pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1);
>      lsi_set_phase(s, PHASE_MI);
> -    s->msg_action = 1;
> +    s->msg_action = LSI_MSG_ACTION_DISCONNECT;
>      lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
>  }
>  
> @@ -901,16 +906,16 @@ static void lsi_do_msgin(LSIState *s)
>          /* ??? Check if ATN (not yet implemented) is asserted and maybe
>             switch to PHASE_MO.  */
>          switch (s->msg_action) {
> -        case 0:
> +        case LSI_MSG_ACTION_COMMAND:
>              lsi_set_phase(s, PHASE_CMD);
>              break;
> -        case 1:
> +        case LSI_MSG_ACTION_DISCONNECT:
>              lsi_disconnect(s);
>              break;
> -        case 2:
> +        case LSI_MSG_ACTION_DOUT:
>              lsi_set_phase(s, PHASE_DO);
>              break;
> -        case 3:
> +        case LSI_MSG_ACTION_DIN:
>              lsi_set_phase(s, PHASE_DI);
>              break;
>          default:
> @@ -1062,7 +1067,7 @@ bad:
>      qemu_log_mask(LOG_UNIMP, "Unimplemented message 0x%02x\n", msg);
>      lsi_set_phase(s, PHASE_MI);
>      lsi_add_msg_byte(s, 7); /* MESSAGE REJECT */
> -    s->msg_action = 0;
> +    s->msg_action = LSI_MSG_ACTION_COMMAND;
>  }
>  
>  #define LSI_BUF_SIZE 4096
> 

  reply	other threads:[~2019-03-04 23:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-04 18:09 [Qemu-devel] [PATCH 1/5] lsi: use ldn_le_p()/stn_le_p() Sven Schnelle
2019-03-04 18:09 ` [Qemu-devel] [PATCH 2/5] lsi: use enum type for s->waiting Sven Schnelle
2019-03-04 23:18   ` Philippe Mathieu-Daudé
2019-03-05  7:17     ` Sven Schnelle
2019-03-05 12:07       ` Philippe Mathieu-Daudé
2019-03-04 18:09 ` [Qemu-devel] [PATCH 3/5] lsi: use enum type for s->msg_action Sven Schnelle
2019-03-04 23:14   ` Philippe Mathieu-Daudé [this message]
2019-03-04 23:22     ` Philippe Mathieu-Daudé
2019-03-04 18:09 ` [Qemu-devel] [PATCH 4/5] lsi: use SCSI phase names instead of numbers in trace Sven Schnelle
2019-03-04 23:10   ` Philippe Mathieu-Daudé
2019-03-04 18:09 ` [Qemu-devel] [PATCH 5/5] lsi: return dfifo value Sven Schnelle
2019-03-04 18:40 ` [Qemu-devel] [PATCH 1/5] lsi: use ldn_le_p()/stn_le_p() Eric Blake
2019-03-04 20:38   ` Sven Schnelle
2019-03-04 21:15     ` Eric Blake
2019-03-04 23:21 ` Philippe Mathieu-Daudé

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=aedf9eef-8048-e5b3-10a0-eafe790caf5a@redhat.com \
    --to=philmd@redhat.com \
    --cc=fam@euphon.net \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=svens@stackframe.org \
    /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 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).