1*852ba100SJustin Hibbits /*
2*852ba100SJustin Hibbits * Copyright 2008-2012 Freescale Semiconductor Inc.
3*852ba100SJustin Hibbits *
4*852ba100SJustin Hibbits * Redistribution and use in source and binary forms, with or without
5*852ba100SJustin Hibbits * modification, are permitted provided that the following conditions are met:
6*852ba100SJustin Hibbits * * Redistributions of source code must retain the above copyright
7*852ba100SJustin Hibbits * notice, this list of conditions and the following disclaimer.
8*852ba100SJustin Hibbits * * Redistributions in binary form must reproduce the above copyright
9*852ba100SJustin Hibbits * notice, this list of conditions and the following disclaimer in the
10*852ba100SJustin Hibbits * documentation and/or other materials provided with the distribution.
11*852ba100SJustin Hibbits * * Neither the name of Freescale Semiconductor nor the
12*852ba100SJustin Hibbits * names of its contributors may be used to endorse or promote products
13*852ba100SJustin Hibbits * derived from this software without specific prior written permission.
14*852ba100SJustin Hibbits *
15*852ba100SJustin Hibbits *
16*852ba100SJustin Hibbits * ALTERNATIVELY, this software may be distributed under the terms of the
17*852ba100SJustin Hibbits * GNU General Public License ("GPL") as published by the Free Software
18*852ba100SJustin Hibbits * Foundation, either version 2 of that License or (at your option) any
19*852ba100SJustin Hibbits * later version.
20*852ba100SJustin Hibbits *
21*852ba100SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22*852ba100SJustin Hibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23*852ba100SJustin Hibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24*852ba100SJustin Hibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25*852ba100SJustin Hibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26*852ba100SJustin Hibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27*852ba100SJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28*852ba100SJustin Hibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29*852ba100SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30*852ba100SJustin Hibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*852ba100SJustin Hibbits */
32*852ba100SJustin Hibbits
33*852ba100SJustin Hibbits
34*852ba100SJustin Hibbits #include "fsl_fman_memac.h"
35*852ba100SJustin Hibbits
36*852ba100SJustin Hibbits
fman_memac_get_event(struct memac_regs * regs,uint32_t ev_mask)37*852ba100SJustin Hibbits uint32_t fman_memac_get_event(struct memac_regs *regs, uint32_t ev_mask)
38*852ba100SJustin Hibbits {
39*852ba100SJustin Hibbits return ioread32be(®s->ievent) & ev_mask;
40*852ba100SJustin Hibbits }
41*852ba100SJustin Hibbits
fman_memac_get_interrupt_mask(struct memac_regs * regs)42*852ba100SJustin Hibbits uint32_t fman_memac_get_interrupt_mask(struct memac_regs *regs)
43*852ba100SJustin Hibbits {
44*852ba100SJustin Hibbits return ioread32be(®s->imask);
45*852ba100SJustin Hibbits }
46*852ba100SJustin Hibbits
fman_memac_ack_event(struct memac_regs * regs,uint32_t ev_mask)47*852ba100SJustin Hibbits void fman_memac_ack_event(struct memac_regs *regs, uint32_t ev_mask)
48*852ba100SJustin Hibbits {
49*852ba100SJustin Hibbits iowrite32be(ev_mask, ®s->ievent);
50*852ba100SJustin Hibbits }
51*852ba100SJustin Hibbits
fman_memac_set_promiscuous(struct memac_regs * regs,bool val)52*852ba100SJustin Hibbits void fman_memac_set_promiscuous(struct memac_regs *regs, bool val)
53*852ba100SJustin Hibbits {
54*852ba100SJustin Hibbits uint32_t tmp;
55*852ba100SJustin Hibbits
56*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
57*852ba100SJustin Hibbits
58*852ba100SJustin Hibbits if (val)
59*852ba100SJustin Hibbits tmp |= CMD_CFG_PROMIS_EN;
60*852ba100SJustin Hibbits else
61*852ba100SJustin Hibbits tmp &= ~CMD_CFG_PROMIS_EN;
62*852ba100SJustin Hibbits
63*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
64*852ba100SJustin Hibbits }
65*852ba100SJustin Hibbits
fman_memac_clear_addr_in_paddr(struct memac_regs * regs,uint8_t paddr_num)66*852ba100SJustin Hibbits void fman_memac_clear_addr_in_paddr(struct memac_regs *regs,
67*852ba100SJustin Hibbits uint8_t paddr_num)
68*852ba100SJustin Hibbits {
69*852ba100SJustin Hibbits if (paddr_num == 0) {
70*852ba100SJustin Hibbits iowrite32be(0, ®s->mac_addr0.mac_addr_l);
71*852ba100SJustin Hibbits iowrite32be(0, ®s->mac_addr0.mac_addr_u);
72*852ba100SJustin Hibbits } else {
73*852ba100SJustin Hibbits iowrite32be(0x0, ®s->mac_addr[paddr_num - 1].mac_addr_l);
74*852ba100SJustin Hibbits iowrite32be(0x0, ®s->mac_addr[paddr_num - 1].mac_addr_u);
75*852ba100SJustin Hibbits }
76*852ba100SJustin Hibbits }
77*852ba100SJustin Hibbits
fman_memac_add_addr_in_paddr(struct memac_regs * regs,uint8_t * adr,uint8_t paddr_num)78*852ba100SJustin Hibbits void fman_memac_add_addr_in_paddr(struct memac_regs *regs,
79*852ba100SJustin Hibbits uint8_t *adr,
80*852ba100SJustin Hibbits uint8_t paddr_num)
81*852ba100SJustin Hibbits {
82*852ba100SJustin Hibbits uint32_t tmp0, tmp1;
83*852ba100SJustin Hibbits
84*852ba100SJustin Hibbits tmp0 = (uint32_t)(adr[0] |
85*852ba100SJustin Hibbits adr[1] << 8 |
86*852ba100SJustin Hibbits adr[2] << 16 |
87*852ba100SJustin Hibbits adr[3] << 24);
88*852ba100SJustin Hibbits tmp1 = (uint32_t)(adr[4] | adr[5] << 8);
89*852ba100SJustin Hibbits
90*852ba100SJustin Hibbits if (paddr_num == 0) {
91*852ba100SJustin Hibbits iowrite32be(tmp0, ®s->mac_addr0.mac_addr_l);
92*852ba100SJustin Hibbits iowrite32be(tmp1, ®s->mac_addr0.mac_addr_u);
93*852ba100SJustin Hibbits } else {
94*852ba100SJustin Hibbits iowrite32be(tmp0, ®s->mac_addr[paddr_num-1].mac_addr_l);
95*852ba100SJustin Hibbits iowrite32be(tmp1, ®s->mac_addr[paddr_num-1].mac_addr_u);
96*852ba100SJustin Hibbits }
97*852ba100SJustin Hibbits }
98*852ba100SJustin Hibbits
fman_memac_enable(struct memac_regs * regs,bool apply_rx,bool apply_tx)99*852ba100SJustin Hibbits void fman_memac_enable(struct memac_regs *regs, bool apply_rx, bool apply_tx)
100*852ba100SJustin Hibbits {
101*852ba100SJustin Hibbits uint32_t tmp;
102*852ba100SJustin Hibbits
103*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
104*852ba100SJustin Hibbits
105*852ba100SJustin Hibbits if (apply_rx)
106*852ba100SJustin Hibbits tmp |= CMD_CFG_RX_EN;
107*852ba100SJustin Hibbits
108*852ba100SJustin Hibbits if (apply_tx)
109*852ba100SJustin Hibbits tmp |= CMD_CFG_TX_EN;
110*852ba100SJustin Hibbits
111*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
112*852ba100SJustin Hibbits }
113*852ba100SJustin Hibbits
fman_memac_disable(struct memac_regs * regs,bool apply_rx,bool apply_tx)114*852ba100SJustin Hibbits void fman_memac_disable(struct memac_regs *regs, bool apply_rx, bool apply_tx)
115*852ba100SJustin Hibbits {
116*852ba100SJustin Hibbits uint32_t tmp;
117*852ba100SJustin Hibbits
118*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
119*852ba100SJustin Hibbits
120*852ba100SJustin Hibbits if (apply_rx)
121*852ba100SJustin Hibbits tmp &= ~CMD_CFG_RX_EN;
122*852ba100SJustin Hibbits
123*852ba100SJustin Hibbits if (apply_tx)
124*852ba100SJustin Hibbits tmp &= ~CMD_CFG_TX_EN;
125*852ba100SJustin Hibbits
126*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
127*852ba100SJustin Hibbits }
128*852ba100SJustin Hibbits
fman_memac_reset_stat(struct memac_regs * regs)129*852ba100SJustin Hibbits void fman_memac_reset_stat(struct memac_regs *regs)
130*852ba100SJustin Hibbits {
131*852ba100SJustin Hibbits uint32_t tmp;
132*852ba100SJustin Hibbits
133*852ba100SJustin Hibbits tmp = ioread32be(®s->statn_config);
134*852ba100SJustin Hibbits
135*852ba100SJustin Hibbits tmp |= STATS_CFG_CLR;
136*852ba100SJustin Hibbits
137*852ba100SJustin Hibbits iowrite32be(tmp, ®s->statn_config);
138*852ba100SJustin Hibbits
139*852ba100SJustin Hibbits while (ioread32be(®s->statn_config) & STATS_CFG_CLR);
140*852ba100SJustin Hibbits }
141*852ba100SJustin Hibbits
fman_memac_reset(struct memac_regs * regs)142*852ba100SJustin Hibbits void fman_memac_reset(struct memac_regs *regs)
143*852ba100SJustin Hibbits {
144*852ba100SJustin Hibbits uint32_t tmp;
145*852ba100SJustin Hibbits
146*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
147*852ba100SJustin Hibbits
148*852ba100SJustin Hibbits tmp |= CMD_CFG_SW_RESET;
149*852ba100SJustin Hibbits
150*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
151*852ba100SJustin Hibbits
152*852ba100SJustin Hibbits while (ioread32be(®s->command_config) & CMD_CFG_SW_RESET);
153*852ba100SJustin Hibbits }
154*852ba100SJustin Hibbits
fman_memac_init(struct memac_regs * regs,struct memac_cfg * cfg,enum enet_interface enet_interface,enum enet_speed enet_speed,bool slow_10g_if,uint32_t exceptions)155*852ba100SJustin Hibbits int fman_memac_init(struct memac_regs *regs,
156*852ba100SJustin Hibbits struct memac_cfg *cfg,
157*852ba100SJustin Hibbits enum enet_interface enet_interface,
158*852ba100SJustin Hibbits enum enet_speed enet_speed,
159*852ba100SJustin Hibbits bool slow_10g_if,
160*852ba100SJustin Hibbits uint32_t exceptions)
161*852ba100SJustin Hibbits {
162*852ba100SJustin Hibbits uint32_t tmp;
163*852ba100SJustin Hibbits
164*852ba100SJustin Hibbits /* Config */
165*852ba100SJustin Hibbits tmp = 0;
166*852ba100SJustin Hibbits if (cfg->wan_mode_enable)
167*852ba100SJustin Hibbits tmp |= CMD_CFG_WAN_MODE;
168*852ba100SJustin Hibbits if (cfg->promiscuous_mode_enable)
169*852ba100SJustin Hibbits tmp |= CMD_CFG_PROMIS_EN;
170*852ba100SJustin Hibbits if (cfg->pause_forward_enable)
171*852ba100SJustin Hibbits tmp |= CMD_CFG_PAUSE_FWD;
172*852ba100SJustin Hibbits if (cfg->pause_ignore)
173*852ba100SJustin Hibbits tmp |= CMD_CFG_PAUSE_IGNORE;
174*852ba100SJustin Hibbits if (cfg->tx_addr_ins_enable)
175*852ba100SJustin Hibbits tmp |= CMD_CFG_TX_ADDR_INS;
176*852ba100SJustin Hibbits if (cfg->loopback_enable)
177*852ba100SJustin Hibbits tmp |= CMD_CFG_LOOPBACK_EN;
178*852ba100SJustin Hibbits if (cfg->cmd_frame_enable)
179*852ba100SJustin Hibbits tmp |= CMD_CFG_CNT_FRM_EN;
180*852ba100SJustin Hibbits if (cfg->send_idle_enable)
181*852ba100SJustin Hibbits tmp |= CMD_CFG_SEND_IDLE;
182*852ba100SJustin Hibbits if (cfg->no_length_check_enable)
183*852ba100SJustin Hibbits tmp |= CMD_CFG_NO_LEN_CHK;
184*852ba100SJustin Hibbits if (cfg->rx_sfd_any)
185*852ba100SJustin Hibbits tmp |= CMD_CFG_SFD_ANY;
186*852ba100SJustin Hibbits if (cfg->pad_enable)
187*852ba100SJustin Hibbits tmp |= CMD_CFG_TX_PAD_EN;
188*852ba100SJustin Hibbits if (cfg->wake_on_lan)
189*852ba100SJustin Hibbits tmp |= CMD_CFG_MG;
190*852ba100SJustin Hibbits
191*852ba100SJustin Hibbits tmp |= CMD_CFG_CRC_FWD;
192*852ba100SJustin Hibbits
193*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
194*852ba100SJustin Hibbits
195*852ba100SJustin Hibbits /* Max Frame Length */
196*852ba100SJustin Hibbits iowrite32be((uint32_t)cfg->max_frame_length, ®s->maxfrm);
197*852ba100SJustin Hibbits
198*852ba100SJustin Hibbits /* Pause Time */
199*852ba100SJustin Hibbits iowrite32be((uint32_t)cfg->pause_quanta, ®s->pause_quanta[0]);
200*852ba100SJustin Hibbits iowrite32be((uint32_t)0, ®s->pause_thresh[0]);
201*852ba100SJustin Hibbits
202*852ba100SJustin Hibbits /* IF_MODE */
203*852ba100SJustin Hibbits tmp = 0;
204*852ba100SJustin Hibbits switch (enet_interface) {
205*852ba100SJustin Hibbits case E_ENET_IF_XGMII:
206*852ba100SJustin Hibbits case E_ENET_IF_XFI:
207*852ba100SJustin Hibbits tmp |= IF_MODE_XGMII;
208*852ba100SJustin Hibbits break;
209*852ba100SJustin Hibbits default:
210*852ba100SJustin Hibbits tmp |= IF_MODE_GMII;
211*852ba100SJustin Hibbits if (enet_interface == E_ENET_IF_RGMII && !cfg->loopback_enable)
212*852ba100SJustin Hibbits tmp |= IF_MODE_RGMII | IF_MODE_RGMII_AUTO;
213*852ba100SJustin Hibbits }
214*852ba100SJustin Hibbits iowrite32be(tmp, ®s->if_mode);
215*852ba100SJustin Hibbits
216*852ba100SJustin Hibbits /* TX_FIFO_SECTIONS */
217*852ba100SJustin Hibbits tmp = 0;
218*852ba100SJustin Hibbits if (enet_interface == E_ENET_IF_XGMII ||
219*852ba100SJustin Hibbits enet_interface == E_ENET_IF_XFI) {
220*852ba100SJustin Hibbits if(slow_10g_if) {
221*852ba100SJustin Hibbits tmp |= (TX_FIFO_SECTIONS_TX_AVAIL_SLOW_10G |
222*852ba100SJustin Hibbits TX_FIFO_SECTIONS_TX_EMPTY_DEFAULT_10G);
223*852ba100SJustin Hibbits } else {
224*852ba100SJustin Hibbits tmp |= (TX_FIFO_SECTIONS_TX_AVAIL_10G |
225*852ba100SJustin Hibbits TX_FIFO_SECTIONS_TX_EMPTY_DEFAULT_10G);
226*852ba100SJustin Hibbits }
227*852ba100SJustin Hibbits } else {
228*852ba100SJustin Hibbits tmp |= (TX_FIFO_SECTIONS_TX_AVAIL_1G |
229*852ba100SJustin Hibbits TX_FIFO_SECTIONS_TX_EMPTY_DEFAULT_1G);
230*852ba100SJustin Hibbits }
231*852ba100SJustin Hibbits iowrite32be(tmp, ®s->tx_fifo_sections);
232*852ba100SJustin Hibbits
233*852ba100SJustin Hibbits /* clear all pending events and set-up interrupts */
234*852ba100SJustin Hibbits fman_memac_ack_event(regs, 0xffffffff);
235*852ba100SJustin Hibbits fman_memac_set_exception(regs, exceptions, TRUE);
236*852ba100SJustin Hibbits
237*852ba100SJustin Hibbits return 0;
238*852ba100SJustin Hibbits }
239*852ba100SJustin Hibbits
fman_memac_set_exception(struct memac_regs * regs,uint32_t val,bool enable)240*852ba100SJustin Hibbits void fman_memac_set_exception(struct memac_regs *regs, uint32_t val, bool enable)
241*852ba100SJustin Hibbits {
242*852ba100SJustin Hibbits uint32_t tmp;
243*852ba100SJustin Hibbits
244*852ba100SJustin Hibbits tmp = ioread32be(®s->imask);
245*852ba100SJustin Hibbits if (enable)
246*852ba100SJustin Hibbits tmp |= val;
247*852ba100SJustin Hibbits else
248*852ba100SJustin Hibbits tmp &= ~val;
249*852ba100SJustin Hibbits
250*852ba100SJustin Hibbits iowrite32be(tmp, ®s->imask);
251*852ba100SJustin Hibbits }
252*852ba100SJustin Hibbits
fman_memac_reset_filter_table(struct memac_regs * regs)253*852ba100SJustin Hibbits void fman_memac_reset_filter_table(struct memac_regs *regs)
254*852ba100SJustin Hibbits {
255*852ba100SJustin Hibbits uint32_t i;
256*852ba100SJustin Hibbits for (i = 0; i < 64; i++)
257*852ba100SJustin Hibbits iowrite32be(i & ~HASH_CTRL_MCAST_EN, ®s->hashtable_ctrl);
258*852ba100SJustin Hibbits }
259*852ba100SJustin Hibbits
fman_memac_set_hash_table_entry(struct memac_regs * regs,uint32_t crc)260*852ba100SJustin Hibbits void fman_memac_set_hash_table_entry(struct memac_regs *regs, uint32_t crc)
261*852ba100SJustin Hibbits {
262*852ba100SJustin Hibbits iowrite32be(crc | HASH_CTRL_MCAST_EN, ®s->hashtable_ctrl);
263*852ba100SJustin Hibbits }
264*852ba100SJustin Hibbits
fman_memac_set_hash_table(struct memac_regs * regs,uint32_t val)265*852ba100SJustin Hibbits void fman_memac_set_hash_table(struct memac_regs *regs, uint32_t val)
266*852ba100SJustin Hibbits {
267*852ba100SJustin Hibbits iowrite32be(val, ®s->hashtable_ctrl);
268*852ba100SJustin Hibbits }
269*852ba100SJustin Hibbits
fman_memac_get_max_frame_len(struct memac_regs * regs)270*852ba100SJustin Hibbits uint16_t fman_memac_get_max_frame_len(struct memac_regs *regs)
271*852ba100SJustin Hibbits {
272*852ba100SJustin Hibbits uint32_t tmp;
273*852ba100SJustin Hibbits
274*852ba100SJustin Hibbits tmp = ioread32be(®s->maxfrm);
275*852ba100SJustin Hibbits
276*852ba100SJustin Hibbits return(uint16_t)tmp;
277*852ba100SJustin Hibbits }
278*852ba100SJustin Hibbits
279*852ba100SJustin Hibbits
fman_memac_set_tx_pause_frames(struct memac_regs * regs,uint8_t priority,uint16_t pause_time,uint16_t thresh_time)280*852ba100SJustin Hibbits void fman_memac_set_tx_pause_frames(struct memac_regs *regs,
281*852ba100SJustin Hibbits uint8_t priority,
282*852ba100SJustin Hibbits uint16_t pause_time,
283*852ba100SJustin Hibbits uint16_t thresh_time)
284*852ba100SJustin Hibbits {
285*852ba100SJustin Hibbits uint32_t tmp;
286*852ba100SJustin Hibbits
287*852ba100SJustin Hibbits tmp = ioread32be(®s->tx_fifo_sections);
288*852ba100SJustin Hibbits
289*852ba100SJustin Hibbits if (priority == 0xff) {
290*852ba100SJustin Hibbits GET_TX_EMPTY_DEFAULT_VALUE(tmp);
291*852ba100SJustin Hibbits iowrite32be(tmp, ®s->tx_fifo_sections);
292*852ba100SJustin Hibbits
293*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
294*852ba100SJustin Hibbits tmp &= ~CMD_CFG_PFC_MODE;
295*852ba100SJustin Hibbits priority = 0;
296*852ba100SJustin Hibbits } else {
297*852ba100SJustin Hibbits GET_TX_EMPTY_PFC_VALUE(tmp);
298*852ba100SJustin Hibbits iowrite32be(tmp, ®s->tx_fifo_sections);
299*852ba100SJustin Hibbits
300*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
301*852ba100SJustin Hibbits tmp |= CMD_CFG_PFC_MODE;
302*852ba100SJustin Hibbits }
303*852ba100SJustin Hibbits
304*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
305*852ba100SJustin Hibbits
306*852ba100SJustin Hibbits tmp = ioread32be(®s->pause_quanta[priority / 2]);
307*852ba100SJustin Hibbits if (priority % 2)
308*852ba100SJustin Hibbits tmp &= 0x0000FFFF;
309*852ba100SJustin Hibbits else
310*852ba100SJustin Hibbits tmp &= 0xFFFF0000;
311*852ba100SJustin Hibbits tmp |= ((uint32_t)pause_time << (16 * (priority % 2)));
312*852ba100SJustin Hibbits iowrite32be(tmp, ®s->pause_quanta[priority / 2]);
313*852ba100SJustin Hibbits
314*852ba100SJustin Hibbits tmp = ioread32be(®s->pause_thresh[priority / 2]);
315*852ba100SJustin Hibbits if (priority % 2)
316*852ba100SJustin Hibbits tmp &= 0x0000FFFF;
317*852ba100SJustin Hibbits else
318*852ba100SJustin Hibbits tmp &= 0xFFFF0000;
319*852ba100SJustin Hibbits tmp |= ((uint32_t)thresh_time<<(16 * (priority % 2)));
320*852ba100SJustin Hibbits iowrite32be(tmp, ®s->pause_thresh[priority / 2]);
321*852ba100SJustin Hibbits }
322*852ba100SJustin Hibbits
fman_memac_set_rx_ignore_pause_frames(struct memac_regs * regs,bool enable)323*852ba100SJustin Hibbits void fman_memac_set_rx_ignore_pause_frames(struct memac_regs *regs,bool enable)
324*852ba100SJustin Hibbits {
325*852ba100SJustin Hibbits uint32_t tmp;
326*852ba100SJustin Hibbits
327*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
328*852ba100SJustin Hibbits if (enable)
329*852ba100SJustin Hibbits tmp |= CMD_CFG_PAUSE_IGNORE;
330*852ba100SJustin Hibbits else
331*852ba100SJustin Hibbits tmp &= ~CMD_CFG_PAUSE_IGNORE;
332*852ba100SJustin Hibbits
333*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
334*852ba100SJustin Hibbits }
335*852ba100SJustin Hibbits
fman_memac_set_wol(struct memac_regs * regs,bool enable)336*852ba100SJustin Hibbits void fman_memac_set_wol(struct memac_regs *regs, bool enable)
337*852ba100SJustin Hibbits {
338*852ba100SJustin Hibbits uint32_t tmp;
339*852ba100SJustin Hibbits
340*852ba100SJustin Hibbits tmp = ioread32be(®s->command_config);
341*852ba100SJustin Hibbits
342*852ba100SJustin Hibbits if (enable)
343*852ba100SJustin Hibbits tmp |= CMD_CFG_MG;
344*852ba100SJustin Hibbits else
345*852ba100SJustin Hibbits tmp &= ~CMD_CFG_MG;
346*852ba100SJustin Hibbits
347*852ba100SJustin Hibbits iowrite32be(tmp, ®s->command_config);
348*852ba100SJustin Hibbits }
349*852ba100SJustin Hibbits
350*852ba100SJustin Hibbits #define GET_MEMAC_CNTR_64(bn) \
351*852ba100SJustin Hibbits (ioread32be(®s->bn ## _l) | \
352*852ba100SJustin Hibbits ((uint64_t)ioread32be(®s->bn ## _u) << 32))
353*852ba100SJustin Hibbits
fman_memac_get_counter(struct memac_regs * regs,enum memac_counters reg_name)354*852ba100SJustin Hibbits uint64_t fman_memac_get_counter(struct memac_regs *regs,
355*852ba100SJustin Hibbits enum memac_counters reg_name)
356*852ba100SJustin Hibbits {
357*852ba100SJustin Hibbits uint64_t ret_val;
358*852ba100SJustin Hibbits
359*852ba100SJustin Hibbits switch (reg_name) {
360*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R64:
361*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r64);
362*852ba100SJustin Hibbits break;
363*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R127:
364*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r127);
365*852ba100SJustin Hibbits break;
366*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R255:
367*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r255);
368*852ba100SJustin Hibbits break;
369*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R511:
370*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r511);
371*852ba100SJustin Hibbits break;
372*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R1023:
373*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r1023);
374*852ba100SJustin Hibbits break;
375*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R1518:
376*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r1518);
377*852ba100SJustin Hibbits break;
378*852ba100SJustin Hibbits case E_MEMAC_COUNTER_R1519X:
379*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(r1519x);
380*852ba100SJustin Hibbits break;
381*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RFRG:
382*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rfrg);
383*852ba100SJustin Hibbits break;
384*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RJBR:
385*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rjbr);
386*852ba100SJustin Hibbits break;
387*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RDRP:
388*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rdrp);
389*852ba100SJustin Hibbits break;
390*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RALN:
391*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(raln);
392*852ba100SJustin Hibbits break;
393*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TUND:
394*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(tund);
395*852ba100SJustin Hibbits break;
396*852ba100SJustin Hibbits case E_MEMAC_COUNTER_ROVR:
397*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rovr);
398*852ba100SJustin Hibbits break;
399*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RXPF:
400*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rxpf);
401*852ba100SJustin Hibbits break;
402*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TXPF:
403*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(txpf);
404*852ba100SJustin Hibbits break;
405*852ba100SJustin Hibbits case E_MEMAC_COUNTER_ROCT:
406*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(roct);
407*852ba100SJustin Hibbits break;
408*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RMCA:
409*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rmca);
410*852ba100SJustin Hibbits break;
411*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RBCA:
412*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rbca);
413*852ba100SJustin Hibbits break;
414*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RPKT:
415*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rpkt);
416*852ba100SJustin Hibbits break;
417*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RUCA:
418*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(ruca);
419*852ba100SJustin Hibbits break;
420*852ba100SJustin Hibbits case E_MEMAC_COUNTER_RERR:
421*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(rerr);
422*852ba100SJustin Hibbits break;
423*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TOCT:
424*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(toct);
425*852ba100SJustin Hibbits break;
426*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TMCA:
427*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(tmca);
428*852ba100SJustin Hibbits break;
429*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TBCA:
430*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(tbca);
431*852ba100SJustin Hibbits break;
432*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TUCA:
433*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(tuca);
434*852ba100SJustin Hibbits break;
435*852ba100SJustin Hibbits case E_MEMAC_COUNTER_TERR:
436*852ba100SJustin Hibbits ret_val = GET_MEMAC_CNTR_64(terr);
437*852ba100SJustin Hibbits break;
438*852ba100SJustin Hibbits default:
439*852ba100SJustin Hibbits ret_val = 0;
440*852ba100SJustin Hibbits }
441*852ba100SJustin Hibbits
442*852ba100SJustin Hibbits return ret_val;
443*852ba100SJustin Hibbits }
444*852ba100SJustin Hibbits
fman_memac_adjust_link(struct memac_regs * regs,enum enet_interface iface_mode,enum enet_speed speed,bool full_dx)445*852ba100SJustin Hibbits void fman_memac_adjust_link(struct memac_regs *regs,
446*852ba100SJustin Hibbits enum enet_interface iface_mode,
447*852ba100SJustin Hibbits enum enet_speed speed, bool full_dx)
448*852ba100SJustin Hibbits {
449*852ba100SJustin Hibbits uint32_t tmp;
450*852ba100SJustin Hibbits
451*852ba100SJustin Hibbits tmp = ioread32be(®s->if_mode);
452*852ba100SJustin Hibbits
453*852ba100SJustin Hibbits if (full_dx)
454*852ba100SJustin Hibbits tmp &= ~IF_MODE_HD;
455*852ba100SJustin Hibbits else
456*852ba100SJustin Hibbits tmp |= IF_MODE_HD;
457*852ba100SJustin Hibbits
458*852ba100SJustin Hibbits if (iface_mode == E_ENET_IF_RGMII) {
459*852ba100SJustin Hibbits /* Configure RGMII in manual mode */
460*852ba100SJustin Hibbits tmp &= ~IF_MODE_RGMII_AUTO;
461*852ba100SJustin Hibbits tmp &= ~IF_MODE_RGMII_SP_MASK;
462*852ba100SJustin Hibbits
463*852ba100SJustin Hibbits if (full_dx)
464*852ba100SJustin Hibbits tmp |= IF_MODE_RGMII_FD;
465*852ba100SJustin Hibbits else
466*852ba100SJustin Hibbits tmp &= ~IF_MODE_RGMII_FD;
467*852ba100SJustin Hibbits
468*852ba100SJustin Hibbits switch (speed) {
469*852ba100SJustin Hibbits case E_ENET_SPEED_1000:
470*852ba100SJustin Hibbits tmp |= IF_MODE_RGMII_1000;
471*852ba100SJustin Hibbits break;
472*852ba100SJustin Hibbits case E_ENET_SPEED_100:
473*852ba100SJustin Hibbits tmp |= IF_MODE_RGMII_100;
474*852ba100SJustin Hibbits break;
475*852ba100SJustin Hibbits case E_ENET_SPEED_10:
476*852ba100SJustin Hibbits tmp |= IF_MODE_RGMII_10;
477*852ba100SJustin Hibbits break;
478*852ba100SJustin Hibbits default:
479*852ba100SJustin Hibbits break;
480*852ba100SJustin Hibbits }
481*852ba100SJustin Hibbits }
482*852ba100SJustin Hibbits
483*852ba100SJustin Hibbits iowrite32be(tmp, ®s->if_mode);
484*852ba100SJustin Hibbits }
485*852ba100SJustin Hibbits
fman_memac_defconfig(struct memac_cfg * cfg)486*852ba100SJustin Hibbits void fman_memac_defconfig(struct memac_cfg *cfg)
487*852ba100SJustin Hibbits {
488*852ba100SJustin Hibbits cfg->reset_on_init = FALSE;
489*852ba100SJustin Hibbits cfg->wan_mode_enable = FALSE;
490*852ba100SJustin Hibbits cfg->promiscuous_mode_enable = FALSE;
491*852ba100SJustin Hibbits cfg->pause_forward_enable = FALSE;
492*852ba100SJustin Hibbits cfg->pause_ignore = FALSE;
493*852ba100SJustin Hibbits cfg->tx_addr_ins_enable = FALSE;
494*852ba100SJustin Hibbits cfg->loopback_enable = FALSE;
495*852ba100SJustin Hibbits cfg->cmd_frame_enable = FALSE;
496*852ba100SJustin Hibbits cfg->rx_error_discard = FALSE;
497*852ba100SJustin Hibbits cfg->send_idle_enable = FALSE;
498*852ba100SJustin Hibbits cfg->no_length_check_enable = TRUE;
499*852ba100SJustin Hibbits cfg->lgth_check_nostdr = FALSE;
500*852ba100SJustin Hibbits cfg->time_stamp_enable = FALSE;
501*852ba100SJustin Hibbits cfg->tx_ipg_length = DEFAULT_TX_IPG_LENGTH;
502*852ba100SJustin Hibbits cfg->max_frame_length = DEFAULT_FRAME_LENGTH;
503*852ba100SJustin Hibbits cfg->pause_quanta = DEFAULT_PAUSE_QUANTA;
504*852ba100SJustin Hibbits cfg->pad_enable = TRUE;
505*852ba100SJustin Hibbits cfg->phy_tx_ena_on = FALSE;
506*852ba100SJustin Hibbits cfg->rx_sfd_any = FALSE;
507*852ba100SJustin Hibbits cfg->rx_pbl_fwd = FALSE;
508*852ba100SJustin Hibbits cfg->tx_pbl_fwd = FALSE;
509*852ba100SJustin Hibbits cfg->debug_mode = FALSE;
510*852ba100SJustin Hibbits cfg->wake_on_lan = FALSE;
511*852ba100SJustin Hibbits }
512