1 /* ===================================================================================
2  * Copyright (c) <2009> Synopsys, Inc.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software annotated with this license and associated documentation files
7  * (the "Software"), to deal in the Software without restriction, including without
8  * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * =================================================================================== */
23 
24 /** \file
25  * This file defines the synopsys GMAC device dependent functions.
26  * Most of the operations on the GMAC device are available in this file.
27  * Functions for initiliasing and accessing MAC/DMA/PHY registers and the DMA descriptors
28  * are encapsulated in this file. The functions are platform/host/OS independent.
29  * These functions in turn use the low level device dependent (HAL) functions to
30  * access the register space.
31  * \internal
32  * ------------------------REVISION HISTORY---------------------------------
33  * Synopsys                 01/Aug/2007                              Created
34  */
35 #include <string.h>
36 #include "synopGMAC_Dev.h"
37 #include "synopGMAC_network_interface.h"
38 
39 /**
40   * Function to set the MDC clock for mdio transactiona
41   *
42   * @param[in] pointer to device structure.
43   * @param[in] clk divider value.
44   * \return Reuturns 0 on success else return the error value.
45   */
synopGMAC_set_mdc_clk_div(synopGMACdevice * gmacdev,u32 clk_div_val)46 s32 synopGMAC_set_mdc_clk_div(synopGMACdevice *gmacdev,u32 clk_div_val)
47 {
48     u32 orig_data;
49     orig_data = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacGmiiAddr); //set the mdc clock to the user defined value
50     orig_data &= (~ GmiiCsrClkMask);
51     orig_data |= clk_div_val;
52     synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacGmiiAddr ,orig_data);
53     return 0;
54 }
55 
56 /**
57   * Returns the current MDC divider value programmed in the ip.
58   *
59   * @param[in] pointer to device structure.
60   * @param[in] clk divider value.
61   * \return Returns the MDC divider value read.
62   */
synopGMAC_get_mdc_clk_div(synopGMACdevice * gmacdev)63 u32 synopGMAC_get_mdc_clk_div(synopGMACdevice *gmacdev)
64 {
65     u32 data;
66     data = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacGmiiAddr);
67     data &= GmiiCsrClkMask;
68     return data;
69 }
70 
71 
72 
73 /**
74   * Function to read the Phy register. The access to phy register
75   * is a slow process as the data is moved accross MDI/MDO interface
76   * @param[in] pointer to Register Base (It is the mac base in our case) .
77   * @param[in] PhyBase register is the index of one of supported 32 PHY devices.
78   * @param[in] Register offset is the index of one of the 32 phy register.
79   * @param[out] u16 data read from the respective phy register (only valid iff return value is 0).
80   * \return Returns 0 on success else return the error status.
81   */
synopGMAC_read_phy_reg(u32 * RegBase,u32 PhyBase,u32 RegOffset,u16 * data)82 s32 synopGMAC_read_phy_reg(u32 *RegBase,u32 PhyBase, u32 RegOffset, u16 * data)
83 {
84     u32 addr;
85     u32 loop_variable;
86     addr = ((PhyBase << GmiiDevShift) & GmiiDevMask) | ((RegOffset << GmiiRegShift) & GmiiRegMask);
87     addr = addr  | GmiiCsrClk0 | GmiiBusy ; //Gmii busy bit
88 
89     synopGMACWriteReg(RegBase,GmacGmiiAddr,addr); //write the address from where the data to be read in GmiiGmiiAddr register of synopGMAC ip
90 
91     for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++) { //Wait till the busy bit gets cleared with in a certain amount of time
92         if (!(synopGMACReadReg(RegBase,GmacGmiiAddr) & GmiiBusy)) {
93             break;
94         }
95         plat_delay(DEFAULT_DELAY_VARIABLE);
96     }
97     if(loop_variable < DEFAULT_LOOP_VARIABLE)
98         * data = (u16)(synopGMACReadReg(RegBase,GmacGmiiData) & 0xFFFF);
99     else {
100         TR("Error::: PHY not responding Busy bit didnot get cleared !!!!!!\n");
101         return -ESYNOPGMACPHYERR;
102     }
103     return 0;
104 }
105 
106 /**
107   * Function to write to the Phy register. The access to phy register
108   * is a slow process as the data is moved accross MDI/MDO interface
109   * @param[in] pointer to Register Base (It is the mac base in our case) .
110   * @param[in] PhyBase register is the index of one of supported 32 PHY devices.
111   * @param[in] Register offset is the index of one of the 32 phy register.
112   * @param[in] data to be written to the respective phy register.
113   * \return Returns 0 on success else return the error status.
114   */
synopGMAC_write_phy_reg(u32 * RegBase,u32 PhyBase,u32 RegOffset,u16 data)115 s32 synopGMAC_write_phy_reg(u32 *RegBase, u32 PhyBase, u32 RegOffset, u16 data)
116 {
117     u32 addr;
118     u32 loop_variable;
119 
120     synopGMACWriteReg(RegBase,GmacGmiiData,data); // write the data in to GmacGmiiData register of synopGMAC ip
121 
122     addr = ((PhyBase << GmiiDevShift) & GmiiDevMask) | ((RegOffset << GmiiRegShift) & GmiiRegMask) | GmiiWrite;
123 
124     addr = addr | GmiiCsrClk0 | GmiiBusy ; //set Gmii clk to 20-35 Mhz and Gmii busy bit
125 
126     synopGMACWriteReg(RegBase,GmacGmiiAddr,addr);
127     for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++) {
128         if (!(synopGMACReadReg(RegBase,GmacGmiiAddr) & GmiiBusy)) {
129             break;
130         }
131         plat_delay(DEFAULT_DELAY_VARIABLE);
132     }
133 
134     if(loop_variable < DEFAULT_LOOP_VARIABLE) {
135         return 0;
136     } else {
137         TR("Error::: PHY not responding Busy bit didnot get cleared !!!!!!\n");
138         return -ESYNOPGMACPHYERR;
139     }
140 }
141 
142 /**
143   * Function to configure the phy in loopback mode.
144   *
145   * @param[in] pointer to synopGMACdevice.
146   * @param[in] enable or disable the loopback.
147   * \return 0 on success else return the error status.
148   * \note Don't get confused with mac loop-back synopGMAC_loopback_on(synopGMACdevice *)
149   * and synopGMAC_loopback_off(synopGMACdevice *) functions.
150   */
synopGMAC_phy_loopback(synopGMACdevice * gmacdev,bool loopback)151 s32 synopGMAC_phy_loopback(synopGMACdevice *gmacdev, bool loopback)
152 {
153     s32 status = 0;
154 #ifndef EMULATION
155     if(loopback)
156         status = synopGMAC_write_phy_reg((u32 *)gmacdev->MacBase, gmacdev->PhyBase, PHY_CONTROL_REG, Mii_Loopback);
157     else
158         status = synopGMAC_write_phy_reg((u32 *)gmacdev->MacBase, gmacdev->PhyBase, PHY_CONTROL_REG, Mii_NoLoopback);
159 #endif
160     return status;
161 }
162 
163 
164 
165 /**
166   * Function to read the GMAC IP Version and populates the same in device data structure.
167   * @param[in] pointer to synopGMACdevice.
168   * \return Always return 0.
169   */
170 
synopGMAC_read_version(synopGMACdevice * gmacdev)171 s32 synopGMAC_read_version (synopGMACdevice * gmacdev)
172 {
173     u32 data = 0;
174 
175     data = synopGMACReadReg((u32 *)gmacdev->MacBase, GmacVersion );
176     gmacdev->Version = data;
177     TR("The data read from %08x is %08x\n",(gmacdev->MacBase+GmacVersion),data);
178     return 0;
179 }
180 
181 
182 /**
183   * Function to reset the GMAC core.
184   * This reests the DMA and GMAC core. After reset all the registers holds their respective reset value
185   * @param[in] pointer to synopGMACdevice.
186   * \return 0 on success else return the error status.
187   */
188 
synopGMAC_reset(synopGMACdevice * gmacdev)189 s32 synopGMAC_reset (synopGMACdevice * gmacdev )
190 {
191     u32 data = 0;
192     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaBusMode ,DmaResetOn);
193     plat_delay(DEFAULT_LOOP_VARIABLE);
194 
195     do {
196     	data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaBusMode);
197     }while(data & 1);
198 
199     TR("DATA after Reset = %08x\n",data);
200 
201     return 0;
202 }
203 
synopGMAC_reset_nocheck(synopGMACdevice * gmacdev)204 s32 synopGMAC_reset_nocheck (synopGMACdevice * gmacdev )
205 {
206     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaBusMode ,DmaResetOn);
207     plat_delay(DEFAULT_LOOP_VARIABLE);
208 
209     TR("DATA after Reset = %08x\n",data);
210 
211     return 0;
212 }
213 
214 /**
215   * Function to program DMA bus mode register.
216   *
217   * The Bus Mode register is programmed with the value given. The bits to be set are
218   * bit wise or'ed and sent as the second argument to this function.
219   * @param[in] pointer to synopGMACdevice.
220   * @param[in] the data to be programmed.
221   * \return 0 on success else return the error status.
222   */
synopGMAC_dma_bus_mode_init(synopGMACdevice * gmacdev,u32 init_value)223 s32 synopGMAC_dma_bus_mode_init(synopGMACdevice * gmacdev, u32 init_value )
224 {
225     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaBusMode ,init_value);
226     return 0;
227 
228 }
229 
230 /**
231   * Function to program DMA Control register.
232   *
233   * The Dma Control register is programmed with the value given. The bits to be set are
234   * bit wise or'ed and sent as the second argument to this function.
235   * @param[in] pointer to synopGMACdevice.
236   * @param[in] the data to be programmed.
237   * \return 0 on success else return the error status.
238   */
synopGMAC_dma_control_init(synopGMACdevice * gmacdev,u32 init_value)239 s32 synopGMAC_dma_control_init(synopGMACdevice * gmacdev, u32 init_value)
240 {
241     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl, init_value);
242     return 0;
243 }
244 
245 
246 /*Gmac configuration functions*/
247 
248 /**
249   * Enable the watchdog timer on the receiver.
250   * When enabled, Gmac enables Watchdog timer, and GMAC allows no more than
251   * 2048 bytes of data (10,240 if Jumbo frame enabled).
252   * @param[in] pointer to synopGMACdevice.
253   * \return returns void.
254   */
synopGMAC_wd_enable(synopGMACdevice * gmacdev)255 void synopGMAC_wd_enable(synopGMACdevice * gmacdev)
256 {
257     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacWatchdog);
258     return;
259 }
260 /**
261   * Disable the watchdog timer on the receiver.
262   * When disabled, Gmac disabled watchdog timer, and can receive frames up to
263   * 16,384 bytes.
264   * @param[in] pointer to synopGMACdevice.
265   * \return returns void.
266   */
synopGMAC_wd_disable(synopGMACdevice * gmacdev)267 void synopGMAC_wd_disable(synopGMACdevice * gmacdev)
268 {
269     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacWatchdog);
270     return;
271 }
272 
273 /**
274   * Enables the Jabber frame support.
275   * When enabled, GMAC disabled the jabber timer, and can transfer 16,384 byte frames.
276   * @param[in] pointer to synopGMACdevice.
277   * \return returns void.
278   */
synopGMAC_jab_enable(synopGMACdevice * gmacdev)279 void synopGMAC_jab_enable(synopGMACdevice * gmacdev)
280 {
281     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacJabber);
282     return;
283 }
284 /**
285   * Disables the Jabber frame support.
286   * When disabled, GMAC enables jabber timer. It cuts of transmitter if application
287   * sends more than 2048 bytes of data (10240 if Jumbo frame enabled).
288   * @param[in] pointer to synopGMACdevice.
289   * \return returns void.
290   */
synopGMAC_jab_disable(synopGMACdevice * gmacdev)291 void synopGMAC_jab_disable(synopGMACdevice * gmacdev)
292 {
293     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacJabber);
294     return;
295 }
296 
297 /**
298   * Enables Frame bursting (Only in Half Duplex Mode).
299   * When enabled, GMAC allows frame bursting in GMII Half Duplex mode.
300   * Reserved in 10/100 and Full-Duplex configurations.
301   * @param[in] pointer to synopGMACdevice.
302   * \return returns void.
303   */
synopGMAC_frame_burst_enable(synopGMACdevice * gmacdev)304 void synopGMAC_frame_burst_enable(synopGMACdevice * gmacdev)
305 {
306     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacFrameBurst);
307     return;
308 }
309 /**
310   * Disables Frame bursting.
311   * When Disabled, frame bursting is not supported.
312   * @param[in] pointer to synopGMACdevice.
313   * \return returns void.
314   */
synopGMAC_frame_burst_disable(synopGMACdevice * gmacdev)315 void synopGMAC_frame_burst_disable(synopGMACdevice * gmacdev)
316 {
317     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacFrameBurst);
318     return;
319 }
320 
321 /**
322   * Enable Jumbo frame support.
323   * When Enabled GMAC supports jumbo frames of 9018/9022(VLAN tagged).
324   * Giant frame error is not reported in receive frame status.
325   * @param[in] pointer to synopGMACdevice.
326   * \return returns void.
327   */
synopGMAC_jumbo_frame_enable(synopGMACdevice * gmacdev)328 void synopGMAC_jumbo_frame_enable(synopGMACdevice * gmacdev)
329 {
330     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacJumboFrame);
331     return;
332 }
333 /**
334   * Disable Jumbo frame support.
335   * When Disabled GMAC does not supports jumbo frames.
336   * Giant frame error is reported in receive frame status.
337   * @param[in] pointer to synopGMACdevice.
338   * \return returns void.
339   */
synopGMAC_jumbo_frame_disable(synopGMACdevice * gmacdev)340 void synopGMAC_jumbo_frame_disable(synopGMACdevice * gmacdev)
341 {
342     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacJumboFrame);
343     return;
344 }
345 
346 /**
347   * Disable Carrier sense.
348   * When Disabled GMAC ignores CRS signal during frame transmission
349   * in half duplex mode.
350   * @param[in] pointer to synopGMACdevice.
351   * \return void.
352   */
353 
synopGMAC_disable_crs(synopGMACdevice * gmacdev)354 void synopGMAC_disable_crs(synopGMACdevice * gmacdev)
355 {
356     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacDisableCrs);
357     return;
358 }
359 
360 
361 
362 /**
363   * Selects the GMII port.
364   * When called GMII (1000Mbps) port is selected (programmable only in 10/100/1000 Mbps configuration).
365   * @param[in] pointer to synopGMACdevice.
366   * \return returns void.
367   */
synopGMAC_select_gmii(synopGMACdevice * gmacdev)368 void synopGMAC_select_gmii(synopGMACdevice * gmacdev)
369 {
370     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacMiiGmii);
371     return;
372 }
373 /**
374   * Selects the MII port.
375   * When called MII (10/100Mbps) port is selected (programmable only in 10/100/1000 Mbps configuration).
376   * @param[in] pointer to synopGMACdevice.
377   * \return returns void.
378   */
synopGMAC_select_mii(synopGMACdevice * gmacdev)379 void synopGMAC_select_mii(synopGMACdevice * gmacdev)
380 {
381     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacMiiGmii);
382     return;
383 }
384 
385 /**
386   * Enables Receive Own bit (Only in Half Duplex Mode).
387   * When enaled GMAC receives all the packets given by phy while transmitting.
388   * @param[in] pointer to synopGMACdevice.
389   * \return returns void.
390   */
synopGMAC_rx_own_enable(synopGMACdevice * gmacdev)391 void synopGMAC_rx_own_enable(synopGMACdevice * gmacdev)
392 {
393     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacRxOwn);
394     return;
395 }
396 /**
397   * Disables Receive Own bit (Only in Half Duplex Mode).
398   * When enaled GMAC disables the reception of frames when gmii_txen_o is asserted.
399   * @param[in] pointer to synopGMACdevice.
400   * \return returns void.
401   */
synopGMAC_rx_own_disable(synopGMACdevice * gmacdev)402 void synopGMAC_rx_own_disable(synopGMACdevice * gmacdev)
403 {
404     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacRxOwn);
405     return;
406 }
407 
408 /**
409   * Sets the GMAC in loopback mode.
410   * When on GMAC operates in loop-back mode at GMII/MII.
411   * @param[in] pointer to synopGMACdevice.
412   * \return returns void.
413   * \note (G)MII Receive clock is required for loopback to work properly, as transmit clock is
414   * not looped back internally.
415   */
synopGMAC_loopback_on(synopGMACdevice * gmacdev)416 void synopGMAC_loopback_on(synopGMACdevice * gmacdev)
417 {
418     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacLoopback);
419     return;
420 }
421 /**
422   * Sets the GMAC in Normal mode.
423   * @param[in] pointer to synopGMACdevice.
424   * \return returns void.
425   */
synopGMAC_loopback_off(synopGMACdevice * gmacdev)426 void synopGMAC_loopback_off(synopGMACdevice * gmacdev)
427 {
428     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacLoopback);
429     return;
430 }
431 
432 /**
433   * Sets the GMAC core in Full-Duplex mode.
434   * @param[in] pointer to synopGMACdevice.
435   * \return returns void.
436   */
synopGMAC_set_full_duplex(synopGMACdevice * gmacdev)437 void synopGMAC_set_full_duplex(synopGMACdevice * gmacdev)
438 {
439     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacDuplex);
440     return;
441 }
442 /**
443   * Sets the GMAC core in Half-Duplex mode.
444   * @param[in] pointer to synopGMACdevice.
445   * \return returns void.
446   */
synopGMAC_set_half_duplex(synopGMACdevice * gmacdev)447 void synopGMAC_set_half_duplex(synopGMACdevice * gmacdev)
448 {
449     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacDuplex);
450     return;
451 }
452 
453 /**
454   * GMAC tries retransmission (Only in Half Duplex mode).
455   * If collision occurs on the GMII/MII, GMAC attempt retries based on the
456   * back off limit configured.
457   * @param[in] pointer to synopGMACdevice.
458   * \return returns void.
459   * \note This function is tightly coupled with synopGMAC_back_off_limit(synopGMACdev *, u32).
460   */
synopGMAC_retry_enable(synopGMACdevice * gmacdev)461 void synopGMAC_retry_enable(synopGMACdevice * gmacdev)
462 {
463     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacRetry);
464     return;
465 }
466 /**
467   * GMAC tries only one transmission (Only in Half Duplex mode).
468   * If collision occurs on the GMII/MII, GMAC will ignore the current frami
469   * transmission and report a frame abort with excessive collision in tranmit frame status.
470   * @param[in] pointer to synopGMACdevice.
471   * \return returns void.
472   */
synopGMAC_retry_disable(synopGMACdevice * gmacdev)473 void synopGMAC_retry_disable(synopGMACdevice * gmacdev)
474 {
475     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacRetry);
476     return;
477 }
478 
479 /**
480   * GMAC strips the Pad/FCS field of incoming frames.
481   * This is true only if the length field value is less than or equal to
482   * 1500 bytes. All received frames with length field greater than or equal to
483   * 1501 bytes are passed to the application without stripping the Pad/FCS field.
484   * @param[in] pointer to synopGMACdevice.
485   * \return returns void.
486   */
synopGMAC_pad_crc_strip_enable(synopGMACdevice * gmacdev)487 void synopGMAC_pad_crc_strip_enable(synopGMACdevice * gmacdev)
488 {
489     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacPadCrcStrip);
490     return;
491 }
492 /**
493   * GMAC doesnot strips the Pad/FCS field of incoming frames.
494   * GMAC will pass all the incoming frames to Host unmodified.
495   * @param[in] pointer to synopGMACdevice.
496   * \return returns void.
497   */
synopGMAC_pad_crc_strip_disable(synopGMACdevice * gmacdev)498 void synopGMAC_pad_crc_strip_disable(synopGMACdevice * gmacdev)
499 {
500     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacPadCrcStrip);
501     return;
502 }
503 /**
504   * GMAC programmed with the back off limit value.
505   * @param[in] pointer to synopGMACdevice.
506   * \return returns void.
507   * \note This function is tightly coupled with synopGMAC_retry_enable(synopGMACdevice * gmacdev)
508   */
synopGMAC_back_off_limit(synopGMACdevice * gmacdev,u32 value)509 void synopGMAC_back_off_limit(synopGMACdevice * gmacdev, u32 value)
510 {
511     u32 data;
512     data = synopGMACReadReg((u32 *)gmacdev->MacBase, GmacConfig);
513     data &= (~GmacBackoffLimit);
514     data |= value;
515     synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacConfig,data);
516     return;
517 }
518 
519 /**
520   * Enables the Deferral check in GMAC (Only in Half Duplex mode)
521   * GMAC issues a Frame Abort Status, along with the excessive deferral error bit set in the
522   * transmit frame status when transmit state machine is deferred for more than
523   *     - 24,288 bit times in 10/100Mbps mode
524   *     - 155,680 bit times in 1000Mbps mode or Jumbo frame mode in 10/100Mbps operation.
525   * @param[in] pointer to synopGMACdevice.
526   * \return returns void.
527   * \note Deferral begins when transmitter is ready to transmit, but is prevented because  of
528   * an active CRS (carrier sense)
529   */
synopGMAC_deferral_check_enable(synopGMACdevice * gmacdev)530 void synopGMAC_deferral_check_enable(synopGMACdevice * gmacdev)
531 {
532     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacDeferralCheck);
533     return;
534 }
535 /**
536   * Disables the Deferral check in GMAC (Only in Half Duplex mode).
537   * GMAC defers until the CRS signal goes inactive.
538   * @param[in] pointer to synopGMACdevice.
539   * \return returns void.
540   */
synopGMAC_deferral_check_disable(synopGMACdevice * gmacdev)541 void synopGMAC_deferral_check_disable(synopGMACdevice * gmacdev)
542 {
543     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacDeferralCheck);
544     return;
545 }
546 /**
547   * Enable the reception of frames on GMII/MII.
548   * @param[in] pointer to synopGMACdevice.
549   * \return returns void.
550   */
synopGMAC_rx_enable(synopGMACdevice * gmacdev)551 void synopGMAC_rx_enable(synopGMACdevice * gmacdev)
552 {
553     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacRx);
554     return;
555 }
556 /**
557   * Disable the reception of frames on GMII/MII.
558   * GMAC receive state machine is disabled after completion of reception of current frame.
559   * @param[in] pointer to synopGMACdevice.
560   * \return returns void.
561   */
synopGMAC_rx_disable(synopGMACdevice * gmacdev)562 void synopGMAC_rx_disable(synopGMACdevice * gmacdev)
563 {
564     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacRx);
565     return;
566 }
567 /**
568   * Enable the transmission of frames on GMII/MII.
569   * @param[in] pointer to synopGMACdevice.
570   * \return returns void.
571   */
synopGMAC_tx_enable(synopGMACdevice * gmacdev)572 void synopGMAC_tx_enable(synopGMACdevice * gmacdev)
573 {
574     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacConfig, GmacTx);
575     return;
576 }
577 /**
578   * Disable the transmission of frames on GMII/MII.
579   * GMAC transmit state machine is disabled after completion of transmission of current frame.
580   * @param[in] pointer to synopGMACdevice.
581   * \return returns void.
582   */
synopGMAC_tx_disable(synopGMACdevice * gmacdev)583 void synopGMAC_tx_disable(synopGMACdevice * gmacdev)
584 {
585     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacConfig, GmacTx);
586     return;
587 }
588 
589 
590 /*Receive frame filter configuration functions*/
591 
592 /**
593   * Enables reception of all the frames to application.
594   * GMAC passes all the frames received to application irrespective of whether they
595   * pass SA/DA address filtering or not.
596   * @param[in] pointer to synopGMACdevice.
597   * \return returns void.
598   */
synopGMAC_frame_filter_enable(synopGMACdevice * gmacdev)599 void synopGMAC_frame_filter_enable(synopGMACdevice * gmacdev)
600 {
601     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacFilter);
602     return;
603 }
604 /**
605   * Disables reception of all the frames to application.
606   * GMAC passes only those received frames to application which
607   * pass SA/DA address filtering.
608   * @param[in] pointer to synopGMACdevice.
609   * \return void.
610   */
synopGMAC_frame_filter_disable(synopGMACdevice * gmacdev)611 void synopGMAC_frame_filter_disable(synopGMACdevice * gmacdev)
612 {
613     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacFilter);
614     return;
615 }
616 
617 /**
618   * Populates the Hash High register with the data supplied.
619   * This function is called when the Hash filtering is to be enabled.
620   * @param[in] pointer to synopGMACdevice.
621   * @param[in] data to be written to hash table high register.
622   * \return void.
623   */
synopGMAC_write_hash_table_high(synopGMACdevice * gmacdev,u32 data)624 void synopGMAC_write_hash_table_high(synopGMACdevice * gmacdev, u32 data)
625 {
626     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacHashHigh,data);
627     return;
628 }
629 
630 /**
631   * Populates the Hash Low register with the data supplied.
632   * This function is called when the Hash filtering is to be enabled.
633   * @param[in] pointer to synopGMACdevice.
634   * @param[in] data to be written to hash table low register.
635   * \return void.
636   */
synopGMAC_write_hash_table_low(synopGMACdevice * gmacdev,u32 data)637 void synopGMAC_write_hash_table_low(synopGMACdevice * gmacdev, u32 data)
638 {
639     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacHashLow,data);
640     return;
641 }
642 
643 /**
644   * Enables Hash or Perfect filter (only if Hash filter is enabled in H/W).
645   * Only frames matching either perfect filtering or Hash Filtering as per HMC and HUC
646   * configuration are sent to application.
647   * @param[in] pointer to synopGMACdevice.
648   * \return void.
649   */
synopGMAC_hash_perfect_filter_enable(synopGMACdevice * gmacdev)650 void synopGMAC_hash_perfect_filter_enable(synopGMACdevice * gmacdev)
651 {
652     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacHashPerfectFilter);
653     return;
654 }
655 
656 /**
657   * Enables only Hash(only if Hash filter is enabled in H/W).
658   * Only frames matching Hash Filtering as per HMC and HUC
659   * configuration are sent to application.
660   * @param[in] pointer to synopGMACdevice.
661   * \return void.
662   */
synopGMAC_Hash_filter_only_enable(synopGMACdevice * gmacdev)663 void synopGMAC_Hash_filter_only_enable(synopGMACdevice * gmacdev)
664 {
665     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacHashPerfectFilter);
666     return;
667 }
668 
669 /**
670   * Enables Source address filtering.
671   * When enabled source address filtering is performed. Only frames matching SA filtering are passed  to application with
672   * SAMatch bit of RxStatus is set. GMAC drops failed frames.
673   * @param[in] pointer to synopGMACdevice.
674   * \return void.
675   * \note This function is overriden by synopGMAC_frame_filter_disable(synopGMACdevice *)
676   */
synopGMAC_src_addr_filter_enable(synopGMACdevice * gmacdev)677 void synopGMAC_src_addr_filter_enable(synopGMACdevice * gmacdev)
678 {
679     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacSrcAddrFilter);
680     return;
681 }
682 /**
683   * Disables Source address filtering.
684   * When disabled GMAC forwards the received frames with updated SAMatch bit in RxStatus.
685   * @param[in] pointer to synopGMACdevice.
686   * \return void.
687   */
synopGMAC_src_addr_filter_disable(synopGMACdevice * gmacdev)688 void synopGMAC_src_addr_filter_disable(synopGMACdevice * gmacdev)
689 {
690     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacSrcAddrFilter);
691     return;
692 }
693 /**
694   * Enables Inverse Destination address filtering.
695   * @param[in] pointer to synopGMACdevice.
696   * \return void.
697   */
synopGMAC_dst_addr_filter_inverse(synopGMACdevice * gmacdev)698 void synopGMAC_dst_addr_filter_inverse(synopGMACdevice * gmacdev)
699 {
700     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacDestAddrFilterNor);
701     return;
702 }
703 /**
704   * Enables the normal Destination address filtering.
705   * @param[in] pointer to synopGMACdevice.
706   * \return void.
707   */
synopGMAC_dst_addr_filter_normal(synopGMACdevice * gmacdev)708 void synopGMAC_dst_addr_filter_normal(synopGMACdevice * gmacdev)
709 {
710     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacDestAddrFilterNor);
711     return;
712 }
713 
714 /**
715   * Enables forwarding of control frames.
716   * When set forwards all the control frames (incl. unicast and multicast PAUSE frames).
717   * @param[in] pointer to synopGMACdevice.
718   * \return void.
719   * \note Depends on RFE of FlowControlRegister[2]
720   */
synopGMAC_set_pass_control(synopGMACdevice * gmacdev,u32 passcontrol)721 void synopGMAC_set_pass_control(synopGMACdevice * gmacdev,u32 passcontrol)
722 {
723     u32 data;
724     data = synopGMACReadReg((u32 *)gmacdev->MacBase, GmacFrameFilter);
725     data &= (~GmacPassControl);
726     data |= passcontrol;
727     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacFrameFilter,data);
728     return;
729 }
730 
731 /**
732   * Enables Broadcast frames.
733   * When enabled Address filtering module passes all incoming broadcast frames.
734   * @param[in] pointer to synopGMACdevice.
735   * \return void.
736   */
synopGMAC_broadcast_enable(synopGMACdevice * gmacdev)737 void synopGMAC_broadcast_enable(synopGMACdevice * gmacdev)
738 {
739     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacBroadcast);
740     return;
741 }
742 /**
743   * Disable Broadcast frames.
744   * When disabled Address filtering module filters all incoming broadcast frames.
745   * @param[in] pointer to synopGMACdevice.
746   * \return void.
747   */
synopGMAC_broadcast_disable(synopGMACdevice * gmacdev)748 void synopGMAC_broadcast_disable(synopGMACdevice * gmacdev)
749 {
750     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacBroadcast);
751     return;
752 }
753 
754 /**
755   * Enables Multicast frames.
756   * When enabled all multicast frames are passed.
757   * @param[in] pointer to synopGMACdevice.
758   * \return void.
759   */
synopGMAC_multicast_enable(synopGMACdevice * gmacdev)760 void synopGMAC_multicast_enable(synopGMACdevice * gmacdev)
761 {
762     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacMulticastFilter);
763     return;
764 }
765 /**
766   * Disable Multicast frames.
767   * When disabled multicast frame filtering depends on HMC bit.
768   * @param[in] pointer to synopGMACdevice.
769   * \return void.
770   */
synopGMAC_multicast_disable(synopGMACdevice * gmacdev)771 void synopGMAC_multicast_disable(synopGMACdevice * gmacdev)
772 {
773     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacMulticastFilter);
774     return;
775 }
776 
777 /**
778   * Enables multicast hash filtering.
779   * When enabled GMAC performs teh destination address filtering according to the hash table.
780   * @param[in] pointer to synopGMACdevice.
781   * \return void.
782   */
synopGMAC_multicast_hash_filter_enable(synopGMACdevice * gmacdev)783 void synopGMAC_multicast_hash_filter_enable(synopGMACdevice * gmacdev)
784 {
785     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacMcastHashFilter);
786     return;
787 }
788 /**
789   * Disables multicast hash filtering.
790   * When disabled GMAC performs perfect destination address filtering for multicast frames, it compares
791   * DA field with the value programmed in DA register.
792   * @param[in] pointer to synopGMACdevice.
793   * \return void.
794   */
synopGMAC_multicast_hash_filter_disable(synopGMACdevice * gmacdev)795 void synopGMAC_multicast_hash_filter_disable(synopGMACdevice * gmacdev)
796 {
797     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacMcastHashFilter);
798     return;
799 }
800 
801 /**
802   * Enables promiscous mode.
803   * When enabled Address filter modules pass all incoming frames regardless of their Destination
804   * and source addresses.
805   * @param[in] pointer to synopGMACdevice.
806   * \return void.
807   */
synopGMAC_promisc_enable(synopGMACdevice * gmacdev)808 void synopGMAC_promisc_enable(synopGMACdevice * gmacdev)
809 {
810     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacPromiscuousMode);
811     return;
812 }
813 /**
814   * Clears promiscous mode.
815   * When called the GMAC falls back to normal operation from promiscous mode.
816   * @param[in] pointer to synopGMACdevice.
817   * \return void.
818   */
synopGMAC_promisc_disable(synopGMACdevice * gmacdev)819 void synopGMAC_promisc_disable(synopGMACdevice * gmacdev)
820 {
821     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacPromiscuousMode);
822     return;
823 }
824 
825 
826 /**
827   * Enables unicast hash filtering.
828   * When enabled GMAC performs the destination address filtering of unicast frames according to the hash table.
829   * @param[in] pointer to synopGMACdevice.
830   * \return void.
831   */
synopGMAC_unicast_hash_filter_enable(synopGMACdevice * gmacdev)832 void synopGMAC_unicast_hash_filter_enable(synopGMACdevice * gmacdev)
833 {
834     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacUcastHashFilter);
835     return;
836 }
837 /**
838   * Disables multicast hash filtering.
839   * When disabled GMAC performs perfect destination address filtering for unicast frames, it compares
840   * DA field with the value programmed in DA register.
841   * @param[in] pointer to synopGMACdevice.
842   * \return void.
843   */
synopGMAC_unicast_hash_filter_disable(synopGMACdevice * gmacdev)844 void synopGMAC_unicast_hash_filter_disable(synopGMACdevice * gmacdev)
845 {
846     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFrameFilter, GmacUcastHashFilter);
847     return;
848 }
849 
850 /*Flow control configuration functions*/
851 
852 /**
853   * Enables detection of pause frames with stations unicast address.
854   * When enabled GMAC detects the pause frames with stations unicast address in addition to the
855   * detection of pause frames with unique multicast address.
856   * @param[in] pointer to synopGMACdevice.
857   * \return void.
858   */
synopGMAC_unicast_pause_frame_detect_enable(synopGMACdevice * gmacdev)859 void synopGMAC_unicast_pause_frame_detect_enable(synopGMACdevice * gmacdev)
860 {
861     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacUnicastPauseFrame);
862     return;
863 }
864 /**
865   * Disables detection of pause frames with stations unicast address.
866   * When disabled GMAC only detects with the unique multicast address (802.3x).
867   * @param[in] pointer to synopGMACdevice.
868   * \return void.
869   */
synopGMAC_unicast_pause_frame_detect_disable(synopGMACdevice * gmacdev)870 void synopGMAC_unicast_pause_frame_detect_disable(synopGMACdevice * gmacdev)
871 {
872     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacUnicastPauseFrame);
873     return;
874 }
875 /**
876   * Rx flow control enable.
877   * When Enabled GMAC will decode the rx pause frame and disable the tx for a specified time.
878   * @param[in] pointer to synopGMACdevice.
879   * \return void.
880   */
synopGMAC_rx_flow_control_enable(synopGMACdevice * gmacdev)881 void synopGMAC_rx_flow_control_enable(synopGMACdevice * gmacdev)
882 {
883     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacRxFlowControl);
884     return;
885 }
886 /**
887   * Rx flow control disable.
888   * When disabled GMAC will not decode pause frame.
889   * @param[in] pointer to synopGMACdevice.
890   * \return void.
891   */
synopGMAC_rx_flow_control_disable(synopGMACdevice * gmacdev)892 void synopGMAC_rx_flow_control_disable(synopGMACdevice * gmacdev)
893 {
894     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacRxFlowControl);
895     return;
896 }
897 /**
898   * Tx flow control enable.
899   * When Enabled
900   *     - In full duplex GMAC enables flow control operation to transmit pause frames.
901   * - In Half duplex GMAC enables the back pressure operation
902   * @param[in] pointer to synopGMACdevice.
903   * \return void.
904   */
synopGMAC_tx_flow_control_enable(synopGMACdevice * gmacdev)905 void synopGMAC_tx_flow_control_enable(synopGMACdevice * gmacdev)
906 {
907     synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacTxFlowControl);
908     return;
909 }
910 
911 /**
912   * Tx flow control disable.
913   * When Disabled
914   *     - In full duplex GMAC will not transmit any pause frames.
915   * - In Half duplex GMAC disables the back pressure feature.
916   * @param[in] pointer to synopGMACdevice.
917   * \return void.
918   */
synopGMAC_tx_flow_control_disable(synopGMACdevice * gmacdev)919 void synopGMAC_tx_flow_control_disable(synopGMACdevice * gmacdev)
920 {
921     synopGMACClearBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacTxFlowControl);
922     return;
923 }
924 
925 /**
926   * Initiate Flowcontrol operation.
927   * When Set
928   *     - In full duplex GMAC initiates pause control frame.
929   * - In Half duplex GMAC initiates back pressure function.
930   * @param[in] pointer to synopGMACdevice.
931   * \return void.
932   */
synopGMAC_tx_activate_flow_control(synopGMACdevice * gmacdev)933 void synopGMAC_tx_activate_flow_control(synopGMACdevice * gmacdev)
934 {
935     //In case of full duplex check for this bit to b'0. if it is read as b'1 indicates that
936     //control frame transmission is in progress.
937     if(gmacdev->Speed == FULLDUPLEX) {
938         if(!synopGMACCheckBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure))
939             synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure);
940     } else { //if half duplex mode
941 
942         synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure);
943     }
944 
945     return;
946 }
947 
948 /**
949   * stops Flowcontrol operation.
950   * @param[in] pointer to synopGMACdevice.
951   * \return void.
952   */
synopGMAC_tx_deactivate_flow_control(synopGMACdevice * gmacdev)953 void synopGMAC_tx_deactivate_flow_control(synopGMACdevice * gmacdev)
954 {
955     //In full duplex this bit is automatically cleared after transmitting a pause control frame.
956     if(gmacdev->Speed == HALFDUPLEX) {
957         synopGMACSetBits((u32 *)gmacdev->MacBase, GmacFlowControl, GmacFlowControlBackPressure);
958     }
959     return;
960 }
961 
962 /**
963   * This enables the pause frame generation after programming the appropriate registers.
964   * presently activation is set at 3k and deactivation set at 4k. These may have to tweaked
965   * if found any issues
966   * @param[in] pointer to synopGMACdevice.
967   * \return void.
968   */
synopGMAC_pause_control(synopGMACdevice * gmacdev)969 void synopGMAC_pause_control(synopGMACdevice *gmacdev)
970 {
971     u32 omr_reg;
972     u32 mac_flow_control_reg;
973     omr_reg = synopGMACReadReg((u32 *)gmacdev->DmaBase,DmaControl);
974     omr_reg |= DmaRxFlowCtrlAct4K | DmaRxFlowCtrlDeact5K |DmaEnHwFlowCtrl;
975     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl, omr_reg);
976 
977     mac_flow_control_reg = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacFlowControl);
978     mac_flow_control_reg |= GmacRxFlowControl | GmacTxFlowControl | 0xFFFF0000;
979     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacFlowControl,mac_flow_control_reg);
980 
981     return;
982 
983 }
984 
985 /**
986   * Example mac initialization sequence.
987   * This function calls the initialization routines to initialize the GMAC register.
988   * One can change the functions invoked here to have different configuration as per the requirement
989   * @param[in] pointer to synopGMACdevice.
990   * \return Returns 0 on success.
991   */
synopGMAC_mac_init(synopGMACdevice * gmacdev)992 s32 synopGMAC_mac_init(synopGMACdevice * gmacdev)
993 {
994     u32 PHYreg;
995 
996     if(gmacdev->DuplexMode == FULLDUPLEX) {
997         synopGMAC_wd_enable(gmacdev);
998         synopGMAC_jab_enable(gmacdev);
999         synopGMAC_frame_burst_enable(gmacdev);
1000         synopGMAC_jumbo_frame_disable(gmacdev);
1001         synopGMAC_rx_own_enable(gmacdev);
1002         synopGMAC_loopback_off(gmacdev);
1003         synopGMAC_set_full_duplex(gmacdev);
1004         synopGMAC_retry_enable(gmacdev);
1005         synopGMAC_pad_crc_strip_disable(gmacdev);
1006         synopGMAC_back_off_limit(gmacdev,GmacBackoffLimit0);
1007         synopGMAC_deferral_check_disable(gmacdev);
1008 
1009 
1010         if(gmacdev->Speed == SPEED1000)
1011             synopGMAC_select_gmii(gmacdev);
1012         else
1013             synopGMAC_select_mii(gmacdev);
1014 
1015         // Cannot enable tx/rx while changing Speed/mode.
1016         synopGMAC_tx_enable(gmacdev);
1017         synopGMAC_rx_enable(gmacdev);
1018         /*Frame Filter Configuration*/
1019         synopGMAC_frame_filter_enable(gmacdev);
1020         synopGMAC_set_pass_control(gmacdev,GmacPassControl0);
1021         synopGMAC_broadcast_enable(gmacdev);
1022         synopGMAC_src_addr_filter_disable(gmacdev);
1023         synopGMAC_multicast_disable(gmacdev);
1024         synopGMAC_dst_addr_filter_normal(gmacdev);
1025         synopGMAC_multicast_hash_filter_disable(gmacdev);
1026         synopGMAC_promisc_disable(gmacdev);
1027         synopGMAC_unicast_hash_filter_disable(gmacdev);
1028 
1029         /*Flow Control Configuration*/
1030         synopGMAC_unicast_pause_frame_detect_disable(gmacdev);
1031         synopGMAC_rx_flow_control_enable(gmacdev);
1032         synopGMAC_tx_flow_control_enable(gmacdev);
1033     } else { //for Half Duplex configuration
1034 
1035         synopGMAC_wd_enable(gmacdev);
1036         synopGMAC_jab_enable(gmacdev);
1037         synopGMAC_frame_burst_enable(gmacdev);
1038         synopGMAC_jumbo_frame_disable(gmacdev);
1039         synopGMAC_rx_own_enable(gmacdev);
1040         synopGMAC_loopback_off(gmacdev);
1041         synopGMAC_set_half_duplex(gmacdev);
1042         synopGMAC_retry_enable(gmacdev);
1043         synopGMAC_pad_crc_strip_disable(gmacdev);
1044         synopGMAC_back_off_limit(gmacdev,GmacBackoffLimit0);
1045         synopGMAC_deferral_check_disable(gmacdev);
1046 
1047 
1048         if(gmacdev->Speed == SPEED1000)
1049             synopGMAC_select_gmii(gmacdev);
1050         else
1051             synopGMAC_select_mii(gmacdev);
1052 
1053         synopGMAC_tx_enable(gmacdev);
1054         synopGMAC_rx_enable(gmacdev);
1055         /*Frame Filter Configuration*/
1056         synopGMAC_frame_filter_enable(gmacdev);
1057         synopGMAC_set_pass_control(gmacdev,GmacPassControl0);
1058         synopGMAC_broadcast_enable(gmacdev);
1059         synopGMAC_src_addr_filter_disable(gmacdev);
1060         synopGMAC_multicast_disable(gmacdev);
1061         synopGMAC_dst_addr_filter_normal(gmacdev);
1062         synopGMAC_multicast_hash_filter_disable(gmacdev);
1063         synopGMAC_promisc_disable(gmacdev);
1064         synopGMAC_unicast_hash_filter_disable(gmacdev);
1065 
1066         /*Flow Control Configuration*/
1067         synopGMAC_unicast_pause_frame_detect_disable(gmacdev);
1068         synopGMAC_rx_flow_control_disable(gmacdev);
1069         synopGMAC_tx_flow_control_disable(gmacdev);
1070 
1071         /*To set PHY register to enable CRS on Transmit*/
1072         synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacGmiiAddr, GmiiBusy | 0x00000408);
1073         PHYreg = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacGmiiData);
1074         synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacGmiiData, PHYreg   | 0x00000800);
1075         synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacGmiiAddr, GmiiBusy | 0x0000040a);
1076     }
1077     return 0;
1078 }
1079 
1080 
1081 /**
1082   * Checks and initialze phy.
1083   * This function checks whether the phy initialization is complete.
1084   * @param[in] pointer to synopGMACdevice.
1085   * \return 0 if success else returns the error number.
1086   */
synopGMAC_check_phy_init(synopGMACdevice * gmacdev)1087 s32 synopGMAC_check_phy_init (synopGMACdevice * gmacdev)
1088 {
1089     //u32 addr;
1090     u16 data;
1091     s32 status = 0;
1092     s32 loop_count;
1093 
1094     loop_count = DEFAULT_LOOP_VARIABLE;
1095     while(loop_count-- > 0) {
1096 
1097         status = synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase,gmacdev->PhyBase,PHY_STATUS_REG, &data);
1098         if(status)
1099             return status;
1100 
1101         if((data & Mii_AutoNegCmplt) != 0) {
1102             //printf("Autonegotiation Complete\n");
1103             break;
1104         }
1105     }
1106 
1107     status = synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase,gmacdev->PhyBase,PHY_SPECIFIC_STATUS_REG, &data);
1108     if(status)
1109         return status;
1110 
1111     if((data & Mii_phy_status_link_up) == 0) {
1112         //printf("No Link\n");
1113         gmacdev->LinkState = LINKDOWN;
1114         return -ESYNOPGMACPHYERR;
1115     } else {
1116         gmacdev->LinkState = LINKUP;
1117         //printf("Link UP\n");
1118     }
1119 
1120     status = synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase,gmacdev->PhyBase,PHY_SPECIFIC_STATUS_REG, &data);
1121     if(status)
1122         return status;
1123 
1124 
1125 
1126     gmacdev->DuplexMode = (data & Mii_phy_status_full_duplex)  ? FULLDUPLEX: HALFDUPLEX ;
1127     //printf("Link is up in %s mode\n",(gmacdev->DuplexMode == FULLDUPLEX) ? "FULL DUPLEX": "HALF DUPLEX");
1128 
1129     /*if not set to Master configuration in case of Half duplex mode set it manually as Master*/
1130     if(gmacdev->DuplexMode == HALFDUPLEX) {
1131         status = synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase,gmacdev->PhyBase,PHY_CONTROL_REG, &data);
1132         if(status)
1133             return status;
1134         //status = synopGMAC_write_phy_reg((u32 *)gmacdev->MacBase,gmacdev->PhyBase,PHY_CONTROL_REG, data | Mii_Manual_Master_Config );
1135         //if(status)
1136         //    return status;
1137     }
1138 
1139     status = synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase,gmacdev->PhyBase,PHY_SPECIFIC_STATUS_REG, &data);
1140     if(status)
1141         return status;
1142     if(data & Mii_phy_status_speed_1000)
1143         gmacdev->Speed      =   SPEED1000;
1144     else if(data & Mii_phy_status_speed_100)
1145         gmacdev->Speed      =   SPEED100;
1146     else
1147         gmacdev->Speed      =   SPEED10;
1148 
1149     return 0;
1150 }
1151 
1152 /**
1153   * Sets the Mac address in to GMAC register.
1154   * This function sets the MAC address to the MAC register in question.
1155   * @param[in] pointer to synopGMACdevice to populate mac dma and phy addresses.
1156   * @param[in] Register offset for Mac address high
1157   * @param[in] Register offset for Mac address low
1158   * @param[in] buffer containing mac address to be programmed.
1159   * \return 0 upon success. Error code upon failure.
1160   */
synopGMAC_set_mac_addr(synopGMACdevice * gmacdev,u32 MacHigh,u32 MacLow,u8 * MacAddr)1161 s32 synopGMAC_set_mac_addr(synopGMACdevice *gmacdev, u32 MacHigh, u32 MacLow, u8 *MacAddr)
1162 {
1163     u32 data;
1164 
1165     data = (MacAddr[5] << 8) | MacAddr[4];
1166     synopGMACWriteReg((u32 *)gmacdev->MacBase,MacHigh,data);
1167     data = (MacAddr[3] << 24) | (MacAddr[2] << 16) | (MacAddr[1] << 8) | MacAddr[0] ;
1168     synopGMACWriteReg((u32 *)gmacdev->MacBase,MacLow,data);
1169     return 0;
1170 }
1171 
1172 
1173 
1174 
1175 /**
1176   * Attaches the synopGMAC device structure to the hardware.
1177   * Device structure is populated with MAC/DMA and PHY base addresses.
1178   * @param[in] pointer to synopGMACdevice to populate mac dma and phy addresses.
1179   * @param[in] GMAC IP mac base address.
1180   * @param[in] GMAC IP dma base address.
1181   * @param[in] GMAC IP phy base address.
1182   * \return 0 upon success. Error code upon failure.
1183   * \note This is important function. No kernel api provided by Synopsys
1184   */
1185 
synopGMAC_attach(synopGMACdevice * gmacdev,u32 macBase,u32 dmaBase,u32 phyBase)1186 s32 synopGMAC_attach (synopGMACdevice *gmacdev, u32 macBase, u32 dmaBase, u32 phyBase)
1187 {
1188     u8 mac_addr0[6] = DEFAULT_MAC0_ADDRESS;
1189     u8 mac_addr1[6] = DEFAULT_MAC1_ADDRESS;
1190     /*Make sure the Device data strucure is cleared before we proceed further*/
1191     memset((void *) gmacdev,0,sizeof(synopGMACdevice));
1192     /*Populate the mac and dma base addresses*/
1193     gmacdev->MacBase = macBase;
1194     gmacdev->DmaBase = dmaBase;
1195     gmacdev->PhyBase = phyBase;
1196 
1197     /* Program/flash in the station/IP's Mac address */
1198     synopGMAC_set_mac_addr(gmacdev,GmacAddr0High,GmacAddr0Low, gmacdev->Intf == 0 ? mac_addr0 : mac_addr1);
1199 
1200     return 0;
1201 }
1202 
1203 
1204 
1205 /**
1206   * Initialize the rx descriptors for ring or chain mode operation.
1207   *     - Status field is initialized to 0.
1208   * - EndOfRing set for the last descriptor.
1209   * - buffer1 and buffer2 set to 0 for ring mode of operation. (note)
1210   * - data1 and data2 set to 0. (note)
1211   * @param[in] pointer to DmaDesc structure.
1212   * @param[in] whether end of ring
1213   * \return void.
1214   * \note Initialization of the buffer1, buffer2, data1,data2 and status are not done here. This only initializes whether one wants to use this descriptor
1215   * in chain mode or ring mode. For chain mode of operation the buffer2 and data2 are programmed before calling this function.
1216   */
synopGMAC_rx_desc_init_ring(DmaDesc * desc,bool last_ring_desc)1217 void synopGMAC_rx_desc_init_ring(DmaDesc *desc, bool last_ring_desc)
1218 {
1219     desc->status = 0;
1220     desc->length = last_ring_desc ? RxDescEndOfRing : 0;
1221     desc->buffer1 = 0;
1222     desc->buffer2 = 0;
1223     //desc->data1 = 0;
1224     //desc->data2 = 0;
1225     return;
1226 }
1227 /**
1228   * Initialize the tx descriptors for ring or chain mode operation.
1229   *     - Status field is initialized to 0.
1230   * - EndOfRing set for the last descriptor.
1231   * - buffer1 and buffer2 set to 0 for ring mode of operation. (note)
1232   * - data1 and data2 set to 0. (note)
1233   * @param[in] pointer to DmaDesc structure.
1234   * @param[in] whether end of ring
1235   * \return void.
1236   * \note Initialization of the buffer1, buffer2, data1,data2 and status are not done here. This only initializes whether one wants to use this descriptor
1237   * in chain mode or ring mode. For chain mode of operation the buffer2 and data2 are programmed before calling this function.
1238   */
synopGMAC_tx_desc_init_ring(DmaDesc * desc,bool last_ring_desc)1239 void synopGMAC_tx_desc_init_ring(DmaDesc *desc, bool last_ring_desc)
1240 {
1241 
1242     desc->status = last_ring_desc? TxDescEndOfRing : 0;
1243     desc->length = 0;
1244 
1245   //    desc->buffer1 = 0;  // Chris: to keep pointer for get-tx buffer
1246     desc->buffer2 = 0;
1247     //desc->data1 = 0;
1248     //desc->data2 = 0;
1249     return;
1250 }
1251 
synopGMAC_init_tx_rx_desc_queue(synopGMACdevice * gmacdev)1252 s32 synopGMAC_init_tx_rx_desc_queue(synopGMACdevice *gmacdev)
1253 {
1254     s32 i;
1255     for(i =0; i < gmacdev -> TxDescCount; i++) {
1256         synopGMAC_tx_desc_init_ring(gmacdev->TxDesc + i, i == gmacdev->TxDescCount-1);
1257     }
1258     TR("At line %d\n",__LINE__);
1259     for(i =0; i < gmacdev -> RxDescCount; i++) {
1260         synopGMAC_rx_desc_init_ring(gmacdev->RxDesc + i, i == gmacdev->RxDescCount-1);
1261     }
1262 
1263     gmacdev->TxNext = 0;
1264     gmacdev->TxBusy = 0;
1265     gmacdev->RxNext = 0;
1266     gmacdev->RxBusy = 0;
1267 
1268     return 0;
1269 }
1270 
1271 /**
1272   * Programs the DmaRxBaseAddress with the Rx descriptor base address.
1273   * Rx Descriptor's base address is available in the gmacdev structure. This function progrms the
1274   * Dma Rx Base address with the starting address of the descriptor ring or chain.
1275   * @param[in] pointer to synopGMACdevice.
1276   * \return returns void.
1277   */
synopGMAC_init_rx_desc_base(synopGMACdevice * gmacdev)1278 void synopGMAC_init_rx_desc_base(synopGMACdevice *gmacdev)
1279 {
1280     synopGMACWriteReg((u32 *)gmacdev->DmaBase,DmaRxBaseAddr,(u32)((u64)gmacdev->RxDescDma & 0xFFFFFFFF));
1281     return;
1282 }
1283 
1284 /**
1285   * Programs the DmaTxBaseAddress with the Tx descriptor base address.
1286   * Tx Descriptor's base address is available in the gmacdev structure. This function progrms the
1287   * Dma Tx Base address with the starting address of the descriptor ring or chain.
1288   * @param[in] pointer to synopGMACdevice.
1289   * \return returns void.
1290   */
synopGMAC_init_tx_desc_base(synopGMACdevice * gmacdev)1291 void synopGMAC_init_tx_desc_base(synopGMACdevice *gmacdev)
1292 {
1293     synopGMACWriteReg((u32 *)gmacdev->DmaBase,DmaTxBaseAddr,(u32)((u64)gmacdev->TxDescDma & 0xFFFFFFFF));
1294     return;
1295 }
1296 
1297 
1298 /**
1299   * Checks whether the descriptor is owned by DMA.
1300   * If descriptor is owned by DMA then the OWN bit is set to 1. This API is same for both ring and chain mode.
1301   * @param[in] pointer to DmaDesc structure.
1302   * \return returns true if Dma owns descriptor and false if not.
1303   */
synopGMAC_is_desc_owned_by_dma(DmaDesc * desc)1304 bool synopGMAC_is_desc_owned_by_dma(DmaDesc *desc)
1305 {
1306     return ((desc->status & DescOwnByDma) == DescOwnByDma );
1307 }
1308 
1309 /**
1310   * returns the byte length of received frame including CRC.
1311   * This returns the no of bytes received in the received ethernet frame including CRC(FCS).
1312   * @param[in] pointer to DmaDesc structure.
1313   * \return returns the length of received frame lengths in bytes.
1314   */
synopGMAC_get_rx_desc_frame_length(u32 status)1315 u32 synopGMAC_get_rx_desc_frame_length(u32 status)
1316 {
1317     return ((status & DescFrameLengthMask) >> DescFrameLengthShift);
1318 }
1319 
1320 /**
1321   * Checks whether the descriptor is valid
1322   * if no errors such as CRC/Receive Error/Watchdog Timeout/Late collision/Giant Frame/Overflow/Descriptor
1323   * error the descritpor is said to be a valid descriptor.
1324   * @param[in] pointer to DmaDesc structure.
1325   * \return True if desc valid. false if error.
1326   */
synopGMAC_is_desc_valid(u32 status)1327 bool synopGMAC_is_desc_valid(u32 status)
1328 {
1329     return ((status & DescError) == 0);
1330 }
1331 
1332 /**
1333   * Checks whether the descriptor is empty.
1334   * If the buffer1 and buffer2 lengths are zero in ring mode descriptor is empty.
1335   * In chain mode buffer2 length is 0 but buffer2 itself contains the next descriptor address.
1336   * @param[in] pointer to DmaDesc structure.
1337   * \return returns true if descriptor is empty, false if not empty.
1338   */
synopGMAC_is_desc_empty(DmaDesc * desc)1339 bool synopGMAC_is_desc_empty(DmaDesc *desc)
1340 {
1341     //if both the buffer1 length and buffer2 length are zero desc is empty
1342     return(((desc->length  & DescSize1Mask) == 0) && ((desc->length  & DescSize2Mask) == 0) );
1343 }
1344 
1345 
1346 /**
1347   * Checks whether the rx descriptor is valid.
1348   * if rx descripor is not in error and complete frame is available in the same descriptor
1349   * @param[in] pointer to DmaDesc structure.
1350   * \return returns true if no error and first and last desc bits are set, otherwise it returns false.
1351   */
synopGMAC_is_rx_desc_valid(u32 status)1352 bool synopGMAC_is_rx_desc_valid(u32 status)
1353 {
1354     return ((status & DescError) == 0) && ((status & DescRxFirst) == DescRxFirst) && ((status & DescRxLast) == DescRxLast);
1355 }
1356 
1357 /**
1358   * Checks whether the tx is aborted due to collisions.
1359   * @param[in] pointer to DmaDesc structure.
1360   * \return returns true if collisions, else returns false.
1361   */
synopGMAC_is_tx_aborted(u32 status)1362 bool synopGMAC_is_tx_aborted(u32 status)
1363 {
1364     return (((status & DescTxLateCollision) == DescTxLateCollision) | ((status & DescTxExcCollisions) == DescTxExcCollisions));
1365 
1366 }
1367 
1368 /**
1369   * Checks whether the tx carrier error.
1370   * @param[in] pointer to DmaDesc structure.
1371   * \return returns true if carrier error occured, else returns falser.
1372   */
synopGMAC_is_tx_carrier_error(u32 status)1373 bool synopGMAC_is_tx_carrier_error(u32 status)
1374 {
1375     return (((status & DescTxLostCarrier) == DescTxLostCarrier)  | ((status & DescTxNoCarrier) == DescTxNoCarrier));
1376 }
1377 
1378 
1379 /**
1380   * Gives the transmission collision count.
1381   * returns the transmission collision count indicating number of collisions occured before the frame was transmitted.
1382   * Make sure to check excessive collision didnot happen to ensure the count is valid.
1383   * @param[in] pointer to DmaDesc structure.
1384   * \return returns the count value of collision.
1385   */
synopGMAC_get_tx_collision_count(u32 status)1386 u32 synopGMAC_get_tx_collision_count(u32 status)
1387 {
1388     return ((status & DescTxCollMask) >> DescTxCollShift);
1389 }
synopGMAC_is_exc_tx_collisions(u32 status)1390 u32 synopGMAC_is_exc_tx_collisions(u32 status)
1391 {
1392     return ((status & DescTxExcCollisions) == DescTxExcCollisions);
1393 }
1394 
1395 
1396 /**
1397   * Check for damaged frame due to overflow or collision.
1398   * Retruns true if rx frame was damaged due to buffer overflow in MTL or late collision in half duplex mode.
1399   * @param[in] pointer to DmaDesc structure.
1400   * \return returns true if error else returns false.
1401   */
synopGMAC_is_rx_frame_damaged(u32 status)1402 bool synopGMAC_is_rx_frame_damaged(u32 status)
1403 {
1404 //bool synopGMAC_dma_rx_collisions(u32 status)
1405     return (((status & DescRxDamaged) == DescRxDamaged) | ((status & DescRxCollision) == DescRxCollision));
1406 }
1407 
1408 /**
1409   * Check for damaged frame due to collision.
1410   * Retruns true if rx frame was damaged due to late collision in half duplex mode.
1411   * @param[in] pointer to DmaDesc structure.
1412   * \return returns true if error else returns false.
1413   */
synopGMAC_is_rx_frame_collision(u32 status)1414 bool synopGMAC_is_rx_frame_collision(u32 status)
1415 {
1416 //bool synopGMAC_dma_rx_collisions(u32 status)
1417     return ((status & DescRxCollision) == DescRxCollision);
1418 }
1419 
1420 /**
1421   * Check for receive CRC error.
1422   * Retruns true if rx frame CRC error occured.
1423   * @param[in] pointer to DmaDesc structure.
1424   * \return returns true if error else returns false.
1425   */
synopGMAC_is_rx_crc(u32 status)1426 bool synopGMAC_is_rx_crc(u32 status)
1427 {
1428 //u32 synopGMAC_dma_rx_crc(u32 status)
1429     return ((status & DescRxCrc) == DescRxCrc);
1430 }
1431 
1432 /**
1433   * Indicates rx frame has non integer multiple of bytes. (odd nibbles).
1434   * Retruns true if dribbling error in rx frame.
1435   * @param[in] pointer to DmaDesc structure.
1436   * \return returns true if error else returns false.
1437   */
synopGMAC_is_frame_dribbling_errors(u32 status)1438 bool synopGMAC_is_frame_dribbling_errors(u32 status)
1439 {
1440 //u32 synopGMAC_dma_rx_frame_errors(u32 status)
1441     return ((status & DescRxDribbling) == DescRxDribbling);
1442 }
1443 
1444 /**
1445   * Indicates error in rx frame length.
1446   * Retruns true if received frame length doesnot match with the length field
1447   * @param[in] pointer to DmaDesc structure.
1448   * \return returns true if error else returns false.
1449   */
synopGMAC_is_rx_frame_length_errors(u32 status)1450 bool synopGMAC_is_rx_frame_length_errors(u32 status)
1451 {
1452 //u32 synopGMAC_dma_rx_length_errors(u32 status)
1453     return((status & DescRxLengthError) == DescRxLengthError);
1454 }
1455 
1456 /**
1457   * Checks whether this rx descriptor is last rx descriptor.
1458   * This returns true if it is last descriptor either in ring mode or in chain mode.
1459   * @param[in] pointer to devic structure.
1460   * @param[in] pointer to DmaDesc structure.
1461   * \return returns true if it is last descriptor, false if not.
1462   * \note This function should not be called before initializing the descriptor using synopGMAC_desc_init().
1463   */
synopGMAC_is_last_rx_desc(synopGMACdevice * gmacdev,DmaDesc * desc)1464 bool synopGMAC_is_last_rx_desc(synopGMACdevice * gmacdev,DmaDesc *desc)
1465 {
1466 //bool synopGMAC_is_last_desc(DmaDesc *desc)
1467     return (((desc->length & RxDescEndOfRing) == RxDescEndOfRing) /*|| ((u32)((u64)gmacdev->RxDesc & 0xFFFFFFFF) == desc->data2)*/);
1468 }
1469 
1470 /**
1471   * Checks whether this tx descriptor is last tx descriptor.
1472   * This returns true if it is last descriptor either in ring mode or in chain mode.
1473   * @param[in] pointer to devic structure.
1474   * @param[in] pointer to DmaDesc structure.
1475   * \return returns true if it is last descriptor, false if not.
1476   * \note This function should not be called before initializing the descriptor using synopGMAC_desc_init().
1477   */
synopGMAC_is_last_tx_desc(synopGMACdevice * gmacdev,DmaDesc * desc)1478 bool synopGMAC_is_last_tx_desc(synopGMACdevice * gmacdev,DmaDesc *desc)
1479 {
1480 //bool synopGMAC_is_last_desc(DmaDesc *desc)
1481 
1482     return (((desc->status & TxDescEndOfRing) == TxDescEndOfRing) /*|| ((u32)((u64)gmacdev->TxDesc & 0xFFFFFFFF) == desc->data2)*/);
1483 
1484 }
1485 
1486 
1487 /**
1488   * This function is defined two times. Once when the code is compiled for ENHANCED DESCRIPTOR SUPPORT and Once for Normal descriptor
1489   * Get the index and address of Tx desc.
1490   * This api is same for both ring mode and chain mode.
1491   * This function tracks the tx descriptor the DMA just closed after the transmission of data from this descriptor is
1492   * over. This returns the descriptor fields to the caller.
1493   * @param[in] pointer to synopGMACdevice.
1494   * @param[out] status field of the descriptor.
1495   * @param[out] Dma-able buffer1 pointer.
1496   * @param[out] length of buffer1 (Max is 2048).
1497   * @param[out] virtual pointer for buffer1.
1498   * @param[out] u32 data indicating whether the descriptor is in ring mode or chain mode.
1499   * \return returns present tx descriptor index on success. Negative value if error.
1500   */
synopGMAC_get_tx_qptr(synopGMACdevice * gmacdev,u32 * Status,u32 * Buffer1,u32 * Length1,u32 * Data1,u32 * Ext_Status,u32 * Time_Stamp_High,u32 * Time_Stamp_Low)1501 s32 synopGMAC_get_tx_qptr(synopGMACdevice * gmacdev, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1, u32 * Ext_Status, u32 * Time_Stamp_High, u32 * Time_Stamp_Low)
1502 {
1503     u32  txover      = gmacdev->TxBusy;
1504 #ifdef CACHE_ON
1505     DmaDesc * txdesc = (DmaDesc *)((uint64_t)(gmacdev->TxBusyDesc) | 0x100000000);
1506 #else
1507     DmaDesc * txdesc = gmacdev->TxBusyDesc;
1508 #endif
1509     if(synopGMAC_is_desc_owned_by_dma(txdesc))
1510         return -1;
1511     if(synopGMAC_is_desc_empty(txdesc))
1512         return -1;
1513 
1514     (gmacdev->BusyTxDesc)--; //busy tx descriptor is reduced by one as it will be handed over to Processor now
1515 
1516     if(Status != 0)
1517         *Status = txdesc->status;
1518 
1519     if(Ext_Status != 0)
1520         *Ext_Status = txdesc->extstatus;
1521     if(Time_Stamp_High != 0)
1522         *Time_Stamp_High = txdesc->timestamphigh;
1523     if(Time_Stamp_Low != 0)
1524         *Time_Stamp_Low = txdesc->timestamplow;
1525 
1526     if(Buffer1 != 0)
1527         *Buffer1 = txdesc->buffer1;
1528     if(Length1 != 0)
1529         *Length1 = (txdesc->length & DescSize1Mask) >> DescSize1Shift;
1530     //if(Data1 != 0)
1531     //    *Data1 = txdesc->data1;
1532 
1533 
1534     gmacdev->TxBusy     = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txover + 1;
1535 
1536     if(1 /* ring mode */) {
1537         gmacdev->TxBusyDesc = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? gmacdev->TxDesc : (txdesc + 1);
1538         synopGMAC_tx_desc_init_ring(txdesc, synopGMAC_is_last_tx_desc(gmacdev,txdesc));
1539     }
1540     TR("(get)%02d %08x %08x %08x %08x %08x %08x %08x\n",txover,(u32)((u64)txdesc & 0xFFFFFFFF),txdesc->status,txdesc->length,txdesc->buffer1,txdesc->buffer2,txdesc->data1,txdesc->data2);
1541 
1542     return txover;
1543 }
1544 
1545 DmaDesc * prevtx;
synopGMAC_set_crc_replacement(synopGMACdevice * gmacdev)1546 void synopGMAC_set_crc_replacement(synopGMACdevice * gmacdev)
1547 {
1548 #ifdef CACHE_ON
1549 	DmaDesc * txdesc = (DmaDesc *)((uint64_t)(gmacdev->TxNextDesc) | 0x100000000);
1550 #else
1551 	DmaDesc * txdesc = gmacdev->TxNextDesc;
1552 #endif
1553 	txdesc->status |= DescTxDisableCrc | DescTxCrcReplacement;
1554 
1555 	prevtx = txdesc;
1556 }
1557 
synopGMAC_clr_crc_replacement(synopGMACdevice * gmacdev)1558 void synopGMAC_clr_crc_replacement(synopGMACdevice * gmacdev)
1559 {
1560 	prevtx->status &= ~(DescTxDisableCrc | DescTxCrcReplacement);
1561 	prevtx = NULL;
1562 }
1563 
1564 /**
1565   * Populate the tx desc structure with the buffer address.
1566   * Once the driver has a packet ready to be transmitted, this function is called with the
1567   * valid dma-able buffer addresses and their lengths. This function populates the descriptor
1568   * and make the DMA the owner for the descriptor. This function also controls whetther Checksum
1569   * offloading to be done in hardware or not.
1570   * This api is same for both ring mode and chain mode.
1571   * @param[in] pointer to synopGMACdevice.
1572   * @param[in] Dma-able buffer1 pointer.
1573   * @param[in] length of buffer1 (Max is 2048).
1574   * @param[in] virtual pointer for buffer1.
1575 
1576   * @param[in] u32 data indicating whether the descriptor is in ring mode or chain mode.
1577   * @param[in] u32 indicating whether the checksum offloading in HW/SW.
1578   * \return returns present tx descriptor index on success. Negative value if error.
1579   */
synopGMAC_set_tx_qptr(synopGMACdevice * gmacdev,u32 Buffer1,u32 Length1,u32 Data1,u32 offload_needed,u32 ts)1580 s32 synopGMAC_set_tx_qptr(synopGMACdevice * gmacdev, u32 Buffer1, u32 Length1, u32 Data1, u32 offload_needed, u32 ts)
1581 {
1582     u32  txnext      = gmacdev->TxNext;
1583 #ifdef CACHE_ON
1584     DmaDesc * txdesc = (DmaDesc *)((uint64_t)(gmacdev->TxNextDesc) | 0x100000000);
1585 #else
1586     DmaDesc * txdesc = gmacdev->TxNextDesc;
1587 #endif
1588     if(!synopGMAC_is_desc_empty(txdesc))
1589         return -1;
1590 
1591     (gmacdev->BusyTxDesc)++; //busy tx descriptor is incremented by one as it will be handed over to DMA
1592 
1593     if(1 /* ring mode */) {
1594         txdesc->length |= ((Length1 <<DescSize1Shift) & DescSize1Mask);
1595 
1596         txdesc->status |=  (DescTxFirst | DescTxLast | DescTxIntEnable | (ts == 1 ? DescTxTSEnable : 0) ); //ENH_DESC  // FIXME: Need to set DescTxTSEnable?
1597 
1598         //memcpy((void *)((u64)(tx_buf[][txnext]->Data) | 0x100000000), (void *)((u64)Buffer1), Length1);
1599         txdesc->buffer1 = Buffer1;
1600         //txdesc->data1 = Data1;
1601 
1602         if(offload_needed) {
1603             /*
1604              Make sure that the OS you are running supports the IP and TCP checkusm offloaidng,
1605              before calling any of the functions given below.
1606              */
1607 
1608         	//TODO:
1609             //synopGMAC_tx_checksum_offload_ipv4hdr(gmacdev, txdesc);
1610             //synopGMAC_tx_checksum_offload_tcponly(gmacdev, txdesc);
1611             synopGMAC_tx_checksum_offload_tcp_pseudo(gmacdev, txdesc);
1612         } else {
1613         	synopGMAC_tx_checksum_offload_bypass(gmacdev, txdesc);
1614         }
1615         __DSB();
1616         txdesc->status |= DescOwnByDma;//ENH_DESC
1617 
1618         gmacdev->TxNext = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? 0 : txnext + 1;
1619         gmacdev->TxNextDesc = synopGMAC_is_last_tx_desc(gmacdev,txdesc) ? gmacdev->TxDesc : (txdesc + 1);
1620     }
1621 
1622     TR("(set)%02d %08x %08x %08x %08x %08x %08x %08x\n",txnext,(u32)((u64)txdesc & 0xFFFFFFFF),txdesc->status,txdesc->length,txdesc->buffer1,txdesc->buffer2,txdesc->data1,txdesc->data2);
1623     return txnext;
1624 }
1625 
1626 /**
1627   * Prepares the descriptor to receive packets.
1628   * The descriptor is allocated with the valid buffer addresses (sk_buff address) and the length fields
1629   * and handed over to DMA by setting the ownership. After successful return from this function the
1630   * descriptor is added to the receive descriptor pool/queue.
1631   * This api is same for both ring mode and chain mode.
1632   * @param[in] pointer to synopGMACdevice.
1633   * @param[in] Dma-able buffer1 pointer.
1634   * @param[in] length of buffer1 (Max is 2048).
1635   * @param[in] Dma-able buffer2 pointer.
1636   * @param[in] length of buffer2 (Max is 2048).
1637   * @param[in] u32 data indicating whether the descriptor is in ring mode or chain mode.
1638   * \return returns present rx descriptor index on success. Negative value if error.
1639   */
synopGMAC_set_rx_qptr(synopGMACdevice * gmacdev,u32 Buffer1,u32 Length1,u32 Data1)1640 s32 synopGMAC_set_rx_qptr(synopGMACdevice * gmacdev, u32 Buffer1, u32 Length1, u32 Data1)
1641 {
1642     u32  rxnext      = gmacdev->RxNext;
1643 #ifdef CACHE_ON
1644     DmaDesc * rxdesc = (DmaDesc *)((uint64_t)(gmacdev->RxNextDesc) | 0x100000000);
1645 #else
1646     DmaDesc * rxdesc = gmacdev->RxNextDesc;
1647 #endif
1648     if(!synopGMAC_is_desc_empty(rxdesc))
1649         return -1;
1650 
1651     rxdesc->length |= ((Length1 <<DescSize1Shift) & DescSize1Mask);
1652 
1653     rxdesc->buffer1 = Buffer1;
1654     //rxdesc->data1 = Data1;
1655 
1656     rxdesc->extstatus = 0;
1657     rxdesc->reserved1 = 0;
1658     rxdesc->timestamplow = 0;
1659     rxdesc->timestamphigh = 0;
1660 
1661     rxdesc->buffer2 = 0;
1662     //rxdesc->data2 = 0;
1663 
1664     if((rxnext % MODULO_INTERRUPT) !=0)
1665         rxdesc->length |= RxDisIntCompl;
1666 
1667     rxdesc->status = DescOwnByDma;
1668 
1669     gmacdev->RxNext     = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
1670     gmacdev->RxNextDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
1671 
1672     TR("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)((u64)rxdesc & 0xFFFFFFFF),rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
1673 
1674     (gmacdev->BusyRxDesc)++; //One descriptor will be given to Hardware. So busy count incremented by one
1675     return rxnext;
1676 }
1677 
1678 
1679 /**
1680   * This function is defined two times. Once when the code is compiled for ENHANCED DESCRIPTOR SUPPORT and Once for Normal descriptor
1681   * Get back the descriptor from DMA after data has been received.
1682   * When the DMA indicates that the data is received (interrupt is generated), this function should be
1683   * called to get the descriptor and hence the data buffers received. With successful return from this
1684   * function caller gets the descriptor fields for processing. check the parameters to understand the
1685   * fields returned.`
1686   * @param[in] pointer to synopGMACdevice.
1687   * @param[out] pointer to hold the status of DMA.
1688   * @param[out] Dma-able buffer1 pointer.
1689   * @param[out] pointer to hold length of buffer1 (Max is 2048).
1690   * @param[out] virtual pointer for buffer1.
1691   * \return returns present rx descriptor index on success. Negative value if error.
1692   */
synopGMAC_get_rx_qptr(synopGMACdevice * gmacdev,u32 * Status,u32 * Buffer1,u32 * Length1,u32 * Data1,u32 * Ext_Status,u32 * Time_Stamp_High,u32 * Time_Stamp_Low)1693 s32 synopGMAC_get_rx_qptr(synopGMACdevice * gmacdev, u32 * Status, u32 * Buffer1, u32 * Length1, u32 * Data1,
1694                           u32 * Ext_Status, u32 * Time_Stamp_High, u32 * Time_Stamp_Low)
1695 {
1696     u32 rxnext       = gmacdev->RxBusy; // index of descriptor the DMA just completed. May be useful when data
1697     //is spread over multiple buffers/descriptors
1698 #ifdef CACHE_ON
1699     DmaDesc * rxdesc = (DmaDesc *)((uint64_t)(gmacdev->RxBusyDesc) | 0x100000000);
1700 #else
1701     DmaDesc * rxdesc = gmacdev->RxBusyDesc;
1702 #endif
1703     if(synopGMAC_is_desc_owned_by_dma(rxdesc))
1704         return -1;
1705     if(synopGMAC_is_desc_empty(rxdesc))
1706         return -1;
1707 
1708 
1709     if(Status != 0)
1710         *Status = rxdesc->status;// send the status of this descriptor
1711 
1712     if(Ext_Status != 0)
1713         *Ext_Status = rxdesc->extstatus;
1714     if(Time_Stamp_High != 0)
1715         *Time_Stamp_High = rxdesc->timestamphigh;
1716     if(Time_Stamp_Low != 0)
1717         *Time_Stamp_Low = rxdesc->timestamplow;
1718 
1719     if(Length1 != 0)
1720         *Length1 = (rxdesc->length & DescSize1Mask) >> DescSize1Shift;
1721     if(Buffer1 != 0)
1722         *Buffer1 = rxdesc->buffer1;
1723     //if(Data1 != 0)
1724     //    *Data1 = rxdesc->data1;
1725 
1726     gmacdev->RxBusy     = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? 0 : rxnext + 1;
1727 
1728 	gmacdev->RxBusyDesc = synopGMAC_is_last_rx_desc(gmacdev,rxdesc) ? gmacdev->RxDesc : (rxdesc + 1);
1729 	// why init here.... should change onwer to DMA --ya
1730 	//synopGMAC_rx_desc_init_ring(rxdesc, synopGMAC_is_last_rx_desc(gmacdev,rxdesc));
1731 	rxdesc->status = DescOwnByDma;
1732 	rxdesc->extstatus = 0;
1733 	rxdesc->reserved1 = 0;
1734 	rxdesc->timestamplow = 0;
1735 	rxdesc->timestamphigh = 0;
1736     TR("%02d %08x %08x %08x %08x %08x %08x %08x\n",rxnext,(u32)((u64)rxdesc & 0xFFFFFFFF),rxdesc->status,rxdesc->length,rxdesc->buffer1,rxdesc->buffer2,rxdesc->data1,rxdesc->data2);
1737     (gmacdev->BusyRxDesc)--; //busy tx descriptor is reduced by one as it will be handed over to Processor now
1738     return(rxnext);
1739 
1740 }
1741 
1742 
1743 /**
1744   * Clears all the pending interrupts.
1745   * If the Dma status register is read then all the interrupts gets cleared
1746   * @param[in] pointer to synopGMACdevice.
1747   * \return returns void.
1748   */
synopGMAC_clear_interrupt(synopGMACdevice * gmacdev)1749 void synopGMAC_clear_interrupt(synopGMACdevice *gmacdev)
1750 {
1751     u32 data;
1752     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaStatus);
1753     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaStatus ,data);
1754 }
1755 
1756 /**
1757   * Returns the all unmasked interrupt status after reading the DmaStatus register.
1758   * @param[in] pointer to synopGMACdevice.
1759   * \return 0 upon success. Error code upon failure.
1760   */
synopGMAC_get_interrupt_type(synopGMACdevice * gmacdev)1761 u32 synopGMAC_get_interrupt_type(synopGMACdevice *gmacdev)
1762 {
1763     u32 data;
1764     u32 interrupts = 0;
1765     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaStatus);
1766     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaStatus ,data); //This is the appropriate location to clear the interrupts
1767     TR("DMA status reg is  %08x\n",data);
1768     if(data & DmaIntErrorMask)  interrupts     |= synopGMACDmaError;
1769     if(data & DmaIntRxNormMask) interrupts     |= synopGMACDmaRxNormal;
1770     if(data & DmaIntRxAbnMask)  interrupts     |= synopGMACDmaRxAbnormal;
1771     if(data & DmaIntRxStoppedMask)  interrupts |= synopGMACDmaRxStopped;
1772     if(data & DmaIntTxNormMask) interrupts     |= synopGMACDmaTxNormal;
1773     if(data & DmaIntTxAbnMask)  interrupts     |= synopGMACDmaTxAbnormal;
1774     if(data & DmaIntTxStoppedMask)  interrupts |= synopGMACDmaTxStopped;
1775 
1776     //printf("%08x\n", data);
1777     //if((interrupts != 0) && (interrupts != 1) && (interrupts != 8) && (interrupts != 9)) {
1778     //	printf("....\n");
1779     //	while(1);
1780     //}
1781     return interrupts;
1782 }
1783 
1784 
1785 /**
1786   * Enable all the interrupts.
1787   * Enables the DMA interrupt as specified by the bit mask.
1788   * @param[in] pointer to synopGMACdevice.
1789   * @param[in] bit mask of interrupts to be enabled.
1790   * \return returns void.
1791   */
synopGMAC_enable_interrupt(synopGMACdevice * gmacdev,u32 interrupts)1792 void synopGMAC_enable_interrupt(synopGMACdevice *gmacdev, u32 interrupts)
1793 {
1794 //    synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaInterrupt, interrupts);
1795     u32 data;
1796     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaInterrupt);
1797     data |= interrupts;
1798     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaInterrupt, data);
1799     return;
1800 }
1801 
1802 
1803 /**
1804   * Disable all the interrupts.
1805   * Disables all DMA interrupts.
1806   * @param[in] pointer to synopGMACdevice.
1807   * \return returns void.
1808   * \note This function disabled all the interrupts, if you want to disable a particular interrupt then
1809   *  use synopGMAC_disable_interrupt().
1810   */
synopGMAC_disable_interrupt_all(synopGMACdevice * gmacdev)1811 void synopGMAC_disable_interrupt_all(synopGMACdevice *gmacdev)
1812 {
1813     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaInterrupt, DmaIntDisable);
1814     return;
1815 }
1816 
1817 /**
1818   * Disable interrupt according to the bitfield supplied.
1819   * Disables only those interrupts specified in the bit mask in second argument.
1820   * @param[in] pointer to synopGMACdevice.
1821   * @param[in] bit mask for interrupts to be disabled.
1822   * \return returns void.
1823   */
synopGMAC_disable_interrupt(synopGMACdevice * gmacdev,u32 interrupts)1824 void synopGMAC_disable_interrupt(synopGMACdevice *gmacdev, u32 interrupts)
1825 {
1826     synopGMACClearBits((u32 *)gmacdev->DmaBase, DmaInterrupt, interrupts);
1827     return;
1828 }
1829 /**
1830   * Enable the DMA Reception.
1831   * @param[in] pointer to synopGMACdevice.
1832   * \return returns void.
1833   */
synopGMAC_enable_dma_rx(synopGMACdevice * gmacdev)1834 void synopGMAC_enable_dma_rx(synopGMACdevice * gmacdev)
1835 {
1836 //  synopGMACSetBits((u32 *)gmacdev->DmaBase, DmaControl, DmaRxStart);
1837     u32 data;
1838     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1839     data |= DmaRxStart;
1840     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1841 
1842 }
1843 
1844 /**
1845   * Enable the DMA Transmission.
1846   * @param[in] pointer to synopGMACdevice.
1847   * \return returns void.
1848   */
synopGMAC_enable_dma_tx(synopGMACdevice * gmacdev)1849 void synopGMAC_enable_dma_tx(synopGMACdevice * gmacdev)
1850 {
1851 //  synopGMACSetBits((u32 *)gmacdev->DmaBase, DmaControl, DmaTxStart);
1852     u32 data;
1853     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1854     data |= DmaTxStart;
1855     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1856 
1857 }
1858 
synopGMAC_enable_under_size_pkt(synopGMACdevice * gmacdev)1859 void synopGMAC_enable_under_size_pkt(synopGMACdevice * gmacdev)
1860 {
1861     u32 data;
1862     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1863     data |= DmaFwdUnderSzFrames;
1864     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1865 
1866 }
1867 
synopGMAC_disable_under_size_pkt(synopGMACdevice * gmacdev)1868 void synopGMAC_disable_under_size_pkt(synopGMACdevice * gmacdev)
1869 {
1870     u32 data;
1871     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1872     data &= ~DmaFwdUnderSzFrames;
1873     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1874 
1875 }
1876 
synopGMAC_enable_crc_err_pkt(synopGMACdevice * gmacdev)1877 void synopGMAC_enable_crc_err_pkt(synopGMACdevice * gmacdev)
1878 {
1879     u32 data;
1880     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1881     data |= DmaFwdErrorFrames;
1882     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1883 
1884 }
1885 
synopGMAC_disable_crc_err_pkt(synopGMACdevice * gmacdev)1886 void synopGMAC_disable_crc_err_pkt(synopGMACdevice * gmacdev)
1887 {
1888     u32 data;
1889     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1890     data &= ~DmaFwdErrorFrames;
1891     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1892 
1893 }
1894 
1895 
1896 /**
1897   * Resumes the DMA Transmission.
1898   * the DmaTxPollDemand is written. (the data writeen could be anything).
1899   * This forces the DMA to resume transmission.
1900   * @param[in] pointer to synopGMACdevice.
1901   * \return returns void.
1902   */
synopGMAC_resume_dma_tx(synopGMACdevice * gmacdev)1903 void synopGMAC_resume_dma_tx(synopGMACdevice * gmacdev)
1904 {
1905     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaTxPollDemand, 0);
1906 
1907 }
1908 /**
1909   * Resumes the DMA Reception.
1910   * the DmaRxPollDemand is written. (the data writeen could be anything).
1911   * This forces the DMA to resume reception.
1912   * @param[in] pointer to synopGMACdevice.
1913   * \return returns void.
1914   */
synopGMAC_resume_dma_rx(synopGMACdevice * gmacdev)1915 void synopGMAC_resume_dma_rx(synopGMACdevice * gmacdev)
1916 {
1917     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaRxPollDemand, 0);
1918 
1919 }
1920 /**
1921   * Take ownership of this Descriptor.
1922   * The function is same for both the ring mode and the chain mode DMA structures.
1923   * @param[in] pointer to synopGMACdevice.
1924   * \return returns void.
1925   */
synopGMAC_take_desc_ownership(DmaDesc * desc)1926 void synopGMAC_take_desc_ownership(DmaDesc * desc)
1927 {
1928     if(desc) {
1929         desc->status &= ~DescOwnByDma;  //Clear the DMA own bit
1930 //      desc->status |= DescError;  // Set the error to indicate this descriptor is bad
1931     }
1932 }
1933 
1934 /**
1935   * Take ownership of all the rx Descriptors.
1936   * This function is called when there is fatal error in DMA transmission.
1937   * When called it takes the ownership of all the rx descriptor in rx descriptor pool/queue from DMA.
1938   * The function is same for both the ring mode and the chain mode DMA structures.
1939   * @param[in] pointer to synopGMACdevice.
1940   * \return returns void.
1941   * \note Make sure to disable the transmission before calling this function, otherwise may result in racing situation.
1942   */
synopGMAC_take_desc_ownership_rx(synopGMACdevice * gmacdev)1943 void synopGMAC_take_desc_ownership_rx(synopGMACdevice * gmacdev)
1944 {
1945     s32 i;
1946     DmaDesc *desc;
1947     desc = gmacdev->RxDesc;
1948     for(i = 0; i < gmacdev->RxDescCount; i++) {
1949         if(1 /* ring mode */) {
1950             synopGMAC_take_desc_ownership(desc + i);
1951         }
1952     }
1953 }
1954 
1955 /**
1956   * Take ownership of all the rx Descriptors.
1957   * This function is called when there is fatal error in DMA transmission.
1958   * When called it takes the ownership of all the tx descriptor in tx descriptor pool/queue from DMA.
1959   * The function is same for both the ring mode and the chain mode DMA structures.
1960   * @param[in] pointer to synopGMACdevice.
1961   * \return returns void.
1962   * \note Make sure to disable the transmission before calling this function, otherwise may result in racing situation.
1963   */
synopGMAC_take_desc_ownership_tx(synopGMACdevice * gmacdev)1964 void synopGMAC_take_desc_ownership_tx(synopGMACdevice * gmacdev)
1965 {
1966     s32 i;
1967     DmaDesc *desc;
1968     desc = gmacdev->TxDesc;
1969     for(i = 0; i < gmacdev->TxDescCount; i++) {
1970         if(1 /* ring mode */) {
1971             synopGMAC_take_desc_ownership(desc + i);
1972         }
1973     }
1974 
1975 }
1976 
1977 /**
1978   * Disable the DMA for Transmission.
1979   * @param[in] pointer to synopGMACdevice.
1980   * \return returns void.
1981   */
1982 
synopGMAC_disable_dma_tx(synopGMACdevice * gmacdev)1983 void synopGMAC_disable_dma_tx(synopGMACdevice * gmacdev)
1984 {
1985 //  synopGMACClearBits((u32 *)gmacdev->DmaBase, DmaControl, DmaTxStart);
1986     u32 data;
1987     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
1988     data &= (~DmaTxStart);
1989     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
1990 }
1991 /**
1992   * Disable the DMA for Reception.
1993   * @param[in] pointer to synopGMACdevice.
1994   * \return returns void.
1995   */
synopGMAC_disable_dma_rx(synopGMACdevice * gmacdev)1996 void synopGMAC_disable_dma_rx(synopGMACdevice * gmacdev)
1997 {
1998 //  synopGMACClearBits((u32 *)gmacdev->DmaBase, DmaControl, DmaRxStart);
1999     u32 data;
2000     data = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaControl);
2001     data &= (~DmaRxStart);
2002     synopGMACWriteReg((u32 *)gmacdev->DmaBase, DmaControl ,data);
2003 }
2004 
2005 
2006 
2007 /*******************PMT APIs***************************************/
2008 
2009 
2010 
2011 
2012 /**
2013   * Enables the assertion of PMT interrupt.
2014   * This enables the assertion of PMT interrupt due to Magic Pkt or Wakeup frame
2015   * reception.
2016   * @param[in] pointer to synopGMACdevice.
2017   * \return returns void.
2018   */
synopGMAC_pmt_int_enable(synopGMACdevice * gmacdev)2019 void synopGMAC_pmt_int_enable(synopGMACdevice *gmacdev)
2020 {
2021     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
2022     return;
2023 }
2024 /**
2025   * Disables the assertion of PMT interrupt.
2026   * This disables the assertion of PMT interrupt due to Magic Pkt or Wakeup frame
2027   * reception.
2028   * @param[in] pointer to synopGMACdevice.
2029   * \return returns void.
2030   */
synopGMAC_pmt_int_disable(synopGMACdevice * gmacdev)2031 void synopGMAC_pmt_int_disable(synopGMACdevice *gmacdev)
2032 {
2033     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
2034     return;
2035 }
2036 /**
2037   * Enables the power down mode of GMAC.
2038   * This function puts the Gmac in power down mode.
2039   * @param[in] pointer to synopGMACdevice.
2040   * \return returns void.
2041   */
synopGMAC_power_down_enable(synopGMACdevice * gmacdev)2042 void synopGMAC_power_down_enable(synopGMACdevice *gmacdev)
2043 {
2044     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtPowerDown);
2045     return;
2046 }
2047 /**
2048   * Disables the powerd down setting of GMAC.
2049   * If the driver wants to bring up the GMAC from powerdown mode, even though the magic packet or the
2050   * wake up frames received from the network, this function should be called.
2051   * @param[in] pointer to synopGMACdevice.
2052   * \return returns void.
2053   */
synopGMAC_power_down_disable(synopGMACdevice * gmacdev)2054 void synopGMAC_power_down_disable(synopGMACdevice *gmacdev)
2055 {
2056     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtPowerDown);
2057     return;
2058 }
2059 /**
2060   * Enables the pmt interrupt generation in powerdown mode.
2061   * @param[in] pointer to synopGMACdevice.
2062   * \return returns void.
2063   */
synopGMAC_enable_pmt_interrupt(synopGMACdevice * gmacdev)2064 void synopGMAC_enable_pmt_interrupt(synopGMACdevice *gmacdev)
2065 {
2066     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
2067 }
2068 /**
2069   * Disables the pmt interrupt generation in powerdown mode.
2070   * @param[in] pointer to synopGMACdevice.
2071   * \return returns void.
2072   */
synopGMAC_disable_pmt_interrupt(synopGMACdevice * gmacdev)2073 void synopGMAC_disable_pmt_interrupt(synopGMACdevice *gmacdev)
2074 {
2075     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacInterruptMask,GmacPmtIntMask);
2076 }
2077 /**
2078   * Enables GMAC to look for Magic packet.
2079   * @param[in] pointer to synopGMACdevice.
2080   * \return returns void.
2081   */
synopGMAC_magic_packet_enable(synopGMACdevice * gmacdev)2082 void synopGMAC_magic_packet_enable(synopGMACdevice *gmacdev)
2083 {
2084     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtMagicPktEnable);
2085     return;
2086 }
2087 
synopGMAC_magic_packet_disable(synopGMACdevice * gmacdev)2088 void synopGMAC_magic_packet_disable(synopGMACdevice *gmacdev)
2089 {
2090     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtMagicPktEnable);
2091     return;
2092 }
2093 
2094 /**
2095   * Enables GMAC to look for wake up frame.
2096   * Wake up frame is defined by the user.
2097   * @param[in] pointer to synopGMACdevice.
2098   * \return returns void.
2099   */
synopGMAC_wakeup_frame_enable(synopGMACdevice * gmacdev)2100 void synopGMAC_wakeup_frame_enable(synopGMACdevice *gmacdev)
2101 {
2102     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtWakeupFrameEnable);
2103     return;
2104 }
2105 
2106 /**
2107   * Enables wake-up frame filter to handle unicast packets.
2108   * @param[in] pointer to synopGMACdevice.
2109   * \return returns void.
2110   */
synopGMAC_pmt_unicast_enable(synopGMACdevice * gmacdev)2111 void synopGMAC_pmt_unicast_enable(synopGMACdevice *gmacdev)
2112 {
2113     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtGlobalUnicast);
2114     return;
2115 }
2116 /**
2117   * Checks whether the packet received is a magic packet?.
2118   * @param[in] pointer to synopGMACdevice.
2119   * \return returns True if magic packet received else returns false.
2120   */
synopGMAC_is_magic_packet_received(synopGMACdevice * gmacdev)2121 bool synopGMAC_is_magic_packet_received(synopGMACdevice *gmacdev)
2122 {
2123     u32 data;
2124     data =  synopGMACReadReg((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus);
2125     return((data & GmacPmtMagicPktReceived) == GmacPmtMagicPktReceived);
2126 }
2127 /**
2128   * Checks whether the packet received is a wakeup frame?.
2129   * @param[in] pointer to synopGMACdevice.
2130   * \return returns true if wakeup frame received else returns false.
2131   */
synopGMAC_is_wakeup_frame_received(synopGMACdevice * gmacdev)2132 bool synopGMAC_is_wakeup_frame_received(synopGMACdevice *gmacdev)
2133 {
2134     u32 data;
2135     data =  synopGMACReadReg((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus);
2136     return((data & GmacPmtWakeupFrameReceived) == GmacPmtWakeupFrameReceived);
2137 }
2138 
2139 /**
2140   * Populates the remote wakeup frame registers.
2141   * Consecutive 8 writes to GmacWakeupAddr writes the wakeup frame filter registers.
2142   * Before commensing a new write, frame filter pointer is reset to 0x0000.
2143   * A small delay is introduced to allow frame filter pointer reset operation.
2144   * @param[in] pointer to synopGMACdevice.
2145   * @param[in] pointer to frame filter contents array.
2146   * \return returns void.
2147   */
2148 #if 0
2149 void synopGMAC_write_wakeup_frame_register(synopGMACdevice *gmacdev, u32 * filter_contents)
2150 {
2151     s32 i;
2152     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacPmtCtrlStatus,GmacPmtFrmFilterPtrReset);
2153     plat_delay(10);
2154     for(i =0; i<WAKEUP_REG_LENGTH; i++)
2155         synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacWakeupAddr,  *(filter_contents + i));
2156     return;
2157 
2158 }
2159 #endif
2160 /*******************PMT APIs***************************************/
2161 
2162 /*******************Ip checksum offloading APIs***************************************/
2163 
2164 /**
2165   * Enables the ip checksum offloading in receive path.
2166   * When set GMAC calculates 16 bit 1's complement of all received ethernet frame payload.
2167   * It also checks IPv4 Header checksum is correct. GMAC core appends the 16 bit checksum calculated
2168   * for payload of IP datagram and appends it to Ethernet frame transferred to the application.
2169   * @param[in] pointer to synopGMACdevice.
2170   * \return returns void.
2171   */
synopGMAC_enable_rx_chksum_offload(synopGMACdevice * gmacdev)2172 void synopGMAC_enable_rx_chksum_offload(synopGMACdevice *gmacdev)
2173 {
2174     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacConfig,GmacRxIpcOffload);
2175     return;
2176 }
2177 /**
2178   * Disable the ip checksum offloading in receive path.
2179   * Ip checksum offloading is disabled in the receive path.
2180   * @param[in] pointer to synopGMACdevice.
2181   * \return returns void.
2182   */
synopGMAC_disable_rx_chksum_offload(synopGMACdevice * gmacdev)2183 void synopGMAC_disable_rx_chksum_offload(synopGMACdevice *gmacdev)
2184 {
2185     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacConfig,GmacRxIpcOffload);
2186 }
2187 /**
2188   * Instruct the DMA to drop the packets fails tcp ip checksum.
2189   * This is to instruct the receive DMA engine to drop the recevied packet if they
2190   * fails the tcp/ip checksum in hardware. Valid only when full checksum offloading is enabled(type-2).
2191   * @param[in] pointer to synopGMACdevice.
2192   * \return returns void.
2193   */
synopGMAC_rx_tcpip_chksum_drop_enable(synopGMACdevice * gmacdev)2194 void synopGMAC_rx_tcpip_chksum_drop_enable(synopGMACdevice *gmacdev)
2195 {
2196     synopGMACClearBits((u32 *)gmacdev->DmaBase,DmaControl,DmaDisableDropTcpCs);
2197     return;
2198 }
2199 /**
2200   * Instruct the DMA not to drop the packets even if it fails tcp ip checksum.
2201   * This is to instruct the receive DMA engine to allow the packets even if recevied packet
2202   * fails the tcp/ip checksum in hardware. Valid only when full checksum offloading is enabled(type-2).
2203   * @param[in] pointer to synopGMACdevice.
2204   * \return returns void.
2205   */
synopGMAC_rx_tcpip_chksum_drop_disable(synopGMACdevice * gmacdev)2206 void synopGMAC_rx_tcpip_chksum_drop_disable(synopGMACdevice *gmacdev)
2207 {
2208     synopGMACSetBits((u32 *)gmacdev->DmaBase,DmaControl,DmaDisableDropTcpCs);
2209     return;
2210 }
2211 
2212 /**
2213   * When the Enhanced Descriptor is enabled then the bit 0 of RDES0 indicates whether the
2214   * Extended Status is available (RDES4). Time Stamp feature and the Checksum Offload Engine2
2215   * makes use of this extended status to provide the status of the received packet.
2216   * @param[in] pointer to synopGMACdevice
2217   * \return returns TRUE or FALSE
2218   */
2219 
2220 
2221 /**
2222   * This function indicates whether extended status is available in the RDES0.
2223   * Any function which accesses the fields of extended status register must ensure a check on this has been made
2224   * This is valid only for Enhanced Descriptor.
2225   * @param[in] pointer to synopGMACdevice.
2226   * @param[in] u32 status field of the corresponding descriptor.
2227   * \return returns TRUE or FALSE.
2228   */
synopGMAC_is_ext_status(synopGMACdevice * gmacdev,u32 status)2229 bool synopGMAC_is_ext_status(synopGMACdevice *gmacdev,u32 status)             // extended status present indicates that the RDES4 need to be probed
2230 {
2231     return((status & DescRxEXTsts ) != 0 ); // if extstatus set then it returns 1
2232 }
2233 /**
2234   * This function returns true if the IP header checksum bit is set in the extended status.
2235   * Valid only when enhaced status available is set in RDES0 bit 0.
2236   * This is valid only for Enhanced Descriptor.
2237   * @param[in] pointer to synopGMACdevice.
2238   * @param[in] u32 status field of the corresponding descriptor.
2239   * \return returns TRUE or FALSE.
2240   */
synopGMAC_ES_is_IP_header_error(synopGMACdevice * gmacdev,u32 ext_status)2241 bool synopGMAC_ES_is_IP_header_error(synopGMACdevice *gmacdev,u32 ext_status)          // IP header (IPV4) checksum error
2242 {
2243     return((ext_status & DescRxIpHeaderError) != 0 ); // if IPV4 header error return 1
2244 }
2245 /**
2246   * This function returns true if the Checksum is bypassed in the hardware.
2247   * Valid only when enhaced status available is set in RDES0 bit 0.
2248   * This is valid only for Enhanced Descriptor.
2249   * @param[in] pointer to synopGMACdevice.
2250   * @param[in] u32 status field of the corresponding descriptor.
2251   * \return returns TRUE or FALSE.
2252   */
synopGMAC_ES_is_rx_checksum_bypassed(synopGMACdevice * gmacdev,u32 ext_status)2253 bool synopGMAC_ES_is_rx_checksum_bypassed(synopGMACdevice *gmacdev,u32 ext_status)     // Hardware engine bypassed the checksum computation/checking
2254 {
2255     return((ext_status & DescRxChkSumBypass ) != 0 ); // if checksum offloading bypassed return 1
2256 }
2257 /**
2258   * This function returns true if payload checksum error is set in the extended status.
2259   * Valid only when enhaced status available is set in RDES0 bit 0.
2260   * This is valid only for Enhanced Descriptor.
2261   * @param[in] pointer to synopGMACdevice.
2262   * @param[in] u32 status field of the corresponding descriptor.
2263   * \return returns TRUE or FALSE.
2264   */
synopGMAC_ES_is_IP_payload_error(synopGMACdevice * gmacdev,u32 ext_status)2265 bool synopGMAC_ES_is_IP_payload_error(synopGMACdevice *gmacdev,u32 ext_status)         // IP payload checksum is in error (UDP/TCP/ICMP checksum error)
2266 {
2267     return((ext_status & DescRxIpPayloadError) != 0 ); // if IP payload error return 1
2268 }
2269 
2270 
2271 
2272 
2273 /**
2274   * Decodes the Rx Descriptor status to various checksum error conditions.
2275   * @param[in] pointer to synopGMACdevice.
2276   * @param[in] u32 status field of the corresponding descriptor.
2277   * \return returns decoded enum (u32) indicating the status.
2278   */
synopGMAC_is_rx_checksum_error(synopGMACdevice * gmacdev,u32 status)2279 u32 synopGMAC_is_rx_checksum_error(synopGMACdevice *gmacdev, u32 status)
2280 {
2281     if     (((status & DescRxChkBit5) == 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) == 0))
2282         return RxLenLT600;
2283     else if(((status & DescRxChkBit5) == 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) != 0))
2284         return RxIpHdrPayLoadChkBypass;
2285     else if(((status & DescRxChkBit5) == 0) && ((status & DescRxChkBit7) != 0) && ((status & DescRxChkBit0) != 0))
2286         return RxChkBypass;
2287     else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) == 0))
2288         return RxNoChkError;
2289     else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) == 0) && ((status & DescRxChkBit0) != 0))
2290         return RxPayLoadChkError;
2291     else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) != 0) && ((status & DescRxChkBit0) == 0))
2292         return RxIpHdrChkError;
2293     else if(((status & DescRxChkBit5) != 0) && ((status & DescRxChkBit7) != 0) && ((status & DescRxChkBit0) != 0))
2294         return RxIpHdrPayLoadChkError;
2295     else
2296         return RxIpHdrPayLoadRes;
2297 }
2298 /**
2299   * Checks if any Ipv4 header checksum error in the frame just transmitted.
2300   * This serves as indication that error occureed in the IPv4 header checksum insertion.
2301   * The sent out frame doesnot carry any ipv4 header checksum inserted by the hardware.
2302   * @param[in] pointer to synopGMACdevice.
2303   * @param[in] u32 status field of the corresponding descriptor.
2304   * \return returns true if error in ipv4 header checksum, else returns false.
2305   */
synopGMAC_is_tx_ipv4header_checksum_error(synopGMACdevice * gmacdev,u32 status)2306 bool synopGMAC_is_tx_ipv4header_checksum_error(synopGMACdevice *gmacdev, u32 status)
2307 {
2308     return((status & DescTxIpv4ChkError) == DescTxIpv4ChkError);
2309 }
2310 
2311 
2312 /**
2313   * Checks if any payload checksum error in the frame just transmitted.
2314   * This serves as indication that error occureed in the payload checksum insertion.
2315   * The sent out frame doesnot carry any payload checksum inserted by the hardware.
2316   * @param[in] pointer to synopGMACdevice.
2317   * @param[in] u32 status field of the corresponding descriptor.
2318   * \return returns true if error in ipv4 header checksum, else returns false.
2319   */
synopGMAC_is_tx_payload_checksum_error(synopGMACdevice * gmacdev,u32 status)2320 bool synopGMAC_is_tx_payload_checksum_error(synopGMACdevice *gmacdev, u32 status)
2321 {
2322     return((status & DescTxPayChkError) == DescTxPayChkError);
2323 }
2324 /**
2325   * The check summ offload engine is bypassed in the tx path.
2326   * Checksum is not computed in the Hardware.
2327   * @param[in] pointer to synopGMACdevice.
2328   * @param[in] Pointer to tx descriptor for which  ointer to synopGMACdevice.
2329   * \return returns void.
2330   */
synopGMAC_tx_checksum_offload_bypass(synopGMACdevice * gmacdev,DmaDesc * desc)2331 void synopGMAC_tx_checksum_offload_bypass(synopGMACdevice *gmacdev, DmaDesc *desc)
2332 {
2333     desc->status = (desc->status & (~DescTxCisMask));//ENH_DESC
2334 
2335 
2336 }
2337 /**
2338   * The check summ offload engine is enabled to do only IPV4 header checksum.
2339   * IPV4 header Checksum is computed in the Hardware.
2340   * @param[in] pointer to synopGMACdevice.
2341   * @param[in] Pointer to tx descriptor for which  ointer to synopGMACdevice.
2342   * \return returns void.
2343   */
synopGMAC_tx_checksum_offload_ipv4hdr(synopGMACdevice * gmacdev,DmaDesc * desc)2344 void synopGMAC_tx_checksum_offload_ipv4hdr(synopGMACdevice *gmacdev, DmaDesc *desc)
2345 {
2346 
2347     desc->status = ((desc->status & (~DescTxCisMask)) | DescTxCisIpv4HdrCs);//ENH_DESC
2348 
2349 
2350 }
2351 
2352 /**
2353   * The check summ offload engine is enabled to do TCPIP checsum assuming Pseudo header is available.
2354   * Hardware computes the tcp ip checksum assuming pseudo header checksum is computed in software.
2355   * Ipv4 header checksum is also inserted.
2356   * @param[in] pointer to synopGMACdevice.
2357   * @param[in] Pointer to tx descriptor for which  ointer to synopGMACdevice.
2358   * \return returns void.
2359   */
synopGMAC_tx_checksum_offload_tcponly(synopGMACdevice * gmacdev,DmaDesc * desc)2360 void synopGMAC_tx_checksum_offload_tcponly(synopGMACdevice *gmacdev, DmaDesc *desc)
2361 {
2362 
2363     desc->status = ((desc->status & (~DescTxCisMask)) | DescTxCisTcpOnlyCs);//ENH_DESC
2364 
2365 
2366 }
2367 /**
2368   * The check summ offload engine is enabled to do complete checksum computation.
2369   * Hardware computes the tcp ip checksum including the pseudo header checksum.
2370   * Here the tcp payload checksum field should be set to 0000.
2371   * Ipv4 header checksum is also inserted.
2372   * @param[in] pointer to synopGMACdevice.
2373   * @param[in] Pointer to tx descriptor for which  ointer to synopGMACdevice.
2374   * \return returns void.
2375   */
synopGMAC_tx_checksum_offload_tcp_pseudo(synopGMACdevice * gmacdev,DmaDesc * desc)2376 void synopGMAC_tx_checksum_offload_tcp_pseudo(synopGMACdevice *gmacdev, DmaDesc *desc)
2377 {
2378 
2379     desc->status = ((desc->status & (~DescTxCisMask)) | DescTxCisTcpPseudoCs);
2380 
2381 
2382 }
2383 /*******************Ip checksum offloading APIs***************************************/
2384 
2385 
2386 
2387 
2388 
2389 /*******************IEEE 1588 Timestamping API***************************************/
2390 
2391 
2392 /*
2393  * At this time the driver supports the IEEE time stamping feature when the Enhanced Descriptors are enabled.
2394  * For normal descriptor and the IEEE time stamp (version 1), driver support is not proviced
2395  * Please make sure you have enabled the Advanced timestamp feature in the hardware and the driver should
2396  * be compiled with the ADV_TME_STAMP feature.
2397  * Some of the APIs provided here may not be valid for all configurations. Please make sure you call the
2398  * API with due care.
2399  */
2400 
2401 /**
2402   * This function enables the timestamping. This enables the timestamping for transmit and receive frames.
2403   * When disabled timestamp is not added to tx and receive frames and timestamp generator is suspended.
2404   * @param[in] pointer to synopGMACdevice
2405   * \return returns void
2406   */
synopGMAC_TS_enable(synopGMACdevice * gmacdev)2407 void synopGMAC_TS_enable(synopGMACdevice *gmacdev)
2408 {
2409     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSENA);
2410     return;
2411 }
2412 /**
2413   * This function disables the timestamping.
2414   * When disabled timestamp is not added to tx and receive frames and timestamp generator is suspended.
2415   * @param[in] pointer to synopGMACdevice
2416   * \return returns void
2417   */
synopGMAC_TS_disable(synopGMACdevice * gmacdev)2418 void synopGMAC_TS_disable(synopGMACdevice *gmacdev)
2419 {
2420     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl, GmacTSENA);
2421     return;
2422 }
2423 
2424 
2425 /**
2426   * Enable the interrupt to get timestamping interrupt.
2427   * This enables the host to get the interrupt when (1) system time is greater or equal to the
2428   * target time high and low register or (2) there is a overflow in th esecond register.
2429   * @param[in] pointer to synopGMACdevice
2430   * \return returns void
2431   */
synopGMAC_TS_int_enable(synopGMACdevice * gmacdev)2432 void synopGMAC_TS_int_enable(synopGMACdevice *gmacdev)
2433 {
2434     //synopGMACClearBits((u32 *)gmacdev->MacBase,GmacInterruptMask,GmacTSIntMask);
2435 	synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSTRIG);
2436     return;
2437 }
2438 
2439 /**
2440   * Disable the interrupt to get timestamping interrupt.
2441   * @param[in] pointer to synopGMACdevice
2442   * \return returns void
2443   */
synopGMAC_TS_int_disable(synopGMACdevice * gmacdev)2444 void synopGMAC_TS_int_disable(synopGMACdevice *gmacdev)
2445 {
2446     //synopGMACSetBits((u32 *)gmacdev->MacBase,GmacInterruptMask,GmacTSIntMask);
2447 	synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSTRIG);
2448     return;
2449 }
2450 
2451 /**
2452   * Enable MAC address for PTP frame filtering.
2453   * When enabled, uses MAC address (apart from MAC address 0) to filter the PTP frames when
2454   * PTP is sent directly over Ethernet.
2455   * @param[in] pointer to synopGMACdevice
2456   * \return returns void
2457   */
synopGMAC_TS_mac_addr_filt_enable(synopGMACdevice * gmacdev)2458 void synopGMAC_TS_mac_addr_filt_enable(synopGMACdevice *gmacdev)
2459 {
2460     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSENMACADDR);
2461     return;
2462 }
2463 
2464 /**
2465   * Disables MAC address for PTP frame filtering.
2466   * @param[in] pointer to synopGMACdevice
2467   * \return returns void
2468   */
synopGMAC_TS_mac_addr_filt_disable(synopGMACdevice * gmacdev)2469 void synopGMAC_TS_mac_addr_filt_disable(synopGMACdevice *gmacdev)
2470 {
2471     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSENMACADDR);
2472     return;
2473 }
2474 
2475 
2476 /**
2477   * Selet the type of clock mode for PTP.
2478   * Please note to use one of the follwoing as the clk_type argument.
2479   * GmacTSOrdClk          = 0x00000000,      00=> Ordinary clock
2480   * GmacTSBouClk          = 0x00010000,      01=> Boundary clock
2481   * GmacTSEtoEClk         = 0x00020000,      10=> End-to-End transparent clock
2482   * GmacTSPtoPClk         = 0x00030000,      11=> P-to-P transparent clock
2483   * @param[in] pointer to synopGMACdevice
2484   * @param[in] u32 value representing one of the above clk value
2485   * \return returns void
2486   */
synopGMAC_TS_set_clk_type(synopGMACdevice * gmacdev,u32 clk_type)2487 void synopGMAC_TS_set_clk_type(synopGMACdevice *gmacdev, u32 clk_type)
2488 {
2489     u32 clkval;
2490     clkval = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSControl); //set the mdc clock to the user defined value
2491     clkval = (clkval & ~GmacTSCLKTYPE)| clk_type;
2492     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSControl,clkval);
2493     return;
2494 }
2495 
2496 /**
2497   * Enable Snapshot for messages relevant to Master.
2498   * When enabled, snapshot is taken for messages relevant to master mode only, else snapshot is taken for messages relevant
2499   * to slave node.
2500   * Valid only for Ordinary clock and Boundary clock
2501   * Reserved when "Advanced Time Stamp" is not selected
2502   * @param[in] pointer to synopGMACdevice
2503   * \return returns void
2504   */
synopGMAC_TS_master_enable(synopGMACdevice * gmacdev)2505 void synopGMAC_TS_master_enable(synopGMACdevice *gmacdev)
2506 {
2507     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSMSTRENA);
2508     return;
2509 }
2510 /**
2511   * Disable Snapshot for messages relevant to Master.
2512   * When disabled, snapshot is taken for messages relevant
2513   * to slave node.
2514   * Valid only for Ordinary clock and Boundary clock
2515   * Reserved when "Advanced Time Stamp" is not selected
2516   * @param[in] pointer to synopGMACdevice
2517   * \return returns void
2518   */
synopGMAC_TS_master_disable(synopGMACdevice * gmacdev)2519 void synopGMAC_TS_master_disable(synopGMACdevice *gmacdev)
2520 {
2521     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSMSTRENA);
2522     return;
2523 }
2524 /**
2525   * Enable Snapshot for Event messages.
2526   * When enabled, snapshot is taken for event messages only (SYNC, Delay_Req, Pdelay_Req or Pdelay_Resp)
2527   * When disabled, snapshot is taken for all messages except Announce, Management and Signaling.
2528   * Reserved when "Advanced Time Stamp" is not selected
2529   * @param[in] pointer to synopGMACdevice
2530   * \return returns void
2531   */
synopGMAC_TS_event_enable(synopGMACdevice * gmacdev)2532 void synopGMAC_TS_event_enable(synopGMACdevice *gmacdev)
2533 {
2534     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSEVNTENA);
2535     return;
2536 }
2537 /**
2538   * Disable Snapshot for Event messages.
2539   * When disabled, snapshot is taken for all messages except Announce, Management and Signaling.
2540   * Reserved when "Advanced Time Stamp" is not selected
2541   * @param[in] pointer to synopGMACdevice
2542   * \return returns void
2543   */
synopGMAC_TS_event_disable(synopGMACdevice * gmacdev)2544 void synopGMAC_TS_event_disable(synopGMACdevice *gmacdev)
2545 {
2546     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSEVNTENA);
2547     return;
2548 }
2549 
2550 /**
2551   * Enable time stamp snapshot for IPV4 frames.
2552   * When enabled, time stamp snapshot is taken for IPV4 frames
2553   * Reserved when "Advanced Time Stamp" is not selected
2554   * @param[in] pointer to synopGMACdevice
2555   * \return returns void
2556   */
synopGMAC_TS_IPV4_enable(synopGMACdevice * gmacdev)2557 void synopGMAC_TS_IPV4_enable(synopGMACdevice *gmacdev)
2558 {
2559     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSIPV4ENA);
2560     return;
2561 }
2562 /**
2563   * Disable time stamp snapshot for IPV4 frames.
2564   * When disabled, time stamp snapshot is not taken for IPV4 frames
2565   * Reserved when "Advanced Time Stamp" is not selected
2566   * @param[in] pointer to synopGMACdevice
2567   * \return returns void
2568   */
synopGMAC_TS_IPV4_disable(synopGMACdevice * gmacdev)2569 void synopGMAC_TS_IPV4_disable(synopGMACdevice *gmacdev)
2570 {
2571     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSIPV4ENA);
2572     return;
2573 }                    // Only for "Advanced Time Stamp"
2574 /**
2575   * Enable time stamp snapshot for IPV6 frames.
2576   * When enabled, time stamp snapshot is taken for IPV6 frames
2577   * Reserved when "Advanced Time Stamp" is not selected
2578   * @param[in] pointer to synopGMACdevice
2579   * \return returns void
2580   */
synopGMAC_TS_IPV6_enable(synopGMACdevice * gmacdev)2581 void synopGMAC_TS_IPV6_enable(synopGMACdevice *gmacdev)
2582 {
2583     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSIPV6ENA);
2584     return;
2585 }
2586 /**
2587   * Disable time stamp snapshot for IPV6 frames.
2588   * When disabled, time stamp snapshot is not taken for IPV6 frames
2589   * Reserved when "Advanced Time Stamp" is not selected
2590   * @param[in] pointer to synopGMACdevice
2591   * \return returns void
2592   */
synopGMAC_TS_IPV6_disable(synopGMACdevice * gmacdev)2593 void synopGMAC_TS_IPV6_disable(synopGMACdevice *gmacdev)
2594 {
2595     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSIPV6ENA);
2596     return;
2597 }
2598 
2599 /**
2600   * Enable time stamp snapshot for PTP over Ethernet frames.
2601   * When enabled, time stamp snapshot is taken for PTP over Ethernet frames
2602   * Reserved when "Advanced Time Stamp" is not selected
2603   * @param[in] pointer to synopGMACdevice
2604   * \return returns void
2605   */
synopGMAC_TS_ptp_over_ethernet_enable(synopGMACdevice * gmacdev)2606 void synopGMAC_TS_ptp_over_ethernet_enable(synopGMACdevice *gmacdev)
2607 {
2608     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSIPENA);
2609     return;
2610 }
2611 /**
2612   * Disable time stamp snapshot for PTP over Ethernet frames.
2613   * When disabled, time stamp snapshot is not taken for PTP over Ethernet frames
2614   * Reserved when "Advanced Time Stamp" is not selected
2615   * @param[in] pointer to synopGMACdevice
2616   * \return returns void
2617   */
synopGMAC_TS_ptp_over_ethernet_disable(synopGMACdevice * gmacdev)2618 void synopGMAC_TS_ptp_over_ethernet_disable(synopGMACdevice *gmacdev)
2619 {
2620     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSIPENA);
2621     return;
2622 }
2623 
2624 
2625 /**
2626   * Snoop PTP packet for version 2 format
2627   * When set the PTP packets are snooped using the version 2 format.
2628   * @param[in] pointer to synopGMACdevice
2629   * \return returns void
2630   */
synopGMAC_TS_pkt_snoop_ver2(synopGMACdevice * gmacdev)2631 void synopGMAC_TS_pkt_snoop_ver2(synopGMACdevice *gmacdev)
2632 {
2633     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSVER2ENA);
2634     return;
2635 }
2636 /**
2637   * Snoop PTP packet for version 2 format
2638   * When set the PTP packets are snooped using the version 2 format.
2639   * @param[in] pointer to synopGMACdevice
2640   * \return returns void
2641   */
synopGMAC_TS_pkt_snoop_ver1(synopGMACdevice * gmacdev)2642 void synopGMAC_TS_pkt_snoop_ver1(synopGMACdevice *gmacdev)
2643 {
2644     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSVER2ENA);
2645     return;
2646 }
2647 
2648 /**
2649   * Timestamp digital rollover
2650   * When set the timestamp low register rolls over after 0x3B9A_C9FF value.
2651   * @param[in] pointer to synopGMACdevice
2652   * \return returns void
2653   */
synopGMAC_TS_digital_rollover_enable(synopGMACdevice * gmacdev)2654 void synopGMAC_TS_digital_rollover_enable(synopGMACdevice *gmacdev)
2655 {
2656     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSCTRLSSR);
2657     return;
2658 }
2659 /**
2660   * Timestamp binary rollover
2661   * When set the timestamp low register rolls over after 0x7FFF_FFFF value.
2662   * @param[in] pointer to synopGMACdevice
2663   * \return returns void
2664   */
synopGMAC_TS_binary_rollover_enable(synopGMACdevice * gmacdev)2665 void synopGMAC_TS_binary_rollover_enable(synopGMACdevice *gmacdev)
2666 {
2667     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSCTRLSSR);
2668     return;
2669 }
2670 /**
2671   * Enable Time Stamp for All frames
2672   * When set the timestamp snap shot is enabled for all frames received by the core.
2673   * Reserved when "Advanced Time Stamp" is not selected
2674   * @param[in] pointer to synopGMACdevice
2675   * \return returns void
2676   */
synopGMAC_TS_all_frames_enable(synopGMACdevice * gmacdev)2677 void synopGMAC_TS_all_frames_enable(synopGMACdevice *gmacdev)
2678 {
2679     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSENALL);
2680     return;
2681 }
2682 /**
2683   * Disable Time Stamp for All frames
2684   * When reset the timestamp snap shot is not enabled for all frames received by the core.
2685   * Reserved when "Advanced Time Stamp" is not selected
2686   * @param[in] pointer to synopGMACdevice
2687   * \return returns void
2688   */
synopGMAC_TS_all_frames_disable(synopGMACdevice * gmacdev)2689 void synopGMAC_TS_all_frames_disable(synopGMACdevice *gmacdev)
2690 {
2691     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSENALL);
2692     return;
2693 }
2694 /**
2695   * Addend Register Update
2696   * This function loads the contents of Time stamp addend register with the supplied 32 value.
2697   * This is reserved function when only coarse correction option is selected
2698   * @param[in] pointer to synopGMACdevice
2699   * @param[in] 32 bit addend value
2700   * \return returns 0 for Success or else Failure
2701   */
synopGMAC_TS_addend_update(synopGMACdevice * gmacdev,u32 addend_value)2702 s32 synopGMAC_TS_addend_update(synopGMACdevice *gmacdev, u32 addend_value)
2703 {
2704     u32 loop_variable;
2705     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSAddend,addend_value);// Load the addend_value in to Addend register
2706     for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++) { //Wait till the busy bit gets cleared with in a certain amount of time
2707         if(!((synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSControl)) & GmacTSADDREG)) { // if it is cleared then break
2708             break;
2709         }
2710         plat_delay(DEFAULT_DELAY_VARIABLE);
2711     }
2712     if(loop_variable < DEFAULT_LOOP_VARIABLE)
2713         synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSADDREG);
2714     else {
2715         TR("Error::: The TSADDREG bit is not getting cleared !!!!!!\n");
2716         return -ESYNOPGMACPHYERR;
2717     }
2718     return 0;
2719 
2720 }
2721 /**
2722   * time stamp Update
2723   * This function updates (adds/subtracts) with the value specified in the Timestamp High Update and
2724   * Timestamp Low Update register.
2725   * @param[in] pointer to synopGMACdevice
2726   * @param[in] Timestamp High Update value
2727   * @param[in] Timestamp Low Update value
2728   * \return returns 0 for Success or else Failure
2729   */
synopGMAC_TS_timestamp_update(synopGMACdevice * gmacdev,u32 high_value,u32 low_value)2730 s32 synopGMAC_TS_timestamp_update(synopGMACdevice *gmacdev, u32 high_value, u32 low_value)
2731 {
2732     u32 loop_variable;
2733     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSHighUpdate,high_value);// Load the high value to Timestamp High register
2734     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSLowUpdate,low_value);// Load the high value to Timestamp High register
2735     for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++) { //Wait till the busy bit gets cleared with in a certain amount of time
2736         if(!((synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSControl)) & GmacTSUPDT)) { // if it is cleared then break
2737             break;
2738         }
2739         plat_delay(DEFAULT_DELAY_VARIABLE);
2740     }
2741     if(loop_variable < DEFAULT_LOOP_VARIABLE)
2742         synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSUPDT);
2743     else {
2744         TR("Error::: The TSADDREG bit is not getting cleared !!!!!!\n");
2745         return -ESYNOPGMACPHYERR;
2746     }
2747     return 0;
2748 }
2749 
2750 /**
2751   * time stamp Initialize
2752   * This function Loads/Initializes h the value specified in the Timestamp High Update and
2753   * Timestamp Low Update register.
2754   * @param[in] pointer to synopGMACdevice
2755   * @param[in] Timestamp High Load value
2756   * @param[in] Timestamp Low Load value
2757   * \return returns 0 for Success or else Failure
2758   */
synopGMAC_TS_timestamp_init(synopGMACdevice * gmacdev,u32 high_value,u32 low_value)2759 s32 synopGMAC_TS_timestamp_init(synopGMACdevice *gmacdev, u32 high_value, u32 low_value)
2760 {
2761     u32 loop_variable;
2762     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSHighUpdate,high_value);// Load the high value to Timestamp High register
2763     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSLowUpdate,low_value);// Load the high value to Timestamp High register
2764     for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++) { //Wait till the busy bit gets cleared with in a certain amount of time
2765         if(!((synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSControl)) & GmacTSINT)) { // if it is cleared then break
2766             break;
2767         }
2768         plat_delay(DEFAULT_DELAY_VARIABLE);
2769     }
2770     if(loop_variable < DEFAULT_LOOP_VARIABLE)
2771         synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSINT);
2772     else {
2773         TR("Error::: The TSADDREG bit is not getting cleared !!!!!!\n");
2774         return -ESYNOPGMACPHYERR;
2775     }
2776     return 0;
2777 }
2778 
2779 /**
2780   * Time Stamp Update Coarse
2781   * When reset the timestamp update is done using coarse method.
2782   * @param[in] pointer to synopGMACdevice
2783   * \return returns void
2784   */
synopGMAC_TS_coarse_update(synopGMACdevice * gmacdev)2785 void synopGMAC_TS_coarse_update(synopGMACdevice *gmacdev)
2786 {
2787     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSCFUPDT);
2788     return;
2789 }
2790 /**
2791   * Time Stamp Update Fine
2792   * When reset the timestamp update is done using Fine method.
2793   * @param[in] pointer to synopGMACdevice
2794   * \return returns void
2795   */
synopGMAC_TS_fine_update(synopGMACdevice * gmacdev)2796 void synopGMAC_TS_fine_update(synopGMACdevice *gmacdev)
2797 {
2798     synopGMACSetBits((u32 *)gmacdev->MacBase,GmacTSControl,GmacTSCFUPDT);
2799     return;
2800 }
2801 
2802 /**
2803   * Load the Sub Second Increment value in to Sub Second increment register
2804   * @param[in] pointer to synopGMACdevice
2805   * \return returns void
2806   */
synopGMAC_TS_subsecond_init(synopGMACdevice * gmacdev,u32 sub_sec_inc_value)2807 void synopGMAC_TS_subsecond_init(synopGMACdevice *gmacdev, u32 sub_sec_inc_value)
2808 {
2809     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSSubSecIncr,(sub_sec_inc_value & GmacSSINCMsk));
2810     return;
2811 }
2812 /**
2813   * Reads the time stamp contents in to the respective pointers
2814   * These registers are readonly.
2815   * This function returns the 48 bit time stamp assuming Version 2 timestamp with higher word is selected.
2816   * @param[in] pointer to synopGMACdevice
2817   * @param[in] pointer to hold 16 higher bit second register contents
2818   * @param[in] pointer to hold 32 bit second register contents
2819   * @param[in] pointer to hold 32 bit subnanosecond register contents
2820   * \return returns void
2821   * \note Please note that since the atomic access to the timestamp registers is not possible,
2822   *  the contents read may be different from the actual time stamp.
2823   */
synopGMAC_TS_read_timestamp(synopGMACdevice * gmacdev,u16 * higher_sec_val,u32 * sec_val,u32 * sub_sec_val)2824 void synopGMAC_TS_read_timestamp(synopGMACdevice *gmacdev, u16 * higher_sec_val, u32 * sec_val, u32 *  sub_sec_val)
2825 {
2826     * higher_sec_val = (u16)(synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSHighWord) & GmacTSHighWordMask);
2827     * sec_val        = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSHigh);
2828     * sub_sec_val    = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSLow);
2829     return;
2830 }
2831 /**
2832   * Loads the time stamp higher sec value from the value supplied
2833   * @param[in] pointer to synopGMACdevice
2834   * @param[in] 16 higher bit second register contents passed as 32 bit value
2835   * \return returns void
2836   */
synopGMAC_TS_load_timestamp_higher_val(synopGMACdevice * gmacdev,u32 higher_sec_val)2837 void synopGMAC_TS_load_timestamp_higher_val(synopGMACdevice *gmacdev, u32 higher_sec_val)
2838 {
2839     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSHighWord, (higher_sec_val & GmacTSHighWordMask));
2840     return;
2841 }
2842 /**
2843   * Reads the time stamp higher sec value to respective pointers
2844   * @param[in] pointer to synopGMACdevice
2845   * @param[in] pointer to hold 16 higher bit second register contents
2846   * \return returns void
2847   */
synopGMAC_TS_read_timestamp_higher_val(synopGMACdevice * gmacdev,u16 * higher_sec_val)2848 void synopGMAC_TS_read_timestamp_higher_val(synopGMACdevice *gmacdev, u16 * higher_sec_val)
2849 {
2850     * higher_sec_val = (u16)(synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSHighWord) & GmacTSHighWordMask);
2851     return;
2852 }
2853 /**
2854   * Load the Target time stamp registers
2855   * This function Loads the target time stamp registers with the values proviced
2856   * @param[in] pointer to synopGMACdevice
2857   * @param[in] target Timestamp High value
2858   * @param[in] target Timestamp Low  value
2859   * \return returns 0 for Success or else Failure
2860   */
synopGMAC_TS_load_target_timestamp(synopGMACdevice * gmacdev,u32 sec_val,u32 sub_sec_val)2861 void synopGMAC_TS_load_target_timestamp(synopGMACdevice *gmacdev, u32 sec_val, u32 sub_sec_val)
2862 {
2863     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSTargetTimeHigh,sec_val);
2864     synopGMACWriteReg((u32 *)gmacdev->MacBase,GmacTSTargetTimeLow,sub_sec_val);
2865     return;
2866 }
2867 /**
2868   * Reads the Target time stamp registers
2869   * This function Loads the target time stamp registers with the values proviced
2870   * @param[in] pointer to synopGMACdevice
2871   * @param[in] pointer to hold target Timestamp High value
2872   * @param[in] pointer to hold target Timestamp Low  value
2873   * \return returns 0 for Success or else Failure
2874   */
synopGMAC_TS_read_target_timestamp(synopGMACdevice * gmacdev,u32 * sec_val,u32 * sub_sec_val)2875 void synopGMAC_TS_read_target_timestamp(synopGMACdevice *gmacdev, u32 * sec_val, u32 * sub_sec_val)
2876 {
2877     * sec_val     = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSTargetTimeHigh);
2878     * sub_sec_val = synopGMACReadReg((u32 *)gmacdev->MacBase,GmacTSTargetTimeLow);
2879     return;
2880 }
2881 
synopGMAC_src_addr_insert_enable(synopGMACdevice * gmacdev)2882 void synopGMAC_src_addr_insert_enable(synopGMACdevice * gmacdev)
2883 {
2884 	synopGMACClearBits((u32 *)gmacdev->MacBase,GmacConfig,GmacSrcAddrInsRpl);
2885 	synopGMACSetBits((u32 *)gmacdev->MacBase,GmacConfig,GmacSrcAddrIns);
2886 
2887 }
synopGMAC_src_addr_insert_disable(synopGMACdevice * gmacdev)2888 void synopGMAC_src_addr_insert_disable(synopGMACdevice * gmacdev)
2889 {
2890 
2891     synopGMACClearBits((u32 *)gmacdev->MacBase,GmacConfig,GmacSrcAddrInsRpl);
2892 
2893 }
synopGMAC_src_addr_replace_enable(synopGMACdevice * gmacdev)2894 void synopGMAC_src_addr_replace_enable(synopGMACdevice * gmacdev)
2895 {
2896 	synopGMACClearBits((u32 *)gmacdev->MacBase,GmacConfig,GmacSrcAddrInsRpl);
2897 	synopGMACSetBits((u32 *)gmacdev->MacBase,GmacConfig,GmacSrcAddrRpl);
2898 
2899 
2900 }
synopGMAC_src_addr_replace_disable(synopGMACdevice * gmacdev)2901 void synopGMAC_src_addr_replace_disable(synopGMACdevice * gmacdev)
2902 {
2903 	synopGMACClearBits((u32 *)gmacdev->MacBase,GmacConfig,GmacSrcAddrInsRpl);
2904 
2905 }
2906 
2907 
synopGMAC_svlan_insertion_enable(synopGMACdevice * gmacdev,u16 vlantag)2908 void synopGMAC_svlan_insertion_enable(synopGMACdevice * gmacdev, u16 vlantag)
2909 {
2910 
2911 	synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacVLANIncRep, GmacVLP | GmacSVLAN | GmacVLANIns| vlantag);
2912 
2913 
2914 }
2915 
synopGMAC_cvlan_insertion_enable(synopGMACdevice * gmacdev,u16 vlantag)2916 void synopGMAC_cvlan_insertion_enable(synopGMACdevice * gmacdev, u16 vlantag)
2917 {
2918 	synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacVLANIncRep, GmacVLP | GmacCVLAN | GmacVLANIns | vlantag);
2919 
2920 
2921 }
2922 
synopGMAC_svlan_replace_enable(synopGMACdevice * gmacdev,u16 vlantag)2923 void synopGMAC_svlan_replace_enable(synopGMACdevice * gmacdev, u16 vlantag)
2924 {
2925 	synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacVLANIncRep, GmacVLP | GmacSVLAN | GmacVLANRep | vlantag);
2926 
2927 }
2928 
synopGMAC_cvlan_replace_enable(synopGMACdevice * gmacdev,u16 vlantag)2929 void synopGMAC_cvlan_replace_enable(synopGMACdevice * gmacdev, u16 vlantag)
2930 {
2931 	synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacVLANIncRep, GmacVLP | GmacCVLAN | GmacVLANRep | vlantag);
2932 
2933 }
2934 
synopGMAC_vlan_deletion_enable(synopGMACdevice * gmacdev)2935 void synopGMAC_vlan_deletion_enable(synopGMACdevice * gmacdev)
2936 {
2937 	synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacVLANIncRep, GmacVLP | GmacVLANDel);
2938 
2939 
2940 }
2941 
2942 
synopGMAC_vlan_no_act_enable(synopGMACdevice * gmacdev)2943 void synopGMAC_vlan_no_act_enable(synopGMACdevice * gmacdev)
2944 {
2945 	synopGMACClearBits((u32 *)gmacdev->MacBase, GmacVLANIncRep, 0xFFFFFFFF);
2946 }
2947 
2948 
2949