fwflash.h revision d65b419ea7828ceaecc8f2ed7188237add6b14dc
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _FWFLASH_H
2N/A#define _FWFLASH_H
2N/A
2N/A/*
2N/A * fwflash.h
2N/A */
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#include <sys/queue.h>
2N/A#include <libdevinfo.h>
2N/A
2N/A
2N/A#define MSG_INFO 0
2N/A#define MSG_WARN 1
2N/A#define MSG_ERROR 2
2N/Aint fwflash_debug;
2N/A
2N/A#define FWFLASH_SUCCESS 0
2N/A#define FWFLASH_FAILURE 1
2N/A
2N/A#define FWFLASH_FLASH_IMAGES 2
2N/A
2N/A#define FWPLUGINDIR "/usr/lib/fwflash/identify"
2N/A#define FWVERIFYPLUGINDIR "/usr/lib/fwflash/verify"
2N/A
2N/A/*
2N/A * we search for a variable (fwplugin_version, type uint32_t)
2N/A * which should equal FWPLUGIN_VERSION_1
2N/A */
2N/A
2N/A#define FWPLUGIN_VERSION_1 1
2N/A#define FWPLUGIN_VERSION_2 2
2N/A
2N/Astruct devicelist;
2N/A
2N/Astruct fw_plugin {
2N/A /*
2N/A * An opaque handle for dlopen()/dlclose() to use.
2N/A */
2N/A void *handle;
2N/A
2N/A /*
2N/A * fully-qualified filename in /usr/lib/fwflash/identify
2N/A * made up of [drivername].so
2N/A *
2N/A * eg /usr/lib/fwflash/identify/ses.so
2N/A * is the identification plugin for devices attached to
2N/A * the host using the ses(7D) driver.
2N/A */
2N/A char *filename;
2N/A
2N/A /*
2N/A * The driver name that this plugin will search for in
2N/A * the device tree snapshot using di_drv_first_node(3DEVINFO)
2N/A * and di_drv_next_node(3DEVINFO).
2N/A */
2N/A char *drvname; /* "ses" or "tavor" or .... */
2N/A
2N/A /*
2N/A * Function entry point to support the command-line "-r"
2N/A * option - read image from device to persistent storage.
2N/A *
2N/A * Not all plugins and devices will support this operation.
2N/A */
2N/A int (*fw_readfw)(struct devicelist *device, char *filename);
2N/A
2N/A /*
2N/A * Function entry point to support the command-line "-f"
2N/A * option - writes from persistent storage to device
2N/A *
2N/A * All identification plugins must support this operation.
2N/A */
2N/A int (*fw_writefw)(struct devicelist *device, char *filename);
2N/A
2N/A /*
2N/A * Function entry point used to build the list of valid, flashable
2N/A * devices attached to the system using the loadable module drvname.
2N/A * (Not all devices attached using drvname will be valid for this
2N/A * plugin to report.
2N/A *
2N/A * start allows us to display flashable devices attached with
2N/A * different drivers and provide the user with a visual clue
2N/A * that these devices are different to others that are detected.
2N/A *
2N/A * All identification plugins must support this operation.
2N/A */
2N/A int (*fw_identify)(int start);
2N/A
2N/A /*
2N/A * Function entry point to support the command-line "-l"
2N/A * option - list/report flashable devices attached to the system.
2N/A *
2N/A * All identification plugins must support this operation.
2N/A */
2N/A int (*fw_devinfo)(struct devicelist *thisdev);
2N/A
2N/A /*
2N/A * Function entry point to allow the plugin to clean up its
2N/A * data structure use IF plugin_version == FWPLUGIN_VERSION_2.
2N/A *
2N/A * If this function is not defined in the plugin, that is not
2N/A * an error condition unless the plugin_version variable is
2N/A * defined.
2N/A */
2N/A void (*fw_cleanup)(struct devicelist *thisdev);
2N/A};
2N/A
2N/A
2N/Astruct pluginlist {
2N/A /*
2N/A * fully qualified filename in /usr/lib/fwflash/identify
2N/A * made up of fwflash-[drivername].so
2N/A *
2N/A * eg /usr/lib/fwflash/identify/ses.so
2N/A * is the identification plugin for devices attached to
2N/A * the host using the ses(7D) driver.
2N/A */
2N/A char *filename;
2N/A
2N/A /*
2N/A * The driver name that this plugin will search for in
2N/A * the device tree snapshot using di_drv_first_node(3DEVINFO)
2N/A * and di_drv_next_node(3DEVINFO).
2N/A */
2N/A char *drvname;
2N/A
2N/A /*
2N/A * pointer to the actual plugin, so we can access its
2N/A * function entry points
2N/A */
2N/A struct fw_plugin *plugin;
2N/A
2N/A /* pointer to the next element in the list */
2N/A TAILQ_ENTRY(pluginlist) nextplugin;
2N/A};
2N/A
2N/Astruct vpr {
2N/A /* vendor ID, eg "HITACHI " */
2N/A char *vid;
2N/A
2N/A /* product ID, eg "DK32EJ36NSUN36G " */
2N/A char *pid;
2N/A
2N/A /* revision, eg "PQ08" */
2N/A char *revid;
2N/A
2N/A /*
2N/A * Additional, encapsulated identifying information.
2N/A * This pointer allows us to add details such as the
2N/A * IB hba sector size, which command set should be
2N/A * used or a part number.
2N/A */
2N/A void *encap_ident;
2N/A};
2N/A
2N/Astruct fwfile {
2N/A /*
2N/A * The fully qualified filename. No default location for
2N/A * the firmware image file is mandated.
2N/A */
2N/A char *filename;
2N/A
2N/A /* Pointer to the identification plugin required */
2N/A struct fw_plugin *plugin;
2N/A
2N/A /* pointer to the identification summary structure */
2N/A struct vpr *ident;
2N/A};
2N/A
2N/Astruct devicelist {
2N/A /*
2N/A * fully qualified pathname, with /devices/.... prefix
2N/A */
2N/A char *access_devname;
2N/A
2N/A /*
2N/A * Which drivername did we find this device attached with
2N/A * in our device tree walk? Eg, ses or tavor or sgen...
2N/A */
2N/A char *drvname;
2N/A
2N/A /*
2N/A * What class of device is this? For tavor-attached devices,
2N/A * we set this to "IB". For other devices, unless there is
2N/A * a common name to use, just make this the same as the
2N/A * drvname field.
2N/A */
2N/A char *classname;
2N/A
2N/A /* pointer to the VPR structure */
2N/A struct vpr *ident;
2N/A
2N/A /*
2N/A * In the original fwflash(1M), it was possible to select a
2N/A * device for flashing by using an index number called a
2N/A * dev_num. We retain that concept for pluggable fwflash, with
2N/A * the following change - whenever our identification plugin has
2N/A * finished and found at least one acceptable device, we bump the
2N/A * index number by 100. This provides the user with another key
2N/A * to distinguish the desired device from a potentially very large
2N/A * list of similar-looking devices.
2N/A */
2N/A unsigned int index;
2N/A
2N/A /*
2N/A * Contains SAS or FC Port-WWNs, or IB GUIDS. Both SAS and FC only
2N/A * need one entry in this array since they really only have one
2N/A * address which we should track. IB devices can have 4 GUIDs
2N/A * (System Image, Node Image, Port 1 and Port 2).
2N/A */
2N/A char *addresses[4];
2N/A
2N/A /*
2N/A * Pointer to the plugin needed to flash this device, and
2N/A * to use for printing appropriate device-specific information
2N/A * as required by the "-l" option to fwflash(1M).
2N/A */
2N/A struct fw_plugin *plugin;
2N/A
2N/A /* Next entry in the list */
2N/A TAILQ_ENTRY(devicelist) nextdev;
2N/A};
2N/A
2N/A
2N/A/*
2N/A * this type of plugin is for the firmware image vendor-specific
2N/A * verification functions, which we load from FWVERIFYPLUGINDIR
2N/A */
2N/A
2N/Astruct vrfyplugin {
2N/A /*
2N/A * fully-qualified filename in /usr/lib/fwflash/verify,
2N/A * made up of [drivername]-[vendorname].so
2N/A *
2N/A * eg /usr/lib/fwflash/verify/ses-SUN.so
2N/A * is the verification plugin for ses-attached devices which
2N/A * have a vendorname of "SUN".
2N/A */
2N/A char *filename;
2N/A
2N/A /*
2N/A * The vendor name, such as "SUN" or "MELLANOX"
2N/A */
2N/A char *vendor;
2N/A
2N/A /*
2N/A * An opaque handle for dlopen()/dlclose() to use.
2N/A */
2N/A void *handle;
2N/A
2N/A /*
2N/A * Firmware image size in bytes, as reported by
2N/A * stat().
2N/A */
2N/A unsigned int imgsize;
2N/A
2N/A /*
2N/A * Flashable devices frequently have different buffers
2N/A * to use for different image types. We track the buffer
2N/A * required for this particular image with this variable.
2N/A *
2N/A * Once the verifier has figured out what sort of image
2N/A * it's been passed, it will know what value to use for
2N/A * this variable.
2N/A */
2N/A unsigned int flashbuf;
2N/A
2N/A /*
2N/A * Points to the entire firmware image in memory.
2N/A * We do this so we can avoid multiple open()/close()
2N/A * operations, and to make it easier for checksum
2N/A * calculations.
2N/A */
2N/A int *fwimage;
2N/A
2N/A /*
2N/A * We also store the name of the firmware file that
2N/A * we point to with *fwimage. This is needed in cases
2N/A * where we need to key off the name of the file to
2N/A * determine whether a different buffer in the target
2N/A * device should be targeted.
2N/A *
2N/A * For example, our "standard" firmware image (file.fw)
2N/A * might require use of buffer id 0, but a boot image
2N/A * (boot.fw) might require use of buffer id 17. In each
2N/A * case, it is the verifier plugin that determines the
2N/A * specific bufferid that is needed by that firmware image.
2N/A */
2N/A char *imgfile;
2N/A
2N/A /*
2N/A * The verification function entry point. The code
2N/A * in fwflash.c calls this function to verify that
2N/A * the nominated firmware image file is valid for
2N/A * the selected devicenode.
2N/A *
2N/A * Note that if the verification fails, the image
2N/A * does _not_ get force-flashed to the device.
2N/A */
2N/A int (*vendorvrfy)(struct devicelist *devicenode);
2N/A};
2N/A
2N/A/* Flags for argument parsing */
2N/A#define FWFLASH_HELP_FLAG 0x01
2N/A#define FWFLASH_VER_FLAG 0x02
2N/A#define FWFLASH_YES_FLAG 0x04
2N/A#define FWFLASH_LIST_FLAG 0x08
2N/A#define FWFLASH_CLASS_FLAG 0x10
2N/A#define FWFLASH_DEVICE_FLAG 0x20
2N/A#define FWFLASH_FW_FLAG 0x40
2N/A#define FWFLASH_READ_FLAG 0x80
2N/A
/* global variables for fwflash */
TAILQ_HEAD(PLUGINLIST, pluginlist);
TAILQ_HEAD(DEVICELIST, devicelist);
struct PLUGINLIST *fw_pluginlist;
struct DEVICELIST *fw_devices;
struct vrfyplugin *verifier;
di_node_t rootnode;
struct fw_plugin *self;
/*
* 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 */