summaryrefslogtreecommitdiff
path: root/usr/src/cmd/fwflash/common/fwflash.h
blob: d4ae6f194812092844c69e060ea6ba4f68670486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_FWFLASH_H
#define	_FWFLASH_H

/*
 * fwflash.h
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/queue.h>
#include <libdevinfo.h>


#define	MSG_INFO	0
#define	MSG_WARN	1
#define	MSG_ERROR	2

#define	FWFLASH_SUCCESS		0
#define	FWFLASH_FAILURE		1

#define	FWFLASH_FLASH_IMAGES	2

#define	FWPLUGINDIR		"/usr/lib/fwflash/identify"
#define	FWVERIFYPLUGINDIR	"/usr/lib/fwflash/verify"

/*
 * we search for a variable (fwplugin_version, type uint32_t)
 * which should equal FWPLUGIN_VERSION_1
 */

#define	FWPLUGIN_VERSION_1	1
#define	FWPLUGIN_VERSION_2	2

struct devicelist;

struct fw_plugin {
	/*
	 * An opaque handle for dlopen()/dlclose() to use.
	 */
	void *handle;

	/*
	 * fully-qualified filename in /usr/lib/fwflash/identify
	 * made up of [drivername].so
	 *
	 * eg  /usr/lib/fwflash/identify/ses.so
	 * is the identification plugin for devices attached to
	 * the host using the ses(4D) driver.
	 */
	char *filename;

	/*
	 * The driver name that this plugin will search for in
	 * the device tree snapshot using di_drv_first_node(3DEVINFO)
	 * and di_drv_next_node(3DEVINFO).
	 */
	char *drvname; /* "ses" or "tavor" or .... */

	/*
	 * Function entry point to support the command-line "-r"
	 * option - read image from device to persistent storage.
	 *
	 * Not all plugins and devices will support this operation.
	 */
	int (*fw_readfw)(struct devicelist *device, char *filename);

	/*
	 * Function entry point to support the command-line "-f"
	 * option - writes from persistent storage to device
	 *
	 * All identification plugins must support this operation.
	 */
	int (*fw_writefw)(struct devicelist *device, char *filename);

	/*
	 * Function entry point used to build the list of valid, flashable
	 * devices attached to the system using the loadable module drvname.
	 * (Not all devices attached using drvname will be valid for this
	 * plugin to report.
	 *
	 * start allows us to display flashable devices attached with
	 * different drivers and provide the user with a visual clue
	 * that these devices are different to others that are detected.
	 *
	 * All identification plugins must support this operation.
	 */
	int (*fw_identify)(int start);

	/*
	 * Function entry point to support the command-line "-l"
	 * option - list/report flashable devices attached to the system.
	 *
	 * All identification plugins must support this operation.
	 */
	int (*fw_devinfo)(struct devicelist *thisdev);

	/*
	 * Function entry point to allow the plugin to clean up its
	 * data structure use IF plugin_version == FWPLUGIN_VERSION_2.
	 *
	 * If this function is not defined in the plugin, that is not
	 * an error condition unless the plugin_version variable is
	 * defined.
	 */
	void (*fw_cleanup)(struct devicelist *thisdev);
};


struct pluginlist {
	/*
	 * fully qualified filename in /usr/lib/fwflash/identify
	 * made up of fwflash-[drivername].so
	 *
	 * eg  /usr/lib/fwflash/identify/ses.so
	 * is the identification plugin for devices attached to
	 * the host using the ses(4D) driver.
	 */
	char *filename;

	/*
	 * The driver name that this plugin will search for in
	 * the device tree snapshot using di_drv_first_node(3DEVINFO)
	 * and di_drv_next_node(3DEVINFO).
	 */
	char *drvname;

	/*
	 * pointer to the actual plugin, so we can access its
	 * function entry points
	 */
	struct fw_plugin *plugin;

	/* pointer to the next element in the list */
	TAILQ_ENTRY(pluginlist) nextplugin;
};

struct vpr {
	/* vendor ID, eg "HITACHI " */
	char *vid;

	/* product ID, eg "DK32EJ36NSUN36G " */
	char *pid;

	/* revision, eg "PQ08" */
	char *revid;

	/*
	 * Additional, encapsulated identifying information.
	 * This pointer allows us to add details such as the
	 * IB hba sector size, which command set should be
	 * used or a part number.
	 */
	void *encap_ident;
};

struct fwfile {
	/*
	 * The fully qualified filename. No default location for
	 * the firmware image file is mandated.
	 */
	char *filename;

	/* Pointer to the identification plugin required */
	struct fw_plugin *plugin;

	/* pointer to the identification summary structure */
	struct vpr *ident;
};

struct devicelist {
	/*
	 * fully qualified pathname, with /devices/.... prefix
	 */
	char *access_devname;

	/*
	 * Which drivername did we find this device attached with
	 * in our device tree walk? Eg, ses or tavor or sgen...
	 */
	char *drvname;

	/*
	 * What class of device is this? For tavor-attached devices,
	 * we set this to "IB". For other devices, unless there is
	 * a common name to use, just make this the same as the
	 * drvname field.
	 */
	char *classname;

	/* pointer to the VPR structure */
	struct vpr *ident;

