Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel 10 Gigabit PCI Express Linux driver |
| 4 | * Copyright(c) 1999 - 2014 Intel Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * The full GNU General Public License is included in this distribution in |
| 16 | * the file called "COPYING". |
| 17 | * |
| 18 | * Contact Information: |
| 19 | * Linux NICS <linux.nics@intel.com> |
| 20 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 21 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | #include "ixgbe_x540.h" |
| 25 | #include "ixgbe_type.h" |
| 26 | #include "ixgbe_common.h" |
| 27 | #include "ixgbe_phy.h" |
| 28 | |
Don Skidmore | ab5fe0c | 2015-06-09 16:18:56 -0700 | [diff] [blame^] | 29 | /** ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control |
| 30 | * @hw: pointer to hardware structure |
| 31 | **/ |
| 32 | static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw) |
| 33 | { |
| 34 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 35 | |
| 36 | if (hw->bus.lan_id) { |
| 37 | esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1); |
| 38 | esdp |= IXGBE_ESDP_SDP1_DIR; |
| 39 | } |
| 40 | esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR); |
| 41 | IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp); |
| 42 | IXGBE_WRITE_FLUSH(hw); |
| 43 | } |
| 44 | |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 45 | /** ixgbe_identify_phy_x550em - Get PHY type based on device id |
| 46 | * @hw: pointer to hardware structure |
| 47 | * |
| 48 | * Returns error code |
| 49 | */ |
| 50 | static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw) |
| 51 | { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 52 | switch (hw->device_id) { |
| 53 | case IXGBE_DEV_ID_X550EM_X_SFP: |
| 54 | /* set up for CS4227 usage */ |
| 55 | hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM; |
Don Skidmore | ab5fe0c | 2015-06-09 16:18:56 -0700 | [diff] [blame^] | 56 | ixgbe_setup_mux_ctl(hw); |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 57 | |
| 58 | return ixgbe_identify_module_generic(hw); |
| 59 | case IXGBE_DEV_ID_X550EM_X_KX4: |
| 60 | hw->phy.type = ixgbe_phy_x550em_kx4; |
| 61 | break; |
| 62 | case IXGBE_DEV_ID_X550EM_X_KR: |
| 63 | hw->phy.type = ixgbe_phy_x550em_kr; |
| 64 | break; |
| 65 | case IXGBE_DEV_ID_X550EM_X_1G_T: |
| 66 | case IXGBE_DEV_ID_X550EM_X_10G_T: |
| 67 | return ixgbe_identify_phy_generic(hw); |
| 68 | default: |
| 69 | break; |
| 70 | } |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr, |
| 75 | u32 device_type, u16 *phy_data) |
| 76 | { |
| 77 | return IXGBE_NOT_IMPLEMENTED; |
| 78 | } |
| 79 | |
| 80 | static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr, |
| 81 | u32 device_type, u16 phy_data) |
| 82 | { |
| 83 | return IXGBE_NOT_IMPLEMENTED; |
| 84 | } |
| 85 | |
| 86 | /** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params |
| 87 | * @hw: pointer to hardware structure |
| 88 | * |
| 89 | * Initializes the EEPROM parameters ixgbe_eeprom_info within the |
| 90 | * ixgbe_hw struct in order to set up EEPROM access. |
| 91 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 92 | static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 93 | { |
| 94 | struct ixgbe_eeprom_info *eeprom = &hw->eeprom; |
| 95 | u32 eec; |
| 96 | u16 eeprom_size; |
| 97 | |
| 98 | if (eeprom->type == ixgbe_eeprom_uninitialized) { |
| 99 | eeprom->semaphore_delay = 10; |
| 100 | eeprom->type = ixgbe_flash; |
| 101 | |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 102 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 103 | eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> |
| 104 | IXGBE_EEC_SIZE_SHIFT); |
| 105 | eeprom->word_size = 1 << (eeprom_size + |
| 106 | IXGBE_EEPROM_WORD_SIZE_SHIFT); |
| 107 | |
| 108 | hw_dbg(hw, "Eeprom params: type = %d, size = %d\n", |
| 109 | eeprom->type, eeprom->word_size); |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 115 | /** |
| 116 | * ixgbe_iosf_wait - Wait for IOSF command completion |
| 117 | * @hw: pointer to hardware structure |
| 118 | * @ctrl: pointer to location to receive final IOSF control value |
| 119 | * |
| 120 | * Return: failing status on timeout |
| 121 | * |
| 122 | * Note: ctrl can be NULL if the IOSF control register value is not needed |
| 123 | */ |
| 124 | static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl) |
| 125 | { |
| 126 | u32 i, command; |
| 127 | |
| 128 | /* Check every 10 usec to see if the address cycle completed. |
| 129 | * The SB IOSF BUSY bit will clear when the operation is |
| 130 | * complete. |
| 131 | */ |
| 132 | for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) { |
| 133 | command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL); |
| 134 | if (!(command & IXGBE_SB_IOSF_CTRL_BUSY)) |
| 135 | break; |
| 136 | usleep_range(10, 20); |
| 137 | } |
| 138 | if (ctrl) |
| 139 | *ctrl = command; |
| 140 | if (i == IXGBE_MDIO_COMMAND_TIMEOUT) { |
| 141 | hw_dbg(hw, "IOSF wait timed out\n"); |
| 142 | return IXGBE_ERR_PHY; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 148 | /** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the |
| 149 | * IOSF device |
| 150 | * @hw: pointer to hardware structure |
| 151 | * @reg_addr: 32 bit PHY register to write |
| 152 | * @device_type: 3 bit device type |
| 153 | * @phy_data: Pointer to read data from the register |
| 154 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 155 | static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr, |
| 156 | u32 device_type, u32 *data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 157 | { |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 158 | u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM; |
| 159 | u32 command, error; |
| 160 | s32 ret; |
| 161 | |
| 162 | ret = hw->mac.ops.acquire_swfw_sync(hw, gssr); |
| 163 | if (ret) |
| 164 | return ret; |
| 165 | |
| 166 | ret = ixgbe_iosf_wait(hw, NULL); |
| 167 | if (ret) |
| 168 | goto out; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 169 | |
| 170 | command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) | |
| 171 | (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT)); |
| 172 | |
| 173 | /* Write IOSF control register */ |
| 174 | IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command); |
| 175 | |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 176 | ret = ixgbe_iosf_wait(hw, &command); |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 177 | |
| 178 | if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) { |
| 179 | error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >> |
| 180 | IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT; |
| 181 | hw_dbg(hw, "Failed to read, error %x\n", error); |
| 182 | return IXGBE_ERR_PHY; |
| 183 | } |
| 184 | |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 185 | if (!ret) |
| 186 | *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA); |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 187 | |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 188 | out: |
| 189 | hw->mac.ops.release_swfw_sync(hw, gssr); |
| 190 | return ret; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** ixgbe_read_ee_hostif_data_X550 - Read EEPROM word using a host interface |
| 194 | * command assuming that the semaphore is already obtained. |
| 195 | * @hw: pointer to hardware structure |
| 196 | * @offset: offset of word in the EEPROM to read |
| 197 | * @data: word read from the EEPROM |
| 198 | * |
| 199 | * Reads a 16 bit word from the EEPROM using the hostif. |
| 200 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 201 | static s32 ixgbe_read_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset, |
| 202 | u16 *data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 203 | { |
| 204 | s32 status; |
| 205 | struct ixgbe_hic_read_shadow_ram buffer; |
| 206 | |
| 207 | buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD; |
| 208 | buffer.hdr.req.buf_lenh = 0; |
| 209 | buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN; |
| 210 | buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM; |
| 211 | |
| 212 | /* convert offset from words to bytes */ |
| 213 | buffer.address = cpu_to_be32(offset * 2); |
| 214 | /* one word */ |
| 215 | buffer.length = cpu_to_be16(sizeof(u16)); |
| 216 | |
| 217 | status = ixgbe_host_interface_command(hw, (u32 *)&buffer, |
| 218 | sizeof(buffer), |
| 219 | IXGBE_HI_COMMAND_TIMEOUT, false); |
| 220 | if (status) |
| 221 | return status; |
| 222 | |
| 223 | *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, |
| 224 | FW_NVM_DATA_OFFSET); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif |
| 230 | * @hw: pointer to hardware structure |
| 231 | * @offset: offset of word in the EEPROM to read |
| 232 | * @words: number of words |
| 233 | * @data: word(s) read from the EEPROM |
| 234 | * |
| 235 | * Reads a 16 bit word(s) from the EEPROM using the hostif. |
| 236 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 237 | static s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw, |
| 238 | u16 offset, u16 words, u16 *data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 239 | { |
| 240 | struct ixgbe_hic_read_shadow_ram buffer; |
| 241 | u32 current_word = 0; |
| 242 | u16 words_to_read; |
| 243 | s32 status; |
| 244 | u32 i; |
| 245 | |
| 246 | /* Take semaphore for the entire operation. */ |
| 247 | status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
| 248 | if (status) { |
| 249 | hw_dbg(hw, "EEPROM read buffer - semaphore failed\n"); |
| 250 | return status; |
| 251 | } |
| 252 | |
| 253 | while (words) { |
| 254 | if (words > FW_MAX_READ_BUFFER_SIZE / 2) |
| 255 | words_to_read = FW_MAX_READ_BUFFER_SIZE / 2; |
| 256 | else |
| 257 | words_to_read = words; |
| 258 | |
| 259 | buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD; |
| 260 | buffer.hdr.req.buf_lenh = 0; |
| 261 | buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN; |
| 262 | buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM; |
| 263 | |
| 264 | /* convert offset from words to bytes */ |
| 265 | buffer.address = cpu_to_be32((offset + current_word) * 2); |
| 266 | buffer.length = cpu_to_be16(words_to_read * 2); |
| 267 | |
| 268 | status = ixgbe_host_interface_command(hw, (u32 *)&buffer, |
| 269 | sizeof(buffer), |
| 270 | IXGBE_HI_COMMAND_TIMEOUT, |
| 271 | false); |
| 272 | if (status) { |
| 273 | hw_dbg(hw, "Host interface command failed\n"); |
| 274 | goto out; |
| 275 | } |
| 276 | |
| 277 | for (i = 0; i < words_to_read; i++) { |
| 278 | u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) + |
| 279 | 2 * i; |
| 280 | u32 value = IXGBE_READ_REG(hw, reg); |
| 281 | |
| 282 | data[current_word] = (u16)(value & 0xffff); |
| 283 | current_word++; |
| 284 | i++; |
| 285 | if (i < words_to_read) { |
| 286 | value >>= 16; |
| 287 | data[current_word] = (u16)(value & 0xffff); |
| 288 | current_word++; |
| 289 | } |
| 290 | } |
| 291 | words -= words_to_read; |
| 292 | } |
| 293 | |
| 294 | out: |
| 295 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
| 296 | return status; |
| 297 | } |
| 298 | |
| 299 | /** ixgbe_checksum_ptr_x550 - Checksum one pointer region |
| 300 | * @hw: pointer to hardware structure |
| 301 | * @ptr: pointer offset in eeprom |
| 302 | * @size: size of section pointed by ptr, if 0 first word will be used as size |
| 303 | * @csum: address of checksum to update |
| 304 | * |
| 305 | * Returns error status for any failure |
| 306 | **/ |
| 307 | static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr, |
| 308 | u16 size, u16 *csum, u16 *buffer, |
| 309 | u32 buffer_size) |
| 310 | { |
| 311 | u16 buf[256]; |
| 312 | s32 status; |
| 313 | u16 length, bufsz, i, start; |
| 314 | u16 *local_buffer; |
| 315 | |
| 316 | bufsz = sizeof(buf) / sizeof(buf[0]); |
| 317 | |
| 318 | /* Read a chunk at the pointer location */ |
| 319 | if (!buffer) { |
| 320 | status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf); |
| 321 | if (status) { |
| 322 | hw_dbg(hw, "Failed to read EEPROM image\n"); |
| 323 | return status; |
| 324 | } |
| 325 | local_buffer = buf; |
| 326 | } else { |
| 327 | if (buffer_size < ptr) |
| 328 | return IXGBE_ERR_PARAM; |
| 329 | local_buffer = &buffer[ptr]; |
| 330 | } |
| 331 | |
| 332 | if (size) { |
| 333 | start = 0; |
| 334 | length = size; |
| 335 | } else { |
| 336 | start = 1; |
| 337 | length = local_buffer[0]; |
| 338 | |
| 339 | /* Skip pointer section if length is invalid. */ |
| 340 | if (length == 0xFFFF || length == 0 || |
| 341 | (ptr + length) >= hw->eeprom.word_size) |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | if (buffer && ((u32)start + (u32)length > buffer_size)) |
| 346 | return IXGBE_ERR_PARAM; |
| 347 | |
| 348 | for (i = start; length; i++, length--) { |
| 349 | if (i == bufsz && !buffer) { |
| 350 | ptr += bufsz; |
| 351 | i = 0; |
| 352 | if (length < bufsz) |
| 353 | bufsz = length; |
| 354 | |
| 355 | /* Read a chunk at the pointer location */ |
| 356 | status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, |
| 357 | bufsz, buf); |
| 358 | if (status) { |
| 359 | hw_dbg(hw, "Failed to read EEPROM image\n"); |
| 360 | return status; |
| 361 | } |
| 362 | } |
| 363 | *csum += local_buffer[i]; |
| 364 | } |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /** ixgbe_calc_checksum_X550 - Calculates and returns the checksum |
| 369 | * @hw: pointer to hardware structure |
| 370 | * @buffer: pointer to buffer containing calculated checksum |
| 371 | * @buffer_size: size of buffer |
| 372 | * |
| 373 | * Returns a negative error code on error, or the 16-bit checksum |
| 374 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 375 | static s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer, |
| 376 | u32 buffer_size) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 377 | { |
| 378 | u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1]; |
| 379 | u16 *local_buffer; |
| 380 | s32 status; |
| 381 | u16 checksum = 0; |
| 382 | u16 pointer, i, size; |
| 383 | |
| 384 | hw->eeprom.ops.init_params(hw); |
| 385 | |
| 386 | if (!buffer) { |
| 387 | /* Read pointer area */ |
| 388 | status = ixgbe_read_ee_hostif_buffer_X550(hw, 0, |
| 389 | IXGBE_EEPROM_LAST_WORD + 1, |
| 390 | eeprom_ptrs); |
| 391 | if (status) { |
| 392 | hw_dbg(hw, "Failed to read EEPROM image\n"); |
| 393 | return status; |
| 394 | } |
| 395 | local_buffer = eeprom_ptrs; |
| 396 | } else { |
| 397 | if (buffer_size < IXGBE_EEPROM_LAST_WORD) |
| 398 | return IXGBE_ERR_PARAM; |
| 399 | local_buffer = buffer; |
| 400 | } |
| 401 | |
| 402 | /* For X550 hardware include 0x0-0x41 in the checksum, skip the |
| 403 | * checksum word itself |
| 404 | */ |
| 405 | for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++) |
| 406 | if (i != IXGBE_EEPROM_CHECKSUM) |
| 407 | checksum += local_buffer[i]; |
| 408 | |
| 409 | /* Include all data from pointers 0x3, 0x6-0xE. This excludes the |
| 410 | * FW, PHY module, and PCIe Expansion/Option ROM pointers. |
| 411 | */ |
| 412 | for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) { |
| 413 | if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR) |
| 414 | continue; |
| 415 | |
| 416 | pointer = local_buffer[i]; |
| 417 | |
| 418 | /* Skip pointer section if the pointer is invalid. */ |
| 419 | if (pointer == 0xFFFF || pointer == 0 || |
| 420 | pointer >= hw->eeprom.word_size) |
| 421 | continue; |
| 422 | |
| 423 | switch (i) { |
| 424 | case IXGBE_PCIE_GENERAL_PTR: |
| 425 | size = IXGBE_IXGBE_PCIE_GENERAL_SIZE; |
| 426 | break; |
| 427 | case IXGBE_PCIE_CONFIG0_PTR: |
| 428 | case IXGBE_PCIE_CONFIG1_PTR: |
| 429 | size = IXGBE_PCIE_CONFIG_SIZE; |
| 430 | break; |
| 431 | default: |
| 432 | size = 0; |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum, |
| 437 | buffer, buffer_size); |
| 438 | if (status) |
| 439 | return status; |
| 440 | } |
| 441 | |
| 442 | checksum = (u16)IXGBE_EEPROM_SUM - checksum; |
| 443 | |
| 444 | return (s32)checksum; |
| 445 | } |
| 446 | |
| 447 | /** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum |
| 448 | * @hw: pointer to hardware structure |
| 449 | * |
| 450 | * Returns a negative error code on error, or the 16-bit checksum |
| 451 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 452 | static s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 453 | { |
| 454 | return ixgbe_calc_checksum_X550(hw, NULL, 0); |
| 455 | } |
| 456 | |
| 457 | /** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command |
| 458 | * @hw: pointer to hardware structure |
| 459 | * @offset: offset of word in the EEPROM to read |
| 460 | * @data: word read from the EEPROM |
| 461 | * |
| 462 | * Reads a 16 bit word from the EEPROM using the hostif. |
| 463 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 464 | static s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 465 | { |
| 466 | s32 status = 0; |
| 467 | |
| 468 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) { |
| 469 | status = ixgbe_read_ee_hostif_data_X550(hw, offset, data); |
| 470 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
| 471 | } else { |
| 472 | status = IXGBE_ERR_SWFW_SYNC; |
| 473 | } |
| 474 | |
| 475 | return status; |
| 476 | } |
| 477 | |
| 478 | /** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum |
| 479 | * @hw: pointer to hardware structure |
| 480 | * @checksum_val: calculated checksum |
| 481 | * |
| 482 | * Performs checksum calculation and validates the EEPROM checksum. If the |
| 483 | * caller does not need checksum_val, the value can be NULL. |
| 484 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 485 | static s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw, |
| 486 | u16 *checksum_val) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 487 | { |
| 488 | s32 status; |
| 489 | u16 checksum; |
| 490 | u16 read_checksum = 0; |
| 491 | |
| 492 | /* Read the first word from the EEPROM. If this times out or fails, do |
| 493 | * not continue or we could be in for a very long wait while every |
| 494 | * EEPROM read fails |
| 495 | */ |
| 496 | status = hw->eeprom.ops.read(hw, 0, &checksum); |
| 497 | if (status) { |
| 498 | hw_dbg(hw, "EEPROM read failed\n"); |
| 499 | return status; |
| 500 | } |
| 501 | |
| 502 | status = hw->eeprom.ops.calc_checksum(hw); |
| 503 | if (status < 0) |
| 504 | return status; |
| 505 | |
| 506 | checksum = (u16)(status & 0xffff); |
| 507 | |
| 508 | status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM, |
| 509 | &read_checksum); |
| 510 | if (status) |
| 511 | return status; |
| 512 | |
| 513 | /* Verify read checksum from EEPROM is the same as |
| 514 | * calculated checksum |
| 515 | */ |
| 516 | if (read_checksum != checksum) { |
| 517 | status = IXGBE_ERR_EEPROM_CHECKSUM; |
| 518 | hw_dbg(hw, "Invalid EEPROM checksum"); |
| 519 | } |
| 520 | |
| 521 | /* If the user cares, return the calculated checksum */ |
| 522 | if (checksum_val) |
| 523 | *checksum_val = checksum; |
| 524 | |
| 525 | return status; |
| 526 | } |
| 527 | |
| 528 | /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif |
| 529 | * @hw: pointer to hardware structure |
| 530 | * @offset: offset of word in the EEPROM to write |
| 531 | * @data: word write to the EEPROM |
| 532 | * |
| 533 | * Write a 16 bit word to the EEPROM using the hostif. |
| 534 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 535 | static s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset, |
| 536 | u16 data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 537 | { |
| 538 | s32 status; |
| 539 | struct ixgbe_hic_write_shadow_ram buffer; |
| 540 | |
| 541 | buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD; |
| 542 | buffer.hdr.req.buf_lenh = 0; |
| 543 | buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN; |
| 544 | buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM; |
| 545 | |
| 546 | /* one word */ |
| 547 | buffer.length = cpu_to_be16(sizeof(u16)); |
| 548 | buffer.data = data; |
| 549 | buffer.address = cpu_to_be32(offset * 2); |
| 550 | |
| 551 | status = ixgbe_host_interface_command(hw, (u32 *)&buffer, |
| 552 | sizeof(buffer), |
| 553 | IXGBE_HI_COMMAND_TIMEOUT, false); |
| 554 | return status; |
| 555 | } |
| 556 | |
| 557 | /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif |
| 558 | * @hw: pointer to hardware structure |
| 559 | * @offset: offset of word in the EEPROM to write |
| 560 | * @data: word write to the EEPROM |
| 561 | * |
| 562 | * Write a 16 bit word to the EEPROM using the hostif. |
| 563 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 564 | static s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 565 | { |
| 566 | s32 status = 0; |
| 567 | |
| 568 | if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) { |
| 569 | status = ixgbe_write_ee_hostif_data_X550(hw, offset, data); |
| 570 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
| 571 | } else { |
| 572 | hw_dbg(hw, "write ee hostif failed to get semaphore"); |
| 573 | status = IXGBE_ERR_SWFW_SYNC; |
| 574 | } |
| 575 | |
| 576 | return status; |
| 577 | } |
| 578 | |
| 579 | /** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device |
| 580 | * @hw: pointer to hardware structure |
| 581 | * |
| 582 | * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash. |
| 583 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 584 | static s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 585 | { |
| 586 | s32 status = 0; |
| 587 | union ixgbe_hic_hdr2 buffer; |
| 588 | |
| 589 | buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD; |
| 590 | buffer.req.buf_lenh = 0; |
| 591 | buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN; |
| 592 | buffer.req.checksum = FW_DEFAULT_CHECKSUM; |
| 593 | |
| 594 | status = ixgbe_host_interface_command(hw, (u32 *)&buffer, |
| 595 | sizeof(buffer), |
| 596 | IXGBE_HI_COMMAND_TIMEOUT, false); |
| 597 | return status; |
| 598 | } |
| 599 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 600 | /** ixgbe_disable_rx_x550 - Disable RX unit |
| 601 | * |
| 602 | * Enables the Rx DMA unit for x550 |
| 603 | **/ |
| 604 | static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw) |
| 605 | { |
| 606 | u32 rxctrl, pfdtxgswc; |
| 607 | s32 status; |
| 608 | struct ixgbe_hic_disable_rxen fw_cmd; |
| 609 | |
| 610 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 611 | if (rxctrl & IXGBE_RXCTRL_RXEN) { |
| 612 | pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC); |
| 613 | if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) { |
| 614 | pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN; |
| 615 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc); |
| 616 | hw->mac.set_lben = true; |
| 617 | } else { |
| 618 | hw->mac.set_lben = false; |
| 619 | } |
| 620 | |
| 621 | fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD; |
| 622 | fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN; |
| 623 | fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM; |
| 624 | fw_cmd.port_number = (u8)hw->bus.lan_id; |
| 625 | |
| 626 | status = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd, |
| 627 | sizeof(struct ixgbe_hic_disable_rxen), |
| 628 | IXGBE_HI_COMMAND_TIMEOUT, true); |
| 629 | |
| 630 | /* If we fail - disable RX using register write */ |
| 631 | if (status) { |
| 632 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 633 | if (rxctrl & IXGBE_RXCTRL_RXEN) { |
| 634 | rxctrl &= ~IXGBE_RXCTRL_RXEN; |
| 635 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl); |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 641 | /** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash |
| 642 | * @hw: pointer to hardware structure |
| 643 | * |
| 644 | * After writing EEPROM to shadow RAM using EEWR register, software calculates |
| 645 | * checksum and updates the EEPROM and instructs the hardware to update |
| 646 | * the flash. |
| 647 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 648 | static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 649 | { |
| 650 | s32 status; |
| 651 | u16 checksum = 0; |
| 652 | |
| 653 | /* Read the first word from the EEPROM. If this times out or fails, do |
| 654 | * not continue or we could be in for a very long wait while every |
| 655 | * EEPROM read fails |
| 656 | */ |
| 657 | status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum); |
| 658 | if (status) { |
| 659 | hw_dbg(hw, "EEPROM read failed\n"); |
| 660 | return status; |
| 661 | } |
| 662 | |
| 663 | status = ixgbe_calc_eeprom_checksum_X550(hw); |
| 664 | if (status < 0) |
| 665 | return status; |
| 666 | |
| 667 | checksum = (u16)(status & 0xffff); |
| 668 | |
| 669 | status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM, |
| 670 | checksum); |
| 671 | if (status) |
| 672 | return status; |
| 673 | |
| 674 | status = ixgbe_update_flash_X550(hw); |
| 675 | |
| 676 | return status; |
| 677 | } |
| 678 | |
| 679 | /** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif |
| 680 | * @hw: pointer to hardware structure |
| 681 | * @offset: offset of word in the EEPROM to write |
| 682 | * @words: number of words |
| 683 | * @data: word(s) write to the EEPROM |
| 684 | * |
| 685 | * |
| 686 | * Write a 16 bit word(s) to the EEPROM using the hostif. |
| 687 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 688 | static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw, |
| 689 | u16 offset, u16 words, |
| 690 | u16 *data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 691 | { |
| 692 | s32 status = 0; |
| 693 | u32 i = 0; |
| 694 | |
| 695 | /* Take semaphore for the entire operation. */ |
| 696 | status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
| 697 | if (status) { |
| 698 | hw_dbg(hw, "EEPROM write buffer - semaphore failed\n"); |
| 699 | return status; |
| 700 | } |
| 701 | |
| 702 | for (i = 0; i < words; i++) { |
| 703 | status = ixgbe_write_ee_hostif_data_X550(hw, offset + i, |
| 704 | data[i]); |
| 705 | if (status) { |
| 706 | hw_dbg(hw, "Eeprom buffered write failed\n"); |
| 707 | break; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); |
| 712 | |
| 713 | return status; |
| 714 | } |
| 715 | |
| 716 | /** ixgbe_init_mac_link_ops_X550em - init mac link function pointers |
| 717 | * @hw: pointer to hardware structure |
| 718 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 719 | static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 720 | { |
| 721 | struct ixgbe_mac_info *mac = &hw->mac; |
| 722 | |
| 723 | /* CS4227 does not support autoneg, so disable the laser control |
| 724 | * functions for SFP+ fiber |
| 725 | */ |
| 726 | if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) { |
| 727 | mac->ops.disable_tx_laser = NULL; |
| 728 | mac->ops.enable_tx_laser = NULL; |
| 729 | mac->ops.flap_tx_laser = NULL; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /** ixgbe_setup_sfp_modules_X550em - Setup SFP module |
| 734 | * @hw: pointer to hardware structure |
| 735 | */ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 736 | static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 737 | { |
| 738 | bool setup_linear; |
| 739 | u16 reg_slice, edc_mode; |
| 740 | s32 ret_val; |
| 741 | |
| 742 | switch (hw->phy.sfp_type) { |
| 743 | case ixgbe_sfp_type_unknown: |
| 744 | return 0; |
| 745 | case ixgbe_sfp_type_not_present: |
| 746 | return IXGBE_ERR_SFP_NOT_PRESENT; |
| 747 | case ixgbe_sfp_type_da_cu_core0: |
| 748 | case ixgbe_sfp_type_da_cu_core1: |
| 749 | setup_linear = true; |
| 750 | break; |
| 751 | case ixgbe_sfp_type_srlr_core0: |
| 752 | case ixgbe_sfp_type_srlr_core1: |
| 753 | case ixgbe_sfp_type_da_act_lmt_core0: |
| 754 | case ixgbe_sfp_type_da_act_lmt_core1: |
| 755 | case ixgbe_sfp_type_1g_sx_core0: |
| 756 | case ixgbe_sfp_type_1g_sx_core1: |
| 757 | setup_linear = false; |
| 758 | break; |
| 759 | default: |
| 760 | return IXGBE_ERR_SFP_NOT_SUPPORTED; |
| 761 | } |
| 762 | |
| 763 | ixgbe_init_mac_link_ops_X550em(hw); |
| 764 | hw->phy.ops.reset = NULL; |
| 765 | |
| 766 | /* The CS4227 slice address is the base address + the port-pair reg |
| 767 | * offset. I.e. Slice 0 = 0x12B0 and slice 1 = 0x22B0. |
| 768 | */ |
| 769 | reg_slice = IXGBE_CS4227_SPARE24_LSB + (hw->bus.lan_id << 12); |
| 770 | |
| 771 | if (setup_linear) |
| 772 | edc_mode = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1; |
| 773 | else |
| 774 | edc_mode = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1; |
| 775 | |
| 776 | /* Configure CS4227 for connection type. */ |
| 777 | ret_val = hw->phy.ops.write_i2c_combined(hw, IXGBE_CS4227, reg_slice, |
| 778 | edc_mode); |
| 779 | |
| 780 | if (ret_val) |
| 781 | ret_val = hw->phy.ops.write_i2c_combined(hw, 0x80, reg_slice, |
| 782 | edc_mode); |
| 783 | |
| 784 | return ret_val; |
| 785 | } |
| 786 | |
| 787 | /** ixgbe_get_link_capabilities_x550em - Determines link capabilities |
| 788 | * @hw: pointer to hardware structure |
| 789 | * @speed: pointer to link speed |
| 790 | * @autoneg: true when autoneg or autotry is enabled |
| 791 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 792 | static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw, |
| 793 | ixgbe_link_speed *speed, |
| 794 | bool *autoneg) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 795 | { |
| 796 | /* SFP */ |
| 797 | if (hw->phy.media_type == ixgbe_media_type_fiber) { |
| 798 | /* CS4227 SFP must not enable auto-negotiation */ |
| 799 | *autoneg = false; |
| 800 | |
| 801 | if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 || |
| 802 | hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) { |
| 803 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* Link capabilities are based on SFP */ |
| 808 | if (hw->phy.multispeed_fiber) |
| 809 | *speed = IXGBE_LINK_SPEED_10GB_FULL | |
| 810 | IXGBE_LINK_SPEED_1GB_FULL; |
| 811 | else |
| 812 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 813 | } else { |
| 814 | *speed = IXGBE_LINK_SPEED_10GB_FULL | |
| 815 | IXGBE_LINK_SPEED_1GB_FULL; |
| 816 | *autoneg = true; |
| 817 | } |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | /** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the |
| 822 | * IOSF device |
| 823 | * |
| 824 | * @hw: pointer to hardware structure |
| 825 | * @reg_addr: 32 bit PHY register to write |
| 826 | * @device_type: 3 bit device type |
| 827 | * @data: Data to write to the register |
| 828 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 829 | static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr, |
| 830 | u32 device_type, u32 data) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 831 | { |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 832 | u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM; |
| 833 | u32 command, error; |
| 834 | s32 ret; |
| 835 | |
| 836 | ret = hw->mac.ops.acquire_swfw_sync(hw, gssr); |
| 837 | if (ret) |
| 838 | return ret; |
| 839 | |
| 840 | ret = ixgbe_iosf_wait(hw, NULL); |
| 841 | if (ret) |
| 842 | goto out; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 843 | |
| 844 | command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) | |
| 845 | (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT)); |
| 846 | |
| 847 | /* Write IOSF control register */ |
| 848 | IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command); |
| 849 | |
| 850 | /* Write IOSF data register */ |
| 851 | IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data); |
| 852 | |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 853 | ret = ixgbe_iosf_wait(hw, &command); |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 854 | |
| 855 | if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) { |
| 856 | error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >> |
| 857 | IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT; |
| 858 | hw_dbg(hw, "Failed to write, error %x\n", error); |
| 859 | return IXGBE_ERR_PHY; |
| 860 | } |
| 861 | |
Mark Rustad | ae14a1d | 2015-04-10 10:36:26 -0700 | [diff] [blame] | 862 | out: |
| 863 | hw->mac.ops.release_swfw_sync(hw, gssr); |
| 864 | return ret; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | /** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode. |
| 868 | * @hw: pointer to hardware structure |
| 869 | * @speed: the link speed to force |
| 870 | * |
| 871 | * Configures the integrated KR PHY to use iXFI mode. Used to connect an |
| 872 | * internal and external PHY at a specific speed, without autonegotiation. |
| 873 | **/ |
| 874 | static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed) |
| 875 | { |
| 876 | s32 status; |
| 877 | u32 reg_val; |
| 878 | |
| 879 | /* Disable AN and force speed to 10G Serial. */ |
| 880 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 881 | IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id), |
| 882 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 883 | if (status) |
| 884 | return status; |
| 885 | |
| 886 | reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE; |
| 887 | reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK; |
| 888 | |
| 889 | /* Select forced link speed for internal PHY. */ |
| 890 | switch (*speed) { |
| 891 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 892 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G; |
| 893 | break; |
| 894 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 895 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G; |
| 896 | break; |
| 897 | default: |
| 898 | /* Other link speeds are not supported by internal KR PHY. */ |
| 899 | return IXGBE_ERR_LINK_SETUP; |
| 900 | } |
| 901 | |
| 902 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 903 | IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id), |
| 904 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 905 | if (status) |
| 906 | return status; |
| 907 | |
| 908 | /* Disable training protocol FSM. */ |
| 909 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 910 | IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id), |
| 911 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 912 | if (status) |
| 913 | return status; |
| 914 | |
| 915 | reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL; |
| 916 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 917 | IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id), |
| 918 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 919 | if (status) |
| 920 | return status; |
| 921 | |
| 922 | /* Disable Flex from training TXFFE. */ |
| 923 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 924 | IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id), |
| 925 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 926 | if (status) |
| 927 | return status; |
| 928 | |
| 929 | reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN; |
| 930 | reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN; |
| 931 | reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN; |
| 932 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 933 | IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id), |
| 934 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 935 | if (status) |
| 936 | return status; |
| 937 | |
| 938 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 939 | IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id), |
| 940 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 941 | if (status) |
| 942 | return status; |
| 943 | |
| 944 | reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN; |
| 945 | reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN; |
| 946 | reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN; |
| 947 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 948 | IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id), |
| 949 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 950 | if (status) |
| 951 | return status; |
| 952 | |
| 953 | /* Enable override for coefficients. */ |
| 954 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 955 | IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id), |
| 956 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 957 | if (status) |
| 958 | return status; |
| 959 | |
| 960 | reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN; |
| 961 | reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN; |
| 962 | reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN; |
| 963 | reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN; |
| 964 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 965 | IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id), |
| 966 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 967 | if (status) |
| 968 | return status; |
| 969 | |
| 970 | /* Toggle port SW reset by AN reset. */ |
| 971 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 972 | IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id), |
| 973 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 974 | if (status) |
| 975 | return status; |
| 976 | |
| 977 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART; |
| 978 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 979 | IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id), |
| 980 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 981 | |
| 982 | return status; |
| 983 | } |
| 984 | |
| 985 | /** ixgbe_setup_kx4_x550em - Configure the KX4 PHY. |
| 986 | * @hw: pointer to hardware structure |
| 987 | * |
| 988 | * Configures the integrated KX4 PHY. |
| 989 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 990 | static s32 ixgbe_setup_kx4_x550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 991 | { |
| 992 | s32 status; |
| 993 | u32 reg_val; |
| 994 | |
| 995 | status = ixgbe_read_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1, |
| 996 | IXGBE_SB_IOSF_TARGET_KX4_PCS0 + |
| 997 | hw->bus.lan_id, ®_val); |
| 998 | if (status) |
| 999 | return status; |
| 1000 | |
| 1001 | reg_val &= ~(IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4 | |
| 1002 | IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX); |
| 1003 | |
| 1004 | reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_ENABLE; |
| 1005 | |
| 1006 | /* Advertise 10G support. */ |
| 1007 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) |
| 1008 | reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4; |
| 1009 | |
| 1010 | /* Advertise 1G support. */ |
| 1011 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) |
| 1012 | reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX; |
| 1013 | |
| 1014 | /* Restart auto-negotiation. */ |
| 1015 | reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_RESTART; |
| 1016 | status = ixgbe_write_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1, |
| 1017 | IXGBE_SB_IOSF_TARGET_KX4_PCS0 + |
| 1018 | hw->bus.lan_id, reg_val); |
| 1019 | |
| 1020 | return status; |
| 1021 | } |
| 1022 | |
| 1023 | /** ixgbe_setup_kr_x550em - Configure the KR PHY. |
| 1024 | * @hw: pointer to hardware structure |
| 1025 | * |
| 1026 | * Configures the integrated KR PHY. |
| 1027 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 1028 | static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1029 | { |
| 1030 | s32 status; |
| 1031 | u32 reg_val; |
| 1032 | |
| 1033 | status = ixgbe_read_iosf_sb_reg_x550(hw, |
| 1034 | IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id), |
| 1035 | IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val); |
| 1036 | if (status) |
| 1037 | return status; |
| 1038 | |
| 1039 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE; |
| 1040 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_FEC_REQ; |
| 1041 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_FEC; |
| 1042 | reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR | |
| 1043 | IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX); |
| 1044 | |
| 1045 | /* Advertise 10G support. */ |
| 1046 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) |
| 1047 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR; |
| 1048 | |
| 1049 | /* Advertise 1G support. */ |
| 1050 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) |
| 1051 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX; |
| 1052 | |
| 1053 | /* Restart auto-negotiation. */ |
| 1054 | reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART; |
| 1055 | status = ixgbe_write_iosf_sb_reg_x550(hw, |
| 1056 | IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id), |
| 1057 | IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val); |
| 1058 | |
| 1059 | return status; |
| 1060 | } |
| 1061 | |
| 1062 | /** ixgbe_setup_internal_phy_x550em - Configure integrated KR PHY |
| 1063 | * @hw: point to hardware structure |
| 1064 | * |
| 1065 | * Configures the integrated KR PHY to talk to the external PHY. The base |
| 1066 | * driver will call this function when it gets notification via interrupt from |
| 1067 | * the external PHY. This function forces the internal PHY into iXFI mode at |
| 1068 | * the correct speed. |
| 1069 | * |
| 1070 | * A return of a non-zero value indicates an error, and the base driver should |
| 1071 | * not report link up. |
| 1072 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 1073 | static s32 ixgbe_setup_internal_phy_x550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1074 | { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 1075 | s32 status; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1076 | u16 lasi, autoneg_status, speed; |
| 1077 | ixgbe_link_speed force_speed; |
| 1078 | |
| 1079 | /* Verify that the external link status has changed */ |
| 1080 | status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_XENPAK_LASI_STATUS, |
| 1081 | IXGBE_MDIO_PMA_PMD_DEV_TYPE, &lasi); |
| 1082 | if (status) |
| 1083 | return status; |
| 1084 | |
| 1085 | /* If there was no change in link status, we can just exit */ |
| 1086 | if (!(lasi & IXGBE_XENPAK_LASI_LINK_STATUS_ALARM)) |
| 1087 | return 0; |
| 1088 | |
| 1089 | /* we read this twice back to back to indicate current status */ |
| 1090 | status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS, |
| 1091 | IXGBE_MDIO_AUTO_NEG_DEV_TYPE, |
| 1092 | &autoneg_status); |
| 1093 | if (status) |
| 1094 | return status; |
| 1095 | |
| 1096 | status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS, |
| 1097 | IXGBE_MDIO_AUTO_NEG_DEV_TYPE, |
| 1098 | &autoneg_status); |
| 1099 | if (status) |
| 1100 | return status; |
| 1101 | |
| 1102 | /* If link is not up return an error indicating treat link as down */ |
| 1103 | if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS)) |
| 1104 | return IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 1105 | |
| 1106 | status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT, |
| 1107 | IXGBE_MDIO_AUTO_NEG_DEV_TYPE, |
| 1108 | &speed); |
| 1109 | |
| 1110 | /* clear everything but the speed and duplex bits */ |
| 1111 | speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK; |
| 1112 | |
| 1113 | switch (speed) { |
| 1114 | case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL: |
| 1115 | force_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 1116 | break; |
| 1117 | case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL: |
| 1118 | force_speed = IXGBE_LINK_SPEED_1GB_FULL; |
| 1119 | break; |
| 1120 | default: |
| 1121 | /* Internal PHY does not support anything else */ |
| 1122 | return IXGBE_ERR_INVALID_LINK_SETTINGS; |
| 1123 | } |
| 1124 | |
| 1125 | return ixgbe_setup_ixfi_x550em(hw, &force_speed); |
| 1126 | } |
| 1127 | |
| 1128 | /** ixgbe_init_phy_ops_X550em - PHY/SFP specific init |
| 1129 | * @hw: pointer to hardware structure |
| 1130 | * |
| 1131 | * Initialize any function pointers that were not able to be |
| 1132 | * set during init_shared_code because the PHY/SFP type was |
| 1133 | * not known. Perform the SFP init if necessary. |
| 1134 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 1135 | static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1136 | { |
| 1137 | struct ixgbe_phy_info *phy = &hw->phy; |
| 1138 | s32 ret_val; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1139 | |
| 1140 | if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1141 | phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM; |
Don Skidmore | ab5fe0c | 2015-06-09 16:18:56 -0700 | [diff] [blame^] | 1142 | ixgbe_setup_mux_ctl(hw); |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /* Identify the PHY or SFP module */ |
| 1146 | ret_val = phy->ops.identify(hw); |
| 1147 | |
| 1148 | /* Setup function pointers based on detected SFP module and speeds */ |
| 1149 | ixgbe_init_mac_link_ops_X550em(hw); |
| 1150 | if (phy->sfp_type != ixgbe_sfp_type_unknown) |
| 1151 | phy->ops.reset = NULL; |
| 1152 | |
| 1153 | /* Set functions pointers based on phy type */ |
| 1154 | switch (hw->phy.type) { |
| 1155 | case ixgbe_phy_x550em_kx4: |
| 1156 | phy->ops.setup_link = ixgbe_setup_kx4_x550em; |
| 1157 | phy->ops.read_reg = ixgbe_read_phy_reg_x550em; |
| 1158 | phy->ops.write_reg = ixgbe_write_phy_reg_x550em; |
| 1159 | break; |
| 1160 | case ixgbe_phy_x550em_kr: |
| 1161 | phy->ops.setup_link = ixgbe_setup_kr_x550em; |
| 1162 | phy->ops.read_reg = ixgbe_read_phy_reg_x550em; |
| 1163 | phy->ops.write_reg = ixgbe_write_phy_reg_x550em; |
| 1164 | break; |
| 1165 | case ixgbe_phy_x550em_ext_t: |
| 1166 | phy->ops.setup_internal_link = ixgbe_setup_internal_phy_x550em; |
| 1167 | break; |
| 1168 | default: |
| 1169 | break; |
| 1170 | } |
| 1171 | return ret_val; |
| 1172 | } |
| 1173 | |
| 1174 | /** ixgbe_get_media_type_X550em - Get media type |
| 1175 | * @hw: pointer to hardware structure |
| 1176 | * |
| 1177 | * Returns the media type (fiber, copper, backplane) |
| 1178 | * |
| 1179 | */ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 1180 | static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1181 | { |
| 1182 | enum ixgbe_media_type media_type; |
| 1183 | |
| 1184 | /* Detect if there is a copper PHY attached. */ |
| 1185 | switch (hw->device_id) { |
| 1186 | case IXGBE_DEV_ID_X550EM_X_KR: |
| 1187 | case IXGBE_DEV_ID_X550EM_X_KX4: |
| 1188 | media_type = ixgbe_media_type_backplane; |
| 1189 | break; |
| 1190 | case IXGBE_DEV_ID_X550EM_X_SFP: |
| 1191 | media_type = ixgbe_media_type_fiber; |
| 1192 | break; |
| 1193 | case IXGBE_DEV_ID_X550EM_X_1G_T: |
| 1194 | case IXGBE_DEV_ID_X550EM_X_10G_T: |
| 1195 | media_type = ixgbe_media_type_copper; |
| 1196 | break; |
| 1197 | default: |
| 1198 | media_type = ixgbe_media_type_unknown; |
| 1199 | break; |
| 1200 | } |
| 1201 | return media_type; |
| 1202 | } |
| 1203 | |
| 1204 | /** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY. |
| 1205 | ** @hw: pointer to hardware structure |
| 1206 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 1207 | static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1208 | { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 1209 | s32 status; |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1210 | u16 reg; |
| 1211 | u32 retries = 2; |
| 1212 | |
| 1213 | do { |
| 1214 | /* decrement retries counter and exit if we hit 0 */ |
| 1215 | if (retries < 1) { |
| 1216 | hw_dbg(hw, "External PHY not yet finished resetting."); |
| 1217 | return IXGBE_ERR_PHY; |
| 1218 | } |
| 1219 | retries--; |
| 1220 | |
| 1221 | status = hw->phy.ops.read_reg(hw, |
| 1222 | IXGBE_MDIO_TX_VENDOR_ALARMS_3, |
| 1223 | IXGBE_MDIO_PMA_PMD_DEV_TYPE, |
| 1224 | ®); |
| 1225 | if (status) |
| 1226 | return status; |
| 1227 | |
| 1228 | /* Verify PHY FW reset has completed */ |
| 1229 | } while ((reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) != 1); |
| 1230 | |
| 1231 | /* Set port to low power mode */ |
| 1232 | status = hw->phy.ops.read_reg(hw, |
| 1233 | IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL, |
| 1234 | IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, |
| 1235 | ®); |
| 1236 | if (status) |
| 1237 | return status; |
| 1238 | |
| 1239 | /* Enable the transmitter */ |
| 1240 | status = hw->phy.ops.read_reg(hw, |
| 1241 | IXGBE_MDIO_PMD_STD_TX_DISABLE_CNTR, |
| 1242 | IXGBE_MDIO_PMA_PMD_DEV_TYPE, |
| 1243 | ®); |
| 1244 | if (status) |
| 1245 | return status; |
| 1246 | |
| 1247 | reg &= ~IXGBE_MDIO_PMD_GLOBAL_TX_DISABLE; |
| 1248 | |
| 1249 | status = hw->phy.ops.write_reg(hw, |
| 1250 | IXGBE_MDIO_PMD_STD_TX_DISABLE_CNTR, |
| 1251 | IXGBE_MDIO_PMA_PMD_DEV_TYPE, |
| 1252 | reg); |
| 1253 | if (status) |
| 1254 | return status; |
| 1255 | |
| 1256 | /* Un-stall the PHY FW */ |
| 1257 | status = hw->phy.ops.read_reg(hw, |
| 1258 | IXGBE_MDIO_GLOBAL_RES_PR_10, |
| 1259 | IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, |
| 1260 | ®); |
| 1261 | if (status) |
| 1262 | return status; |
| 1263 | |
| 1264 | reg &= ~IXGBE_MDIO_POWER_UP_STALL; |
| 1265 | |
| 1266 | status = hw->phy.ops.write_reg(hw, |
| 1267 | IXGBE_MDIO_GLOBAL_RES_PR_10, |
| 1268 | IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, |
| 1269 | reg); |
| 1270 | return status; |
| 1271 | } |
| 1272 | |
| 1273 | /** ixgbe_reset_hw_X550em - Perform hardware reset |
| 1274 | ** @hw: pointer to hardware structure |
| 1275 | ** |
| 1276 | ** Resets the hardware by resetting the transmit and receive units, masks |
| 1277 | ** and clears all interrupts, perform a PHY reset, and perform a link (MAC) |
| 1278 | ** reset. |
| 1279 | **/ |
Don Skidmore | 7ddbde3 | 2014-12-06 05:59:21 +0000 | [diff] [blame] | 1280 | static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw) |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1281 | { |
| 1282 | ixgbe_link_speed link_speed; |
| 1283 | s32 status; |
| 1284 | u32 ctrl = 0; |
| 1285 | u32 i; |
| 1286 | bool link_up = false; |
| 1287 | |
| 1288 | /* Call adapter stop to disable Tx/Rx and clear interrupts */ |
| 1289 | status = hw->mac.ops.stop_adapter(hw); |
| 1290 | if (status) |
| 1291 | return status; |
| 1292 | |
| 1293 | /* flush pending Tx transactions */ |
| 1294 | ixgbe_clear_tx_pending(hw); |
| 1295 | |
| 1296 | /* PHY ops must be identified and initialized prior to reset */ |
| 1297 | |
| 1298 | /* Identify PHY and related function pointers */ |
| 1299 | status = hw->phy.ops.init(hw); |
| 1300 | |
| 1301 | /* start the external PHY */ |
| 1302 | if (hw->phy.type == ixgbe_phy_x550em_ext_t) { |
| 1303 | status = ixgbe_init_ext_t_x550em(hw); |
| 1304 | if (status) |
| 1305 | return status; |
| 1306 | } |
| 1307 | |
| 1308 | /* Setup SFP module if there is one present. */ |
| 1309 | if (hw->phy.sfp_setup_needed) { |
| 1310 | status = hw->mac.ops.setup_sfp(hw); |
| 1311 | hw->phy.sfp_setup_needed = false; |
| 1312 | } |
| 1313 | |
| 1314 | /* Reset PHY */ |
| 1315 | if (!hw->phy.reset_disable && hw->phy.ops.reset) |
| 1316 | hw->phy.ops.reset(hw); |
| 1317 | |
| 1318 | mac_reset_top: |
| 1319 | /* Issue global reset to the MAC. Needs to be SW reset if link is up. |
| 1320 | * If link reset is used when link is up, it might reset the PHY when |
| 1321 | * mng is using it. If link is down or the flag to force full link |
| 1322 | * reset is set, then perform link reset. |
| 1323 | */ |
| 1324 | ctrl = IXGBE_CTRL_LNK_RST; |
| 1325 | |
| 1326 | if (!hw->force_full_reset) { |
| 1327 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
| 1328 | if (link_up) |
| 1329 | ctrl = IXGBE_CTRL_RST; |
| 1330 | } |
| 1331 | |
| 1332 | ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 1333 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 1334 | IXGBE_WRITE_FLUSH(hw); |
| 1335 | |
| 1336 | /* Poll for reset bit to self-clear meaning reset is complete */ |
| 1337 | for (i = 0; i < 10; i++) { |
| 1338 | udelay(1); |
| 1339 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 1340 | if (!(ctrl & IXGBE_CTRL_RST_MASK)) |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | if (ctrl & IXGBE_CTRL_RST_MASK) { |
| 1345 | status = IXGBE_ERR_RESET_FAILED; |
| 1346 | hw_dbg(hw, "Reset polling failed to complete.\n"); |
| 1347 | } |
| 1348 | |
| 1349 | msleep(50); |
| 1350 | |
| 1351 | /* Double resets are required for recovery from certain error |
| 1352 | * clear the multicast table. Also reset num_rar_entries to 128, |
| 1353 | * since we modify this value when programming the SAN MAC address. |
| 1354 | */ |
| 1355 | if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) { |
| 1356 | hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; |
| 1357 | goto mac_reset_top; |
| 1358 | } |
| 1359 | |
| 1360 | /* Store the permanent mac address */ |
| 1361 | hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); |
| 1362 | |
| 1363 | /* Store MAC address from RAR0, clear receive address registers, and |
| 1364 | * clear the multicast table. Also reset num_rar_entries to 128, |
| 1365 | * since we modify this value when programming the SAN MAC address. |
| 1366 | */ |
| 1367 | hw->mac.num_rar_entries = 128; |
| 1368 | hw->mac.ops.init_rx_addrs(hw); |
| 1369 | |
Don Skidmore | ab5fe0c | 2015-06-09 16:18:56 -0700 | [diff] [blame^] | 1370 | if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) |
| 1371 | ixgbe_setup_mux_ctl(hw); |
| 1372 | |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1373 | return status; |
| 1374 | } |
| 1375 | |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 1376 | /** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype |
| 1377 | * anti-spoofing |
| 1378 | * @hw: pointer to hardware structure |
| 1379 | * @enable: enable or disable switch for Ethertype anti-spoofing |
| 1380 | * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing |
| 1381 | **/ |
Don Skidmore | bc035fc | 2015-03-13 14:03:25 -0700 | [diff] [blame] | 1382 | static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw, |
| 1383 | bool enable, int vf) |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 1384 | { |
| 1385 | int vf_target_reg = vf >> 3; |
| 1386 | int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT; |
| 1387 | u32 pfvfspoof; |
| 1388 | |
| 1389 | pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); |
| 1390 | if (enable) |
| 1391 | pfvfspoof |= (1 << vf_target_shift); |
| 1392 | else |
| 1393 | pfvfspoof &= ~(1 << vf_target_shift); |
| 1394 | |
| 1395 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof); |
| 1396 | } |
| 1397 | |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 1398 | /** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning |
| 1399 | * @hw: pointer to hardware structure |
| 1400 | * @enable: enable or disable source address pruning |
| 1401 | * @pool: Rx pool to set source address pruning for |
| 1402 | **/ |
| 1403 | static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw, |
| 1404 | bool enable, |
| 1405 | unsigned int pool) |
| 1406 | { |
| 1407 | u64 pfflp; |
| 1408 | |
| 1409 | /* max rx pool is 63 */ |
| 1410 | if (pool > 63) |
| 1411 | return; |
| 1412 | |
| 1413 | pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL); |
| 1414 | pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32; |
| 1415 | |
| 1416 | if (enable) |
| 1417 | pfflp |= (1ULL << pool); |
| 1418 | else |
| 1419 | pfflp &= ~(1ULL << pool); |
| 1420 | |
| 1421 | IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp); |
| 1422 | IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32)); |
| 1423 | } |
| 1424 | |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1425 | #define X550_COMMON_MAC \ |
| 1426 | .init_hw = &ixgbe_init_hw_generic, \ |
| 1427 | .start_hw = &ixgbe_start_hw_X540, \ |
| 1428 | .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \ |
| 1429 | .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \ |
| 1430 | .get_mac_addr = &ixgbe_get_mac_addr_generic, \ |
| 1431 | .get_device_caps = &ixgbe_get_device_caps_generic, \ |
| 1432 | .stop_adapter = &ixgbe_stop_adapter_generic, \ |
| 1433 | .get_bus_info = &ixgbe_get_bus_info_generic, \ |
| 1434 | .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \ |
| 1435 | .read_analog_reg8 = NULL, \ |
| 1436 | .write_analog_reg8 = NULL, \ |
| 1437 | .set_rxpba = &ixgbe_set_rxpba_generic, \ |
| 1438 | .check_link = &ixgbe_check_mac_link_generic, \ |
| 1439 | .led_on = &ixgbe_led_on_generic, \ |
| 1440 | .led_off = &ixgbe_led_off_generic, \ |
| 1441 | .blink_led_start = &ixgbe_blink_led_start_X540, \ |
| 1442 | .blink_led_stop = &ixgbe_blink_led_stop_X540, \ |
| 1443 | .set_rar = &ixgbe_set_rar_generic, \ |
| 1444 | .clear_rar = &ixgbe_clear_rar_generic, \ |
| 1445 | .set_vmdq = &ixgbe_set_vmdq_generic, \ |
| 1446 | .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \ |
| 1447 | .clear_vmdq = &ixgbe_clear_vmdq_generic, \ |
| 1448 | .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \ |
| 1449 | .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \ |
| 1450 | .enable_mc = &ixgbe_enable_mc_generic, \ |
| 1451 | .disable_mc = &ixgbe_disable_mc_generic, \ |
| 1452 | .clear_vfta = &ixgbe_clear_vfta_generic, \ |
| 1453 | .set_vfta = &ixgbe_set_vfta_generic, \ |
| 1454 | .fc_enable = &ixgbe_fc_enable_generic, \ |
| 1455 | .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, \ |
| 1456 | .init_uta_tables = &ixgbe_init_uta_tables_generic, \ |
| 1457 | .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \ |
| 1458 | .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \ |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 1459 | .set_source_address_pruning = \ |
| 1460 | &ixgbe_set_source_address_pruning_X550, \ |
Don Skidmore | 5b7f000 | 2015-01-28 07:03:38 +0000 | [diff] [blame] | 1461 | .set_ethertype_anti_spoofing = \ |
| 1462 | &ixgbe_set_ethertype_anti_spoofing_X550, \ |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1463 | .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540, \ |
| 1464 | .release_swfw_sync = &ixgbe_release_swfw_sync_X540, \ |
| 1465 | .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \ |
| 1466 | .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \ |
| 1467 | .get_thermal_sensor_data = NULL, \ |
| 1468 | .init_thermal_sensor_thresh = NULL, \ |
| 1469 | .prot_autoc_read = &prot_autoc_read_generic, \ |
| 1470 | .prot_autoc_write = &prot_autoc_write_generic, \ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 1471 | .enable_rx = &ixgbe_enable_rx_generic, \ |
| 1472 | .disable_rx = &ixgbe_disable_rx_x550, \ |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1473 | |
| 1474 | static struct ixgbe_mac_operations mac_ops_X550 = { |
| 1475 | X550_COMMON_MAC |
| 1476 | .reset_hw = &ixgbe_reset_hw_X540, |
| 1477 | .get_media_type = &ixgbe_get_media_type_X540, |
| 1478 | .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic, |
| 1479 | .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic, |
| 1480 | .setup_link = &ixgbe_setup_mac_link_X540, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1481 | .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic, |
| 1482 | .setup_sfp = NULL, |
| 1483 | }; |
| 1484 | |
| 1485 | static struct ixgbe_mac_operations mac_ops_X550EM_x = { |
| 1486 | X550_COMMON_MAC |
| 1487 | .reset_hw = &ixgbe_reset_hw_X550em, |
| 1488 | .get_media_type = &ixgbe_get_media_type_X550em, |
| 1489 | .get_san_mac_addr = NULL, |
| 1490 | .get_wwn_prefix = NULL, |
| 1491 | .setup_link = NULL, /* defined later */ |
| 1492 | .get_link_capabilities = &ixgbe_get_link_capabilities_X550em, |
| 1493 | .setup_sfp = ixgbe_setup_sfp_modules_X550em, |
| 1494 | |
| 1495 | }; |
| 1496 | |
| 1497 | #define X550_COMMON_EEP \ |
| 1498 | .read = &ixgbe_read_ee_hostif_X550, \ |
| 1499 | .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \ |
| 1500 | .write = &ixgbe_write_ee_hostif_X550, \ |
| 1501 | .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \ |
| 1502 | .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \ |
| 1503 | .update_checksum = &ixgbe_update_eeprom_checksum_X550, \ |
| 1504 | .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \ |
| 1505 | |
| 1506 | static struct ixgbe_eeprom_operations eeprom_ops_X550 = { |
| 1507 | X550_COMMON_EEP |
| 1508 | .init_params = &ixgbe_init_eeprom_params_X550, |
| 1509 | }; |
| 1510 | |
| 1511 | static struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = { |
| 1512 | X550_COMMON_EEP |
| 1513 | .init_params = &ixgbe_init_eeprom_params_X540, |
| 1514 | }; |
| 1515 | |
| 1516 | #define X550_COMMON_PHY \ |
| 1517 | .identify_sfp = &ixgbe_identify_module_generic, \ |
| 1518 | .reset = NULL, \ |
| 1519 | .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \ |
| 1520 | .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \ |
| 1521 | .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \ |
| 1522 | .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \ |
| 1523 | .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \ |
| 1524 | .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \ |
| 1525 | .check_overtemp = &ixgbe_tn_check_overtemp, \ |
| 1526 | .get_firmware_version = &ixgbe_get_phy_firmware_version_generic, |
| 1527 | |
| 1528 | static struct ixgbe_phy_operations phy_ops_X550 = { |
| 1529 | X550_COMMON_PHY |
| 1530 | .init = NULL, |
| 1531 | .identify = &ixgbe_identify_phy_generic, |
| 1532 | .read_reg = &ixgbe_read_phy_reg_generic, |
| 1533 | .write_reg = &ixgbe_write_phy_reg_generic, |
| 1534 | .setup_link = &ixgbe_setup_phy_link_generic, |
| 1535 | .read_i2c_combined = &ixgbe_read_i2c_combined_generic, |
| 1536 | .write_i2c_combined = &ixgbe_write_i2c_combined_generic, |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 1537 | .set_phy_power = &ixgbe_set_copper_phy_power, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1538 | }; |
| 1539 | |
| 1540 | static struct ixgbe_phy_operations phy_ops_X550EM_x = { |
| 1541 | X550_COMMON_PHY |
| 1542 | .init = &ixgbe_init_phy_ops_X550em, |
| 1543 | .identify = &ixgbe_identify_phy_x550em, |
| 1544 | .read_reg = NULL, /* defined later */ |
| 1545 | .write_reg = NULL, /* defined later */ |
| 1546 | .setup_link = NULL, /* defined later */ |
| 1547 | }; |
| 1548 | |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 1549 | static const u32 ixgbe_mvals_X550[IXGBE_MVALS_IDX_LIMIT] = { |
| 1550 | IXGBE_MVALS_INIT(X550) |
| 1551 | }; |
| 1552 | |
| 1553 | static const u32 ixgbe_mvals_X550EM_x[IXGBE_MVALS_IDX_LIMIT] = { |
| 1554 | IXGBE_MVALS_INIT(X550EM_x) |
| 1555 | }; |
| 1556 | |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1557 | struct ixgbe_info ixgbe_X550_info = { |
| 1558 | .mac = ixgbe_mac_X550, |
| 1559 | .get_invariants = &ixgbe_get_invariants_X540, |
| 1560 | .mac_ops = &mac_ops_X550, |
| 1561 | .eeprom_ops = &eeprom_ops_X550, |
| 1562 | .phy_ops = &phy_ops_X550, |
| 1563 | .mbx_ops = &mbx_ops_generic, |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 1564 | .mvals = ixgbe_mvals_X550, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1565 | }; |
| 1566 | |
| 1567 | struct ixgbe_info ixgbe_X550EM_x_info = { |
| 1568 | .mac = ixgbe_mac_X550EM_x, |
| 1569 | .get_invariants = &ixgbe_get_invariants_X540, |
| 1570 | .mac_ops = &mac_ops_X550EM_x, |
| 1571 | .eeprom_ops = &eeprom_ops_X550EM_x, |
| 1572 | .phy_ops = &phy_ops_X550EM_x, |
| 1573 | .mbx_ops = &mbx_ops_generic, |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 1574 | .mvals = ixgbe_mvals_X550EM_x, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 1575 | }; |