转载:http://blog.chinaunix.net/uid-24148050-id-132863.html

1. 简介

The MDIO
interface is a simple, two-wire, serial interface to connect a
management entity and a managed PHY for the purposes of controlling the
PHY and gathering status from the PHY.
   The two lines include the
MDC line [Management Data Clock], and the MDIO line [Management Data
Input/Output]. The clock is point-to-point, while the data line is a
bi-directional multi-drop interface.
   The data line is Tri-state able and can drive 32 devices.

MDIO接口,MAC与PHY间的管理接口(MII是数据接口),有2根线:时钟线MDC,数据线MDIO(双向)

   MDIO工作流程:
    * Preamle(PRE)       在没有传输数据的空闲状态时,数据线MDIO处于高阻态(一直为1)。
    * Start of Frame(ST) MAC驱动MDIO线,出现一个2bit的开始标识码(01)。
    * Operation Code(OP) MAC驱动MDIO线,出现一个2bit数据来标识是读操作(10)还是写操作(01)。
    * PHY Address(PHYAD) MAC驱动MDIO线,出现一个5bit数据标识PHY的地址。
    * Reg Address(REGAD) MAC驱动MDIO线,出现一个5bitPHY寄存器地址。
    * Turnaround(TA)     写操作的话,MAC驱动MDIO线,出现10
                         读操作的话,MDIO pin of MAC must be put in high-impedance state
                                     在第二个周期,PHY驱动MDIO线,出现0

* Data               MDIO串行读出/写入16bit的寄存器数据。

* MDIO恢复成空闲状态,同时MDIO进入高阻状态。

下面是PHY芯片 BCM5461 的一个例子:

2. PowerPC对MDIO的支持

PowerPC操作MDIO时,涉及以下寄存器:
MIIMCFG  配置寄存器
MIIMCOM  命令寄存器
MIIMADD  地址寄存器
MIIMCON  控制寄存器
MIIMSTAT 状态寄存器
MIIMIND  指示寄存器

以MPC8560举例,这些寄存器在CCSR中的位置如下:

2.1 MIIMCFG:配置寄存器

ResetMgmt:   用于重置MDIO模块
MgmtClockSet:时钟设置,是CCB的 2的n次方之一

2.2 MIIMCOM  命令寄存器

ReadCycle: 0->1 触发MDIO读时序

2.3 MIIMADD  地址寄存器

PHYaddr:PHY地址,共5bit,系统最多联31个PHY(地址0为保留)
REGaddr:寄存器地址,共5bit,一个PHY上最多32个寄存器地址(可以使用shadow value技术,访问更多的寄存器)

2.4 MIIMCON  控制寄存器

PHYcontrol:在写流程时,这里存放要写入寄存器的值

2.5 MIIMSTAT 状态寄存器

PHYstatus:读流程时,PHY reg的内容会放到此

2.6 MIIMIND  指示寄存器

NotVal:若置1,表示读流程结束,可以去读MIIMSTAT
Scan:  若置1,表示扫描流程进行中
Busy:  只有置0时,才能进行新的读写流程

3. linux中MDIO的实现

读写PHY寄存器时通过2个函数

phy_read()和phy_write(),

最终调用
int gfar_local_mdio_read(struct gfar_mii *regs, int mii_id, int regnum)
int gfar_local_mdio_write(struct gfar_mii *regs, int mii_id, int regnum, u16 value)

参数regs就是MDIO相关寄存器:

  1. struct gfar_mii {
  2. u32 miimcfg; /* 0x.520 - MII Management Config Register */
  3. u32 miimcom; /* 0x.524 - MII Management Command Register */
  4. u32 miimadd; /* 0x.528 - MII Management Address Register */
  5. u32 miimcon; /* 0x.52c - MII Management Control Register */
  6. u32 miimstat; /* 0x.530 - MII Management Status Register */
  7. u32 miimind; /* 0x.534 - MII Management Indicator Register */
  8. };

参数mii_id,就是PHY的id
参数regnum,就是寄存器地址

