qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <weil@mail.berlios.de>
To: QEMU Developers <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 09/20] eepro100: Use symbolic names and BIT macros in binary operations
Date: Sun, 14 Feb 2010 17:16:18 +0100	[thread overview]
Message-ID: <1266164189-21062-9-git-send-email-weil@mail.berlios.de> (raw)
In-Reply-To: <1266164189-21062-8-git-send-email-weil@mail.berlios.de>

Instead of magic numbers like 0x8000, symbolic names are used
for the SCB command and status bits.

There are too many configuration bits to use symbolic names
there, too. Using the BIT macro is a little help when comparing
code and documentation.

For the same reason, some other constants were replaced by
the BITS macro.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/eepro100.c |   52 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/hw/eepro100.c b/hw/eepro100.c
index 031fe69..1ce2cd1 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -172,6 +172,20 @@ typedef struct {
     char packet[MAX_ETH_FRAME_SIZE + 4];
 } eepro100_rx_t;
 
+typedef enum {
+    COMMAND_EL = BIT(15),
+    COMMAND_S = BIT(14),
+    COMMAND_I = BIT(13),
+    COMMAND_NC = BIT(4),
+    COMMAND_SF = BIT(3),
+    COMMAND_CMD = BITS(2, 0),
+} scb_command_bit;
+
+typedef enum {
+    STATUS_C = BIT(15),
+    STATUS_OK = BIT(13),
+} scb_status_bit;
+
 typedef struct {
     uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
         tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
@@ -753,22 +767,22 @@ enum commands {
 
 static cu_state_t get_cu_state(EEPRO100State * s)
 {
-    return ((s->mem[SCBStatus] >> 6) & 0x03);
+    return ((s->mem[SCBStatus] & BITS(7, 6)) >> 6);
 }
 
 static void set_cu_state(EEPRO100State * s, cu_state_t state)
 {
-    s->mem[SCBStatus] = (s->mem[SCBStatus] & 0x3f) + (state << 6);
+    s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(7, 6)) + (state << 6);
 }
 
 static ru_state_t get_ru_state(EEPRO100State * s)
 {
-    return ((s->mem[SCBStatus] >> 2) & 0x0f);
+    return ((s->mem[SCBStatus] & BITS(5, 2)) >> 2);
 }
 
 static void set_ru_state(EEPRO100State * s, ru_state_t state)
 {
-    s->mem[SCBStatus] = (s->mem[SCBStatus] & 0xc3) + (state << 2);
+    s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(5, 2)) + (state << 2);
 }
 
 static void dump_statistics(EEPRO100State * s)
@@ -898,13 +912,13 @@ static void action_command(EEPRO100State *s)
         uint16_t command = le16_to_cpu(s->tx.command);
         logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
                status, command, s->tx.link);
-        bool bit_el = ((command & 0x8000) != 0);
-        bool bit_s = ((command & 0x4000) != 0);
-        bool bit_i = ((command & 0x2000) != 0);
-        bool bit_nc = ((command & 0x0010) != 0);
+        bool bit_el = ((command & COMMAND_EL) != 0);
+        bool bit_s = ((command & COMMAND_S) != 0);
+        bool bit_i = ((command & COMMAND_I) != 0);
+        bool bit_nc = ((command & COMMAND_NC) != 0);
         bool success = true;
-        //~ bool bit_sf = ((command & 0x0008) != 0);
-        uint16_t cmd = command & 0x0007;
+        //~ bool bit_sf = ((command & COMMAND_SF) != 0);
+        uint16_t cmd = command & COMMAND_CMD;
         s->cu_offset = le32_to_cpu(s->tx.link);
         switch (cmd) {
         case CmdNOp:
@@ -941,7 +955,7 @@ static void action_command(EEPRO100State *s)
             break;
         }
         /* Write new status. */
