162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
362306a36Sopenharmony_ci * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * This software is available to you under a choice of one of two
662306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
762306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
862306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
962306a36Sopenharmony_ci * OpenIB.org BSD license below:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1262306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1362306a36Sopenharmony_ci *     conditions are met:
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1662306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1762306a36Sopenharmony_ci *        disclaimer.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
2062306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2162306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2262306a36Sopenharmony_ci *        provided with the distribution.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2562306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2662306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2762306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2862306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2962306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3062306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3162306a36Sopenharmony_ci * SOFTWARE.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ci/* QSFP support common definitions, for ib_qib driver */
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define QSFP_DEV 0xA0
3662306a36Sopenharmony_ci#define QSFP_PWR_LAG_MSEC 2000
3762306a36Sopenharmony_ci#define QSFP_MODPRS_LAG_MSEC 20
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * Below are masks for various QSFP signals, for Port 1.
4162306a36Sopenharmony_ci * Port2 equivalents are shifted by QSFP_GPIO_PORT2_SHIFT.
4262306a36Sopenharmony_ci * _N means asserted low
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci#define QSFP_GPIO_MOD_SEL_N (4)
4562306a36Sopenharmony_ci#define QSFP_GPIO_MOD_PRS_N (8)
4662306a36Sopenharmony_ci#define QSFP_GPIO_INT_N (0x10)
4762306a36Sopenharmony_ci#define QSFP_GPIO_MOD_RST_N (0x20)
4862306a36Sopenharmony_ci#define QSFP_GPIO_LP_MODE (0x40)
4962306a36Sopenharmony_ci#define QSFP_GPIO_PORT2_SHIFT 5
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define QSFP_PAGESIZE 128
5262306a36Sopenharmony_ci/* Defined fields that QLogic requires of qualified cables */
5362306a36Sopenharmony_ci/* Byte 0 is Identifier, not checked */
5462306a36Sopenharmony_ci/* Byte 1 is reserved "status MSB" */
5562306a36Sopenharmony_ci/* Byte 2 is "status LSB" We only care that D2 "Flat Mem" is set. */
5662306a36Sopenharmony_ci/*
5762306a36Sopenharmony_ci * Rest of first 128 not used, although 127 is reserved for page select
5862306a36Sopenharmony_ci * if module is not "Flat memory".
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_ci/* Byte 128 is Identifier: must be 0x0c for QSFP, or 0x0d for QSFP+ */
6162306a36Sopenharmony_ci#define QSFP_MOD_ID_OFFS 128
6262306a36Sopenharmony_ci/*
6362306a36Sopenharmony_ci * Byte 129 is "Extended Identifier". We only care about D7,D6: Power class
6462306a36Sopenharmony_ci *  0:1.5W, 1:2.0W, 2:2.5W, 3:3.5W
6562306a36Sopenharmony_ci */
6662306a36Sopenharmony_ci#define QSFP_MOD_PWR_OFFS 129
6762306a36Sopenharmony_ci/* Byte 130 is Connector type. Not QLogic req'd */
6862306a36Sopenharmony_ci/* Bytes 131..138 are Transceiver types, bit maps for various tech, none IB */
6962306a36Sopenharmony_ci/* Byte 139 is encoding. code 0x01 is 8b10b. Not QLogic req'd */
7062306a36Sopenharmony_ci/* byte 140 is nominal bit-rate, in units of 100Mbits/sec Not QLogic req'd */
7162306a36Sopenharmony_ci/* Byte 141 is Extended Rate Select. Not QLogic req'd */
7262306a36Sopenharmony_ci/* Bytes 142..145 are lengths for various fiber types. Not QLogic req'd */
7362306a36Sopenharmony_ci/* Byte 146 is length for Copper. Units of 1 meter */
7462306a36Sopenharmony_ci#define QSFP_MOD_LEN_OFFS 146
7562306a36Sopenharmony_ci/*
7662306a36Sopenharmony_ci * Byte 147 is Device technology. D0..3 not Qlogc req'd
7762306a36Sopenharmony_ci * D4..7 select from 15 choices, translated by table:
7862306a36Sopenharmony_ci */
7962306a36Sopenharmony_ci#define QSFP_MOD_TECH_OFFS 147
8062306a36Sopenharmony_ciextern const char *const qib_qsfp_devtech[16];
8162306a36Sopenharmony_ci/* Active Equalization includes fiber, copper full EQ, and copper near Eq */
8262306a36Sopenharmony_ci#define QSFP_IS_ACTIVE(tech) ((0xA2FF >> ((tech) >> 4)) & 1)
8362306a36Sopenharmony_ci/* Active Equalization includes fiber, copper full EQ, and copper far Eq */
8462306a36Sopenharmony_ci#define QSFP_IS_ACTIVE_FAR(tech) ((0x32FF >> ((tech) >> 4)) & 1)
8562306a36Sopenharmony_ci/* Attenuation should be valid for copper other than full/near Eq */
8662306a36Sopenharmony_ci#define QSFP_HAS_ATTEN(tech) ((0x4D00 >> ((tech) >> 4)) & 1)
8762306a36Sopenharmony_ci/* Length is only valid if technology is "copper" */
8862306a36Sopenharmony_ci#define QSFP_IS_CU(tech) ((0xED00 >> ((tech) >> 4)) & 1)
8962306a36Sopenharmony_ci#define QSFP_TECH_1490 9
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define QSFP_OUI(oui) (((unsigned)oui[0] << 16) | ((unsigned)oui[1] << 8) | \
9262306a36Sopenharmony_ci			oui[2])
9362306a36Sopenharmony_ci#define QSFP_OUI_AMPHENOL 0x415048
9462306a36Sopenharmony_ci#define QSFP_OUI_FINISAR  0x009065
9562306a36Sopenharmony_ci#define QSFP_OUI_GORE     0x002177
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* Bytes 148..163 are Vendor Name, Left-justified Blank-filled */
9862306a36Sopenharmony_ci#define QSFP_VEND_OFFS 148
9962306a36Sopenharmony_ci#define QSFP_VEND_LEN 16
10062306a36Sopenharmony_ci/* Byte 164 is IB Extended tranceiver codes Bits D0..3 are SDR,DDR,QDR,EDR */
10162306a36Sopenharmony_ci#define QSFP_IBXCV_OFFS 164
10262306a36Sopenharmony_ci/* Bytes 165..167 are Vendor OUI number */
10362306a36Sopenharmony_ci#define QSFP_VOUI_OFFS 165
10462306a36Sopenharmony_ci#define QSFP_VOUI_LEN 3
10562306a36Sopenharmony_ci/* Bytes 168..183 are Vendor Part Number, string */
10662306a36Sopenharmony_ci#define QSFP_PN_OFFS 168
10762306a36Sopenharmony_ci#define QSFP_PN_LEN 16
10862306a36Sopenharmony_ci/* Bytes 184,185 are Vendor Rev. Left Justified, Blank-filled */
10962306a36Sopenharmony_ci#define QSFP_REV_OFFS 184
11062306a36Sopenharmony_ci#define QSFP_REV_LEN 2
11162306a36Sopenharmony_ci/*
11262306a36Sopenharmony_ci * Bytes 186,187 are Wavelength, if Optical. Not Qlogic req'd
11362306a36Sopenharmony_ci *  If copper, they are attenuation in dB:
11462306a36Sopenharmony_ci * Byte 186 is at 2.5Gb/sec (SDR), Byte 187 at 5.0Gb/sec (DDR)
11562306a36Sopenharmony_ci */
11662306a36Sopenharmony_ci#define QSFP_ATTEN_OFFS 186
11762306a36Sopenharmony_ci#define QSFP_ATTEN_LEN 2
11862306a36Sopenharmony_ci/* Bytes 188,189 are Wavelength tolerance, not QLogic req'd */
11962306a36Sopenharmony_ci/* Byte 190 is Max Case Temp. Not QLogic req'd */
12062306a36Sopenharmony_ci/* Byte 191 is LSB of sum of bytes 128..190. Not QLogic req'd */
12162306a36Sopenharmony_ci#define QSFP_CC_OFFS 191
12262306a36Sopenharmony_ci/* Bytes 192..195 are Options implemented in qsfp. Not Qlogic req'd */
12362306a36Sopenharmony_ci/* Bytes 196..211 are Serial Number, String */
12462306a36Sopenharmony_ci#define QSFP_SN_OFFS 196
12562306a36Sopenharmony_ci#define QSFP_SN_LEN 16
12662306a36Sopenharmony_ci/* Bytes 212..219 are date-code YYMMDD (MM==1 for Jan) */
12762306a36Sopenharmony_ci#define QSFP_DATE_OFFS 212
12862306a36Sopenharmony_ci#define QSFP_DATE_LEN 6
12962306a36Sopenharmony_ci/* Bytes 218,219 are optional lot-code, string */
13062306a36Sopenharmony_ci#define QSFP_LOT_OFFS 218
13162306a36Sopenharmony_ci#define QSFP_LOT_LEN 2
13262306a36Sopenharmony_ci/* Bytes 220, 221 indicate monitoring options, Not QLogic req'd */
13362306a36Sopenharmony_ci/* Byte 223 is LSB of sum of bytes 192..222 */
13462306a36Sopenharmony_ci#define QSFP_CC_EXT_OFFS 223
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/*
13762306a36Sopenharmony_ci * struct qib_qsfp_data encapsulates state of QSFP device for one port.
13862306a36Sopenharmony_ci * it will be part of port-chip-specific data if a board supports QSFP.
13962306a36Sopenharmony_ci *
14062306a36Sopenharmony_ci * Since multiple board-types use QSFP, and their pport_data structs
14162306a36Sopenharmony_ci * differ (in the chip-specific section), we need a pointer to its head.
14262306a36Sopenharmony_ci *
14362306a36Sopenharmony_ci * Avoiding premature optimization, we will have one work_struct per port,
14462306a36Sopenharmony_ci * and let the (increasingly inaccurately named) eep_lock arbitrate
14562306a36Sopenharmony_ci * access to common resources.
14662306a36Sopenharmony_ci *
14762306a36Sopenharmony_ci */
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/*
15062306a36Sopenharmony_ci * Hold the parts of the onboard EEPROM that we care about, so we aren't
15162306a36Sopenharmony_ci * coonstantly bit-boffing
15262306a36Sopenharmony_ci */
15362306a36Sopenharmony_cistruct qib_qsfp_cache {
15462306a36Sopenharmony_ci	u8 id;	/* must be 0x0C or 0x0D; 0 indicates invalid EEPROM read */
15562306a36Sopenharmony_ci	u8 pwr; /* in D6,7 */
15662306a36Sopenharmony_ci	u8 len;	/* in meters, Cu only */
15762306a36Sopenharmony_ci	u8 tech;
15862306a36Sopenharmony_ci	char vendor[QSFP_VEND_LEN];
15962306a36Sopenharmony_ci	u8 xt_xcv; /* Ext. tranceiver codes, 4 lsbs are IB speed supported */
16062306a36Sopenharmony_ci	u8 oui[QSFP_VOUI_LEN];
16162306a36Sopenharmony_ci	u8 partnum[QSFP_PN_LEN];
16262306a36Sopenharmony_ci	u8 rev[QSFP_REV_LEN];
16362306a36Sopenharmony_ci	u8 atten[QSFP_ATTEN_LEN];
16462306a36Sopenharmony_ci	u8 cks1;	/* Checksum of bytes 128..190 */
16562306a36Sopenharmony_ci	u8 serial[QSFP_SN_LEN];
16662306a36Sopenharmony_ci	u8 date[QSFP_DATE_LEN];
16762306a36Sopenharmony_ci	u8 lot[QSFP_LOT_LEN];
16862306a36Sopenharmony_ci	u8 cks2;	/* Checsum of bytes 192..222 */
16962306a36Sopenharmony_ci};
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci#define QSFP_PWR(pbyte) (((pbyte) >> 6) & 3)
17262306a36Sopenharmony_ci#define QSFP_ATTEN_SDR(attenarray) (attenarray[0])
17362306a36Sopenharmony_ci#define QSFP_ATTEN_DDR(attenarray) (attenarray[1])
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_cistruct qib_qsfp_data {
17662306a36Sopenharmony_ci	/* Helps to find our way */
17762306a36Sopenharmony_ci	struct qib_pportdata *ppd;
17862306a36Sopenharmony_ci	struct work_struct work;
17962306a36Sopenharmony_ci	struct qib_qsfp_cache cache;
18062306a36Sopenharmony_ci	unsigned long t_insert;
18162306a36Sopenharmony_ci	u8 modpresent;
18262306a36Sopenharmony_ci};
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ciextern int qib_refresh_qsfp_cache(struct qib_pportdata *ppd,
18562306a36Sopenharmony_ci				  struct qib_qsfp_cache *cp);
18662306a36Sopenharmony_ciextern int qib_qsfp_mod_present(struct qib_pportdata *ppd);
18762306a36Sopenharmony_ciextern void qib_qsfp_init(struct qib_qsfp_data *qd,
18862306a36Sopenharmony_ci			  void (*fevent)(struct work_struct *));
189