Re: [PATCH] generic: platform/mikrotik: implement multi caldata

2020-10-19 Thread Thibaut

> Le 8 oct. 2020 à 11:11, Thibaut  a écrit :
> 
> Hi,
> 
>> On 7 Oct 2020, at 22:41, Alexander 'lynxis' Couzens  wrote:
>> 
>> On Fri, 25 Sep 2020 21:09:26 +0200
>> Thibaut  wrote:
>> 
>>> Ping?
>> 
>> LGTM.
>> 
>> What's in the "$wdata/data_0" file? Is it the BDF?
> 
> My understanding is (disclaimer: I don’t own any hardware that exposes these 
> new files) that on old style devices, the calibration (and BDF where 
> applicable, which means it could be dynamically loaded as well) data of all 
> radios was packed into a single payload, which got exposed as the “wlan_data” 
> sysfs file. Userspace then had to apply offsets to access data pertaining to 
> each radio.
> 
> New style simply separates each radio into its own payload, so data_0 is 
> calib (+BDF where applicable) for one of the radios and so on, which makes it 
> easier to process (probably for RouterOS as well, hence the change ;)
> 
> There are some devices out there which have been shipped with both styles 
> (the hap-ac2 is one of them), hence the patch ensure that 1) previous 
> behavior is unchanged and 2) it’s “easy” to accommodate both styles in 
> userspace (as suggested in the commit log).

CC’ing Robert Marko who wants to add his Tested-by.

Patch at 
https://patchwork.ozlabs.org/project/openwrt/patch/20200824103840.38920-1-ha...@slashdirt.org/

Cheers
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH] generic: platform/mikrotik: implement multi caldata

2020-10-19 Thread Robert Marko
On Mon, 19 Oct 2020 at 20:01, Thibaut  wrote:
>
>
> > Le 8 oct. 2020 à 11:11, Thibaut  a écrit :
> >
> > Hi,
> >
> >> On 7 Oct 2020, at 22:41, Alexander 'lynxis' Couzens  wrote:
> >>
> >> On Fri, 25 Sep 2020 21:09:26 +0200
> >> Thibaut  wrote:
> >>
> >>> Ping?
> >>
> >> LGTM.
> >>
> >> What's in the "$wdata/data_0" file? Is it the BDF?
> >
> > My understanding is (disclaimer: I don’t own any hardware that exposes 
> > these new files) that on old style devices, the calibration (and BDF where 
> > applicable, which means it could be dynamically loaded as well) data of all 
> > radios was packed into a single payload, which got exposed as the 
> > “wlan_data” sysfs file. Userspace then had to apply offsets to access data 
> > pertaining to each radio.
> >
> > New style simply separates each radio into its own payload, so data_0 is 
> > calib (+BDF where applicable) for one of the radios and so on, which makes 
> > it easier to process (probably for RouterOS as well, hence the change ;)
> >
> > There are some devices out there which have been shipped with both styles 
> > (the hap-ac2 is one of them), hence the patch ensure that 1) previous 
> > behavior is unchanged and 2) it’s “easy” to accommodate both styles in 
> > userspace (as suggested in the commit log).
>
> CC’ing Robert Marko who wants to add his Tested-by.
>
> Patch at 
> https://patchwork.ozlabs.org/project/openwrt/patch/20200824103840.38920-1-ha...@slashdirt.org/
>
> Cheers

Works on my hAP ac2 with old style caldata, so:

Tested-by: Robert Marko 

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH] generic: platform/mikrotik: implement multi caldata

2020-10-08 Thread Thibaut
Hi,

> On 7 Oct 2020, at 22:41, Alexander 'lynxis' Couzens  wrote:
> 
> On Fri, 25 Sep 2020 21:09:26 +0200
> Thibaut  wrote:
> 
>> Ping?
> 
> LGTM.
> 
> What's in the "$wdata/data_0" file? Is it the BDF?

My understanding is (disclaimer: I don’t own any hardware that exposes these 
new files) that on old style devices, the calibration (and BDF where 
applicable, which means it could be dynamically loaded as well) data of all 
radios was packed into a single payload, which got exposed as the “wlan_data” 
sysfs file. Userspace then had to apply offsets to access data pertaining to 
each radio.

