1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell CN10K RPM driver
4 * Copyright (C) 2020 Marvell.
9 #include "lmac_common.h"
11 static struct mac_ops rpm_mac_ops = {
15 .int_register = RPMX_CMRX_SW_INT,
16 .int_set_reg = RPMX_CMRX_SW_INT_ENA_W1S,
18 .int_ena_bit = BIT_ULL(0),
19 .lmac_fwi = RPM_LMAC_FWI,
20 .non_contiguous_serdes_lane = true,
23 .dmac_filter_count = 32,
24 .get_nr_lmacs = rpm_get_nr_lmacs,
25 .get_lmac_type = rpm_get_lmac_type,
26 .lmac_fifo_len = rpm_get_lmac_fifo_len,
27 .mac_lmac_intl_lbk = rpm_lmac_internal_loopback,
28 .mac_get_rx_stats = rpm_get_rx_stats,
29 .mac_get_tx_stats = rpm_get_tx_stats,
30 .get_fec_stats = rpm_get_fec_stats,
31 .mac_enadis_rx_pause_fwding = rpm_lmac_enadis_rx_pause_fwding,
32 .mac_get_pause_frm_status = rpm_lmac_get_pause_frm_status,
33 .mac_enadis_pause_frm = rpm_lmac_enadis_pause_frm,
34 .mac_pause_frm_config = rpm_lmac_pause_frm_config,
35 .mac_enadis_ptp_config = rpm_lmac_ptp_config,
36 .mac_rx_tx_enable = rpm_lmac_rx_tx_enable,
37 .mac_tx_enable = rpm_lmac_tx_enable,
38 .pfc_config = rpm_lmac_pfc_config,
39 .mac_get_pfc_frm_cfg = rpm_lmac_get_pfc_frm_cfg,
40 .mac_reset = rpm_lmac_reset,
43 static struct mac_ops rpm2_mac_ops = {
45 .csr_offset = RPM2_CSR_OFFSET,
47 .int_register = RPM2_CMRX_SW_INT,
48 .int_set_reg = RPM2_CMRX_SW_INT_ENA_W1S,
50 .int_ena_bit = BIT_ULL(0),
51 .lmac_fwi = RPM2_LMAC_FWI,
52 .non_contiguous_serdes_lane = true,
55 .dmac_filter_count = 64,
56 .get_nr_lmacs = rpm2_get_nr_lmacs,
57 .get_lmac_type = rpm_get_lmac_type,
58 .lmac_fifo_len = rpm2_get_lmac_fifo_len,
59 .mac_lmac_intl_lbk = rpm_lmac_internal_loopback,
60 .mac_get_rx_stats = rpm_get_rx_stats,
61 .mac_get_tx_stats = rpm_get_tx_stats,
62 .get_fec_stats = rpm_get_fec_stats,
63 .mac_enadis_rx_pause_fwding = rpm_lmac_enadis_rx_pause_fwding,
64 .mac_get_pause_frm_status = rpm_lmac_get_pause_frm_status,
65 .mac_enadis_pause_frm = rpm_lmac_enadis_pause_frm,
66 .mac_pause_frm_config = rpm_lmac_pause_frm_config,
67 .mac_enadis_ptp_config = rpm_lmac_ptp_config,
68 .mac_rx_tx_enable = rpm_lmac_rx_tx_enable,
69 .mac_tx_enable = rpm_lmac_tx_enable,
70 .pfc_config = rpm_lmac_pfc_config,
71 .mac_get_pfc_frm_cfg = rpm_lmac_get_pfc_frm_cfg,
72 .mac_reset = rpm_lmac_reset,
75 bool is_dev_rpm2(void *rpmd)
79 return (rpm->pdev->device == PCI_DEVID_CN10KB_RPM);
82 struct mac_ops *rpm_get_mac_ops(rpm_t *rpm)
90 static void rpm_write(rpm_t *rpm, u64 lmac, u64 offset, u64 val)
92 cgx_write(rpm, lmac, offset, val);
95 static u64 rpm_read(rpm_t *rpm, u64 lmac, u64 offset)
97 return cgx_read(rpm, lmac, offset);
100 /* Read HW major version to determine RPM
103 static bool is_mac_rpmusx(void *rpmd)
107 return rpm_read(rpm, 0, RPMX_CONST1) & 0x700ULL;
110 int rpm_get_nr_lmacs(void *rpmd)
114 return hweight8(rpm_read(rpm, 0, CGXX_CMRX_RX_LMACS) & 0xFULL);
117 int rpm2_get_nr_lmacs(void *rpmd)
121 return hweight8(rpm_read(rpm, 0, RPM2_CMRX_RX_LMACS) & 0xFFULL);
124 int rpm_lmac_tx_enable(void *rpmd, int lmac_id, bool enable)
129 if (!is_lmac_valid(rpm, lmac_id))
132 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
140 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
141 return !!(last & RPM_TX_EN);
144 int rpm_lmac_rx_tx_enable(void *rpmd, int lmac_id, bool enable)
149 if (!is_lmac_valid(rpm, lmac_id))
152 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
154 cfg |= RPM_RX_EN | RPM_TX_EN;
156 cfg &= ~(RPM_RX_EN | RPM_TX_EN);
157 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
161 void rpm_lmac_enadis_rx_pause_fwding(void *rpmd, int lmac_id, bool enable)
170 lmac = lmac_pdata(lmac_id, rpm);
174 /* Pause frames are not enabled just return */
175 if (!bitmap_weight(lmac->rx_fc_pfvf_bmap.bmap, lmac->rx_fc_pfvf_bmap.max))
179 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
180 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE;
181 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
183 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
184 cfg |= RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE;
185 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
189 int rpm_lmac_get_pause_frm_status(void *rpmd, int lmac_id,
190 u8 *tx_pause, u8 *rx_pause)
195 if (!is_lmac_valid(rpm, lmac_id))
198 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
199 if (!(cfg & RPMX_MTI_MAC100X_COMMAND_CONFIG_PFC_MODE)) {
200 *rx_pause = !(cfg & RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE);
201 *tx_pause = !(cfg & RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE);
207 static void rpm_cfg_pfc_quanta_thresh(rpm_t *rpm, int lmac_id,
208 unsigned long pfc_en,
211 u64 quanta_offset = 0, quanta_thresh = 0, cfg;
214 /* Set pause time and interval */
215 for_each_set_bit(i, &pfc_en, 16) {
219 quanta_offset = RPMX_MTI_MAC100X_CL01_PAUSE_QUANTA;
220 quanta_thresh = RPMX_MTI_MAC100X_CL01_QUANTA_THRESH;
224 quanta_offset = RPMX_MTI_MAC100X_CL23_PAUSE_QUANTA;
225 quanta_thresh = RPMX_MTI_MAC100X_CL23_QUANTA_THRESH;
229 quanta_offset = RPMX_MTI_MAC100X_CL45_PAUSE_QUANTA;
230 quanta_thresh = RPMX_MTI_MAC100X_CL45_QUANTA_THRESH;
234 quanta_offset = RPMX_MTI_MAC100X_CL67_PAUSE_QUANTA;
235 quanta_thresh = RPMX_MTI_MAC100X_CL67_QUANTA_THRESH;
239 quanta_offset = RPMX_MTI_MAC100X_CL89_PAUSE_QUANTA;
240 quanta_thresh = RPMX_MTI_MAC100X_CL89_QUANTA_THRESH;
244 quanta_offset = RPMX_MTI_MAC100X_CL1011_PAUSE_QUANTA;
245 quanta_thresh = RPMX_MTI_MAC100X_CL1011_QUANTA_THRESH;
249 quanta_offset = RPMX_MTI_MAC100X_CL1213_PAUSE_QUANTA;
250 quanta_thresh = RPMX_MTI_MAC100X_CL1213_QUANTA_THRESH;
254 quanta_offset = RPMX_MTI_MAC100X_CL1415_PAUSE_QUANTA;
255 quanta_thresh = RPMX_MTI_MAC100X_CL1415_QUANTA_THRESH;
259 if (!quanta_offset || !quanta_thresh)
262 shift = (i % 2) ? 1 : 0;
263 cfg = rpm_read(rpm, lmac_id, quanta_offset);
265 cfg |= ((u64)RPM_DEFAULT_PAUSE_TIME << shift * 16);
268 cfg &= ~GENMASK_ULL(15, 0);
270 cfg &= ~GENMASK_ULL(31, 16);
272 rpm_write(rpm, lmac_id, quanta_offset, cfg);
274 cfg = rpm_read(rpm, lmac_id, quanta_thresh);
276 cfg |= ((u64)(RPM_DEFAULT_PAUSE_TIME / 2) << shift * 16);
279 cfg &= ~GENMASK_ULL(15, 0);
281 cfg &= ~GENMASK_ULL(31, 16);
283 rpm_write(rpm, lmac_id, quanta_thresh, cfg);
287 static void rpm2_lmac_cfg_bp(rpm_t *rpm, int lmac_id, u8 tx_pause, u8 rx_pause)
291 cfg = rpm_read(rpm, lmac_id, RPM2_CMR_RX_OVR_BP);
293 /* Configure CL0 Pause Quanta & threshold
296 rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 1, true);
297 cfg &= ~RPM2_CMR_RX_OVR_BP_EN;
299 /* Disable all Pause Quanta & threshold values */
300 rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 0xffff, false);
301 cfg |= RPM2_CMR_RX_OVR_BP_EN;
302 cfg &= ~RPM2_CMR_RX_OVR_BP_BP;
304 rpm_write(rpm, lmac_id, RPM2_CMR_RX_OVR_BP, cfg);
307 static void rpm_lmac_cfg_bp(rpm_t *rpm, int lmac_id, u8 tx_pause, u8 rx_pause)
311 cfg = rpm_read(rpm, 0, RPMX_CMR_RX_OVR_BP);
313 /* Configure CL0 Pause Quanta & threshold for
316 rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 1, true);
317 cfg &= ~RPMX_CMR_RX_OVR_BP_EN(lmac_id);
319 /* Disable all Pause Quanta & threshold values */
320 rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 0xffff, false);
321 cfg |= RPMX_CMR_RX_OVR_BP_EN(lmac_id);
322 cfg &= ~RPMX_CMR_RX_OVR_BP_BP(lmac_id);
324 rpm_write(rpm, 0, RPMX_CMR_RX_OVR_BP, cfg);
327 int rpm_lmac_enadis_pause_frm(void *rpmd, int lmac_id, u8 tx_pause,
333 if (!is_lmac_valid(rpm, lmac_id))
336 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
337 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE;
338 cfg |= rx_pause ? 0x0 : RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE;
339 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE;
340 cfg |= rx_pause ? 0x0 : RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE;
341 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
343 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
344 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE;
345 cfg |= tx_pause ? 0x0 : RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE;
346 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
348 if (is_dev_rpm2(rpm))
349 rpm2_lmac_cfg_bp(rpm, lmac_id, tx_pause, rx_pause);
351 rpm_lmac_cfg_bp(rpm, lmac_id, tx_pause, rx_pause);
356 void rpm_lmac_pause_frm_config(void *rpmd, int lmac_id, bool enable)
358 u64 cfg, pfc_class_mask_cfg;
361 /* ALL pause frames received are completely ignored */
362 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
363 cfg |= RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE;
364 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
366 /* Disable forward pause to TX block */
367 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
368 cfg |= RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE;
369 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
371 /* Disable pause frames transmission */
372 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
373 cfg |= RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE;
374 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
376 /* Disable forward pause to driver */
377 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
378 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_FWD;
379 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
381 /* Enable channel mask for all LMACS */
382 if (is_dev_rpm2(rpm))
383 rpm_write(rpm, lmac_id, RPM2_CMR_CHAN_MSK_OR, 0xffff);
385 rpm_write(rpm, 0, RPMX_CMR_CHAN_MSK_OR, ~0ULL);
387 /* Disable all PFC classes */
388 pfc_class_mask_cfg = is_dev_rpm2(rpm) ? RPM2_CMRX_PRT_CBFC_CTL :
389 RPMX_CMRX_PRT_CBFC_CTL;
390 cfg = rpm_read(rpm, lmac_id, pfc_class_mask_cfg);
391 cfg = FIELD_SET(RPM_PFC_CLASS_MASK, 0, cfg);
392 rpm_write(rpm, lmac_id, pfc_class_mask_cfg, cfg);
395 int rpm_get_rx_stats(void *rpmd, int lmac_id, int idx, u64 *rx_stat)
400 if (!is_lmac_valid(rpm, lmac_id))
403 mutex_lock(&rpm->lock);
405 /* Update idx to point per lmac Rx statistics page */
406 idx += lmac_id * rpm->mac_ops->rx_stats_cnt;
408 /* Read lower 32 bits of counter */
409 val_lo = rpm_read(rpm, 0, RPMX_MTI_STAT_RX_STAT_PAGES_COUNTERX +
412 /* upon read of lower 32 bits, higher 32 bits are written
413 * to RPMX_MTI_STAT_DATA_HI_CDC
415 val_hi = rpm_read(rpm, 0, RPMX_MTI_STAT_DATA_HI_CDC);
417 *rx_stat = (val_hi << 32 | val_lo);
419 mutex_unlock(&rpm->lock);
423 int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, u64 *tx_stat)
428 if (!is_lmac_valid(rpm, lmac_id))
431 mutex_lock(&rpm->lock);
433 /* Update idx to point per lmac Tx statistics page */
434 idx += lmac_id * rpm->mac_ops->tx_stats_cnt;
436 val_lo = rpm_read(rpm, 0, RPMX_MTI_STAT_TX_STAT_PAGES_COUNTERX +
438 val_hi = rpm_read(rpm, 0, RPMX_MTI_STAT_DATA_HI_CDC);
440 *tx_stat = (val_hi << 32 | val_lo);
442 mutex_unlock(&rpm->lock);
446 u8 rpm_get_lmac_type(void *rpmd, int lmac_id)
452 req = FIELD_SET(CMDREG_ID, CGX_CMD_GET_LINK_STS, req);
453 err = cgx_fwi_cmd_generic(req, &resp, rpm, 0);
455 return FIELD_GET(RESP_LINKSTAT_LMAC_TYPE, resp);
459 u32 rpm_get_lmac_fifo_len(void *rpmd, int lmac_id)
466 fifo_len = rpm->mac_ops->fifo_len;
467 num_lmacs = rpm->mac_ops->get_nr_lmacs(rpm);
475 /* LMAC marked as hi_perf gets half of the FIFO and rest 1/4th */
476 hi_perf_lmac = rpm_read(rpm, 0, CGXX_CMRX_RX_LMACS);
477 hi_perf_lmac = (hi_perf_lmac >> 4) & 0x3ULL;
478 if (lmac_id == hi_perf_lmac)
488 static int rpmusx_lmac_internal_loopback(rpm_t *rpm, int lmac_id, bool enable)
492 cfg = rpm_read(rpm, lmac_id, RPM2_USX_PCSX_CONTROL1);
495 cfg |= RPM2_USX_PCS_LBK;
497 cfg &= ~RPM2_USX_PCS_LBK;
498 rpm_write(rpm, lmac_id, RPM2_USX_PCSX_CONTROL1, cfg);
503 u32 rpm2_get_lmac_fifo_len(void *rpmd, int lmac_id)
505 u64 hi_perf_lmac, lmac_info;
510 lmac_info = rpm_read(rpm, 0, RPM2_CMRX_RX_LMACS);
511 /* LMACs are divided into two groups and each group
512 * gets half of the FIFO
513 * Group0 lmac_id range {0..3}
514 * Group1 lmac_id range {4..7}
516 fifo_len = rpm->mac_ops->fifo_len / 2;
519 num_lmacs = hweight8(lmac_info & 0xF);
520 hi_perf_lmac = (lmac_info >> 8) & 0x3ULL;
522 num_lmacs = hweight8(lmac_info & 0xF0);
523 hi_perf_lmac = (lmac_info >> 10) & 0x3ULL;
533 /* LMAC marked as hi_perf gets half of the FIFO
536 if (lmac_id == hi_perf_lmac)
546 int rpm_lmac_internal_loopback(void *rpmd, int lmac_id, bool enable)
552 if (!is_lmac_valid(rpm, lmac_id))
555 lmac = lmac_pdata(lmac_id, rpm);
556 if (lmac->lmac_type == LMAC_MODE_QSGMII ||
557 lmac->lmac_type == LMAC_MODE_SGMII) {
558 dev_err(&rpm->pdev->dev, "loopback not supported for LPC mode\n");
562 if (is_dev_rpm2(rpm) && is_mac_rpmusx(rpm))
563 return rpmusx_lmac_internal_loopback(rpm, lmac_id, enable);
565 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_PCS100X_CONTROL1);
568 cfg |= RPMX_MTI_PCS_LBK;
570 cfg &= ~RPMX_MTI_PCS_LBK;
571 rpm_write(rpm, lmac_id, RPMX_MTI_PCS100X_CONTROL1, cfg);
576 void rpm_lmac_ptp_config(void *rpmd, int lmac_id, bool enable)
581 if (!is_lmac_valid(rpm, lmac_id))
584 cfg = rpm_read(rpm, lmac_id, RPMX_CMRX_CFG);
586 cfg |= RPMX_RX_TS_PREPEND;
587 cfg |= RPMX_TX_PTP_1S_SUPPORT;
589 cfg &= ~RPMX_RX_TS_PREPEND;
590 cfg &= ~RPMX_TX_PTP_1S_SUPPORT;
593 rpm_write(rpm, lmac_id, RPMX_CMRX_CFG, cfg);
595 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_XIF_MODE);
598 cfg |= RPMX_ONESTEP_ENABLE;
599 cfg &= ~RPMX_TS_BINARY_MODE;
601 cfg &= ~RPMX_ONESTEP_ENABLE;
604 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_XIF_MODE, cfg);
607 int rpm_lmac_pfc_config(void *rpmd, int lmac_id, u8 tx_pause, u8 rx_pause, u16 pfc_en)
609 u64 cfg, class_en, pfc_class_mask_cfg;
612 if (!is_lmac_valid(rpm, lmac_id))
615 pfc_class_mask_cfg = is_dev_rpm2(rpm) ? RPM2_CMRX_PRT_CBFC_CTL :
616 RPMX_CMRX_PRT_CBFC_CTL;
618 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
619 class_en = rpm_read(rpm, lmac_id, pfc_class_mask_cfg);
620 pfc_en |= FIELD_GET(RPM_PFC_CLASS_MASK, class_en);
623 cfg &= ~(RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE |
624 RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE);
626 cfg |= (RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE |
627 RPMX_MTI_MAC100X_COMMAND_CONFIG_PAUSE_IGNORE);
631 rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, pfc_en, true);
632 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE;
633 class_en = FIELD_SET(RPM_PFC_CLASS_MASK, pfc_en, class_en);
635 rpm_cfg_pfc_quanta_thresh(rpm, lmac_id, 0xfff, false);
636 cfg |= RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE;
637 class_en = FIELD_SET(RPM_PFC_CLASS_MASK, 0, class_en);
640 if (!rx_pause && !tx_pause)
641 cfg &= ~RPMX_MTI_MAC100X_COMMAND_CONFIG_PFC_MODE;
643 cfg |= RPMX_MTI_MAC100X_COMMAND_CONFIG_PFC_MODE;
645 rpm_write(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG, cfg);
646 rpm_write(rpm, lmac_id, pfc_class_mask_cfg, class_en);
651 int rpm_lmac_get_pfc_frm_cfg(void *rpmd, int lmac_id, u8 *tx_pause, u8 *rx_pause)
656 if (!is_lmac_valid(rpm, lmac_id))
659 cfg = rpm_read(rpm, lmac_id, RPMX_MTI_MAC100X_COMMAND_CONFIG);
660 if (cfg & RPMX_MTI_MAC100X_COMMAND_CONFIG_PFC_MODE) {
661 *rx_pause = !(cfg & RPMX_MTI_MAC100X_COMMAND_CONFIG_RX_P_DISABLE);
662 *tx_pause = !(cfg & RPMX_MTI_MAC100X_COMMAND_CONFIG_TX_P_DISABLE);
668 int rpm_get_fec_stats(void *rpmd, int lmac_id, struct cgx_fec_stats_rsp *rsp)
674 if (!is_lmac_valid(rpm, lmac_id))
677 if (rpm->lmac_idmap[lmac_id]->link_info.fec == OTX2_FEC_NONE)
680 if (rpm->lmac_idmap[lmac_id]->link_info.fec == OTX2_FEC_BASER) {
681 val_lo = rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_VL0_CCW_LO);
682 val_hi = rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_CW_HI);
683 rsp->fec_corr_blks = (val_hi << 16 | val_lo);
685 val_lo = rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_VL0_NCCW_LO);
686 val_hi = rpm_read(rpm, lmac_id, RPMX_MTI_FCFECX_CW_HI);
687 rsp->fec_uncorr_blks = (val_hi << 16 | val_lo);
689 /* 50G uses 2 Physical serdes lines */
690 if (rpm->lmac_idmap[lmac_id]->link_info.lmac_type_id ==
692 val_lo = rpm_read(rpm, lmac_id,
693 RPMX_MTI_FCFECX_VL1_CCW_LO);
694 val_hi = rpm_read(rpm, lmac_id,
695 RPMX_MTI_FCFECX_CW_HI);
696 rsp->fec_corr_blks += (val_hi << 16 | val_lo);
698 val_lo = rpm_read(rpm, lmac_id,
699 RPMX_MTI_FCFECX_VL1_NCCW_LO);
700 val_hi = rpm_read(rpm, lmac_id,
701 RPMX_MTI_FCFECX_CW_HI);
702 rsp->fec_uncorr_blks += (val_hi << 16 | val_lo);
705 /* enable RS-FEC capture */
706 cfg = rpm_read(rpm, 0, RPMX_MTI_STAT_STATN_CONTROL);
707 cfg |= RPMX_RSFEC_RX_CAPTURE | BIT(lmac_id);
708 rpm_write(rpm, 0, RPMX_MTI_STAT_STATN_CONTROL, cfg);
710 val_lo = rpm_read(rpm, 0,
711 RPMX_MTI_RSFEC_STAT_COUNTER_CAPTURE_2);
712 val_hi = rpm_read(rpm, 0, RPMX_MTI_STAT_DATA_HI_CDC);
713 rsp->fec_corr_blks = (val_hi << 32 | val_lo);
715 val_lo = rpm_read(rpm, 0,
716 RPMX_MTI_RSFEC_STAT_COUNTER_CAPTURE_3);
717 val_hi = rpm_read(rpm, 0, RPMX_MTI_STAT_DATA_HI_CDC);
718 rsp->fec_uncorr_blks = (val_hi << 32 | val_lo);
724 int rpm_lmac_reset(void *rpmd, int lmac_id, u8 pf_req_flr)
726 u64 rx_logl_xon, cfg;
729 if (!is_lmac_valid(rpm, lmac_id))
732 /* Resetting PFC related CSRs */
733 rx_logl_xon = is_dev_rpm2(rpm) ? RPM2_CMRX_RX_LOGL_XON :
734 RPMX_CMRX_RX_LOGL_XON;
737 rpm_write(rpm, lmac_id, rx_logl_xon, cfg);
740 rpm_lmac_internal_loopback(rpm, lmac_id, false);