xref: /titanic_44/usr/src/cmd/fwflash/plugins/hdrs/hermon_ib.h (revision cb8a054b1ab30d5caa746e6c44f29d4c9d3071c1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _HDRS_HERMON_IB_H
28 #define	_HDRS_HERMON_IB_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * ConnectX (hermon) specific definitions.
36  */
37 
38 /*
39  * The reference for the definitions in this file is the
40  *
41  *	Mellanox HCA Flash Programming Application Note
42  * (Mellanox document number 2205AN)
43  * rev 1.45, 2007. Chapter 4 in particular.
44  */
45 
46 #include <sys/types.h>
47 #include <sys/ib/adapters/hermon/hermon_ioctl.h>
48 #include "MELLANOX.h"
49 
50 #define	FWFLASH_IB_HERMON_DRIVER	"hermon"
51 
52 /*
53  * Image Info section: Refer Mellanox App note 1.45, Section 4.4
54  *
55  * The Image Info section contains management information about the
56  * firmware image. It consists of a series of consecutive data tags.
57  * Each tag contains a 32-bit header, providing a TagID which indicates
58  * the data type, and the size of the data in the tag.
59  */
60 #define	MLX_MASK_TAGID		0xff000000
61 #define	MLX_MASK_TAGSIZE	0x00ffffff
62 
63 enum tag_ids {
64 	CNX_IMAGE_INFO_REV	= 0,	/* IMAGE_INFO format revision */
65 	CNX_FW_VER		= 1,	/* Firmware Version */
66 	CNX_FW_BUILD_TIME	= 2,	/* Firmware Build Time */
67 	CNX_DEV_TYPE		= 3,	/* Device Type */
68 	CNX_PSID		= 4,	/* Parameter Set IDentification */
69 	CNX_VSD			= 5,	/* Vendor Specific Data */
70 	CNX_RES1		= 6,	/* reserved */
71 	CNX_RES2		= 7,	/* reserved */
72 	CNX_VSD_VENDOR_ID	= 8,	/* PCISIG vendor ID */
73 	/* 0x9 - 0xFE are reserved */
74 	CNX_END_TAG		= 0xff	/* END tag */
75 };
76 
77 enum tag_sizes {
78 	CNX_IMAGE_INFO_REV_SZ	= 4,
79 	CNX_FW_VER_SZ		= 8,
80 	CNX_FW_BUILD_TIME_SZ	= 8,
81 	CNX_DEV_TYPE_SZ		= 4,
82 	CNX_PSID_SZ		= 16,
83 	CNX_VSD_SZ		= 208,
84 	CNX_VSD_VENDOR_ID_SZ	= 4,
85 	CNX_END_TAG_SZ		= 0
86 };
87 
88 /*
89  * Image Info Format revision (TagID - CNX_IMAGE_INFO_REV).
90  * Provides the format revision of the Image Info section. Currently it is 0x1
91  */
92 #define	CNX_IMAGE_INFO_VER	1
93 
94 /*
95  * Firmware Version (TagID - CNX_FW_VER)
96  * Provides the major, minor and sub-minor versions of the firmware image.
97  */
98 #define	CNX_MASK_FW_VER_MAJ	0xffff0000
99 #define	CNX_MASK_FW_VER_MIN	CNX_MASK_FW_VER_MAJ
100 #define	CNX_MASK_FW_VER_SUBMIN	0x0000ffff
101 
102 typedef struct cnx_fw_rev_s {
103 	uint16_t	major;
104 	uint16_t	reserved;
105 	uint16_t	minor;
106 	uint16_t	subminor;
107 } cnx_fw_rev_t;
108 
109 
110 /*
111  * Firmware Build Time (TagID - CNX_FW_BUILD_TIME)
112  * Provides the data and time of the firmware image build.
113  */
114 #define	CNX_MASK_FW_BUILD_HOUR	0x00ff0000
115 #define	CNX_MASK_FW_BUILD_MIN	0x0000ff00
116 #define	CNX_MASK_FW_BUILD_SEC	0x000000ff
117 #define	CNX_MASK_FW_BUILD_YEAR	0xffff0000
118 #define	CNX_MASK_FW_BUILD_MON	0x0000ff00
119 #define	CNX_MASK_FW_BUILD_DAY	0x000000ff
120 
121 typedef struct cnx_fw_build_time_tag {
122 	uint8_t		reserved;
123 	uint8_t		hour;
124 	uint8_t		minute;
125 	uint8_t		second;
126 	uint16_t	year;
127 	uint8_t		month;
128 	uint8_t		day;
129 } cnx_fw_build_time_t;
130 
131 /*
132  * Device Type (TagID - CNX_DEV_TYPE)
133  * The device type tag is only 4 bytes long, so we don't bother to
134  * declare a separate struct for it.
135  *
136  * The CNX_MASK_DEV_TYPE_REV provides the mask to extract the hardware
137  * device's PCI Revision ID.
138  * The CNX_MASK_DEV_TYPE_ID provides the mask to extract the hardware
139  * device's PCI Device ID.
140  */
141 #define	CNX_MASK_DEV_TYPE_REV	0x00ff0000
142 #define	CNX_MASK_DEV_TYPE_ID	0x0000ffff
143 
144 /*
145  * The PSID (TagID - CNX_PSID) and VSD (TagID - CNX_VSD) tag contents are
146  * just bytes without any specific structure, so we'll declare their sizes
147  * but nothing else.
148  */
149 #define	CNX_TAG_PSID_SIZE		0x10
150 #define	CNX_TAG_VSD_SIZE		0xD0
151 
152 /*
153  * VSD Vendor ID (TagID - CNX_VSD_VENDOR_ID)
154  * The VSD Vendor ID tag holds the PCISIG vendor ID of the vendor that
155  * fills the VSD tag.
156  */
157 #define	CNX_MASK_VSD_VENDORID		0x00ff
158 
159 typedef struct cnx_img_info_s {
160 	cnx_fw_rev_t		fw_rev;
161 	cnx_fw_build_time_t	fw_buildtime;
162 	uint16_t		dev_id;
163 	uint16_t		vsd_vendor_id;
164 	uint8_t			psid[CNX_PSID_SZ];
165 	uint8_t			vsd[CNX_VSD_SZ];
166 } cnx_img_info_t;
167 
168 /*
169  * ConnectX Devices Firmware Image Format
170  */
171 typedef struct mlx_cnx_xfi {			/* Byte Offset */
172 	uint32_t	magic_pattern[4];	/* 0x00 - 0x0F */
173 	uint8_t		xfiresv1[24];		/* 0x10 - 0x27 */
174 	uint32_t	failsafechunkinfo;	/* 0x28 - 0x2B */
175 	uint32_t	imageinfoptr;		/* 0x2C - 0x2F */
176 	uint32_t	fwimagesz;		/* 0x30 - 0x33 */
177 	uint32_t	nguidptr;		/* 0x34 - 0x37 */
178 	uint8_t		*xfiremainder;
179 } mlx_cnx_xfi_t;
180 
181 uint32_t	cnx_magic_pattern[4] = {
182 			0x4D544657,
183 			0x8CDFD000,
184 			0xDEAD9270,
185 			0x4154BEEF };
186 
187 #define	CNX_XFI_IMGINFO_CKSUM_MASK	0xFF000000
188 #define	CNX_XFI_IMGINFO_PTR_MASK	0x00FFFFFF
189 
190 #define	CNX_HWVER_OFFSET		0x20
191 #define	CNX_HWVER_MASK			0xFF000000
192 
193 #define	CNX_CHUNK_SIZE_OFFSET		0x28
194 #define	CNX_IMG_INF_PTR_OFFSET		0x2C
195 #define	CNX_IMG_INF_SZ_OFFSET		-0x0C
196 #define	CNX_IMG_SIZE_OFFSET		0x30
197 #define	CNX_NGUIDPTR_OFFSET		0x34
198 
199 /*
200  * ConnectX Devices GUID Section Structure.
201  *
202  * Of all the structures we poke around with, we're packing
203  * these because we frequently have to operate on them as
204  * plain old byte arrays. If we don't pack it then the compiler
205  * will "properly" align it for us - which results in a
206  * structure that's a l l  s p r e a d  o u t.
207  */
208 #pragma pack(1)
209 typedef struct mlx_cnx_guid_sect {	/* Byte Offset */
210 	uint8_t		guidresv[16];	/* 0x00 - 0x0F */
211 	uint64_t	nodeguid;	/* 0x10 - 0x17 */
212 	uint64_t	port1guid;	/* 0x18 - 0x1F */
213 	uint64_t	port2guid;	/* 0x20 - 0x27 */
214 	uint64_t	sysimguid;	/* 0x28 - 0x2F */
215 	uint64_t	port1_mac; 	/* 0x30 - 0x31 - rsvd - must be zero */
216 					/* 0x32 - 0x37 - Port1 MAC [47:0] */
217 	uint64_t	port2_mac; 	/* 0x38 - 0x39 - rsvd - must be zero */
218 					/* 0x3A - 0x3F - Port2 MAC [47:0] */
219 	uint16_t	guidresv2;	/* 0x40 - 0x41 */
220 	uint16_t	guidcrc;	/* 0x42 - 0x43 */
221 } mlx_cnx_guid_sect_t;
222 #pragma pack()
223 
224 #define	CNX_NGUID_OFFSET		0x10
225 #define	CNX_P1GUID_OFFSET		0x18
226 #define	CNX_P2GUID_OFFSET		0x20
227 #define	CNX_SYSIMGUID_OFFSET		0x28
228 #define	CNX_P1MAC_OFFSET		0x32
229 #define	CNX_P2MAC_OFFSET		0x3A
230 #define	CNX_GUID_CRC16_SIZE		0x40	/* 00-3F */
231 #define	CNX_GUID_CRC16_OFFSET		0x42
232 
233 
234 /* we hook this struct into vpr->encap_ident */
235 typedef struct ib_cnx_encap_ident_s {
236 	uint_t		magic;		/* FWFLASH_IB_MAGIC_NUMBER */
237 	int		fd;		/* fd of hermon device */
238 	int		cmd_set;	/* COMMAND SET */
239 	int		pn_len;		/* Part# Length */
240 	int		hwfw_match;	/* 1 = match, 0 - nomatch */
241 					/* Used during write for validation */
242 	cnx_img_info_t	hwfw_img_info;	/* HW Image Info Section */
243 	cnx_img_info_t	file_img_info;	/* Image File's Image Info Section */
244 	mlx_mdr_t	info;		/* Details of HW part#, name, */
245 	uint32_t	*fw;		/* this where image is read to */
246 	uint32_t	hwrev;		/* H/W revision. ex: A0, A1 */
247 	uint32_t	fw_sz;		/* FW image size */
248 	uint32_t	sector_sz;	/* FW sector size */
249 	uint32_t	device_sz;	/* FW device size */
250 	uint32_t	state;
251 	uint64_t	ibguids[4];	/* HW's GUIDs backup info */
252 	uint64_t	ib_mac[2];	/* HW's MAC backup info */
253 	uint32_t	log2_chunk_sz;	/* FW chunk size */
254 	uint32_t	img2_start_addr;	/* Boot Address, 0 - Pri */
255 } ib_cnx_encap_ident_t;
256 
257 /*
258  * Common Flash Interface data.
259  */
260 typedef union cfi_u {
261 	uchar_t		cfi_char[HERMON_CFI_INFO_SIZE];
262 	uint32_t	cfi_int[HERMON_CFI_INFO_QSIZE];
263 } cfi_t;
264 
265 /* used by both identify and verifier plugin */
266 uint16_t cnx_crc16(uint8_t *image, uint32_t size, int is_image);
267 int cnx_is_magic_pattern_present(int *data, int hwim_or_fwim);
268 int cnx_parse_img_info(int *buf, uint32_t byte_size, cnx_img_info_t *img_info,
269     int is_image);
270 
271 #define	CNX_FILE_IMG	1	/* Processing File Image */
272 #define	CNX_HW_IMG	2	/* Processing Hardware Image */
273 
274 /* Validate the handle */
275 #define	CNX_I_CHECK_HANDLE(s)	\
276 	((s == NULL) || ((s)->magic != FWFLASH_IB_MAGIC_NUMBER))
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif /* _HDRS_HERMON_IB_H */
283