From patchwork Tue Sep 17 15:41:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eliad Peller X-Patchwork-Id: 2903001 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D08779F1E3 for ; Tue, 17 Sep 2013 15:42:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 63E4A20179 for ; Tue, 17 Sep 2013 15:42:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 946EB2038B for ; Tue, 17 Sep 2013 15:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753105Ab3IQPlq (ORCPT ); Tue, 17 Sep 2013 11:41:46 -0400 Received: from mail-ea0-f179.google.com ([209.85.215.179]:61097 "EHLO mail-ea0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753002Ab3IQPlp (ORCPT ); Tue, 17 Sep 2013 11:41:45 -0400 Received: by mail-ea0-f179.google.com with SMTP id b10so2803174eae.38 for ; Tue, 17 Sep 2013 08:41:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=30ZEXabPicteyyQIa1DGyCyPhdpsI+fw78MT217gT5w=; b=mPxwPL/f9vXrTtCZYPdUQ0+WZ2oKBu8T+NOh6aBNogedyDhl4SVQkcaiDtMr/YRLow 5vGwIfdzcsd9XCTKeydfBR2yMM6ZFENvT7714QCGxXHakmwSh1XJ13zZqBwnl38L639d 5q5ga3f9lY0g0c67akq4No6TLbr6a2qzWdhSEh640EJnjpXruoXrxatju+4nnbvUfMWj 0UTUJjN1zZT4QhzcWM5ktiyqxMAnutOE11rnHIkh/B5l61CGF0Ez9mXCFZYU/2Ou2w09 U8+PaR1l4QIddmsAhqaxC+9lHle/uDaOhfAmimkYwg8KLFRvHK9fQ4hXEl6Apzu/KHLX IKmA== X-Gm-Message-State: ALoCoQm2rhqXjoLj84rxo78YhaahyeLdWH9G1FvKcaV6xwh12uDey4iu2muJXlNm8eika+FzY4J8 X-Received: by 10.15.32.136 with SMTP id a8mr3359336eev.71.1379432504005; Tue, 17 Sep 2013 08:41:44 -0700 (PDT) Received: from localhost.localdomain (85-250-66-253.bb.netvision.net.il. [85.250.66.253]) by mx.google.com with ESMTPSA id p5sm51918197eeg.5.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Sep 2013 08:41:43 -0700 (PDT) From: Eliad Peller To: Luciano Coelho Cc: Subject: [PATCH v2 08/11] wlcore: clarify and fix regulatory domain bit translation Date: Tue, 17 Sep 2013 18:41:27 +0300 Message-Id: <1379432490-22157-8-git-send-email-eliad@wizery.com> X-Mailer: git-send-email 1.8.3.rc1.35.g9b79519 In-Reply-To: <1379432490-22157-1-git-send-email-eliad@wizery.com> References: <1379432490-22157-1-git-send-email-eliad@wizery.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Channels 52-64 were mapped incorrectly. Refactor and document wlcore_get_reg_conf_ch_idx() in order to make it clear what's going on there. While on it, fix the return value check to consider 0 as a valid return value as well (indicates channel 1). Reported-by: Yaniv Machani Signed-off-by: Eliad Peller Signed-off-by: Ido Reis Signed-off-by: Victor Goldenshtein --- drivers/net/wireless/ti/wlcore/cmd.c | 52 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c index e3ae425..9e5416f8 100644 --- a/drivers/net/wireless/ti/wlcore/cmd.c +++ b/drivers/net/wireless/ti/wlcore/cmd.c @@ -1607,33 +1607,43 @@ out: static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band, u16 ch) { - int idx = -1; - + /* + * map the given band/channel to the respective predefined + * bit expected by the fw + */ switch (band) { - case IEEE80211_BAND_5GHZ: - if (ch >= 8 && ch <= 16) - idx = ((ch-8)/4 + 18); - else if (ch >= 34 && ch <= 64) - idx = ((ch-34)/2 + 3 + 18); - else if (ch >= 100 && ch <= 140) - idx = ((ch-100)/4 + 15 + 18); - else if (ch >= 149 && ch <= 165) - idx = ((ch-149)/4 + 26 + 18); - else - idx = -1; - break; case IEEE80211_BAND_2GHZ: + /* channels 1..14 are mapped to 0..13 */ if (ch >= 1 && ch <= 14) - idx = ch - 1; - else - idx = -1; + return ch - 1; + break; + case IEEE80211_BAND_5GHZ: + switch (ch) { + case 8 ... 16: + /* channels 8,12,16 are mapped to 18,19,20 */ + return 18 + (ch-8)/4; + case 34 ... 48: + /* channels 34,36..48 are mapped to 21..28 */ + return 21 + (ch-34)/2; + case 52 ... 64: + /* channels 52,56..64 are mapped to 29..32 */ + return 29 + (ch-52)/4; + case 100 ... 140: + /* channels 100,104..140 are mapped to 33..43 */ + return 33 + (ch-100)/4; + case 149 ... 165: + /* channels 149,153..165 are mapped to 44..48 */ + return 44 + (ch-149)/4; + default: + break; + } break; default: - wl1271_error("get reg conf ch idx - unknown band: %d", - (int)band); + break; } - return idx; + wl1271_error("%s: unknown band/channel: %d/%d", __func__, band, ch); + return -1; } void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel, @@ -1646,7 +1656,7 @@ void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel, ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel); - if (ch_bit_idx > 0 && ch_bit_idx <= WL1271_MAX_CHANNELS) + if (ch_bit_idx >= 0 && ch_bit_idx <= WL1271_MAX_CHANNELS) set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending); }