blob: 50aaa2bd3c818458b1d7982c079e901c246cfb4d [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
Paul Greenwalt8dc963e2017-04-13 08:07:07 -040052static s32 ixgbe_get_invariants_X550_x_fw(struct ixgbe_hw *hw)
53{
54 struct ixgbe_phy_info *phy = &hw->phy;
55
56 /* Start with X540 invariants, since so similar */
57 ixgbe_get_invariants_X540(hw);
58
59 phy->ops.set_phy_power = NULL;
60
61 return 0;
62}
63
Emil Tantilovb71f6c42016-10-10 14:54:03 -070064static s32 ixgbe_get_invariants_X550_a(struct ixgbe_hw *hw)
65{
66 struct ixgbe_mac_info *mac = &hw->mac;
67 struct ixgbe_phy_info *phy = &hw->phy;
Don Skidmoreb5529ef2015-06-10 20:42:30 -040068
69 /* Start with X540 invariants, since so simular */
70 ixgbe_get_invariants_X540(hw);
71
72 if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
73 phy->ops.set_phy_power = NULL;
74
75 return 0;
76}
77
Mark Rustadb3eb4e12016-12-14 11:02:16 -080078static s32 ixgbe_get_invariants_X550_a_fw(struct ixgbe_hw *hw)
79{
80 struct ixgbe_phy_info *phy = &hw->phy;
81
82 /* Start with X540 invariants, since so similar */
83 ixgbe_get_invariants_X540(hw);
84
85 phy->ops.set_phy_power = NULL;
86
87 return 0;
88}
89
Don Skidmoreab5fe0c2015-06-09 16:18:56 -070090/** ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
91 * @hw: pointer to hardware structure
92 **/
93static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
94{
95 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
96
97 if (hw->bus.lan_id) {
98 esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
99 esdp |= IXGBE_ESDP_SDP1_DIR;
100 }
101 esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
102 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
103 IXGBE_WRITE_FLUSH(hw);
104}
105
Mark Rustad542b6ee2015-08-08 16:18:38 -0700106/**
107 * ixgbe_read_cs4227 - Read CS4227 register
108 * @hw: pointer to hardware structure
109 * @reg: register number to write
110 * @value: pointer to receive value read
111 *
112 * Returns status code
113 */
114static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
115{
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700116 return hw->link.ops.read_link_unlocked(hw, hw->link.addr, reg, value);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700117}
118
119/**
120 * ixgbe_write_cs4227 - Write CS4227 register
121 * @hw: pointer to hardware structure
122 * @reg: register number to write
123 * @value: value to write to register
124 *
125 * Returns status code
126 */
127static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
128{
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700129 return hw->link.ops.write_link_unlocked(hw, hw->link.addr, reg, value);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700130}
131
132/**
Mark Rustad542b6ee2015-08-08 16:18:38 -0700133 * ixgbe_read_pe - Read register from port expander
134 * @hw: pointer to hardware structure
135 * @reg: register number to read
136 * @value: pointer to receive read value
137 *
138 * Returns status code
139 */
140static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
141{
142 s32 status;
143
144 status = ixgbe_read_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE, value);
145 if (status)
146 hw_err(hw, "port expander access failed with %d\n", status);
147 return status;
148}
149
150/**
151 * ixgbe_write_pe - Write register to port expander
152 * @hw: pointer to hardware structure
153 * @reg: register number to write
154 * @value: value to write
155 *
156 * Returns status code
157 */
158static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
159{
160 s32 status;
161
162 status = ixgbe_write_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE,
163 value);
164 if (status)
165 hw_err(hw, "port expander access failed with %d\n", status);
166 return status;
167}
168
169/**
170 * ixgbe_reset_cs4227 - Reset CS4227 using port expander
171 * @hw: pointer to hardware structure
172 *
Mark Rustad8bf7a7b2015-08-26 14:10:22 -0700173 * This function assumes that the caller has acquired the proper semaphore.
Mark Rustad542b6ee2015-08-08 16:18:38 -0700174 * Returns error code
175 */
176static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
177{
178 s32 status;
179 u32 retry;
180 u16 value;
181 u8 reg;
182
183 /* Trigger hard reset. */
184 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
185 if (status)
186 return status;
187 reg |= IXGBE_PE_BIT1;
188 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
189 if (status)
190 return status;
191
192 status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, &reg);
193 if (status)
194 return status;
195 reg &= ~IXGBE_PE_BIT1;
196 status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
197 if (status)
198 return status;
199
200 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
201 if (status)
202 return status;
203 reg &= ~IXGBE_PE_BIT1;
204 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
205 if (status)
206 return status;
207
208 usleep_range(IXGBE_CS4227_RESET_HOLD, IXGBE_CS4227_RESET_HOLD + 100);
209
210 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
211 if (status)
212 return status;
213 reg |= IXGBE_PE_BIT1;
214 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
215 if (status)
216 return status;
217
218 /* Wait for the reset to complete. */
219 msleep(IXGBE_CS4227_RESET_DELAY);
220 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
221 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
222 &value);
223 if (!status && value == IXGBE_CS4227_EEPROM_LOAD_OK)
224 break;
225 msleep(IXGBE_CS4227_CHECK_DELAY);
226 }
227 if (retry == IXGBE_CS4227_RETRIES) {
228 hw_err(hw, "CS4227 reset did not complete\n");
229 return IXGBE_ERR_PHY;
230 }
231
232 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
233 if (status || !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
234 hw_err(hw, "CS4227 EEPROM did not load successfully\n");
235 return IXGBE_ERR_PHY;
236 }
237
238 return 0;
239}
240
241/**
242 * ixgbe_check_cs4227 - Check CS4227 and reset as needed
243 * @hw: pointer to hardware structure
244 */
245static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
246{
247 u32 swfw_mask = hw->phy.phy_semaphore_mask;
248 s32 status;
249 u16 value;
250 u8 retry;
251
252 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
253 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
254 if (status) {
255 hw_err(hw, "semaphore failed with %d\n", status);
256 msleep(IXGBE_CS4227_CHECK_DELAY);
257 continue;
258 }
259
260 /* Get status of reset flow. */
261 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
262 if (!status && value == IXGBE_CS4227_RESET_COMPLETE)
263 goto out;
264
265 if (status || value != IXGBE_CS4227_RESET_PENDING)
266 break;
267
268 /* Reset is pending. Wait and check again. */
269 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
270 msleep(IXGBE_CS4227_CHECK_DELAY);
271 }
Mark Rustad8bf7a7b2015-08-26 14:10:22 -0700272 /* If still pending, assume other instance failed. */
273 if (retry == IXGBE_CS4227_RETRIES) {
274 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
275 if (status) {
276 hw_err(hw, "semaphore failed with %d\n", status);
277 return;
278 }
279 }
Mark Rustad542b6ee2015-08-08 16:18:38 -0700280
281 /* Reset the CS4227. */
282 status = ixgbe_reset_cs4227(hw);
283 if (status) {
284 hw_err(hw, "CS4227 reset failed: %d", status);
285 goto out;
286 }
287
288 /* Reset takes so long, temporarily release semaphore in case the
289 * other driver instance is waiting for the reset indication.
290 */
291 ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
292 IXGBE_CS4227_RESET_PENDING);
293 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
294 usleep_range(10000, 12000);
295 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
296 if (status) {
297 hw_err(hw, "semaphore failed with %d", status);
298 return;
299 }
300
Mark Rustad542b6ee2015-08-08 16:18:38 -0700301 /* Record completion for next time. */
302 status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
303 IXGBE_CS4227_RESET_COMPLETE);
304
305out:
306 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
307 msleep(hw->eeprom.semaphore_delay);
308}
309
Don Skidmore6a14ee02014-12-05 03:59:50 +0000310/** ixgbe_identify_phy_x550em - Get PHY type based on device id
311 * @hw: pointer to hardware structure
312 *
313 * Returns error code
314 */
315static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
316{
Don Skidmore6a14ee02014-12-05 03:59:50 +0000317 switch (hw->device_id) {
Mark Rustad2d40cd12016-04-01 12:18:35 -0700318 case IXGBE_DEV_ID_X550EM_A_SFP:
319 if (hw->bus.lan_id)
320 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
321 else
322 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
323 return ixgbe_identify_module_generic(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000324 case IXGBE_DEV_ID_X550EM_X_SFP:
325 /* set up for CS4227 usage */
326 hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
Don Skidmoreab5fe0c2015-06-09 16:18:56 -0700327 ixgbe_setup_mux_ctl(hw);
Mark Rustad542b6ee2015-08-08 16:18:38 -0700328 ixgbe_check_cs4227(hw);
Mark Rustad49425df2016-04-01 12:18:09 -0700329 /* Fallthrough */
330 case IXGBE_DEV_ID_X550EM_A_SFP_N:
Don Skidmore6a14ee02014-12-05 03:59:50 +0000331 return ixgbe_identify_module_generic(hw);
332 case IXGBE_DEV_ID_X550EM_X_KX4:
333 hw->phy.type = ixgbe_phy_x550em_kx4;
334 break;
Don Skidmore18e01ee2016-12-30 21:07:58 -0500335 case IXGBE_DEV_ID_X550EM_X_XFI:
336 hw->phy.type = ixgbe_phy_x550em_xfi;
337 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000338 case IXGBE_DEV_ID_X550EM_X_KR:
Mark Rustadf572b2c2016-04-01 12:18:46 -0700339 case IXGBE_DEV_ID_X550EM_A_KR:
340 case IXGBE_DEV_ID_X550EM_A_KR_L:
Don Skidmore6a14ee02014-12-05 03:59:50 +0000341 hw->phy.type = ixgbe_phy_x550em_kr;
342 break;
Don Skidmore92ed8432016-08-17 20:34:40 -0400343 case IXGBE_DEV_ID_X550EM_A_10G_T:
344 if (hw->bus.lan_id)
345 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
346 else
347 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
348 /* Fallthrough */
Don Skidmore6a14ee02014-12-05 03:59:50 +0000349 case IXGBE_DEV_ID_X550EM_X_10G_T:
350 return ixgbe_identify_phy_generic(hw);
Paul Greenwalt8dc963e2017-04-13 08:07:07 -0400351 case IXGBE_DEV_ID_X550EM_X_1G_T:
352 hw->phy.type = ixgbe_phy_ext_1g_t;
353 break;
Don Skidmore18bda0d2016-12-30 21:07:14 -0500354 case IXGBE_DEV_ID_X550EM_A_1G_T:
355 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
356 hw->phy.type = ixgbe_phy_fw;
357 hw->phy.ops.read_reg = NULL;
358 hw->phy.ops.write_reg = NULL;
359 if (hw->bus.lan_id)
360 hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY1_SM;
361 else
362 hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY0_SM;
363 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000364 default:
365 break;
366 }
367 return 0;
368}
369
370static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
371 u32 device_type, u16 *phy_data)
372{
373 return IXGBE_NOT_IMPLEMENTED;
374}
375
376static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
377 u32 device_type, u16 phy_data)
378{
379 return IXGBE_NOT_IMPLEMENTED;
380}
381
Emil Tantilovb71f6c42016-10-10 14:54:03 -0700382/**
383 * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
384 * @hw: pointer to the hardware structure
385 * @addr: I2C bus address to read from
386 * @reg: I2C device register to read from
387 * @val: pointer to location to receive read value
388 *
389 * Returns an error code on error.
390 **/
391static s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
392 u16 reg, u16 *val)
393{
394 return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, true);
395}
396
397/**
398 * ixgbe_read_i2c_combined_generic_unlocked - Do I2C read combined operation
399 * @hw: pointer to the hardware structure
400 * @addr: I2C bus address to read from
401 * @reg: I2C device register to read from
402 * @val: pointer to location to receive read value
403 *
404 * Returns an error code on error.
405 **/
406static s32
407ixgbe_read_i2c_combined_generic_unlocked(struct ixgbe_hw *hw, u8 addr,
408 u16 reg, u16 *val)
409{
410 return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, false);
411}
412
413/**
414 * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
415 * @hw: pointer to the hardware structure
416 * @addr: I2C bus address to write to
417 * @reg: I2C device register to write to
418 * @val: value to write
419 *
420 * Returns an error code on error.
421 **/
422static s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
423 u8 addr, u16 reg, u16 val)
424{
425 return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, true);
426}
427
428/**
429 * ixgbe_write_i2c_combined_generic_unlocked - Do I2C write combined operation
430 * @hw: pointer to the hardware structure
431 * @addr: I2C bus address to write to
432 * @reg: I2C device register to write to
433 * @val: value to write
434 *
435 * Returns an error code on error.
436 **/
437static s32
438ixgbe_write_i2c_combined_generic_unlocked(struct ixgbe_hw *hw,
439 u8 addr, u16 reg, u16 val)
440{
441 return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, false);
442}
443
Mark Rustad12c78ef2016-12-14 11:02:11 -0800444/**
445 * ixgbe_fw_phy_activity - Perform an activity on a PHY
446 * @hw: pointer to hardware structure
447 * @activity: activity to perform
448 * @data: Pointer to 4 32-bit words of data
449 */
450s32 ixgbe_fw_phy_activity(struct ixgbe_hw *hw, u16 activity,
451 u32 (*data)[FW_PHY_ACT_DATA_COUNT])
452{
453 union {
454 struct ixgbe_hic_phy_activity_req cmd;
455 struct ixgbe_hic_phy_activity_resp rsp;
456 } hic;
457 u16 retries = FW_PHY_ACT_RETRIES;
458 s32 rc;
459 u32 i;
460
461 do {
462 memset(&hic, 0, sizeof(hic));
463 hic.cmd.hdr.cmd = FW_PHY_ACT_REQ_CMD;
464 hic.cmd.hdr.buf_len = FW_PHY_ACT_REQ_LEN;
465 hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
466 hic.cmd.port_number = hw->bus.lan_id;
467 hic.cmd.activity_id = cpu_to_le16(activity);
468 for (i = 0; i < ARRAY_SIZE(hic.cmd.data); ++i)
469 hic.cmd.data[i] = cpu_to_be32((*data)[i]);
470
471 rc = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
472 IXGBE_HI_COMMAND_TIMEOUT,
473 true);
474 if (rc)
475 return rc;
476 if (hic.rsp.hdr.cmd_or_resp.ret_status ==
477 FW_CEM_RESP_STATUS_SUCCESS) {
478 for (i = 0; i < FW_PHY_ACT_DATA_COUNT; ++i)
479 (*data)[i] = be32_to_cpu(hic.rsp.data[i]);
480 return 0;
481 }
482 usleep_range(20, 30);
483 --retries;
484 } while (retries > 0);
485
486 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
487}
488
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800489static const struct {
490 u16 fw_speed;
491 ixgbe_link_speed phy_speed;
492} ixgbe_fw_map[] = {
493 { FW_PHY_ACT_LINK_SPEED_10, IXGBE_LINK_SPEED_10_FULL },
494 { FW_PHY_ACT_LINK_SPEED_100, IXGBE_LINK_SPEED_100_FULL },
495 { FW_PHY_ACT_LINK_SPEED_1G, IXGBE_LINK_SPEED_1GB_FULL },
496 { FW_PHY_ACT_LINK_SPEED_2_5G, IXGBE_LINK_SPEED_2_5GB_FULL },
497 { FW_PHY_ACT_LINK_SPEED_5G, IXGBE_LINK_SPEED_5GB_FULL },
498 { FW_PHY_ACT_LINK_SPEED_10G, IXGBE_LINK_SPEED_10GB_FULL },
499};
500
501/**
502 * ixgbe_get_phy_id_fw - Get the phy ID via firmware command
503 * @hw: pointer to hardware structure
504 *
505 * Returns error code
506 */
507static s32 ixgbe_get_phy_id_fw(struct ixgbe_hw *hw)
508{
509 u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
510 u16 phy_speeds;
511 u16 phy_id_lo;
512 s32 rc;
513 u16 i;
514
515 if (hw->phy.id)
516 return 0;
517
518 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_PHY_INFO, &info);
519 if (rc)
520 return rc;
521
522 hw->phy.speeds_supported = 0;
523 phy_speeds = info[0] & FW_PHY_INFO_SPEED_MASK;
524 for (i = 0; i < ARRAY_SIZE(ixgbe_fw_map); ++i) {
525 if (phy_speeds & ixgbe_fw_map[i].fw_speed)
526 hw->phy.speeds_supported |= ixgbe_fw_map[i].phy_speed;
527 }
528
529 hw->phy.id = info[0] & FW_PHY_INFO_ID_HI_MASK;
530 phy_id_lo = info[1] & FW_PHY_INFO_ID_LO_MASK;
531 hw->phy.id |= phy_id_lo & IXGBE_PHY_REVISION_MASK;
532 hw->phy.revision = phy_id_lo & ~IXGBE_PHY_REVISION_MASK;
533 if (!hw->phy.id || hw->phy.id == IXGBE_PHY_REVISION_MASK)
534 return IXGBE_ERR_PHY_ADDR_INVALID;
535
536 hw->phy.autoneg_advertised = hw->phy.speeds_supported;
537 hw->phy.eee_speeds_supported = IXGBE_LINK_SPEED_100_FULL |
538 IXGBE_LINK_SPEED_1GB_FULL;
539 hw->phy.eee_speeds_advertised = hw->phy.eee_speeds_supported;
540 return 0;
541}
542
543/**
544 * ixgbe_identify_phy_fw - Get PHY type based on firmware command
545 * @hw: pointer to hardware structure
546 *
547 * Returns error code
548 */
549static s32 ixgbe_identify_phy_fw(struct ixgbe_hw *hw)
550{
551 if (hw->bus.lan_id)
552 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
553 else
554 hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
555
556 hw->phy.type = ixgbe_phy_fw;
557 hw->phy.ops.read_reg = NULL;
558 hw->phy.ops.write_reg = NULL;
559 return ixgbe_get_phy_id_fw(hw);
560}
561
562/**
563 * ixgbe_shutdown_fw_phy - Shutdown a firmware-controlled PHY
564 * @hw: pointer to hardware structure
565 *
566 * Returns error code
567 */
568static s32 ixgbe_shutdown_fw_phy(struct ixgbe_hw *hw)
569{
570 u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
571
572 setup[0] = FW_PHY_ACT_FORCE_LINK_DOWN_OFF;
573 return ixgbe_fw_phy_activity(hw, FW_PHY_ACT_FORCE_LINK_DOWN, &setup);
574}
575
576/**
577 * ixgbe_setup_fw_link - Setup firmware-controlled PHYs
578 * @hw: pointer to hardware structure
579 */
580static s32 ixgbe_setup_fw_link(struct ixgbe_hw *hw)
581{
582 u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
583 s32 rc;
584 u16 i;
585
586 if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
587 return 0;
588
589 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
590 hw_err(hw, "rx_pause not valid in strict IEEE mode\n");
591 return IXGBE_ERR_INVALID_LINK_SETTINGS;
592 }
593
594 switch (hw->fc.requested_mode) {
595 case ixgbe_fc_full:
596 setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RXTX <<
597 FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
598 break;
599 case ixgbe_fc_rx_pause:
600 setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RX <<
601 FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
602 break;
603 case ixgbe_fc_tx_pause:
604 setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_TX <<
605 FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
606 break;
607 default:
608 break;
609 }
610
611 for (i = 0; i < ARRAY_SIZE(ixgbe_fw_map); ++i) {
612 if (hw->phy.autoneg_advertised & ixgbe_fw_map[i].phy_speed)
613 setup[0] |= ixgbe_fw_map[i].fw_speed;
614 }
615 setup[0] |= FW_PHY_ACT_SETUP_LINK_HP | FW_PHY_ACT_SETUP_LINK_AN;
616
617 if (hw->phy.eee_speeds_advertised)
618 setup[0] |= FW_PHY_ACT_SETUP_LINK_EEE;
619
620 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_SETUP_LINK, &setup);
621 if (rc)
622 return rc;
623 if (setup[0] == FW_PHY_ACT_SETUP_LINK_RSP_DOWN)
624 return IXGBE_ERR_OVERTEMP;
625 return 0;
626}
627
628/**
629 * ixgbe_fc_autoneg_fw - Set up flow control for FW-controlled PHYs
630 * @hw: pointer to hardware structure
631 *
632 * Called at init time to set up flow control.
633 */
634static s32 ixgbe_fc_autoneg_fw(struct ixgbe_hw *hw)
635{
636 if (hw->fc.requested_mode == ixgbe_fc_default)
637 hw->fc.requested_mode = ixgbe_fc_full;
638
639 return ixgbe_setup_fw_link(hw);
640}
641
Don Skidmore6a14ee02014-12-05 03:59:50 +0000642/** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
643 * @hw: pointer to hardware structure
644 *
645 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
646 * ixgbe_hw struct in order to set up EEPROM access.
647 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000648static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000649{
650 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
651 u32 eec;
652 u16 eeprom_size;
653
654 if (eeprom->type == ixgbe_eeprom_uninitialized) {
655 eeprom->semaphore_delay = 10;
656 eeprom->type = ixgbe_flash;
657
Don Skidmore9a900ec2015-06-09 17:15:01 -0700658 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Don Skidmore6a14ee02014-12-05 03:59:50 +0000659 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
660 IXGBE_EEC_SIZE_SHIFT);
Jacob Kellerb4f47a42016-04-13 16:08:22 -0700661 eeprom->word_size = BIT(eeprom_size +
662 IXGBE_EEPROM_WORD_SIZE_SHIFT);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000663
664 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
665 eeprom->type, eeprom->word_size);
666 }
667
668 return 0;
669}
670
Mark Rustadae14a1d2015-04-10 10:36:26 -0700671/**
672 * ixgbe_iosf_wait - Wait for IOSF command completion
673 * @hw: pointer to hardware structure
674 * @ctrl: pointer to location to receive final IOSF control value
675 *
676 * Return: failing status on timeout
677 *
678 * Note: ctrl can be NULL if the IOSF control register value is not needed
679 */
680static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
681{
682 u32 i, command;
683
684 /* Check every 10 usec to see if the address cycle completed.
685 * The SB IOSF BUSY bit will clear when the operation is
686 * complete.
687 */
688 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
689 command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
690 if (!(command & IXGBE_SB_IOSF_CTRL_BUSY))
691 break;
Mark Rustadd90b5b02016-01-29 14:44:29 -0800692 udelay(10);
Mark Rustadae14a1d2015-04-10 10:36:26 -0700693 }
694 if (ctrl)
695 *ctrl = command;
696 if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
697 hw_dbg(hw, "IOSF wait timed out\n");
698 return IXGBE_ERR_PHY;
699 }
700
701 return 0;
702}
703
Don Skidmore6a14ee02014-12-05 03:59:50 +0000704/** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the
705 * IOSF device
706 * @hw: pointer to hardware structure
707 * @reg_addr: 32 bit PHY register to write
708 * @device_type: 3 bit device type
709 * @phy_data: Pointer to read data from the register
710 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000711static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
712 u32 device_type, u32 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000713{
Mark Rustadae14a1d2015-04-10 10:36:26 -0700714 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
715 u32 command, error;
716 s32 ret;
717
718 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
719 if (ret)
720 return ret;
721
722 ret = ixgbe_iosf_wait(hw, NULL);
723 if (ret)
724 goto out;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000725
726 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
727 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
728
729 /* Write IOSF control register */
730 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
731
Mark Rustadae14a1d2015-04-10 10:36:26 -0700732 ret = ixgbe_iosf_wait(hw, &command);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000733
734 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
735 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
736 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
737 hw_dbg(hw, "Failed to read, error %x\n", error);
738 return IXGBE_ERR_PHY;
739 }
740
Mark Rustadae14a1d2015-04-10 10:36:26 -0700741 if (!ret)
742 *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000743
Mark Rustadae14a1d2015-04-10 10:36:26 -0700744out:
745 hw->mac.ops.release_swfw_sync(hw, gssr);
746 return ret;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000747}
748
Mark Rustad49425df2016-04-01 12:18:09 -0700749/**
750 * ixgbe_get_phy_token - Get the token for shared PHY access
751 * @hw: Pointer to hardware structure
752 */
753static s32 ixgbe_get_phy_token(struct ixgbe_hw *hw)
754{
755 struct ixgbe_hic_phy_token_req token_cmd;
756 s32 status;
757
758 token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
759 token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
760 token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
761 token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
762 token_cmd.port_number = hw->bus.lan_id;
763 token_cmd.command_type = FW_PHY_TOKEN_REQ;
764 token_cmd.pad = 0;
765 status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
766 IXGBE_HI_COMMAND_TIMEOUT,
767 true);
768 if (status)
769 return status;
770 if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
771 return 0;
772 if (token_cmd.hdr.cmd_or_resp.ret_status != FW_PHY_TOKEN_RETRY)
773 return IXGBE_ERR_FW_RESP_INVALID;
774
775 return IXGBE_ERR_TOKEN_RETRY;
776}
777
778/**
779 * ixgbe_put_phy_token - Put the token for shared PHY access
780 * @hw: Pointer to hardware structure
781 */
782static s32 ixgbe_put_phy_token(struct ixgbe_hw *hw)
783{
784 struct ixgbe_hic_phy_token_req token_cmd;
785 s32 status;
786
787 token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
788 token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
789 token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
790 token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
791 token_cmd.port_number = hw->bus.lan_id;
792 token_cmd.command_type = FW_PHY_TOKEN_REL;
793 token_cmd.pad = 0;
794 status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
795 IXGBE_HI_COMMAND_TIMEOUT,
796 true);
797 if (status)
798 return status;
799 if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
800 return 0;
801 return IXGBE_ERR_FW_RESP_INVALID;
802}
803
804/**
805 * ixgbe_write_iosf_sb_reg_x550a - Write to IOSF PHY register
806 * @hw: pointer to hardware structure
807 * @reg_addr: 32 bit PHY register to write
808 * @device_type: 3 bit device type
809 * @data: Data to write to the register
810 **/
811static s32 ixgbe_write_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
812 __always_unused u32 device_type,
813 u32 data)
814{
815 struct ixgbe_hic_internal_phy_req write_cmd;
816
817 memset(&write_cmd, 0, sizeof(write_cmd));
818 write_cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
819 write_cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
820 write_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
821 write_cmd.port_number = hw->bus.lan_id;
822 write_cmd.command_type = FW_INT_PHY_REQ_WRITE;
823 write_cmd.address = cpu_to_be16(reg_addr);
824 write_cmd.write_data = cpu_to_be32(data);
825
826 return ixgbe_host_interface_command(hw, &write_cmd, sizeof(write_cmd),
827 IXGBE_HI_COMMAND_TIMEOUT, false);
828}
829
830/**
831 * ixgbe_read_iosf_sb_reg_x550a - Read from IOSF PHY register
832 * @hw: pointer to hardware structure
833 * @reg_addr: 32 bit PHY register to write
834 * @device_type: 3 bit device type
835 * @data: Pointer to read data from the register
836 **/
837static s32 ixgbe_read_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
838 __always_unused u32 device_type,
839 u32 *data)
840{
841 union {
842 struct ixgbe_hic_internal_phy_req cmd;
843 struct ixgbe_hic_internal_phy_resp rsp;
844 } hic;
845 s32 status;
846
847 memset(&hic, 0, sizeof(hic));
848 hic.cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
849 hic.cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
850 hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
851 hic.cmd.port_number = hw->bus.lan_id;
852 hic.cmd.command_type = FW_INT_PHY_REQ_READ;
853 hic.cmd.address = cpu_to_be16(reg_addr);
854
855 status = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
856 IXGBE_HI_COMMAND_TIMEOUT, true);
857
858 /* Extract the register value from the response. */
859 *data = be32_to_cpu(hic.rsp.read_data);
860
861 return status;
862}
863
Don Skidmore6a14ee02014-12-05 03:59:50 +0000864/** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
865 * @hw: pointer to hardware structure
866 * @offset: offset of word in the EEPROM to read
867 * @words: number of words
868 * @data: word(s) read from the EEPROM
869 *
870 * Reads a 16 bit word(s) from the EEPROM using the hostif.
871 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +0000872static s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
873 u16 offset, u16 words, u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +0000874{
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800875 const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
Don Skidmore6a14ee02014-12-05 03:59:50 +0000876 struct ixgbe_hic_read_shadow_ram buffer;
877 u32 current_word = 0;
878 u16 words_to_read;
879 s32 status;
880 u32 i;
881
882 /* Take semaphore for the entire operation. */
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800883 status = hw->mac.ops.acquire_swfw_sync(hw, mask);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000884 if (status) {
885 hw_dbg(hw, "EEPROM read buffer - semaphore failed\n");
886 return status;
887 }
888
889 while (words) {
890 if (words > FW_MAX_READ_BUFFER_SIZE / 2)
891 words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
892 else
893 words_to_read = words;
894
895 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
896 buffer.hdr.req.buf_lenh = 0;
897 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
898 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
899
900 /* convert offset from words to bytes */
901 buffer.address = cpu_to_be32((offset + current_word) * 2);
902 buffer.length = cpu_to_be16(words_to_read * 2);
903
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800904 status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
905 IXGBE_HI_COMMAND_TIMEOUT);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000906 if (status) {
907 hw_dbg(hw, "Host interface command failed\n");
908 goto out;
909 }
910
911 for (i = 0; i < words_to_read; i++) {
912 u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
913 2 * i;
914 u32 value = IXGBE_READ_REG(hw, reg);
915
916 data[current_word] = (u16)(value & 0xffff);
917 current_word++;
918 i++;
919 if (i < words_to_read) {
920 value >>= 16;
921 data[current_word] = (u16)(value & 0xffff);
922 current_word++;
923 }
924 }
925 words -= words_to_read;
926 }
927
928out:
Mark Rustad3efa9ed2016-12-14 11:02:00 -0800929 hw->mac.ops.release_swfw_sync(hw, mask);
Don Skidmore6a14ee02014-12-05 03:59:50 +0000930 return status;
931}
932
933/** ixgbe_checksum_ptr_x550 - Checksum one pointer region
934 * @hw: pointer to hardware structure
935 * @ptr: pointer offset in eeprom
936 * @size: size of section pointed by ptr, if 0 first word will be used as size
937 * @csum: address of checksum to update
938 *
939 * Returns error status for any failure
940 **/
941static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
942 u16 size, u16 *csum, u16 *buffer,
943 u32 buffer_size)
944{
945 u16 buf[256];
946 s32 status;
947 u16 length, bufsz, i, start;
948 u16 *local_buffer;
949
950 bufsz = sizeof(buf) / sizeof(buf[0]);
951
952 /* Read a chunk at the pointer location */
953 if (!buffer) {
954 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
955 if (status) {
956 hw_dbg(hw, "Failed to read EEPROM image\n");
957 return status;
958 }
959 local_buffer = buf;
960 } else {
961 if (buffer_size < ptr)
962 return IXGBE_ERR_PARAM;
963 local_buffer = &buffer[ptr];
964 }
965
966 if (size) {
967 start = 0;
968 length = size;
969 } else {
970 start = 1;
971 length = local_buffer[0];
972
973 /* Skip pointer section if length is invalid. */
974 if (length == 0xFFFF || length == 0 ||
975 (ptr + length) >= hw->eeprom.word_size)
976 return 0;
977 }
978
979 if (buffer && ((u32)start + (u32)length > buffer_size))
980 return IXGBE_ERR_PARAM;
981
982 for (i = start; length; i++, length--) {
983 if (i == bufsz && !buffer) {
984 ptr += bufsz;
985 i = 0;
986 if (length < bufsz)
987 bufsz = length;
988
989 /* Read a chunk at the pointer location */
990 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
991 bufsz, buf);
992 if (status) {
993 hw_dbg(hw, "Failed to read EEPROM image\n");
994 return status;
995 }
996 }
997 *csum += local_buffer[i];
998 }
999 return 0;
1000}
1001
1002/** ixgbe_calc_checksum_X550 - Calculates and returns the checksum
1003 * @hw: pointer to hardware structure
1004 * @buffer: pointer to buffer containing calculated checksum
1005 * @buffer_size: size of buffer
1006 *
1007 * Returns a negative error code on error, or the 16-bit checksum
1008 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001009static s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer,
1010 u32 buffer_size)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001011{
1012 u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
1013 u16 *local_buffer;
1014 s32 status;
1015 u16 checksum = 0;
1016 u16 pointer, i, size;
1017
1018 hw->eeprom.ops.init_params(hw);
1019
1020 if (!buffer) {
1021 /* Read pointer area */
1022 status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
1023 IXGBE_EEPROM_LAST_WORD + 1,
1024 eeprom_ptrs);
1025 if (status) {
1026 hw_dbg(hw, "Failed to read EEPROM image\n");
1027 return status;
1028 }
1029 local_buffer = eeprom_ptrs;
1030 } else {
1031 if (buffer_size < IXGBE_EEPROM_LAST_WORD)
1032 return IXGBE_ERR_PARAM;
1033 local_buffer = buffer;
1034 }
1035
1036 /* For X550 hardware include 0x0-0x41 in the checksum, skip the
1037 * checksum word itself
1038 */
1039 for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
1040 if (i != IXGBE_EEPROM_CHECKSUM)
1041 checksum += local_buffer[i];
1042
1043 /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
1044 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
1045 */
1046 for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
1047 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
1048 continue;
1049
1050 pointer = local_buffer[i];
1051
1052 /* Skip pointer section if the pointer is invalid. */
1053 if (pointer == 0xFFFF || pointer == 0 ||
1054 pointer >= hw->eeprom.word_size)
1055 continue;
1056
1057 switch (i) {
1058 case IXGBE_PCIE_GENERAL_PTR:
1059 size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
1060 break;
1061 case IXGBE_PCIE_CONFIG0_PTR:
1062 case IXGBE_PCIE_CONFIG1_PTR:
1063 size = IXGBE_PCIE_CONFIG_SIZE;
1064 break;
1065 default:
1066 size = 0;
1067 break;
1068 }
1069
1070 status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
1071 buffer, buffer_size);
1072 if (status)
1073 return status;
1074 }
1075
1076 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1077
1078 return (s32)checksum;
1079}
1080
1081/** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
1082 * @hw: pointer to hardware structure
1083 *
1084 * Returns a negative error code on error, or the 16-bit checksum
1085 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001086static s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001087{
1088 return ixgbe_calc_checksum_X550(hw, NULL, 0);
1089}
1090
1091/** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
1092 * @hw: pointer to hardware structure
1093 * @offset: offset of word in the EEPROM to read
1094 * @data: word read from the EEPROM
1095 *
1096 * Reads a 16 bit word from the EEPROM using the hostif.
1097 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001098static s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001099{
Mark Rustad3efa9ed2016-12-14 11:02:00 -08001100 const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
1101 struct ixgbe_hic_read_shadow_ram buffer;
1102 s32 status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001103
Mark Rustad3efa9ed2016-12-14 11:02:00 -08001104 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
1105 buffer.hdr.req.buf_lenh = 0;
1106 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
1107 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
1108
1109 /* convert offset from words to bytes */
1110 buffer.address = cpu_to_be32(offset * 2);
1111 /* one word */
1112 buffer.length = cpu_to_be16(sizeof(u16));
1113
1114 status = hw->mac.ops.acquire_swfw_sync(hw, mask);
1115 if (status)
1116 return status;
1117
1118 status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
1119 IXGBE_HI_COMMAND_TIMEOUT);
1120 if (!status) {
1121 *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
1122 FW_NVM_DATA_OFFSET);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001123 }
1124
Mark Rustad3efa9ed2016-12-14 11:02:00 -08001125 hw->mac.ops.release_swfw_sync(hw, mask);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001126 return status;
1127}
1128
1129/** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
1130 * @hw: pointer to hardware structure
1131 * @checksum_val: calculated checksum
1132 *
1133 * Performs checksum calculation and validates the EEPROM checksum. If the
1134 * caller does not need checksum_val, the value can be NULL.
1135 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001136static s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw,
1137 u16 *checksum_val)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001138{
1139 s32 status;
1140 u16 checksum;
1141 u16 read_checksum = 0;
1142
1143 /* Read the first word from the EEPROM. If this times out or fails, do
1144 * not continue or we could be in for a very long wait while every
1145 * EEPROM read fails
1146 */
1147 status = hw->eeprom.ops.read(hw, 0, &checksum);
1148 if (status) {
1149 hw_dbg(hw, "EEPROM read failed\n");
1150 return status;
1151 }
1152
1153 status = hw->eeprom.ops.calc_checksum(hw);
1154 if (status < 0)
1155 return status;
1156
1157 checksum = (u16)(status & 0xffff);
1158
1159 status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
1160 &read_checksum);
1161 if (status)
1162 return status;
1163
1164 /* Verify read checksum from EEPROM is the same as
1165 * calculated checksum
1166 */
1167 if (read_checksum != checksum) {
1168 status = IXGBE_ERR_EEPROM_CHECKSUM;
1169 hw_dbg(hw, "Invalid EEPROM checksum");
1170 }
1171
1172 /* If the user cares, return the calculated checksum */
1173 if (checksum_val)
1174 *checksum_val = checksum;
1175
1176 return status;
1177}
1178
1179/** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
1180 * @hw: pointer to hardware structure
1181 * @offset: offset of word in the EEPROM to write
1182 * @data: word write to the EEPROM
1183 *
1184 * Write a 16 bit word to the EEPROM using the hostif.
1185 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001186static s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
1187 u16 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001188{
1189 s32 status;
1190 struct ixgbe_hic_write_shadow_ram buffer;
1191
1192 buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
1193 buffer.hdr.req.buf_lenh = 0;
1194 buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
1195 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
1196
1197 /* one word */
1198 buffer.length = cpu_to_be16(sizeof(u16));
1199 buffer.data = data;
1200 buffer.address = cpu_to_be32(offset * 2);
1201
Mark Rustad5cffde32016-03-14 11:05:57 -07001202 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +00001203 IXGBE_HI_COMMAND_TIMEOUT, false);
1204 return status;
1205}
1206
1207/** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
1208 * @hw: pointer to hardware structure
1209 * @offset: offset of word in the EEPROM to write
1210 * @data: word write to the EEPROM
1211 *
1212 * Write a 16 bit word to the EEPROM using the hostif.
1213 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001214static s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001215{
1216 s32 status = 0;
1217
1218 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
1219 status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
1220 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1221 } else {
1222 hw_dbg(hw, "write ee hostif failed to get semaphore");
1223 status = IXGBE_ERR_SWFW_SYNC;
1224 }
1225
1226 return status;
1227}
1228
1229/** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
1230 * @hw: pointer to hardware structure
1231 *
1232 * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
1233 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001234static s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001235{
1236 s32 status = 0;
1237 union ixgbe_hic_hdr2 buffer;
1238
1239 buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
1240 buffer.req.buf_lenh = 0;
1241 buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
1242 buffer.req.checksum = FW_DEFAULT_CHECKSUM;
1243
Mark Rustad5cffde32016-03-14 11:05:57 -07001244 status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
Don Skidmore6a14ee02014-12-05 03:59:50 +00001245 IXGBE_HI_COMMAND_TIMEOUT, false);
1246 return status;
1247}
1248
Don Skidmore454c65d2015-06-17 20:59:59 -04001249/**
1250 * ixgbe_get_bus_info_X550em - Set PCI bus info
1251 * @hw: pointer to hardware structure
1252 *
1253 * Sets bus link width and speed to unknown because X550em is
1254 * not a PCI device.
1255 **/
1256static s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
1257{
Don Skidmoref9328bc2015-06-18 13:24:06 -04001258 hw->bus.type = ixgbe_bus_type_internal;
Don Skidmore454c65d2015-06-17 20:59:59 -04001259 hw->bus.width = ixgbe_bus_width_unknown;
1260 hw->bus.speed = ixgbe_bus_speed_unknown;
1261
1262 hw->mac.ops.set_lan_id(hw);
1263
1264 return 0;
1265}
1266
Don Skidmore1f9ac572015-03-13 13:54:30 -07001267/** ixgbe_disable_rx_x550 - Disable RX unit
1268 *
1269 * Enables the Rx DMA unit for x550
1270 **/
1271static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
1272{
1273 u32 rxctrl, pfdtxgswc;
1274 s32 status;
1275 struct ixgbe_hic_disable_rxen fw_cmd;
1276
1277 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1278 if (rxctrl & IXGBE_RXCTRL_RXEN) {
1279 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
1280 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
1281 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
1282 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
1283 hw->mac.set_lben = true;
1284 } else {
1285 hw->mac.set_lben = false;
1286 }
1287
1288 fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
1289 fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
1290 fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
Mark Rustad3775b812016-03-14 11:05:46 -07001291 fw_cmd.port_number = hw->bus.lan_id;
Don Skidmore1f9ac572015-03-13 13:54:30 -07001292
Mark Rustad5cffde32016-03-14 11:05:57 -07001293 status = ixgbe_host_interface_command(hw, &fw_cmd,
Don Skidmore1f9ac572015-03-13 13:54:30 -07001294 sizeof(struct ixgbe_hic_disable_rxen),
1295 IXGBE_HI_COMMAND_TIMEOUT, true);
1296
1297 /* If we fail - disable RX using register write */
1298 if (status) {
1299 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1300 if (rxctrl & IXGBE_RXCTRL_RXEN) {
1301 rxctrl &= ~IXGBE_RXCTRL_RXEN;
1302 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
1303 }
1304 }
1305 }
1306}
1307
Don Skidmore6a14ee02014-12-05 03:59:50 +00001308/** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
1309 * @hw: pointer to hardware structure
1310 *
1311 * After writing EEPROM to shadow RAM using EEWR register, software calculates
1312 * checksum and updates the EEPROM and instructs the hardware to update
1313 * the flash.
1314 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001315static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001316{
1317 s32 status;
1318 u16 checksum = 0;
1319
1320 /* Read the first word from the EEPROM. If this times out or fails, do
1321 * not continue or we could be in for a very long wait while every
1322 * EEPROM read fails
1323 */
1324 status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
1325 if (status) {
1326 hw_dbg(hw, "EEPROM read failed\n");
1327 return status;
1328 }
1329
1330 status = ixgbe_calc_eeprom_checksum_X550(hw);
1331 if (status < 0)
1332 return status;
1333
1334 checksum = (u16)(status & 0xffff);
1335
1336 status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
1337 checksum);
1338 if (status)
1339 return status;
1340
1341 status = ixgbe_update_flash_X550(hw);
1342
1343 return status;
1344}
1345
1346/** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
1347 * @hw: pointer to hardware structure
1348 * @offset: offset of word in the EEPROM to write
1349 * @words: number of words
1350 * @data: word(s) write to the EEPROM
1351 *
1352 *
1353 * Write a 16 bit word(s) to the EEPROM using the hostif.
1354 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001355static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
1356 u16 offset, u16 words,
1357 u16 *data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001358{
1359 s32 status = 0;
1360 u32 i = 0;
1361
1362 /* Take semaphore for the entire operation. */
1363 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1364 if (status) {
1365 hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
1366 return status;
1367 }
1368
1369 for (i = 0; i < words; i++) {
1370 status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
1371 data[i]);
1372 if (status) {
1373 hw_dbg(hw, "Eeprom buffered write failed\n");
1374 break;
1375 }
1376 }
1377
1378 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1379
1380 return status;
1381}
1382
Don Skidmore6a14ee02014-12-05 03:59:50 +00001383/** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
1384 * IOSF device
1385 *
1386 * @hw: pointer to hardware structure
1387 * @reg_addr: 32 bit PHY register to write
1388 * @device_type: 3 bit device type
1389 * @data: Data to write to the register
1390 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00001391static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
1392 u32 device_type, u32 data)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001393{
Mark Rustadae14a1d2015-04-10 10:36:26 -07001394 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
1395 u32 command, error;
1396 s32 ret;
1397
1398 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
1399 if (ret)
1400 return ret;
1401
1402 ret = ixgbe_iosf_wait(hw, NULL);
1403 if (ret)
1404 goto out;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001405
1406 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
1407 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
1408
1409 /* Write IOSF control register */
1410 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
1411
1412 /* Write IOSF data register */
1413 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
1414
Mark Rustadae14a1d2015-04-10 10:36:26 -07001415 ret = ixgbe_iosf_wait(hw, &command);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001416
1417 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
1418 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
1419 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
1420 hw_dbg(hw, "Failed to write, error %x\n", error);
1421 return IXGBE_ERR_PHY;
1422 }
1423
Mark Rustadae14a1d2015-04-10 10:36:26 -07001424out:
1425 hw->mac.ops.release_swfw_sync(hw, gssr);
1426 return ret;
Don Skidmore6a14ee02014-12-05 03:59:50 +00001427}
1428
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001429/**
1430 * ixgbe_setup_ixfi_x550em_x - MAC specific iXFI configuration
Don Skidmore6a14ee02014-12-05 03:59:50 +00001431 * @hw: pointer to hardware structure
Don Skidmore6a14ee02014-12-05 03:59:50 +00001432 *
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001433 * iXfI configuration needed for ixgbe_mac_X550EM_x devices.
Don Skidmore6a14ee02014-12-05 03:59:50 +00001434 **/
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001435static s32 ixgbe_setup_ixfi_x550em_x(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00001436{
1437 s32 status;
1438 u32 reg_val;
1439
Don Skidmore6a14ee02014-12-05 03:59:50 +00001440 /* Disable training protocol FSM. */
1441 status = ixgbe_read_iosf_sb_reg_x550(hw,
1442 IXGBE_KRM_RX_TRN_LINKUP_CTRL(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_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
1448 status = ixgbe_write_iosf_sb_reg_x550(hw,
1449 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1450 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1451 if (status)
1452 return status;
1453
1454 /* Disable Flex from training TXFFE. */
1455 status = ixgbe_read_iosf_sb_reg_x550(hw,
1456 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1457 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1458 if (status)
1459 return status;
1460
1461 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1462 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1463 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1464 status = ixgbe_write_iosf_sb_reg_x550(hw,
1465 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1466 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1467 if (status)
1468 return status;
1469
1470 status = ixgbe_read_iosf_sb_reg_x550(hw,
1471 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1472 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1473 if (status)
1474 return status;
1475
1476 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1477 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1478 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1479 status = ixgbe_write_iosf_sb_reg_x550(hw,
1480 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1481 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1482 if (status)
1483 return status;
1484
1485 /* Enable override for coefficients. */
1486 status = ixgbe_read_iosf_sb_reg_x550(hw,
1487 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1488 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1489 if (status)
1490 return status;
1491
1492 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
1493 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
1494 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
1495 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
1496 status = ixgbe_write_iosf_sb_reg_x550(hw,
1497 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1498 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001499 return status;
1500}
1501
Don Skidmore470739b2016-11-03 21:01:37 -04001502/**
1503 * ixgbe_restart_an_internal_phy_x550em - restart autonegotiation for the
1504 * internal PHY
1505 * @hw: pointer to hardware structure
1506 **/
1507static s32 ixgbe_restart_an_internal_phy_x550em(struct ixgbe_hw *hw)
1508{
1509 s32 status;
1510 u32 link_ctrl;
1511
1512 /* Restart auto-negotiation. */
1513 status = hw->mac.ops.read_iosf_sb_reg(hw,
1514 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1515 IXGBE_SB_IOSF_TARGET_KR_PHY, &link_ctrl);
1516
1517 if (status) {
1518 hw_dbg(hw, "Auto-negotiation did not complete\n");
1519 return status;
1520 }
1521
1522 link_ctrl |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1523 status = hw->mac.ops.write_iosf_sb_reg(hw,
1524 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1525 IXGBE_SB_IOSF_TARGET_KR_PHY, link_ctrl);
1526
1527 if (hw->mac.type == ixgbe_mac_x550em_a) {
1528 u32 flx_mask_st20;
1529
1530 /* Indicate to FW that AN restart has been asserted */
1531 status = hw->mac.ops.read_iosf_sb_reg(hw,
1532 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1533 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_mask_st20);
1534
1535 if (status) {
1536 hw_dbg(hw, "Auto-negotiation did not complete\n");
1537 return status;
1538 }
1539
1540 flx_mask_st20 |= IXGBE_KRM_PMD_FLX_MASK_ST20_FW_AN_RESTART;
1541 status = hw->mac.ops.write_iosf_sb_reg(hw,
1542 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1543 IXGBE_SB_IOSF_TARGET_KR_PHY, flx_mask_st20);
1544 }
1545
1546 return status;
1547}
1548
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001549/** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
1550 * @hw: pointer to hardware structure
1551 * @speed: the link speed to force
1552 *
1553 * Configures the integrated KR PHY to use iXFI mode. Used to connect an
1554 * internal and external PHY at a specific speed, without autonegotiation.
1555 **/
1556static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1557{
1558 s32 status;
1559 u32 reg_val;
1560
1561 /* Disable AN and force speed to 10G Serial. */
1562 status = ixgbe_read_iosf_sb_reg_x550(hw,
1563 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1564 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001565 if (status)
1566 return status;
1567
Don Skidmore0c1b7de2016-09-21 20:21:52 -04001568 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1569 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1570
1571 /* Select forced link speed for internal PHY. */
1572 switch (*speed) {
1573 case IXGBE_LINK_SPEED_10GB_FULL:
1574 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
1575 break;
1576 case IXGBE_LINK_SPEED_1GB_FULL:
1577 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1578 break;
1579 default:
1580 /* Other link speeds are not supported by internal KR PHY. */
1581 return IXGBE_ERR_LINK_SETUP;
1582 }
1583
1584 status = ixgbe_write_iosf_sb_reg_x550(hw,
1585 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1586 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1587 if (status)
1588 return status;
1589
1590 /* Additional configuration needed for x550em_x */
1591 if (hw->mac.type == ixgbe_mac_X550EM_x) {
1592 status = ixgbe_setup_ixfi_x550em_x(hw);
1593 if (status)
1594 return status;
1595 }
1596
Don Skidmore6a14ee02014-12-05 03:59:50 +00001597 /* Toggle port SW reset by AN reset. */
Don Skidmore470739b2016-11-03 21:01:37 -04001598 status = ixgbe_restart_an_internal_phy_x550em(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +00001599
1600 return status;
1601}
1602
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001603/**
Mark Rustade23f3332015-08-08 16:18:33 -07001604 * ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
1605 * @hw: pointer to hardware structure
1606 * @linear: true if SFP module is linear
1607 */
1608static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
1609{
1610 switch (hw->phy.sfp_type) {
1611 case ixgbe_sfp_type_not_present:
1612 return IXGBE_ERR_SFP_NOT_PRESENT;
1613 case ixgbe_sfp_type_da_cu_core0:
1614 case ixgbe_sfp_type_da_cu_core1:
1615 *linear = true;
1616 break;
1617 case ixgbe_sfp_type_srlr_core0:
1618 case ixgbe_sfp_type_srlr_core1:
1619 case ixgbe_sfp_type_da_act_lmt_core0:
1620 case ixgbe_sfp_type_da_act_lmt_core1:
1621 case ixgbe_sfp_type_1g_sx_core0:
1622 case ixgbe_sfp_type_1g_sx_core1:
1623 case ixgbe_sfp_type_1g_lx_core0:
1624 case ixgbe_sfp_type_1g_lx_core1:
1625 *linear = false;
1626 break;
1627 case ixgbe_sfp_type_unknown:
1628 case ixgbe_sfp_type_1g_cu_core0:
1629 case ixgbe_sfp_type_1g_cu_core1:
1630 default:
1631 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1632 }
1633
1634 return 0;
1635}
1636
1637/**
Mark Rustad6d373a12015-08-08 16:18:28 -07001638 * ixgbe_setup_mac_link_sfp_x550em - Configure the KR PHY for SFP.
1639 * @hw: pointer to hardware structure
1640 *
1641 * Configures the extern PHY and the integrated KR PHY for SFP support.
1642 */
1643static s32
1644ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
1645 ixgbe_link_speed speed,
1646 __always_unused bool autoneg_wait_to_complete)
1647{
Mark Rustade23f3332015-08-08 16:18:33 -07001648 s32 status;
Emil Tantilov812d7df2016-10-03 17:09:58 -07001649 u16 reg_slice, reg_val;
Mark Rustade23f3332015-08-08 16:18:33 -07001650 bool setup_linear = false;
1651
1652 /* Check if SFP module is supported and linear */
1653 status = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1654
1655 /* If no SFP module present, then return success. Return success since
1656 * there is no reason to configure CS4227 and SFP not present error is
1657 * not accepted in the setup MAC link flow.
1658 */
1659 if (status == IXGBE_ERR_SFP_NOT_PRESENT)
1660 return 0;
1661
1662 if (status)
1663 return status;
1664
Emil Tantilov812d7df2016-10-03 17:09:58 -07001665 /* Configure internal PHY for KR/KX. */
1666 ixgbe_setup_kr_speed_x550em(hw, speed);
Mark Rustade23f3332015-08-08 16:18:33 -07001667
Emil Tantilov812d7df2016-10-03 17:09:58 -07001668 /* Configure CS4227 LINE side to proper mode. */
1669 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
1670 if (setup_linear)
1671 reg_val = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
1672 else
1673 reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
Emil Tantilovb71f6c42016-10-10 14:54:03 -07001674
1675 status = hw->link.ops.write_link(hw, hw->link.addr, reg_slice,
1676 reg_val);
1677
Mark Rustade23f3332015-08-08 16:18:33 -07001678 return status;
Mark Rustad6d373a12015-08-08 16:18:28 -07001679}
1680
1681/**
Don Skidmore470739b2016-11-03 21:01:37 -04001682 * ixgbe_setup_sfi_x550a - Configure the internal PHY for native SFI mode
1683 * @hw: pointer to hardware structure
1684 * @speed: the link speed to force
1685 *
1686 * Configures the integrated PHY for native SFI mode. Used to connect the
1687 * internal PHY directly to an SFP cage, without autonegotiation.
1688 **/
1689static s32 ixgbe_setup_sfi_x550a(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1690{
1691 struct ixgbe_mac_info *mac = &hw->mac;
1692 s32 status;
1693 u32 reg_val;
1694
1695 /* Disable all AN and force speed to 10G Serial. */
1696 status = mac->ops.read_iosf_sb_reg(hw,
1697 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1698 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
1699 if (status)
1700 return status;
1701
1702 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
1703 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
1704 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
1705 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
1706
1707 /* Select forced link speed for internal PHY. */
1708 switch (*speed) {
1709 case IXGBE_LINK_SPEED_10GB_FULL:
1710 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_10G;
1711 break;
1712 case IXGBE_LINK_SPEED_1GB_FULL:
1713 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
1714 break;
1715 default:
1716 /* Other link speeds are not supported by internal PHY. */
1717 return IXGBE_ERR_LINK_SETUP;
1718 }
1719
1720 status = mac->ops.write_iosf_sb_reg(hw,
1721 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1722 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1723
1724 /* Toggle port SW reset by AN reset. */
1725 status = ixgbe_restart_an_internal_phy_x550em(hw);
1726
1727 return status;
1728}
1729
1730/**
Mark Rustad2d40cd12016-04-01 12:18:35 -07001731 * ixgbe_setup_mac_link_sfp_n - Setup internal PHY for native SFP
1732 * @hw: pointer to hardware structure
1733 *
1734 * Configure the the integrated PHY for native SFP support.
1735 */
1736static s32
1737ixgbe_setup_mac_link_sfp_n(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1738 __always_unused bool autoneg_wait_to_complete)
1739{
1740 bool setup_linear = false;
1741 u32 reg_phy_int;
Don Skidmore470739b2016-11-03 21:01:37 -04001742 s32 ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001743
1744 /* Check if SFP module is supported and linear */
Don Skidmore470739b2016-11-03 21:01:37 -04001745 ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
Mark Rustad2d40cd12016-04-01 12:18:35 -07001746
1747 /* If no SFP module present, then return success. Return success since
1748 * SFP not present error is not excepted in the setup MAC link flow.
1749 */
Don Skidmore470739b2016-11-03 21:01:37 -04001750 if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001751 return 0;
1752
Don Skidmore470739b2016-11-03 21:01:37 -04001753 if (!ret_val)
1754 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001755
Don Skidmore470739b2016-11-03 21:01:37 -04001756 /* Configure internal PHY for native SFI based on module type */
1757 ret_val = hw->mac.ops.read_iosf_sb_reg(hw,
1758 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1759 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_phy_int);
1760 if (!ret_val)
1761 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001762
Don Skidmore470739b2016-11-03 21:01:37 -04001763 reg_phy_int &= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_DA;
1764 if (!setup_linear)
1765 reg_phy_int |= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_SR;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001766
Don Skidmore470739b2016-11-03 21:01:37 -04001767 ret_val = hw->mac.ops.write_iosf_sb_reg(hw,
1768 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1769 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_phy_int);
1770 if (!ret_val)
1771 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001772
Don Skidmore470739b2016-11-03 21:01:37 -04001773 /* Setup SFI internal link. */
1774 return ixgbe_setup_sfi_x550a(hw, &speed);
Mark Rustad2d40cd12016-04-01 12:18:35 -07001775}
1776
1777/**
1778 * ixgbe_setup_mac_link_sfp_x550a - Setup internal PHY for SFP
1779 * @hw: pointer to hardware structure
1780 *
1781 * Configure the the integrated PHY for SFP support.
1782 */
1783static s32
1784ixgbe_setup_mac_link_sfp_x550a(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1785 __always_unused bool autoneg_wait_to_complete)
1786{
1787 u32 reg_slice, slice_offset;
1788 bool setup_linear = false;
1789 u16 reg_phy_ext;
Don Skidmore470739b2016-11-03 21:01:37 -04001790 s32 ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001791
1792 /* Check if SFP module is supported and linear */
Don Skidmore470739b2016-11-03 21:01:37 -04001793 ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
Mark Rustad2d40cd12016-04-01 12:18:35 -07001794
1795 /* If no SFP module present, then return success. Return success since
1796 * SFP not present error is not excepted in the setup MAC link flow.
1797 */
Don Skidmore470739b2016-11-03 21:01:37 -04001798 if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001799 return 0;
1800
Don Skidmore470739b2016-11-03 21:01:37 -04001801 if (!ret_val)
1802 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001803
1804 /* Configure internal PHY for KR/KX. */
1805 ixgbe_setup_kr_speed_x550em(hw, speed);
1806
Mark Rustad7564a882016-09-01 13:58:51 -07001807 if (hw->phy.mdio.prtad == MDIO_PRTAD_NONE)
Mark Rustad2d40cd12016-04-01 12:18:35 -07001808 return IXGBE_ERR_PHY_ADDR_INVALID;
1809
1810 /* Get external PHY device id */
Don Skidmore470739b2016-11-03 21:01:37 -04001811 ret_val = hw->phy.ops.read_reg(hw, IXGBE_CS4227_GLOBAL_ID_MSB,
Mark Rustad2d40cd12016-04-01 12:18:35 -07001812 IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
Don Skidmore470739b2016-11-03 21:01:37 -04001813 if (ret_val)
1814 return ret_val;
Mark Rustad2d40cd12016-04-01 12:18:35 -07001815
1816 /* When configuring quad port CS4223, the MAC instance is part
1817 * of the slice offset.
1818 */
1819 if (reg_phy_ext == IXGBE_CS4223_PHY_ID)
1820 slice_offset = (hw->bus.lan_id +
1821 (hw->bus.instance_id << 1)) << 12;
1822 else
1823 slice_offset = hw->bus.lan_id << 12;
1824
1825 /* Configure CS4227/CS4223 LINE side to proper mode. */
1826 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + slice_offset;
1827 if (setup_linear)
1828 reg_phy_ext = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1829 else
1830 reg_phy_ext = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1831 return hw->phy.ops.write_reg(hw, reg_slice, IXGBE_MDIO_ZERO_DEV_TYPE,
1832 reg_phy_ext);
1833}
1834
1835/**
Don Skidmorec3dc4c02015-06-09 16:26:44 -07001836 * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
1837 * @hw: pointer to hardware structure
1838 * @speed: new link speed
1839 * @autoneg_wait_to_complete: true when waiting for completion is needed
1840 *
1841 * Setup internal/external PHY link speed based on link speed, then set
1842 * external PHY auto advertised link speed.
1843 *
1844 * Returns error status for any failure
1845 **/
1846static s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
1847 ixgbe_link_speed speed,
1848 bool autoneg_wait)
1849{
1850 s32 status;
1851 ixgbe_link_speed force_speed;
1852
1853 /* Setup internal/external PHY link speed to iXFI (10G), unless
1854 * only 1G is auto advertised then setup KX link.
1855 */
1856 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1857 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
1858 else
1859 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
1860
1861 /* If internal link mode is XFI, then setup XFI internal link. */
1862 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1863 status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
1864
1865 if (status)
1866 return status;
1867 }
1868
1869 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
1870}
1871
Don Skidmorea4e293a2015-06-09 17:44:58 -07001872/** ixgbe_check_link_t_X550em - Determine link and speed status
1873 * @hw: pointer to hardware structure
1874 * @speed: pointer to link speed
1875 * @link_up: true when link is up
1876 * @link_up_wait_to_complete: bool used to wait for link up or not
1877 *
1878 * Check that both the MAC and X557 external PHY have link.
1879 **/
1880static s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw,
1881 ixgbe_link_speed *speed,
1882 bool *link_up,
1883 bool link_up_wait_to_complete)
1884{
1885 u32 status;
Emil Tantilov21d882e2016-09-26 14:08:18 -07001886 u16 i, autoneg_status;
Don Skidmorea4e293a2015-06-09 17:44:58 -07001887
1888 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
1889 return IXGBE_ERR_CONFIG;
1890
1891 status = ixgbe_check_mac_link_generic(hw, speed, link_up,
1892 link_up_wait_to_complete);
1893
1894 /* If check link fails or MAC link is not up, then return */
1895 if (status || !(*link_up))
1896 return status;
1897
Emil Tantilov21d882e2016-09-26 14:08:18 -07001898 /* MAC link is up, so check external PHY link.
1899 * Link status is latching low, and can only be used to detect link
1900 * drop, and not the current status of the link without performing
1901 * back-to-back reads.
1902 */
1903 for (i = 0; i < 2; i++) {
1904 status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
1905 &autoneg_status);
1906
1907 if (status)
1908 return status;
1909 }
Don Skidmorea4e293a2015-06-09 17:44:58 -07001910
1911 /* If external PHY link is not up, then indicate link not up */
1912 if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
1913 *link_up = false;
1914
1915 return 0;
1916}
1917
Mark Rustad200157c2016-04-01 12:18:40 -07001918/**
1919 * ixgbe_setup_sgmii - Set up link for sgmii
1920 * @hw: pointer to hardware structure
1921 */
1922static s32
1923ixgbe_setup_sgmii(struct ixgbe_hw *hw, __always_unused ixgbe_link_speed speed,
1924 __always_unused bool autoneg_wait_to_complete)
1925{
1926 struct ixgbe_mac_info *mac = &hw->mac;
Don Skidmore470739b2016-11-03 21:01:37 -04001927 u32 lval, sval, flx_val;
Mark Rustad200157c2016-04-01 12:18:40 -07001928 s32 rc;
1929
1930 rc = mac->ops.read_iosf_sb_reg(hw,
1931 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1932 IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
1933 if (rc)
1934 return rc;
1935
1936 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1937 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1938 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
1939 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
1940 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1941 rc = mac->ops.write_iosf_sb_reg(hw,
1942 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1943 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
1944 if (rc)
1945 return rc;
1946
1947 rc = mac->ops.read_iosf_sb_reg(hw,
1948 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
1949 IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
1950 if (rc)
1951 return rc;
1952
1953 sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
1954 sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
1955 rc = mac->ops.write_iosf_sb_reg(hw,
1956 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
1957 IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
1958 if (rc)
1959 return rc;
1960
Don Skidmore470739b2016-11-03 21:01:37 -04001961 rc = mac->ops.read_iosf_sb_reg(hw,
1962 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1963 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
1964 if (rc)
1965 return rc;
Mark Rustad200157c2016-04-01 12:18:40 -07001966
Don Skidmore470739b2016-11-03 21:01:37 -04001967 rc = mac->ops.read_iosf_sb_reg(hw,
1968 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1969 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
1970 if (rc)
1971 return rc;
1972
1973 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
1974 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
1975 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
1976 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
1977 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
1978
1979 rc = mac->ops.write_iosf_sb_reg(hw,
1980 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
1981 IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
1982 if (rc)
1983 return rc;
1984
1985 rc = ixgbe_restart_an_internal_phy_x550em(hw);
Mark Rustad200157c2016-04-01 12:18:40 -07001986 return rc;
1987}
1988
Mark Rustadb3eb4e12016-12-14 11:02:16 -08001989/**
1990 * ixgbe_setup_sgmii_fw - Set up link for sgmii with firmware-controlled PHYs
1991 * @hw: pointer to hardware structure
1992 */
1993static s32 ixgbe_setup_sgmii_fw(struct ixgbe_hw *hw, ixgbe_link_speed speed,
1994 bool autoneg_wait)
1995{
1996 struct ixgbe_mac_info *mac = &hw->mac;
1997 u32 lval, sval, flx_val;
1998 s32 rc;
1999
2000 rc = mac->ops.read_iosf_sb_reg(hw,
2001 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2002 IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
2003 if (rc)
2004 return rc;
2005
2006 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
2007 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
2008 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
2009 lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
2010 lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
2011 rc = mac->ops.write_iosf_sb_reg(hw,
2012 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2013 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
2014 if (rc)
2015 return rc;
2016
2017 rc = mac->ops.read_iosf_sb_reg(hw,
2018 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
2019 IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
2020 if (rc)
2021 return rc;
2022
2023 sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
2024 sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
2025 rc = mac->ops.write_iosf_sb_reg(hw,
2026 IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
2027 IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
2028 if (rc)
2029 return rc;
2030
2031 rc = mac->ops.write_iosf_sb_reg(hw,
2032 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2033 IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
2034 if (rc)
2035 return rc;
2036
2037 rc = mac->ops.read_iosf_sb_reg(hw,
2038 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2039 IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
2040 if (rc)
2041 return rc;
2042
2043 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
2044 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
2045 flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
2046 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
2047 flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
2048
2049 rc = mac->ops.write_iosf_sb_reg(hw,
2050 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2051 IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
2052 if (rc)
2053 return rc;
2054
2055 ixgbe_restart_an_internal_phy_x550em(hw);
2056
2057 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
2058}
2059
2060/**
2061 * ixgbe_fc_autoneg_sgmii_x550em_a - Enable flow control IEEE clause 37
2062 * @hw: pointer to hardware structure
2063 *
2064 * Enable flow control according to IEEE clause 37.
2065 */
2066static void ixgbe_fc_autoneg_sgmii_x550em_a(struct ixgbe_hw *hw)
2067{
2068 s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2069 u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
2070 ixgbe_link_speed speed;
2071 bool link_up;
2072
2073 /* AN should have completed when the cable was plugged in.
2074 * Look for reasons to bail out. Bail out if:
2075 * - FC autoneg is disabled, or if
2076 * - link is not up.
2077 */
2078 if (hw->fc.disable_fc_autoneg)
2079 goto out;
2080
2081 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2082 if (!link_up)
2083 goto out;
2084
2085 /* Check if auto-negotiation has completed */
2086 status = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &info);
2087 if (status || !(info[0] & FW_PHY_ACT_GET_LINK_INFO_AN_COMPLETE)) {
2088 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2089 goto out;
2090 }
2091
2092 /* Negotiate the flow control */
2093 status = ixgbe_negotiate_fc(hw, info[0], info[0],
2094 FW_PHY_ACT_GET_LINK_INFO_FC_RX,
2095 FW_PHY_ACT_GET_LINK_INFO_FC_TX,
2096 FW_PHY_ACT_GET_LINK_INFO_LP_FC_RX,
2097 FW_PHY_ACT_GET_LINK_INFO_LP_FC_TX);
2098
2099out:
2100 if (!status) {
2101 hw->fc.fc_was_autonegged = true;
2102 } else {
2103 hw->fc.fc_was_autonegged = false;
2104 hw->fc.current_mode = hw->fc.requested_mode;
2105 }
2106}
2107
Don Skidmore29165002016-09-27 14:31:12 -04002108/** ixgbe_init_mac_link_ops_X550em_a - Init mac link function pointers
2109 * @hw: pointer to hardware structure
2110 **/
2111static void ixgbe_init_mac_link_ops_X550em_a(struct ixgbe_hw *hw)
2112{
2113 struct ixgbe_mac_info *mac = &hw->mac;
2114
2115 switch (mac->ops.get_media_type(hw)) {
2116 case ixgbe_media_type_fiber:
2117 mac->ops.setup_fc = NULL;
2118 mac->ops.fc_autoneg = ixgbe_fc_autoneg_fiber_x550em_a;
2119 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002120 case ixgbe_media_type_copper:
2121 if (hw->device_id != IXGBE_DEV_ID_X550EM_A_1G_T &&
2122 hw->device_id != IXGBE_DEV_ID_X550EM_A_1G_T_L) {
2123 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
2124 break;
2125 }
2126 mac->ops.fc_autoneg = ixgbe_fc_autoneg_sgmii_x550em_a;
2127 mac->ops.setup_fc = ixgbe_fc_autoneg_fw;
2128 mac->ops.setup_link = ixgbe_setup_sgmii_fw;
2129 mac->ops.check_link = ixgbe_check_mac_link_generic;
2130 break;
Don Skidmore29165002016-09-27 14:31:12 -04002131 case ixgbe_media_type_backplane:
2132 mac->ops.fc_autoneg = ixgbe_fc_autoneg_backplane_x550em_a;
2133 mac->ops.setup_fc = ixgbe_setup_fc_backplane_x550em_a;
2134 break;
2135 default:
2136 break;
2137 }
2138}
2139
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002140/** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
2141 * @hw: pointer to hardware structure
2142 **/
2143static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
2144{
2145 struct ixgbe_mac_info *mac = &hw->mac;
2146
Emil Tantilovabf76d72016-07-07 17:18:38 -07002147 mac->ops.setup_fc = ixgbe_setup_fc_x550em;
2148
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002149 switch (mac->ops.get_media_type(hw)) {
2150 case ixgbe_media_type_fiber:
2151 /* CS4227 does not support autoneg, so disable the laser control
2152 * functions for SFP+ fiber
2153 */
2154 mac->ops.disable_tx_laser = NULL;
2155 mac->ops.enable_tx_laser = NULL;
2156 mac->ops.flap_tx_laser = NULL;
Mark Rustad6d373a12015-08-08 16:18:28 -07002157 mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
Mark Rustad2d40cd12016-04-01 12:18:35 -07002158 switch (hw->device_id) {
2159 case IXGBE_DEV_ID_X550EM_A_SFP_N:
2160 mac->ops.setup_mac_link = ixgbe_setup_mac_link_sfp_n;
2161 break;
2162 case IXGBE_DEV_ID_X550EM_A_SFP:
2163 mac->ops.setup_mac_link =
2164 ixgbe_setup_mac_link_sfp_x550a;
2165 break;
2166 default:
2167 mac->ops.setup_mac_link =
2168 ixgbe_setup_mac_link_sfp_x550em;
2169 break;
2170 }
Mark Rustad6d373a12015-08-08 16:18:28 -07002171 mac->ops.set_rate_select_speed =
2172 ixgbe_set_soft_rate_select_speed;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002173 break;
2174 case ixgbe_media_type_copper:
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04002175 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_1G_T)
2176 break;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002177 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
Mark Rustadafdc71e2016-01-25 16:32:10 -08002178 mac->ops.setup_fc = ixgbe_setup_fc_generic;
Don Skidmorea4e293a2015-06-09 17:44:58 -07002179 mac->ops.check_link = ixgbe_check_link_t_X550em;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002180 break;
Mark Rustad49425df2016-04-01 12:18:09 -07002181 case ixgbe_media_type_backplane:
Mark Rustad200157c2016-04-01 12:18:40 -07002182 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII ||
2183 hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII_L)
2184 mac->ops.setup_link = ixgbe_setup_sgmii;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002185 break;
2186 default:
2187 break;
2188 }
Don Skidmore29165002016-09-27 14:31:12 -04002189
2190 /* Additional modification for X550em_a devices */
2191 if (hw->mac.type == ixgbe_mac_x550em_a)
2192 ixgbe_init_mac_link_ops_X550em_a(hw);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002193}
2194
2195/** ixgbe_setup_sfp_modules_X550em - Setup SFP module
2196 * @hw: pointer to hardware structure
2197 */
2198static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
2199{
Mark Rustade23f3332015-08-08 16:18:33 -07002200 s32 status;
2201 bool linear;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002202
Mark Rustade23f3332015-08-08 16:18:33 -07002203 /* Check if SFP module is supported */
2204 status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
2205 if (status)
2206 return status;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002207
2208 ixgbe_init_mac_link_ops_X550em(hw);
2209 hw->phy.ops.reset = NULL;
2210
Mark Rustade23f3332015-08-08 16:18:33 -07002211 return 0;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002212}
2213
2214/** ixgbe_get_link_capabilities_x550em - Determines link capabilities
2215 * @hw: pointer to hardware structure
2216 * @speed: pointer to link speed
2217 * @autoneg: true when autoneg or autotry is enabled
2218 **/
2219static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
2220 ixgbe_link_speed *speed,
2221 bool *autoneg)
2222{
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002223 if (hw->phy.type == ixgbe_phy_fw) {
2224 *autoneg = true;
2225 *speed = hw->phy.speeds_supported;
2226 return 0;
2227 }
2228
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002229 /* SFP */
2230 if (hw->phy.media_type == ixgbe_media_type_fiber) {
2231 /* CS4227 SFP must not enable auto-negotiation */
2232 *autoneg = false;
2233
2234 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
2235 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
2236 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2237 return 0;
2238 }
2239
2240 /* Link capabilities are based on SFP */
2241 if (hw->phy.multispeed_fiber)
2242 *speed = IXGBE_LINK_SPEED_10GB_FULL |
2243 IXGBE_LINK_SPEED_1GB_FULL;
2244 else
2245 *speed = IXGBE_LINK_SPEED_10GB_FULL;
2246 } else {
Don Skidmore18bda0d2016-12-30 21:07:14 -05002247 switch (hw->phy.type) {
2248 case ixgbe_phy_x550em_kx4:
2249 *speed = IXGBE_LINK_SPEED_1GB_FULL |
2250 IXGBE_LINK_SPEED_2_5GB_FULL |
2251 IXGBE_LINK_SPEED_10GB_FULL;
2252 break;
Don Skidmore18e01ee2016-12-30 21:07:58 -05002253 case ixgbe_phy_x550em_xfi:
2254 *speed = IXGBE_LINK_SPEED_1GB_FULL |
2255 IXGBE_LINK_SPEED_10GB_FULL;
2256 break;
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04002257 case ixgbe_phy_ext_1g_t:
Don Skidmore18bda0d2016-12-30 21:07:14 -05002258 case ixgbe_phy_sgmii:
2259 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2260 break;
Don Skidmore8e5c9c52016-12-30 21:13:18 -05002261 case ixgbe_phy_x550em_kr:
2262 if (hw->mac.type == ixgbe_mac_x550em_a) {
2263 /* check different backplane modes */
2264 if (hw->phy.nw_mng_if_sel &
2265 IXGBE_NW_MNG_IF_SEL_PHY_SPEED_2_5G) {
2266 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
2267 break;
2268 } else if (hw->device_id ==
2269 IXGBE_DEV_ID_X550EM_A_KR_L) {
2270 *speed = IXGBE_LINK_SPEED_1GB_FULL;
2271 break;
2272 }
2273 }
2274 /* fall through */
Don Skidmore18bda0d2016-12-30 21:07:14 -05002275 default:
2276 *speed = IXGBE_LINK_SPEED_10GB_FULL |
2277 IXGBE_LINK_SPEED_1GB_FULL;
2278 break;
2279 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002280 *autoneg = true;
2281 }
2282 return 0;
2283}
2284
2285/**
2286 * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
2287 * @hw: pointer to hardware structure
2288 * @lsc: pointer to boolean flag which indicates whether external Base T
2289 * PHY interrupt is lsc
2290 *
2291 * Determime if external Base T PHY interrupt cause is high temperature
2292 * failure alarm or link status change.
2293 *
2294 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
2295 * failure alarm, else return PHY access status.
2296 **/
2297static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
2298{
2299 u32 status;
2300 u16 reg;
2301
2302 *lsc = false;
2303
2304 /* Vendor alarm triggered */
2305 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002306 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002307 &reg);
2308
2309 if (status || !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
2310 return status;
2311
2312 /* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
2313 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002314 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002315 &reg);
2316
2317 if (status || !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
2318 IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
2319 return status;
2320
Mark Rustad83a9fb22015-10-19 09:22:14 -07002321 /* Global alarm triggered */
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002322 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002323 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002324 &reg);
2325
2326 if (status)
2327 return status;
2328
2329 /* If high temperature failure, then return over temp error and exit */
2330 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
2331 /* power down the PHY in case the PHY FW didn't already */
2332 ixgbe_set_copper_phy_power(hw, false);
2333 return IXGBE_ERR_OVERTEMP;
2334 }
Mark Rustad83a9fb22015-10-19 09:22:14 -07002335 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
2336 /* device fault alarm triggered */
2337 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002338 MDIO_MMD_VEND1,
Mark Rustad83a9fb22015-10-19 09:22:14 -07002339 &reg);
2340 if (status)
2341 return status;
2342
2343 /* if device fault was due to high temp alarm handle and exit */
2344 if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
2345 /* power down the PHY in case the PHY FW didn't */
2346 ixgbe_set_copper_phy_power(hw, false);
2347 return IXGBE_ERR_OVERTEMP;
2348 }
2349 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002350
2351 /* Vendor alarm 2 triggered */
2352 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002353 MDIO_MMD_AN, &reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002354
2355 if (status || !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
2356 return status;
2357
2358 /* link connect/disconnect event occurred */
2359 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002360 MDIO_MMD_AN, &reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002361
2362 if (status)
2363 return status;
2364
2365 /* Indicate LSC */
2366 if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
2367 *lsc = true;
2368
2369 return 0;
2370}
2371
2372/**
2373 * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
2374 * @hw: pointer to hardware structure
2375 *
2376 * Enable link status change and temperature failure alarm for the external
2377 * Base T PHY
2378 *
2379 * Returns PHY access status
2380 **/
2381static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
2382{
2383 u32 status;
2384 u16 reg;
2385 bool lsc;
2386
2387 /* Clear interrupt flags */
2388 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
2389
2390 /* Enable link status change alarm */
2391 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002392 MDIO_MMD_AN, &reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002393 if (status)
2394 return status;
2395
2396 reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
2397
2398 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002399 MDIO_MMD_AN, reg);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002400 if (status)
2401 return status;
2402
Mark Rustad83a9fb22015-10-19 09:22:14 -07002403 /* Enable high temperature failure and global fault alarms */
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002404 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002405 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002406 &reg);
2407 if (status)
2408 return status;
2409
Mark Rustad83a9fb22015-10-19 09:22:14 -07002410 reg |= (IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN |
2411 IXGBE_MDIO_GLOBAL_INT_DEV_FAULT_EN);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002412
2413 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002414 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002415 reg);
2416 if (status)
2417 return status;
2418
2419 /* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
2420 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002421 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002422 &reg);
2423 if (status)
2424 return status;
2425
2426 reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
2427 IXGBE_MDIO_GLOBAL_ALARM_1_INT);
2428
2429 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002430 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002431 reg);
2432 if (status)
2433 return status;
2434
2435 /* Enable chip-wide vendor alarm */
2436 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002437 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002438 &reg);
2439 if (status)
2440 return status;
2441
2442 reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
2443
2444 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002445 MDIO_MMD_VEND1,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002446 reg);
2447
2448 return status;
2449}
2450
2451/**
2452 * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
2453 * @hw: pointer to hardware structure
2454 *
2455 * Handle external Base T PHY interrupt. If high temperature
2456 * failure alarm then return error, else if link status change
2457 * then setup internal/external PHY link
2458 *
2459 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
2460 * failure alarm, else return PHY access status.
2461 **/
2462static s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
2463{
2464 struct ixgbe_phy_info *phy = &hw->phy;
2465 bool lsc;
2466 u32 status;
2467
2468 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
2469 if (status)
2470 return status;
2471
Mark Rustada85ce532015-09-09 13:37:33 -07002472 if (lsc && phy->ops.setup_internal_link)
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002473 return phy->ops.setup_internal_link(hw);
2474
2475 return 0;
2476}
2477
2478/**
2479 * ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
2480 * @hw: pointer to hardware structure
2481 * @speed: link speed
2482 *
2483 * Configures the integrated KR PHY.
2484 **/
2485static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
2486 ixgbe_link_speed speed)
2487{
2488 s32 status;
2489 u32 reg_val;
2490
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002491 status = hw->mac.ops.read_iosf_sb_reg(hw,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002492 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2493 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
2494 if (status)
2495 return status;
2496
2497 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002498 reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
2499 IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
2500
2501 /* Advertise 10G support. */
2502 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
2503 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
2504
2505 /* Advertise 1G support. */
2506 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
2507 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
2508
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002509 status = hw->mac.ops.write_iosf_sb_reg(hw,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002510 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2511 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2512
Don Skidmore470739b2016-11-03 21:01:37 -04002513 if (hw->mac.type == ixgbe_mac_x550em_a) {
2514 /* Set lane mode to KR auto negotiation */
2515 status = hw->mac.ops.read_iosf_sb_reg(hw,
2516 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2517 IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
2518
2519 if (status)
2520 return status;
2521
2522 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
2523 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
2524 reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
2525 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
2526 reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
2527
2528 status = hw->mac.ops.write_iosf_sb_reg(hw,
2529 IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
2530 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2531 }
2532
2533 return ixgbe_restart_an_internal_phy_x550em(hw);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002534}
2535
Mark Rustadf572b2c2016-04-01 12:18:46 -07002536/**
2537 * ixgbe_setup_kr_x550em - Configure the KR PHY
2538 * @hw: pointer to hardware structure
Don Skidmore6a14ee02014-12-05 03:59:50 +00002539 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00002540static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002541{
Don Skidmore54f6d4c2016-12-13 20:34:51 -05002542 /* leave link alone for 2.5G */
2543 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_2_5GB_FULL)
Mark Rustadf572b2c2016-04-01 12:18:46 -07002544 return 0;
2545
Tony Nguyenf4a63742017-03-01 11:52:09 -08002546 if (ixgbe_check_reset_blocked(hw))
2547 return 0;
2548
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002549 return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002550}
2551
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002552/** ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
2553 * @hw: address of hardware structure
2554 * @link_up: address of boolean to indicate link status
2555 *
2556 * Returns error code if unable to get link status.
2557 **/
2558static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
2559{
2560 u32 ret;
2561 u16 autoneg_status;
2562
2563 *link_up = false;
2564
2565 /* read this twice back to back to indicate current status */
Emil Tantilov4dc40002016-09-26 14:08:13 -07002566 ret = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002567 &autoneg_status);
2568 if (ret)
2569 return ret;
2570
Emil Tantilov4dc40002016-09-26 14:08:13 -07002571 ret = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002572 &autoneg_status);
2573 if (ret)
2574 return ret;
2575
2576 *link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
2577
2578 return 0;
2579}
2580
2581/** ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
Don Skidmore6a14ee02014-12-05 03:59:50 +00002582 * @hw: point to hardware structure
2583 *
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002584 * Configures the link between the integrated KR PHY and the external X557 PHY
2585 * The driver will call this function when it gets a link status change
2586 * interrupt from the X557 PHY. This function configures the link speed
2587 * between the PHYs to match the link speed of the BASE-T link.
Don Skidmore6a14ee02014-12-05 03:59:50 +00002588 *
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002589 * A return of a non-zero value indicates an error, and the base driver should
2590 * not report link up.
Don Skidmore6a14ee02014-12-05 03:59:50 +00002591 **/
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002592static s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002593{
Don Skidmore6a14ee02014-12-05 03:59:50 +00002594 ixgbe_link_speed force_speed;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002595 bool link_up;
2596 u32 status;
2597 u16 speed;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002598
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002599 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
2600 return IXGBE_ERR_CONFIG;
2601
Mark Rustadf164b842015-10-16 13:27:49 -07002602 if (hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE) {
2603 speed = IXGBE_LINK_SPEED_10GB_FULL |
2604 IXGBE_LINK_SPEED_1GB_FULL;
2605 return ixgbe_setup_kr_speed_x550em(hw, speed);
2606 }
2607
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002608 /* If link is not up, then there is no setup necessary so return */
2609 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
Don Skidmore6a14ee02014-12-05 03:59:50 +00002610 if (status)
2611 return status;
2612
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002613 if (!link_up)
Don Skidmore6a14ee02014-12-05 03:59:50 +00002614 return 0;
2615
Don Skidmore6a14ee02014-12-05 03:59:50 +00002616 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002617 MDIO_MMD_AN,
Don Skidmore6a14ee02014-12-05 03:59:50 +00002618 &speed);
Don Skidmorec3dc4c02015-06-09 16:26:44 -07002619 if (status)
2620 return status;
2621
2622 /* If link is not still up, then no setup is necessary so return */
2623 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2624 if (status)
2625 return status;
2626
2627 if (!link_up)
2628 return 0;
Don Skidmore6a14ee02014-12-05 03:59:50 +00002629
2630 /* clear everything but the speed and duplex bits */
2631 speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
2632
2633 switch (speed) {
2634 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
2635 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
2636 break;
2637 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
2638 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
2639 break;
2640 default:
2641 /* Internal PHY does not support anything else */
2642 return IXGBE_ERR_INVALID_LINK_SETTINGS;
2643 }
2644
2645 return ixgbe_setup_ixfi_x550em(hw, &force_speed);
2646}
2647
Don Skidmoref4410d22015-06-09 16:29:51 -07002648/** ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
2649 * @hw: pointer to hardware structure
2650 **/
2651static s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
2652{
2653 s32 status;
2654
2655 status = ixgbe_reset_phy_generic(hw);
2656
2657 if (status)
2658 return status;
2659
2660 /* Configure Link Status Alarm and Temperature Threshold interrupts */
2661 return ixgbe_enable_lasi_ext_t_x550em(hw);
2662}
2663
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002664/**
2665 * ixgbe_led_on_t_x550em - Turns on the software controllable LEDs.
2666 * @hw: pointer to hardware structure
2667 * @led_idx: led number to turn on
2668 **/
Emil Tantilovd2d43e52016-08-22 16:28:34 -07002669static s32 ixgbe_led_on_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002670{
2671 u16 phy_data;
2672
2673 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
2674 return IXGBE_ERR_PARAM;
2675
2676 /* To turn on the LED, set mode to ON. */
2677 hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002678 MDIO_MMD_VEND1, &phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002679 phy_data |= IXGBE_X557_LED_MANUAL_SET_MASK;
2680 hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002681 MDIO_MMD_VEND1, phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002682
2683 return 0;
2684}
2685
2686/**
2687 * ixgbe_led_off_t_x550em - Turns off the software controllable LEDs.
2688 * @hw: pointer to hardware structure
2689 * @led_idx: led number to turn off
2690 **/
Emil Tantilovd2d43e52016-08-22 16:28:34 -07002691static s32 ixgbe_led_off_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002692{
2693 u16 phy_data;
2694
2695 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
2696 return IXGBE_ERR_PARAM;
2697
2698 /* To turn on the LED, set mode to ON. */
2699 hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002700 MDIO_MMD_VEND1, &phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002701 phy_data &= ~IXGBE_X557_LED_MANUAL_SET_MASK;
2702 hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002703 MDIO_MMD_VEND1, phy_data);
Don Skidmorea0ad55a2016-08-17 14:11:57 -04002704
2705 return 0;
2706}
2707
Tony Nguyencb8e0512016-10-26 16:25:18 -07002708/**
2709 * ixgbe_set_fw_drv_ver_x550 - Sends driver version to firmware
2710 * @hw: pointer to the HW structure
2711 * @maj: driver version major number
2712 * @min: driver version minor number
2713 * @build: driver version build number
2714 * @sub: driver version sub build number
2715 * @len: length of driver_ver string
2716 * @driver_ver: driver string
2717 *
2718 * Sends driver version number to firmware through the manageability
2719 * block. On success return 0
2720 * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
2721 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
2722 **/
2723static s32 ixgbe_set_fw_drv_ver_x550(struct ixgbe_hw *hw, u8 maj, u8 min,
2724 u8 build, u8 sub, u16 len,
2725 const char *driver_ver)
2726{
2727 struct ixgbe_hic_drv_info2 fw_cmd;
2728 s32 ret_val;
2729 int i;
2730
2731 if (!len || !driver_ver || (len > sizeof(fw_cmd.driver_string)))
2732 return IXGBE_ERR_INVALID_ARGUMENT;
2733
2734 fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
2735 fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN + len;
2736 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
2737 fw_cmd.port_num = (u8)hw->bus.func;
2738 fw_cmd.ver_maj = maj;
2739 fw_cmd.ver_min = min;
2740 fw_cmd.ver_build = build;
2741 fw_cmd.ver_sub = sub;
2742 fw_cmd.hdr.checksum = 0;
2743 memcpy(fw_cmd.driver_string, driver_ver, len);
2744 fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
2745 (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
2746
2747 for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
2748 ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
2749 sizeof(fw_cmd),
2750 IXGBE_HI_COMMAND_TIMEOUT,
2751 true);
2752 if (ret_val)
2753 continue;
2754
2755 if (fw_cmd.hdr.cmd_or_resp.ret_status !=
2756 FW_CEM_RESP_STATUS_SUCCESS)
2757 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
2758 return 0;
2759 }
2760
2761 return ret_val;
2762}
2763
Don Skidmore6ac74392015-06-17 17:34:31 -04002764/** ixgbe_get_lcd_x550em - Determine lowest common denominator
2765 * @hw: pointer to hardware structure
2766 * @lcd_speed: pointer to lowest common link speed
2767 *
2768 * Determine lowest common link speed with link partner.
2769 **/
2770static s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw,
2771 ixgbe_link_speed *lcd_speed)
2772{
2773 u16 an_lp_status;
2774 s32 status;
2775 u16 word = hw->eeprom.ctrl_word_3;
2776
2777 *lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
2778
2779 status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
Emil Tantilov4dc40002016-09-26 14:08:13 -07002780 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04002781 &an_lp_status);
2782 if (status)
2783 return status;
2784
2785 /* If link partner advertised 1G, return 1G */
2786 if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
2787 *lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
2788 return status;
2789 }
2790
2791 /* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
2792 if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
2793 (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
2794 return status;
2795
2796 /* Link partner not capable of lower speeds, return 10G */
2797 *lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
2798 return status;
2799}
2800
Mark Rustadafdc71e2016-01-25 16:32:10 -08002801/**
2802 * ixgbe_setup_fc_x550em - Set up flow control
2803 * @hw: pointer to hardware structure
2804 */
2805static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *hw)
2806{
2807 bool pause, asm_dir;
2808 u32 reg_val;
2809 s32 rc;
2810
2811 /* Validate the requested mode */
2812 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2813 hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
2814 return IXGBE_ERR_INVALID_LINK_SETTINGS;
2815 }
2816
2817 /* 10gig parts do not have a word in the EEPROM to determine the
2818 * default flow control setting, so we explicitly set it to full.
2819 */
2820 if (hw->fc.requested_mode == ixgbe_fc_default)
2821 hw->fc.requested_mode = ixgbe_fc_full;
2822
2823 /* Determine PAUSE and ASM_DIR bits. */
2824 switch (hw->fc.requested_mode) {
2825 case ixgbe_fc_none:
2826 pause = false;
2827 asm_dir = false;
2828 break;
2829 case ixgbe_fc_tx_pause:
2830 pause = false;
2831 asm_dir = true;
2832 break;
2833 case ixgbe_fc_rx_pause:
2834 /* Rx Flow control is enabled and Tx Flow control is
2835 * disabled by software override. Since there really
2836 * isn't a way to advertise that we are capable of RX
2837 * Pause ONLY, we will advertise that we support both
2838 * symmetric and asymmetric Rx PAUSE, as such we fall
2839 * through to the fc_full statement. Later, we will
2840 * disable the adapter's ability to send PAUSE frames.
2841 */
2842 /* Fallthrough */
2843 case ixgbe_fc_full:
2844 pause = true;
2845 asm_dir = true;
2846 break;
2847 default:
2848 hw_err(hw, "Flow control param set incorrectly\n");
2849 return IXGBE_ERR_CONFIG;
2850 }
2851
Mark Rustadf572b2c2016-04-01 12:18:46 -07002852 if (hw->device_id != IXGBE_DEV_ID_X550EM_X_KR &&
2853 hw->device_id != IXGBE_DEV_ID_X550EM_A_KR &&
2854 hw->device_id != IXGBE_DEV_ID_X550EM_A_KR_L)
Mark Rustadafdc71e2016-01-25 16:32:10 -08002855 return 0;
2856
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002857 rc = hw->mac.ops.read_iosf_sb_reg(hw,
2858 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2859 IXGBE_SB_IOSF_TARGET_KR_PHY,
2860 &reg_val);
Mark Rustadafdc71e2016-01-25 16:32:10 -08002861 if (rc)
2862 return rc;
2863
2864 reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
2865 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
2866 if (pause)
2867 reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
2868 if (asm_dir)
2869 reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
Mark Rustad9a5c27e2016-04-01 12:18:04 -07002870 rc = hw->mac.ops.write_iosf_sb_reg(hw,
2871 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2872 IXGBE_SB_IOSF_TARGET_KR_PHY,
2873 reg_val);
Mark Rustadafdc71e2016-01-25 16:32:10 -08002874
2875 /* This device does not fully support AN. */
2876 hw->fc.disable_fc_autoneg = true;
2877
2878 return rc;
2879}
2880
Don Skidmore29165002016-09-27 14:31:12 -04002881/**
2882 * ixgbe_fc_autoneg_backplane_x550em_a - Enable flow control IEEE clause 37
2883 * @hw: pointer to hardware structure
2884 **/
2885static void ixgbe_fc_autoneg_backplane_x550em_a(struct ixgbe_hw *hw)
2886{
2887 u32 link_s1, lp_an_page_low, an_cntl_1;
2888 s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2889 ixgbe_link_speed speed;
2890 bool link_up;
2891
2892 /* AN should have completed when the cable was plugged in.
2893 * Look for reasons to bail out. Bail out if:
2894 * - FC autoneg is disabled, or if
2895 * - link is not up.
2896 */
2897 if (hw->fc.disable_fc_autoneg) {
2898 hw_err(hw, "Flow control autoneg is disabled");
2899 goto out;
2900 }
2901
2902 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2903 if (!link_up) {
2904 hw_err(hw, "The link is down");
2905 goto out;
2906 }
2907
2908 /* Check at auto-negotiation has completed */
2909 status = hw->mac.ops.read_iosf_sb_reg(hw,
2910 IXGBE_KRM_LINK_S1(hw->bus.lan_id),
2911 IXGBE_SB_IOSF_TARGET_KR_PHY, &link_s1);
2912
2913 if (status || (link_s1 & IXGBE_KRM_LINK_S1_MAC_AN_COMPLETE) == 0) {
2914 hw_dbg(hw, "Auto-Negotiation did not complete\n");
2915 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
2916 goto out;
2917 }
2918
2919 /* Read the 10g AN autoc and LP ability registers and resolve
2920 * local flow control settings accordingly
2921 */
2922 status = hw->mac.ops.read_iosf_sb_reg(hw,
2923 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2924 IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl_1);
2925
2926 if (status) {
2927 hw_dbg(hw, "Auto-Negotiation did not complete\n");
2928 goto out;
2929 }
2930
2931 status = hw->mac.ops.read_iosf_sb_reg(hw,
2932 IXGBE_KRM_LP_BASE_PAGE_HIGH(hw->bus.lan_id),
2933 IXGBE_SB_IOSF_TARGET_KR_PHY, &lp_an_page_low);
2934
2935 if (status) {
2936 hw_dbg(hw, "Auto-Negotiation did not complete\n");
2937 goto out;
2938 }
2939
2940 status = ixgbe_negotiate_fc(hw, an_cntl_1, lp_an_page_low,
2941 IXGBE_KRM_AN_CNTL_1_SYM_PAUSE,
2942 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE,
2943 IXGBE_KRM_LP_BASE_PAGE_HIGH_SYM_PAUSE,
2944 IXGBE_KRM_LP_BASE_PAGE_HIGH_ASM_PAUSE);
2945
2946out:
2947 if (!status) {
2948 hw->fc.fc_was_autonegged = true;
2949 } else {
2950 hw->fc.fc_was_autonegged = false;
2951 hw->fc.current_mode = hw->fc.requested_mode;
2952 }
2953}
2954
2955/**
2956 * ixgbe_fc_autoneg_fiber_x550em_a - passthrough FC settings
2957 * @hw: pointer to hardware structure
2958 **/
2959static void ixgbe_fc_autoneg_fiber_x550em_a(struct ixgbe_hw *hw)
2960{
2961 hw->fc.fc_was_autonegged = false;
2962 hw->fc.current_mode = hw->fc.requested_mode;
2963}
2964
Don Skidmore6ac74392015-06-17 17:34:31 -04002965/** ixgbe_enter_lplu_x550em - Transition to low power states
2966 * @hw: pointer to hardware structure
2967 *
2968 * Configures Low Power Link Up on transition to low power states
2969 * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting
2970 * the X557 PHY immediately prior to entering LPLU.
2971 **/
2972static s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
2973{
2974 u16 an_10g_cntl_reg, autoneg_reg, speed;
2975 s32 status;
2976 ixgbe_link_speed lcd_speed;
2977 u32 save_autoneg;
2978 bool link_up;
2979
Don Skidmore6ac74392015-06-17 17:34:31 -04002980 /* If blocked by MNG FW, then don't restart AN */
2981 if (ixgbe_check_reset_blocked(hw))
2982 return 0;
2983
2984 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2985 if (status)
2986 return status;
2987
2988 status = hw->eeprom.ops.read(hw, NVM_INIT_CTRL_3,
2989 &hw->eeprom.ctrl_word_3);
2990 if (status)
2991 return status;
2992
2993 /* If link is down, LPLU disabled in NVM, WoL disabled, or
2994 * manageability disabled, then force link down by entering
2995 * low power mode.
2996 */
2997 if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
2998 !(hw->wol_enabled || ixgbe_mng_present(hw)))
2999 return ixgbe_set_copper_phy_power(hw, false);
3000
3001 /* Determine LCD */
3002 status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
3003 if (status)
3004 return status;
3005
3006 /* If no valid LCD link speed, then force link down and exit. */
3007 if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
3008 return ixgbe_set_copper_phy_power(hw, false);
3009
3010 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003011 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003012 &speed);
3013 if (status)
3014 return status;
3015
3016 /* If no link now, speed is invalid so take link down */
3017 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
3018 if (status)
3019 return ixgbe_set_copper_phy_power(hw, false);
3020
3021 /* clear everything but the speed bits */
3022 speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
3023
3024 /* If current speed is already LCD, then exit. */
3025 if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
3026 (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
3027 ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
3028 (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
3029 return status;
3030
3031 /* Clear AN completed indication */
3032 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003033 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003034 &autoneg_reg);
3035 if (status)
3036 return status;
3037
Emil Tantilov4dc40002016-09-26 14:08:13 -07003038 status = hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
3039 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003040 &an_10g_cntl_reg);
3041 if (status)
3042 return status;
3043
3044 status = hw->phy.ops.read_reg(hw,
3045 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003046 MDIO_MMD_AN,
Don Skidmore6ac74392015-06-17 17:34:31 -04003047 &autoneg_reg);
3048 if (status)
3049 return status;
3050
3051 save_autoneg = hw->phy.autoneg_advertised;
3052
3053 /* Setup link at least common link speed */
3054 status = hw->mac.ops.setup_link(hw, lcd_speed, false);
3055
3056 /* restore autoneg from before setting lplu speed */
3057 hw->phy.autoneg_advertised = save_autoneg;
3058
3059 return status;
3060}
3061
Mark Rustad537cc5d2016-04-01 12:18:25 -07003062/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003063 * ixgbe_reset_phy_fw - Reset firmware-controlled PHYs
3064 * @hw: pointer to hardware structure
3065 */
3066static s32 ixgbe_reset_phy_fw(struct ixgbe_hw *hw)
3067{
3068 u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
3069 s32 rc;
3070
3071 if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
3072 return 0;
3073
3074 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_PHY_SW_RESET, &store);
3075 if (rc)
3076 return rc;
3077 memset(store, 0, sizeof(store));
3078
3079 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_INIT_PHY, &store);
3080 if (rc)
3081 return rc;
3082
3083 return ixgbe_setup_fw_link(hw);
3084}
3085
3086/**
3087 * ixgbe_check_overtemp_fw - Check firmware-controlled PHYs for overtemp
3088 * @hw: pointer to hardware structure
3089 */
3090static s32 ixgbe_check_overtemp_fw(struct ixgbe_hw *hw)
3091{
3092 u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
3093 s32 rc;
3094
3095 rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &store);
3096 if (rc)
3097 return rc;
3098
3099 if (store[0] & FW_PHY_ACT_GET_LINK_INFO_TEMP) {
3100 ixgbe_shutdown_fw_phy(hw);
3101 return IXGBE_ERR_OVERTEMP;
3102 }
3103 return 0;
3104}
3105
3106/**
Mark Rustad537cc5d2016-04-01 12:18:25 -07003107 * ixgbe_read_mng_if_sel_x550em - Read NW_MNG_IF_SEL register
3108 * @hw: pointer to hardware structure
3109 *
3110 * Read NW_MNG_IF_SEL register and save field values.
3111 */
3112static void ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw)
3113{
3114 /* Save NW management interface connected on board. This is used
3115 * to determine internal PHY mode.
3116 */
3117 hw->phy.nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
3118
3119 /* If X552 (X550EM_a) and MDIO is connected to external PHY, then set
3120 * PHY address. This register field was has only been used for X552.
3121 */
Mark Rustadae3cb8c2016-08-30 11:33:43 -07003122 if (hw->mac.type == ixgbe_mac_x550em_a &&
3123 hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_MDIO_ACT) {
3124 hw->phy.mdio.prtad = (hw->phy.nw_mng_if_sel &
3125 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
3126 IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
Mark Rustad537cc5d2016-04-01 12:18:25 -07003127 }
Mark Rustad537cc5d2016-04-01 12:18:25 -07003128}
3129
Don Skidmore6a14ee02014-12-05 03:59:50 +00003130/** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
3131 * @hw: pointer to hardware structure
3132 *
3133 * Initialize any function pointers that were not able to be
3134 * set during init_shared_code because the PHY/SFP type was
3135 * not known. Perform the SFP init if necessary.
3136 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00003137static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003138{
3139 struct ixgbe_phy_info *phy = &hw->phy;
3140 s32 ret_val;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003141
Don Skidmore7e49d612015-06-09 17:48:54 -07003142 hw->mac.ops.set_lan_id(hw);
3143
Mark Rustad537cc5d2016-04-01 12:18:25 -07003144 ixgbe_read_mng_if_sel_x550em(hw);
3145
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003146 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003147 phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
Don Skidmoreab5fe0c2015-06-09 16:18:56 -07003148 ixgbe_setup_mux_ctl(hw);
Don Skidmore6a14ee02014-12-05 03:59:50 +00003149 }
3150
3151 /* Identify the PHY or SFP module */
3152 ret_val = phy->ops.identify(hw);
3153
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003154 /* Setup function pointers based on detected hardware */
Don Skidmore6a14ee02014-12-05 03:59:50 +00003155 ixgbe_init_mac_link_ops_X550em(hw);
3156 if (phy->sfp_type != ixgbe_sfp_type_unknown)
3157 phy->ops.reset = NULL;
3158
3159 /* Set functions pointers based on phy type */
3160 switch (hw->phy.type) {
3161 case ixgbe_phy_x550em_kx4:
Tony Nguyen5fbf5ad2016-11-01 13:58:27 -07003162 phy->ops.setup_link = NULL;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003163 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
3164 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
3165 break;
3166 case ixgbe_phy_x550em_kr:
3167 phy->ops.setup_link = ixgbe_setup_kr_x550em;
3168 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
3169 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
3170 break;
Don Skidmore18e01ee2016-12-30 21:07:58 -05003171 case ixgbe_phy_x550em_xfi:
3172 /* link is managed by HW */
3173 phy->ops.setup_link = NULL;
3174 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
3175 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
3176 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003177 case ixgbe_phy_x550em_ext_t:
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003178 /* Save NW management interface connected on board. This is used
3179 * to determine internal PHY mode
3180 */
3181 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
3182
3183 /* If internal link mode is XFI, then setup iXFI internal link,
3184 * else setup KR now.
3185 */
Mark Rustadf164b842015-10-16 13:27:49 -07003186 phy->ops.setup_internal_link =
3187 ixgbe_setup_internal_phy_t_x550em;
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003188
Don Skidmore6ac74392015-06-17 17:34:31 -04003189 /* setup SW LPLU only for first revision */
Mark Rustad3ca2b252015-11-20 13:12:17 -08003190 if (hw->mac.type == ixgbe_mac_X550EM_x &&
3191 !(IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0)) &
3192 IXGBE_FUSES0_REV_MASK))
Don Skidmore6ac74392015-06-17 17:34:31 -04003193 phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
3194
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003195 phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
Don Skidmoref4410d22015-06-09 16:29:51 -07003196 phy->ops.reset = ixgbe_reset_phy_t_X550em;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003197 break;
Don Skidmore18bda0d2016-12-30 21:07:14 -05003198 case ixgbe_phy_sgmii:
3199 phy->ops.setup_link = NULL;
3200 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003201 case ixgbe_phy_fw:
3202 phy->ops.setup_link = ixgbe_setup_fw_link;
3203 phy->ops.reset = ixgbe_reset_phy_fw;
3204 break;
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04003205 case ixgbe_phy_ext_1g_t:
3206 phy->ops.setup_link = NULL;
3207 phy->ops.read_reg = NULL;
3208 phy->ops.write_reg = NULL;
Paul Greenwalt5e999fb42017-04-21 05:37:13 -04003209 phy->ops.reset = NULL;
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04003210 break;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003211 default:
3212 break;
3213 }
Don Skidmorec3dc4c02015-06-09 16:26:44 -07003214
Don Skidmore6a14ee02014-12-05 03:59:50 +00003215 return ret_val;
3216}
3217
3218/** ixgbe_get_media_type_X550em - Get media type
3219 * @hw: pointer to hardware structure
3220 *
3221 * Returns the media type (fiber, copper, backplane)
3222 *
3223 */
Don Skidmore7ddbde32014-12-06 05:59:21 +00003224static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003225{
3226 enum ixgbe_media_type media_type;
3227
3228 /* Detect if there is a copper PHY attached. */
3229 switch (hw->device_id) {
Mark Rustad200157c2016-04-01 12:18:40 -07003230 case IXGBE_DEV_ID_X550EM_A_SGMII:
3231 case IXGBE_DEV_ID_X550EM_A_SGMII_L:
3232 hw->phy.type = ixgbe_phy_sgmii;
3233 /* Fallthrough */
Don Skidmore6a14ee02014-12-05 03:59:50 +00003234 case IXGBE_DEV_ID_X550EM_X_KR:
3235 case IXGBE_DEV_ID_X550EM_X_KX4:
Don Skidmore18e01ee2016-12-30 21:07:58 -05003236 case IXGBE_DEV_ID_X550EM_X_XFI:
Mark Rustadf572b2c2016-04-01 12:18:46 -07003237 case IXGBE_DEV_ID_X550EM_A_KR:
3238 case IXGBE_DEV_ID_X550EM_A_KR_L:
Don Skidmore6a14ee02014-12-05 03:59:50 +00003239 media_type = ixgbe_media_type_backplane;
3240 break;
3241 case IXGBE_DEV_ID_X550EM_X_SFP:
Mark Rustad2d40cd12016-04-01 12:18:35 -07003242 case IXGBE_DEV_ID_X550EM_A_SFP:
Mark Rustad49425df2016-04-01 12:18:09 -07003243 case IXGBE_DEV_ID_X550EM_A_SFP_N:
Don Skidmore6a14ee02014-12-05 03:59:50 +00003244 media_type = ixgbe_media_type_fiber;
3245 break;
3246 case IXGBE_DEV_ID_X550EM_X_1G_T:
3247 case IXGBE_DEV_ID_X550EM_X_10G_T:
Don Skidmore92ed8432016-08-17 20:34:40 -04003248 case IXGBE_DEV_ID_X550EM_A_10G_T:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003249 case IXGBE_DEV_ID_X550EM_A_1G_T:
3250 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
Mark Rustad49425df2016-04-01 12:18:09 -07003251 media_type = ixgbe_media_type_copper;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003252 break;
3253 default:
3254 media_type = ixgbe_media_type_unknown;
3255 break;
3256 }
3257 return media_type;
3258}
3259
3260/** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
3261 ** @hw: pointer to hardware structure
3262 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00003263static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003264{
Mark Rustada1e869d2015-04-10 10:36:36 -07003265 s32 status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003266 u16 reg;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003267
Don Skidmore6a14ee02014-12-05 03:59:50 +00003268 status = hw->phy.ops.read_reg(hw,
Don Skidmoree2261bc2015-06-09 17:02:35 -07003269 IXGBE_MDIO_TX_VENDOR_ALARMS_3,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003270 MDIO_MMD_PMAPMD,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003271 &reg);
3272 if (status)
3273 return status;
3274
Don Skidmoree2261bc2015-06-09 17:02:35 -07003275 /* If PHY FW reset completed bit is set then this is the first
3276 * SW instance after a power on so the PHY FW must be un-stalled.
3277 */
3278 if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
3279 status = hw->phy.ops.read_reg(hw,
3280 IXGBE_MDIO_GLOBAL_RES_PR_10,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003281 MDIO_MMD_VEND1,
Don Skidmoree2261bc2015-06-09 17:02:35 -07003282 &reg);
3283 if (status)
3284 return status;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003285
Don Skidmoree2261bc2015-06-09 17:02:35 -07003286 reg &= ~IXGBE_MDIO_POWER_UP_STALL;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003287
Don Skidmoree2261bc2015-06-09 17:02:35 -07003288 status = hw->phy.ops.write_reg(hw,
3289 IXGBE_MDIO_GLOBAL_RES_PR_10,
Emil Tantilov4dc40002016-09-26 14:08:13 -07003290 MDIO_MMD_VEND1,
Don Skidmoree2261bc2015-06-09 17:02:35 -07003291 reg);
3292 if (status)
3293 return status;
3294 }
Don Skidmore6a14ee02014-12-05 03:59:50 +00003295
Don Skidmore6a14ee02014-12-05 03:59:50 +00003296 return status;
3297}
3298
Mark Rustade84db722016-04-01 12:18:30 -07003299/**
3300 * ixgbe_set_mdio_speed - Set MDIO clock speed
3301 * @hw: pointer to hardware structure
3302 */
3303static void ixgbe_set_mdio_speed(struct ixgbe_hw *hw)
3304{
3305 u32 hlreg0;
3306
3307 switch (hw->device_id) {
3308 case IXGBE_DEV_ID_X550EM_X_10G_T:
Don Skidmorea83c27e2016-08-17 17:34:07 -04003309 case IXGBE_DEV_ID_X550EM_A_SGMII:
3310 case IXGBE_DEV_ID_X550EM_A_SGMII_L:
Don Skidmore92ed8432016-08-17 20:34:40 -04003311 case IXGBE_DEV_ID_X550EM_A_10G_T:
Mark Rustad2d40cd12016-04-01 12:18:35 -07003312 case IXGBE_DEV_ID_X550EM_A_SFP:
Mark Rustade84db722016-04-01 12:18:30 -07003313 /* Config MDIO clock speed before the first MDIO PHY access */
3314 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3315 hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
3316 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3317 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003318 case IXGBE_DEV_ID_X550EM_A_1G_T:
3319 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
3320 /* Select fast MDIO clock speed for these devices */
3321 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3322 hlreg0 |= IXGBE_HLREG0_MDCSPD;
3323 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3324 break;
Mark Rustade84db722016-04-01 12:18:30 -07003325 default:
3326 break;
3327 }
3328}
3329
Don Skidmore6a14ee02014-12-05 03:59:50 +00003330/** ixgbe_reset_hw_X550em - Perform hardware reset
3331 ** @hw: pointer to hardware structure
3332 **
3333 ** Resets the hardware by resetting the transmit and receive units, masks
3334 ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
3335 ** reset.
3336 **/
Don Skidmore7ddbde32014-12-06 05:59:21 +00003337static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
Don Skidmore6a14ee02014-12-05 03:59:50 +00003338{
3339 ixgbe_link_speed link_speed;
3340 s32 status;
3341 u32 ctrl = 0;
3342 u32 i;
3343 bool link_up = false;
Paul Greenwalt61334062017-03-13 05:47:56 -04003344 u32 swfw_mask = hw->phy.phy_semaphore_mask;
Don Skidmore6a14ee02014-12-05 03:59:50 +00003345
3346 /* Call adapter stop to disable Tx/Rx and clear interrupts */
3347 status = hw->mac.ops.stop_adapter(hw);
3348 if (status)
3349 return status;
3350
3351 /* flush pending Tx transactions */
3352 ixgbe_clear_tx_pending(hw);
3353
3354 /* PHY ops must be identified and initialized prior to reset */
3355
3356 /* Identify PHY and related function pointers */
3357 status = hw->phy.ops.init(hw);
3358
3359 /* start the external PHY */
3360 if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
3361 status = ixgbe_init_ext_t_x550em(hw);
3362 if (status)
3363 return status;
3364 }
3365
3366 /* Setup SFP module if there is one present. */
3367 if (hw->phy.sfp_setup_needed) {
3368 status = hw->mac.ops.setup_sfp(hw);
3369 hw->phy.sfp_setup_needed = false;
3370 }
3371
3372 /* Reset PHY */
3373 if (!hw->phy.reset_disable && hw->phy.ops.reset)
3374 hw->phy.ops.reset(hw);
3375
3376mac_reset_top:
3377 /* Issue global reset to the MAC. Needs to be SW reset if link is up.
3378 * If link reset is used when link is up, it might reset the PHY when
3379 * mng is using it. If link is down or the flag to force full link
3380 * reset is set, then perform link reset.
3381 */
3382 ctrl = IXGBE_CTRL_LNK_RST;
3383
3384 if (!hw->force_full_reset) {
3385 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3386 if (link_up)
3387 ctrl = IXGBE_CTRL_RST;
3388 }
3389
Paul Greenwalt61334062017-03-13 05:47:56 -04003390 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
3391 if (status) {
3392 hw_dbg(hw, "semaphore failed with %d", status);
3393 return IXGBE_ERR_SWFW_SYNC;
3394 }
3395
Don Skidmore6a14ee02014-12-05 03:59:50 +00003396 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
3397 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
3398 IXGBE_WRITE_FLUSH(hw);
Paul Greenwalt61334062017-03-13 05:47:56 -04003399 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
Mark Rustadefff2e02015-10-27 13:23:14 -07003400 usleep_range(1000, 1200);
Don Skidmore6a14ee02014-12-05 03:59:50 +00003401
3402 /* Poll for reset bit to self-clear meaning reset is complete */
3403 for (i = 0; i < 10; i++) {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003404 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
3405 if (!(ctrl & IXGBE_CTRL_RST_MASK))
3406 break;
Mark Rustadefff2e02015-10-27 13:23:14 -07003407 udelay(1);
Don Skidmore6a14ee02014-12-05 03:59:50 +00003408 }
3409
3410 if (ctrl & IXGBE_CTRL_RST_MASK) {
3411 status = IXGBE_ERR_RESET_FAILED;
3412 hw_dbg(hw, "Reset polling failed to complete.\n");
3413 }
3414
3415 msleep(50);
3416
3417 /* Double resets are required for recovery from certain error
3418 * clear the multicast table. Also reset num_rar_entries to 128,
3419 * since we modify this value when programming the SAN MAC address.
3420 */
3421 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
3422 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3423 goto mac_reset_top;
3424 }
3425
3426 /* Store the permanent mac address */
3427 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
3428
3429 /* Store MAC address from RAR0, clear receive address registers, and
3430 * clear the multicast table. Also reset num_rar_entries to 128,
3431 * since we modify this value when programming the SAN MAC address.
3432 */
3433 hw->mac.num_rar_entries = 128;
3434 hw->mac.ops.init_rx_addrs(hw);
3435
Mark Rustade84db722016-04-01 12:18:30 -07003436 ixgbe_set_mdio_speed(hw);
Don Skidmorededa5622015-06-09 17:39:46 -07003437
Don Skidmoreab5fe0c2015-06-09 16:18:56 -07003438 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
3439 ixgbe_setup_mux_ctl(hw);
3440
Don Skidmore6a14ee02014-12-05 03:59:50 +00003441 return status;
3442}
3443
Don Skidmore5b7f0002015-01-28 07:03:38 +00003444/** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype
3445 * anti-spoofing
3446 * @hw: pointer to hardware structure
3447 * @enable: enable or disable switch for Ethertype anti-spoofing
3448 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
3449 **/
Don Skidmorebc035fc2015-03-13 14:03:25 -07003450static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
3451 bool enable, int vf)
Don Skidmore5b7f0002015-01-28 07:03:38 +00003452{
3453 int vf_target_reg = vf >> 3;
3454 int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
3455 u32 pfvfspoof;
3456
3457 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3458 if (enable)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003459 pfvfspoof |= BIT(vf_target_shift);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003460 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003461 pfvfspoof &= ~BIT(vf_target_shift);
Don Skidmore5b7f0002015-01-28 07:03:38 +00003462
3463 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3464}
3465
Don Skidmore6d4c96a2015-04-09 22:03:23 -07003466/** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning
3467 * @hw: pointer to hardware structure
3468 * @enable: enable or disable source address pruning
3469 * @pool: Rx pool to set source address pruning for
3470 **/
3471static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw,
3472 bool enable,
3473 unsigned int pool)
3474{
3475 u64 pfflp;
3476
3477 /* max rx pool is 63 */
3478 if (pool > 63)
3479 return;
3480
3481 pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
3482 pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
3483
3484 if (enable)
3485 pfflp |= (1ULL << pool);
3486 else
3487 pfflp &= ~(1ULL << pool);
3488
3489 IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
3490 IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
3491}
3492
Mark Rustad449e21a2015-08-08 16:18:53 -07003493/**
Don Skidmore29165002016-09-27 14:31:12 -04003494 * ixgbe_setup_fc_backplane_x550em_a - Set up flow control
3495 * @hw: pointer to hardware structure
3496 *
3497 * Called at init time to set up flow control.
3498 **/
3499static s32 ixgbe_setup_fc_backplane_x550em_a(struct ixgbe_hw *hw)
3500{
3501 s32 status = 0;
Don Skidmore29165002016-09-27 14:31:12 -04003502 u32 an_cntl = 0;
3503
3504 /* Validate the requested mode */
3505 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
3506 hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
3507 return IXGBE_ERR_INVALID_LINK_SETTINGS;
3508 }
3509
3510 if (hw->fc.requested_mode == ixgbe_fc_default)
3511 hw->fc.requested_mode = ixgbe_fc_full;
3512
3513 /* Set up the 1G and 10G flow control advertisement registers so the
3514 * HW will be able to do FC autoneg once the cable is plugged in. If
3515 * we link at 10G, the 1G advertisement is harmless and vice versa.
3516 */
3517 status = hw->mac.ops.read_iosf_sb_reg(hw,
3518 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
3519 IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl);
3520
3521 if (status) {
3522 hw_dbg(hw, "Auto-Negotiation did not complete\n");
3523 return status;
3524 }
3525
3526 /* The possible values of fc.requested_mode are:
3527 * 0: Flow control is completely disabled
3528 * 1: Rx flow control is enabled (we can receive pause frames,
3529 * but not send pause frames).
3530 * 2: Tx flow control is enabled (we can send pause frames but
3531 * we do not support receiving pause frames).
3532 * 3: Both Rx and Tx flow control (symmetric) are enabled.
3533 * other: Invalid.
3534 */
3535 switch (hw->fc.requested_mode) {
3536 case ixgbe_fc_none:
3537 /* Flow control completely disabled by software override. */
3538 an_cntl &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
3539 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
3540 break;
3541 case ixgbe_fc_tx_pause:
3542 /* Tx Flow control is enabled, and Rx Flow control is
3543 * disabled by software override.
3544 */
3545 an_cntl |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
3546 an_cntl &= ~IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
3547 break;
3548 case ixgbe_fc_rx_pause:
3549 /* Rx Flow control is enabled and Tx Flow control is
3550 * disabled by software override. Since there really
3551 * isn't a way to advertise that we are capable of RX
3552 * Pause ONLY, we will advertise that we support both
3553 * symmetric and asymmetric Rx PAUSE, as such we fall
3554 * through to the fc_full statement. Later, we will
3555 * disable the adapter's ability to send PAUSE frames.
3556 */
3557 case ixgbe_fc_full:
3558 /* Flow control (both Rx and Tx) is enabled by SW override. */
3559 an_cntl |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
3560 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
3561 break;
3562 default:
3563 hw_err(hw, "Flow control param set incorrectly\n");
3564 return IXGBE_ERR_CONFIG;
3565 }
3566
3567 status = hw->mac.ops.write_iosf_sb_reg(hw,
3568 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
3569 IXGBE_SB_IOSF_TARGET_KR_PHY, an_cntl);
3570
3571 /* Restart auto-negotiation. */
Don Skidmore470739b2016-11-03 21:01:37 -04003572 status = ixgbe_restart_an_internal_phy_x550em(hw);
Don Skidmore29165002016-09-27 14:31:12 -04003573
3574 return status;
3575}
3576
3577/**
Mark Rustad449e21a2015-08-08 16:18:53 -07003578 * ixgbe_set_mux - Set mux for port 1 access with CS4227
3579 * @hw: pointer to hardware structure
3580 * @state: set mux if 1, clear if 0
3581 */
3582static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
3583{
3584 u32 esdp;
3585
3586 if (!hw->bus.lan_id)
3587 return;
3588 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3589 if (state)
3590 esdp |= IXGBE_ESDP_SDP1;
3591 else
3592 esdp &= ~IXGBE_ESDP_SDP1;
3593 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
3594 IXGBE_WRITE_FLUSH(hw);
3595}
3596
3597/**
3598 * ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
3599 * @hw: pointer to hardware structure
3600 * @mask: Mask to specify which semaphore to acquire
3601 *
3602 * Acquires the SWFW semaphore and sets the I2C MUX
3603 */
3604static s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
3605{
3606 s32 status;
3607
3608 status = ixgbe_acquire_swfw_sync_X540(hw, mask);
3609 if (status)
3610 return status;
3611
3612 if (mask & IXGBE_GSSR_I2C_MASK)
3613 ixgbe_set_mux(hw, 1);
3614
3615 return 0;
3616}
3617
3618/**
3619 * ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
3620 * @hw: pointer to hardware structure
3621 * @mask: Mask to specify which semaphore to release
3622 *
3623 * Releases the SWFW semaphore and sets the I2C MUX
3624 */
3625static void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
3626{
3627 if (mask & IXGBE_GSSR_I2C_MASK)
3628 ixgbe_set_mux(hw, 0);
3629
3630 ixgbe_release_swfw_sync_X540(hw, mask);
3631}
3632
Mark Rustad49425df2016-04-01 12:18:09 -07003633/**
3634 * ixgbe_acquire_swfw_sync_x550em_a - Acquire SWFW semaphore
3635 * @hw: pointer to hardware structure
3636 * @mask: Mask to specify which semaphore to acquire
3637 *
3638 * Acquires the SWFW semaphore and get the shared PHY token as needed
3639 */
3640static s32 ixgbe_acquire_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
3641{
3642 u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
3643 int retries = FW_PHY_TOKEN_RETRIES;
3644 s32 status;
3645
3646 while (--retries) {
3647 status = 0;
3648 if (hmask)
3649 status = ixgbe_acquire_swfw_sync_X540(hw, hmask);
3650 if (status)
3651 return status;
3652 if (!(mask & IXGBE_GSSR_TOKEN_SM))
3653 return 0;
3654
3655 status = ixgbe_get_phy_token(hw);
3656 if (!status)
3657 return 0;
3658 if (hmask)
3659 ixgbe_release_swfw_sync_X540(hw, hmask);
3660 if (status != IXGBE_ERR_TOKEN_RETRY)
3661 return status;
Arnd Bergmannd4f90d92016-04-16 22:35:08 +02003662 msleep(FW_PHY_TOKEN_DELAY);
Mark Rustad49425df2016-04-01 12:18:09 -07003663 }
3664
3665 return status;
3666}
3667
3668/**
3669 * ixgbe_release_swfw_sync_x550em_a - Release SWFW semaphore
3670 * @hw: pointer to hardware structure
3671 * @mask: Mask to specify which semaphore to release
3672 *
3673 * Release the SWFW semaphore and puts the shared PHY token as needed
3674 */
3675static void ixgbe_release_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
3676{
3677 u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
3678
3679 if (mask & IXGBE_GSSR_TOKEN_SM)
3680 ixgbe_put_phy_token(hw);
3681
3682 if (hmask)
3683 ixgbe_release_swfw_sync_X540(hw, hmask);
3684}
3685
Mark Rustadd31afc82016-04-01 12:18:14 -07003686/**
3687 * ixgbe_read_phy_reg_x550a - Reads specified PHY register
3688 * @hw: pointer to hardware structure
3689 * @reg_addr: 32 bit address of PHY register to read
3690 * @phy_data: Pointer to read data from PHY register
3691 *
3692 * Reads a value from a specified PHY register using the SWFW lock and PHY
3693 * Token. The PHY Token is needed since the MDIO is shared between to MAC
3694 * instances.
3695 */
3696static s32 ixgbe_read_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
3697 u32 device_type, u16 *phy_data)
3698{
3699 u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
3700 s32 status;
3701
3702 if (hw->mac.ops.acquire_swfw_sync(hw, mask))
3703 return IXGBE_ERR_SWFW_SYNC;
3704
3705 status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
3706
3707 hw->mac.ops.release_swfw_sync(hw, mask);
3708
3709 return status;
3710}
3711
3712/**
3713 * ixgbe_write_phy_reg_x550a - Writes specified PHY register
3714 * @hw: pointer to hardware structure
3715 * @reg_addr: 32 bit PHY register to write
3716 * @device_type: 5 bit device type
3717 * @phy_data: Data to write to the PHY register
3718 *
3719 * Writes a value to specified PHY register using the SWFW lock and PHY Token.
3720 * The PHY Token is needed since the MDIO is shared between to MAC instances.
3721 */
3722static s32 ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
3723 u32 device_type, u16 phy_data)
3724{
3725 u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
3726 s32 status;
3727
3728 if (hw->mac.ops.acquire_swfw_sync(hw, mask))
3729 return IXGBE_ERR_SWFW_SYNC;
3730
3731 status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type, phy_data);
3732 hw->mac.ops.release_swfw_sync(hw, mask);
3733
3734 return status;
3735}
3736
Don Skidmore6a14ee02014-12-05 03:59:50 +00003737#define X550_COMMON_MAC \
3738 .init_hw = &ixgbe_init_hw_generic, \
3739 .start_hw = &ixgbe_start_hw_X540, \
3740 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
3741 .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
3742 .get_mac_addr = &ixgbe_get_mac_addr_generic, \
3743 .get_device_caps = &ixgbe_get_device_caps_generic, \
3744 .stop_adapter = &ixgbe_stop_adapter_generic, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003745 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
3746 .read_analog_reg8 = NULL, \
3747 .write_analog_reg8 = NULL, \
3748 .set_rxpba = &ixgbe_set_rxpba_generic, \
3749 .check_link = &ixgbe_check_mac_link_generic, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003750 .blink_led_start = &ixgbe_blink_led_start_X540, \
3751 .blink_led_stop = &ixgbe_blink_led_stop_X540, \
3752 .set_rar = &ixgbe_set_rar_generic, \
3753 .clear_rar = &ixgbe_clear_rar_generic, \
3754 .set_vmdq = &ixgbe_set_vmdq_generic, \
3755 .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
3756 .clear_vmdq = &ixgbe_clear_vmdq_generic, \
3757 .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
3758 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
3759 .enable_mc = &ixgbe_enable_mc_generic, \
3760 .disable_mc = &ixgbe_disable_mc_generic, \
3761 .clear_vfta = &ixgbe_clear_vfta_generic, \
3762 .set_vfta = &ixgbe_set_vfta_generic, \
3763 .fc_enable = &ixgbe_fc_enable_generic, \
Tony Nguyencb8e0512016-10-26 16:25:18 -07003764 .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_x550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003765 .init_uta_tables = &ixgbe_init_uta_tables_generic, \
3766 .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
3767 .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
Don Skidmore6d4c96a2015-04-09 22:03:23 -07003768 .set_source_address_pruning = \
3769 &ixgbe_set_source_address_pruning_X550, \
Don Skidmore5b7f0002015-01-28 07:03:38 +00003770 .set_ethertype_anti_spoofing = \
3771 &ixgbe_set_ethertype_anti_spoofing_X550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003772 .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
3773 .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
3774 .get_thermal_sensor_data = NULL, \
3775 .init_thermal_sensor_thresh = NULL, \
Don Skidmore1f9ac572015-03-13 13:54:30 -07003776 .enable_rx = &ixgbe_enable_rx_generic, \
3777 .disable_rx = &ixgbe_disable_rx_x550, \
Don Skidmore6a14ee02014-12-05 03:59:50 +00003778
Mark Rustad37689012016-01-07 10:13:03 -08003779static const struct ixgbe_mac_operations mac_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003780 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04003781 .led_on = ixgbe_led_on_generic,
3782 .led_off = ixgbe_led_off_generic,
Don Skidmore805cedd2016-10-20 21:42:00 -04003783 .init_led_link_act = ixgbe_init_led_link_act_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003784 .reset_hw = &ixgbe_reset_hw_X540,
3785 .get_media_type = &ixgbe_get_media_type_X540,
3786 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
3787 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
3788 .setup_link = &ixgbe_setup_mac_link_X540,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003789 .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
Don Skidmore454c65d2015-06-17 20:59:59 -04003790 .get_bus_info = &ixgbe_get_bus_info_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003791 .setup_sfp = NULL,
Mark Rustad449e21a2015-08-08 16:18:53 -07003792 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
3793 .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
Don Skidmoredbd15b82016-03-09 16:45:00 -05003794 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
Mark Rustadafdc71e2016-01-25 16:32:10 -08003795 .prot_autoc_read = prot_autoc_read_generic,
3796 .prot_autoc_write = prot_autoc_write_generic,
3797 .setup_fc = ixgbe_setup_fc_generic,
Don Skidmore29165002016-09-27 14:31:12 -04003798 .fc_autoneg = ixgbe_fc_autoneg,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003799};
3800
Mark Rustad37689012016-01-07 10:13:03 -08003801static const struct ixgbe_mac_operations mac_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003802 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04003803 .led_on = ixgbe_led_on_t_x550em,
3804 .led_off = ixgbe_led_off_t_x550em,
Don Skidmore805cedd2016-10-20 21:42:00 -04003805 .init_led_link_act = ixgbe_init_led_link_act_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003806 .reset_hw = &ixgbe_reset_hw_X550em,
3807 .get_media_type = &ixgbe_get_media_type_X550em,
3808 .get_san_mac_addr = NULL,
3809 .get_wwn_prefix = NULL,
Emil Tantilov46958862016-03-24 09:58:40 -07003810 .setup_link = &ixgbe_setup_mac_link_X540,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003811 .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
Don Skidmore454c65d2015-06-17 20:59:59 -04003812 .get_bus_info = &ixgbe_get_bus_info_X550em,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003813 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
Mark Rustad449e21a2015-08-08 16:18:53 -07003814 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X550em,
3815 .release_swfw_sync = &ixgbe_release_swfw_sync_X550em,
Don Skidmoredbd15b82016-03-09 16:45:00 -05003816 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
Mark Rustadafdc71e2016-01-25 16:32:10 -08003817 .setup_fc = NULL, /* defined later */
Don Skidmore29165002016-09-27 14:31:12 -04003818 .fc_autoneg = ixgbe_fc_autoneg,
Mark Rustad9a5c27e2016-04-01 12:18:04 -07003819 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550,
3820 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003821};
3822
Paul Greenwalt5e999fb42017-04-21 05:37:13 -04003823static const struct ixgbe_mac_operations mac_ops_X550EM_x_fw = {
3824 X550_COMMON_MAC
3825 .led_on = NULL,
3826 .led_off = NULL,
3827 .init_led_link_act = NULL,
3828 .reset_hw = &ixgbe_reset_hw_X550em,
3829 .get_media_type = &ixgbe_get_media_type_X550em,
3830 .get_san_mac_addr = NULL,
3831 .get_wwn_prefix = NULL,
3832 .setup_link = &ixgbe_setup_mac_link_X540,
3833 .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
3834 .get_bus_info = &ixgbe_get_bus_info_X550em,
3835 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
3836 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X550em,
3837 .release_swfw_sync = &ixgbe_release_swfw_sync_X550em,
3838 .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
3839 .setup_fc = NULL,
3840 .fc_autoneg = ixgbe_fc_autoneg,
3841 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550,
3842 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550,
3843};
3844
Mark Rustad49425df2016-04-01 12:18:09 -07003845static struct ixgbe_mac_operations mac_ops_x550em_a = {
3846 X550_COMMON_MAC
Don Skidmorea0ad55a2016-08-17 14:11:57 -04003847 .led_on = ixgbe_led_on_t_x550em,
3848 .led_off = ixgbe_led_off_t_x550em,
Don Skidmore805cedd2016-10-20 21:42:00 -04003849 .init_led_link_act = ixgbe_init_led_link_act_generic,
Mark Rustad49425df2016-04-01 12:18:09 -07003850 .reset_hw = ixgbe_reset_hw_X550em,
3851 .get_media_type = ixgbe_get_media_type_X550em,
3852 .get_san_mac_addr = NULL,
3853 .get_wwn_prefix = NULL,
Emil Tantilov5b9d3cf2017-01-19 15:55:12 -08003854 .setup_link = &ixgbe_setup_mac_link_X540,
Mark Rustad49425df2016-04-01 12:18:09 -07003855 .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
3856 .get_bus_info = ixgbe_get_bus_info_X550em,
3857 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
3858 .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
3859 .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
Mark Rustada0254a72016-04-08 16:19:29 -07003860 .setup_fc = ixgbe_setup_fc_x550em,
Don Skidmore470739b2016-11-03 21:01:37 -04003861 .fc_autoneg = ixgbe_fc_autoneg,
Mark Rustad49425df2016-04-01 12:18:09 -07003862 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
3863 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
3864};
3865
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003866static struct ixgbe_mac_operations mac_ops_x550em_a_fw = {
3867 X550_COMMON_MAC
3868 .led_on = ixgbe_led_on_generic,
3869 .led_off = ixgbe_led_off_generic,
3870 .init_led_link_act = ixgbe_init_led_link_act_generic,
3871 .reset_hw = ixgbe_reset_hw_X550em,
3872 .get_media_type = ixgbe_get_media_type_X550em,
3873 .get_san_mac_addr = NULL,
3874 .get_wwn_prefix = NULL,
3875 .setup_link = NULL, /* defined later */
3876 .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
3877 .get_bus_info = ixgbe_get_bus_info_X550em,
3878 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
3879 .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
3880 .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
3881 .setup_fc = ixgbe_setup_fc_x550em,
3882 .fc_autoneg = ixgbe_fc_autoneg,
3883 .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
3884 .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
3885};
3886
Don Skidmore6a14ee02014-12-05 03:59:50 +00003887#define X550_COMMON_EEP \
3888 .read = &ixgbe_read_ee_hostif_X550, \
3889 .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
3890 .write = &ixgbe_write_ee_hostif_X550, \
3891 .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
3892 .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
3893 .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
3894 .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
3895
Mark Rustad37689012016-01-07 10:13:03 -08003896static const struct ixgbe_eeprom_operations eeprom_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003897 X550_COMMON_EEP
3898 .init_params = &ixgbe_init_eeprom_params_X550,
3899};
3900
Mark Rustad37689012016-01-07 10:13:03 -08003901static const struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003902 X550_COMMON_EEP
3903 .init_params = &ixgbe_init_eeprom_params_X540,
3904};
3905
3906#define X550_COMMON_PHY \
3907 .identify_sfp = &ixgbe_identify_module_generic, \
3908 .reset = NULL, \
3909 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
3910 .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
3911 .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
3912 .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
3913 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
3914 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
Don Skidmorebef23de2015-06-09 17:36:53 -07003915 .setup_link = &ixgbe_setup_phy_link_generic, \
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003916 .set_phy_power = NULL,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003917
Mark Rustad37689012016-01-07 10:13:03 -08003918static const struct ixgbe_phy_operations phy_ops_X550 = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003919 X550_COMMON_PHY
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003920 .check_overtemp = &ixgbe_tn_check_overtemp,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003921 .init = NULL,
3922 .identify = &ixgbe_identify_phy_generic,
Mark Rustadd31afc82016-04-01 12:18:14 -07003923 .read_reg = &ixgbe_read_phy_reg_generic,
3924 .write_reg = &ixgbe_write_phy_reg_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003925};
3926
Mark Rustad37689012016-01-07 10:13:03 -08003927static const struct ixgbe_phy_operations phy_ops_X550EM_x = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003928 X550_COMMON_PHY
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003929 .check_overtemp = &ixgbe_tn_check_overtemp,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003930 .init = &ixgbe_init_phy_ops_X550em,
3931 .identify = &ixgbe_identify_phy_x550em,
Mark Rustadd31afc82016-04-01 12:18:14 -07003932 .read_reg = &ixgbe_read_phy_reg_generic,
3933 .write_reg = &ixgbe_write_phy_reg_generic,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003934};
3935
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04003936static const struct ixgbe_phy_operations phy_ops_x550em_x_fw = {
3937 X550_COMMON_PHY
3938 .check_overtemp = NULL,
3939 .init = ixgbe_init_phy_ops_X550em,
3940 .identify = ixgbe_identify_phy_x550em,
3941 .read_reg = NULL,
3942 .write_reg = NULL,
3943 .read_reg_mdi = NULL,
3944 .write_reg_mdi = NULL,
3945};
3946
Mark Rustadd31afc82016-04-01 12:18:14 -07003947static const struct ixgbe_phy_operations phy_ops_x550em_a = {
3948 X550_COMMON_PHY
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003949 .check_overtemp = &ixgbe_tn_check_overtemp,
Mark Rustadd31afc82016-04-01 12:18:14 -07003950 .init = &ixgbe_init_phy_ops_X550em,
3951 .identify = &ixgbe_identify_phy_x550em,
3952 .read_reg = &ixgbe_read_phy_reg_x550a,
3953 .write_reg = &ixgbe_write_phy_reg_x550a,
Mark Rustad8fe293a2016-08-26 14:48:28 -07003954 .read_reg_mdi = &ixgbe_read_phy_reg_mdi,
3955 .write_reg_mdi = &ixgbe_write_phy_reg_mdi,
Mark Rustadd31afc82016-04-01 12:18:14 -07003956};
3957
Mark Rustadb3eb4e12016-12-14 11:02:16 -08003958static const struct ixgbe_phy_operations phy_ops_x550em_a_fw = {
3959 X550_COMMON_PHY
3960 .check_overtemp = ixgbe_check_overtemp_fw,
3961 .init = ixgbe_init_phy_ops_X550em,
3962 .identify = ixgbe_identify_phy_fw,
3963 .read_reg = NULL,
3964 .write_reg = NULL,
3965 .read_reg_mdi = NULL,
3966 .write_reg_mdi = NULL,
3967};
3968
Emil Tantilovb71f6c42016-10-10 14:54:03 -07003969static const struct ixgbe_link_operations link_ops_x550em_x = {
3970 .read_link = &ixgbe_read_i2c_combined_generic,
3971 .read_link_unlocked = &ixgbe_read_i2c_combined_generic_unlocked,
3972 .write_link = &ixgbe_write_i2c_combined_generic,
3973 .write_link_unlocked = &ixgbe_write_i2c_combined_generic_unlocked,
3974};
3975
Don Skidmore9a900ec2015-06-09 17:15:01 -07003976static const u32 ixgbe_mvals_X550[IXGBE_MVALS_IDX_LIMIT] = {
3977 IXGBE_MVALS_INIT(X550)
3978};
3979
3980static const u32 ixgbe_mvals_X550EM_x[IXGBE_MVALS_IDX_LIMIT] = {
3981 IXGBE_MVALS_INIT(X550EM_x)
3982};
3983
Mark Rustad49425df2016-04-01 12:18:09 -07003984static const u32 ixgbe_mvals_x550em_a[IXGBE_MVALS_IDX_LIMIT] = {
3985 IXGBE_MVALS_INIT(X550EM_a)
3986};
3987
Mark Rustad37689012016-01-07 10:13:03 -08003988const struct ixgbe_info ixgbe_X550_info = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003989 .mac = ixgbe_mac_X550,
3990 .get_invariants = &ixgbe_get_invariants_X540,
3991 .mac_ops = &mac_ops_X550,
3992 .eeprom_ops = &eeprom_ops_X550,
3993 .phy_ops = &phy_ops_X550,
3994 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07003995 .mvals = ixgbe_mvals_X550,
Don Skidmore6a14ee02014-12-05 03:59:50 +00003996};
3997
Mark Rustad37689012016-01-07 10:13:03 -08003998const struct ixgbe_info ixgbe_X550EM_x_info = {
Don Skidmore6a14ee02014-12-05 03:59:50 +00003999 .mac = ixgbe_mac_X550EM_x,
Don Skidmoreb5529ef2015-06-10 20:42:30 -04004000 .get_invariants = &ixgbe_get_invariants_X550_x,
Don Skidmore6a14ee02014-12-05 03:59:50 +00004001 .mac_ops = &mac_ops_X550EM_x,
4002 .eeprom_ops = &eeprom_ops_X550EM_x,
4003 .phy_ops = &phy_ops_X550EM_x,
4004 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07004005 .mvals = ixgbe_mvals_X550EM_x,
Emil Tantilovb71f6c42016-10-10 14:54:03 -07004006 .link_ops = &link_ops_x550em_x,
Don Skidmore6a14ee02014-12-05 03:59:50 +00004007};
Mark Rustad49425df2016-04-01 12:18:09 -07004008
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04004009const struct ixgbe_info ixgbe_x550em_x_fw_info = {
4010 .mac = ixgbe_mac_X550EM_x,
4011 .get_invariants = ixgbe_get_invariants_X550_x_fw,
Paul Greenwalt5e999fb42017-04-21 05:37:13 -04004012 .mac_ops = &mac_ops_X550EM_x_fw,
Paul Greenwalt8dc963e2017-04-13 08:07:07 -04004013 .eeprom_ops = &eeprom_ops_X550EM_x,
4014 .phy_ops = &phy_ops_x550em_x_fw,
4015 .mbx_ops = &mbx_ops_generic,
4016 .mvals = ixgbe_mvals_X550EM_x,
4017};
4018
Mark Rustad49425df2016-04-01 12:18:09 -07004019const struct ixgbe_info ixgbe_x550em_a_info = {
4020 .mac = ixgbe_mac_x550em_a,
Emil Tantilovb71f6c42016-10-10 14:54:03 -07004021 .get_invariants = &ixgbe_get_invariants_X550_a,
Mark Rustad49425df2016-04-01 12:18:09 -07004022 .mac_ops = &mac_ops_x550em_a,
4023 .eeprom_ops = &eeprom_ops_X550EM_x,
Mark Rustadd31afc82016-04-01 12:18:14 -07004024 .phy_ops = &phy_ops_x550em_a,
Mark Rustad49425df2016-04-01 12:18:09 -07004025 .mbx_ops = &mbx_ops_generic,
4026 .mvals = ixgbe_mvals_x550em_a,
4027};
Mark Rustadb3eb4e12016-12-14 11:02:16 -08004028
4029const struct ixgbe_info ixgbe_x550em_a_fw_info = {
4030 .mac = ixgbe_mac_x550em_a,
4031 .get_invariants = ixgbe_get_invariants_X550_a_fw,
4032 .mac_ops = &mac_ops_x550em_a_fw,
4033 .eeprom_ops = &eeprom_ops_X550EM_x,
4034 .phy_ops = &phy_ops_x550em_a_fw,
4035 .mbx_ops = &mbx_ops_generic,
4036 .mvals = ixgbe_mvals_x550em_a,
4037};