Repository navigation
Conversation
3c1e5f6 to
c2d3dfe
Compare
|
Do you have plans to send patches upstream? |
I wasn't thinking about that, at least not yet. |
5d62647 to
0ae4f4f
Compare
0ae4f4f to
7cc2fdc
Compare
8134f74 to
03a379c
Compare
03a379c to
a8c9478
Compare
Adds support for the `RTL8261N` NBASE-T PHY to the Gemtek W1700K. Depends: openwrt#20450 (phy-realtek: add rtl8251l, rtl8254b, rtl8261be, rtl8261n, rtl8264 and rtl8264b) Signed-off-by: Kenneth Kasilag <[email protected]>
Based on disassembly of the OEM driver, and from logic analyzer measurement, the following needs to be configued for the RTL8261N PHY of Gemtek W1700K: - UXSGMII HSO/HSI polarity swap - Device specific quirk (realtek,patch-gemtek-top) Depends: openwrt#20450 (phy-realtek: add rtl8251l, rtl8254b, rtl8261be, rtl8261n, rtl8264 and rtl8264b) Signed-off-by: Richard Huynh <[email protected]> Signed-off-by: Kenneth Kasilag <[email protected]>
Adds support for the `RTL8261N` NBASE-T PHY to the Gemtek W1700K. Depends: openwrt#20450 (phy-realtek: add rtl8251l, rtl8254b, rtl8261be, rtl8261n, rtl8264 and rtl8264b) Signed-off-by: Kenneth Kasilag <[email protected]>
Based on disassembly of the OEM driver, and from logic analyzer measurement, the following needs to be configued for the RTL8261N PHY of Gemtek W1700K: - UXSGMII HSO/HSI polarity swap - Device specific quirk (realtek,patch-gemtek-top) Depends: openwrt#20450 (phy-realtek: add rtl8251l, rtl8254b, rtl8261be, rtl8261n, rtl8264 and rtl8264b) Signed-off-by: Richard Huynh <[email protected]> Signed-off-by: Kenneth Kasilag <[email protected]>
|
Aside from the issue with the Only issue I'm having now is that ethtool seemingly isn't exporting info about the PHY - likewise, |
Huh. It works fine for me on ST5008 |
a8c9478 to
85bbe02
Compare
Adds support for the `RTL8261N` NBASE-T PHY to the Gemtek W1700K. Depends: openwrt#20450 (phy-realtek: add rtl8251l, rtl8254b, rtl8261be, rtl8261n, rtl8264 and rtl8264b) Signed-off-by: Kenneth Kasilag <[email protected]>
OpenWRT-fanboy
left a comment
There was a problem hiding this comment.
Works great on W1700k without the 737 hack.
|
Tested on: TP-Link BE450 (Mediatek MT7988d, RTL8261N, Device Support PR pending #20398) |
|
I took the freedom to take care of the rebasing |
|
Imho this looks ready to be sent upstream, so next step would be to squash all files in |
i also pushed the new firmwares: https://github.com/balika011/realtek_phy_firmware/releases |
|
Sorry, I don't want to delay this further since we finally are on the finish line, but according to @hauke we should clear up the licensing situation before it can be sent upstream, no?
@dangowrt @balika011 which GPL version were the original source files for each of these? copyright/licensing should not be swept under the carpet when upstreaming |
|
The source files released in various GPL drops under GPLv2 contain huge numeral arrays. In the repo you can see how the binaries are generated from the GPLv2-only licenced source files. I suppose GPLv3 applies to the script generating the binaries from the source files, as the resulting binaries have the identical content of the GPLv2 sources, just in different encoding (binary instead of an array of numbers in a C source file) |
|
great, now that that is answered who upstreams this to netdev after this step:
|
|
Adding the RTL8224 without having one I can't grantee that it will work. So I rather not add that unless someone donates one. |
RTL8224 is supported upstream. I wouldn't link it to this PR. |
Does the upstream supports the patching too? |
The upstream driver doesn't support patching. I think it's even better that it works correctly without patches. Some patches simply set registers, the functions of which we don't yet know. Unless the patched firmware for RTL8224 has some new features, I don't think it's worth adding. |
| int ret = 0, us_diff; | ||
| struct timespec64 start, now; | ||
|
|
||
| ktime_get_real_ts64(&start); |
There was a problem hiding this comment.
Why would you need the real time? This looks like it would break when somebody changes the system clock in the middle.
Maybe you wanted to use a monotonic time like ktime_get_ts64. Or just use ktime_get in both situations (start + current time) and then directly calculate your usecs via something like uint32_t us_diff = ktime_to_us(ktime_sub(now, start));
ecsv
left a comment
There was a problem hiding this comment.
Many of these things can directly be found when running checkpatch (from lets say Linux 7.0) against the newly introduced directory:
./scripts/checkpatch.pl --strict -f /home/..../target/linux/generic/files/drivers/net/phy/realtek/*
Other things were just noticed while scrolling through the changes
| @@ -0,0 +1,25 @@ | |||
| #include "realtek.h" | |||
There was a problem hiding this comment.
| #include "realtek.h" | |
| // SPDX-License-Identifier: GPL-2.0 | |
| #include "phy_patch.h" | |
| #include <linux/errno.h> | |
| #include <linux/phy.h> | |
| #include "realtek.h" |
| { | ||
| struct rtl826x_priv *priv = phydev->priv; | ||
| struct rt_phy_patch_db *patch_db = priv->patch; | ||
| int ret = 0, i = 0; |
There was a problem hiding this comment.
| int ret = 0, i = 0; | |
| int ret = 0 | |
| size_t i; |
| struct rt_phy_patch_db *patch_db = priv->patch; | ||
| int ret = 0, i = 0; | ||
|
|
||
| if (patch_db == NULL || patch_db->patch_op == NULL) { |
There was a problem hiding this comment.
| if (patch_db == NULL || patch_db->patch_op == NULL) { | |
| if (!patch_db || !patch_db->patch_op) { |
| @@ -0,0 +1,40 @@ | |||
| #ifndef __PHY_PATCH_H__ | |||
There was a problem hiding this comment.
| #ifndef __PHY_PATCH_H__ | |
| /* SPDX-License-Identifier: GPL-2.0 */ | |
| #ifndef __PHY_PATCH_H__ |
| } __packed; | ||
|
|
||
| struct rt_phy_patch_db { | ||
| int (*patch_op)(struct phy_device *phydev, struct rtk_hwpatch *pPatch_data); |
There was a problem hiding this comment.
| int (*patch_op)(struct phy_device *phydev, struct rtk_hwpatch *pPatch_data); | |
| int (*patch_op)(struct phy_device *phydev, const struct rtk_hwpatch *patch); |
I don't like that there are two things called patch_op. One is the something which stores a value from rtk_phypatch_op and the other one is a pointer to executing the op. Maybe we can call this one patch_op_exec or something like this?
|
|
||
| data = (data >> 8) & 0x1f; | ||
| for (cnt = 0; cnt <= data; cnt++) { | ||
| ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, 0xbc62, GENMASK(12, 8), cnt << 8); |
There was a problem hiding this comment.
| ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, 0xbc62, GENMASK(12, 8), cnt << 8); | |
| ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, 0xbc62, | |
| GENMASK(12, 8), cnt << 8); |
| case RTK_PATCH_OP_TOP: | ||
| reg = (patch->pagemmd * 8) + (patch->addr - 16); | ||
| if (mask != GENMASK(15, 0)) { | ||
| ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, reg, mask, patch->data << patch->lsb); |
There was a problem hiding this comment.
| ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, reg, mask, patch->data << patch->lsb); | |
| ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, reg, mask, | |
| patch->data << patch->lsb); |
| break; | ||
|
|
||
| case RTK_PATCH_OP_PSDS0: | ||
| ret = _phy_patch_rtl826x_sds_modify(phydev, patch->pagemmd, patch->addr, mask, patch->data << patch->lsb); |
There was a problem hiding this comment.
| ret = _phy_patch_rtl826x_sds_modify(phydev, patch->pagemmd, patch->addr, mask, patch->data << patch->lsb); | |
| ret = _phy_patch_rtl826x_sds_modify(phydev, patch->pagemmd, patch->addr, mask, | |
| patch->data << patch->lsb); |
| struct rt_phy_patch_db { | ||
| int (*patch_op)(struct phy_device *phydev, struct rtk_hwpatch *pPatch_data); | ||
| struct rtk_hwpatch *conf; | ||
| u32 size; | ||
| }; |
There was a problem hiding this comment.
In theory, this can be written also as a flex array:
| struct rt_phy_patch_db { | |
| int (*patch_op)(struct phy_device *phydev, struct rtk_hwpatch *pPatch_data); | |
| struct rtk_hwpatch *conf; | |
| u32 size; | |
| }; | |
| struct rt_phy_patch_db { | |
| int (*patch_op)(struct phy_device *phydev, struct rtk_hwpatch *pPatch_data); | |
| size_t count; | |
| struct rtk_hwpatch conf[] __counted_by(count); | |
| }; |
Of course, then the size would be the number of entries in conf and no longer the raw size of conf. The loops must therefore be adjusted to not divide but directly use count as upper bound check.
The allocation of struct rt_phy_patch_db would look then like:
size_t count;
count = fw->size / sizeof(struct rtk_hwpatch);
patch_db = devm_kzalloc(struct_size(patch_db, conf, count), GFP_KERNEL);
if (!patch_db) {
...
}
patch_db->count = count;
or with Linux 7.0:
size_t count;
count = fw->size / sizeof(struct rtk_hwpatch);
patch_db = kzalloc_flex(*patch_db, conf, count, GFP_ATOMIC);
if (!patch_db) {
...
}
patch_db->count = count;
This is preferred in the kernel because you can then utilize the already existing infrastructure better. Things like CONFIG_FORTIFY_SOURCE or CONFIG_UBSAN_BOUNDS
devm_kzalloc_flex would even be better because you don't free the allocated memory in your code. devm_*alloc* can help you with this because it is then freed automatically when the device is freed
| for (i = 0; i < fw->size / sizeof(struct rtk_hwpatch); i++) { | ||
| patch_db->conf[i].patch_op = patches[i].patch_op; | ||
| patch_db->conf[i].portmask = patches[i].portmask; | ||
| patch_db->conf[i].pagemmd = le16_to_cpu(patches[i].pagemmd); | ||
| patch_db->conf[i].addr = le16_to_cpu(patches[i].addr); | ||
| patch_db->conf[i].msb = patches[i].msb; | ||
| patch_db->conf[i].lsb = patches[i].lsb; | ||
| patch_db->conf[i].data = le16_to_cpu(patches[i].data); | ||
| } |
There was a problem hiding this comment.
This is slightly ugly because the le16_to_cpu converts a __le16 to a u16. For sparse/cgcc, this is in different address spaces and you will therefore get errors because of this.
For now, it works. But when you want to upstream it, you need to check your code by building it with make C=1 - and then you have to fix it.
One way to handle it is to have a file representation structure and a in-memory representation structure (which is used in the patch_db)
struct rtk_hwpatch {
u8 patch_op;
u8 portmask;
__le16 pagemmd;
__le16 addr;
u8 msb;
u8 lsb;
__le16 data;
} __packed;
struct rtk_patch_op {
u8 patch_op;
u8 portmask;
u16 pagemmd;
u16 addr;
u8 msb;
u8 lsb;
u16 data;
};
Or you always store the in-file representation (__le16) and then on-demand convert the __le16 to u16.
|
Just to document it: this can also be used in u-boot to get RTL8261BE working on something like MT7988. I've just did a really rough PoC which uses a slightly different format for the patch file. uboot-mediatek-rtl8261-1.patch Which can then be loaded from a MTD partition (in my case 0x10000 bytes large) when it is registered in the devicetree: The loader in Of course, |
The RTL8261C/D-CG is a Realtek 10Gbps copper PHY supporting 100M/1G/2.5G/5G/10G speeds via USXGMII interface. Requires firmware patching at init via patch mode entry/exit sequence. Work around MMD7 AN STAT1 not reporting autonegotiation capability correctly by forcing the Autoneg bit in get_features.
|
@balika011 do you plan on addressing the comments here? I think this change would still be received well by all the new gear using 10G RTL PHYs. |
|
hello. |
@xvolte there is:
|
|
It would be a real shame if so much effort goes to waste. If this were to be committed, we should expect continued improvement and refinement. Just look at the near daily committing of realtek driver fixes. If (as seems likely) @balika011 has abandoned this PR, maybe someone else can slightly clean this up, submit a new PR and get it done. @ecsv? Sometimes the committers let perfect be the enemy of the good. Certainly seems so here. |
|
@OpenWRT-fanboy https://git.no.mesh.fail/mirror/realtek-doc/src/branch/main/sources/rtk-gp3000/src/hal/phy/construct have updated values |
I find this rather sub-optimal. I've prepared all these changes already in github but now need to redo them because I can't apply my own suggestions from this PR. But yes, I think this PR is unmanageable and the original author is unavailable. This thing has to be splitted up in multiple commits (firmware, patching, features, ...) and PRs (adding of new things, removal of the old driver) I don't have the HW with me at the moment, but I can start thinking about the "mechanical" cleanups. I will definitely not do anything which broaden the scope of this PR. And will also not assist with debugging or adding of features. EDIT: See #22563 |
This change adds/moves support for rtl8251l, rtl8254b, rtl8261be, rtl8261n, rtl8264 and rtl8264b phys into common realtek phy driver.
Also removes phy-rtl8261n as it's no longer needed.
note: this pr supersedes #20392