1 // SPDX-License-Identifier: GPL-2.0+
3 Copyright (c) 2013 Broadcom Corporation
11 /******************************************************************************/
13 /* File Description: */
15 /* This file contains the implementation of the HwApiMac for unimac */
17 /******************************************************************************/
21 /*****************************************************************************/
25 /*****************************************************************************/
26 #include "unimac_drv.h"
27 #if defined(__UBOOT__) && !defined(CONFIG_BCM6856) && !defined(CONFIG_BCM6878)
28 static void get_rdp_freq(uint32_t *rdp_freq
) { }
33 #if defined(CONFIG_BCM63138) || defined(CONFIG_BCM63148)
34 #include "rdp_drv_bbh.h"
37 /******************************************************************************/
39 /* Types and values definitions */
41 /******************************************************************************/
42 #define UNIMAC_SWRESET_ON 1
43 #define UNIMAC_SWRESET_OFF 0
44 #define UNIMAC_DEFAULT_IPG 12
45 #define UNIMAC_DEFAULT_PAUSE_QUANTA 0xffff
46 #define UNIMAC_DEFAULT_PAUSE_TIMER 0x1ffff
47 #define UNIMAC_MAX_FRAME_LENGHT 0xffff
50 #define mac_unlikely(a) a
52 #define mac_unlikely(a) unlikely(a)
55 #define UNIMAC_NUMBER_OF_SPEEDS ( UNIMAC_SPEED_2500 + 1 )
56 #define UNIMAC_NUMBER_OF_DUPLEXES ( UNIMAC_DUPLEX_FULL + 1 )
58 static uint32_t ipgSpeedTable
[UNIMAC_NUMBER_OF_SPEEDS
][UNIMAC_NUMBER_OF_DUPLEXES
] =
66 static uint32_t enabled_emac
;
68 #if defined(CONFIG_BCM4908)
69 #include "bcm_map_part.h"
70 uint8_t *soc_base_address
; // used by DEVICE_ADDRESS()
73 /******************************************************************************/
77 /* mac_hwapi_get_configuration */
81 /* MAC Driver - get configuration */
85 /* get the configuratin of a mac port ,note that current status of emac */
86 /* might be different than configuration when working in autoneg */
87 /* to get the current status use mac_hwapi_get_mac_status API */
91 /* emacNum - emac Port index */
95 /* emac_cfg - structure holds the current configuration of the mac port */
97 /******************************************************************************/
98 void mac_hwapi_get_configuration(rdpa_emac emacNum
,rdpa_emac_cfg_t
*emac_cfg
)
100 S_UNIMAC_CMD_REG mCfgReg
;
102 if (!(enabled_emac
& (1 << emacNum
)))
105 UNIMAC_READ32_REG(emacNum
,CMD
,mCfgReg
);
106 emac_cfg
->allow_too_long
= 0;//no such
107 emac_cfg
->back2back_gap
= 0;//no such
108 emac_cfg
->check_length
= !mCfgReg
.no_lgth_check
;
109 emac_cfg
->full_duplex
= !mCfgReg
.hd_ena
;
110 emac_cfg
->generate_crc
= 0;
111 emac_cfg
->loopback
= mCfgReg
.rmt_loop_ena
;
112 emac_cfg
->non_back2back_gap
= 0;//no such
113 emac_cfg
->pad_short
= 0;//no such
114 emac_cfg
->rate
= mCfgReg
.eth_speed
;
115 emac_cfg
->rx_flow_control
= !mCfgReg
.rx_pause_ignore
;
116 emac_cfg
->tx_flow_control
= !mCfgReg
.tx_pause_ignore
;
118 UNIMAC_READ_FIELD(emacNum
,HD_BKP_CNTL
,ipg_config_rx
,emac_cfg
->min_interframe_gap
);
119 UNIMAC_READ_FIELD(emacNum
,TX_IPG_LEN
,tx_ipg_len
,emac_cfg
->preamble_length
);
121 EXPORT_SYMBOL(mac_hwapi_get_configuration
);
122 /******************************************************************************/
126 /* mac_hwapi_set_configuration */
130 /* MAC Driver - set configuration */
134 /* set the configuratin of a mac port */
137 /* emacNum - emac Port index */
138 /* emac_cfg - structure holds the current configuration of the mac port */
143 /******************************************************************************/
144 void mac_hwapi_set_configuration(rdpa_emac emacNum
,rdpa_emac_cfg_t
*emac_cfg
)
146 S_UNIMAC_CMD_REG mCfgReg
;
148 if (!(enabled_emac
& (1 << emacNum
)))
151 /*first put the mac in reset to enable config change*/
152 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,1);
155 UNIMAC_READ32_REG(emacNum
,CMD
,mCfgReg
);
157 /*now mac configuration can be changed */
158 if(!mCfgReg
.ena_ext_config
) /* Change only if auto_config is not set */
160 mCfgReg
.eth_speed
= emac_cfg
->rate
;
161 mCfgReg
.hd_ena
= !emac_cfg
->full_duplex
;
162 mCfgReg
.rx_pause_ignore
= !emac_cfg
->rx_flow_control
;
163 mCfgReg
.tx_pause_ignore
= !emac_cfg
->tx_flow_control
;
164 /*set the interframe gap*/
165 UNIMAC_WRITE_FIELD(emacNum
,HD_BKP_CNTL
,ipg_config_rx
,ipgSpeedTable
[emac_cfg
->rate
][(unsigned)emac_cfg
->full_duplex
]);
169 /*set the interframe gap*/
170 UNIMAC_WRITE_FIELD(emacNum
,HD_BKP_CNTL
,ipg_config_rx
,emac_cfg
->min_interframe_gap
);
173 mCfgReg
.no_lgth_check
= !emac_cfg
->check_length
;
174 mCfgReg
.pad_en
= emac_cfg
->pad_short
;
175 mCfgReg
.rmt_loop_ena
= emac_cfg
->loopback
;
178 UNIMAC_WRITE32_REG(emacNum
,CMD
,mCfgReg
);
181 /* set the preamble length */
182 UNIMAC_WRITE_FIELD(emacNum
,TX_IPG_LEN
,tx_ipg_len
,emac_cfg
->preamble_length
);
184 /* when link up at 10M, hold unimac reset longer per ASIC team */
185 if (emac_cfg
->rate
== rdpa_emac_rate_10m
)
188 /*release the sw_reset bit*/
189 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,0);
191 EXPORT_SYMBOL(mac_hwapi_set_configuration
);
193 /******************************************************************************/
197 /* mac_hwapi_get_duplex */
201 /* MAC Driver - get port duplex */
205 /* get the dulplex of a port */
209 /* emacNum - emac Port index */
213 /* full_duples : 1 = full dulplex,0 = half_duplex */
215 /******************************************************************************/
216 void mac_hwapi_get_duplex(rdpa_emac emacNum
,int32_t *full_duplex
)
218 /*read field and reverse polarity*/
221 if (!(enabled_emac
& (1 << emacNum
)))
224 UNIMAC_READ_FIELD(emacNum
,CMD
,hd_ena
,fieldData
);
225 *full_duplex
= !fieldData
;
227 EXPORT_SYMBOL(mac_hwapi_get_duplex
);
229 /******************************************************************************/
233 /* mac_hwapi_set_duplex */
237 /* MAC Driver - set port duplex */
241 /* set the dulplex of a port */
245 /* emacNum - emac Port index */
249 /* full_duples : 1 = full dulplex,0 = half_duplex */
251 /******************************************************************************/
252 void mac_hwapi_set_duplex(rdpa_emac emacNum
,int32_t full_duplex
)
254 S_UNIMAC_CMD_REG mCfgReg
;
256 if (!(enabled_emac
& (1 << emacNum
)))
259 UNIMAC_READ32_REG(emacNum
,CMD
,mCfgReg
);
260 if (!mCfgReg
.ena_ext_config
) /* Change only if auto_config is not set */
262 /*write the dulplex field in reverse polarity,must be set in sw_reset state*/
263 S_HWAPI_MAC_STATUS macMode
;
265 UNIMAC_READ32_REG(emacNum
,MODE
,macMode
);
267 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
269 UNIMAC_WRITE_FIELD(emacNum
,CMD
,hd_ena
,full_duplex
? 0 : 1);
271 /*when setting the duplex we have to set new IPG value*/
272 //UNIMAC_WRITE_FIELD(emacNum,TX_IPG_LEN ,tx_ipg_len,ipgSpeedTable[macMode.mac_speed][macMode.mac_duplex]);
274 /*take the mac out of sw_reset*/
275 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
278 EXPORT_SYMBOL(mac_hwapi_set_duplex
);
283 /******************************************************************************/
287 /* mac_hwapi_get_speed */
291 /* MAC Driver - get port speed rate */
295 /* get the speed of a port */
299 /* emacNum - emac Port index */
303 /* rate - enum of the speed */
304 /******************************************************************************/
305 void mac_hwapi_get_speed(rdpa_emac emacNum
,rdpa_emac_rate
*rate
)
307 if (!(enabled_emac
& (1 << emacNum
)))
310 /*read the speed field*/
311 UNIMAC_READ_FIELD(emacNum
,CMD
,eth_speed
,*rate
);
313 EXPORT_SYMBOL(mac_hwapi_get_speed
);
318 /******************************************************************************/
322 /* mac_hwapi_set_speed */
326 /* MAC Driver - set port speed rate */
330 /* set the speed of a port */
334 /* emacNum - emac Port index */
335 /* rate - enum of the speed */
339 /******************************************************************************/
341 void mac_hwapi_set_speed(rdpa_emac emacNum
,rdpa_emac_rate rate
)
343 S_UNIMAC_CMD_REG mCfgReg
;
345 if (!(enabled_emac
& (1 << emacNum
)))
348 UNIMAC_READ32_REG(emacNum
,CMD
,mCfgReg
);
349 if (!mCfgReg
.ena_ext_config
) /* Change only if auto_config is not set */
351 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
353 UNIMAC_WRITE_FIELD(emacNum
,CMD
,eth_speed
,rate
);
356 UNIMAC_WRITE_FIELD(emacNum
,HD_BKP_CNTL
,ipg_config_rx
,ipgSpeedTable
[rate
][0]);
359 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
362 EXPORT_SYMBOL(mac_hwapi_set_speed
);
364 void mac_hwapi_set_external_conf(rdpa_emac emacNum
, int enable
)
366 S_UNIMAC_CMD_REG mCfgReg
;
368 if (!(enabled_emac
& (1 << emacNum
)))
371 UNIMAC_READ32_REG(emacNum
,CMD
,mCfgReg
);
372 mCfgReg
.ena_ext_config
= enable
;
373 UNIMAC_WRITE32_REG(emacNum
,CMD
,mCfgReg
);
375 EXPORT_SYMBOL(mac_hwapi_set_external_conf
);
377 /******************************************************************************/
381 /* mac_hwapi_get_rxtx_enable */
385 /* MAC Driver - set tx and rx enable */
389 /* get tx and rx enable */
393 /* emacNum - emac Port index */
397 /* rxtxEnable - boolean enable */
398 /******************************************************************************/
399 void mac_hwapi_get_rxtx_enable(rdpa_emac emacNum
,int32_t *rxEnable
,int32_t *txEnable
)
401 if (!(enabled_emac
& (1 << emacNum
)))
404 UNIMAC_READ_FIELD(emacNum
,CMD
,tx_ena
,*txEnable
);
405 UNIMAC_READ_FIELD(emacNum
,CMD
,rx_ena
,*rxEnable
);
407 EXPORT_SYMBOL(mac_hwapi_get_rxtx_enable
);
413 /******************************************************************************/
417 /* mac_hwapi_set_rxtx_enable */
421 /* MAC Driver - set tx and rx enable */
425 /* set tx and rx enable */
429 /* emacNum - emac Port index */
430 /* rxtxEnable - boolean enable */
434 /******************************************************************************/
435 void mac_hwapi_set_rxtx_enable(rdpa_emac emacNum
,int32_t rxEnable
,int32_t txEnable
)
437 if (!(enabled_emac
& (1 << emacNum
)))
440 UNIMAC_WRITE_FIELD(emacNum
,CMD
,tx_ena
,txEnable
);
441 UNIMAC_WRITE_FIELD(emacNum
,CMD
,rx_ena
,rxEnable
);
443 EXPORT_SYMBOL(mac_hwapi_set_rxtx_enable
);
448 /******************************************************************************/
452 /* mac_hwapi_get_sw_reset */
456 /* MAC Driver - get port software reset */
460 /* get the sw reset bit of emac port */
464 /* emacNum - emac Port index */
468 /* swReset : 1 = reset,0 = not reset */
470 /******************************************************************************/
471 void mac_hwapi_get_sw_reset(rdpa_emac emacNum
,int32_t *swReset
)
473 if (!(enabled_emac
& (1 << emacNum
)))
476 UNIMAC_READ_FIELD(emacNum
,CMD
,sw_reset
,*swReset
);
478 EXPORT_SYMBOL(mac_hwapi_get_sw_reset
);
483 /******************************************************************************/
487 /* mac_hwapi_set_sw_reset */
491 /* MAC Driver - set port software reset */
495 /* set the sw reset bit of emac port */
499 /* emacNum - emac Port index */
500 /* swReset : 1 = reset,0 = not reset */
505 /******************************************************************************/
506 void mac_hwapi_set_sw_reset(rdpa_emac emacNum
,int32_t swReset
)
508 if (!(enabled_emac
& (1 << emacNum
)))
511 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,swReset
);
513 EXPORT_SYMBOL(mac_hwapi_set_sw_reset
);
516 /******************************************************************************/
520 /* mac_hwapi_get_tx_min_pkt_size */
524 /* MAC Driver - get tx minimum packet size */
528 /* Get the unimac configuration for minimum tx packet size */
532 /* emacNum - emac Port index */
536 /* min_pkt_size : 14...125 */
538 /******************************************************************************/
539 void mac_hwapi_get_tx_min_pkt_size(rdpa_emac emacNum
,int32_t *min_pkt_size
)
541 if (!(enabled_emac
& (1 << emacNum
)))
544 UNIMAC_READ_FIELD(emacNum
,TX_IPG_LEN
,tx_min_pkt_size
,*min_pkt_size
);
546 EXPORT_SYMBOL(mac_hwapi_get_tx_min_pkt_size
);
551 /******************************************************************************/
555 /* mac_hwapi_set_tx_min_pkt_size */
559 /* MAC Driver - set tx minimum packet size */
563 /* Set the unimac configuration for minimum tx packet size */
567 /* emacNum - emac Port index */
568 /* min_pkt_size : 14...125 */
573 /******************************************************************************/
574 void mac_hwapi_set_tx_min_pkt_size(rdpa_emac emacNum
,int32_t min_pkt_size
)
576 if (!(enabled_emac
& (1 << emacNum
)))
579 #if defined(CONFIG_BCM4908) || defined(CONFIG_BCM63158) || defined(CONFIG_BCM47622)
580 UNIMAC_WRITE_FIELD(emacNum
,TX_IPG_LEN
,tx_min_pkt_size
,min_pkt_size
);
583 EXPORT_SYMBOL(mac_hwapi_set_tx_min_pkt_size
);
586 /******************************************************************************/
590 /* mac_hwapi_get_tx_max_frame_len */
594 /* MAC Driver - get port TX MTU */
598 /* get the port maximum transmit unit size in bytes */
602 /* emacNum - emac Port index */
606 /* maxTxFrameLen - size of frame in bytes */
608 /******************************************************************************/
609 #if defined(CONFIG_BCM47622)
610 void mac_hwapi_get_tx_max_frame_len(rdpa_emac emacNum
,uint32_t *maxTxFrameLen
)
612 S_UNIMAC_TOPCTRL_MAX_PKT_SZ_REG cfgreg
;
613 uintptr_t address
= (uintptr_t)UNIMAC_TOPCTRL_MIB_MAX_PKT_SIZE
+ UNIMAC_TOPCTRL_INSTANCE_OFFSET(emacNum
);
615 if (!(enabled_emac
& (1 << emacNum
)))
618 READ_32(address
,cfgreg
);
620 *maxTxFrameLen
= cfgreg
.max_pkt_size
;
623 void mac_hwapi_get_tx_max_frame_len(rdpa_emac emacNum
,uint32_t *maxTxFrameLen
)
625 S_UNIMAC_TOP_CFG1_REG cfgreg
;
626 uintptr_t address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG1
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
628 if (!(enabled_emac
& (1 << emacNum
)))
631 READ_32(address
,cfgreg
);
633 *maxTxFrameLen
= cfgreg
.max_pkt_size
;
636 EXPORT_SYMBOL(mac_hwapi_get_tx_max_frame_len
);
641 /******************************************************************************/
645 /* mac_hwapi_set_tx_max_frame_len */
649 /* MAC Driver - set port TX MTU */
653 /* set the port maximum transmit unit size in bytes */
657 /* emacNum - emac Port index */
658 /* maxTxFrameLen - size of frame in bytes */
663 /******************************************************************************/
664 #if defined(CONFIG_BCM47622)
665 void mac_hwapi_set_tx_max_frame_len(rdpa_emac emacNum
,uint32_t maxTxFrameLen
)
668 S_UNIMAC_TOPCTRL_MAX_PKT_SZ_REG cfgreg
;
669 uintptr_t address
= (uintptr_t)UNIMAC_TOPCTRL_MIB_MAX_PKT_SIZE
+ UNIMAC_TOPCTRL_INSTANCE_OFFSET(emacNum
);
671 if (!(enabled_emac
& (1 << emacNum
)))
674 /*put emac in sw reset state*/
675 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
677 READ_32(address
,cfgreg
);
678 cfgreg
.max_pkt_size
= maxTxFrameLen
;
679 WRITE_32(address
,cfgreg
);
681 UNIMAC_WRITE_FIELD(emacNum
,FRM_LEN
,frame_length
,UNIMAC_MAX_FRAME_LENGHT
);
683 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
686 void mac_hwapi_set_tx_max_frame_len(rdpa_emac emacNum
,uint32_t maxTxFrameLen
)
689 S_UNIMAC_TOP_CFG1_REG cfgreg
;
690 uintptr_t address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG1
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
692 if (!(enabled_emac
& (1 << emacNum
)))
695 /*put emac in sw reset state*/
696 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
698 READ_32(address
,cfgreg
);
699 cfgreg
.max_pkt_size
= maxTxFrameLen
;
700 WRITE_32(address
,cfgreg
);
702 UNIMAC_WRITE_FIELD(emacNum
,FRM_LEN
,frame_length
,UNIMAC_MAX_FRAME_LENGHT
);
704 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
707 EXPORT_SYMBOL(mac_hwapi_set_tx_max_frame_len
);
711 /******************************************************************************/
715 /* mac_hwapi_get_rx_max_frame_len */
719 /* MAC Driver - get port RX MTU */
723 /* get the port maximum receive unit size in bytes */
727 /* emacNum - emac Port index */
731 /* maxRxFrameLen - size of current MRU */
733 /******************************************************************************/
734 #if defined(CONFIG_BCM47622)
735 void mac_hwapi_get_rx_max_frame_len(rdpa_emac emacNum
,uint32_t *maxRxFrameLen
)
737 if (!(enabled_emac
& (1 << emacNum
)))
740 UNIMAC_READ_FIELD(emacNum
,FRM_LEN
,frame_length
,*maxRxFrameLen
);
743 void mac_hwapi_get_rx_max_frame_len(rdpa_emac emacNum
,uint32_t *maxRxFrameLen
)
745 if (!(enabled_emac
& (1 << emacNum
)))
748 UNIMAC_READ_FIELD(emacNum
,RX_MAX_PKT_SIZE
,max_pkt_size
,*maxRxFrameLen
);
751 EXPORT_SYMBOL(mac_hwapi_get_rx_max_frame_len
);
755 /******************************************************************************/
759 /* mac_hwapi_set_rx_max_frame_len */
763 /* MAC Driver - set port RX MTU */
767 /* set the port maximum receive unit size in bytes */
771 /* emacNum - emac Port index */
772 /* maxRxFrameLen - size of current MRU */
777 /******************************************************************************/
778 #if defined(CONFIG_BCM47622)
779 void mac_hwapi_set_rx_max_frame_len(rdpa_emac emacNum
,uint32_t maxRxFrameLen
)
781 S_UNIMAC_TOPCTRL_MAX_PKT_SZ_REG cfgreg
;
782 uintptr_t address
= (uintptr_t)UNIMAC_TOPCTRL_MIB_MAX_PKT_SIZE
+ UNIMAC_TOPCTRL_INSTANCE_OFFSET(emacNum
);
784 if (!(enabled_emac
& (1 << emacNum
)))
787 /*put emac in sw reset state*/
788 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
790 READ_32(address
,cfgreg
);
791 cfgreg
.max_pkt_size
= maxRxFrameLen
;
792 WRITE_32(address
,cfgreg
);
794 UNIMAC_WRITE_FIELD(emacNum
,FRM_LEN
,frame_length
,maxRxFrameLen
);
796 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
799 void mac_hwapi_set_rx_max_frame_len(rdpa_emac emacNum
,uint32_t maxRxFrameLen
)
801 S_UNIMAC_TOP_CFG1_REG cfgreg
;
802 uintptr_t address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG1
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
804 if (!(enabled_emac
& (1 << emacNum
)))
807 /*put emac in sw reset state*/
808 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
810 READ_32(address
,cfgreg
);
811 cfgreg
.max_pkt_size
= maxRxFrameLen
;
812 WRITE_32(address
,cfgreg
);
814 UNIMAC_WRITE_FIELD(emacNum
,RX_MAX_PKT_SIZE
,max_pkt_size
,maxRxFrameLen
);
816 /*put emac out sw reset state*/
817 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
820 EXPORT_SYMBOL(mac_hwapi_set_rx_max_frame_len
);
824 /******************************************************************************/
828 /* mac_hwapi_set_tx_igp_len */
832 /* MAC Driver - set port inter frame gap */
836 /* set the inter frame gap size in bytes */
840 /* emacNum - emac Port index */
841 /* txIpgLen - length in bytes */
846 /******************************************************************************/
847 void mac_hwapi_set_tx_igp_len(rdpa_emac emacNum
,uint32_t txIpgLen
)
849 /*we assume that txIpgLen called with bits time resolution*/
852 if (!(enabled_emac
& (1 << emacNum
)))
855 /*put emac in sw reset state*/
856 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
859 newIpg
= txIpgLen
/ 8;
864 } else if (newIpg
> 27)
868 UNIMAC_WRITE_FIELD(emacNum
,TX_IPG_LEN
,tx_ipg_len
,newIpg
);
870 /*put emac out sw reset state*/
871 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
874 EXPORT_SYMBOL(mac_hwapi_set_tx_igp_len
);
878 /******************************************************************************/
882 /* mac_hwapi_get_tx_igp_len */
886 /* MAC Driver - get port inter frame gap */
890 /* get the inter frame gap size in bytes */
894 /* emacNum - emac Port index */
898 /* txIpgLen - length in bytes */
900 /******************************************************************************/
901 void mac_hwapi_get_tx_igp_len(rdpa_emac emacNum
,uint32_t *txIpgLen
)
903 if (!(enabled_emac
& (1 << emacNum
)))
906 UNIMAC_READ_FIELD(emacNum
,TX_IPG_LEN
,tx_ipg_len
,*txIpgLen
);
909 EXPORT_SYMBOL(mac_hwapi_get_tx_igp_len
);
914 /******************************************************************************/
918 /* mac_hwapi_get_mac_status */
922 /* MAC Driver - set port status */
926 /* set the status of mac */
930 /* emacNum - emac Port index */
936 /******************************************************************************/
937 void mac_hwapi_get_mac_status(rdpa_emac emacNum
,S_HWAPI_MAC_STATUS
*macStatus
)
941 EXPORT_SYMBOL(mac_hwapi_get_mac_status
);
947 /******************************************************************************/
951 /* mac_hwapi_get_flow_control */
955 /* MAC Driver - get port flow control */
959 /* get the flow control of a port */
963 /* emacNum - emac Port index */
967 /* flowControl - structure with parameters of tx and rx flow control */
969 /******************************************************************************/
970 #if defined(CONFIG_BCM47622)
971 void mac_hwapi_get_flow_control(rdpa_emac emacNum
,S_MAC_HWAPI_FLOW_CTRL
*flowControl
)
973 uint32_t rxFlow
, txFlow
;
975 if (!(enabled_emac
& (1 << emacNum
)))
978 UNIMAC_READ_FIELD(emacNum
,CMD
,rx_pause_ignore
,rxFlow
);
979 UNIMAC_READ_FIELD(emacNum
,CMD
,tx_pause_ignore
,txFlow
);
980 flowControl
->rxFlowEnable
= !rxFlow
;
981 flowControl
->txFlowEnable
= !txFlow
;
984 void mac_hwapi_get_flow_control(rdpa_emac emacNum
,S_MAC_HWAPI_FLOW_CTRL
*flowControl
)
986 uint32_t rxFlow
, txFlow
, value
;
987 uintptr_t misc_top_address
;
989 if (!(enabled_emac
& (1 << emacNum
)))
992 misc_top_address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG2
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
993 READ_32(misc_top_address
, value
);
996 if(value
& UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG2_BACKPRESSURE_ENABLE_INT
)
998 UNIMAC_READ_FIELD(emacNum
,CMD
,rx_pause_ignore
,rxFlow
);
999 UNIMAC_READ_FIELD(emacNum
,CMD
,tx_pause_ignore
,txFlow
);
1000 flowControl
->rxFlowEnable
= !rxFlow
;
1001 flowControl
->txFlowEnable
= !txFlow
;
1005 flowControl
->rxFlowEnable
= 0;
1006 flowControl
->txFlowEnable
= 0;
1010 EXPORT_SYMBOL(mac_hwapi_get_flow_control
);
1011 /******************************************************************************/
1015 /* mac_hwapi_set_pause_params */
1019 /* MAC Driver - set port flow control */
1023 /* set the flow control of a port */
1027 /* emacNum - emac Port index */
1028 /* flowControl - structure with parameters of tx and rx flow control */
1033 /******************************************************************************/
1034 void mac_hwapi_set_pause_params(rdpa_emac emacNum
,int32_t pauseCtrlEnable
,uint32_t pauseTimer
,uint32_t pauseQuanta
)
1036 if (!(enabled_emac
& (1 << emacNum
)))
1039 UNIMAC_WRITE_FIELD(emacNum
,PAUSE_CNTRL
,pause_control_en
,pauseCtrlEnable
);
1040 UNIMAC_WRITE_FIELD(emacNum
,PAUSE_CNTRL
,pause_timer
,pauseTimer
);
1041 UNIMAC_WRITE_FIELD(emacNum
,PAUSE_QUNAT
,pause_quant
,pauseQuanta
);
1043 EXPORT_SYMBOL(mac_hwapi_set_pause_params
);
1046 /******************************************************************************/
1050 /* mac_hwapi_set_flow_control */
1054 /* MAC Driver - set port flow control */
1058 /* set the flow control of a port */
1062 /* emacNum - emac Port index */
1063 /* flowControl - structure with parameters of tx and rx flow control */
1068 /******************************************************************************/
1069 #if defined(CONFIG_BCM47622)
1070 void mac_hwapi_set_flow_control(rdpa_emac emacNum
,S_MAC_HWAPI_FLOW_CTRL
*flowControl
)
1072 if (!(enabled_emac
& (1 << emacNum
)))
1075 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_override_rx
, 1);
1076 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_override_tx
, 1);
1078 UNIMAC_WRITE_FIELD(emacNum
,CMD
,rx_pause_ignore
, !flowControl
->rxFlowEnable
);
1079 UNIMAC_WRITE_FIELD(emacNum
,CMD
,tx_pause_ignore
, !flowControl
->txFlowEnable
);
1082 void mac_hwapi_set_flow_control(rdpa_emac emacNum
,S_MAC_HWAPI_FLOW_CTRL
*flowControl
)
1084 uintptr_t misc_top_address
;
1087 if (!(enabled_emac
& (1 << emacNum
)))
1090 UNIMAC_WRITE_FIELD(emacNum
,CMD
,rx_pause_ignore
, !flowControl
->rxFlowEnable
);
1091 UNIMAC_WRITE_FIELD(emacNum
,CMD
,tx_pause_ignore
, !flowControl
->txFlowEnable
);
1092 misc_top_address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG2
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
1093 READ_32(misc_top_address
, value
);
1095 if(flowControl
->rxFlowEnable
|| flowControl
->txFlowEnable
)
1096 value
|= UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG2_BACKPRESSURE_ENABLE_INT
;
1098 value
&= ~UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG2_BACKPRESSURE_ENABLE_INT
;
1100 WRITE_32(misc_top_address
, value
);
1103 EXPORT_SYMBOL(mac_hwapi_set_flow_control
);
1106 static rdpa_emac_rx_stat_t rxCountersLast
[MAX_NUM_OF_EMACS
];
1107 #define UNIMAC_CURRENT_RX_COUNTERS(emacNum, rxCounters, param) \
1109 uint32_t paramCurrent = rxCounters->param; \
1110 if(mac_unlikely(rxCounters->param < rxCountersLast[emacNum].param)){ \
1111 rxCounters->param += (0xFFFFFFFF-rxCountersLast[emacNum].param)+1; \
1113 rxCounters->param -= rxCountersLast[emacNum].param; \
1115 rxCountersLast[emacNum].param = paramCurrent; \
1118 /******************************************************************************/
1122 /* mac_hwapi_get_rx_counters */
1126 /* MAC Driver - get the rx counters of port */
1130 /* get the rx counters of port */
1134 /* emacNum - emac Port index */
1138 /* rxCounters : structure filled with counters */
1140 /******************************************************************************/
1141 void mac_hwapi_get_rx_counters(rdpa_emac emacNum
,rdpa_emac_rx_stat_t
*rxCounters
)
1145 if (!(enabled_emac
& (1 << emacNum
)))
1147 memset(rxCounters
, 0, sizeof(rdpa_emac_rx_stat_t
));
1151 UNIMAC_READ32_MIB(emacNum
,GRALN
,rxCounters
->alignment_error
);
1152 UNIMAC_READ32_MIB(emacNum
,GRBCA
,rxCounters
->broadcast_packet
);
1153 UNIMAC_READ32_MIB(emacNum
,GRUC
, rxCounters
->unicast_packet
);
1154 UNIMAC_READ32_MIB(emacNum
,GRBYT
,rxCounters
->byte
);
1155 UNIMAC_READ32_MIB(emacNum
,RRBYT
,tempVal
);
1156 rxCounters
->byte
+= tempVal
;
1157 UNIMAC_READ32_MIB(emacNum
,GRFCR
,rxCounters
->carrier_sense_error
);
1158 UNIMAC_READ32_MIB(emacNum
,GRCDE
,rxCounters
->code_error
);
1159 UNIMAC_READ32_MIB(emacNum
,GRXCF
,rxCounters
->control_frame
);
1160 UNIMAC_READ32_MIB(emacNum
,GRFCS
,rxCounters
->fcs_error
);
1161 rxCounters
->fragments
= 0;//?????
1162 UNIMAC_READ32_MIB(emacNum
,GR255
,rxCounters
->frame_128_255
);
1163 UNIMAC_READ32_MIB(emacNum
,GR2047
,tempVal
);
1164 rxCounters
->frame_1519_mtu
= tempVal
;
1165 UNIMAC_READ32_MIB(emacNum
,GR4095
,tempVal
);
1166 rxCounters
->frame_1519_mtu
+= tempVal
;
1167 UNIMAC_READ32_MIB(emacNum
,GR9216
,tempVal
);
1168 rxCounters
->frame_1519_mtu
+= tempVal
;
1170 UNIMAC_READ32_MIB(emacNum
,GR511
,rxCounters
->frame_256_511
);
1172 UNIMAC_READ32_MIB(emacNum
,GR1023
,rxCounters
->frame_512_1023
);
1174 UNIMAC_READ32_MIB(emacNum
,GR1518
,rxCounters
->frame_1024_1518
);
1176 UNIMAC_READ32_MIB(emacNum
,GR64
,rxCounters
->frame_64
);
1178 UNIMAC_READ32_MIB(emacNum
,GR127
,rxCounters
->frame_65_127
);
1180 UNIMAC_READ32_MIB(emacNum
,GRFLR
,rxCounters
->frame_length_error
);
1182 UNIMAC_READ32_MIB(emacNum
,GRJBR
,rxCounters
->jabber
);
1184 UNIMAC_READ32_MIB(emacNum
,GRMCA
,rxCounters
->multicast_packet
);
1186 rxCounters
->overflow
= 0;//no matched counter
1187 UNIMAC_READ32_MIB(emacNum
,GROVR
,rxCounters
->oversize_packet
);
1189 UNIMAC_READ32_MIB(emacNum
,RRPKT
,rxCounters
->undersize_packet
);
1191 UNIMAC_READ32_MIB(emacNum
,GRPKT
,rxCounters
->packet
);
1193 UNIMAC_READ32_MIB(emacNum
,GRXPF
,rxCounters
->pause_control_frame
);
1195 UNIMAC_READ32_MIB(emacNum
,GRXUO
,rxCounters
->unknown_opcode
);
1197 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, alignment_error
);
1198 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, broadcast_packet
);
1199 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, unicast_packet
);
1200 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, byte
);
1201 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, carrier_sense_error
);
1202 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, code_error
);
1203 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, control_frame
);
1204 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, fcs_error
);
1205 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_64
);
1206 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_65_127
);
1207 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_128_255
);
1208 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_256_511
);
1209 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_512_1023
);
1210 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_1024_1518
);
1211 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_1519_mtu
);
1212 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, frame_length_error
);
1213 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, jabber
);
1214 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, multicast_packet
);
1215 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, oversize_packet
);
1216 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, undersize_packet
);
1217 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, packet
);
1218 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, pause_control_frame
);
1219 UNIMAC_CURRENT_RX_COUNTERS(emacNum
, rxCounters
, unknown_opcode
);
1221 EXPORT_SYMBOL(mac_hwapi_get_rx_counters
);
1224 static rdpa_emac_tx_stat_t txCountersLast
[MAX_NUM_OF_EMACS
];
1225 #define UNIMAC_CURRENT_TX_COUNTERS(emacNum, txCounters, param) \
1227 uint32_t paramCurrent = txCounters->param; \
1228 if(mac_unlikely(txCounters->param < txCountersLast[emacNum].param)){ \
1229 txCounters->param += (0xFFFFFFFF-txCountersLast[emacNum].param)+1; \
1231 txCounters->param -= txCountersLast[emacNum].param; \
1233 txCountersLast[emacNum].param = paramCurrent; \
1237 /******************************************************************************/
1241 /* mac_hwapi_get_tx_counters */
1245 /* MAC Driver - get the tx counters of port */
1249 /* get the tx counters of port */
1253 /* emacNum - emac Port index */
1257 /* txCounters : structure filled with counters */
1259 /******************************************************************************/
1260 void mac_hwapi_get_tx_counters(rdpa_emac emacNum
,rdpa_emac_tx_stat_t
*txCounters
)
1262 /*fill the rdpa counters structure*/
1265 if (!(enabled_emac
& (1 << emacNum
)))
1267 memset(txCounters
, 0, sizeof(rdpa_emac_tx_stat_t
));
1271 UNIMAC_READ32_MIB(emacNum
,GTBYT
,txCounters
->byte
);
1273 UNIMAC_READ32_MIB(emacNum
,GTBCA
,txCounters
->broadcast_packet
);
1275 UNIMAC_READ32_MIB(emacNum
,GTMCA
, txCounters
->multicast_packet
);
1277 UNIMAC_READ32_MIB(emacNum
,GTUC
, txCounters
->unicast_packet
);
1279 UNIMAC_READ32_MIB(emacNum
,GTXCF
,txCounters
->control_frame
);
1281 UNIMAC_READ32_MIB(emacNum
,GTDRF
,txCounters
->deferral_packet
);
1284 UNIMAC_READ32_MIB(emacNum
,GTNCL
,tempVal
);
1285 txCounters
->error
= tempVal
;
1286 UNIMAC_READ32_MIB(emacNum
,GTOVR
,tempVal
);
1287 txCounters
->error
+= tempVal
;
1288 UNIMAC_READ32_MIB(emacNum
,GTFCS
,tempVal
);
1289 txCounters
->error
+= tempVal
;
1290 UNIMAC_READ32_MIB(emacNum
,GTEDF
,txCounters
->excessive_deferral_packet
);
1292 UNIMAC_READ32_MIB(emacNum
,GTFCS
,txCounters
->fcs_error
);
1294 UNIMAC_READ32_MIB(emacNum
,GTFRG
,txCounters
->fragments_frame
);
1296 UNIMAC_READ32_MIB(emacNum
,TR1518
,txCounters
->frame_1024_1518
);
1298 UNIMAC_READ32_MIB(emacNum
,TR255
, txCounters
->frame_128_255
);
1300 UNIMAC_READ32_MIB(emacNum
,TR2047
, tempVal
);
1301 txCounters
->frame_1519_mtu
= tempVal
;
1302 UNIMAC_READ32_MIB(emacNum
,TR4095
, tempVal
);
1303 txCounters
->frame_1519_mtu
+= tempVal
;
1304 UNIMAC_READ32_MIB(emacNum
,TR9216
, tempVal
);
1305 txCounters
->frame_1519_mtu
+= tempVal
;
1306 UNIMAC_READ32_MIB(emacNum
,TR511
, txCounters
->frame_256_511
);
1308 UNIMAC_READ32_MIB(emacNum
,TR1023
, txCounters
->frame_512_1023
);
1310 UNIMAC_READ32_MIB(emacNum
,TR64
,txCounters
->frame_64
);
1312 UNIMAC_READ32_MIB(emacNum
,TR127
, txCounters
->frame_65_127
);
1314 UNIMAC_READ32_MIB(emacNum
,GTJBR
, txCounters
->jabber_frame
);
1316 UNIMAC_READ32_MIB(emacNum
,GTLCL
, txCounters
->late_collision
);
1318 UNIMAC_READ32_MIB(emacNum
,GTMCL
, txCounters
->multiple_collision
);
1320 UNIMAC_READ32_MIB(emacNum
,GTOVR
,txCounters
->oversize_frame
);
1322 UNIMAC_READ32_MIB(emacNum
,GTPOK
, txCounters
->packet
);
1324 UNIMAC_READ32_MIB(emacNum
,GTXPF
, txCounters
->pause_control_frame
);
1326 UNIMAC_READ32_MIB(emacNum
,GTSCL
, txCounters
->single_collision
);
1328 UNIMAC_READ32_MIB(emacNum
,GTNCL
, txCounters
->total_collision
);
1330 UNIMAC_READ32_MIB(emacNum
,GTXCL
, txCounters
->excessive_collision
);
1332 txCounters
->underrun
= 0;
1333 txCounters
->undersize_frame
= 0;
1335 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, byte
);
1336 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, packet
);
1337 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, broadcast_packet
);
1338 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, multicast_packet
);
1339 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, unicast_packet
);
1340 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, deferral_packet
);
1341 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, excessive_deferral_packet
);
1342 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, control_frame
);
1343 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, jabber_frame
);
1344 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, oversize_frame
);
1345 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, pause_control_frame
);
1346 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, fragments_frame
);
1347 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, error
);
1348 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, fcs_error
);
1349 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_64
);
1350 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_65_127
);
1351 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_128_255
);
1352 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_256_511
);
1353 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_512_1023
);
1354 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_1024_1518
);
1355 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, frame_1519_mtu
);
1356 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, single_collision
);
1357 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, total_collision
);
1358 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, late_collision
);
1359 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, multiple_collision
);
1360 UNIMAC_CURRENT_TX_COUNTERS(emacNum
, txCounters
, excessive_collision
);
1362 EXPORT_SYMBOL(mac_hwapi_get_tx_counters
);
1363 /******************************************************************************/
1367 /* mac_hwapi_init_emac */
1371 /* MAC Driver - init the emac to well known state */
1375 /* initialized the emac port */
1379 /* emacNum - emac Port index */
1384 /******************************************************************************/
1385 void mac_hwapi_init_emac(rdpa_emac emacNum
)
1387 /*configure the emac and put it in automatic speed mode*/
1388 S_UNIMAC_CMD_REG mCfgReg
;
1389 uint32_t max_frame_length
= UNIMAC_MAX_FRAME_LENGHT
;
1391 #if defined(CONFIG_BCM4908)
1392 soc_base_address
= RDP_BASE
;
1395 /*before calling this function make sure you pull out of reset the emac */
1397 /*put the emac in sw_reset state*/
1398 //UNIMAC_WRITE_FIELD(emacNum,CMD,sw_reset,UNIMAC_SWRESET_ON);
1400 UNIMAC_READ32_REG(emacNum
,CMD
,mCfgReg
);
1401 /* Do the initialization */
1402 #ifndef CONFIG_BRCM_QEMU
1406 printk("%s RX TX Enable no PHY EXIST\n",__FUNCTION__
);
1411 /* for 63138 - even though the EMAC_1 is connected to SF2 @ 2Gbps, we still set the link to 1G.
1412 * Actual speed of the link is derived from SF2 based on the speed set for IMP port#8. */
1413 mCfgReg
.eth_speed
= UNIMAC_SPEED_1000
;
1414 mCfgReg
.promis_en
= 1;
1416 mCfgReg
.pause_fwd
= 1;
1417 mCfgReg
.crc_fwd
= 1;
1418 mCfgReg
.ena_ext_config
= 0;
1419 mCfgReg
.rx_pause_ignore
= 0;
1420 mCfgReg
.tx_pause_ignore
= 0;
1421 mCfgReg
.tx_addr_ins
= 0;
1422 mCfgReg
.lcl_loop_ena
= 0;
1423 mCfgReg
.cntl_frm_ena
= 1;
1424 mCfgReg
.no_lgth_check
= 1;
1425 mCfgReg
.rmt_loop_ena
= 0;
1426 mCfgReg
.rx_err_disc
= 0;
1427 mCfgReg
.prbl_ena
= 0;
1428 mCfgReg
.cntl_frm_ena
= 1;
1430 /*write the configuration */
1431 UNIMAC_WRITE32_REG(emacNum
,CMD
,mCfgReg
);
1432 UNIMAC_WRITE32_REG(emacNum
,FRM_LEN
, max_frame_length
);
1434 /*take out the emac from sw_reset state*/
1435 //UNIMAC_WRITE_FIELD(emacNum,CMD,sw_reset,UNIMAC_SWRESET_OFF);
1437 /*configure the pause control*/
1438 UNIMAC_WRITE_FIELD(emacNum
,PAUSE_CNTRL
,pause_timer
,UNIMAC_DEFAULT_PAUSE_TIMER
);
1439 UNIMAC_WRITE_FIELD(emacNum
,PAUSE_CNTRL
,pause_control_en
,1);
1441 /*configure the pause quanta*/
1442 UNIMAC_WRITE_FIELD(emacNum
,PAUSE_QUNAT
,pause_quant
,UNIMAC_DEFAULT_PAUSE_QUANTA
);
1444 /*write default ipg*/
1445 UNIMAC_WRITE_FIELD(emacNum
,TX_IPG_LEN
,tx_ipg_len
,UNIMAC_DEFAULT_IPG
);
1447 memset(&rxCountersLast
, 0, MAX_NUM_OF_EMACS
*sizeof(rdpa_emac_rx_stat_t
));
1448 memset(&txCountersLast
, 0, MAX_NUM_OF_EMACS
*sizeof(rdpa_emac_tx_stat_t
));
1450 enabled_emac
|= (1 << emacNum
);
1452 /*emac is ready to go!*/
1454 EXPORT_SYMBOL(mac_hwapi_init_emac
);
1455 /******************************************************************************/
1459 /* mac_hwapi_get_loopback */
1463 /* MAC Driver - init the emac to well known state */
1467 /* initialized the emac port */
1471 /* emacNum - emac Port index */
1476 /******************************************************************************/
1477 void mac_hwapi_get_loopback(rdpa_emac emacNum
,MAC_LPBK
*loopback
)
1479 S_UNIMAC_CMD_REG mCmdReg
;
1481 if (!(enabled_emac
& (1 << emacNum
)))
1484 UNIMAC_READ32_REG(emacNum
,CMD
,mCmdReg
);
1486 if (mCmdReg
.lcl_loop_ena
&& mCmdReg
.rmt_loop_ena
)
1488 *loopback
= MAC_LPBK_BOTH
;
1490 else if (mCmdReg
.lcl_loop_ena
)
1492 *loopback
= MAC_LPBK_LOCAL
;
1494 else if (mCmdReg
.rmt_loop_ena
)
1496 *loopback
= MAC_LPBK_REMOTE
;
1500 *loopback
= MAC_LPBK_NONE
;
1504 EXPORT_SYMBOL(mac_hwapi_get_loopback
);
1507 /******************************************************************************/
1511 /* mac_hwapi_set_loopback */
1515 /* MAC Driver - set loopback type of the mac */
1519 /* initialized the emac port */
1523 /* emacNum - emac Port index */
1528 /******************************************************************************/
1529 void mac_hwapi_set_loopback(rdpa_emac emacNum
,MAC_LPBK loopback
)
1531 if (!(enabled_emac
& (1 << emacNum
)))
1534 /*put the emac in sw_reset state*/
1535 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_ON
);
1540 UNIMAC_WRITE_FIELD(emacNum
,CMD
,rmt_loop_ena
,1);
1541 UNIMAC_WRITE_FIELD(emacNum
,CMD
, lcl_loop_ena
,1);
1543 case MAC_LPBK_LOCAL
:
1544 UNIMAC_WRITE_FIELD(emacNum
,CMD
, lcl_loop_ena
,1);
1546 case MAC_LPBK_REMOTE
:
1547 UNIMAC_WRITE_FIELD(emacNum
,CMD
,rmt_loop_ena
,1);
1550 UNIMAC_WRITE_FIELD(emacNum
,CMD
,rmt_loop_ena
,0);
1551 UNIMAC_WRITE_FIELD(emacNum
,CMD
, lcl_loop_ena
,0);
1557 /* take out the emac from sw_reset state*/
1558 UNIMAC_WRITE_FIELD(emacNum
,CMD
,sw_reset
,UNIMAC_SWRESET_OFF
);
1561 EXPORT_SYMBOL(mac_hwapi_set_loopback
);
1563 #if !defined(CONFIG_BCM47622)
1564 void mac_hwapi_set_unimac_cfg(rdpa_emac emacNum
, int32_t enabled
)
1566 S_UNIMAC_CFG_REG cfgreg
;
1567 uintptr_t address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_CFG
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
1569 if (!(enabled_emac
& (1 << emacNum
)))
1572 READ_32(address
,cfgreg
);
1573 cfgreg
.gmii_direct
= enabled
? 1 : 0;
1574 WRITE_32(address
,cfgreg
);
1576 EXPORT_SYMBOL(mac_hwapi_set_unimac_cfg
);
1579 void mac_hwapi_modify_flow_control_pause_pkt_addr ( rdpa_emac emacNum
,bdmf_mac_t mac
)
1581 uint32_t value
= *(uint32_t*)(&(mac
.b
[4])) >> 16 ;
1582 uintptr_t mac_address
= (uintptr_t)UNIMAC_CONFIGURATION_UMAC_0_RDP_MAC0
+ UNIMAC_CONF_INSTANCE_OFFSET(emacNum
);
1584 if (!(enabled_emac
& (1 << emacNum
)))
1587 WRITE_32(mac_address
, *(uint32_t*)mac
.b
);
1589 mac_address
= (uintptr_t)UNIMAC_CONFIGURATION_UMAC_0_RDP_MAC1
+ UNIMAC_CONF_INSTANCE_OFFSET(emacNum
);
1590 WRITE_32(mac_address
, value
);
1593 EXPORT_SYMBOL(mac_hwapi_modify_flow_control_pause_pkt_addr
);
1595 #if !defined(CONFIG_BCM47622)
1596 void mac_hwapi_set_backpressure_ext(rdpa_emac emacNum
,int32_t enable
)
1598 #if defined(CONFIG_BCM63138) || defined(CONFIG_BCM63148) || defined(CONFIG_BCM4908) || defined(CONFIG_BCM63158)
1599 S_UNIMAC_TOP_CFG2_REG cfgreg
;
1600 uintptr_t misc_top_address
= (uintptr_t)UNIMAC_TOP_UNIMAC_MISC_UNIMAC_EXT_CFG2
+ UNIMAC_MISC_INSTANCE_OFFSET(emacNum
);
1602 if (!(enabled_emac
& (1 << emacNum
)))
1605 READ_32(misc_top_address
,cfgreg
);
1606 cfgreg
.backpressure_enable_ext
= (enable
? 1 : 0);
1607 WRITE_32(misc_top_address
,cfgreg
);
1610 EXPORT_SYMBOL(mac_hwapi_set_backpressure_ext
);
1613 void mac_hwapi_set_eee(rdpa_emac emacNum
, int32_t enable
)
1615 uint32_t eee_ref_count
= 0;
1616 uint32_t eee_wake_timer
= 0;
1617 uint32_t eee_lpi_timer
= 0;
1619 S_UNIMAC_EEE_CTRL_REG eee_ctrl
;
1620 S_HWAPI_MAC_STATUS mac_mode
;
1622 /* Determine EEE timers only when EEE is enabled */
1625 #if defined(CONFIG_BCM63158) || defined(CONFIG_BCM6856) || defined(CONFIG_BCM47622) || defined(CONFIG_BCM6878)
1626 eee_ref_count
= 0xfa; /* 250 Mhz */;
1628 get_rdp_freq(&eee_ref_count
);
1632 /* Read actual mac speed */
1633 UNIMAC_READ32_REG(emacNum
, MODE
, mac_mode
);
1635 switch (mac_mode
.mac_speed
) {
1636 case rdpa_emac_rate_100m
: /* 100Mbps */
1638 eee_lpi_timer
= 0x3c; /* 60 uS */
1639 eee_wake_timer
= 0x1e; /* 30 uS */
1642 case rdpa_emac_rate_1g
: /* 1000Mbps */
1644 eee_lpi_timer
= 0x22; /* 34 uS */
1645 eee_wake_timer
= 0x11; /* 17 uS */
1648 case rdpa_emac_rate_2_5g
: /* 2500Mbps */
1650 eee_lpi_timer
= 0x3c; /* 60 uS */
1651 eee_wake_timer
= 0x1e; /* 30 uS */
1659 UNIMAC_READ32_REG(emacNum
, EEE_CTRL
, eee_ctrl
);
1660 eee_ctrl
.eee_en
= enable
? 1 : 0;
1661 UNIMAC_WRITE32_REG(emacNum
, EEE_CTRL
, eee_ctrl
);
1662 UNIMAC_WRITE32_REG(emacNum
, EEE_REF_COUNT
, eee_ref_count
);
1664 #if defined(CONFIG_BCM6856)
1665 if (mac_mode
.mac_speed
== rdpa_emac_rate_100m
)
1667 UNIMAC_WRITE32_REG(emacNum
, EEE_MII_LPI_TIMER
, eee_lpi_timer
);
1668 UNIMAC_WRITE32_REG(emacNum
, EEE_MII_WAKE_TIMER
, eee_wake_timer
);
1672 UNIMAC_WRITE32_REG(emacNum
, EEE_GMII_LPI_TIMER
, eee_lpi_timer
);
1673 UNIMAC_WRITE32_REG(emacNum
, EEE_GMII_WAKE_TIMER
, eee_wake_timer
);
1676 UNIMAC_WRITE32_REG(emacNum
, EEE_LPI_TIMER
, eee_lpi_timer
);
1677 UNIMAC_WRITE32_REG(emacNum
, EEE_WAKE_TIMER
, eee_wake_timer
);
1680 EXPORT_SYMBOL(mac_hwapi_set_eee
);