1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * stmmac_pcs.h: Physical Coding Sublayer Header File
4 *
5 * Copyright (C) 2016 STMicroelectronics (R&D) Limited
6 * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
7 */
8
9 #ifndef __STMMAC_PCS_H__
10 #define __STMMAC_PCS_H__
11
12 #include <linux/phylink.h>
13 #include <linux/slab.h>
14 #include <linux/io.h>
15 #include "common.h"
16
17 /* PCS registers (AN/TBI/SGMII/RGMII) offsets */
18 #define GMAC_AN_CTRL(x) (x) /* AN control */
19
20 /* AN Configuration defines */
21 #define GMAC_AN_CTRL_RAN BIT_U32(9) /* Restart Auto-Negotiation */
22 #define GMAC_AN_CTRL_ANE BIT_U32(12) /* Auto-Negotiation Enable */
23 #define GMAC_AN_CTRL_ELE BIT_U32(14) /* External Loopback Enable */
24 #define GMAC_AN_CTRL_ECD BIT_U32(16) /* Enable Comma Detect */
25 #define GMAC_AN_CTRL_LR BIT_U32(17) /* Lock to Reference */
26 #define GMAC_AN_CTRL_SGMRAL BIT_U32(18) /* SGMII RAL Control */
27
28 struct stmmac_priv;
29
30 struct stmmac_pcs {
31 struct stmmac_priv *priv;
32 void __iomem *base;
33 u32 int_mask;
34 struct phylink_pcs pcs;
35 };
36
37 static inline struct stmmac_pcs *
phylink_pcs_to_stmmac_pcs(struct phylink_pcs * pcs)38 phylink_pcs_to_stmmac_pcs(struct phylink_pcs *pcs)
39 {
40 return container_of(pcs, struct stmmac_pcs, pcs);
41 }
42
43 void stmmac_integrated_pcs_irq(struct stmmac_priv *priv, u32 status,
44 struct stmmac_extra_stats *x);
45 int stmmac_integrated_pcs_get_phy_intf_sel(struct phylink_pcs *pcs,
46 phy_interface_t interface);
47 int stmmac_integrated_pcs_init(struct stmmac_priv *priv, unsigned int offset,
48 u32 int_mask);
49
50 /**
51 * dwmac_ctrl_ane - To program the AN Control Register.
52 * @ioaddr: IO registers pointer
53 * @reg: Base address of the AN Control Register.
54 * @ane: to enable the auto-negotiation
55 * @srgmi_ral: to manage MAC-2-MAC SGMII connections.
56 * Description: this is the main function to configure the AN control register
57 * and init the ANE, select loopback (usually for debugging purpose) and
58 * configure SGMII RAL.
59 */
dwmac_ctrl_ane(void __iomem * ioaddr,u32 reg,bool ane,bool srgmi_ral)60 static inline void dwmac_ctrl_ane(void __iomem *ioaddr, u32 reg, bool ane,
61 bool srgmi_ral)
62 {
63 u32 value = readl(ioaddr + GMAC_AN_CTRL(reg));
64
65 /* Enable and restart the Auto-Negotiation */
66 if (ane)
67 value |= GMAC_AN_CTRL_ANE | GMAC_AN_CTRL_RAN;
68 else
69 value &= ~GMAC_AN_CTRL_ANE;
70
71 /* In case of MAC-2-MAC connection, block is configured to operate
72 * according to MAC conf register.
73 */
74 if (srgmi_ral)
75 value |= GMAC_AN_CTRL_SGMRAL;
76
77 writel(value, ioaddr + GMAC_AN_CTRL(reg));
78 }
79 #endif /* __STMMAC_PCS_H__ */
80