1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright(c) 2015, 2016 Intel Corporation.
6 #include <linux/firmware.h>
12 #define DEFAULT_PLATFORM_CONFIG_NAME "hfi1_platform.dat"
14 static int validate_scratch_checksum(struct hfi1_devdata
*dd
)
16 u64 checksum
= 0, temp_scratch
= 0;
19 temp_scratch
= read_csr(dd
, ASIC_CFG_SCRATCH
);
20 version
= (temp_scratch
& BITMAP_VERSION_SMASK
) >> BITMAP_VERSION_SHIFT
;
22 /* Prevent power on default of all zeroes from passing checksum */
24 dd_dev_err(dd
, "%s: Config bitmap uninitialized\n", __func__
);
26 "%s: Please update your BIOS to support active channels\n",
32 * ASIC scratch 0 only contains the checksum and bitmap version as
33 * fields of interest, both of which are handled separately from the
34 * loop below, so skip it
37 for (i
= 1; i
< ASIC_NUM_SCRATCH
; i
++) {
38 temp_scratch
= read_csr(dd
, ASIC_CFG_SCRATCH
+ (8 * i
));
39 for (j
= sizeof(u64
); j
!= 0; j
-= 2) {
40 checksum
+= (temp_scratch
& 0xFFFF);
45 while (checksum
>> 16)
46 checksum
= (checksum
& CHECKSUM_MASK
) + (checksum
>> 16);
48 temp_scratch
= read_csr(dd
, ASIC_CFG_SCRATCH
);
49 temp_scratch
&= CHECKSUM_SMASK
;
50 temp_scratch
>>= CHECKSUM_SHIFT
;
52 if (checksum
+ temp_scratch
== 0xFFFF)
55 dd_dev_err(dd
, "%s: Configuration bitmap corrupted\n", __func__
);
59 static void save_platform_config_fields(struct hfi1_devdata
*dd
)
61 struct hfi1_pportdata
*ppd
= dd
->pport
;
62 u64 temp_scratch
= 0, temp_dest
= 0;
64 temp_scratch
= read_csr(dd
, ASIC_CFG_SCRATCH_1
);
66 temp_dest
= temp_scratch
&
67 (dd
->hfi1_id
? PORT1_PORT_TYPE_SMASK
:
68 PORT0_PORT_TYPE_SMASK
);
69 ppd
->port_type
= temp_dest
>>
70 (dd
->hfi1_id
? PORT1_PORT_TYPE_SHIFT
:
71 PORT0_PORT_TYPE_SHIFT
);
73 temp_dest
= temp_scratch
&
74 (dd
->hfi1_id
? PORT1_LOCAL_ATTEN_SMASK
:
75 PORT0_LOCAL_ATTEN_SMASK
);
76 ppd
->local_atten
= temp_dest
>>
77 (dd
->hfi1_id
? PORT1_LOCAL_ATTEN_SHIFT
:
78 PORT0_LOCAL_ATTEN_SHIFT
);
80 temp_dest
= temp_scratch
&
81 (dd
->hfi1_id
? PORT1_REMOTE_ATTEN_SMASK
:
82 PORT0_REMOTE_ATTEN_SMASK
);
83 ppd
->remote_atten
= temp_dest
>>
84 (dd
->hfi1_id
? PORT1_REMOTE_ATTEN_SHIFT
:
85 PORT0_REMOTE_ATTEN_SHIFT
);
87 temp_dest
= temp_scratch
&
88 (dd
->hfi1_id
? PORT1_DEFAULT_ATTEN_SMASK
:
89 PORT0_DEFAULT_ATTEN_SMASK
);
90 ppd
->default_atten
= temp_dest
>>
91 (dd
->hfi1_id
? PORT1_DEFAULT_ATTEN_SHIFT
:
92 PORT0_DEFAULT_ATTEN_SHIFT
);
94 temp_scratch
= read_csr(dd
, dd
->hfi1_id
? ASIC_CFG_SCRATCH_3
:
97 ppd
->tx_preset_eq
= (temp_scratch
& TX_EQ_SMASK
) >> TX_EQ_SHIFT
;
98 ppd
->tx_preset_noeq
= (temp_scratch
& TX_NO_EQ_SMASK
) >> TX_NO_EQ_SHIFT
;
99 ppd
->rx_preset
= (temp_scratch
& RX_SMASK
) >> RX_SHIFT
;
101 ppd
->max_power_class
= (temp_scratch
& QSFP_MAX_POWER_SMASK
) >>
102 QSFP_MAX_POWER_SHIFT
;
104 ppd
->config_from_scratch
= true;
107 void get_platform_config(struct hfi1_devdata
*dd
)
110 u8
*temp_platform_config
= NULL
;
112 const struct firmware
*platform_config_file
= NULL
;
114 if (is_integrated(dd
)) {
115 if (validate_scratch_checksum(dd
)) {
116 save_platform_config_fields(dd
);
120 ret
= eprom_read_platform_config(dd
,
121 (void **)&temp_platform_config
,
125 dd
->platform_config
.data
= temp_platform_config
;
126 dd
->platform_config
.size
= esize
;
131 "%s: Failed to get platform config, falling back to sub-optimal default file\n",
134 ret
= request_firmware(&platform_config_file
,
135 DEFAULT_PLATFORM_CONFIG_NAME
,
139 "%s: No default platform config file found\n",
145 * Allocate separate memory block to store data and free firmware
146 * structure. This allows free_platform_config to treat EPROM and
147 * fallback configs in the same manner.
149 dd
->platform_config
.data
= kmemdup(platform_config_file
->data
,
150 platform_config_file
->size
,
152 dd
->platform_config
.size
= platform_config_file
->size
;
153 release_firmware(platform_config_file
);
156 void free_platform_config(struct hfi1_devdata
*dd
)
158 /* Release memory allocated for eprom or fallback file read. */
159 kfree(dd
->platform_config
.data
);
160 dd
->platform_config
.data
= NULL
;
163 void get_port_type(struct hfi1_pportdata
*ppd
)
168 ret
= get_platform_config_field(ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
169 PORT_TABLE_PORT_TYPE
, &temp
,
172 ppd
->port_type
= PORT_TYPE_UNKNOWN
;
175 ppd
->port_type
= temp
;
178 int set_qsfp_tx(struct hfi1_pportdata
*ppd
, int on
)
180 u8 tx_ctrl_byte
= on
? 0x0 : 0xF;
183 ret
= qsfp_write(ppd
, ppd
->dd
->hfi1_id
, QSFP_TX_CTRL_BYTE_OFFS
,
185 /* we expected 1, so consider 0 an error */
193 static int qual_power(struct hfi1_pportdata
*ppd
)
195 u32 cable_power_class
= 0, power_class_max
= 0;
196 u8
*cache
= ppd
->qsfp_info
.cache
;
199 ret
= get_platform_config_field(
200 ppd
->dd
, PLATFORM_CONFIG_SYSTEM_TABLE
, 0,
201 SYSTEM_TABLE_QSFP_POWER_CLASS_MAX
, &power_class_max
, 4);
205 cable_power_class
= get_qsfp_power_class(cache
[QSFP_MOD_PWR_OFFS
]);
207 if (cable_power_class
> power_class_max
)
208 ppd
->offline_disabled_reason
=
209 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY
);
211 if (ppd
->offline_disabled_reason
==
212 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY
)) {
215 "%s: Port disabled due to system power restrictions\n",
222 static int qual_bitrate(struct hfi1_pportdata
*ppd
)
224 u16 lss
= ppd
->link_speed_supported
, lse
= ppd
->link_speed_enabled
;
225 u8
*cache
= ppd
->qsfp_info
.cache
;
227 if ((lss
& OPA_LINK_SPEED_25G
) && (lse
& OPA_LINK_SPEED_25G
) &&
228 cache
[QSFP_NOM_BIT_RATE_250_OFFS
] < 0x64)
229 ppd
->offline_disabled_reason
=
230 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY
);
232 if ((lss
& OPA_LINK_SPEED_12_5G
) && (lse
& OPA_LINK_SPEED_12_5G
) &&
233 cache
[QSFP_NOM_BIT_RATE_100_OFFS
] < 0x7D)
234 ppd
->offline_disabled_reason
=
235 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY
);
237 if (ppd
->offline_disabled_reason
==
238 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY
)) {
241 "%s: Cable failed bitrate check, disabling port\n",
248 static int set_qsfp_high_power(struct hfi1_pportdata
*ppd
)
250 u8 cable_power_class
= 0, power_ctrl_byte
= 0;
251 u8
*cache
= ppd
->qsfp_info
.cache
;
254 cable_power_class
= get_qsfp_power_class(cache
[QSFP_MOD_PWR_OFFS
]);
256 if (cable_power_class
> QSFP_POWER_CLASS_1
) {
257 power_ctrl_byte
= cache
[QSFP_PWR_CTRL_BYTE_OFFS
];
259 power_ctrl_byte
|= 1;
260 power_ctrl_byte
&= ~(0x2);
262 ret
= qsfp_write(ppd
, ppd
->dd
->hfi1_id
,
263 QSFP_PWR_CTRL_BYTE_OFFS
,
264 &power_ctrl_byte
, 1);
268 if (cable_power_class
> QSFP_POWER_CLASS_4
) {
269 power_ctrl_byte
|= (1 << 2);
270 ret
= qsfp_write(ppd
, ppd
->dd
->hfi1_id
,
271 QSFP_PWR_CTRL_BYTE_OFFS
,
272 &power_ctrl_byte
, 1);
277 /* SFF 8679 rev 1.7 LPMode Deassert time */
283 static void apply_rx_cdr(struct hfi1_pportdata
*ppd
,
288 u8
*cache
= ppd
->qsfp_info
.cache
;
289 int cable_power_class
;
291 if (!((cache
[QSFP_MOD_PWR_OFFS
] & 0x4) &&
292 (cache
[QSFP_CDR_INFO_OFFS
] & 0x40)))
295 /* RX CDR present, bypass supported */
296 cable_power_class
= get_qsfp_power_class(cache
[QSFP_MOD_PWR_OFFS
]);
298 if (cable_power_class
<= QSFP_POWER_CLASS_3
) {
299 /* Power class <= 3, ignore config & turn RX CDR on */
300 *cdr_ctrl_byte
|= 0xF;
304 get_platform_config_field(
305 ppd
->dd
, PLATFORM_CONFIG_RX_PRESET_TABLE
,
306 rx_preset_index
, RX_PRESET_TABLE_QSFP_RX_CDR_APPLY
,
312 "%s: RX_CDR_APPLY is set to disabled\n",
316 get_platform_config_field(
317 ppd
->dd
, PLATFORM_CONFIG_RX_PRESET_TABLE
,
318 rx_preset_index
, RX_PRESET_TABLE_QSFP_RX_CDR
,
321 /* Expand cdr setting to all 4 lanes */
322 rx_preset
= (rx_preset
| (rx_preset
<< 1) |
323 (rx_preset
<< 2) | (rx_preset
<< 3));
326 *cdr_ctrl_byte
|= rx_preset
;
328 *cdr_ctrl_byte
&= rx_preset
;
329 /* Preserve current TX CDR status */
330 *cdr_ctrl_byte
|= (cache
[QSFP_CDR_CTRL_BYTE_OFFS
] & 0xF0);
334 static void apply_tx_cdr(struct hfi1_pportdata
*ppd
,
339 u8
*cache
= ppd
->qsfp_info
.cache
;
340 int cable_power_class
;
342 if (!((cache
[QSFP_MOD_PWR_OFFS
] & 0x8) &&
343 (cache
[QSFP_CDR_INFO_OFFS
] & 0x80)))
346 /* TX CDR present, bypass supported */
347 cable_power_class
= get_qsfp_power_class(cache
[QSFP_MOD_PWR_OFFS
]);
349 if (cable_power_class
<= QSFP_POWER_CLASS_3
) {
350 /* Power class <= 3, ignore config & turn TX CDR on */
351 *cdr_ctrl_byte
|= 0xF0;
355 get_platform_config_field(
357 PLATFORM_CONFIG_TX_PRESET_TABLE
, tx_preset_index
,
358 TX_PRESET_TABLE_QSFP_TX_CDR_APPLY
, &tx_preset
, 4);
363 "%s: TX_CDR_APPLY is set to disabled\n",
367 get_platform_config_field(
369 PLATFORM_CONFIG_TX_PRESET_TABLE
,
371 TX_PRESET_TABLE_QSFP_TX_CDR
, &tx_preset
, 4);
373 /* Expand cdr setting to all 4 lanes */
374 tx_preset
= (tx_preset
| (tx_preset
<< 1) |
375 (tx_preset
<< 2) | (tx_preset
<< 3));
378 *cdr_ctrl_byte
|= (tx_preset
<< 4);
380 /* Preserve current/determined RX CDR status */
381 *cdr_ctrl_byte
&= ((tx_preset
<< 4) | 0xF);
384 static void apply_cdr_settings(
385 struct hfi1_pportdata
*ppd
, u32 rx_preset_index
,
388 u8
*cache
= ppd
->qsfp_info
.cache
;
389 u8 cdr_ctrl_byte
= cache
[QSFP_CDR_CTRL_BYTE_OFFS
];
391 apply_rx_cdr(ppd
, rx_preset_index
, &cdr_ctrl_byte
);
393 apply_tx_cdr(ppd
, tx_preset_index
, &cdr_ctrl_byte
);
395 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, QSFP_CDR_CTRL_BYTE_OFFS
,
399 static void apply_tx_eq_auto(struct hfi1_pportdata
*ppd
)
401 u8
*cache
= ppd
->qsfp_info
.cache
;
404 if (!(cache
[QSFP_EQ_INFO_OFFS
] & 0x8))
406 /* Disable adaptive TX EQ if present */
407 tx_eq
= cache
[(128 * 3) + 241];
409 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 241, &tx_eq
, 1);
412 static void apply_tx_eq_prog(struct hfi1_pportdata
*ppd
, u32 tx_preset_index
)
414 u8
*cache
= ppd
->qsfp_info
.cache
;
418 if (!(cache
[QSFP_EQ_INFO_OFFS
] & 0x4))
421 get_platform_config_field(
422 ppd
->dd
, PLATFORM_CONFIG_TX_PRESET_TABLE
,
423 tx_preset_index
, TX_PRESET_TABLE_QSFP_TX_EQ_APPLY
,
428 "%s: TX_EQ_APPLY is set to disabled\n",
432 get_platform_config_field(
433 ppd
->dd
, PLATFORM_CONFIG_TX_PRESET_TABLE
,
434 tx_preset_index
, TX_PRESET_TABLE_QSFP_TX_EQ
,
437 if (((cache
[(128 * 3) + 224] & 0xF0) >> 4) < tx_preset
) {
440 "%s: TX EQ %x unsupported\n",
441 __func__
, tx_preset
);
445 "%s: Applying EQ %x\n",
446 __func__
, cache
[608] & 0xF0);
448 tx_preset
= (cache
[608] & 0xF0) >> 4;
451 tx_eq
= tx_preset
| (tx_preset
<< 4);
452 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 234, &tx_eq
, 1);
453 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 235, &tx_eq
, 1);
456 static void apply_rx_eq_emp(struct hfi1_pportdata
*ppd
, u32 rx_preset_index
)
459 u8 rx_eq
, *cache
= ppd
->qsfp_info
.cache
;
461 if (!(cache
[QSFP_EQ_INFO_OFFS
] & 0x2))
463 get_platform_config_field(
464 ppd
->dd
, PLATFORM_CONFIG_RX_PRESET_TABLE
,
465 rx_preset_index
, RX_PRESET_TABLE_QSFP_RX_EMP_APPLY
,
471 "%s: RX_EMP_APPLY is set to disabled\n",
475 get_platform_config_field(
476 ppd
->dd
, PLATFORM_CONFIG_RX_PRESET_TABLE
,
477 rx_preset_index
, RX_PRESET_TABLE_QSFP_RX_EMP
,
480 if ((cache
[(128 * 3) + 224] & 0xF) < rx_preset
) {
483 "%s: Requested RX EMP %x\n",
484 __func__
, rx_preset
);
488 "%s: Applying supported EMP %x\n",
489 __func__
, cache
[608] & 0xF);
491 rx_preset
= cache
[608] & 0xF;
494 rx_eq
= rx_preset
| (rx_preset
<< 4);
496 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 236, &rx_eq
, 1);
497 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 237, &rx_eq
, 1);
500 static void apply_eq_settings(struct hfi1_pportdata
*ppd
,
501 u32 rx_preset_index
, u32 tx_preset_index
)
503 u8
*cache
= ppd
->qsfp_info
.cache
;
505 /* no point going on w/o a page 3 */
508 "%s: Upper page 03 not present\n",
513 apply_tx_eq_auto(ppd
);
515 apply_tx_eq_prog(ppd
, tx_preset_index
);
517 apply_rx_eq_emp(ppd
, rx_preset_index
);
520 static void apply_rx_amplitude_settings(
521 struct hfi1_pportdata
*ppd
, u32 rx_preset_index
,
525 u8 rx_amp
= 0, i
= 0, preferred
= 0, *cache
= ppd
->qsfp_info
.cache
;
527 /* no point going on w/o a page 3 */
530 "%s: Upper page 03 not present\n",
534 if (!(cache
[QSFP_EQ_INFO_OFFS
] & 0x1)) {
536 "%s: RX_AMP_APPLY is set to disabled\n",
541 get_platform_config_field(ppd
->dd
,
542 PLATFORM_CONFIG_RX_PRESET_TABLE
,
544 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY
,
549 "%s: RX_AMP_APPLY is set to disabled\n",
553 get_platform_config_field(ppd
->dd
,
554 PLATFORM_CONFIG_RX_PRESET_TABLE
,
556 RX_PRESET_TABLE_QSFP_RX_AMP
,
560 "%s: Requested RX AMP %x\n",
564 for (i
= 0; i
< 4; i
++) {
565 if (cache
[(128 * 3) + 225] & (1 << i
)) {
567 if (preferred
== rx_preset
)
573 * Verify that preferred RX amplitude is not just a
574 * fall through of the default
576 if (!preferred
&& !(cache
[(128 * 3) + 225] & 0x1)) {
577 dd_dev_info(ppd
->dd
, "No supported RX AMP, not applying\n");
582 "%s: Applying RX AMP %x\n", __func__
, preferred
);
584 rx_amp
= preferred
| (preferred
<< 4);
585 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 238, &rx_amp
, 1);
586 qsfp_write(ppd
, ppd
->dd
->hfi1_id
, (256 * 3) + 239, &rx_amp
, 1);
589 #define OPA_INVALID_INDEX 0xFFF
591 static void apply_tx_lanes(struct hfi1_pportdata
*ppd
, u8 field_id
,
592 u32 config_data
, const char *message
)
597 for (i
= 0; i
< 4; i
++) {
598 ret
= load_8051_config(ppd
->dd
, field_id
, i
, config_data
);
599 if (ret
!= HCMD_SUCCESS
) {
602 "%s: %s for lane %u failed\n",
603 message
, __func__
, i
);
609 * Return a special SerDes setting for low power AOC cables. The power class
610 * threshold and setting being used were all found by empirical testing.
612 * Summary of the logic:
614 * if (QSFP and QSFP_TYPE == AOC and QSFP_POWER_CLASS < 4)
616 * return 0; // leave at default
618 static u8
aoc_low_power_setting(struct hfi1_pportdata
*ppd
)
620 u8
*cache
= ppd
->qsfp_info
.cache
;
624 if (ppd
->port_type
!= PORT_TYPE_QSFP
)
625 return 0; /* leave at default */
627 /* active optical cables only */
628 switch ((cache
[QSFP_MOD_TECH_OFFS
] & 0xF0) >> 4) {
629 case 0x0 ... 0x9: fallthrough
;
630 case 0xC: fallthrough
;
633 power_class
= get_qsfp_power_class(cache
[QSFP_MOD_PWR_OFFS
]);
634 if (power_class
< QSFP_POWER_CLASS_4
)
637 return 0; /* leave at default */
640 static void apply_tunings(
641 struct hfi1_pportdata
*ppd
, u32 tx_preset_index
,
642 u8 tuning_method
, u32 total_atten
, u8 limiting_active
)
645 u32 config_data
= 0, tx_preset
= 0;
646 u8 precur
= 0, attn
= 0, postcur
= 0, external_device_config
= 0;
647 u8
*cache
= ppd
->qsfp_info
.cache
;
649 /* Pass tuning method to 8051 */
650 read_8051_config(ppd
->dd
, LINK_TUNING_PARAMETERS
, GENERAL_CONFIG
,
652 config_data
&= ~(0xff << TUNING_METHOD_SHIFT
);
653 config_data
|= ((u32
)tuning_method
<< TUNING_METHOD_SHIFT
);
654 ret
= load_8051_config(ppd
->dd
, LINK_TUNING_PARAMETERS
, GENERAL_CONFIG
,
656 if (ret
!= HCMD_SUCCESS
)
657 dd_dev_err(ppd
->dd
, "%s: Failed to set tuning method\n",
660 /* Set same channel loss for both TX and RX */
661 config_data
= 0 | (total_atten
<< 16) | (total_atten
<< 24);
662 apply_tx_lanes(ppd
, CHANNEL_LOSS_SETTINGS
, config_data
,
663 "Setting channel loss");
665 /* Inform 8051 of cable capabilities */
666 if (ppd
->qsfp_info
.cache_valid
) {
667 external_device_config
=
668 ((cache
[QSFP_MOD_PWR_OFFS
] & 0x4) << 3) |
669 ((cache
[QSFP_MOD_PWR_OFFS
] & 0x8) << 2) |
670 ((cache
[QSFP_EQ_INFO_OFFS
] & 0x2) << 1) |
671 (cache
[QSFP_EQ_INFO_OFFS
] & 0x4);
672 ret
= read_8051_config(ppd
->dd
, DC_HOST_COMM_SETTINGS
,
673 GENERAL_CONFIG
, &config_data
);
674 /* Clear, then set the external device config field */
675 config_data
&= ~(u32
)0xFF;
676 config_data
|= external_device_config
;
677 ret
= load_8051_config(ppd
->dd
, DC_HOST_COMM_SETTINGS
,
678 GENERAL_CONFIG
, config_data
);
679 if (ret
!= HCMD_SUCCESS
)
681 "%s: Failed set ext device config params\n",
685 if (tx_preset_index
== OPA_INVALID_INDEX
) {
686 if (ppd
->port_type
== PORT_TYPE_QSFP
&& limiting_active
)
687 dd_dev_err(ppd
->dd
, "%s: Invalid Tx preset index\n",
692 /* Following for limiting active channels only */
693 get_platform_config_field(
694 ppd
->dd
, PLATFORM_CONFIG_TX_PRESET_TABLE
, tx_preset_index
,
695 TX_PRESET_TABLE_PRECUR
, &tx_preset
, 4);
698 get_platform_config_field(
699 ppd
->dd
, PLATFORM_CONFIG_TX_PRESET_TABLE
,
700 tx_preset_index
, TX_PRESET_TABLE_ATTN
, &tx_preset
, 4);
703 get_platform_config_field(
704 ppd
->dd
, PLATFORM_CONFIG_TX_PRESET_TABLE
,
705 tx_preset_index
, TX_PRESET_TABLE_POSTCUR
, &tx_preset
, 4);
710 * o The aoc_low_power_setting is applied to all lanes even
711 * though only lane 0's value is examined by the firmware.
712 * o A lingering low power setting after a cable swap does
713 * not occur. On cable unplug the 8051 is reset and
714 * restarted on cable insert. This resets all settings to
715 * their default, erasing any previous low power setting.
717 config_data
= precur
| (attn
<< 8) | (postcur
<< 16) |
718 (aoc_low_power_setting(ppd
) << 24);
720 apply_tx_lanes(ppd
, TX_EQ_SETTINGS
, config_data
,
721 "Applying TX settings");
724 /* Must be holding the QSFP i2c resource */
725 static int tune_active_qsfp(struct hfi1_pportdata
*ppd
, u32
*ptr_tx_preset
,
726 u32
*ptr_rx_preset
, u32
*ptr_total_atten
)
729 u16 lss
= ppd
->link_speed_supported
, lse
= ppd
->link_speed_enabled
;
730 u8
*cache
= ppd
->qsfp_info
.cache
;
732 ppd
->qsfp_info
.limiting_active
= 1;
734 ret
= set_qsfp_tx(ppd
, 0);
738 ret
= qual_power(ppd
);
742 ret
= qual_bitrate(ppd
);
747 * We'll change the QSFP memory contents from here on out, thus we set a
748 * flag here to remind ourselves to reset the QSFP module. This prevents
749 * reuse of stale settings established in our previous pass through.
751 if (ppd
->qsfp_info
.reset_needed
) {
752 ret
= reset_qsfp(ppd
);
755 refresh_qsfp_cache(ppd
, &ppd
->qsfp_info
);
757 ppd
->qsfp_info
.reset_needed
= 1;
760 ret
= set_qsfp_high_power(ppd
);
764 if (cache
[QSFP_EQ_INFO_OFFS
] & 0x4) {
765 ret
= get_platform_config_field(
767 PLATFORM_CONFIG_PORT_TABLE
, 0,
768 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ
,
771 *ptr_tx_preset
= OPA_INVALID_INDEX
;
775 ret
= get_platform_config_field(
777 PLATFORM_CONFIG_PORT_TABLE
, 0,
778 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ
,
781 *ptr_tx_preset
= OPA_INVALID_INDEX
;
786 ret
= get_platform_config_field(
787 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
788 PORT_TABLE_RX_PRESET_IDX
, ptr_rx_preset
, 4);
790 *ptr_rx_preset
= OPA_INVALID_INDEX
;
794 if ((lss
& OPA_LINK_SPEED_25G
) && (lse
& OPA_LINK_SPEED_25G
))
795 get_platform_config_field(
796 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
797 PORT_TABLE_LOCAL_ATTEN_25G
, ptr_total_atten
, 4);
798 else if ((lss
& OPA_LINK_SPEED_12_5G
) && (lse
& OPA_LINK_SPEED_12_5G
))
799 get_platform_config_field(
800 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
801 PORT_TABLE_LOCAL_ATTEN_12G
, ptr_total_atten
, 4);
803 apply_cdr_settings(ppd
, *ptr_rx_preset
, *ptr_tx_preset
);
805 apply_eq_settings(ppd
, *ptr_rx_preset
, *ptr_tx_preset
);
807 apply_rx_amplitude_settings(ppd
, *ptr_rx_preset
, *ptr_tx_preset
);
809 ret
= set_qsfp_tx(ppd
, 1);
814 static int tune_qsfp(struct hfi1_pportdata
*ppd
,
815 u32
*ptr_tx_preset
, u32
*ptr_rx_preset
,
816 u8
*ptr_tuning_method
, u32
*ptr_total_atten
)
818 u32 cable_atten
= 0, remote_atten
= 0, platform_atten
= 0;
819 u16 lss
= ppd
->link_speed_supported
, lse
= ppd
->link_speed_enabled
;
821 u8
*cache
= ppd
->qsfp_info
.cache
;
823 switch ((cache
[QSFP_MOD_TECH_OFFS
] & 0xF0) >> 4) {
825 ret
= get_platform_config_field(
827 PLATFORM_CONFIG_PORT_TABLE
, 0,
828 PORT_TABLE_LOCAL_ATTEN_25G
,
833 if ((lss
& OPA_LINK_SPEED_25G
) && (lse
& OPA_LINK_SPEED_25G
))
834 cable_atten
= cache
[QSFP_CU_ATTEN_12G_OFFS
];
835 else if ((lss
& OPA_LINK_SPEED_12_5G
) &&
836 (lse
& OPA_LINK_SPEED_12_5G
))
837 cable_atten
= cache
[QSFP_CU_ATTEN_7G_OFFS
];
839 /* Fallback to configured attenuation if cable memory is bad */
840 if (cable_atten
== 0 || cable_atten
> 36) {
841 ret
= get_platform_config_field(
843 PLATFORM_CONFIG_SYSTEM_TABLE
, 0,
844 SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G
,
850 ret
= get_platform_config_field(
851 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
852 PORT_TABLE_REMOTE_ATTEN_25G
, &remote_atten
, 4);
856 *ptr_total_atten
= platform_atten
+ cable_atten
+ remote_atten
;
858 *ptr_tuning_method
= OPA_PASSIVE_TUNING
;
860 case 0x0 ... 0x9: fallthrough
;
861 case 0xC: fallthrough
;
863 ret
= tune_active_qsfp(ppd
, ptr_tx_preset
, ptr_rx_preset
,
868 *ptr_tuning_method
= OPA_ACTIVE_TUNING
;
870 case 0xD: fallthrough
;
873 dd_dev_warn(ppd
->dd
, "%s: Unknown/unsupported cable\n",
881 * This function communicates its success or failure via ppd->driver_link_ready
882 * Thus, it depends on its association with start_link(...) which checks
883 * driver_link_ready before proceeding with the link negotiation and
884 * initialization process.
886 void tune_serdes(struct hfi1_pportdata
*ppd
)
890 u32 remote_atten
= 0, platform_atten
= 0;
891 u32 rx_preset_index
, tx_preset_index
;
892 u8 tuning_method
= 0, limiting_active
= 0;
893 struct hfi1_devdata
*dd
= ppd
->dd
;
895 rx_preset_index
= OPA_INVALID_INDEX
;
896 tx_preset_index
= OPA_INVALID_INDEX
;
898 /* the link defaults to enabled */
899 ppd
->link_enabled
= 1;
900 /* the driver link ready state defaults to not ready */
901 ppd
->driver_link_ready
= 0;
902 ppd
->offline_disabled_reason
= HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE
);
904 /* Skip the tuning for testing (loopback != none) and simulations */
905 if (loopback
!= LOOPBACK_NONE
||
906 ppd
->dd
->icode
== ICODE_FUNCTIONAL_SIMULATOR
) {
907 ppd
->driver_link_ready
= 1;
909 if (qsfp_mod_present(ppd
)) {
910 ret
= acquire_chip_resource(ppd
->dd
,
911 qsfp_resource(ppd
->dd
),
914 dd_dev_err(ppd
->dd
, "%s: hfi%d: cannot lock i2c chain\n",
915 __func__
, (int)ppd
->dd
->hfi1_id
);
919 refresh_qsfp_cache(ppd
, &ppd
->qsfp_info
);
920 release_chip_resource(ppd
->dd
, qsfp_resource(ppd
->dd
));
926 switch (ppd
->port_type
) {
927 case PORT_TYPE_DISCONNECTED
:
928 ppd
->offline_disabled_reason
=
929 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_DISCONNECTED
);
930 dd_dev_warn(dd
, "%s: Port disconnected, disabling port\n",
933 case PORT_TYPE_FIXED
:
934 /* platform_atten, remote_atten pre-zeroed to catch error */
935 get_platform_config_field(
936 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
937 PORT_TABLE_LOCAL_ATTEN_25G
, &platform_atten
, 4);
939 get_platform_config_field(
940 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
941 PORT_TABLE_REMOTE_ATTEN_25G
, &remote_atten
, 4);
943 total_atten
= platform_atten
+ remote_atten
;
945 tuning_method
= OPA_PASSIVE_TUNING
;
947 case PORT_TYPE_VARIABLE
:
948 if (qsfp_mod_present(ppd
)) {
950 * platform_atten, remote_atten pre-zeroed to
953 get_platform_config_field(
954 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
955 PORT_TABLE_LOCAL_ATTEN_25G
,
958 get_platform_config_field(
959 ppd
->dd
, PLATFORM_CONFIG_PORT_TABLE
, 0,
960 PORT_TABLE_REMOTE_ATTEN_25G
,
963 total_atten
= platform_atten
+ remote_atten
;
965 tuning_method
= OPA_PASSIVE_TUNING
;
967 ppd
->offline_disabled_reason
=
968 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_CHASSIS_CONFIG
);
973 if (qsfp_mod_present(ppd
)) {
974 ret
= acquire_chip_resource(ppd
->dd
,
975 qsfp_resource(ppd
->dd
),
978 dd_dev_err(ppd
->dd
, "%s: hfi%d: cannot lock i2c chain\n",
979 __func__
, (int)ppd
->dd
->hfi1_id
);
982 refresh_qsfp_cache(ppd
, &ppd
->qsfp_info
);
984 if (ppd
->qsfp_info
.cache_valid
) {
992 * We may have modified the QSFP memory, so
993 * update the cache to reflect the changes
995 refresh_qsfp_cache(ppd
, &ppd
->qsfp_info
);
997 ppd
->qsfp_info
.limiting_active
;
1000 "%s: Reading QSFP memory failed\n",
1002 ret
= -EINVAL
; /* a fail indication */
1004 release_chip_resource(ppd
->dd
, qsfp_resource(ppd
->dd
));
1008 ppd
->offline_disabled_reason
=
1010 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED
);
1015 dd_dev_warn(ppd
->dd
, "%s: Unknown port type\n", __func__
);
1016 ppd
->port_type
= PORT_TYPE_UNKNOWN
;
1017 tuning_method
= OPA_UNKNOWN_TUNING
;
1019 limiting_active
= 0;
1020 tx_preset_index
= OPA_INVALID_INDEX
;
1024 if (ppd
->offline_disabled_reason
==
1025 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE
))
1026 apply_tunings(ppd
, tx_preset_index
, tuning_method
,
1027 total_atten
, limiting_active
);
1030 ppd
->driver_link_ready
= 1;
1034 ppd
->driver_link_ready
= 0;