\documentclass[aspectratio=169,obeyspaces,spaces,hyphens,dvipsnames]{beamer}
\usepackage[utf8x]{inputenc}
\usepackage{lmodern}% http://ctan.org/pkg/lm
\usepackage{minted}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage[normalem]{ulem}
\usepackage{textcomp}

\usepackage{multimedia}

\mode<presentation>
\usetheme{Bootlin}

\def\signed #1{{\leavevmode\unskip\nobreak\hfil\penalty50\hskip2em
  \hbox{}\nobreak\hfil(#1)
  \parfillskip=0pt \finalhyphendemerits=0 \endgraf}}

\newsavebox\mybox
\newenvironment{aquote}[1]
  {\savebox\mybox{#1}\begin{quotation}}
  {\signed{\usebox\mybox}\end{quotation}}

\title{From the Ethernet MAC to the link partner}
\conference{Embedded Linux Conference Europe, October 2018}
\authors{Maxime Chevallier \hfill Antoine Ténart}
\email{{\tiny maxc@bootlin.com \hfill antoine@bootlin.com}}
\institute{Bootlin}
\slidesurl{https://bootlin.com/pub/conferences/2018/elce/chevallier-tenart-high-speed-phy/}

\begin{document}

\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\section{From the Ethernet MAC to the link partner}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}

\begin{frame}{Antoine Ténart}
  \begin{itemize}
    \item Linux kernel engineer and trainer at Bootlin.
      \begin{itemize}
        \item Linux kernel and driver development, system integration,
          boot time optimization, consulting\dots
        \item Embedded Linux, Linux driver development, Yocto Project
          \& OpenEmbedded and Buildroot training, with materials
          freely available under a Creative Commons license.
        \item \url{https://bootlin.com}
      \end{itemize}
    \item Contributions:
      \begin{itemize}
        \item Worked on network (MAC, PHY, switch) and cryptographic
          engines.
        \item Contributed to the Marvell EBU SoCs upstream support.
        \item Introduced the Marvell Berlin SoCs upstream support.
        \item Co-maintainer of the Annapurna Alpine SoCs.
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}{Maxime Chevallier}
  \begin{itemize}
    \item Linux kernel engineer at Bootlin.
      \begin{itemize}
        \item Linux kernel and driver development, system integration,
          boot time optimization, consulting\dots
        \item Embedded Linux, Linux driver development, Yocto Project
          \& OpenEmbedded and Buildroot training, with materials
          freely available under a Creative Commons license.
        \item \url{https://bootlin.com}
      \end{itemize}
    \item Contributions:
      \begin{itemize}
        \item Worked on network (MAC, PHY, switch) engines.
        \item Contributed to the Marvell EBU SoCs upstream support.
        \item Also worked on SPI and real-time topics.
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}{Preamble - goals}
  \begin{itemize}
    \item Discover what are the components of an Ethernet data link
      and physical layer.
    \item Have a first glance at the technologies and protocols used
      for the components to communicate.
    \item Learn how to configure all of this in Linux.
    \item This subject is wide and complex: we'll
      \underline{take shortcuts and make approximations}.
  \end{itemize}
\end{frame}

\section{Introduction to the Ethernet link layer}

\begin{frame}{Reminder: the OSI model}
  \begin{enumerate}
    \item Physical layer.
      \begin{itemize}
        \item Rx/Tx of unstructured data, converts the digital data
          into a signal (e.g. electrical, radio, optical).
      \end{itemize}
    \item Data link layer (e.g. \code{Ethernet}).
      \begin{itemize}
        \item Data transfer between directly connected nodes using
          frames.
      \end{itemize}
    \item Network layer (e.g. \code{IP}).
      \begin{itemize}
        \item Data transfer between nodes — directly connected or
          being routed through other nodes — using packets.
      \end{itemize}
    \item Transport layer (e.g. \code{TCP}, \code{UDP}).
      \begin{itemize}
        \item Reliability, flow control, QoS, ordering,
          segmentation\dots
      \end{itemize}
  \end{enumerate}
  \begin{itemize}
    \item We'll focus on the first two layers, when using
      {\bf Ethernet}.
  \end{itemize}
\end{frame}

\begin{frame}{The Ethernet link layer}
  \begin{center}
    \includegraphics[width=1\textwidth]{graphics/ethernet-link.pdf}
  \end{center}
  \begin{itemize}
    \item The MAC (\code{media access control}), makes up the
      {\it data link layer}:
      \begin{itemize}
        \item Transfers/receives frames.
        \item Handles preambles and paddings.
        \item Protects against errors — checks frames and their FCS
          (\code{frame check sequence}).
        \item \dots
      \end{itemize}
    \item The network PHY, makes up the {\it physical layer}:
      \begin{itemize}
        \item Connects the {\it link layer device} to a {\it physical
          medium}.
        \item Accessible through an \code{MDIO} bus.
      \end{itemize}
    \item Cages (e.g. RJ45, SFP), physical mediums (e.g. copper,
      fiber)\dots
  \end{itemize}
\end{frame}

\begin{frame}{The MacchiatoBin example \small{(1/4)}}
  \begin{itemize}
    \item The Ethernet link layer is built using the elements we just
      saw (\code{MAC}, \code{PHY}\dots), and can differ a bit
      depending on the hardware design and purpose.
    \item Let's focus on the {\it MacchiatoBin double shot} example,
      a board using a Marvell Armada 8040 SoC —
      \url{https://macchiatobin.net}
      \begin{itemize}
        \item It has 4 network ports, 3 different link designs and 6
          cages.
      \end{itemize}
  \end{itemize}
  \begin{center}
    \includegraphics[width=0.4\textwidth]{graphics/mcbin.jpg}
    \includegraphics[width=0.55\textwidth]{graphics/mcbin.pdf}
  \end{center}
\end{frame}

\begin{frame}{The MacchiatoBin example \small{(2/4)}}
  \begin{itemize}
    \item The first port (\code{eth2} in Linux) can handle up to 1G
      links, connected to an RJ45 port.
  \end{itemize}
  \begin{center}
    \includegraphics[width=1\textwidth]{graphics/mcbin-eth2.pdf}
  \end{center}
\end{frame}

\begin{frame}{The MacchiatoBin example \small{(3/4)}}
  \begin{itemize}
    \item The second and third ports (\code{eth0}/\code{eth1} in
      Linux) can handle up to 10G links, connected to RJ45 and SFP+
      cages.
    \item Only one cage can be used at a time.
    \item Dynamic reconfiguration (\code{MAC}, \code{SerDes lanes},
      \code{PHY}) allows to switch between the two usages.
  \end{itemize}
  \begin{center}
    \includegraphics[width=1\textwidth]{graphics/mcbin-eth0.pdf}
  \end{center}
\end{frame}

\begin{frame}{The MacchiatoBin example \small{(4/4)}}
  \begin{itemize}
    \item The fourth port (\code{eth3} in Linux) can handle up to
      2.5G links, connected to an SFP+ cage.
    \item No \code{PHY} on the board — direct \code{MAC} to \code{MAC}
      communication, or a \code{PHY} can be on the \code{SFP}
      external connector.
  \end{itemize}
  \begin{center}
    \includegraphics[width=1\textwidth]{graphics/mcbin-eth3.pdf}
  \end{center}
\end{frame}

\begin{frame}{Linux representation}
  \begin{itemize}
    \item The Ethernet \code{MAC} controller is driven by an Ethernet
      driver:
      \begin{itemize}
        \item Within \kdir{drivers/net/ethernet}.
        \item Represented by \kstruct{net_device}.
      \end{itemize}
    \item The \code{PHY} is driven by a network PHY driver:
      \begin{itemize}
        \item Within \kdir{drivers/net/phy}.
        \item Represented by \kstruct{phy_device}.
      \end{itemize}
    \item In the {\it MacchiatoBin} case:
      \begin{itemize}
        \item \kdir{drivers/net/ethernet/marvell}\code{mvpp2/*,mvmdio.c}
        \item \kfile{drivers/net/phy/marvell.c}
        \item \kfile{drivers/net/phy/marvell10g.c}
      \end{itemize}
    \item In case the \code{MAC} and the \code{PHY} are in the same
      hardware package, everything can be handled directly in
      \code{drivers/net/ethernet/}.
  \end{itemize}
\end{frame}

\begin{frame}{Reporting tools}
  \begin{itemize}
    \item \code{ethtool}: reports information from the Ethernet driver.
      \begin{itemize}
        \item It can be what the MAC is seeing,
        \item Or if the \code{MAC} and the \code{PHY} are in the same
          package, the view of the package itself.
      \end{itemize}
    \item \code{mii-tool}: deprecated and mostly replaced by
      \code{ethtool}, but can be useful to dump the \code{PHY} status.
  \end{itemize}
\end{frame}

\begin{frame}{Interfaces overview}
  \begin{itemize}
    \item For the components of the Ethernet link to communicate, two
      interfaces are standardized by the {\it IEEE 802.3}
      specifications and amendments:
      \begin{itemize}
        \item The Media-Independent Interface (\code{MII}):
          \begin{itemize}
            \item Connects various types of \code{MAC} to various
              types of \code{PHY}.
            \item Originally standardized by the {\it IEEE 802.3u}.
            \item E.g. MII, GMII, RGMII, SGMII, XGMII, XAUI\dots
          \end{itemize}
        \item The Media-Dependent Interface (\code{MDI}):
          \begin{itemize}
            \item Connects the physical layer implementation to the
              physical medium.
            \item E.g. 100BASE-T, 1000BASE-T, 1000BASE-CX,
              1000BASE-SZ, 10GBASE-T\dots
          \end{itemize}
      \end{itemize}
  \end{itemize}
\end{frame}
\newcommand{\colsizeeth}{0.15\linewidth}
\begin{frame}{Ethernet standards}
  The \code{802.3} standard is short and simple, with only a few specifications to remember :
  \begin{columns}
    {\tiny
    \begin{column}{0.20\linewidth}
    \textbf{Specifications}
      \begin{itemize}
        \item 802.3z 802.3aa
        \item 802.3ab 802.3ac
        \item 802.3ad 802.3ae
        \item 802.3af 802.3ag
        \item 802.3ah 802.3aj
        \item 802.3ak 802.3an
        \item 802.3ap 802.3aq
        \item 802.3as 802.3at
        \item 802.3av 802.1AX
        \item 802.3az 802.3ba
        \item 802.3bc 802.3bd
        \item 802.3be 802.3bf
        \item 802.3bg 802.3bj
        \item 802.3bk 802.3bm
        \item 802.3bn 802.3bp
	\dots
% Too many specs
%        \item 802.3bq 802.3br
%        \item 802.3bu 802.3bv
%        \item 802.3bw 802.3by
%        \item 802.3bz 802.3bs
%        \item 802.3cc 802.3bt
%        \item 802.3cb
      \end{itemize}
    \end{column}
    \begin{column}{0.20\linewidth}
    \textbf{Formats}
      \begin{itemize}
        \item 10BASE2
        \item 10BASE5
        \item 10BASE-F
        \item 10BASE-FB
        \item 10BASE-FL
        \item 10BASE-FP
        \item 10BASE-T
        \item 100BASE-BX10
        \item 100BASE-FX
        \item 100BASE-LX10
        \item 100BASE-T
        \item 100BASE-T2
        \item 100BASE-T4
        \item 100BASE-TX
        \item 100BASE-X
      \end{itemize}
    \end{column}
    \begin{column}{0.20\linewidth}
      \begin{itemize}
        \item 1000BASE-BX10
        \item 1000BASE-CX
        \item 1000BASE-KX
        \item 1000BASE-LX
        \item 1000BASE-LX10
        \item 1000BASE-PX
        \item 1000BASE-SX
        \item 1000BASE-T
        \item 1000BASE-X
        \item 2.5GBASE-T
        \item 5GBASE-T
        \item 10GBASE-CX4
        \item 10GBASE-E
        \item 10GBASE-ER
        \item 10GBASE-EW
        \item 10GBASE-KR
      \end{itemize}
    \end{column}
    \begin{column}{0.20\linewidth}
      \begin{itemize}
        \item 10GBASE-KX4
        \item 10GBASE-L
        \item 10GBASE-LR
        \item 10GBASE-LRM
        \item 10GBASE-LW
        \item 10GBASE-LX4
        \item 10GBASE-PR
        \item 10/1GBASE-PRX
        \item 10GBASE-R
        \item 10GBASE-S
        \item 10GBASE-SR
        \item 10GBASE-SW
        \item 10GBASE-T
        \item 10GBASE-W
        \item 10GBASE-X
        \item 40GBASE-R
      \end{itemize}
    \end{column}
    \begin{column}{0.20\linewidth}
      \begin{itemize}
        \item 40GBASE-CR4
        \item 40GBASE-ER4
        \item 40GBASE-FR
        \item 40GBASE-KR4
        \item 40GBASE-LR4
        \item 40GBASE-SR4
        \item 100GBASE-P
        \item 100GBASE-R
        \item 100GBASE-CR4
        \item 100GBASE-CR10
        \item 100GBASE-KP4
        \item 100GBASE-KR4
        \item 100GBASE-ER4
        \item 100GBASE-LR4
        \item 100GBASE-SR4
        \item 100GBASE-SR10
    \end{itemize}
    \end{column}
    }
  \end{columns}
\end{frame}

\begin{frame}{Ethernet link modes notation}
  \begin{itemize}
    \item 802.3 standards use a special notation to describe links and
    protocols:
    \item
{\color{BlueViolet}speed}\code{Band-}{\color{JungleGreen}Medium}{\color{blue}Encoding}{\color{orange}Lanes}
: {\color{BlueViolet}1000}Base-{\color{JungleGreen}T},
{\color{BlueViolet}10G}Base-{\color{JungleGreen}K}{\color{blue}R},
{\color{BlueViolet}100}Base-{\color{JungleGreen}T}{\color{orange}4}\dots
  \end{itemize}

  \begin{itemize}
    \item Band: \code{BASE}band, \code{BROAD}band or \code{PASS}band.
    \item {\color{JungleGreen}Medium}
      \begin{itemize}
        \item Base-\textbf{T}: Link over twisted-pair copper cables
(Classic RJ45).
	\item Base-\textbf{K}: Backplanes (PCB traces) links.
	\item Base-\textbf{C}: Copper links.
	\item Base-\textbf{L}, Base-\textbf{S}, Base-\textbf{F}: Fiber
        links.
	\item Base-\textbf{H}: Plastic Fiber.
	\item \dots
      \end{itemize}
    \item {\color{blue}Encoding}: Describe the block encoding used by the \code{PCS}
      \begin{itemize}
        \item Base-\textbf{X}: 10b/8b encoding.
	\item Base-\textbf{R}: 66b/64b encoding.
      \end{itemize}
    \item {\color{orange}Lanes}: Number of lanes per link (for
    Base-\textbf{T}, number of twisted pairs used).
  \end{itemize}
\end{frame}

\begin{frame}{Link parameters}
  \begin{itemize}
    \item An interface specification has many characteristics:
      \begin{itemize}
        \item {\bf Speed}: the transmission rate at which data is
          flowing through the link: 10Mbps, 100Mbps, 1000Mbps,
          2.5Gbps, 10Gbps, 40Gbps\dots
        \item {\bf Duplex}: it can be {\it half-duplex} (the device
          is either transmitting or receiving data at a given time) or
          {\it full-duplex} (transmission and reception can happen
          simultaneously).
        \item {\bf Auto-negotiation}: can be used to exchange
          information about the {\it duplex}, {\it transmission
          rate}\dots when a device is capable of handling different
          modes or standards.
          \begin{itemize}
            \item Through \code{MII} ({\it in-band}) or \code{MDIO} ({\it out-of-band}).
          \end{itemize}
      \end{itemize}
    \item Different specifications can operate at the same speed, or
      using the same duplex.
    \item But the link can only be operational if compatible {\it MII}
      and {\it MDI} protocols are used.
    \item A given link can support multiple modes, through {\bf
      advertisement}.
  \end{itemize}
\end{frame}

\section{Media interfaces}

\begin{frame}{MAC to PHY connection}
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/mac-to-phy.pdf}
  \end{center}

Inside a \code{PHY}:
  \begin{itemize}
    \item \textbf{PCS}: \textbf{P}hysical \textbf{C}oding \textbf{S}ubsystem
      \begin{itemize}
  \item Encodes and decodes the \code{MII} link.
        \item Several \code{PCS} are described in different
        specifications: 1000Base-X, 10Base-R\dots.
      \end{itemize}
    \item \textbf{PMA}: \textbf{P}hysical \textbf{M}edium \textbf{A}ttachment
      \begin{itemize}
        \item Translates between \code{PCS} and \code{PMD}.
      \item Handles collision detection and data transfers.
      \end{itemize}
    \item \textbf{PMD}: \textbf{P}hysical \textbf{M}edium \textbf{D}ependent
      \begin{itemize}
        \item Interfaces to the physical transmission medium
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}{MDIO bus}
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/small-mac-phy-mdio.pdf}
  \end{center}
  \vspace{-1cm} % ugly
  \center{\textbf{M}anagement \textbf{D}ata \textbf{I}nput \textbf{O}utput}
  \begin{itemize}
    \item Also called \code{SMI}.
    \item Two lines: \code{MDC} for clock, \code{MDIO} for data.
    \item Serial addressable bus between \code{MAC} and up to 32
    \code{PHYs}.
    \item Access to \code{PHY} configuration and status registers.
    \item Not always part of the \code{MAC}, can be a separate controller.
    \item \textbf{Clause 22}: 5bit register addresses, 16bit data.
    \item \textbf{Clause 45}: Extends \code{C22} in a backwards-compatible way.
      \begin{itemize}
        \item 16bit register addresses, 16bit data.
        \item Multiple "devices" per PHY, each with a register set.
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{MDIO in Linux}
  \begin{itemize}
    \item \code{C22} and \code{C45} are supported:
      \begin{itemize}
      \item \kfile{drivers/net/phy/phy_device.c}
      \item \kfile{drivers/net/phy/phy-c45.c}
      \end{itemize}
    \item The driver is selected by matching the \code{UID} register:

  \begin{minted}[fontsize=\footnotesize]{perl}
    struct phy_driver mv3310_drivers[] = {{
        .phy_id         = 0x002b09aa,
        .phy_id_mask    = 0xfffffff0,
        ...
  \end{minted}
    \item Each \code{PHY} is described as a child of the \code{mdio}
    bus:
  \end{itemize}

  \begin{minted}[fontsize=\footnotesize]{perl}
    &mdio {
      ge_phy: ethernet-phy@0 {
        /* Clause 45 register accesses */
        compatible = "ethernet-phy-ieee802.3-c45";
        /* PHY id 0 */
        reg = <0>;
      };
    };
  \end{minted}
\end{frame}

\begin{frame}{MII family}
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/small-mac-phy-mii.pdf}
  \end{center}
  \vspace{-1cm} % Yeah yeah ugly
  \begin{itemize}
    \item \textbf{MII}: \textbf{M}edia \textbf{I}ndependent \textbf{I}nterface
      \begin{itemize}
        \item Originally a single standard, later extended. 16 pins, up to 100Mbps.
        \item \textbf{RMII}: \textbf{R}educed \textbf{MII}: 8 pins.
      \end{itemize}
    \item \textbf{GMII}: \textbf{G}igabit \textbf{MII}
      \begin{itemize}
        \item 24 pins, 1Gbps, compatible with MII for 10/100 Mbps.
        \item \textbf{RGMII}: \textbf{R}educed \textbf{GMII}: 12 pins.
        \item \textbf{RGMII-ID}: Hardware variant with clock delay tweaks.
      \end{itemize}
    \item \textbf{XGMII}: \textbf{X} (ten) \textbf{G}igabit \textbf{MII}
      \begin{itemize}
        \item 74 pins, 10Gbps. Mostly used for on-chip MAC to PHY
          links.
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}{Serializing the MII}

  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/serialized-mac-to-phy.pdf}
  \end{center}

  \begin{itemize}
    \item x\textbf{MII} interfaces have a high pin count, duplicated for each \code{PHY}.
    \item Re-use already defined \code{PCS} and \code{PMA} to serialize the xMII
    link.
    \item \textbf{RS}: \textbf{R}econciliation \textbf{S}ublayer: Glue
      between the \code{MAC} and the PCS.
    \item \textbf{SerDes Lanes}: Differential pair transmitting an encoded serialized signal.
      \begin{itemize}
        \item Base-\textbf{X} (10b/8b) or Base-\textbf{R} (66b/64b).
	\item Embedded or Parallel clock.
        \item Handled by the Generic \code{PHY} Subsystem.
       \end{itemize}
  \end{itemize}
