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