Skip to content

Commit

Permalink
move mt76_wcid_alloc to core
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Fietkau <[email protected]>
  • Loading branch information
Felix Fietkau committed Dec 20, 2015
1 parent 93db8ee commit b948496
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
24 changes: 1 addition & 23 deletions mt76x2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,6 @@ mt76x2_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
mutex_unlock(&dev->mutex);
}

static int
mt76_wcid_alloc(struct mt76x2_dev *dev)
{
int i, idx = 0;

for (i = 0; i < ARRAY_SIZE(dev->wcid_mask); i++) {
idx = ffs(~dev->wcid_mask[i]);
if (!idx)
continue;

idx--;
dev->wcid_mask[i] |= BIT(idx);
break;
}

idx = i * BITS_PER_LONG + idx;
if (idx > 247)
return -1;

return idx;
}

static int
mt76x2_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
Expand All @@ -223,7 +201,7 @@ mt76x2_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,

mutex_lock(&dev->mutex);

idx = mt76_wcid_alloc(dev);
idx = mt76_wcid_alloc(dev->wcid_mask, ARRAY_SIZE(dev->wcid));
if (idx < 0) {
ret = -ENOSPC;
goto out;
Expand Down
22 changes: 22 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,26 @@ bool __mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,
}
EXPORT_SYMBOL_GPL(__mt76_poll_msec);

int mt76_wcid_alloc(unsigned long *mask, int size)
{
int i, idx = 0, cur;

for (i = 0; i < size / BITS_PER_LONG; i++) {
idx = ffs(~mask[i]);
if (!idx)
continue;

idx--;
cur = i * BITS_PER_LONG + idx;
if (cur >= size)
break;

mask[i] |= BIT(idx);
return cur;
}

return -1;
}
EXPORT_SYMBOL_GPL(mt76_wcid_alloc);

MODULE_LICENSE("GPL");
1 change: 1 addition & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

int mt76_insert_hdr_pad(struct sk_buff *skb);
void mt76_remove_hdr_pad(struct sk_buff *skb);
int mt76_wcid_alloc(unsigned long *mask, int size);

static inline void
mt76_skb_set_moredata(struct sk_buff *skb, bool enable)
Expand Down

0 comments on commit b948496

Please sign in to comment.