Skip to content

Commit

Permalink
mac80211: add driver ops wrappers
Browse files Browse the repository at this point in the history
In order to later add tracing or verifications to the driver
calls mac80211 makes, this patch adds static inline wrappers
for all operations.

All calls are now written as

	drv_<op>(local, ...);

instead of

	local->ops-><op>(&local->hw, ...);

Where necessary, the wrappers also do existence checking and
return default values as appropriate.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Johannes Berg authored and John W. Linville committed May 6, 2009
1 parent 2d0ddec commit 2448798
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 130 deletions.
11 changes: 5 additions & 6 deletions net/mac80211/agg-rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#include <linux/ieee80211.h>
#include <net/mac80211.h>
#include "ieee80211_i.h"
#include "driver-ops.h"

void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
u16 initiator, u16 reason)
{
struct ieee80211_local *local = sta->local;
struct ieee80211_hw *hw = &local->hw;
int i;

/* check if TID is in operational state */
Expand All @@ -41,8 +41,8 @@ void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
sta->sta.addr, tid);
#endif /* CONFIG_MAC80211_HT_DEBUG */

if (local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
&sta->sta, tid, NULL))
if (drv_ampdu_action(local, IEEE80211_AMPDU_RX_STOP,
&sta->sta, tid, NULL))
printk(KERN_DEBUG "HW problem - can not stop rx "
"aggregation for tid %d\n", tid);

Expand Down Expand Up @@ -278,9 +278,8 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
goto end;
}

if (local->ops->ampdu_action)
ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
&sta->sta, tid, &start_seq_num);
ret = drv_ampdu_action(local, IEEE80211_AMPDU_RX_START,
&sta->sta, tid, &start_seq_num);
#ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
#endif /* CONFIG_MAC80211_HT_DEBUG */
Expand Down
13 changes: 7 additions & 6 deletions net/mac80211/agg-tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/ieee80211.h>
#include <net/mac80211.h>
#include "ieee80211_i.h"
#include "driver-ops.h"
#include "wme.h"

/**
Expand Down Expand Up @@ -134,8 +135,8 @@ static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
*state = HT_AGG_STATE_REQ_STOP_BA_MSK |
(initiator << HT_AGG_STATE_INITIATOR_SHIFT);

ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP,
&sta->sta, tid, NULL);
ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_STOP,
&sta->sta, tid, NULL);

/* HW shall not deny going back to legacy */
if (WARN_ON(ret)) {
Expand Down Expand Up @@ -306,8 +307,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)

start_seq_num = sta->tid_seq[tid];

ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
&sta->sta, tid, &start_seq_num);
ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_START,
&sta->sta, tid, &start_seq_num);

if (ret) {
#ifdef CONFIG_MAC80211_HT_DEBUG
Expand Down Expand Up @@ -418,8 +419,8 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
ieee80211_agg_splice_finish(local, sta, tid);
spin_unlock(&local->ampdu_lock);

local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_OPERATIONAL,
&sta->sta, tid, NULL);
drv_ampdu_action(local, IEEE80211_AMPDU_TX_OPERATIONAL,
&sta->sta, tid, NULL);
}

void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
Expand Down
24 changes: 10 additions & 14 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/rcupdate.h>
#include <net/cfg80211.h>
#include "ieee80211_i.h"
#include "driver-ops.h"
#include "cfg.h"
#include "rate.h"
#include "mesh.h"
Expand Down Expand Up @@ -245,12 +246,10 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
iv32 = key->u.tkip.tx.iv32;
iv16 = key->u.tkip.tx.iv16;

if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
sdata->local->ops->get_tkip_seq)
sdata->local->ops->get_tkip_seq(
local_to_hw(sdata->local),
key->conf.hw_key_idx,
&iv32, &iv16);
if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
drv_get_tkip_seq(sdata->local,
key->conf.hw_key_idx,
&iv32, &iv16);

