1 From 523f11b5d4fd72efb72b04cd7006bfd1d1d4f341 Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
3 Date: Thu, 16 Jan 2014 10:52:14 +0000
4 Subject: [PATCH] net: stmmac: move hardware setup for stmmac_open to new
7 This patch moves hardware setup part of the code in stmmac_open to a new
8 function stmmac_hw_setup, the reason for doing this is to make hw
9 initialization independent function so that PM functions can re-use it to
10 re-initialize the IP after returning from low power state.
11 This will also avoid code duplication across stmmac_resume/restore and
14 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
15 Acked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
18 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 155 ++++++++++++----------
19 1 file changed, 88 insertions(+), 67 deletions(-)
21 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
22 index 532f2b4..341c8dc3 100644
23 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
24 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
25 @@ -1586,6 +1586,86 @@ static void stmmac_init_tx_coalesce(struct stmmac_priv *priv)
29 + * stmmac_hw_setup: setup mac in a usable state.
30 + * @dev : pointer to the device structure.
32 + * This function sets up the ip in a usable state.
34 + * 0 on success and an appropriate (-)ve integer as defined in errno.h
37 +static int stmmac_hw_setup(struct net_device *dev)
39 + struct stmmac_priv *priv = netdev_priv(dev);
42 + ret = init_dma_desc_rings(dev);
44 + pr_err("%s: DMA descriptors initialization failed\n", __func__);
47 + /* DMA initialization and SW reset */
48 + ret = stmmac_init_dma_engine(priv);
50 + pr_err("%s: DMA engine initialization failed\n", __func__);
54 + /* Copy the MAC addr into the HW */
55 + priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
57 + /* If required, perform hw setup of the bus. */
58 + if (priv->plat->bus_setup)
59 + priv->plat->bus_setup(priv->ioaddr);
61 + /* Initialize the MAC Core */
62 + priv->hw->mac->core_init(priv->ioaddr);
64 + /* Enable the MAC Rx/Tx */
65 + stmmac_set_mac(priv->ioaddr, true);
67 + /* Set the HW DMA mode and the COE */
68 + stmmac_dma_operation_mode(priv);
70 + stmmac_mmc_setup(priv);
72 + ret = stmmac_init_ptp(priv);
74 + pr_warn("%s: failed PTP initialisation\n", __func__);
76 +#ifdef CONFIG_STMMAC_DEBUG_FS
77 + ret = stmmac_init_fs(dev);
79 + pr_warn("%s: failed debugFS registration\n", __func__);
81 + /* Start the ball rolling... */
82 + pr_debug("%s: DMA RX/TX processes started...\n", dev->name);
83 + priv->hw->dma->start_tx(priv->ioaddr);
84 + priv->hw->dma->start_rx(priv->ioaddr);
86 + /* Dump DMA/MAC registers */
87 + if (netif_msg_hw(priv)) {
88 + priv->hw->mac->dump_regs(priv->ioaddr);
89 + priv->hw->dma->dump_regs(priv->ioaddr);
91 + priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS;
93 + priv->eee_enabled = stmmac_eee_init(priv);
95 + stmmac_init_tx_coalesce(priv);
97 + if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) {
98 + priv->rx_riwt = MAX_DMA_RIWT;
99 + priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT);
102 + if (priv->pcs && priv->hw->mac->ctrl_ane)
103 + priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
109 * stmmac_open - open entry point of the driver
110 * @dev : pointer to the device structure.
112 @@ -1613,6 +1693,10 @@ static int stmmac_open(struct net_device *dev)
116 + /* Extra statistics */
117 + memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
118 + priv->xstats.threshold = tc;
120 /* Create and initialize the TX/RX descriptors chains. */
121 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
122 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
123 @@ -1624,28 +1708,14 @@ static int stmmac_open(struct net_device *dev)
127 - ret = init_dma_desc_rings(dev);
128 + ret = stmmac_hw_setup(dev);
130 - pr_err("%s: DMA descriptors initialization failed\n", __func__);
131 - goto dma_desc_error;
134 - /* DMA initialization and SW reset */
135 - ret = stmmac_init_dma_engine(priv);
137 - pr_err("%s: DMA engine initialization failed\n", __func__);
138 + pr_err("%s: Hw setup failed\n", __func__);
142 - /* Copy the MAC addr into the HW */
143 - priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
145 - /* If required, perform hw setup of the bus. */
146 - if (priv->plat->bus_setup)
147 - priv->plat->bus_setup(priv->ioaddr);
149 - /* Initialize the MAC Core */
150 - priv->hw->mac->core_init(priv->ioaddr);
152 + phy_start(priv->phydev);
154 /* Request the IRQ lines */
155 ret = request_irq(dev->irq, stmmac_interrupt,
156 @@ -1678,55 +1748,6 @@ static int stmmac_open(struct net_device *dev)
160 - /* Enable the MAC Rx/Tx */
161 - stmmac_set_mac(priv->ioaddr, true);
163 - /* Set the HW DMA mode and the COE */
164 - stmmac_dma_operation_mode(priv);
166 - /* Extra statistics */
167 - memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
168 - priv->xstats.threshold = tc;
170 - stmmac_mmc_setup(priv);
172 - ret = stmmac_init_ptp(priv);
174 - pr_warn("%s: failed PTP initialisation\n", __func__);
176 -#ifdef CONFIG_STMMAC_DEBUG_FS
177 - ret = stmmac_init_fs(dev);
179 - pr_warn("%s: failed debugFS registration\n", __func__);
181 - /* Start the ball rolling... */
182 - pr_debug("%s: DMA RX/TX processes started...\n", dev->name);
183 - priv->hw->dma->start_tx(priv->ioaddr);
184 - priv->hw->dma->start_rx(priv->ioaddr);
186 - /* Dump DMA/MAC registers */
187 - if (netif_msg_hw(priv)) {
188 - priv->hw->mac->dump_regs(priv->ioaddr);
189 - priv->hw->dma->dump_regs(priv->ioaddr);
193 - phy_start(priv->phydev);
195 - priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS;
197 - priv->eee_enabled = stmmac_eee_init(priv);
199 - stmmac_init_tx_coalesce(priv);
201 - if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) {
202 - priv->rx_riwt = MAX_DMA_RIWT;
203 - priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT);
206 - if (priv->pcs && priv->hw->mac->ctrl_ane)
207 - priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
209 napi_enable(&priv->napi);
210 netif_start_queue(dev);