blob: 8004f1da75485ba322a4bf3b66b01980941b4b13 [file] [log] [blame]
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001/*
Jubin John05d6ac12016-02-14 20:22:17 -08002 * Copyright(c) 2015, 2016 Intel Corporation.
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08003 *
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.
6 *
7 * GPL LICENSE SUMMARY
8 *
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009 * 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.
12 *
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.
17 *
18 * BSD LICENSE
19 *
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080020 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
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
29 * distribution.
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.
33 *
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.
45 *
46 */
Easwar Hariharanc3838b32016-02-09 14:29:13 -080047
Jakub Byczkowski76ae6222017-08-13 08:08:40 -070048#include <linux/firmware.h>
49
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080050#include "hfi.h"
Easwar Hariharanc3838b32016-02-09 14:29:13 -080051#include "efivar.h"
Dean Luicke83eba22016-09-30 04:41:45 -070052#include "eprom.h"
Easwar Hariharanc3838b32016-02-09 14:29:13 -080053
Jakub Byczkowski76ae6222017-08-13 08:08:40 -070054#define DEFAULT_PLATFORM_CONFIG_NAME "hfi1_platform.dat"
55
Easwar Hariharanfe4d9242016-10-17 04:19:47 -070056static int validate_scratch_checksum(struct hfi1_devdata *dd)
57{
58 u64 checksum = 0, temp_scratch = 0;
59 int i, j, version;
60
61 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
62 version = (temp_scratch & BITMAP_VERSION_SMASK) >> BITMAP_VERSION_SHIFT;
63
64 /* Prevent power on default of all zeroes from passing checksum */
Jan Sokolowskic8226522017-07-29 08:43:37 -070065 if (!version) {
66 dd_dev_err(dd, "%s: Config bitmap uninitialized\n", __func__);
67 dd_dev_err(dd,
68 "%s: Please update your BIOS to support active channels\n",
69 __func__);
Easwar Hariharanfe4d9242016-10-17 04:19:47 -070070 return 0;
Jan Sokolowskic8226522017-07-29 08:43:37 -070071 }
Easwar Hariharanfe4d9242016-10-17 04:19:47 -070072
73 /*
74 * ASIC scratch 0 only contains the checksum and bitmap version as
75 * fields of interest, both of which are handled separately from the
76 * loop below, so skip it
77 */
78 checksum += version;
79 for (i = 1; i < ASIC_NUM_SCRATCH; i++) {
80 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH + (8 * i));
81 for (j = sizeof(u64); j != 0; j -= 2) {
82 checksum += (temp_scratch & 0xFFFF);
83 temp_scratch >>= 16;
84 }
85 }
86
87 while (checksum >> 16)
88 checksum = (checksum & CHECKSUM_MASK) + (checksum >> 16);
89
90 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
91 temp_scratch &= CHECKSUM_SMASK;
92 temp_scratch >>= CHECKSUM_SHIFT;
93
94 if (checksum + temp_scratch == 0xFFFF)
95 return 1;
Jan Sokolowskic8226522017-07-29 08:43:37 -070096
97 dd_dev_err(dd, "%s: Configuration bitmap corrupted\n", __func__);
Easwar Hariharanfe4d9242016-10-17 04:19:47 -070098 return 0;
99}
100
101static void save_platform_config_fields(struct hfi1_devdata *dd)
102{
103 struct hfi1_pportdata *ppd = dd->pport;
104 u64 temp_scratch = 0, temp_dest = 0;
105
106 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH_1);
107
108 temp_dest = temp_scratch &
109 (dd->hfi1_id ? PORT1_PORT_TYPE_SMASK :
110 PORT0_PORT_TYPE_SMASK);
111 ppd->port_type = temp_dest >>
112 (dd->hfi1_id ? PORT1_PORT_TYPE_SHIFT :
113 PORT0_PORT_TYPE_SHIFT);
114
115 temp_dest = temp_scratch &
116 (dd->hfi1_id ? PORT1_LOCAL_ATTEN_SMASK :
117 PORT0_LOCAL_ATTEN_SMASK);
118 ppd->local_atten = temp_dest >>
119 (dd->hfi1_id ? PORT1_LOCAL_ATTEN_SHIFT :
120 PORT0_LOCAL_ATTEN_SHIFT);
121
122 temp_dest = temp_scratch &
123 (dd->hfi1_id ? PORT1_REMOTE_ATTEN_SMASK :
124 PORT0_REMOTE_ATTEN_SMASK);
125 ppd->remote_atten = temp_dest >>
126 (dd->hfi1_id ? PORT1_REMOTE_ATTEN_SHIFT :
127 PORT0_REMOTE_ATTEN_SHIFT);
128
129 temp_dest = temp_scratch &
130 (dd->hfi1_id ? PORT1_DEFAULT_ATTEN_SMASK :
131 PORT0_DEFAULT_ATTEN_SMASK);
132 ppd->default_atten = temp_dest >>
133 (dd->hfi1_id ? PORT1_DEFAULT_ATTEN_SHIFT :
134 PORT0_DEFAULT_ATTEN_SHIFT);
135
136 temp_scratch = read_csr(dd, dd->hfi1_id ? ASIC_CFG_SCRATCH_3 :
137 ASIC_CFG_SCRATCH_2);
138
139 ppd->tx_preset_eq = (temp_scratch & TX_EQ_SMASK) >> TX_EQ_SHIFT;
140 ppd->tx_preset_noeq = (temp_scratch & TX_NO_EQ_SMASK) >> TX_NO_EQ_SHIFT;
141 ppd->rx_preset = (temp_scratch & RX_SMASK) >> RX_SHIFT;
142
143 ppd->max_power_class = (temp_scratch & QSFP_MAX_POWER_SMASK) >>
144 QSFP_MAX_POWER_SHIFT;
Jakub Byczkowski91618602017-08-13 08:08:34 -0700145
146 ppd->config_from_scratch = true;
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700147}
148
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800149void get_platform_config(struct hfi1_devdata *dd)
150{
151 int ret = 0;
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800152 u8 *temp_platform_config = NULL;
Dean Luicke83eba22016-09-30 04:41:45 -0700153 u32 esize;
Jakub Byczkowski76ae6222017-08-13 08:08:40 -0700154 const struct firmware *platform_config_file = NULL;
Dean Luicke83eba22016-09-30 04:41:45 -0700155
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700156 if (is_integrated(dd)) {
157 if (validate_scratch_checksum(dd)) {
158 save_platform_config_fields(dd);
159 return;
160 }
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700161 } else {
162 ret = eprom_read_platform_config(dd,
163 (void **)&temp_platform_config,
164 &esize);
165 if (!ret) {
166 /* success */
167 dd->platform_config.data = temp_platform_config;
168 dd->platform_config.size = esize;
169 return;
170 }
Dean Luicke83eba22016-09-30 04:41:45 -0700171 }
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700172 dd_dev_err(dd,
173 "%s: Failed to get platform config, falling back to sub-optimal default file\n",
174 __func__);
Jakub Byczkowski76ae6222017-08-13 08:08:40 -0700175
176 ret = request_firmware(&platform_config_file,
177 DEFAULT_PLATFORM_CONFIG_NAME,
178 &dd->pcidev->dev);
179 if (ret) {
180 dd_dev_err(dd,
181 "%s: No default platform config file found\n",
182 __func__);
183 return;
184 }
185
186 /*
187 * Allocate separate memory block to store data and free firmware
188 * structure. This allows free_platform_config to treat EPROM and
189 * fallback configs in the same manner.
190 */
191 dd->platform_config.data = kmemdup(platform_config_file->data,
192 platform_config_file->size,
193 GFP_KERNEL);
194 dd->platform_config.size = platform_config_file->size;
195 release_firmware(platform_config_file);
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800196}
197
198void free_platform_config(struct hfi1_devdata *dd)
199{
Jakub Byczkowski76ae6222017-08-13 08:08:40 -0700200 /* Release memory allocated for eprom or fallback file read. */
201 kfree(dd->platform_config.data);
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800202}
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800203
Easwar Hariharan9775a992016-05-12 10:22:39 -0700204void get_port_type(struct hfi1_pportdata *ppd)
205{
206 int ret;
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700207 u32 temp;
Easwar Hariharan9775a992016-05-12 10:22:39 -0700208
209 ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700210 PORT_TABLE_PORT_TYPE, &temp,
Easwar Hariharan9775a992016-05-12 10:22:39 -0700211 4);
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700212 if (ret) {
Easwar Hariharan9775a992016-05-12 10:22:39 -0700213 ppd->port_type = PORT_TYPE_UNKNOWN;
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700214 return;
215 }
216 ppd->port_type = temp;
Easwar Hariharan9775a992016-05-12 10:22:39 -0700217}
218
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800219int set_qsfp_tx(struct hfi1_pportdata *ppd, int on)
220{
221 u8 tx_ctrl_byte = on ? 0x0 : 0xF;
222 int ret = 0;
223
224 ret = qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_TX_CTRL_BYTE_OFFS,
225 &tx_ctrl_byte, 1);
226 /* we expected 1, so consider 0 an error */
227 if (ret == 0)
228 ret = -EIO;
229 else if (ret == 1)
230 ret = 0;
231 return ret;
232}
233
234static int qual_power(struct hfi1_pportdata *ppd)
235{
236 u32 cable_power_class = 0, power_class_max = 0;
237 u8 *cache = ppd->qsfp_info.cache;
238 int ret = 0;
239
240 ret = get_platform_config_field(
241 ppd->dd, PLATFORM_CONFIG_SYSTEM_TABLE, 0,
242 SYSTEM_TABLE_QSFP_POWER_CLASS_MAX, &power_class_max, 4);
243 if (ret)
244 return ret;
245
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700246 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800247
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700248 if (cable_power_class > power_class_max)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800249 ppd->offline_disabled_reason =
250 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800251
252 if (ppd->offline_disabled_reason ==
253 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY)) {
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -0700254 dd_dev_err(
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800255 ppd->dd,
256 "%s: Port disabled due to system power restrictions\n",
257 __func__);
258 ret = -EPERM;
259 }
260 return ret;
261}
262
263static int qual_bitrate(struct hfi1_pportdata *ppd)
264{
265 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
266 u8 *cache = ppd->qsfp_info.cache;
267
268 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G) &&
269 cache[QSFP_NOM_BIT_RATE_250_OFFS] < 0x64)
270 ppd->offline_disabled_reason =
271 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
272
273 if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G) &&
274 cache[QSFP_NOM_BIT_RATE_100_OFFS] < 0x7D)
275 ppd->offline_disabled_reason =
276 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
277
278 if (ppd->offline_disabled_reason ==
279 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY)) {
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -0700280 dd_dev_err(
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800281 ppd->dd,
282 "%s: Cable failed bitrate check, disabling port\n",
283 __func__);
284 return -EPERM;
285 }
286 return 0;
287}
288
289static int set_qsfp_high_power(struct hfi1_pportdata *ppd)
290{
291 u8 cable_power_class = 0, power_ctrl_byte = 0;
292 u8 *cache = ppd->qsfp_info.cache;
293 int ret;
294
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700295 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800296
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700297 if (cable_power_class > QSFP_POWER_CLASS_1) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800298 power_ctrl_byte = cache[QSFP_PWR_CTRL_BYTE_OFFS];
299
300 power_ctrl_byte |= 1;
301 power_ctrl_byte &= ~(0x2);
302
303 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
304 QSFP_PWR_CTRL_BYTE_OFFS,
305 &power_ctrl_byte, 1);
306 if (ret != 1)
307 return -EIO;
308
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700309 if (cable_power_class > QSFP_POWER_CLASS_4) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800310 power_ctrl_byte |= (1 << 2);
311 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
312 QSFP_PWR_CTRL_BYTE_OFFS,
313 &power_ctrl_byte, 1);
314 if (ret != 1)
315 return -EIO;
316 }
317
318 /* SFF 8679 rev 1.7 LPMode Deassert time */
319 msleep(300);
320 }
321 return 0;
322}
323
324static void apply_rx_cdr(struct hfi1_pportdata *ppd,
325 u32 rx_preset_index,
326 u8 *cdr_ctrl_byte)
327{
328 u32 rx_preset;
329 u8 *cache = ppd->qsfp_info.cache;
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700330 int cable_power_class;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800331
332 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x4) &&
333 (cache[QSFP_CDR_INFO_OFFS] & 0x40)))
334 return;
335
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700336 /* RX CDR present, bypass supported */
337 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
338
339 if (cable_power_class <= QSFP_POWER_CLASS_3) {
340 /* Power class <= 3, ignore config & turn RX CDR on */
341 *cdr_ctrl_byte |= 0xF;
342 return;
343 }
344
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800345 get_platform_config_field(
346 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
347 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR_APPLY,
348 &rx_preset, 4);
349
350 if (!rx_preset) {
351 dd_dev_info(
352 ppd->dd,
353 "%s: RX_CDR_APPLY is set to disabled\n",
354 __func__);
355 return;
356 }
357 get_platform_config_field(
358 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
359 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR,
360 &rx_preset, 4);
361
362 /* Expand cdr setting to all 4 lanes */
363 rx_preset = (rx_preset | (rx_preset << 1) |
364 (rx_preset << 2) | (rx_preset << 3));
365
366 if (rx_preset) {
367 *cdr_ctrl_byte |= rx_preset;
368 } else {
369 *cdr_ctrl_byte &= rx_preset;
370 /* Preserve current TX CDR status */
371 *cdr_ctrl_byte |= (cache[QSFP_CDR_CTRL_BYTE_OFFS] & 0xF0);
372 }
373}
374
375static void apply_tx_cdr(struct hfi1_pportdata *ppd,
376 u32 tx_preset_index,
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700377 u8 *cdr_ctrl_byte)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800378{
379 u32 tx_preset;
380 u8 *cache = ppd->qsfp_info.cache;
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700381 int cable_power_class;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800382
383 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x8) &&
384 (cache[QSFP_CDR_INFO_OFFS] & 0x80)))
385 return;
386
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700387 /* TX CDR present, bypass supported */
388 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
389
390 if (cable_power_class <= QSFP_POWER_CLASS_3) {
391 /* Power class <= 3, ignore config & turn TX CDR on */
392 *cdr_ctrl_byte |= 0xF0;
393 return;
394 }
395
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800396 get_platform_config_field(
397 ppd->dd,
398 PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
399 TX_PRESET_TABLE_QSFP_TX_CDR_APPLY, &tx_preset, 4);
400
401 if (!tx_preset) {
402 dd_dev_info(
403 ppd->dd,
404 "%s: TX_CDR_APPLY is set to disabled\n",
405 __func__);
406 return;
407 }
408 get_platform_config_field(
409 ppd->dd,
410 PLATFORM_CONFIG_TX_PRESET_TABLE,
411 tx_preset_index,
412 TX_PRESET_TABLE_QSFP_TX_CDR, &tx_preset, 4);
413
414 /* Expand cdr setting to all 4 lanes */
415 tx_preset = (tx_preset | (tx_preset << 1) |
416 (tx_preset << 2) | (tx_preset << 3));
417
418 if (tx_preset)
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700419 *cdr_ctrl_byte |= (tx_preset << 4);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800420 else
421 /* Preserve current/determined RX CDR status */
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700422 *cdr_ctrl_byte &= ((tx_preset << 4) | 0xF);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800423}
424
425static void apply_cdr_settings(
426 struct hfi1_pportdata *ppd, u32 rx_preset_index,
427 u32 tx_preset_index)
428{
429 u8 *cache = ppd->qsfp_info.cache;
430 u8 cdr_ctrl_byte = cache[QSFP_CDR_CTRL_BYTE_OFFS];
431
432 apply_rx_cdr(ppd, rx_preset_index, &cdr_ctrl_byte);
433
434 apply_tx_cdr(ppd, tx_preset_index, &cdr_ctrl_byte);
435
436 qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_CDR_CTRL_BYTE_OFFS,
437 &cdr_ctrl_byte, 1);
438}
439
440static void apply_tx_eq_auto(struct hfi1_pportdata *ppd)
441{
442 u8 *cache = ppd->qsfp_info.cache;
443 u8 tx_eq;
444
445 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x8))
446 return;
447 /* Disable adaptive TX EQ if present */
448 tx_eq = cache[(128 * 3) + 241];
449 tx_eq &= 0xF0;
450 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 241, &tx_eq, 1);
451}
452
453static void apply_tx_eq_prog(struct hfi1_pportdata *ppd, u32 tx_preset_index)
454{
455 u8 *cache = ppd->qsfp_info.cache;
456 u32 tx_preset;
457 u8 tx_eq;
458
459 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x4))
460 return;
461
462 get_platform_config_field(
463 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
464 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ_APPLY,
465 &tx_preset, 4);
466 if (!tx_preset) {
467 dd_dev_info(
468 ppd->dd,
469 "%s: TX_EQ_APPLY is set to disabled\n",
470 __func__);
471 return;
472 }
473 get_platform_config_field(
474 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
475 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ,
476 &tx_preset, 4);
477
478 if (((cache[(128 * 3) + 224] & 0xF0) >> 4) < tx_preset) {
479 dd_dev_info(
480 ppd->dd,
481 "%s: TX EQ %x unsupported\n",
482 __func__, tx_preset);
483
484 dd_dev_info(
485 ppd->dd,
486 "%s: Applying EQ %x\n",
487 __func__, cache[608] & 0xF0);
488
489 tx_preset = (cache[608] & 0xF0) >> 4;
490 }
491
492 tx_eq = tx_preset | (tx_preset << 4);
493 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 234, &tx_eq, 1);
494 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 235, &tx_eq, 1);
495}
496
497static void apply_rx_eq_emp(struct hfi1_pportdata *ppd, u32 rx_preset_index)
498{
499 u32 rx_preset;
500 u8 rx_eq, *cache = ppd->qsfp_info.cache;
501
502 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x2))
503 return;
504 get_platform_config_field(
505 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
506 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP_APPLY,
507 &rx_preset, 4);
508
509 if (!rx_preset) {
510 dd_dev_info(
511 ppd->dd,
512 "%s: RX_EMP_APPLY is set to disabled\n",
513 __func__);
514 return;
515 }
516 get_platform_config_field(
517 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
518 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP,
519 &rx_preset, 4);
520
521 if ((cache[(128 * 3) + 224] & 0xF) < rx_preset) {
522 dd_dev_info(
523 ppd->dd,
524 "%s: Requested RX EMP %x\n",
525 __func__, rx_preset);
526
527 dd_dev_info(
528 ppd->dd,
529 "%s: Applying supported EMP %x\n",
530 __func__, cache[608] & 0xF);
531
532 rx_preset = cache[608] & 0xF;
533 }
534
535 rx_eq = rx_preset | (rx_preset << 4);
536
537 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 236, &rx_eq, 1);
538 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 237, &rx_eq, 1);
539}
540
541static void apply_eq_settings(struct hfi1_pportdata *ppd,
542 u32 rx_preset_index, u32 tx_preset_index)
543{
544 u8 *cache = ppd->qsfp_info.cache;
545
546 /* no point going on w/o a page 3 */
547 if (cache[2] & 4) {
548 dd_dev_info(ppd->dd,
549 "%s: Upper page 03 not present\n",
550 __func__);
551 return;
552 }
553
554 apply_tx_eq_auto(ppd);
555
556 apply_tx_eq_prog(ppd, tx_preset_index);
557
558 apply_rx_eq_emp(ppd, rx_preset_index);
559}
560
561static void apply_rx_amplitude_settings(
562 struct hfi1_pportdata *ppd, u32 rx_preset_index,
563 u32 tx_preset_index)
564{
565 u32 rx_preset;
566 u8 rx_amp = 0, i = 0, preferred = 0, *cache = ppd->qsfp_info.cache;
567
568 /* no point going on w/o a page 3 */
569 if (cache[2] & 4) {
570 dd_dev_info(ppd->dd,
571 "%s: Upper page 03 not present\n",
572 __func__);
573 return;
574 }
575 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x1)) {
576 dd_dev_info(ppd->dd,
577 "%s: RX_AMP_APPLY is set to disabled\n",
578 __func__);
579 return;
580 }
581
582 get_platform_config_field(ppd->dd,
583 PLATFORM_CONFIG_RX_PRESET_TABLE,
584 rx_preset_index,
585 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY,
586 &rx_preset, 4);
587
588 if (!rx_preset) {
589 dd_dev_info(ppd->dd,
590 "%s: RX_AMP_APPLY is set to disabled\n",
591 __func__);
592 return;
593 }
594 get_platform_config_field(ppd->dd,
595 PLATFORM_CONFIG_RX_PRESET_TABLE,
596 rx_preset_index,
597 RX_PRESET_TABLE_QSFP_RX_AMP,
598 &rx_preset, 4);
599
600 dd_dev_info(ppd->dd,
601 "%s: Requested RX AMP %x\n",
602 __func__,
603 rx_preset);
604
605 for (i = 0; i < 4; i++) {
606 if (cache[(128 * 3) + 225] & (1 << i)) {
607 preferred = i;
608 if (preferred == rx_preset)
609 break;
610 }
611 }
612
613 /*
614 * Verify that preferred RX amplitude is not just a
615 * fall through of the default
616 */
617 if (!preferred && !(cache[(128 * 3) + 225] & 0x1)) {
618 dd_dev_info(ppd->dd, "No supported RX AMP, not applying\n");
619 return;
620 }
621
622 dd_dev_info(ppd->dd,
623 "%s: Applying RX AMP %x\n", __func__, preferred);
624
625 rx_amp = preferred | (preferred << 4);
626 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 238, &rx_amp, 1);
627 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 239, &rx_amp, 1);
628}
629
630#define OPA_INVALID_INDEX 0xFFF
631
Easwar Hariharan97167e82016-02-09 14:29:22 -0800632static void apply_tx_lanes(struct hfi1_pportdata *ppd, u8 field_id,
633 u32 config_data, const char *message)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800634{
635 u8 i;
636 int ret = HCMD_SUCCESS;
637
638 for (i = 0; i < 4; i++) {
Easwar Hariharan97167e82016-02-09 14:29:22 -0800639 ret = load_8051_config(ppd->dd, field_id, i, config_data);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800640 if (ret != HCMD_SUCCESS) {
641 dd_dev_err(
642 ppd->dd,
643 "%s: %s for lane %u failed\n",
644 message, __func__, i);
645 }
646 }
647}
648
Dean Luick52130062016-12-07 19:33:13 -0800649/*
650 * Return a special SerDes setting for low power AOC cables. The power class
651 * threshold and setting being used were all found by empirical testing.
652 *
653 * Summary of the logic:
654 *
655 * if (QSFP and QSFP_TYPE == AOC and QSFP_POWER_CLASS < 4)
656 * return 0xe
657 * return 0; // leave at default
658 */
659static u8 aoc_low_power_setting(struct hfi1_pportdata *ppd)
660{
661 u8 *cache = ppd->qsfp_info.cache;
662 int power_class;
663
664 /* QSFP only */
665 if (ppd->port_type != PORT_TYPE_QSFP)
666 return 0; /* leave at default */
667
668 /* active optical cables only */
669 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
670 case 0x0 ... 0x9: /* fallthrough */
671 case 0xC: /* fallthrough */
672 case 0xE:
673 /* active AOC */
674 power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
675 if (power_class < QSFP_POWER_CLASS_4)
676 return 0xe;
677 }
678 return 0; /* leave at default */
679}
680
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800681static void apply_tunings(
682 struct hfi1_pportdata *ppd, u32 tx_preset_index,
683 u8 tuning_method, u32 total_atten, u8 limiting_active)
684{
685 int ret = 0;
686 u32 config_data = 0, tx_preset = 0;
687 u8 precur = 0, attn = 0, postcur = 0, external_device_config = 0;
688 u8 *cache = ppd->qsfp_info.cache;
689
Easwar Hariharan97167e82016-02-09 14:29:22 -0800690 /* Pass tuning method to 8051 */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800691 read_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
692 &config_data);
Dean Luickf6de3d32016-05-24 12:51:00 -0700693 config_data &= ~(0xff << TUNING_METHOD_SHIFT);
694 config_data |= ((u32)tuning_method << TUNING_METHOD_SHIFT);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800695 ret = load_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
696 config_data);
697 if (ret != HCMD_SUCCESS)
698 dd_dev_err(ppd->dd, "%s: Failed to set tuning method\n",
699 __func__);
700
Easwar Hariharan97167e82016-02-09 14:29:22 -0800701 /* Set same channel loss for both TX and RX */
702 config_data = 0 | (total_atten << 16) | (total_atten << 24);
703 apply_tx_lanes(ppd, CHANNEL_LOSS_SETTINGS, config_data,
704 "Setting channel loss");
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800705
Easwar Hariharan97167e82016-02-09 14:29:22 -0800706 /* Inform 8051 of cable capabilities */
707 if (ppd->qsfp_info.cache_valid) {
708 external_device_config =
709 ((cache[QSFP_MOD_PWR_OFFS] & 0x4) << 3) |
710 ((cache[QSFP_MOD_PWR_OFFS] & 0x8) << 2) |
711 ((cache[QSFP_EQ_INFO_OFFS] & 0x2) << 1) |
712 (cache[QSFP_EQ_INFO_OFFS] & 0x4);
713 ret = read_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
714 GENERAL_CONFIG, &config_data);
715 /* Clear, then set the external device config field */
Easwar Hariharan27a340f2016-05-12 10:22:45 -0700716 config_data &= ~(u32)0xFF;
717 config_data |= external_device_config;
Easwar Hariharan97167e82016-02-09 14:29:22 -0800718 ret = load_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
719 GENERAL_CONFIG, config_data);
720 if (ret != HCMD_SUCCESS)
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -0700721 dd_dev_err(ppd->dd,
722 "%s: Failed set ext device config params\n",
723 __func__);
Easwar Hariharan97167e82016-02-09 14:29:22 -0800724 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800725
Easwar Hariharan97167e82016-02-09 14:29:22 -0800726 if (tx_preset_index == OPA_INVALID_INDEX) {
727 if (ppd->port_type == PORT_TYPE_QSFP && limiting_active)
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -0700728 dd_dev_err(ppd->dd, "%s: Invalid Tx preset index\n",
729 __func__);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800730 return;
Easwar Hariharan97167e82016-02-09 14:29:22 -0800731 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800732
Easwar Hariharan97167e82016-02-09 14:29:22 -0800733 /* Following for limiting active channels only */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800734 get_platform_config_field(
735 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
736 TX_PRESET_TABLE_PRECUR, &tx_preset, 4);
737 precur = tx_preset;
738
739 get_platform_config_field(
740 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
741 tx_preset_index, TX_PRESET_TABLE_ATTN, &tx_preset, 4);
742 attn = tx_preset;
743
744 get_platform_config_field(
745 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
746 tx_preset_index, TX_PRESET_TABLE_POSTCUR, &tx_preset, 4);
747 postcur = tx_preset;
748
Dean Luick52130062016-12-07 19:33:13 -0800749 /*
750 * NOTES:
751 * o The aoc_low_power_setting is applied to all lanes even
752 * though only lane 0's value is examined by the firmware.
753 * o A lingering low power setting after a cable swap does
754 * not occur. On cable unplug the 8051 is reset and
755 * restarted on cable insert. This resets all settings to
756 * their default, erasing any previous low power setting.
757 */
758 config_data = precur | (attn << 8) | (postcur << 16) |
759 (aoc_low_power_setting(ppd) << 24);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800760
Easwar Hariharan97167e82016-02-09 14:29:22 -0800761 apply_tx_lanes(ppd, TX_EQ_SETTINGS, config_data,
762 "Applying TX settings");
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800763}
764
Dean Luicke4e0e392016-04-12 11:28:36 -0700765/* Must be holding the QSFP i2c resource */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800766static int tune_active_qsfp(struct hfi1_pportdata *ppd, u32 *ptr_tx_preset,
767 u32 *ptr_rx_preset, u32 *ptr_total_atten)
768{
Dean Luick765a6fa2016-03-05 08:50:06 -0800769 int ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800770 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
771 u8 *cache = ppd->qsfp_info.cache;
772
773 ppd->qsfp_info.limiting_active = 1;
774
775 ret = set_qsfp_tx(ppd, 0);
776 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700777 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800778
779 ret = qual_power(ppd);
780 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700781 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800782
783 ret = qual_bitrate(ppd);
784 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700785 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800786
Easwar Hariharanb5e71012016-07-25 13:40:03 -0700787 /*
788 * We'll change the QSFP memory contents from here on out, thus we set a
789 * flag here to remind ourselves to reset the QSFP module. This prevents
790 * reuse of stale settings established in our previous pass through.
791 */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800792 if (ppd->qsfp_info.reset_needed) {
793 reset_qsfp(ppd);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800794 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
795 } else {
796 ppd->qsfp_info.reset_needed = 1;
797 }
798
799 ret = set_qsfp_high_power(ppd);
800 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700801 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800802
803 if (cache[QSFP_EQ_INFO_OFFS] & 0x4) {
804 ret = get_platform_config_field(
805 ppd->dd,
806 PLATFORM_CONFIG_PORT_TABLE, 0,
807 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ,
808 ptr_tx_preset, 4);
809 if (ret) {
810 *ptr_tx_preset = OPA_INVALID_INDEX;
Dean Luicke4e0e392016-04-12 11:28:36 -0700811 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800812 }
813 } else {
814 ret = get_platform_config_field(
815 ppd->dd,
816 PLATFORM_CONFIG_PORT_TABLE, 0,
817 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ,
818 ptr_tx_preset, 4);
819 if (ret) {
820 *ptr_tx_preset = OPA_INVALID_INDEX;
Dean Luicke4e0e392016-04-12 11:28:36 -0700821 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800822 }
823 }
824
825 ret = get_platform_config_field(
826 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
827 PORT_TABLE_RX_PRESET_IDX, ptr_rx_preset, 4);
828 if (ret) {
829 *ptr_rx_preset = OPA_INVALID_INDEX;
Dean Luicke4e0e392016-04-12 11:28:36 -0700830 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800831 }
832
833 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
834 get_platform_config_field(
835 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
836 PORT_TABLE_LOCAL_ATTEN_25G, ptr_total_atten, 4);
837 else if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G))
838 get_platform_config_field(
839 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
840 PORT_TABLE_LOCAL_ATTEN_12G, ptr_total_atten, 4);
841
842 apply_cdr_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
843
844 apply_eq_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
845
846 apply_rx_amplitude_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
847
848 ret = set_qsfp_tx(ppd, 1);
Dean Luick765a6fa2016-03-05 08:50:06 -0800849
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800850 return ret;
851}
852
853static int tune_qsfp(struct hfi1_pportdata *ppd,
854 u32 *ptr_tx_preset, u32 *ptr_rx_preset,
855 u8 *ptr_tuning_method, u32 *ptr_total_atten)
856{
857 u32 cable_atten = 0, remote_atten = 0, platform_atten = 0;
858 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
859 int ret = 0;
860 u8 *cache = ppd->qsfp_info.cache;
861
862 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
863 case 0xA ... 0xB:
864 ret = get_platform_config_field(
865 ppd->dd,
866 PLATFORM_CONFIG_PORT_TABLE, 0,
867 PORT_TABLE_LOCAL_ATTEN_25G,
868 &platform_atten, 4);
869 if (ret)
870 return ret;
871
872 if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
873 cable_atten = cache[QSFP_CU_ATTEN_12G_OFFS];
874 else if ((lss & OPA_LINK_SPEED_12_5G) &&
875 (lse & OPA_LINK_SPEED_12_5G))
876 cable_atten = cache[QSFP_CU_ATTEN_7G_OFFS];
877
878 /* Fallback to configured attenuation if cable memory is bad */
879 if (cable_atten == 0 || cable_atten > 36) {
880 ret = get_platform_config_field(
881 ppd->dd,
882 PLATFORM_CONFIG_SYSTEM_TABLE, 0,
883 SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G,
884 &cable_atten, 4);
885 if (ret)
886 return ret;
887 }
888
889 ret = get_platform_config_field(
890 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
891 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
892 if (ret)
893 return ret;
894
895 *ptr_total_atten = platform_atten + cable_atten + remote_atten;
896
897 *ptr_tuning_method = OPA_PASSIVE_TUNING;
898 break;
899 case 0x0 ... 0x9: /* fallthrough */
900 case 0xC: /* fallthrough */
901 case 0xE:
902 ret = tune_active_qsfp(ppd, ptr_tx_preset, ptr_rx_preset,
903 ptr_total_atten);
904 if (ret)
905 return ret;
906
907 *ptr_tuning_method = OPA_ACTIVE_TUNING;
908 break;
909 case 0xD: /* fallthrough */
910 case 0xF:
911 default:
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -0700912 dd_dev_warn(ppd->dd, "%s: Unknown/unsupported cable\n",
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800913 __func__);
914 break;
915 }
916 return ret;
917}
918
919/*
920 * This function communicates its success or failure via ppd->driver_link_ready
921 * Thus, it depends on its association with start_link(...) which checks
922 * driver_link_ready before proceeding with the link negotiation and
923 * initialization process.
924 */
925void tune_serdes(struct hfi1_pportdata *ppd)
926{
927 int ret = 0;
928 u32 total_atten = 0;
929 u32 remote_atten = 0, platform_atten = 0;
930 u32 rx_preset_index, tx_preset_index;
Easwar Hariharan97167e82016-02-09 14:29:22 -0800931 u8 tuning_method = 0, limiting_active = 0;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800932 struct hfi1_devdata *dd = ppd->dd;
933
934 rx_preset_index = OPA_INVALID_INDEX;
935 tx_preset_index = OPA_INVALID_INDEX;
936
937 /* the link defaults to enabled */
938 ppd->link_enabled = 1;
939 /* the driver link ready state defaults to not ready */
940 ppd->driver_link_ready = 0;
941 ppd->offline_disabled_reason = HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
942
Easwar Hariharan715c4302016-02-03 14:32:14 -0800943 /* Skip the tuning for testing (loopback != none) and simulations */
944 if (loopback != LOOPBACK_NONE ||
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800945 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800946 ppd->driver_link_ready = 1;
947 return;
948 }
949
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800950 switch (ppd->port_type) {
951 case PORT_TYPE_DISCONNECTED:
952 ppd->offline_disabled_reason =
953 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_DISCONNECTED);
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -0700954 dd_dev_warn(dd, "%s: Port disconnected, disabling port\n",
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800955 __func__);
956 goto bail;
957 case PORT_TYPE_FIXED:
958 /* platform_atten, remote_atten pre-zeroed to catch error */
959 get_platform_config_field(
960 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
961 PORT_TABLE_LOCAL_ATTEN_25G, &platform_atten, 4);
962
963 get_platform_config_field(
964 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
965 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
966
967 total_atten = platform_atten + remote_atten;
968
969 tuning_method = OPA_PASSIVE_TUNING;
970 break;
971 case PORT_TYPE_VARIABLE:
972 if (qsfp_mod_present(ppd)) {
973 /*
974 * platform_atten, remote_atten pre-zeroed to
975 * catch error
976 */
977 get_platform_config_field(
978 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
979 PORT_TABLE_LOCAL_ATTEN_25G,
980 &platform_atten, 4);
981
982 get_platform_config_field(
983 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
984 PORT_TABLE_REMOTE_ATTEN_25G,
985 &remote_atten, 4);
986
987 total_atten = platform_atten + remote_atten;
988
989 tuning_method = OPA_PASSIVE_TUNING;
Easwar Hariharan623bba22016-04-12 11:25:57 -0700990 } else {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800991 ppd->offline_disabled_reason =
992 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_CHASSIS_CONFIG);
Easwar Hariharan623bba22016-04-12 11:25:57 -0700993 goto bail;
994 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800995 break;
996 case PORT_TYPE_QSFP:
997 if (qsfp_mod_present(ppd)) {
Dean Luicke4e0e392016-04-12 11:28:36 -0700998 ret = acquire_chip_resource(ppd->dd,
999 qsfp_resource(ppd->dd),
1000 QSFP_WAIT);
1001 if (ret) {
1002 dd_dev_err(ppd->dd, "%s: hfi%d: cannot lock i2c chain\n",
1003 __func__, (int)ppd->dd->hfi1_id);
1004 goto bail;
1005 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001006 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
1007
1008 if (ppd->qsfp_info.cache_valid) {
1009 ret = tune_qsfp(ppd,
1010 &tx_preset_index,
1011 &rx_preset_index,
1012 &tuning_method,
1013 &total_atten);
Easwar Hariharanc3838b32016-02-09 14:29:13 -08001014
1015 /*
1016 * We may have modified the QSFP memory, so
1017 * update the cache to reflect the changes
1018 */
1019 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
Easwar Hariharan97167e82016-02-09 14:29:22 -08001020 limiting_active =
1021 ppd->qsfp_info.limiting_active;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001022 } else {
1023 dd_dev_err(dd,
1024 "%s: Reading QSFP memory failed\n",
1025 __func__);
Dean Luicke4e0e392016-04-12 11:28:36 -07001026 ret = -EINVAL; /* a fail indication */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001027 }
Dean Luicke4e0e392016-04-12 11:28:36 -07001028 release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
1029 if (ret)
1030 goto bail;
Easwar Hariharan623bba22016-04-12 11:25:57 -07001031 } else {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001032 ppd->offline_disabled_reason =
1033 HFI1_ODR_MASK(
Easwar Hariharane1bf0d52016-02-03 14:36:58 -08001034 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
Easwar Hariharan623bba22016-04-12 11:25:57 -07001035 goto bail;
1036 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001037 break;
1038 default:
Sebastian Sanchezb4e9e2f2017-05-26 05:35:57 -07001039 dd_dev_warn(ppd->dd, "%s: Unknown port type\n", __func__);
Easwar Hariharan97167e82016-02-09 14:29:22 -08001040 ppd->port_type = PORT_TYPE_UNKNOWN;
1041 tuning_method = OPA_UNKNOWN_TUNING;
1042 total_atten = 0;
1043 limiting_active = 0;
1044 tx_preset_index = OPA_INVALID_INDEX;
1045 break;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001046 }
Easwar Hariharan97167e82016-02-09 14:29:22 -08001047
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001048 if (ppd->offline_disabled_reason ==
1049 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
1050 apply_tunings(ppd, tx_preset_index, tuning_method,
Easwar Hariharan97167e82016-02-09 14:29:22 -08001051 total_atten, limiting_active);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001052
Easwar Hariharanc3838b32016-02-09 14:29:13 -08001053 if (!ret)
1054 ppd->driver_link_ready = 1;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001055
1056 return;
1057bail:
1058 ppd->driver_link_ready = 0;
1059}