Received: from eggs.gnu.org ([2001:4830:134:3::10]:48320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDt7H-0007vk-UU for qemu-devel@nongnu.org; Fri, 17 Jun 2016 08:43:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDt7D-0001QG-PU for qemu-devel@nongnu.org; Fri, 17 Jun 2016 08:43:18 -0400 Received: from 8.mo53.mail-out.ovh.net ([87.98.185.57]:44354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDt7D-0001Q3-Eh for qemu-devel@nongnu.org; Fri, 17 Jun 2016 08:43:15 -0400 Received: from player158.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo53.mail-out.ovh.net (Postfix) with ESMTP id 5CCF4FF9454 for ; Fri, 17 Jun 2016 14:43:14 +0200 (CEST) References: <1465998071-7355-1-git-send-email-marcin.krzeminski@nokia.com> <1465998071-7355-7-git-send-email-marcin.krzeminski@nokia.com> <57616564.1070404@kaod.org> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= Message-ID: Date: Fri, 17 Jun 2016 14:43:09 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] Odp.: [PATCH 6/9] m25p80: Introduce quad and equad modes. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Krzeminski, Marcin (Nokia - PL/Wroclaw)" , "qemu-devel@nongnu.org" Cc: "crosthwaitepeter@gmail.com" , "pawel.lenkow@itlen.com" , "peter.maydell@linaro.org" On 06/15/2016 07:40 PM, Krzeminski, Marcin (Nokia - PL/Wroclaw) wrote: >=20 >=20 > W dniu 15.06.2016 o 16:25, C=E9dric Le Goater pisze: >> On 06/15/2016 03:41 PM, marcin.krzeminski@nokia.com wrote: >>> From: Marcin Krzeminski >>> >>> Quad and Equad modes for Spansion and Macronix flash devices. >>> This commit also includes modification and new command to manipulate >>> quad mode (status registers and dedicated commands). >>> This work is based on Pawel Lenkow work. >>> >>> Signed-off-by: Marcin Krzeminski >>> --- >>> hw/block/m25p80.c | 70 +++++++++++++++++++++++++++++++++++++++++++++= ++++++---- >>> 1 file changed, 65 insertions(+), 5 deletions(-) >>> >>> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c >>> index 55b4377..d1c4d46 100644 >>> --- a/hw/block/m25p80.c >>> +++ b/hw/block/m25p80.c >>> @@ -281,6 +281,7 @@ typedef enum { >>> JEDEC_READ =3D 0x9f, >>> BULK_ERASE =3D 0xc7, >>> READ_FSR =3D 0x70, >>> + RDCR =3D 0x15, >>> >>> READ =3D 0x03, >>> READ4 =3D 0x13, >>> @@ -317,6 +318,13 @@ typedef enum { >>> RESET_ENABLE =3D 0x66, >>> RESET_MEMORY =3D 0x99, >>> >>> + /* >>> + * Micron: 0x35 - enable QPI >>> + * Spansion: 0x35 - read control register >>> + */ >>> + RDCR_EQIO =3D 0x35, >>> + RSTQIO =3D 0xf5, >>> + >>> RNVCR =3D 0xB5, >>> WNVCR =3D 0xB1, >>> >>> @@ -366,6 +374,7 @@ typedef struct Flash { >>> bool write_enable; >>> bool four_bytes_address_mode; >>> bool reset_enable; >>> + bool quad_enable; >>> uint8_t ear; >>> >>> int64_t dirty_page; >>> @@ -586,6 +595,16 @@ static void complete_collecting_data(Flash *s) >>> flash_erase(s, s->cur_addr, s->cmd_in_progress); >>> break; >>> case WRSR: >>> + switch (get_man(s)) { >>> + case MAN_SPANSION: >>> + s->quad_enable =3D !!(s->data[1] & 0x02); >>> + break; >>> + case MAN_MACRONIX: >>> + s->quad_enable =3D extract32(s->data[0], 6, 1); >>> + break; >>> + default: >>> + break; >>> + } >>> if (s->write_enable) { >>> s->write_enable =3D false; >>> } >>> @@ -619,6 +638,7 @@ static void reset_memory(Flash *s) >>> s->state =3D STATE_IDLE; >>> s->write_enable =3D false; >>> s->reset_enable =3D false; >>> + s->quad_enable =3D false; >>> >>> switch (get_man(s)) { >>> case MAN_NUMONYX: >>> @@ -747,10 +767,20 @@ static void decode_new_cmd(Flash *s, uint32_t v= alue) >>> >>> case WRSR: >>> if (s->write_enable) { >>> - s->needed_bytes =3D 1; >>> + switch (get_man(s)) { >>> + case MAN_SPANSION: >>> + s->needed_bytes =3D 2; >>> + s->state =3D STATE_COLLECTING_DATA; >>> + break; >>> + case MAN_MACRONIX: >>> + s->needed_bytes =3D 2; >>> + s->state =3D STATE_COLLECTING_VAR_LEN_DATA; >>> + break; >> >> ah. I am glad you address this topic because I am having a little issu= e >> with the mx25l25635e and the mx25l25635f. >> >> mx25l25635e is a macronix which supports the WRSR command with one byt= e=20 >> and the mx25l25635f needs two. The fun part is that they have the same >> JEDEC : 0xc22019. >> >> So not all macronix need 2 bytes. Should we add a flag for that ?=20 >> > I think this case should be partially handled with path 4 and this one. > The new state (patch 4) was introduced to allow use variable write cmds= . > As in my case mx66u51235f allow write up to 2 bytes, but linux writes o= nly one, > and that is allowed and works on real HW. From the datasheet mx25l25635= f > should behave exactly same way. > In case you mention, the problem might pop up, when guest will try > to write 2 bytes to mx25l25635e. Real HW will treat second byte as new = command, > but this model accept this situation. qemu complains a bit but that's OK. > Generally my approach and I think original author was to not emulate ex= actly > real hw behaviour but allow to model it in such way the quest can boot = up and use it. > If we go witch very restricted command behaviour we will end up in unre= adable code > (eg. newest Spansions/Cypress family does not support extended address = register, > but such commands will work in this model). The question is if you real= ly need to flag > and support this. If yes additional if is not a problem. I will wait for your patchset to be merged and then see if the mx25l25635= f needs anything more. This is really minor. It should be a onliner. Thanks, C.=20 >> >>> + default: >>> + s->needed_bytes =3D 1; >>> + s->state =3D STATE_COLLECTING_DATA; >>> + } >>> s->pos =3D 0; >>> - s->len =3D 0; >>> - s->state =3D STATE_COLLECTING_DATA; >>> } >>> break; >>> >>> @@ -763,6 +793,9 @@ static void decode_new_cmd(Flash *s, uint32_t val= ue) >>> >>> case RDSR: >>> s->data[0] =3D (!!s->write_enable) << 1; >>> + if (get_man(s) =3D=3D MAN_MACRONIX) { >>> + s->data[0] |=3D (!!s->quad_enable) << 6; >>> + } >>> s->pos =3D 0; >>> s->len =3D 1; >>> s->state =3D STATE_READING_DATA; >>> @@ -789,6 +822,14 @@ static void decode_new_cmd(Flash *s, uint32_t va= lue) >>> s->state =3D STATE_READING_DATA; >>> break; >>> >>> + case RDCR: >>> + s->data[0] =3D s->volatile_cfg & 0xFF; >>> + s->data[0] |=3D (!!s->four_bytes_address_mode) << 5; >>> + s->pos =3D 0; >>> + s->len =3D 1; >>> + s->state =3D STATE_READING_DATA; >>> + break; >>> + >>> case BULK_ERASE: >>> if (s->write_enable) { >>> DB_PRINT_L(0, "chip erase\n"); >>> @@ -828,7 +869,7 @@ static void decode_new_cmd(Flash *s, uint32_t val= ue) >>> s->state =3D STATE_READING_DATA; >>> break; >>> case WNVCR: >>> - if (s->write_enable) { >>> + if (s->write_enable && get_man(s) =3D=3D MAN_NUMONYX) { >>> s->needed_bytes =3D 2; >>> s->pos =3D 0; >>> s->len =3D 0; >>> @@ -871,6 +912,24 @@ static void decode_new_cmd(Flash *s, uint32_t va= lue) >>> reset_memory(s); >>> } >>> break; >>> + case RDCR_EQIO: >>> + switch (get_man(s)) { >>> + case MAN_SPANSION: >>> + s->data[0] =3D (!!s->quad_enable) << 1; >>> + s->pos =3D 0; >>> + s->len =3D 1; >>> + s->state =3D STATE_READING_DATA; >>> + break; >>> + case MAN_MACRONIX: >>> + s->quad_enable =3D true; >>> + break; >>> + default: >>> + break; >>> + } >>> + break; >>> + case RSTQIO: >>> + s->quad_enable =3D false; >>> + break; >>> default: >>> qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", v= alue); >>> break; >>> @@ -999,7 +1058,7 @@ static Property m25p80_properties[] =3D { >>> >>> static const VMStateDescription vmstate_m25p80 =3D { >>> .name =3D "xilinx_spi", >>> - .version_id =3D 2, >>> + .version_id =3D 3, >>> .minimum_version_id =3D 1, >>> .pre_save =3D m25p80_pre_save, >>> .fields =3D (VMStateField[]) { >>> @@ -1017,6 +1076,7 @@ static const VMStateDescription vmstate_m25p80 = =3D { >>> VMSTATE_UINT32_V(nonvolatile_cfg, Flash, 2), >>> VMSTATE_UINT32_V(volatile_cfg, Flash, 2), >>> VMSTATE_UINT32_V(enh_volatile_cfg, Flash, 2), >>> + VMSTATE_BOOL_V(quad_enable, Flash, 3), >>> VMSTATE_END_OF_LIST() >>> } >>> }; >>> >> >> >> >=20