	/*
	 * In the original fwflash(8), it was possible to select a
	 * device for flashing by using an index number called a
	 * dev_num. We retain that concept for pluggable fwflash, with
	 * the following change - whenever our identification plugin has
	 * finished and found at least one acceptable device, we bump the
	 * index number by 100. This provides the user with another key
	 * to distinguish the desired device from a potentially very large
	 * list of similar-looking devices.
	 */
	unsigned int index;

	/*
	 * Contains SAS or FC Port-WWNs, or IB GUIDS. Both SAS and FC only
	 * need one entry in this array since they really only have one
	 * address which we should track. IB devices can have 4 GUIDs
	 * (System Image, Node Image, Port 1 and Port 2).
	 */
	char *addresses[4];

	/*
	 * Pointer to the plugin needed to flash this device, and
	 * to use for printing appropriate device-specific information
	 * as required by the "-l" option to fwflash(8).
	 */
	struct fw_plugin *plugin;

	/* Next entry in the list */
	TAILQ_ENTRY(devicelist) nextdev;
};


/*
 * this type of plugin is for the firmware image vendor-specific
 * verification functions, which we load from FWVERIFYPLUGINDIR
 */

struct vrfyplugin {
	/*
	 * fully-qualified filename in /usr/lib/fwflash/verify,
	 * made up of [drivername]-[vendorname].so
	 *
	 * eg  /usr/lib/fwflash/verify/ses-SUN.so
	 * is the verification plugin for ses-attached devices which
	 * have a vendorname of "SUN".
	 */
	char *filename;

	/*
	 * The vendor name, such as "SUN" or "MELLANOX"
	 */
	char *vendor;

	/*
	 * An opaque handle for dlopen()/dlclose() to use.
	 */
	void *handle;

	/*
	 * Firmware image size in bytes, as reported by
	 * stat().
	 */
	unsigned int imgsize;

	/*
	 * Flashable devices frequently have different buffers
	 * to use for different image types. We track the buffer
	 * required for this particular image with this variable.
	 *
	 * Once the verifier has figured out what sort of image
	 * it's been passed, it will know what value to use for
	 * this variable.
	 */
	unsigned int flashbuf;

	/*
	 * Points to the entire firmware image in memory.
	 * We do this so we can avoid multiple open()/close()
	 * operations, and to make it easier for checksum
	 * calculations.
	 */
	int *fwimage;

	/*
	 * We also store the name of the firmware file that
	 * we point to with *fwimage. This is needed in cases
	 * where we need to key off the name of the file to
	 * determine whether a different buffer in the target
	 * device should be targeted.
	 *
	 * For example, our "standard" firmware image (file.fw)
	 * might require use of buffer id 0, but a boot image
	 * (boot.fw) might require use of buffer id 17. In each
	 * case, it is the verifier plugin that determines the
	 * specific bufferid that is needed by that firmware image.
	 */
	char *imgfile;

	/*
	 * The verification function entry point. The code
	 * in fwflash.c calls this function to verify that
	 * the nominated firmware image file is valid for
	 * the selected devicenode.
	 *
	 * Note that if the verification fails, the image
	 * does _not_ get force-flashed to the device.
	 */
	int (*vendorvrfy)(struct devicelist *devicenode);
};

/* Flags for argument parsing */
#define	FWFLASH_HELP_FLAG	0x01
#define	FWFLASH_VER_FLAG	0x02
#define	FWFLASH_YES_FLAG	0x04
#define	FWFLASH_LIST_FLAG	0x08
#define	FWFLASH_CLASS_FLAG	0x10
#define	FWFLASH_DEVICE_FLAG	0x20
#define	FWFLASH_FW_FLAG		0x40
#define	FWFLASH_READ_FLAG	0x80

/* global variables for fwflash */
TAILQ_HEAD(PLUGINLIST, pluginlist);
TAILQ_HEAD(DEVICELIST, devicelist);

/* exposed global args */
extern di_node_t rootnode;
extern struct PLUGINLIST *fw_pluginlist;
extern struct DEVICELIST *fw_devices;
extern struct vrfyplugin *verifier;
extern struct fw_plugin *self;
extern int fwflash_debug;

/*
 * utility defines and macros, since the firmware image we get
 * from LSI is ARM-format and that means byte- and short-swapping
 * on sparc
 */

#define	HIGHBITS16		0xff00
#define	HIGHBITS32		0xffff0000
#define	HIGHBITS64		0xffffffff00000000ULL
#define	LOWBITS16		0x00ff
#define	LOWBITS32		0x0000ffff
#define	LOWBITS64		0x00000000ffffffffULL

#if defined(_LITTLE_ENDIAN)
#define	ARMSWAPBITS(bs)		(bs)
#define	MLXSWAPBITS16(bs)	ntohs(bs)
#define	MLXSWAPBITS32(bs)	ntohl(bs)
#define	MLXSWAPBITS64(bs)	\
	(BE_64(((bs) & LOWBITS64)) | BE_64(((bs) & HIGHBITS64)))
#else
#define	ARMSWAPBITS(bs)	(LE_32(((bs) & LOWBITS32)) | LE_32(((bs) & HIGHBITS32)))
#define	MLXSWAPBITS16(bs)	(bs)
#define	MLXSWAPBITS32(bs)	(bs)
#define	MLXSWAPBITS64(bs)	(bs)
#endif

/* common functions for fwflash */
void logmsg(int severity, const char *msg, ...);

#ifdef __cplusplus
}
#endif

#endif /* _FWFLASH_H */