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->gpio_ctrl) { 43 /* gpio0 is used to power on/off control*/ 44 wr32(wx, NGBE_GPIO_DDR, 0x1); 45 ngbe_sfp_modules_txrx_powerctl(wx, false); 46 } 47 return 0; 48 } 49 50 void ngbe_sfp_modules_txrx_powerctl(struct wx *wx, bool swi) 51 { 52 if (swi) 53 /* gpio0 is used to power on control*/ 54 wr32(wx, NGBE_GPIO_DR, 0); 55 else 56 /* gpio0 is used to power off control*/ 57 wr32(wx, NGBE_GPIO_DR, NGBE_GPIO_DR_0); 58 } 59 60 /** 61 * ngbe_reset_hw - Perform hardware reset 62 * @wx: pointer to hardware structure 63 * 64 * Resets the hardware by resetting the transmit and receive units, masks 65 * and clears all interrupts, perform a PHY reset, and perform a link (MAC) 66 * reset. 67 **/ 68 int ngbe_reset_hw(struct wx *wx) 69 { 70 u32 val = 0; 71 int ret = 0; 72 73 /* Call wx stop to disable tx/rx and clear interrupts */ 74 ret = wx_stop_adapter(wx); 75 if (ret != 0) 76 return ret; 77 78 if (wx->mac_type != em_mac_type_mdi) { 79 val = WX_MIS_RST_LAN_RST(wx->bus.func); 80 wr32(wx, WX_MIS_RST, val | rd32(wx, WX_MIS_RST)); 81 82 ret = read_poll_timeout(rd32, val, 83 !(val & (BIT(9) << wx->bus.func)), 1000, 84 100000, false, wx, 0x10028); 85 if (ret) { 86 wx_err(wx, "Lan reset exceed s maximum times.\n"); 87 return ret; 88 } 89 } 90 ngbe_reset_misc(wx); 91 92 /* Store the permanent mac address */ 93 wx_get_mac_addr(wx, wx->mac.perm_addr); 94 95 /* reset num_rar_entries to 128 */ 96 wx->mac.num_rar_entries = NGBE_RAR_ENTRIES; 97 wx_init_rx_addrs(wx); 98 pci_set_master(wx->pdev); 99 100 return 0; 101 } 102