seq[0] = iv16 & 0xff;
seq[1] = (iv16 >> 8) & 0xff;
Expand Down Expand Up @@ -1115,7 +1114,7 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,
p.cw_max = params->cwmax;
p.cw_min = params->cwmin;
p.txop = params->txop;
if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
if (drv_conf_tx(local, params->queue, &p)) {
printk(KERN_DEBUG "%s: failed to set TX queue "
"parameters for queue %d\n", local->mdev->name,
params->queue);
Expand Down Expand Up @@ -1296,16 +1295,13 @@ static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
int err;

if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
int err;
err = drv_set_rts_threshold(local, wiphy->rts_threshold);

if (local->ops->set_rts_threshold) {
err = local->ops->set_rts_threshold(
local_to_hw(local), wiphy->rts_threshold);
if (err)
return err;
}
if (err)
return err;
}

if (changed & WIPHY_PARAM_RETRY_SHORT)
Expand Down
20 changes: 9 additions & 11 deletions net/mac80211/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/debugfs.h>
#include <linux/rtnetlink.h>
#include "ieee80211_i.h"
#include "driver-ops.h"
#include "rate.h"
#include "debugfs.h"

Expand Down Expand Up @@ -70,11 +71,10 @@ static ssize_t tsf_read(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
struct ieee80211_local *local = file->private_data;
u64 tsf = 0;
u64 tsf;
char buf[100];

if (local->ops->get_tsf)
tsf = local->ops->get_tsf(local_to_hw(local));
tsf = drv_get_tsf(local);

snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);

Expand All @@ -97,13 +97,13 @@ static ssize_t tsf_write(struct file *file,

if (strncmp(buf, "reset", 5) == 0) {
if (local->ops->reset_tsf) {
local->ops->reset_tsf(local_to_hw(local));
drv_reset_tsf(local);
printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
}
} else {
tsf = simple_strtoul(buf, NULL, 0);
if (local->ops->set_tsf) {
local->ops->set_tsf(local_to_hw(local), tsf);
drv_set_tsf(local, tsf);
printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
}
}
Expand Down Expand Up @@ -150,14 +150,12 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local,
char buf[20];
int res;

if (!local->ops->get_stats)
return -EOPNOTSUPP;

rtnl_lock();
res = local->ops->get_stats(local_to_hw(local), &stats);
res = drv_get_stats(local, &stats);
rtnl_unlock();
if (!res)
res = printvalue(&stats, buf, sizeof(buf));
if (res)
return res;
res = printvalue(&stats, buf, sizeof(buf));
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
}

Expand Down
184 changes: 184 additions & 0 deletions net/mac80211/driver-ops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#ifndef __MAC80211_DRIVER_OPS
#define __MAC80211_DRIVER_OPS

#include <net/mac80211.h>
#include "ieee80211_i.h"

static inline int drv_tx(struct ieee80211_local *local, struct sk_buff *skb)
{
return local->ops->tx(&local->hw, skb);
}

static inline int drv_start(struct ieee80211_local *local)
{
return local->ops->start(&local->hw);
}

static inline void drv_stop(struct ieee80211_local *local)
{
local->ops->stop(&local->hw);
}

static inline int drv_add_interface(struct ieee80211_local *local,
struct ieee80211_if_init_conf *conf)
{
return local->ops->add_interface(&local->hw, conf);
}

static inline void drv_remove_interface(struct ieee80211_local *local,
struct ieee80211_if_init_conf *conf)
{
local->ops->remove_interface(&local->hw, conf);
}

static inline int drv_config(struct ieee80211_local *local, u32 changed)
{
return local->ops->config(&local->hw, changed);
}

static inline void drv_bss_info_changed(struct ieee80211_local *local,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *info,
u32 changed)
{
if (local->ops->bss_info_changed)
local->ops->bss_info_changed(&local->hw, vif, info, changed);
}