New style simply separates each radio into its own payload, so data_0 is calib 
(+BDF where applicable) for one of the radios and so on, which makes it easier 
to process (probably for RouterOS as well, hence the change ;)

There are some devices out there which have been shipped with both styles (the 
hap-ac2 is one of them), hence the patch ensure that 1) previous behavior is 
unchanged and 2) it’s “easy” to accommodate both styles in userspace (as 
suggested in the commit log).

HTH,
Thibaut
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH] generic: platform/mikrotik: implement multi caldata

2020-10-07 Thread Alexander 'lynxis' Couzens
On Fri, 25 Sep 2020 21:09:26 +0200
Thibaut  wrote:

> Ping?

LGTM.

What's in the "$wdata/data_0" file? Is it the BDF?

Best,
lynxis
-- 
Alexander Couzens

mail: lyn...@fe80.eu
jabber: lyn...@fe80.eu
gpg: 390D CF78 8BF9 AA50 4F8F  F1E2 C29E 9DA6 A0DF 8604


pgpbyv_G_1yGj.pgp
Description: OpenPGP digital signature
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH] generic: platform/mikrotik: implement multi caldata

2020-09-25 Thread Thibaut
Ping?

> Le 24 août 2020 à 12:38, Thibaut VARÈNE  a écrit :
> 
> MikroTik recently changed again the way they store wlan calibration data
> on devices. Prior to this change, ERD calibration data for all available
> radios was stored within a single identifier node ("tag" in RouterBoot
> parlance).
> 
> Recent devices have been seen with calibration (and BDF) data stored in
> separate identifiers within LZOR packing for each radio: this patch
> addresses this by:
> 1) ensuring that both variants are properly supported,
> 2) preserving backward compatibility with existing data consumers,
> 3) allowing for more than 2 calibration blobs to be exposed via sysfs.
> 
> Specifically, before this patch, the driver would provide a single sysfs
> file named /sys/firmware/mikrotik/hard_config/wlan_data that contained
> whatever calibration data found on the device's flash. After this patch,
> when executed on a device that uses the old style storage, this behavior
> is unchanged, but when executed on a device that uses new style storage
> (for either traditional "ERD" packing or "LZOR" packing), the driver
> replaces that single file with a folder containing one or more files
> each containing the data encoded within individual identifiers.
> 
> As far as OpenWRT is concerned, this means that for devices which are
> known to exist with both styles of data storage, a suitable hotplug stub
> could look like this for e.g. the second radio:
> 
> wdata="/sys/firmware/mikrotik/hard_config/wlan_data"
> ( [ -f "$wdata" ] && caldata_sysfsload_from_file "$wdata" 0x8000 0x2f20 ) || \
> ( [ -d "$wdata" ] && caldata_sysfsload_from_file "$wdata/data_2" 0x0 0x2f20 )
> 
> This patch has been tested with LZOR old and new style packing on ipq4019,
> and with old style on ath79.
> 
> Tested-by: John Thomson 
> Tested-by: Шебанов Алексей 
> Tested-by: Alen Opačić 
> Signed-off-by: Thibaut VARÈNE 
> ---
> .../drivers/platform/mikrotik/rb_hardconfig.c | 139 +-
> 1 file changed, 106 insertions(+), 33 deletions(-)
> 
> diff --git 
> a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
> b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
> index 8861814be4..41dea98b5e 100644
> --- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
> +++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
> @@ -39,7 +39,7 @@
> 
> #include "routerboot.h"
> 
> -#define RB_HARDCONFIG_VER"0.05"
> +#define RB_HARDCONFIG_VER"0.06"
> #define RB_HC_PR_PFX  "[rb_hardconfig] "
> 
> /* ID values for hardware settings */
> @@ -76,6 +76,17 @@
> #define RB_HW_OPT_HAS_TS_FOR_ADC  BIT(22)
> #define RB_HW_OPT_HAS_PLC BIT(29)
> 
> +/*
> + * Tag ID values for ERD data.
> + * Mikrotik used to pack all calibration data under a single tag id 0x1, but
> + * recently switched to a new scheme where each radio calibration gets a
> + * separate tag. The new scheme has tag id bit 15 always set and seems to be
> + * mutually exclusive with the old scheme.
> + */
> +#define RB_WLAN_ERD_ID_SOLO  0x0001
> +#define RB_WLAN_ERD_ID_MULTI_80010x8001
> +#define RB_WLAN_ERD_ID_MULTI_82010x8201
> +
> static struct kobject *hc_kobj;
> static u8 *hc_buf;// ro buffer after init(): no locking required
> static size_t hc_buflen;
> @@ -351,10 +362,22 @@ static ssize_t hc_wlan_data_bin_read(struct file *filp, 
> struct kobject *kobj,
>loff_t off, size_t count);
> 
> static struct hc_wlan_attr {
> + const u16 erd_tag_id;
>   struct bin_attribute battr;
>   u16 pld_ofs;
>   u16 pld_len;
> -} hc_wlandata_battr = {
> +} hc_wd_multi_battrs[] = {
> + {
> + .erd_tag_id = RB_WLAN_ERD_ID_MULTI_8001,
> + .battr = __BIN_ATTR(data_0, S_IRUSR, hc_wlan_data_bin_read, 
> NULL, 0),
> + }, {
> + .erd_tag_id = RB_WLAN_ERD_ID_MULTI_8201,
> + .battr = __BIN_ATTR(data_2, S_IRUSR, hc_wlan_data_bin_read, 
> NULL, 0),
> + }
> +};
> +
> +static struct hc_wlan_attr hc_wd_solo_battr = {
> + .erd_tag_id = RB_WLAN_ERD_ID_SOLO,
>   .battr = __BIN_ATTR(wlan_data, S_IRUSR, hc_wlan_data_bin_read, NULL, 0),
> };
> 
> @@ -426,19 +449,19 @@ static struct hc_attr {
> /*
>  * If the RB_ID_WLAN_DATA payload starts with RB_MAGIC_ERD, then past
>  * that magic number the payload itself contains a routerboot tag node
> - * locating the LZO-compressed calibration data at id 0x1.
> + * locating the LZO-compressed calibration data. So far this scheme is only
> + * known to use a single tag at id 0x1.
>  */
> -static int hc_wlan_data_unpack_erd(const u8 *inbuf, size_t inlen,
> +static int hc_wlan_data_unpack_erd(const u16 tag_id, const u8 *inbuf, size_t 
> inlen,
>  void *outbuf, size_t *outlen)
> {
>   u16 lzo_ofs, lzo_len;
>   int ret;
> 
>   /* Find embedded tag */
> - ret = routerboot_tag_find(inbuf, 

[PATCH] generic: platform/mikrotik: implement multi caldata

2020-08-24 Thread Thibaut VARÈNE
MikroTik recently changed again the way they store wlan calibration data
on devices. Prior to this change, ERD calibration data for all available
radios was stored within a single identifier node ("tag" in RouterBoot
parlance).

Recent devices have been seen with calibration (and BDF) data stored in
separate identifiers within LZOR packing for each radio: this patch
addresses this by:
1) ensuring that both variants are properly supported,
2) preserving backward compatibility with existing data consumers,
3) allowing for more than 2 calibration blobs to be exposed via sysfs.

Specifically, before this patch, the driver would provide a single sysfs
file named /sys/firmware/mikrotik/hard_config/wlan_data that contained
whatever calibration data found on the device's flash. After this patch,
when executed on a device that uses the old style storage, this behavior
is unchanged, but when executed on a device that uses new style storage
(for either traditional "ERD" packing or "LZOR" packing), the driver
replaces that single file with a folder containing one or more files
each containing the data encoded within individual identifiers.

As far as OpenWRT is concerned, this means that for devices which are
known to exist with both styles of data storage, a suitable hotplug stub
could look like this for e.g. the second radio:

wdata="/sys/firmware/mikrotik/hard_config/wlan_data"
( [ -f "$wdata" ] && caldata_sysfsload_from_file "$wdata" 0x8000 0x2f20 ) || \
( [ -d "$wdata" ] && caldata_sysfsload_from_file "$wdata/data_2" 0x0 0x2f20 )

This patch has been tested with LZOR old and new style packing on ipq4019,
and with old style on ath79.

Tested-by: John Thomson 
Tested-by: Шебанов Алексей 
Tested-by: Alen Opačić 
Signed-off-by: Thibaut VARÈNE 
---
 .../drivers/platform/mikrotik/rb_hardconfig.c | 139 +-
 1 file changed, 106 insertions(+), 33 deletions(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 8861814be4..41dea98b5e 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -39,7 +39,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER  "0.05"
+#define RB_HARDCONFIG_VER  "0.06"
 #define RB_HC_PR_PFX   "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -76,6 +76,17 @@
 #define RB_HW_OPT_HAS_TS_FOR_ADC   BIT(22)
 #define RB_HW_OPT_HAS_PLC  BIT(29)
 
+/*
+ * Tag ID values for ERD data.
+ * Mikrotik used to pack all calibration data under a single tag id 0x1, but
+ * recently switched to a new scheme where each radio calibration gets a
+ * separate tag. The new scheme has tag id bit 15 always set and seems to be
+ * mutually exclusive with the old scheme.
+ */
+#define RB_WLAN_ERD_ID_SOLO0x0001
+#define RB_WLAN_ERD_ID_MULTI_8001  0x8001
+#define RB_WLAN_ERD_ID_MULTI_8201  0x8201
+
 static struct kobject *hc_kobj;
 static u8 *hc_buf; // ro buffer after init(): no locking required
 static size_t hc_buflen;
@@ -351,10 +362,22 @@ static ssize_t hc_wlan_data_bin_read(struct file *filp, 
struct kobject *kobj,
 loff_t off, size_t count);
 
 static struct hc_wlan_attr {
+   const u16 erd_tag_id;
struct bin_attribute battr;
u16 pld_ofs;
u16 pld_len;
-} hc_wlandata_battr = {
+} hc_wd_multi_battrs[] = {
+   {
+   .erd_tag_id = RB_WLAN_ERD_ID_MULTI_8001,
+   .battr = __BIN_ATTR(data_0, S_IRUSR, hc_wlan_data_bin_read, 
NULL, 0),
+   }, {
+   .erd_tag_id = RB_WLAN_ERD_ID_MULTI_8201,
+   .battr = __BIN_ATTR(data_2, S_IRUSR, hc_wlan_data_bin_read, 
NULL, 0),
+   }
+};
+
+static struct hc_wlan_attr hc_wd_solo_battr = {
+   .erd_tag_id = RB_WLAN_ERD_ID_SOLO,
.battr = __BIN_ATTR(wlan_data, S_IRUSR, hc_wlan_data_bin_read, NULL, 0),
 };
 
@@ -426,19 +449,19 @@ static struct hc_attr {
 /*
  * If the RB_ID_WLAN_DATA payload starts with RB_MAGIC_ERD, then past
  * that magic number the payload itself contains a routerboot tag node
- * locating the LZO-compressed calibration data at id 0x1.
+ * locating the LZO-compressed calibration data. So far this scheme is only
+ * known to use a single tag at id 0x1.
  */
-static int hc_wlan_data_unpack_erd(const u8 *inbuf, size_t inlen,
+static int hc_wlan_data_unpack_erd(const u16 tag_id, const u8 *inbuf, size_t 
inlen,
   void *outbuf, size_t *outlen)
 {
u16 lzo_ofs, lzo_len;
int ret;
 
/* Find embedded tag */
-   ret = routerboot_tag_find(inbuf, inlen, 0x1,// always id 1
- _ofs, _len);
+   ret = routerboot_tag_find(inbuf, inlen, tag_id, _ofs, _len);
if (ret) {
-   pr_debug(RB_HC_PR_PFX "ERD data not found\n");