xref: /linux/drivers/infiniband/hw/hfi1/platform.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1*3ec648c6SKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2f48ad614SDennis Dalessandro /*
3f48ad614SDennis Dalessandro  * Copyright(c) 2015, 2016 Intel Corporation.
4f48ad614SDennis Dalessandro  */
5f48ad614SDennis Dalessandro 
676ae6222SJakub Byczkowski #include <linux/firmware.h>
776ae6222SJakub Byczkowski 
8f48ad614SDennis Dalessandro #include "hfi.h"
9f48ad614SDennis Dalessandro #include "efivar.h"
10e83eba21SDean Luick #include "eprom.h"
11f48ad614SDennis Dalessandro 
1276ae6222SJakub Byczkowski #define DEFAULT_PLATFORM_CONFIG_NAME "hfi1_platform.dat"
1376ae6222SJakub Byczkowski 
validate_scratch_checksum(struct hfi1_devdata * dd)14fe4d9243SEaswar Hariharan static int validate_scratch_checksum(struct hfi1_devdata *dd)
15fe4d9243SEaswar Hariharan {
16fe4d9243SEaswar Hariharan 	u64 checksum = 0, temp_scratch = 0;
17fe4d9243SEaswar Hariharan 	int i, j, version;
18fe4d9243SEaswar Hariharan 
19fe4d9243SEaswar Hariharan 	temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
20fe4d9243SEaswar Hariharan 	version = (temp_scratch & BITMAP_VERSION_SMASK) >> BITMAP_VERSION_SHIFT;
21fe4d9243SEaswar Hariharan 
22fe4d9243SEaswar Hariharan 	/* Prevent power on default of all zeroes from passing checksum */
23c822652eSJan Sokolowski 	if (!version) {
24c822652eSJan Sokolowski 		dd_dev_err(dd, "%s: Config bitmap uninitialized\n", __func__);
25c822652eSJan Sokolowski 		dd_dev_err(dd,
26c822652eSJan Sokolowski 			   "%s: Please update your BIOS to support active channels\n",
27c822652eSJan Sokolowski 			   __func__);
28fe4d9243SEaswar Hariharan 		return 0;
29c822652eSJan Sokolowski 	}
30fe4d9243SEaswar Hariharan 
31fe4d9243SEaswar Hariharan 	/*
32fe4d9243SEaswar Hariharan 	 * ASIC scratch 0 only contains the checksum and bitmap version as
33fe4d9243SEaswar Hariharan 	 * fields of interest, both of which are handled separately from the
34fe4d9243SEaswar Hariharan 	 * loop below, so skip it
35fe4d9243SEaswar Hariharan 	 */
36fe4d9243SEaswar Hariharan 	checksum += version;
37fe4d9243SEaswar Hariharan 	for (i = 1; i < ASIC_NUM_SCRATCH; i++) {
38fe4d9243SEaswar Hariharan 		temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH + (8 * i));
39fe4d9243SEaswar Hariharan 		for (j = sizeof(u64); j != 0; j -= 2) {
40fe4d9243SEaswar Hariharan 			checksum += (temp_scratch & 0xFFFF);
41fe4d9243SEaswar Hariharan 			temp_scratch >>= 16;
42fe4d9243SEaswar Hariharan 		}
43fe4d9243SEaswar Hariharan 	}
44fe4d9243SEaswar Hariharan 
45fe4d9243SEaswar Hariharan 	while (checksum >> 16)
46fe4d9243SEaswar Hariharan 		checksum = (checksum & CHECKSUM_MASK) + (checksum >> 16);
47fe4d9243SEaswar Hariharan 
48fe4d9243SEaswar Hariharan 	temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH);
49fe4d9243SEaswar Hariharan 	temp_scratch &= CHECKSUM_SMASK;
50fe4d9243SEaswar Hariharan 	temp_scratch >>= CHECKSUM_SHIFT;
51fe4d9243SEaswar Hariharan 
52fe4d9243SEaswar Hariharan 	if (checksum + temp_scratch == 0xFFFF)
53fe4d9243SEaswar Hariharan 		return 1;
54c822652eSJan Sokolowski 
55c822652eSJan Sokolowski 	dd_dev_err(dd, "%s: Configuration bitmap corrupted\n", __func__);
56fe4d9243SEaswar Hariharan 	return 0;
57fe4d9243SEaswar Hariharan }
58fe4d9243SEaswar Hariharan 
save_platform_config_fields(struct hfi1_devdata * dd)59fe4d9243SEaswar Hariharan static void save_platform_config_fields(struct hfi1_devdata *dd)
60fe4d9243SEaswar Hariharan {
61fe4d9243SEaswar Hariharan 	struct hfi1_pportdata *ppd = dd->pport;
62fe4d9243SEaswar Hariharan 	u64 temp_scratch = 0, temp_dest = 0;
63fe4d9243SEaswar Hariharan 
64fe4d9243SEaswar Hariharan 	temp_scratch = read_csr(dd, ASIC_CFG_SCRATCH_1);
65fe4d9243SEaswar Hariharan 
66fe4d9243SEaswar Hariharan 	temp_dest = temp_scratch &
67fe4d9243SEaswar Hariharan 		    (dd->hfi1_id ? PORT1_PORT_TYPE_SMASK :
68fe4d9243SEaswar Hariharan 		     PORT0_PORT_TYPE_SMASK);
69fe4d9243SEaswar Hariharan 	ppd->port_type = temp_dest >>
70fe4d9243SEaswar Hariharan 			 (dd->hfi1_id ? PORT1_PORT_TYPE_SHIFT :
71fe4d9243SEaswar Hariharan 			  PORT0_PORT_TYPE_SHIFT);
72fe4d9243SEaswar Hariharan 
73fe4d9243SEaswar Hariharan 	temp_dest = temp_scratch &
74fe4d9243SEaswar Hariharan 		    (dd->hfi1_id ? PORT1_LOCAL_ATTEN_SMASK :
75fe4d9243SEaswar Hariharan 		     PORT0_LOCAL_ATTEN_SMASK);
76fe4d9243SEaswar Hariharan 	ppd->local_atten = temp_dest >>
77fe4d9243SEaswar Hariharan 			   (dd->hfi1_id ? PORT1_LOCAL_ATTEN_SHIFT :
78fe4d9243SEaswar Hariharan 			    PORT0_LOCAL_ATTEN_SHIFT);
79fe4d9243SEaswar Hariharan 
80fe4d9243SEaswar Hariharan 	temp_dest = temp_scratch &
81fe4d9243SEaswar Hariharan 		    (dd->hfi1_id ? PORT1_REMOTE_ATTEN_SMASK :
82fe4d9243SEaswar Hariharan 		     PORT0_REMOTE_ATTEN_SMASK);
83fe4d9243SEaswar Hariharan 	ppd->remote_atten = temp_dest >>
84fe4d9243SEaswar Hariharan 			    (dd->hfi1_id ? PORT1_REMOTE_ATTEN_SHIFT :
85fe4d9243SEaswar Hariharan 			     PORT0_REMOTE_ATTEN_SHIFT);
86fe4d9243SEaswar Hariharan 
87fe4d9243SEaswar Hariharan 	temp_dest = temp_scratch &
88fe4d9243SEaswar Hariharan 		    (dd->hfi1_id ? PORT1_DEFAULT_ATTEN_SMASK :
89fe4d9243SEaswar Hariharan 		     PORT0_DEFAULT_ATTEN_SMASK);
90fe4d9243SEaswar Hariharan 	ppd->default_atten = temp_dest >>
91fe4d9243SEaswar Hariharan 			     (dd->hfi1_id ? PORT1_DEFAULT_ATTEN_SHIFT :
92fe4d9243SEaswar Hariharan 			      PORT0_DEFAULT_ATTEN_SHIFT);
93fe4d9243SEaswar Hariharan 
94fe4d9243SEaswar Hariharan 	temp_scratch = read_csr(dd, dd->hfi1_id ? ASIC_CFG_SCRATCH_3 :
95fe4d9243SEaswar Hariharan 				ASIC_CFG_SCRATCH_2);
96fe4d9243SEaswar Hariharan 
97fe4d9243SEaswar Hariharan 	ppd->tx_preset_eq = (temp_scratch & TX_EQ_SMASK) >> TX_EQ_SHIFT;
98fe4d9243SEaswar Hariharan 	ppd->tx_preset_noeq = (temp_scratch & TX_NO_EQ_SMASK) >> TX_NO_EQ_SHIFT;
99fe4d9243SEaswar Hariharan 	ppd->rx_preset = (temp_scratch & RX_SMASK) >> RX_SHIFT;
100fe4d9243SEaswar Hariharan 
101fe4d9243SEaswar Hariharan 	ppd->max_power_class = (temp_scratch & QSFP_MAX_POWER_SMASK) >>
102fe4d9243SEaswar Hariharan 				QSFP_MAX_POWER_SHIFT;
10391618604SJakub Byczkowski 
10491618604SJakub Byczkowski 	ppd->config_from_scratch = true;
105fe4d9243SEaswar Hariharan }
106fe4d9243SEaswar Hariharan 
get_platform_config(struct hfi1_devdata * dd)107f48ad614SDennis Dalessandro void get_platform_config(struct hfi1_devdata *dd)
108f48ad614SDennis Dalessandro {
109f48ad614SDennis Dalessandro 	int ret = 0;
110f48ad614SDennis Dalessandro 	u8 *temp_platform_config = NULL;
111e83eba21SDean Luick 	u32 esize;
11276ae6222SJakub Byczkowski 	const struct firmware *platform_config_file = NULL;
113e83eba21SDean Luick 
114fe4d9243SEaswar Hariharan 	if (is_integrated(dd)) {
115fe4d9243SEaswar Hariharan 		if (validate_scratch_checksum(dd)) {
116fe4d9243SEaswar Hariharan 			save_platform_config_fields(dd);
117fe4d9243SEaswar Hariharan 			return;
118fe4d9243SEaswar Hariharan 		}
119fe4d9243SEaswar Hariharan 	} else {
120fe4d9243SEaswar Hariharan 		ret = eprom_read_platform_config(dd,
121fe4d9243SEaswar Hariharan 						 (void **)&temp_platform_config,
122e83eba21SDean Luick 						 &esize);
123e83eba21SDean Luick 		if (!ret) {
124e83eba21SDean Luick 			/* success */
125fe4d9243SEaswar Hariharan 			dd->platform_config.data = temp_platform_config;
126fe4d9243SEaswar Hariharan 			dd->platform_config.size = esize;
127fe4d9243SEaswar Hariharan 			return;
128e83eba21SDean Luick 		}
129fe4d9243SEaswar Hariharan 	}
130fe4d9243SEaswar Hariharan 	dd_dev_err(dd,
131fe4d9243SEaswar Hariharan 		   "%s: Failed to get platform config, falling back to sub-optimal default file\n",
132f48ad614SDennis Dalessandro 		   __func__);
13376ae6222SJakub Byczkowski 
13476ae6222SJakub Byczkowski 	ret = request_firmware(&platform_config_file,
13576ae6222SJakub Byczkowski 			       DEFAULT_PLATFORM_CONFIG_NAME,
13676ae6222SJakub Byczkowski 			       &dd->pcidev->dev);
13776ae6222SJakub Byczkowski 	if (ret) {
13876ae6222SJakub Byczkowski 		dd_dev_err(dd,
13976ae6222SJakub Byczkowski 			   "%s: No default platform config file found\n",
14076ae6222SJakub Byczkowski 			   __func__);
14176ae6222SJakub Byczkowski 		return;
14276ae6222SJakub Byczkowski 	}
14376ae6222SJakub Byczkowski 
14476ae6222SJakub Byczkowski 	/*
14576ae6222SJakub Byczkowski 	 * Allocate separate memory block to store data and free firmware
14676ae6222SJakub Byczkowski 	 * structure. This allows free_platform_config to treat EPROM and
14776ae6222SJakub Byczkowski 	 * fallback configs in the same manner.
14876ae6222SJakub Byczkowski 	 */
14976ae6222SJakub Byczkowski 	dd->platform_config.data = kmemdup(platform_config_file->data,
15076ae6222SJakub Byczkowski 					   platform_config_file->size,
15176ae6222SJakub Byczkowski 					   GFP_KERNEL);
15276ae6222SJakub Byczkowski 	dd->platform_config.size = platform_config_file->size;
15376ae6222SJakub Byczkowski 	release_firmware(platform_config_file);
154f48ad614SDennis Dalessandro }
155f48ad614SDennis Dalessandro 
free_platform_config(struct hfi1_devdata * dd)156f48ad614SDennis Dalessandro void free_platform_config(struct hfi1_devdata *dd)
157f48ad614SDennis Dalessandro {
15876ae6222SJakub Byczkowski 	/* Release memory allocated for eprom or fallback file read. */
159f48ad614SDennis Dalessandro 	kfree(dd->platform_config.data);
160e9777ad4SSebastian Sanchez 	dd->platform_config.data = NULL;
161f48ad614SDennis Dalessandro }
162f48ad614SDennis Dalessandro 
get_port_type(struct hfi1_pportdata * ppd)163f48ad614SDennis Dalessandro void get_port_type(struct hfi1_pportdata *ppd)
164f48ad614SDennis Dalessandro {
165f48ad614SDennis Dalessandro 	int ret;
166fe4d9243SEaswar Hariharan 	u32 temp;
167f48ad614SDennis Dalessandro 
168f48ad614SDennis Dalessandro 	ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
169fe4d9243SEaswar Hariharan 					PORT_TABLE_PORT_TYPE, &temp,
170f48ad614SDennis Dalessandro 					4);
171fe4d9243SEaswar Hariharan 	if (ret) {
172f48ad614SDennis Dalessandro 		ppd->port_type = PORT_TYPE_UNKNOWN;
173fe4d9243SEaswar Hariharan 		return;
174fe4d9243SEaswar Hariharan 	}
175fe4d9243SEaswar Hariharan 	ppd->port_type = temp;
176f48ad614SDennis Dalessandro }
177f48ad614SDennis Dalessandro 
set_qsfp_tx(struct hfi1_pportdata * ppd,int on)178f48ad614SDennis Dalessandro int set_qsfp_tx(struct hfi1_pportdata *ppd, int on)
179f48ad614SDennis Dalessandro {
180f48ad614SDennis Dalessandro 	u8 tx_ctrl_byte = on ? 0x0 : 0xF;
181f48ad614SDennis Dalessandro 	int ret = 0;
182f48ad614SDennis Dalessandro 
183f48ad614SDennis Dalessandro 	ret = qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_TX_CTRL_BYTE_OFFS,
184f48ad614SDennis Dalessandro 			 &tx_ctrl_byte, 1);
185f48ad614SDennis Dalessandro 	/* we expected 1, so consider 0 an error */
186f48ad614SDennis Dalessandro 	if (ret == 0)
187f48ad614SDennis Dalessandro 		ret = -EIO;
188f48ad614SDennis Dalessandro 	else if (ret == 1)
189f48ad614SDennis Dalessandro 		ret = 0;
190f48ad614SDennis Dalessandro 	return ret;
191f48ad614SDennis Dalessandro }
192f48ad614SDennis Dalessandro 
qual_power(struct hfi1_pportdata * ppd)193f48ad614SDennis Dalessandro static int qual_power(struct hfi1_pportdata *ppd)
194f48ad614SDennis Dalessandro {
195f48ad614SDennis Dalessandro 	u32 cable_power_class = 0, power_class_max = 0;
196f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
197f48ad614SDennis Dalessandro 	int ret = 0;
198f48ad614SDennis Dalessandro 
199f48ad614SDennis Dalessandro 	ret = get_platform_config_field(
200f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_SYSTEM_TABLE, 0,
201f48ad614SDennis Dalessandro 		SYSTEM_TABLE_QSFP_POWER_CLASS_MAX, &power_class_max, 4);
202f48ad614SDennis Dalessandro 	if (ret)
203f48ad614SDennis Dalessandro 		return ret;
204f48ad614SDennis Dalessandro 
205f48ad614SDennis Dalessandro 	cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
206f48ad614SDennis Dalessandro 
207f48ad614SDennis Dalessandro 	if (cable_power_class > power_class_max)
208f48ad614SDennis Dalessandro 		ppd->offline_disabled_reason =
209f48ad614SDennis Dalessandro 			HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY);
210f48ad614SDennis Dalessandro 
211f48ad614SDennis Dalessandro 	if (ppd->offline_disabled_reason ==
212f48ad614SDennis Dalessandro 			HFI1_ODR_MASK(OPA_LINKDOWN_REASON_POWER_POLICY)) {
213b4e9e2f0SSebastian Sanchez 		dd_dev_err(
214f48ad614SDennis Dalessandro 			ppd->dd,
215f48ad614SDennis Dalessandro 			"%s: Port disabled due to system power restrictions\n",
216f48ad614SDennis Dalessandro 			__func__);
217f48ad614SDennis Dalessandro 		ret = -EPERM;
218f48ad614SDennis Dalessandro 	}
219f48ad614SDennis Dalessandro 	return ret;
220f48ad614SDennis Dalessandro }
221f48ad614SDennis Dalessandro 
qual_bitrate(struct hfi1_pportdata * ppd)222f48ad614SDennis Dalessandro static int qual_bitrate(struct hfi1_pportdata *ppd)
223f48ad614SDennis Dalessandro {
224f48ad614SDennis Dalessandro 	u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
225f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
226f48ad614SDennis Dalessandro 
227f48ad614SDennis Dalessandro 	if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G) &&
228f48ad614SDennis Dalessandro 	    cache[QSFP_NOM_BIT_RATE_250_OFFS] < 0x64)
229f48ad614SDennis Dalessandro 		ppd->offline_disabled_reason =
230f48ad614SDennis Dalessandro 			   HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
231f48ad614SDennis Dalessandro 
232f48ad614SDennis Dalessandro 	if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G) &&
233f48ad614SDennis Dalessandro 	    cache[QSFP_NOM_BIT_RATE_100_OFFS] < 0x7D)
234f48ad614SDennis Dalessandro 		ppd->offline_disabled_reason =
235f48ad614SDennis Dalessandro 			   HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY);
236f48ad614SDennis Dalessandro 
237f48ad614SDennis Dalessandro 	if (ppd->offline_disabled_reason ==
238f48ad614SDennis Dalessandro 			HFI1_ODR_MASK(OPA_LINKDOWN_REASON_LINKSPEED_POLICY)) {
239b4e9e2f0SSebastian Sanchez 		dd_dev_err(
240f48ad614SDennis Dalessandro 			ppd->dd,
241f48ad614SDennis Dalessandro 			"%s: Cable failed bitrate check, disabling port\n",
242f48ad614SDennis Dalessandro 			__func__);
243f48ad614SDennis Dalessandro 		return -EPERM;
244f48ad614SDennis Dalessandro 	}
245f48ad614SDennis Dalessandro 	return 0;
246f48ad614SDennis Dalessandro }
247f48ad614SDennis Dalessandro 
set_qsfp_high_power(struct hfi1_pportdata * ppd)248f48ad614SDennis Dalessandro static int set_qsfp_high_power(struct hfi1_pportdata *ppd)
249f48ad614SDennis Dalessandro {
250f48ad614SDennis Dalessandro 	u8 cable_power_class = 0, power_ctrl_byte = 0;
251f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
252f48ad614SDennis Dalessandro 	int ret;
253f48ad614SDennis Dalessandro 
254f48ad614SDennis Dalessandro 	cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
255f48ad614SDennis Dalessandro 
256f48ad614SDennis Dalessandro 	if (cable_power_class > QSFP_POWER_CLASS_1) {
257f48ad614SDennis Dalessandro 		power_ctrl_byte = cache[QSFP_PWR_CTRL_BYTE_OFFS];
258f48ad614SDennis Dalessandro 
259f48ad614SDennis Dalessandro 		power_ctrl_byte |= 1;
260f48ad614SDennis Dalessandro 		power_ctrl_byte &= ~(0x2);
261f48ad614SDennis Dalessandro 
262f48ad614SDennis Dalessandro 		ret = qsfp_write(ppd, ppd->dd->hfi1_id,
263f48ad614SDennis Dalessandro 				 QSFP_PWR_CTRL_BYTE_OFFS,
264f48ad614SDennis Dalessandro 				 &power_ctrl_byte, 1);
265f48ad614SDennis Dalessandro 		if (ret != 1)
266f48ad614SDennis Dalessandro 			return -EIO;
267f48ad614SDennis Dalessandro 
268f48ad614SDennis Dalessandro 		if (cable_power_class > QSFP_POWER_CLASS_4) {
269f48ad614SDennis Dalessandro 			power_ctrl_byte |= (1 << 2);
270f48ad614SDennis Dalessandro 			ret = qsfp_write(ppd, ppd->dd->hfi1_id,
271f48ad614SDennis Dalessandro 					 QSFP_PWR_CTRL_BYTE_OFFS,
272f48ad614SDennis Dalessandro 					 &power_ctrl_byte, 1);
273f48ad614SDennis Dalessandro 			if (ret != 1)
274f48ad614SDennis Dalessandro 				return -EIO;
275f48ad614SDennis Dalessandro 		}
276f48ad614SDennis Dalessandro 
277f48ad614SDennis Dalessandro 		/* SFF 8679 rev 1.7 LPMode Deassert time */
278f48ad614SDennis Dalessandro 		msleep(300);
279f48ad614SDennis Dalessandro 	}
280f48ad614SDennis Dalessandro 	return 0;
281f48ad614SDennis Dalessandro }
282f48ad614SDennis Dalessandro 
apply_rx_cdr(struct hfi1_pportdata * ppd,u32 rx_preset_index,u8 * cdr_ctrl_byte)283f48ad614SDennis Dalessandro static void apply_rx_cdr(struct hfi1_pportdata *ppd,
284f48ad614SDennis Dalessandro 			 u32 rx_preset_index,
285f48ad614SDennis Dalessandro 			 u8 *cdr_ctrl_byte)
286f48ad614SDennis Dalessandro {
287f48ad614SDennis Dalessandro 	u32 rx_preset;
288f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
289f48ad614SDennis Dalessandro 	int cable_power_class;
290f48ad614SDennis Dalessandro 
291f48ad614SDennis Dalessandro 	if (!((cache[QSFP_MOD_PWR_OFFS] & 0x4) &&
292f48ad614SDennis Dalessandro 	      (cache[QSFP_CDR_INFO_OFFS] & 0x40)))
293f48ad614SDennis Dalessandro 		return;
294f48ad614SDennis Dalessandro 
295f48ad614SDennis Dalessandro 	/* RX CDR present, bypass supported */
296f48ad614SDennis Dalessandro 	cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
297f48ad614SDennis Dalessandro 
298f48ad614SDennis Dalessandro 	if (cable_power_class <= QSFP_POWER_CLASS_3) {
299f48ad614SDennis Dalessandro 		/* Power class <= 3, ignore config & turn RX CDR on */
300f48ad614SDennis Dalessandro 		*cdr_ctrl_byte |= 0xF;
301f48ad614SDennis Dalessandro 		return;
302f48ad614SDennis Dalessandro 	}
303f48ad614SDennis Dalessandro 
304f48ad614SDennis Dalessandro 	get_platform_config_field(
305f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
306f48ad614SDennis Dalessandro 		rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR_APPLY,
307f48ad614SDennis Dalessandro 		&rx_preset, 4);
308f48ad614SDennis Dalessandro 
309f48ad614SDennis Dalessandro 	if (!rx_preset) {
310f48ad614SDennis Dalessandro 		dd_dev_info(
311f48ad614SDennis Dalessandro 			ppd->dd,
312f48ad614SDennis Dalessandro 			"%s: RX_CDR_APPLY is set to disabled\n",
313f48ad614SDennis Dalessandro 			__func__);
314f48ad614SDennis Dalessandro 		return;
315f48ad614SDennis Dalessandro 	}
316f48ad614SDennis Dalessandro 	get_platform_config_field(
317f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
318f48ad614SDennis Dalessandro 		rx_preset_index, RX_PRESET_TABLE_QSFP_RX_CDR,
319f48ad614SDennis Dalessandro 		&rx_preset, 4);
320f48ad614SDennis Dalessandro 
321f48ad614SDennis Dalessandro 	/* Expand cdr setting to all 4 lanes */
322f48ad614SDennis Dalessandro 	rx_preset = (rx_preset | (rx_preset << 1) |
323f48ad614SDennis Dalessandro 			(rx_preset << 2) | (rx_preset << 3));
324f48ad614SDennis Dalessandro 
325f48ad614SDennis Dalessandro 	if (rx_preset) {
326f48ad614SDennis Dalessandro 		*cdr_ctrl_byte |= rx_preset;
327f48ad614SDennis Dalessandro 	} else {
328f48ad614SDennis Dalessandro 		*cdr_ctrl_byte &= rx_preset;
329f48ad614SDennis Dalessandro 		/* Preserve current TX CDR status */
330f48ad614SDennis Dalessandro 		*cdr_ctrl_byte |= (cache[QSFP_CDR_CTRL_BYTE_OFFS] & 0xF0);
331f48ad614SDennis Dalessandro 	}
332f48ad614SDennis Dalessandro }
333f48ad614SDennis Dalessandro 
apply_tx_cdr(struct hfi1_pportdata * ppd,u32 tx_preset_index,u8 * cdr_ctrl_byte)334f48ad614SDennis Dalessandro static void apply_tx_cdr(struct hfi1_pportdata *ppd,
335f48ad614SDennis Dalessandro 			 u32 tx_preset_index,
336f48ad614SDennis Dalessandro 			 u8 *cdr_ctrl_byte)
337f48ad614SDennis Dalessandro {
338f48ad614SDennis Dalessandro 	u32 tx_preset;
339f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
340f48ad614SDennis Dalessandro 	int cable_power_class;
341f48ad614SDennis Dalessandro 
342f48ad614SDennis Dalessandro 	if (!((cache[QSFP_MOD_PWR_OFFS] & 0x8) &&
343f48ad614SDennis Dalessandro 	      (cache[QSFP_CDR_INFO_OFFS] & 0x80)))
344f48ad614SDennis Dalessandro 		return;
345f48ad614SDennis Dalessandro 
346f48ad614SDennis Dalessandro 	/* TX CDR present, bypass supported */
347f48ad614SDennis Dalessandro 	cable_power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
348f48ad614SDennis Dalessandro 
349f48ad614SDennis Dalessandro 	if (cable_power_class <= QSFP_POWER_CLASS_3) {
350f48ad614SDennis Dalessandro 		/* Power class <= 3, ignore config & turn TX CDR on */
351f48ad614SDennis Dalessandro 		*cdr_ctrl_byte |= 0xF0;
352f48ad614SDennis Dalessandro 		return;
353f48ad614SDennis Dalessandro 	}
354f48ad614SDennis Dalessandro 
355f48ad614SDennis Dalessandro 	get_platform_config_field(
356f48ad614SDennis Dalessandro 		ppd->dd,
357f48ad614SDennis Dalessandro 		PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
358f48ad614SDennis Dalessandro 		TX_PRESET_TABLE_QSFP_TX_CDR_APPLY, &tx_preset, 4);
359f48ad614SDennis Dalessandro 
360f48ad614SDennis Dalessandro 	if (!tx_preset) {
361f48ad614SDennis Dalessandro 		dd_dev_info(
362f48ad614SDennis Dalessandro 			ppd->dd,
363f48ad614SDennis Dalessandro 			"%s: TX_CDR_APPLY is set to disabled\n",
364f48ad614SDennis Dalessandro 			__func__);
365f48ad614SDennis Dalessandro 		return;
366f48ad614SDennis Dalessandro 	}
367f48ad614SDennis Dalessandro 	get_platform_config_field(
368f48ad614SDennis Dalessandro 		ppd->dd,
369f48ad614SDennis Dalessandro 		PLATFORM_CONFIG_TX_PRESET_TABLE,
370f48ad614SDennis Dalessandro 		tx_preset_index,
371f48ad614SDennis Dalessandro 		TX_PRESET_TABLE_QSFP_TX_CDR, &tx_preset, 4);
372f48ad614SDennis Dalessandro 
373f48ad614SDennis Dalessandro 	/* Expand cdr setting to all 4 lanes */
374f48ad614SDennis Dalessandro 	tx_preset = (tx_preset | (tx_preset << 1) |
375f48ad614SDennis Dalessandro 			(tx_preset << 2) | (tx_preset << 3));
376f48ad614SDennis Dalessandro 
377f48ad614SDennis Dalessandro 	if (tx_preset)
378f48ad614SDennis Dalessandro 		*cdr_ctrl_byte |= (tx_preset << 4);
379f48ad614SDennis Dalessandro 	else
380f48ad614SDennis Dalessandro 		/* Preserve current/determined RX CDR status */
381f48ad614SDennis Dalessandro 		*cdr_ctrl_byte &= ((tx_preset << 4) | 0xF);
382f48ad614SDennis Dalessandro }
383f48ad614SDennis Dalessandro 
apply_cdr_settings(struct hfi1_pportdata * ppd,u32 rx_preset_index,u32 tx_preset_index)384f48ad614SDennis Dalessandro static void apply_cdr_settings(
385f48ad614SDennis Dalessandro 		struct hfi1_pportdata *ppd, u32 rx_preset_index,
386f48ad614SDennis Dalessandro 		u32 tx_preset_index)
387f48ad614SDennis Dalessandro {
388f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
389f48ad614SDennis Dalessandro 	u8 cdr_ctrl_byte = cache[QSFP_CDR_CTRL_BYTE_OFFS];
390f48ad614SDennis Dalessandro 
391f48ad614SDennis Dalessandro 	apply_rx_cdr(ppd, rx_preset_index, &cdr_ctrl_byte);
392f48ad614SDennis Dalessandro 
393f48ad614SDennis Dalessandro 	apply_tx_cdr(ppd, tx_preset_index, &cdr_ctrl_byte);
394f48ad614SDennis Dalessandro 
395f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, QSFP_CDR_CTRL_BYTE_OFFS,
396f48ad614SDennis Dalessandro 		   &cdr_ctrl_byte, 1);
397f48ad614SDennis Dalessandro }
398f48ad614SDennis Dalessandro 
apply_tx_eq_auto(struct hfi1_pportdata * ppd)399f48ad614SDennis Dalessandro static void apply_tx_eq_auto(struct hfi1_pportdata *ppd)
400f48ad614SDennis Dalessandro {
401f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
402f48ad614SDennis Dalessandro 	u8 tx_eq;
403f48ad614SDennis Dalessandro 
404f48ad614SDennis Dalessandro 	if (!(cache[QSFP_EQ_INFO_OFFS] & 0x8))
405f48ad614SDennis Dalessandro 		return;
406f48ad614SDennis Dalessandro 	/* Disable adaptive TX EQ if present */
407f48ad614SDennis Dalessandro 	tx_eq = cache[(128 * 3) + 241];
408f48ad614SDennis Dalessandro 	tx_eq &= 0xF0;
409f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 241, &tx_eq, 1);
410f48ad614SDennis Dalessandro }
411f48ad614SDennis Dalessandro 
apply_tx_eq_prog(struct hfi1_pportdata * ppd,u32 tx_preset_index)412f48ad614SDennis Dalessandro static void apply_tx_eq_prog(struct hfi1_pportdata *ppd, u32 tx_preset_index)
413f48ad614SDennis Dalessandro {
414f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
415f48ad614SDennis Dalessandro 	u32 tx_preset;
416f48ad614SDennis Dalessandro 	u8 tx_eq;
417f48ad614SDennis Dalessandro 
418f48ad614SDennis Dalessandro 	if (!(cache[QSFP_EQ_INFO_OFFS] & 0x4))
419f48ad614SDennis Dalessandro 		return;
420f48ad614SDennis Dalessandro 
421f48ad614SDennis Dalessandro 	get_platform_config_field(
422f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
423f48ad614SDennis Dalessandro 		tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ_APPLY,
424f48ad614SDennis Dalessandro 		&tx_preset, 4);
425f48ad614SDennis Dalessandro 	if (!tx_preset) {
426f48ad614SDennis Dalessandro 		dd_dev_info(
427f48ad614SDennis Dalessandro 			ppd->dd,
428f48ad614SDennis Dalessandro 			"%s: TX_EQ_APPLY is set to disabled\n",
429f48ad614SDennis Dalessandro 			__func__);
430f48ad614SDennis Dalessandro 		return;
431f48ad614SDennis Dalessandro 	}
432f48ad614SDennis Dalessandro 	get_platform_config_field(
433f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
434f48ad614SDennis Dalessandro 			tx_preset_index, TX_PRESET_TABLE_QSFP_TX_EQ,
435f48ad614SDennis Dalessandro 			&tx_preset, 4);
436f48ad614SDennis Dalessandro 
437f48ad614SDennis Dalessandro 	if (((cache[(128 * 3) + 224] & 0xF0) >> 4) < tx_preset) {
438f48ad614SDennis Dalessandro 		dd_dev_info(
439f48ad614SDennis Dalessandro 			ppd->dd,
440f48ad614SDennis Dalessandro 			"%s: TX EQ %x unsupported\n",
441f48ad614SDennis Dalessandro 			__func__, tx_preset);
442f48ad614SDennis Dalessandro 
443f48ad614SDennis Dalessandro 		dd_dev_info(
444f48ad614SDennis Dalessandro 			ppd->dd,
445f48ad614SDennis Dalessandro 			"%s: Applying EQ %x\n",
446f48ad614SDennis Dalessandro 			__func__, cache[608] & 0xF0);
447f48ad614SDennis Dalessandro 
448f48ad614SDennis Dalessandro 		tx_preset = (cache[608] & 0xF0) >> 4;
449f48ad614SDennis Dalessandro 	}
450f48ad614SDennis Dalessandro 
451f48ad614SDennis Dalessandro 	tx_eq = tx_preset | (tx_preset << 4);
452f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 234, &tx_eq, 1);
453f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 235, &tx_eq, 1);
454f48ad614SDennis Dalessandro }
455f48ad614SDennis Dalessandro 
apply_rx_eq_emp(struct hfi1_pportdata * ppd,u32 rx_preset_index)456f48ad614SDennis Dalessandro static void apply_rx_eq_emp(struct hfi1_pportdata *ppd, u32 rx_preset_index)
457f48ad614SDennis Dalessandro {
458f48ad614SDennis Dalessandro 	u32 rx_preset;
459f48ad614SDennis Dalessandro 	u8 rx_eq, *cache = ppd->qsfp_info.cache;
460f48ad614SDennis Dalessandro 
461f48ad614SDennis Dalessandro 	if (!(cache[QSFP_EQ_INFO_OFFS] & 0x2))
462f48ad614SDennis Dalessandro 		return;
463f48ad614SDennis Dalessandro 	get_platform_config_field(
464f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
465f48ad614SDennis Dalessandro 			rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP_APPLY,
466f48ad614SDennis Dalessandro 			&rx_preset, 4);
467f48ad614SDennis Dalessandro 
468f48ad614SDennis Dalessandro 	if (!rx_preset) {
469f48ad614SDennis Dalessandro 		dd_dev_info(
470f48ad614SDennis Dalessandro 			ppd->dd,
471f48ad614SDennis Dalessandro 			"%s: RX_EMP_APPLY is set to disabled\n",
472f48ad614SDennis Dalessandro 			__func__);
473f48ad614SDennis Dalessandro 		return;
474f48ad614SDennis Dalessandro 	}
475f48ad614SDennis Dalessandro 	get_platform_config_field(
476f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_RX_PRESET_TABLE,
477f48ad614SDennis Dalessandro 		rx_preset_index, RX_PRESET_TABLE_QSFP_RX_EMP,
478f48ad614SDennis Dalessandro 		&rx_preset, 4);
479f48ad614SDennis Dalessandro 
480f48ad614SDennis Dalessandro 	if ((cache[(128 * 3) + 224] & 0xF) < rx_preset) {
481f48ad614SDennis Dalessandro 		dd_dev_info(
482f48ad614SDennis Dalessandro 			ppd->dd,
483f48ad614SDennis Dalessandro 			"%s: Requested RX EMP %x\n",
484f48ad614SDennis Dalessandro 			__func__, rx_preset);
485f48ad614SDennis Dalessandro 
486f48ad614SDennis Dalessandro 		dd_dev_info(
487f48ad614SDennis Dalessandro 			ppd->dd,
488f48ad614SDennis Dalessandro 			"%s: Applying supported EMP %x\n",
489f48ad614SDennis Dalessandro 			__func__, cache[608] & 0xF);
490f48ad614SDennis Dalessandro 
491f48ad614SDennis Dalessandro 		rx_preset = cache[608] & 0xF;
492f48ad614SDennis Dalessandro 	}
493f48ad614SDennis Dalessandro 
494f48ad614SDennis Dalessandro 	rx_eq = rx_preset | (rx_preset << 4);
495f48ad614SDennis Dalessandro 
496f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 236, &rx_eq, 1);
497f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 237, &rx_eq, 1);
498f48ad614SDennis Dalessandro }
499f48ad614SDennis Dalessandro 
apply_eq_settings(struct hfi1_pportdata * ppd,u32 rx_preset_index,u32 tx_preset_index)500f48ad614SDennis Dalessandro static void apply_eq_settings(struct hfi1_pportdata *ppd,
501f48ad614SDennis Dalessandro 			      u32 rx_preset_index, u32 tx_preset_index)
502f48ad614SDennis Dalessandro {
503f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
504f48ad614SDennis Dalessandro 
505f48ad614SDennis Dalessandro 	/* no point going on w/o a page 3 */
506f48ad614SDennis Dalessandro 	if (cache[2] & 4) {
507f48ad614SDennis Dalessandro 		dd_dev_info(ppd->dd,
508f48ad614SDennis Dalessandro 			    "%s: Upper page 03 not present\n",
509f48ad614SDennis Dalessandro 			    __func__);
510f48ad614SDennis Dalessandro 		return;
511f48ad614SDennis Dalessandro 	}
512f48ad614SDennis Dalessandro 
513f48ad614SDennis Dalessandro 	apply_tx_eq_auto(ppd);
514f48ad614SDennis Dalessandro 
515f48ad614SDennis Dalessandro 	apply_tx_eq_prog(ppd, tx_preset_index);
516f48ad614SDennis Dalessandro 
517f48ad614SDennis Dalessandro 	apply_rx_eq_emp(ppd, rx_preset_index);
518f48ad614SDennis Dalessandro }
519f48ad614SDennis Dalessandro 
apply_rx_amplitude_settings(struct hfi1_pportdata * ppd,u32 rx_preset_index,u32 tx_preset_index)520f48ad614SDennis Dalessandro static void apply_rx_amplitude_settings(
521f48ad614SDennis Dalessandro 		struct hfi1_pportdata *ppd, u32 rx_preset_index,
522f48ad614SDennis Dalessandro 		u32 tx_preset_index)
523f48ad614SDennis Dalessandro {
524f48ad614SDennis Dalessandro 	u32 rx_preset;
525f48ad614SDennis Dalessandro 	u8 rx_amp = 0, i = 0, preferred = 0, *cache = ppd->qsfp_info.cache;
526f48ad614SDennis Dalessandro 
527f48ad614SDennis Dalessandro 	/* no point going on w/o a page 3 */
528f48ad614SDennis Dalessandro 	if (cache[2] & 4) {
529f48ad614SDennis Dalessandro 		dd_dev_info(ppd->dd,
530f48ad614SDennis Dalessandro 			    "%s: Upper page 03 not present\n",
531f48ad614SDennis Dalessandro 			    __func__);
532f48ad614SDennis Dalessandro 		return;
533f48ad614SDennis Dalessandro 	}
534f48ad614SDennis Dalessandro 	if (!(cache[QSFP_EQ_INFO_OFFS] & 0x1)) {
535f48ad614SDennis Dalessandro 		dd_dev_info(ppd->dd,
536f48ad614SDennis Dalessandro 			    "%s: RX_AMP_APPLY is set to disabled\n",
537f48ad614SDennis Dalessandro 			    __func__);
538f48ad614SDennis Dalessandro 		return;
539f48ad614SDennis Dalessandro 	}
540f48ad614SDennis Dalessandro 
541f48ad614SDennis Dalessandro 	get_platform_config_field(ppd->dd,
542f48ad614SDennis Dalessandro 				  PLATFORM_CONFIG_RX_PRESET_TABLE,
543f48ad614SDennis Dalessandro 				  rx_preset_index,
544f48ad614SDennis Dalessandro 				  RX_PRESET_TABLE_QSFP_RX_AMP_APPLY,
545f48ad614SDennis Dalessandro 				  &rx_preset, 4);
546f48ad614SDennis Dalessandro 
547f48ad614SDennis Dalessandro 	if (!rx_preset) {
548f48ad614SDennis Dalessandro 		dd_dev_info(ppd->dd,
549f48ad614SDennis Dalessandro 			    "%s: RX_AMP_APPLY is set to disabled\n",
550f48ad614SDennis Dalessandro 			    __func__);
551f48ad614SDennis Dalessandro 		return;
552f48ad614SDennis Dalessandro 	}
553f48ad614SDennis Dalessandro 	get_platform_config_field(ppd->dd,
554f48ad614SDennis Dalessandro 				  PLATFORM_CONFIG_RX_PRESET_TABLE,
555f48ad614SDennis Dalessandro 				  rx_preset_index,
556f48ad614SDennis Dalessandro 				  RX_PRESET_TABLE_QSFP_RX_AMP,
557f48ad614SDennis Dalessandro 				  &rx_preset, 4);
558f48ad614SDennis Dalessandro 
559f48ad614SDennis Dalessandro 	dd_dev_info(ppd->dd,
560f48ad614SDennis Dalessandro 		    "%s: Requested RX AMP %x\n",
561f48ad614SDennis Dalessandro 		    __func__,
562f48ad614SDennis Dalessandro 		    rx_preset);
563f48ad614SDennis Dalessandro 
564f48ad614SDennis Dalessandro 	for (i = 0; i < 4; i++) {
565f48ad614SDennis Dalessandro 		if (cache[(128 * 3) + 225] & (1 << i)) {
566f48ad614SDennis Dalessandro 			preferred = i;
567f48ad614SDennis Dalessandro 			if (preferred == rx_preset)
568f48ad614SDennis Dalessandro 				break;
569f48ad614SDennis Dalessandro 		}
570f48ad614SDennis Dalessandro 	}
571f48ad614SDennis Dalessandro 
572f48ad614SDennis Dalessandro 	/*
573f48ad614SDennis Dalessandro 	 * Verify that preferred RX amplitude is not just a
574f48ad614SDennis Dalessandro 	 * fall through of the default
575f48ad614SDennis Dalessandro 	 */
576f48ad614SDennis Dalessandro 	if (!preferred && !(cache[(128 * 3) + 225] & 0x1)) {
577f48ad614SDennis Dalessandro 		dd_dev_info(ppd->dd, "No supported RX AMP, not applying\n");
578f48ad614SDennis Dalessandro 		return;
579f48ad614SDennis Dalessandro 	}
580f48ad614SDennis Dalessandro 
581f48ad614SDennis Dalessandro 	dd_dev_info(ppd->dd,
582f48ad614SDennis Dalessandro 		    "%s: Applying RX AMP %x\n", __func__, preferred);
583f48ad614SDennis Dalessandro 
584f48ad614SDennis Dalessandro 	rx_amp = preferred | (preferred << 4);
585f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 238, &rx_amp, 1);
586f48ad614SDennis Dalessandro 	qsfp_write(ppd, ppd->dd->hfi1_id, (256 * 3) + 239, &rx_amp, 1);
587f48ad614SDennis Dalessandro }
588f48ad614SDennis Dalessandro 
589f48ad614SDennis Dalessandro #define OPA_INVALID_INDEX 0xFFF
590f48ad614SDennis Dalessandro 
apply_tx_lanes(struct hfi1_pportdata * ppd,u8 field_id,u32 config_data,const char * message)591f48ad614SDennis Dalessandro static void apply_tx_lanes(struct hfi1_pportdata *ppd, u8 field_id,
592f48ad614SDennis Dalessandro 			   u32 config_data, const char *message)
593f48ad614SDennis Dalessandro {
594f48ad614SDennis Dalessandro 	u8 i;
59525d24f42SColin Ian King 	int ret;
596f48ad614SDennis Dalessandro 
597f48ad614SDennis Dalessandro 	for (i = 0; i < 4; i++) {
598f48ad614SDennis Dalessandro 		ret = load_8051_config(ppd->dd, field_id, i, config_data);
599f48ad614SDennis Dalessandro 		if (ret != HCMD_SUCCESS) {
600f48ad614SDennis Dalessandro 			dd_dev_err(
601f48ad614SDennis Dalessandro 				ppd->dd,
602f48ad614SDennis Dalessandro 				"%s: %s for lane %u failed\n",
603f48ad614SDennis Dalessandro 				message, __func__, i);
604f48ad614SDennis Dalessandro 		}
605f48ad614SDennis Dalessandro 	}
606f48ad614SDennis Dalessandro }
607f48ad614SDennis Dalessandro 
6085213006aSDean Luick /*
6095213006aSDean Luick  * Return a special SerDes setting for low power AOC cables.  The power class
6105213006aSDean Luick  * threshold and setting being used were all found by empirical testing.
6115213006aSDean Luick  *
6125213006aSDean Luick  * Summary of the logic:
6135213006aSDean Luick  *
6145213006aSDean Luick  * if (QSFP and QSFP_TYPE == AOC and QSFP_POWER_CLASS < 4)
6155213006aSDean Luick  *     return 0xe
6165213006aSDean Luick  * return 0; // leave at default
6175213006aSDean Luick  */
aoc_low_power_setting(struct hfi1_pportdata * ppd)6185213006aSDean Luick static u8 aoc_low_power_setting(struct hfi1_pportdata *ppd)
6195213006aSDean Luick {
6205213006aSDean Luick 	u8 *cache = ppd->qsfp_info.cache;
6215213006aSDean Luick 	int power_class;
6225213006aSDean Luick 
6235213006aSDean Luick 	/* QSFP only */
6245213006aSDean Luick 	if (ppd->port_type != PORT_TYPE_QSFP)
6255213006aSDean Luick 		return 0; /* leave at default */
6265213006aSDean Luick 
6275213006aSDean Luick 	/* active optical cables only */
6285213006aSDean Luick 	switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
6296f24b159SGustavo A. R. Silva 	case 0x0 ... 0x9: fallthrough;
6306f24b159SGustavo A. R. Silva 	case 0xC: fallthrough;
6315213006aSDean Luick 	case 0xE:
6325213006aSDean Luick 		/* active AOC */
6335213006aSDean Luick 		power_class = get_qsfp_power_class(cache[QSFP_MOD_PWR_OFFS]);
6345213006aSDean Luick 		if (power_class < QSFP_POWER_CLASS_4)
6355213006aSDean Luick 			return 0xe;
6365213006aSDean Luick 	}
6375213006aSDean Luick 	return 0; /* leave at default */
6385213006aSDean Luick }
6395213006aSDean Luick 
apply_tunings(struct hfi1_pportdata * ppd,u32 tx_preset_index,u8 tuning_method,u32 total_atten,u8 limiting_active)640f48ad614SDennis Dalessandro static void apply_tunings(
641f48ad614SDennis Dalessandro 		struct hfi1_pportdata *ppd, u32 tx_preset_index,
642f48ad614SDennis Dalessandro 		u8 tuning_method, u32 total_atten, u8 limiting_active)
643f48ad614SDennis Dalessandro {
644f48ad614SDennis Dalessandro 	int ret = 0;
645f48ad614SDennis Dalessandro 	u32 config_data = 0, tx_preset = 0;
646f48ad614SDennis Dalessandro 	u8 precur = 0, attn = 0, postcur = 0, external_device_config = 0;
647f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
648f48ad614SDennis Dalessandro 
649f48ad614SDennis Dalessandro 	/* Pass tuning method to 8051 */
650f48ad614SDennis Dalessandro 	read_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
651f48ad614SDennis Dalessandro 			 &config_data);
652f6de3d39SDean Luick 	config_data &= ~(0xff << TUNING_METHOD_SHIFT);
653f6de3d39SDean Luick 	config_data |= ((u32)tuning_method << TUNING_METHOD_SHIFT);
654f48ad614SDennis Dalessandro 	ret = load_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG,
655f48ad614SDennis Dalessandro 			       config_data);
656f48ad614SDennis Dalessandro 	if (ret != HCMD_SUCCESS)
657f48ad614SDennis Dalessandro 		dd_dev_err(ppd->dd, "%s: Failed to set tuning method\n",
658f48ad614SDennis Dalessandro 			   __func__);
659f48ad614SDennis Dalessandro 
660f48ad614SDennis Dalessandro 	/* Set same channel loss for both TX and RX */
661f48ad614SDennis Dalessandro 	config_data = 0 | (total_atten << 16) | (total_atten << 24);
662f48ad614SDennis Dalessandro 	apply_tx_lanes(ppd, CHANNEL_LOSS_SETTINGS, config_data,
663f48ad614SDennis Dalessandro 		       "Setting channel loss");
664f48ad614SDennis Dalessandro 
665f48ad614SDennis Dalessandro 	/* Inform 8051 of cable capabilities */
666f48ad614SDennis Dalessandro 	if (ppd->qsfp_info.cache_valid) {
667f48ad614SDennis Dalessandro 		external_device_config =
668f48ad614SDennis Dalessandro 			((cache[QSFP_MOD_PWR_OFFS] & 0x4) << 3) |
669f48ad614SDennis Dalessandro 			((cache[QSFP_MOD_PWR_OFFS] & 0x8) << 2) |
670f48ad614SDennis Dalessandro 			((cache[QSFP_EQ_INFO_OFFS] & 0x2) << 1) |
671f48ad614SDennis Dalessandro 			(cache[QSFP_EQ_INFO_OFFS] & 0x4);
672f48ad614SDennis Dalessandro 		ret = read_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
673f48ad614SDennis Dalessandro 				       GENERAL_CONFIG, &config_data);
674f48ad614SDennis Dalessandro 		/* Clear, then set the external device config field */
675f48ad614SDennis Dalessandro 		config_data &= ~(u32)0xFF;
676f48ad614SDennis Dalessandro 		config_data |= external_device_config;
677f48ad614SDennis Dalessandro 		ret = load_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS,
678f48ad614SDennis Dalessandro 				       GENERAL_CONFIG, config_data);
679f48ad614SDennis Dalessandro 		if (ret != HCMD_SUCCESS)
680b4e9e2f0SSebastian Sanchez 			dd_dev_err(ppd->dd,
681f48ad614SDennis Dalessandro 				   "%s: Failed set ext device config params\n",
682f48ad614SDennis Dalessandro 				   __func__);
683f48ad614SDennis Dalessandro 	}
684f48ad614SDennis Dalessandro 
685f48ad614SDennis Dalessandro 	if (tx_preset_index == OPA_INVALID_INDEX) {
686f48ad614SDennis Dalessandro 		if (ppd->port_type == PORT_TYPE_QSFP && limiting_active)
687b4e9e2f0SSebastian Sanchez 			dd_dev_err(ppd->dd, "%s: Invalid Tx preset index\n",
688f48ad614SDennis Dalessandro 				   __func__);
689f48ad614SDennis Dalessandro 		return;
690f48ad614SDennis Dalessandro 	}
691f48ad614SDennis Dalessandro 
692f48ad614SDennis Dalessandro 	/* Following for limiting active channels only */
693f48ad614SDennis Dalessandro 	get_platform_config_field(
694f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE, tx_preset_index,
695f48ad614SDennis Dalessandro 		TX_PRESET_TABLE_PRECUR, &tx_preset, 4);
696f48ad614SDennis Dalessandro 	precur = tx_preset;
697f48ad614SDennis Dalessandro 
698f48ad614SDennis Dalessandro 	get_platform_config_field(
699f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
700f48ad614SDennis Dalessandro 		tx_preset_index, TX_PRESET_TABLE_ATTN, &tx_preset, 4);
701f48ad614SDennis Dalessandro 	attn = tx_preset;
702f48ad614SDennis Dalessandro 
703f48ad614SDennis Dalessandro 	get_platform_config_field(
704f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_TX_PRESET_TABLE,
705f48ad614SDennis Dalessandro 		tx_preset_index, TX_PRESET_TABLE_POSTCUR, &tx_preset, 4);
706f48ad614SDennis Dalessandro 	postcur = tx_preset;
707f48ad614SDennis Dalessandro 
7085213006aSDean Luick 	/*
7095213006aSDean Luick 	 * NOTES:
7105213006aSDean Luick 	 * o The aoc_low_power_setting is applied to all lanes even
7115213006aSDean Luick 	 *   though only lane 0's value is examined by the firmware.
7125213006aSDean Luick 	 * o A lingering low power setting after a cable swap does
7135213006aSDean Luick 	 *   not occur.  On cable unplug the 8051 is reset and
7145213006aSDean Luick 	 *   restarted on cable insert.  This resets all settings to
7155213006aSDean Luick 	 *   their default, erasing any previous low power setting.
7165213006aSDean Luick 	 */
7175213006aSDean Luick 	config_data = precur | (attn << 8) | (postcur << 16) |
7185213006aSDean Luick 			(aoc_low_power_setting(ppd) << 24);
719f48ad614SDennis Dalessandro 
720f48ad614SDennis Dalessandro 	apply_tx_lanes(ppd, TX_EQ_SETTINGS, config_data,
721f48ad614SDennis Dalessandro 		       "Applying TX settings");
722f48ad614SDennis Dalessandro }
723f48ad614SDennis Dalessandro 
724f48ad614SDennis Dalessandro /* Must be holding the QSFP i2c resource */
tune_active_qsfp(struct hfi1_pportdata * ppd,u32 * ptr_tx_preset,u32 * ptr_rx_preset,u32 * ptr_total_atten)725f48ad614SDennis Dalessandro static int tune_active_qsfp(struct hfi1_pportdata *ppd, u32 *ptr_tx_preset,
726f48ad614SDennis Dalessandro 			    u32 *ptr_rx_preset, u32 *ptr_total_atten)
727f48ad614SDennis Dalessandro {
728f48ad614SDennis Dalessandro 	int ret;
729f48ad614SDennis Dalessandro 	u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
730f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
731f48ad614SDennis Dalessandro 
732f48ad614SDennis Dalessandro 	ppd->qsfp_info.limiting_active = 1;
733f48ad614SDennis Dalessandro 
734f48ad614SDennis Dalessandro 	ret = set_qsfp_tx(ppd, 0);
735f48ad614SDennis Dalessandro 	if (ret)
736f48ad614SDennis Dalessandro 		return ret;
737f48ad614SDennis Dalessandro 
738f48ad614SDennis Dalessandro 	ret = qual_power(ppd);
739f48ad614SDennis Dalessandro 	if (ret)
740f48ad614SDennis Dalessandro 		return ret;
741f48ad614SDennis Dalessandro 
742f48ad614SDennis Dalessandro 	ret = qual_bitrate(ppd);
743f48ad614SDennis Dalessandro 	if (ret)
744f48ad614SDennis Dalessandro 		return ret;
745f48ad614SDennis Dalessandro 
746b5e71019SEaswar Hariharan 	/*
747b5e71019SEaswar Hariharan 	 * We'll change the QSFP memory contents from here on out, thus we set a
748b5e71019SEaswar Hariharan 	 * flag here to remind ourselves to reset the QSFP module. This prevents
749b5e71019SEaswar Hariharan 	 * reuse of stale settings established in our previous pass through.
750b5e71019SEaswar Hariharan 	 */
751f48ad614SDennis Dalessandro 	if (ppd->qsfp_info.reset_needed) {
75230e10527SSebastian Sanchez 		ret = reset_qsfp(ppd);
75330e10527SSebastian Sanchez 		if (ret)
75430e10527SSebastian Sanchez 			return ret;
755f48ad614SDennis Dalessandro 		refresh_qsfp_cache(ppd, &ppd->qsfp_info);
756f48ad614SDennis Dalessandro 	} else {
757f48ad614SDennis Dalessandro 		ppd->qsfp_info.reset_needed = 1;
758f48ad614SDennis Dalessandro 	}
759f48ad614SDennis Dalessandro 
760f48ad614SDennis Dalessandro 	ret = set_qsfp_high_power(ppd);
761f48ad614SDennis Dalessandro 	if (ret)
762f48ad614SDennis Dalessandro 		return ret;
763f48ad614SDennis Dalessandro 
764f48ad614SDennis Dalessandro 	if (cache[QSFP_EQ_INFO_OFFS] & 0x4) {
765f48ad614SDennis Dalessandro 		ret = get_platform_config_field(
766f48ad614SDennis Dalessandro 			ppd->dd,
767f48ad614SDennis Dalessandro 			PLATFORM_CONFIG_PORT_TABLE, 0,
768f48ad614SDennis Dalessandro 			PORT_TABLE_TX_PRESET_IDX_ACTIVE_EQ,
769f48ad614SDennis Dalessandro 			ptr_tx_preset, 4);
770f48ad614SDennis Dalessandro 		if (ret) {
771f48ad614SDennis Dalessandro 			*ptr_tx_preset = OPA_INVALID_INDEX;
772f48ad614SDennis Dalessandro 			return ret;
773f48ad614SDennis Dalessandro 		}
774f48ad614SDennis Dalessandro 	} else {
775f48ad614SDennis Dalessandro 		ret = get_platform_config_field(
776f48ad614SDennis Dalessandro 			ppd->dd,
777f48ad614SDennis Dalessandro 			PLATFORM_CONFIG_PORT_TABLE, 0,
778f48ad614SDennis Dalessandro 			PORT_TABLE_TX_PRESET_IDX_ACTIVE_NO_EQ,
779f48ad614SDennis Dalessandro 			ptr_tx_preset, 4);
780f48ad614SDennis Dalessandro 		if (ret) {
781f48ad614SDennis Dalessandro 			*ptr_tx_preset = OPA_INVALID_INDEX;
782f48ad614SDennis Dalessandro 			return ret;
783f48ad614SDennis Dalessandro 		}
784f48ad614SDennis Dalessandro 	}
785f48ad614SDennis Dalessandro 
786f48ad614SDennis Dalessandro 	ret = get_platform_config_field(
787f48ad614SDennis Dalessandro 		ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
788f48ad614SDennis Dalessandro 		PORT_TABLE_RX_PRESET_IDX, ptr_rx_preset, 4);
789f48ad614SDennis Dalessandro 	if (ret) {
790f48ad614SDennis Dalessandro 		*ptr_rx_preset = OPA_INVALID_INDEX;
791f48ad614SDennis Dalessandro 		return ret;
792f48ad614SDennis Dalessandro 	}
793f48ad614SDennis Dalessandro 
794f48ad614SDennis Dalessandro 	if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
795f48ad614SDennis Dalessandro 		get_platform_config_field(
796f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
797f48ad614SDennis Dalessandro 			PORT_TABLE_LOCAL_ATTEN_25G, ptr_total_atten, 4);
798f48ad614SDennis Dalessandro 	else if ((lss & OPA_LINK_SPEED_12_5G) && (lse & OPA_LINK_SPEED_12_5G))
799f48ad614SDennis Dalessandro 		get_platform_config_field(
800f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
801f48ad614SDennis Dalessandro 			PORT_TABLE_LOCAL_ATTEN_12G, ptr_total_atten, 4);
802f48ad614SDennis Dalessandro 
803f48ad614SDennis Dalessandro 	apply_cdr_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
804f48ad614SDennis Dalessandro 
805f48ad614SDennis Dalessandro 	apply_eq_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
806f48ad614SDennis Dalessandro 
807f48ad614SDennis Dalessandro 	apply_rx_amplitude_settings(ppd, *ptr_rx_preset, *ptr_tx_preset);
808f48ad614SDennis Dalessandro 
809f48ad614SDennis Dalessandro 	ret = set_qsfp_tx(ppd, 1);
810f48ad614SDennis Dalessandro 
811f48ad614SDennis Dalessandro 	return ret;
812f48ad614SDennis Dalessandro }
813f48ad614SDennis Dalessandro 
tune_qsfp(struct hfi1_pportdata * ppd,u32 * ptr_tx_preset,u32 * ptr_rx_preset,u8 * ptr_tuning_method,u32 * ptr_total_atten)814f48ad614SDennis Dalessandro static int tune_qsfp(struct hfi1_pportdata *ppd,
815f48ad614SDennis Dalessandro 		     u32 *ptr_tx_preset, u32 *ptr_rx_preset,
816f48ad614SDennis Dalessandro 		     u8 *ptr_tuning_method, u32 *ptr_total_atten)
817f48ad614SDennis Dalessandro {
818f48ad614SDennis Dalessandro 	u32 cable_atten = 0, remote_atten = 0, platform_atten = 0;
819f48ad614SDennis Dalessandro 	u16 lss = ppd->link_speed_supported, lse = ppd->link_speed_enabled;
820f48ad614SDennis Dalessandro 	int ret = 0;
821f48ad614SDennis Dalessandro 	u8 *cache = ppd->qsfp_info.cache;
822f48ad614SDennis Dalessandro 
823f48ad614SDennis Dalessandro 	switch ((cache[QSFP_MOD_TECH_OFFS] & 0xF0) >> 4) {
824f48ad614SDennis Dalessandro 	case 0xA ... 0xB:
825f48ad614SDennis Dalessandro 		ret = get_platform_config_field(
826f48ad614SDennis Dalessandro 			ppd->dd,
827f48ad614SDennis Dalessandro 			PLATFORM_CONFIG_PORT_TABLE, 0,
828f48ad614SDennis Dalessandro 			PORT_TABLE_LOCAL_ATTEN_25G,
829f48ad614SDennis Dalessandro 			&platform_atten, 4);
830f48ad614SDennis Dalessandro 		if (ret)
831f48ad614SDennis Dalessandro 			return ret;
832f48ad614SDennis Dalessandro 
833f48ad614SDennis Dalessandro 		if ((lss & OPA_LINK_SPEED_25G) && (lse & OPA_LINK_SPEED_25G))
834f48ad614SDennis Dalessandro 			cable_atten = cache[QSFP_CU_ATTEN_12G_OFFS];
835f48ad614SDennis Dalessandro 		else if ((lss & OPA_LINK_SPEED_12_5G) &&
836f48ad614SDennis Dalessandro 			 (lse & OPA_LINK_SPEED_12_5G))
837f48ad614SDennis Dalessandro 			cable_atten = cache[QSFP_CU_ATTEN_7G_OFFS];
838f48ad614SDennis Dalessandro 
839f48ad614SDennis Dalessandro 		/* Fallback to configured attenuation if cable memory is bad */
840f48ad614SDennis Dalessandro 		if (cable_atten == 0 || cable_atten > 36) {
841f48ad614SDennis Dalessandro 			ret = get_platform_config_field(
842f48ad614SDennis Dalessandro 				ppd->dd,
843f48ad614SDennis Dalessandro 				PLATFORM_CONFIG_SYSTEM_TABLE, 0,
844f48ad614SDennis Dalessandro 				SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_25G,
845f48ad614SDennis Dalessandro 				&cable_atten, 4);
846f48ad614SDennis Dalessandro 			if (ret)
847f48ad614SDennis Dalessandro 				return ret;
848f48ad614SDennis Dalessandro 		}
849f48ad614SDennis Dalessandro 
850f48ad614SDennis Dalessandro 		ret = get_platform_config_field(
851f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
852f48ad614SDennis Dalessandro 			PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
853f48ad614SDennis Dalessandro 		if (ret)
854f48ad614SDennis Dalessandro 			return ret;
855f48ad614SDennis Dalessandro 
856f48ad614SDennis Dalessandro 		*ptr_total_atten = platform_atten + cable_atten + remote_atten;
857f48ad614SDennis Dalessandro 
858f48ad614SDennis Dalessandro 		*ptr_tuning_method = OPA_PASSIVE_TUNING;
859f48ad614SDennis Dalessandro 		break;
8606f24b159SGustavo A. R. Silva 	case 0x0 ... 0x9: fallthrough;
8616f24b159SGustavo A. R. Silva 	case 0xC: fallthrough;
862f48ad614SDennis Dalessandro 	case 0xE:
863f48ad614SDennis Dalessandro 		ret = tune_active_qsfp(ppd, ptr_tx_preset, ptr_rx_preset,
864f48ad614SDennis Dalessandro 				       ptr_total_atten);
865f48ad614SDennis Dalessandro 		if (ret)
866f48ad614SDennis Dalessandro 			return ret;
867f48ad614SDennis Dalessandro 
868f48ad614SDennis Dalessandro 		*ptr_tuning_method = OPA_ACTIVE_TUNING;
869f48ad614SDennis Dalessandro 		break;
8706f24b159SGustavo A. R. Silva 	case 0xD: fallthrough;
871f48ad614SDennis Dalessandro 	case 0xF:
872f48ad614SDennis Dalessandro 	default:
873b4e9e2f0SSebastian Sanchez 		dd_dev_warn(ppd->dd, "%s: Unknown/unsupported cable\n",
874f48ad614SDennis Dalessandro 			    __func__);
875f48ad614SDennis Dalessandro 		break;
876f48ad614SDennis Dalessandro 	}
877f48ad614SDennis Dalessandro 	return ret;
878f48ad614SDennis Dalessandro }
879f48ad614SDennis Dalessandro 
880f48ad614SDennis Dalessandro /*
881f48ad614SDennis Dalessandro  * This function communicates its success or failure via ppd->driver_link_ready
882f48ad614SDennis Dalessandro  * Thus, it depends on its association with start_link(...) which checks
883f48ad614SDennis Dalessandro  * driver_link_ready before proceeding with the link negotiation and
884f48ad614SDennis Dalessandro  * initialization process.
885f48ad614SDennis Dalessandro  */
tune_serdes(struct hfi1_pportdata * ppd)886f48ad614SDennis Dalessandro void tune_serdes(struct hfi1_pportdata *ppd)
887f48ad614SDennis Dalessandro {
888f48ad614SDennis Dalessandro 	int ret = 0;
889f48ad614SDennis Dalessandro 	u32 total_atten = 0;
890f48ad614SDennis Dalessandro 	u32 remote_atten = 0, platform_atten = 0;
891f48ad614SDennis Dalessandro 	u32 rx_preset_index, tx_preset_index;
892f48ad614SDennis Dalessandro 	u8 tuning_method = 0, limiting_active = 0;
893f48ad614SDennis Dalessandro 	struct hfi1_devdata *dd = ppd->dd;
894f48ad614SDennis Dalessandro 
895f48ad614SDennis Dalessandro 	rx_preset_index = OPA_INVALID_INDEX;
896f48ad614SDennis Dalessandro 	tx_preset_index = OPA_INVALID_INDEX;
897f48ad614SDennis Dalessandro 
898f48ad614SDennis Dalessandro 	/* the link defaults to enabled */
899f48ad614SDennis Dalessandro 	ppd->link_enabled = 1;
900f48ad614SDennis Dalessandro 	/* the driver link ready state defaults to not ready */
901f48ad614SDennis Dalessandro 	ppd->driver_link_ready = 0;
902f48ad614SDennis Dalessandro 	ppd->offline_disabled_reason = HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
903f48ad614SDennis Dalessandro 
904f48ad614SDennis Dalessandro 	/* Skip the tuning for testing (loopback != none) and simulations */
905f48ad614SDennis Dalessandro 	if (loopback != LOOPBACK_NONE ||
906f48ad614SDennis Dalessandro 	    ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
907f48ad614SDennis Dalessandro 		ppd->driver_link_ready = 1;
908ba81a427SJan Sokolowski 
909ba81a427SJan Sokolowski 		if (qsfp_mod_present(ppd)) {
910ba81a427SJan Sokolowski 			ret = acquire_chip_resource(ppd->dd,
911ba81a427SJan Sokolowski 						    qsfp_resource(ppd->dd),
912ba81a427SJan Sokolowski 						    QSFP_WAIT);
913ba81a427SJan Sokolowski 			if (ret) {
914ba81a427SJan Sokolowski 				dd_dev_err(ppd->dd, "%s: hfi%d: cannot lock i2c chain\n",
915ba81a427SJan Sokolowski 					   __func__, (int)ppd->dd->hfi1_id);
916ba81a427SJan Sokolowski 				goto bail;
917ba81a427SJan Sokolowski 			}
918ba81a427SJan Sokolowski 
919ba81a427SJan Sokolowski 			refresh_qsfp_cache(ppd, &ppd->qsfp_info);
920ba81a427SJan Sokolowski 			release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
921ba81a427SJan Sokolowski 		}
922ba81a427SJan Sokolowski 
923f48ad614SDennis Dalessandro 		return;
924f48ad614SDennis Dalessandro 	}
925f48ad614SDennis Dalessandro 
926f48ad614SDennis Dalessandro 	switch (ppd->port_type) {
927f48ad614SDennis Dalessandro 	case PORT_TYPE_DISCONNECTED:
928f48ad614SDennis Dalessandro 		ppd->offline_disabled_reason =
929f48ad614SDennis Dalessandro 			HFI1_ODR_MASK(OPA_LINKDOWN_REASON_DISCONNECTED);
930b4e9e2f0SSebastian Sanchez 		dd_dev_warn(dd, "%s: Port disconnected, disabling port\n",
931f48ad614SDennis Dalessandro 			    __func__);
932f48ad614SDennis Dalessandro 		goto bail;
933f48ad614SDennis Dalessandro 	case PORT_TYPE_FIXED:
934f48ad614SDennis Dalessandro 		/* platform_atten, remote_atten pre-zeroed to catch error */
935f48ad614SDennis Dalessandro 		get_platform_config_field(
936f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
937f48ad614SDennis Dalessandro 			PORT_TABLE_LOCAL_ATTEN_25G, &platform_atten, 4);
938f48ad614SDennis Dalessandro 
939f48ad614SDennis Dalessandro 		get_platform_config_field(
940f48ad614SDennis Dalessandro 			ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
941f48ad614SDennis Dalessandro 			PORT_TABLE_REMOTE_ATTEN_25G, &remote_atten, 4);
942f48ad614SDennis Dalessandro 
943f48ad614SDennis Dalessandro 		total_atten = platform_atten + remote_atten;
944f48ad614SDennis Dalessandro 
945f48ad614SDennis Dalessandro 		tuning_method = OPA_PASSIVE_TUNING;
946f48ad614SDennis Dalessandro 		break;
947f48ad614SDennis Dalessandro 	case PORT_TYPE_VARIABLE:
948f48ad614SDennis Dalessandro 		if (qsfp_mod_present(ppd)) {
949f48ad614SDennis Dalessandro 			/*
950f48ad614SDennis Dalessandro 			 * platform_atten, remote_atten pre-zeroed to
951f48ad614SDennis Dalessandro 			 * catch error
952f48ad614SDennis Dalessandro 			 */
953f48ad614SDennis Dalessandro 			get_platform_config_field(
954f48ad614SDennis Dalessandro 				ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
955f48ad614SDennis Dalessandro 				PORT_TABLE_LOCAL_ATTEN_25G,
956f48ad614SDennis Dalessandro 				&platform_atten, 4);
957f48ad614SDennis Dalessandro 
958f48ad614SDennis Dalessandro 			get_platform_config_field(
959f48ad614SDennis Dalessandro 				ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0,
960f48ad614SDennis Dalessandro 				PORT_TABLE_REMOTE_ATTEN_25G,
961f48ad614SDennis Dalessandro 				&remote_atten, 4);
962f48ad614SDennis Dalessandro 
963f48ad614SDennis Dalessandro 			total_atten = platform_atten + remote_atten;
964f48ad614SDennis Dalessandro 
965f48ad614SDennis Dalessandro 			tuning_method = OPA_PASSIVE_TUNING;
966f48ad614SDennis Dalessandro 		} else {
967f48ad614SDennis Dalessandro 			ppd->offline_disabled_reason =
968f48ad614SDennis Dalessandro 			     HFI1_ODR_MASK(OPA_LINKDOWN_REASON_CHASSIS_CONFIG);
969f48ad614SDennis Dalessandro 			goto bail;
970f48ad614SDennis Dalessandro 		}
971f48ad614SDennis Dalessandro 		break;
972f48ad614SDennis Dalessandro 	case PORT_TYPE_QSFP:
973f48ad614SDennis Dalessandro 		if (qsfp_mod_present(ppd)) {
974f48ad614SDennis Dalessandro 			ret = acquire_chip_resource(ppd->dd,
975f48ad614SDennis Dalessandro 						    qsfp_resource(ppd->dd),
976f48ad614SDennis Dalessandro 						    QSFP_WAIT);
977f48ad614SDennis Dalessandro 			if (ret) {
978f48ad614SDennis Dalessandro 				dd_dev_err(ppd->dd, "%s: hfi%d: cannot lock i2c chain\n",
979f48ad614SDennis Dalessandro 					   __func__, (int)ppd->dd->hfi1_id);
980f48ad614SDennis Dalessandro 				goto bail;
981f48ad614SDennis Dalessandro 			}
982f48ad614SDennis Dalessandro 			refresh_qsfp_cache(ppd, &ppd->qsfp_info);
983f48ad614SDennis Dalessandro 
984f48ad614SDennis Dalessandro 			if (ppd->qsfp_info.cache_valid) {
985f48ad614SDennis Dalessandro 				ret = tune_qsfp(ppd,
986f48ad614SDennis Dalessandro 						&tx_preset_index,
987f48ad614SDennis Dalessandro 						&rx_preset_index,
988f48ad614SDennis Dalessandro 						&tuning_method,
989f48ad614SDennis Dalessandro 						&total_atten);
990f48ad614SDennis Dalessandro 
991f48ad614SDennis Dalessandro 				/*
992f48ad614SDennis Dalessandro 				 * We may have modified the QSFP memory, so
993f48ad614SDennis Dalessandro 				 * update the cache to reflect the changes
994f48ad614SDennis Dalessandro 				 */
995f48ad614SDennis Dalessandro 				refresh_qsfp_cache(ppd, &ppd->qsfp_info);
996f48ad614SDennis Dalessandro 				limiting_active =
997f48ad614SDennis Dalessandro 						ppd->qsfp_info.limiting_active;
998f48ad614SDennis Dalessandro 			} else {
999f48ad614SDennis Dalessandro 				dd_dev_err(dd,
1000f48ad614SDennis Dalessandro 					   "%s: Reading QSFP memory failed\n",
1001f48ad614SDennis Dalessandro 					   __func__);
1002f48ad614SDennis Dalessandro 				ret = -EINVAL; /* a fail indication */
1003f48ad614SDennis Dalessandro 			}
1004f48ad614SDennis Dalessandro 			release_chip_resource(ppd->dd, qsfp_resource(ppd->dd));
1005f48ad614SDennis Dalessandro 			if (ret)
1006f48ad614SDennis Dalessandro 				goto bail;
1007f48ad614SDennis Dalessandro 		} else {
1008f48ad614SDennis Dalessandro 			ppd->offline_disabled_reason =
1009f48ad614SDennis Dalessandro 			   HFI1_ODR_MASK(
1010f48ad614SDennis Dalessandro 				OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
1011f48ad614SDennis Dalessandro 			goto bail;
1012f48ad614SDennis Dalessandro 		}
1013f48ad614SDennis Dalessandro 		break;
1014f48ad614SDennis Dalessandro 	default:
1015b4e9e2f0SSebastian Sanchez 		dd_dev_warn(ppd->dd, "%s: Unknown port type\n", __func__);
1016f48ad614SDennis Dalessandro 		ppd->port_type = PORT_TYPE_UNKNOWN;
1017f48ad614SDennis Dalessandro 		tuning_method = OPA_UNKNOWN_TUNING;
1018f48ad614SDennis Dalessandro 		total_atten = 0;
1019f48ad614SDennis Dalessandro 		limiting_active = 0;
1020f48ad614SDennis Dalessandro 		tx_preset_index = OPA_INVALID_INDEX;
1021f48ad614SDennis Dalessandro 		break;
1022f48ad614SDennis Dalessandro 	}
1023f48ad614SDennis Dalessandro 
1024f48ad614SDennis Dalessandro 	if (ppd->offline_disabled_reason ==
1025f48ad614SDennis Dalessandro 			HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
1026f48ad614SDennis Dalessandro 		apply_tunings(ppd, tx_preset_index, tuning_method,
1027f48ad614SDennis Dalessandro 			      total_atten, limiting_active);
1028f48ad614SDennis Dalessandro 
1029f48ad614SDennis Dalessandro 	if (!ret)
1030f48ad614SDennis Dalessandro 		ppd->driver_link_ready = 1;
1031f48ad614SDennis Dalessandro 
1032f48ad614SDennis Dalessandro 	return;
1033f48ad614SDennis Dalessandro bail:
1034f48ad614SDennis Dalessandro 	ppd->driver_link_ready = 0;
1035f48ad614SDennis Dalessandro }
1036