static inline void drv_configure_filter(struct ieee80211_local *local,
unsigned int changed_flags,
unsigned int *total_flags,
int mc_count,
struct dev_addr_list *mc_list)
{
local->ops->configure_filter(&local->hw, changed_flags, total_flags,
mc_count, mc_list);
}

static inline int drv_set_tim(struct ieee80211_local *local,
struct ieee80211_sta *sta, bool set)
{
if (local->ops->set_tim)
return local->ops->set_tim(&local->hw, sta, set);
return 0;
}

static inline int drv_set_key(struct ieee80211_local *local,
enum set_key_cmd cmd, struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
{
return local->ops->set_key(&local->hw, cmd, vif, sta, key);
}

static inline void drv_update_tkip_key(struct ieee80211_local *local,
struct ieee80211_key_conf *conf,
const u8 *address, u32 iv32,
u16 *phase1key)
{
if (local->ops->update_tkip_key)
local->ops->update_tkip_key(&local->hw, conf, address,
iv32, phase1key);
}

static inline int drv_hw_scan(struct ieee80211_local *local,
struct cfg80211_scan_request *req)
{
return local->ops->hw_scan(&local->hw, req);
}

static inline void drv_sw_scan_start(struct ieee80211_local *local)
{
if (local->ops->sw_scan_start)
local->ops->sw_scan_start(&local->hw);
}

static inline void drv_sw_scan_complete(struct ieee80211_local *local)
{
if (local->ops->sw_scan_complete)
local->ops->sw_scan_complete(&local->hw);
}

static inline int drv_get_stats(struct ieee80211_local *local,
struct ieee80211_low_level_stats *stats)
{
if (!local->ops->get_stats)
return -EOPNOTSUPP;
return local->ops->get_stats(&local->hw, stats);
}

static inline void drv_get_tkip_seq(struct ieee80211_local *local,
u8 hw_key_idx, u32 *iv32, u16 *iv16)
{
if (local->ops->get_tkip_seq)
local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
}

static inline int drv_set_rts_threshold(struct ieee80211_local *local,
u32 value)
{
if (local->ops->set_rts_threshold)
return local->ops->set_rts_threshold(&local->hw, value);
return 0;
}

static inline void drv_sta_notify(struct ieee80211_local *local,
struct ieee80211_vif *vif,
enum sta_notify_cmd cmd,
struct ieee80211_sta *sta)
{
if (local->ops->sta_notify)
local->ops->sta_notify(&local->hw, vif, cmd, sta);
}

static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue,
const struct ieee80211_tx_queue_params *params)
{
if (local->ops->conf_tx)
return local->ops->conf_tx(&local->hw, queue, params);
return -EOPNOTSUPP;
}

static inline int drv_get_tx_stats(struct ieee80211_local *local,
struct ieee80211_tx_queue_stats *stats)
{
return local->ops->get_tx_stats(&local->hw, stats);
}

static inline u64 drv_get_tsf(struct ieee80211_local *local)
{
if (local->ops->get_tsf)
return local->ops->get_tsf(&local->hw);
return -1ULL;
}

static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf)
{
if (local->ops->set_tsf)
local->ops->set_tsf(&local->hw, tsf);
}

static inline void drv_reset_tsf(struct ieee80211_local *local)
{
if (local->ops->reset_tsf)
local->ops->reset_tsf(&local->hw);
}

static inline int drv_tx_last_beacon(struct ieee80211_local *local)
{
if (local->ops->tx_last_beacon)
return local->ops->tx_last_beacon(&local->hw);
return 1;
}

static inline int drv_ampdu_action(struct ieee80211_local *local,
enum ieee80211_ampdu_mlme_action action,
struct ieee80211_sta *sta, u16 tid,
u16 *ssn)
{
if (local->ops->ampdu_action)
return local->ops->ampdu_action(&local->hw, action,
sta, tid, ssn);
return -EOPNOTSUPP;
}
#endif /* __MAC80211_DRIVER_OPS */
Loading

0 comments on commit 2448798

Please sign in to comment.