\end{frame}


\begin{frame}{MII Family - Continued}

  \begin{itemize}
    \item \textbf{SGMII}: \textbf{S}erialized \textbf{GMII}
      \begin{itemize}
        \item De-facto standard, 4 differential pairs, Base-X PCS.
        \item Designed for 1Gbps, but a 2.5Gbps variant exists.
        \item \textbf{QSGMII}: Quad SGMII, 5Gbps.
      \end{itemize}
      \item \textbf{XAUI}: \textbf{X} (ten) Gigabit \textbf{A}ttachment \textbf{U}nit \textbf{I}nterface
      \begin{itemize}
        \item XGMII serialized on 4 SerDes lanes, Base-X PCS.
        \item \textbf{RXAUI}: Reduced XAUI, using only 2 SerDes lanes.
      \end{itemize}
    \item \textbf{XFI}: Part of XFP specs (outside of IEEE 802.3)
      \begin{itemize}
        \item 10Gbps over one SerDes lane.
        \item Uses 10GBase-R PCS.
  \item Similar to \textbf{10GBase-KR}
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{MAC to PHY link in linux}

  \begin{itemize}
    \item \code{PHY} connection represented by \ksym{phy_interface_t}.
    \item The \code{phylink} framework provides a representation of this link.
    \item Specified in DT using \code{phy-mode} in the \code{MAC}
    driver node:
  \end{itemize}

  \begin{minted}[fontsize=\footnotesize]{perl}
        &eth1 {
                status = "okay";
        
        	/* Reference to the PHY node */
                phy-handle = <&ge_phy>;
        
        	 /* PHY interface mode */
                phy-mode = "sgmii";
        };
  \end{minted}
