zoukankan      html  css  js  c++  java
  • 基本数据结构简介--ath9k网卡驱动开发总结(二)

           ath9k驱动代码主要数据结构概览。

          (1)在ath9k的驱动中,几乎是最顶层的数据结构是ath_softc,这个数据结构几乎随处可见。ath_softc是硬件与MAC层进行交互的中间载体,很多有用的

    网络参数都可以从ath_softc中得到,对于进一步的网卡驱动开发,收集网络数据等很有帮助。 

           定义位置:drivers/net/wireless/ath/ath9k/ath9k.h 具体定义如下:

    struct ath_softc {
        struct ieee80211_hw *hw;    //保存硬件信息
        struct device *dev;         //当前工作的设备
    
        u32 chan_bw;                // 信道带宽
        int chan_idx;               // 信道序号
        int chan_is_ht;             // 是否使用high_throughput模式 即绿野模式
        struct survey_info *cur_survey;
        struct survey_info survey[ATH9K_NUM_CHANNELS];
    
        struct tasklet_struct intr_tq;   
        struct tasklet_struct bcon_tasklet;   //结构体定义在 include <linux/interrupt.h>  用于中断管理
        struct ath_hw *sc_ah;                //hw的包装结构体
        void __iomem *mem;                   //内存区域
        int irq;
        spinlock_t sc_serial_rw;
        spinlock_t sc_pm_lock;
        spinlock_t sc_pcu_lock;             //进行数据读取,或者处理skb时需要的锁
        struct mutex mutex;
        struct work_struct paprd_work;
        struct work_struct hw_check_work;
        struct work_struct hw_reset_work;   //执行不同工作的工作队列 以后在代码中具体解释
        struct completion paprd_complete;
    
        unsigned int hw_busy_count;
    
        u32 intrstatus;
        u32 sc_flags; /* SC_OP_* */
        u16 ps_flags; /* PS_* */
        u16 curtxpow;
        bool ps_enabled;
        bool ps_idle;
        short nbcnvifs;
        short nvifs;
        unsigned long ps_usecount;
    
        struct ath_config config;
        struct ath_rx rx;
        struct ath_tx tx;
        struct ath_beacon beacon;
        struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];     //当前支持的带宽
    
    #ifdef CONFIG_MAC80211_LEDS
        const char *led_default_trigger;
        struct list_head leds;
    #endif
    
        struct ath9k_hw_cal_data caldata;
        int last_rssi;
    
    #ifdef CONFIG_ATH9K_DEBUGFS
        struct ath9k_debug debug;
        spinlock_t nodes_lock;
        struct list_head nodes; /* basically, stations */
        unsigned int tx_complete_poll_work_seen;
    #endif
        struct ath_beacon_config cur_beacon_conf;
        struct delayed_work tx_complete_work;
        struct delayed_work hw_pll_work;
        struct ath_btcoex btcoex;
        struct ath_mci_coex mci_coex;
    
        struct ath_descdma txsdma;
    
        struct ath_ant_comb ant_comb;
        u8 ant_tx, ant_rx;
    };

         在ath_softc中的一些数据结构是值得注意的,ieee80211_hw, ath_rx,ath_tx,ath_beacon,ath_debug。这些结构体在网卡编码中经常使用,现在逐一

    对其分析解释。

           (2)ath9k_debug。在Linux运行过程中,会建立一个虚拟的文件操作系统 /proc,通过/proc可以访问内核内部数据结构、改变内核设置的机制,对

    于OpenWrt操作系统来说,内核与外部shell之间的交互是通过读写/sys/kernel/debug/ieee80211/phy0/ath9k/目录下的文件实现的。ath9k_debug中定义

    的数据结构承接了外部参数输入和内核数据的导出。如果先要改变内核运行时的参数,可以在此结构中定义新的数据变量,然后通过实现新的file_operations达到

    参数的读入和内核数据的导出的目的。总之,想要在代码中增加需要的数据结构,定义好后,放一个对象在这个结构体中,就可以安心使用了,当然具体的操作

    方法,会在以后的博客中再具体说明。

      ath_debug定义在 drivers/net/wireless/ath/ath9k/debug.h 中。

    struct ath9k_debug {
        struct dentry *debugfs_phy;
        u32 regidx;
        struct ath_stats stats;
        spinlock_t samp_lock;
        struct ath_dbg_bb_mac_samp bb_mac_samp[ATH_DBG_MAX_SAMPLES];
        u8 sampidx;
        u8 tsidx;
        u8 rsidx;
        // 以上是系统自定义的变量
        // 下面是个人开发需要所增加的变量,其中的结构体变量的定义也在debug.h中
        bool first_into;
        unsigned long mcs_tx_time;
        struct inject_settings *setting;
        struct list_head recv_tp_list;
        struct realtime_var rtv;
        struct list_head xmit_bw_list;
        struct list_head rx_infos_list;
        struct list_head frame_list;
        unsigned int frame_maxnum;     
    };

      (3)ath_rx_status这个数据结构,。此结构提供的信息对于分析信道状况、统计单帧的信息都很有帮助,而且信息的粒度足够小了。这个数据结构

    定义了网卡接收到一个skb时网卡的状态,数据帧的状态等信息,具体见代码注释,没注释的就是我也没看懂的各位谁知道的请留言,多谢赐教。

    格式:结构体:成员变量--含义 比如 ath_rx_status:rs_rate--标记速率类型。

           结构体定义在:drivers/net/wireless/ath/ath9k/mac.h

    struct ath_rx_status {
        u32 rs_tstamp;       // 接收的时间戳
        u16 rs_datalen;     
        u8 rs_status;        // 标记出错类型 CRC or PHY     
        u8 rs_phyerr;        // PHY Error 有很多类型,这个变量可以使这些类型对应的某一个或几个
        int8_t rs_rssi;      // 当前数据帧的信号接收强度 
        u8 rs_keyix;
        u8 rs_rate;      // 标记当前速率是否是HT模式 如果是 则rs_rate = 0x80
        u8 rs_antenna;       // 接收天线编号
        u8 rs_more;          // 标记当前数据帧是否是分片之一
        int8_t rs_rssi_ctl[3]; // 候选RSSI集合,与diversity和combining有关
        int8_t rs_rssi_ext[3];
        u8 rs_isaggr;          // 是否是聚合帧的一部分
        u8 rs_moreaggr;        // 是否是聚合帧中的最后一个数据帧
        u8 rs_num_delims;      
        u8 rs_flags;
        bool is_mybeacon;      // 是否是属于自己的beacon帧
        u32 evm0;
        u32 evm1;
        u32 evm2;
        u32 evm3;
        u32 evm4;
    };

           (4)ath_atx_tid是发送端MAC层非常重要的一个数据结构。块确认机制、重传、窗口管理、发送队列的管理和实现都依赖或者设计到ath_atx_tid。

    具体使用方法会在后续的发送端详解中依次说明,现在看一下其中的成员变量及含义。

             此数据结构定义在drivers/net/wireless/ath/ath9k/ath9k.h。

    struct ath_atx_tid {
        struct list_head list;
        struct sk_buff_head buf_q;
        struct ath_node *an;
        struct ath_atx_ac *ac;
        unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];  //类似于Bitmap,标记窗口内已发送的数据帧
        int buf_pending;
        int bar_index;       // Block Ack Request的索引
        u16 seq_start;       // 当前发送序号的开始
        u16 seq_next;        // 下一次发送序号的开始
        u16 baw_size;        // Block Ack Window 的大小 一般为128
        int tidno;           //标记当前传输的数据的类型:媒体数据或者是文本数据等等
        int baw_head;        /* first un-acked tx buffer */
        int baw_tail;        /* next unused tx buffer slot */
        int sched;
        int paused;        
        u8 state;            // 发送状态,正在发送,发送完毕,或出错
    };

        未完待续。

  • 相关阅读:
    Annotation
    injector
    Java容器(container)
    build tool(构建工具)maven和gradle安装方法
    version control(版本控制)
    函数式编程
    URI与URL
    超文本传输协议HTTP
    annotation的理解
    Injection
  • 原文地址:https://www.cnblogs.com/tju-gsp/p/3687513.html
Copyright © 2011-2022 走看看