Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp715101ybz; Wed, 15 Apr 2020 17:21:02 -0700 (PDT) X-Google-Smtp-Source: APiQypI5HEG+9kwpix8HSvaoDf+9NwiWWVhZrdTCgZlilNUHIxZjmZx0+Lq+6hwbYEj9PugZgB+v X-Received: by 2002:aa7:c90d:: with SMTP id b13mr11205496edt.14.1586996462709; Wed, 15 Apr 2020 17:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586996462; cv=none; d=google.com; s=arc-20160816; b=YCLp8SD5UQ7jarRySrZc8zYQX/ZB0O8xi2Ikq804+8K+8W5vRHKgxRGI2D8Sz18Gdl Vn1+498O+mgHN6lpAoVPR//vsTeYlPAUowLCO4qBxtFkp1fEWvWAPLGkOXDlzMvpjc5W 49O3/nayFTue3s1lbJLroR6rp6oE18iaTWmdtLD56ugh04Ms+33gCYgCR+JAS0c9wn+c 3gJKY02t4coz1gSqKtSPfFxXzjKVxXZM4ycA9JUki82n38nhh2sBH0rxribhkeLxJtt6 A4UBMMmHZ/Hgtkc9SfpDD7RUU29s87I14XsxHFshZ/7ZRFpZq2l6psxns1sCZbTXJLKZ 0uFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:dkim-signature; bh=Vu1CQuZeQboKmC9G4fwI28n6pl1G54U+sZQ4vl/FEKs=; b=xPOfc2KQO6e1HGMRaHRmIXx7ehBtSfA374bIsB0Oy3hChPeVdWdKvESykcCfbevOq5 JsB9isUUm7cOI78A9EkfSG0E1xBUL9rKXbj1G4qb3b65iDv6pAEI1azu7foZt8zztSPD KCyjM2iB6cASjlMJhBuyjqDl1tje3C31D/QJyV6Ls7UodcTJ6//1SBVtivb7uxW9KeKL gN6czOfftqsu4WyiIx2OyPjJ120++KCfa2C4rqo88pY6okCtiI3sQNS2TMwV4U4HJwBO mB7eUT5jBsjvtQxtt1wBpfT97xh0IULc+zccrepbqGJogbk6LTYwi8tdjaZDb2iSB3ah HHHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=EoWkEo3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h1si10452365ejd.517.2020.04.15.17.20.39; Wed, 15 Apr 2020 17:21:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=EoWkEo3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1415886AbgDOQ06 (ORCPT + 99 others); Wed, 15 Apr 2020 12:26:58 -0400 Received: from mout.gmx.net ([212.227.17.20]:39147 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1415805AbgDOQ0K (ORCPT ); Wed, 15 Apr 2020 12:26:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1586967955; bh=zl3dIME8m5TAi4H0VnWtCwmfus3CS38tz+uqFrZLE1w=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=EoWkEo3fYpyU9jMc6NtPYxkbJNsU49EZB02cQCuQO9SzL4hW9OyzHimcLgp7X/FuP v/sz2iARfIKUlRUBEeR3KCYHHmpDWYBV+xeAcpgIaFoLbYKyI2fnzEh/ykyMLgAl2C rB34eP65M0VuWKagZKsRXyHlM41nzdnjlUFjf9B4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from ubuntu ([83.52.229.196]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MybGX-1j3lzq20nF-00z2mN; Wed, 15 Apr 2020 18:25:55 +0200 Date: Wed, 15 Apr 2020 18:25:41 +0200 From: Oscar Carter To: Dan Carpenter Cc: Oscar Carter , Forest Bond , Greg Kroah-Hartman , Malcolm Priestley , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [RFC] staging: vt6656: Add formula to the vnt_rf_addpower function Message-ID: <20200415162541.GA3893@ubuntu> References: <20200413140209.4520-1-oscar.carter@gmx.com> <20200414131214.GI1163@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200414131214.GI1163@kadam> User-Agent: Mutt/1.10.1 (2018-07-13) X-Provags-ID: V03:K1:nYv/kF/we1JsuO8LWjxXq+0QxYonZ31MEK38T47ADdrh0589O4i kKbTs3IDTUpwuWyR9qXUZ11R4nSeLzNGWtzyefZefMGS0OVxboJYvnfCnbuZL0KU/tmt0vF GHXlRtEjnYnZNNY/jMZeZL3oMWv04e2+4HJ06Ct7DcTxgb18fOoBZgGxO7qDVfSm0hjQWJ3 CiJI6fa0cQzg5E/In9PvQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fBHZRgKJ54A=:dr7qHGkXpeErDhFX4qfEZ4 +MhL7j3VSPyXXieVkOuSc0iiQyUZwEQF7TFIEhe9lVIdjTBHL3OZNM+ftFQmwjZUMG6IXqS8c 2m5xtZ61xduDMiKzsEFjGxS4rHw0idiXHeLCF96+Jpf1dcBZXjTZ53liRAzYe9n3F9bWAF+HZ Pe94AK7Um6mfMbm1X7tj2TUIBhK3P0M2ZI2eVWwZ8Lj5cqMGRatmxZAmAR4MzDhZn384rLwEj pu4334sGEpHc/UZcYtZGjZxKG7wM/JbAC0HoiSyYyLPj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mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 14, 2020 at 04:12:14PM +0300, Dan Carpenter wrote: > On Mon, Apr 13, 2020 at 04:02:09PM +0200, Oscar Carter wrote: > > diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c > > index 4f9aba0f21b0..3b200d7290a5 100644 > > --- a/drivers/staging/vt6656/rf.c > > +++ b/drivers/staging/vt6656/rf.c > > @@ -575,28 +575,14 @@ int vnt_rf_setpower(struct vnt_private *priv, u3= 2 rate, u32 channel) > > > > static u8 vnt_rf_addpower(struct vnt_private *priv) > > { > > + s32 base; > > Just use "int". s32 is for when signed 32 bit is specified in the > hardware. I realize that it's done in this file, but if all your > friends jumped off a bridge doesn't mean you should drink their kool-aid= . Ok, lesson learned and thanks for the aclaration about when use every type= . > > s32 rssi =3D -priv->current_rssi; > > > > if (!rssi) > > return 7; > > > > - if (priv->rf_type =3D=3D RF_VT3226D0) { > > - if (rssi < -70) > > - return 9; > > - else if (rssi < -65) > > - return 7; > > - else if (rssi < -60) > > - return 5; > > - } else { > > - if (rssi < -80) > > - return 9; > > - else if (rssi < -75) > > - return 7; > > - else if (rssi < -70) > > - return 5; > > - } > > - > > - return 0; > > + base =3D (priv->rf_type =3D=3D RF_VT3226D0) ? -60 : -70; > > + return (rssi < base--) ? ((rssi - base) / -5) * 2 + 5 : 0; > ^^^^^^ > I quite hate this postop. It would have been cleaner to write it like: > > return (rssi < base) ? ((rssi - (base - 1)) / -5) * 2 + 5 : 0 ^ ^ Now, if we apply the minus operator one parentheses can be removed. The same expression is now: return (rssi < base) ? ((rssi - base + 1) / -5) * 2 + 5 : 0 I think it's clear enought. > I'm sorry, I'm not clever enough to figure out the potential values of > "rssi". The IEEE 802.11 standard specifies that RSSI can be on a scale of 0 to up to 255, and that each chipset manufacturer can define their own max RSSI value. It's all up to the manufacturer. > How did you work out this formula? It feels like it came from > a standard or something? I realized that the two branches of the if statement return the same values (5, 7, 9) and that each value has a difference of 2 units from the previous one. Also, every branch has 3 ranges, and every range has an interval of 5. The only difference in this case is the "base" value of each branch. So, the solution was obtain the range index --> (rssi - base) / -5 Then, we need two units for every range index -> * 2 Now, the return value starts with five -------> + 5 The base-- was to obtain the range index the same that the orignal function. > Do we not have a function already which implements the standard? I have been searching but I have not found anything that relates the RSSI value with the amount of power to add. I have found struct station_parameters -> member txpwr (struct sta_txpwr type) but all the functions related to this doesn't set the tx power depending on the RSSI value. > regards, > dan carpenter > thanks, oscar carter