\end{frame}

\begin{frame}{Network PHY driver in Linux}

\begin{itemize}
  \item A \code{PHY} driver is responsible for:
  \begin{itemize}
    \item Handling the auto-negotiation parameters.
    \item Reporting the link status to the MAC
      \begin{itemize}
        \item Except in \code{in-band} status management.
      \end{itemize}
  \end{itemize}
\item Interfaces with the \code{phylib} and \code{phylink} frameworks.
  \item \code{PHY} registers are standardized, the \code{phylib} does
  most of the hard work.
  \item Starts to have more advanced features:
    \begin{itemize}
      \item Report statistics.
      \item Configure the Wake-on-LAN parameters.
      \item Implement MACSec.
    \end{itemize}
\end{itemize}
\end{frame}

\begin{frame}{Auto-negotiation}
  \begin{itemize}
    \item What the \code{PHY} advertises is dictated by software.
    \item In Linux, the \code{phylib} subsystem manages the advertised
    modes.
    \item Each \code{MAC} and \code{PHY} driver reports its supported
    modes.
    \item \code{phylink} can take the \code{MAC} to \code{PHY} link
    into account.
  \end{itemize}
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/autoneg.pdf}
  \end{center}
\begin{columns}
  \begin{column}{0.45\linewidth}
    \begin{itemize}
      \item \code{XAUI} interface, 10Gbps capable.
      \item $\rightarrow$ \code{PHY} advertises all of its
      capabilities.
    \end{itemize}
  \end{column}
  \begin{column}{0.55\linewidth}
    \begin{itemize}
      \item \code{XAUI} interface.
      \item $\rightarrow$ \code{PHY} advertises 10/100/1000M and 2.5G in Base-T.
    \end{itemize}
  \end{column}
