==============================================================
作者:shanzongyingcao
网址:http://blog.csdn.net/shanzongyingcao
版权所有,转载请保留此段声明
==============================================================
网口寄存器说明
- 以网口芯片82567为例,说明网口寄存机
- CTRL:offset 0x00, CD_RST 31 LAN Connected Device (PHY) Reset
- STATUS:offset 0x08, LU 1 Link Up
-
MDIC :offset 0x20, MDI Control Register: Software uses this register to read or write Management Data Interface (MDI) register in the PHY:
通过MDI访问PHY Register Address:
PHY Control Register - PCTRL (00d; R/W)
Reset 15 1b = PHY reset
(Note: When using PHY Reset, the PHY default configuration is not loaded from the EEPROM. The preferred way to reset the 82576 PHY is using the CTRL.PHY_RST field.)PHY Status Register - PSTATUS (01d; R)
Link Status 2 1b = Link is up- 访问 PCTRL及 PSTATUS 时通过MDI访问的,例:
- 要读PCTRL,先往MDI寄存器写值0x08400000(配置为读、寄存器0),
再读MDI寄存器,当(28位)为1时,读的值为有效值,低16位为读的PCTRL值。 - 要写PCTRL,直接往MDI寄存器写值0x0440xxxx(配置为写、寄存器0)
- 要读PSTATUS,先往MDI寄存器写值0x08410000(配置为读、寄存器1),
再读MDI寄存器,当(28位)为1时,读的值为有效值,低16位为读的PCTRL值。 - 要写PSTATUS,直接往MDI寄存器写值0x0440xxxx(配置为写、寄存器1)
通过memory地址访问寄存器
- BAR0为memory地址,映射后地址+offset,可以直接方位寄存器,此方式,只能在内核空间访问;用户空间不能访问。
通过io port地址访问寄存器
- BAR2为IO port地址,可以间接方位寄存器,此方式,既可以在内核空间访问,又可以在用户空间访问。- 通过IOADDR及IODATA来间接访问寄存器,其中:
IOADDR = pci_base_addr[0][2] + 0;
IODATA = pci_base_addr[0][2] + 4; - 要访问CTRL、MDI等寄存器,先将寄存器偏移地址写到IOADDR中,再读写IODATA(必须为32位),如往MDI(0x20)写值0x08410000:
outl(0x20, (void *)IOADDR);
outl(0x08410000, (void *)IODATA);
读:value = inl((void *)IODATA);
注:The IODATA register must always be written as a DWORD access when the IOADDR register contains avalue for the Internal Register and Memories (for example, 0x00000-0x1FFFC). In this case, writes that are less than 32 bits is ignored.