dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / fwflash / common / fwflash.h
blob46bffe33727c717e64a393e0305345d8b1edc33b
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _FWFLASH_H
27 #define _FWFLASH_H
30 * fwflash.h
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #include <sys/queue.h>
38 #include <libdevinfo.h>
41 #define MSG_INFO 0
42 #define MSG_WARN 1
43 #define MSG_ERROR 2
45 #define FWFLASH_SUCCESS 0
46 #define FWFLASH_FAILURE 1
48 #define FWFLASH_FLASH_IMAGES 2
50 #define FWPLUGINDIR "/usr/lib/fwflash/identify"
51 #define FWVERIFYPLUGINDIR "/usr/lib/fwflash/verify"
54 * we search for a variable (fwplugin_version, type uint32_t)
55 * which should equal FWPLUGIN_VERSION_1
58 #define FWPLUGIN_VERSION_1 1
59 #define FWPLUGIN_VERSION_2 2
61 struct devicelist;
63 struct fw_plugin {
65 * An opaque handle for dlopen()/dlclose() to use.
67 void *handle;
70 * fully-qualified filename in /usr/lib/fwflash/identify
71 * made up of [drivername].so
73 * eg /usr/lib/fwflash/identify/ses.so
74 * is the identification plugin for devices attached to
75 * the host using the ses(7D) driver.
77 char *filename;
80 * The driver name that this plugin will search for in
81 * the device tree snapshot using di_drv_first_node(3DEVINFO)
82 * and di_drv_next_node(3DEVINFO).
84 char *drvname; /* "ses" or "tavor" or .... */
87 * Function entry point to support the command-line "-r"
88 * option - read image from device to persistent storage.
90 * Not all plugins and devices will support this operation.
92 int (*fw_readfw)(struct devicelist *device, char *filename);
95 * Function entry point to support the command-line "-f"
96 * option - writes from persistent storage to device
98 * All identification plugins must support this operation.
100 int (*fw_writefw)(struct devicelist *device, char *filename);
103 * Function entry point used to build the list of valid, flashable
104 * devices attached to the system using the loadable module drvname.
105 * (Not all devices attached using drvname will be valid for this
106 * plugin to report.
108 * start allows us to display flashable devices attached with
109 * different drivers and provide the user with a visual clue
110 * that these devices are different to others that are detected.
112 * All identification plugins must support this operation.
114 int (*fw_identify)(int start);
117 * Function entry point to support the command-line "-l"
118 * option - list/report flashable devices attached to the system.
120 * All identification plugins must support this operation.
122 int (*fw_devinfo)(struct devicelist *thisdev);
125 * Function entry point to allow the plugin to clean up its
126 * data structure use IF plugin_version == FWPLUGIN_VERSION_2.
128 * If this function is not defined in the plugin, that is not
129 * an error condition unless the plugin_version variable is
130 * defined.
132 void (*fw_cleanup)(struct devicelist *thisdev);
136 struct pluginlist {
138 * fully qualified filename in /usr/lib/fwflash/identify
139 * made up of fwflash-[drivername].so
141 * eg /usr/lib/fwflash/identify/ses.so
142 * is the identification plugin for devices attached to
143 * the host using the ses(7D) driver.
145 char *filename;
148 * The driver name that this plugin will search for in
149 * the device tree snapshot using di_drv_first_node(3DEVINFO)
150 * and di_drv_next_node(3DEVINFO).
152 char *drvname;
155 * pointer to the actual plugin, so we can access its
156 * function entry points
158 struct fw_plugin *plugin;
160 /* pointer to the next element in the list */
161 TAILQ_ENTRY(pluginlist) nextplugin;
164 struct vpr {
165 /* vendor ID, eg "HITACHI " */
166 char *vid;
168 /* product ID, eg "DK32EJ36NSUN36G " */
169 char *pid;
171 /* revision, eg "PQ08" */
172 char *revid;
175 * Additional, encapsulated identifying information.
176 * This pointer allows us to add details such as the
177 * IB hba sector size, which command set should be
178 * used or a part number.
180 void *encap_ident;
183 struct fwfile {
185 * The fully qualified filename. No default location for
186 * the firmware image file is mandated.
188 char *filename;
190 /* Pointer to the identification plugin required */
191 struct fw_plugin *plugin;
193 /* pointer to the identification summary structure */
194 struct vpr *ident;
197 struct devicelist {
199 * fully qualified pathname, with /devices/.... prefix
201 char *access_devname;
204 * Which drivername did we find this device attached with
205 * in our device tree walk? Eg, ses or tavor or sgen...
207 char *drvname;
210 * What class of device is this? For tavor-attached devices,
211 * we set this to "IB". For other devices, unless there is
212 * a common name to use, just make this the same as the
213 * drvname field.
215 char *classname;
217 /* pointer to the VPR structure */
218 struct vpr *ident;
221 * In the original fwflash(1M), it was possible to select a
222 * device for flashing by using an index number called a
223 * dev_num. We retain that concept for pluggable fwflash, with
224 * the following change - whenever our identification plugin has
225 * finished and found at least one acceptable device, we bump the
226 * index number by 100. This provides the user with another key
227 * to distinguish the desired device from a potentially very large
228 * list of similar-looking devices.
230 unsigned int index;
233 * Contains SAS or FC Port-WWNs, or IB GUIDS. Both SAS and FC only
234 * need one entry in this array since they really only have one
235 * address which we should track. IB devices can have 4 GUIDs
236 * (System Image, Node Image, Port 1 and Port 2).
238 char *addresses[4];
241 * Pointer to the plugin needed to flash this device, and
242 * to use for printing appropriate device-specific information
243 * as required by the "-l" option to fwflash(1M).
245 struct fw_plugin *plugin;
247 /* Next entry in the list */
248 TAILQ_ENTRY(devicelist) nextdev;
253 * this type of plugin is for the firmware image vendor-specific
254 * verification functions, which we load from FWVERIFYPLUGINDIR
257 struct vrfyplugin {
259 * fully-qualified filename in /usr/lib/fwflash/verify,
260 * made up of [drivername]-[vendorname].so
262 * eg /usr/lib/fwflash/verify/ses-SUN.so
263 * is the verification plugin for ses-attached devices which
264 * have a vendorname of "SUN".
266 char *filename;
269 * The vendor name, such as "SUN" or "MELLANOX"
271 char *vendor;
274 * An opaque handle for dlopen()/dlclose() to use.
276 void *handle;
279 * Firmware image size in bytes, as reported by
280 * stat().
282 unsigned int imgsize;
285 * Flashable devices frequently have different buffers
286 * to use for different image types. We track the buffer
287 * required for this particular image with this variable.
289 * Once the verifier has figured out what sort of image
290 * it's been passed, it will know what value to use for
291 * this variable.
293 unsigned int flashbuf;
296 * Points to the entire firmware image in memory.
297 * We do this so we can avoid multiple open()/close()
298 * operations, and to make it easier for checksum
299 * calculations.
301 int *fwimage;
304 * We also store the name of the firmware file that
305 * we point to with *fwimage. This is needed in cases
306 * where we need to key off the name of the file to
307 * determine whether a different buffer in the target
308 * device should be targeted.
310 * For example, our "standard" firmware image (file.fw)
311 * might require use of buffer id 0, but a boot image
312 * (boot.fw) might require use of buffer id 17. In each
313 * case, it is the verifier plugin that determines the
314 * specific bufferid that is needed by that firmware image.
316 char *imgfile;
319 * The verification function entry point. The code
320 * in fwflash.c calls this function to verify that
321 * the nominated firmware image file is valid for
322 * the selected devicenode.
324 * Note that if the verification fails, the image
325 * does _not_ get force-flashed to the device.
327 int (*vendorvrfy)(struct devicelist *devicenode);
330 /* Flags for argument parsing */
331 #define FWFLASH_HELP_FLAG 0x01
332 #define FWFLASH_VER_FLAG 0x02
333 #define FWFLASH_YES_FLAG 0x04
334 #define FWFLASH_LIST_FLAG 0x08
335 #define FWFLASH_CLASS_FLAG 0x10
336 #define FWFLASH_DEVICE_FLAG 0x20
337 #define FWFLASH_FW_FLAG 0x40
338 #define FWFLASH_READ_FLAG 0x80
340 /* global variables for fwflash */
341 TAILQ_HEAD(PLUGINLIST, pluginlist);
342 TAILQ_HEAD(DEVICELIST, devicelist);
344 /* exposed global args */
345 extern di_node_t rootnode;
346 extern struct PLUGINLIST *fw_pluginlist;
347 extern struct DEVICELIST *fw_devices;
348 extern struct vrfyplugin *verifier;
349 extern struct fw_plugin *self;
350 extern int fwflash_debug;
353 * utility defines and macros, since the firmware image we get
354 * from LSI is ARM-format and that means byte- and short-swapping
355 * on sparc
358 #define HIGHBITS16 0xff00
359 #define HIGHBITS32 0xffff0000
360 #define HIGHBITS64 0xffffffff00000000ULL
361 #define LOWBITS16 0x00ff
362 #define LOWBITS32 0x0000ffff
363 #define LOWBITS64 0x00000000ffffffffULL
365 #if defined(_LITTLE_ENDIAN)
366 #define ARMSWAPBITS(bs) (bs)
367 #define MLXSWAPBITS16(bs) ntohs(bs)
368 #define MLXSWAPBITS32(bs) ntohl(bs)
369 #define MLXSWAPBITS64(bs) \
370 (BE_64(((bs) & LOWBITS64)) | BE_64(((bs) & HIGHBITS64)))
371 #else
372 #define ARMSWAPBITS(bs) (LE_32(((bs) & LOWBITS32)) | LE_32(((bs) & HIGHBITS32)))
373 #define MLXSWAPBITS16(bs) (bs)
374 #define MLXSWAPBITS32(bs) (bs)
375 #define MLXSWAPBITS64(bs) (bs)
376 #endif
378 /* common functions for fwflash */
379 void logmsg(int severity, const char *msg, ...);
381 #ifdef __cplusplus
383 #endif
385 #endif /* _FWFLASH_H */