\end{columns}
  \center{\textbf{Link establishes at 2.5Gbps}}
\end{frame}

\begin{frame}{The MacchiatoBin example}
  \begin{center}
    \includegraphics[width=0.9\textwidth]{graphics/mcbin-eth2-modes.pdf}\\
  \end{center}
  \begin{columns}
    \begin{column}{0.4\textwidth}
      \includegraphics[width=1.2\textwidth]{graphics/mcbin-eth2-ethtool.pdf}
    \end{column}
    \begin{column}{0.6\textwidth}
      \begin{itemize}
        \item {\bf (a)}: supported link modes by the \code{MAC}.
        \item {\bf (b)}: overall transmission rate.
        \item {\bf (c)}: overall duplex mode.
        \item {\bf (d)}: port type.
        \item {\bf (e)}: MDI protocol used.
      \end{itemize}
    \end{column}
  \end{columns}
\end{frame}

\section{Evolution of the Ethernet interface}

\begin{frame}{SFP modules}
  \begin{itemize}
    \item The small form-factor pluggable transceiver (\code{SFP}) is
      a module used for data communication.
    \item Its form factor is described by a specification, which makes
      it widely used by networking device vendors.
    \item An \code{SFP} interface supports various media, such as
      fiber optic or copper cables.
    \item It is {\bf hot-pluggable} and can {\bf optionally embed a
      PHY}.
    \item \code{SFP} transceivers can be {\bf{passive}}, even for optical links.
      \begin{itemize}
        \item The SerDes driver or the \code{SFP} module reports the link state.
      \end{itemize}
  \end{itemize}
  \begin{figure}
    \centering
    \includegraphics[width=0.3\textwidth]{graphics/sfp.jpg}\\
    \tiny{CC BY-SA 3.0 — Christophe Finot}
  \end{figure}
