2 * Copyright(c) 2015, 2016 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 static int validate_scratch_checksum(struct hfi1_devdata *dd)
54 u64 checksum = 0, temp_scratch = 0;
57 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
58 version = (temp_scratch & BITMAP_VERSION_SMASK) >> BITMAP_VERSION_SHIFT;
60 /* Prevent power on default of all zeroes from passing checksum */
65 * ASIC scratch 0 only contains the checksum and bitmap version as
66 * fields of interest, both of which are handled separately from the
67 * loop below, so skip it
70 for (i = 1; i < ASIC_NUM_SCRATCH; i++) {
71 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH + (8 * i));
72 for (j = sizeof(u64); j != 0; j -= 2) {
73 checksum += (temp_scratch & 0xFFFF);
78 while (checksum >> 16)
79 checksum = (checksum & CHECKSUM_MASK) + (checksum >> 16);
81 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
82 temp_scratch &= CHECKSUM_SMASK;
83 temp_scratch >>= CHECKSUM_SHIFT;
85 if (checksum + temp_scratch == 0xFFFF)
90 static void save_platform_config_fields(struct hfi1_devdata *dd)
92 struct hfi1_pportdata *ppd = dd->pport;
93 u64 temp_scratch = 0, temp_dest = 0;
95 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH_1);
97 temp_dest = temp_scratch &
98 (dd->hfi1_id ? PORT1_PORT_TYPE_SMASK :
99 PORT0_PORT_TYPE_SMASK);
100 ppd->port_type = temp_dest >>
101 (dd->hfi1_id ? PORT1_PORT_TYPE_SHIFT :
102 PORT0_PORT_TYPE_SHIFT);
104 temp_dest = temp_scratch &
105 (dd->hfi1_id ? PORT1_LOCAL_ATTEN_SMASK :
106 PORT0_LOCAL_ATTEN_SMASK);
107 ppd->local_atten = temp_dest >>
108 (dd->hfi1_id ? PORT1_LOCAL_ATTEN_SHIFT :
109 PORT0_LOCAL_ATTEN_SHIFT);
111 temp_dest = temp_scratch &
112 (dd->hfi1_id ? PORT1_REMOTE_ATTEN_SMASK :
113 PORT0_REMOTE_ATTEN_SMASK);
114 ppd->remote_atten = temp_dest >>
115 (dd->hfi1_id ? PORT1_REMOTE_ATTEN_SHIFT :
116 PORT0_REMOTE_ATTEN_SHIFT);
118 temp_dest = temp_scratch &
119 (dd->hfi1_id ? PORT1_DEFAULT_ATTEN_SMASK :
120 PORT0_DEFAULT_ATTEN_SMASK);
121 ppd->default_atten = temp_dest >>
122 (dd->hfi1_id ? PORT1_DEFAULT_ATTEN_SHIFT :
123 PORT0_DEFAULT_ATTEN_SHIFT);
125 temp_scratch = read_csr(dd, dd->hfi1_id ? ASIC_CFG_SCRATCH_3 :
128 ppd->tx_preset_eq = (temp_scratch & TX_EQ_SMASK) >> TX_EQ_SHIFT;
129 ppd->tx_preset_noeq = (temp_scratch & TX_NO_EQ_SMASK) >> TX_NO_EQ_SHIFT;
130 ppd->rx_preset = (temp_scratch & RX_SMASK) >> RX_SHIFT;
132 ppd->max_power_class = (temp_scratch & QSFP_MAX_POWER_SMASK) >>
133 QSFP_MAX_POWER_SHIFT;
136 void get_platform_config(struct hfi1_devdata *dd)
139 unsigned long size = 0;
140 u8 *temp_platform_config = NULL;
143 if (is_integrated(dd)) {
144 if (validate_scratch_checksum(dd)) {
145 save_platform_config_fields(dd);
148 dd_dev_err(dd, "%s: Config bitmap corrupted/uninitialized\n",
151 "%s: Please update your BIOS to support active channels\n",
154 ret = eprom_read_platform_config(dd,
155 (void **)&temp_platform_config,
159 dd->platform_config.data = temp_platform_config;
160 dd->platform_config.size = esize;
163 /* fail, try EFI variable */
165 ret = read_hfi1_efi_var(dd, "configuration", &size,
166 (void **)&temp_platform_config);
168 dd->platform_config.data = temp_platform_config;
169 dd->platform_config.size = size;
174 "%s: Failed to get platform config, falling back to sub-optimal default file\n",
176 /* fall back to request firmware */
177 platform_config_load = 1;
180 void free_platform_config(struct hfi1_devdata *dd)
182 if (!platform_config_load) {
184 * was loaded from EFI or the EPROM, release memory
185 * allocated by read_efi_var/eprom_read_platform_config
187 kfree(dd->platform_config.data);
190 * else do nothing, dispose_firmware will release
191 * struct firmware platform_config on driver exit
195 void get_port_type(struct hfi1_pportdata *ppd)
200 ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
201 PORT_TABLE_PORT_TYPE, &temp,
204 ppd->port_type = PORT_TYPE_UNKNOWN;
207 ppd->port_type = temp;
210 int set_qsfp_tx(struct hfi1_pportdata *ppd, int on)
212 u8 tx_ctrl_byte = on ? 0x0 : 0xF;
215 ret = qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_TX_CTRL_BYTE_OFFS,
217 /* we expected 1, so consider 0 an error */
225 static int qual_power(struct hfi1_pportdata *ppd)
227 u32 cable_power_class = 0, power_class_max = 0;
228 u8 *cache = ppd->qsfp_info.cache;
231 ret = get_platform_config_field(
232 ppd->dd, PLATFORM_CONFIG_SYSTEM_TABLE, 0,
233 SYSTEM_TABLE_QSFP_POWER_CLASS_MAX, &power_class_max, 4);
237 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
239 if (cable_power_class > power_class_max)
240 ppd->offline_disabled_reason =
241 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY);
243 if (ppd->offline_disabled_reason ==
244 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY)) {
247 "%s: Port disabled due to system power restrictions\n",
254 static int qual_bitrate(struct hfi1_pportdata *ppd)
256 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
257 u8 *cache = ppd->qsfp_info.cache;
259 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G) &&
260 cache[QSFP_NOM_BIT_RATE_250_OFFS] < 0x64)
261 ppd->offline_disabled_reason =
262 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
264 if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G) &&
265 cache[QSFP_NOM_BIT_RATE_100_OFFS] < 0x7D)
266 ppd->offline_disabled_reason =
267 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
269 if (ppd->offline_disabled_reason ==
270 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY)) {
273 "%s: Cable failed bitrate check, disabling port\n",
280 static int set_qsfp_high_power(struct hfi1_pportdata *ppd)
282 u8 cable_power_class = 0, power_ctrl_byte = 0;
283 u8 *cache = ppd->qsfp_info.cache;
286 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
288 if (cable_power_class > QSFP_POWER_CLASS_1) {
289 power_ctrl_byte = cache[QSFP_PWR_CTRL_BYTE_OFFS];
291 power_ctrl_byte |= 1;
292 power_ctrl_byte &= ~(0x2);
294 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
295 QSFP_PWR_CTRL_BYTE_OFFS,
296 &power_ctrl_byte, 1);
300 if (cable_power_class > QSFP_POWER_CLASS_4) {
301 power_ctrl_byte |= (1 << 2);
302 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
303 QSFP_PWR_CTRL_BYTE_OFFS,
304 &power_ctrl_byte, 1);
309 /* SFF 8679 rev 1.7 LPMode Deassert time */
315 static void apply_rx_cdr(struct hfi1_pportdata *ppd,
320 u8 *cache = ppd->qsfp_info.cache;
321 int cable_power_class;
323 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x4) &&
324 (cache[QSFP_CDR_INFO_OFFS] & 0x40)))
327 /* RX CDR present, bypass supported */
328 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
330 if (cable_power_class <= QSFP_POWER_CLASS_3) {
331 /* Power class <= 3, ignore config & turn RX CDR on */
332 *cdr_ctrl_byte |= 0xF;
336 get_platform_config_field(
337 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
338 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR_APPLY,
344 "%s: RX_CDR_APPLY is set to disabled\n",
348 get_platform_config_field(
349 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
350 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR,
353 /* Expand cdr setting to all 4 lanes */
354 rx_preset = (rx_preset | (rx_preset << 1) |
355 (rx_preset << 2) | (rx_preset << 3));
358 *cdr_ctrl_byte |= rx_preset;
360 *cdr_ctrl_byte &= rx_preset;
361 /* Preserve current TX CDR status */
362 *cdr_ctrl_byte |= (cache[QSFP_CDR_CTRL_BYTE_OFFS] & 0xF0);
366 static void apply_tx_cdr(struct hfi1_pportdata *ppd,
371 u8 *cache = ppd->qsfp_info.cache;
372 int cable_power_class;
374 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x8) &&
375 (cache[QSFP_CDR_INFO_OFFS] & 0x80)))
378 /* TX CDR present, bypass supported */
379 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
381 if (cable_power_class <= QSFP_POWER_CLASS_3) {
382 /* Power class <= 3, ignore config & turn TX CDR on */
383 *cdr_ctrl_byte |= 0xF0;
387 get_platform_config_field(
389 PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
390 TX_PRESET_TABLE_QSFP_TX_CDR_APPLY, &tx_preset, 4);
395 "%s: TX_CDR_APPLY is set to disabled\n",
399 get_platform_config_field(
401 PLATFORM_CONFIG_TX_PRESET_TABLE,
403 TX_PRESET_TABLE_QSFP_TX_CDR, &tx_preset, 4);
405 /* Expand cdr setting to all 4 lanes */
406 tx_preset = (tx_preset | (tx_preset << 1) |
407 (tx_preset << 2) | (tx_preset << 3));
410 *cdr_ctrl_byte |= (tx_preset << 4);
412 /* Preserve current/determined RX CDR status */
413 *cdr_ctrl_byte &= ((tx_preset << 4) | 0xF);
416 static void apply_cdr_settings(
417 struct hfi1_pportdata *ppd, u32 rx_preset_index,
420 u8 *cache = ppd->qsfp_info.cache;
421 u8 cdr_ctrl_byte = cache[QSFP_CDR_CTRL_BYTE_OFFS];
423 apply_rx_cdr(ppd, rx_preset_index, &cdr_ctrl_byte);
425 apply_tx_cdr(ppd, tx_preset_index, &cdr_ctrl_byte);
427 qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_CDR_CTRL_BYTE_OFFS,
431 static void apply_tx_eq_auto(struct hfi1_pportdata *ppd)
433 u8 *cache = ppd->qsfp_info.cache;
436 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x8))
438 /* Disable adaptive TX EQ if present */
439 tx_eq = cache[(128 * 3) + 241];
441 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 241, &tx_eq, 1);
444 static void apply_tx_eq_prog(struct hfi1_pportdata *ppd, u32 tx_preset_index)
446 u8 *cache = ppd->qsfp_info.cache;
450 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x4))
453 get_platform_config_field(
454 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
455 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ_APPLY,
460 "%s: TX_EQ_APPLY is set to disabled\n",
464 get_platform_config_field(
465 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
466 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ,
469 if (((cache[(128 * 3) + 224] & 0xF0) >> 4) < tx_preset) {
472 "%s: TX EQ %x unsupported\n",
473 __func__, tx_preset);
477 "%s: Applying EQ %x\n",
478 __func__, cache[608] & 0xF0);
480 tx_preset = (cache[608] & 0xF0) >> 4;
483 tx_eq = tx_preset | (tx_preset << 4);
484 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 234, &tx_eq, 1);
485 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 235, &tx_eq, 1);
488 static void apply_rx_eq_emp(struct hfi1_pportdata *ppd, u32 rx_preset_index)
491 u8 rx_eq, *cache = ppd->qsfp_info.cache;
493 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x2))
495 get_platform_config_field(
496 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
497 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP_APPLY,
503 "%s: RX_EMP_APPLY is set to disabled\n",
507 get_platform_config_field(
508 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
509 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP,
512 if ((cache[(128 * 3) + 224] & 0xF) < rx_preset) {
515 "%s: Requested RX EMP %x\n",
516 __func__, rx_preset);
520 "%s: Applying supported EMP %x\n",
521 __func__, cache[608] & 0xF);
523 rx_preset = cache[608] & 0xF;
526 rx_eq = rx_preset | (rx_preset << 4);
528 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 236, &rx_eq, 1);
529 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 237, &rx_eq, 1);
532 static void apply_eq_settings(struct hfi1_pportdata *ppd,
533 u32 rx_preset_index, u32 tx_preset_index)
535 u8 *cache = ppd->qsfp_info.cache;
537 /* no point going on w/o a page 3 */
540 "%s: Upper page 03 not present\n",
545 apply_tx_eq_auto(ppd);
547 apply_tx_eq_prog(ppd, tx_preset_index);
549 apply_rx_eq_emp(ppd, rx_preset_index);
552 static void apply_rx_amplitude_settings(
553 struct hfi1_pportdata *ppd, u32 rx_preset_index,
557 u8 rx_amp = 0, i = 0, preferred = 0, *cache = ppd->qsfp_info.cache;
559 /* no point going on w/o a page 3 */
562 "%s: Upper page 03 not present\n",
566 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x1)) {
568 "%s: RX_AMP_APPLY is set to disabled\n",
573 get_platform_config_field(ppd->dd,
574 PLATFORM_CONFIG_RX_PRESET_TABLE,
576 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY,
581 "%s: RX_AMP_APPLY is set to disabled\n",
585 get_platform_config_field(ppd->dd,
586 PLATFORM_CONFIG_RX_PRESET_TABLE,
588 RX_PRESET_TABLE_QSFP_RX_AMP,
592 "%s: Requested RX AMP %x\n",
596 for (i = 0; i < 4; i++) {
597 if (cache[(128 * 3) + 225] & (1 << i)) {
599 if (preferred == rx_preset)
605 * Verify that preferred RX amplitude is not just a
606 * fall through of the default
608 if (!preferred && !(cache[(128 * 3) + 225] & 0x1)) {
609 dd_dev_info(ppd->dd, "No supported RX AMP, not applying\n");
614 "%s: Applying RX AMP %x\n", __func__, preferred);
616 rx_amp = preferred | (preferred << 4);
617 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 238, &rx_amp, 1);
618 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 239, &rx_amp, 1);
621 #define OPA_INVALID_INDEX 0xFFF
623 static void apply_tx_lanes(struct hfi1_pportdata *ppd, u8 field_id,
624 u32 config_data, const char *message)
627 int ret = HCMD_SUCCESS;
629 for (i = 0; i < 4; i++) {
630 ret = load_8051_config(ppd->dd, field_id, i, config_data);
631 if (ret != HCMD_SUCCESS) {
634 "%s: %s for lane %u failed\n",
635 message, __func__, i);
641 * Return a special SerDes setting for low power AOC cables. The power class
642 * threshold and setting being used were all found by empirical testing.
644 * Summary of the logic:
646 * if (QSFP and QSFP_TYPE == AOC and QSFP_POWER_CLASS < 4)
648 * return 0; // leave at default
650 static u8 aoc_low_power_setting(struct hfi1_pportdata *ppd)
652 u8 *cache = ppd->qsfp_info.cache;
656 if (ppd->port_type != PORT_TYPE_QSFP)
657 return 0; /* leave at default */
659 /* active optical cables only */
660 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
661 case 0x0 ... 0x9: /* fallthrough */
662 case 0xC: /* fallthrough */
665 power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
666 if (power_class < QSFP_POWER_CLASS_4)
669 return 0; /* leave at default */
672 static void apply_tunings(
673 struct hfi1_pportdata *ppd, u32 tx_preset_index,
674 u8 tuning_method, u32 total_atten, u8 limiting_active)
677 u32 config_data = 0, tx_preset = 0;
678 u8 precur = 0, attn = 0, postcur = 0, external_device_config = 0;
679 u8 *cache = ppd->qsfp_info.cache;
681 /* Pass tuning method to 8051 */
682 read_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
684 config_data &= ~(0xff << TUNING_METHOD_SHIFT);
685 config_data |= ((u32)tuning_method << TUNING_METHOD_SHIFT);
686 ret = load_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
688 if (ret != HCMD_SUCCESS)
689 dd_dev_err(ppd->dd, "%s: Failed to set tuning method\n",
692 /* Set same channel loss for both TX and RX */
693 config_data = 0 | (total_atten << 16) | (total_atten << 24);
694 apply_tx_lanes(ppd, CHANNEL_LOSS_SETTINGS, config_data,
695 "Setting channel loss");
697 /* Inform 8051 of cable capabilities */
698 if (ppd->qsfp_info.cache_valid) {
699 external_device_config =
700 ((cache[QSFP_MOD_PWR_OFFS] & 0x4) << 3) |
701 ((cache[QSFP_MOD_PWR_OFFS] & 0x8) << 2) |
702 ((cache[QSFP_EQ_INFO_OFFS] & 0x2) << 1) |
703 (cache[QSFP_EQ_INFO_OFFS] & 0x4);
704 ret = read_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
705 GENERAL_CONFIG, &config_data);
706 /* Clear, then set the external device config field */
707 config_data &= ~(u32)0xFF;
708 config_data |= external_device_config;
709 ret = load_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
710 GENERAL_CONFIG, config_data);
711 if (ret != HCMD_SUCCESS)
713 "%s: Failed set ext device config params\n",
717 if (tx_preset_index == OPA_INVALID_INDEX) {
718 if (ppd->port_type == PORT_TYPE_QSFP && limiting_active)
719 dd_dev_info(ppd->dd, "%s: Invalid Tx preset index\n",
724 /* Following for limiting active channels only */
725 get_platform_config_field(
726 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
727 TX_PRESET_TABLE_PRECUR, &tx_preset, 4);
730 get_platform_config_field(
731 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
732 tx_preset_index, TX_PRESET_TABLE_ATTN, &tx_preset, 4);
735 get_platform_config_field(
736 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
737 tx_preset_index, TX_PRESET_TABLE_POSTCUR, &tx_preset, 4);
742 * o The aoc_low_power_setting is applied to all lanes even
743 * though only lane 0's value is examined by the firmware.
744 * o A lingering low power setting after a cable swap does
745 * not occur. On cable unplug the 8051 is reset and
746 * restarted on cable insert. This resets all settings to
747 * their default, erasing any previous low power setting.
749 config_data = precur | (attn << 8) | (postcur << 16) |
750 (aoc_low_power_setting(ppd) << 24);
752 apply_tx_lanes(ppd, TX_EQ_SETTINGS, config_data,
753 "Applying TX settings");
756 /* Must be holding the QSFP i2c resource */
757 static int tune_active_qsfp(struct hfi1_pportdata *ppd, u32 *ptr_tx_preset,
758 u32 *ptr_rx_preset, u32 *ptr_total_atten)
761 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
762 u8 *cache = ppd->qsfp_info.cache;
764 ppd->qsfp_info.limiting_active = 1;
766 ret = set_qsfp_tx(ppd, 0);
770 ret = qual_power(ppd);
774 ret = qual_bitrate(ppd);
779 * We'll change the QSFP memory contents from here on out, thus we set a
780 * flag here to remind ourselves to reset the QSFP module. This prevents
781 * reuse of stale settings established in our previous pass through.
783 if (ppd->qsfp_info.reset_needed) {
785 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
787 ppd->qsfp_info.reset_needed = 1;
790 ret = set_qsfp_high_power(ppd);
794 if (cache[QSFP_EQ_INFO_OFFS] & 0x4) {
795 ret = get_platform_config_field(
797 PLATFORM_CONFIG_PORT_TABLE, 0,
798 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ,
801 *ptr_tx_preset = OPA_INVALID_INDEX;
805 ret = get_platform_config_field(
807 PLATFORM_CONFIG_PORT_TABLE, 0,
808 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ,
811 *ptr_tx_preset = OPA_INVALID_INDEX;
816 ret = get_platform_config_field(
817 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
818 PORT_TABLE_RX_PRESET_IDX, ptr_rx_preset, 4);
820 *ptr_rx_preset = OPA_INVALID_INDEX;
824 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
825 get_platform_config_field(
826 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
827 PORT_TABLE_LOCAL_ATTEN_25G, ptr_total_atten, 4);
828 else if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G))
829 get_platform_config_field(
830 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
831 PORT_TABLE_LOCAL_ATTEN_12G, ptr_total_atten, 4);
833 apply_cdr_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
835 apply_eq_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
837 apply_rx_amplitude_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
839 ret = set_qsfp_tx(ppd, 1);
844 static int tune_qsfp(struct hfi1_pportdata *ppd,
845 u32 *ptr_tx_preset, u32 *ptr_rx_preset,
846 u8 *ptr_tuning_method, u32 *ptr_total_atten)
848 u32 cable_atten = 0, remote_atten = 0, platform_atten = 0;
849 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
851 u8 *cache = ppd->qsfp_info.cache;
853 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
855 ret = get_platform_config_field(
857 PLATFORM_CONFIG_PORT_TABLE, 0,
858 PORT_TABLE_LOCAL_ATTEN_25G,
863 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
864 cable_atten = cache[QSFP_CU_ATTEN_12G_OFFS];
865 else if ((lss & OPA_LINK_SPEED_12_5G) &&
866 (lse & OPA_LINK_SPEED_12_5G))
867 cable_atten = cache[QSFP_CU_ATTEN_7G_OFFS];
869 /* Fallback to configured attenuation if cable memory is bad */
870 if (cable_atten == 0 || cable_atten > 36) {
871 ret = get_platform_config_field(
873 PLATFORM_CONFIG_SYSTEM_TABLE, 0,
874 SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G,
880 ret = get_platform_config_field(
881 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
882 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
886 *ptr_total_atten = platform_atten + cable_atten + remote_atten;
888 *ptr_tuning_method = OPA_PASSIVE_TUNING;
890 case 0x0 ... 0x9: /* fallthrough */
891 case 0xC: /* fallthrough */
893 ret = tune_active_qsfp(ppd, ptr_tx_preset, ptr_rx_preset,
898 *ptr_tuning_method = OPA_ACTIVE_TUNING;
900 case 0xD: /* fallthrough */
903 dd_dev_info(ppd->dd, "%s: Unknown/unsupported cable\n",
911 * This function communicates its success or failure via ppd->driver_link_ready
912 * Thus, it depends on its association with start_link(...) which checks
913 * driver_link_ready before proceeding with the link negotiation and
914 * initialization process.
916 void tune_serdes(struct hfi1_pportdata *ppd)
920 u32 remote_atten = 0, platform_atten = 0;
921 u32 rx_preset_index, tx_preset_index;
922 u8 tuning_method = 0, limiting_active = 0;
923 struct hfi1_devdata *dd = ppd->dd;
925 rx_preset_index = OPA_INVALID_INDEX;
926 tx_preset_index = OPA_INVALID_INDEX;
928 /* the link defaults to enabled */
929 ppd->link_enabled = 1;
930 /* the driver link ready state defaults to not ready */
931 ppd->driver_link_ready = 0;
932 ppd->offline_disabled_reason = HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
934 /* Skip the tuning for testing (loopback != none) and simulations */
935 if (loopback != LOOPBACK_NONE ||
936 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
937 ppd->driver_link_ready = 1;
941 switch (ppd->port_type) {
942 case PORT_TYPE_DISCONNECTED:
943 ppd->offline_disabled_reason =
944 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_DISCONNECTED);
945 dd_dev_info(dd, "%s: Port disconnected, disabling port\n",
948 case PORT_TYPE_FIXED:
949 /* platform_atten, remote_atten pre-zeroed to catch error */
950 get_platform_config_field(
951 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
952 PORT_TABLE_LOCAL_ATTEN_25G, &platform_atten, 4);
954 get_platform_config_field(
955 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
956 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
958 total_atten = platform_atten + remote_atten;
960 tuning_method = OPA_PASSIVE_TUNING;
962 case PORT_TYPE_VARIABLE:
963 if (qsfp_mod_present(ppd)) {
965 * platform_atten, remote_atten pre-zeroed to
968 get_platform_config_field(
969 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
970 PORT_TABLE_LOCAL_ATTEN_25G,
973 get_platform_config_field(
974 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
975 PORT_TABLE_REMOTE_ATTEN_25G,
978 total_atten = platform_atten + remote_atten;
980 tuning_method = OPA_PASSIVE_TUNING;
982 ppd->offline_disabled_reason =
983 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_CHASSIS_CONFIG);
988 if (qsfp_mod_present(ppd)) {
989 ret = acquire_chip_resource(ppd->dd,
990 qsfp_resource(ppd->dd),
993 dd_dev_err(ppd->dd, "%s: hfi%d: cannot lock i2c chain\n",
994 __func__, (int)ppd->dd->hfi1_id);
997 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
999 if (ppd->qsfp_info.cache_valid) {
1000 ret = tune_qsfp(ppd,
1007 * We may have modified the QSFP memory, so
1008 * update the cache to reflect the changes
1010 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
1012 ppd->qsfp_info.limiting_active;
1015 "%s: Reading QSFP memory failed\n",
1017 ret = -EINVAL; /* a fail indication */
1019 release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
1023 ppd->offline_disabled_reason =
1025 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
1030 dd_dev_info(ppd->dd, "%s: Unknown port type\n", __func__);
1031 ppd->port_type = PORT_TYPE_UNKNOWN;
1032 tuning_method = OPA_UNKNOWN_TUNING;
1034 limiting_active = 0;
1035 tx_preset_index = OPA_INVALID_INDEX;
1039 if (ppd->offline_disabled_reason ==
1040 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
1041 apply_tunings(ppd, tx_preset_index, tuning_method,
1042 total_atten, limiting_active);
1045 ppd->driver_link_ready = 1;
1049 ppd->driver_link_ready = 0;