1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2015 - 2022 Beijing WangXun Technology Co., Ltd. */
4 #include <linux/etherdevice.h>
5 #include <linux/if_ether.h>
6 #include <linux/string.h>
7 #include <linux/iopoll.h>
8 #include <linux/types.h>
11 #include "../libwx/wx_type.h"
12 #include "../libwx/wx_hw.h"
13 #include "txgbe_type.h"
17 * txgbe_disable_sec_tx_path - Stops the transmit data path
18 * @wx: pointer to hardware structure
20 * Stops the transmit data path and waits for the HW to internally empty
21 * the tx security block
23 int txgbe_disable_sec_tx_path(struct wx *wx)
27 wr32m(wx, WX_TSC_CTL, WX_TSC_CTL_TX_DIS, WX_TSC_CTL_TX_DIS);
28 return read_poll_timeout(rd32, val, val & WX_TSC_ST_SECTX_RDY,
29 1000, 20000, false, wx, WX_TSC_ST);
33 * txgbe_enable_sec_tx_path - Enables the transmit data path
34 * @wx: pointer to hardware structure
36 * Enables the transmit data path.
38 void txgbe_enable_sec_tx_path(struct wx *wx)
40 wr32m(wx, WX_TSC_CTL, WX_TSC_CTL_TX_DIS, 0);
45 * txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
46 * @wx: pointer to hardware structure
48 * Inits the thermal sensor thresholds according to the NVM map
49 * and save off the threshold and location values into mac.thermal_sensor_data
51 static void txgbe_init_thermal_sensor_thresh(struct wx *wx)
53 struct wx_thermal_sensor_data *data = &wx->mac.sensor;
55 memset(data, 0, sizeof(struct wx_thermal_sensor_data));
57 /* Only support thermal sensors attached to SP physical port 0 */
61 wr32(wx, TXGBE_TS_CTL, TXGBE_TS_CTL_EVAL_MD);
63 wr32(wx, WX_TS_INT_EN,
64 WX_TS_INT_EN_ALARM_INT_EN | WX_TS_INT_EN_DALARM_INT_EN);
65 wr32(wx, WX_TS_EN, WX_TS_EN_ENA);
67 data->alarm_thresh = 100;
68 wr32(wx, WX_TS_ALARM_THRE, 677);
69 data->dalarm_thresh = 90;
70 wr32(wx, WX_TS_DALARM_THRE, 614);
74 * txgbe_calc_eeprom_checksum - Calculates and returns the checksum
75 * @wx: pointer to hardware structure
76 * @checksum: pointer to cheksum
78 * Returns a negative error code on error
80 static int txgbe_calc_eeprom_checksum(struct wx *wx, u16 *checksum)
82 u16 *eeprom_ptrs = NULL;
87 wx_init_eeprom_params(wx);
89 eeprom_ptrs = kvmalloc_array(TXGBE_EEPROM_LAST_WORD, sizeof(u16),
93 /* Read pointer area */
94 status = wx_read_ee_hostif_buffer(wx, 0, TXGBE_EEPROM_LAST_WORD, eeprom_ptrs);
96 wx_err(wx, "Failed to read EEPROM image\n");
100 local_buffer = eeprom_ptrs;
102 for (i = 0; i < TXGBE_EEPROM_LAST_WORD; i++)
103 if (i != wx->eeprom.sw_region_offset + TXGBE_EEPROM_CHECKSUM)
104 *checksum += local_buffer[i];
109 *checksum = TXGBE_EEPROM_SUM - *checksum;
115 * txgbe_validate_eeprom_checksum - Validate EEPROM checksum
116 * @wx: pointer to hardware structure
117 * @checksum_val: calculated checksum
119 * Performs checksum calculation and validates the EEPROM checksum. If the
120 * caller does not need checksum_val, the value can be NULL.
122 int txgbe_validate_eeprom_checksum(struct wx *wx, u16 *checksum_val)
124 u16 read_checksum = 0;
128 /* Read the first word from the EEPROM. If this times out or fails, do
129 * not continue or we could be in for a very long wait while every
132 status = wx_read_ee_hostif(wx, 0, &checksum);
134 wx_err(wx, "EEPROM read failed\n");
139 status = txgbe_calc_eeprom_checksum(wx, &checksum);
143 status = wx_read_ee_hostif(wx, wx->eeprom.sw_region_offset +
144 TXGBE_EEPROM_CHECKSUM, &read_checksum);
148 /* Verify read checksum from EEPROM is the same as
149 * calculated checksum
151 if (read_checksum != checksum) {
153 wx_err(wx, "Invalid EEPROM checksum\n");
156 /* If the user cares, return the calculated checksum */
158 *checksum_val = checksum;
163 static void txgbe_reset_misc(struct wx *wx)
166 txgbe_init_thermal_sensor_thresh(wx);
170 * txgbe_reset_hw - Perform hardware reset
171 * @wx: pointer to wx structure
173 * Resets the hardware by resetting the transmit and receive units, masks
174 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
177 int txgbe_reset_hw(struct wx *wx)
181 /* Call adapter stop to disable tx/rx and clear interrupts */
182 status = wx_stop_adapter(wx);
186 if (wx->media_type != sp_media_copper) {
189 val = WX_MIS_RST_LAN_RST(wx->bus.func);
190 wr32(wx, WX_MIS_RST, val | rd32(wx, WX_MIS_RST));
192 usleep_range(10, 100);
195 status = wx_check_flash_load(wx, TXGBE_SPI_ILDR_STATUS_LAN_SW_RST(wx->bus.func));
199 txgbe_reset_misc(wx);
201 wx_clear_hw_cntrs(wx);
203 /* Store the permanent mac address */
204 wx_get_mac_addr(wx, wx->mac.perm_addr);
206 /* Store MAC address from RAR0, clear receive address registers, and
207 * clear the multicast table. Also reset num_rar_entries to 128,
208 * since we modify this value when programming the SAN MAC address.
210 wx->mac.num_rar_entries = TXGBE_SP_RAR_ENTRIES;
211 wx_init_rx_addrs(wx);
213 pci_set_master(wx->pdev);