\end{frame}

\begin{frame}{The need for a dynamic link infrastructure}
  \begin{itemize}
    \item The Ethernet link is no longer fixed, with a single
      \code{MAC} connected to a single \code{PHY} with a single
      \code{connector}.
    \item \code{PHY} can be hot-pluggable when in an \code{SFP}
      transceiver.
    \item Part of the \code{PHY} can be embedded into the \code{MAC},
      such as the \code{PCS}. The SerDes lanes can be configured and
      connected to various devices such as other \code{PHY}s or modules
      (\code{SFP}, \code{SFF}).
      \begin{itemize}
        \item This allows more flexibility: less lanes, greater
          distance can be covered, \code{SFP} cages can be connected
          directly to the \code{MAC}\dots
        \item Remember \code{eth3} on the {\it MacchiatoBin}?
      \end{itemize}
  \end{itemize}
  $\Rightarrow$ The Ethernet link in its whole should be {\bf
    dynamically reconfigurable}.
\end{frame}

\begin{frame}{Mandatory MacchiatoBin example {\small (\code{eth0}/\code{eth1})}}
  \begin{center}
    \includegraphics[width=0.75\textwidth]{graphics/mcbin-eth0-dynamic.pdf}
  \end{center}
\end{frame}

\begin{frame}[fragile]{Phylink to the rescue {\small (1/2)}}
  \begin{itemize}
    \item To solve this problematic the {\bf phylink} infrastructure
      was introduced:
  \end{itemize}
  \vspace{0.3cm}
  \begin{minted}[fontsize=\footnotesize]{text}
