blob: 838fe84e285aeef2e89805075ded337ac2502a63 [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
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080048#include "hfi.h"
Easwar Hariharanc3838b32016-02-09 14:29:13 -080049#include "efivar.h"
Dean Luicke83eba22016-09-30 04:41:45 -070050#include "eprom.h"
Easwar Hariharanc3838b32016-02-09 14:29:13 -080051
Easwar Hariharanfe4d9242016-10-17 04:19:47 -070052static int validate_scratch_checksum(struct hfi1_devdata *dd)
53{
54 u64 checksum = 0, temp_scratch = 0;
55 int i, j, version;
56
57 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
58 version = (temp_scratch & BITMAP_VERSION_SMASK) >> BITMAP_VERSION_SHIFT;
59
60 /* Prevent power on default of all zeroes from passing checksum */
61 if (!version)
62 return 0;
63
64 /*
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
68 */
69 checksum += version;
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);
74 temp_scratch >>= 16;
75 }
76 }
77
78 while (checksum >> 16)
79 checksum = (checksum & CHECKSUM_MASK) + (checksum >> 16);
80
81 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
82 temp_scratch &= CHECKSUM_SMASK;
83 temp_scratch >>= CHECKSUM_SHIFT;
84
85 if (checksum + temp_scratch == 0xFFFF)
86 return 1;
87 return 0;
88}
89
90static void save_platform_config_fields(struct hfi1_devdata *dd)
91{
92 struct hfi1_pportdata *ppd = dd->pport;
93 u64 temp_scratch = 0, temp_dest = 0;
94
95 temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH_1);
96
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);
103
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);
110
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);
117
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);
124
125 temp_scratch = read_csr(dd, dd->hfi1_id ? ASIC_CFG_SCRATCH_3 :
126 ASIC_CFG_SCRATCH_2);
127
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;
131
132 ppd->max_power_class = (temp_scratch & QSFP_MAX_POWER_SMASK) >>
133 QSFP_MAX_POWER_SHIFT;
134}
135
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800136void get_platform_config(struct hfi1_devdata *dd)
137{
138 int ret = 0;
139 unsigned long size = 0;
140 u8 *temp_platform_config = NULL;
Dean Luicke83eba22016-09-30 04:41:45 -0700141 u32 esize;
142
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700143 if (is_integrated(dd)) {
144 if (validate_scratch_checksum(dd)) {
145 save_platform_config_fields(dd);
146 return;
147 }
148 dd_dev_err(dd, "%s: Config bitmap corrupted/uninitialized\n",
149 __func__);
150 dd_dev_err(dd,
151 "%s: Please update your BIOS to support active channels\n",
152 __func__);
153 } else {
154 ret = eprom_read_platform_config(dd,
155 (void **)&temp_platform_config,
156 &esize);
157 if (!ret) {
158 /* success */
159 dd->platform_config.data = temp_platform_config;
160 dd->platform_config.size = esize;
161 return;
162 }
163 /* fail, try EFI variable */
164
165 ret = read_hfi1_efi_var(dd, "configuration", &size,
166 (void **)&temp_platform_config);
167 if (!ret) {
168 dd->platform_config.data = temp_platform_config;
169 dd->platform_config.size = size;
170 return;
171 }
Dean Luicke83eba22016-09-30 04:41:45 -0700172 }
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700173 dd_dev_err(dd,
174 "%s: Failed to get platform config, falling back to sub-optimal default file\n",
175 __func__);
Dean Luicke83eba22016-09-30 04:41:45 -0700176 /* fall back to request firmware */
177 platform_config_load = 1;
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800178}
179
180void free_platform_config(struct hfi1_devdata *dd)
181{
182 if (!platform_config_load) {
183 /*
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700184 * was loaded from EFI or the EPROM, release memory
185 * allocated by read_efi_var/eprom_read_platform_config
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800186 */
187 kfree(dd->platform_config.data);
188 }
189 /*
190 * else do nothing, dispose_firmware will release
191 * struct firmware platform_config on driver exit
192 */
193}
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800194
Easwar Hariharan9775a992016-05-12 10:22:39 -0700195void get_port_type(struct hfi1_pportdata *ppd)
196{
197 int ret;
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700198 u32 temp;
Easwar Hariharan9775a992016-05-12 10:22:39 -0700199
200 ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700201 PORT_TABLE_PORT_TYPE, &temp,
Easwar Hariharan9775a992016-05-12 10:22:39 -0700202 4);
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700203 if (ret) {
Easwar Hariharan9775a992016-05-12 10:22:39 -0700204 ppd->port_type = PORT_TYPE_UNKNOWN;
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700205 return;
206 }
207 ppd->port_type = temp;
Easwar Hariharan9775a992016-05-12 10:22:39 -0700208}
209
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800210int set_qsfp_tx(struct hfi1_pportdata *ppd, int on)
211{
212 u8 tx_ctrl_byte = on ? 0x0 : 0xF;
213 int ret = 0;
214
215 ret = qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_TX_CTRL_BYTE_OFFS,
216 &tx_ctrl_byte, 1);
217 /* we expected 1, so consider 0 an error */
218 if (ret == 0)
219 ret = -EIO;
220 else if (ret == 1)
221 ret = 0;
222 return ret;
223}
224
225static int qual_power(struct hfi1_pportdata *ppd)
226{
227 u32 cable_power_class = 0, power_class_max = 0;
228 u8 *cache = ppd->qsfp_info.cache;
229 int ret = 0;
230
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);
234 if (ret)
235 return ret;
236
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700237 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800238
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700239 if (cable_power_class > power_class_max)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800240 ppd->offline_disabled_reason =
241 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800242
243 if (ppd->offline_disabled_reason ==
244 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY)) {
245 dd_dev_info(
246 ppd->dd,
247 "%s: Port disabled due to system power restrictions\n",
248 __func__);
249 ret = -EPERM;
250 }
251 return ret;
252}
253
254static int qual_bitrate(struct hfi1_pportdata *ppd)
255{
256 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
257 u8 *cache = ppd->qsfp_info.cache;
258
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);
263
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);
268
269 if (ppd->offline_disabled_reason ==
270 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY)) {
271 dd_dev_info(
272 ppd->dd,
273 "%s: Cable failed bitrate check, disabling port\n",
274 __func__);
275 return -EPERM;
276 }
277 return 0;
278}
279
280static int set_qsfp_high_power(struct hfi1_pportdata *ppd)
281{
282 u8 cable_power_class = 0, power_ctrl_byte = 0;
283 u8 *cache = ppd->qsfp_info.cache;
284 int ret;
285
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700286 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800287
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700288 if (cable_power_class > QSFP_POWER_CLASS_1) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800289 power_ctrl_byte = cache[QSFP_PWR_CTRL_BYTE_OFFS];
290
291 power_ctrl_byte |= 1;
292 power_ctrl_byte &= ~(0x2);
293
294 ret = qsfp_write(ppd, ppd->dd->hfi1_id,
295 QSFP_PWR_CTRL_BYTE_OFFS,
296 &power_ctrl_byte, 1);
297 if (ret != 1)
298 return -EIO;
299
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700300 if (cable_power_class > QSFP_POWER_CLASS_4) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800301 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);
305 if (ret != 1)
306 return -EIO;
307 }
308
309 /* SFF 8679 rev 1.7 LPMode Deassert time */
310 msleep(300);
311 }
312 return 0;
313}
314
315static void apply_rx_cdr(struct hfi1_pportdata *ppd,
316 u32 rx_preset_index,
317 u8 *cdr_ctrl_byte)
318{
319 u32 rx_preset;
320 u8 *cache = ppd->qsfp_info.cache;
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700321 int cable_power_class;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800322
323 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x4) &&
324 (cache[QSFP_CDR_INFO_OFFS] & 0x40)))
325 return;
326
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700327 /* RX CDR present, bypass supported */
328 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
329
330 if (cable_power_class <= QSFP_POWER_CLASS_3) {
331 /* Power class <= 3, ignore config & turn RX CDR on */
332 *cdr_ctrl_byte |= 0xF;
333 return;
334 }
335
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800336 get_platform_config_field(
337 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
338 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR_APPLY,
339 &rx_preset, 4);
340
341 if (!rx_preset) {
342 dd_dev_info(
343 ppd->dd,
344 "%s: RX_CDR_APPLY is set to disabled\n",
345 __func__);
346 return;
347 }
348 get_platform_config_field(
349 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
350 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR,
351 &rx_preset, 4);
352
353 /* Expand cdr setting to all 4 lanes */
354 rx_preset = (rx_preset | (rx_preset << 1) |
355 (rx_preset << 2) | (rx_preset << 3));
356
357 if (rx_preset) {
358 *cdr_ctrl_byte |= rx_preset;
359 } else {
360 *cdr_ctrl_byte &= rx_preset;
361 /* Preserve current TX CDR status */
362 *cdr_ctrl_byte |= (cache[QSFP_CDR_CTRL_BYTE_OFFS] & 0xF0);
363 }
364}
365
366static void apply_tx_cdr(struct hfi1_pportdata *ppd,
367 u32 tx_preset_index,
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700368 u8 *cdr_ctrl_byte)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800369{
370 u32 tx_preset;
371 u8 *cache = ppd->qsfp_info.cache;
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700372 int cable_power_class;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800373
374 if (!((cache[QSFP_MOD_PWR_OFFS] & 0x8) &&
375 (cache[QSFP_CDR_INFO_OFFS] & 0x80)))
376 return;
377
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700378 /* TX CDR present, bypass supported */
379 cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
380
381 if (cable_power_class <= QSFP_POWER_CLASS_3) {
382 /* Power class <= 3, ignore config & turn TX CDR on */
383 *cdr_ctrl_byte |= 0xF0;
384 return;
385 }
386
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800387 get_platform_config_field(
388 ppd->dd,
389 PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
390 TX_PRESET_TABLE_QSFP_TX_CDR_APPLY, &tx_preset, 4);
391
392 if (!tx_preset) {
393 dd_dev_info(
394 ppd->dd,
395 "%s: TX_CDR_APPLY is set to disabled\n",
396 __func__);
397 return;
398 }
399 get_platform_config_field(
400 ppd->dd,
401 PLATFORM_CONFIG_TX_PRESET_TABLE,
402 tx_preset_index,
403 TX_PRESET_TABLE_QSFP_TX_CDR, &tx_preset, 4);
404
405 /* Expand cdr setting to all 4 lanes */
406 tx_preset = (tx_preset | (tx_preset << 1) |
407 (tx_preset << 2) | (tx_preset << 3));
408
409 if (tx_preset)
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700410 *cdr_ctrl_byte |= (tx_preset << 4);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800411 else
412 /* Preserve current/determined RX CDR status */
Easwar Hariharan145dd2b2016-04-12 11:25:31 -0700413 *cdr_ctrl_byte &= ((tx_preset << 4) | 0xF);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800414}
415
416static void apply_cdr_settings(
417 struct hfi1_pportdata *ppd, u32 rx_preset_index,
418 u32 tx_preset_index)
419{
420 u8 *cache = ppd->qsfp_info.cache;
421 u8 cdr_ctrl_byte = cache[QSFP_CDR_CTRL_BYTE_OFFS];
422
423 apply_rx_cdr(ppd, rx_preset_index, &cdr_ctrl_byte);
424
425 apply_tx_cdr(ppd, tx_preset_index, &cdr_ctrl_byte);
426
427 qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_CDR_CTRL_BYTE_OFFS,
428 &cdr_ctrl_byte, 1);
429}
430
431static void apply_tx_eq_auto(struct hfi1_pportdata *ppd)
432{
433 u8 *cache = ppd->qsfp_info.cache;
434 u8 tx_eq;
435
436 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x8))
437 return;
438 /* Disable adaptive TX EQ if present */
439 tx_eq = cache[(128 * 3) + 241];
440 tx_eq &= 0xF0;
441 qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 241, &tx_eq, 1);
442}
443
444static void apply_tx_eq_prog(struct hfi1_pportdata *ppd, u32 tx_preset_index)
445{
446 u8 *cache = ppd->qsfp_info.cache;
447 u32 tx_preset;
448 u8 tx_eq;
449
450 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x4))
451 return;
452
453 get_platform_config_field(
454 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
455 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ_APPLY,
456 &tx_preset, 4);
457 if (!tx_preset) {
458 dd_dev_info(
459 ppd->dd,
460 "%s: TX_EQ_APPLY is set to disabled\n",
461 __func__);
462 return;
463 }
464 get_platform_config_field(
465 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
466 tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ,
467 &tx_preset, 4);
468
469 if (((cache[(128 * 3) + 224] & 0xF0) >> 4) < tx_preset) {
470 dd_dev_info(
471 ppd->dd,
472 "%s: TX EQ %x unsupported\n",
473 __func__, tx_preset);
474
475 dd_dev_info(
476 ppd->dd,
477 "%s: Applying EQ %x\n",
478 __func__, cache[608] & 0xF0);
479
480 tx_preset = (cache[608] & 0xF0) >> 4;
481 }
482
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);
486}
487
488static void apply_rx_eq_emp(struct hfi1_pportdata *ppd, u32 rx_preset_index)
489{
490 u32 rx_preset;
491 u8 rx_eq, *cache = ppd->qsfp_info.cache;
492
493 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x2))
494 return;
495 get_platform_config_field(
496 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
497 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP_APPLY,
498 &rx_preset, 4);
499
500 if (!rx_preset) {
501 dd_dev_info(
502 ppd->dd,
503 "%s: RX_EMP_APPLY is set to disabled\n",
504 __func__);
505 return;
506 }
507 get_platform_config_field(
508 ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
509 rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP,
510 &rx_preset, 4);
511
512 if ((cache[(128 * 3) + 224] & 0xF) < rx_preset) {
513 dd_dev_info(
514 ppd->dd,
515 "%s: Requested RX EMP %x\n",
516 __func__, rx_preset);
517
518 dd_dev_info(
519 ppd->dd,
520 "%s: Applying supported EMP %x\n",
521 __func__, cache[608] & 0xF);
522
523 rx_preset = cache[608] & 0xF;
524 }
525
526 rx_eq = rx_preset | (rx_preset << 4);
527
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);
530}
531
532static void apply_eq_settings(struct hfi1_pportdata *ppd,
533 u32 rx_preset_index, u32 tx_preset_index)
534{
535 u8 *cache = ppd->qsfp_info.cache;
536
537 /* no point going on w/o a page 3 */
538 if (cache[2] & 4) {
539 dd_dev_info(ppd->dd,
540 "%s: Upper page 03 not present\n",
541 __func__);
542 return;
543 }
544
545 apply_tx_eq_auto(ppd);
546
547 apply_tx_eq_prog(ppd, tx_preset_index);
548
549 apply_rx_eq_emp(ppd, rx_preset_index);
550}
551
552static void apply_rx_amplitude_settings(
553 struct hfi1_pportdata *ppd, u32 rx_preset_index,
554 u32 tx_preset_index)
555{
556 u32 rx_preset;
557 u8 rx_amp = 0, i = 0, preferred = 0, *cache = ppd->qsfp_info.cache;
558
559 /* no point going on w/o a page 3 */
560 if (cache[2] & 4) {
561 dd_dev_info(ppd->dd,
562 "%s: Upper page 03 not present\n",
563 __func__);
564 return;
565 }
566 if (!(cache[QSFP_EQ_INFO_OFFS] & 0x1)) {
567 dd_dev_info(ppd->dd,
568 "%s: RX_AMP_APPLY is set to disabled\n",
569 __func__);
570 return;
571 }
572
573 get_platform_config_field(ppd->dd,
574 PLATFORM_CONFIG_RX_PRESET_TABLE,
575 rx_preset_index,
576 RX_PRESET_TABLE_QSFP_RX_AMP_APPLY,
577 &rx_preset, 4);
578
579 if (!rx_preset) {
580 dd_dev_info(ppd->dd,
581 "%s: RX_AMP_APPLY is set to disabled\n",
582 __func__);
583 return;
584 }
585 get_platform_config_field(ppd->dd,
586 PLATFORM_CONFIG_RX_PRESET_TABLE,
587 rx_preset_index,
588 RX_PRESET_TABLE_QSFP_RX_AMP,
589 &rx_preset, 4);
590
591 dd_dev_info(ppd->dd,
592 "%s: Requested RX AMP %x\n",
593 __func__,
594 rx_preset);
595
596 for (i = 0; i < 4; i++) {
597 if (cache[(128 * 3) + 225] & (1 << i)) {
598 preferred = i;
599 if (preferred == rx_preset)
600 break;
601 }
602 }
603
604 /*
605 * Verify that preferred RX amplitude is not just a
606 * fall through of the default
607 */
608 if (!preferred && !(cache[(128 * 3) + 225] & 0x1)) {
609 dd_dev_info(ppd->dd, "No supported RX AMP, not applying\n");
610 return;
611 }
612
613 dd_dev_info(ppd->dd,
614 "%s: Applying RX AMP %x\n", __func__, preferred);
615
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);
619}
620
621#define OPA_INVALID_INDEX 0xFFF
622
Easwar Hariharan97167e82016-02-09 14:29:22 -0800623static void apply_tx_lanes(struct hfi1_pportdata *ppd, u8 field_id,
624 u32 config_data, const char *message)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800625{
626 u8 i;
627 int ret = HCMD_SUCCESS;
628
629 for (i = 0; i < 4; i++) {
Easwar Hariharan97167e82016-02-09 14:29:22 -0800630 ret = load_8051_config(ppd->dd, field_id, i, config_data);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800631 if (ret != HCMD_SUCCESS) {
632 dd_dev_err(
633 ppd->dd,
634 "%s: %s for lane %u failed\n",
635 message, __func__, i);
636 }
637 }
638}
639
Dean Luick52130062016-12-07 19:33:13 -0800640/*
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.
643 *
644 * Summary of the logic:
645 *
646 * if (QSFP and QSFP_TYPE == AOC and QSFP_POWER_CLASS < 4)
647 * return 0xe
648 * return 0; // leave at default
649 */
650static u8 aoc_low_power_setting(struct hfi1_pportdata *ppd)
651{
652 u8 *cache = ppd->qsfp_info.cache;
653 int power_class;
654
655 /* QSFP only */
656 if (ppd->port_type != PORT_TYPE_QSFP)
657 return 0; /* leave at default */
658
659 /* active optical cables only */
660 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
661 case 0x0 ... 0x9: /* fallthrough */
662 case 0xC: /* fallthrough */
663 case 0xE:
664 /* active AOC */
665 power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
666 if (power_class < QSFP_POWER_CLASS_4)
667 return 0xe;
668 }
669 return 0; /* leave at default */
670}
671
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800672static void apply_tunings(
673 struct hfi1_pportdata *ppd, u32 tx_preset_index,
674 u8 tuning_method, u32 total_atten, u8 limiting_active)
675{
676 int ret = 0;
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;
680
Easwar Hariharan97167e82016-02-09 14:29:22 -0800681 /* Pass tuning method to 8051 */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800682 read_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
683 &config_data);
Dean Luickf6de3d32016-05-24 12:51:00 -0700684 config_data &= ~(0xff << TUNING_METHOD_SHIFT);
685 config_data |= ((u32)tuning_method << TUNING_METHOD_SHIFT);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800686 ret = load_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
687 config_data);
688 if (ret != HCMD_SUCCESS)
689 dd_dev_err(ppd->dd, "%s: Failed to set tuning method\n",
690 __func__);
691
Easwar Hariharan97167e82016-02-09 14:29:22 -0800692 /* 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");
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800696
Easwar Hariharan97167e82016-02-09 14:29:22 -0800697 /* 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 */
Easwar Hariharan27a340f2016-05-12 10:22:45 -0700707 config_data &= ~(u32)0xFF;
708 config_data |= external_device_config;
Easwar Hariharan97167e82016-02-09 14:29:22 -0800709 ret = load_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
710 GENERAL_CONFIG, config_data);
711 if (ret != HCMD_SUCCESS)
712 dd_dev_info(ppd->dd,
713 "%s: Failed set ext device config params\n",
714 __func__);
715 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800716
Easwar Hariharan97167e82016-02-09 14:29:22 -0800717 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",
720 __func__);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800721 return;
Easwar Hariharan97167e82016-02-09 14:29:22 -0800722 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800723
Easwar Hariharan97167e82016-02-09 14:29:22 -0800724 /* Following for limiting active channels only */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800725 get_platform_config_field(
726 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
727 TX_PRESET_TABLE_PRECUR, &tx_preset, 4);
728 precur = tx_preset;
729
730 get_platform_config_field(
731 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
732 tx_preset_index, TX_PRESET_TABLE_ATTN, &tx_preset, 4);
733 attn = tx_preset;
734
735 get_platform_config_field(
736 ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
737 tx_preset_index, TX_PRESET_TABLE_POSTCUR, &tx_preset, 4);
738 postcur = tx_preset;
739
Dean Luick52130062016-12-07 19:33:13 -0800740 /*
741 * NOTES:
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.
748 */
749 config_data = precur | (attn << 8) | (postcur << 16) |
750 (aoc_low_power_setting(ppd) << 24);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800751
Easwar Hariharan97167e82016-02-09 14:29:22 -0800752 apply_tx_lanes(ppd, TX_EQ_SETTINGS, config_data,
753 "Applying TX settings");
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800754}
755
Dean Luicke4e0e392016-04-12 11:28:36 -0700756/* Must be holding the QSFP i2c resource */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800757static int tune_active_qsfp(struct hfi1_pportdata *ppd, u32 *ptr_tx_preset,
758 u32 *ptr_rx_preset, u32 *ptr_total_atten)
759{
Dean Luick765a6fa2016-03-05 08:50:06 -0800760 int ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800761 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
762 u8 *cache = ppd->qsfp_info.cache;
763
764 ppd->qsfp_info.limiting_active = 1;
765
766 ret = set_qsfp_tx(ppd, 0);
767 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700768 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800769
770 ret = qual_power(ppd);
771 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700772 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800773
774 ret = qual_bitrate(ppd);
775 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700776 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800777
Easwar Hariharanb5e71012016-07-25 13:40:03 -0700778 /*
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.
782 */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800783 if (ppd->qsfp_info.reset_needed) {
784 reset_qsfp(ppd);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800785 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
786 } else {
787 ppd->qsfp_info.reset_needed = 1;
788 }
789
790 ret = set_qsfp_high_power(ppd);
791 if (ret)
Dean Luicke4e0e392016-04-12 11:28:36 -0700792 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800793
794 if (cache[QSFP_EQ_INFO_OFFS] & 0x4) {
795 ret = get_platform_config_field(
796 ppd->dd,
797 PLATFORM_CONFIG_PORT_TABLE, 0,
798 PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ,
799 ptr_tx_preset, 4);
800 if (ret) {
801 *ptr_tx_preset = OPA_INVALID_INDEX;
Dean Luicke4e0e392016-04-12 11:28:36 -0700802 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800803 }
804 } else {
805 ret = get_platform_config_field(
806 ppd->dd,
807 PLATFORM_CONFIG_PORT_TABLE, 0,
808 PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ,
809 ptr_tx_preset, 4);
810 if (ret) {
811 *ptr_tx_preset = OPA_INVALID_INDEX;
Dean Luicke4e0e392016-04-12 11:28:36 -0700812 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800813 }
814 }
815
816 ret = get_platform_config_field(
817 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
818 PORT_TABLE_RX_PRESET_IDX, ptr_rx_preset, 4);
819 if (ret) {
820 *ptr_rx_preset = OPA_INVALID_INDEX;
Dean Luicke4e0e392016-04-12 11:28:36 -0700821 return ret;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800822 }
823
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);
832
833 apply_cdr_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
834
835 apply_eq_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
836
837 apply_rx_amplitude_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
838
839 ret = set_qsfp_tx(ppd, 1);
Dean Luick765a6fa2016-03-05 08:50:06 -0800840
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800841 return ret;
842}
843
844static 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)
847{
848 u32 cable_atten = 0, remote_atten = 0, platform_atten = 0;
849 u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
850 int ret = 0;
851 u8 *cache = ppd->qsfp_info.cache;
852
853 switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
854 case 0xA ... 0xB:
855 ret = get_platform_config_field(
856 ppd->dd,
857 PLATFORM_CONFIG_PORT_TABLE, 0,
858 PORT_TABLE_LOCAL_ATTEN_25G,
859 &platform_atten, 4);
860 if (ret)
861 return ret;
862
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];
868
869 /* Fallback to configured attenuation if cable memory is bad */
870 if (cable_atten == 0 || cable_atten > 36) {
871 ret = get_platform_config_field(
872 ppd->dd,
873 PLATFORM_CONFIG_SYSTEM_TABLE, 0,
874 SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G,
875 &cable_atten, 4);
876 if (ret)
877 return ret;
878 }
879
880 ret = get_platform_config_field(
881 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
882 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
883 if (ret)
884 return ret;
885
886 *ptr_total_atten = platform_atten + cable_atten + remote_atten;
887
888 *ptr_tuning_method = OPA_PASSIVE_TUNING;
889 break;
890 case 0x0 ... 0x9: /* fallthrough */
891 case 0xC: /* fallthrough */
892 case 0xE:
893 ret = tune_active_qsfp(ppd, ptr_tx_preset, ptr_rx_preset,
894 ptr_total_atten);
895 if (ret)
896 return ret;
897
898 *ptr_tuning_method = OPA_ACTIVE_TUNING;
899 break;
900 case 0xD: /* fallthrough */
901 case 0xF:
902 default:
903 dd_dev_info(ppd->dd, "%s: Unknown/unsupported cable\n",
904 __func__);
905 break;
906 }
907 return ret;
908}
909
910/*
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.
915 */
916void tune_serdes(struct hfi1_pportdata *ppd)
917{
918 int ret = 0;
919 u32 total_atten = 0;
920 u32 remote_atten = 0, platform_atten = 0;
921 u32 rx_preset_index, tx_preset_index;
Easwar Hariharan97167e82016-02-09 14:29:22 -0800922 u8 tuning_method = 0, limiting_active = 0;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800923 struct hfi1_devdata *dd = ppd->dd;
924
925 rx_preset_index = OPA_INVALID_INDEX;
926 tx_preset_index = OPA_INVALID_INDEX;
927
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);
933
Easwar Hariharan715c4302016-02-03 14:32:14 -0800934 /* Skip the tuning for testing (loopback != none) and simulations */
935 if (loopback != LOOPBACK_NONE ||
Easwar Hariharanc3838b32016-02-09 14:29:13 -0800936 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800937 ppd->driver_link_ready = 1;
938 return;
939 }
940
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800941 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",
946 __func__);
947 goto bail;
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);
953
954 get_platform_config_field(
955 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
956 PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
957
958 total_atten = platform_atten + remote_atten;
959
960 tuning_method = OPA_PASSIVE_TUNING;
961 break;
962 case PORT_TYPE_VARIABLE:
963 if (qsfp_mod_present(ppd)) {
964 /*
965 * platform_atten, remote_atten pre-zeroed to
966 * catch error
967 */
968 get_platform_config_field(
969 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
970 PORT_TABLE_LOCAL_ATTEN_25G,
971 &platform_atten, 4);
972
973 get_platform_config_field(
974 ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
975 PORT_TABLE_REMOTE_ATTEN_25G,
976 &remote_atten, 4);
977
978 total_atten = platform_atten + remote_atten;
979
980 tuning_method = OPA_PASSIVE_TUNING;
Easwar Hariharan623bba22016-04-12 11:25:57 -0700981 } else {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800982 ppd->offline_disabled_reason =
983 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_CHASSIS_CONFIG);
Easwar Hariharan623bba22016-04-12 11:25:57 -0700984 goto bail;
985 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800986 break;
987 case PORT_TYPE_QSFP:
988 if (qsfp_mod_present(ppd)) {
Dean Luicke4e0e392016-04-12 11:28:36 -0700989 ret = acquire_chip_resource(ppd->dd,
990 qsfp_resource(ppd->dd),
991 QSFP_WAIT);
992 if (ret) {
993 dd_dev_err(ppd->dd, "%s: hfi%d: cannot lock i2c chain\n",
994 __func__, (int)ppd->dd->hfi1_id);
995 goto bail;
996 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800997 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
998
999 if (ppd->qsfp_info.cache_valid) {
1000 ret = tune_qsfp(ppd,
1001 &tx_preset_index,
1002 &rx_preset_index,
1003 &tuning_method,
1004 &total_atten);
Easwar Hariharanc3838b32016-02-09 14:29:13 -08001005
1006 /*
1007 * We may have modified the QSFP memory, so
1008 * update the cache to reflect the changes
1009 */
1010 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
Easwar Hariharan97167e82016-02-09 14:29:22 -08001011 limiting_active =
1012 ppd->qsfp_info.limiting_active;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001013 } else {
1014 dd_dev_err(dd,
1015 "%s: Reading QSFP memory failed\n",
1016 __func__);
Dean Luicke4e0e392016-04-12 11:28:36 -07001017 ret = -EINVAL; /* a fail indication */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001018 }
Dean Luicke4e0e392016-04-12 11:28:36 -07001019 release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
1020 if (ret)
1021 goto bail;
Easwar Hariharan623bba22016-04-12 11:25:57 -07001022 } else {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001023 ppd->offline_disabled_reason =
1024 HFI1_ODR_MASK(
Easwar Hariharane1bf0d52016-02-03 14:36:58 -08001025 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
Easwar Hariharan623bba22016-04-12 11:25:57 -07001026 goto bail;
1027 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001028 break;
1029 default:
1030 dd_dev_info(ppd->dd, "%s: Unknown port type\n", __func__);
Easwar Hariharan97167e82016-02-09 14:29:22 -08001031 ppd->port_type = PORT_TYPE_UNKNOWN;
1032 tuning_method = OPA_UNKNOWN_TUNING;
1033 total_atten = 0;
1034 limiting_active = 0;
1035 tx_preset_index = OPA_INVALID_INDEX;
1036 break;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001037 }
Easwar Hariharan97167e82016-02-09 14:29:22 -08001038
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001039 if (ppd->offline_disabled_reason ==
1040 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
1041 apply_tunings(ppd, tx_preset_index, tuning_method,
Easwar Hariharan97167e82016-02-09 14:29:22 -08001042 total_atten, limiting_active);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001043
Easwar Hariharanc3838b32016-02-09 14:29:13 -08001044 if (!ret)
1045 ppd->driver_link_ready = 1;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08001046
1047 return;
1048bail:
1049 ppd->driver_link_ready = 0;
1050}