3030#include <linux/slab.h>
3131#include <linux/ethtool.h>
3232#include <asm/io.h>
33+ #include "stmmac_pcs.h"
3334#include "dwmac1000.h"
3435
3536static void dwmac1000_core_init (struct mac_device_info * hw , int mtu )
@@ -241,6 +242,39 @@ static void dwmac1000_pmt(struct mac_device_info *hw, unsigned long mode)
241242 writel (pmt , ioaddr + GMAC_PMT );
242243}
243244
245+ /* RGMII or SMII interface */
246+ static void dwmac1000_rgsmii (void __iomem * ioaddr , struct stmmac_extra_stats * x )
247+ {
248+ u32 status ;
249+
250+ status = readl (ioaddr + GMAC_RGSMIIIS );
251+ x -> irq_rgmii_n ++ ;
252+
253+ /* Check the link status */
254+ if (status & GMAC_RGSMIIIS_LNKSTS ) {
255+ int speed_value ;
256+
257+ x -> pcs_link = 1 ;
258+
259+ speed_value = ((status & GMAC_RGSMIIIS_SPEED ) >>
260+ GMAC_RGSMIIIS_SPEED_SHIFT );
261+ if (speed_value == GMAC_RGSMIIIS_SPEED_125 )
262+ x -> pcs_speed = SPEED_1000 ;
263+ else if (speed_value == GMAC_RGSMIIIS_SPEED_25 )
264+ x -> pcs_speed = SPEED_100 ;
265+ else
266+ x -> pcs_speed = SPEED_10 ;
267+
268+ x -> pcs_duplex = (status & GMAC_RGSMIIIS_LNKMOD_MASK );
269+
270+ pr_info ("Link is Up - %d/%s\n" , (int )x -> pcs_speed ,
271+ x -> pcs_duplex ? "Full" : "Half" );
272+ } else {
273+ x -> pcs_link = 0 ;
274+ pr_info ("Link is Down\n" );
275+ }
276+ }
277+
244278static int dwmac1000_irq_status (struct mac_device_info * hw ,
245279 struct stmmac_extra_stats * x )
246280{
@@ -260,6 +294,7 @@ static int dwmac1000_irq_status(struct mac_device_info *hw,
260294 readl (ioaddr + GMAC_PMT );
261295 x -> irq_receive_pmt_irq_n ++ ;
262296 }
297+
263298 /* MAC trx/rx EEE LPI entry/exit interrupts */
264299 if (intr_status & lpiis_irq ) {
265300 /* Clean LPI interrupt by reading the Reg 12 */
@@ -275,36 +310,10 @@ static int dwmac1000_irq_status(struct mac_device_info *hw,
275310 x -> irq_rx_path_exit_lpi_mode_n ++ ;
276311 }
277312
278- if ((intr_status & pcs_ane_irq ) || (intr_status & pcs_link_irq )) {
279- readl (ioaddr + GMAC_AN_STATUS );
280- x -> irq_pcs_ane_n ++ ;
281- }
282- if (intr_status & rgmii_irq ) {
283- u32 status = readl (ioaddr + GMAC_S_R_GMII );
284- x -> irq_rgmii_n ++ ;
285-
286- /* Save and dump the link status. */
287- if (status & GMAC_S_R_GMII_LINK ) {
288- int speed_value = (status & GMAC_S_R_GMII_SPEED ) >>
289- GMAC_S_R_GMII_SPEED_SHIFT ;
290- x -> pcs_duplex = (status & GMAC_S_R_GMII_MODE );
291-
292- if (speed_value == GMAC_S_R_GMII_SPEED_125 )
293- x -> pcs_speed = SPEED_1000 ;
294- else if (speed_value == GMAC_S_R_GMII_SPEED_25 )
295- x -> pcs_speed = SPEED_100 ;
296- else
297- x -> pcs_speed = SPEED_10 ;
298-
299- x -> pcs_link = 1 ;
300- pr_debug ("%s: Link is Up - %d/%s\n" , __func__ ,
301- (int )x -> pcs_speed ,
302- x -> pcs_duplex ? "Full" : "Half" );
303- } else {
304- x -> pcs_link = 0 ;
305- pr_debug ("%s: Link is Down\n" , __func__ );
306- }
307- }
313+ dwmac_pcs_isr (ioaddr , GMAC_PCS_BASE , intr_status , x );
314+
315+ if (intr_status & PCS_RGSMIIIS_IRQ )
316+ dwmac1000_rgsmii (ioaddr , x );
308317
309318 return ret ;
310319}
@@ -363,38 +372,20 @@ static void dwmac1000_set_eee_timer(struct mac_device_info *hw, int ls, int tw)
363372 writel (value , ioaddr + LPI_TIMER_CTRL );
364373}
365374
366- static void dwmac1000_ctrl_ane (struct mac_device_info * hw , bool restart )
375+ static void dwmac1000_ctrl_ane (void __iomem * ioaddr , bool ane , bool srgmi_ral ,
376+ bool loopback )
367377{
368- void __iomem * ioaddr = hw -> pcsr ;
369- /* auto negotiation enable and External Loopback enable */
370- u32 value = GMAC_AN_CTRL_ANE | GMAC_AN_CTRL_ELE ;
371-
372- if (restart )
373- value |= GMAC_AN_CTRL_RAN ;
374-
375- writel (value , ioaddr + GMAC_AN_CTRL );
378+ dwmac_ctrl_ane (ioaddr , GMAC_PCS_BASE , ane , srgmi_ral , loopback );
376379}
377380
378- static void dwmac1000_get_adv ( struct mac_device_info * hw , struct rgmii_adv * adv )
381+ static void dwmac1000_rane ( void __iomem * ioaddr , bool restart )
379382{
380- void __iomem * ioaddr = hw -> pcsr ;
381- u32 value = readl (ioaddr + GMAC_ANE_ADV );
382-
383- if (value & GMAC_ANE_FD )
384- adv -> duplex = DUPLEX_FULL ;
385- if (value & GMAC_ANE_HD )
386- adv -> duplex |= DUPLEX_HALF ;
387-
388- adv -> pause = (value & GMAC_ANE_PSE ) >> GMAC_ANE_PSE_SHIFT ;
389-
390- value = readl (ioaddr + GMAC_ANE_LPA );
391-
392- if (value & GMAC_ANE_FD )
393- adv -> lp_duplex = DUPLEX_FULL ;
394- if (value & GMAC_ANE_HD )
395- adv -> lp_duplex = DUPLEX_HALF ;
383+ dwmac_rane (ioaddr , GMAC_PCS_BASE , restart );
384+ }
396385
397- adv -> lp_pause = (value & GMAC_ANE_PSE ) >> GMAC_ANE_PSE_SHIFT ;
386+ static void dwmac1000_get_adv_lp (void __iomem * ioaddr , struct rgmii_adv * adv )
387+ {
388+ dwmac_get_adv_lp (ioaddr , GMAC_PCS_BASE , adv );
398389}
399390
400391static void dwmac1000_debug (void __iomem * ioaddr , struct stmmac_extra_stats * x )
@@ -485,9 +476,10 @@ static const struct stmmac_ops dwmac1000_ops = {
485476 .reset_eee_mode = dwmac1000_reset_eee_mode ,
486477 .set_eee_timer = dwmac1000_set_eee_timer ,
487478 .set_eee_pls = dwmac1000_set_eee_pls ,
488- .ctrl_ane = dwmac1000_ctrl_ane ,
489- .get_adv = dwmac1000_get_adv ,
490479 .debug = dwmac1000_debug ,
480+ .pcs_ctrl_ane = dwmac1000_ctrl_ane ,
481+ .pcs_rane = dwmac1000_rane ,
482+ .pcs_get_adv_lp = dwmac1000_get_adv_lp ,
491483};
492484
493485struct mac_device_info * dwmac1000_setup (void __iomem * ioaddr , int mcbins ,
0 commit comments