commit 9525ae83959b60c6061fe2f2caabdc8f69a48bc6
Author: Russell King <rmk+kernel@arm.linux.org.uk>
Commit: David S. Miller <davem@davemloft.net>

    phylink: add phylink infrastructure

    […]

    Phylink aims to solve this by providing an intermediary between the
    MAC and PHY, providing a safe way for PHYs to be hotplugged, and
    allowing a SFP driver to reconfigure the SerDes connection.

    […]
  \end{minted}
\end{frame}

\begin{frame}{Phylink to the rescue {\small (2/2)}}
  \begin{itemize}
    \item \code{phylink} represents the link itself, between a \code{MAC} and
      a \code{PHY}.
    \item There can be an on-board \code{PHY}, a hot-pluggable
      \code{PHY}, a \code{SFP transceiver}.
    \item The \code{PCS} within the \code{MAC} can be reconfigured.
    \item Everything is configured at {\bf runtime}.
    \item \code{phylink} acts as a single synchronization layer between the
      devices on the Ethernet link, maintaining a state machine.
    \item One of the goals is to ensure all elements of the link are
      configured using compatible modes.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Dynamic reconfiguration using phylink {\small (1/3)}}
  At boot time, the Ethernet driver is probed:
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/phylink-0.pdf}
  \end{center}
  \begin{enumerate}
    \item The \code{MAC} is initialized, its ports are down.
    \item A \code{phylink} instance is created — \kfunc{phylink_create}.
    \item An interface per port is created in Linux — \kfunc{register_netdev}.
  \end{enumerate}
\end{frame}

\begin{frame}[fragile]{Dynamic reconfiguration using phylink {\small (2/3)}}
  An interface is brought {\bf up}:
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/phylink-1.pdf}
  \end{center}
  \begin{enumerate}
    \item The \code{MAC} port is started —
      \code{net_device_ops->ndo_open()}.
    \item \code{phylink} connects to the \code{PHY} —
      \kfunc{phylink_of_phy_connect}.
    \item The \code{PHY} is powered on — \kfunc{phy_power_on}.
    \item The \code{phylink} state machine is started —
      \kfunc{phylink_start}.
    \item The \code{MII} interface is configured to its default value.
  \end{enumerate}
\end{frame}

\begin{frame}[fragile]{Dynamic reconfiguration using phylink {\small (3/3)}}
  An RJ45 cable is connected:
  \begin{center}
    \includegraphics[width=0.8\textwidth]{graphics/phylink-2.pdf}
  \end{center}
  \begin{enumerate}
    \item The \code{PHY} sees a cable has been connected, and performs
      an auto-negotiation. It reconfigures itself to use
      \code{1000Base-T}.
    \item The \code{phylib} state machine detects a change in the PHY state —
      \kfunc{phy_state_machine}.
    \item A resolution of the flow is performed —
      \kfunc{phylink_resolve}.
    \item The \code{MII} is reconfigured to \code{SGMII} —
      \kfunc{phylink_mac_config}.
  \end{enumerate}
\end{frame}

\section{Conclusion}

\begin{frame}{Conclusion}
  \begin{itemize}
    \item The \code{MAC-PHY-LP} representation of the link has
      evolved:
      \begin{itemize}
        \item It is useful to understand the concepts, and the Linux
          representation.
        \item It is still used in many embedded devices.
      \end{itemize}
    \item More complex designs are also used:
      \begin{itemize}
        \item A \code{PHY} can be hot-plugged.
        \item Parts of a \code{PHY} can be re-used within the
          \code{MAC}.
        \item The full link can be reconfigured, to support
          incompatible modes (e.g. \code{SGMII} and \code{10GBase-KR}
          in the \code{MAC}).
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \begin{center}
    \Huge
    Thank you! \\
    Questions? Comments?\\
    \vspace{1cm}
    \large
    Maxime Chevallier — \code{maxc@bootlin.com}\\
    Antoine Ténart — \code{antoine@bootlin.com}\\
    \vspace{1cm}
    Slides under CC-BY-SA 3.0
    \scriptsize
    \url{https://bootlin.com/pub/conferences/2018/elce/chevallier-tenart-high-speed-phy/}
  \end{center}
\end{frame}

\end{document}
