From patchwork Tue Mar 18 13:53:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 3853691 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A403CBF540 for ; Wed, 19 Mar 2014 17:45:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8ADD0203B7 for ; Wed, 19 Mar 2014 17:45:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 56C9B20171 for ; Wed, 19 Mar 2014 17:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755309AbaCROAK (ORCPT ); Tue, 18 Mar 2014 10:00:10 -0400 Received: from mail-ee0-f43.google.com ([74.125.83.43]:61818 "EHLO mail-ee0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754708AbaCRN7X (ORCPT ); Tue, 18 Mar 2014 09:59:23 -0400 Received: by mail-ee0-f43.google.com with SMTP id e53so5392732eek.2 for ; Tue, 18 Mar 2014 06:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xtg5P3m3Drgrq5h5Ew5/UuoqqQymBYaXiOOuri5D0mI=; b=4+QgPjWW7EHK2PkEnB/vTIIuq4hDLqIyQZkD7QauOHp4XRwlSqzEyjNV8lZ1Vgo0Av Gz464UvaALZ9jGbzU8wkwv3WadXqgAyqau4TiWVyeB9qRjLn3D9l95kCgkJL+ok4JamR Rpkpd+XoyJ7rdxUjoXvHa4gd5hmpkbYL9wgwY= 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=xtg5P3m3Drgrq5h5Ew5/UuoqqQymBYaXiOOuri5D0mI=; b=B8nbcafcjroqvNqO3srg5e2SiXa8Gd8C8Txu3gZY79gMD85nU6rr3wzv9B8+uLWNzX IlQgwIbt0b5YBxMCEdrazk85lbDPiIl34i0nANBwbU5lQJPCZvMFYbMu0t8CJ04UALdF eMaeFF7evgbm3nO8GOBqdW1DRHqspLbBDii7j7gNW0N0rx7Sy8c3p2va+sU1GzB58ia8 F6Suh6fPO65lwkb1rM/ebFMaKQOhACu6iv8T1lsa1DwNyxi9cc7pXnLlyUjdFqF6FML/ H1OPcai3INzoaQoJ374o8V4q56DMetT8+DiAAlpp6qfIrT2d277w9JKElpiH8gHUuj/x 7CXw== X-Gm-Message-State: ALoCoQmLRj84Mipb0vOSoyz03NZ4DJy5stXuzNGmghTJixypeMdgqHf9YBx/PBDyto+WDYv9wp2cYzy7a+BvSCIRI+yERJLwx6PJl8AIq4UAiQ67gIxIA80= X-Received: by 10.14.126.73 with SMTP id a49mr30328524eei.46.1395151161995; Tue, 18 Mar 2014 06:59:21 -0700 (PDT) Received: from localhost.localdomain ([91.198.246.8]) by mx.google.com with ESMTPSA id x45sm35223167eeu.23.2014.03.18.06.59.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Mar 2014 06:59:21 -0700 (PDT) From: Michal Kazior To: linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net, Michal Kazior Subject: [RFC 12/21] mac80211: compute chanctx refcount on-the-fly Date: Tue, 18 Mar 2014 14:53:15 +0100 Message-Id: <1395150804-24090-13-git-send-email-michal.kazior@tieto.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1395150804-24090-1-git-send-email-michal.kazior@tieto.com> References: <1395150804-24090-1-git-send-email-michal.kazior@tieto.com> X-DomainID: tieto.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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_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 It doesn't make much sense to store refcount in the chanctx structure. One still needs to hold chanctx_mtx to get the value safely. Besides, refcount isn't on performance critical paths. This will make implementing chanctx reservation refcounting a little easier. Signed-off-by: Michal Kazior --- net/mac80211/cfg.c | 2 +- net/mac80211/chan.c | 59 +++++++++++++++++++++++++++++++++++----------- net/mac80211/ieee80211_i.h | 3 ++- net/mac80211/mlme.c | 2 +- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 61b62f4..954259d 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -3251,7 +3251,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, /* don't handle for multi-VIF cases */ chanctx = container_of(conf, struct ieee80211_chanctx, conf); - if (chanctx->refcount > 1) { + if (ieee80211_chanctx_refcount(local, chanctx) > 1) { mutex_unlock(&local->chanctx_mtx); return -EBUSY; } diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c index 623df6f..e99362d 100644 --- a/net/mac80211/chan.c +++ b/net/mac80211/chan.c @@ -9,6 +9,41 @@ #include "ieee80211_i.h" #include "driver-ops.h" +static int ieee80211_chanctx_num_assigned(struct ieee80211_local *local, + struct ieee80211_chanctx *ctx) +{ + struct ieee80211_sub_if_data *sdata; + int num = 0; + + lockdep_assert_held(&local->chanctx_mtx); + + list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list) + num++; + + return num; +} + +static int ieee80211_chanctx_num_reserved(struct ieee80211_local *local, + struct ieee80211_chanctx *ctx) +{ + struct ieee80211_sub_if_data *sdata; + int num = 0; + + lockdep_assert_held(&local->chanctx_mtx); + + list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list) + num++; + + return num; +} + +int ieee80211_chanctx_refcount(struct ieee80211_local *local, + struct ieee80211_chanctx *ctx) +{ + return ieee80211_chanctx_num_assigned(local, ctx) + + ieee80211_chanctx_num_reserved(local, ctx); +} + static int ieee80211_num_chanctx(struct ieee80211_local *local) { struct ieee80211_chanctx *ctx; @@ -465,7 +500,7 @@ static void ieee80211_free_chanctx(struct ieee80211_local *local, { lockdep_assert_held(&local->chanctx_mtx); - WARN_ON_ONCE(ctx->refcount != 0); + WARN_ON_ONCE(ieee80211_chanctx_refcount(local, ctx) != 0); list_del_rcu(&ctx->list); ieee80211_del_chanctx(local, ctx); @@ -544,7 +579,6 @@ static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata, if (conf) { curr_ctx = container_of(conf, struct ieee80211_chanctx, conf); - curr_ctx->refcount--; drv_unassign_vif_chanctx(local, sdata, curr_ctx); conf = NULL; list_del(&sdata->assigned_chanctx_list); @@ -555,7 +589,6 @@ static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata, if (ret) goto out; - new_ctx->refcount++; conf = &new_ctx->conf; list_add(&sdata->assigned_chanctx_list, &new_ctx->assigned_vifs); @@ -566,14 +599,14 @@ out: sdata->vif.bss_conf.idle = !conf; - if (curr_ctx && curr_ctx->refcount > 0) { + if (curr_ctx && ieee80211_chanctx_num_assigned(local, curr_ctx) > 0) { ieee80211_recalc_chanctx_chantype(local, curr_ctx); ieee80211_recalc_smps_chanctx(local, curr_ctx); ieee80211_recalc_radar_chanctx(local, curr_ctx); ieee80211_recalc_chanctx_min_def(local, curr_ctx); } - if (new_ctx && new_ctx->refcount > 0) { + if (new_ctx && ieee80211_chanctx_num_assigned(local, new_ctx) > 0) { ieee80211_recalc_txpower(sdata); ieee80211_recalc_chanctx_min_def(local, new_ctx); } @@ -605,7 +638,7 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) ieee80211_vif_unreserve_chanctx(sdata); ieee80211_assign_vif_chanctx(sdata, NULL); - if (ctx->refcount == 0) + if (ieee80211_chanctx_refcount(local, ctx) == 0) ieee80211_free_chanctx(local, ctx); } @@ -737,7 +770,7 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, ret = ieee80211_assign_vif_chanctx(sdata, ctx); if (ret) { /* if assign fails refcount stays the same */ - if (ctx->refcount == 0) + if (ieee80211_chanctx_refcount(local, ctx) == 0) ieee80211_free_chanctx(local, ctx); goto out; } @@ -761,7 +794,7 @@ static int __ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata, IEEE80211_CHAN_DISABLED)) return -EINVAL; - if (ctx->refcount != 1) + if (ieee80211_chanctx_refcount(local, ctx) != 1) return -EINVAL; if (sdata->vif.bss_conf.chandef.width != chandef->width) { @@ -867,7 +900,7 @@ int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata) list_del(&sdata->reserved_chanctx_list); sdata->reserved_chanctx = NULL; - if (--ctx->refcount == 0) + if (ieee80211_chanctx_refcount(sdata->local, ctx) == 0) ieee80211_free_chanctx(sdata->local, ctx); return 0; @@ -896,7 +929,7 @@ int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata, new_ctx = ieee80211_find_reservation_chanctx(local, chandef, mode); if (!new_ctx) { - if (curr_ctx->refcount == 1 && + if (ieee80211_chanctx_refcount(local, curr_ctx) == 1 && (local->hw.flags & IEEE80211_HW_CHANGE_RUNNING_CHANCTX)) { /* if we're the only users of the chanctx and * the driver supports changing a running @@ -917,7 +950,6 @@ int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata, } list_add(&sdata->reserved_chanctx_list, &new_ctx->reserved_vifs); - new_ctx->refcount++; sdata->reserved_chanctx = new_ctx; sdata->reserved_chandef = *chandef; sdata->reserved_radar_required = radar_required; @@ -963,7 +995,6 @@ int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata, sdata->vif.bss_conf.chandef = sdata->reserved_chandef; /* unref our reservation */ - ctx->refcount--; sdata->reserved_chanctx = NULL; sdata->radar_required = sdata->reserved_radar_required; list_del(&sdata->reserved_chanctx_list); @@ -976,11 +1007,11 @@ int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata, goto out; } else { ret = ieee80211_assign_vif_chanctx(sdata, ctx); - if (old_ctx->refcount == 0) + if (ieee80211_chanctx_refcount(local, old_ctx) == 0) ieee80211_free_chanctx(local, old_ctx); if (ret) { /* if assign fails refcount stays the same */ - if (ctx->refcount == 0) + if (ieee80211_chanctx_refcount(local, ctx) == 0) ieee80211_free_chanctx(local, ctx); goto out; } diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 0701631..2de8121 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -695,7 +695,6 @@ struct ieee80211_chanctx { struct list_head reserved_vifs; enum ieee80211_chanctx_mode mode; - int refcount; bool driver_present; struct ieee80211_chanctx_conf conf; @@ -1802,6 +1801,8 @@ void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata); void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata); void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, bool clear); +int ieee80211_chanctx_refcount(struct ieee80211_local *local, + struct ieee80211_chanctx *ctx); void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local, struct ieee80211_chanctx *chanctx); diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 94f0af2..a4d8e99 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -1089,7 +1089,7 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, } chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf), struct ieee80211_chanctx, conf); - if (chanctx->refcount > 1) { + if (ieee80211_chanctx_refcount(local, chanctx) > 1) { sdata_info(sdata, "channel switch with multiple interfaces on the same channel, disconnecting\n"); ieee80211_queue_work(&local->hw,