362f4bc7edcb8295ce1f404a172eb0ef2dffb6ce
[openwrt/openwrt.git] / target / linux / octeontx / patches-4.14 / 0001-net-thunderx-add-support-for-rgmii-internal-delay-mo.patch
1 From 69a99101748bb1bdb2730393ef48bc152c4d244a Mon Sep 17 00:00:00 2001
2 From: Tim Harvey <tharvey@gateworks.com>
3 Date: Tue, 12 Dec 2017 12:49:55 -0800
4 Subject: [PATCH] net: thunderx: add support for rgmii internal delay modes
5
6 The XCV_DLL_CTL is being configured with the assumption that
7 phy-mode is rgmii-txid (PHY_INTERFACE_MODE_RGMII_TXID) which is not always
8 the case.
9
10 This patch parses the phy-mode property and uses it to configure CXV_DLL_CTL
11 properly.
12
13 Signed-off-by: Tim Harvey <tharvey@gateworks.com>
14 ---
15 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 13 +++++++---
16 drivers/net/ethernet/cavium/thunder/thunder_bgx.h | 2 +-
17 drivers/net/ethernet/cavium/thunder/thunder_xcv.c | 31 ++++++++++++++++++-----
18 3 files changed, 35 insertions(+), 11 deletions(-)
19
20 diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
21 index 5e5c4d7..805c02a 100644
22 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
23 +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
24 @@ -55,6 +55,7 @@ struct bgx {
25 struct pci_dev *pdev;
26 bool is_dlm;
27 bool is_rgx;
28 + int phy_mode;
29 };
30
31 static struct bgx *bgx_vnic[MAX_BGX_THUNDER];
32 @@ -841,12 +842,12 @@ static void bgx_poll_for_link(struct work_struct *work)
33 queue_delayed_work(lmac->check_link, &lmac->dwork, HZ * 2);
34 }
35
36 -static int phy_interface_mode(u8 lmac_type)
37 +static int phy_interface_mode(struct bgx *bgx, u8 lmac_type)
38 {
39 if (lmac_type == BGX_MODE_QSGMII)
40 return PHY_INTERFACE_MODE_QSGMII;
41 if (lmac_type == BGX_MODE_RGMII)
42 - return PHY_INTERFACE_MODE_RGMII;
43 + return bgx->phy_mode;
44
45 return PHY_INTERFACE_MODE_SGMII;
46 }
47 @@ -912,7 +913,8 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
48
49 if (phy_connect_direct(&lmac->netdev, lmac->phydev,
50 bgx_lmac_handler,
51 - phy_interface_mode(lmac->lmac_type)))
52 + phy_interface_mode(bgx,
53 + lmac->lmac_type)))
54 return -ENODEV;
55
56 phy_start_aneg(lmac->phydev);
57 @@ -1287,6 +1289,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
58 bgx->lmac[lmac].lmacid = lmac;
59
60 phy_np = of_parse_phandle(node, "phy-handle", 0);
61 + if (phy_np)
62 + bgx->phy_mode = of_get_phy_mode(phy_np);
63 /* If there is no phy or defective firmware presents
64 * this cortina phy, for which there is no driver
65 * support, ignore it.
66 @@ -1390,7 +1394,6 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
67 bgx->max_lmac = 1;
68 bgx->bgx_id = MAX_BGX_PER_CN81XX - 1;
69 bgx_vnic[bgx->bgx_id] = bgx;
70 - xcv_init_hw();
71 }
72
73 /* On 81xx all are DLMs and on 83xx there are 3 BGX QLMs and one
74 @@ -1407,6 +1410,8 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
75 if (err)
76 goto err_enable;
77
78 + if (bgx->is_rgx)
79 + xcv_init_hw(bgx->phy_mode);
80 bgx_init_hw(bgx);
81
82 /* Enable all LMACs */
83 diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
84 index 23acdc5..2bba9d1 100644
85 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
86 +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
87 @@ -226,7 +226,7 @@ void bgx_lmac_internal_loopback(int node, int bgx_idx,
88 void bgx_lmac_get_pfc(int node, int bgx_idx, int lmacid, void *pause);
89 void bgx_lmac_set_pfc(int node, int bgx_idx, int lmacid, void *pause);
90
91 -void xcv_init_hw(void);
92 +void xcv_init_hw(int phy_mode);
93 void xcv_setup_link(bool link_up, int link_speed);
94
95 u64 bgx_get_rx_stats(int node, int bgx_idx, int lmac, int idx);
96 diff --git a/drivers/net/ethernet/cavium/thunder/thunder_xcv.c b/drivers/net/ethernet/cavium/thunder/thunder_xcv.c
97 index 578c7f8..7e0c4cb 100644
98 --- a/drivers/net/ethernet/cavium/thunder/thunder_xcv.c
99 +++ b/drivers/net/ethernet/cavium/thunder/thunder_xcv.c
100 @@ -65,7 +65,7 @@ MODULE_LICENSE("GPL v2");
101 MODULE_VERSION(DRV_VERSION);
102 MODULE_DEVICE_TABLE(pci, xcv_id_table);
103
104 -void xcv_init_hw(void)
105 +void xcv_init_hw(int phy_mode)
106 {
107 u64 cfg;
108
109 @@ -81,12 +81,31 @@ void xcv_init_hw(void)
110 /* Wait for DLL to lock */
111 msleep(1);
112
113 - /* Configure DLL - enable or bypass
114 - * TX no bypass, RX bypass
115 - */
116 + /* enable/bypass DLL providing MAC based internal TX/RX delays */
117 cfg = readq_relaxed(xcv->reg_base + XCV_DLL_CTL);
118 - cfg &= ~0xFF03;
119 - cfg |= CLKRX_BYP;
120 + cfg &= ~0xffff00;
121 + switch (phy_mode) {
122 + /* RX and TX delays are added by the MAC */
123 + case PHY_INTERFACE_MODE_RGMII:
124 + break;
125 + /* internal RX and TX delays provided by the PHY */
126 + case PHY_INTERFACE_MODE_RGMII_ID:
127 + cfg |= CLKRX_BYP;
128 + cfg |= CLKTX_BYP;
129 + break;
130 + /* internal RX delay provided by the PHY, the MAC
131 + * should not add an RX delay in this case
132 + */
133 + case PHY_INTERFACE_MODE_RGMII_RXID:
134 + cfg |= CLKRX_BYP;
135 + break;
136 + /* internal TX delay provided by the PHY, the MAC
137 + * should not add an TX delay in this case
138 + */
139 + case PHY_INTERFACE_MODE_RGMII_TXID:
140 + cfg |= CLKRX_BYP;
141 + break;
142 + }
143 writeq_relaxed(cfg, xcv->reg_base + XCV_DLL_CTL);
144
145 /* Enable compensation controller and force the
146 --
147 2.7.4
148