Received: from eggs.gnu.org ([2001:4830:134:3::10]:54668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYj6g-0007qu-Sc for qemu-devel@nongnu.org; Fri, 11 Apr 2014 17:35:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYj6b-0004pe-CL for qemu-devel@nongnu.org; Fri, 11 Apr 2014 17:35:30 -0400 Received: from indium.canonical.com ([91.189.90.7]:52163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYj6b-0004pS-4s for qemu-devel@nongnu.org; Fri, 11 Apr 2014 17:35:25 -0400 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.76 #1 (Debian)) id 1WYj6a-0007kW-2h for ; Fri, 11 Apr 2014 21:35:24 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 049402E80CC for ; Fri, 11 Apr 2014 21:35:24 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Fri, 11 Apr 2014 21:29:30 -0000 From: Sunha Ahn Sender: bounces@canonical.com References: <20140411212931.9215.60239.malonedeb@gac.canonical.com> Message-Id: <20140411212931.9215.60239.malonedeb@gac.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 1306818] [NEW] resetting moder register in opencores_eth.c code (ethernet IP core specification code) Reply-To: Bug 1306818 <1306818@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Public bug reported: Hi, I would like to report a possible error in the code qemu/hw/net/opencores_eth.c The corresponding data sheet : http://www.cprover.org/firmware/doc/ethoc/eth_speci.pdf In the code, there is a function open_eth_moder_host_write. = static void open_eth_moder_host_write(OpenEthState *s, uint32_t val) { uint32_t set =3D val & ~s->regs[MODER]; if (set & MODER_RST) { open_eth_reset(s); } s->regs[MODER] =3D val; if (set & MODER_RXEN) { s->rx_desc =3D s->regs[TX_BD_NUM]; open_eth_notify_can_receive(s); } if (set & MODER_TXEN) { s->tx_desc =3D 0; open_eth_check_start_xmit(s); } } This piece of code is executed when MODER (Mode Register) resister is command to updated to =E2=80=98val=E2=80=99. In case of reset, as you can see, if the MODER_RST bit (0x800) bit is set &= & the old MODER_RST bit (0x800) of MODER register is clear, the code falls = into the if(set & MODER_RST) branch. Then, it calls open_eth_reset(s), whic= h does =E2=80=9Cs->regs[MODER] =3D 0xa000;=E2=80=9D. Now, the MODER registe= r is reset to 0xa000. Page 9 of the data sheet (http://www.cprover.org/firm= ware/doc/ethoc/eth_speci.pdf) specifies the reset value of the moder is 000= 0A000h. So far, the code works fine. = Then, the open_eth_moder_host_write function does not end but executes but = executes =E2=80=9Cs->regs[MODER] =3D val;=E2=80=9D line. Now, the MODER reg= ister is not 0xa000 any more. = In fact, since the MODER_RST bit of =E2=80=98val=E2=80=99 is 1, now the MOD= ER_RST bit of the MODER register becomes 1 as well. Suppose one somehow cal= ls this open_eth_moder_host_write again with val =3D MODER_RST with purpos= e of resetting again. Since the MODER_RST bit is 1, (set =3D val & ~s->regs= [MODER]) & MODER_RST is zero. So after this, resetting again is not possibl= e. = Hence, I doubt the function=E2=80=99s correctness here. I think it could be better if the function changes to : if (set & MODER_RST) { open_eth_reset(s); return; } Please let me know if I am correct. ** Affects: qemu Importance: Undecided Status: New -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1306818 Title: resetting moder register in opencores_eth.c code (ethernet IP core specification code) Status in QEMU: New Bug description: Hi, I would like to report a possible error in the code qemu/hw/net/opencores_eth.c The corresponding data sheet : http://www.cprover.org/firmware/doc/ethoc/eth_speci.pdf = In the code, there is a function open_eth_moder_host_write. = static void open_eth_moder_host_write(OpenEthState *s, uint32_t val) { uint32_t set =3D val & ~s->regs[MODER]; if (set & MODER_RST) { open_eth_reset(s); } s->regs[MODER] =3D val; if (set & MODER_RXEN) { s->rx_desc =3D s->regs[TX_BD_NUM]; open_eth_notify_can_receive(s); } if (set & MODER_TXEN) { s->tx_desc =3D 0; open_eth_check_start_xmit(s); } } This piece of code is executed when MODER (Mode Register) resister is command to updated to =E2=80=98val=E2=80=99. In case of reset, as you can see, if the MODER_RST bit (0x800) bit is set= && the old MODER_RST bit (0x800) of MODER register is clear, the code fall= s into the if(set & MODER_RST) branch. Then, it calls open_eth_reset(s), wh= ich does =E2=80=9Cs->regs[MODER] =3D 0xa000;=E2=80=9D. Now, the MODER regis= ter is reset to 0xa000. Page 9 of the data sheet (http://www.cprover.org/fi= rmware/doc/ethoc/eth_speci.pdf) specifies the reset value of the moder is 0= 000A000h. So far, the code works fine. = Then, the open_eth_moder_host_write function does not end but executes bu= t executes =E2=80=9Cs->regs[MODER] =3D val;=E2=80=9D line. Now, the MODER r= egister is not 0xa000 any more. = In fact, since the MODER_RST bit of =E2=80=98val=E2=80=99 is 1, now the M= ODER_RST bit of the MODER register becomes 1 as well. Suppose one somehow c= alls this open_eth_moder_host_write again with val =3D MODER_RST with purp= ose of resetting again. Since the MODER_RST bit is 1, (set =3D val & ~s->re= gs[MODER]) & MODER_RST is zero. So after this, resetting again is not possi= ble. = Hence, I doubt the function=E2=80=99s correctness here. I think it could = be better if the function changes to : if (set & MODER_RST) { open_eth_reset(s); return; } Please let me know if I am correct. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1306818/+subscriptions