-        stw_phys(s->cb_address, status | 0x8000 | (success ? 0x2000 : 0));
+        stw_phys(s->cb_address, status | STATUS_C | (success ? STATUS_OK : 0));
         if (bit_i) {
             /* CU completed action. */
             eepro100_cx_interrupt(s);
@@ -1684,13 +1698,13 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         /* CSMA is disabled. */
         logout("%p received while CSMA is disabled\n", s);
         return -1;
-    } else if (size < 64 && (s->configuration[7] & 1)) {
+    } else if (size < 64 && (s->configuration[7] & BIT(0))) {
         /* Short frame and configuration byte 7/0 (discard short receive) set:
          * Short frame is discarded */
         logout("%p received short frame (%zu byte)\n", s, size);
         s->statistics.rx_short_frame_errors++;
         //~ return -1;
-    } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) {
+    } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
         /* Long frame and configuration byte 18/3 (long receive ok) not set:
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
@@ -1713,7 +1727,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
           assert(mcast_idx < 64);
           if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) {
             /* Multicast frame is allowed in hash table. */
-          } else if (s->configuration[15] & 1) {
+          } else if (s->configuration[15] & BIT(0)) {
               /* Promiscuous: receive all. */
               rfd_status |= 0x0004;
           } else {
@@ -1723,7 +1737,7 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
         }
         /* TODO: Next not for promiscuous mode? */
         rfd_status |= 0x0002;
