Nvidia 工程师,您好
我使用ioctl()函数读取AQR113C的寄存器,但我得到的值全都是0x0,驱动程序是否不支持使用ioctl()读取AQR113C的寄存器?
这是我使用的代码:
#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>
#include <unistd.h>
int main(int argc, char *argv[])
{
int sockfd;
struct mii_ioctl_data *mii = NULL;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
if(argc == 4)
{
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
sockfd = socket(PF_LOCAL, SOCK_DGRAM, 0);
ioctl(sockfd, SIOCGMIIPHY, &ifr);
mii = (struct mii_ioctl_data*)&ifr.ifr_data;
mii->phy_id = (uint16_t)strtoul(argv[2], NULL, 0);
mii->reg_num = (uint16_t)strtoul(argv[3], NULL, 0);
ioctl(sockfd, SIOCGMIIREG, &ifr);
printf("read --- value : 0x%x", mii->val_out);
}
else if(argc == 5)
{
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
sockfd = socket(PF_LOCAL, SOCK_DGRAM, 0);
ioctl(sockfd, SIOCGMIIPHY, &ifr);
mii = (struct mii_ioctl_data*)&ifr.ifr_data;
mii->phy_id = (uint16_t)strtoul(argv[2], NULL, 0);
mii->reg_num = (uint16_t)strtoul(argv[3], NULL, 0);
mii->val_in = (uint16_t)strtoul(argv[4], NULL, 0);
ioctl(sockfd, SIOCSMIIREG, &ifr);
}
else
{
printf("mdio ethX phyId addr value\n");
}
close(sockfd);
return 0;
}