Skip to content

Commit

Permalink
mac80211: add support for multiple wiphys behind a single device
Browse files Browse the repository at this point in the history
backport from openwrt(8b15e7f661b4263a7b9fb6a410a5f58263b72caa),
original message:

The device path will be the same for the first phy. For all subsequent
phys, the path gets an extra +1, +2, ...
Move the code for converting path to phy and vice versa to a separate
library script shared by config detection code and the netifd wireless
handler script

Signed-off-by: Felix Fietkau <[email protected]>
  • Loading branch information
mantas-p committed Nov 9, 2020
1 parent 174e417 commit 31a19eb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 66 deletions.
1 change: 1 addition & 0 deletions qca/feeds/wlan-open/mac80211/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ define KernelPackage/cfg80211/install
$(INSTALL_DIR) $(1)/lib/wifi $(1)/etc/hotplug.d/devcoredump
$(INSTALL_DIR) $(1)/lib/wifi $(1)/lib/netifd/wireless
$(INSTALL_DATA) ./files/lib/wifi/mac80211.sh $(1)/lib/wifi
$(INSTALL_DATA) ./files/lib/netifd/mac80211.sh $(1)/lib/netifd
$(INSTALL_BIN) ./files/lib/netifd/wireless/mac80211.sh $(1)/lib/netifd/wireless
$(INSTALL_BIN) ./files/lib/performance.sh $(1)/lib
$(INSTALL_BIN) ./files/lib/smp_affinity_settings.sh $(1)/lib
Expand Down
36 changes: 36 additions & 0 deletions qca/feeds/wlan-open/mac80211/files/lib/netifd/mac80211.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mac80211_phy_to_path() {
local phy="$1"

[ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${phy} ] || return

local path="$(readlink -f /sys/class/ieee80211/${phy}/device)"
[ -n "$path" ] || return

path="${path##/sys/devices/}"
case "$path" in
platform*/pci*) path="${path##platform/}";;
esac

local p
local seq=""
for p in $(ls /sys/class/ieee80211/$phy/device/ieee80211); do
[ "$p" = "$phy" ] && {
echo "$path${seq:++$seq}"
break
}

seq=$((${seq:-0} + 1))
done
}

mac80211_path_to_phy() {
local path="$1"

local p
for p in $(ls /sys/class/ieee80211); do
local cur="$(mac80211_phy_to_path "$p")"
case "$cur" in
*$path) echo "$p"; return;;
esac
done
}
39 changes: 7 additions & 32 deletions qca/feeds/wlan-open/mac80211/files/lib/netifd/wireless/mac80211.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[ -e /lib/netifd/hostapd.sh ] && . /lib/netifd/hostapd.sh
[ -e /lib/wifi/hostapd.sh ] && . /lib/wifi/hostapd.sh
[ -e /lib/wifi/wpa_supplicant.sh ] && . /lib/wifi/wpa_supplicant.sh
. /lib/netifd/mac80211.sh

init_wireless_driver "$@"

Expand Down Expand Up @@ -717,34 +718,9 @@ mac80211_generate_mac() {

find_phy() {
[ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0

# Incase multiple radio's are in the same soc, device path
# for these radio's will be the same. In such case we can
# get the phy based on the phy index of the soc
local radio_idx=${1:5:1}
local first_phy_idx=0
local delta=0
config_load wireless
while :; do
config_get devicepath "radio$first_phy_idx" path
[ -n "$devicepath" -a -n "$path" ] || break
[ "$path" == "$devicepath" ] && break
first_phy_idx=$(($first_phy_idx + 1))
done

delta=$(($radio_idx - $first_phy_idx))

[ -n "$path" ] && {
for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
case "$(readlink -f /sys/class/ieee80211/$phy/device)" in
*$path)
if [ $delta -gt 0 ]; then
delta=$(($delta - 1))
continue;
fi
return 0;;
esac
done
phy="$(mac80211_path_to_phy "$path")"
[ -n "$phy" ] && return 0
}
[ -n "$macaddr" ] && {
for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
Expand Down Expand Up @@ -1130,11 +1106,10 @@ mac80211_interface_cleanup() {
local phy="$1"

for wdev in $(list_phy_interfaces "$phy"); do
#Ensure the interface belongs to the phy being passed
phy_name="$(cat /sys/class/ieee80211/${phy}/device/net/${wdev}/phy80211/name)"
if [ "$phy_name" != "$phy" ]; then
continue
fi
local wdev_phy="$(readlink /sys/class/net/${wdev}/phy80211)"
wdev_phy="$(basename "$wdev_phy")"
[ -n "$wdev_phy" -a "$wdev_phy" != "$phy" ] && continue

# 11ad uses single hostapd and single wpa_supplicant instance
[ -f "/var/run/hostapd-${wdev}.lock" ] && [ $hwmode = "ad" ] && { \
hostapd_cli -p /var/run/hostapd raw REMOVE ${wdev}
Expand Down
39 changes: 5 additions & 34 deletions qca/feeds/wlan-open/mac80211/files/lib/wifi/mac80211.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
#!/bin/sh
. /lib/netifd/mac80211.sh

append DRIVERS "mac80211"

lookup_phy() {
[ -n "$phy" ] && {
[ -d /sys/class/ieee80211/$phy ] && return
}

# Incase of multiple radios belonging to the same soc, the device path
# of these radio's would be same. To find the correct phy, we can
# get the phy index of the device in soc and use it during searching
# the global phy list
local radio_idx=${device:5:1}
local first_phy_idx=0
local delta=0
local devpath
config_get devpath "$device" path
while :; do
config_get devicepath "radio$first_phy_idx" path
[ -n "$devicepath" -a -n "$devpath" ] || break
[ "$devpath" == "$devicepath" ] && break
first_phy_idx=$(($first_phy_idx + 1))
done

delta=$(($radio_idx - $first_phy_idx))

[ -n "$devpath" ] && {
for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
case "$(readlink -f /sys/class/ieee80211/$phy/device)" in
*$devpath)
if [ $delta -gt 0 ]; then
delta=$(($delta - 1))
continue;
fi
return;;
esac
done
phy="$(mac80211_path_to_phy "$devpath")"
[ -n "$phy" ] && return
}

local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
Expand Down Expand Up @@ -145,16 +124,8 @@ EOF

[ -n $htmode ] && append ht_capab " option htmode $htmode" "$N"

if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then
path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
else
path=""
fi
path="$(mac80211_phy_to_path "$dev")"
if [ -n "$path" ]; then
path="${path##/sys/devices/}"
case "$path" in
platform*/pci*) path="${path##platform/}";;
esac
dev_id=" option path '$path'"
else
dev_id=" option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)"
Expand Down

0 comments on commit 31a19eb

Please sign in to comment.