网卡驱动基础知识


title: 网卡驱动基础知识
date: 2019/12/31 19:51:11
toc: true

网卡驱动基础知识

网络分层

mark

我们的网卡驱动就是最下面的两层,一个是mac这个一般是soc带的,另一个是phy这个是外挂的,常用的其他形式有几种

1.
soc(带mac和phy) -----差分信号-----RJ45接口网线
2.
soc(带mac,不带phy)   -- RGMII/RMII ----phy -----差分信号-----RJ45接口网线
3.  
soc(不带mac,不带phy)  - mdio接口/spi接口/gpio接口-- mac(带phy) -----差分信号-----RJ45接口网线
 		|________MDIO/MDCK_________________________|
4.
soc(不带mac,不带phy)  - mdio接口/spi接口/gpio接口-- mac(不带phy) ---RGMII/RMII---phy -----差分信号-----RJ45接口网线
 |________MDIO/MDCK________________________|

网络接口

更多其他的接口知识查看01-以太网接口分析.pdf

mark

imx的网卡移植

其实phy是有通用驱动的

  1. 修改设备树

    • 修改phy地址
    • 修改复位管脚
    &fec1 {
    	pinctrl-names = "default";
    	pinctrl-0 = <&pinctrl_enet1>;
    	phy-mode = "rmii";
    	phy-reset-gpios = <&gpio1 12 0>; /* GPIO1_12 */
    	phy-handle = <&ethphy0>;
    	status = "okay";
    };
    
    &fec2 {
    	pinctrl-names = "default";
    	pinctrl-0 = <&pinctrl_enet2>;
    	phy-mode = "rmii";
    	phy-reset-gpios = <&gpio1 10 0>; /* GPIO1_10 */
    	phy-handle = <&ethphy1>;
    	status = "okay";
    		mdio {
    		#address-cells = <1>;
    		#size-cells = <0>;
    
    		ethphy0: ethernet-phy@5 {
    			compatible = "ethernet-phy-i00d22.1537";
    			reg = <5>;
    			status = "okay";
    		};/*compatible = "ethernet-phy-i00d22.1537","ethernet-phy-ieee802.3-c22","ethernet-phy-ieee802.3-c45";*/
    
    		ethphy1: ethernet-phy@1 {
    			compatible = "ethernet-phy-id0022.1537";/*compatible = "ethernet-phy-id0022.1537","ethernet-phy-ieee802.3-c22","ethernet-phy-ieee802.3-c45";*/
    			reg = <1>;
    			status = "okay";
    		};
    	};
    };
    
  2. 启动信息如下,下面这个是通用驱动,如果是指定了具体驱动,这里会有显示驱动名字的

    ifconfig eth0 up  
    fec 2188000.ethernet eth0: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr2188000.ethernet:00, irq=-1) 
    IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready  
    
  3. 当插上网线提示

    libphy: 2188000.ethernet:00 - Link is Up - 100/Full  
    IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready 
    
  4. 设置ip就可以ping通局域网地址了,或者使用udhpc,添加网关使用route add default gw 192.168.2.1我之前ping不通,是由于外接50M晶振,所以无法ping,后面去除了就能ping通

  5. 关键文件

    关键文件
    arch/arm/mach-imx/mach-imx6u.c  这里有对专门的phy的一些fixup
    imx.c  
    
    
    drivers/net/phy/mdio_bus.c
    
    当使用通用驱动的时候会调用到这里,可以查看调用关系
    drivers/regulator/core.c > _regulator_get   在这里使用dump_stack()
    
原文地址:https://www.cnblogs.com/zongzi10010/p/12127182.html