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 
13 int ngbe_eeprom_chksum_hostif(struct ngbe_adapter *adapter)
14 {
15 	struct wx_hic_read_shadow_ram buffer;
16 	struct wx *wx = &adapter->wx;
17 	int status;
18 	int tmp;
19 
20 	buffer.hdr.req.cmd = NGBE_FW_EEPROM_CHECKSUM_CMD;
21 	buffer.hdr.req.buf_lenh = 0;
22 	buffer.hdr.req.buf_lenl = 0;
23 	buffer.hdr.req.checksum = NGBE_FW_CMD_DEFAULT_CHECKSUM;
24 	/* convert offset from words to bytes */
25 	buffer.address = 0;
26 	/* one word */
27 	buffer.length = 0;
28 
29 	status = wx_host_interface_command(wx, (u32 *)&buffer, sizeof(buffer),
30 					   WX_HI_COMMAND_TIMEOUT, false);
31 
32 	if (status < 0)
33 		return status;
34 	tmp = rd32a(wx, WX_MNG_MBOX, 1);
35 	if (tmp == NGBE_FW_CMD_ST_PASS)
36 		return 0;
37 	return -EIO;
38 }
39 
40 static int ngbe_reset_misc(struct ngbe_adapter *adapter)
41 {
42 	struct wx *wx = &adapter->wx;
43 
44 	wx_reset_misc(wx);
45 	if (adapter->mac_type == ngbe_mac_type_rgmii)
46 		wr32(wx, NGBE_MDIO_CLAUSE_SELECT, 0xF);
47 	if (adapter->gpio_ctrl) {
48 		/* gpio0 is used to power on/off control*/
49 		wr32(wx, NGBE_GPIO_DDR, 0x1);
50 		wr32(wx, NGBE_GPIO_DR, NGBE_GPIO_DR_0);
51 	}
52 	return 0;
53 }
54 
55 /**
56  *  ngbe_reset_hw - Perform hardware reset
57  *  @adapter: pointer to hardware structure
58  *
59  *  Resets the hardware by resetting the transmit and receive units, masks
60  *  and clears all interrupts, perform a PHY reset, and perform a link (MAC)
61  *  reset.
62  **/
63 int ngbe_reset_hw(struct ngbe_adapter *adapter)
64 {
65 	struct wx *wx = &adapter->wx;
66 	int status = 0;
67 	u32 reset = 0;
68 
69 	/* Call adapter stop to disable tx/rx and clear interrupts */
70 	status = wx_stop_adapter(wx);
71 	if (status != 0)
72 		return status;
73 	reset = WX_MIS_RST_LAN_RST(wx->bus.func);
74 	wr32(wx, WX_MIS_RST, reset | rd32(wx, WX_MIS_RST));
75 	ngbe_reset_misc(adapter);
76 
77 	/* Store the permanent mac address */
78 	wx_get_mac_addr(wx, wx->mac.perm_addr);
79 
80 	/* reset num_rar_entries to 128 */
81 	wx->mac.num_rar_entries = NGBE_RAR_ENTRIES;
82 	wx_init_rx_addrs(wx);
83 	pci_set_master(wx->pdev);
84 
85 	return 0;
86 }
87