2 * Copyright 2008-2012 Freescale Semiconductor Inc.
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.
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
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.
34 #include "fsl_fman_dtsec.h"
37 void fman_dtsec_stop_rx(struct dtsec_regs *regs)
39 /* Assert the graceful stop bit */
40 iowrite32be(ioread32be(®s->rctrl) | RCTRL_GRS, ®s->rctrl);
43 void fman_dtsec_stop_tx(struct dtsec_regs *regs)
45 /* Assert the graceful stop bit */
46 iowrite32be(ioread32be(®s->tctrl) | DTSEC_TCTRL_GTS, ®s->tctrl);
49 void fman_dtsec_start_tx(struct dtsec_regs *regs)
51 /* clear the graceful stop bit */
52 iowrite32be(ioread32be(®s->tctrl) & ~DTSEC_TCTRL_GTS, ®s->tctrl);
55 void fman_dtsec_start_rx(struct dtsec_regs *regs)
57 /* clear the graceful stop bit */
58 iowrite32be(ioread32be(®s->rctrl) & ~RCTRL_GRS, ®s->rctrl);
61 void fman_dtsec_defconfig(struct dtsec_cfg *cfg)
63 cfg->halfdup_on = DEFAULT_HALFDUP_ON;
64 cfg->halfdup_retransmit = DEFAULT_HALFDUP_RETRANSMIT;
65 cfg->halfdup_coll_window = DEFAULT_HALFDUP_COLL_WINDOW;
66 cfg->halfdup_excess_defer = DEFAULT_HALFDUP_EXCESS_DEFER;
67 cfg->halfdup_no_backoff = DEFAULT_HALFDUP_NO_BACKOFF;
68 cfg->halfdup_bp_no_backoff = DEFAULT_HALFDUP_BP_NO_BACKOFF;
69 cfg->halfdup_alt_backoff_val = DEFAULT_HALFDUP_ALT_BACKOFF_VAL;
70 cfg->halfdup_alt_backoff_en = DEFAULT_HALFDUP_ALT_BACKOFF_EN;
71 cfg->rx_drop_bcast = DEFAULT_RX_DROP_BCAST;
72 cfg->rx_short_frm = DEFAULT_RX_SHORT_FRM;
73 cfg->rx_len_check = DEFAULT_RX_LEN_CHECK;
74 cfg->tx_pad_crc = DEFAULT_TX_PAD_CRC;
75 cfg->tx_crc = DEFAULT_TX_CRC;
76 cfg->rx_ctrl_acc = DEFAULT_RX_CTRL_ACC;
77 cfg->tx_pause_time = DEFAULT_TX_PAUSE_TIME;
78 cfg->tbipa = DEFAULT_TBIPA; /* PHY address 0 is reserved (DPAA RM)*/
79 cfg->rx_prepend = DEFAULT_RX_PREPEND;
80 cfg->ptp_tsu_en = DEFAULT_PTP_TSU_EN;
81 cfg->ptp_exception_en = DEFAULT_PTP_EXCEPTION_EN;
82 cfg->preamble_len = DEFAULT_PREAMBLE_LEN;
83 cfg->rx_preamble = DEFAULT_RX_PREAMBLE;
84 cfg->tx_preamble = DEFAULT_TX_PREAMBLE;
85 cfg->loopback = DEFAULT_LOOPBACK;
86 cfg->rx_time_stamp_en = DEFAULT_RX_TIME_STAMP_EN;
87 cfg->tx_time_stamp_en = DEFAULT_TX_TIME_STAMP_EN;
88 cfg->rx_flow = DEFAULT_RX_FLOW;
89 cfg->tx_flow = DEFAULT_TX_FLOW;
90 cfg->rx_group_hash_exd = DEFAULT_RX_GROUP_HASH_EXD;
91 cfg->tx_pause_time_extd = DEFAULT_TX_PAUSE_TIME_EXTD;
92 cfg->rx_promisc = DEFAULT_RX_PROMISC;
93 cfg->non_back_to_back_ipg1 = DEFAULT_NON_BACK_TO_BACK_IPG1;
94 cfg->non_back_to_back_ipg2 = DEFAULT_NON_BACK_TO_BACK_IPG2;
95 cfg->min_ifg_enforcement = DEFAULT_MIN_IFG_ENFORCEMENT;
96 cfg->back_to_back_ipg = DEFAULT_BACK_TO_BACK_IPG;
97 cfg->maximum_frame = DEFAULT_MAXIMUM_FRAME;
98 cfg->tbi_phy_addr = DEFAULT_TBI_PHY_ADDR;
99 cfg->wake_on_lan = DEFAULT_WAKE_ON_LAN;
102 int fman_dtsec_init(struct dtsec_regs *regs, struct dtsec_cfg *cfg,
103 enum enet_interface iface_mode,
104 enum enet_speed iface_speed,
108 uint32_t exception_mask)
110 bool is_rgmii = FALSE;
111 bool is_sgmii = FALSE;
112 bool is_qsgmii = FALSE;
116 UNUSED(fm_rev_maj);UNUSED(fm_rev_min);
118 /* let's start with a soft reset */
119 iowrite32be(MACCFG1_SOFT_RESET, ®s->maccfg1);
120 iowrite32be(0, ®s->maccfg1);
122 /*************dtsec_id2******************/
123 tmp = ioread32be(®s->tsec_id2);
125 /* check RGMII support */
126 if (iface_mode == E_ENET_IF_RGMII ||
127 iface_mode == E_ENET_IF_RMII)
128 if (tmp & DTSEC_ID2_INT_REDUCED_OFF)
131 if (iface_mode == E_ENET_IF_SGMII ||
132 iface_mode == E_ENET_IF_MII)
133 if (tmp & DTSEC_ID2_INT_REDUCED_OFF)
136 /***************ECNTRL************************/
138 is_rgmii = (bool)((iface_mode == E_ENET_IF_RGMII) ? TRUE : FALSE);
139 is_sgmii = (bool)((iface_mode == E_ENET_IF_SGMII) ? TRUE : FALSE);
140 is_qsgmii = (bool)((iface_mode == E_ENET_IF_QSGMII) ? TRUE : FALSE);
143 if (is_rgmii || iface_mode == E_ENET_IF_GMII)
144 tmp |= DTSEC_ECNTRL_GMIIM;
146 tmp |= (DTSEC_ECNTRL_SGMIIM | DTSEC_ECNTRL_TBIM);
148 tmp |= (DTSEC_ECNTRL_SGMIIM | DTSEC_ECNTRL_TBIM |
149 DTSEC_ECNTRL_QSGMIIM);
151 tmp |= DTSEC_ECNTRL_RPM;
152 if (iface_speed == E_ENET_SPEED_100)
153 tmp |= DTSEC_ECNTRL_R100M;
155 iowrite32be(tmp, ®s->ecntrl);
156 /***************ECNTRL************************/
158 /***************TCTRL************************/
161 tmp |= DTSEC_TCTRL_THDF;
162 if (cfg->tx_time_stamp_en)
163 tmp |= DTSEC_TCTRL_TTSE;
165 iowrite32be(tmp, ®s->tctrl);
167 /***************TCTRL************************/
169 /***************PTV************************/
172 #ifdef FM_SHORT_PAUSE_TIME_ERRATA_DTSEC1
173 if ((fm_rev_maj == 1) && (fm_rev_min == 0))
174 cfg->tx_pause_time += 2;
175 #endif /* FM_SHORT_PAUSE_TIME_ERRATA_DTSEC1 */
177 if (cfg->tx_pause_time)
178 tmp |= cfg->tx_pause_time;
179 if (cfg->tx_pause_time_extd)
180 tmp |= cfg->tx_pause_time_extd << PTV_PTE_OFST;
181 iowrite32be(tmp, ®s->ptv);
183 /***************RCTRL************************/
185 tmp |= ((uint32_t)(cfg->rx_prepend & 0x0000001f)) << 16;
186 if (cfg->rx_ctrl_acc)
188 if (cfg->rx_group_hash_exd)
190 if (cfg->rx_time_stamp_en)
192 if (cfg->rx_drop_bcast)
194 if (cfg->rx_short_frm)
199 iowrite32be(tmp, ®s->rctrl);
200 /***************RCTRL************************/
203 * Assign a Phy Address to the TBI (TBIPA).
204 * Done also in cases where TBI is not selected to avoid conflict with
205 * the external PHY's Physical address
207 iowrite32be(cfg->tbipa, ®s->tbipa);
209 /***************TMR_CTL************************/
210 iowrite32be(0, ®s->tmr_ctrl);
212 if (cfg->ptp_tsu_en) {
214 tmp |= TMR_PEVENT_TSRE;
215 iowrite32be(tmp, ®s->tmr_pevent);
217 if (cfg->ptp_exception_en) {
219 tmp |= TMR_PEMASK_TSREEN;
220 iowrite32be(tmp, ®s->tmr_pemask);
224 /***************MACCFG1***********************/
227 tmp |= MACCFG1_LOOPBACK;
229 tmp |= MACCFG1_RX_FLOW;
231 tmp |= MACCFG1_TX_FLOW;
232 iowrite32be(tmp, ®s->maccfg1);
234 /***************MACCFG1***********************/
236 /***************MACCFG2***********************/
239 if (iface_speed < E_ENET_SPEED_1000)
240 tmp |= MACCFG2_NIBBLE_MODE;
241 else if (iface_speed == E_ENET_SPEED_1000)
242 tmp |= MACCFG2_BYTE_MODE;
244 tmp |= ((uint32_t) cfg->preamble_len & 0x0000000f)
245 << PREAMBLE_LENGTH_SHIFT;
247 if (cfg->rx_preamble)
248 tmp |= MACCFG2_PRE_AM_Rx_EN;
249 if (cfg->tx_preamble)
250 tmp |= MACCFG2_PRE_AM_Tx_EN;
251 if (cfg->rx_len_check)
252 tmp |= MACCFG2_LENGTH_CHECK;
254 tmp |= MACCFG2_PAD_CRC_EN;
256 tmp |= MACCFG2_CRC_EN;
257 if (!cfg->halfdup_on)
258 tmp |= MACCFG2_FULL_DUPLEX;
259 iowrite32be(tmp, ®s->maccfg2);
261 /***************MACCFG2***********************/
263 /***************IPGIFG************************/
264 tmp = (((cfg->non_back_to_back_ipg1 <<
265 IPGIFG_NON_BACK_TO_BACK_IPG_1_SHIFT)
266 & IPGIFG_NON_BACK_TO_BACK_IPG_1)
267 | ((cfg->non_back_to_back_ipg2 <<
268 IPGIFG_NON_BACK_TO_BACK_IPG_2_SHIFT)
269 & IPGIFG_NON_BACK_TO_BACK_IPG_2)
270 | ((cfg->min_ifg_enforcement <<
271 IPGIFG_MIN_IFG_ENFORCEMENT_SHIFT)
272 & IPGIFG_MIN_IFG_ENFORCEMENT)
273 | (cfg->back_to_back_ipg & IPGIFG_BACK_TO_BACK_IPG));
274 iowrite32be(tmp, ®s->ipgifg);
276 /***************IPGIFG************************/
278 /***************HAFDUP************************/
281 if (cfg->halfdup_alt_backoff_en)
282 tmp = (uint32_t)(HAFDUP_ALT_BEB |
283 ((cfg->halfdup_alt_backoff_val & 0x0000000f)
284 << HAFDUP_ALTERNATE_BEB_TRUNCATION_SHIFT));
285 if (cfg->halfdup_bp_no_backoff)
286 tmp |= HAFDUP_BP_NO_BACKOFF;
287 if (cfg->halfdup_no_backoff)
288 tmp |= HAFDUP_NO_BACKOFF;
289 if (cfg->halfdup_excess_defer)
290 tmp |= HAFDUP_EXCESS_DEFER;
291 tmp |= ((cfg->halfdup_retransmit << HAFDUP_RETRANSMISSION_MAX_SHIFT)
292 & HAFDUP_RETRANSMISSION_MAX);
293 tmp |= (cfg->halfdup_coll_window & HAFDUP_COLLISION_WINDOW);
295 iowrite32be(tmp, ®s->hafdup);
296 /***************HAFDUP************************/
298 /***************MAXFRM************************/
299 /* Initialize MAXFRM */
300 iowrite32be(cfg->maximum_frame, ®s->maxfrm);
302 /***************MAXFRM************************/
304 /***************CAM1************************/
305 iowrite32be(0xffffffff, ®s->cam1);
306 iowrite32be(0xffffffff, ®s->cam2);
308 /***************IMASK************************/
309 iowrite32be(exception_mask, ®s->imask);
310 /***************IMASK************************/
312 /***************IEVENT************************/
313 iowrite32be(0xffffffff, ®s->ievent);
315 /***************MACSTNADDR1/2*****************/
317 tmp = (uint32_t)((macaddr[5] << 24) |
321 iowrite32be(tmp, ®s->macstnaddr1);
323 tmp = (uint32_t)((macaddr[1] << 24) |
325 iowrite32be(tmp, ®s->macstnaddr2);
327 /***************MACSTNADDR1/2*****************/
329 /*****************HASH************************/
330 for (i = 0; i < NUM_OF_HASH_REGS ; i++) {
331 /* Initialize IADDRx */
332 iowrite32be(0, ®s->igaddr[i]);
333 /* Initialize GADDRx */
334 iowrite32be(0, ®s->gaddr[i]);
337 fman_dtsec_reset_stat(regs);
342 uint16_t fman_dtsec_get_max_frame_len(struct dtsec_regs *regs)
344 return (uint16_t)ioread32be(®s->maxfrm);
347 void fman_dtsec_set_max_frame_len(struct dtsec_regs *regs, uint16_t length)
349 iowrite32be(length, ®s->maxfrm);
352 void fman_dtsec_set_mac_address(struct dtsec_regs *regs, uint8_t *adr)
356 tmp = (uint32_t)((adr[5] << 24) |
360 iowrite32be(tmp, ®s->macstnaddr1);
362 tmp = (uint32_t)((adr[1] << 24) |
364 iowrite32be(tmp, ®s->macstnaddr2);
367 void fman_dtsec_get_mac_address(struct dtsec_regs *regs, uint8_t *macaddr)
371 tmp1 = ioread32be(®s->macstnaddr1);
372 tmp2 = ioread32be(®s->macstnaddr2);
374 macaddr[0] = (uint8_t)((tmp2 & 0x00ff0000) >> 16);
375 macaddr[1] = (uint8_t)((tmp2 & 0xff000000) >> 24);
376 macaddr[2] = (uint8_t)(tmp1 & 0x000000ff);
377 macaddr[3] = (uint8_t)((tmp1 & 0x0000ff00) >> 8);
378 macaddr[4] = (uint8_t)((tmp1 & 0x00ff0000) >> 16);
379 macaddr[5] = (uint8_t)((tmp1 & 0xff000000) >> 24);
382 void fman_dtsec_set_hash_table(struct dtsec_regs *regs, uint32_t crc, bool mcast, bool ghtx)
386 bucket = (int32_t)((crc >> 23) & 0x1ff);
388 bucket = (int32_t)((crc >> 24) & 0xff);
389 /* if !ghtx and mcast the bit must be set in gaddr instead of igaddr. */
393 fman_dtsec_set_bucket(regs, bucket, TRUE);
396 void fman_dtsec_set_bucket(struct dtsec_regs *regs, int bucket, bool enable)
398 int reg_idx = (bucket >> 5) & 0xf;
399 int bit_idx = bucket & 0x1f;
400 uint32_t bit_mask = 0x80000000 >> bit_idx;
404 reg = ®s->gaddr[reg_idx-8];
406 reg = ®s->igaddr[reg_idx];
409 iowrite32be(ioread32be(reg) | bit_mask, reg);
411 iowrite32be(ioread32be(reg) & (~bit_mask), reg);
414 void fman_dtsec_reset_filter_table(struct dtsec_regs *regs, bool mcast, bool ucast)
419 ghtx = (bool)((ioread32be(®s->rctrl) & RCTRL_GHTX) ? TRUE : FALSE);
421 if (ucast || (ghtx && mcast)) {
422 for (i = 0; i < NUM_OF_HASH_REGS; i++)
423 iowrite32be(0, ®s->igaddr[i]);
426 for (i = 0; i < NUM_OF_HASH_REGS; i++)
427 iowrite32be(0, ®s->gaddr[i]);
431 int fman_dtsec_set_tbi_phy_addr(struct dtsec_regs *regs,
434 if (addr > 0 && addr < 32)
435 iowrite32be(addr, ®s->tbipa);
442 void fman_dtsec_set_wol(struct dtsec_regs *regs, bool en)
446 tmp = ioread32be(®s->maccfg2);
448 tmp |= MACCFG2_MAGIC_PACKET_EN;
450 tmp &= ~MACCFG2_MAGIC_PACKET_EN;
451 iowrite32be(tmp, ®s->maccfg2);
454 int fman_dtsec_adjust_link(struct dtsec_regs *regs,
455 enum enet_interface iface_mode,
456 enum enet_speed speed, bool full_dx)
462 if ((speed == E_ENET_SPEED_1000) && !full_dx)
465 tmp = ioread32be(®s->maccfg2);
467 tmp &= ~MACCFG2_FULL_DUPLEX;
469 tmp |= MACCFG2_FULL_DUPLEX;
471 tmp &= ~(MACCFG2_NIBBLE_MODE | MACCFG2_BYTE_MODE);
472 if (speed < E_ENET_SPEED_1000)
473 tmp |= MACCFG2_NIBBLE_MODE;
474 else if (speed == E_ENET_SPEED_1000)
475 tmp |= MACCFG2_BYTE_MODE;
476 iowrite32be(tmp, ®s->maccfg2);
478 tmp = ioread32be(®s->ecntrl);
479 if (speed == E_ENET_SPEED_100)
480 tmp |= DTSEC_ECNTRL_R100M;
482 tmp &= ~DTSEC_ECNTRL_R100M;
483 iowrite32be(tmp, ®s->ecntrl);
488 void fman_dtsec_set_uc_promisc(struct dtsec_regs *regs, bool enable)
492 tmp = ioread32be(®s->rctrl);
499 iowrite32be(tmp, ®s->rctrl);
502 void fman_dtsec_set_mc_promisc(struct dtsec_regs *regs, bool enable)
506 tmp = ioread32be(®s->rctrl);
513 iowrite32be(tmp, ®s->rctrl);
516 bool fman_dtsec_get_clear_carry_regs(struct dtsec_regs *regs,
517 uint32_t *car1, uint32_t *car2)
519 /* read carry registers */
520 *car1 = ioread32be(®s->car1);
521 *car2 = ioread32be(®s->car2);
522 /* clear carry registers */
524 iowrite32be(*car1, ®s->car1);
526 iowrite32be(*car2, ®s->car2);
528 return (bool)((*car1 | *car2) ? TRUE : FALSE);
531 void fman_dtsec_reset_stat(struct dtsec_regs *regs)
533 /* clear HW counters */
534 iowrite32be(ioread32be(®s->ecntrl) |
535 DTSEC_ECNTRL_CLRCNT, ®s->ecntrl);
538 int fman_dtsec_set_stat_level(struct dtsec_regs *regs, enum dtsec_stat_level level)
541 case E_MAC_STAT_NONE:
542 iowrite32be(0xffffffff, ®s->cam1);
543 iowrite32be(0xffffffff, ®s->cam2);
544 iowrite32be(ioread32be(®s->ecntrl) & ~DTSEC_ECNTRL_STEN,
546 iowrite32be(ioread32be(®s->imask) & ~DTSEC_IMASK_MSROEN,
549 case E_MAC_STAT_PARTIAL:
550 iowrite32be(CAM1_ERRORS_ONLY, ®s->cam1);
551 iowrite32be(CAM2_ERRORS_ONLY, ®s->cam2);
552 iowrite32be(ioread32be(®s->ecntrl) | DTSEC_ECNTRL_STEN,
554 iowrite32be(ioread32be(®s->imask) | DTSEC_IMASK_MSROEN,
557 case E_MAC_STAT_MIB_GRP1:
558 iowrite32be((uint32_t)~CAM1_MIB_GRP_1, ®s->cam1);
559 iowrite32be((uint32_t)~CAM2_MIB_GRP_1, ®s->cam2);
560 iowrite32be(ioread32be(®s->ecntrl) | DTSEC_ECNTRL_STEN,
562 iowrite32be(ioread32be(®s->imask) | DTSEC_IMASK_MSROEN,
565 case E_MAC_STAT_FULL:
566 iowrite32be(0, ®s->cam1);
567 iowrite32be(0, ®s->cam2);
568 iowrite32be(ioread32be(®s->ecntrl) | DTSEC_ECNTRL_STEN,
570 iowrite32be(ioread32be(®s->imask) | DTSEC_IMASK_MSROEN,
580 void fman_dtsec_set_ts(struct dtsec_regs *regs, bool en)
583 iowrite32be(ioread32be(®s->rctrl) | RCTRL_RTSE,
585 iowrite32be(ioread32be(®s->tctrl) | DTSEC_TCTRL_TTSE,
588 iowrite32be(ioread32be(®s->rctrl) & ~RCTRL_RTSE,
590 iowrite32be(ioread32be(®s->tctrl) & ~DTSEC_TCTRL_TTSE,
595 void fman_dtsec_enable(struct dtsec_regs *regs, bool apply_rx, bool apply_tx)
599 tmp = ioread32be(®s->maccfg1);
602 tmp |= MACCFG1_RX_EN ;
605 tmp |= MACCFG1_TX_EN ;
607 iowrite32be(tmp, ®s->maccfg1);
610 void fman_dtsec_clear_addr_in_paddr(struct dtsec_regs *regs, uint8_t paddr_num)
612 iowrite32be(0, ®s->macaddr[paddr_num].exact_match1);
613 iowrite32be(0, ®s->macaddr[paddr_num].exact_match2);
616 void fman_dtsec_add_addr_in_paddr(struct dtsec_regs *regs,
622 tmp = (uint32_t)(addr);
624 tmp = (((tmp & 0x000000FF) << 24) |
625 ((tmp & 0x0000FF00) << 8) |
626 ((tmp & 0x00FF0000) >> 8) |
627 ((tmp & 0xFF000000) >> 24));
628 iowrite32be(tmp, ®s->macaddr[paddr_num].exact_match1);
630 tmp = (uint32_t)(addr>>32);
632 tmp = (((tmp & 0x000000FF) << 24) |
633 ((tmp & 0x0000FF00) << 8) |
634 ((tmp & 0x00FF0000) >> 8) |
635 ((tmp & 0xFF000000) >> 24));
636 iowrite32be(tmp, ®s->macaddr[paddr_num].exact_match2);
639 void fman_dtsec_disable(struct dtsec_regs *regs, bool apply_rx, bool apply_tx)
643 tmp = ioread32be(®s->maccfg1);
646 tmp &= ~MACCFG1_RX_EN;
649 tmp &= ~MACCFG1_TX_EN;
651 iowrite32be(tmp, ®s->maccfg1);
654 void fman_dtsec_set_tx_pause_frames(struct dtsec_regs *regs, uint16_t time)
658 /* fixme: don't enable tx pause for half-duplex */
661 ptv = ioread32be(®s->ptv);
663 ptv |= time & 0x0000ffff;
664 iowrite32be(ptv, ®s->ptv);
666 /* trigger the transmission of a flow-control pause frame */
667 iowrite32be(ioread32be(®s->maccfg1) | MACCFG1_TX_FLOW,
670 iowrite32be(ioread32be(®s->maccfg1) & ~MACCFG1_TX_FLOW,
674 void fman_dtsec_handle_rx_pause(struct dtsec_regs *regs, bool en)
678 /* todo: check if mac is set to full-duplex */
680 tmp = ioread32be(®s->maccfg1);
682 tmp |= MACCFG1_RX_FLOW;
684 tmp &= ~MACCFG1_RX_FLOW;
685 iowrite32be(tmp, ®s->maccfg1);
688 uint32_t fman_dtsec_get_rctrl(struct dtsec_regs *regs)
690 return ioread32be(®s->rctrl);
693 uint32_t fman_dtsec_get_revision(struct dtsec_regs *regs)
695 return ioread32be(®s->tsec_id);
698 uint32_t fman_dtsec_get_event(struct dtsec_regs *regs, uint32_t ev_mask)
700 return ioread32be(®s->ievent) & ev_mask;
703 void fman_dtsec_ack_event(struct dtsec_regs *regs, uint32_t ev_mask)
705 iowrite32be(ev_mask, ®s->ievent);
708 uint32_t fman_dtsec_get_interrupt_mask(struct dtsec_regs *regs)
710 return ioread32be(®s->imask);
713 uint32_t fman_dtsec_check_and_clear_tmr_event(struct dtsec_regs *regs)
717 event = ioread32be(®s->tmr_pevent);
718 event &= ioread32be(®s->tmr_pemask);
721 iowrite32be(event, ®s->tmr_pevent);
725 void fman_dtsec_enable_tmr_interrupt(struct dtsec_regs *regs)
727 iowrite32be(ioread32be(®s->tmr_pemask) | TMR_PEMASK_TSREEN,
731 void fman_dtsec_disable_tmr_interrupt(struct dtsec_regs *regs)
733 iowrite32be(ioread32be(®s->tmr_pemask) & ~TMR_PEMASK_TSREEN,
737 void fman_dtsec_enable_interrupt(struct dtsec_regs *regs, uint32_t ev_mask)
739 iowrite32be(ioread32be(®s->imask) | ev_mask, ®s->imask);
742 void fman_dtsec_disable_interrupt(struct dtsec_regs *regs, uint32_t ev_mask)
744 iowrite32be(ioread32be(®s->imask) & ~ev_mask, ®s->imask);
747 uint32_t fman_dtsec_get_stat_counter(struct dtsec_regs *regs,
748 enum dtsec_stat_counters reg_name)
753 case E_DTSEC_STAT_TR64:
754 ret_val = ioread32be(®s->tr64);
756 case E_DTSEC_STAT_TR127:
757 ret_val = ioread32be(®s->tr127);
759 case E_DTSEC_STAT_TR255:
760 ret_val = ioread32be(®s->tr255);
762 case E_DTSEC_STAT_TR511:
763 ret_val = ioread32be(®s->tr511);
765 case E_DTSEC_STAT_TR1K:
766 ret_val = ioread32be(®s->tr1k);
768 case E_DTSEC_STAT_TRMAX:
769 ret_val = ioread32be(®s->trmax);
771 case E_DTSEC_STAT_TRMGV:
772 ret_val = ioread32be(®s->trmgv);
774 case E_DTSEC_STAT_RBYT:
775 ret_val = ioread32be(®s->rbyt);
777 case E_DTSEC_STAT_RPKT:
778 ret_val = ioread32be(®s->rpkt);
780 case E_DTSEC_STAT_RMCA:
781 ret_val = ioread32be(®s->rmca);
783 case E_DTSEC_STAT_RBCA:
784 ret_val = ioread32be(®s->rbca);
786 case E_DTSEC_STAT_RXPF:
787 ret_val = ioread32be(®s->rxpf);
789 case E_DTSEC_STAT_RALN:
790 ret_val = ioread32be(®s->raln);
792 case E_DTSEC_STAT_RFLR:
793 ret_val = ioread32be(®s->rflr);
795 case E_DTSEC_STAT_RCDE:
796 ret_val = ioread32be(®s->rcde);
798 case E_DTSEC_STAT_RCSE:
799 ret_val = ioread32be(®s->rcse);
801 case E_DTSEC_STAT_RUND:
802 ret_val = ioread32be(®s->rund);
804 case E_DTSEC_STAT_ROVR:
805 ret_val = ioread32be(®s->rovr);
807 case E_DTSEC_STAT_RFRG:
808 ret_val = ioread32be(®s->rfrg);
810 case E_DTSEC_STAT_RJBR:
811 ret_val = ioread32be(®s->rjbr);
813 case E_DTSEC_STAT_RDRP:
814 ret_val = ioread32be(®s->rdrp);
816 case E_DTSEC_STAT_TFCS:
817 ret_val = ioread32be(®s->tfcs);
819 case E_DTSEC_STAT_TBYT:
820 ret_val = ioread32be(®s->tbyt);
822 case E_DTSEC_STAT_TPKT:
823 ret_val = ioread32be(®s->tpkt);
825 case E_DTSEC_STAT_TMCA:
826 ret_val = ioread32be(®s->tmca);
828 case E_DTSEC_STAT_TBCA:
829 ret_val = ioread32be(®s->tbca);
831 case E_DTSEC_STAT_TXPF:
832 ret_val = ioread32be(®s->txpf);
834 case E_DTSEC_STAT_TNCL:
835 ret_val = ioread32be(®s->tncl);
837 case E_DTSEC_STAT_TDRP:
838 ret_val = ioread32be(®s->tdrp);