1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */
4 #include <linux/etherdevice.h>
5 #include <linux/iopoll.h>
8 #include "../libwx/wx_type.h"
9 #include "../libwx/wx_hw.h"
10 #include "ngbe_type.h"
13 int ngbe_eeprom_chksum_hostif(struct wx *wx)
15 struct wx_hic_read_shadow_ram buffer;
19 buffer.hdr.req.cmd = NGBE_FW_EEPROM_CHECKSUM_CMD;
20 buffer.hdr.req.buf_lenh = 0;
21 buffer.hdr.req.buf_lenl = 0;
22 buffer.hdr.req.checksum = NGBE_FW_CMD_DEFAULT_CHECKSUM;
23 /* convert offset from words to bytes */
28 status = wx_host_interface_command(wx, (u32 *)&buffer, sizeof(buffer),
29 WX_HI_COMMAND_TIMEOUT, false);
33 tmp = rd32a(wx, WX_MNG_MBOX, 1);
34 if (tmp == NGBE_FW_CMD_ST_PASS)
39 static int ngbe_reset_misc(struct wx *wx)
43 /* gpio0 is used to power on/off control*/
44 wr32(wx, NGBE_GPIO_DDR, 0x1);
45 ngbe_sfp_modules_txrx_powerctl(wx, false);
50 void ngbe_sfp_modules_txrx_powerctl(struct wx *wx, bool swi)
52 /* gpio0 is used to power on control . 0 is on */
53 wr32(wx, NGBE_GPIO_DR, swi ? 0 : NGBE_GPIO_DR_0);
57 * ngbe_reset_hw - Perform hardware reset
58 * @wx: pointer to hardware structure
60 * Resets the hardware by resetting the transmit and receive units, masks
61 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
64 int ngbe_reset_hw(struct wx *wx)
69 /* Call wx stop to disable tx/rx and clear interrupts */
70 ret = wx_stop_adapter(wx);
74 if (wx->mac_type != em_mac_type_mdi) {
75 val = WX_MIS_RST_LAN_RST(wx->bus.func);
76 wr32(wx, WX_MIS_RST, val | rd32(wx, WX_MIS_RST));
78 ret = read_poll_timeout(rd32, val,
79 !(val & (BIT(9) << wx->bus.func)), 1000,
80 100000, false, wx, 0x10028);
82 wx_err(wx, "Lan reset exceed s maximum times.\n");
88 wx_clear_hw_cntrs(wx);
90 /* Store the permanent mac address */
91 wx_get_mac_addr(wx, wx->mac.perm_addr);
93 /* reset num_rar_entries to 128 */
94 wx->mac.num_rar_entries = NGBE_RAR_ENTRIES;
96 pci_set_master(wx->pdev);