-    } else if (s->configuration[15] & 1) {
+    } else if (s->configuration[15] & BIT(0)) {
         /* Promiscuous: receive all. */
         TRACE(RXTX, logout("%p received frame in promiscuous mode, len=%zu\n", s, size));
         rfd_status |= 0x0004;
@@ -1764,23 +1778,23 @@ static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size
     /* Early receive interrupt not supported. */
     //~ eepro100_er_interrupt(s);
     /* Receive CRC Transfer not supported. */
-    if (s->configuration[18] & 4) {
+    if (s->configuration[18] & BIT(2)) {
         missing("Receive CRC Transfer");
         return -1;
     }
     /* TODO: check stripping enable bit. */
-    //~ assert(!(s->configuration[17] & 1));
+    //~ assert(!(s->configuration[17] & BIT(0)));
     cpu_physical_memory_write(s->ru_base + s->ru_offset +
                               offsetof(eepro100_rx_t, packet), buf, size);
     s->statistics.rx_good_frames++;
     eepro100_fr_interrupt(s);
     s->ru_offset = le32_to_cpu(rx.link);
-    if (rfd_command & 0x8000) {
+    if (rfd_command & COMMAND_EL) {
         /* EL bit is set, so this was the last frame. */
         logout("receive: Running out of frames\n");
         set_ru_state(s, ru_suspended);
     }
-    if (rfd_command & 0x4000) {
+    if (rfd_command & COMMAND_S) {
         /* S bit is set. */
         set_ru_state(s, ru_suspended);
     }
-- 
1.6.6.1

  reply	other threads:[~2010-02-14 16:17 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-14 16:15 [Qemu-devel] eepro100: New patch series adds full GPXE support Stefan Weil
2010-02-14 16:16 ` [Qemu-devel] [PATCH 01/20] eepro100: Fix compiler errors from debug messages Stefan Weil
2010-02-14 16:16   ` [Qemu-devel] [PATCH 02/20] eepro100: Add missing SCB register names Stefan Weil
2010-02-14 16:16     ` [Qemu-devel] [PATCH 03/20] eepro100: Fix PXE boot Stefan Weil
2010-02-14 16:16       ` [Qemu-devel] [PATCH 04/20] eepro100: Support gpxe boot for all eepro100 devices Stefan Weil
2010-02-14 16:16         ` [Qemu-devel] [PATCH 05/20] eepro100: Add all supported devices to pci.c Stefan Weil
2010-02-14 16:16           ` [Qemu-devel] [PATCH 06/20] eepro100: Add TODO list Stefan Weil
2010-02-14 16:16             ` [Qemu-devel] [PATCH 07/20] eepro100: Update copyright notice Stefan Weil
2010-02-14 16:16               ` [Qemu-devel] [PATCH 08/20] eepro100: Add device descriptions Stefan Weil
2010-02-14 16:16                 ` Stefan Weil [this message]
2010-02-14 16:16                   ` [Qemu-devel] [PATCH 10/20] eepro100: Remove old unused code Stefan Weil
2010-02-14 16:16                     ` [Qemu-devel] [PATCH 11/20] eepro100: Use symbolic names for bits in EEPROM id Stefan Weil
2010-02-14 16:16                       ` [Qemu-devel] [PATCH 12/20] eepro100: Replace variable name to fix a compiler warning Stefan Weil
2010-02-14 16:16                         ` [Qemu-devel] [PATCH 13/20] eepro100: Support RNR interrupt Stefan Weil
2010-02-14 16:16                           ` [Qemu-devel] [PATCH 14/20] eepro100: Fix CU Start command Stefan Weil
2010-02-14 16:16                             ` [Qemu-devel] [PATCH 15/20] eepro100: Prettify code (no functional changes) Stefan Weil
2010-02-14 16:16                               ` [Qemu-devel] [PATCH 16/20] eepro100: Use tx.status Stefan Weil
2010-02-14 16:16                                 ` [Qemu-devel] [PATCH 17/20] eepro100: New function for reading command block Stefan Weil
2010-02-14 16:16                                   ` [Qemu-devel] [PATCH 18/20] eepro100: Add diagnose command Stefan Weil
2010-02-14 16:16                                     ` [Qemu-devel] [PATCH 19/20] eepro100: Remove C++ comments Stefan Weil
2010-02-14 16:16                                       ` [Qemu-devel] [PATCH 20/20] eepro100: Keep includes sorted Stefan Weil
2010-02-21 17:05                       ` [Qemu-devel] Re: [PATCH 11/20] eepro100: Use symbolic names for bits in EEPROM id Michael S. Tsirkin
2010-02-21 21:38                         ` Stefan Weil
2010-02-22  9:00                           ` Michael S. Tsirkin
2010-03-02 18:42                       ` [Qemu-devel] " Stefan Weil
2010-02-21 17:00           ` [Qemu-devel] Re: [PATCH 05/20] eepro100: Add all supported devices to pci.c Michael S. Tsirkin
2010-02-21 21:08             ` Stefan Weil
2010-03-03 11:51               ` Michael S. Tsirkin
2010-03-03 13:31                 ` Gerd Hoffmann
2010-03-03 13:33                   ` Michael S. Tsirkin
2010-03-03 18:53                     ` Stefan Weil
2010-03-04  8:56                       ` Gerd Hoffmann
2010-03-02 18:43       ` [Qemu-devel] [PATCH 03/20] eepro100: Fix PXE boot Stefan Weil
2010-03-02 20:04         ` [Qemu-devel] " Michael S. Tsirkin
2010-02-19 21:05   ` [Qemu-devel] [PATCH 01/20] eepro100: Fix compiler errors from debug messages Anthony Liguori
2010-03-01 17:54     ` Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 " Stefan Weil
2010-03-03 11:52   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 02/20] eepro100: Add missing SCB register names Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 03/20] eepro100: Fix PXE boot Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 04/20] eepro100: Support gpxe boot for all eepro100 devices Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 05/20] eepro100: Add all supported devices to pci.c Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 06/20] eepro100: Add TODO list Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 07/20] eepro100: Update copyright notice Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 08/20] eepro100: Add device descriptions Stefan Weil
2010-03-03 11:49   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 09/20] eepro100: Use symbolic names and BIT macros in binary operations Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 10/20] eepro100: Remove old unused code Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 11/20] eepro100: Use symbolic names for bits in EEPROM id Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 12/20] eepro100: Replace variable name to fix a compiler warning Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 13/20] eepro100: Support RNR interrupt Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 14/20] eepro100: Fix CU Start command Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 15/20] eepro100: Prettify code (no functional changes) Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 16/20] eepro100: Use tx.status Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 17/20] eepro100: New function for reading command block Stefan Weil
2010-03-03 11:44   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 18/20] eepro100: Add diagnose command Stefan Weil
2010-03-02 21:37 ` [Qemu-devel] [PATCHv3 19/20] eepro100: Remove C++ comments Stefan Weil
2010-03-03 11:47   ` [Qemu-devel] " Michael S. Tsirkin
2010-03-03 19:15     ` Stefan Weil
2010-03-03 19:59       ` Michael S. Tsirkin
2010-03-02 21:38 ` [Qemu-devel] [PATCHv3 20/20] eepro100: Keep includes sorted Stefan Weil

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=1266164189-21062-9-git-send-email-weil@mail.berlios.de \
    --to=weil@mail.berlios.de \
    --cc=qemu-devel@nongnu.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).