Chinaunix首页 | 论坛 | 博客
  • 博客访问: 142175
  • 博文数量: 25
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 232
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-04 16:25
文章分类

全部博文(25)

文章存档

2019年(1)

2018年(1)

2017年(14)

2015年(9)

我的朋友

分类: LINUX

2017-05-26 16:07:47

AR9344芯片中5G网卡是通过AHB总线连接在SOC中的.还有一个2.4G的无线网卡是挂在PCI总线上的
在ath9k驱动insmod时首先调用的是ath9k_init(void);代码如下:

点击(此处)折叠或打开

  1. static int __init ath9k_init(void)
  2. {
  3.     int error;

  4.     error = ath_ahb_init(); //这是是初始化AHB总线上的网卡设备的
  5.     if (error < 0) {
  6.         error = -ENODEV;
  7.         goto err_out;
  8.     }

  9.     error = ath_pci_init(); //初始化PCI总线的网卡设备
  10.     if (error < 0) {
  11.         pr_err("No PCI devices found, driver not installed\n");
  12.         error = -ENODEV;
  13.         goto err_ahb_exit;
  14.     }

  15.     return 0;

  16.  err_ahb_exit:
  17.     ath_ahb_exit();
  18.  err_out:
  19.     return error;
  20. }
  21. module_init(ath9k_init);
通过上面的代码我们知道insmod ath9k驱动时会分别初始化AHB和PCI总线的网卡设备.
我们再看看AHB初始化时会做什么操作:

点击(此处)折叠或打开

  1. int ath_ahb_init(void)
  2. {
  3.     return platform_driver_register(&ath_ahb_driver);
  4. }
其实就是通过函数platform_driver_register注册ahb驱动.
再看看ath_ahb_driver:

点击(此处)折叠或打开

  1. static struct platform_driver ath_ahb_driver = {
  2.     .probe = ath_ahb_probe,
  3.     .remove = ath_ahb_remove,
  4.     .driver        = {
  5.         .name    = "ath9k",
  6.     },
  7.     .id_table = ath9k_platform_id_table,
  8. };
我们主要关注ath_ahb_probe函数, 在注册完成后会系统会自动调用它.
ath_ahb_remove函数会在unregister时候调用.


点击(此处)折叠或打开

  1. static int ath_ahb_probe(struct platform_device *pdev)
  2. {
  3.     void __iomem *mem;
  4.     struct ath_softc *sc; //atheros用于硬件和mac层交互的中间载体.后面我们会单独分析改结构
  5.     struct ieee80211_hw *hw; //mac80211层中代表硬件的信息和状态.后面会分析.
  6.     struct resource *res;
  7.     const struct platform_device_id *id = platform_get_device_id(pdev);
  8.     int irq;
  9.     int ret = 0;
  10.     struct ath_hw *ah;
  11.     char hw_name[64];

  12.     if (!dev_get_platdata(&pdev->dev)) {
  13.         dev_err(&pdev->dev, "no platform data specified\n");
  14.         return -EINVAL;
  15.     }

  16.     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  17.     if (res == NULL) {
  18.         dev_err(&pdev->dev, "no memory resource found\n");
  19.         return -ENXIO;
  20.     }

  21.     mem = devm_ioremap_nocache(&pdev->dev, res->start, resource_size(res));
  22.     if (mem == NULL) {
  23.         dev_err(&pdev->dev, "ioremap failed\n");
  24.         return -ENOMEM;
  25.     }

  26.     res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);//获取设备irq线
  27.     if (res == NULL) {
  28.         dev_err(&pdev->dev, "no IRQ resource found\n");
  29.         return -ENXIO;
  30.     }

  31.     irq = res->start;

  32.     ath9k_fill_chanctx_ops();
  33.     hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);//分配mac层硬件相关信息和状态结构体
  34.     if (hw == NULL) {
  35.         dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
  36.         return -ENOMEM;
  37.     }

  38.     SET_IEEE80211_DEV(hw, &pdev->dev);
  39.     platform_set_drvdata(pdev, hw);

  40.     sc = hw->priv;
  41.     sc->hw = hw;
  42.     sc->dev = &pdev->dev;
  43.     sc->mem = mem;
  44.     sc->irq = irq;

  45.     ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);//注册中断号
  46.     if (ret) {
  47.         dev_err(&pdev->dev, "request_irq failed\n");
  48.         goto err_free_hw;
  49.     }

  50.     ret = ath9k_init_device(id->driver_data, sc, &ath_ahb_bus_ops);
  51.     if (ret) {
  52.         dev_err(&pdev->dev, "failed to initialize device\n");
  53.         goto err_irq;
  54.     }

  55.     ah = sc->sc_ah;
  56.     ath9k_hw_name(ah, hw_name, sizeof(hw_name));
  57.     printk("carson[%s:%d], irq=%d\n", __func__, __LINE__, irq);
  58.     wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n",
  59.          hw_name, (unsigned long)mem, irq);

  60.     return 0;

  61.  err_irq:
  62.     free_irq(irq, sc);
  63.  err_free_hw:
  64.     ieee80211_free_hw(hw);
  65.     return ret;
  66. }
上面即是AHB驱动注册是的相关操作包括: 请求设备的IO内存,irq号等.分配ieee80211_hw结构.
我们先看看相关的结构体分别代码什么意思,再来分析上面的代码.









阅读(2553) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~