CaryStudio

 找回密码
 立即注册
搜索
查看: 1570|回复: 0

atheros无线驱动之:系统初始化

[复制链接]
发表于 2017-11-18 10:30:03 | 显示全部楼层 |阅读模式

请先登录

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
1:atheros WLAN系统框图

                               
登录/注册后可看大图

Atheros的驱动是应用于在类似如上图的方案中的,可以不是很清楚但是可以看看如下的框

                               
登录/注册后可看大图


                               
登录/注册后可看大图

其中atheros主要的芯片有:AR9344、AR9341,AR9382,AR7240,AR7342(无wifi),交换芯片类AR8328/8337。
在双频率设备中,第一张网卡wifi0基本上使用如AR9344、9341提供的2.4或者5.8G来实现,第二组网络wifi1是通过如上面的框图显示的有PCIE扩展而来,如使用:AR9382。
2:WLAN模块的加载
现在我们的驱动从PCIE接口类的网卡的初始化说起。此处的流程是当WLAN的驱动在加载的时候即insmod,可以在atheros提供的rc.wlan中可知在insmod和rmmod时操作的是那些模块。
加载时:
insmod $MODULE_PATH/adf.ko
    insmod $MODULE_PATH/asf.ko
    insmod $MODULE_PATH/ath_hal.ko
    insmod $MODULE_PATH/ath_rate_atheros.ko
    insmod $MODULE_PATH/ath_spectral.ko$SPECTRAL_ARGS
    if [ "${AP_NO_A_BAND}" !="1" ]; then
        #load DFS if A band issupported,default is supported and set AP_NO_A_BAND=1 if not supported
        insmod $MODULE_PATH/ath_dfs.ko$DFS_ARGS
    fi
    insmod $MODULE_PATH/hst_tx99.ko
    insmod $MODULE_PATH/ath_dev.ko
    insmod $MODULE_PATH/umac.ko
    insmod $MODULE_PATH/wlan_me.ko
insmod $MODULE_PATH/ath_pktlog.ko
卸载时:
_ath_unload()
{
    rmmod wlan_scan_ap
    rmmod wlan_scan_sta
    rmmod ath_pktlog
    sleep 2
    rmmod wlan_me
    sleep 2
    rmmod umac
    sleep 2
    rmmod ath_dev
    rmmod hst_tx99
    rmmod ath_dfs
    rmmod ath_spectral
    rmmod ath_rate_atheros
    rmmod ath_hal
    rmmod asf
    rmmod adf
}
来看看当加载PCEI的接口时,初始化打印的信息如下:此处使用的是9382扩展的5.8G的信号

                               
登录/注册后可看大图

上面前面的信息主要是在函数:init_ath_pci()中的
  1. if (pci_register_driver(&ath_pci_drv_id) < 0) { 此处进行的是PCI的注册。
  2.         printk("ath_pci: No devices found, driver not installed.\n");
  3.         pci_unregister_driver(&ath_pci_drv_id);
  4. #ifdef ATH_AHB
  5.         pciret = -ENODEV;
  6. #else
  7.         return (-ENODEV);
  8. #endif
  9.     }
复制代码
其中ath_pci_drv_id定义如下
  1. //static struct pci_driver ath_pci_drv_id = {
  2. struct pci_driver ath_pci_drv_id = {
  3.     .name       = "ath_pci",
  4.     .id_table   = ath_pci_id_table,
  5.     .probe      = ath_pci_probe,
  6.     .remove     = ath_pci_remove,
  7. #ifdef ATH_BUS_PM
  8.     .suspend    = ath_pci_suspend,
  9.     .resume     = ath_pci_resume,
  10. #endif /* ATH_BUS_PM */
  11.     /* Linux 2.4.6 has save_state and enable_wake that are not used here */
  12. };
复制代码

在PCI的probe函数ath_pci_probe中有如下的代码:
    dev = alloc_netdev(sizeof(struct ath_pci_softc), "wifi%d", ether_setup);  //此处分别了设备节点dev.
    if (dev == NULL) {
        printk(KERN_ERR "ath_pci: no memory for device state\n");
        goto bad2;
    }
    dev->type = ARPHRD_IEEE80211;
    if (__ath_attach(id->device, dev, &bus_context, &sc->aps_osdev) != 0)
        goto bad3;
    athname = ath_hal_probe(id->vendor, id->device);
    printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d hw_base=0x%p\n",
dev->name, athname ? athname : "Atheros ???", phymem, dev->irq,(void *)(((struct ath_softc *)(sc->aps_sc.sc_dev))->sc_ah->ah_sh));
    return 0;
上面可以知道调用函数__ath_attach(),此函数中attach了很多操作相关的处理函数。
其中网络设备net_device的操作函数定义如下:
  1. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
  2. static const struct net_device_ops athdev_net_ops = {
  3.     .ndo_open    = ath_netdev_open,
  4.     .ndo_stop    = ath_netdev_stop,
  5.     .ndo_start_xmit = ath_netdev_hardstart,
  6.     .ndo_set_mac_address = ath_netdev_set_macaddr,
  7.     .ndo_tx_timeout = ath_netdev_tx_timeout,
  8.     .ndo_get_stats = ath_getstats,
  9.     .ndo_change_mtu = ath_change_mtu,
  10.     .ndo_set_multicast_list = ath_netdev_set_mcast_list,
  11.     .ndo_do_ioctl = ath_ioctl,
  12. };
  13. #endif
复制代码
PCI接口的wifi设备在各层中attach了很多需要处理的函数,其贯穿整个WLAN驱动框架,

                               
登录/注册后可看大图


在atheros提供的驱动程序时封分层处理的,从下到上可以看到有:
  1. HAL:Hardware Abstraction Layer (HAL):
  2. Lower MAC (LMAC)
  3. Upper MAC (UMAC)
  4. OS Interface Layer (OSIF) 此处就不详细说明了,其他地方再说。
  5.     /*
  6.      * Create an Atheros Device object
  7.      */
  8.     error = ath_dev_attach(devid, base_addr,ic, &net80211_ops, osdev,
  9.                            &scn->sc_dev, &scn->sc_ops,scn->amem.handle,ath_conf_parm, hal_conf_parm);
复制代码
其中ieee80211_ops定义很多对80211协议的特定处理函数。
  1. /*
  2.      * ath_ops is stored per device instance because EDMA devices
  3.      * have EDMA specific functions.
  4.      */
  5.     sc->sc_ath_ops = ath_ar_ops;
  6.     *ops = &sc->sc_ath_ops;
复制代码
其中ath_ar_ops;  定义了很多处理函数。这些函数太多,都是回调函数。

                               
登录/注册后可看大图

上面是device在加载的过程中attach的各层的处理函数,同理当驱动rmmod的时候,做出相反动作,其函数的调用流程如下:

                               
登录/注册后可看大图

上面提到的中断的申请与释放:可以proc目录下面看到系统申请的中断。

                               
登录/注册后可看大图


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|CaryStudio ( 粤ICP备16022806号 )

GMT+8, 2023-6-8 09:50 , Processed in 0.087709 second(s), 12 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表