1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 - 2022 Beijing WangXun Technology Co., Ltd. */
3 
4 #include <linux/etherdevice.h>
5 #include <linux/iopoll.h>
6 #include <linux/pci.h>
7 
8 #include "../libwx/wx_type.h"
9 #include "../libwx/wx_hw.h"
10 #include "ngbe_type.h"
11 #include "ngbe_hw.h"
12 #include "ngbe.h"
13 
14 int ngbe_eeprom_chksum_hostif(struct ngbe_hw *hw)
15 {
16 	struct wx_hic_read_shadow_ram buffer;
17 	struct wx_hw *wxhw = &hw->wxhw;
18 	int status;
19 	int tmp;
20 
21 	buffer.hdr.req.cmd = NGBE_FW_EEPROM_CHECKSUM_CMD;
22 	buffer.hdr.req.buf_lenh = 0;
23 	buffer.hdr.req.buf_lenl = 0;
24 	buffer.hdr.req.checksum = NGBE_FW_CMD_DEFAULT_CHECKSUM;
25 	/* convert offset from words to bytes */
26 	buffer.address = 0;
27 	/* one word */
28 	buffer.length = 0;
29 
30 	status = wx_host_interface_command(wxhw, (u32 *)&buffer, sizeof(buffer),
31 					   WX_HI_COMMAND_TIMEOUT, false);
32 
33 	if (status < 0)
34 		return status;
35 	tmp = rd32a(wxhw, WX_MNG_MBOX, 1);
36 	if (tmp == NGBE_FW_CMD_ST_PASS)
37 		return 0;
38 	return -EIO;
39 }
40 
41 static int ngbe_reset_misc(struct ngbe_hw *hw)
42 {
43 	struct wx_hw *wxhw = &hw->wxhw;
44 
45 	wx_reset_misc(wxhw);
46 	if (hw->mac_type == ngbe_mac_type_rgmii)
47 		wr32(wxhw, NGBE_MDIO_CLAUSE_SELECT, 0xF);
48 	if (hw->gpio_ctrl) {
49 		/* gpio0 is used to power on/off control*/
50 		wr32(wxhw, NGBE_GPIO_DDR, 0x1);
51 		wr32(wxhw, NGBE_GPIO_DR, NGBE_GPIO_DR_0);
52 	}
53 	return 0;
54 }
55 
56 /**
57  *  ngbe_reset_hw - Perform hardware reset
58  *  @hw: pointer to hardware structure
59  *
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)
62  *  reset.
63  **/
64 int ngbe_reset_hw(struct ngbe_hw *hw)
65 {
66 	struct wx_hw *wxhw = &hw->wxhw;
67 	int status = 0;
68 	u32 reset = 0;
69 
70 	/* Call adapter stop to disable tx/rx and clear interrupts */
71 	status = wx_stop_adapter(wxhw);
72 	if (status != 0)
73 		return status;
74 	reset = WX_MIS_RST_LAN_RST(wxhw->bus.func);
75 	wr32(wxhw, WX_MIS_RST, reset | rd32(wxhw, WX_MIS_RST));
76 	ngbe_reset_misc(hw);
77 
78 	/* Store the permanent mac address */
79 	wx_get_mac_addr(wxhw, wxhw->mac.perm_addr);
80 
81 	/* reset num_rar_entries to 128 */
82 	wxhw->mac.num_rar_entries = NGBE_RAR_ENTRIES;
83 	wx_init_rx_addrs(wxhw);
84 	pci_set_master(wxhw->pdev);
85 
86 	return 0;
87 }
88