blob: 58d3bcaca2b9a9e89508a2f5f41521d6c385c1c6 [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 *);
Don Skidmore29165002016-09-27 14:31:12 -040031static void ixgbe_fc_autoneg_fiber_x550em_a(struct ixgbe_hw *);
32static void ixgbe_fc_autoneg_backplane_x550em_a(struct ixgbe_hw *);
33static s32 ixgbe_setup_fc_backplane_x550em_a(struct ixgbe_hw *);
Mark Rustadd91e3a72015-09-28 14:37:47 -070034
Don Skidmoreb5529ef2015-06-10 20:42:30 -040035static s32 ixgbe_get_invariants_X550_x(struct ixgbe_hw *hw)
36{
37 struct ixgbe_mac_info *mac = &hw->mac;
38 struct ixgbe_phy_info *phy = &hw->phy;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070039 struct ixgbe_link_info *link = &hw->link;
40
41 /* Start with X540 invariants, since so simular */
42 ixgbe_get_invariants_X540(hw);
43
44 if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
45 phy->ops.set_phy_power = NULL;
46
47 link->addr = IXGBE_CS4227;
48
49 return 0;
50}
51
52static s32 ixgbe_get_invariants_X550_a(struct ixgbe_hw *hw)
53{
54 struct ixgbe_mac_info *mac = &hw->mac;
55 struct ixgbe_phy_info *phy = &hw->phy;
Don Skidmoreb5529ef2015-06-10 20:42:30 -040056
57 /* Start with X540 invariants, since so simular */
58 ixgbe_get_invariants_X540(hw);
59
60 if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
61 phy->ops.set_phy_power = NULL;
62
63 return 0;
64}
65
Mark Rustadb3eb4e12016-12-14 11:02:16 -080066static s32 ixgbe_get_invariants_X550_a_fw(struct ixgbe_hw *hw)
67{
68 struct ixgbe_phy_info *phy = &hw->phy;
69
70 /* Start with X540 invariants, since so similar */
71 ixgbe_get_invariants_X540(hw);
72
73 phy->ops.set_phy_power = NULL;
74
75 return 0;
76}
77
Don Skidmoreab5fe0c2015-06-09 16:18:56 -070078/** ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
79 * @hw: pointer to hardware structure
80 **/
81static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
82{
83 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
84
85 if (hw->bus.lan_id) {
86 esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
87 esdp |= IXGBE_ESDP_SDP1_DIR;
88 }
89 esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
90 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
91 IXGBE_WRITE_FLUSH(hw);
92}
93
Mark Rustad542b6ee2015-08-08 16:18:38 -070094/**
95 * ixgbe_read_cs4227 - Read CS4227 register
96 * @hw: pointer to hardware structure
97 * @reg: register number to write
98 * @value: pointer to receive value read
99 *
100 * Returns status code
101 */
102static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
103{
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700104 return hw->link.ops.read_link_unlocked(hw, hw->link.addr, reg, value);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700105}
106
107/**
108 * ixgbe_write_cs4227 - Write CS4227 register
109 * @hw: pointer to hardware structure
110 * @reg: register number to write
111 * @value: value to write to register
112 *
113 * Returns status code
114 */
115static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
116{
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700117 return hw->link.ops.write_link_unlocked(hw, hw->link.addr, reg, value);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700118}
119
120/**
Mark Rustad542b6ee2015-08-08 16:18:38 -0700121 * ixgbe_read_pe - Read register from port expander
122 * @hw: pointer to hardware structure
123 * @reg: register number to read
124 * @value: pointer to receive read value
125 *
126 * Returns status code
127 */
128static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
129{
130 s32 status;
131
132 status = ixgbe_read_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE, value);
133 if (status)
134 hw_err(hw, "port expander access failed with %d\n", status);
135 return status;
136}
137
138/**
139 * ixgbe_write_pe - Write register to port expander
140 * @hw: pointer to hardware structure
141 * @reg: register number to write
142 * @value: value to write
143 *
144 * Returns status code
145 */
146static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
147{
148 s32 status;
149
150 status = ixgbe_write_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE,
151 value);
152 if (status)
153 hw_err(hw, "port expander access failed with %d\n", status);
154 return status;
155}
156
157/**
158 * ixgbe_reset_cs4227 - Reset CS4227 using port expander
159 * @hw: pointer to hardware structure
160 *
Mark Rustad8bf7a7b2015-08-26 14:10:22 -0700161 * This function assumes that the caller has acquired the proper semaphore.
Mark Rustad542b6ee2015-08-08 16:18:38 -0700162 * Returns error code
163 */
164static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
165{
166 s32 status;
167 u32 retry;
168 u16 value;
169 u8 reg;
170
171 /* Trigger hard reset. */
172 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
173 if (status)
174 return status;
175 reg |= IXGBE_PE_BIT1;
176 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
177 if (status)
178 return status;
179
180 status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, &reg);
181 if (status)
182 return status;
183 reg &= ~IXGBE_PE_BIT1;
184 status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
185 if (status)
186 return status;
187
188 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
189 if (status)
190 return status;
191 reg &= ~IXGBE_PE_BIT1;
192 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
193 if (status)
194 return status;
195
196 usleep_range(IXGBE_CS4227_RESET_HOLD, IXGBE_CS4227_RESET_HOLD + 100);
197
198 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
199 if (status)
200 return status;
201 reg |= IXGBE_PE_BIT1;
202 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
203 if (status)
204 return status;
205
206 /* Wait for the reset to complete. */
207 msleep(IXGBE_CS4227_RESET_DELAY);
208 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
209 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
210 &value);
211 if (!status && value == IXGBE_CS4227_EEPROM_LOAD_OK)
212 break;
213 msleep(IXGBE_CS4227_CHECK_DELAY);
214 }
215 if (retry == IXGBE_CS4227_RETRIES) {
216 hw_err(hw, "CS4227 reset did not complete\n");
217 return IXGBE_ERR_PHY;
218 }
219
220 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
221 if (status || !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
222 hw_err(hw, "CS4227 EEPROM did not load successfully\n");
223 return IXGBE_ERR_PHY;
224 }
225
226 return 0;
227}
228
229/**
230 * ixgbe_check_cs4227 - Check CS4227 and reset as needed
231 * @hw: pointer to hardware structure
232 */
233static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
234{
235 u32 swfw_mask = hw->phy.phy_semaphore_mask;
236 s32 status;
237 u16 value;
238 u8 retry;
239
240 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
241 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
242 if (status) {
243 hw_err(hw, "semaphore failed with %d\n", status);
244 msleep(IXGBE_CS4227_CHECK_DELAY);
245 continue;
246 }
247
248 /* Get status of reset flow. */
249 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
250 if (!status && value == IXGBE_CS4227_RESET_COMPLETE)
251 goto out;
252
253 if (status || value != IXGBE_CS4227_RESET_PENDING)
254 break;
255
256 /* Reset is pending. Wait and check again. */
257 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
258 msleep(IXGBE_CS4227_CHECK_DELAY);
259 }
Mark Rustad8bf7a7b2015-08-26 14:10:22 -0700260 /* If still pending, assume other instance failed. */
261 if (retry == IXGBE_CS4227_RETRIES) {
262 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
263 if (status) {
264 hw_err(hw, "semaphore failed with %d\n", status);
265 return;
266 }
267 }
Mark Rustad542b6ee2015-08-08 16:18:38 -0700268
269 /* Reset the CS4227. */
270 status = ixgbe_reset_cs4227(hw);
271 if (status) {
272 hw_err(hw, "CS4227 reset failed: %d", status);
273 goto out;
274 }
275
276 /* Reset takes so long, temporarily release semaphore in case the
277 * other driver instance is waiting for the reset indication.
278 */
279 ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
280 IXGBE_CS4227_RESET_PENDING);
281 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
282 usleep_range(10000, 12000);
283 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
284 if (status) {
285 hw_err(hw, "semaphore failed with %d", status);
286 return;
287 }
288
Mark Rustad542b6ee2015-08-08 16:18:38 -0700289 /* Record completion for next time. */
290 status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
291 IXGBE_CS4227_RESET_COMPLETE);
292
293out:
294 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
295 msleep(hw->eeprom.semaphore_delay);
296}
297
Don Skidmore6a14ee02014-12-05 03:59:50 +0000298/** ixgbe_identify_phy_x550em - Get PHY type based on device id
299 * @hw: pointer to hardware structure
300 *
301 * Returns error code
302 */
303static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
304{
Don Skidmore6a14ee02014-12-05 03:59:50 +0000305 switch (hw->device_id) {
Mark Rustad2d40cd12016-04-01 12:18:35 -0700306 case IXGBE_DEV_ID_X550EM_A_SFP:
307 if (hw->bus.lan_id)
308 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
309 else
310 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
311 return ixgbe_identify_module_generic(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000312 case IXGBE_DEV_ID_X550EM_X_SFP:
313 /* set up for CS4227 usage */
314 hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
Don Skidmoreab5fe0c2015-06-09 16:18:56 -0700315 ixgbe_setup_mux_ctl(hw);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700316 ixgbe_check_cs4227(hw);
Mark Rustad49425df2016-04-01 12:18:09 -0700317 /* Fallthrough */
318 case IXGBE_DEV_ID_X550EM_A_SFP_N:
Don Skidmore6a14ee02014-12-05 03:59:50 +0000319 return ixgbe_identify_module_generic(hw);
320 case IXGBE_DEV_ID_X550EM_X_KX4:
321 hw->phy.type = ixgbe_phy_x550em_kx4;
322 break;
Don Skidmore18e01ee2016-12-30 21:07:58 -0500323 case IXGBE_DEV_ID_X550EM_X_XFI:
324 hw->phy.type = ixgbe_phy_x550em_xfi;
325 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000326 case IXGBE_DEV_ID_X550EM_X_KR:
Mark Rustadf572b2c2016-04-01 12:18:46 -0700327 case IXGBE_DEV_ID_X550EM_A_KR:
328 case IXGBE_DEV_ID_X550EM_A_KR_L:
Don Skidmore6a14ee02014-12-05 03:59:50 +0000329 hw->phy.type = ixgbe_phy_x550em_kr;
330 break;
Don Skidmore92ed8432016-08-17 20:34:40 -0400331 case IXGBE_DEV_ID_X550EM_A_10G_T:
332 if (hw->bus.lan_id)
333 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
334 else
335 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
336 /* Fallthrough */
Don Skidmore6a14ee02014-12-05 03:59:50 +0000337 case IXGBE_DEV_ID_X550EM_X_1G_T:
338 case IXGBE_DEV_ID_X550EM_X_10G_T:
339 return ixgbe_identify_phy_generic(hw);
Don Skidmore18bda0d2016-12-30 21:07:14 -0500340 case IXGBE_DEV_ID_X550EM_A_1G_T:
341 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
342 hw->phy.type = ixgbe_phy_fw;
343 hw->phy.ops.read_reg = NULL;
344 hw->phy.ops.write_reg = NULL;
345 if (hw->bus.lan_id)
346 hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY1_SM;
347 else
348 hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY0_SM;
349 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000350 default:
351 break;
352 }
353 return 0;
354}
355
356static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
357 u32 device_type, u16 *phy_data)
358{
359 return IXGBE_NOT_IMPLEMENTED;
360}
361
362static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
363 u32 device_type, u16 phy_data)
364{
365 return IXGBE_NOT_IMPLEMENTED;
366}
367
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700368/**
369 * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
370 * @hw: pointer to the hardware structure
371 * @addr: I2C bus address to read from
372 * @reg: I2C device register to read from
373 * @val: pointer to location to receive read value
374 *
375 * Returns an error code on error.
376 **/
377static s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
378 u16 reg, u16 *val)
379{
380 return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, true);
381}
382
383/**
384 * ixgbe_read_i2c_combined_generic_unlocked - Do I2C read combined operation
385 * @hw: pointer to the hardware structure
386 * @addr: I2C bus address to read from
387 * @reg: I2C device register to read from
388 * @val: pointer to location to receive read value
389 *
390 * Returns an error code on error.
391 **/
392static s32
393ixgbe_read_i2c_combined_generic_unlocked(struct ixgbe_hw *hw, u8 addr,
394 u16 reg, u16 *val)
395{
396 return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, false);
397}
398
399/**
400 * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
401 * @hw: pointer to the hardware structure
402 * @addr: I2C bus address to write to
403 * @reg: I2C device register to write to
404 * @val: value to write
405 *
406 * Returns an error code on error.
407 **/
408static s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
409 u8 addr, u16 reg, u16 val)
410{
411 return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, true);
412}
413
414/**
415 * ixgbe_write_i2c_combined_generic_unlocked - Do I2C write combined operation
416 * @hw: pointer to the hardware structure
417 * @addr: I2C bus address to write to
418 * @reg: I2C device register to write to
419 * @val: value to write
420 *
421 * Returns an error code on error.
422 **/
423static s32
424ixgbe_write_i2c_combined_generic_unlocked(struct ixgbe_hw *hw,
425 u8 addr, u16 reg, u16 val)
426{
427 return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, false);
428}
429
Mark Rustad12c78ef2016-12-14 11:02:11 -0800430/**
431 * ixgbe_fw_phy_activity - Perform an activity on a PHY
432 * @hw: pointer to hardware structure
433 * @activity: activity to perform
434 * @data: Pointer to 4 32-bit words of data
435 */
436s32 ixgbe_fw_phy_activity(struct ixgbe_hw *hw, u16 activity,
437 u32 (*data)[FW_PHY_ACT_DATA_COUNT])
438{
439 union {
440 struct ixgbe_hic_phy_activity_req cmd;
441 struct ixgbe_hic_phy_activity_resp rsp;
442 } hic;
443 u16 retries = FW_PHY_ACT_RETRIES;
444 s32 rc;
445 u32 i;
446
447 do {
448 memset(&hic, 0, sizeof(hic));
449 hic.cmd.hdr.cmd = FW_PHY_ACT_REQ_CMD;
450 hic.cmd.hdr.buf_len = FW_PHY_ACT_REQ_LEN;
451 hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
452 hic.cmd.port_number = hw->bus.lan_id;
453 hic.cmd.activity_id = cpu_to_le16(activity);
454 for (i = 0; i < ARRAY_SIZE(hic.cmd.data); ++i)
455 hic.cmd.data[i] = cpu_to_be32((*data)[i]);
456
457 rc = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
458 IXGBE_HI_COMMAND_TIMEOUT,
459 true);
460 if (rc)
461 return rc;
462 if (hic.rsp.hdr.cmd_or_resp.ret_status ==
463 FW_CEM_RESP_STATUS_SUCCESS) {
464 for (i = 0; i < FW_PHY_ACT_DATA_COUNT; ++i)
465 (*data)[i] = be32_to_cpu(hic.rsp.data[i]);
466 return 0;
467 }
468 usleep_range(20, 30);
469 --retries;
470 } while (retries > 0);
471
472 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
473}
474
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800475static const struct {
476 u16 fw_speed;
477 ixgbe_link_speed phy_speed;
478} ixgbe_fw_map[] = {
479 { FW_PHY_ACT_LINK_SPEED_10, IXGBE_LINK_SPEED_10_FULL },
480 { FW_PHY_ACT_LINK_SPEED_100, IXGBE_LINK_SPEED_100_FULL },
481 { FW_PHY_ACT_LINK_SPEED_1G, IXGBE_LINK_SPEED_1GB_FULL },
482 { FW_PHY_ACT_LINK_SPEED_2_5G, IXGBE_LINK_SPEED_2_5GB_FULL },
483 { FW_PHY_ACT_LINK_SPEED_5G, IXGBE_LINK_SPEED_5GB_FULL },
484 { FW_PHY_ACT_LINK_SPEED_10G, IXGBE_LINK_SPEED_10GB_FULL },
485};
486
487/**
488 * ixgbe_get_phy_id_fw - Get the phy ID via firmware command
489 * @hw: pointer to hardware structure
490 *
491 * Returns error code
492 */
493static s32 ixgbe_get_phy_id_fw(struct ixgbe_hw *hw)
494{
495 u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
496 u16 phy_speeds;
497 u16 phy_id_lo;
498 s32 rc;
499 u16 i;
500
501 if (hw->phy.id)
502 return 0;
503
504 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_PHY_INFO, &info);
505 if (rc)
506 return rc;
507
508 hw->phy.speeds_supported = 0;
509 phy_speeds = info[0] & FW_PHY_INFO_SPEED_MASK;
510 for (i = 0; i < ARRAY_SIZE(ixgbe_fw_map); ++i) {
511 if (phy_speeds & ixgbe_fw_map[i].fw_speed)
512 hw->phy.speeds_supported |= ixgbe_fw_map[i].phy_speed;
513 }
514
515 hw->phy.id = info[0] & FW_PHY_INFO_ID_HI_MASK;
516 phy_id_lo = info[1] & FW_PHY_INFO_ID_LO_MASK;
517 hw->phy.id |= phy_id_lo & IXGBE_PHY_REVISION_MASK;
518 hw->phy.revision = phy_id_lo & ~IXGBE_PHY_REVISION_MASK;
519 if (!hw->phy.id || hw->phy.id == IXGBE_PHY_REVISION_MASK)
520 return IXGBE_ERR_PHY_ADDR_INVALID;
521
522 hw->phy.autoneg_advertised = hw->phy.speeds_supported;
523 hw->phy.eee_speeds_supported = IXGBE_LINK_SPEED_100_FULL |
524 IXGBE_LINK_SPEED_1GB_FULL;
525 hw->phy.eee_speeds_advertised = hw->phy.eee_speeds_supported;
526 return 0;
527}
528
529/**
530 * ixgbe_identify_phy_fw - Get PHY type based on firmware command
531 * @hw: pointer to hardware structure
532 *
533 * Returns error code
534 */
535static s32 ixgbe_identify_phy_fw(struct ixgbe_hw *hw)
536{
537 if (hw->bus.lan_id)
538 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
539 else
540 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
541
542 hw->phy.type = ixgbe_phy_fw;
543 hw->phy.ops.read_reg = NULL;
544 hw->phy.ops.write_reg = NULL;
545 return ixgbe_get_phy_id_fw(hw);
546}
547
548/**
549 * ixgbe_shutdown_fw_phy - Shutdown a firmware-controlled PHY
550 * @hw: pointer to hardware structure
551 *
552 * Returns error code
553 */
554static s32 ixgbe_shutdown_fw_phy(struct ixgbe_hw *hw)
555{
556 u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
557
558 setup[0] = FW_PHY_ACT_FORCE_LINK_DOWN_OFF;
559 return ixgbe_fw_phy_activity(hw, FW_PHY_ACT_FORCE_LINK_DOWN, &setup);
560}
561
562/**
563 * ixgbe_setup_fw_link - Setup firmware-controlled PHYs
564 * @hw: pointer to hardware structure
565 */
566static s32 ixgbe_setup_fw_link(struct ixgbe_hw *hw)
567{
568 u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
569 s32 rc;
570 u16 i;
571
572 if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
573 return 0;
574
575 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
576 hw_err(hw, "rx_pause not valid in strict IEEE mode\n");
577 return IXGBE_ERR_INVALID_LINK_SETTINGS;
578 }
579
580 switch (hw->fc.requested_mode) {
581 case ixgbe_fc_full:
582 setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RXTX <<
583 FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
584 break;
585 case ixgbe_fc_rx_pause:
586 setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RX <<
587 FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
588 break;
589 case ixgbe_fc_tx_pause:
590 setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_TX <<
591 FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
592 break;
593 default:
594 break;
595 }
596
597 for (i = 0; i < ARRAY_SIZE(ixgbe_fw_map); ++i) {
598 if (hw->phy.autoneg_advertised & ixgbe_fw_map[i].phy_speed)
599 setup[0] |= ixgbe_fw_map[i].fw_speed;
600 }
601 setup[0] |= FW_PHY_ACT_SETUP_LINK_HP | FW_PHY_ACT_SETUP_LINK_AN;
602
603 if (hw->phy.eee_speeds_advertised)
604 setup[0] |= FW_PHY_ACT_SETUP_LINK_EEE;
605
606 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_SETUP_LINK, &setup);
607 if (rc)
608 return rc;
609 if (setup[0] == FW_PHY_ACT_SETUP_LINK_RSP_DOWN)
610 return IXGBE_ERR_OVERTEMP;
611 return 0;
612}
613
614/**
615 * ixgbe_fc_autoneg_fw - Set up flow control for FW-controlled PHYs
616 * @hw: pointer to hardware structure
617 *
618 * Called at init time to set up flow control.
619 */
620static s32 ixgbe_fc_autoneg_fw(struct ixgbe_hw *hw)
621{
622 if (hw->fc.requested_mode == ixgbe_fc_default)
623 hw->fc.requested_mode = ixgbe_fc_full;
624
625 return ixgbe_setup_fw_link(hw);
626}
627
Don Skidmore6a14ee02014-12-05 03:59:50 +0000628/** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
629 * @hw: pointer to hardware structure
630 *
631 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
632 * ixgbe_hw struct in order to set up EEPROM access.
633 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000634static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000635{
636 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
637 u32 eec;
638 u16 eeprom_size;
639
640 if (eeprom->type == ixgbe_eeprom_uninitialized) {
641 eeprom->semaphore_delay = 10;
642 eeprom->type = ixgbe_flash;
643
Don Skidmore9a900ec2015-06-09 17:15:01 -0700644 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Don Skidmore6a14ee02014-12-05 03:59:50 +0000645 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
646 IXGBE_EEC_SIZE_SHIFT);
Jacob Kellerb4f47a42016-04-13 16:08:22 -0700647 eeprom->word_size = BIT(eeprom_size +
648 IXGBE_EEPROM_WORD_SIZE_SHIFT);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000649
650 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
651 eeprom->type, eeprom->word_size);
652 }
653
654 return 0;
655}
656
Mark Rustadae14a1d2015-04-10 10:36:26 -0700657/**
658 * ixgbe_iosf_wait - Wait for IOSF command completion
659 * @hw: pointer to hardware structure
660 * @ctrl: pointer to location to receive final IOSF control value
661 *
662 * Return: failing status on timeout
663 *
664 * Note: ctrl can be NULL if the IOSF control register value is not needed
665 */
666static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
667{
668 u32 i, command;
669
670 /* Check every 10 usec to see if the address cycle completed.
671 * The SB IOSF BUSY bit will clear when the operation is
672 * complete.
673 */
674 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
675 command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
676 if (!(command & IXGBE_SB_IOSF_CTRL_BUSY))
677 break;
Mark Rustadd90b5b02016-01-29 14:44:29 -0800678 udelay(10);
Mark Rustadae14a1d2015-04-10 10:36:26 -0700679 }
680 if (ctrl)
681 *ctrl = command;
682 if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
683 hw_dbg(hw, "IOSF wait timed out\n");
684 return IXGBE_ERR_PHY;
685 }
686
687 return 0;
688}
689
Don Skidmore6a14ee02014-12-05 03:59:50 +0000690/** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the
691 * IOSF device
692 * @hw: pointer to hardware structure
693 * @reg_addr: 32 bit PHY register to write
694 * @device_type: 3 bit device type
695 * @phy_data: Pointer to read data from the register
696 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000697static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
698 u32 device_type, u32 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000699{
Mark Rustadae14a1d2015-04-10 10:36:26 -0700700 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
701 u32 command, error;
702 s32 ret;
703
704 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
705 if (ret)
706 return ret;
707
708 ret = ixgbe_iosf_wait(hw, NULL);
709 if (ret)
710 goto out;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000711
712 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
713 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
714
715 /* Write IOSF control register */
716 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
717
Mark Rustadae14a1d2015-04-10 10:36:26 -0700718 ret = ixgbe_iosf_wait(hw, &command);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000719
720 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
721 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
722 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
723 hw_dbg(hw, "Failed to read, error %x\n", error);
724 return IXGBE_ERR_PHY;
725 }
726
Mark Rustadae14a1d2015-04-10 10:36:26 -0700727 if (!ret)
728 *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000729
Mark Rustadae14a1d2015-04-10 10:36:26 -0700730out:
731 hw->mac.ops.release_swfw_sync(hw, gssr);
732 return ret;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000733}
734
Mark Rustad49425df2016-04-01 12:18:09 -0700735/**
736 * ixgbe_get_phy_token - Get the token for shared PHY access
737 * @hw: Pointer to hardware structure
738 */
739static s32 ixgbe_get_phy_token(struct ixgbe_hw *hw)
740{
741 struct ixgbe_hic_phy_token_req token_cmd;
742 s32 status;
743
744 token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
745 token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
746 token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
747 token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
748 token_cmd.port_number = hw->bus.lan_id;
749 token_cmd.command_type = FW_PHY_TOKEN_REQ;
750 token_cmd.pad = 0;
751 status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
752 IXGBE_HI_COMMAND_TIMEOUT,
753 true);
754 if (status)
755 return status;
756 if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
757 return 0;
758 if (token_cmd.hdr.cmd_or_resp.ret_status != FW_PHY_TOKEN_RETRY)
759 return IXGBE_ERR_FW_RESP_INVALID;
760
761 return IXGBE_ERR_TOKEN_RETRY;
762}
763
764/**
765 * ixgbe_put_phy_token - Put the token for shared PHY access
766 * @hw: Pointer to hardware structure
767 */
768static s32 ixgbe_put_phy_token(struct ixgbe_hw *hw)
769{
770 struct ixgbe_hic_phy_token_req token_cmd;
771 s32 status;
772
773 token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
774 token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
775 token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
776 token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
777 token_cmd.port_number = hw->bus.lan_id;
778 token_cmd.command_type = FW_PHY_TOKEN_REL;
779 token_cmd.pad = 0;
780 status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
781 IXGBE_HI_COMMAND_TIMEOUT,
782 true);
783 if (status)
784 return status;
785 if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
786 return 0;
787 return IXGBE_ERR_FW_RESP_INVALID;
788}
789
790/**
791 * ixgbe_write_iosf_sb_reg_x550a - Write to IOSF PHY register
792 * @hw: pointer to hardware structure
793 * @reg_addr: 32 bit PHY register to write
794 * @device_type: 3 bit device type
795 * @data: Data to write to the register
796 **/
797static s32 ixgbe_write_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
798 __always_unused u32 device_type,
799 u32 data)
800{
801 struct ixgbe_hic_internal_phy_req write_cmd;
802
803 memset(&write_cmd, 0, sizeof(write_cmd));
804 write_cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
805 write_cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
806 write_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
807 write_cmd.port_number = hw->bus.lan_id;
808 write_cmd.command_type = FW_INT_PHY_REQ_WRITE;
809 write_cmd.address = cpu_to_be16(reg_addr);
810 write_cmd.write_data = cpu_to_be32(data);
811
812 return ixgbe_host_interface_command(hw, &write_cmd, sizeof(write_cmd),
813 IXGBE_HI_COMMAND_TIMEOUT, false);
814}
815
816/**
817 * ixgbe_read_iosf_sb_reg_x550a - Read from IOSF PHY register
818 * @hw: pointer to hardware structure
819 * @reg_addr: 32 bit PHY register to write
820 * @device_type: 3 bit device type
821 * @data: Pointer to read data from the register
822 **/
823static s32 ixgbe_read_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
824 __always_unused u32 device_type,
825 u32 *data)
826{
827 union {
828 struct ixgbe_hic_internal_phy_req cmd;
829 struct ixgbe_hic_internal_phy_resp rsp;
830 } hic;
831 s32 status;
832
833 memset(&hic, 0, sizeof(hic));
834 hic.cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
835 hic.cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
836 hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
837 hic.cmd.port_number = hw->bus.lan_id;
838 hic.cmd.command_type = FW_INT_PHY_REQ_READ;
839 hic.cmd.address = cpu_to_be16(reg_addr);
840
841 status = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
842 IXGBE_HI_COMMAND_TIMEOUT, true);
843
844 /* Extract the register value from the response. */
845 *data = be32_to_cpu(hic.rsp.read_data);
846
847 return status;
848}
849
Don Skidmore6a14ee02014-12-05 03:59:50 +0000850/** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
851 * @hw: pointer to hardware structure
852 * @offset: offset of word in the EEPROM to read
853 * @words: number of words
854 * @data: word(s) read from the EEPROM
855 *
856 * Reads a 16 bit word(s) from the EEPROM using the hostif.
857 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000858static s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
859 u16 offset, u16 words, u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000860{
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800861 const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000862 struct ixgbe_hic_read_shadow_ram buffer;
863 u32 current_word = 0;
864 u16 words_to_read;
865 s32 status;
866 u32 i;
867
868 /* Take semaphore for the entire operation. */
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800869 status = hw->mac.ops.acquire_swfw_sync(hw, mask);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000870 if (status) {
871 hw_dbg(hw, "EEPROM read buffer - semaphore failed\n");
872 return status;
873 }
874
875 while (words) {
876 if (words > FW_MAX_READ_BUFFER_SIZE / 2)
877 words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
878 else
879 words_to_read = words;
880
881 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
882 buffer.hdr.req.buf_lenh = 0;
883 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
884 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
885
886 /* convert offset from words to bytes */
887 buffer.address = cpu_to_be32((offset + current_word) * 2);
888 buffer.length = cpu_to_be16(words_to_read * 2);
889
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800890 status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
891 IXGBE_HI_COMMAND_TIMEOUT);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000892 if (status) {
893 hw_dbg(hw, "Host interface command failed\n");
894 goto out;
895 }
896
897 for (i = 0; i < words_to_read; i++) {
898 u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
899 2 * i;
900 u32 value = IXGBE_READ_REG(hw, reg);
901
902 data[current_word] = (u16)(value & 0xffff);
903 current_word++;
904 i++;
905 if (i < words_to_read) {
906 value >>= 16;
907 data[current_word] = (u16)(value & 0xffff);
908 current_word++;
909 }
910 }
911 words -= words_to_read;
912 }
913
914out:
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800915 hw->mac.ops.release_swfw_sync(hw, mask);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000916 return status;
917}
918
919/** ixgbe_checksum_ptr_x550 - Checksum one pointer region
920 * @hw: pointer to hardware structure
921 * @ptr: pointer offset in eeprom
922 * @size: size of section pointed by ptr, if 0 first word will be used as size
923 * @csum: address of checksum to update
924 *
925 * Returns error status for any failure
926 **/
927static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
928 u16 size, u16 *csum, u16 *buffer,
929 u32 buffer_size)
930{
931 u16 buf[256];
932 s32 status;
933 u16 length, bufsz, i, start;
934 u16 *local_buffer;
935
936 bufsz = sizeof(buf) / sizeof(buf[0]);
937
938 /* Read a chunk at the pointer location */
939 if (!buffer) {
940 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
941 if (status) {
942 hw_dbg(hw, "Failed to read EEPROM image\n");
943 return status;
944 }
945 local_buffer = buf;
946 } else {
947 if (buffer_size < ptr)
948 return IXGBE_ERR_PARAM;
949 local_buffer = &buffer[ptr];
950 }
951
952 if (size) {
953 start = 0;
954 length = size;
955 } else {
956 start = 1;
957 length = local_buffer[0];
958
959 /* Skip pointer section if length is invalid. */
960 if (length == 0xFFFF || length == 0 ||
961 (ptr + length) >= hw->eeprom.word_size)
962 return 0;
963 }
964
965 if (buffer && ((u32)start + (u32)length > buffer_size))
966 return IXGBE_ERR_PARAM;
967
968 for (i = start; length; i++, length--) {
969 if (i == bufsz && !buffer) {
970 ptr += bufsz;
971 i = 0;
972 if (length < bufsz)
973 bufsz = length;
974
975 /* Read a chunk at the pointer location */
976 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
977 bufsz, buf);
978 if (status) {
979 hw_dbg(hw, "Failed to read EEPROM image\n");
980 return status;
981 }
982 }
983 *csum += local_buffer[i];
984 }
985 return 0;
986}
987
988/** ixgbe_calc_checksum_X550 - Calculates and returns the checksum
989 * @hw: pointer to hardware structure
990 * @buffer: pointer to buffer containing calculated checksum
991 * @buffer_size: size of buffer
992 *
993 * Returns a negative error code on error, or the 16-bit checksum
994 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000995static s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer,
996 u32 buffer_size)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000997{
998 u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
999 u16 *local_buffer;
1000 s32 status;
1001 u16 checksum = 0;
1002 u16 pointer, i, size;
1003
1004 hw->eeprom.ops.init_params(hw);
1005
1006 if (!buffer) {
1007 /* Read pointer area */
1008 status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
1009 IXGBE_EEPROM_LAST_WORD + 1,
1010 eeprom_ptrs);
1011 if (status) {
1012 hw_dbg(hw, "Failed to read EEPROM image\n");
1013 return status;
1014 }
1015 local_buffer = eeprom_ptrs;
1016 } else {
1017 if (buffer_size < IXGBE_EEPROM_LAST_WORD)
1018 return IXGBE_ERR_PARAM;
1019 local_buffer = buffer;
1020 }
1021
1022 /* For X550 hardware include 0x0-0x41 in the checksum, skip the
1023 * checksum word itself
1024 */
1025 for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
1026 if (i != IXGBE_EEPROM_CHECKSUM)
1027 checksum += local_buffer[i];
1028
1029 /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
1030 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
1031 */
1032 for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
1033 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
1034 continue;
1035
1036 pointer = local_buffer[i];
1037
1038 /* Skip pointer section if the pointer is invalid. */
1039 if (pointer == 0xFFFF || pointer == 0 ||
1040 pointer >= hw->eeprom.word_size)
1041 continue;
1042
1043 switch (i) {
1044 case IXGBE_PCIE_GENERAL_PTR:
1045 size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
1046 break;
1047 case IXGBE_PCIE_CONFIG0_PTR:
1048 case IXGBE_PCIE_CONFIG1_PTR:
1049 size = IXGBE_PCIE_CONFIG_SIZE;
1050 break;
1051 default:
1052 size = 0;
1053 break;
1054 }
1055
1056 status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
1057 buffer, buffer_size);
1058 if (status)
1059 return status;
1060 }
1061
1062 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1063
1064 return (s32)checksum;
1065}
1066
1067/** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
1068 * @hw: pointer to hardware structure
1069 *
1070 * Returns a negative error code on error, or the 16-bit checksum
1071 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001072static s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001073{
1074 return ixgbe_calc_checksum_X550(hw, NULL, 0);
1075}
1076
1077/** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
1078 * @hw: pointer to hardware structure
1079 * @offset: offset of word in the EEPROM to read
1080 * @data: word read from the EEPROM
1081 *
1082 * Reads a 16 bit word from the EEPROM using the hostif.
1083 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001084static s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001085{
Mark Rustad3efa9ed2016-12-14 11:02:00 -08001086 const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
1087 struct ixgbe_hic_read_shadow_ram buffer;
1088 s32 status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001089
Mark Rustad3efa9ed2016-12-14 11:02:00 -08001090 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
1091 buffer.hdr.req.buf_lenh = 0;
1092 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
1093 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
1094
1095 /* convert offset from words to bytes */
1096 buffer.address = cpu_to_be32(offset * 2);
1097 /* one word */
1098 buffer.length = cpu_to_be16(sizeof(u16));
1099
1100 status = hw->mac.ops.acquire_swfw_sync(hw, mask);
1101 if (status)
1102 return status;
1103
1104 status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
1105 IXGBE_HI_COMMAND_TIMEOUT);
1106 if (!status) {
1107 *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
1108 FW_NVM_DATA_OFFSET);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001109 }
1110
Mark Rustad3efa9ed2016-12-14 11:02:00 -08001111 hw->mac.ops.release_swfw_sync(hw, mask);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001112 return status;
1113}
1114
1115/** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
1116 * @hw: pointer to hardware structure
1117 * @checksum_val: calculated checksum
1118 *
1119 * Performs checksum calculation and validates the EEPROM checksum. If the
1120 * caller does not need checksum_val, the value can be NULL.
1121 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001122static s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw,
1123 u16 *checksum_val)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001124{
1125 s32 status;
1126 u16 checksum;
1127 u16 read_checksum = 0;
1128
1129 /* Read the first word from the EEPROM. If this times out or fails, do
1130 * not continue or we could be in for a very long wait while every
1131 * EEPROM read fails
1132 */
1133 status = hw->eeprom.ops.read(hw, 0, &checksum);
1134 if (status) {
1135 hw_dbg(hw, "EEPROM read failed\n");
1136 return status;
1137 }
1138
1139 status = hw->eeprom.ops.calc_checksum(hw);
1140 if (status < 0)
1141 return status;
1142
1143 checksum = (u16)(status & 0xffff);
1144
1145 status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
1146 &read_checksum);
1147 if (status)
1148 return status;
1149
1150 /* Verify read checksum from EEPROM is the same as
1151 * calculated checksum
1152 */
1153 if (read_checksum != checksum) {
1154 status = IXGBE_ERR_EEPROM_CHECKSUM;
1155 hw_dbg(hw, "Invalid EEPROM checksum");
1156 }
1157
1158 /* If the user cares, return the calculated checksum */
1159 if (checksum_val)
1160 *checksum_val = checksum;
1161
1162 return status;
1163}
1164
1165/** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
1166 * @hw: pointer to hardware structure
1167 * @offset: offset of word in the EEPROM to write
1168 * @data: word write to the EEPROM
1169 *
1170 * Write a 16 bit word to the EEPROM using the hostif.
1171 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001172static s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
1173 u16 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001174{
1175 s32 status;
1176 struct ixgbe_hic_write_shadow_ram buffer;
1177
1178 buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
1179 buffer.hdr.req.buf_lenh = 0;
1180 buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
1181 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
1182
1183 /* one word */
1184 buffer.length = cpu_to_be16(sizeof(u16));
1185 buffer.data = data;
1186 buffer.address = cpu_to_be32(offset * 2);
1187
Mark Rustad5cffde32016-03-14 11:05:57 -07001188 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +00001189 IXGBE_HI_COMMAND_TIMEOUT, false);
1190 return status;
1191}
1192
1193/** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
1194 * @hw: pointer to hardware structure
1195 * @offset: offset of word in the EEPROM to write
1196 * @data: word write to the EEPROM
1197 *
1198 * Write a 16 bit word to the EEPROM using the hostif.
1199 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001200static s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001201{
1202 s32 status = 0;
1203
1204 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
1205 status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
1206 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1207 } else {
1208 hw_dbg(hw, "write ee hostif failed to get semaphore");
1209 status = IXGBE_ERR_SWFW_SYNC;
1210 }
1211
1212 return status;
1213}
1214
1215/** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
1216 * @hw: pointer to hardware structure
1217 *
1218 * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
1219 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001220static s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001221{
1222 s32 status = 0;
1223 union ixgbe_hic_hdr2 buffer;
1224
1225 buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
1226 buffer.req.buf_lenh = 0;
1227 buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
1228 buffer.req.checksum = FW_DEFAULT_CHECKSUM;
1229
Mark Rustad5cffde32016-03-14 11:05:57 -07001230 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +00001231 IXGBE_HI_COMMAND_TIMEOUT, false);
1232 return status;
1233}
1234
Don Skidmore454c65d2015-06-17 20:59:59 -04001235/**
1236 * ixgbe_get_bus_info_X550em - Set PCI bus info
1237 * @hw: pointer to hardware structure
1238 *
1239 * Sets bus link width and speed to unknown because X550em is
1240 * not a PCI device.
1241 **/
1242static s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
1243{
Don Skidmoref9328bc2015-06-18 13:24:06 -04001244 hw->bus.type = ixgbe_bus_type_internal;
Don Skidmore454c65d2015-06-17 20:59:59 -04001245 hw->bus.width = ixgbe_bus_width_unknown;
1246 hw->bus.speed = ixgbe_bus_speed_unknown;
1247
1248 hw->mac.ops.set_lan_id(hw);
1249
1250 return 0;
1251}
1252
Don Skidmore1f9ac572015-03-13 13:54:30 -07001253/** ixgbe_disable_rx_x550 - Disable RX unit
1254 *
1255 * Enables the Rx DMA unit for x550
1256 **/
1257static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
1258{
1259 u32 rxctrl, pfdtxgswc;
1260 s32 status;
1261 struct ixgbe_hic_disable_rxen fw_cmd;
1262
1263 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1264 if (rxctrl & IXGBE_RXCTRL_RXEN) {
1265 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
1266 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
1267 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
1268 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
1269 hw->mac.set_lben = true;
1270 } else {
1271 hw->mac.set_lben = false;
1272 }
1273
1274 fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
1275 fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
1276 fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
Mark Rustad3775b812016-03-14 11:05:46 -07001277 fw_cmd.port_number = hw->bus.lan_id;
Don Skidmore1f9ac572015-03-13 13:54:30 -07001278
Mark Rustad5cffde32016-03-14 11:05:57 -07001279 status = ixgbe_host_interface_command(hw, &fw_cmd,
Don Skidmore1f9ac572015-03-13 13:54:30 -07001280 sizeof(struct ixgbe_hic_disable_rxen),
1281 IXGBE_HI_COMMAND_TIMEOUT, true);
1282
1283 /* If we fail - disable RX using register write */
1284 if (status) {
1285 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1286 if (rxctrl & IXGBE_RXCTRL_RXEN) {
1287 rxctrl &= ~IXGBE_RXCTRL_RXEN;
1288 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
1289 }
1290 }
1291 }
1292}
1293
Don Skidmore6a14ee02014-12-05 03:59:50 +00001294/** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
1295 * @hw: pointer to hardware structure
1296 *
1297 * After writing EEPROM to shadow RAM using EEWR register, software calculates
1298 * checksum and updates the EEPROM and instructs the hardware to update
1299 * the flash.
1300 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001301static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001302{
1303 s32 status;
1304 u16 checksum = 0;
1305
1306 /* Read the first word from the EEPROM. If this times out or fails, do
1307 * not continue or we could be in for a very long wait while every
1308 * EEPROM read fails
1309 */
1310 status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
1311 if (status) {
1312 hw_dbg(hw, "EEPROM read failed\n");
1313 return status;
1314 }
1315
1316 status = ixgbe_calc_eeprom_checksum_X550(hw);
1317 if (status < 0)
1318 return status;
1319
1320 checksum = (u16)(status & 0xffff);
1321
1322 status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
1323 checksum);
1324 if (status)
1325 return status;
1326
1327 status = ixgbe_update_flash_X550(hw);
1328
1329 return status;
1330}
1331
1332/** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
1333 * @hw: pointer to hardware structure
1334 * @offset: offset of word in the EEPROM to write
1335 * @words: number of words
1336 * @data: word(s) write to the EEPROM
1337 *
1338 *
1339 * Write a 16 bit word(s) to the EEPROM using the hostif.
1340 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001341static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
1342 u16 offset, u16 words,
1343 u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001344{
1345 s32 status = 0;
1346 u32 i = 0;
1347
1348 /* Take semaphore for the entire operation. */
1349 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1350 if (status) {
1351 hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
1352 return status;
1353 }
1354
1355 for (i = 0; i < words; i++) {
1356 status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
1357 data[i]);
1358 if (status) {
1359 hw_dbg(hw, "Eeprom buffered write failed\n");
1360 break;
1361 }
1362 }
1363
1364 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1365
1366 return status;
1367}
1368
Don Skidmore6a14ee02014-12-05 03:59:50 +00001369/** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
1370 * IOSF device
1371 *
1372 * @hw: pointer to hardware structure
1373 * @reg_addr: 32 bit PHY register to write
1374 * @device_type: 3 bit device type
1375 * @data: Data to write to the register
1376 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001377static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
1378 u32 device_type, u32 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001379{
Mark Rustadae14a1d2015-04-10 10:36:26 -07001380 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
1381 u32 command, error;
1382 s32 ret;
1383
1384 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
1385 if (ret)
1386 return ret;
1387
1388 ret = ixgbe_iosf_wait(hw, NULL);
1389 if (ret)
1390 goto out;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001391
1392 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
1393 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
1394
1395 /* Write IOSF control register */
1396 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
1397
1398 /* Write IOSF data register */
1399 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
1400
Mark Rustadae14a1d2015-04-10 10:36:26 -07001401 ret = ixgbe_iosf_wait(hw, &command);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001402
1403 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
1404 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
1405 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
1406 hw_dbg(hw, "Failed to write, error %x\n", error);
1407 return IXGBE_ERR_PHY;
1408 }
1409
Mark Rustadae14a1d2015-04-10 10:36:26 -07001410out:
1411 hw->mac.ops.release_swfw_sync(hw, gssr);
1412 return ret;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001413}
1414
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001415/**
1416 * ixgbe_setup_ixfi_x550em_x - MAC specific iXFI configuration
Don Skidmore6a14ee02014-12-05 03:59:50 +00001417 * @hw: pointer to hardware structure
Don Skidmore6a14ee02014-12-05 03:59:50 +00001418 *
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001419 * iXfI configuration needed for ixgbe_mac_X550EM_x devices.
Don Skidmore6a14ee02014-12-05 03:59:50 +00001420 **/
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001421static s32 ixgbe_setup_ixfi_x550em_x(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001422{
1423 s32 status;
1424 u32 reg_val;
1425
Don Skidmore6a14ee02014-12-05 03:59:50 +00001426 /* Disable training protocol FSM. */
1427 status = ixgbe_read_iosf_sb_reg_x550(hw,
1428 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1429 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1430 if (status)
1431 return status;
1432
1433 reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
1434 status = ixgbe_write_iosf_sb_reg_x550(hw,
1435 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1436 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1437 if (status)
1438 return status;
1439
1440 /* Disable Flex from training TXFFE. */
1441 status = ixgbe_read_iosf_sb_reg_x550(hw,
1442 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1443 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1444 if (status)
1445 return status;
1446
1447 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1448 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1449 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1450 status = ixgbe_write_iosf_sb_reg_x550(hw,
1451 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1452 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1453 if (status)
1454 return status;
1455
1456 status = ixgbe_read_iosf_sb_reg_x550(hw,
1457 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1458 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1459 if (status)
1460 return status;
1461
1462 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1463 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1464 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1465 status = ixgbe_write_iosf_sb_reg_x550(hw,
1466 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1467 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1468 if (status)
1469 return status;
1470
1471 /* Enable override for coefficients. */
1472 status = ixgbe_read_iosf_sb_reg_x550(hw,
1473 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1474 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1475 if (status)
1476 return status;
1477
1478 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
1479 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
1480 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
1481 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
1482 status = ixgbe_write_iosf_sb_reg_x550(hw,
1483 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1484 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001485 return status;
1486}
1487
Don Skidmore470739b2016-11-03 21:01:37 -04001488/**
1489 * ixgbe_restart_an_internal_phy_x550em - restart autonegotiation for the
1490 * internal PHY
1491 * @hw: pointer to hardware structure
1492 **/
1493static s32 ixgbe_restart_an_internal_phy_x550em(struct ixgbe_hw *hw)
1494{
1495 s32 status;
1496 u32 link_ctrl;
1497
1498 /* Restart auto-negotiation. */
1499 status = hw->mac.ops.read_iosf_sb_reg(hw,
1500 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1501 IXGBE_SB_IOSF_TARGET_KR_PHY, &link_ctrl);
1502
1503 if (status) {
1504 hw_dbg(hw, "Auto-negotiation did not complete\n");
1505 return status;
1506 }
1507
1508 link_ctrl |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1509 status = hw->mac.ops.write_iosf_sb_reg(hw,
1510 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1511 IXGBE_SB_IOSF_TARGET_KR_PHY, link_ctrl);
1512
1513 if (hw->mac.type == ixgbe_mac_x550em_a) {
1514 u32 flx_mask_st20;
1515
1516 /* Indicate to FW that AN restart has been asserted */
1517 status = hw->mac.ops.read_iosf_sb_reg(hw,
1518 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1519 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_mask_st20);
1520
1521 if (status) {
1522 hw_dbg(hw, "Auto-negotiation did not complete\n");
1523 return status;
1524 }
1525
1526 flx_mask_st20 |= IXGBE_KRM_PMD_FLX_MASK_ST20_FW_AN_RESTART;
1527 status = hw->mac.ops.write_iosf_sb_reg(hw,
1528 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1529 IXGBE_SB_IOSF_TARGET_KR_PHY, flx_mask_st20);
1530 }
1531
1532 return status;
1533}
1534
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001535/** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
1536 * @hw: pointer to hardware structure
1537 * @speed: the link speed to force
1538 *
1539 * Configures the integrated KR PHY to use iXFI mode. Used to connect an
1540 * internal and external PHY at a specific speed, without autonegotiation.
1541 **/
1542static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1543{
1544 s32 status;
1545 u32 reg_val;
1546
1547 /* Disable AN and force speed to 10G Serial. */
1548 status = ixgbe_read_iosf_sb_reg_x550(hw,
1549 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1550 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001551 if (status)
1552 return status;
1553
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001554 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1555 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1556
1557 /* Select forced link speed for internal PHY. */
1558 switch (*speed) {
1559 case IXGBE_LINK_SPEED_10GB_FULL:
1560 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
1561 break;
1562 case IXGBE_LINK_SPEED_1GB_FULL:
1563 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1564 break;
1565 default:
1566 /* Other link speeds are not supported by internal KR PHY. */
1567 return IXGBE_ERR_LINK_SETUP;
1568 }
1569
1570 status = ixgbe_write_iosf_sb_reg_x550(hw,
1571 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1572 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1573 if (status)
1574 return status;
1575
1576 /* Additional configuration needed for x550em_x */
1577 if (hw->mac.type == ixgbe_mac_X550EM_x) {
1578 status = ixgbe_setup_ixfi_x550em_x(hw);
1579 if (status)
1580 return status;
1581 }
1582
Don Skidmore6a14ee02014-12-05 03:59:50 +00001583 /* Toggle port SW reset by AN reset. */
Don Skidmore470739b2016-11-03 21:01:37 -04001584 status = ixgbe_restart_an_internal_phy_x550em(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001585
1586 return status;
1587}
1588
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001589/**
Mark Rustade23f3332015-08-08 16:18:33 -07001590 * ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
1591 * @hw: pointer to hardware structure
1592 * @linear: true if SFP module is linear
1593 */
1594static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
1595{
1596 switch (hw->phy.sfp_type) {
1597 case ixgbe_sfp_type_not_present:
1598 return IXGBE_ERR_SFP_NOT_PRESENT;
1599 case ixgbe_sfp_type_da_cu_core0:
1600 case ixgbe_sfp_type_da_cu_core1:
1601 *linear = true;
1602 break;
1603 case ixgbe_sfp_type_srlr_core0:
1604 case ixgbe_sfp_type_srlr_core1:
1605 case ixgbe_sfp_type_da_act_lmt_core0:
1606 case ixgbe_sfp_type_da_act_lmt_core1:
1607 case ixgbe_sfp_type_1g_sx_core0:
1608 case ixgbe_sfp_type_1g_sx_core1:
1609 case ixgbe_sfp_type_1g_lx_core0:
1610 case ixgbe_sfp_type_1g_lx_core1:
1611 *linear = false;
1612 break;
1613 case ixgbe_sfp_type_unknown:
1614 case ixgbe_sfp_type_1g_cu_core0:
1615 case ixgbe_sfp_type_1g_cu_core1:
1616 default:
1617 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1618 }
1619
1620 return 0;
1621}
1622
1623/**
Mark Rustad6d373a12015-08-08 16:18:28 -07001624 * ixgbe_setup_mac_link_sfp_x550em - Configure the KR PHY for SFP.
1625 * @hw: pointer to hardware structure
1626 *
1627 * Configures the extern PHY and the integrated KR PHY for SFP support.
1628 */
1629static s32
1630ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
1631 ixgbe_link_speed speed,
1632 __always_unused bool autoneg_wait_to_complete)
1633{
Mark Rustade23f3332015-08-08 16:18:33 -07001634 s32 status;
Emil Tantilov812d7df2016-10-03 17:09:58 -07001635 u16 reg_slice, reg_val;
Mark Rustade23f3332015-08-08 16:18:33 -07001636 bool setup_linear = false;
1637
1638 /* Check if SFP module is supported and linear */
1639 status = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1640
1641 /* If no SFP module present, then return success. Return success since
1642 * there is no reason to configure CS4227 and SFP not present error is
1643 * not accepted in the setup MAC link flow.
1644 */
1645 if (status == IXGBE_ERR_SFP_NOT_PRESENT)
1646 return 0;
1647
1648 if (status)
1649 return status;
1650
Emil Tantilov812d7df2016-10-03 17:09:58 -07001651 /* Configure internal PHY for KR/KX. */
1652 ixgbe_setup_kr_speed_x550em(hw, speed);
Mark Rustade23f3332015-08-08 16:18:33 -07001653
Emil Tantilov812d7df2016-10-03 17:09:58 -07001654 /* Configure CS4227 LINE side to proper mode. */
1655 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
1656 if (setup_linear)
1657 reg_val = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
1658 else
1659 reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
Emil Tantilovb71f6c42016-10-10 14:54:03 -07001660
1661 status = hw->link.ops.write_link(hw, hw->link.addr, reg_slice,
1662 reg_val);
1663
Mark Rustade23f3332015-08-08 16:18:33 -07001664 return status;
Mark Rustad6d373a12015-08-08 16:18:28 -07001665}
1666
1667/**
Don Skidmore470739b2016-11-03 21:01:37 -04001668 * ixgbe_setup_sfi_x550a - Configure the internal PHY for native SFI mode
1669 * @hw: pointer to hardware structure
1670 * @speed: the link speed to force
1671 *
1672 * Configures the integrated PHY for native SFI mode. Used to connect the
1673 * internal PHY directly to an SFP cage, without autonegotiation.
1674 **/
1675static s32 ixgbe_setup_sfi_x550a(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1676{
1677 struct ixgbe_mac_info *mac = &hw->mac;
1678 s32 status;
1679 u32 reg_val;
1680
1681 /* Disable all AN and force speed to 10G Serial. */
1682 status = mac->ops.read_iosf_sb_reg(hw,
1683 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1684 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1685 if (status)
1686 return status;
1687
1688 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
1689 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
1690 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
1691 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
1692
1693 /* Select forced link speed for internal PHY. */
1694 switch (*speed) {
1695 case IXGBE_LINK_SPEED_10GB_FULL:
1696 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_10G;
1697 break;
1698 case IXGBE_LINK_SPEED_1GB_FULL:
1699 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
1700 break;
1701 default:
1702 /* Other link speeds are not supported by internal PHY. */
1703 return IXGBE_ERR_LINK_SETUP;
1704 }
1705
1706 status = mac->ops.write_iosf_sb_reg(hw,
1707 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1708 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1709
1710 /* Toggle port SW reset by AN reset. */
1711 status = ixgbe_restart_an_internal_phy_x550em(hw);
1712
1713 return status;
1714}
1715
1716/**
Mark Rustad2d40cd12016-04-01 12:18:35 -07001717 * ixgbe_setup_mac_link_sfp_n - Setup internal PHY for native SFP
1718 * @hw: pointer to hardware structure
1719 *
1720 * Configure the the integrated PHY for native SFP support.
1721 */
1722static s32
1723ixgbe_setup_mac_link_sfp_n(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1724 __always_unused bool autoneg_wait_to_complete)
1725{
1726 bool setup_linear = false;
1727 u32 reg_phy_int;
Don Skidmore470739b2016-11-03 21:01:37 -04001728 s32 ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001729
1730 /* Check if SFP module is supported and linear */
Don Skidmore470739b2016-11-03 21:01:37 -04001731 ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
Mark Rustad2d40cd12016-04-01 12:18:35 -07001732
1733 /* If no SFP module present, then return success. Return success since
1734 * SFP not present error is not excepted in the setup MAC link flow.
1735 */
Don Skidmore470739b2016-11-03 21:01:37 -04001736 if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001737 return 0;
1738
Don Skidmore470739b2016-11-03 21:01:37 -04001739 if (!ret_val)
1740 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001741
Don Skidmore470739b2016-11-03 21:01:37 -04001742 /* Configure internal PHY for native SFI based on module type */
1743 ret_val = hw->mac.ops.read_iosf_sb_reg(hw,
1744 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1745 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_phy_int);
1746 if (!ret_val)
1747 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001748
Don Skidmore470739b2016-11-03 21:01:37 -04001749 reg_phy_int &= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_DA;
1750 if (!setup_linear)
1751 reg_phy_int |= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_SR;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001752
Don Skidmore470739b2016-11-03 21:01:37 -04001753 ret_val = hw->mac.ops.write_iosf_sb_reg(hw,
1754 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1755 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_phy_int);
1756 if (!ret_val)
1757 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001758
Don Skidmore470739b2016-11-03 21:01:37 -04001759 /* Setup SFI internal link. */
1760 return ixgbe_setup_sfi_x550a(hw, &speed);
Mark Rustad2d40cd12016-04-01 12:18:35 -07001761}
1762
1763/**
1764 * ixgbe_setup_mac_link_sfp_x550a - Setup internal PHY for SFP
1765 * @hw: pointer to hardware structure
1766 *
1767 * Configure the the integrated PHY for SFP support.
1768 */
1769static s32
1770ixgbe_setup_mac_link_sfp_x550a(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1771 __always_unused bool autoneg_wait_to_complete)
1772{
1773 u32 reg_slice, slice_offset;
1774 bool setup_linear = false;
1775 u16 reg_phy_ext;
Don Skidmore470739b2016-11-03 21:01:37 -04001776 s32 ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001777
1778 /* Check if SFP module is supported and linear */
Don Skidmore470739b2016-11-03 21:01:37 -04001779 ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
Mark Rustad2d40cd12016-04-01 12:18:35 -07001780
1781 /* If no SFP module present, then return success. Return success since
1782 * SFP not present error is not excepted in the setup MAC link flow.
1783 */
Don Skidmore470739b2016-11-03 21:01:37 -04001784 if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001785 return 0;
1786
Don Skidmore470739b2016-11-03 21:01:37 -04001787 if (!ret_val)
1788 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001789
1790 /* Configure internal PHY for KR/KX. */
1791 ixgbe_setup_kr_speed_x550em(hw, speed);
1792
Mark Rustad7564a882016-09-01 13:58:51 -07001793 if (hw->phy.mdio.prtad == MDIO_PRTAD_NONE)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001794 return IXGBE_ERR_PHY_ADDR_INVALID;
1795
1796 /* Get external PHY device id */
Don Skidmore470739b2016-11-03 21:01:37 -04001797 ret_val = hw->phy.ops.read_reg(hw, IXGBE_CS4227_GLOBAL_ID_MSB,
Mark Rustad2d40cd12016-04-01 12:18:35 -07001798 IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
Don Skidmore470739b2016-11-03 21:01:37 -04001799 if (ret_val)
1800 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001801
1802 /* When configuring quad port CS4223, the MAC instance is part
1803 * of the slice offset.
1804 */
1805 if (reg_phy_ext == IXGBE_CS4223_PHY_ID)
1806 slice_offset = (hw->bus.lan_id +
1807 (hw->bus.instance_id << 1)) << 12;
1808 else
1809 slice_offset = hw->bus.lan_id << 12;
1810
1811 /* Configure CS4227/CS4223 LINE side to proper mode. */
1812 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + slice_offset;
1813 if (setup_linear)
1814 reg_phy_ext = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1815 else
1816 reg_phy_ext = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1817 return hw->phy.ops.write_reg(hw, reg_slice, IXGBE_MDIO_ZERO_DEV_TYPE,
1818 reg_phy_ext);
1819}
1820
1821/**
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001822 * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
1823 * @hw: pointer to hardware structure
1824 * @speed: new link speed
1825 * @autoneg_wait_to_complete: true when waiting for completion is needed
1826 *
1827 * Setup internal/external PHY link speed based on link speed, then set
1828 * external PHY auto advertised link speed.
1829 *
1830 * Returns error status for any failure
1831 **/
1832static s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
1833 ixgbe_link_speed speed,
1834 bool autoneg_wait)
1835{
1836 s32 status;
1837 ixgbe_link_speed force_speed;
1838
1839 /* Setup internal/external PHY link speed to iXFI (10G), unless
1840 * only 1G is auto advertised then setup KX link.
1841 */
1842 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1843 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
1844 else
1845 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
1846
1847 /* If internal link mode is XFI, then setup XFI internal link. */
1848 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1849 status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
1850
1851 if (status)
1852 return status;
1853 }
1854
1855 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
1856}
1857
Don Skidmorea4e293a2015-06-09 17:44:58 -07001858/** ixgbe_check_link_t_X550em - Determine link and speed status
1859 * @hw: pointer to hardware structure
1860 * @speed: pointer to link speed
1861 * @link_up: true when link is up
1862 * @link_up_wait_to_complete: bool used to wait for link up or not
1863 *
1864 * Check that both the MAC and X557 external PHY have link.
1865 **/
1866static s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw,
1867 ixgbe_link_speed *speed,
1868 bool *link_up,
1869 bool link_up_wait_to_complete)
1870{
1871 u32 status;
Emil Tantilov21d882e2016-09-26 14:08:18 -07001872 u16 i, autoneg_status;
Don Skidmorea4e293a2015-06-09 17:44:58 -07001873
1874 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
1875 return IXGBE_ERR_CONFIG;
1876
1877 status = ixgbe_check_mac_link_generic(hw, speed, link_up,
1878 link_up_wait_to_complete);
1879
1880 /* If check link fails or MAC link is not up, then return */
1881 if (status || !(*link_up))
1882 return status;
1883
Emil Tantilov21d882e2016-09-26 14:08:18 -07001884 /* MAC link is up, so check external PHY link.
1885 * Link status is latching low, and can only be used to detect link
1886 * drop, and not the current status of the link without performing
1887 * back-to-back reads.
1888 */
1889 for (i = 0; i < 2; i++) {
1890 status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
1891 &autoneg_status);
1892
1893 if (status)
1894 return status;
1895 }
Don Skidmorea4e293a2015-06-09 17:44:58 -07001896
1897 /* If external PHY link is not up, then indicate link not up */
1898 if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
1899 *link_up = false;
1900
1901 return 0;
1902}
1903
Mark Rustad200157c2016-04-01 12:18:40 -07001904/**
1905 * ixgbe_setup_sgmii - Set up link for sgmii
1906 * @hw: pointer to hardware structure
1907 */
1908static s32
1909ixgbe_setup_sgmii(struct ixgbe_hw *hw, __always_unused ixgbe_link_speed speed,
1910 __always_unused bool autoneg_wait_to_complete)
1911{
1912 struct ixgbe_mac_info *mac = &hw->mac;
Don Skidmore470739b2016-11-03 21:01:37 -04001913 u32 lval, sval, flx_val;
Mark Rustad200157c2016-04-01 12:18:40 -07001914 s32 rc;
1915
1916 rc = mac->ops.read_iosf_sb_reg(hw,
1917 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1918 IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
1919 if (rc)
1920 return rc;
1921
1922 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1923 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1924 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
1925 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
1926 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1927 rc = mac->ops.write_iosf_sb_reg(hw,
1928 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1929 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
1930 if (rc)
1931 return rc;
1932
1933 rc = mac->ops.read_iosf_sb_reg(hw,
1934 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
1935 IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
1936 if (rc)
1937 return rc;
1938
1939 sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
1940 sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
1941 rc = mac->ops.write_iosf_sb_reg(hw,
1942 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
1943 IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
1944 if (rc)
1945 return rc;
1946
Don Skidmore470739b2016-11-03 21:01:37 -04001947 rc = mac->ops.read_iosf_sb_reg(hw,
1948 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1949 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
1950 if (rc)
1951 return rc;
Mark Rustad200157c2016-04-01 12:18:40 -07001952
Don Skidmore470739b2016-11-03 21:01:37 -04001953 rc = mac->ops.read_iosf_sb_reg(hw,
1954 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1955 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
1956 if (rc)
1957 return rc;
1958
1959 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
1960 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
1961 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
1962 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
1963 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
1964
1965 rc = mac->ops.write_iosf_sb_reg(hw,
1966 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1967 IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
1968 if (rc)
1969 return rc;
1970
1971 rc = ixgbe_restart_an_internal_phy_x550em(hw);
Mark Rustad200157c2016-04-01 12:18:40 -07001972 return rc;
1973}
1974
Mark Rustadb3eb4e12016-12-14 11:02:16 -08001975/**
1976 * ixgbe_setup_sgmii_fw - Set up link for sgmii with firmware-controlled PHYs
1977 * @hw: pointer to hardware structure
1978 */
1979static s32 ixgbe_setup_sgmii_fw(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1980 bool autoneg_wait)
1981{
1982 struct ixgbe_mac_info *mac = &hw->mac;
1983 u32 lval, sval, flx_val;
1984 s32 rc;
1985
1986 rc = mac->ops.read_iosf_sb_reg(hw,
1987 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1988 IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
1989 if (rc)
1990 return rc;
1991
1992 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1993 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1994 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
1995 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
1996 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1997 rc = mac->ops.write_iosf_sb_reg(hw,
1998 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1999 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
2000 if (rc)
2001 return rc;
2002
2003 rc = mac->ops.read_iosf_sb_reg(hw,
2004 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
2005 IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
2006 if (rc)
2007 return rc;
2008
2009 sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
2010 sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
2011 rc = mac->ops.write_iosf_sb_reg(hw,
2012 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
2013 IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
2014 if (rc)
2015 return rc;
2016
2017 rc = mac->ops.write_iosf_sb_reg(hw,
2018 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2019 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
2020 if (rc)
2021 return rc;
2022
2023 rc = mac->ops.read_iosf_sb_reg(hw,
2024 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2025 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
2026 if (rc)
2027 return rc;
2028
2029 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
2030 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
2031 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
2032 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
2033 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
2034
2035 rc = mac->ops.write_iosf_sb_reg(hw,
2036 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2037 IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
2038 if (rc)
2039 return rc;
2040
2041 ixgbe_restart_an_internal_phy_x550em(hw);
2042
2043 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
2044}
2045
2046/**
2047 * ixgbe_fc_autoneg_sgmii_x550em_a - Enable flow control IEEE clause 37
2048 * @hw: pointer to hardware structure
2049 *
2050 * Enable flow control according to IEEE clause 37.
2051 */
2052static void ixgbe_fc_autoneg_sgmii_x550em_a(struct ixgbe_hw *hw)
2053{
2054 s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2055 u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
2056 ixgbe_link_speed speed;
2057 bool link_up;
2058
2059 /* AN should have completed when the cable was plugged in.
2060 * Look for reasons to bail out. Bail out if:
2061 * - FC autoneg is disabled, or if
2062 * - link is not up.
2063 */
2064 if (hw->fc.disable_fc_autoneg)
2065 goto out;
2066
2067 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2068 if (!link_up)
2069 goto out;
2070
2071 /* Check if auto-negotiation has completed */
2072 status = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &info);
2073 if (status || !(info[0] & FW_PHY_ACT_GET_LINK_INFO_AN_COMPLETE)) {
2074 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2075 goto out;
2076 }
2077
2078 /* Negotiate the flow control */
2079 status = ixgbe_negotiate_fc(hw, info[0], info[0],
2080 FW_PHY_ACT_GET_LINK_INFO_FC_RX,
2081 FW_PHY_ACT_GET_LINK_INFO_FC_TX,
2082 FW_PHY_ACT_GET_LINK_INFO_LP_FC_RX,
2083 FW_PHY_ACT_GET_LINK_INFO_LP_FC_TX);
2084
2085out:
2086 if (!status) {
2087 hw->fc.fc_was_autonegged = true;
2088 } else {
2089 hw->fc.fc_was_autonegged = false;
2090 hw->fc.current_mode = hw->fc.requested_mode;
2091 }
2092}
2093
Don Skidmore29165002016-09-27 14:31:12 -04002094/** ixgbe_init_mac_link_ops_X550em_a - Init mac link function pointers
2095 * @hw: pointer to hardware structure
2096 **/
2097static void ixgbe_init_mac_link_ops_X550em_a(struct ixgbe_hw *hw)
2098{
2099 struct ixgbe_mac_info *mac = &hw->mac;
2100
2101 switch (mac->ops.get_media_type(hw)) {
2102 case ixgbe_media_type_fiber:
2103 mac->ops.setup_fc = NULL;
2104 mac->ops.fc_autoneg = ixgbe_fc_autoneg_fiber_x550em_a;
2105 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002106 case ixgbe_media_type_copper:
2107 if (hw->device_id != IXGBE_DEV_ID_X550EM_A_1G_T &&
2108 hw->device_id != IXGBE_DEV_ID_X550EM_A_1G_T_L) {
2109 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
2110 break;
2111 }
2112 mac->ops.fc_autoneg = ixgbe_fc_autoneg_sgmii_x550em_a;
2113 mac->ops.setup_fc = ixgbe_fc_autoneg_fw;
2114 mac->ops.setup_link = ixgbe_setup_sgmii_fw;
2115 mac->ops.check_link = ixgbe_check_mac_link_generic;
2116 break;
Don Skidmore29165002016-09-27 14:31:12 -04002117 case ixgbe_media_type_backplane:
2118 mac->ops.fc_autoneg = ixgbe_fc_autoneg_backplane_x550em_a;
2119 mac->ops.setup_fc = ixgbe_setup_fc_backplane_x550em_a;
2120 break;
2121 default:
2122 break;
2123 }
2124}
2125
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002126/** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
2127 * @hw: pointer to hardware structure
2128 **/
2129static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
2130{
2131 struct ixgbe_mac_info *mac = &hw->mac;
2132
Emil Tantilovabf76d72016-07-07 17:18:38 -07002133 mac->ops.setup_fc = ixgbe_setup_fc_x550em;
2134
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002135 switch (mac->ops.get_media_type(hw)) {
2136 case ixgbe_media_type_fiber:
2137 /* CS4227 does not support autoneg, so disable the laser control
2138 * functions for SFP+ fiber
2139 */
2140 mac->ops.disable_tx_laser = NULL;
2141 mac->ops.enable_tx_laser = NULL;
2142 mac->ops.flap_tx_laser = NULL;
Mark Rustad6d373a12015-08-08 16:18:28 -07002143 mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
Mark Rustad2d40cd12016-04-01 12:18:35 -07002144 switch (hw->device_id) {
2145 case IXGBE_DEV_ID_X550EM_A_SFP_N:
2146 mac->ops.setup_mac_link = ixgbe_setup_mac_link_sfp_n;
2147 break;
2148 case IXGBE_DEV_ID_X550EM_A_SFP:
2149 mac->ops.setup_mac_link =
2150 ixgbe_setup_mac_link_sfp_x550a;
2151 break;
2152 default:
2153 mac->ops.setup_mac_link =
2154 ixgbe_setup_mac_link_sfp_x550em;
2155 break;
2156 }
Mark Rustad6d373a12015-08-08 16:18:28 -07002157 mac->ops.set_rate_select_speed =
2158 ixgbe_set_soft_rate_select_speed;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002159 break;
2160 case ixgbe_media_type_copper:
2161 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
Mark Rustadafdc71e2016-01-25 16:32:10 -08002162 mac->ops.setup_fc = ixgbe_setup_fc_generic;
Don Skidmorea4e293a2015-06-09 17:44:58 -07002163 mac->ops.check_link = ixgbe_check_link_t_X550em;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002164 break;
Mark Rustad49425df2016-04-01 12:18:09 -07002165 case ixgbe_media_type_backplane:
Mark Rustad200157c2016-04-01 12:18:40 -07002166 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII ||
2167 hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII_L)
2168 mac->ops.setup_link = ixgbe_setup_sgmii;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002169 break;
2170 default:
2171 break;
2172 }
Don Skidmore29165002016-09-27 14:31:12 -04002173
2174 /* Additional modification for X550em_a devices */
2175 if (hw->mac.type == ixgbe_mac_x550em_a)
2176 ixgbe_init_mac_link_ops_X550em_a(hw);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002177}
2178
2179/** ixgbe_setup_sfp_modules_X550em - Setup SFP module
2180 * @hw: pointer to hardware structure
2181 */
2182static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
2183{
Mark Rustade23f3332015-08-08 16:18:33 -07002184 s32 status;
2185 bool linear;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002186
Mark Rustade23f3332015-08-08 16:18:33 -07002187 /* Check if SFP module is supported */
2188 status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
2189 if (status)
2190 return status;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002191
2192 ixgbe_init_mac_link_ops_X550em(hw);
2193 hw->phy.ops.reset = NULL;
2194
Mark Rustade23f3332015-08-08 16:18:33 -07002195 return 0;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002196}
2197
2198/** ixgbe_get_link_capabilities_x550em - Determines link capabilities
2199 * @hw: pointer to hardware structure
2200 * @speed: pointer to link speed
2201 * @autoneg: true when autoneg or autotry is enabled
2202 **/
2203static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
2204 ixgbe_link_speed *speed,
2205 bool *autoneg)
2206{
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002207 if (hw->phy.type == ixgbe_phy_fw) {
2208 *autoneg = true;
2209 *speed = hw->phy.speeds_supported;
2210 return 0;
2211 }
2212
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002213 /* SFP */
2214 if (hw->phy.media_type == ixgbe_media_type_fiber) {
2215 /* CS4227 SFP must not enable auto-negotiation */
2216 *autoneg = false;
2217
2218 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
2219 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
2220 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2221 return 0;
2222 }
2223
2224 /* Link capabilities are based on SFP */
2225 if (hw->phy.multispeed_fiber)
2226 *speed = IXGBE_LINK_SPEED_10GB_FULL |
2227 IXGBE_LINK_SPEED_1GB_FULL;
2228 else
2229 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2230 } else {
Don Skidmore18bda0d2016-12-30 21:07:14 -05002231 switch (hw->phy.type) {
2232 case ixgbe_phy_x550em_kx4:
2233 *speed = IXGBE_LINK_SPEED_1GB_FULL |
2234 IXGBE_LINK_SPEED_2_5GB_FULL |
2235 IXGBE_LINK_SPEED_10GB_FULL;
2236 break;
Don Skidmore18e01ee2016-12-30 21:07:58 -05002237 case ixgbe_phy_x550em_xfi:
2238 *speed = IXGBE_LINK_SPEED_1GB_FULL |
2239 IXGBE_LINK_SPEED_10GB_FULL;
2240 break;
Don Skidmore18bda0d2016-12-30 21:07:14 -05002241 case ixgbe_phy_sgmii:
2242 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2243 break;
Don Skidmore8e5c9c52016-12-30 21:13:18 -05002244 case ixgbe_phy_x550em_kr:
2245 if (hw->mac.type == ixgbe_mac_x550em_a) {
2246 /* check different backplane modes */
2247 if (hw->phy.nw_mng_if_sel &
2248 IXGBE_NW_MNG_IF_SEL_PHY_SPEED_2_5G) {
2249 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
2250 break;
2251 } else if (hw->device_id ==
2252 IXGBE_DEV_ID_X550EM_A_KR_L) {
2253 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2254 break;
2255 }
2256 }
2257 /* fall through */
Don Skidmore18bda0d2016-12-30 21:07:14 -05002258 default:
2259 *speed = IXGBE_LINK_SPEED_10GB_FULL |
2260 IXGBE_LINK_SPEED_1GB_FULL;
2261 break;
2262 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002263 *autoneg = true;
2264 }
2265 return 0;
2266}
2267
2268/**
2269 * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
2270 * @hw: pointer to hardware structure
2271 * @lsc: pointer to boolean flag which indicates whether external Base T
2272 * PHY interrupt is lsc
2273 *
2274 * Determime if external Base T PHY interrupt cause is high temperature
2275 * failure alarm or link status change.
2276 *
2277 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
2278 * failure alarm, else return PHY access status.
2279 **/
2280static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
2281{
2282 u32 status;
2283 u16 reg;
2284
2285 *lsc = false;
2286
2287 /* Vendor alarm triggered */
2288 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002289 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002290 &reg);
2291
2292 if (status || !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
2293 return status;
2294
2295 /* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
2296 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002297 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002298 &reg);
2299
2300 if (status || !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
2301 IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
2302 return status;
2303
Mark Rustad83a9fb22015-10-19 09:22:14 -07002304 /* Global alarm triggered */
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002305 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002306 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002307 &reg);
2308
2309 if (status)
2310 return status;
2311
2312 /* If high temperature failure, then return over temp error and exit */
2313 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
2314 /* power down the PHY in case the PHY FW didn't already */
2315 ixgbe_set_copper_phy_power(hw, false);
2316 return IXGBE_ERR_OVERTEMP;
2317 }
Mark Rustad83a9fb22015-10-19 09:22:14 -07002318 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
2319 /* device fault alarm triggered */
2320 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002321 MDIO_MMD_VEND1,
Mark Rustad83a9fb22015-10-19 09:22:14 -07002322 &reg);
2323 if (status)
2324 return status;
2325
2326 /* if device fault was due to high temp alarm handle and exit */
2327 if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
2328 /* power down the PHY in case the PHY FW didn't */
2329 ixgbe_set_copper_phy_power(hw, false);
2330 return IXGBE_ERR_OVERTEMP;
2331 }
2332 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002333
2334 /* Vendor alarm 2 triggered */
2335 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002336 MDIO_MMD_AN, &reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002337
2338 if (status || !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
2339 return status;
2340
2341 /* link connect/disconnect event occurred */
2342 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002343 MDIO_MMD_AN, &reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002344
2345 if (status)
2346 return status;
2347
2348 /* Indicate LSC */
2349 if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
2350 *lsc = true;
2351
2352 return 0;
2353}
2354
2355/**
2356 * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
2357 * @hw: pointer to hardware structure
2358 *
2359 * Enable link status change and temperature failure alarm for the external
2360 * Base T PHY
2361 *
2362 * Returns PHY access status
2363 **/
2364static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
2365{
2366 u32 status;
2367 u16 reg;
2368 bool lsc;
2369
2370 /* Clear interrupt flags */
2371 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
2372
2373 /* Enable link status change alarm */
2374 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002375 MDIO_MMD_AN, &reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002376 if (status)
2377 return status;
2378
2379 reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
2380
2381 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002382 MDIO_MMD_AN, reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002383 if (status)
2384 return status;
2385
Mark Rustad83a9fb22015-10-19 09:22:14 -07002386 /* Enable high temperature failure and global fault alarms */
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002387 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002388 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002389 &reg);
2390 if (status)
2391 return status;
2392
Mark Rustad83a9fb22015-10-19 09:22:14 -07002393 reg |= (IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN |
2394 IXGBE_MDIO_GLOBAL_INT_DEV_FAULT_EN);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002395
2396 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002397 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002398 reg);
2399 if (status)
2400 return status;
2401
2402 /* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
2403 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002404 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002405 &reg);
2406 if (status)
2407 return status;
2408
2409 reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
2410 IXGBE_MDIO_GLOBAL_ALARM_1_INT);
2411
2412 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002413 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002414 reg);
2415 if (status)
2416 return status;
2417
2418 /* Enable chip-wide vendor alarm */
2419 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002420 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002421 &reg);
2422 if (status)
2423 return status;
2424
2425 reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
2426
2427 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002428 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002429 reg);
2430
2431 return status;
2432}
2433
2434/**
2435 * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
2436 * @hw: pointer to hardware structure
2437 *
2438 * Handle external Base T PHY interrupt. If high temperature
2439 * failure alarm then return error, else if link status change
2440 * then setup internal/external PHY link
2441 *
2442 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
2443 * failure alarm, else return PHY access status.
2444 **/
2445static s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
2446{
2447 struct ixgbe_phy_info *phy = &hw->phy;
2448 bool lsc;
2449 u32 status;
2450
2451 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
2452 if (status)
2453 return status;
2454
Mark Rustada85ce532015-09-09 13:37:33 -07002455 if (lsc && phy->ops.setup_internal_link)
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002456 return phy->ops.setup_internal_link(hw);
2457
2458 return 0;
2459}
2460
2461/**
2462 * ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
2463 * @hw: pointer to hardware structure
2464 * @speed: link speed
2465 *
2466 * Configures the integrated KR PHY.
2467 **/
2468static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
2469 ixgbe_link_speed speed)
2470{
2471 s32 status;
2472 u32 reg_val;
2473
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002474 status = hw->mac.ops.read_iosf_sb_reg(hw,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002475 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2476 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
2477 if (status)
2478 return status;
2479
2480 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002481 reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
2482 IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
2483
2484 /* Advertise 10G support. */
2485 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
2486 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
2487
2488 /* Advertise 1G support. */
2489 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
2490 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
2491
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002492 status = hw->mac.ops.write_iosf_sb_reg(hw,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002493 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2494 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2495
Don Skidmore470739b2016-11-03 21:01:37 -04002496 if (hw->mac.type == ixgbe_mac_x550em_a) {
2497 /* Set lane mode to KR auto negotiation */
2498 status = hw->mac.ops.read_iosf_sb_reg(hw,
2499 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2500 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
2501
2502 if (status)
2503 return status;
2504
2505 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
2506 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
2507 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
2508 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
2509 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
2510
2511 status = hw->mac.ops.write_iosf_sb_reg(hw,
2512 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2513 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2514 }
2515
2516 return ixgbe_restart_an_internal_phy_x550em(hw);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002517}
2518
Mark Rustadf572b2c2016-04-01 12:18:46 -07002519/**
2520 * ixgbe_setup_kr_x550em - Configure the KR PHY
2521 * @hw: pointer to hardware structure
Don Skidmore6a14ee02014-12-05 03:59:50 +00002522 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00002523static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002524{
Don Skidmore54f6d4c2016-12-13 20:34:51 -05002525 /* leave link alone for 2.5G */
2526 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_2_5GB_FULL)
Mark Rustadf572b2c2016-04-01 12:18:46 -07002527 return 0;
2528
Tony Nguyenf4a63742017-03-01 11:52:09 -08002529 if (ixgbe_check_reset_blocked(hw))
2530 return 0;
2531
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002532 return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002533}
2534
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002535/** ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
2536 * @hw: address of hardware structure
2537 * @link_up: address of boolean to indicate link status
2538 *
2539 * Returns error code if unable to get link status.
2540 **/
2541static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
2542{
2543 u32 ret;
2544 u16 autoneg_status;
2545
2546 *link_up = false;
2547
2548 /* read this twice back to back to indicate current status */
Emil Tantilov4dc40002016-09-26 14:08:13 -07002549 ret = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002550 &autoneg_status);
2551 if (ret)
2552 return ret;
2553
Emil Tantilov4dc40002016-09-26 14:08:13 -07002554 ret = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002555 &autoneg_status);
2556 if (ret)
2557 return ret;
2558
2559 *link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
2560
2561 return 0;
2562}
2563
2564/** ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
Don Skidmore6a14ee02014-12-05 03:59:50 +00002565 * @hw: point to hardware structure
2566 *
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002567 * Configures the link between the integrated KR PHY and the external X557 PHY
2568 * The driver will call this function when it gets a link status change
2569 * interrupt from the X557 PHY. This function configures the link speed
2570 * between the PHYs to match the link speed of the BASE-T link.
Don Skidmore6a14ee02014-12-05 03:59:50 +00002571 *
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002572 * A return of a non-zero value indicates an error, and the base driver should
2573 * not report link up.
Don Skidmore6a14ee02014-12-05 03:59:50 +00002574 **/
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002575static s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002576{
Don Skidmore6a14ee02014-12-05 03:59:50 +00002577 ixgbe_link_speed force_speed;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002578 bool link_up;
2579 u32 status;
2580 u16 speed;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002581
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002582 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2583 return IXGBE_ERR_CONFIG;
2584
Mark Rustadf164b842015-10-16 13:27:49 -07002585 if (hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE) {
2586 speed = IXGBE_LINK_SPEED_10GB_FULL |
2587 IXGBE_LINK_SPEED_1GB_FULL;
2588 return ixgbe_setup_kr_speed_x550em(hw, speed);
2589 }
2590
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002591 /* If link is not up, then there is no setup necessary so return */
2592 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002593 if (status)
2594 return status;
2595
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002596 if (!link_up)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002597 return 0;
2598
Don Skidmore6a14ee02014-12-05 03:59:50 +00002599 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002600 MDIO_MMD_AN,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002601 &speed);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002602 if (status)
2603 return status;
2604
2605 /* If link is not still up, then no setup is necessary so return */
2606 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2607 if (status)
2608 return status;
2609
2610 if (!link_up)
2611 return 0;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002612
2613 /* clear everything but the speed and duplex bits */
2614 speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
2615
2616 switch (speed) {
2617 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
2618 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
2619 break;
2620 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
2621 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
2622 break;
2623 default:
2624 /* Internal PHY does not support anything else */
2625 return IXGBE_ERR_INVALID_LINK_SETTINGS;
2626 }
2627
2628 return ixgbe_setup_ixfi_x550em(hw, &force_speed);
2629}
2630
Don Skidmoref4410d22015-06-09 16:29:51 -07002631/** ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
2632 * @hw: pointer to hardware structure
2633 **/
2634static s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
2635{
2636 s32 status;
2637
2638 status = ixgbe_reset_phy_generic(hw);
2639
2640 if (status)
2641 return status;
2642
2643 /* Configure Link Status Alarm and Temperature Threshold interrupts */
2644 return ixgbe_enable_lasi_ext_t_x550em(hw);
2645}
2646
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002647/**
2648 * ixgbe_led_on_t_x550em - Turns on the software controllable LEDs.
2649 * @hw: pointer to hardware structure
2650 * @led_idx: led number to turn on
2651 **/
Emil Tantilovd2d43e52016-08-22 16:28:34 -07002652static s32 ixgbe_led_on_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002653{
2654 u16 phy_data;
2655
2656 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
2657 return IXGBE_ERR_PARAM;
2658
2659 /* To turn on the LED, set mode to ON. */
2660 hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002661 MDIO_MMD_VEND1, &phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002662 phy_data |= IXGBE_X557_LED_MANUAL_SET_MASK;
2663 hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002664 MDIO_MMD_VEND1, phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002665
2666 return 0;
2667}
2668
2669/**
2670 * ixgbe_led_off_t_x550em - Turns off the software controllable LEDs.
2671 * @hw: pointer to hardware structure
2672 * @led_idx: led number to turn off
2673 **/
Emil Tantilovd2d43e52016-08-22 16:28:34 -07002674static s32 ixgbe_led_off_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002675{
2676 u16 phy_data;
2677
2678 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
2679 return IXGBE_ERR_PARAM;
2680
2681 /* To turn on the LED, set mode to ON. */
2682 hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002683 MDIO_MMD_VEND1, &phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002684 phy_data &= ~IXGBE_X557_LED_MANUAL_SET_MASK;
2685 hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002686 MDIO_MMD_VEND1, phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002687
2688 return 0;
2689}
2690
Tony Nguyencb8e0512016-10-26 16:25:18 -07002691/**
2692 * ixgbe_set_fw_drv_ver_x550 - Sends driver version to firmware
2693 * @hw: pointer to the HW structure
2694 * @maj: driver version major number
2695 * @min: driver version minor number
2696 * @build: driver version build number
2697 * @sub: driver version sub build number
2698 * @len: length of driver_ver string
2699 * @driver_ver: driver string
2700 *
2701 * Sends driver version number to firmware through the manageability
2702 * block. On success return 0
2703 * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
2704 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
2705 **/
2706static s32 ixgbe_set_fw_drv_ver_x550(struct ixgbe_hw *hw, u8 maj, u8 min,
2707 u8 build, u8 sub, u16 len,
2708 const char *driver_ver)
2709{
2710 struct ixgbe_hic_drv_info2 fw_cmd;
2711 s32 ret_val;
2712 int i;
2713
2714 if (!len || !driver_ver || (len > sizeof(fw_cmd.driver_string)))
2715 return IXGBE_ERR_INVALID_ARGUMENT;
2716
2717 fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
2718 fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN + len;
2719 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
2720 fw_cmd.port_num = (u8)hw->bus.func;
2721 fw_cmd.ver_maj = maj;
2722 fw_cmd.ver_min = min;
2723 fw_cmd.ver_build = build;
2724 fw_cmd.ver_sub = sub;
2725 fw_cmd.hdr.checksum = 0;
2726 memcpy(fw_cmd.driver_string, driver_ver, len);
2727 fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
2728 (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
2729
2730 for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
2731 ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
2732 sizeof(fw_cmd),
2733 IXGBE_HI_COMMAND_TIMEOUT,
2734 true);
2735 if (ret_val)
2736 continue;
2737
2738 if (fw_cmd.hdr.cmd_or_resp.ret_status !=
2739 FW_CEM_RESP_STATUS_SUCCESS)
2740 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
2741 return 0;
2742 }
2743
2744 return ret_val;
2745}
2746
Don Skidmore6ac74392015-06-17 17:34:31 -04002747/** ixgbe_get_lcd_x550em - Determine lowest common denominator
2748 * @hw: pointer to hardware structure
2749 * @lcd_speed: pointer to lowest common link speed
2750 *
2751 * Determine lowest common link speed with link partner.
2752 **/
2753static s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw,
2754 ixgbe_link_speed *lcd_speed)
2755{
2756 u16 an_lp_status;
2757 s32 status;
2758 u16 word = hw->eeprom.ctrl_word_3;
2759
2760 *lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
2761
2762 status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002763 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04002764 &an_lp_status);
2765 if (status)
2766 return status;
2767
2768 /* If link partner advertised 1G, return 1G */
2769 if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
2770 *lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
2771 return status;
2772 }
2773
2774 /* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
2775 if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
2776 (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
2777 return status;
2778
2779 /* Link partner not capable of lower speeds, return 10G */
2780 *lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
2781 return status;
2782}
2783
Mark Rustadafdc71e2016-01-25 16:32:10 -08002784/**
2785 * ixgbe_setup_fc_x550em - Set up flow control
2786 * @hw: pointer to hardware structure
2787 */
2788static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *hw)
2789{
2790 bool pause, asm_dir;
2791 u32 reg_val;
2792 s32 rc;
2793
2794 /* Validate the requested mode */
2795 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2796 hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
2797 return IXGBE_ERR_INVALID_LINK_SETTINGS;
2798 }
2799
2800 /* 10gig parts do not have a word in the EEPROM to determine the
2801 * default flow control setting, so we explicitly set it to full.
2802 */
2803 if (hw->fc.requested_mode == ixgbe_fc_default)
2804 hw->fc.requested_mode = ixgbe_fc_full;
2805
2806 /* Determine PAUSE and ASM_DIR bits. */
2807 switch (hw->fc.requested_mode) {
2808 case ixgbe_fc_none:
2809 pause = false;
2810 asm_dir = false;
2811 break;
2812 case ixgbe_fc_tx_pause:
2813 pause = false;
2814 asm_dir = true;
2815 break;
2816 case ixgbe_fc_rx_pause:
2817 /* Rx Flow control is enabled and Tx Flow control is
2818 * disabled by software override. Since there really
2819 * isn't a way to advertise that we are capable of RX
2820 * Pause ONLY, we will advertise that we support both
2821 * symmetric and asymmetric Rx PAUSE, as such we fall
2822 * through to the fc_full statement. Later, we will
2823 * disable the adapter's ability to send PAUSE frames.
2824 */
2825 /* Fallthrough */
2826 case ixgbe_fc_full:
2827 pause = true;
2828 asm_dir = true;
2829 break;
2830 default:
2831 hw_err(hw, "Flow control param set incorrectly\n");
2832 return IXGBE_ERR_CONFIG;
2833 }
2834
Mark Rustadf572b2c2016-04-01 12:18:46 -07002835 if (hw->device_id != IXGBE_DEV_ID_X550EM_X_KR &&
2836 hw->device_id != IXGBE_DEV_ID_X550EM_A_KR &&
2837 hw->device_id != IXGBE_DEV_ID_X550EM_A_KR_L)
Mark Rustadafdc71e2016-01-25 16:32:10 -08002838 return 0;
2839
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002840 rc = hw->mac.ops.read_iosf_sb_reg(hw,
2841 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2842 IXGBE_SB_IOSF_TARGET_KR_PHY,
2843 &reg_val);
Mark Rustadafdc71e2016-01-25 16:32:10 -08002844 if (rc)
2845 return rc;
2846
2847 reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
2848 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
2849 if (pause)
2850 reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
2851 if (asm_dir)
2852 reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002853 rc = hw->mac.ops.write_iosf_sb_reg(hw,
2854 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2855 IXGBE_SB_IOSF_TARGET_KR_PHY,
2856 reg_val);
Mark Rustadafdc71e2016-01-25 16:32:10 -08002857
2858 /* This device does not fully support AN. */
2859 hw->fc.disable_fc_autoneg = true;
2860
2861 return rc;
2862}
2863
Don Skidmore29165002016-09-27 14:31:12 -04002864/**
2865 * ixgbe_fc_autoneg_backplane_x550em_a - Enable flow control IEEE clause 37
2866 * @hw: pointer to hardware structure
2867 **/
2868static void ixgbe_fc_autoneg_backplane_x550em_a(struct ixgbe_hw *hw)
2869{
2870 u32 link_s1, lp_an_page_low, an_cntl_1;
2871 s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2872 ixgbe_link_speed speed;
2873 bool link_up;
2874
2875 /* AN should have completed when the cable was plugged in.
2876 * Look for reasons to bail out. Bail out if:
2877 * - FC autoneg is disabled, or if
2878 * - link is not up.
2879 */
2880 if (hw->fc.disable_fc_autoneg) {
2881 hw_err(hw, "Flow control autoneg is disabled");
2882 goto out;
2883 }
2884
2885 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2886 if (!link_up) {
2887 hw_err(hw, "The link is down");
2888 goto out;
2889 }
2890
2891 /* Check at auto-negotiation has completed */
2892 status = hw->mac.ops.read_iosf_sb_reg(hw,
2893 IXGBE_KRM_LINK_S1(hw->bus.lan_id),
2894 IXGBE_SB_IOSF_TARGET_KR_PHY, &link_s1);
2895
2896 if (status || (link_s1 & IXGBE_KRM_LINK_S1_MAC_AN_COMPLETE) == 0) {
2897 hw_dbg(hw, "Auto-Negotiation did not complete\n");
2898 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2899 goto out;
2900 }
2901
2902 /* Read the 10g AN autoc and LP ability registers and resolve
2903 * local flow control settings accordingly
2904 */
2905 status = hw->mac.ops.read_iosf_sb_reg(hw,
2906 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2907 IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl_1);
2908
2909 if (status) {
2910 hw_dbg(hw, "Auto-Negotiation did not complete\n");
2911 goto out;
2912 }
2913
2914 status = hw->mac.ops.read_iosf_sb_reg(hw,
2915 IXGBE_KRM_LP_BASE_PAGE_HIGH(hw->bus.lan_id),
2916 IXGBE_SB_IOSF_TARGET_KR_PHY, &lp_an_page_low);
2917
2918 if (status) {
2919 hw_dbg(hw, "Auto-Negotiation did not complete\n");
2920 goto out;
2921 }
2922
2923 status = ixgbe_negotiate_fc(hw, an_cntl_1, lp_an_page_low,
2924 IXGBE_KRM_AN_CNTL_1_SYM_PAUSE,
2925 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE,
2926 IXGBE_KRM_LP_BASE_PAGE_HIGH_SYM_PAUSE,
2927 IXGBE_KRM_LP_BASE_PAGE_HIGH_ASM_PAUSE);
2928
2929out:
2930 if (!status) {
2931 hw->fc.fc_was_autonegged = true;
2932 } else {
2933 hw->fc.fc_was_autonegged = false;
2934 hw->fc.current_mode = hw->fc.requested_mode;
2935 }
2936}
2937
2938/**
2939 * ixgbe_fc_autoneg_fiber_x550em_a - passthrough FC settings
2940 * @hw: pointer to hardware structure
2941 **/
2942static void ixgbe_fc_autoneg_fiber_x550em_a(struct ixgbe_hw *hw)
2943{
2944 hw->fc.fc_was_autonegged = false;
2945 hw->fc.current_mode = hw->fc.requested_mode;
2946}
2947
Don Skidmore6ac74392015-06-17 17:34:31 -04002948/** ixgbe_enter_lplu_x550em - Transition to low power states
2949 * @hw: pointer to hardware structure
2950 *
2951 * Configures Low Power Link Up on transition to low power states
2952 * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting
2953 * the X557 PHY immediately prior to entering LPLU.
2954 **/
2955static s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
2956{
2957 u16 an_10g_cntl_reg, autoneg_reg, speed;
2958 s32 status;
2959 ixgbe_link_speed lcd_speed;
2960 u32 save_autoneg;
2961 bool link_up;
2962
Don Skidmore6ac74392015-06-17 17:34:31 -04002963 /* If blocked by MNG FW, then don't restart AN */
2964 if (ixgbe_check_reset_blocked(hw))
2965 return 0;
2966
2967 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2968 if (status)
2969 return status;
2970
2971 status = hw->eeprom.ops.read(hw, NVM_INIT_CTRL_3,
2972 &hw->eeprom.ctrl_word_3);
2973 if (status)
2974 return status;
2975
2976 /* If link is down, LPLU disabled in NVM, WoL disabled, or
2977 * manageability disabled, then force link down by entering
2978 * low power mode.
2979 */
2980 if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
2981 !(hw->wol_enabled || ixgbe_mng_present(hw)))
2982 return ixgbe_set_copper_phy_power(hw, false);
2983
2984 /* Determine LCD */
2985 status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
2986 if (status)
2987 return status;
2988
2989 /* If no valid LCD link speed, then force link down and exit. */
2990 if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
2991 return ixgbe_set_copper_phy_power(hw, false);
2992
2993 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002994 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04002995 &speed);
2996 if (status)
2997 return status;
2998
2999 /* If no link now, speed is invalid so take link down */
3000 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
3001 if (status)
3002 return ixgbe_set_copper_phy_power(hw, false);
3003
3004 /* clear everything but the speed bits */
3005 speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
3006
3007 /* If current speed is already LCD, then exit. */
3008 if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
3009 (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
3010 ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
3011 (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
3012 return status;
3013
3014 /* Clear AN completed indication */
3015 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003016 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003017 &autoneg_reg);
3018 if (status)
3019 return status;
3020
Emil Tantilov4dc40002016-09-26 14:08:13 -07003021 status = hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
3022 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003023 &an_10g_cntl_reg);
3024 if (status)
3025 return status;
3026
3027 status = hw->phy.ops.read_reg(hw,
3028 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003029 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003030 &autoneg_reg);
3031 if (status)
3032 return status;
3033
3034 save_autoneg = hw->phy.autoneg_advertised;
3035
3036 /* Setup link at least common link speed */
3037 status = hw->mac.ops.setup_link(hw, lcd_speed, false);
3038
3039 /* restore autoneg from before setting lplu speed */
3040 hw->phy.autoneg_advertised = save_autoneg;
3041
3042 return status;
3043}
3044
Mark Rustad537cc5d2016-04-01 12:18:25 -07003045/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003046 * ixgbe_reset_phy_fw - Reset firmware-controlled PHYs
3047 * @hw: pointer to hardware structure
3048 */
3049static s32 ixgbe_reset_phy_fw(struct ixgbe_hw *hw)
3050{
3051 u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
3052 s32 rc;
3053
3054 if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
3055 return 0;
3056
3057 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_PHY_SW_RESET, &store);
3058 if (rc)
3059 return rc;
3060 memset(store, 0, sizeof(store));
3061
3062 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_INIT_PHY, &store);
3063 if (rc)
3064 return rc;
3065
3066 return ixgbe_setup_fw_link(hw);
3067}
3068
3069/**
3070 * ixgbe_check_overtemp_fw - Check firmware-controlled PHYs for overtemp
3071 * @hw: pointer to hardware structure
3072 */
3073static s32 ixgbe_check_overtemp_fw(struct ixgbe_hw *hw)
3074{
3075 u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
3076 s32 rc;
3077
3078 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &store);
3079 if (rc)
3080 return rc;
3081
3082 if (store[0] & FW_PHY_ACT_GET_LINK_INFO_TEMP) {
3083 ixgbe_shutdown_fw_phy(hw);
3084 return IXGBE_ERR_OVERTEMP;
3085 }
3086 return 0;
3087}
3088
3089/**
Mark Rustad537cc5d2016-04-01 12:18:25 -07003090 * ixgbe_read_mng_if_sel_x550em - Read NW_MNG_IF_SEL register
3091 * @hw: pointer to hardware structure
3092 *
3093 * Read NW_MNG_IF_SEL register and save field values.
3094 */
3095static void ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw)
3096{
3097 /* Save NW management interface connected on board. This is used
3098 * to determine internal PHY mode.
3099 */
3100 hw->phy.nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
3101
3102 /* If X552 (X550EM_a) and MDIO is connected to external PHY, then set
3103 * PHY address. This register field was has only been used for X552.
3104 */
Mark Rustadae3cb8c2016-08-30 11:33:43 -07003105 if (hw->mac.type == ixgbe_mac_x550em_a &&
3106 hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_MDIO_ACT) {
3107 hw->phy.mdio.prtad = (hw->phy.nw_mng_if_sel &
3108 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
3109 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
Mark Rustad537cc5d2016-04-01 12:18:25 -07003110 }
Mark Rustad537cc5d2016-04-01 12:18:25 -07003111}
3112
Don Skidmore6a14ee02014-12-05 03:59:50 +00003113/** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
3114 * @hw: pointer to hardware structure
3115 *
3116 * Initialize any function pointers that were not able to be
3117 * set during init_shared_code because the PHY/SFP type was
3118 * not known. Perform the SFP init if necessary.
3119 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00003120static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003121{
3122 struct ixgbe_phy_info *phy = &hw->phy;
3123 s32 ret_val;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003124
Don Skidmore7e49d612015-06-09 17:48:54 -07003125 hw->mac.ops.set_lan_id(hw);
3126
Mark Rustad537cc5d2016-04-01 12:18:25 -07003127 ixgbe_read_mng_if_sel_x550em(hw);
3128
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003129 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003130 phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
Don Skidmoreab5fe0c2015-06-09 16:18:56 -07003131 ixgbe_setup_mux_ctl(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +00003132 }
3133
3134 /* Identify the PHY or SFP module */
3135 ret_val = phy->ops.identify(hw);
3136
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003137 /* Setup function pointers based on detected hardware */
Don Skidmore6a14ee02014-12-05 03:59:50 +00003138 ixgbe_init_mac_link_ops_X550em(hw);
3139 if (phy->sfp_type != ixgbe_sfp_type_unknown)
3140 phy->ops.reset = NULL;
3141
3142 /* Set functions pointers based on phy type */
3143 switch (hw->phy.type) {
3144 case ixgbe_phy_x550em_kx4:
Tony Nguyen5fbf5ad2016-11-01 13:58:27 -07003145 phy->ops.setup_link = NULL;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003146 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
3147 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
3148 break;
3149 case ixgbe_phy_x550em_kr:
3150 phy->ops.setup_link = ixgbe_setup_kr_x550em;
3151 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
3152 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
3153 break;
Don Skidmore18e01ee2016-12-30 21:07:58 -05003154 case ixgbe_phy_x550em_xfi:
3155 /* link is managed by HW */
3156 phy->ops.setup_link = NULL;
3157 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
3158 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
3159 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003160 case ixgbe_phy_x550em_ext_t:
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003161 /* Save NW management interface connected on board. This is used
3162 * to determine internal PHY mode
3163 */
3164 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
3165
3166 /* If internal link mode is XFI, then setup iXFI internal link,
3167 * else setup KR now.
3168 */
Mark Rustadf164b842015-10-16 13:27:49 -07003169 phy->ops.setup_internal_link =
3170 ixgbe_setup_internal_phy_t_x550em;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003171
Don Skidmore6ac74392015-06-17 17:34:31 -04003172 /* setup SW LPLU only for first revision */
Mark Rustad3ca2b252015-11-20 13:12:17 -08003173 if (hw->mac.type == ixgbe_mac_X550EM_x &&
3174 !(IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0)) &
3175 IXGBE_FUSES0_REV_MASK))
Don Skidmore6ac74392015-06-17 17:34:31 -04003176 phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
3177
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003178 phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
Don Skidmoref4410d22015-06-09 16:29:51 -07003179 phy->ops.reset = ixgbe_reset_phy_t_X550em;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003180 break;
Don Skidmore18bda0d2016-12-30 21:07:14 -05003181 case ixgbe_phy_sgmii:
3182 phy->ops.setup_link = NULL;
3183 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003184 case ixgbe_phy_fw:
3185 phy->ops.setup_link = ixgbe_setup_fw_link;
3186 phy->ops.reset = ixgbe_reset_phy_fw;
3187 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003188 default:
3189 break;
3190 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003191
Don Skidmore6a14ee02014-12-05 03:59:50 +00003192 return ret_val;
3193}
3194
3195/** ixgbe_get_media_type_X550em - Get media type
3196 * @hw: pointer to hardware structure
3197 *
3198 * Returns the media type (fiber, copper, backplane)
3199 *
3200 */
Don Skidmore7ddbde32014-12-06 05:59:21 +00003201static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003202{
3203 enum ixgbe_media_type media_type;
3204
3205 /* Detect if there is a copper PHY attached. */
3206 switch (hw->device_id) {
Mark Rustad200157c2016-04-01 12:18:40 -07003207 case IXGBE_DEV_ID_X550EM_A_SGMII:
3208 case IXGBE_DEV_ID_X550EM_A_SGMII_L:
3209 hw->phy.type = ixgbe_phy_sgmii;
3210 /* Fallthrough */
Don Skidmore6a14ee02014-12-05 03:59:50 +00003211 case IXGBE_DEV_ID_X550EM_X_KR:
3212 case IXGBE_DEV_ID_X550EM_X_KX4:
Don Skidmore18e01ee2016-12-30 21:07:58 -05003213 case IXGBE_DEV_ID_X550EM_X_XFI:
Mark Rustadf572b2c2016-04-01 12:18:46 -07003214 case IXGBE_DEV_ID_X550EM_A_KR:
3215 case IXGBE_DEV_ID_X550EM_A_KR_L:
Don Skidmore6a14ee02014-12-05 03:59:50 +00003216 media_type = ixgbe_media_type_backplane;
3217 break;
3218 case IXGBE_DEV_ID_X550EM_X_SFP:
Mark Rustad2d40cd12016-04-01 12:18:35 -07003219 case IXGBE_DEV_ID_X550EM_A_SFP:
Mark Rustad49425df2016-04-01 12:18:09 -07003220 case IXGBE_DEV_ID_X550EM_A_SFP_N:
Don Skidmore6a14ee02014-12-05 03:59:50 +00003221 media_type = ixgbe_media_type_fiber;
3222 break;
3223 case IXGBE_DEV_ID_X550EM_X_1G_T:
3224 case IXGBE_DEV_ID_X550EM_X_10G_T:
Don Skidmore92ed8432016-08-17 20:34:40 -04003225 case IXGBE_DEV_ID_X550EM_A_10G_T:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003226 case IXGBE_DEV_ID_X550EM_A_1G_T:
3227 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
Mark Rustad49425df2016-04-01 12:18:09 -07003228 media_type = ixgbe_media_type_copper;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003229 break;
3230 default:
3231 media_type = ixgbe_media_type_unknown;
3232 break;
3233 }
3234 return media_type;
3235}
3236
3237/** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
3238 ** @hw: pointer to hardware structure
3239 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00003240static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003241{
Mark Rustada1e869d2015-04-10 10:36:36 -07003242 s32 status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003243 u16 reg;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003244
Don Skidmore6a14ee02014-12-05 03:59:50 +00003245 status = hw->phy.ops.read_reg(hw,
Don Skidmoree2261bc2015-06-09 17:02:35 -07003246 IXGBE_MDIO_TX_VENDOR_ALARMS_3,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003247 MDIO_MMD_PMAPMD,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003248 &reg);
3249 if (status)
3250 return status;
3251
Don Skidmoree2261bc2015-06-09 17:02:35 -07003252 /* If PHY FW reset completed bit is set then this is the first
3253 * SW instance after a power on so the PHY FW must be un-stalled.
3254 */
3255 if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
3256 status = hw->phy.ops.read_reg(hw,
3257 IXGBE_MDIO_GLOBAL_RES_PR_10,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003258 MDIO_MMD_VEND1,
Don Skidmoree2261bc2015-06-09 17:02:35 -07003259 &reg);
3260 if (status)
3261 return status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003262
Don Skidmoree2261bc2015-06-09 17:02:35 -07003263 reg &= ~IXGBE_MDIO_POWER_UP_STALL;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003264
Don Skidmoree2261bc2015-06-09 17:02:35 -07003265 status = hw->phy.ops.write_reg(hw,
3266 IXGBE_MDIO_GLOBAL_RES_PR_10,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003267 MDIO_MMD_VEND1,
Don Skidmoree2261bc2015-06-09 17:02:35 -07003268 reg);
3269 if (status)
3270 return status;
3271 }
Don Skidmore6a14ee02014-12-05 03:59:50 +00003272
Don Skidmore6a14ee02014-12-05 03:59:50 +00003273 return status;
3274}
3275
Mark Rustade84db722016-04-01 12:18:30 -07003276/**
3277 * ixgbe_set_mdio_speed - Set MDIO clock speed
3278 * @hw: pointer to hardware structure
3279 */
3280static void ixgbe_set_mdio_speed(struct ixgbe_hw *hw)
3281{
3282 u32 hlreg0;
3283
3284 switch (hw->device_id) {
3285 case IXGBE_DEV_ID_X550EM_X_10G_T:
Don Skidmorea83c27e2016-08-17 17:34:07 -04003286 case IXGBE_DEV_ID_X550EM_A_SGMII:
3287 case IXGBE_DEV_ID_X550EM_A_SGMII_L:
Don Skidmore92ed8432016-08-17 20:34:40 -04003288 case IXGBE_DEV_ID_X550EM_A_10G_T:
Mark Rustad2d40cd12016-04-01 12:18:35 -07003289 case IXGBE_DEV_ID_X550EM_A_SFP:
Mark Rustade84db722016-04-01 12:18:30 -07003290 /* Config MDIO clock speed before the first MDIO PHY access */
3291 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3292 hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
3293 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3294 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003295 case IXGBE_DEV_ID_X550EM_A_1G_T:
3296 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
3297 /* Select fast MDIO clock speed for these devices */
3298 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3299 hlreg0 |= IXGBE_HLREG0_MDCSPD;
3300 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3301 break;
Mark Rustade84db722016-04-01 12:18:30 -07003302 default:
3303 break;
3304 }
3305}
3306
Don Skidmore6a14ee02014-12-05 03:59:50 +00003307/** ixgbe_reset_hw_X550em - Perform hardware reset
3308 ** @hw: pointer to hardware structure
3309 **
3310 ** Resets the hardware by resetting the transmit and receive units, masks
3311 ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
3312 ** reset.
3313 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00003314static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003315{
3316 ixgbe_link_speed link_speed;
3317 s32 status;
3318 u32 ctrl = 0;
3319 u32 i;
3320 bool link_up = false;
Paul Greenwalt61334062017-03-13 05:47:56 -04003321 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003322
3323 /* Call adapter stop to disable Tx/Rx and clear interrupts */
3324 status = hw->mac.ops.stop_adapter(hw);
3325 if (status)
3326 return status;
3327
3328 /* flush pending Tx transactions */
3329 ixgbe_clear_tx_pending(hw);
3330
3331 /* PHY ops must be identified and initialized prior to reset */
3332
3333 /* Identify PHY and related function pointers */
3334 status = hw->phy.ops.init(hw);
3335
3336 /* start the external PHY */
3337 if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
3338 status = ixgbe_init_ext_t_x550em(hw);
3339 if (status)
3340 return status;
3341 }
3342
3343 /* Setup SFP module if there is one present. */
3344 if (hw->phy.sfp_setup_needed) {
3345 status = hw->mac.ops.setup_sfp(hw);
3346 hw->phy.sfp_setup_needed = false;
3347 }
3348
3349 /* Reset PHY */
3350 if (!hw->phy.reset_disable && hw->phy.ops.reset)
3351 hw->phy.ops.reset(hw);
3352
3353mac_reset_top:
3354 /* Issue global reset to the MAC. Needs to be SW reset if link is up.
3355 * If link reset is used when link is up, it might reset the PHY when
3356 * mng is using it. If link is down or the flag to force full link
3357 * reset is set, then perform link reset.
3358 */
3359 ctrl = IXGBE_CTRL_LNK_RST;
3360
3361 if (!hw->force_full_reset) {
3362 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3363 if (link_up)
3364 ctrl = IXGBE_CTRL_RST;
3365 }
3366
Paul Greenwalt61334062017-03-13 05:47:56 -04003367 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
3368 if (status) {
3369 hw_dbg(hw, "semaphore failed with %d", status);
3370 return IXGBE_ERR_SWFW_SYNC;
3371 }
3372
Don Skidmore6a14ee02014-12-05 03:59:50 +00003373 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
3374 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
3375 IXGBE_WRITE_FLUSH(hw);
Paul Greenwalt61334062017-03-13 05:47:56 -04003376 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Mark Rustadefff2e02015-10-27 13:23:14 -07003377 usleep_range(1000, 1200);
Don Skidmore6a14ee02014-12-05 03:59:50 +00003378
3379 /* Poll for reset bit to self-clear meaning reset is complete */
3380 for (i = 0; i < 10; i++) {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003381 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
3382 if (!(ctrl & IXGBE_CTRL_RST_MASK))
3383 break;
Mark Rustadefff2e02015-10-27 13:23:14 -07003384 udelay(1);
Don Skidmore6a14ee02014-12-05 03:59:50 +00003385 }
3386
3387 if (ctrl & IXGBE_CTRL_RST_MASK) {
3388 status = IXGBE_ERR_RESET_FAILED;
3389 hw_dbg(hw, "Reset polling failed to complete.\n");
3390 }
3391
3392 msleep(50);
3393
3394 /* Double resets are required for recovery from certain error
3395 * clear the multicast table. Also reset num_rar_entries to 128,
3396 * since we modify this value when programming the SAN MAC address.
3397 */
3398 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
3399 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3400 goto mac_reset_top;
3401 }
3402
3403 /* Store the permanent mac address */
3404 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
3405
3406 /* Store MAC address from RAR0, clear receive address registers, and
3407 * clear the multicast table. Also reset num_rar_entries to 128,
3408 * since we modify this value when programming the SAN MAC address.
3409 */
3410 hw->mac.num_rar_entries = 128;
3411 hw->mac.ops.init_rx_addrs(hw);
3412
Mark Rustade84db722016-04-01 12:18:30 -07003413 ixgbe_set_mdio_speed(hw);
Don Skidmorededa5622015-06-09 17:39:46 -07003414
Don Skidmoreab5fe0c2015-06-09 16:18:56 -07003415 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
3416 ixgbe_setup_mux_ctl(hw);
3417
Don Skidmore6a14ee02014-12-05 03:59:50 +00003418 return status;
3419}
3420
Don Skidmore5b7f0002015-01-28 07:03:38 +00003421/** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype
3422 * anti-spoofing
3423 * @hw: pointer to hardware structure
3424 * @enable: enable or disable switch for Ethertype anti-spoofing
3425 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
3426 **/
Don Skidmorebc035fc2015-03-13 14:03:25 -07003427static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
3428 bool enable, int vf)
Don Skidmore5b7f0002015-01-28 07:03:38 +00003429{
3430 int vf_target_reg = vf >> 3;
3431 int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
3432 u32 pfvfspoof;
3433
3434 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3435 if (enable)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003436 pfvfspoof |= BIT(vf_target_shift);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003437 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003438 pfvfspoof &= ~BIT(vf_target_shift);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003439
3440 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3441}
3442
Don Skidmore6d4c96a2015-04-09 22:03:23 -07003443/** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning
3444 * @hw: pointer to hardware structure
3445 * @enable: enable or disable source address pruning
3446 * @pool: Rx pool to set source address pruning for
3447 **/
3448static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw,
3449 bool enable,
3450 unsigned int pool)
3451{
3452 u64 pfflp;
3453
3454 /* max rx pool is 63 */
3455 if (pool > 63)
3456 return;
3457
3458 pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
3459 pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
3460
3461 if (enable)
3462 pfflp |= (1ULL << pool);
3463 else
3464 pfflp &= ~(1ULL << pool);
3465
3466 IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
3467 IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
3468}
3469
Mark Rustad449e21a2015-08-08 16:18:53 -07003470/**
Don Skidmore29165002016-09-27 14:31:12 -04003471 * ixgbe_setup_fc_backplane_x550em_a - Set up flow control
3472 * @hw: pointer to hardware structure
3473 *
3474 * Called at init time to set up flow control.
3475 **/
3476static s32 ixgbe_setup_fc_backplane_x550em_a(struct ixgbe_hw *hw)
3477{
3478 s32 status = 0;
Don Skidmore29165002016-09-27 14:31:12 -04003479 u32 an_cntl = 0;
3480
3481 /* Validate the requested mode */
3482 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
3483 hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
3484 return IXGBE_ERR_INVALID_LINK_SETTINGS;
3485 }
3486
3487 if (hw->fc.requested_mode == ixgbe_fc_default)
3488 hw->fc.requested_mode = ixgbe_fc_full;
3489
3490 /* Set up the 1G and 10G flow control advertisement registers so the
3491 * HW will be able to do FC autoneg once the cable is plugged in. If
3492 * we link at 10G, the 1G advertisement is harmless and vice versa.
3493 */
3494 status = hw->mac.ops.read_iosf_sb_reg(hw,
3495 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
3496 IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl);
3497
3498 if (status) {
3499 hw_dbg(hw, "Auto-Negotiation did not complete\n");
3500 return status;
3501 }
3502
3503 /* The possible values of fc.requested_mode are:
3504 * 0: Flow control is completely disabled
3505 * 1: Rx flow control is enabled (we can receive pause frames,
3506 * but not send pause frames).
3507 * 2: Tx flow control is enabled (we can send pause frames but
3508 * we do not support receiving pause frames).
3509 * 3: Both Rx and Tx flow control (symmetric) are enabled.
3510 * other: Invalid.
3511 */
3512 switch (hw->fc.requested_mode) {
3513 case ixgbe_fc_none:
3514 /* Flow control completely disabled by software override. */
3515 an_cntl &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
3516 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
3517 break;
3518 case ixgbe_fc_tx_pause:
3519 /* Tx Flow control is enabled, and Rx Flow control is
3520 * disabled by software override.
3521 */
3522 an_cntl |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
3523 an_cntl &= ~IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
3524 break;
3525 case ixgbe_fc_rx_pause:
3526 /* Rx Flow control is enabled and Tx Flow control is
3527 * disabled by software override. Since there really
3528 * isn't a way to advertise that we are capable of RX
3529 * Pause ONLY, we will advertise that we support both
3530 * symmetric and asymmetric Rx PAUSE, as such we fall
3531 * through to the fc_full statement. Later, we will
3532 * disable the adapter's ability to send PAUSE frames.
3533 */
3534 case ixgbe_fc_full:
3535 /* Flow control (both Rx and Tx) is enabled by SW override. */
3536 an_cntl |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
3537 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
3538 break;
3539 default:
3540 hw_err(hw, "Flow control param set incorrectly\n");
3541 return IXGBE_ERR_CONFIG;
3542 }
3543
3544 status = hw->mac.ops.write_iosf_sb_reg(hw,
3545 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
3546 IXGBE_SB_IOSF_TARGET_KR_PHY, an_cntl);
3547
3548 /* Restart auto-negotiation. */
Don Skidmore470739b2016-11-03 21:01:37 -04003549 status = ixgbe_restart_an_internal_phy_x550em(hw);
Don Skidmore29165002016-09-27 14:31:12 -04003550
3551 return status;
3552}
3553
3554/**
Mark Rustad449e21a2015-08-08 16:18:53 -07003555 * ixgbe_set_mux - Set mux for port 1 access with CS4227
3556 * @hw: pointer to hardware structure
3557 * @state: set mux if 1, clear if 0
3558 */
3559static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
3560{
3561 u32 esdp;
3562
3563 if (!hw->bus.lan_id)
3564 return;
3565 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3566 if (state)
3567 esdp |= IXGBE_ESDP_SDP1;
3568 else
3569 esdp &= ~IXGBE_ESDP_SDP1;
3570 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
3571 IXGBE_WRITE_FLUSH(hw);
3572}
3573
3574/**
3575 * ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
3576 * @hw: pointer to hardware structure
3577 * @mask: Mask to specify which semaphore to acquire
3578 *
3579 * Acquires the SWFW semaphore and sets the I2C MUX
3580 */
3581static s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
3582{
3583 s32 status;
3584
3585 status = ixgbe_acquire_swfw_sync_X540(hw, mask);
3586 if (status)
3587 return status;
3588
3589 if (mask & IXGBE_GSSR_I2C_MASK)
3590 ixgbe_set_mux(hw, 1);
3591
3592 return 0;
3593}
3594
3595/**
3596 * ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
3597 * @hw: pointer to hardware structure
3598 * @mask: Mask to specify which semaphore to release
3599 *
3600 * Releases the SWFW semaphore and sets the I2C MUX
3601 */
3602static void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
3603{
3604 if (mask & IXGBE_GSSR_I2C_MASK)
3605 ixgbe_set_mux(hw, 0);
3606
3607 ixgbe_release_swfw_sync_X540(hw, mask);
3608}
3609
Mark Rustad49425df2016-04-01 12:18:09 -07003610/**
3611 * ixgbe_acquire_swfw_sync_x550em_a - Acquire SWFW semaphore
3612 * @hw: pointer to hardware structure
3613 * @mask: Mask to specify which semaphore to acquire
3614 *
3615 * Acquires the SWFW semaphore and get the shared PHY token as needed
3616 */
3617static s32 ixgbe_acquire_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
3618{
3619 u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
3620 int retries = FW_PHY_TOKEN_RETRIES;
3621 s32 status;
3622
3623 while (--retries) {
3624 status = 0;
3625 if (hmask)
3626 status = ixgbe_acquire_swfw_sync_X540(hw, hmask);
3627 if (status)
3628 return status;
3629 if (!(mask & IXGBE_GSSR_TOKEN_SM))
3630 return 0;
3631
3632 status = ixgbe_get_phy_token(hw);
3633 if (!status)
3634 return 0;
3635 if (hmask)
3636 ixgbe_release_swfw_sync_X540(hw, hmask);
3637 if (status != IXGBE_ERR_TOKEN_RETRY)
3638 return status;
Arnd Bergmannd4f90d92016-04-16 22:35:08 +02003639 msleep(FW_PHY_TOKEN_DELAY);
Mark Rustad49425df2016-04-01 12:18:09 -07003640 }
3641
3642 return status;
3643}
3644
3645/**
3646 * ixgbe_release_swfw_sync_x550em_a - Release SWFW semaphore
3647 * @hw: pointer to hardware structure
3648 * @mask: Mask to specify which semaphore to release
3649 *
3650 * Release the SWFW semaphore and puts the shared PHY token as needed
3651 */
3652static void ixgbe_release_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
3653{
3654 u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
3655
3656 if (mask & IXGBE_GSSR_TOKEN_SM)
3657 ixgbe_put_phy_token(hw);
3658
3659 if (hmask)
3660 ixgbe_release_swfw_sync_X540(hw, hmask);
3661}
3662
Mark Rustadd31afc82016-04-01 12:18:14 -07003663/**
3664 * ixgbe_read_phy_reg_x550a - Reads specified PHY register
3665 * @hw: pointer to hardware structure
3666 * @reg_addr: 32 bit address of PHY register to read
3667 * @phy_data: Pointer to read data from PHY register
3668 *
3669 * Reads a value from a specified PHY register using the SWFW lock and PHY
3670 * Token. The PHY Token is needed since the MDIO is shared between to MAC
3671 * instances.
3672 */
3673static s32 ixgbe_read_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
3674 u32 device_type, u16 *phy_data)
3675{
3676 u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
3677 s32 status;
3678
3679 if (hw->mac.ops.acquire_swfw_sync(hw, mask))
3680 return IXGBE_ERR_SWFW_SYNC;
3681
3682 status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
3683
3684 hw->mac.ops.release_swfw_sync(hw, mask);
3685
3686 return status;
3687}
3688
3689/**
3690 * ixgbe_write_phy_reg_x550a - Writes specified PHY register
3691 * @hw: pointer to hardware structure
3692 * @reg_addr: 32 bit PHY register to write
3693 * @device_type: 5 bit device type
3694 * @phy_data: Data to write to the PHY register
3695 *
3696 * Writes a value to specified PHY register using the SWFW lock and PHY Token.
3697 * The PHY Token is needed since the MDIO is shared between to MAC instances.
3698 */
3699static s32 ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
3700 u32 device_type, u16 phy_data)
3701{
3702 u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
3703 s32 status;
3704
3705 if (hw->mac.ops.acquire_swfw_sync(hw, mask))
3706 return IXGBE_ERR_SWFW_SYNC;
3707
3708 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type, phy_data);
3709 hw->mac.ops.release_swfw_sync(hw, mask);
3710
3711 return status;
3712}
3713
Don Skidmore6a14ee02014-12-05 03:59:50 +00003714#define X550_COMMON_MAC \
3715 .init_hw = &ixgbe_init_hw_generic, \
3716 .start_hw = &ixgbe_start_hw_X540, \
3717 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
3718 .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
3719 .get_mac_addr = &ixgbe_get_mac_addr_generic, \
3720 .get_device_caps = &ixgbe_get_device_caps_generic, \
3721 .stop_adapter = &ixgbe_stop_adapter_generic, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003722 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
3723 .read_analog_reg8 = NULL, \
3724 .write_analog_reg8 = NULL, \
3725 .set_rxpba = &ixgbe_set_rxpba_generic, \
3726 .check_link = &ixgbe_check_mac_link_generic, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003727 .blink_led_start = &ixgbe_blink_led_start_X540, \
3728 .blink_led_stop = &ixgbe_blink_led_stop_X540, \
3729 .set_rar = &ixgbe_set_rar_generic, \
3730 .clear_rar = &ixgbe_clear_rar_generic, \
3731 .set_vmdq = &ixgbe_set_vmdq_generic, \
3732 .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
3733 .clear_vmdq = &ixgbe_clear_vmdq_generic, \
3734 .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
3735 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
3736 .enable_mc = &ixgbe_enable_mc_generic, \
3737 .disable_mc = &ixgbe_disable_mc_generic, \
3738 .clear_vfta = &ixgbe_clear_vfta_generic, \
3739 .set_vfta = &ixgbe_set_vfta_generic, \
3740 .fc_enable = &ixgbe_fc_enable_generic, \
Tony Nguyencb8e0512016-10-26 16:25:18 -07003741 .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_x550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003742 .init_uta_tables = &ixgbe_init_uta_tables_generic, \
3743 .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
3744 .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
Don Skidmore6d4c96a2015-04-09 22:03:23 -07003745 .set_source_address_pruning = \
3746 &ixgbe_set_source_address_pruning_X550, \
Don Skidmore5b7f0002015-01-28 07:03:38 +00003747 .set_ethertype_anti_spoofing = \
3748 &ixgbe_set_ethertype_anti_spoofing_X550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003749 .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
3750 .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
3751 .get_thermal_sensor_data = NULL, \
3752 .init_thermal_sensor_thresh = NULL, \
Don Skidmore1f9ac572015-03-13 13:54:30 -07003753 .enable_rx = &ixgbe_enable_rx_generic, \
3754 .disable_rx = &ixgbe_disable_rx_x550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003755
Mark Rustad37689012016-01-07 10:13:03 -08003756static const struct ixgbe_mac_operations mac_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003757 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04003758 .led_on = ixgbe_led_on_generic,
3759 .led_off = ixgbe_led_off_generic,
Don Skidmore805cedd2016-10-20 21:42:00 -04003760 .init_led_link_act = ixgbe_init_led_link_act_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003761 .reset_hw = &ixgbe_reset_hw_X540,
3762 .get_media_type = &ixgbe_get_media_type_X540,
3763 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
3764 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
3765 .setup_link = &ixgbe_setup_mac_link_X540,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003766 .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
Don Skidmore454c65d2015-06-17 20:59:59 -04003767 .get_bus_info = &ixgbe_get_bus_info_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003768 .setup_sfp = NULL,
Mark Rustad449e21a2015-08-08 16:18:53 -07003769 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
3770 .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
Don Skidmoredbd15b82016-03-09 16:45:00 -05003771 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
Mark Rustadafdc71e2016-01-25 16:32:10 -08003772 .prot_autoc_read = prot_autoc_read_generic,
3773 .prot_autoc_write = prot_autoc_write_generic,
3774 .setup_fc = ixgbe_setup_fc_generic,
Don Skidmore29165002016-09-27 14:31:12 -04003775 .fc_autoneg = ixgbe_fc_autoneg,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003776};
3777
Mark Rustad37689012016-01-07 10:13:03 -08003778static const struct ixgbe_mac_operations mac_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003779 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04003780 .led_on = ixgbe_led_on_t_x550em,
3781 .led_off = ixgbe_led_off_t_x550em,
Don Skidmore805cedd2016-10-20 21:42:00 -04003782 .init_led_link_act = ixgbe_init_led_link_act_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003783 .reset_hw = &ixgbe_reset_hw_X550em,
3784 .get_media_type = &ixgbe_get_media_type_X550em,
3785 .get_san_mac_addr = NULL,
3786 .get_wwn_prefix = NULL,
Emil Tantilov46958862016-03-24 09:58:40 -07003787 .setup_link = &ixgbe_setup_mac_link_X540,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003788 .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
Don Skidmore454c65d2015-06-17 20:59:59 -04003789 .get_bus_info = &ixgbe_get_bus_info_X550em,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003790 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
Mark Rustad449e21a2015-08-08 16:18:53 -07003791 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X550em,
3792 .release_swfw_sync = &ixgbe_release_swfw_sync_X550em,
Don Skidmoredbd15b82016-03-09 16:45:00 -05003793 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
Mark Rustadafdc71e2016-01-25 16:32:10 -08003794 .setup_fc = NULL, /* defined later */
Don Skidmore29165002016-09-27 14:31:12 -04003795 .fc_autoneg = ixgbe_fc_autoneg,
Mark Rustad9a5c27e2016-04-01 12:18:04 -07003796 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550,
3797 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003798};
3799
Mark Rustad49425df2016-04-01 12:18:09 -07003800static struct ixgbe_mac_operations mac_ops_x550em_a = {
3801 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04003802 .led_on = ixgbe_led_on_t_x550em,
3803 .led_off = ixgbe_led_off_t_x550em,
Don Skidmore805cedd2016-10-20 21:42:00 -04003804 .init_led_link_act = ixgbe_init_led_link_act_generic,
Mark Rustad49425df2016-04-01 12:18:09 -07003805 .reset_hw = ixgbe_reset_hw_X550em,
3806 .get_media_type = ixgbe_get_media_type_X550em,
3807 .get_san_mac_addr = NULL,
3808 .get_wwn_prefix = NULL,
Emil Tantilov5b9d3cf2017-01-19 15:55:12 -08003809 .setup_link = &ixgbe_setup_mac_link_X540,
Mark Rustad49425df2016-04-01 12:18:09 -07003810 .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
3811 .get_bus_info = ixgbe_get_bus_info_X550em,
3812 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
3813 .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
3814 .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
Mark Rustada0254a72016-04-08 16:19:29 -07003815 .setup_fc = ixgbe_setup_fc_x550em,
Don Skidmore470739b2016-11-03 21:01:37 -04003816 .fc_autoneg = ixgbe_fc_autoneg,
Mark Rustad49425df2016-04-01 12:18:09 -07003817 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
3818 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
3819};
3820
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003821static struct ixgbe_mac_operations mac_ops_x550em_a_fw = {
3822 X550_COMMON_MAC
3823 .led_on = ixgbe_led_on_generic,
3824 .led_off = ixgbe_led_off_generic,
3825 .init_led_link_act = ixgbe_init_led_link_act_generic,
3826 .reset_hw = ixgbe_reset_hw_X550em,
3827 .get_media_type = ixgbe_get_media_type_X550em,
3828 .get_san_mac_addr = NULL,
3829 .get_wwn_prefix = NULL,
3830 .setup_link = NULL, /* defined later */
3831 .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
3832 .get_bus_info = ixgbe_get_bus_info_X550em,
3833 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
3834 .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
3835 .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
3836 .setup_fc = ixgbe_setup_fc_x550em,
3837 .fc_autoneg = ixgbe_fc_autoneg,
3838 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
3839 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
3840};
3841
Don Skidmore6a14ee02014-12-05 03:59:50 +00003842#define X550_COMMON_EEP \
3843 .read = &ixgbe_read_ee_hostif_X550, \
3844 .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
3845 .write = &ixgbe_write_ee_hostif_X550, \
3846 .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
3847 .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
3848 .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
3849 .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
3850
Mark Rustad37689012016-01-07 10:13:03 -08003851static const struct ixgbe_eeprom_operations eeprom_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003852 X550_COMMON_EEP
3853 .init_params = &ixgbe_init_eeprom_params_X550,
3854};
3855
Mark Rustad37689012016-01-07 10:13:03 -08003856static const struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003857 X550_COMMON_EEP
3858 .init_params = &ixgbe_init_eeprom_params_X540,
3859};
3860
3861#define X550_COMMON_PHY \
3862 .identify_sfp = &ixgbe_identify_module_generic, \
3863 .reset = NULL, \
3864 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
3865 .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
3866 .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
3867 .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
3868 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
3869 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
Don Skidmorebef23de2015-06-09 17:36:53 -07003870 .setup_link = &ixgbe_setup_phy_link_generic, \
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003871 .set_phy_power = NULL,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003872
Mark Rustad37689012016-01-07 10:13:03 -08003873static const struct ixgbe_phy_operations phy_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003874 X550_COMMON_PHY
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003875 .check_overtemp = &ixgbe_tn_check_overtemp,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003876 .init = NULL,
3877 .identify = &ixgbe_identify_phy_generic,
Mark Rustadd31afc82016-04-01 12:18:14 -07003878 .read_reg = &ixgbe_read_phy_reg_generic,
3879 .write_reg = &ixgbe_write_phy_reg_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003880};
3881
Mark Rustad37689012016-01-07 10:13:03 -08003882static const struct ixgbe_phy_operations phy_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003883 X550_COMMON_PHY
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003884 .check_overtemp = &ixgbe_tn_check_overtemp,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003885 .init = &ixgbe_init_phy_ops_X550em,
3886 .identify = &ixgbe_identify_phy_x550em,
Mark Rustadd31afc82016-04-01 12:18:14 -07003887 .read_reg = &ixgbe_read_phy_reg_generic,
3888 .write_reg = &ixgbe_write_phy_reg_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003889};
3890
Mark Rustadd31afc82016-04-01 12:18:14 -07003891static const struct ixgbe_phy_operations phy_ops_x550em_a = {
3892 X550_COMMON_PHY
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003893 .check_overtemp = &ixgbe_tn_check_overtemp,
Mark Rustadd31afc82016-04-01 12:18:14 -07003894 .init = &ixgbe_init_phy_ops_X550em,
3895 .identify = &ixgbe_identify_phy_x550em,
3896 .read_reg = &ixgbe_read_phy_reg_x550a,
3897 .write_reg = &ixgbe_write_phy_reg_x550a,
Mark Rustad8fe293a2016-08-26 14:48:28 -07003898 .read_reg_mdi = &ixgbe_read_phy_reg_mdi,
3899 .write_reg_mdi = &ixgbe_write_phy_reg_mdi,
Mark Rustadd31afc82016-04-01 12:18:14 -07003900};
3901
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003902static const struct ixgbe_phy_operations phy_ops_x550em_a_fw = {
3903 X550_COMMON_PHY
3904 .check_overtemp = ixgbe_check_overtemp_fw,
3905 .init = ixgbe_init_phy_ops_X550em,
3906 .identify = ixgbe_identify_phy_fw,
3907 .read_reg = NULL,
3908 .write_reg = NULL,
3909 .read_reg_mdi = NULL,
3910 .write_reg_mdi = NULL,
3911};
3912
Emil Tantilovb71f6c42016-10-10 14:54:03 -07003913static const struct ixgbe_link_operations link_ops_x550em_x = {
3914 .read_link = &ixgbe_read_i2c_combined_generic,
3915 .read_link_unlocked = &ixgbe_read_i2c_combined_generic_unlocked,
3916 .write_link = &ixgbe_write_i2c_combined_generic,
3917 .write_link_unlocked = &ixgbe_write_i2c_combined_generic_unlocked,
3918};
3919
Don Skidmore9a900ec2015-06-09 17:15:01 -07003920static const u32 ixgbe_mvals_X550[IXGBE_MVALS_IDX_LIMIT] = {
3921 IXGBE_MVALS_INIT(X550)
3922};
3923
3924static const u32 ixgbe_mvals_X550EM_x[IXGBE_MVALS_IDX_LIMIT] = {
3925 IXGBE_MVALS_INIT(X550EM_x)
3926};
3927
Mark Rustad49425df2016-04-01 12:18:09 -07003928static const u32 ixgbe_mvals_x550em_a[IXGBE_MVALS_IDX_LIMIT] = {
3929 IXGBE_MVALS_INIT(X550EM_a)
3930};
3931
Mark Rustad37689012016-01-07 10:13:03 -08003932const struct ixgbe_info ixgbe_X550_info = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003933 .mac = ixgbe_mac_X550,
3934 .get_invariants = &ixgbe_get_invariants_X540,
3935 .mac_ops = &mac_ops_X550,
3936 .eeprom_ops = &eeprom_ops_X550,
3937 .phy_ops = &phy_ops_X550,
3938 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07003939 .mvals = ixgbe_mvals_X550,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003940};
3941
Mark Rustad37689012016-01-07 10:13:03 -08003942const struct ixgbe_info ixgbe_X550EM_x_info = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003943 .mac = ixgbe_mac_X550EM_x,
Don Skidmoreb5529ef2015-06-10 20:42:30 -04003944 .get_invariants = &ixgbe_get_invariants_X550_x,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003945 .mac_ops = &mac_ops_X550EM_x,
3946 .eeprom_ops = &eeprom_ops_X550EM_x,
3947 .phy_ops = &phy_ops_X550EM_x,
3948 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07003949 .mvals = ixgbe_mvals_X550EM_x,
Emil Tantilovb71f6c42016-10-10 14:54:03 -07003950 .link_ops = &link_ops_x550em_x,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003951};
Mark Rustad49425df2016-04-01 12:18:09 -07003952
3953const struct ixgbe_info ixgbe_x550em_a_info = {
3954 .mac = ixgbe_mac_x550em_a,
Emil Tantilovb71f6c42016-10-10 14:54:03 -07003955 .get_invariants = &ixgbe_get_invariants_X550_a,
Mark Rustad49425df2016-04-01 12:18:09 -07003956 .mac_ops = &mac_ops_x550em_a,
3957 .eeprom_ops = &eeprom_ops_X550EM_x,
Mark Rustadd31afc82016-04-01 12:18:14 -07003958 .phy_ops = &phy_ops_x550em_a,
Mark Rustad49425df2016-04-01 12:18:09 -07003959 .mbx_ops = &mbx_ops_generic,
3960 .mvals = ixgbe_mvals_x550em_a,
3961};
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003962
3963const struct ixgbe_info ixgbe_x550em_a_fw_info = {
3964 .mac = ixgbe_mac_x550em_a,
3965 .get_invariants = ixgbe_get_invariants_X550_a_fw,
3966 .mac_ops = &mac_ops_x550em_a_fw,
3967 .eeprom_ops = &eeprom_ops_X550EM_x,
3968 .phy_ops = &phy_ops_x550em_a_fw,
3969 .mbx_ops = &mbx_ops_generic,
3970 .mvals = ixgbe_mvals_x550em_a,
3971};