All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kalle Valo <kvalo@codeaurora.org>
To: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Priit Laes <plaes@plaes.org>, Kees Cook <keescook@chromium.org>,
	Jia-Ju Bai <baijiaju1990@gmail.com>,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Colin Ian King <colin.king@canonical.com>,
	Arend van Spriel <arend.vanspriel@broadcom.com>,
	Varsha Rao <rvarsha016@gmail.com>,
	linux-wireless@vger.kernel.org, b43-dev@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] b43: Use cordic algorithm from kernel library
Date: Mon, 19 Nov 2018 12:43:32 +0200	[thread overview]
Message-ID: <87lg5pcppn.fsf@kamboji.qca.qualcomm.com> (raw)
In-Reply-To: <df798743-10bb-0455-be83-2fb59eca3209@lwfinger.net> (Larry Finger's message of "Sun, 18 Nov 2018 13:35:57 -0600")

Larry Finger <Larry.Finger@lwfinger.net> writes:

>>>> @@ -1570,10 +1571,10 @@ static u16 b43_nphy_gen_load_samples(struct b43_wldev *dev, u32 freq, u16 max,
>>>>    	angle = 0;
>>>>    	for (i = 0; i < len; i++) {
>>>> -		samples[i] = b43_cordic(angle);
>>>> +		samples[i] = cordic_calc_iq(angle);
>>>>    		angle += rot;
>>>> -		samples[i].q = CORDIC_CONVERT(samples[i].q * max);
>>>> -		samples[i].i = CORDIC_CONVERT(samples[i].i * max);
>>>> +		samples[i].q = CORDIC_FLOAT(samples[i].q * max);
>>>> +		samples[i].i = CORDIC_FLOAT(samples[i].i * max);
>>>>    	}
>>>>    	i = b43_nphy_load_samples(dev, samples, len);
>>>
>>> There is a fundamental flaw in this patch. Routine b43_cordic() takes an
>>> angle in degrees scaled by 2^16, whereas cordic_calc_iq() takes an angle in
>>> degrees. For a given input, the two routines must get different answers. At
>>> a minimum, the calculation of rot would need to remove the left shift of 16.
>>
>> Thanks for the hint. I modified my "test harness" a bit to plot out values
>> from -360 .. 360 and transformed the theta for b43_cordic argument
>> using CORDIC_FIXED macro:
>>
>> b43_cordic(CORDIC_FIXED(theta));
>> cordic_calc_iq(theta);
>>
>> Then I plotted the results and well.. they are not that pretty.
>> While the results give
>> identical answers between certain ranges of degrees, the cordic
>> algorithm for b43 seems
>> to be broken for certain ranges: (-270..-180 ; -90 .. 0; 90.. 180 and 270..360).
>>
>> You can find my test harnesses here:
>>
>> https://gist.github.com/plaes/284993a4fc65e0926d0628a11f0cf874
>
> I found a problem with the b43 implementation. The local variables for
> that routine includes
>
>         u32 angle = 0;
>
> If one looks further down in the algorithm, if the reduced value of
> "theta" is less than 0, then "angle" should be negative. That causes
> the calculation to blow up. This explains why some ranges of angles
> got the same result for both routines. When that declaration is
> changed to "int angle = 0", the two routines give the same answer for
> all inputs.
>
> My test setup has a hardware failure, thus I cannot test your patch,
> but I now believe it to be correct. Thus your first and third patches
> may be annotated with
> ACKed-by: Larry Finger <Larry.Finger@lwfinger.net>
>
> One thing that should be done is to fix the error in the b43 code for
> stable as it was introduced in 2.6.34. I propose adding the attached
> patched to your series placed between your current 2nd and 3rd patches
> so that the old kernels get fixed. Of course, your 3rd patch will need
> to be revised. If all 4 of the patches get submitted together there
> will be no problems with the timing. My change will exist for seconds
> in the mainline kernel, but it will get propagated back through
> stable.

Sorry Larry, I'm not fully understanding what you mean here. So I'm
going to just drop the whole series and assume that Priit will submit a
new version. Please let me know if I should do something else.

-- 
Kalle Valo

  reply	other threads:[~2018-11-19 10:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-14 18:27 [PATCH v3 0/3] wireless: Use common cordic algorithm for b43 driver Priit Laes
2018-11-14 18:27 ` [PATCH v3 1/3] lib: cordic: Move cordic macros and defines to header file Priit Laes
2018-11-14 18:27 ` [PATCH v3 2/3] brcmsmac: Use cordic-related macros from common cordic library Priit Laes
2018-11-14 18:27 ` [PATCH v3 3/3] b43: Use cordic algorithm from kernel library Priit Laes
2018-11-14 18:46   ` Michael Büsch
2018-11-17  8:36     ` Priit Laes
2018-11-17 11:06       ` Kalle Valo
2018-11-18  3:31   ` Larry Finger
2018-11-18  8:23     ` Priit Laes
2018-11-18 19:35       ` Larry Finger
2018-11-19 10:43         ` Kalle Valo [this message]
2018-11-19 11:14           ` Priit Laes
2018-11-19 17:41           ` Larry Finger
2018-11-19 11:27         ` Priit Laes
2018-11-19 17:40           ` Larry Finger
2018-11-15 11:09 ` [PATCH v3 0/3] wireless: Use common cordic algorithm for b43 driver Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lg5pcppn.fsf@kamboji.qca.qualcomm.com \
    --to=kvalo@codeaurora.org \
    --cc=Larry.Finger@lwfinger.net \
    --cc=arend.vanspriel@broadcom.com \
    --cc=b43-dev@lists.infradead.org \
    --cc=baijiaju1990@gmail.com \
    --cc=colin.king@canonical.com \
    --cc=gustavo@embeddedor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=plaes@plaes.org \
    --cc=rvarsha016@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.