Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2023 Mucse IC Design Ltd.
3 : : */
4 : :
5 : : #include "rnp_osdep.h"
6 : : #include "rnp_hw.h"
7 : : #include "rnp_mac_regs.h"
8 : : #include "rnp_eth_regs.h"
9 : : #include "rnp_dma_regs.h"
10 : : #include "rnp_common.h"
11 : : #include "rnp_mbx_fw.h"
12 : : #include "rnp_mac.h"
13 : : #include "../rnp.h"
14 : :
15 : : static void
16 : 0 : rnp_hw_reset(struct rnp_hw *hw)
17 : : {
18 : 0 : PMD_INIT_FUNC_TRACE();
19 : :
20 : 0 : RNP_E_REG_WR(hw, RNP_NIC_RESET, 0);
21 : : /* hardware reset valid must be 0 -> 1 */
22 : : wmb();
23 : 0 : RNP_E_REG_WR(hw, RNP_NIC_RESET, 1);
24 : 0 : RNP_PMD_DRV_LOG(INFO, "PF[%d] reset nic finish", hw->mbx.pf_num);
25 : 0 : }
26 : :
27 : 0 : int rnp_init_hw(struct rnp_hw *hw)
28 : : {
29 : 0 : struct rnp_eth_port *port = RNP_DEV_TO_PORT(hw->back->eth_dev);
30 : : u32 version = 0;
31 : : int ret = -1;
32 : : u32 idx = 0;
33 : : u32 state;
34 : :
35 : 0 : PMD_INIT_FUNC_TRACE();
36 : 0 : version = RNP_E_REG_RD(hw, RNP_DMA_VERSION);
37 : 0 : RNP_PMD_DRV_LOG(INFO, "nic hw version:0x%.2x", version);
38 : 0 : rnp_fw_init(hw);
39 : 0 : RNP_E_REG_WR(hw, RNP_DMA_HW_EN, FALSE);
40 : : do {
41 : 0 : state = RNP_E_REG_RD(hw, RNP_DMA_HW_STATE);
42 [ # # ]: 0 : } while (state == 0);
43 : 0 : ret = rnp_mbx_fw_get_capability(port);
44 [ # # ]: 0 : if (ret) {
45 : 0 : RNP_PMD_ERR("mbx_get_capability error! errcode=%d", ret);
46 : 0 : return ret;
47 : : }
48 : 0 : rnp_hw_reset(hw);
49 : 0 : rnp_mbx_fw_reset_phy(hw);
50 : : /* rx packet protocol engine bypass */
51 : 0 : RNP_E_REG_WR(hw, RNP_E_ENG_BYPASS, FALSE);
52 : : /* enable host filter */
53 : 0 : RNP_E_REG_WR(hw, RNP_E_FILTER_EN, TRUE);
54 : : /* enable vxlan parse */
55 : 0 : RNP_E_REG_WR(hw, RNP_E_VXLAN_PARSE_EN, TRUE);
56 : : /* enable flow direct engine */
57 : 0 : RNP_E_REG_WR(hw, RNP_E_REDIR_EN, TRUE);
58 : : /* enable dma engine */
59 : 0 : RNP_E_REG_WR(hw, RNP_DMA_HW_EN, RNP_DMA_EN_ALL);
60 : : #define RNP_TARGET_TC_PORT (2)
61 : : #define RNP_PORT_OFF_QUEUE_NUM (2)
62 [ # # ]: 0 : if (hw->nic_mode == RNP_DUAL_10G && hw->max_port_num == 2)
63 : 0 : RNP_E_REG_WR(hw, RNP_TC_PORT_OFFSET(RNP_TARGET_TC_PORT),
64 : : RNP_PORT_OFF_QUEUE_NUM);
65 : : /* setup mac resiger ctrl base */
66 [ # # ]: 0 : for (idx = 0; idx < hw->max_port_num; idx++)
67 : 0 : hw->mac_base[idx] = (u8 *)hw->e_ctrl + RNP_MAC_BASE_OFFSET(idx);
68 : : /* tx all hw queue must be started */
69 [ # # ]: 0 : for (idx = 0; idx < RNP_MAX_RX_QUEUE_NUM; idx++)
70 : 0 : RNP_E_REG_WR(hw, RNP_TXQ_START(idx), true);
71 : :
72 : : return 0;
73 : : }
74 : :
75 : : int
76 : 0 : rnp_setup_common_ops(struct rnp_hw *hw)
77 : : {
78 : 0 : rnp_mac_ops_init(hw);
79 : :
80 : 0 : return 0;
81 : : }
82 : :
83 : 0 : int rnp_clock_valid_check(struct rnp_hw *hw, u16 nr_lane)
84 : : {
85 : : uint16_t timeout = 0;
86 : :
87 : : do {
88 : 0 : RNP_E_REG_WR(hw, RNP_RSS_REDIR_TB(nr_lane, 0), 0x7f);
89 : 0 : udelay(10);
90 : 0 : timeout++;
91 [ # # ]: 0 : if (timeout >= 1000)
92 : : break;
93 [ # # ]: 0 : } while (RNP_E_REG_RD(hw, RNP_RSS_REDIR_TB(nr_lane, 0)) != 0x7f);
94 : :
95 [ # # ]: 0 : if (timeout >= 1000) {
96 : 0 : RNP_PMD_ERR("ethernet[%d] eth reg can't be write", nr_lane);
97 : 0 : return -EPERM;
98 : : }
99 : : /* clear the dirty value */
100 : 0 : RNP_E_REG_WR(hw, RNP_RSS_REDIR_TB(nr_lane, 0), 0);
101 : :
102 : 0 : return 0;
103 : : }
|