andorid usb网卡名分配过程

1、网卡驱动加载log

[  142.122850][ T1830] read descriptors
[  142.127081][ T1830] read strings
[  142.194801][  T180] xhci-hcd xhci-hcd.2.auto: xHCI Host Controller
[  142.203234][  T180] xhci-hcd xhci-hcd.2.auto: new USB bus registered, assigned bus number 2
[  142.215209][  T180] xhci-hcd xhci-hcd.2.auto: hcc params 0x0230fe65 hci version 0x110 quirks 0x0000002000010010
[  142.225788][  T180] xhci-hcd xhci-hcd.2.auto: irq 275, io mem 0x0a600000
[  142.235906][  T180] usb usb2: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.10
[  142.245278][  T180] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[  142.253598][  T180] usb usb2: Product: xHCI Host Controller
[  142.259555][  T180] usb usb2: Manufacturer: Linux 5.10.149-qki-consolidate+ xhci-hcd
[  142.267630][  T180] usb usb2: SerialNumber: xhci-hcd.2.auto
[  142.277088][  T180] hub 2-0:1.0: USB hub found
[  142.282055][  T180] hub 2-0:1.0: 1 port detected
[  142.289970][  T180] xhci-hcd xhci-hcd.2.auto: xHCI Host Controller
[  142.292212][  T167] i2c_geni a8c000.i2c: i2c error :-107
[  142.298179][  T180] xhci-hcd xhci-hcd.2.auto: new USB bus registered, assigned bus number 3
[  142.302301][  T167] PM8008: pm8008_read: failed to read 0x0950
[  142.311078][  T180] xhci-hcd xhci-hcd.2.auto: Host supports USB 3.0 SuperSpeed
[  142.317959][  T167] PM8008: _pm8008_chip_is_enabled: qcom,pm8008-chip-en: failed to get chip state rc=-107
[  142.325707][  T180] usb usb3: We don't know the algorithms for LPM for this host, disabling LPM.
[  142.334785][  T167] PM8008: pm8008_chip_probe: Failed to register chip enable regulator rc=-107
[  142.354889][  T180] usb usb3: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.10
[  142.364656][  T180] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[  142.372942][  T180] usb usb3: Product: xHCI Host Controller
[  142.378935][  T180] usb usb3: Manufacturer: Linux 5.10.149-qki-consolidate+ xhci-hcd
[  142.387046][  T180] usb usb3: SerialNumber: xhci-hcd.2.auto
[  142.397574][  T180] hub 3-0:1.0: USB hub found
[  142.402879][  T180] hub 3-0:1.0: 1 port detected
[  142.413466][  T167] i2c_geni a8c000.i2c: i2c error :-107
[  142.419305][  T167] PM8008: pm8008_read: failed to read 0x0950
[  142.425552][  T167] PM8008: _pm8008_chip_is_enabled: qcom,pm8008-chip-en: failed to get chip state rc=-107
[  142.436299][  T167] PM8008: pm8008_chip_probe: Failed to register chip enable regulator rc=-107
[  142.540229][ T1357] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[  143.090481][  T167] (virq:irq_count)- GICv3:IPI(1):144885 GICv3:arch_timer(11):134045 GICv3:IPI(6):55713 GICv3:IPI(2):51356 GICv3:ufshcd(141):35443 ipcc:glink-native-adsp(330):9803 GICv3:ipcc_0(137):9714 GICv3:apps_rsc(132):6943 ipcc:glink-native-modem(346):2238 GICv3:virtio_dev_11(354):2237 
[  143.118348][  T167] (cpu:irq_count)- 0:106796 1:52994 2:54457 3:51558 4:27889 5:26610 6:74306 7:67015 
[  143.128489][  T167] (ipi:irq_count)- 0:144885 1:51356 2:0 3:0 4:0 5:55713 6:0 
[  143.289535][   T33] usb 3-1: new SuperSpeed Gen 1 USB device number 2 using xhci-hcd
[  143.333240][   T33] usb 3-1: New USB device found, idVendor=0bda, idProduct=8156, bcdDevice=31.04
[  143.343024][   T33] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=6
[  143.352141][   T33] usb 3-1: Product: USB 10/100/1G/2.5G LAN
[  143.358409][   T33] usb 3-1: Manufacturer: Realtek
[  143.363717][   T33] usb 3-1: SerialNumber: 401000001
[  143.468414][   T33] 
[  143.468414][   T33] ****usbnet_probe********
[  143.512630][   T33] cdc_ncm 3-1:2.0: MAC-Address: 08:26:ae:38:1d:dd
[  143.519687][   T33] cdc_ncm 3-1:2.0: setting rx_max = 16384
[  143.527874][   T33] cdc_ncm 3-1:2.0: setting tx_max = 16384
[  143.535113][   T33] 
[  143.535113][   T33] ***usbnet_probe***net->name=eth%d******
[  143.577286][   T33] cdc_ncm 3-1:2.0 eth0: register 'cdc_ncm' at usb-xhci-hcd.2.auto-1, CDC NCM, 08:26:ae:38:1d:dd
[  143.590355][  T204] i2c_geni a8c000.i2c: i2c error :-107
[  143.597185][  T204] PM8008: pm8008_read: failed to read 0x0950
[  143.603758][  T204] PM8008: _pm8008_chip_is_enabled: qcom,pm8008-chip-en: failed to get chip state rc=-107
[  143.613847][  T204] PM8008: pm8008_chip_probe: Failed to register chip enable regulator rc=-107
[  143.616747][   T33] cdc_ncm 3-1:2.0 eth0: unregister 'cdc_ncm' usb-xhci-hcd.2.auto-1, CDC NCM
[  143.625415][  T204] i2c_geni a8c000.i2c: i2c error :-107
[  143.637604][  T204] PM8008: pm8008_read: failed to read 0x0950
[  143.644118][  T204] PM8008: _pm8008_chip_is_enabled: qcom,pm8008-chip-en: failed to get chip state rc=-107
[  143.654141][  T204] PM8008: pm8008_chip_probe: Failed to register chip enable regulator rc=-107
[  143.976241][   T33] r8152-cfgselector 3-1: reset SuperSpeed Gen 1 USB device number 2 using xhci-hcd
[  144.423201][   T33] r8152 3-1:1.0 (unnamed net_device) (uninitialized): netif_napi_add() called with weight 256
[  144.480728][   T33] r8152 3-1:1.0 eth0: v2.17.1 (2023/06/13)
[  144.482018][  T250] selinux: SELinux:  Could not stat /sys/devices/platform/soc/a600000.ssusb/a600000.dwc3/xhci-hcd.2.auto/usb3/3-1/wakeup/wakeup53: No such file or directory.
[  144.486920][   T33] r8152 3-1:1.0 eth0: This product is covered by one or more of the following patents:
[  144.486920][   T33]          US6,570,884, US6,115,776, and US6,327,625.
[  144.486920][   T33] 
[  144.493933][  T204] i2c_geni a8c000.i2c: i2c error :-107
[  144.522368][  T250] selinux: 
[  144.527619][  T204] PM8008: pm8008_read: failed to read 0x0950

  

 

2、网名分配调用接口的过程

usbnet_probe--》register_netdev—————》register_netdevice---》dev_get_valid_name--》dev_alloc_name_ns--->__dev_alloc_name

 

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;

        if (!dev_valid_name(name))
                return -EINVAL;

        p = strchr(name, '%');
        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) {
                        struct netdev_name_node *name_node;
                        list_for_each_entry(name_node, &d->name_node->list, list) {
                                if (!sscanf(name_node->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, name_node->name, IFNAMSIZ))
                                        set_bit(i, inuse);
                        }
                        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);
        }

        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

  

 

alloc_etherdev_mqs--》alloc_netdev_mqs---》

struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
                                      unsigned int rxqs)
{
        return alloc_netdev_mqs(sizeof_priv, "eth%d", NET_NAME_UNKNOWN,
                                ether_setup, txqs, rxqs);
}

  

posted @ 2024-04-17 09:47  轻轻的吻  阅读(9)  评论(0编辑  收藏  举报