xref: /openbmc/u-boot/cmd/aspeed/nettest/comminf.h (revision fabbeb33)
1 /*
2  *  This program is distributed in the hope that it will be useful,
3  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
4  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5  *  GNU General Public License for more details.
6  *
7  *  You should have received a copy of the GNU General Public License
8  *  along with this program; if not, write to the Free Software
9  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10  */
11 
12 #ifndef COMMINF_H
13 #define COMMINF_H
14 
15 #include "swfunc.h"
16 
17 #include "mac.h"
18 
19 //---------------------------------------------------------
20 // Print Message
21 //---------------------------------------------------------
22 // for function
23 #define FP_LOG                                   0
24 #define FP_IO                                    1
25 #define STD_OUT                                  2
26 
27 #define PRINTF(i, ...)                                                         \
28 	do {                                                                   \
29 		if (i == STD_OUT) {                                            \
30 			fprintf(stdout, __VA_ARGS__);                          \
31 			break;                                                 \
32 		}                                                              \
33 		if ((display_lantest_log_msg != 0) && (i == FP_LOG)) {         \
34 			fprintf(stdout, "[Log]:   ");                          \
35 			fprintf(stdout, __VA_ARGS__);                          \
36 		}                                                              \
37 	} while (0);
38 
39 //---------------------------------------------------------
40 // Function
41 //---------------------------------------------------------
42   #define SWAP_4B( x )                                                             \
43                                                  ( ( ( ( x ) & 0xff000000 ) >> 24) \
44                                                  | ( ( ( x ) & 0x00ff0000 ) >>  8) \
45                                                  | ( ( ( x ) & 0x0000ff00 ) <<  8) \
46                                                  | ( ( ( x ) & 0x000000ff ) << 24) \
47                                                  )
48   #define SWAP_2B( x )                                                             \
49                                                  ( ( ( ( x ) & 0xff00     ) >>  8) \
50                                                  | ( ( ( x ) & 0x00ff     ) <<  8) \
51                                                  )
52 
53   #define SWAP_2B_BEDN( x )                      ( SWAP_2B ( x ) )
54   #define SWAP_2B_LEDN( x )                      ( x )
55   #define SWAP_4B_BEDN( x )                      ( SWAP_4B ( x ) )
56   #define SWAP_4B_LEDN( x )                      ( x )
57 
58   #define SWAP_4B_BEDN_NCSI( x )                 ( SWAP_4B( x ) )
59   #define SWAP_4B_LEDN_NCSI( x )                 ( x )
60 
61 #if defined(ENABLE_BIG_ENDIAN_MEM)
62   #define SWAP_4B_LEDN_MEM( x )                  ( SWAP_4B( x ) )
63 #else
64   #define SWAP_4B_LEDN_MEM( x )                  ( x )
65 #endif
66 #if defined(ENABLE_BIG_ENDIAN_REG)
67   #define SWAP_4B_LEDN_REG( x )                  ( SWAP_4B( x ) )
68 #else
69   #define SWAP_4B_LEDN_REG( x )                  ( x )
70 #endif
71 
72 #define DELAY( x )                       	udelay( ( x ) * 1000 )
73 #define GET_CAHR                         	getc
74 
75 //---------------------------------------------------------
76 // Default argument
77 //---------------------------------------------------------
78 #define  DEF_GUSER_DEF_PACKET_VAL                0xaaaaaaaa     //0xff00ff00, 0xf0f0f0f0, 0xcccccccc, 0x55aa55aa, 0x5a5a5a5a, 0x66666666
79 #define  DEF_GIOTIMINGBUND                       2
80 #define  DEF_GPHY_ADR                            0
81 #define  DEF_GTESTMODE                           0              //[0]0: no burst mode, 1: 0xff, 2: 0x55, 3: random, 4: ARP, 5: ARP, 6: IO timing, 7: IO timing+IO Strength
82 #define  DEF_GLOOP_MAX                           1
83 #define  DEF_GCTRL                               0
84 
85 #define  SET_1GBPS                               BIT(0)
86 #define  SET_100MBPS                             BIT(1)
87 #define  SET_10MBPS                              BIT(2)
88 #define  SET_1G_100M_10MBPS                      (SET_1GBPS | SET_100MBPS | SET_10MBPS)
89 #define  SET_100M_10MBPS                         (SET_100MBPS | SET_10MBPS)
90 
91 #define  DEF_GSPEED                              SET_1G_100M_10MBPS
92 #define  DEF_GARPNUMCNT                          0
93 
94 //---------------------------------------------------------
95 // MAC information
96 //---------------------------------------------------------
97 
98 #define MDC_Thres                                0x3f
99 #define MAC_PHYWr                                0x08000000
100 #define MAC_PHYRd                                0x04000000
101 
102 #ifdef CONFIG_ASPEED_AST2600
103 #define MAC_PHYWr_New 	(BIT(31) | BIT(28) | (0x1 << 26)) /* 0x94000000 */
104 #define MAC_PHYRd_New 	(BIT(31) | BIT(28) | (0x2 << 26)) /* 0x98000000 */
105 #define MAC_PHYBusy_New	BIT(31)
106 #else
107 #define MAC_PHYWr_New                            0x00009400
108 #define MAC_PHYRd_New                            0x00009800
109 #define MAC_PHYBusy_New                          0x00008000
110 #endif
111 
112 #define MAC_048_def                          0x000002F1 //default 0xf1
113 //#define MAC_058_def                              0x00000040 //0x000001c0
114 
115 //---------------------------------------------------------
116 // Data information
117 //---------------------------------------------------------
118 #define ZeroCopy_OFFSET                    (( eng->run.tm_tx_only ) ? 0 : 2)
119 
120 //      --------------------------------- DRAM_MapAdr            = tdes_base
121 //              | TX descriptor ring    |
122 //              ------------------------- DRAM_MapAdr + 0x040000 = rdes_base
123 //              | RX descriptor ring    |
124 //              -------------------------
125 //              | Reserved              |
126 //              -------------------------
127 //              | Reserved              |
128 //      --------------------------------- DRAM_MapAdr + 0x100000 = DMA_BASE    -------------------------
129 //              |   #1                  |  \                                   |     #1     Tx         |
130 //  DMA buffer  |                       |   DMA_BufSize                        |      LOOP = 0         |
131 // ( Tx/Rx )    -------------------------  /                                   --------------------------------------------------
132 //              |   #2                  |                                      |     #2     Rx         |  #2     Tx             |
133 //              |                       |                                      |      LOOP = 0         |   LOOP = 1             |
134 //              -------------------------                                      --------------------------------------------------
135 //              |   #3                  |                                                              |  #3     Rx             |
136 //              |                       |                                                              |   LOOP = 1             |
137 //              -------------------------                                                              -------------------------
138 //              |   #4                  |                                                                                     ..........
139 //              |                       |
140 //              -------------------------
141 //              |   #5                  |
142 //              |                       |
143 //              -------------------------
144 //              |   #6                  |
145 //              |                       |
146 //              -------------------------
147 //                           .
148 //                           .
149 //              -------------------------
150 //              |   #n, n = DMA_BufNum  |
151 //              |                       |
152 //      ---------------------------------
153 
154 #define BUF_SIZE			0x04000000
155 #define TDES_SIZE			0x00040000
156 #define RDES_SIZE			0x00040000
157 #define RESV_SIZE			0x00000000		/* reserved */
158 
159 #define TDES_IniVal (0xb0000000 + eng->dat.FRAME_LEN_Cur)
160 #define RDES_IniVal (0x00000fff)
161 #define EOR_IniVal (0x40000000)
162 #define HWOwnTx(dat) (dat & 0x80000000)
163 #define HWOwnRx(dat) ((dat & 0x80000000) == 0)
164 #define HWEOR(dat) (dat & 0x40000000)
165 
166 #define AT_MEMRW_BUF(x) ((x) - ASPEED_DRAM_BASE)
167 #define AT_BUF_MEMRW(x) ((x) + ASPEED_DRAM_BASE)
168 
169 //---------------------------------------------------------
170 // Error Flag Bits
171 //---------------------------------------------------------
172 #define Err_Flag_MACMode                              ( 1 <<  0 )   // MAC interface mode mismatch
173 #define Err_Flag_PHY_Type                             ( 1 <<  1 )   // Unidentifiable PHY
174 #define Err_Flag_MALLOC_FrmSize                       ( 1 <<  2 )   // Malloc fail at frame size buffer
175 #define Err_Flag_MALLOC_LastWP                        ( 1 <<  3 )   // Malloc fail at last WP buffer
176 #define Err_Flag_Check_Buf_Data                       ( 1 <<  4 )   // Received data mismatch
177 #define Err_Flag_Check_Des                            ( 1 <<  5 )   // Descriptor error
178 #define ERR_FLAG_NCSI_LINKFAIL			(1 << 6)	// NCSI packet retry number over flows
179 #define Err_Flag_NCSI_Check_TxOwnTimeOut              ( 1 <<  7 )   // Time out of checking Tx owner bit in NCSI packet
180 #define Err_Flag_NCSI_Check_RxOwnTimeOut              ( 1 <<  8 )   // Time out of checking Rx owner bit in NCSI packet
181 #define Err_Flag_NCSI_Check_ARPOwnTimeOut             ( 1 <<  9 )   // Time out of checking ARP owner bit in NCSI packet
182 #define Err_Flag_NCSI_No_PHY                          ( 1 << 10 )   // Can not find NCSI PHY
183 #define Err_Flag_NCSI_Channel_Num                     ( 1 << 11 )   // NCSI Channel Number Mismatch
184 #define Err_Flag_NCSI_Package_Num                     ( 1 << 12 )   // NCSI Package Number Mismatch
185 #define Err_Flag_PHY_TimeOut_RW                       ( 1 << 13 )   // Time out of read/write PHY register
186 #define Err_Flag_PHY_TimeOut_Rst                      ( 1 << 14 )   // Time out of reset PHY register
187 #define Err_Flag_RXBUF_UNAVA                          ( 1 << 15 )   // MAC00h[2]:Receiving buffer unavailable
188 #define Err_Flag_RPKT_LOST                            ( 1 << 16 )   // MAC00h[3]:Received packet lost due to RX FIFO full
189 #define Err_Flag_NPTXBUF_UNAVA                        ( 1 << 17 )   // MAC00h[6]:Normal priority transmit buffer unavailable
190 #define Err_Flag_TPKT_LOST                            ( 1 << 18 )   // MAC00h[7]:Packets transmitted to Ethernet lost
191 #define Err_Flag_DMABufNum                            ( 1 << 19 )   // DMA Buffer is not enough
192 #define Err_Flag_IOMargin                             ( 1 << 20 )   // IO timing margin is not enough
193 #define Err_Flag_IOMarginOUF                          ( 1 << 21 )   // IO timing testing out of boundary
194 #define Err_Flag_MHCLK_Ratio                          ( 1 << 22 )   // Error setting of MAC AHB bus clock (SCU08[18:16])
195 
196 #define Wrn_Flag_IOMarginOUF                          ( 1 <<  0 )   // IO timing testing out of boundary
197 #define Wrn_Flag_RxErFloatting                        ( 1 <<  1 )   // NCSI RXER pin may be floatting to the MAC
198 //#define Wrn_Flag_RMIICK_IOMode                        ( 1 <<  2 )   // The PHY's RMII refreence clock input/output mode
199 
200 #define PHY_Flag_RMIICK_IOMode_RTL8201E               ( 1 <<  0 )
201 #define PHY_Flag_RMIICK_IOMode_RTL8201F               ( 1 <<  1 )
202 
203 #define Des_Flag_TxOwnTimeOut                         ( 1 <<  0 )   // Time out of checking Tx owner bit
204 #define Des_Flag_RxOwnTimeOut                         ( 1 <<  1 )   // Time out of checking Rx owner bit
205 #define Des_Flag_FrameLen                             ( 1 <<  2 )   // Frame length mismatch
206 #define Des_Flag_RxErr                                ( 1 <<  3 )   // Input signal RxErr
207 #define Des_Flag_CRC                                  ( 1 <<  4 )   // CRC error of frame
208 #define Des_Flag_FTL                                  ( 1 <<  5 )   // Frame too long
209 #define Des_Flag_Runt                                 ( 1 <<  6 )   // Runt packet
210 #define Des_Flag_OddNibble                            ( 1 <<  7 )   // Nibble bit happen
211 #define Des_Flag_RxFIFOFull                           ( 1 <<  8 )   // Rx FIFO full
212 
213 #define NCSI_Flag_Get_Version_ID                      ( 1 <<  0 )   // Time out when Get Version ID
214 #define NCSI_Flag_Get_Capabilities                    ( 1 <<  1 )   // Time out when Get Capabilities
215 #define NCSI_Flag_Select_Active_Package               ( 1 <<  2 )   // Time out when Select Active Package
216 #define NCSI_Flag_Enable_Set_MAC_Address              ( 1 <<  3 )   // Time out when Enable Set MAC Address
217 #define NCSI_Flag_Enable_Broadcast_Filter             ( 1 <<  4 )   // Time out when Enable Broadcast Filter
218 #define NCSI_Flag_Enable_Network_TX                   ( 1 <<  5 )   // Time out when Enable Network TX
219 #define NCSI_Flag_Enable_Channel                      ( 1 <<  6 )   // Time out when Enable Channel
220 #define NCSI_Flag_Disable_Network_TX                  ( 1 <<  7 )   // Time out when Disable Network TX
221 #define NCSI_Flag_Disable_Channel                     ( 1 <<  8 )   // Time out when Disable Channel
222 #define NCSI_Flag_Select_Package                      ( 1 <<  9 )   // Time out when Select Package
223 #define NCSI_Flag_Deselect_Package                    ( 1 << 10 )   // Time out when Deselect Package
224 #define NCSI_Flag_Set_Link                            ( 1 << 11 )   // Time out when Set Link
225 #define NCSI_Flag_Get_Controller_Packet_Statistics    ( 1 << 12 )   // Time out when Get Controller Packet Statistics
226 #define NCSI_Flag_Reset_Channel                       ( 1 << 13 )   // Time out when Reset Channel
227 
228 //---------------------------------------------------------
229 // DMA Buffer information
230 //---------------------------------------------------------
231 #define DMA_BUF_SIZE				(56 * 1024 * 1024)
232 extern uint8_t dma_buf[DMA_BUF_SIZE];
233 
234 #define DMA_BASE				((uint32_t)(&dma_buf[0]))
235 /* The size of one LAN packet */
236 #define DMA_PakSize 				(2 * 1024)
237 
238 #ifdef SelectSimpleBoundary
239 #define DMA_BufSize (((((p_eng->dat.Des_Num + 15) * DMA_PakSize) >> 2) << 2))
240 #else
241 #define DMA_BufSize                                                            \
242 	(4 + ((((p_eng->dat.Des_Num + 15) * DMA_PakSize) >> 2) << 2))
243 #endif
244 #define DMA_BufNum (DMA_BUF_SIZE / (p_eng->dat.DMABuf_Size))
245 
246 /* get DMA buffer address according to the loop counter */
247 #define GET_DMA_BASE(p_eng, x)                                                 \
248 	(DMA_BASE + ((((x) % p_eng->dat.DMABuf_Num)) * p_eng->dat.DMABuf_Size))
249 
250 #define SEED_START                               8
251 #define DATA_SEED(seed)                          ( ( seed ) | (( seed + 1 ) << 16 ) )
252 #define DATA_IncVal                              0x00020001
253 #define PktByteSize                              ( ( ( ( ZeroCopy_OFFSET + eng->dat.FRAME_LEN_Cur - 1 ) >> 2 ) + 1) << 2 )
254 
255 //---------------------------------------------------------
256 // Delay (ms)
257 //---------------------------------------------------------
258 //#define Delay_DesGap                             1    //off
259 //#define Delay_CntMax                             40
260 //#define Delay_CntMax                             1000
261 //#define Delay_CntMax                             8465
262 //#define Delay_CntMaxIncVal                       50000
263 #define Delay_CntMaxIncVal                       47500
264 
265 
266 //#define Delay_ChkRxOwn                           1
267 //#define Delay_ChkTxOwn                           1
268 
269 #define Delay_PHYRst                             100
270 //#define Delay_PHYRd                              5
271 #define Delay_PHYRd                              1         //20150423
272 
273 #define Delay_MACRst                             1
274 #define Delay_MACDump                            1
275 
276 //#define Delay_DES                                1
277 
278 //---------------------------------------------------------
279 // Time Out
280 //---------------------------------------------------------
281 #define TIME_OUT_Des_1G                      10000     //400
282 #define TIME_OUT_Des_100M                    20000     //4000
283 #define TIME_OUT_Des_10M                     50000     //20000
284 #define TIME_OUT_NCSI                        100000    //40000
285 #define TIME_OUT_PHY_RW                      2000000   //100000
286 #define TIME_OUT_PHY_Rst                     20000     //1000
287 
288 //---------------------------------------------------------
289 // Chip memory MAP
290 //---------------------------------------------------------
291 typedef union {
292 	uint32_t w;
293 	struct {
294 		uint32_t txdma_en		: 1;	/* bit[0] */
295 		uint32_t rxdma_en		: 1;	/* bit[1] */
296 		uint32_t txmac_en		: 1;	/* bit[2] */
297 		uint32_t rxmac_en		: 1;	/* bit[3] */
298 		uint32_t rm_vlan		: 1;	/* bit[4] */
299 		uint32_t hptxr_en		: 1;	/* bit[5] */
300 		uint32_t phy_link_sts_dtct	: 1;	/* bit[6] */
301 		uint32_t enrx_in_halftx		: 1;	/* bit[7] */
302 		uint32_t fulldup		: 1;	/* bit[8] */
303 		uint32_t gmac_mode		: 1;	/* bit[9] */
304 		uint32_t crc_apd		: 1;	/* bit[10] */
305 #ifdef CONFIG_ASPEED_AST2600
306 		uint32_t reserved_1		: 1;	/* bit[11] */
307 #else
308 		uint32_t phy_link_lvl_dtct	: 1;	/* bit[11] */
309 #endif
310 		uint32_t rx_runt		: 1;	/* bit[12] */
311 		uint32_t jumbo_lf		: 1;	/* bit[13] */
312 		uint32_t rx_alladr		: 1;	/* bit[14] */
313 		uint32_t rx_ht_en		: 1;	/* bit[15] */
314 		uint32_t rx_multipkt_en		: 1;	/* bit[16] */
315 		uint32_t rx_broadpkt_en		: 1;	/* bit[17] */
316 		uint32_t discard_crcerr		: 1;	/* bit[18] */
317 		uint32_t speed_100		: 1;	/* bit[19] */
318 		uint32_t reserved_0		: 11;	/* bit[30:20] */
319 		uint32_t sw_rst			: 1;	/* bit[31] */
320 	}b;
321 } mac_cr_t;
322 // ========================================================
323 // For ncsi.c
324 
325 #define DEF_GPACKAGE2NUM                         1         // Default value
326 #define DEF_GCHANNEL2NUM                         1         // Default value
327 
328 //---------------------------------------------------------
329 // Variable
330 //---------------------------------------------------------
331 //NC-SI Command Packet
332 typedef struct {
333 //Ethernet Header
334 	unsigned char        DA[6];                        // Destination Address
335 	unsigned char        SA[6];                        // Source Address
336 	uint16_t       EtherType;                    // DMTF NC-SI, it should be 0x88F8
337 //NC-SI Control Packet
338 	unsigned char        MC_ID;                        // Management Controller should set this field to 0x00
339 	unsigned char        Header_Revision;              // For NC-SI 1.0 spec, this field has to set 0x01
340 	unsigned char        Reserved_1;                   // Reserved has to set to 0x00
341 	unsigned char        IID;                          // Instance ID
342 	unsigned char        Command;
343 //	unsigned char        Channel_ID;
344 	unsigned char        ChID;
345 	uint16_t	Payload_Length;               // Payload Length = 12 bits, 4 bits are reserved
346 	uint32_t	Reserved_2;
347 	uint32_t	Reserved_3;
348 
349 	uint16_t	Reserved_4;
350 	uint16_t	Reserved_5;
351 	uint16_t	Response_Code;
352 	uint16_t       Reason_Code;
353 	unsigned char        Payload_Data[64];
354 #if !defined(SLT_UBOOT)
355 }  NCSI_Command_Packet;
356 #else
357 }  __attribute__ ((__packed__)) NCSI_Command_Packet;
358 #endif
359 
360 //NC-SI Response Packet
361 typedef struct {
362 	unsigned char        DA[6];
363 	unsigned char        SA[6];
364 	uint16_t       EtherType;                    //DMTF NC-SI
365 //NC-SI Control Packet
366 	unsigned char        MC_ID;                        //Management Controller should set this field to 0x00
367 	unsigned char        Header_Revision;              //For NC-SI 1.0 spec, this field has to set 0x01
368 	unsigned char        Reserved_1;                   //Reserved has to set to 0x00
369 	unsigned char        IID;                          //Instance ID
370 	unsigned char        Command;
371 //	unsigned char        Channel_ID;
372 	unsigned char        ChID;
373 	uint16_t       Payload_Length;               //Payload Length = 12 bits, 4 bits are reserved
374 	uint16_t       Reserved_2;
375 	uint16_t       Reserved_3;
376 	uint16_t       Reserved_4;
377 	uint16_t       Reserved_5;
378 
379 	uint16_t       Response_Code;
380 	uint16_t       Reason_Code;
381 	unsigned char        Payload_Data[64];
382 #if !defined(SLT_UBOOT)
383 }  NCSI_Response_Packet;
384 #else
385 }  __attribute__ ((__packed__)) NCSI_Response_Packet;
386 #endif
387 
388 typedef struct {
389 	unsigned char        All_ID                                   ;
390 	unsigned char        Package_ID                               ;
391 	unsigned char        Channel_ID                               ;
392 	uint32_t Capabilities_Flags                       ;
393 	uint32_t Broadcast_Packet_Filter_Capabilities     ;
394 	uint32_t Multicast_Packet_Filter_Capabilities     ;
395 	uint32_t Buffering_Capabilities                   ;
396 	uint32_t AEN_Control_Support                      ;
397 	unsigned char        VLAN_Filter_Count                        ;
398 	unsigned char        Mixed_Filter_Count                       ;
399 	unsigned char        Multicast_Filter_Count                   ;
400 	unsigned char        Unicast_Filter_Count                     ;
401 	unsigned char        VLAN_Mode_Support                        ;
402 	unsigned char        Channel_Count                            ;
403 	uint32_t PCI_DID_VID                              ;
404 	uint32_t manufacturer_id                           ;
405 } NCSI_Capability;
406 
407 typedef struct {
408 	mac_cr_t maccr;
409 	uint32_t mac_madr;
410 	uint32_t mac_ladr;
411 	uint32_t mac_fear;
412 
413 	uint32_t WDT_00c                       ;
414 	uint32_t WDT_02c                       ;
415 	uint32_t WDT_04c                       ;
416 
417 	int8_t                 SCU_oldvld;
418 } mac_reg_t;
419 typedef struct {
420 	uint8_t ast2600;
421 	uint8_t ast2500;
422 	uint8_t mac_num;
423 	uint8_t is_new_mdio_reg[4];
424 
425 	uint8_t is_1g_valid[4];
426 	uint8_t at_least_1g_valid;
427 	uint8_t MHCLK_Ratio;
428 } mac_env_t;
429 
430 typedef union {
431 	uint32_t w;
432 	struct {
433 		uint32_t skip_phy_init	: 1;	/* bit[0] */
434 		uint32_t skip_phy_deinit: 1;	/* bit[1] */
435 		uint32_t skip_phy_id_check	: 1;	/* bit[2] */
436 		uint32_t reserved_0	: 1;	/* bit[3] */
437 		uint32_t phy_int_loopback : 1;	/* bit[4] */
438 		uint32_t mac_int_loopback : 1;	/* bit[5] */
439 		uint32_t reserved_1	: 2;	/* bit[7:6] */
440 		uint32_t rmii_50m_out	: 1;	/* bit[8] */
441 		uint32_t rmii_phy_in	: 1;	/* bit[9] */
442 		uint32_t inv_rgmii_rxclk: 1;	/* bit[10] */
443 		uint32_t reserved_2	: 1;	/* bit[11] */
444 		uint32_t single_packet	: 1;	/* bit[12] */
445 		uint32_t full_range	: 1;	/* bit[13] */
446 		uint32_t reserved_3	: 2;	/* bit[15:14] */
447 		uint32_t print_ncsi	: 1;	/* bit[16] */
448 		uint32_t skip_rx_err	: 1;	/* bit[17] */
449 	} b;
450 } mac_arg_ctrl_t;
451 typedef struct {
452 	uint32_t run_mode;		/* select dedicated or NCSI */
453 	uint32_t mac_idx;		/* argv[1] */
454 	uint32_t mdio_idx;
455 	uint32_t run_speed;		/* argv[2] for dedicated */
456 	mac_arg_ctrl_t ctrl;		/* argv[3] for dedicated
457 					   argv[6] for ncsi */
458 	uint32_t loop_max;		/* argv[4] for dedicated */
459 	uint32_t loop_inf;		/* argv[4] for dedicated */
460 
461 	uint32_t GPackageTolNum;	/* argv[2] for ncsi */
462 	uint32_t GChannelTolNum;	/* argv[3] for ncsi */
463 
464 	uint32_t test_mode;		/* argv[5] for dedicated
465 					   argv[4] for ncsi */
466 
467 	uint32_t phy_addr;		/* argv[6] for dedicated */
468 	uint32_t delay_scan_range;	/* argv[7] for dedicated
469 					   argv[5] for ncsi */
470 	uint32_t ieee_sel;		/* argv[7] for dedicated */
471 
472 	uint32_t GARPNumCnt;		/* argv[7] for ncsi */
473 	uint32_t user_def_val;		/* argv[8] for dedicated */
474 } mac_arg_t;
475 typedef struct {
476 	uint32_t mac_idx;
477 	uint32_t mac_base;
478 	uint32_t mdio_idx;
479 	uint32_t mdio_base;
480 	uint32_t is_rgmii;
481 	uint32_t ieee_sel;		/* derived from delay_scan_range */
482 
483 	uint32_t tdes_base;
484 	uint32_t rdes_base;
485 
486 	uint32_t ncsi_tdes_base;
487 	uint32_t ncsi_rdes_base;
488 
489 	uint32_t LOOP_CheckNum                 ;
490 	uint32_t CheckBuf_MBSize               ;
491 	uint32_t timeout_th;	/* time out threshold (varies with run-speed) */
492 
493 	uint32_t loop_max;
494 	uint32_t loop_of_cnt;
495 	uint32_t loop_cnt;
496 	uint32_t speed_idx;
497 	int                  NCSI_RxTimeOutScale           ;
498 
499 	uint8_t speed_cfg[3];
500 	uint8_t speed_sel[3];
501 
502 	/* test mode */
503 	uint8_t delay_margin;
504 	uint8_t tm_tx_only;
505 	int8_t                 TM_IEEE                       ;//test_mode
506 	int8_t                 TM_IOTiming                   ;//test_mode
507 	int8_t                 TM_IOStrength                 ;//test_mode
508 	int8_t                 TM_TxDataEn                   ;//test_mode
509 	int8_t                 TM_RxDataEn                   ;//test_mode
510 	int8_t                 TM_WaitStart                  ;//test_mode
511 	int8_t                 TM_DefaultPHY                 ;//test_mode
512 	int8_t                 TM_NCSI_DiSChannel            ;//test_mode
513 
514 	int8_t                 IO_MrgChk                     ;
515 
516 
517 } MAC_Running;
518 
519 typedef struct {
520 	uint8_t SA[6];
521 } MAC_Information;
522 
523 typedef struct {
524 	uint32_t mdio_base;
525 	uint32_t loopback;
526 	uint8_t phy_name[64];
527 	int8_t                 default_phy                   ;
528 	int8_t                 Adr                           ;
529 
530 	uint16_t id2                       ;
531 	uint16_t id1                       ;
532 
533 	uint32_t PHY_00h                       ;
534 	uint32_t PHY_06h                       ;
535 	uint32_t PHY_09h                       ;
536 	uint32_t PHY_0eh                       ;
537 	uint32_t PHY_10h                       ;
538 	uint32_t PHY_11h                       ;
539 	uint32_t PHY_12h                       ;
540 	uint32_t PHY_14h                       ;
541 	uint32_t PHY_15h                       ;
542 	uint32_t PHY_18h                       ;
543 	uint32_t PHY_19h                       ;
544 	uint32_t PHY_1ch                       ;
545 	uint32_t PHY_1eh                       ;
546 	uint32_t PHY_1fh                       ;
547 	uint32_t PHY_06hA[7]                   ;
548 
549 	uint32_t RMIICK_IOMode                 ;
550 } MAC_PHY;
551 
552 #ifdef CONFIG_ASPEED_AST2600
553 typedef union {
554 	uint32_t w;
555 	struct {
556 		uint32_t tx_delay_1		: 6;	/* bit[5:0] */
557 		uint32_t tx_delay_2		: 6;	/* bit[11:6] */
558 		uint32_t rx_delay_1		: 6;	/* bit[17:12] */
559 		uint32_t rx_delay_2		: 6;	/* bit[23:18] */
560 		uint32_t rx_clk_inv_1 		: 1;	/* bit[24] */
561 		uint32_t rx_clk_inv_2 		: 1;	/* bit[25] */
562 		uint32_t rmii_tx_data_at_falling_1 : 1; /* bit[26] */
563 		uint32_t rmii_tx_data_at_falling_2 : 1; /* bit[27] */
564 		uint32_t rgmiick_pad_dir	: 1;	/* bit[28] */
565 		uint32_t rmii_50m_oe_1 		: 1;	/* bit[29] */
566 		uint32_t rmii_50m_oe_2		: 1;	/* bit[30] */
567 		uint32_t rgmii_125m_o_sel 	: 1;	/* bit[31] */
568 	}b;
569 } mac_delay_1g_t;
570 
571 typedef union {
572 	uint32_t w;
573 	struct {
574 		uint32_t tx_delay_1		: 6;	/* bit[5:0] */
575 		uint32_t tx_delay_2		: 6;	/* bit[11:6] */
576 		uint32_t rx_delay_1		: 6;	/* bit[17:12] */
577 		uint32_t rx_delay_2		: 6;	/* bit[23:18] */
578 		uint32_t rx_clk_inv_1 		: 1;	/* bit[24] */
579 		uint32_t rx_clk_inv_2 		: 1;	/* bit[25] */
580 		uint32_t reserved_0 		: 6;	/* bit[31:26] */
581 	}b;
582 } mac_delay_100_10_t;
583 #else
584 typedef union {
585 	uint32_t w;
586 	struct {
587 		uint32_t tx_delay_1		: 6;	/* bit[5:0] */
588 		uint32_t tx_delay_2		: 6;	/* bit[11:6] */
589 		uint32_t rx_delay_1		: 6;	/* bit[17:12] */
590 		uint32_t rx_delay_2		: 6;	/* bit[23:18] */
591 		uint32_t rmii_tx_data_at_falling_1 : 1; /* bit[24] */
592 		uint32_t rmii_tx_data_at_falling_2 : 1; /* bit[25] */
593 		uint32_t reserved		: 3;	/* bit[28:26] */
594 		uint32_t rmii_50m_oe_1 		: 1;	/* bit[29] */
595 		uint32_t rmii_50m_oe_2		: 1;	/* bit[30] */
596 		uint32_t rgmii_125m_o_sel 	: 1;	/* bit[31] */
597 	}b;
598 } mac_delay_1g_t;
599 
600 typedef union {
601 	uint32_t w;
602 	struct {
603 		uint32_t tx_delay_1		: 6;	/* bit[5:0] */
604 		uint32_t tx_delay_2		: 6;	/* bit[11:6] */
605 		uint32_t rx_delay_1		: 6;	/* bit[17:12] */
606 		uint32_t rx_delay_2		: 6;	/* bit[23:18] */
607 		uint32_t enable 		: 1;	/* bit[24] */
608 		uint32_t reserved_0 		: 7;	/* bit[31:25] */
609 	}b;
610 } mac_delay_100_10_t;
611 #endif
612 
613 typedef struct mac_delay_1g_reg_s {
614 	uint32_t addr;
615 	int32_t tx_min;
616 	int32_t tx_max;
617 	int32_t rx_min;
618 	int32_t rx_max;
619 	int32_t rmii_tx_min;
620 	int32_t rmii_tx_max;
621 	int32_t rmii_rx_min;
622 	int32_t rmii_rx_max;
623 	mac_delay_1g_t value;	/* backup register value */
624 } mac_delay_1g_reg_t;
625 
626 typedef struct mac_delay_100_10_reg_s {
627 	uint32_t addr;
628 	int32_t tx_min;
629 	int32_t tx_max;
630 	int32_t rx_min;
631 	int32_t rx_max;
632 	mac_delay_100_10_t value;
633 } mac_delay_100_10_reg_t;
634 
635 #ifdef CONFIG_ASPEED_AST2600
636 typedef union {
637 	uint32_t w;
638 	struct {
639 		uint32_t mac3_tx_drv		: 2;	/* bit[1:0] */
640 		uint32_t mac4_tx_drv		: 2;	/* bit[3:2] */
641 		uint32_t reserved_0		: 28;	/* bit[31:4] */
642 	}b;
643 } mac34_drv_t;
644 typedef struct mac34_drv_reg_s {
645 	uint32_t addr;
646 	uint32_t drv_max;
647 	mac34_drv_t value;
648 } mac34_drv_reg_t;
649 
650 #else
651 typedef union {
652 	uint32_t w;
653 	struct {
654 		uint32_t reserved_0		: 8;	/* bit[7:0] */
655 		uint32_t mac1_rmii_tx_drv	: 1;	/* bit[8] */
656 		uint32_t mac1_rgmii_tx_drv	: 1;	/* bit[9] */
657 		uint32_t mac2_rmii_tx_drv	: 1;	/* bit[10] */
658 		uint32_t mac2_rgmii_tx_drv	: 1;	/* bit[11] */
659 		uint32_t reserved_1		: 20;	/* bit[31:12] */
660 	}b;
661 } mac12_drv_t;
662 
663 typedef struct mac12_drv_reg_s {
664 	uint32_t addr;
665 	uint32_t drv_max;
666 	mac12_drv_t value;
667 } mac12_drv_reg_t;
668 #endif
669 
670 typedef struct delay_scan_s {
671 	int8_t begin;
672 	int8_t end;
673 	int8_t step;
674 	int8_t orig;
675 } delay_scan_t;
676 typedef struct {
677 	/* driving strength */
678 #ifdef CONFIG_ASPEED_AST2600
679 	mac34_drv_reg_t mac34_drv_reg;
680 #else
681 	mac12_drv_reg_t mac12_drv_reg;
682 #endif
683 	uint32_t drv_upper_bond;
684 	uint32_t drv_lower_bond;
685 	uint32_t drv_curr;
686 
687 	mac_delay_1g_reg_t mac12_1g_delay;
688 	mac_delay_1g_reg_t mac34_1g_delay;
689 	mac_delay_100_10_reg_t mac12_100m_delay;
690 	mac_delay_100_10_reg_t mac34_100m_delay;
691 	mac_delay_100_10_reg_t mac12_10m_delay;
692 	mac_delay_100_10_reg_t mac34_10m_delay;
693 
694 	delay_scan_t tx_delay_scan;
695 	delay_scan_t rx_delay_scan;
696 
697 	uint8_t                 Dly_in_reg_idx;
698 	int8_t                Dly_in_min                    ;
699 	uint8_t                 Dly_in_max                    ;
700 	uint8_t                 Dly_out_reg_idx               ;
701 	int8_t                Dly_out_min                   ;
702 	uint8_t                 Dly_out_max                   ;
703 
704 	uint8_t                 Dly_in                        ;
705 	uint8_t                 Dly_in_selval                 ;
706 	uint8_t                 Dly_out                       ;
707 	uint8_t                 Dly_out_selval                ;
708 	int8_t result;
709 	int8_t result_history[128][64];
710 	uint32_t init_done;
711 } MAC_IO;
712 typedef struct {
713 #ifdef Enable_ShowBW
714 	double               Total_frame_len               ;//__attribute__ ((aligned (8)));
715 #endif
716 	uint32_t Des_Num                       ;
717 	uint32_t Des_Num_Org                   ;
718 	uint32_t DMABuf_Size                   ;
719 	uint32_t DMABuf_Num                    ;
720 
721 	uint32_t *FRAME_LEN                    ;
722 	uint32_t FRAME_LEN_Cur                 ;
723 	uint32_t *wp_lst                       ;
724 	uint32_t wp_fir                        ;
725 
726 	uint32_t DMA_Base_Setup                 ;
727 	uint32_t DMA_Base_Tx                  ;
728 	uint32_t DMA_Base_Rx                   ;
729 
730 	uint32_t ARP_data[16]                  ;
731 	uint32_t TxDes0DW                      ;
732 	uint32_t RxDes0DW                      ;
733 	uint32_t RxDes3DW                      ;
734 
735 	uint8_t                 number_chl                    ;
736 	uint8_t                 number_pak                    ;
737 	char                 NCSI_RxEr                     ;
738 	uint32_t NCSI_TxDWBUF[512]             ;
739 	uint32_t NCSI_RxDWBUF[512]             ;
740 	char                 NCSI_CommandStr[512]          ;
741 	unsigned char        *NCSI_TxByteBUF               ;
742 	unsigned char        *NCSI_RxByteBUF               ;
743 	unsigned char        NCSI_Payload_Data[16]         ;
744 	uint32_t Payload_Checksum_NCSI         ;
745 } MAC_Data;
746 
747 typedef struct {
748 	uint32_t warn;
749 	uint32_t error;
750 	uint32_t desc;
751 	uint32_t ncsi;
752 	uint32_t error_backup;
753 	uint32_t ncsi_backup;
754 	uint32_t n_desc_fail;
755 	uint8_t print_en;
756 	uint8_t all_fail;
757 } MAC_Flag;
758 
759 typedef struct {
760 	mac_reg_t reg;
761 	mac_env_t env;
762 	mac_arg_t arg;
763 	MAC_Running          run;
764 	MAC_Information      inf;
765 	MAC_PHY              phy;
766 	MAC_IO               io;
767 	MAC_Data             dat;
768 	MAC_Flag             flg;
769 	NCSI_Command_Packet  ncsi_req;
770 	NCSI_Response_Packet ncsi_rsp;
771 	NCSI_Capability      ncsi_cap;
772 } MAC_ENGINE;
773 typedef void (* PHY_SETTING) (MAC_ENGINE *);
774 typedef struct {
775 	PHY_SETTING          fp_set;
776 	PHY_SETTING          fp_clr;
777 } PHY_ENGINE;
778 
779 #undef GLOBAL
780 #ifdef NCSI_C
781 #define GLOBAL
782 #else
783 #define GLOBAL    extern
784 #endif
785 
786 GLOBAL  char phy_ncsi (MAC_ENGINE *eng);
787 
788 // ========================================================
789 // For mactest
790 
791 #undef GLOBAL
792 #ifdef MACTEST_C
793 #define GLOBAL
794 #else
795 #define GLOBAL    extern
796 #endif
797 
798 #define MODE_DEDICATED                           0x01
799 #define MODE_NCSI                                0x02
800 
801 GLOBAL  uint8_t            *mmiobase;
802 GLOBAL  uint32_t ulPCIBaseAddress;
803 GLOBAL  uint32_t ulMMIOBaseAddress;
804 
805 GLOBAL  uint8_t             display_lantest_log_msg;
806 
807 // ========================================================
808 // For mac.c
809 #undef GLOBAL
810 #ifdef MAC_C
811 #define GLOBAL
812 #else
813 #define GLOBAL    extern
814 #endif
815 
816 #if defined(MAC_C)
817 static  const  char version_name[] = VER_NAME;
818 static  const  uint8_t IOValue_Array_A0[16] = {8,1, 10,3, 12,5, 14,7, 0,9, 2,11, 4,13, 6,15}; // AST2300-A0
819 #endif
820 
821 GLOBAL void    debug_pause (void);
822 GLOBAL uint32_t Read_Mem_Dat_NCSI_DD (uint32_t addr);
823 GLOBAL uint32_t Read_Mem_Des_NCSI_DD (uint32_t addr);
824 
825 
826 
827 
828 
829 
830 
831 GLOBAL void Write_Mem_Dat_NCSI_DD (uint32_t addr, uint32_t data);
832 GLOBAL void Write_Mem_Des_NCSI_DD (uint32_t addr, uint32_t data);
833 
834 
835 GLOBAL void Write_Reg_TIMER_DD (uint32_t addr, uint32_t data);
836 
837 
838 
839 
840 
841 
842 GLOBAL void    PrintTest (MAC_ENGINE *eng);
843 GLOBAL void    PrintIOTimingBund (MAC_ENGINE *eng);
844 
845 
846 
847 GLOBAL void    PrintPHYAdr (MAC_ENGINE *eng);
848 
849 
850 
851 
852 
853 GLOBAL void    setup_arp (MAC_ENGINE *eng);
854 GLOBAL void    TestingSetup (MAC_ENGINE *eng);
855 
856 
857 
858 GLOBAL void    init_mac (MAC_ENGINE *eng);
859 GLOBAL char TestingLoop (MAC_ENGINE *eng, uint32_t loop_checknum);
860 
861 GLOBAL void    init_phy (MAC_ENGINE *eng, PHY_ENGINE *phyeng);
862 
863 
864 GLOBAL void    phy_select (MAC_ENGINE *eng, PHY_ENGINE *phyeng);
865 GLOBAL void    recov_phy (MAC_ENGINE *eng, PHY_ENGINE *phyeng);
866 GLOBAL int     FindErr (MAC_ENGINE *eng, int value);
867 GLOBAL int     FindErr_Des (MAC_ENGINE *eng, int value);
868 GLOBAL void    PrintIO_Header (MAC_ENGINE *eng, uint8_t option);
869 
870 
871 
872 GLOBAL void    FPri_ErrFlag (MAC_ENGINE *eng, uint8_t option);
873 
874 GLOBAL void init_hwtimer( void );
875 GLOBAL void delay_hwtimer(uint16_t msec);
876 
877 // ========================================================
878 // For PHYGPIO.c
879 #undef GLOBAL
880 #ifdef PHYGPIO_C
881 #define GLOBAL
882 #else
883 #define GLOBAL    extern
884 #endif
885 
886 
887 // ========================================================
888 // For PHYSPECIAL.c
889 #undef GLOBAL
890 #ifdef PHYMISC_C
891 #define GLOBAL
892 #else
893 #define GLOBAL    extern
894 #endif
895 
896 
897 #endif // End COMMINF_H
898