lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <59b47f0b-6201-3814-e17f-1435ce5c2dad@microchip.com>
Date:   Thu, 12 May 2022 15:31:31 +0000
From:   <Claudiu.Beznea@...rochip.com>
To:     <krzysztof.kozlowski@...aro.org>, <srinivas.kandagatla@...aro.org>,
        <robh+dt@...nel.org>, <krzk+dt@...nel.org>
CC:     <linux-arm-kernel@...ts.infradead.org>,
        <devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/2] dt-bindings: microchip-otpc: document Microchip OTPC

On 12.05.2022 10:54, Krzysztof Kozlowski wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 12/05/2022 09:17, Claudiu.Beznea@...rochip.com wrote:
>>>
>>>> +
>>>> +#ifndef _DT_BINDINGS_NVMEM_MICROCHIP_OTPC_H
>>>> +#define _DT_BINDINGS_NVMEM_MICROCHIP_OTPC_H
>>>> +
>>>> +/*
>>>> + * Need to have it as a multiple of 4 as NVMEM memory is registered with
>>>> + * stride = 4.
>>>> + */
>>>> +#define OTP_PKT(id)                  ((id) * 4)
>>>
>>> Do I get it correctly - the offset or register address is now part of a
>>> binding? You write here "id", however you use it as part of "reg", so
>>> it's confusing.
>>
>> I agree that reg should describe the offset in OTP memory and its the
>> length for a cell.
>>
>> However this OTP memory is organized into packets (this is how hardware is
>> designed), the 1st one being the boot configuration packet, the 2nd one
>> being temperature calibration data. At the moment Microchip provides only
>> these 2 packets in OTP memory. Boot configuration packet may vary in length
>> thus it may change the offset the temperature calibration packet resides
>> to. If this happen and we use offset based addressing in device trees then
>> the solution will not work all the time.
>>
>> OTP hardware is designed to work with packets. For a packet being in memory
>> at offset 0x0E as follows:
>>
>> offset  OTP Memory layout
>>
>>          .           .
>>          .    ...    .
>>          .           .
>> 0x0E     +-----------+        <--- packet X
>>          | header  X |
>> 0x12     +-----------+
>>          | payload X |
>> 0x16     |           |
>>          |           |
>> 0x1A     |           |
>>          +-----------+
>>          .           .
>>          .    ...    .
>>          .           .
>>
>> requesting from software data at address 0x16 (through OTP control
>> registers) will return the whole packet starting at offset 0x0E. Same
>> things happens when requesting data at offset 0x0E, 0x12, 0x1A.
>>
>> Thus, as underlying hardware returns to software chunks of 4 bytes though
>> data registers the driver has been registered with stride = 4. The
>> OTP_PKT() macro expects packet identifier (starting from 0), multiplies it
>> by 4 to be able to pass the NVMEM subsystem accordingly, then the driver
>> which manages a list of the available packets divides this value by 4 and
>> gets the packet ID and the proper offset in memory for the requested packet ID.
>>
>> The intention was to have the OTP_PKT() macro here to be used in device
>> trees for simpler way of describing different cells in this OTP memory.
>> Also, using OTP_PKT() abstraction looked to me closer to the reality
>> (although the computed value is not reflecting this, it is only an
>> abstraction to be able to pass the NVMEM subsystem).
>>
>> Would you prefer to have raw values instead of using this macro?
> 
> Macro is a nice idea if it can be stable. I understood that length of
> packets depends on hardware, so this part could be stable. But what
> about number of packets, so the OTP_PKT_SAMA7G5_TEMP_CALIB_LEN below?

The OTP_PKT_SAMA7G5_TEMP_CALIB_LEN here is the length of thermal
calibration packet. This length is fixed and will not be changed.

After these 2 packets (provided by Microchip) user may further flash any
number of packets and use them as they wish.

Driver is in charge of scanning the NVMEM for the available packets and
prepare a list with their IDs and their starting offsets in NVMEM memory
such that when it receives a read request it will be able to decode the
packet offset based on packet identifier.

In case different number of packets are available in NVMEM for different
kind of setups (boards) these could also be referenced in board specific DT
using OTP_PKT() macro and with proper length (which will depend on what
user flashed).

> You wrote "Boot configuration packet may vary in length", so it could be
> changed by Microchip?

Yes, between chip revisions its length could be changed.

> 
> Once this value is stored in the bindings, it is not supposed to change.

I agree!

> 
>>
>> Adapting the subsystem for this kind of devices is also an option if
>> Srinivas thinks like this.
>>
>>>
>>>> +
>>>> +/*
>>>> + * Temperature calibration packet length for SAMA7G5: 1 words header,
>>>> + * 18 words payload.
>>>> + */
>>>> +#define OTP_PKT_SAMA7G5_TEMP_CALIB_LEN       (19 * 4)
>>>
>>> Length of some memory region also does not look like job for bindings.
>>
>> I added it here to be able to have the same macro in DT and consumer
>> drivers taking as example iio drivers that uses this approach to describe
>> IIO channel identifiers. I can remove it and use necessary macros in the
>> consumer drivers, if it's better this way.
> 
> 
> 
> Best regards,
> Krzysztof

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