上代码,简单不解释

  1. int gfar_local_mdio_read(struct gfar_mii *regs, int mii_id, int regnum)
  2. {
  3. u16 value;
  4. /* Set the PHY address and the register address we want to read */
  5. gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
  6. /* Clear miimcom, and then initiate a read */
  7. gfar_write(&regs->miimcom, 0);
  8. gfar_write(&regs->miimcom, MII_READ_COMMAND);
  9. /* Wait for the transaction to finish */
  10. while (gfar_read(&regs->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
  11. cpu_relax();
  12. /* Grab the value of the register from miimstat */
  13. value = gfar_read(&regs->miimstat);
  14. return value;
  15. }
  1. int gfar_local_mdio_write(struct gfar_mii *regs, int mii_id,
  2. int regnum, u16 value)
  3. {
  4. /* Set the PHY address and the register address we want to write */
  5. gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
  6. /* Write out the value we want */
  7. gfar_write(&regs->miimcon, value);
  8. /* Wait for the transaction to finish */
  9. while (gfar_read(&regs->miimind) & MIIMIND_BUSY)
  10. cpu_relax();
  11. return 0;
  12. }

MDIO/MDC(SMI)接口的更多相关文章

  1. MDIO/MDC(SMI)接口-leonwang202

    ChinaUnix博客 http://blog.chinaunix.net/uid-24148050-id-132863.html

  2. SMI接口,SMI帧结构,MDC/MDIO

    转载:http://blog.csdn.net/zyboy2000/article/details/7442464 SMI全称是串行管理接口(Serial Management Interface). ...

  3. (二)再议MII、RMII、GMII接口

    概述:         MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC ...

  4. 61.MII、RMII、GMII接口的详细介绍

    概述: MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC和PHY之间的管 ...

  5. MII、RMII、GMII接口的详细介绍

    转载:http://blog.csdn.net/reille/article/details/6312156 概述: MII (Media Independent Interface(介质无关接口)或 ...

  6. MII、RMII、GMII接口的详细介绍【转】

    转自:https://www.cnblogs.com/geekite/p/5204512.html 概述: MII (Media Independent Interface(介质无关接口)或称为媒体独 ...

  7. 006 媒体独立接口(MII,Meida Independent Interface)

    一.MII接口 MII接口Medium Independent Interface MII(Media Independent Interface)即媒体独立接口,MII接口是MAC与PHY连接的标准 ...

  8. RGMII,MII,GMI接口

    简介 RGMII(Reduced Gigabit Media Independent Interface)是Reduced GMII(吉比特介质独立接口).GMII和RGMII均采用8位数据接口,工作 ...

  9. MII、GMII、RMII、SGMII、XGMII 接口区别

    MII即媒体独立接口,也叫介质无关接口.它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口,以及一个MAC和PHY之间的管理接口(图1). 数据接口包括分别用于发送器和接收器的两条独立信 ...

随机推荐

  1. cocos2d-x 添加背景音乐和音效-SimpleAudioEngine

    首先,要想使用音效,需要启用音效引擎库CocosDenshion中的SimpleAudioEngine类, #include "SimpleAudioEngine.h" Cocos ...

  2. 复习C语言

    今天突然有感觉复习下C语言了,发现已经好久没有用过C编程了,话说最近都没有编过程序了都,趁现在还有点时间,好好学习下C了.话不多说上题目 请定义一个宏,比较两个数a.b的大小,不能使用大于.小于.if ...

  3. vbox磁盘空间扩容

    前提:将虚拟机真正关机,不能在仅状态保存的场合做磁盘扩容. 步骤1.获取需要增加容量的映像的uuid 在vbox的安装目录下使用命令行:VBoxManage list hdds 得到结果如下: UUI ...

  4. 配置RHadoop与运行WordCount例子

    1.安装R语言环境 su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch. ...

  5. 《Java数据结构与算法》笔记-CH4-1栈的实现

    class StackX{ private int maxSize; private long[] stackArray; private int top; public StackX(int siz ...

  6. 【现代程序设计】【homework-05】

    这次作业的运行效果图: 新建了20个客户端线程,服务器相应开了20个线程接收客户端数据,每一秒输出每一轮的结果 这次作业用c#完成 利用 Socket 类实现了局域网中的客户端和服务器之间的通信 主要 ...

  7. Android实例-获取程序版本号(XE10+小米2)

    相关资料: 383675978群号 实例源码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, Sy ...

  8. Spring入门(3)-Spring命名空间与Bean作用域

    Spring入门(3)-Spring命名空间与Bean作用域 这篇文章主要介绍Spring的命名空间和Bean作用域 0. 目录 Spring命名空间 Bean作用域 1. Spring命名空间 在前 ...

  9. Mysql创建、删除用户

    1.新建用户 //登录MYSQL@>mysql -u root -p@>密码//创建用户mysql> insert into mysql.user(Host,User,Passwor ...

  10. java 2 8 10 16

    An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8), or ...