📄 io-eth-call-graph.html
字号:
<!-- Copyright (C) 2003 Red Hat, 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. --><HTML><HEAD><TITLE>Calling graph for Transmission and Reception</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="Generic Ethernet Device Driver"HREF="io-eth-drv-generic1.html"><LINKREL="PREVIOUS"TITLE="Upper Layer Functions"HREF="io-eth-drv-upper-api.html"><LINKREL="NEXT"TITLE="SNMP"HREF="net-snmp.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="io-eth-drv-upper-api.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 46. Generic Ethernet Device Driver</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="net-snmp.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="IO-ETH-CALL-GRAPH">Calling graph for Transmission and Reception</H1><P>It may be worth clarifying further the flow of control in the transmit andreceive cases, where the hardware driver does use interrupts and so DSRs totell the “foreground” when something asynchronous has occurred.</P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-CALL-GRAPH-TX">Transmission</H2><P></P><OLTYPE="1"><LI><P>Some foreground task such as the application, SNMP “daemon”,DHCP management thread or whatever, calls into network stack to send apacket, or the stack decides to send a packet in response to incomingtraffic such as a “ping” or <SPANCLASS="ACRONYM">ARP</SPAN> request.</P></LI><LI><P>The driver calls the<TTCLASS="FUNCTION"><TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_can_send()</TT>function in the hardware driver.</P></LI><LI><P><TTCLASS="FUNCTION"><TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_can_send()</TT>returns the number of available "slots" in which itcan store a pending transmit packet.If it cannot send at this time, the packet is queued outside thehardware driver for later; in this case, the hardware is already busytransmitting, so expect an interrupt as described below for completionof the packet currently outgoing.</P></LI><LI><P>If it can send right now, <TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_send() is called.<TTCLASS="FUNCTION"><TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_send()</TT> copies thedata into special hardware buffers, or instructs the hardware to“send that.” It also remembers the key that is associated withthis tx request.</P></LI><LI><P>These calls return … time passes …</P></LI><LI><P>Asynchronously, the hardware makes an interrupt to say“transmit is done.”The ISR quietens the interrupt source in the hardware andrequests that the associated DSR be run.</P></LI><LI><P>The DSR calls (or <SPANCLASS="emphasis"><ICLASS="EMPHASIS">is</I></SPAN>) the<TTCLASS="FUNCTION">eth_drv_dsr()</TT> function in the generic driver.</P></LI><LI><P><TTCLASS="FUNCTION">eth_drv_dsr()</TT> in the generic driver awakens the“Network Delivery Thread” which calls the deliver function<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_deliver() in the driver.</P></LI><LI><P>The deliver function realizes that a transmit request has completed,and calls the callback tx-done function<TTCLASS="FUNCTION">(sc->funs->eth_drv->tx_done)()</TT>with the same key that it remembered for this tx.</P></LI><LI><P>The callback tx-done functionuses the key to find the resources associated withthis transmit request; thus the stack knows that the transmit hascompleted and its resources can be freed.</P></LI><LI><P>The callback tx-done functionalso enquires whether <TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_can_send() now says“yes, we can send”and if so, dequeues a further transmit requestwhich may have been queued as described above. If so, then<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_send() copies the data into the hardware buffers, orinstructs the hardware to "send that" and remembers the new key, as above.These calls then all return to the “Network Delivery Thread”which then sleeps, awaiting the next asynchronous event.</P></LI><LI><P>All done …</P></LI></OL></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-CALL-GRAPH-RX">Receive</H2><P></P><OLTYPE="1"><LI><P>Asynchronously, the hardware makes an interrupt to say“there is ready data in a receive buffer.”The ISR quietens the interrupt source in the hardware andrequests that the associated DSR be run.</P></LI><LI><P>The DSR calls (or <SPANCLASS="emphasis"><ICLASS="EMPHASIS">is</I></SPAN>) the<TTCLASS="FUNCTION">eth_drv_dsr()</TT> function in the generic driver.</P></LI><LI><P><TTCLASS="FUNCTION">eth_drv_dsr()</TT> in the generic driver awakens the“Network Delivery Thread” which calls the deliver function<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_deliver() in the driver.</P></LI><LI><P>The deliver function realizes that there is data ready and callsthe callback receive function<TTCLASS="FUNCTION">(sc->funs->eth_drv->recv)()</TT>to tell it how many bytes to prepare for.</P></LI><LI><P>The callback receive function allocates memory within the stack(eg. <SPANCLASS="TYPE">MBUFs</SPAN> in BSD/Unix style stacks) and preparesa set of scatter-gather buffers that canaccommodate the packet.</P></LI><LI><P>It then calls back into the hardware driver routine<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_recv().<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_recv() must copy the data from thehardware's buffers into the scatter-gather buffers provided, and return.</P></LI><LI><P>The network stack now has the data in-hand, and does with it what it will.This might include recursive calls to transmit a response packet.When this all is done, these calls return, and the“Network Delivery Thread”sleeps once more, awaiting the next asynchronous event.</P></LI></OL></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="io-eth-drv-upper-api.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="net-snmp.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Upper Layer Functions</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-eth-drv-generic1.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">SNMP</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -