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

\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{Representing the front-facing port of Ethernet interfaces}
\authors{Maxime Chevallier}
\email{maxime.chevallier@bootlin.com}
\slidesurl{https://bootlin.com/pub/conferences/2024/lpc/multi-port.pdf}
\institute{Bootlin}
\conference{LPC 2024 - Vienna}

\begin{document}

\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\section{Representing the front-facing port of Ethernet interfaces}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}

\begin{frame}{Maxime Chevallier}
  \begin{itemize}
  \item Embedded Linux engineer at Bootlin
    \begin{itemize}
    \item Embedded Linux {\bf expertise}
    \item {\bf Development}, consulting and training
    \item Strong open-source focus
    \end{itemize}
  \item Open-source contributor
  \item Living near {\bf Toulouse}, France
  \end{itemize}
\end{frame}
%
%\begin{frame}[fragile]{Frame with code}
%  \begin{block}{\code{filename}}
%    \fontsize{9}{9}\selectfont
%    \begin{minted}{c}
%#include <stdio.h>
%
%int main(void)
%{
%    printf("hello, world\n");
%}
%    \end{minted}
%  \end{block}
%\end{frame}

\begin{frame}{Typical embedded hardware design}
	\begin{columns}
		\begin{column}{0.3\textwidth}
			\begin{center}
			 \includegraphics[width=0.8\linewidth]{graphics/one-phy-one-mac.pdf}
			\end{center}
		\end{column}
		\begin{column}{0.7\textwidth}
			\begin{itemize}
				\item \code{MII}: Media Independent Interface
					\begin{itemize}
						\item SGMII, RGMII, RXAUI, etc.
					\end{itemize}
				\item \code{MDI}: Media Dependent Interface
					\begin{itemize}
						\item 1000BaseT4, 10BaseT1S, 10GBaseSR, etc.
					\end{itemize}
			\end{itemize}
			Variants
			\begin{itemize}
				\item The PHY can be integrated in the SoC or MAC
				\item The PHY might not exist at all
				\item The PHY can be handled by a firmware
				\item The Port isn't always BaseT4
				\item The Port can be internal (backplane ethernet)
			\end{itemize}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}{Mutli-port designs}
	\begin{columns}
		\begin{column}{0.3\textwidth}
			\begin{center}
			 \includegraphics[width=0.8\linewidth]{graphics/two-ports-one-mac.pdf}
			\end{center}
		\end{column}
		\begin{column}{0.7\textwidth}
			\begin{itemize}
				\item One interface, multiple front-facing ports
				\item \code{SFP} + Copper combo ports (MCBin for example)
				\item Also used for redundancy
			\end{itemize}
		\end{column}
	\end{columns}

\end{frame}

\begin{frame}{What do we know about the port ?}
PHY information
	\begin{itemize}
		\item \code{int phydev.port} : \code{PORT_FIBRE}, \code{PORT_TP}, etc. Active port.
		\item \code{phydev.supported}, \code{phydev.advertising} : Supported ports and linkmodes
		\item \code{ethtool_ksettings} : whole NIC (MAC + PHY) supported modes
		\item Works well, but only makes sense for a single port.
	\end{itemize}
SFP/SFF
	\begin{itemize}
		\item \textit{upstream} MAC or PHY knows precisely the SFP cage protocols
		\item When the module is inserted, we detect the real link modes
	\end{itemize}
\end{frame}

\begin{frame}{New representation}
	\begin{itemize}
		\item \code{struct phy_port} (or \code{struct phy_mdi} ? \code{struct mdi} ?)
		\item Set of ops to get the status and support using \code{ethtool_ksettings}
			\begin{itemize}
				\item \code{phy_port_ethtool_ksettings_[g|s]et}
			\end{itemize}
		\item Set of ops to configure the port :
			\begin{itemize}
				\item \code{enabled}
				\item \code{preferred} ?
			\end{itemize}
		\item Port "provider" implement these ops : PHY driver, phylink, MAC, SFP
		\item Helpers in \code{phylib} to make it as transparent as possible
	\end{itemize}
\end{frame}

\begin{frame}{MDI information}
	\begin{itemize}
		\item Populated by the PHY driver or NIC driver, based on what it knows.
			\begin{itemize}
				\item Hardcoded, if only one possible mode
				\item Reported by HW straps, eeproms or FW (sometimes incorrect)
				\item Extracted from devicetree
			\end{itemize}
		\item Device Tree current status : Not ideal
			\begin{itemize}
				\item \code{ti,fiber-mode}, \code{micrel,fiber-mode}
				\item \code{ti,op-mode} : Correlates \code{MII} and {MDI}
				\item \code{max-speed} : (ab)used for 100M limitation ( 2 lanes wired instead of 4)
			\end{itemize}
		\item We lack information about the presence or absence of the MDI
	\end{itemize}
\end{frame}

\begin{frame}[fragile]{Combo SFP + Copper}
	\begin{columns}
		\begin{column}{0.5\textwidth}
				 \includegraphics[width=0.7\linewidth]{graphics/phy_1p.pdf}
		\end{column}
		\begin{column}{0.5\textwidth}
		  \begin{block}{}
		    \fontsize{9}{9}\selectfont
		    \begin{minted}{c}
ethernet-phy@0 {
    reg = <0>;
};
		    \end{minted}
		  \end{block}
		\end{column}
	\end{columns}
	\begin{columns}
		\begin{column}{0.5\textwidth}
				 \includegraphics[width=0.7\linewidth]{graphics/phy_sfp.pdf}
		\end{column}
		\begin{column}{0.5\textwidth}
		  \begin{block}{}
		    \fontsize{9}{9}\selectfont
		    \begin{minted}{c}
ethernet-phy@0 {
    reg = <0>;
    sfp = <&sfp0>;
};
		    \end{minted}
		  \end{block}
		\end{column}
	\end{columns}
	\begin{columns}
		\begin{column}{0.5\textwidth}
				 \includegraphics[width=0.7\linewidth]{graphics/phy_2p.pdf}
		\end{column}
		\begin{column}{0.5\textwidth}
		  \begin{block}{}
		    \fontsize{9}{9}\selectfont
		    \begin{minted}{c}
ethernet-phy@0 {
    reg = <0>;
    sfp = <&sfp0>;
    // No indication about the 8P8C presence
};
		    \end{minted}
		  \end{block}
		\end{column}
	\end{columns}

\end{frame}

\begin{frame}[fragile]{Devicetree example - WIP}
  \begin{block}{\code{example.dts}}
    \fontsize{9}{9}\selectfont
    \begin{minted}{c}
ethernet-phy@0 {
 ...

  mdi {
    port@0 {
      media = "10baseT", "100baseT", "1000baseT";
      lanes = <4>;

      /* Attach PSE ports to the actual connector */
      pses = <&pse_pi0>;
    };

    port@1 {
      sfp = <&sfp>;
      lanes = <1>;
    };
  };
};
    \end{minted}
  \end{block}
	\begin{itemize}
		\item Only relevant when the current representation isn't enough
	\end{itemize}
\end{frame}

\begin{frame}{Port switching}
	\begin{center}
	 \includegraphics[width=0.7\linewidth]{graphics/overview_2.pdf}
	\end{center}

	User cares about which \textcolor[rgb]{1,0.6,0.2}{front-facing-ports} are on a given \textcolor[rgb]{0, 0, 1}{interface}
\end{frame}

\begin{frame}{Link detection and commutation}
	\begin{itemize}
		\item The port's parent must report how link detection happens.
		\item Case 1 : We can always independently detect and negociate the link
			\begin{itemize}
				\item Dual-PHY with MII multiplexer
				\item Support for preferred port
				\item Support for highest-speed link
			\end{itemize}
		\item Case 2 : While one port is actively used, we can't detect link on other ports
			\begin{itemize}
				\item Fiber SFP + Copper Combo-PHY
				\item Limited support for preferred port
			\end{itemize}
		\item Case 3 : We can only detect link one port at a time, even if no port has link
			\begin{itemize}
				\item Dual-PHY, no multiplexer, PHY has broken isolation
			\end{itemize}

		\item Send a gratuitous ARP upon switching port
		\item Similarities with \code{bonding}, but with only one netdev
	\end{itemize}
\end{frame}

\begin{frame}{uAPI}
	\begin{itemize}
		\item Prototype code using a new set of ethtool netlink messages
			\begin{itemize}
				\item \code{ETHTOOL_A_PORT_GET}
				\item \code{ETHTOOL_A_PORT_SET}
			\end{itemize}
		\item Relies on setting port attributes :
			\begin{itemize}
				\item \code{enabled} : Power the port link detection on/off
				\item \code{forced} : Force this port to be used.
				\item \code{preferred} : Prefer this port, if possible
			\end{itemize}
	\end{itemize}
\end{frame}

\begin{frame}{Conclusion}
	Open questions :
	\begin{itemize}
		\item Naming : \code{mdi} ? \code{port} ? something else ?
		\item Device tree binding
		\item uAPI
		\item Integration with bonding ?
	\end{itemize}
	Ongoing work :
	\begin{itemize}
		\item Support for multiple PHYs started :\code{phy_link_topology}
		\item Support for PHY isolation submitted
		\item Next : Port representation and multiplexing
		\item PSE integration, with Köry Maincent
	\end{itemize}
\end{frame}

\questionslide

\end{document}
