Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MT76x0: Correct s6_to_s8 function #631

Closed
wants to merge 2 commits into from

Conversation

Devmax21
Copy link

@Devmax21 Devmax21 commented Dec 2, 2021

MT76x0: Fix sign calculation for negative numbers in s6_to_s8 function

mt76x0/eeprom.h Outdated

if (ret & BIT(5))
if (ret & BIT(6))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't seem right to me. The reference driver does this:
if (val & 0x20) val -= 64;
Subtracting BIT(6) if BIT(6) is set also doesn't make it have the correct range, because it means that the resulting number can never be negative.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIT(6) should always be 0. The reference driver masks the eeprom value with 0x3F.

Copy link
Author

@Devmax21 Devmax21 Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/zaccareal/openwrt-archer-c2/blob/master/package/mediatek/drivers/mt7610e/src/chips/mt76x0.c#L2933 I see some other logic. I thought that this logic is correct. Am I wrong? In that code I see substracting 0x40 if more or equal 0x40.
Now we subtracting BIT(6) if BIT(5) is set. In this case, if val=0x3f than we get FF. If we check BIT(6) we will doesn't subtract and will get 0x3f

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Archer c2 has 0x3f in eeprom and MT7610E-V10-FEM.bin has 0x3a.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even that code has InputTxpower & 0x3F

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no bit6 in input

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think the original function is correct, as it matches my interpretation of the vendor code. Even if you revert to the BIT(5) check, including bit 6 in the mask is still wrong

You are right. Bit 6 in the mask is still wrong.

@nbd168
Copy link
Member

nbd168 commented Dec 2, 2021

I still think the original function is correct, as it matches my interpretation of the vendor code.
Even if you revert to the BIT(5) check, including bit 6 in the mask is still wrong

@nbd168 nbd168 closed this Dec 2, 2021
@Devmax21 Devmax21 deleted the fix-mt76x0-s6_to_s8 branch December 2, 2021 14:14
@sanitariu
Copy link

Does this fix work on archer c2 ? If so i would like it wrong but working :)

@Devmax21
Copy link
Author

Devmax21 commented Dec 2, 2021

No, unfortunately this fix doesn't work. I deeply investigated I saw that is cosmetic fix. It doesn't increase the real txpower.

@Devmax21
Copy link
Author

Devmax21 commented Dec 3, 2021

Does this fix work on archer c2 ? If so i would like it wrong but working :)

This fix #227 (comment) work for me on archer c2. But it doesn't suit for commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants