xref: /freebsd/sys/contrib/ncsw/Peripherals/FM/MAC/tgec.c (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1 /*
2  * Copyright 2008-2012 Freescale Semiconductor Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above copyright
9  *       notice, this list of conditions and the following disclaimer in the
10  *       documentation and/or other materials provided with the distribution.
11  *     * Neither the name of Freescale Semiconductor nor the
12  *       names of its contributors may be used to endorse or promote products
13  *       derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 
34 /******************************************************************************
35  @File          tgec.c
36 
37  @Description   FM 10G MAC ...
38 *//***************************************************************************/
39 
40 #include "std_ext.h"
41 #include "string_ext.h"
42 #include "error_ext.h"
43 #include "xx_ext.h"
44 #include "endian_ext.h"
45 #include "debug_ext.h"
46 #include "crc_mac_addr_ext.h"
47 
48 #include "fm_common.h"
49 #include "fsl_fman_tgec.h"
50 #include "tgec.h"
51 
52 
53 /*****************************************************************************/
54 /*                      Internal routines                                    */
55 /*****************************************************************************/
56 
57 static t_Error CheckInitParameters(t_Tgec    *p_Tgec)
58 {
59     if (ENET_SPEED_FROM_MODE(p_Tgec->enetMode) < e_ENET_SPEED_10000)
60         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet 10G MAC driver only support 10G speed"));
61 #if (FM_MAX_NUM_OF_10G_MACS > 0)
62     if (p_Tgec->macId >= FM_MAX_NUM_OF_10G_MACS)
63         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("macId of 10G can not be greater than 0"));
64 #endif /* (FM_MAX_NUM_OF_10G_MACS > 0) */
65 
66     if (p_Tgec->addr == 0)
67         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet 10G MAC Must have a valid MAC Address"));
68     if (!p_Tgec->f_Exception)
69         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("uninitialized f_Exception"));
70     if (!p_Tgec->f_Event)
71         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("uninitialized f_Event"));
72 #ifdef FM_LEN_CHECK_ERRATA_FMAN_SW002
73     if (!p_Tgec->p_TgecDriverParam->no_length_check_enable)
74        RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("LengthCheck!"));
75 #endif /* FM_LEN_CHECK_ERRATA_FMAN_SW002 */
76     return E_OK;
77 }
78 
79 /* ......................................................................... */
80 
81 static uint32_t GetMacAddrHashCode(uint64_t ethAddr)
82 {
83     uint32_t crc;
84 
85     /* CRC calculation */
86     GET_MAC_ADDR_CRC(ethAddr, crc);
87 
88     crc = GetMirror32(crc);
89 
90     return crc;
91 }
92 
93 /* ......................................................................... */
94 
95 static void TgecErrException(t_Handle h_Tgec)
96 {
97     t_Tgec              *p_Tgec = (t_Tgec *)h_Tgec;
98     uint32_t            event;
99     struct tgec_regs    *p_TgecMemMap = p_Tgec->p_MemMap;
100 
101     /* do not handle MDIO events */
102     event = fman_tgec_get_event(p_TgecMemMap, ~(TGEC_IMASK_MDIO_SCAN_EVENT | TGEC_IMASK_MDIO_CMD_CMPL));
103     event &= fman_tgec_get_interrupt_mask(p_TgecMemMap);
104 
105     fman_tgec_ack_event(p_TgecMemMap, event);
106 
107     if (event & TGEC_IMASK_REM_FAULT)
108         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_REM_FAULT);
109     if (event & TGEC_IMASK_LOC_FAULT)
110         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_LOC_FAULT);
111     if (event & TGEC_IMASK_TX_ECC_ER)
112         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_1TX_ECC_ER);
113     if (event & TGEC_IMASK_TX_FIFO_UNFL)
114         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_TX_FIFO_UNFL);
115     if (event & TGEC_IMASK_TX_FIFO_OVFL)
116         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_TX_FIFO_OVFL);
117     if (event & TGEC_IMASK_TX_ER)
118         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_TX_ER);
119     if (event & TGEC_IMASK_RX_FIFO_OVFL)
120         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_FIFO_OVFL);
121     if (event & TGEC_IMASK_RX_ECC_ER)
122         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_ECC_ER);
123     if (event & TGEC_IMASK_RX_JAB_FRM)
124         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_JAB_FRM);
125     if (event & TGEC_IMASK_RX_OVRSZ_FRM)
126         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_OVRSZ_FRM);
127     if (event & TGEC_IMASK_RX_RUNT_FRM)
128         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_RUNT_FRM);
129     if (event & TGEC_IMASK_RX_FRAG_FRM)
130         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_FRAG_FRM);
131     if (event & TGEC_IMASK_RX_LEN_ER)
132         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_LEN_ER);
133     if (event & TGEC_IMASK_RX_CRC_ER)
134         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_CRC_ER);
135     if (event & TGEC_IMASK_RX_ALIGN_ER)
136         p_Tgec->f_Exception(p_Tgec->h_App, e_FM_MAC_EX_10G_RX_ALIGN_ER);
137 }
138 
139 /* ......................................................................... */
140 
141 static void TgecException(t_Handle h_Tgec)
142 {
143      t_Tgec             *p_Tgec = (t_Tgec *)h_Tgec;
144      uint32_t           event;
145      struct tgec_regs   *p_TgecMemMap = p_Tgec->p_MemMap;
146 
147      /* handle only MDIO events */
148      event = fman_tgec_get_event(p_TgecMemMap, (TGEC_IMASK_MDIO_SCAN_EVENT | TGEC_IMASK_MDIO_CMD_CMPL));
149      event &= fman_tgec_get_interrupt_mask(p_TgecMemMap);
150 
151      fman_tgec_ack_event(p_TgecMemMap, event);
152 
153      if (event & TGEC_IMASK_MDIO_SCAN_EVENT)
154          p_Tgec->f_Event(p_Tgec->h_App, e_FM_MAC_EX_10G_MDIO_SCAN_EVENTMDIO);
155      if (event & TGEC_IMASK_MDIO_CMD_CMPL)
156          p_Tgec->f_Event(p_Tgec->h_App, e_FM_MAC_EX_10G_MDIO_CMD_CMPL);
157 }
158 
159 /* ......................................................................... */
160 
161 static void FreeInitResources(t_Tgec *p_Tgec)
162 {
163     if (p_Tgec->mdioIrq != NO_IRQ)
164     {
165         XX_DisableIntr(p_Tgec->mdioIrq);
166         XX_FreeIntr(p_Tgec->mdioIrq);
167     }
168 
169     FmUnregisterIntr(p_Tgec->fmMacControllerDriver.h_Fm, e_FM_MOD_10G_MAC, p_Tgec->macId, e_FM_INTR_TYPE_ERR);
170 
171     /* release the driver's group hash table */
172     FreeHashTable(p_Tgec->p_MulticastAddrHash);
173     p_Tgec->p_MulticastAddrHash =   NULL;
174 
175     /* release the driver's individual hash table */
176     FreeHashTable(p_Tgec->p_UnicastAddrHash);
177     p_Tgec->p_UnicastAddrHash =     NULL;
178 }
179 
180 
181 /*****************************************************************************/
182 /*                     10G MAC API routines                                  */
183 /*****************************************************************************/
184 
185 /* ......................................................................... */
186 
187 static t_Error TgecEnable(t_Handle h_Tgec,  e_CommMode mode)
188 {
189     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
190 
191     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
192     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
193 
194     fman_tgec_enable(p_Tgec->p_MemMap, (mode & e_COMM_MODE_RX), (mode & e_COMM_MODE_TX));
195 
196     return E_OK;
197 }
198 
199 /* ......................................................................... */
200 
201 static t_Error TgecDisable (t_Handle h_Tgec, e_CommMode mode)
202 {
203     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
204 
205     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
206     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
207 
208     fman_tgec_disable(p_Tgec->p_MemMap, (mode & e_COMM_MODE_RX), (mode & e_COMM_MODE_TX));
209 
210     return E_OK;
211 }
212 
213 /* ......................................................................... */
214 
215 static t_Error TgecSetPromiscuous(t_Handle h_Tgec, bool newVal)
216 {
217     t_Tgec       *p_Tgec = (t_Tgec *)h_Tgec;
218 
219     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
220     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
221 
222     fman_tgec_set_promiscuous(p_Tgec->p_MemMap, newVal);
223 
224     return E_OK;
225 }
226 
227 
228 /*****************************************************************************/
229 /*                      Tgec Configs modification functions                 */
230 /*****************************************************************************/
231 
232 /* ......................................................................... */
233 
234 static t_Error TgecConfigLoopback(t_Handle h_Tgec, bool newVal)
235 {
236     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
237 
238     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
239     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
240 
241     p_Tgec->p_TgecDriverParam->loopback_enable = newVal;
242 
243     return E_OK;
244 }
245 
246 /* ......................................................................... */
247 
248 static t_Error TgecConfigWan(t_Handle h_Tgec, bool newVal)
249 {
250     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
251 
252     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
253     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
254 
255     p_Tgec->p_TgecDriverParam->wan_mode_enable = newVal;
256 
257     return E_OK;
258 }
259 
260 /* ......................................................................... */
261 
262 static t_Error TgecConfigMaxFrameLength(t_Handle h_Tgec, uint16_t newVal)
263 {
264     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
265 
266     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
267     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
268 
269     p_Tgec->p_TgecDriverParam->max_frame_length = newVal;
270 
271     return E_OK;
272 }
273 
274 /* ......................................................................... */
275 
276 static t_Error TgecConfigLengthCheck(t_Handle h_Tgec, bool newVal)
277 {
278     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
279 
280     UNUSED(newVal);
281 
282     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
283     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
284 
285     p_Tgec->p_TgecDriverParam->no_length_check_enable = !newVal;
286 
287     return E_OK;
288 }
289 
290 /* ......................................................................... */
291 
292 static t_Error TgecConfigException(t_Handle h_Tgec, e_FmMacExceptions exception, bool enable)
293 {
294     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
295     uint32_t    bitMask = 0;
296 
297     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
298     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
299 
300     GET_EXCEPTION_FLAG(bitMask, exception);
301     if (bitMask)
302     {
303         if (enable)
304             p_Tgec->exceptions |= bitMask;
305         else
306             p_Tgec->exceptions &= ~bitMask;
307     }
308     else
309         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
310 
311     return E_OK;
312 }
313 
314 #ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
315 /* ......................................................................... */
316 
317 static t_Error TgecConfigSkipFman11Workaround(t_Handle h_Tgec)
318 {
319     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
320 
321     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
322     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
323 
324     p_Tgec->p_TgecDriverParam->skip_fman11_workaround = TRUE;
325 
326     return E_OK;
327 }
328 #endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */
329 
330 
331 /*****************************************************************************/
332 /*                      Tgec Run Time API functions                         */
333 /*****************************************************************************/
334 
335 /* ......................................................................... */
336 /* backward compatibility. will be removed in the future. */
337 static t_Error TgecTxMacPause(t_Handle h_Tgec, uint16_t pauseTime)
338 {
339     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
340 
341     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_STATE);
342     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
343     fman_tgec_set_tx_pause_frames(p_Tgec->p_MemMap, pauseTime);
344 
345 
346     return E_OK;
347 }
348 
349 /* ......................................................................... */
350 
351 static t_Error TgecSetTxPauseFrames(t_Handle h_Tgec,
352                                     uint8_t  priority,
353                                     uint16_t pauseTime,
354                                     uint16_t threshTime)
355 {
356     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
357 
358     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_STATE);
359     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
360 
361     UNUSED(priority); UNUSED(threshTime);
362 
363     fman_tgec_set_tx_pause_frames(p_Tgec->p_MemMap, pauseTime);
364 
365     return E_OK;
366 }
367 
368 /* ......................................................................... */
369 
370 static t_Error TgecRxIgnoreMacPause(t_Handle h_Tgec, bool en)
371 {
372     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
373 
374     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_STATE);
375     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
376 
377     fman_tgec_set_rx_ignore_pause_frames(p_Tgec->p_MemMap, en);
378 
379     return E_OK;
380 }
381 
382 /* ......................................................................... */
383 
384 static t_Error TgecGetStatistics(t_Handle h_Tgec, t_FmMacStatistics *p_Statistics)
385 {
386     t_Tgec              *p_Tgec = (t_Tgec *)h_Tgec;
387     struct tgec_regs    *p_TgecMemMap;
388 
389     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_NULL_POINTER);
390     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
391     SANITY_CHECK_RETURN_ERROR(p_Statistics, E_NULL_POINTER);
392 
393     p_TgecMemMap = p_Tgec->p_MemMap;
394 
395     p_Statistics->eStatPkts64           = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R64);
396     p_Statistics->eStatPkts65to127      = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R127);
397     p_Statistics->eStatPkts128to255     = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R255);
398     p_Statistics->eStatPkts256to511     = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R511);
399     p_Statistics->eStatPkts512to1023    = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R1023);
400     p_Statistics->eStatPkts1024to1518   = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R1518);
401     p_Statistics->eStatPkts1519to1522   = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_R1519X);
402 /* */
403     p_Statistics->eStatFragments        = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TRFRG);
404     p_Statistics->eStatJabbers          = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TRJBR);
405 
406     p_Statistics->eStatsDropEvents      = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RDRP);
407     p_Statistics->eStatCRCAlignErrors   = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RALN);
408 
409     p_Statistics->eStatUndersizePkts    = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TRUND);
410     p_Statistics->eStatOversizePkts     = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TROVR);
411 /* Pause */
412     p_Statistics->reStatPause           = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RXPF);
413     p_Statistics->teStatPause           = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TXPF);
414 
415 /* MIB II */
416     p_Statistics->ifInOctets            = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_ROCT);
417     p_Statistics->ifInUcastPkts         = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RUCA);
418     p_Statistics->ifInMcastPkts         = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RMCA);
419     p_Statistics->ifInBcastPkts         = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RBCA);
420     p_Statistics->ifInPkts              = p_Statistics->ifInUcastPkts
421                                         + p_Statistics->ifInMcastPkts
422                                         + p_Statistics->ifInBcastPkts;
423     p_Statistics->ifInDiscards          = 0;
424     p_Statistics->ifInErrors            = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_RERR);
425 
426     p_Statistics->ifOutOctets           = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TOCT);
427     p_Statistics->ifOutUcastPkts        = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TUCA);
428     p_Statistics->ifOutMcastPkts        = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TMCA);
429     p_Statistics->ifOutBcastPkts        = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TBCA);
430     p_Statistics->ifOutPkts             = p_Statistics->ifOutUcastPkts
431                                         + p_Statistics->ifOutMcastPkts
432                                         + p_Statistics->ifOutBcastPkts;
433     p_Statistics->ifOutDiscards         = 0;
434     p_Statistics->ifOutErrors           = fman_tgec_get_counter(p_TgecMemMap, E_TGEC_COUNTER_TERR);
435 
436     return E_OK;
437 }
438 
439 /* ......................................................................... */
440 
441 static t_Error TgecEnable1588TimeStamp(t_Handle h_Tgec)
442 {
443     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
444 
445     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
446     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
447 
448     fman_tgec_enable_1588_time_stamp(p_Tgec->p_MemMap, 1);
449 
450     return E_OK;
451 }
452 
453 /* ......................................................................... */
454 
455 static t_Error TgecDisable1588TimeStamp(t_Handle h_Tgec)
456 {
457     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
458 
459     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
460     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
461 
462     fman_tgec_enable_1588_time_stamp(p_Tgec->p_MemMap, 0);
463 
464     return E_OK;
465 }
466 
467 /* ......................................................................... */
468 
469 static t_Error TgecModifyMacAddress (t_Handle h_Tgec, t_EnetAddr *p_EnetAddr)
470 {
471     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
472 
473     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_NULL_POINTER);
474     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
475 
476     p_Tgec->addr = ENET_ADDR_TO_UINT64(*p_EnetAddr);
477     fman_tgec_set_mac_address(p_Tgec->p_MemMap, (uint8_t *)(*p_EnetAddr));
478 
479     return E_OK;
480 }
481 
482 /* ......................................................................... */
483 
484 static t_Error TgecResetCounters (t_Handle h_Tgec)
485 {
486     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
487 
488     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
489     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
490 
491     fman_tgec_reset_stat(p_Tgec->p_MemMap);
492 
493     return E_OK;
494 }
495 
496 /* ......................................................................... */
497 
498 static t_Error TgecAddExactMatchMacAddress(t_Handle h_Tgec, t_EnetAddr *p_EthAddr)
499 {
500     t_Tgec      *p_Tgec = (t_Tgec *) h_Tgec;
501     uint64_t    ethAddr;
502     uint8_t     paddrNum;
503 
504     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
505     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
506 
507     ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
508 
509     if (ethAddr & GROUP_ADDRESS)
510         /* Multicast address has no effect in PADDR */
511         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Multicast address"));
512 
513     /* Make sure no PADDR contains this address */
514     for (paddrNum = 0; paddrNum < TGEC_NUM_OF_PADDRS; paddrNum++)
515         if (p_Tgec->indAddrRegUsed[paddrNum])
516             if (p_Tgec->paddr[paddrNum] == ethAddr)
517                 RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, NO_MSG);
518 
519     /* Find first unused PADDR */
520     for (paddrNum = 0; paddrNum < TGEC_NUM_OF_PADDRS; paddrNum++)
521     {
522         if (!(p_Tgec->indAddrRegUsed[paddrNum]))
523         {
524             /* mark this PADDR as used */
525             p_Tgec->indAddrRegUsed[paddrNum] = TRUE;
526             /* store address */
527             p_Tgec->paddr[paddrNum] = ethAddr;
528 
529             /* put in hardware */
530             fman_tgec_add_addr_in_paddr(p_Tgec->p_MemMap, (uint8_t*)(*p_EthAddr)/* , paddrNum */);
531             p_Tgec->numOfIndAddrInRegs++;
532 
533             return E_OK;
534         }
535     }
536 
537     /* No free PADDR */
538     RETURN_ERROR(MAJOR, E_FULL, NO_MSG);
539 }
540 
541 /* ......................................................................... */
542 
543 static t_Error TgecDelExactMatchMacAddress(t_Handle h_Tgec, t_EnetAddr *p_EthAddr)
544 {
545     t_Tgec      *p_Tgec = (t_Tgec *) h_Tgec;
546     uint64_t    ethAddr;
547     uint8_t     paddrNum;
548 
549     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
550     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
551 
552     ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
553 
554     /* Find used PADDR containing this address */
555     for (paddrNum = 0; paddrNum < TGEC_NUM_OF_PADDRS; paddrNum++)
556     {
557         if ((p_Tgec->indAddrRegUsed[paddrNum]) &&
558             (p_Tgec->paddr[paddrNum] == ethAddr))
559         {
560             /* mark this PADDR as not used */
561             p_Tgec->indAddrRegUsed[paddrNum] = FALSE;
562             /* clear in hardware */
563             fman_tgec_clear_addr_in_paddr(p_Tgec->p_MemMap /*, paddrNum */);
564             p_Tgec->numOfIndAddrInRegs--;
565 
566             return E_OK;
567         }
568     }
569 
570     RETURN_ERROR(MAJOR, E_NOT_FOUND, NO_MSG);
571 }
572 
573 /* ......................................................................... */
574 
575 static t_Error TgecAddHashMacAddress(t_Handle h_Tgec, t_EnetAddr *p_EthAddr)
576 {
577     t_Tgec          *p_Tgec = (t_Tgec *)h_Tgec;
578     t_EthHashEntry  *p_HashEntry;
579     uint32_t        crc;
580     uint32_t        hash;
581     uint64_t        ethAddr;
582 
583     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_NULL_POINTER);
584     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
585 
586     ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
587 
588     if (!(ethAddr & GROUP_ADDRESS))
589         /* Unicast addresses not supported in hash */
590         RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("Unicast Address"));
591 
592     /* CRC calculation */
593     crc = GetMacAddrHashCode(ethAddr);
594 
595     hash = (crc >> TGEC_HASH_MCAST_SHIFT) & TGEC_HASH_ADR_MSK;        /* Take 9 MSB bits */
596 
597     /* Create element to be added to the driver hash table */
598     p_HashEntry = (t_EthHashEntry *)XX_Malloc(sizeof(t_EthHashEntry));
599     p_HashEntry->addr = ethAddr;
600     INIT_LIST(&p_HashEntry->node);
601 
602     NCSW_LIST_AddToTail(&(p_HashEntry->node), &(p_Tgec->p_MulticastAddrHash->p_Lsts[hash]));
603     fman_tgec_set_hash_table(p_Tgec->p_MemMap, (hash | TGEC_HASH_MCAST_EN));
604 
605     return E_OK;
606 }
607 
608 /* ......................................................................... */
609 
610 static t_Error TgecDelHashMacAddress(t_Handle h_Tgec, t_EnetAddr *p_EthAddr)
611 {
612     t_Tgec           *p_Tgec = (t_Tgec *)h_Tgec;
613     t_EthHashEntry   *p_HashEntry = NULL;
614     t_List           *p_Pos;
615     uint32_t         crc;
616     uint32_t         hash;
617     uint64_t         ethAddr;
618 
619     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_NULL_POINTER);
620     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
621 
622     ethAddr = ((*(uint64_t *)p_EthAddr) >> 16);
623 
624     /* CRC calculation */
625     crc = GetMacAddrHashCode(ethAddr);
626 
627     hash = (crc >> TGEC_HASH_MCAST_SHIFT) & TGEC_HASH_ADR_MSK;        /* Take 9 MSB bits */
628 
629     NCSW_LIST_FOR_EACH(p_Pos, &(p_Tgec->p_MulticastAddrHash->p_Lsts[hash]))
630     {
631         p_HashEntry = ETH_HASH_ENTRY_OBJ(p_Pos);
632         if (p_HashEntry->addr == ethAddr)
633         {
634             NCSW_LIST_DelAndInit(&p_HashEntry->node);
635             XX_Free(p_HashEntry);
636             break;
637         }
638     }
639     if (NCSW_LIST_IsEmpty(&p_Tgec->p_MulticastAddrHash->p_Lsts[hash]))
640         fman_tgec_set_hash_table(p_Tgec->p_MemMap, (hash & ~TGEC_HASH_MCAST_EN));
641 
642     return E_OK;
643 }
644 
645 /* ......................................................................... */
646 
647 static t_Error TgecGetId(t_Handle h_Tgec, uint32_t *macId)
648 {
649     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
650 
651     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
652     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
653 
654     UNUSED(p_Tgec);
655     UNUSED(macId);
656     RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("TgecGetId Not Supported"));
657 }
658 
659 /* ......................................................................... */
660 
661 static t_Error TgecGetVersion(t_Handle h_Tgec, uint32_t *macVersion)
662 {
663     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
664 
665     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
666     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
667 
668     *macVersion = fman_tgec_get_revision(p_Tgec->p_MemMap);
669 
670     return E_OK;
671 }
672 
673 /* ......................................................................... */
674 
675 static t_Error TgecSetExcpetion(t_Handle h_Tgec, e_FmMacExceptions exception, bool enable)
676 {
677     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
678     uint32_t    bitMask = 0;
679 
680     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
681     SANITY_CHECK_RETURN_ERROR(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
682 
683     GET_EXCEPTION_FLAG(bitMask, exception);
684     if (bitMask)
685     {
686         if (enable)
687             p_Tgec->exceptions |= bitMask;
688         else
689             p_Tgec->exceptions &= ~bitMask;
690    }
691     else
692         RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
693 
694     if (enable)
695         fman_tgec_enable_interrupt(p_Tgec->p_MemMap, bitMask);
696     else
697         fman_tgec_disable_interrupt(p_Tgec->p_MemMap, bitMask);
698 
699     return E_OK;
700 }
701 
702 /* ......................................................................... */
703 
704 static uint16_t TgecGetMaxFrameLength(t_Handle h_Tgec)
705 {
706     t_Tgec      *p_Tgec = (t_Tgec *)h_Tgec;
707 
708     SANITY_CHECK_RETURN_VALUE(p_Tgec, E_INVALID_HANDLE, 0);
709     SANITY_CHECK_RETURN_VALUE(!p_Tgec->p_TgecDriverParam, E_INVALID_STATE, 0);
710 
711     return fman_tgec_get_max_frame_len(p_Tgec->p_MemMap);
712 }
713 
714 /* ......................................................................... */
715 
716 #ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
717 static t_Error TgecTxEccWorkaround(t_Tgec *p_Tgec)
718 {
719     t_Error err;
720 
721 #if defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)
722     XX_Print("Applying 10G TX ECC workaround (10GMAC-A004) ... ");
723 #endif /* (DEBUG_ERRORS > 0) */
724     /* enable and set promiscuous */
725     fman_tgec_enable(p_Tgec->p_MemMap, TRUE, TRUE);
726     fman_tgec_set_promiscuous(p_Tgec->p_MemMap, TRUE);
727     err = Fm10GTxEccWorkaround(p_Tgec->fmMacControllerDriver.h_Fm, p_Tgec->macId);
728     /* disable */
729     fman_tgec_set_promiscuous(p_Tgec->p_MemMap, FALSE);
730     fman_tgec_enable(p_Tgec->p_MemMap, FALSE, FALSE);
731     fman_tgec_reset_stat(p_Tgec->p_MemMap);
732     fman_tgec_ack_event(p_Tgec->p_MemMap, 0xffffffff);
733 #if defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)
734     if (err)
735         XX_Print("FAILED!\n");
736     else
737         XX_Print("done.\n");
738 #endif /* (DEBUG_ERRORS > 0) */
739 
740     return err;
741 }
742 #endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */
743 
744 /*****************************************************************************/
745 /*                      FM Init & Free API                                   */
746 /*****************************************************************************/
747 
748 /* ......................................................................... */
749 
750 static t_Error TgecInit(t_Handle h_Tgec)
751 {
752     t_Tgec                  *p_Tgec = (t_Tgec *)h_Tgec;
753     struct tgec_cfg         *p_TgecDriverParam;
754     t_EnetAddr              ethAddr;
755     t_Error                 err;
756 
757     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
758     SANITY_CHECK_RETURN_ERROR(p_Tgec->p_TgecDriverParam, E_INVALID_STATE);
759     SANITY_CHECK_RETURN_ERROR(p_Tgec->fmMacControllerDriver.h_Fm, E_INVALID_HANDLE);
760 
761     FM_GetRevision(p_Tgec->fmMacControllerDriver.h_Fm, &p_Tgec->fmMacControllerDriver.fmRevInfo);
762     CHECK_INIT_PARAMETERS(p_Tgec, CheckInitParameters);
763 
764     p_TgecDriverParam = p_Tgec->p_TgecDriverParam;
765 
766     MAKE_ENET_ADDR_FROM_UINT64(p_Tgec->addr, ethAddr);
767     fman_tgec_set_mac_address(p_Tgec->p_MemMap, (uint8_t *)ethAddr);
768 
769     /* interrupts */
770 #ifdef FM_10G_REM_N_LCL_FLT_EX_10GMAC_ERRATA_SW005
771     {
772         if (p_Tgec->fmMacControllerDriver.fmRevInfo.majorRev <=2)
773             p_Tgec->exceptions &= ~(TGEC_IMASK_REM_FAULT | TGEC_IMASK_LOC_FAULT);
774     }
775 #endif /* FM_10G_REM_N_LCL_FLT_EX_10GMAC_ERRATA_SW005 */
776 
777 #ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
778     if (!p_Tgec->p_TgecDriverParam->skip_fman11_workaround &&
779         ((err = TgecTxEccWorkaround(p_Tgec)) != E_OK))
780     {
781         FreeInitResources(p_Tgec);
782         REPORT_ERROR(MINOR, err, ("TgecTxEccWorkaround FAILED"));
783     }
784 #endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */
785 
786     err = fman_tgec_init(p_Tgec->p_MemMap, p_TgecDriverParam, p_Tgec->exceptions);
787     if (err)
788     {
789         FreeInitResources(p_Tgec);
790         RETURN_ERROR(MAJOR, err, ("This TGEC version does not support the required i/f mode"));
791     }
792 
793     /* Max Frame Length */
794     err = FmSetMacMaxFrame(p_Tgec->fmMacControllerDriver.h_Fm,
795                            e_FM_MAC_10G,
796                            p_Tgec->fmMacControllerDriver.macId,
797                            p_TgecDriverParam->max_frame_length);
798     if (err != E_OK)
799     {
800         FreeInitResources(p_Tgec);
801         RETURN_ERROR(MINOR, err, NO_MSG);
802     }
803 /* we consider having no IPC a non crasher... */
804 
805 #ifdef FM_TX_FIFO_CORRUPTION_ERRATA_10GMAC_A007
806     if (p_Tgec->fmMacControllerDriver.fmRevInfo.majorRev == 2)
807         fman_tgec_set_erratum_tx_fifo_corruption_10gmac_a007(p_Tgec->p_MemMap);
808 #endif /* FM_TX_FIFO_CORRUPTION_ERRATA_10GMAC_A007 */
809 
810     p_Tgec->p_MulticastAddrHash = AllocHashTable(HASH_TABLE_SIZE);
811     if (!p_Tgec->p_MulticastAddrHash)
812     {
813         FreeInitResources(p_Tgec);
814         RETURN_ERROR(MAJOR, E_NO_MEMORY, ("allocation hash table is FAILED"));
815     }
816 
817     p_Tgec->p_UnicastAddrHash = AllocHashTable(HASH_TABLE_SIZE);
818     if (!p_Tgec->p_UnicastAddrHash)
819     {
820         FreeInitResources(p_Tgec);
821         RETURN_ERROR(MAJOR, E_NO_MEMORY, ("allocation hash table is FAILED"));
822     }
823 
824     FmRegisterIntr(p_Tgec->fmMacControllerDriver.h_Fm,
825                    e_FM_MOD_10G_MAC,
826                    p_Tgec->macId,
827                    e_FM_INTR_TYPE_ERR,
828                    TgecErrException,
829                    p_Tgec);
830     if (p_Tgec->mdioIrq != NO_IRQ)
831     {
832         XX_SetIntr(p_Tgec->mdioIrq, TgecException, p_Tgec);
833         XX_EnableIntr(p_Tgec->mdioIrq);
834     }
835 
836     XX_Free(p_TgecDriverParam);
837     p_Tgec->p_TgecDriverParam = NULL;
838 
839     return E_OK;
840 }
841 
842 /* ......................................................................... */
843 
844 static t_Error TgecFree(t_Handle h_Tgec)
845 {
846     t_Tgec       *p_Tgec = (t_Tgec *)h_Tgec;
847 
848     SANITY_CHECK_RETURN_ERROR(p_Tgec, E_INVALID_HANDLE);
849 
850     if (p_Tgec->p_TgecDriverParam)
851     {
852         /* Called after config */
853         XX_Free(p_Tgec->p_TgecDriverParam);
854         p_Tgec->p_TgecDriverParam = NULL;
855     }
856     else
857         /* Called after init */
858         FreeInitResources(p_Tgec);
859 
860     XX_Free(p_Tgec);
861 
862     return E_OK;
863 }
864 
865 /* ......................................................................... */
866 
867 static void InitFmMacControllerDriver(t_FmMacControllerDriver *p_FmMacControllerDriver)
868 {
869     p_FmMacControllerDriver->f_FM_MAC_Init                      = TgecInit;
870     p_FmMacControllerDriver->f_FM_MAC_Free                      = TgecFree;
871 
872     p_FmMacControllerDriver->f_FM_MAC_SetStatistics             = NULL;
873     p_FmMacControllerDriver->f_FM_MAC_ConfigLoopback            = TgecConfigLoopback;
874     p_FmMacControllerDriver->f_FM_MAC_ConfigMaxFrameLength      = TgecConfigMaxFrameLength;
875 
876     p_FmMacControllerDriver->f_FM_MAC_ConfigWan                 = TgecConfigWan;
877 
878     p_FmMacControllerDriver->f_FM_MAC_ConfigPadAndCrc           = NULL; /* TGEC always works with pad+crc */
879     p_FmMacControllerDriver->f_FM_MAC_ConfigHalfDuplex          = NULL; /* half-duplex is not supported in xgec */
880     p_FmMacControllerDriver->f_FM_MAC_ConfigLengthCheck         = TgecConfigLengthCheck;
881     p_FmMacControllerDriver->f_FM_MAC_ConfigException           = TgecConfigException;
882     p_FmMacControllerDriver->f_FM_MAC_ConfigResetOnInit         = NULL;
883 
884 #ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
885     p_FmMacControllerDriver->f_FM_MAC_ConfigSkipFman11Workaround= TgecConfigSkipFman11Workaround;
886 #endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */
887 
888     p_FmMacControllerDriver->f_FM_MAC_SetException              = TgecSetExcpetion;
889 
890     p_FmMacControllerDriver->f_FM_MAC_Enable1588TimeStamp       = TgecEnable1588TimeStamp;
891     p_FmMacControllerDriver->f_FM_MAC_Disable1588TimeStamp      = TgecDisable1588TimeStamp;
892 
893     p_FmMacControllerDriver->f_FM_MAC_SetPromiscuous            = TgecSetPromiscuous;
894     p_FmMacControllerDriver->f_FM_MAC_AdjustLink                = NULL;
895     p_FmMacControllerDriver->f_FM_MAC_SetWakeOnLan              = NULL;
896     p_FmMacControllerDriver->f_FM_MAC_RestartAutoneg            = NULL;
897 
898     p_FmMacControllerDriver->f_FM_MAC_Enable                    = TgecEnable;
899     p_FmMacControllerDriver->f_FM_MAC_Disable                   = TgecDisable;
900     p_FmMacControllerDriver->f_FM_MAC_Resume                    = NULL;
901 
902     p_FmMacControllerDriver->f_FM_MAC_SetTxAutoPauseFrames      = TgecTxMacPause;
903     p_FmMacControllerDriver->f_FM_MAC_SetTxPauseFrames          = TgecSetTxPauseFrames;
904     p_FmMacControllerDriver->f_FM_MAC_SetRxIgnorePauseFrames    = TgecRxIgnoreMacPause;
905 
906     p_FmMacControllerDriver->f_FM_MAC_ResetCounters             = TgecResetCounters;
907     p_FmMacControllerDriver->f_FM_MAC_GetStatistics             = TgecGetStatistics;
908 
909     p_FmMacControllerDriver->f_FM_MAC_ModifyMacAddr             = TgecModifyMacAddress;
910     p_FmMacControllerDriver->f_FM_MAC_AddHashMacAddr            = TgecAddHashMacAddress;
911     p_FmMacControllerDriver->f_FM_MAC_RemoveHashMacAddr         = TgecDelHashMacAddress;
912     p_FmMacControllerDriver->f_FM_MAC_AddExactMatchMacAddr      = TgecAddExactMatchMacAddress;
913     p_FmMacControllerDriver->f_FM_MAC_RemovelExactMatchMacAddr  = TgecDelExactMatchMacAddress;
914     p_FmMacControllerDriver->f_FM_MAC_GetId                     = TgecGetId;
915     p_FmMacControllerDriver->f_FM_MAC_GetVersion                = TgecGetVersion;
916     p_FmMacControllerDriver->f_FM_MAC_GetMaxFrameLength         = TgecGetMaxFrameLength;
917 
918     p_FmMacControllerDriver->f_FM_MAC_MII_WritePhyReg           = TGEC_MII_WritePhyReg;
919     p_FmMacControllerDriver->f_FM_MAC_MII_ReadPhyReg            = TGEC_MII_ReadPhyReg;
920 }
921 
922 
923 /*****************************************************************************/
924 /*                      Tgec Config  Main Entry                             */
925 /*****************************************************************************/
926 
927 /* ......................................................................... */
928 
929 t_Handle TGEC_Config(t_FmMacParams *p_FmMacParam)
930 {
931     t_Tgec              *p_Tgec;
932     struct tgec_cfg     *p_TgecDriverParam;
933     uintptr_t           baseAddr;
934 
935     SANITY_CHECK_RETURN_VALUE(p_FmMacParam, E_NULL_POINTER, NULL);
936 
937     baseAddr = p_FmMacParam->baseAddr;
938     /* allocate memory for the UCC GETH data structure. */
939     p_Tgec = (t_Tgec *)XX_Malloc(sizeof(t_Tgec));
940     if (!p_Tgec)
941     {
942         REPORT_ERROR(MAJOR, E_NO_MEMORY, ("10G MAC driver structure"));
943         return NULL;
944     }
945     memset(p_Tgec, 0, sizeof(t_Tgec));
946     InitFmMacControllerDriver(&p_Tgec->fmMacControllerDriver);
947 
948     /* allocate memory for the 10G MAC driver parameters data structure. */
949     p_TgecDriverParam = (struct tgec_cfg *) XX_Malloc(sizeof(struct tgec_cfg));
950     if (!p_TgecDriverParam)
951     {
952         REPORT_ERROR(MAJOR, E_NO_MEMORY, ("10G MAC driver parameters"));
953         XX_Free(p_Tgec);
954         return NULL;
955     }
956     memset(p_TgecDriverParam, 0, sizeof(struct tgec_cfg));
957 
958     /* Plant parameter structure pointer */
959     p_Tgec->p_TgecDriverParam = p_TgecDriverParam;
960 
961     fman_tgec_defconfig(p_TgecDriverParam);
962 
963     p_Tgec->p_MemMap        = (struct tgec_regs *)UINT_TO_PTR(baseAddr);
964     p_Tgec->p_MiiMemMap     = (t_TgecMiiAccessMemMap *)UINT_TO_PTR(baseAddr + TGEC_TO_MII_OFFSET);
965     p_Tgec->addr            = ENET_ADDR_TO_UINT64(p_FmMacParam->addr);
966     p_Tgec->enetMode        = p_FmMacParam->enetMode;
967     p_Tgec->macId           = p_FmMacParam->macId;
968     p_Tgec->exceptions      = DEFAULT_exceptions;
969     p_Tgec->mdioIrq         = p_FmMacParam->mdioIrq;
970     p_Tgec->f_Exception     = p_FmMacParam->f_Exception;
971     p_Tgec->f_Event         = p_FmMacParam->f_Event;
972     p_Tgec->h_App           = p_FmMacParam->h_App;
973 
974     return p_Tgec;
975 }
976