Debian Codegraph @

drivers/net/ethernet/stmicro/stmmac/stmmac_pcs.c

raw
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include "stmmac.h"
3 #include "stmmac_pcs.h"
4
5 /*
6 * GMAC_AN_STATUS is equivalent to MII_BMSR
7 * GMAC_ANE_ADV is equivalent to 802.3z MII_ADVERTISE
8 * GMAC_ANE_LPA is equivalent to 802.3z MII_LPA
9 * GMAC_ANE_EXP is equivalent to MII_EXPANSION
10 * GMAC_TBI is equivalent to MII_ESTATUS
11 *
12 * ADV, LPA and EXP are only available for the TBI and RTBI modes.
13 */
14 #define GMAC_AN_STATUS 0x04 /* AN status */
15 #define GMAC_ANE_ADV 0x08 /* ANE Advertisement */
16 #define GMAC_ANE_LPA 0x0c /* ANE link partener ability */
17 #define GMAC_TBI 0x14 /* TBI extend status */
18
19 static int dwmac_integrated_pcs_enable(struct phylink_pcs *pcs)
20 {
21 struct stmmac_pcs *spcs = phylink_pcs_to_stmmac_pcs(pcs);
22
23 stmmac_mac_irq_modify(spcs->priv, 0, spcs->int_mask);
24
25 return 0;
26 }
27
28 static void dwmac_integrated_pcs_disable(struct phylink_pcs *pcs)
29 {
30 struct stmmac_pcs *spcs = phylink_pcs_to_stmmac_pcs(pcs);
31
32 stmmac_mac_irq_modify(spcs->priv, spcs->int_mask, 0);
33 }
34
35 static void dwmac_integrated_pcs_get_state(struct phylink_pcs *pcs,
36 unsigned int neg_mode,
37 struct phylink_link_state *state)
38 {
39 state->link = false;
40 }
41
42 static int dwmac_integrated_pcs_config(struct phylink_pcs *pcs,
43 unsigned int neg_mode,
44 phy_interface_t interface,
45 const unsigned long *advertising,
46 bool permit_pause_to_mac)
47 {
48 struct stmmac_pcs *spcs = phylink_pcs_to_stmmac_pcs(pcs);
49
50 dwmac_ctrl_ane(spcs->base, 0, 1, spcs->priv->hw->reverse_sgmii_enable);
51
52 return 0;
53 }
54
55 static const struct phylink_pcs_ops dwmac_integrated_pcs_ops = {
56 .pcs_enable = dwmac_integrated_pcs_enable,
57 .pcs_disable = dwmac_integrated_pcs_disable,
58 .pcs_get_state = dwmac_integrated_pcs_get_state,
59 .pcs_config = dwmac_integrated_pcs_config,
60 };
61
62 void stmmac_integrated_pcs_irq(struct stmmac_priv *priv, u32 status,
63 struct stmmac_extra_stats *x)
64 {
65 struct stmmac_pcs *spcs = priv->integrated_pcs;
66 u32 val = readl(spcs->base + GMAC_AN_STATUS);
67
68 if (status & PCS_ANE_IRQ) {
69 x->irq_pcs_ane_n++;
70 if (val & BMSR_ANEGCOMPLETE)
71 dev_info(priv->device,
72 "PCS ANE process completed\n");
73 }
74
75 if (status & PCS_LINK_IRQ) {
76 x->irq_pcs_link_n++;
77 dev_info(priv->device, "PCS Link %s\n",
78 val & BMSR_LSTATUS ? "Up" : "Down");
79
80 phylink_pcs_change(&spcs->pcs, val & BMSR_LSTATUS);
81 }
82 }
83
84 int stmmac_integrated_pcs_get_phy_intf_sel(struct phylink_pcs *pcs,
85 phy_interface_t interface)
86 {
87 if (interface == PHY_INTERFACE_MODE_SGMII)
88 return PHY_INTF_SEL_SGMII;
89
90 return -EINVAL;
91 }
92
93 int stmmac_integrated_pcs_init(struct stmmac_priv *priv, unsigned int offset,
94 u32 int_mask)
95 {
96 struct stmmac_pcs *spcs;
97
98 spcs = devm_kzalloc(priv->device, sizeof(*spcs), GFP_KERNEL);
99 if (!spcs)
100 return -ENOMEM;
101
102 spcs->priv = priv;
103 spcs->base = priv->ioaddr + offset;
104 spcs->int_mask = int_mask;
105 spcs->pcs.ops = &dwmac_integrated_pcs_ops;
106
107 __set_bit(PHY_INTERFACE_MODE_SGMII, spcs->pcs.supported_interfaces);
108
109 priv->integrated_pcs = spcs;
110
111 return 0;
112 }