blob: 60f0bf779073bcbaff7b7afd2b1794593c884f4c [file] [log] [blame]
Don Skidmore6a14ee02014-12-05 03:59:50 +00001/*******************************************************************************
2 *
3 * Intel 10 Gigabit PCI Express Linux driver
Mark Rustad37689012016-01-07 10:13:03 -08004 * Copyright(c) 1999 - 2016 Intel Corporation.
Don Skidmore6a14ee02014-12-05 03:59:50 +00005 *
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
Mark Rustadd91e3a72015-09-28 14:37:47 -070029static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *, ixgbe_link_speed);
Mark Rustadafdc71e2016-01-25 16:32:10 -080030static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *);
Mark Rustadd91e3a72015-09-28 14:37:47 -070031
Don Skidmoreb5529ef2015-06-10 20:42:30 -040032static s32 ixgbe_get_invariants_X550_x(struct ixgbe_hw *hw)
33{
34 struct ixgbe_mac_info *mac = &hw->mac;
35 struct ixgbe_phy_info *phy = &hw->phy;
36
37 /* Start with X540 invariants, since so simular */
38 ixgbe_get_invariants_X540(hw);
39
40 if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
41 phy->ops.set_phy_power = NULL;
42
43 return 0;
44}
45
Don Skidmoreab5fe0c2015-06-09 16:18:56 -070046/** ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
47 * @hw: pointer to hardware structure
48 **/
49static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
50{
51 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
52
53 if (hw->bus.lan_id) {
54 esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
55 esdp |= IXGBE_ESDP_SDP1_DIR;
56 }
57 esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
58 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
59 IXGBE_WRITE_FLUSH(hw);
60}
61
Mark Rustad542b6ee2015-08-08 16:18:38 -070062/**
63 * ixgbe_read_cs4227 - Read CS4227 register
64 * @hw: pointer to hardware structure
65 * @reg: register number to write
66 * @value: pointer to receive value read
67 *
68 * Returns status code
69 */
70static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
71{
72 return hw->phy.ops.read_i2c_combined_unlocked(hw, IXGBE_CS4227, reg,
73 value);
74}
75
76/**
77 * ixgbe_write_cs4227 - Write CS4227 register
78 * @hw: pointer to hardware structure
79 * @reg: register number to write
80 * @value: value to write to register
81 *
82 * Returns status code
83 */
84static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
85{
86 return hw->phy.ops.write_i2c_combined_unlocked(hw, IXGBE_CS4227, reg,
87 value);
88}
89
90/**
Mark Rustad542b6ee2015-08-08 16:18:38 -070091 * ixgbe_read_pe - Read register from port expander
92 * @hw: pointer to hardware structure
93 * @reg: register number to read
94 * @value: pointer to receive read value
95 *
96 * Returns status code
97 */
98static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
99{
100 s32 status;
101
102 status = ixgbe_read_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE, value);
103 if (status)
104 hw_err(hw, "port expander access failed with %d\n", status);
105 return status;
106}
107
108/**
109 * ixgbe_write_pe - Write register to port expander
110 * @hw: pointer to hardware structure
111 * @reg: register number to write
112 * @value: value to write
113 *
114 * Returns status code
115 */
116static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
117{
118 s32 status;
119
120 status = ixgbe_write_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE,
121 value);
122 if (status)
123 hw_err(hw, "port expander access failed with %d\n", status);
124 return status;
125}
126
127/**
128 * ixgbe_reset_cs4227 - Reset CS4227 using port expander
129 * @hw: pointer to hardware structure
130 *
Mark Rustad8bf7a7b2015-08-26 14:10:22 -0700131 * This function assumes that the caller has acquired the proper semaphore.
Mark Rustad542b6ee2015-08-08 16:18:38 -0700132 * Returns error code
133 */
134static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
135{
136 s32 status;
137 u32 retry;
138 u16 value;
139 u8 reg;
140
141 /* Trigger hard reset. */
142 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
143 if (status)
144 return status;
145 reg |= IXGBE_PE_BIT1;
146 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
147 if (status)
148 return status;
149
150 status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, &reg);
151 if (status)
152 return status;
153 reg &= ~IXGBE_PE_BIT1;
154 status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
155 if (status)
156 return status;
157
158 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
159 if (status)
160 return status;
161 reg &= ~IXGBE_PE_BIT1;
162 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
163 if (status)
164 return status;
165
166 usleep_range(IXGBE_CS4227_RESET_HOLD, IXGBE_CS4227_RESET_HOLD + 100);
167
168 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
169 if (status)
170 return status;
171 reg |= IXGBE_PE_BIT1;
172 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
173 if (status)
174 return status;
175
176 /* Wait for the reset to complete. */
177 msleep(IXGBE_CS4227_RESET_DELAY);
178 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
179 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
180 &value);
181 if (!status && value == IXGBE_CS4227_EEPROM_LOAD_OK)
182 break;
183 msleep(IXGBE_CS4227_CHECK_DELAY);
184 }
185 if (retry == IXGBE_CS4227_RETRIES) {
186 hw_err(hw, "CS4227 reset did not complete\n");
187 return IXGBE_ERR_PHY;
188 }
189
190 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
191 if (status || !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
192 hw_err(hw, "CS4227 EEPROM did not load successfully\n");
193 return IXGBE_ERR_PHY;
194 }
195
196 return 0;
197}
198
199/**
200 * ixgbe_check_cs4227 - Check CS4227 and reset as needed
201 * @hw: pointer to hardware structure
202 */
203static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
204{
205 u32 swfw_mask = hw->phy.phy_semaphore_mask;
206 s32 status;
207 u16 value;
208 u8 retry;
209
210 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
211 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
212 if (status) {
213 hw_err(hw, "semaphore failed with %d\n", status);
214 msleep(IXGBE_CS4227_CHECK_DELAY);
215 continue;
216 }
217
218 /* Get status of reset flow. */
219 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
220 if (!status && value == IXGBE_CS4227_RESET_COMPLETE)
221 goto out;
222
223 if (status || value != IXGBE_CS4227_RESET_PENDING)
224 break;
225
226 /* Reset is pending. Wait and check again. */
227 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
228 msleep(IXGBE_CS4227_CHECK_DELAY);
229 }
Mark Rustad8bf7a7b2015-08-26 14:10:22 -0700230 /* If still pending, assume other instance failed. */
231 if (retry == IXGBE_CS4227_RETRIES) {
232 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
233 if (status) {
234 hw_err(hw, "semaphore failed with %d\n", status);
235 return;
236 }
237 }
Mark Rustad542b6ee2015-08-08 16:18:38 -0700238
239 /* Reset the CS4227. */
240 status = ixgbe_reset_cs4227(hw);
241 if (status) {
242 hw_err(hw, "CS4227 reset failed: %d", status);
243 goto out;
244 }
245
246 /* Reset takes so long, temporarily release semaphore in case the
247 * other driver instance is waiting for the reset indication.
248 */
249 ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
250 IXGBE_CS4227_RESET_PENDING);
251 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
252 usleep_range(10000, 12000);
253 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
254 if (status) {
255 hw_err(hw, "semaphore failed with %d", status);
256 return;
257 }
258
Mark Rustad542b6ee2015-08-08 16:18:38 -0700259 /* Record completion for next time. */
260 status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
261 IXGBE_CS4227_RESET_COMPLETE);
262
263out:
264 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
265 msleep(hw->eeprom.semaphore_delay);
266}
267
Don Skidmore6a14ee02014-12-05 03:59:50 +0000268/** ixgbe_identify_phy_x550em - Get PHY type based on device id
269 * @hw: pointer to hardware structure
270 *
271 * Returns error code
272 */
273static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
274{
Don Skidmore6a14ee02014-12-05 03:59:50 +0000275 switch (hw->device_id) {
Mark Rustad2d40cd12016-04-01 12:18:35 -0700276 case IXGBE_DEV_ID_X550EM_A_SFP:
277 if (hw->bus.lan_id)
278 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
279 else
280 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
281 return ixgbe_identify_module_generic(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000282 case IXGBE_DEV_ID_X550EM_X_SFP:
283 /* set up for CS4227 usage */
284 hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
Don Skidmoreab5fe0c2015-06-09 16:18:56 -0700285 ixgbe_setup_mux_ctl(hw);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700286 ixgbe_check_cs4227(hw);
Mark Rustad49425df2016-04-01 12:18:09 -0700287 /* Fallthrough */
288 case IXGBE_DEV_ID_X550EM_A_SFP_N:
Don Skidmore6a14ee02014-12-05 03:59:50 +0000289 return ixgbe_identify_module_generic(hw);
290 case IXGBE_DEV_ID_X550EM_X_KX4:
291 hw->phy.type = ixgbe_phy_x550em_kx4;
292 break;
293 case IXGBE_DEV_ID_X550EM_X_KR:
Mark Rustadf572b2c2016-04-01 12:18:46 -0700294 case IXGBE_DEV_ID_X550EM_A_KR:
295 case IXGBE_DEV_ID_X550EM_A_KR_L:
Don Skidmore6a14ee02014-12-05 03:59:50 +0000296 hw->phy.type = ixgbe_phy_x550em_kr;
297 break;
Don Skidmore92ed8432016-08-17 20:34:40 -0400298 case IXGBE_DEV_ID_X550EM_A_10G_T:
299 if (hw->bus.lan_id)
300 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
301 else
302 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
303 /* Fallthrough */
Don Skidmore6a14ee02014-12-05 03:59:50 +0000304 case IXGBE_DEV_ID_X550EM_X_1G_T:
305 case IXGBE_DEV_ID_X550EM_X_10G_T:
306 return ixgbe_identify_phy_generic(hw);
307 default:
308 break;
309 }
310 return 0;
311}
312
313static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
314 u32 device_type, u16 *phy_data)
315{
316 return IXGBE_NOT_IMPLEMENTED;
317}
318
319static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
320 u32 device_type, u16 phy_data)
321{
322 return IXGBE_NOT_IMPLEMENTED;
323}
324
325/** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
326 * @hw: pointer to hardware structure
327 *
328 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
329 * ixgbe_hw struct in order to set up EEPROM access.
330 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000331static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000332{
333 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
334 u32 eec;
335 u16 eeprom_size;
336
337 if (eeprom->type == ixgbe_eeprom_uninitialized) {
338 eeprom->semaphore_delay = 10;
339 eeprom->type = ixgbe_flash;
340
Don Skidmore9a900ec2015-06-09 17:15:01 -0700341 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Don Skidmore6a14ee02014-12-05 03:59:50 +0000342 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
343 IXGBE_EEC_SIZE_SHIFT);
Jacob Kellerb4f47a42016-04-13 16:08:22 -0700344 eeprom->word_size = BIT(eeprom_size +
345 IXGBE_EEPROM_WORD_SIZE_SHIFT);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000346
347 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
348 eeprom->type, eeprom->word_size);
349 }
350
351 return 0;
352}
353
Mark Rustadae14a1d2015-04-10 10:36:26 -0700354/**
355 * ixgbe_iosf_wait - Wait for IOSF command completion
356 * @hw: pointer to hardware structure
357 * @ctrl: pointer to location to receive final IOSF control value
358 *
359 * Return: failing status on timeout
360 *
361 * Note: ctrl can be NULL if the IOSF control register value is not needed
362 */
363static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
364{
365 u32 i, command;
366
367 /* Check every 10 usec to see if the address cycle completed.
368 * The SB IOSF BUSY bit will clear when the operation is
369 * complete.
370 */
371 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
372 command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
373 if (!(command & IXGBE_SB_IOSF_CTRL_BUSY))
374 break;
Mark Rustadd90b5b02016-01-29 14:44:29 -0800375 udelay(10);
Mark Rustadae14a1d2015-04-10 10:36:26 -0700376 }
377 if (ctrl)
378 *ctrl = command;
379 if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
380 hw_dbg(hw, "IOSF wait timed out\n");
381 return IXGBE_ERR_PHY;
382 }
383
384 return 0;
385}
386
Don Skidmore6a14ee02014-12-05 03:59:50 +0000387/** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the
388 * IOSF device
389 * @hw: pointer to hardware structure
390 * @reg_addr: 32 bit PHY register to write
391 * @device_type: 3 bit device type
392 * @phy_data: Pointer to read data from the register
393 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000394static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
395 u32 device_type, u32 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000396{
Mark Rustadae14a1d2015-04-10 10:36:26 -0700397 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
398 u32 command, error;
399 s32 ret;
400
401 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
402 if (ret)
403 return ret;
404
405 ret = ixgbe_iosf_wait(hw, NULL);
406 if (ret)
407 goto out;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000408
409 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
410 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
411
412 /* Write IOSF control register */
413 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
414
Mark Rustadae14a1d2015-04-10 10:36:26 -0700415 ret = ixgbe_iosf_wait(hw, &command);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000416
417 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
418 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
419 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
420 hw_dbg(hw, "Failed to read, error %x\n", error);
421 return IXGBE_ERR_PHY;
422 }
423
Mark Rustadae14a1d2015-04-10 10:36:26 -0700424 if (!ret)
425 *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000426
Mark Rustadae14a1d2015-04-10 10:36:26 -0700427out:
428 hw->mac.ops.release_swfw_sync(hw, gssr);
429 return ret;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000430}
431
Mark Rustad49425df2016-04-01 12:18:09 -0700432/**
433 * ixgbe_get_phy_token - Get the token for shared PHY access
434 * @hw: Pointer to hardware structure
435 */
436static s32 ixgbe_get_phy_token(struct ixgbe_hw *hw)
437{
438 struct ixgbe_hic_phy_token_req token_cmd;
439 s32 status;
440
441 token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
442 token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
443 token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
444 token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
445 token_cmd.port_number = hw->bus.lan_id;
446 token_cmd.command_type = FW_PHY_TOKEN_REQ;
447 token_cmd.pad = 0;
448 status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
449 IXGBE_HI_COMMAND_TIMEOUT,
450 true);
451 if (status)
452 return status;
453 if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
454 return 0;
455 if (token_cmd.hdr.cmd_or_resp.ret_status != FW_PHY_TOKEN_RETRY)
456 return IXGBE_ERR_FW_RESP_INVALID;
457
458 return IXGBE_ERR_TOKEN_RETRY;
459}
460
461/**
462 * ixgbe_put_phy_token - Put the token for shared PHY access
463 * @hw: Pointer to hardware structure
464 */
465static s32 ixgbe_put_phy_token(struct ixgbe_hw *hw)
466{
467 struct ixgbe_hic_phy_token_req token_cmd;
468 s32 status;
469
470 token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
471 token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
472 token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
473 token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
474 token_cmd.port_number = hw->bus.lan_id;
475 token_cmd.command_type = FW_PHY_TOKEN_REL;
476 token_cmd.pad = 0;
477 status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
478 IXGBE_HI_COMMAND_TIMEOUT,
479 true);
480 if (status)
481 return status;
482 if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
483 return 0;
484 return IXGBE_ERR_FW_RESP_INVALID;
485}
486
487/**
488 * ixgbe_write_iosf_sb_reg_x550a - Write to IOSF PHY register
489 * @hw: pointer to hardware structure
490 * @reg_addr: 32 bit PHY register to write
491 * @device_type: 3 bit device type
492 * @data: Data to write to the register
493 **/
494static s32 ixgbe_write_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
495 __always_unused u32 device_type,
496 u32 data)
497{
498 struct ixgbe_hic_internal_phy_req write_cmd;
499
500 memset(&write_cmd, 0, sizeof(write_cmd));
501 write_cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
502 write_cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
503 write_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
504 write_cmd.port_number = hw->bus.lan_id;
505 write_cmd.command_type = FW_INT_PHY_REQ_WRITE;
506 write_cmd.address = cpu_to_be16(reg_addr);
507 write_cmd.write_data = cpu_to_be32(data);
508
509 return ixgbe_host_interface_command(hw, &write_cmd, sizeof(write_cmd),
510 IXGBE_HI_COMMAND_TIMEOUT, false);
511}
512
513/**
514 * ixgbe_read_iosf_sb_reg_x550a - Read from IOSF PHY register
515 * @hw: pointer to hardware structure
516 * @reg_addr: 32 bit PHY register to write
517 * @device_type: 3 bit device type
518 * @data: Pointer to read data from the register
519 **/
520static s32 ixgbe_read_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
521 __always_unused u32 device_type,
522 u32 *data)
523{
524 union {
525 struct ixgbe_hic_internal_phy_req cmd;
526 struct ixgbe_hic_internal_phy_resp rsp;
527 } hic;
528 s32 status;
529
530 memset(&hic, 0, sizeof(hic));
531 hic.cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
532 hic.cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
533 hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
534 hic.cmd.port_number = hw->bus.lan_id;
535 hic.cmd.command_type = FW_INT_PHY_REQ_READ;
536 hic.cmd.address = cpu_to_be16(reg_addr);
537
538 status = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
539 IXGBE_HI_COMMAND_TIMEOUT, true);
540
541 /* Extract the register value from the response. */
542 *data = be32_to_cpu(hic.rsp.read_data);
543
544 return status;
545}
546
Don Skidmore6a14ee02014-12-05 03:59:50 +0000547/** ixgbe_read_ee_hostif_data_X550 - Read EEPROM word using a host interface
548 * command assuming that the semaphore is already obtained.
549 * @hw: pointer to hardware structure
550 * @offset: offset of word in the EEPROM to read
551 * @data: word read from the EEPROM
552 *
553 * Reads a 16 bit word from the EEPROM using the hostif.
554 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000555static s32 ixgbe_read_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
556 u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000557{
558 s32 status;
559 struct ixgbe_hic_read_shadow_ram buffer;
560
561 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
562 buffer.hdr.req.buf_lenh = 0;
563 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
564 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
565
566 /* convert offset from words to bytes */
567 buffer.address = cpu_to_be32(offset * 2);
568 /* one word */
569 buffer.length = cpu_to_be16(sizeof(u16));
570
Mark Rustad5cffde32016-03-14 11:05:57 -0700571 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +0000572 IXGBE_HI_COMMAND_TIMEOUT, false);
573 if (status)
574 return status;
575
576 *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
577 FW_NVM_DATA_OFFSET);
578
579 return 0;
580}
581
582/** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
583 * @hw: pointer to hardware structure
584 * @offset: offset of word in the EEPROM to read
585 * @words: number of words
586 * @data: word(s) read from the EEPROM
587 *
588 * Reads a 16 bit word(s) from the EEPROM using the hostif.
589 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000590static s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
591 u16 offset, u16 words, u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000592{
593 struct ixgbe_hic_read_shadow_ram buffer;
594 u32 current_word = 0;
595 u16 words_to_read;
596 s32 status;
597 u32 i;
598
599 /* Take semaphore for the entire operation. */
600 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
601 if (status) {
602 hw_dbg(hw, "EEPROM read buffer - semaphore failed\n");
603 return status;
604 }
605
606 while (words) {
607 if (words > FW_MAX_READ_BUFFER_SIZE / 2)
608 words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
609 else
610 words_to_read = words;
611
612 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
613 buffer.hdr.req.buf_lenh = 0;
614 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
615 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
616
617 /* convert offset from words to bytes */
618 buffer.address = cpu_to_be32((offset + current_word) * 2);
619 buffer.length = cpu_to_be16(words_to_read * 2);
620
Mark Rustad5cffde32016-03-14 11:05:57 -0700621 status = ixgbe_host_interface_command(hw, &buffer,
Don Skidmore6a14ee02014-12-05 03:59:50 +0000622 sizeof(buffer),
623 IXGBE_HI_COMMAND_TIMEOUT,
624 false);
625 if (status) {
626 hw_dbg(hw, "Host interface command failed\n");
627 goto out;
628 }
629
630 for (i = 0; i < words_to_read; i++) {
631 u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
632 2 * i;
633 u32 value = IXGBE_READ_REG(hw, reg);
634
635 data[current_word] = (u16)(value & 0xffff);
636 current_word++;
637 i++;
638 if (i < words_to_read) {
639 value >>= 16;
640 data[current_word] = (u16)(value & 0xffff);
641 current_word++;
642 }
643 }
644 words -= words_to_read;
645 }
646
647out:
648 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
649 return status;
650}
651
652/** ixgbe_checksum_ptr_x550 - Checksum one pointer region
653 * @hw: pointer to hardware structure
654 * @ptr: pointer offset in eeprom
655 * @size: size of section pointed by ptr, if 0 first word will be used as size
656 * @csum: address of checksum to update
657 *
658 * Returns error status for any failure
659 **/
660static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
661 u16 size, u16 *csum, u16 *buffer,
662 u32 buffer_size)
663{
664 u16 buf[256];
665 s32 status;
666 u16 length, bufsz, i, start;
667 u16 *local_buffer;
668
669 bufsz = sizeof(buf) / sizeof(buf[0]);
670
671 /* Read a chunk at the pointer location */
672 if (!buffer) {
673 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
674 if (status) {
675 hw_dbg(hw, "Failed to read EEPROM image\n");
676 return status;
677 }
678 local_buffer = buf;
679 } else {
680 if (buffer_size < ptr)
681 return IXGBE_ERR_PARAM;
682 local_buffer = &buffer[ptr];
683 }
684
685 if (size) {
686 start = 0;
687 length = size;
688 } else {
689 start = 1;
690 length = local_buffer[0];
691
692 /* Skip pointer section if length is invalid. */
693 if (length == 0xFFFF || length == 0 ||
694 (ptr + length) >= hw->eeprom.word_size)
695 return 0;
696 }
697
698 if (buffer && ((u32)start + (u32)length > buffer_size))
699 return IXGBE_ERR_PARAM;
700
701 for (i = start; length; i++, length--) {
702 if (i == bufsz && !buffer) {
703 ptr += bufsz;
704 i = 0;
705 if (length < bufsz)
706 bufsz = length;
707
708 /* Read a chunk at the pointer location */
709 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
710 bufsz, buf);
711 if (status) {
712 hw_dbg(hw, "Failed to read EEPROM image\n");
713 return status;
714 }
715 }
716 *csum += local_buffer[i];
717 }
718 return 0;
719}
720
721/** ixgbe_calc_checksum_X550 - Calculates and returns the checksum
722 * @hw: pointer to hardware structure
723 * @buffer: pointer to buffer containing calculated checksum
724 * @buffer_size: size of buffer
725 *
726 * Returns a negative error code on error, or the 16-bit checksum
727 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000728static s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer,
729 u32 buffer_size)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000730{
731 u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
732 u16 *local_buffer;
733 s32 status;
734 u16 checksum = 0;
735 u16 pointer, i, size;
736
737 hw->eeprom.ops.init_params(hw);
738
739 if (!buffer) {
740 /* Read pointer area */
741 status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
742 IXGBE_EEPROM_LAST_WORD + 1,
743 eeprom_ptrs);
744 if (status) {
745 hw_dbg(hw, "Failed to read EEPROM image\n");
746 return status;
747 }
748 local_buffer = eeprom_ptrs;
749 } else {
750 if (buffer_size < IXGBE_EEPROM_LAST_WORD)
751 return IXGBE_ERR_PARAM;
752 local_buffer = buffer;
753 }
754
755 /* For X550 hardware include 0x0-0x41 in the checksum, skip the
756 * checksum word itself
757 */
758 for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
759 if (i != IXGBE_EEPROM_CHECKSUM)
760 checksum += local_buffer[i];
761
762 /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
763 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
764 */
765 for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
766 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
767 continue;
768
769 pointer = local_buffer[i];
770
771 /* Skip pointer section if the pointer is invalid. */
772 if (pointer == 0xFFFF || pointer == 0 ||
773 pointer >= hw->eeprom.word_size)
774 continue;
775
776 switch (i) {
777 case IXGBE_PCIE_GENERAL_PTR:
778 size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
779 break;
780 case IXGBE_PCIE_CONFIG0_PTR:
781 case IXGBE_PCIE_CONFIG1_PTR:
782 size = IXGBE_PCIE_CONFIG_SIZE;
783 break;
784 default:
785 size = 0;
786 break;
787 }
788
789 status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
790 buffer, buffer_size);
791 if (status)
792 return status;
793 }
794
795 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
796
797 return (s32)checksum;
798}
799
800/** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
801 * @hw: pointer to hardware structure
802 *
803 * Returns a negative error code on error, or the 16-bit checksum
804 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000805static s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000806{
807 return ixgbe_calc_checksum_X550(hw, NULL, 0);
808}
809
810/** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
811 * @hw: pointer to hardware structure
812 * @offset: offset of word in the EEPROM to read
813 * @data: word read from the EEPROM
814 *
815 * Reads a 16 bit word from the EEPROM using the hostif.
816 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000817static s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000818{
819 s32 status = 0;
820
821 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
822 status = ixgbe_read_ee_hostif_data_X550(hw, offset, data);
823 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
824 } else {
825 status = IXGBE_ERR_SWFW_SYNC;
826 }
827
828 return status;
829}
830
831/** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
832 * @hw: pointer to hardware structure
833 * @checksum_val: calculated checksum
834 *
835 * Performs checksum calculation and validates the EEPROM checksum. If the
836 * caller does not need checksum_val, the value can be NULL.
837 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000838static s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw,
839 u16 *checksum_val)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000840{
841 s32 status;
842 u16 checksum;
843 u16 read_checksum = 0;
844
845 /* Read the first word from the EEPROM. If this times out or fails, do
846 * not continue or we could be in for a very long wait while every
847 * EEPROM read fails
848 */
849 status = hw->eeprom.ops.read(hw, 0, &checksum);
850 if (status) {
851 hw_dbg(hw, "EEPROM read failed\n");
852 return status;
853 }
854
855 status = hw->eeprom.ops.calc_checksum(hw);
856 if (status < 0)
857 return status;
858
859 checksum = (u16)(status & 0xffff);
860
861 status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
862 &read_checksum);
863 if (status)
864 return status;
865
866 /* Verify read checksum from EEPROM is the same as
867 * calculated checksum
868 */
869 if (read_checksum != checksum) {
870 status = IXGBE_ERR_EEPROM_CHECKSUM;
871 hw_dbg(hw, "Invalid EEPROM checksum");
872 }
873
874 /* If the user cares, return the calculated checksum */
875 if (checksum_val)
876 *checksum_val = checksum;
877
878 return status;
879}
880
881/** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
882 * @hw: pointer to hardware structure
883 * @offset: offset of word in the EEPROM to write
884 * @data: word write to the EEPROM
885 *
886 * Write a 16 bit word to the EEPROM using the hostif.
887 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000888static s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
889 u16 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000890{
891 s32 status;
892 struct ixgbe_hic_write_shadow_ram buffer;
893
894 buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
895 buffer.hdr.req.buf_lenh = 0;
896 buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
897 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
898
899 /* one word */
900 buffer.length = cpu_to_be16(sizeof(u16));
901 buffer.data = data;
902 buffer.address = cpu_to_be32(offset * 2);
903
Mark Rustad5cffde32016-03-14 11:05:57 -0700904 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +0000905 IXGBE_HI_COMMAND_TIMEOUT, false);
906 return status;
907}
908
909/** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
910 * @hw: pointer to hardware structure
911 * @offset: offset of word in the EEPROM to write
912 * @data: word write to the EEPROM
913 *
914 * Write a 16 bit word to the EEPROM using the hostif.
915 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000916static s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000917{
918 s32 status = 0;
919
920 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
921 status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
922 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
923 } else {
924 hw_dbg(hw, "write ee hostif failed to get semaphore");
925 status = IXGBE_ERR_SWFW_SYNC;
926 }
927
928 return status;
929}
930
931/** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
932 * @hw: pointer to hardware structure
933 *
934 * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
935 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000936static s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000937{
938 s32 status = 0;
939 union ixgbe_hic_hdr2 buffer;
940
941 buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
942 buffer.req.buf_lenh = 0;
943 buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
944 buffer.req.checksum = FW_DEFAULT_CHECKSUM;
945
Mark Rustad5cffde32016-03-14 11:05:57 -0700946 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +0000947 IXGBE_HI_COMMAND_TIMEOUT, false);
948 return status;
949}
950
Don Skidmore454c65d2015-06-17 20:59:59 -0400951/**
952 * ixgbe_get_bus_info_X550em - Set PCI bus info
953 * @hw: pointer to hardware structure
954 *
955 * Sets bus link width and speed to unknown because X550em is
956 * not a PCI device.
957 **/
958static s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
959{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400960 hw->bus.type = ixgbe_bus_type_internal;
Don Skidmore454c65d2015-06-17 20:59:59 -0400961 hw->bus.width = ixgbe_bus_width_unknown;
962 hw->bus.speed = ixgbe_bus_speed_unknown;
963
964 hw->mac.ops.set_lan_id(hw);
965
966 return 0;
967}
968
Don Skidmore1f9ac572015-03-13 13:54:30 -0700969/** ixgbe_disable_rx_x550 - Disable RX unit
970 *
971 * Enables the Rx DMA unit for x550
972 **/
973static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
974{
975 u32 rxctrl, pfdtxgswc;
976 s32 status;
977 struct ixgbe_hic_disable_rxen fw_cmd;
978
979 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
980 if (rxctrl & IXGBE_RXCTRL_RXEN) {
981 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
982 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
983 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
984 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
985 hw->mac.set_lben = true;
986 } else {
987 hw->mac.set_lben = false;
988 }
989
990 fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
991 fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
992 fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
Mark Rustad3775b812016-03-14 11:05:46 -0700993 fw_cmd.port_number = hw->bus.lan_id;
Don Skidmore1f9ac572015-03-13 13:54:30 -0700994
Mark Rustad5cffde32016-03-14 11:05:57 -0700995 status = ixgbe_host_interface_command(hw, &fw_cmd,
Don Skidmore1f9ac572015-03-13 13:54:30 -0700996 sizeof(struct ixgbe_hic_disable_rxen),
997 IXGBE_HI_COMMAND_TIMEOUT, true);
998
999 /* If we fail - disable RX using register write */
1000 if (status) {
1001 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1002 if (rxctrl & IXGBE_RXCTRL_RXEN) {
1003 rxctrl &= ~IXGBE_RXCTRL_RXEN;
1004 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
1005 }
1006 }
1007 }
1008}
1009
Don Skidmore6a14ee02014-12-05 03:59:50 +00001010/** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
1011 * @hw: pointer to hardware structure
1012 *
1013 * After writing EEPROM to shadow RAM using EEWR register, software calculates
1014 * checksum and updates the EEPROM and instructs the hardware to update
1015 * the flash.
1016 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001017static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001018{
1019 s32 status;
1020 u16 checksum = 0;
1021
1022 /* Read the first word from the EEPROM. If this times out or fails, do
1023 * not continue or we could be in for a very long wait while every
1024 * EEPROM read fails
1025 */
1026 status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
1027 if (status) {
1028 hw_dbg(hw, "EEPROM read failed\n");
1029 return status;
1030 }
1031
1032 status = ixgbe_calc_eeprom_checksum_X550(hw);
1033 if (status < 0)
1034 return status;
1035
1036 checksum = (u16)(status & 0xffff);
1037
1038 status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
1039 checksum);
1040 if (status)
1041 return status;
1042
1043 status = ixgbe_update_flash_X550(hw);
1044
1045 return status;
1046}
1047
1048/** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
1049 * @hw: pointer to hardware structure
1050 * @offset: offset of word in the EEPROM to write
1051 * @words: number of words
1052 * @data: word(s) write to the EEPROM
1053 *
1054 *
1055 * Write a 16 bit word(s) to the EEPROM using the hostif.
1056 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001057static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
1058 u16 offset, u16 words,
1059 u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001060{
1061 s32 status = 0;
1062 u32 i = 0;
1063
1064 /* Take semaphore for the entire operation. */
1065 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1066 if (status) {
1067 hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
1068 return status;
1069 }
1070
1071 for (i = 0; i < words; i++) {
1072 status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
1073 data[i]);
1074 if (status) {
1075 hw_dbg(hw, "Eeprom buffered write failed\n");
1076 break;
1077 }
1078 }
1079
1080 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1081
1082 return status;
1083}
1084
Don Skidmore6a14ee02014-12-05 03:59:50 +00001085/** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
1086 * IOSF device
1087 *
1088 * @hw: pointer to hardware structure
1089 * @reg_addr: 32 bit PHY register to write
1090 * @device_type: 3 bit device type
1091 * @data: Data to write to the register
1092 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001093static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
1094 u32 device_type, u32 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001095{
Mark Rustadae14a1d2015-04-10 10:36:26 -07001096 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
1097 u32 command, error;
1098 s32 ret;
1099
1100 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
1101 if (ret)
1102 return ret;
1103
1104 ret = ixgbe_iosf_wait(hw, NULL);
1105 if (ret)
1106 goto out;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001107
1108 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
1109 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
1110
1111 /* Write IOSF control register */
1112 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
1113
1114 /* Write IOSF data register */
1115 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
1116
Mark Rustadae14a1d2015-04-10 10:36:26 -07001117 ret = ixgbe_iosf_wait(hw, &command);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001118
1119 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
1120 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
1121 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
1122 hw_dbg(hw, "Failed to write, error %x\n", error);
1123 return IXGBE_ERR_PHY;
1124 }
1125
Mark Rustadae14a1d2015-04-10 10:36:26 -07001126out:
1127 hw->mac.ops.release_swfw_sync(hw, gssr);
1128 return ret;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001129}
1130
1131/** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
1132 * @hw: pointer to hardware structure
1133 * @speed: the link speed to force
1134 *
1135 * Configures the integrated KR PHY to use iXFI mode. Used to connect an
1136 * internal and external PHY at a specific speed, without autonegotiation.
1137 **/
1138static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1139{
1140 s32 status;
1141 u32 reg_val;
1142
1143 /* Disable AN and force speed to 10G Serial. */
1144 status = ixgbe_read_iosf_sb_reg_x550(hw,
1145 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1146 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1147 if (status)
1148 return status;
1149
1150 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1151 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1152
1153 /* Select forced link speed for internal PHY. */
1154 switch (*speed) {
1155 case IXGBE_LINK_SPEED_10GB_FULL:
1156 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
1157 break;
1158 case IXGBE_LINK_SPEED_1GB_FULL:
1159 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1160 break;
1161 default:
1162 /* Other link speeds are not supported by internal KR PHY. */
1163 return IXGBE_ERR_LINK_SETUP;
1164 }
1165
1166 status = ixgbe_write_iosf_sb_reg_x550(hw,
Don Skidmorebec4e682015-06-09 17:55:59 -07001167 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
Don Skidmore6a14ee02014-12-05 03:59:50 +00001168 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1169 if (status)
1170 return status;
1171
1172 /* Disable training protocol FSM. */
1173 status = ixgbe_read_iosf_sb_reg_x550(hw,
1174 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1175 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1176 if (status)
1177 return status;
1178
1179 reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
1180 status = ixgbe_write_iosf_sb_reg_x550(hw,
1181 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1182 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1183 if (status)
1184 return status;
1185
1186 /* Disable Flex from training TXFFE. */
1187 status = ixgbe_read_iosf_sb_reg_x550(hw,
1188 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1189 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1190 if (status)
1191 return status;
1192
1193 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1194 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1195 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1196 status = ixgbe_write_iosf_sb_reg_x550(hw,
1197 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1198 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1199 if (status)
1200 return status;
1201
1202 status = ixgbe_read_iosf_sb_reg_x550(hw,
1203 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1204 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1205 if (status)
1206 return status;
1207
1208 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1209 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1210 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1211 status = ixgbe_write_iosf_sb_reg_x550(hw,
1212 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1213 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1214 if (status)
1215 return status;
1216
1217 /* Enable override for coefficients. */
1218 status = ixgbe_read_iosf_sb_reg_x550(hw,
1219 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1220 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1221 if (status)
1222 return status;
1223
1224 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
1225 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
1226 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
1227 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
1228 status = ixgbe_write_iosf_sb_reg_x550(hw,
1229 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1230 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1231 if (status)
1232 return status;
1233
1234 /* Toggle port SW reset by AN reset. */
1235 status = ixgbe_read_iosf_sb_reg_x550(hw,
1236 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1237 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1238 if (status)
1239 return status;
1240
1241 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1242 status = ixgbe_write_iosf_sb_reg_x550(hw,
1243 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1244 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1245
1246 return status;
1247}
1248
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001249/**
Mark Rustade23f3332015-08-08 16:18:33 -07001250 * ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
1251 * @hw: pointer to hardware structure
1252 * @linear: true if SFP module is linear
1253 */
1254static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
1255{
1256 switch (hw->phy.sfp_type) {
1257 case ixgbe_sfp_type_not_present:
1258 return IXGBE_ERR_SFP_NOT_PRESENT;
1259 case ixgbe_sfp_type_da_cu_core0:
1260 case ixgbe_sfp_type_da_cu_core1:
1261 *linear = true;
1262 break;
1263 case ixgbe_sfp_type_srlr_core0:
1264 case ixgbe_sfp_type_srlr_core1:
1265 case ixgbe_sfp_type_da_act_lmt_core0:
1266 case ixgbe_sfp_type_da_act_lmt_core1:
1267 case ixgbe_sfp_type_1g_sx_core0:
1268 case ixgbe_sfp_type_1g_sx_core1:
1269 case ixgbe_sfp_type_1g_lx_core0:
1270 case ixgbe_sfp_type_1g_lx_core1:
1271 *linear = false;
1272 break;
1273 case ixgbe_sfp_type_unknown:
1274 case ixgbe_sfp_type_1g_cu_core0:
1275 case ixgbe_sfp_type_1g_cu_core1:
1276 default:
1277 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1278 }
1279
1280 return 0;
1281}
1282
1283/**
Mark Rustad6d373a12015-08-08 16:18:28 -07001284 * ixgbe_setup_mac_link_sfp_x550em - Configure the KR PHY for SFP.
1285 * @hw: pointer to hardware structure
1286 *
1287 * Configures the extern PHY and the integrated KR PHY for SFP support.
1288 */
1289static s32
1290ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
1291 ixgbe_link_speed speed,
1292 __always_unused bool autoneg_wait_to_complete)
1293{
Mark Rustade23f3332015-08-08 16:18:33 -07001294 s32 status;
1295 u16 slice, value;
1296 bool setup_linear = false;
1297
1298 /* Check if SFP module is supported and linear */
1299 status = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1300
1301 /* If no SFP module present, then return success. Return success since
1302 * there is no reason to configure CS4227 and SFP not present error is
1303 * not accepted in the setup MAC link flow.
1304 */
1305 if (status == IXGBE_ERR_SFP_NOT_PRESENT)
1306 return 0;
1307
1308 if (status)
1309 return status;
1310
Mark Rustadd91e3a72015-09-28 14:37:47 -07001311 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1312 /* Configure CS4227 LINE side to 10G SR. */
1313 slice = IXGBE_CS4227_LINE_SPARE22_MSB + (hw->bus.lan_id << 12);
1314 value = IXGBE_CS4227_SPEED_10G;
1315 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1316 slice, value);
1317 if (status)
1318 goto i2c_err;
Mark Rustade23f3332015-08-08 16:18:33 -07001319
Mark Rustadd91e3a72015-09-28 14:37:47 -07001320 slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
Mark Rustade23f3332015-08-08 16:18:33 -07001321 value = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
Mark Rustadd91e3a72015-09-28 14:37:47 -07001322 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1323 slice, value);
1324 if (status)
1325 goto i2c_err;
Mark Rustade23f3332015-08-08 16:18:33 -07001326
Mark Rustadd91e3a72015-09-28 14:37:47 -07001327 /* Configure CS4227 for HOST connection rate then type. */
1328 slice = IXGBE_CS4227_HOST_SPARE22_MSB + (hw->bus.lan_id << 12);
1329 value = speed & IXGBE_LINK_SPEED_10GB_FULL ?
1330 IXGBE_CS4227_SPEED_10G : IXGBE_CS4227_SPEED_1G;
1331 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1332 slice, value);
1333 if (status)
1334 goto i2c_err;
1335
1336 slice = IXGBE_CS4227_HOST_SPARE24_LSB + (hw->bus.lan_id << 12);
1337 if (setup_linear)
1338 value = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1339 else
1340 value = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1341 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1342 slice, value);
1343 if (status)
1344 goto i2c_err;
1345
1346 /* Setup XFI internal link. */
Mark Rustade23f3332015-08-08 16:18:33 -07001347 status = ixgbe_setup_ixfi_x550em(hw, &speed);
Mark Rustadd91e3a72015-09-28 14:37:47 -07001348 if (status) {
1349 hw_dbg(hw, "setup_ixfi failed with %d\n", status);
1350 return status;
1351 }
1352 } else {
1353 /* Configure internal PHY for KR/KX. */
1354 status = ixgbe_setup_kr_speed_x550em(hw, speed);
1355 if (status) {
1356 hw_dbg(hw, "setup_kr_speed failed with %d\n", status);
1357 return status;
1358 }
Mark Rustade23f3332015-08-08 16:18:33 -07001359
Mark Rustadd91e3a72015-09-28 14:37:47 -07001360 /* Configure CS4227 LINE side to proper mode. */
1361 slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
1362 if (setup_linear)
1363 value = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1364 else
1365 value = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1366 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1367 slice, value);
1368 if (status)
1369 goto i2c_err;
1370 }
1371
1372 return 0;
1373
1374i2c_err:
1375 hw_dbg(hw, "combined i2c access failed with %d\n", status);
Mark Rustade23f3332015-08-08 16:18:33 -07001376 return status;
Mark Rustad6d373a12015-08-08 16:18:28 -07001377}
1378
1379/**
Mark Rustad2d40cd12016-04-01 12:18:35 -07001380 * ixgbe_setup_mac_link_sfp_n - Setup internal PHY for native SFP
1381 * @hw: pointer to hardware structure
1382 *
1383 * Configure the the integrated PHY for native SFP support.
1384 */
1385static s32
1386ixgbe_setup_mac_link_sfp_n(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1387 __always_unused bool autoneg_wait_to_complete)
1388{
1389 bool setup_linear = false;
1390 u32 reg_phy_int;
1391 s32 rc;
1392
1393 /* Check if SFP module is supported and linear */
1394 rc = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1395
1396 /* If no SFP module present, then return success. Return success since
1397 * SFP not present error is not excepted in the setup MAC link flow.
1398 */
1399 if (rc == IXGBE_ERR_SFP_NOT_PRESENT)
1400 return 0;
1401
1402 if (!rc)
1403 return rc;
1404
1405 /* Configure internal PHY for native SFI */
1406 rc = hw->mac.ops.read_iosf_sb_reg(hw,
1407 IXGBE_KRM_AN_CNTL_8(hw->bus.lan_id),
1408 IXGBE_SB_IOSF_TARGET_KR_PHY,
1409 &reg_phy_int);
1410 if (rc)
1411 return rc;
1412
1413 if (setup_linear) {
1414 reg_phy_int &= ~IXGBE_KRM_AN_CNTL_8_LIMITING;
1415 reg_phy_int |= IXGBE_KRM_AN_CNTL_8_LINEAR;
1416 } else {
1417 reg_phy_int |= IXGBE_KRM_AN_CNTL_8_LIMITING;
1418 reg_phy_int &= ~IXGBE_KRM_AN_CNTL_8_LINEAR;
1419 }
1420
1421 rc = hw->mac.ops.write_iosf_sb_reg(hw,
1422 IXGBE_KRM_AN_CNTL_8(hw->bus.lan_id),
1423 IXGBE_SB_IOSF_TARGET_KR_PHY,
1424 reg_phy_int);
1425 if (rc)
1426 return rc;
1427
1428 /* Setup XFI/SFI internal link */
1429 return ixgbe_setup_ixfi_x550em(hw, &speed);
1430}
1431
1432/**
1433 * ixgbe_setup_mac_link_sfp_x550a - Setup internal PHY for SFP
1434 * @hw: pointer to hardware structure
1435 *
1436 * Configure the the integrated PHY for SFP support.
1437 */
1438static s32
1439ixgbe_setup_mac_link_sfp_x550a(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1440 __always_unused bool autoneg_wait_to_complete)
1441{
1442 u32 reg_slice, slice_offset;
1443 bool setup_linear = false;
1444 u16 reg_phy_ext;
1445 s32 rc;
1446
1447 /* Check if SFP module is supported and linear */
1448 rc = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1449
1450 /* If no SFP module present, then return success. Return success since
1451 * SFP not present error is not excepted in the setup MAC link flow.
1452 */
1453 if (rc == IXGBE_ERR_SFP_NOT_PRESENT)
1454 return 0;
1455
1456 if (!rc)
1457 return rc;
1458
1459 /* Configure internal PHY for KR/KX. */
1460 ixgbe_setup_kr_speed_x550em(hw, speed);
1461
Mark Rustad7564a882016-09-01 13:58:51 -07001462 if (hw->phy.mdio.prtad == MDIO_PRTAD_NONE)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001463 return IXGBE_ERR_PHY_ADDR_INVALID;
1464
1465 /* Get external PHY device id */
1466 rc = hw->phy.ops.read_reg(hw, IXGBE_CS4227_GLOBAL_ID_MSB,
1467 IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
1468 if (rc)
1469 return rc;
1470
1471 /* When configuring quad port CS4223, the MAC instance is part
1472 * of the slice offset.
1473 */
1474 if (reg_phy_ext == IXGBE_CS4223_PHY_ID)
1475 slice_offset = (hw->bus.lan_id +
1476 (hw->bus.instance_id << 1)) << 12;
1477 else
1478 slice_offset = hw->bus.lan_id << 12;
1479
1480 /* Configure CS4227/CS4223 LINE side to proper mode. */
1481 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + slice_offset;
1482 if (setup_linear)
1483 reg_phy_ext = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1484 else
1485 reg_phy_ext = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1486 return hw->phy.ops.write_reg(hw, reg_slice, IXGBE_MDIO_ZERO_DEV_TYPE,
1487 reg_phy_ext);
1488}
1489
1490/**
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001491 * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
1492 * @hw: pointer to hardware structure
1493 * @speed: new link speed
1494 * @autoneg_wait_to_complete: true when waiting for completion is needed
1495 *
1496 * Setup internal/external PHY link speed based on link speed, then set
1497 * external PHY auto advertised link speed.
1498 *
1499 * Returns error status for any failure
1500 **/
1501static s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
1502 ixgbe_link_speed speed,
1503 bool autoneg_wait)
1504{
1505 s32 status;
1506 ixgbe_link_speed force_speed;
1507
1508 /* Setup internal/external PHY link speed to iXFI (10G), unless
1509 * only 1G is auto advertised then setup KX link.
1510 */
1511 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1512 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
1513 else
1514 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
1515
1516 /* If internal link mode is XFI, then setup XFI internal link. */
1517 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1518 status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
1519
1520 if (status)
1521 return status;
1522 }
1523
1524 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
1525}
1526
Don Skidmorea4e293a2015-06-09 17:44:58 -07001527/** ixgbe_check_link_t_X550em - Determine link and speed status
1528 * @hw: pointer to hardware structure
1529 * @speed: pointer to link speed
1530 * @link_up: true when link is up
1531 * @link_up_wait_to_complete: bool used to wait for link up or not
1532 *
1533 * Check that both the MAC and X557 external PHY have link.
1534 **/
1535static s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw,
1536 ixgbe_link_speed *speed,
1537 bool *link_up,
1538 bool link_up_wait_to_complete)
1539{
1540 u32 status;
1541 u16 autoneg_status;
1542
1543 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
1544 return IXGBE_ERR_CONFIG;
1545
1546 status = ixgbe_check_mac_link_generic(hw, speed, link_up,
1547 link_up_wait_to_complete);
1548
1549 /* If check link fails or MAC link is not up, then return */
1550 if (status || !(*link_up))
1551 return status;
1552
1553 /* MAC link is up, so check external PHY link.
1554 * Read this twice back to back to indicate current status.
1555 */
1556 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
1557 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1558 &autoneg_status);
1559 if (status)
1560 return status;
1561
1562 /* If external PHY link is not up, then indicate link not up */
1563 if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
1564 *link_up = false;
1565
1566 return 0;
1567}
1568
Mark Rustad200157c2016-04-01 12:18:40 -07001569/**
1570 * ixgbe_setup_sgmii - Set up link for sgmii
1571 * @hw: pointer to hardware structure
1572 */
1573static s32
1574ixgbe_setup_sgmii(struct ixgbe_hw *hw, __always_unused ixgbe_link_speed speed,
1575 __always_unused bool autoneg_wait_to_complete)
1576{
1577 struct ixgbe_mac_info *mac = &hw->mac;
1578 u32 lval, sval;
1579 s32 rc;
1580
1581 rc = mac->ops.read_iosf_sb_reg(hw,
1582 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1583 IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
1584 if (rc)
1585 return rc;
1586
1587 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1588 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1589 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
1590 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
1591 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1592 rc = mac->ops.write_iosf_sb_reg(hw,
1593 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1594 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
1595 if (rc)
1596 return rc;
1597
1598 rc = mac->ops.read_iosf_sb_reg(hw,
1599 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
1600 IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
1601 if (rc)
1602 return rc;
1603
1604 sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
1605 sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
1606 rc = mac->ops.write_iosf_sb_reg(hw,
1607 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
1608 IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
1609 if (rc)
1610 return rc;
1611
1612 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1613 rc = mac->ops.write_iosf_sb_reg(hw,
1614 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1615 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
1616
1617 return rc;
1618}
1619
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001620/** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
1621 * @hw: pointer to hardware structure
1622 **/
1623static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
1624{
1625 struct ixgbe_mac_info *mac = &hw->mac;
1626
Emil Tantilovabf76d72016-07-07 17:18:38 -07001627 mac->ops.setup_fc = ixgbe_setup_fc_x550em;
1628
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001629 switch (mac->ops.get_media_type(hw)) {
1630 case ixgbe_media_type_fiber:
1631 /* CS4227 does not support autoneg, so disable the laser control
1632 * functions for SFP+ fiber
1633 */
1634 mac->ops.disable_tx_laser = NULL;
1635 mac->ops.enable_tx_laser = NULL;
1636 mac->ops.flap_tx_laser = NULL;
Mark Rustad6d373a12015-08-08 16:18:28 -07001637 mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001638 switch (hw->device_id) {
1639 case IXGBE_DEV_ID_X550EM_A_SFP_N:
1640 mac->ops.setup_mac_link = ixgbe_setup_mac_link_sfp_n;
1641 break;
1642 case IXGBE_DEV_ID_X550EM_A_SFP:
1643 mac->ops.setup_mac_link =
1644 ixgbe_setup_mac_link_sfp_x550a;
1645 break;
1646 default:
1647 mac->ops.setup_mac_link =
1648 ixgbe_setup_mac_link_sfp_x550em;
1649 break;
1650 }
Mark Rustad6d373a12015-08-08 16:18:28 -07001651 mac->ops.set_rate_select_speed =
1652 ixgbe_set_soft_rate_select_speed;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001653 break;
1654 case ixgbe_media_type_copper:
1655 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
Mark Rustadafdc71e2016-01-25 16:32:10 -08001656 mac->ops.setup_fc = ixgbe_setup_fc_generic;
Don Skidmorea4e293a2015-06-09 17:44:58 -07001657 mac->ops.check_link = ixgbe_check_link_t_X550em;
Mark Rustad49425df2016-04-01 12:18:09 -07001658 return;
1659 case ixgbe_media_type_backplane:
Mark Rustad200157c2016-04-01 12:18:40 -07001660 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII ||
1661 hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII_L)
1662 mac->ops.setup_link = ixgbe_setup_sgmii;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001663 break;
1664 default:
1665 break;
1666 }
1667}
1668
1669/** ixgbe_setup_sfp_modules_X550em - Setup SFP module
1670 * @hw: pointer to hardware structure
1671 */
1672static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
1673{
Mark Rustade23f3332015-08-08 16:18:33 -07001674 s32 status;
1675 bool linear;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001676
Mark Rustade23f3332015-08-08 16:18:33 -07001677 /* Check if SFP module is supported */
1678 status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
1679 if (status)
1680 return status;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001681
1682 ixgbe_init_mac_link_ops_X550em(hw);
1683 hw->phy.ops.reset = NULL;
1684
Mark Rustade23f3332015-08-08 16:18:33 -07001685 return 0;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001686}
1687
1688/** ixgbe_get_link_capabilities_x550em - Determines link capabilities
1689 * @hw: pointer to hardware structure
1690 * @speed: pointer to link speed
1691 * @autoneg: true when autoneg or autotry is enabled
1692 **/
1693static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
1694 ixgbe_link_speed *speed,
1695 bool *autoneg)
1696{
1697 /* SFP */
1698 if (hw->phy.media_type == ixgbe_media_type_fiber) {
1699 /* CS4227 SFP must not enable auto-negotiation */
1700 *autoneg = false;
1701
1702 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1703 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
1704 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1705 return 0;
1706 }
1707
1708 /* Link capabilities are based on SFP */
1709 if (hw->phy.multispeed_fiber)
1710 *speed = IXGBE_LINK_SPEED_10GB_FULL |
1711 IXGBE_LINK_SPEED_1GB_FULL;
1712 else
1713 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1714 } else {
1715 *speed = IXGBE_LINK_SPEED_10GB_FULL |
1716 IXGBE_LINK_SPEED_1GB_FULL;
1717 *autoneg = true;
1718 }
1719 return 0;
1720}
1721
1722/**
1723 * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
1724 * @hw: pointer to hardware structure
1725 * @lsc: pointer to boolean flag which indicates whether external Base T
1726 * PHY interrupt is lsc
1727 *
1728 * Determime if external Base T PHY interrupt cause is high temperature
1729 * failure alarm or link status change.
1730 *
1731 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
1732 * failure alarm, else return PHY access status.
1733 **/
1734static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
1735{
1736 u32 status;
1737 u16 reg;
1738
1739 *lsc = false;
1740
1741 /* Vendor alarm triggered */
1742 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
1743 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1744 &reg);
1745
1746 if (status || !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
1747 return status;
1748
1749 /* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
1750 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
1751 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1752 &reg);
1753
1754 if (status || !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
1755 IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
1756 return status;
1757
Mark Rustad83a9fb22015-10-19 09:22:14 -07001758 /* Global alarm triggered */
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001759 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
1760 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1761 &reg);
1762
1763 if (status)
1764 return status;
1765
1766 /* If high temperature failure, then return over temp error and exit */
1767 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
1768 /* power down the PHY in case the PHY FW didn't already */
1769 ixgbe_set_copper_phy_power(hw, false);
1770 return IXGBE_ERR_OVERTEMP;
1771 }
Mark Rustad83a9fb22015-10-19 09:22:14 -07001772 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
1773 /* device fault alarm triggered */
1774 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
1775 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1776 &reg);
1777 if (status)
1778 return status;
1779
1780 /* if device fault was due to high temp alarm handle and exit */
1781 if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
1782 /* power down the PHY in case the PHY FW didn't */
1783 ixgbe_set_copper_phy_power(hw, false);
1784 return IXGBE_ERR_OVERTEMP;
1785 }
1786 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001787
1788 /* Vendor alarm 2 triggered */
1789 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
1790 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg);
1791
1792 if (status || !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
1793 return status;
1794
1795 /* link connect/disconnect event occurred */
1796 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
1797 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg);
1798
1799 if (status)
1800 return status;
1801
1802 /* Indicate LSC */
1803 if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
1804 *lsc = true;
1805
1806 return 0;
1807}
1808
1809/**
1810 * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
1811 * @hw: pointer to hardware structure
1812 *
1813 * Enable link status change and temperature failure alarm for the external
1814 * Base T PHY
1815 *
1816 * Returns PHY access status
1817 **/
1818static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
1819{
1820 u32 status;
1821 u16 reg;
1822 bool lsc;
1823
1824 /* Clear interrupt flags */
1825 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
1826
1827 /* Enable link status change alarm */
1828 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
1829 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg);
1830 if (status)
1831 return status;
1832
1833 reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
1834
1835 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
1836 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg);
1837 if (status)
1838 return status;
1839
Mark Rustad83a9fb22015-10-19 09:22:14 -07001840 /* Enable high temperature failure and global fault alarms */
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001841 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
1842 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1843 &reg);
1844 if (status)
1845 return status;
1846
Mark Rustad83a9fb22015-10-19 09:22:14 -07001847 reg |= (IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN |
1848 IXGBE_MDIO_GLOBAL_INT_DEV_FAULT_EN);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001849
1850 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
1851 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1852 reg);
1853 if (status)
1854 return status;
1855
1856 /* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
1857 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
1858 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1859 &reg);
1860 if (status)
1861 return status;
1862
1863 reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
1864 IXGBE_MDIO_GLOBAL_ALARM_1_INT);
1865
1866 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
1867 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1868 reg);
1869 if (status)
1870 return status;
1871
1872 /* Enable chip-wide vendor alarm */
1873 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
1874 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1875 &reg);
1876 if (status)
1877 return status;
1878
1879 reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
1880
1881 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
1882 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1883 reg);
1884
1885 return status;
1886}
1887
1888/**
1889 * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
1890 * @hw: pointer to hardware structure
1891 *
1892 * Handle external Base T PHY interrupt. If high temperature
1893 * failure alarm then return error, else if link status change
1894 * then setup internal/external PHY link
1895 *
1896 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
1897 * failure alarm, else return PHY access status.
1898 **/
1899static s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
1900{
1901 struct ixgbe_phy_info *phy = &hw->phy;
1902 bool lsc;
1903 u32 status;
1904
1905 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
1906 if (status)
1907 return status;
1908
Mark Rustada85ce532015-09-09 13:37:33 -07001909 if (lsc && phy->ops.setup_internal_link)
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001910 return phy->ops.setup_internal_link(hw);
1911
1912 return 0;
1913}
1914
1915/**
1916 * ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
1917 * @hw: pointer to hardware structure
1918 * @speed: link speed
1919 *
1920 * Configures the integrated KR PHY.
1921 **/
1922static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
1923 ixgbe_link_speed speed)
1924{
1925 s32 status;
1926 u32 reg_val;
1927
Mark Rustad9a5c27e2016-04-01 12:18:04 -07001928 status = hw->mac.ops.read_iosf_sb_reg(hw,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001929 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1930 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1931 if (status)
1932 return status;
1933
1934 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001935 reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
1936 IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
1937
1938 /* Advertise 10G support. */
1939 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1940 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
1941
1942 /* Advertise 1G support. */
1943 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
1944 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
1945
1946 /* Restart auto-negotiation. */
1947 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
Mark Rustad9a5c27e2016-04-01 12:18:04 -07001948 status = hw->mac.ops.write_iosf_sb_reg(hw,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001949 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1950 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1951
1952 return status;
1953}
1954
Don Skidmore6a14ee02014-12-05 03:59:50 +00001955/** ixgbe_setup_kx4_x550em - Configure the KX4 PHY.
1956 * @hw: pointer to hardware structure
1957 *
1958 * Configures the integrated KX4 PHY.
1959 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001960static s32 ixgbe_setup_kx4_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001961{
1962 s32 status;
1963 u32 reg_val;
1964
Mark Rustad9a5c27e2016-04-01 12:18:04 -07001965 status = hw->mac.ops.read_iosf_sb_reg(hw, IXGBE_KX4_LINK_CNTL_1,
1966 IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
1967 hw->bus.lan_id, &reg_val);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001968 if (status)
1969 return status;
1970
1971 reg_val &= ~(IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4 |
1972 IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX);
1973
1974 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_ENABLE;
1975
1976 /* Advertise 10G support. */
1977 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
1978 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4;
1979
1980 /* Advertise 1G support. */
1981 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
1982 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX;
1983
1984 /* Restart auto-negotiation. */
1985 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_RESTART;
Mark Rustad9a5c27e2016-04-01 12:18:04 -07001986 status = hw->mac.ops.write_iosf_sb_reg(hw, IXGBE_KX4_LINK_CNTL_1,
1987 IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
1988 hw->bus.lan_id, reg_val);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001989
1990 return status;
1991}
1992
Mark Rustadf572b2c2016-04-01 12:18:46 -07001993/**
1994 * ixgbe_setup_kr_x550em - Configure the KR PHY
1995 * @hw: pointer to hardware structure
Don Skidmore6a14ee02014-12-05 03:59:50 +00001996 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001997static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001998{
Don Skidmore6c799992016-12-13 20:34:51 -05001999 /* leave link alone for 2.5G */
2000 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_2_5GB_FULL)
Mark Rustadf572b2c2016-04-01 12:18:46 -07002001 return 0;
2002
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002003 return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002004}
2005
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002006/** ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
2007 * @hw: address of hardware structure
2008 * @link_up: address of boolean to indicate link status
2009 *
2010 * Returns error code if unable to get link status.
2011 **/
2012static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
2013{
2014 u32 ret;
2015 u16 autoneg_status;
2016
2017 *link_up = false;
2018
2019 /* read this twice back to back to indicate current status */
2020 ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
2021 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2022 &autoneg_status);
2023 if (ret)
2024 return ret;
2025
2026 ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
2027 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2028 &autoneg_status);
2029 if (ret)
2030 return ret;
2031
2032 *link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
2033
2034 return 0;
2035}
2036
2037/** ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
Don Skidmore6a14ee02014-12-05 03:59:50 +00002038 * @hw: point to hardware structure
2039 *
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002040 * Configures the link between the integrated KR PHY and the external X557 PHY
2041 * The driver will call this function when it gets a link status change
2042 * interrupt from the X557 PHY. This function configures the link speed
2043 * between the PHYs to match the link speed of the BASE-T link.
Don Skidmore6a14ee02014-12-05 03:59:50 +00002044 *
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002045 * A return of a non-zero value indicates an error, and the base driver should
2046 * not report link up.
Don Skidmore6a14ee02014-12-05 03:59:50 +00002047 **/
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002048static s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002049{
Don Skidmore6a14ee02014-12-05 03:59:50 +00002050 ixgbe_link_speed force_speed;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002051 bool link_up;
2052 u32 status;
2053 u16 speed;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002054
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002055 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2056 return IXGBE_ERR_CONFIG;
2057
Mark Rustadf164b842015-10-16 13:27:49 -07002058 if (hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE) {
2059 speed = IXGBE_LINK_SPEED_10GB_FULL |
2060 IXGBE_LINK_SPEED_1GB_FULL;
2061 return ixgbe_setup_kr_speed_x550em(hw, speed);
2062 }
2063
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002064 /* If link is not up, then there is no setup necessary so return */
2065 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002066 if (status)
2067 return status;
2068
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002069 if (!link_up)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002070 return 0;
2071
Don Skidmore6a14ee02014-12-05 03:59:50 +00002072 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
2073 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2074 &speed);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002075 if (status)
2076 return status;
2077
2078 /* If link is not still up, then no setup is necessary so return */
2079 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2080 if (status)
2081 return status;
2082
2083 if (!link_up)
2084 return 0;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002085
2086 /* clear everything but the speed and duplex bits */
2087 speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
2088
2089 switch (speed) {
2090 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
2091 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
2092 break;
2093 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
2094 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
2095 break;
2096 default:
2097 /* Internal PHY does not support anything else */
2098 return IXGBE_ERR_INVALID_LINK_SETTINGS;
2099 }
2100
2101 return ixgbe_setup_ixfi_x550em(hw, &force_speed);
2102}
2103
Don Skidmoref4410d22015-06-09 16:29:51 -07002104/** ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
2105 * @hw: pointer to hardware structure
2106 **/
2107static s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
2108{
2109 s32 status;
2110
2111 status = ixgbe_reset_phy_generic(hw);
2112
2113 if (status)
2114 return status;
2115
2116 /* Configure Link Status Alarm and Temperature Threshold interrupts */
2117 return ixgbe_enable_lasi_ext_t_x550em(hw);
2118}
2119
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002120/**
2121 * ixgbe_led_on_t_x550em - Turns on the software controllable LEDs.
2122 * @hw: pointer to hardware structure
2123 * @led_idx: led number to turn on
2124 **/
Emil Tantilovd2d43e52016-08-22 16:28:34 -07002125static s32 ixgbe_led_on_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002126{
2127 u16 phy_data;
2128
2129 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
2130 return IXGBE_ERR_PARAM;
2131
2132 /* To turn on the LED, set mode to ON. */
2133 hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
2134 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, &phy_data);
2135 phy_data |= IXGBE_X557_LED_MANUAL_SET_MASK;
2136 hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
2137 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, phy_data);
2138
2139 return 0;
2140}
2141
2142/**
2143 * ixgbe_led_off_t_x550em - Turns off the software controllable LEDs.
2144 * @hw: pointer to hardware structure
2145 * @led_idx: led number to turn off
2146 **/
Emil Tantilovd2d43e52016-08-22 16:28:34 -07002147static s32 ixgbe_led_off_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002148{
2149 u16 phy_data;
2150
2151 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
2152 return IXGBE_ERR_PARAM;
2153
2154 /* To turn on the LED, set mode to ON. */
2155 hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
2156 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, &phy_data);
2157 phy_data &= ~IXGBE_X557_LED_MANUAL_SET_MASK;
2158 hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
2159 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, phy_data);
2160
2161 return 0;
2162}
2163
Don Skidmore6ac74392015-06-17 17:34:31 -04002164/** ixgbe_get_lcd_x550em - Determine lowest common denominator
2165 * @hw: pointer to hardware structure
2166 * @lcd_speed: pointer to lowest common link speed
2167 *
2168 * Determine lowest common link speed with link partner.
2169 **/
2170static s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw,
2171 ixgbe_link_speed *lcd_speed)
2172{
2173 u16 an_lp_status;
2174 s32 status;
2175 u16 word = hw->eeprom.ctrl_word_3;
2176
2177 *lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
2178
2179 status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
2180 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2181 &an_lp_status);
2182 if (status)
2183 return status;
2184
2185 /* If link partner advertised 1G, return 1G */
2186 if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
2187 *lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
2188 return status;
2189 }
2190
2191 /* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
2192 if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
2193 (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
2194 return status;
2195
2196 /* Link partner not capable of lower speeds, return 10G */
2197 *lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
2198 return status;
2199}
2200
Mark Rustadafdc71e2016-01-25 16:32:10 -08002201/**
2202 * ixgbe_setup_fc_x550em - Set up flow control
2203 * @hw: pointer to hardware structure
2204 */
2205static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *hw)
2206{
2207 bool pause, asm_dir;
2208 u32 reg_val;
2209 s32 rc;
2210
2211 /* Validate the requested mode */
2212 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2213 hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
2214 return IXGBE_ERR_INVALID_LINK_SETTINGS;
2215 }
2216
2217 /* 10gig parts do not have a word in the EEPROM to determine the
2218 * default flow control setting, so we explicitly set it to full.
2219 */
2220 if (hw->fc.requested_mode == ixgbe_fc_default)
2221 hw->fc.requested_mode = ixgbe_fc_full;
2222
2223 /* Determine PAUSE and ASM_DIR bits. */
2224 switch (hw->fc.requested_mode) {
2225 case ixgbe_fc_none:
2226 pause = false;
2227 asm_dir = false;
2228 break;
2229 case ixgbe_fc_tx_pause:
2230 pause = false;
2231 asm_dir = true;
2232 break;
2233 case ixgbe_fc_rx_pause:
2234 /* Rx Flow control is enabled and Tx Flow control is
2235 * disabled by software override. Since there really
2236 * isn't a way to advertise that we are capable of RX
2237 * Pause ONLY, we will advertise that we support both
2238 * symmetric and asymmetric Rx PAUSE, as such we fall
2239 * through to the fc_full statement. Later, we will
2240 * disable the adapter's ability to send PAUSE frames.
2241 */
2242 /* Fallthrough */
2243 case ixgbe_fc_full:
2244 pause = true;
2245 asm_dir = true;
2246 break;
2247 default:
2248 hw_err(hw, "Flow control param set incorrectly\n");
2249 return IXGBE_ERR_CONFIG;
2250 }
2251
Mark Rustadf572b2c2016-04-01 12:18:46 -07002252 if (hw->device_id != IXGBE_DEV_ID_X550EM_X_KR &&
2253 hw->device_id != IXGBE_DEV_ID_X550EM_A_KR &&
2254 hw->device_id != IXGBE_DEV_ID_X550EM_A_KR_L)
Mark Rustadafdc71e2016-01-25 16:32:10 -08002255 return 0;
2256
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002257 rc = hw->mac.ops.read_iosf_sb_reg(hw,
2258 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2259 IXGBE_SB_IOSF_TARGET_KR_PHY,
2260 &reg_val);
Mark Rustadafdc71e2016-01-25 16:32:10 -08002261 if (rc)
2262 return rc;
2263
2264 reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
2265 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
2266 if (pause)
2267 reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
2268 if (asm_dir)
2269 reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002270 rc = hw->mac.ops.write_iosf_sb_reg(hw,
2271 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2272 IXGBE_SB_IOSF_TARGET_KR_PHY,
2273 reg_val);
Mark Rustadafdc71e2016-01-25 16:32:10 -08002274
2275 /* This device does not fully support AN. */
2276 hw->fc.disable_fc_autoneg = true;
2277
2278 return rc;
2279}
2280
Don Skidmore6ac74392015-06-17 17:34:31 -04002281/** ixgbe_enter_lplu_x550em - Transition to low power states
2282 * @hw: pointer to hardware structure
2283 *
2284 * Configures Low Power Link Up on transition to low power states
2285 * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting
2286 * the X557 PHY immediately prior to entering LPLU.
2287 **/
2288static s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
2289{
2290 u16 an_10g_cntl_reg, autoneg_reg, speed;
2291 s32 status;
2292 ixgbe_link_speed lcd_speed;
2293 u32 save_autoneg;
2294 bool link_up;
2295
Don Skidmore6ac74392015-06-17 17:34:31 -04002296 /* If blocked by MNG FW, then don't restart AN */
2297 if (ixgbe_check_reset_blocked(hw))
2298 return 0;
2299
2300 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2301 if (status)
2302 return status;
2303
2304 status = hw->eeprom.ops.read(hw, NVM_INIT_CTRL_3,
2305 &hw->eeprom.ctrl_word_3);
2306 if (status)
2307 return status;
2308
2309 /* If link is down, LPLU disabled in NVM, WoL disabled, or
2310 * manageability disabled, then force link down by entering
2311 * low power mode.
2312 */
2313 if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
2314 !(hw->wol_enabled || ixgbe_mng_present(hw)))
2315 return ixgbe_set_copper_phy_power(hw, false);
2316
2317 /* Determine LCD */
2318 status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
2319 if (status)
2320 return status;
2321
2322 /* If no valid LCD link speed, then force link down and exit. */
2323 if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
2324 return ixgbe_set_copper_phy_power(hw, false);
2325
2326 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
2327 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2328 &speed);
2329 if (status)
2330 return status;
2331
2332 /* If no link now, speed is invalid so take link down */
2333 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2334 if (status)
2335 return ixgbe_set_copper_phy_power(hw, false);
2336
2337 /* clear everything but the speed bits */
2338 speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
2339
2340 /* If current speed is already LCD, then exit. */
2341 if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
2342 (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
2343 ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
2344 (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
2345 return status;
2346
2347 /* Clear AN completed indication */
2348 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
2349 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2350 &autoneg_reg);
2351 if (status)
2352 return status;
2353
2354 status = hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
2355 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2356 &an_10g_cntl_reg);
2357 if (status)
2358 return status;
2359
2360 status = hw->phy.ops.read_reg(hw,
2361 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
2362 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2363 &autoneg_reg);
2364 if (status)
2365 return status;
2366
2367 save_autoneg = hw->phy.autoneg_advertised;
2368
2369 /* Setup link at least common link speed */
2370 status = hw->mac.ops.setup_link(hw, lcd_speed, false);
2371
2372 /* restore autoneg from before setting lplu speed */
2373 hw->phy.autoneg_advertised = save_autoneg;
2374
2375 return status;
2376}
2377
Mark Rustad537cc5d2016-04-01 12:18:25 -07002378/**
2379 * ixgbe_read_mng_if_sel_x550em - Read NW_MNG_IF_SEL register
2380 * @hw: pointer to hardware structure
2381 *
2382 * Read NW_MNG_IF_SEL register and save field values.
2383 */
2384static void ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw)
2385{
2386 /* Save NW management interface connected on board. This is used
2387 * to determine internal PHY mode.
2388 */
2389 hw->phy.nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
2390
2391 /* If X552 (X550EM_a) and MDIO is connected to external PHY, then set
2392 * PHY address. This register field was has only been used for X552.
2393 */
Mark Rustadae3cb8c2016-08-30 11:33:43 -07002394 if (hw->mac.type == ixgbe_mac_x550em_a &&
2395 hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_MDIO_ACT) {
2396 hw->phy.mdio.prtad = (hw->phy.nw_mng_if_sel &
2397 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
2398 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
Mark Rustad537cc5d2016-04-01 12:18:25 -07002399 }
Mark Rustad537cc5d2016-04-01 12:18:25 -07002400}
2401
Don Skidmore6a14ee02014-12-05 03:59:50 +00002402/** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
2403 * @hw: pointer to hardware structure
2404 *
2405 * Initialize any function pointers that were not able to be
2406 * set during init_shared_code because the PHY/SFP type was
2407 * not known. Perform the SFP init if necessary.
2408 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00002409static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002410{
2411 struct ixgbe_phy_info *phy = &hw->phy;
2412 s32 ret_val;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002413
Don Skidmore7e49d612015-06-09 17:48:54 -07002414 hw->mac.ops.set_lan_id(hw);
2415
Mark Rustad537cc5d2016-04-01 12:18:25 -07002416 ixgbe_read_mng_if_sel_x550em(hw);
2417
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002418 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
Don Skidmore6a14ee02014-12-05 03:59:50 +00002419 phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
Don Skidmoreab5fe0c2015-06-09 16:18:56 -07002420 ixgbe_setup_mux_ctl(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002421 }
2422
2423 /* Identify the PHY or SFP module */
2424 ret_val = phy->ops.identify(hw);
2425
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002426 /* Setup function pointers based on detected hardware */
Don Skidmore6a14ee02014-12-05 03:59:50 +00002427 ixgbe_init_mac_link_ops_X550em(hw);
2428 if (phy->sfp_type != ixgbe_sfp_type_unknown)
2429 phy->ops.reset = NULL;
2430
2431 /* Set functions pointers based on phy type */
2432 switch (hw->phy.type) {
2433 case ixgbe_phy_x550em_kx4:
2434 phy->ops.setup_link = ixgbe_setup_kx4_x550em;
2435 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
2436 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
2437 break;
2438 case ixgbe_phy_x550em_kr:
2439 phy->ops.setup_link = ixgbe_setup_kr_x550em;
2440 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
2441 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
2442 break;
2443 case ixgbe_phy_x550em_ext_t:
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002444 /* Save NW management interface connected on board. This is used
2445 * to determine internal PHY mode
2446 */
2447 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
2448
2449 /* If internal link mode is XFI, then setup iXFI internal link,
2450 * else setup KR now.
2451 */
Mark Rustadf164b842015-10-16 13:27:49 -07002452 phy->ops.setup_internal_link =
2453 ixgbe_setup_internal_phy_t_x550em;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002454
Don Skidmore6ac74392015-06-17 17:34:31 -04002455 /* setup SW LPLU only for first revision */
Mark Rustad3ca2b252015-11-20 13:12:17 -08002456 if (hw->mac.type == ixgbe_mac_X550EM_x &&
2457 !(IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0)) &
2458 IXGBE_FUSES0_REV_MASK))
Don Skidmore6ac74392015-06-17 17:34:31 -04002459 phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
2460
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002461 phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
Don Skidmoref4410d22015-06-09 16:29:51 -07002462 phy->ops.reset = ixgbe_reset_phy_t_X550em;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002463 break;
2464 default:
2465 break;
2466 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002467
Don Skidmore6a14ee02014-12-05 03:59:50 +00002468 return ret_val;
2469}
2470
2471/** ixgbe_get_media_type_X550em - Get media type
2472 * @hw: pointer to hardware structure
2473 *
2474 * Returns the media type (fiber, copper, backplane)
2475 *
2476 */
Don Skidmore7ddbde32014-12-06 05:59:21 +00002477static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002478{
2479 enum ixgbe_media_type media_type;
2480
2481 /* Detect if there is a copper PHY attached. */
2482 switch (hw->device_id) {
Mark Rustad200157c2016-04-01 12:18:40 -07002483 case IXGBE_DEV_ID_X550EM_A_SGMII:
2484 case IXGBE_DEV_ID_X550EM_A_SGMII_L:
2485 hw->phy.type = ixgbe_phy_sgmii;
2486 /* Fallthrough */
Don Skidmore6a14ee02014-12-05 03:59:50 +00002487 case IXGBE_DEV_ID_X550EM_X_KR:
2488 case IXGBE_DEV_ID_X550EM_X_KX4:
Mark Rustadf572b2c2016-04-01 12:18:46 -07002489 case IXGBE_DEV_ID_X550EM_A_KR:
2490 case IXGBE_DEV_ID_X550EM_A_KR_L:
Don Skidmore6a14ee02014-12-05 03:59:50 +00002491 media_type = ixgbe_media_type_backplane;
2492 break;
2493 case IXGBE_DEV_ID_X550EM_X_SFP:
Mark Rustad2d40cd12016-04-01 12:18:35 -07002494 case IXGBE_DEV_ID_X550EM_A_SFP:
Mark Rustad49425df2016-04-01 12:18:09 -07002495 case IXGBE_DEV_ID_X550EM_A_SFP_N:
Don Skidmore6a14ee02014-12-05 03:59:50 +00002496 media_type = ixgbe_media_type_fiber;
2497 break;
2498 case IXGBE_DEV_ID_X550EM_X_1G_T:
2499 case IXGBE_DEV_ID_X550EM_X_10G_T:
Don Skidmore92ed8432016-08-17 20:34:40 -04002500 case IXGBE_DEV_ID_X550EM_A_10G_T:
Mark Rustad49425df2016-04-01 12:18:09 -07002501 media_type = ixgbe_media_type_copper;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002502 break;
2503 default:
2504 media_type = ixgbe_media_type_unknown;
2505 break;
2506 }
2507 return media_type;
2508}
2509
2510/** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
2511 ** @hw: pointer to hardware structure
2512 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00002513static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002514{
Mark Rustada1e869d2015-04-10 10:36:36 -07002515 s32 status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002516 u16 reg;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002517
Don Skidmore6a14ee02014-12-05 03:59:50 +00002518 status = hw->phy.ops.read_reg(hw,
Don Skidmoree2261bc2015-06-09 17:02:35 -07002519 IXGBE_MDIO_TX_VENDOR_ALARMS_3,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002520 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
2521 &reg);
2522 if (status)
2523 return status;
2524
Don Skidmoree2261bc2015-06-09 17:02:35 -07002525 /* If PHY FW reset completed bit is set then this is the first
2526 * SW instance after a power on so the PHY FW must be un-stalled.
2527 */
2528 if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
2529 status = hw->phy.ops.read_reg(hw,
2530 IXGBE_MDIO_GLOBAL_RES_PR_10,
2531 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2532 &reg);
2533 if (status)
2534 return status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002535
Don Skidmoree2261bc2015-06-09 17:02:35 -07002536 reg &= ~IXGBE_MDIO_POWER_UP_STALL;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002537
Don Skidmoree2261bc2015-06-09 17:02:35 -07002538 status = hw->phy.ops.write_reg(hw,
2539 IXGBE_MDIO_GLOBAL_RES_PR_10,
2540 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2541 reg);
2542 if (status)
2543 return status;
2544 }
Don Skidmore6a14ee02014-12-05 03:59:50 +00002545
Don Skidmore6a14ee02014-12-05 03:59:50 +00002546 return status;
2547}
2548
Mark Rustade84db722016-04-01 12:18:30 -07002549/**
2550 * ixgbe_set_mdio_speed - Set MDIO clock speed
2551 * @hw: pointer to hardware structure
2552 */
2553static void ixgbe_set_mdio_speed(struct ixgbe_hw *hw)
2554{
2555 u32 hlreg0;
2556
2557 switch (hw->device_id) {
2558 case IXGBE_DEV_ID_X550EM_X_10G_T:
Don Skidmorea83c27e2016-08-17 17:34:07 -04002559 case IXGBE_DEV_ID_X550EM_A_SGMII:
2560 case IXGBE_DEV_ID_X550EM_A_SGMII_L:
Don Skidmore92ed8432016-08-17 20:34:40 -04002561 case IXGBE_DEV_ID_X550EM_A_10G_T:
Mark Rustad2d40cd12016-04-01 12:18:35 -07002562 case IXGBE_DEV_ID_X550EM_A_SFP:
Mark Rustade84db722016-04-01 12:18:30 -07002563 /* Config MDIO clock speed before the first MDIO PHY access */
2564 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2565 hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
2566 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2567 break;
2568 default:
2569 break;
2570 }
2571}
2572
Don Skidmore6a14ee02014-12-05 03:59:50 +00002573/** ixgbe_reset_hw_X550em - Perform hardware reset
2574 ** @hw: pointer to hardware structure
2575 **
2576 ** Resets the hardware by resetting the transmit and receive units, masks
2577 ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
2578 ** reset.
2579 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00002580static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002581{
2582 ixgbe_link_speed link_speed;
2583 s32 status;
2584 u32 ctrl = 0;
2585 u32 i;
2586 bool link_up = false;
2587
2588 /* Call adapter stop to disable Tx/Rx and clear interrupts */
2589 status = hw->mac.ops.stop_adapter(hw);
2590 if (status)
2591 return status;
2592
2593 /* flush pending Tx transactions */
2594 ixgbe_clear_tx_pending(hw);
2595
2596 /* PHY ops must be identified and initialized prior to reset */
2597
2598 /* Identify PHY and related function pointers */
2599 status = hw->phy.ops.init(hw);
2600
2601 /* start the external PHY */
2602 if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
2603 status = ixgbe_init_ext_t_x550em(hw);
2604 if (status)
2605 return status;
2606 }
2607
2608 /* Setup SFP module if there is one present. */
2609 if (hw->phy.sfp_setup_needed) {
2610 status = hw->mac.ops.setup_sfp(hw);
2611 hw->phy.sfp_setup_needed = false;
2612 }
2613
2614 /* Reset PHY */
2615 if (!hw->phy.reset_disable && hw->phy.ops.reset)
2616 hw->phy.ops.reset(hw);
2617
2618mac_reset_top:
2619 /* Issue global reset to the MAC. Needs to be SW reset if link is up.
2620 * If link reset is used when link is up, it might reset the PHY when
2621 * mng is using it. If link is down or the flag to force full link
2622 * reset is set, then perform link reset.
2623 */
2624 ctrl = IXGBE_CTRL_LNK_RST;
2625
2626 if (!hw->force_full_reset) {
2627 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
2628 if (link_up)
2629 ctrl = IXGBE_CTRL_RST;
2630 }
2631
2632 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
2633 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
2634 IXGBE_WRITE_FLUSH(hw);
Mark Rustadefff2e02015-10-27 13:23:14 -07002635 usleep_range(1000, 1200);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002636
2637 /* Poll for reset bit to self-clear meaning reset is complete */
2638 for (i = 0; i < 10; i++) {
Don Skidmore6a14ee02014-12-05 03:59:50 +00002639 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
2640 if (!(ctrl & IXGBE_CTRL_RST_MASK))
2641 break;
Mark Rustadefff2e02015-10-27 13:23:14 -07002642 udelay(1);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002643 }
2644
2645 if (ctrl & IXGBE_CTRL_RST_MASK) {
2646 status = IXGBE_ERR_RESET_FAILED;
2647 hw_dbg(hw, "Reset polling failed to complete.\n");
2648 }
2649
2650 msleep(50);
2651
2652 /* Double resets are required for recovery from certain error
2653 * clear the multicast table. Also reset num_rar_entries to 128,
2654 * since we modify this value when programming the SAN MAC address.
2655 */
2656 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
2657 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2658 goto mac_reset_top;
2659 }
2660
2661 /* Store the permanent mac address */
2662 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
2663
2664 /* Store MAC address from RAR0, clear receive address registers, and
2665 * clear the multicast table. Also reset num_rar_entries to 128,
2666 * since we modify this value when programming the SAN MAC address.
2667 */
2668 hw->mac.num_rar_entries = 128;
2669 hw->mac.ops.init_rx_addrs(hw);
2670
Mark Rustade84db722016-04-01 12:18:30 -07002671 ixgbe_set_mdio_speed(hw);
Don Skidmorededa5622015-06-09 17:39:46 -07002672
Don Skidmoreab5fe0c2015-06-09 16:18:56 -07002673 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
2674 ixgbe_setup_mux_ctl(hw);
2675
Don Skidmore6a14ee02014-12-05 03:59:50 +00002676 return status;
2677}
2678
Don Skidmore5b7f0002015-01-28 07:03:38 +00002679/** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype
2680 * anti-spoofing
2681 * @hw: pointer to hardware structure
2682 * @enable: enable or disable switch for Ethertype anti-spoofing
2683 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
2684 **/
Don Skidmorebc035fc2015-03-13 14:03:25 -07002685static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
2686 bool enable, int vf)
Don Skidmore5b7f0002015-01-28 07:03:38 +00002687{
2688 int vf_target_reg = vf >> 3;
2689 int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
2690 u32 pfvfspoof;
2691
2692 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2693 if (enable)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002694 pfvfspoof |= BIT(vf_target_shift);
Don Skidmore5b7f0002015-01-28 07:03:38 +00002695 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002696 pfvfspoof &= ~BIT(vf_target_shift);
Don Skidmore5b7f0002015-01-28 07:03:38 +00002697
2698 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2699}
2700
Don Skidmore6d4c96a2015-04-09 22:03:23 -07002701/** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning
2702 * @hw: pointer to hardware structure
2703 * @enable: enable or disable source address pruning
2704 * @pool: Rx pool to set source address pruning for
2705 **/
2706static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw,
2707 bool enable,
2708 unsigned int pool)
2709{
2710 u64 pfflp;
2711
2712 /* max rx pool is 63 */
2713 if (pool > 63)
2714 return;
2715
2716 pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
2717 pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
2718
2719 if (enable)
2720 pfflp |= (1ULL << pool);
2721 else
2722 pfflp &= ~(1ULL << pool);
2723
2724 IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
2725 IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
2726}
2727
Mark Rustad449e21a2015-08-08 16:18:53 -07002728/**
2729 * ixgbe_set_mux - Set mux for port 1 access with CS4227
2730 * @hw: pointer to hardware structure
2731 * @state: set mux if 1, clear if 0
2732 */
2733static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
2734{
2735 u32 esdp;
2736
2737 if (!hw->bus.lan_id)
2738 return;
2739 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2740 if (state)
2741 esdp |= IXGBE_ESDP_SDP1;
2742 else
2743 esdp &= ~IXGBE_ESDP_SDP1;
2744 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2745 IXGBE_WRITE_FLUSH(hw);
2746}
2747
2748/**
2749 * ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
2750 * @hw: pointer to hardware structure
2751 * @mask: Mask to specify which semaphore to acquire
2752 *
2753 * Acquires the SWFW semaphore and sets the I2C MUX
2754 */
2755static s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
2756{
2757 s32 status;
2758
2759 status = ixgbe_acquire_swfw_sync_X540(hw, mask);
2760 if (status)
2761 return status;
2762
2763 if (mask & IXGBE_GSSR_I2C_MASK)
2764 ixgbe_set_mux(hw, 1);
2765
2766 return 0;
2767}
2768
2769/**
2770 * ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
2771 * @hw: pointer to hardware structure
2772 * @mask: Mask to specify which semaphore to release
2773 *
2774 * Releases the SWFW semaphore and sets the I2C MUX
2775 */
2776static void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
2777{
2778 if (mask & IXGBE_GSSR_I2C_MASK)
2779 ixgbe_set_mux(hw, 0);
2780
2781 ixgbe_release_swfw_sync_X540(hw, mask);
2782}
2783
Mark Rustad49425df2016-04-01 12:18:09 -07002784/**
2785 * ixgbe_acquire_swfw_sync_x550em_a - Acquire SWFW semaphore
2786 * @hw: pointer to hardware structure
2787 * @mask: Mask to specify which semaphore to acquire
2788 *
2789 * Acquires the SWFW semaphore and get the shared PHY token as needed
2790 */
2791static s32 ixgbe_acquire_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
2792{
2793 u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
2794 int retries = FW_PHY_TOKEN_RETRIES;
2795 s32 status;
2796
2797 while (--retries) {
2798 status = 0;
2799 if (hmask)
2800 status = ixgbe_acquire_swfw_sync_X540(hw, hmask);
2801 if (status)
2802 return status;
2803 if (!(mask & IXGBE_GSSR_TOKEN_SM))
2804 return 0;
2805
2806 status = ixgbe_get_phy_token(hw);
2807 if (!status)
2808 return 0;
2809 if (hmask)
2810 ixgbe_release_swfw_sync_X540(hw, hmask);
2811 if (status != IXGBE_ERR_TOKEN_RETRY)
2812 return status;
Arnd Bergmannd4f90d92016-04-16 22:35:08 +02002813 msleep(FW_PHY_TOKEN_DELAY);
Mark Rustad49425df2016-04-01 12:18:09 -07002814 }
2815
2816 return status;
2817}
2818
2819/**
2820 * ixgbe_release_swfw_sync_x550em_a - Release SWFW semaphore
2821 * @hw: pointer to hardware structure
2822 * @mask: Mask to specify which semaphore to release
2823 *
2824 * Release the SWFW semaphore and puts the shared PHY token as needed
2825 */
2826static void ixgbe_release_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
2827{
2828 u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
2829
2830 if (mask & IXGBE_GSSR_TOKEN_SM)
2831 ixgbe_put_phy_token(hw);
2832
2833 if (hmask)
2834 ixgbe_release_swfw_sync_X540(hw, hmask);
2835}
2836
Mark Rustadd31afc82016-04-01 12:18:14 -07002837/**
2838 * ixgbe_read_phy_reg_x550a - Reads specified PHY register
2839 * @hw: pointer to hardware structure
2840 * @reg_addr: 32 bit address of PHY register to read
2841 * @phy_data: Pointer to read data from PHY register
2842 *
2843 * Reads a value from a specified PHY register using the SWFW lock and PHY
2844 * Token. The PHY Token is needed since the MDIO is shared between to MAC
2845 * instances.
2846 */
2847static s32 ixgbe_read_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
2848 u32 device_type, u16 *phy_data)
2849{
2850 u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
2851 s32 status;
2852
2853 if (hw->mac.ops.acquire_swfw_sync(hw, mask))
2854 return IXGBE_ERR_SWFW_SYNC;
2855
2856 status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
2857
2858 hw->mac.ops.release_swfw_sync(hw, mask);
2859
2860 return status;
2861}
2862
2863/**
2864 * ixgbe_write_phy_reg_x550a - Writes specified PHY register
2865 * @hw: pointer to hardware structure
2866 * @reg_addr: 32 bit PHY register to write
2867 * @device_type: 5 bit device type
2868 * @phy_data: Data to write to the PHY register
2869 *
2870 * Writes a value to specified PHY register using the SWFW lock and PHY Token.
2871 * The PHY Token is needed since the MDIO is shared between to MAC instances.
2872 */
2873static s32 ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
2874 u32 device_type, u16 phy_data)
2875{
2876 u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
2877 s32 status;
2878
2879 if (hw->mac.ops.acquire_swfw_sync(hw, mask))
2880 return IXGBE_ERR_SWFW_SYNC;
2881
2882 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type, phy_data);
2883 hw->mac.ops.release_swfw_sync(hw, mask);
2884
2885 return status;
2886}
2887
Don Skidmore6a14ee02014-12-05 03:59:50 +00002888#define X550_COMMON_MAC \
2889 .init_hw = &ixgbe_init_hw_generic, \
2890 .start_hw = &ixgbe_start_hw_X540, \
2891 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
2892 .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
2893 .get_mac_addr = &ixgbe_get_mac_addr_generic, \
2894 .get_device_caps = &ixgbe_get_device_caps_generic, \
2895 .stop_adapter = &ixgbe_stop_adapter_generic, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00002896 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
2897 .read_analog_reg8 = NULL, \
2898 .write_analog_reg8 = NULL, \
2899 .set_rxpba = &ixgbe_set_rxpba_generic, \
2900 .check_link = &ixgbe_check_mac_link_generic, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00002901 .blink_led_start = &ixgbe_blink_led_start_X540, \
2902 .blink_led_stop = &ixgbe_blink_led_stop_X540, \
2903 .set_rar = &ixgbe_set_rar_generic, \
2904 .clear_rar = &ixgbe_clear_rar_generic, \
2905 .set_vmdq = &ixgbe_set_vmdq_generic, \
2906 .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
2907 .clear_vmdq = &ixgbe_clear_vmdq_generic, \
2908 .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
2909 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
2910 .enable_mc = &ixgbe_enable_mc_generic, \
2911 .disable_mc = &ixgbe_disable_mc_generic, \
2912 .clear_vfta = &ixgbe_clear_vfta_generic, \
2913 .set_vfta = &ixgbe_set_vfta_generic, \
2914 .fc_enable = &ixgbe_fc_enable_generic, \
2915 .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, \
2916 .init_uta_tables = &ixgbe_init_uta_tables_generic, \
2917 .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
2918 .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
Don Skidmore6d4c96a2015-04-09 22:03:23 -07002919 .set_source_address_pruning = \
2920 &ixgbe_set_source_address_pruning_X550, \
Don Skidmore5b7f0002015-01-28 07:03:38 +00002921 .set_ethertype_anti_spoofing = \
2922 &ixgbe_set_ethertype_anti_spoofing_X550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00002923 .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
2924 .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
2925 .get_thermal_sensor_data = NULL, \
2926 .init_thermal_sensor_thresh = NULL, \
Don Skidmore1f9ac572015-03-13 13:54:30 -07002927 .enable_rx = &ixgbe_enable_rx_generic, \
2928 .disable_rx = &ixgbe_disable_rx_x550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00002929
Mark Rustad37689012016-01-07 10:13:03 -08002930static const struct ixgbe_mac_operations mac_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00002931 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002932 .led_on = ixgbe_led_on_generic,
2933 .led_off = ixgbe_led_off_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002934 .reset_hw = &ixgbe_reset_hw_X540,
2935 .get_media_type = &ixgbe_get_media_type_X540,
2936 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
2937 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
2938 .setup_link = &ixgbe_setup_mac_link_X540,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002939 .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
Don Skidmore454c65d2015-06-17 20:59:59 -04002940 .get_bus_info = &ixgbe_get_bus_info_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002941 .setup_sfp = NULL,
Mark Rustad449e21a2015-08-08 16:18:53 -07002942 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
2943 .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
Don Skidmoredbd15b82016-03-09 16:45:00 -05002944 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
Mark Rustadafdc71e2016-01-25 16:32:10 -08002945 .prot_autoc_read = prot_autoc_read_generic,
2946 .prot_autoc_write = prot_autoc_write_generic,
2947 .setup_fc = ixgbe_setup_fc_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002948};
2949
Mark Rustad37689012016-01-07 10:13:03 -08002950static const struct ixgbe_mac_operations mac_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00002951 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002952 .led_on = ixgbe_led_on_t_x550em,
2953 .led_off = ixgbe_led_off_t_x550em,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002954 .reset_hw = &ixgbe_reset_hw_X550em,
2955 .get_media_type = &ixgbe_get_media_type_X550em,
2956 .get_san_mac_addr = NULL,
2957 .get_wwn_prefix = NULL,
Emil Tantilov46958862016-03-24 09:58:40 -07002958 .setup_link = &ixgbe_setup_mac_link_X540,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002959 .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
Don Skidmore454c65d2015-06-17 20:59:59 -04002960 .get_bus_info = &ixgbe_get_bus_info_X550em,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002961 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
Mark Rustad449e21a2015-08-08 16:18:53 -07002962 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X550em,
2963 .release_swfw_sync = &ixgbe_release_swfw_sync_X550em,
Don Skidmoredbd15b82016-03-09 16:45:00 -05002964 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
Mark Rustadafdc71e2016-01-25 16:32:10 -08002965 .setup_fc = NULL, /* defined later */
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002966 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550,
2967 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002968};
2969
Mark Rustad49425df2016-04-01 12:18:09 -07002970static struct ixgbe_mac_operations mac_ops_x550em_a = {
2971 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002972 .led_on = ixgbe_led_on_t_x550em,
2973 .led_off = ixgbe_led_off_t_x550em,
Mark Rustad49425df2016-04-01 12:18:09 -07002974 .reset_hw = ixgbe_reset_hw_X550em,
2975 .get_media_type = ixgbe_get_media_type_X550em,
2976 .get_san_mac_addr = NULL,
2977 .get_wwn_prefix = NULL,
Mark Rustada0254a72016-04-08 16:19:29 -07002978 .setup_link = NULL, /* defined later */
Mark Rustad49425df2016-04-01 12:18:09 -07002979 .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
2980 .get_bus_info = ixgbe_get_bus_info_X550em,
2981 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
2982 .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
2983 .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
Mark Rustada0254a72016-04-08 16:19:29 -07002984 .setup_fc = ixgbe_setup_fc_x550em,
Mark Rustad49425df2016-04-01 12:18:09 -07002985 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
2986 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
2987};
2988
Don Skidmore6a14ee02014-12-05 03:59:50 +00002989#define X550_COMMON_EEP \
2990 .read = &ixgbe_read_ee_hostif_X550, \
2991 .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
2992 .write = &ixgbe_write_ee_hostif_X550, \
2993 .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
2994 .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
2995 .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
2996 .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
2997
Mark Rustad37689012016-01-07 10:13:03 -08002998static const struct ixgbe_eeprom_operations eeprom_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00002999 X550_COMMON_EEP
3000 .init_params = &ixgbe_init_eeprom_params_X550,
3001};
3002
Mark Rustad37689012016-01-07 10:13:03 -08003003static const struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003004 X550_COMMON_EEP
3005 .init_params = &ixgbe_init_eeprom_params_X540,
3006};
3007
3008#define X550_COMMON_PHY \
3009 .identify_sfp = &ixgbe_identify_module_generic, \
3010 .reset = NULL, \
3011 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
3012 .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
3013 .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
3014 .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
3015 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
3016 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
Don Skidmorebef23de2015-06-09 17:36:53 -07003017 .setup_link = &ixgbe_setup_phy_link_generic, \
Don Skidmoreb5529ef2015-06-10 20:42:30 -04003018 .set_phy_power = NULL, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003019 .check_overtemp = &ixgbe_tn_check_overtemp, \
3020 .get_firmware_version = &ixgbe_get_phy_firmware_version_generic,
3021
Mark Rustad37689012016-01-07 10:13:03 -08003022static const struct ixgbe_phy_operations phy_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003023 X550_COMMON_PHY
3024 .init = NULL,
3025 .identify = &ixgbe_identify_phy_generic,
Mark Rustadd31afc82016-04-01 12:18:14 -07003026 .read_reg = &ixgbe_read_phy_reg_generic,
3027 .write_reg = &ixgbe_write_phy_reg_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003028};
3029
Mark Rustad37689012016-01-07 10:13:03 -08003030static const struct ixgbe_phy_operations phy_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003031 X550_COMMON_PHY
3032 .init = &ixgbe_init_phy_ops_X550em,
3033 .identify = &ixgbe_identify_phy_x550em,
Mark Rustadd31afc82016-04-01 12:18:14 -07003034 .read_reg = &ixgbe_read_phy_reg_generic,
3035 .write_reg = &ixgbe_write_phy_reg_generic,
Mark Rustad4f9e3a32015-08-08 16:17:57 -07003036 .read_i2c_combined = &ixgbe_read_i2c_combined_generic,
3037 .write_i2c_combined = &ixgbe_write_i2c_combined_generic,
Mark Rustadbb5ce9a2015-08-08 16:18:02 -07003038 .read_i2c_combined_unlocked = &ixgbe_read_i2c_combined_generic_unlocked,
3039 .write_i2c_combined_unlocked =
3040 &ixgbe_write_i2c_combined_generic_unlocked,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003041};
3042
Mark Rustadd31afc82016-04-01 12:18:14 -07003043static const struct ixgbe_phy_operations phy_ops_x550em_a = {
3044 X550_COMMON_PHY
3045 .init = &ixgbe_init_phy_ops_X550em,
3046 .identify = &ixgbe_identify_phy_x550em,
3047 .read_reg = &ixgbe_read_phy_reg_x550a,
3048 .write_reg = &ixgbe_write_phy_reg_x550a,
Mark Rustad8fe293a2016-08-26 14:48:28 -07003049 .read_reg_mdi = &ixgbe_read_phy_reg_mdi,
3050 .write_reg_mdi = &ixgbe_write_phy_reg_mdi,
Mark Rustadd31afc82016-04-01 12:18:14 -07003051};
3052
Don Skidmore9a900ec2015-06-09 17:15:01 -07003053static const u32 ixgbe_mvals_X550[IXGBE_MVALS_IDX_LIMIT] = {
3054 IXGBE_MVALS_INIT(X550)
3055};
3056
3057static const u32 ixgbe_mvals_X550EM_x[IXGBE_MVALS_IDX_LIMIT] = {
3058 IXGBE_MVALS_INIT(X550EM_x)
3059};
3060
Mark Rustad49425df2016-04-01 12:18:09 -07003061static const u32 ixgbe_mvals_x550em_a[IXGBE_MVALS_IDX_LIMIT] = {
3062 IXGBE_MVALS_INIT(X550EM_a)
3063};
3064
Mark Rustad37689012016-01-07 10:13:03 -08003065const struct ixgbe_info ixgbe_X550_info = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003066 .mac = ixgbe_mac_X550,
3067 .get_invariants = &ixgbe_get_invariants_X540,
3068 .mac_ops = &mac_ops_X550,
3069 .eeprom_ops = &eeprom_ops_X550,
3070 .phy_ops = &phy_ops_X550,
3071 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07003072 .mvals = ixgbe_mvals_X550,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003073};
3074
Mark Rustad37689012016-01-07 10:13:03 -08003075const struct ixgbe_info ixgbe_X550EM_x_info = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003076 .mac = ixgbe_mac_X550EM_x,
Don Skidmoreb5529ef2015-06-10 20:42:30 -04003077 .get_invariants = &ixgbe_get_invariants_X550_x,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003078 .mac_ops = &mac_ops_X550EM_x,
3079 .eeprom_ops = &eeprom_ops_X550EM_x,
3080 .phy_ops = &phy_ops_X550EM_x,
3081 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07003082 .mvals = ixgbe_mvals_X550EM_x,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003083};
Mark Rustad49425df2016-04-01 12:18:09 -07003084
3085const struct ixgbe_info ixgbe_x550em_a_info = {
3086 .mac = ixgbe_mac_x550em_a,
3087 .get_invariants = &ixgbe_get_invariants_X550_x,
3088 .mac_ops = &mac_ops_x550em_a,
3089 .eeprom_ops = &eeprom_ops_X550EM_x,
Mark Rustadd31afc82016-04-01 12:18:14 -07003090 .phy_ops = &phy_ops_x550em_a,
Mark Rustad49425df2016-04-01 12:18:09 -07003091 .mbx_ops = &mbx_ops_generic,
3092 .mvals = ixgbe_mvals_x550em_a,
3093};