1、设备名称是如何创建的
#define WIFI_DEV_NAME_PDEV "wifi%d"
qdf_netdev_t wlan_create_pdev_netdevice(struct wlan_objmgr_psoc *psoc,
uint8_t id)
{
......
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
dev = alloc_netdev(sizeof(struct ol_ath_softc_net80211),
soc->is_sim ? "wifi-sim%d" : radio_if,
0,
ether_setup);
......
}
[ 34.119604] wlan: [1328:I:ANY] __ol_ath_attach: 4320: pdev_netdev name wifi2
__ol_ath_attach(){
dev_alloc_name(pdev_netdev, pdev_netdev->name);
}
/**
* dev_alloc_name - allocate a name for a device
* @dev: device
* @name: name format string
*
* Passed a format string - eg "lt%d" it will try and find a suitable
* id. It scans list of devices to build up a free map, then chooses
* the first empty slot. The caller must hold the dev_base or rtnl lock
* while allocating the name and adding the device in order to avoid
* duplicates.
* Limited to bits_per_byte * page size devices (ie 32K on most platforms).
* Returns the number of the unit assigned or a negative errno code.
*/
int dev_alloc_name(struct net_device *dev, const char *name)
{
char buf[IFNAMSIZ];
struct net *net;
int ret;
BUG_ON(!dev_net(dev));
net = dev_net(dev);
ret = __dev_alloc_name(net, name, buf);
if (ret >= 0)
strlcpy(dev->name, buf, IFNAMSIZ);
return ret;
}
/**
* __dev_alloc_name - allocate a name for a device
* @net: network namespace to allocate the device name in
* @name: name format string
* @buf: scratch buffer and result name string
*
* Passed a format string - eg "lt%d" it will try and find a suitable
* id. It scans list of devices to build up a free map, then chooses
* the first empty slot. The caller must hold the dev_base or rtnl lock
* while allocating the name and adding the device in order to avoid
* duplicates.
* Limited to bits_per_byte * page size devices (ie 32K on most platforms).
* Returns the number of the unit assigned or a negative errno code.
*/
static int __dev_alloc_name(struct net *net, const char *name, char *buf)
{
int i = 0;
const char *p;
const int max_netdevices = 8*PAGE_SIZE;
unsigned long *inuse;
struct net_device *d;
p = strnchr(name, IFNAMSIZ-1, '%');
if (p) {
/*
* Verify the string as this thing may have come from
* the user. There must be either one "%d" and no other "%"
* characters.
*/
if (p[1] != 'd' || strchr(p + 2, '%'))
return -EINVAL;
/* Use one page as a bit array of possible slots */
inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
if (!inuse)
return -ENOMEM;
for_each_netdev(net, d) {
if (!sscanf(d->name, name, &i))
continue;
if (i < 0 || i >= max_netdevices)
continue;
/* avoid cases where sscanf is not exact inverse of printf */
snprintf(buf, IFNAMSIZ, name, i);
if (!strncmp(buf, d->name, IFNAMSIZ))
set_bit(i, inuse);
}
i = find_first_zero_bit(inuse, max_netdevices);
free_page((unsigned long) inuse);
}
if (buf != name)
snprintf(buf, IFNAMSIZ, name, i);
if (!__dev_get_by_name(net, buf))
return i;
/* It is possible to run out of possible slots
* when the name is long and there isn't enough space left
* for the digits, or if all bits are used.
*/
return -ENFILE;
}
2、修改方法
/* Support to change radio interface id of offload radio */
#define WIFI_DEV_NUM_MAX 3
static unsigned int wifi_start_idx = 0;
module_param(wifi_start_idx, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(wifi_start_idx,
"Radio interface id for offload chips");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
//switch wifi index .zk.20210118
if(0 == wifi_start_idx){
snprintf(radio_if, IFNAMSIZ, "%s%d", "wifi", 1);
wifi_start_idx++;
}else if(1 == wifi_start_idx){
snprintf(radio_if, IFNAMSIZ, "%s%d", "wifi", 0);
wifi_start_idx++;
}else{
snprintf(radio_if, IFNAMSIZ, "%s%d", "wifi", 2);
}
dev = alloc_netdev(sizeof(struct ol_ath_softc_net80211),
soc->is_sim ? "wifi-sim%d" : radio_if,
0,
ether_setup);