生活随笔
收集整理的這篇文章主要介紹了
转载:linux+arm 网卡故障调试:ethtoolphy寄存器读写
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
兩個工具一個是ethtool工具,一個是源碼編譯的可以讀phy寄存器的工具phyreg。兩者結合使用,事半功倍。
ethtool 可以查看和設置網卡的工作狀態(tài),比如查看設置網卡的鏈接 自協商,10/100/1000M,雙工半雙工的工作狀態(tài)。
ethtool的交叉編譯工具,見個人博客文章:http://blog.csdn.net/vc66vcc/article/details/52398864
phyreg 可以讀寫phy的任意寄存器。相關源碼如下
[cpp] view plaincopyprint?
#include?<stdio.h>??#include?<stdlib.h>??#include?<string.h>??#include?<linux/mii.h>??#include?<sys/types.h>??#include?<sys/socket.h>??#include?<sys/ioctl.h>??#include?<net/if.h>??#include?<linux/sockios.h>??#include?<linux/types.h>??#include?<netinet/in.h>??????#define?reteck(ret)?????\??????????if(ret?<?0){????\??????????????printf(”%m!?\”%s\”?:?line:?%d\n”,?func,?LINE);???\??????????????goto?lab;???\??????????}????#define?help()?\??????printf(”mdio:\n”);??????????????????\??????printf(”read?operation:?mdio?reg_addr\n”);??????????\??????printf(”write?operation:?mdio?reg_addr?value\n”);????\??????printf(”For?example:\n”);????????????\??????printf(”mdio?eth0?1\n”);?????????????\??????printf(”mdio?eth0?0?0x12\n\n”);??????\??????exit(0);????int?sockfd;????int?main(int?argc,?char?argv[]){????????????????if(argc?==?1?||?!strcmp(argv[1],?“-h”)){??????????help();??????}????????????struct?mii_ioctl_data?*mii?=?NULL;??????struct?ifreq?ifr;??????int?ret;????????memset(&ifr,?0,?sizeof(ifr));??????strncpy(ifr.ifr_name,?argv[1],?IFNAMSIZ?-?1);????????sockfd?=?socket(PF_LOCAL,?SOCK_DGRAM,?0);??????reteck(sockfd);??????????????ret?=?ioctl(sockfd,?SIOCGMIIPHY,?&ifr);??????reteck(ret);????????mii?=?(struct?mii_ioctl_data)&ifr.ifr_data;????????if(argc?==?3){????????????mii->reg_num????=?(uint16_t)strtoul(argv[2],?NULL,?0);????????????????????ret?=?ioctl(sockfd,?SIOCGMIIREG,?&ifr);??????????reteck(ret);????????????????printf(”read?phy?addr:?0x%x??reg:?0x%x???value?:?0x%x\n\n”,?mii->phy_id,?mii->reg_num,?mii->val_out);??????}else?if(argc?==?4){????????????mii->reg_num????=?(uint16_t)strtoul(argv[2],?NULL,?0);??????????mii->val_in?????=?(uint16_t)strtoul(argv[3],?NULL,?0);????????????ret?=?ioctl(sockfd,?SIOCSMIIREG,?&ifr);??????????reteck(ret);????????????printf(”write?phy?addr:?0x%x??reg:?0x%x??value?:?0x%x\n\n”,?mii->phy_id,?mii->reg_num,?mii->val_in);??????}????lab:??????close(sockfd);??????return?0;??}??
總結
以上是生活随笔為你收集整理的转载:linux+arm 网卡故障调试:ethtoolphy寄存器读写的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。