From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=anoo@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yC7T20QFJzDr67 for ; Thu, 12 Oct 2017 09:10:13 +1100 (AEDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9BM8hUm125858 for ; Wed, 11 Oct 2017 18:10:11 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0b-001b2d01.pphosted.com with ESMTP id 2dhs4pen84-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 11 Oct 2017 18:10:10 -0400 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 11 Oct 2017 18:10:09 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 11 Oct 2017 18:10:07 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9BMA7of58392716; Wed, 11 Oct 2017 22:10:07 GMT Received: from localhost (unknown [127.0.0.1]) by IMSVA (Postfix) with SMTP id DC0FD112034; Wed, 11 Oct 2017 18:09:41 -0400 (EDT) X-IMSS-HAND-OFF-DIRECTIVE: 127.0.0.1:10026 Received: from adriana-mbp.austin.ibm.com (unknown [9.53.179.190]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTPS id 4C3B3112051; Wed, 11 Oct 2017 18:09:22 -0400 (EDT) From: Adriana Kobylak Content-Type: multipart/alternative; boundary="Apple-Mail=_CB7D46C2-EB63-428E-A6BF-A993BA5AE43F" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH] docs: Specify V3 of the mbox protocol Date: Wed, 11 Oct 2017 17:07:37 -0500 In-Reply-To: <1507183803.5452.58.camel@aj.id.au> Cc: Suraj Jitindar Singh , skiboot@lists.ozlabs.org, openbmc@lists.ozlabs.org, stewart@linux.vnet.ibm.com, cyrilbur@gmail.com, wak@google.com To: Andrew Jeffery References: <20171004004520.18593-1-sjitindarsingh@gmail.com> <1507183803.5452.58.camel@aj.id.au> X-Mailer: Apple Mail (2.3273) X-TM-AS-GCONF: 00 x-cbid: 17101122-0036-0000-0000-0000027A3AEF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007880; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000236; SDB=6.00929772; UDB=6.00467990; IPR=6.00710044; BA=6.00005634; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017496; XFM=3.00000015; UTC=2017-10-11 22:10:09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101122-0037-0000-0000-0000420BFDF6 Message-Id: <4ADF6D39-02A8-4567-8ED5-5A1B206B1CE3@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-11_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710110298 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Oct 2017 22:10:15 -0000 --Apple-Mail=_CB7D46C2-EB63-428E-A6BF-A993BA5AE43F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Acked-by: Adriana Kobylak .com = > > On Oct 5, 2017, at 1:10 AM, Andrew Jeffery wrote: >=20 > On Wed, 2017-10-04 at 11:45 +1100, Suraj Jitindar Singh wrote: >> Version 3 of the mbox protocol makes four protocol changes: >> - Add a requested block size argument to GET_MBOX_INFO >> - Add a no erase argument to MARK_DIRTY >> - Add a GET_FLASH_NAME command and support multiple flash devices >> - Add a MARK_LOCKED command >>=20 >> Requested Block Size: >> The requested block size argument has been added to the GET_MBOX_INFO >> command to allow the host to request a specified block size which = might >> be required to allow data manipulation at a finer granularity. The >> daemon should take this into account when choosing a block size for = use >> which it will specify in the response as before. The daemon has final >> say and the host must use the block size the daemon chooses. >>=20 >> No Erase: >> The no erase argument to the mark dirty command allows a host to = specify >> that an area of flash should not be erased before being written to, = as is >> the default behaviour. This can be used when a host has already = erased a >> large area and then performs many small writes which would normally = mean >> many erases due to the implicit erase before write, making this slow. >>=20 >> Add GET_FLASH_NAME command: >> The ability to support multiple flash devices has been added so that = the >> mbox protocol can be used to arbitrate access from the host to a = number >> of flash devices which the daemon has access to. To facilitate this = the >> GET_FLASH_INFO, CREATE_{READ/WRITE}_WINDOW, and MARK_LOCKED commands = now >> take a flash ID, with the number of flash IDs allocated returned by = the >> GET_MBOX_INFO commands. There is also a new command GET_FLASH_NAME = used >> to convert a flash ID to a flash name. >>=20 >> Add MARK_LOCKED command: >> The MARK_LOCKED command has been added to allow an area(s) of flash = to be >> locked, that is that area must be treated as read only and the host = is >> not allowed to dirty or erase any windows which map that area of = flash. >> Additionally another error code LOCKED_ERROR was added to be returned >> when the host does try to dirty or erase a locked area. >>=20 >> The host cannot lock a currently dirty or erased area of the current >> write window as it is not defined if the clean/dirty/erased value is >> what should actually be "locked". >>=20 >> A locked area of flash remains so until the daemon receives an >> mboxctl --clear-locked command and the locked areas are stored in a = file >> on the BMC filesystem to ensure persistence across BMC reboots/daemon >> crashes. >>=20 >> Multiple flash device support proposed and defined by: >>> William A. Kennington III >>=20 >> Change-Id: I898698840dec221ae20e33943bb28e65abc4fe37 >> Signed-off-by: Suraj Jitindar Singh >=20 > Reviewed-by: Andrew Jeffery > >=20 > But everyone else: please chime in. >=20 > Cheers, >=20 > Andrew >=20 >> --- >> Documentation/mbox_protocol.md | 163 = ++++++++++++++++++++++++++++++++--------- >> 1 file changed, 127 insertions(+), 36 deletions(-) >>=20 >> diff --git a/Documentation/mbox_protocol.md = b/Documentation/mbox_protocol.md >> index bcd70a8..797ac7b 100644 >> --- a/Documentation/mbox_protocol.md >> +++ b/Documentation/mbox_protocol.md >> @@ -17,19 +17,22 @@ limitations under the License. >> This document describes a protocol for host to BMC communication via = the >> mailbox registers present on the Aspeed 2400 and 2500 chips. >> This protocol is specifically designed to allow a host to request = and manage >> -access to the flash with the specifics of how the host is required = to control >> -this described below. >> +access to a flash device(s) with the specifics of how the host is = required to >> +control this described below. >> =20 >> ## Version >> =20 >> -Both version 1 and version 2 of the protocol are described below = with version 2 >> -specificities represented with V2 in brackets - (V2). >> +Version specific protocol functionalities are represented by the = version number >> +in brackets next to the definition of the functionality. (e.g. (V2) = for version >> +2 specific funtionality). All version specific functionality must = also be >> +implemented by proceeding versions up to and not including the = version a command >> +was removed. >> =20 >> ## Problem Overview >> =20 >> "mbox" is the name we use to represent a protocol we have = established between >> the host and the BMC via the Aspeed mailbox registers. This protocol = is used >> -for the host to control the flash. >> +for the host to control access to the flash device(s). >> =20 >> Prior to the mbox protocol, the host uses a backdoor into the BMC = address space >> (the iLPC-to-AHB bridge) to directly manipulate the BMCs own flash = controller. >> @@ -215,9 +218,11 @@ communicate a change in state. >> Given that a majority of command and response arguments are = specified as a >> multiple of block size it is necessary for the host and BMC to agree = on a >> protocol version as this determines the block size. In V1 it is hard = coded at >> -4K and in V2 the BMC chooses and specifies this to the host as a = response >> -argument to `MBOX_GET_INFO`. Thus the host must always call = `MBOX_GET_INFO` >> -before any other command which specifies an argument in block size. >> +4K, in V2 the BMC chooses and in V3 the host is allowed to request a = specific >> +block size with the actual size chosen communicated back to the host = as a >> +response argument to `MBOX_GET_INFO`. Thus the host must always call >> +`MBOX_GET_INFO` before any other command which specifies an argument = in block >> +size. >> =20 >> When invoking `MBOX_GET_INFO` the host must provide the BMC its = highest >> supported version of the protocol. The BMC must respond with a = protocol version >> @@ -231,10 +236,13 @@ version by issuing a subsequent `MBOX_GET_INFO` = command. >> ### Window Management >> =20 >> In order to access flash contents, the host must request a window be = opened at >> -the flash offset it would like to access. The host may give a hint = as to how >> -much data it would like to access or otherwise set this argument to = zero. The >> -BMC must respond with the LPC bus address to access this window and = the >> -window size. The host must not access past the end of the active = window. >> +the flash offset it would like to access with the = CREATE_{READ,WRITE}_WINDOW >> +commands. The host may give a hint as to how much data it would like = to access >> +or otherwise set this argument to zero. The BMC must respond with = the LPC bus >> +address to access this window and the window size. The host must not = access >> +past the end of the active window. On returning success to either of = the create >> +window commands the BMC must guarantee that the window provided = contains data >> +which correctly represents the state of flash at the time the = response is given. >> =20 >> There is only ever one active window which is the window created by = the most >> recent CREATE_READ_WINDOW or CREATE_WRITE_WINDOW call which = succeeded. Even >> @@ -278,7 +286,19 @@ contents cannot be guaranteed. >> =20 >> The host is not required to perform an erase before a write command = and the >> BMC must ensure that a write performs as expected - that is if an = erase is >> -required before a write then the BMC must perform this itself. >> +required before a write then the BMC must perform this itself = (unless the >> +no_erase flag is set in the MARK_WRITE_DIRTY command in which case = the BMC will >> +blindly write without a prior erase (V3)). >> + >> +The host may lock an area of flash using the MARK_LOCKED command. = Any attempt >> +to mark dirty or erased this area of flash must fail with the = LOCKED_ERROR >> +response code. The host may open a write window which contains a = locked area >> +of flash however changes to a locked area of flash must never be = written back >> +to the backing data source (i.e. that area of flash must be treated = as read >> +only with respect to the backing store at all times). An attempt to = lock an area >> +of flash which is not clean in the current window must fail with = PARAM_ERROR. >> +Locked flash regions must persist across a BMC reboot or daemon = restart. It is >> +only possible to clear the lock state through a clear_locked dbus = command. (V3) >> =20 >> ### BMC Events >> =20 >> @@ -316,6 +336,8 @@ MARK_WRITE_DIRTY 0x07 >> WRITE_FLUSH 0x08 >> BMC_EVENT_ACK 0x09 >>> MARK_WRITE_ERASED 0x0a (V2) >>> +GET_FLASH_NAME 0x0b (V3) >>> +MARK_LOCKED 0x0c (V3) >> ``` >> =20 >> ### Responses >>> @@ -329,13 +351,14 @@ TIMEOUT 5 >>>> BUSY 6 (V2) >>>> WINDOW_ERROR 7 (V2) >>>> SEQ_ERROR 8 (V2) >>>> +LOCKED_ERROR 9 (V3) >> ``` >> =20 >> ### Sequence Numbers >> =20 >> Sequence numbers are included in messages for correlation of = commands and >> -responses. V1 and V2 of the protocol permit either zero or one = commands to be >> -in progress (yet to receive a response). >> +responses. V1, V2 and V3 of the protocol permit either zero or one = commands to >> +be in progress (yet to receive a response). >> =20 >> For generality, the host must generate a sequence number that is = unique with >> respect to the previous command (one that has received a response) = and any >>> @@ -368,6 +391,10 @@ BUSY - Daemon in suspended state = (currently unable to access flash) >>> WINDOW_ERROR - Command not valid for active window or no = active window >>> - Try opening an appropriate window and retrying the = command >> =20 >>> +SEQ_ERROR - Invalid sequence number supplied with command >> + >>> +LOCKED_ERROR - Tried to mark dirty or erased locked area of = flash >> + >> ### Information >> - All multibyte messages are LSB first (little endian) >> - All responses must have a valid return code in byte 13 >> @@ -381,6 +408,12 @@ allows us to specify larger values with fewer = command and response fields. >> =20 >> In V1 block size is hard coded to 4K. >> In V2 it is variable and must be queried with the GET_MBOX_INFO = command. >> +In V3 the host can request a given block size however it is = ultimately up to >> +the daemon to choose a block size which is returned as part of the = GET_MBOX_INFO >> +command response. The host must respect the daemons choice. The = ability for the >> +host to request a block size is provided such that it can choose an = appropriate >> +size to be able to utilise commands which only operate at the block = level. >> + >> Note that for simplicity block size must always be a power-of-2. >> Block size must also be greater than or equal to 4K. This is due to = the >> fact that we have a 28-bit LPC address space and commands which = return an >> @@ -395,8 +428,7 @@ multiplying by the block size. >> ``` >> Command: >>> RESET_STATE >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> - >>> Response: >> @@ -409,8 +441,7 @@ Command: >> =20 >> Command: >>> GET_MBOX_INFO >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> V1: >>> Args 0: API version >> @@ -418,6 +449,10 @@ Command: >>> V2: >>> Args 0: API version >> =20 >>> + V3: >>> + Args 0: API version >>> + Args 1: Requested block size (shift) >> + >>> Response: >>> V1: >>> Args 0: API version >> @@ -430,6 +465,14 @@ Command: >>> Args 3-4: reserved >>> Args 5: Block size as power of two (encoded as a shift) >>> Args 6-7: Suggested Timeout (seconds) >> + >>> + V3: >>> + Args 0: API version >>> + Args 1-2: reserved >>> + Args 3-4: reserved >>> + Args 5: Block size as power of two (encoded as a shift) >>> + Args 6-7: Suggested Timeout (seconds) >>> + Args 8: Num Allocated Flash IDs >>> Notes: >>> The suggested timeout is a hint to the host as to how = long >>> it should wait after issuing a command to the BMC before = it >> @@ -439,25 +482,34 @@ Command: >>>> the BMC does not wish to provide a hint in which case = the host >>> must choose some reasonable value. >> =20 >>> + The host may desire a specific block size and thus can = request >>> + this by giving a hint to the daemon (may be zero). The = daemon >>> + may use this to select the block size which it will use = however >>> + is free to ignore it. The value in the response is the = block >>> + size which must be used for all further requests until a = new >>>> + size is negotiated by another call to GET_MBOX_INFO. = (V3) >> + >> Command: >>> GET_FLASH_INFO >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> + V1, V2: >>> - >> + >>> + V3: >>> + Args 0: Flash ID >>> Response: >>> V1: >>> Args 0-3: Flash size (bytes) >>> Args 4-7: Erase granule (bytes) >> =20 >>> - V2: >>> + V2, V3: >>> Args 0-1: Flash size (blocks) >>> Args 2-3: Erase granule (blocks) >> =20 >> Command: >>> CREATE_{READ/WRITE}_WINDOW >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> V1: >>> Args 0-1: Requested flash offset (blocks) >> @@ -466,11 +518,15 @@ Command: >>> Args 0-1: Requested flash offset (blocks) >>> Args 2-3: Requested flash size to access (blocks) >> =20 >>> + V3: >>> + Args 0-1: Requested flash offset (blocks) >>> + Args 2-3: Requested flash size to access (blocks) >>> + Args 4: Flash ID >>> Response: >>> V1: >>> Args 0-1: LPC bus address of window (blocks) >> =20 >>> - V2: >>> + V2, V3: >>> Args 0-1: LPC bus address of window (blocks) >>> Args 2-3: Window size (blocks) >>> Args 4-5: Flash offset mapped by window (blocks) >> @@ -505,8 +561,7 @@ Command: >> =20 >> Command: >>> CLOSE_WINDOW >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> V1: >>> - >> @@ -534,8 +589,7 @@ Command: >> =20 >> Command: >>> MARK_WRITE_DIRTY >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> V1: >>> Args 0-1: Flash offset to mark from base of flash = (blocks) >> @@ -544,6 +598,7 @@ Command: >>> V2: >>> Args 0-1: Window offset to mark (blocks) >>> Args 2-3: Number to mark dirty at offset (blocks) >>> + Args 4 : Don't Erase Before Write (V3) >> =20 >>> Response: >>> - >> @@ -558,10 +613,16 @@ Command: >>> block. If the offset + number exceeds the size of the = active >>> window then the command must not succeed. >> =20 >>> + The host can give a hint to the daemon that is doesn't = have to >>> + erase a flash area before writing to it by setting = ARG[4]. This >>> + means that the daemon will blindly perform a write to = that area >>> + and will not try to erase it before hand. This can be = used if >>> + the host knows that a large area has already been erased = for >>> + example but then wants to perform many small writes. >> + >> Command >>> WRITE_FLUSH >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>> V1: >>> Args 0-1: Flash offset to mark from base of flash = (blocks) >> @@ -586,8 +647,7 @@ Command >> =20 >> Command: >>> BMC_EVENT_ACK >>> - Implemented in Versions: >>> - V1, V2 >>>> + Added in: V1 >>> Arguments: >>>> Args 0: Bits in the BMC status byte (mailbox data >>> register 15) to ack >> @@ -599,8 +659,7 @@ Command: >> =20 >> Command: >>> MARK_WRITE_ERASED >>> - Implemented in Versions: >>> - V2 >>>> + Added in: V2 >>> Arguments: >>> V2: >>> Args 0-1: Window offset to erase (blocks) >> @@ -617,6 +676,38 @@ Command: >>> number is the number of blocks of the active window to = erase >>> starting at offset. If the offset + number exceeds the = size of >>> the active window then the command must not succeed. >> + >> +Command: >>> + GET_FLASH_NAME >>>> + Added in: V3 >>> + Arguments: >>> + Args 0: Flash ID >>> + Response: >>> + Args 0 : Flash Name Length (bytes) >>> + Args 1-10: Flash Name / UID >>> + Notes: >>> + Describes a flash with some kind of identifier useful to = the >>> + host system. This is typically a null-padded string. >> + >>> + The length in the response is the number of response = arguments >>> + as part of the flash name field which the host should = expect to >>> + have been populated. >> + >> +Command: >>> + MARK_LOCKED >>>> + Added in: V3 >>> + Arguments: >>> + Args 0-1: Flash offset to lock (blocks) >>> + Args 2-3: Number to lock at offset (blocks) >>> + Args 4: Flash ID >>> + Response: >>> + - >>> + Notes: >>> + Lock an area of flash so that the host can't mark it = dirty or >>> + erased. If the requested area is within the current = window and >>> + that area is currently marked dirty or erased then this = command >>> + must fail with PARAM_ERROR. >> + >> ``` >> =20 >> ### BMC Events in Detail: >> @@ -627,7 +718,7 @@ on that register, or otherwise be polling it. >> =20 >> #### Bit Definitions: >> =20 >> -Events which should be ACKed: >> +Events which must be ACKed: >> ``` >> 0x01: BMC Reboot >> 0x02: BMC Windows Reset (V2) --Apple-Mail=_CB7D46C2-EB63-428E-A6BF-A993BA5AE43F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Acked-by: Adriana Kobylak <anoo@us.ibm.com>

On Oct 5, 2017, at 1:10 AM, Andrew Jeffery <andrew@aj.id.au> = wrote:

On Wed, 2017-10-04 = at 11:45 +1100, Suraj Jitindar Singh wrote:
Version 3 of the mbox = protocol makes four protocol changes:
 - Add a = requested block size argument to GET_MBOX_INFO
 - Add = a no erase argument to MARK_DIRTY
 - Add a = GET_FLASH_NAME command and support multiple flash devices
 - Add a MARK_LOCKED command

Requested Block Size:
The requested block size = argument has been added to the GET_MBOX_INFO
command to = allow the host to request a specified block size which might
be required to allow data manipulation at a finer = granularity. The
daemon should take this into account when = choosing a block size for use
which it will specify in the = response as before. The daemon has final
say and the host = must use the block size the daemon chooses.

No Erase:
The no erase argument to the mark = dirty command allows a host to specify
that an area of = flash should not be erased before being written to, as is
the default behaviour. This can be used when a host has = already erased a
large area and then performs many small = writes which would normally mean
many erases due to the = implicit erase before write, making this slow.

Add GET_FLASH_NAME command:
The ability to = support multiple flash devices has been added so that the
mbox protocol can be used to arbitrate access from the host = to a number
of flash devices which the daemon has access = to. To facilitate this the
GET_FLASH_INFO, = CREATE_{READ/WRITE}_WINDOW, and MARK_LOCKED commands now
take a flash ID, with the number of flash IDs allocated = returned by the
GET_MBOX_INFO commands. There is also a = new command GET_FLASH_NAME used
to convert a flash ID to a = flash name.

Add MARK_LOCKED command:
The MARK_LOCKED command has been added to allow an area(s) of = flash to be
locked, that is that area must be treated as = read only and the host is
not allowed to dirty or erase = any windows which map that area of flash.
Additionally = another error code LOCKED_ERROR was added to be returned
when the host does try to dirty or erase a locked area.

The host cannot lock a currently dirty or = erased area of the current
write window as it is not = defined if the clean/dirty/erased value is
what should = actually be "locked".

A locked area of = flash remains so until the daemon receives an
mboxctl = --clear-locked command and the locked areas are stored in a file
on the BMC filesystem to ensure persistence across BMC = reboots/daemon
crashes.

Multiple flash device support proposed and defined by:
William A. Kennington = III <wak@google.com>

Change-Id: I898698840dec221ae20e33943bb28e65abc4fe37
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>

But everyone else: please chime = in.

Cheers,

Andrew

---
 Documentation/mbox_protocol.md | 163 = ++++++++++++++++++++++++++++++++---------
 1 file = changed, 127 insertions(+), 36 deletions(-)

diff --git a/Documentation/mbox_protocol.md = b/Documentation/mbox_protocol.md
index bcd70a8..797ac7b = 100644
--- a/Documentation/mbox_protocol.md
+++ b/Documentation/mbox_protocol.md
@@ -17,19 = +17,22 @@ limitations under the License.
 This = document describes a protocol for host to BMC communication via the
 mailbox registers present on the Aspeed 2400 and 2500 = chips.
 This protocol is specifically designed to = allow a host to request and manage
-access to the flash = with the specifics of how the host is required to control
-this described below.
+access to a flash = device(s) with the specifics of how the host is required to
+control this described below.
 
 ## Version
 
-Both = version 1 and version 2 of the protocol are described below with version = 2
-specificities represented with V2 in brackets - = (V2).
+Version specific protocol functionalities are = represented by the version number
+in brackets next to the = definition of the functionality. (e.g. (V2) for version
+2 = specific funtionality). All version specific functionality must also = be
+implemented by proceeding versions up to and not = including the version a command
+was removed.
 
 ## Problem Overview
 
 "mbox" is the name we use to = represent a protocol we have established between
 the = host and the BMC via the Aspeed mailbox registers. This protocol is = used
-for the host to control the flash.
+for = the host to control access to the flash device(s).
  Prior to the mbox protocol, the host uses a backdoor = into the BMC address space
 (the iLPC-to-AHB bridge) = to directly manipulate the BMCs own flash controller.
@@ = -215,9 +218,11 @@ communicate a change in state.
 Given= that a majority of command and response arguments are specified as a
 multiple of block size it is necessary for the host and = BMC to agree on a
 protocol version as this = determines the block size. In V1 it is hard coded at
-4K = and in V2 the BMC chooses and specifies this to the host as a = response
-argument to `MBOX_GET_INFO`. Thus the host must = always call `MBOX_GET_INFO`
-before any other command = which specifies an argument in block size.
+4K, in V2 the = BMC chooses and in V3 the host is allowed to request a specific
+block size with the actual size chosen communicated back to = the host as a
+response argument to `MBOX_GET_INFO`. Thus = the host must always call
+`MBOX_GET_INFO` before any = other command which specifies an argument in block
+size. 
 When invoking `MBOX_GET_INFO` the = host must provide the BMC its highest
 supported = version of the protocol. The BMC must respond with a protocol version
@@ -231,10 +236,13 @@ version by issuing a subsequent = `MBOX_GET_INFO` command.
 ### Window Management
 
 In order to access flash contents, = the host must request a window be opened at
-the flash = offset it would like to access. The host may give a hint as to how
-much data it would like to access or otherwise set this = argument to zero. The
-BMC must respond with the LPC bus = address to access this window and the
-window size. The = host must not access past the end of the active window.
+the= flash offset it would like to access with the = CREATE_{READ,WRITE}_WINDOW
+commands. The host may give a = hint as to how much data it would like to access
+or = otherwise set this argument to zero. The BMC must respond with the LPC = bus
+address to access this window and the window size. = The host must not access
+past the end of the active = window. On returning success to either of the create
+window= commands the BMC must guarantee that the window provided contains = data
+which correctly represents the state of flash at the = time the response is given.
 
 There= is only ever one active window which is the window created by the = most
 recent CREATE_READ_WINDOW or = CREATE_WRITE_WINDOW call which succeeded. Even
@@ -278,7 = +286,19 @@ contents cannot be guaranteed.
 
 The host is not required to perform an erase before a = write command and the
 BMC must ensure that a write = performs as expected - that is if an erase is
-required = before a write then the BMC must perform this itself.
+required before a write then the BMC must perform this = itself (unless the
+no_erase flag is set in the = MARK_WRITE_DIRTY command in which case the BMC will
+blindly= write without a prior erase (V3)).
+
+The = host may lock an area of flash using the MARK_LOCKED command. Any = attempt
+to mark dirty or erased this area of flash must = fail with the LOCKED_ERROR
+response code. The host may = open a write window which contains a locked area
+of flash = however changes to a locked area of flash must never be written back
+to the backing data source (i.e. that area of flash must be = treated as read
+only with respect to the backing store at = all times). An attempt to lock an area
+of flash which is = not clean in the current window must fail with PARAM_ERROR.
+Locked flash regions must persist across a BMC reboot or = daemon restart. It is
+only possible to clear the lock = state through a clear_locked dbus command. (V3)
 
 ### BMC Events
 
@@ = -316,6 +336,8 @@ MARK_WRITE_DIRTY     0x07
 WRITE_FLUSH       &nbs= p;  0x08
 BMC_EVENT_ACK       &n= bsp;0x09
 MARK_WRITE_ERASED    0x0a (V2)
+GET_FLASH_NAME       0x0b = (V3)
+MARK_LOCKED        &nb= sp; 0x0c = (V3)
 ```
 
 ### Responses
@@ -329,13 +351,14 @@ TIMEOUT 5
 BUSY 6 (V2)
 WINDOW_ERROR 7 (V2)
 SEQ_ERROR 8 (V2)
+LOCKED_ERROR 9 (V3)
 ```
 
 ### Sequence Numbers
 
 Sequence numbers are included in messages for = correlation of commands and
-responses. V1 and V2 of the = protocol permit either zero or one commands to be
-in = progress (yet to receive a response).
+responses. V1, V2 = and V3 of the protocol permit either zero or one commands to
+be in progress (yet to receive a response).
 
 For generality, the host must = generate a sequence number that is unique with
 respect= to the previous command (one that has received a response) and any
@@ -368,6 +391,10 @@ = BUSY = = - Daemon in suspended state (currently unable to access flash)
 WINDOW_ERROR - Command not valid for active = window or no active window
  - Try = opening an appropriate window and retrying the command
 
+SEQ_ERROR - Invalid sequence number supplied with command
+
+LOCKED_ERROR - Tried to mark dirty or erased = locked area of flash
+
 ### = Information
 - All multibyte messages are LSB first = (little endian)
 - All responses must have a valid = return code in byte 13
@@ -381,6 +408,12 @@ allows us to = specify larger values with fewer command and response fields.
 
 In V1 block size is hard coded to = 4K.
 In V2 it is variable and must be queried with = the GET_MBOX_INFO command.
+In V3 the host can request a = given block size however it is ultimately up to
+the = daemon to choose a block size which is returned as part of the = GET_MBOX_INFO
+command response. The host must respect the = daemons choice. The ability for the
+host to request a = block size is provided such that it can choose an appropriate
+size to be able to utilise commands which only operate at = the block level.
+
 Note that for = simplicity block size must always be a power-of-2.
 Block size must also be greater than or equal to 4K. = This is due to the
 fact that we have a 28-bit LPC = address space and commands which return an
@@ -395,8 = +428,7 @@ multiplying by the block size.
 ```
 Command:
  RESET_STATE
- Implemented in Versions:
- = = V1, V2
+ Added = in: = V1
  Arguments:
  -
  Response:
@@ -409,8 +441,7 @@ Command:
 
 Command:
  GET_MBOX_INFO
- = Implemented in Versions:
- V1, V2
+ Added = in: = V1
  Arguments:
  V1:
  Args 0: API version
@@ -418,6 +449,10 @@ Command:
  V2:
  Args 0: API version
 
+ V3:
+ = = Args 0: API version
+ Args 1: Requested block size = (shift)
+
  Response:
  V1:
  Args 0: API version
@@ -430,6 = +465,14 @@ Command:
  Args 3-4: reserved
  Args 5: = Block size as power of two (encoded as a shift)
  Args 6-7: = Suggested Timeout (seconds)
+
+ V3:
+ = = Args 0: API version
+ Args 1-2: reserved
+ = = Args 3-4: reserved
+ Args 5: Block size as power of = two (encoded as a shift)
+ Args 6-7: Suggested Timeout = (seconds)
+ Args 8: Num Allocated Flash = IDs
  Notes:
  The = suggested timeout is a hint to the host as to how long
  it should wait after issuing a command to the BMC before = it
@@ -439,25 +482,34 @@ Command:
  the BMC does not wish to provide a hint in which case the host
  must choose some reasonable = value.
 
+ The host may desire a specific = block size and thus can request
+ this by = giving a hint to the daemon (may be zero). The daemon
+ may use = this to select the block size which it will use however
+ = = is free to ignore it. The value in the response is the block
+ = = size which must be used for all further requests until a new
+ size = is = negotiated by another call to GET_MBOX_INFO. (V3)
+
 Command:
  = GET_FLASH_INFO
- Implemented in Versions:
- = = V1, V2
+ Added = in: = V1
  Arguments:
+ V1, = V2:
  -
+
+ V3:
+ = = Args 0: Flash ID
  Response:
  V1:
  Args 0-3: Flash size (bytes)
  Args 4-7: = Erase granule (bytes)
 
- V2:
+ = = V2, V3:
  Args 0-1: Flash size (blocks)
  Args 2-3: Erase granule (blocks)
 
 Command:
  = CREATE_{READ/WRITE}_WINDOW
- = Implemented in Versions:
- V1, V2
+ Added = in: = V1
  Arguments:
  V1:
  Args 0-1: Requested flash offset = (blocks)
@@ -466,11 +518,15 @@ Command:
  Args 0-1: = Requested flash offset (blocks)
  Args 2-3: = Requested flash size to access (blocks)
 
+ = = V3:
+ Args 0-1: Requested flash offset = (blocks)
+ Args 2-3: Requested flash size to = access (blocks)
+ Args 4: Flash ID
  Response:
  V1:
  Args 0-1: LPC bus address of window (blocks)
 
- = = V2:
+ V2, V3:
  Args 0-1: = LPC bus address of window (blocks)
  Args 2-3: = Window size (blocks)
  Args 4-5: Flash offset mapped by = window (blocks)
@@ -505,8 +561,7 @@ = Command:
 
 Command:
  = CLOSE_WINDOW
- Implemented in Versions:
- = = V1, V2
+ Added = in: = V1
  Arguments:
  V1:
  -
@@ = -534,8 +589,7 @@ Command:
 
 Command:
  MARK_WRITE_DIRTY
- = Implemented in Versions:
- V1, V2
+ Added = in: = V1
  Arguments:
  V1:
  Args 0-1: Flash offset to mark = from base of flash (blocks)
@@ -544,6 +598,7 = @@ Command:
  V2:
  Args 0-1: Window offset to mark (blocks)
  Args 2-3: Number to mark dirty at offset (blocks)
+ = = Args 4  : Don't Erase Before Write (V3)
 
  Response:
  -
@@ -558,10 +613,16 @@ Command:
  block. If = the offset + number exceeds the size of the active
  window then the command must not succeed.
 
+ = = The host can give a hint to the daemon that is doesn't have to
+ = = erase a flash area before writing to it by setting ARG[4]. = This
+ means that the daemon will blindly perform a write to = that area
+ and will not try to erase it = before hand. This can be used if
+ the host = knows that a large area has already been erased for
+ example = but then wants to perform many small writes.
+
 Command
  = WRITE_FLUSH
- Implemented in Versions:
- = = V1, V2
+ Added = in: = V1
  Arguments:
  V1:
  Args 0-1: Flash offset to mark = from base of flash (blocks)
@@ -586,8 +647,7 = @@ Command
 
 Command:
  = BMC_EVENT_ACK
- Implemented in Versions:
- = = V1, V2
+ Added = in: = V1
  Arguments:
  Args = 0: = Bits in the BMC status byte (mailbox data
  register 15) to ack
@@ -599,8 +659,7 @@ Command:
 
 Command:
  MARK_WRITE_ERASED
- = Implemented in Versions:
- V2
+ Added = in: = V2
  Arguments:
  V2:
  Args 0-1: Window offset to erase = (blocks)
@@ -617,6 +676,38 @@ Command:
  number is = the number of blocks of the active window to erase
  starting at offset. If the offset + number exceeds the = size of
  the active window then the = command must not succeed.
+
+Command:
+ = GET_FLASH_NAME
+ = Added in: V3
+ = Arguments:
+ Args 0: Flash ID
+ = Response:
+ Args 0   : Flash = Name Length (bytes)
+ Args 1-10: Flash Name / UID
+ = Notes:
+ Describes a flash with some kind = of identifier useful to the
+ host system. This is typically a = null-padded string.
+
+ The length in the response is the = number of response arguments
+ as part of the flash name field = which the host should expect to
+ have been = populated.
+
+Command:
+ = MARK_LOCKED
+ = Added in: V3
+ = Arguments:
+ Args 0-1: Flash offset to lock = (blocks)
+ Args 2-3: Number to lock at = offset (blocks)
+ Args 4: Flash ID
+ = Response:
+ -
+ Notes:
+ = = Lock an area of flash so that the host can't mark it dirty or
+ = = erased. If the requested area is within the current window and
+ = = that area is currently marked dirty or erased then this = command
+ must fail with PARAM_ERROR.
+
 ```
 
 ### BMC Events in Detail:
@@ -627,7 = +718,7 @@ on that register, or otherwise be polling it.
 
 #### Bit Definitions:
 
-Events which should be ACKed:
+Events which must be ACKed:
 ```
 0x01: BMC Reboot
 0x02: BMC Windows = Reset (V2)

= --Apple-Mail=_CB7D46C2-EB63-428E-A6BF-A993BA5AE43F--