1*9e39c5baSBill Taylor /*
2*9e39c5baSBill Taylor  * CDDL HEADER START
3*9e39c5baSBill Taylor  *
4*9e39c5baSBill Taylor  * The contents of this file are subject to the terms of the
5*9e39c5baSBill Taylor  * Common Development and Distribution License (the "License").
6*9e39c5baSBill Taylor  * You may not use this file except in compliance with the License.
7*9e39c5baSBill Taylor  *
8*9e39c5baSBill Taylor  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9e39c5baSBill Taylor  * or http://www.opensolaris.org/os/licensing.
10*9e39c5baSBill Taylor  * See the License for the specific language governing permissions
11*9e39c5baSBill Taylor  * and limitations under the License.
12*9e39c5baSBill Taylor  *
13*9e39c5baSBill Taylor  * When distributing Covered Code, include this CDDL HEADER in each
14*9e39c5baSBill Taylor  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9e39c5baSBill Taylor  * If applicable, add the following below this CDDL HEADER, with the
16*9e39c5baSBill Taylor  * fields enclosed by brackets "[]" replaced with your own identifying
17*9e39c5baSBill Taylor  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9e39c5baSBill Taylor  *
19*9e39c5baSBill Taylor  * CDDL HEADER END
20*9e39c5baSBill Taylor  */
21*9e39c5baSBill Taylor 
22*9e39c5baSBill Taylor /*
23*9e39c5baSBill Taylor  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*9e39c5baSBill Taylor  * Use is subject to license terms.
25*9e39c5baSBill Taylor  */
26*9e39c5baSBill Taylor 
27*9e39c5baSBill Taylor #ifndef _TAVOR_IB_H
28*9e39c5baSBill Taylor #define	_TAVOR_IB_H
29*9e39c5baSBill Taylor 
30*9e39c5baSBill Taylor /*
31*9e39c5baSBill Taylor  * tavor_ib.h
32*9e39c5baSBill Taylor  */
33*9e39c5baSBill Taylor 
34*9e39c5baSBill Taylor #ifdef __cplusplus
35*9e39c5baSBill Taylor extern "C" {
36*9e39c5baSBill Taylor #endif
37*9e39c5baSBill Taylor 
38*9e39c5baSBill Taylor #include <sys/types.h>
39*9e39c5baSBill Taylor #include <sys/ib/adapters/tavor/tavor_ioctl.h>
40*9e39c5baSBill Taylor 
41*9e39c5baSBill Taylor #define	FWFLASH_IB_DRIVER_NAME		"tavor"
42*9e39c5baSBill Taylor 
43*9e39c5baSBill Taylor #define	NODE_GUID_OFFSET		0x0
44*9e39c5baSBill Taylor #define	PORT1_GUID_OFFSET		0x08
45*9e39c5baSBill Taylor #define	PORT2_GUID_OFFSET		0x10
46*9e39c5baSBill Taylor #define	FLASH_SIZE_OFFSET		0x20
47*9e39c5baSBill Taylor #define	FLASH_GUID_PTR			0x24
48*9e39c5baSBill Taylor 
49*9e39c5baSBill Taylor typedef struct fw_rev_s {
50*9e39c5baSBill Taylor 	uint32_t	major;
51*9e39c5baSBill Taylor 	uint32_t	minor;
52*9e39c5baSBill Taylor 	uint32_t	subminor;
53*9e39c5baSBill Taylor 	uint32_t	holder;
54*9e39c5baSBill Taylor } fw_rev_t;
55*9e39c5baSBill Taylor 
56*9e39c5baSBill Taylor 
57*9e39c5baSBill Taylor typedef struct mlx_is {
58*9e39c5baSBill Taylor 	uint8_t		isresv1[16];
59*9e39c5baSBill Taylor 	uint8_t		hwrev; /* hardware version */
60*9e39c5baSBill Taylor 	uint8_t		isver; /* Invariant Sector version */
61*9e39c5baSBill Taylor 	uint32_t	isresv2;
62*9e39c5baSBill Taylor 	/* offset from 0x32 to get log2sectsz */
63*9e39c5baSBill Taylor 	uint16_t	log2sectszp;
64*9e39c5baSBill Taylor 	/*
65*9e39c5baSBill Taylor 	 * 3rd lot of reserved bytes CAN BE variable length,
66*9e39c5baSBill Taylor 	 * but defaults to 0x18 bytes
67*9e39c5baSBill Taylor 	 */
68*9e39c5baSBill Taylor 	uint8_t		isresv3[0x18];
69*9e39c5baSBill Taylor 	uint16_t	log2sectsz; /* log_2 of flash sector size */
70*9e39c5baSBill Taylor 	uint8_t		*isresv4; /* remainder of IS */
71*9e39c5baSBill Taylor } mlx_is_t;
72*9e39c5baSBill Taylor 
73*9e39c5baSBill Taylor typedef struct mlx_xps {
74*9e39c5baSBill Taylor 	uint32_t	fia; /* fw image addr */
75*9e39c5baSBill Taylor 	uint32_t	fis; /* fw image size */
76*9e39c5baSBill Taylor 	uint32_t	signature; /* firmware signature */
77*9e39c5baSBill Taylor 	uint8_t		xpsresv1[20];
78*9e39c5baSBill Taylor 	uint8_t		vsdpsid[224]; /* VSD and PSID */
79*9e39c5baSBill Taylor 	uint32_t	xpsresv2;
80*9e39c5baSBill Taylor 	uint16_t	xpsresv3; /* MUST be zero */
81*9e39c5baSBill Taylor 	uint16_t	crc16;
82*9e39c5baSBill Taylor 	uint8_t		*xpsresv4; /* from 0x108 to END OF SECTOR */
83*9e39c5baSBill Taylor } mlx_xps_t;
84*9e39c5baSBill Taylor 
85*9e39c5baSBill Taylor 
86*9e39c5baSBill Taylor #define	XFI_IMGINFO_OFFSET	28
87*9e39c5baSBill Taylor #define	XFI_IMGINFO_CKSUM_MASK	0xFF000000
88*9e39c5baSBill Taylor #define	XFI_IMGINFO_PTR_MASK	0x00FFFFFF
89*9e39c5baSBill Taylor 
90*9e39c5baSBill Taylor typedef struct mlx_xfi {
91*9e39c5baSBill Taylor 	uint8_t		xfiresv1[28];
92*9e39c5baSBill Taylor 	uint32_t	imageinfoptr;
93*9e39c5baSBill Taylor 	uint32_t	xfiresv2;
94*9e39c5baSBill Taylor 	uint32_t	nguidptr;
95*9e39c5baSBill Taylor 	uint8_t		*xfiremainder;
96*9e39c5baSBill Taylor } mlx_xfi_t;
97*9e39c5baSBill Taylor 
98*9e39c5baSBill Taylor /*
99*9e39c5baSBill Taylor  * Of all the structures we poke around with, we're packing
100*9e39c5baSBill Taylor  * these because we frequently have to operate on them as
101*9e39c5baSBill Taylor  * plain old byte arrays. If we don't pack it then the compiler
102*9e39c5baSBill Taylor  * will "properly" align it for us - which results in a
103*9e39c5baSBill Taylor  * structure that's a l l  s p r e a d  o u t.
104*9e39c5baSBill Taylor  */
105*9e39c5baSBill Taylor #pragma pack(1)
106*9e39c5baSBill Taylor typedef struct mlx_guid_sect
107*9e39c5baSBill Taylor {
108*9e39c5baSBill Taylor 	uint8_t		guidresv[16];
109*9e39c5baSBill Taylor 	uint64_t	nodeguid;
110*9e39c5baSBill Taylor 	uint64_t	port1guid;
111*9e39c5baSBill Taylor 	uint64_t	port2guid;
112*9e39c5baSBill Taylor 	uint64_t	sysimguid;
113*9e39c5baSBill Taylor 	uint16_t	guidresv2;
114*9e39c5baSBill Taylor 	uint16_t	guidcrc;
115*9e39c5baSBill Taylor } mlx_guid_sect_t;
116*9e39c5baSBill Taylor #pragma pack()
117*9e39c5baSBill Taylor 
118*9e39c5baSBill Taylor /* this is 13x 32bit words */
119*9e39c5baSBill Taylor #define	GUIDSECTION_SZ	sizeof (struct mlx_guid_sect)
120*9e39c5baSBill Taylor 
121*9e39c5baSBill Taylor /* we hook this struct into vpr->encap_ident */
122*9e39c5baSBill Taylor typedef struct ib_encap_ident {
123*9e39c5baSBill Taylor 	uint_t		magic;
124*9e39c5baSBill Taylor 	int		fd;
125*9e39c5baSBill Taylor 	fw_rev_t	fw_rev;
126*9e39c5baSBill Taylor 	uint32_t	hwrev;
127*9e39c5baSBill Taylor 	uint32_t	sector_sz;
128*9e39c5baSBill Taylor 	uint32_t	device_sz;
129*9e39c5baSBill Taylor 	uint32_t	state;
130*9e39c5baSBill Taylor 	int		cmd_set;
131*9e39c5baSBill Taylor 	mlx_mdr_t	info;
132*9e39c5baSBill Taylor 	int		pn_len;
133*9e39c5baSBill Taylor 	int		hwfw_match;
134*9e39c5baSBill Taylor 	uint32_t	pfi_guid_addr; /* addr of the offset */
135*9e39c5baSBill Taylor 	uint32_t	sfi_guid_addr;
136*9e39c5baSBill Taylor 	uint32_t	pri_guid_section[GUIDSECTION_SZ];
137*9e39c5baSBill Taylor 	uint32_t	sec_guid_section[GUIDSECTION_SZ];
138*9e39c5baSBill Taylor 	uint64_t	ibguids[4];
139*9e39c5baSBill Taylor 	uint8_t		*inv; /* Invariant Sector */
140*9e39c5baSBill Taylor 	uint8_t		*pps; /* Primary Pointer Sector */
141*9e39c5baSBill Taylor 	uint8_t		*sps; /* Secondary Pointer Sector */
142*9e39c5baSBill Taylor 	uint8_t		*pfi; /* Primary Firmware Image */
143*9e39c5baSBill Taylor 	uint8_t		*sfi; /* Secondary Firmware Image */
144*9e39c5baSBill Taylor 	uint8_t		mlx_psid[16];
145*9e39c5baSBill Taylor 	uint8_t		mlx_vsd[208];
146*9e39c5baSBill Taylor } ib_encap_ident_t;
147*9e39c5baSBill Taylor 
148*9e39c5baSBill Taylor #define	FLASH_PS_SIGNATURE				0x5a445a44
149*9e39c5baSBill Taylor 
150*9e39c5baSBill Taylor #define	FLASH_IS_SECTOR_SIZE_OFFSET			0x32
151*9e39c5baSBill Taylor #define	FLASH_IS_SECTOR_SIZE_MASK			0x0000FFFF
152*9e39c5baSBill Taylor #define	FLASH_IS_HWVER_OFFSET				0x10
153*9e39c5baSBill Taylor #define	FLASH_IS_HWVER_MASK				0xFF000000
154*9e39c5baSBill Taylor #define	FLASH_IS_ISVER_MASK				0x00FF0000
155*9e39c5baSBill Taylor 
156*9e39c5baSBill Taylor #define	FLASH_IS_SECT_SIZE_PTR				0x16
157*9e39c5baSBill Taylor #define	FLASH_IS_SECT_SIZE_PTR_MASK			0x0000FFFF
158*9e39c5baSBill Taylor 
159*9e39c5baSBill Taylor #define	FLASH_PS_FI_ADDR_OFFSET				0x00
160*9e39c5baSBill Taylor #define	FLASH_PS_FW_SIZE_OFFSET				0x04
161*9e39c5baSBill Taylor #define	FLASH_PS_SIGNATURE_OFFSET			0x08
162*9e39c5baSBill Taylor /* Vendor Specific Data (VSD) */
163*9e39c5baSBill Taylor #define	FLASH_PS_VSD_OFFSET				0x20
164*9e39c5baSBill Taylor /* VSD length in bytes */
165*9e39c5baSBill Taylor #define	FLASH_PS_VSD_LENGTH				0xE0
166*9e39c5baSBill Taylor #define	FLASH_PS_VSD_LENGTH_4				0x38
167*9e39c5baSBill Taylor /* PSID is the last 16B of VSD */
168*9e39c5baSBill Taylor #define	FLASH_PS_PSID_OFFSET				0xF0
169*9e39c5baSBill Taylor 
170*9e39c5baSBill Taylor /* For use with Cisco's VSD */
171*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_SIGNATURE			0x05ad
172*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_BOOT_OPTIONS			0x00000004
173*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_FLAG_AUTOUPGRADE		0x01000000
174*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_PORT_1		0x00010000
175*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_PORT_2		0x00020000
176*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_SCAN		0x00040000
177*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_FLAG_BOOT_TYPE_WELL_KNOWN	0x00000000
178*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_FLAG_BOOT_TRY_FOREVER		0x00001000
179*9e39c5baSBill Taylor #define	FLASH_VSD_CISCO_BOOT_VERSION			2
180*9e39c5baSBill Taylor /* For use with Cisco's VSD */
181*9e39c5baSBill Taylor 
182*9e39c5baSBill Taylor #define	MLX_CISCO_CHECK					1
183*9e39c5baSBill Taylor #define	MLX_CISCO_SET					2
184*9e39c5baSBill Taylor 
185*9e39c5baSBill Taylor #define	FLASH_PS_CRC16_SIZE				0x104
186*9e39c5baSBill Taylor #define	FLASH_PS_CRC16_OFFSET				0x106
187*9e39c5baSBill Taylor 
188*9e39c5baSBill Taylor #define	FLASH_FI_NGUID_OFFSET				0x0
189*9e39c5baSBill Taylor #define	FLASH_FI_P1GUID_OFFSET				0x08
190*9e39c5baSBill Taylor #define	FLASH_FI_P2GUID_OFFSET				0x10
191*9e39c5baSBill Taylor #define	FLASH_FI_SYSIMGUID_OFFSET			0x18
192*9e39c5baSBill Taylor #define	FLASH_GUID_CRC16_SIZE				0x30
193*9e39c5baSBill Taylor #define	FLASH_GUID_CRC16_OFFSET				0x32
194*9e39c5baSBill Taylor #define	FLASH_GUID_SIZE					0x34
195*9e39c5baSBill Taylor 
196*9e39c5baSBill Taylor #define	FLASH_GUID_CRC_LEN				0x2F
197*9e39c5baSBill Taylor /*
198*9e39c5baSBill Taylor  * Used during read/write ioctl calls to setup the offset into the firmware
199*9e39c5baSBill Taylor  * image memory for that particular sector.
200*9e39c5baSBill Taylor  */
201*9e39c5baSBill Taylor #define	FLASH_SECTOR_OFFSET(fw, sect, sz)		\
202*9e39c5baSBill Taylor 	(caddr_t)((uintptr_t)fw + (sect << sz))
203*9e39c5baSBill Taylor 
204*9e39c5baSBill Taylor /*
205*9e39c5baSBill Taylor  * Vital System Data from PCI config space.
206*9e39c5baSBill Taylor  */
207*9e39c5baSBill Taylor uint32_t vsd_int[FLASH_PS_VSD_LENGTH_4];
208*9e39c5baSBill Taylor 
209*9e39c5baSBill Taylor 
210*9e39c5baSBill Taylor /*
211*9e39c5baSBill Taylor  * Common Flash Interface data.
212*9e39c5baSBill Taylor  */
213*9e39c5baSBill Taylor typedef union cfi_u {
214*9e39c5baSBill Taylor 	uchar_t cfi_char[TAVOR_CFI_INFO_SIZE];
215*9e39c5baSBill Taylor 	uint32_t cfi_int[TAVOR_CFI_INFO_QSIZE];
216*9e39c5baSBill Taylor } cfi_t;
217*9e39c5baSBill Taylor 
218*9e39c5baSBill Taylor 
219*9e39c5baSBill Taylor #ifdef __cplusplus
220*9e39c5baSBill Taylor }
221*9e39c5baSBill Taylor #endif
222*9e39c5baSBill Taylor 
223*9e39c5baSBill Taylor 
224*9e39c5baSBill Taylor 
225*9e39c5baSBill Taylor 
226*9e39c5baSBill Taylor #endif /* _TAVOR_IB_H */
227