📄 io-eth-phy-generic1.html
字号:
<!-- Copyright (C) 2009 Free Software Foundation, Inc. -->
<!-- This material may be distributed only subject to the terms -->
<!-- and conditions set forth in the Open Publication License, v1.0 -->
<!-- or later (the latest version is presently available at -->
<!-- http://www.opencontent.org/openpub/). -->
<!-- Distribution of the work or derivative of the work in any -->
<!-- standard (paper) book form is prohibited unless prior -->
<!-- permission is obtained from the copyright holder. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Ethernet PHY Device Support</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="Ethernet PHY Device Support"
HREF="io-eth-phy-generic.html"><LINK
REL="PREVIOUS"
TITLE="Ethernet PHY Device Support"
HREF="io-eth-phy-generic.html"><LINK
REL="NEXT"
TITLE="SNMP"
HREF="net-snmp.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="io-eth-phy-generic.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="net-snmp.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="IO-ETH-PHY-GENERIC1"
></A
>Chapter 60. Ethernet PHY Device Support</H1
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="IO-ETH-PHY-API"
>Ethernet PHY Device API</A
></H1
><P
>Modern ethernet subsystems are often separated into two pieces, the
media access controller (sometimes known as a MAC) and the physical
device or line interface (often referred to as a PHY). In this case,
the MAC handles generating and parsing physical frames and the PHY
handles how this data is actually moved to/from the wire. The MAC
and PHY communicate via a special protocol, known as MII. This MII
protocol can handle control over the PHY which allows for selection
of such transmission criteria as line speed, duplex mode, etc.</P
><P
>In most cases, ethernet drivers only need to bother with the PHY during
system initialization. Since the details of the PHY are separate from
the MAC, there are different drivers for each. The drivers for the PHY
are described by a set of exported functions which are commonly used by
the MAC. The primary use of these functions currently is to initialize
the PHY and determine the status of the line connection.</P
><P
>The connection between the MAC and the PHY differs from MAC to MAC, so
the actual routines to manipulate this data channel are a property of
the MAC instance. Furthermore, there are many PHY devices each with their
own internal operations. A complete MAC/PHY driver setup will be comprised
of the MAC MII access functions and the PHY internal driver.</P
><P
>A driver instance is contained within a
<SPAN
CLASS="TYPE"
>eth_phy_access_t</SPAN
>:
<TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> #define PHY_BIT_LEVEL_ACCESS_TYPE 0
#define PHY_REG_LEVEL_ACCESS_TYPE 1
typedef struct {
int ops_type; // 0 => bit level, 1 => register level
bool init_done;
void (*init)(void);
void (*reset)(void);
union {
struct {
void (*set_data)(int);
int (*get_data)(void);
void (*set_clock)(int);
void (*set_dir)(int);
} bit_level_ops;
struct {
void (*put_reg)(int reg, int unit, unsigned short data);
bool (*get_reg)(int reg, int unit, unsigned short *data);
} reg_level_ops;
} ops;
int phy_addr;
struct _eth_phy_dev_entry *dev; // Chip access functions
} eth_phy_access_t;
struct _eth_phy_dev_entry {
char *name;
unsigned long id;
bool (*stat)(eth_phy_access_t *f, int *stat);
}; </PRE
></TD
></TR
></TABLE
>
The <CODE
CLASS="VARNAME"
>dev</CODE
> element points to the PHY specific support
functions.
Currently, the only function which must be defined is <CODE
CLASS="FUNCTION"
>stat()</CODE
>.</P
><P
>The MAC-MII-PHY interface is a narrow connection, with commands and status
moving between the MAC and PHY using a bit-serial protocol.
Some MAC devices contain the intelligence to run this protocol, exposing
a mechanism to access PHY registers one at a time. Other MAC devices may only
provide access to the MII data lines (or even still, this may be considered
completely separate from the MAC). In these cases, the PHY support layer
must handle the serial protocol.
The choice between the access methods is in the
<CODE
CLASS="VARNAME"
>ops_type</CODE
> field.
If it has the value
<CODE
CLASS="VARNAME"
>PHY_BIT_LEVEL_ACCESS_TYPE</CODE
>, then the PHY device layer will
run the protocol, using the access functions
<CODE
CLASS="FUNCTION"
>set_data()</CODE
>,
<CODE
CLASS="FUNCTION"
>get_data()</CODE
>,
<CODE
CLASS="FUNCTION"
>set_clock()</CODE
>,
<CODE
CLASS="FUNCTION"
>set_dir()</CODE
> are used to control the MII signals and run
the protocol.
If <CODE
CLASS="VARNAME"
>ops_type</CODE
> has the value
<CODE
CLASS="VARNAME"
>PHY_REG_LEVEL_ACCESS_TYPE</CODE
>,
then the routines
<CODE
CLASS="FUNCTION"
>put_reg()</CODE
>, and
<CODE
CLASS="FUNCTION"
>get_reg()</CODE
>
are used to access the PHY registers.</P
><P
>Two additional functions may be defined.
These are
<CODE
CLASS="FUNCTION"
>init()</CODE
>, and
<CODE
CLASS="FUNCTION"
>reset()</CODE
>.
The purpose of these functions is for gross-level management of the
MII interface.
The
<CODE
CLASS="FUNCTION"
>init()</CODE
>
function will be called once, at system initialization time.
It should do whatever operations are necessary to prepare the
MII channel.
In the case of
<CODE
CLASS="VARNAME"
>PHY_BIT_LEVEL_ACCESS_TYPE</CODE
> devices,
<CODE
CLASS="FUNCTION"
>init()</CODE
>
should prepare the signals for use, i.e. set up the appropriate
parallel port registers, etc.
The
<CODE
CLASS="FUNCTION"
>reset()</CODE
>
function may be called by a driver to cause the PHY device to
be reset to a known state.
Not all drivers will require this and this function may not even
be possible, so it's use and behavior is somewhat target specific.</P
><P
>Currently, the only function required of device specific drivers is
<CODE
CLASS="FUNCTION"
>stat()</CODE
>.
This routine should query appropriate registers in the PHY and return
a status bitmap indicating the state of the physical connection.
In the case where the PHY can auto-negotiate a line speed and condition,
this information may be useful to the MAC to indicate what speed it should
provide data, etc.
The status bitmask contains these bits:
<TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#define ETH_PHY_STAT_LINK 0x0001 // Link up/down
#define ETH_PHY_STAT_100MB 0x0002 // Connection is 100Mb/10Mb
#define ETH_PHY_STAT_FDX 0x0004 // Connection is full/half duplex</PRE
></TD
></TR
></TABLE
>
Note: the usage here is that if the bit is set, then the condition
exists. For example, if the
<CODE
CLASS="VARNAME"
>ETH_PHY_STAT_LINK</CODE
>
is set, then a physical link has been established.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="io-eth-phy-generic.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="net-snmp.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Ethernet PHY Device Support</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="io-eth-phy-generic.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>SNMP</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -