Skip to content
Snippets Groups Projects
Commit 931066c2 authored by Florian Pose's avatar Florian Pose
Browse files

Ethernet devices.

parent f5659967
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
% %
% $Id$ % $Id$
% %
% vi: spell spelllang=en
%
%------------------------------------------------------------------------------ %------------------------------------------------------------------------------
% %
...@@ -320,7 +322,7 @@ EtherCAT functionality (see section~\ref{sec:ecrt}). ...@@ -320,7 +322,7 @@ EtherCAT functionality (see section~\ref{sec:ecrt}).
\begin{itemize} \begin{itemize}
\item Master and network device configuration via Sysconfig files. \item Master and network device configuration via sysconfig files.
\item Init script for master control. \item Init script for master control.
...@@ -719,18 +721,17 @@ respectively. ...@@ -719,18 +721,17 @@ respectively.
\paragraph{Tasks of a Network Driver} \paragraph{Tasks of a Network Driver}
Network device drivers handle the lower two layers of the OSI model, Network device drivers usually handle the lower two layers of the OSI model,
that is the physical layer and the data-link layer. A network device that is the physical layer and the data-link layer. A network device itself
itself natively handles the physical layer issues: It represents the natively handles the physical layer issues: It represents the hardware to
hardware to connect to the medium and to send and receive data in the connect to the medium and to send and receive data in the way, the physical
way, the physical layer protocol describes. The network device driver layer protocol describes. The network device driver is responsible for getting
is responsible for getting data from the kernel's networking stack and data from the kernel's networking stack and forwarding it to the hardware,
forwarding it to the hardware, that does the physical transmission. that does the physical transmission. If data is received by the hardware
If data is received by the hardware respectively, the driver is respectively, the driver is notified (usually by means of an interrupt) and
notified (usually by means of an interrupt) and has to read the data has to read the data from the hardware memory and forward it to the network
from the hardware memory and forward it to the network stack. There stack. There are a few more tasks, a network device driver has to handle,
are a few more tasks, a network device driver has to handle, including including queue control, statistics and device dependent features.
queue control, statistics and device dependent features.
\paragraph{Driver Startup} \paragraph{Driver Startup}
...@@ -767,98 +768,95 @@ callback is mandatory, but for reasonable operation the ones below are ...@@ -767,98 +768,95 @@ callback is mandatory, but for reasonable operation the ones below are
needed in any case: needed in any case:
\begin{description} \begin{description}
\item[int (*open)(struct net\_device *)] This function is called when
network communication has to be started, for example after a command \item[open()] This function is called when network communication has to be
\textit{ifconfig ethX up} from user space. Frame reception has to be started, for example after a command \textit{ifconfig ethX up} from user
enabled by the driver. space. Frame reception has to be enabled by the driver.
\item[int (*stop)(struct net\_device *)] The purpose of this callback
is to ``close'' the device, i.~e. make the hardware stop receiving \item[stop()] The purpose of this callback is to ``close'' the device, i.~e.
frames. make the hardware stop receiving frames.
\item[int (*hard\_start\_xmit)(struct sk\_buff *, struct net\_device
*)] This function is cal\-led for each frame that has to be \item[hard\_start\_xmit()] This function is cal\-led for each frame that has
transmitted. The network stack passes the frame as a pointer to an to be transmitted. The network stack passes the frame as a pointer to an
\textit{sk\_buff} structure (``socket buffer''\index{Socket buffer}, \textit{sk\_buff} structure (``socket buffer''\index{Socket buffer}, see
see below), which has to be freed after sending. below), which has to be freed after sending.
\item[struct net\_device\_stats *(*get\_stats)(struct net\_device *)]
This call has to return a pointer to the device's \item[get\_stats()] This call has to return a pointer to the device's
\textit{net\_device\_stats} structure, which permanently has to be \textit{net\_device\_stats} structure, which permanently has to be filled with
filled with frame statistics. This means, that every time a frame is frame statistics. This means, that every time a frame is received, sent, or an
received, sent, or an error happened, the appropriate counter in error happened, the appropriate counter in this structure has to be increased.
this structure has to be increased.
\end{description} \end{description}
The actual registration is done with the \textit{register\_netdev()} The actual registration is done with the \lstinline+register_netdev()+ call,
call, unregistering is done with \textit{unregister\_netdev()}. unregistering is done with \lstinline+unregister_netdev()+.
\paragraph{The netif Interface} \paragraph{The netif Interface}
\index{netif} \index{netif}
All other communication in the direction interface $\to$ network stack is done All other communication in the direction interface $\to$ network stack is done
via the \textit{netif\_*} calls. For example, on successful device opening, the via the \lstinline+netif_*()+ calls. For example, on successful device
network stack has to be notified, that it can now pass frames to the interface. opening, the network stack has to be notified, that it can now pass frames to
This is done by calling \textit{netif\_start\_queue()}. After this call, the the interface. This is done by calling \lstinline+netif_start_queue()+. After
\textit{hard\_start\_xmit()} callback can be called by the network stack. this call, the \lstinline+hard_start_xmit()+ callback can be called by the
Furthermore a network driver usually manages a frame transmission queue. If network stack. Furthermore a network driver usually manages a frame
this gets filled up, the network stack has to be told to stop passing further transmission queue. If this gets filled up, the network stack has to be told
frames for a while. This happens with a call to \textit{netif\_stop\_queue()}. to stop passing further frames for a while. This happens with a call to
If some frames have been sent, and there is enough space again to queue new \lstinline+netif_stop_queue()+. If some frames have been sent, and there is
frames, this can be notified with \textit{netif\_wake\_queue()}. Another enough space again to queue new frames, this can be notified with
important call is \textit{netif\_receive\_skb()}\footnote{This function is part \lstinline+netif_wake_queue()+. Another important call is
of the NAPI (``New API''), that replaces the ``old'' kernel 2.4 technique for \lstinline+netif_receive_skb()+\footnote{This function is part of the NAPI
interfacing to the network stack (with \textit{netif\_rx()}). NAPI is a (``New API''), that replaces the kernel 2.4 technique for interfacing to the
technique to improve network performance on Linux. Read more in network stack (with \lstinline+netif_rx()+). NAPI is a technique to improve
\url{http://www.cyberus.ca/~hadi/usenix-paper.tgz}}: It passes a frame to the network performance on Linux. Read more in
network stack, that was just received by the device. Frame data has to be \url{http://www.cyberus.ca/~hadi/usenix-paper.tgz}.}: It passes a frame to the
network stack, that was just received by the device. Frame data has to be
packed into a so-called ``socket buffer'' for that (see below). packed into a so-called ``socket buffer'' for that (see below).
\paragraph{Socket Buffers} \paragraph{Socket Buffers}
\index{Socket buffer} \index{Socket buffer}
Socket buffers are the basic data type for the whole network stack. Socket buffers are the basic data type for the whole network stack. They
They serve as containers for network data and are able to quickly add serve as containers for network data and are able to quickly add data headers
data headers and footers, or strip them off again. Therefore a socket and footers, or strip them off again. Therefore a socket buffer consists of an
buffer consists of an allocated buffer and several pointers that mark allocated buffer and several pointers that mark beginning of the buffer
beginning of the buffer (\textit{head}), beginning of data (\textit{head}), beginning of data (\textit{data}), end of data
(\textit{data}), end of data (\textit{tail}) and end of buffer (\textit{tail}) and end of buffer (\textit{end}). In addition, a socket buffer
(\textit{end}). In addition, a socket buffer holds network header holds network header information and (in case of received data) a pointer to
information and (in case of received data) a pointer to the the \textit{net\_device}, it was received on. There exist functions that
\textit{net\_device}, it was received on. There exist functions that create a socket buffer (\lstinline+dev_alloc_skb()+), add data either from
create a socket buffer (\textit{dev\_alloc\_skb()}), add data either front (\lstinline+skb_push()+) or back (\lstinline+skb_put()+), remove data
from front (\textit{skb\_push()}) or back (\textit{skb\_put()}), from front (\lstinline+skb_pull()+) or back (\lstinline+skb_trim()+), or
remove data from front (\textit{skb\_pull()}) or back delete the buffer (\lstinline+kfree_skb()+). A socket buffer is passed from
(\textit{skb\_trim()}), or delete the buffer (\textit{kfree\_skb()}). layer to layer, and is freed by the layer that uses it the last time. In case
A socket buffer is passed from layer to layer, and is freed by the of sending, freeing has to be done by the network driver.
layer that uses it the last time. In case of sending, freeing has to
be done by the network driver.
%------------------------------------------------------------------------------ %------------------------------------------------------------------------------
\section{EtherCAT Device Drivers} \section{EtherCAT Device Drivers}
\label{sec:requirements} \label{sec:requirements}
There are a few requirements for Ethernet network devices to function There are a few requirements for Ethernet network devices to function as
as EtherCAT devices, when connected to an EtherCAT bus. EtherCAT devices, when connected to an EtherCAT bus.
\paragraph{Dedicated Interfaces} \paragraph{Dedicated Interfaces}
For performance and realtime purposes, the EtherCAT master needs For performance and realtime purposes, the EtherCAT master needs direct and
direct and exclusive access to the Ethernet hardware. This implies exclusive access to the Ethernet hardware. This implies that the network
that the network device must not be connected to the kernel's network device must not be connected to the kernel's network stack as usual, because
stack as usual, because the kernel would try to use it as an ordinary the kernel would try to use it as an ordinary Ethernet device.
Ethernet device.
\paragraph{Interrupt-less Operation} \paragraph{Interrupt-less Operation}
\index{Interrupt} \index{Interrupt}
EtherCAT frames travel through the logical EtherCAT ring and are then EtherCAT frames travel through the logical EtherCAT ring and are then sent
sent back to the master. Communication is highly deterministic: A back to the master. Communication is highly deterministic: A frame is sent and
frame is sent and will be received again after a constant time. will be received again after a constant time. Therefore, there is no need to
Therefore, there is no need to notify the driver about frame notify the driver about frame reception: The master can instead query the
reception: The master can instead query the hardware for received hardware for received frames.
frames.
Figure~\ref{fig:interrupt} shows two workflows for cyclic frame Figure~\ref{fig:interrupt} shows two workflows for cyclic frame transmission
transmission and reception with and without interrupts. and reception with and without interrupts.
\begin{figure}[htbp] \begin{figure}[htbp]
\centering \centering
...@@ -867,46 +865,42 @@ transmission and reception with and without interrupts. ...@@ -867,46 +865,42 @@ transmission and reception with and without interrupts.
\label{fig:interrupt} \label{fig:interrupt}
\end{figure} \end{figure}
In the left workflow ``Interrupt Operation'', the data from the last In the left workflow ``Interrupt Operation'', the data from the last cycle is
cycle is first processed and a new frame is assembled with new first processed and a new frame is assembled with new datagrams, which is then
datagrams, which is then sent. The cyclic work is done for now. sent. The cyclic work is done for now. Later, when the frame is received
Later, when the frame is received again by the hardware, an interrupt again by the hardware, an interrupt is triggered and the ISR is executed. The
is triggered and the ISR is executed. The ISR will fetch the frame ISR will fetch the frame data from the hardware and initiate the frame
data from the hardware and initiate the frame dissection: The dissection: The datagrams will be processed, so that the data is ready for
datagrams will be processed, so that the data is ready for processing processing in the next cycle.
in the next cycle.
In the right workflow ``Interrupt-less Operation'', there is no hardware
In the right workflow ``Interrupt-less Operation'', there is no interrupt enabled. Instead, the hardware will be polled by the master by
hardware interrupt enabled. Instead, the hardware will be polled by executing the ISR. If the frame has been received in the meantime, it will be
the master by executing the ISR. If the frame has been received in the dissected. The situation is now the same as at the beginning of the left
meantime, it will be dissected. The situation is now the same as at workflow: The received data is processed and a new frame is assembled and
the beginning of the left workflow: The received data is processed and sent. There is nothing to do for the rest of the cycle.
a new frame is assembled and sent. There is nothing to do for the rest
of the cycle. The interrupt-less operation is desirable, because there is simply no need for
an interrupt. Moreover hardware interrupts are not conducive in improving the
The interrupt-less operation is desirable, because there is simply no driver's realtime behaviour: Their indeterministic incidences contribute to
need for an interrupt. Moreover hardware interrupts are not conducive increasing the jitter. Besides, if a realtime extension (like RTAI) is used,
in improving the driver's realtime behaviour: Their indeterministic some additional effort would have to be made to prioritize interrupts.
incidences contribute to increasing the jitter. Besides, if a realtime
extension (like RTAI) is used, some additional effort would have to be
made to prioritize interrupts.
\paragraph{Ethernet and EtherCAT Devices} \paragraph{Ethernet and EtherCAT Devices}
Another issue lies in the way Linux handles devices of the same type. Another issue lies in the way Linux handles devices of the same type. For
For example, a PCI\nomenclature{PCI}{Peripheral Component example, a PCI\nomenclature{PCI}{Peripheral Component Interconnect, Computer
Interconnect, Computer Bus} driver scans the PCI bus for devices it Bus} driver scans the PCI bus for devices it can handle. Then it registers
can handle. Then it registers itself as the responsible driver for all itself as the responsible driver for all of the devices found. The problem is,
of the devices found. The problem is, that an unmodified driver can that an unmodified driver can not be told to ignore a device because it will
not be told to ignore a device because it will be used for EtherCAT be used for EtherCAT later. There must be a way to handle multiple devices of
later. There must be a way to handle multiple devices of the same the same type, where one is reserved for EtherCAT, while the other is treated
type, where one is reserved for EtherCAT, while the other is treated
as an ordinary Ethernet device. as an ordinary Ethernet device.
For all this reasons, the author has decided that the only acceptable For all this reasons, the author decided that the only acceptable solution is
solution is to modify standard Ethernet drivers in a way that they to modify standard Ethernet drivers in a way that they keep their normal
keep their normal functionality, but gain the ability to treat one or functionality, but gain the ability to treat one or more of the devices as
more of the devices as EtherCAT-capable. EtherCAT-capable.
Below are the advantages of this solution: Below are the advantages of this solution:
...@@ -1921,10 +1915,9 @@ $\rightarrow$~READ STATES ...@@ -1921,10 +1915,9 @@ $\rightarrow$~READ STATES
for the first slave marked as offline. for the first slave marked as offline.
$\rightarrow$~REWRITE ADDRESSES $\rightarrow$~REWRITE ADDRESSES
\item[REWRITE ADDRESSES] If the station address was successfully \item[REWRITE ADDRESSES] If the station address was successfully written, it is
written, it is sear\-ched for the next slave marked as offline. If searched for the next slave marked as offline. If there is one, its address is
there is one, its address is reconfigured, too. reconfigured, too. $\rightarrow$~REWRITE ADDRESSES
$\rightarrow$~REWRITE ADDRESSES
If there are no more slaves marked as offline, the state machine is If there are no more slaves marked as offline, the state machine is
restarted. $\rightarrow$~START restarted. $\rightarrow$~START
...@@ -2428,7 +2421,7 @@ approach was considered as difficult, because of several reasons: ...@@ -2428,7 +2421,7 @@ approach was considered as difficult, because of several reasons:
the instances using the network interfaces. the instances using the network interfaces.
\end{itemize} \end{itemize}
\paragraph{Number of Handlers} \paragraph{Number of Handlers} % FIXME
The master module has a parameter \textit{ec\_eoeif\_count} to specify The master module has a parameter \textit{ec\_eoeif\_count} to specify
the number of EoE interfaces (and handlers) per master to create. This the number of EoE interfaces (and handlers) per master to create. This
...@@ -3099,7 +3092,7 @@ extracted from the Linux kernel sources. ...@@ -3099,7 +3092,7 @@ extracted from the Linux kernel sources.
The source code is documented using Doxygen~\cite{doxygen}. To build the HTML The source code is documented using Doxygen~\cite{doxygen}. To build the HTML
documentation, you must have the Doxygen software installed. The below command documentation, you must have the Doxygen software installed. The below command
will generate the documents in the subdirecory \textit{doxygen-output}: will generate the documents in the subdirectory \textit{doxygen-output}:
\begin{lstlisting} \begin{lstlisting}
$ `\textbf{make doc}` $ `\textbf{make doc}`
...@@ -3119,9 +3112,9 @@ sysconfig file and the user space tools to the prefix path. ...@@ -3119,9 +3112,9 @@ sysconfig file and the user space tools to the prefix path.
# `\textbf{make install}` # `\textbf{make install}`
\end{lstlisting} \end{lstlisting}
If the target kernel's modules directory is not under If the target kernel's modules directory is not under \textit{/lib/modules}, a
\textit{/lib/modules}, a different destination directory can be different destination directory can be specified with the \lstinline+DESTDIR+
specified with the \textit{DESTDIR} make variable. For example: make variable. For example:
\begin{lstlisting} \begin{lstlisting}
# `\textbf{make DESTDIR=/vol/nfs/root modules\_install}` # `\textbf{make DESTDIR=/vol/nfs/root modules\_install}`
...@@ -3824,10 +3817,10 @@ for rapid realtime code generation under Linux with Simulink/RTW and EtherCAT ...@@ -3824,10 +3817,10 @@ for rapid realtime code generation under Linux with Simulink/RTW and EtherCAT
technology. \url{http://etherlab.org/en}, 2008. technology. \url{http://etherlab.org/en}, 2008.
\bibitem{dlspec} IEC 61158-4-12: Data-link Protocol Specification. \bibitem{dlspec} IEC 61158-4-12: Data-link Protocol Specification.
International Electrotechnical Comission (IEC), 2005. International Electrotechnical Commission (IEC), 2005.
\bibitem{alspec} IEC 61158-6-12: Application Layer Protocol Specification. \bibitem{alspec} IEC 61158-6-12: Application Layer Protocol Specification.
International Electrotechnical Comission (IEC), 2005. International Electrotechnical Commission (IEC), 2005.
\bibitem{gpl} GNU General Public License, Version 2. \bibitem{gpl} GNU General Public License, Version 2.
\url{http://www.gnu.org/licenses/gpl.txt}. August~9, 2006. \url{http://www.gnu.org/licenses/gpl.txt}. August~9, 2006.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment