summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/Makefile.lint2
-rw-r--r--usr/src/cmd/Makefile4
-rw-r--r--usr/src/cmd/fwflash/Makefile66
-rw-r--r--usr/src/cmd/fwflash/fwflash.c878
-rw-r--r--usr/src/cmd/fwflash/fwflash.h102
-rw-r--r--usr/src/cmd/fwflash/fwflash_ib.c2352
-rw-r--r--usr/src/cmd/fwflash/fwflash_ib.h120
-rw-r--r--usr/src/cmd/fwflash/fwflash_ib_impl.h110
-rw-r--r--usr/src/cmd/fwflash/fwflash_mlx.h130
9 files changed, 3 insertions, 3761 deletions
diff --git a/usr/src/Makefile.lint b/usr/src/Makefile.lint
index 32a1ec95af..c10810fc9e 100644
--- a/usr/src/Makefile.lint
+++ b/usr/src/Makefile.lint
@@ -139,7 +139,6 @@ COMMON_SUBDIRS = \
cmd/fs.d/ufs/fsirand\
cmd/fs.d/zfs/fstyp \
cmd/fuser \
- cmd/fwflash \
cmd/gcore \
cmd/getconf \
cmd/getdevpolicy \
@@ -414,6 +413,7 @@ COMMON_SUBDIRS = \
$(CLOSED_BUILD)COMMON_SUBDIRS += \
$(CLOSED)/cmd/cmd-inet/usr.lib/in.iked \
+ $(CLOSED)/cmd/fwflash \
$(CLOSED)/cmd/pax \
$(CLOSED)/cmd/pcitool \
$(CLOSED)/cmd/sed_xpg4 \
diff --git a/usr/src/cmd/Makefile b/usr/src/cmd/Makefile
index 35717d17f8..420cb93003 100644
--- a/usr/src/cmd/Makefile
+++ b/usr/src/cmd/Makefile
@@ -166,7 +166,6 @@ COMMON_SUBDIRS= \
fs.d \
fstyp \
fuser \
- fwflash \
gcore \
gencat \
geniconvtbl \
@@ -434,6 +433,7 @@ COMMON_SUBDIRS= \
$(CLOSED_BUILD)COMMON_SUBDIRS += \
$(CLOSED)/cmd/dodatadm \
+ $(CLOSED)/cmd/fwflash \
$(CLOSED)/cmd/iconv \
$(CLOSED)/cmd/ksh \
$(CLOSED)/cmd/llc2 \
@@ -555,7 +555,6 @@ MSGSUBDIRS= \
fm \
fold \
fs.d \
- fwflash \
geniconvtbl \
genmsg \
getconf \
@@ -701,6 +700,7 @@ MSGSUBDIRS= \
zpool
$(CLOSED_BUILD)MSGSUBDIRS += \
+ $(CLOSED)/cmd/fwflash \
$(CLOSED)/cmd/iconv \
$(CLOSED)/cmd/ksh \
$(CLOSED)/cmd/llc2 \
diff --git a/usr/src/cmd/fwflash/Makefile b/usr/src/cmd/fwflash/Makefile
deleted file mode 100644
index 4e7640cdfa..0000000000
--- a/usr/src/cmd/fwflash/Makefile
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# 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 2007 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
-#
-#ident "%Z%%M% %I% %E% SMI"
-#
-# cmd/fwflash/Makefile
-#
-#
-PROG= fwflash
-OBJS= fwflash.o fwflash_ib.o
-SRCS= $(OBJS:%.o=%.c)
-
-include ../Makefile.cmd
-
-#
-# Message catalog
-#
-POFILES= $(OBJS:%.o=%.po)
-POFILE= fwflash_msg.po
-
-CFLAGS += $(CCVERBOSE)
-LDLIBS += -ldevinfo
-
-.KEEP_STATE:
-
-all: $(PROG)
-
-$(PROG): $(OBJS)
- $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
- $(POST_PROCESS)
-
-#
-# Message catalog
-#
-$(POFILE): $(POFILES)
- $(RM) $@
- cat $(POFILES) > $@
-
-install: all $(ROOTUSRSBINPROG)
-
-clean:
- $(RM) $(PROG)
-
-lint: lint_SRCS
-
-include ../Makefile.targ
diff --git a/usr/src/cmd/fwflash/fwflash.c b/usr/src/cmd/fwflash/fwflash.c
deleted file mode 100644
index 2d95d78da0..0000000000
--- a/usr/src/cmd/fwflash/fwflash.c
+++ /dev/null
@@ -1,878 +0,0 @@
-/*
- * 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 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * fwflash.c
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <locale.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include "fwflash.h"
-#include "fwflash_ib.h"
-
-/* FWflash functions */
-static fwflash_device_info_t *fwflash_device_list(int *count);
-static char *fwflash_name_from_class(int class);
-static int fwflash_class_from_name(char *class_name);
-static int fwflash_device_class_from_path(char *dev_name);
-static int fwflash_update(char *device, char *filename);
-static int fwflash_read_file(char *device, char *filename);
-static int fwflash_list_fw(int dev_class);
-static void fwflash_intr(int sig);
-static void fwflash_handle_signals(void);
-static void fwflash_usage();
-static void fwflash_help(void);
-static void fwflash_version(void);
-
-/* IB Specific functions */
-static int fwflash_list_fw_ib(int device);
-static void fwflash_ib_print_guids(uint64_t *guids);
-static int fwflash_update_ib(char *device);
-static int fwflash_read_file_ib(char *device);
-
-#if !defined(lint)
-/* embedded software license agreement */
-static char *sla [] = { "Copyright 2007 Sun Microsystems, Inc., 4150 Network "
-"Circle, Santa Clara, California 95054, U.S.A. All rights reserved. U.S. "
-"Government Rights - Commercial software. Government users are subject to the "
-"Sun Microsystems, Inc. standard license agreement and applicable provisions "
-"of the FAR and its supplements. Use is subject to license terms. Parts of "
-"the product may be derived from Berkeley BSD systems, licensed from the "
-"University of California. UNIX is a registered trademark in the U.S. and in "
-"other countries, exclusively licensed through X/Open Company, Ltd.Sun, Sun "
-"Microsystems, the Sun logo and Solaris are trademarks or registered "
-"trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This "
-"product is covered and controlled by U.S. Export Control laws and may be "
-"subject to the export or import laws in other countries. Nuclear, missile, "
-"chemical biological weapons or nuclear maritime end uses or end users, "
-"whether direct or indirect, are strictly prohibited. Export or reexport "
-"to countries subject to U.S. embargo or to entities identified on U.S. export "
-"exclusion lists, including, but not limited to, the denied persons and "
-"specially designated nationals lists is strictly prohibited." };
-#endif /* lint */
-
-/* global arg list */
-int fwflash_arg_list = 0;
-
-/* global state */
-fwflash_state_t state;
-
-/* are we writing to flash? */
-static int fwflash_in_write = 0;
-
-/*
- * Define the types of devices we support. The order matters, add appropriate
- * values to the below #defines as well when updating this information.
- */
-char *fwflash_classes [] =
-{
- "ALL",
- "IB",
- ""
-};
-#define FWFLASH_DEVCLASS_ALL 0
-#define FWFLASH_DEVCLASS_IB 1
-
-/*
- * FWFlash main code
- */
-int
-main(int argc, char *argv[])
-{
- int rv;
- char ch;
- char *fw_file;
- char *read_file;
- int dev_class = FWFLASH_DEVCLASS_ALL;
- extern char *optarg;
-
- fw_file = NULL;
- read_file = NULL;
-
- bzero(&state, sizeof (fwflash_state_t));
-
- /* gather list of available devices to flash */
- state.devices = fwflash_device_list(&state.count);
- if (state.devices == NULL) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("No flash devices found"));
- (void) fprintf(stderr, "\n");
- fwflash_usage();
- return (FWFLASH_FAILURE);
- }
-
- while ((ch = getopt(argc, argv, "hvylc:f:r:d:-:")) != -1) {
- switch (ch) {
- case 'h':
- fwflash_arg_list |= FWFLASH_HELP_FLAG;
- break;
-
- case 'v':
- fwflash_arg_list |= FWFLASH_VER_FLAG;
- break;
-
- case 'y':
- fwflash_arg_list |= FWFLASH_YES_FLAG;
- break;
-
- case 'l':
- fwflash_arg_list |= FWFLASH_LIST_FLAG;
- break;
-
- case 'c':
- fwflash_arg_list |= FWFLASH_CLASS_FLAG;
-
- while (*optarg == ' ') {
- optarg++;
- }
- dev_class = fwflash_class_from_name(optarg);
- if (dev_class == -1) {
- (void) fprintf(stderr, "%s: ",
- FWFLASH_PGM_NAME);
- (void) fprintf(stderr,
- gettext("Invalid device class"));
- (void) fprintf(stderr, ": %s", optarg);
- (void) fprintf(stderr, "\n");
- return (FWFLASH_FAILURE);
- }
- break;
-
- case 'd':
- fwflash_arg_list |= FWFLASH_DEVICE_FLAG;
-
- while (*optarg == ' ') {
- optarg++;
- }
-
- if (isdigit(*optarg)) {
- if (atoi(optarg) >= state.count) {
- (void) fprintf(stderr,
- gettext(
- "Unknown device specification"));
- (void) fprintf(stderr,
- ": %s\n", optarg);
- fwflash_usage();
- return (FWFLASH_FAILURE);
- }
- state.device_name =
- state.devices->device_list[atoi(optarg)];
- } else {
- state.device_name = optarg;
- }
- break;
-
- case 'f':
- fwflash_arg_list |= FWFLASH_FW_FLAG;
- while (*optarg == ' ') {
- optarg++;
- }
- fw_file = optarg;
- break;
-
- case 'r':
- fwflash_arg_list |= FWFLASH_READ_FLAG;
- while (*optarg == ' ') {
- optarg++;
- }
- read_file = optarg;
- break;
-
- /* illegal options */
- default:
- fwflash_usage();
- return (FWFLASH_FAILURE);
- }
- }
-
- /* Do Help */
- if (fwflash_arg_list & FWFLASH_HELP_FLAG) {
- fwflash_help();
- return (FWFLASH_SUCCESS);
- }
-
- /* Do Version */
- if (fwflash_arg_list == FWFLASH_VER_FLAG) {
- fwflash_version();
- return (FWFLASH_SUCCESS);
- }
-
- /* Do list */
- if (fwflash_arg_list == (FWFLASH_LIST_FLAG) ||
- fwflash_arg_list == (FWFLASH_LIST_FLAG | FWFLASH_CLASS_FLAG)) {
- rv = fwflash_list_fw(dev_class);
- if (rv != FWFLASH_SUCCESS) {
- (void) fprintf(stderr,
- gettext(
- "Unable to generate list of available devices"));
- (void) fprintf(stderr, "\n");
- }
- return (FWFLASH_SUCCESS);
- }
-
- fwflash_handle_signals();
-
- /* Do flash update */
- if (fwflash_arg_list == (FWFLASH_FW_FLAG | FWFLASH_DEVICE_FLAG) ||
- fwflash_arg_list == (FWFLASH_FW_FLAG | FWFLASH_DEVICE_FLAG |
- FWFLASH_YES_FLAG)) {
-
- if (fw_file != NULL) {
- rv = fwflash_update(state.device_name, fw_file);
- if (rv != FWFLASH_SUCCESS) {
- (void) fprintf(stderr,
- gettext("Failed to (re)write firmware"));
- (void) fprintf(stderr, "\n");
- return (FWFLASH_FAILURE);
- }
- return (FWFLASH_SUCCESS);
- } else {
- (void) fprintf(stderr,
- gettext("Write filename invalid"));
- (void) fprintf(stderr, "\n");
- return (FWFLASH_FAILURE);
- }
- }
-
- /* Do flash read */
- if (fwflash_arg_list == (FWFLASH_READ_FLAG | FWFLASH_DEVICE_FLAG) ||
- fwflash_arg_list == (FWFLASH_READ_FLAG | FWFLASH_DEVICE_FLAG |
- FWFLASH_YES_FLAG)) {
-
- if (read_file != NULL) {
- rv = fwflash_read_file(state.device_name, read_file);
- if (rv == 0) {
- (void) fprintf(stderr,
- gettext("Failed to read out firmware"));
- (void) fprintf(stderr, "\n");
- return (FWFLASH_FAILURE);
- }
- return (FWFLASH_SUCCESS);
- } else {
- (void) fprintf(stderr,
- gettext("Read filename invalid"));
- (void) fprintf(stderr, "\n");
- return (FWFLASH_FAILURE);
- }
- }
-
- if (fwflash_arg_list == 0) {
- (void) fprintf(stdout, "%s: ", FWFLASH_PGM_NAME);
- (void) fprintf(stdout, gettext("please choose an option"));
- (void) fprintf(stdout, "\n");
- } else {
- (void) fprintf(stdout, "%s: ", FWFLASH_PGM_NAME);
- (void) fprintf(stdout, gettext("illegal options"));
- (void) fprintf(stdout, "\n");
- }
- fwflash_usage();
-
- return (FWFLASH_FAILURE);
-}
-
-static fwflash_device_info_t *
-fwflash_device_list(int *count)
-{
- fwflash_device_info_t *devices;
- int i;
-
- devices = (fwflash_device_info_t *)malloc(
- sizeof (fwflash_device_info_t));
-
- /* Probe out all the supported devices */
-
- /*
- * First find all IB devices
- */
- devices->device_list = fwflash_ib_device_list(count);
- if (count == 0) {
- free(devices);
- devices = NULL;
- } else {
- devices->device_class = (int *)malloc(sizeof (int) * (*count));
- for (i = 0; i < *count; i++) {
- devices->device_class[i] = FWFLASH_DEVCLASS_IB;
- }
- }
-
- return (devices);
-}
-
-static char *
-fwflash_name_from_class(int dev_class)
-{
- return (fwflash_classes[dev_class]);
-}
-
-static int
-fwflash_class_from_name(char *class_name)
-{
- int class;
-
- while (*class_name == ' ') {
- class_name++;
- }
-
- for (class = 0; fwflash_classes[class][0] != '\0'; class++) {
- if (!strcasecmp(fwflash_classes[class], class_name))
- break;
- }
-
- if (fwflash_classes[class][0] == '\0') {
- return (-1);
- } else {
- return (class);
- }
-}
-
-static int
-fwflash_device_class_from_path(char *dev_name)
-{
- int entry;
-
- for (entry = 0; entry < state.count; entry++) {
- if (!strcasecmp(state.devices->device_list[entry], dev_name))
- break;
- }
-
- if (entry == state.count) {
- return (-1);
- } else {
- return (state.devices->device_class[entry]);
- }
-}
-
-static int
-fwflash_list_fw(int dev_class)
-{
- int rv = FWFLASH_FAILURE;
- int i;
-
- (void) fprintf(stdout, gettext("List of available devices"));
- (void) fprintf(stdout, ":\n");
- for (i = 0; i < state.count; i++) {
- (void) fprintf(stdout, gettext("Device"));
- (void) fprintf(stdout, "[%d], %s\n", i,
- state.devices->device_list[i]);
-
- if (dev_class == FWFLASH_DEVCLASS_ALL ||
- dev_class == state.devices->device_class[i]) {
- switch (state.devices->device_class[i]) {
- case FWFLASH_DEVCLASS_IB:
- state.device_class = FWFLASH_DEVCLASS_IB;
- rv = fwflash_list_fw_ib(i);
- if (rv != 0) {
- /*
- * flash type not yet supported
- * move on to the next device
- */
- rv = 0;
- }
- break;
- default:
- (void) fprintf(stderr,
- gettext("Unknown class for device"));
- (void) fprintf(stderr, " %d.\n", i);
- break;
- }
- }
- }
-out:
- return (rv);
-}
-
-static int
-fwflash_update(char *device, char *filename)
-{
- int class;
- int rv = 0;
-
- /* new firmware filename and device desc */
- DPRINTF(DBG_INFO, ("fwflash_update: fw_filename (%s) device (%s)\n",
- filename, device));
- state.filename = filename;
-
- class = fwflash_device_class_from_path(device);
- if (class == -1) {
- (void) fprintf(stderr, gettext("Invalid class type for"));
- (void) fprintf(stderr, ": %s\n", device);
- return (FWFLASH_FAILURE);
- }
-
- switch (class) {
- case FWFLASH_DEVCLASS_IB:
- state.device_class = FWFLASH_DEVCLASS_IB;
- rv = fwflash_update_ib(device);
- if (rv != 0) {
- (void) fprintf(stderr,
- gettext("Flash update IB failed."));
- (void) fprintf(stderr, "\n");
- return (rv);
- }
- break;
- default:
- break;
- }
- return (rv);
-}
-
-static int
-fwflash_read_file(char *device, char *filename)
-{
- int class;
- int rv;
-
- /* new firmware filename and device desc */
- DPRINTF(DBG_INFO, ("fwflash_read_file: fw_filename (%s) device (%s)\n",
- filename, device));
- state.filename = filename;
-
- class = fwflash_device_class_from_path(device);
- if (class == -1) {
- (void) fprintf(stderr, gettext("Unknown device path"));
- (void) fprintf(stderr, ": %s\n", device);
- return (FWFLASH_FAILURE);
- }
-
- switch (class) {
- case FWFLASH_DEVCLASS_IB:
- state.device_class = FWFLASH_DEVCLASS_IB;
- rv = fwflash_read_file_ib(device);
- if (rv == 0) {
- (void) fprintf(stderr,
- gettext("Flash read file failed."));
- (void) fprintf(stderr, "\n");
- return (rv);
- }
- break;
- default:
- break;
- }
- return (rv);
-}
-
-static void
-fwflash_usage()
-{
- (void) fprintf(stderr, gettext("Usage"));
- (void) fprintf(stderr, ": \n\t");
- (void) fprintf(stderr, gettext(
- "fwflash [-l [-c <device_class> | ALL]] | [-v] | [-h]"));
- (void) fprintf(stderr, "\n\t");
- (void) fprintf(stderr, gettext(
- "fwflash [-f <file>] | -r <file>] [-y] -d <dev_spec]"));
- (void) fprintf(stderr, "\n");
-}
-
-static void
-fwflash_version(void)
-{
- (void) fprintf(stderr, "%s: ", FWFLASH_PGM_NAME);
- (void) fprintf(stderr, gettext("version"));
- (void) fprintf(stderr, " %s\n", FWFLASH_VERSION);
-}
-
-static void
-fwflash_help(void)
-{
- fwflash_usage();
-}
-
-/* ARGSUSED */
-static void
-fwflash_intr(int sig)
-{
- (void) signal(SIGINT, SIG_IGN);
- (void) signal(SIGTERM, SIG_IGN);
- if (fwflash_in_write) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr,
- gettext("WARNING: firmware image may be corrupted"));
- (void) fprintf(stderr, "\n\t");
- (void) fprintf(stderr,
- gettext("Reflash firmware before rebooting!"));
- (void) fprintf(stderr, "\n");
- }
-
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("fwflash exiting due to signal"));
- (void) fprintf(stderr, "\n");
-
- switch (state.device_class) {
- case FWFLASH_DEVCLASS_IB:
- fwflash_ib_close(state.ibhdl);
- break;
- default:
- break;
- }
- exit(FWFLASH_FAILURE);
-}
-
-static void
-fwflash_handle_signals(void)
-{
- if (signal(SIGINT, fwflash_intr) == SIG_ERR) {
- perror("signal");
- exit(FWFLASH_FAILURE);
- }
-
- if (signal(SIGTERM, fwflash_intr) == SIG_ERR) {
- perror("signal");
- exit(FWFLASH_FAILURE);
- }
-}
-
-/*
- * IB (InfiniBand) specific functions. Add additional functions following
- * these for otherclass types.
- */
-static int
-fwflash_list_fw_ib(int device)
-{
- uint64_t guids[4];
- int rv;
- char *dev_name;
-
- DPRINTF(DBG_INFO, ("fwflash_list_fw_ib\n"));
- /* open device and read some stuff */
- dev_name = state.devices->device_list[device];
- state.ibhdl = fwflash_ib_open(dev_name);
- if (state.ibhdl == NULL) {
- (void) fprintf(stderr, gettext("Failed to open device"));
- (void) fprintf(stderr, " (%s)\n", dev_name);
- return (FWFLASH_FAILURE);
- }
-
- /*
- * Flash read GUIDs
- * - First try the primary image GUIDs. If this exists, then
- * we have booted the primary image.
- *
- * - If primary doesn't work, fallback to the secondary GUIDs,
- * assuming we have booted from the secondary firmware image.
- *
- * - If both fail, something is wrong here, and we must print
- * out an error.
- */
- rv = fwflash_ib_flash_read_guids(state.ibhdl, &guids[0],
- FWFLASH_IB_PRIMARY_IMAGE);
- if (rv != 0) {
- DPRINTF(DBG_ERR, ("Failed to read primary guids. "
- "Trying secondary..\n"));
- rv = fwflash_ib_flash_read_guids(state.ibhdl, &guids[0],
- FWFLASH_IB_SECONDARY_IMAGE);
- if (rv != 0) {
- fwflash_ib_close(state.ibhdl);
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr,
- gettext("WARNING: HCA FIRMWARE MAY BE CORRUPT"));
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr,
- gettext("Unable to read GUID values"));
- (void) fprintf(stderr, "\n");
- fwflash_ib_close(state.ibhdl);
- return (FWFLASH_FAILURE);
- }
- }
-
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout, gettext("Class"));
- (void) fprintf(stdout, " [%s]\n",
- fwflash_name_from_class(state.devices->device_class[device]));
-
- /* print the guids */
- fwflash_ib_print_guids(guids);
-
- /* print firmware revision */
- if (state.ibhdl->fw_rev.major != 0x0) {
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout, gettext("Firmware revision"));
- (void) fprintf(stdout, " : ");
- (void) fprintf(stdout, "%d.%d.%04d\n",
- state.ibhdl->fw_rev.major,
- state.ibhdl->fw_rev.minor,
- state.ibhdl->fw_rev.subminor);
- } else {
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout,
- gettext("WARNING: HCA FIRMWARE MAY BE CORRUPT"));
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout,
- gettext("Unable to read firmware version"));
- (void) fprintf(stdout, "\n");
- fwflash_ib_close(state.ibhdl);
- return (FWFLASH_FAILURE);
- }
-
- /* print the HW product name, PSID, and part number */
- if (state.ibhdl->pn_len != 0) {
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout, gettext("Product"));
- (void) fprintf(stdout, " : ");
- (void) fprintf(stdout, "%s ", state.ibhdl->info.mlx_pn);
- (void) fprintf(stdout, "(%s)\n", state.ibhdl->info.mlx_id);
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout, gettext("PSID"));
- (void) fprintf(stdout, " : ");
- (void) fprintf(stdout, "%s\n", state.ibhdl->info.mlx_psid);
- } else {
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout, gettext("No HW information available"));
- (void) fprintf(stdout, "\n\n");
- }
-
- /* close the device */
- fwflash_ib_close(state.ibhdl);
-
- return (FWFLASH_SUCCESS);
-}
-
-static void
-fwflash_ib_print_guids(uint64_t *guids)
-{
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout, gettext("GUID"));
- (void) fprintf(stdout, ":\t");
- (void) fprintf(stdout, gettext("System Image"));
- (void) fprintf(stdout, " - %016llx\n", guids[3]);
- (void) fprintf(stdout, " \t");
- (void) fprintf(stdout, gettext("Node Image"));
- (void) fprintf(stdout, " - %016llx\n", guids[0]);
- (void) fprintf(stdout, " \t");
- (void) fprintf(stdout, gettext("Port 1"));
- (void) fprintf(stdout, " - %016llx\n", guids[1]);
- (void) fprintf(stdout, " \t");
- (void) fprintf(stdout, gettext("Port 2"));
- (void) fprintf(stdout, " - %016llx\n", guids[2]);
-}
-
-static int
-fwflash_update_ib(char *device)
-{
- uint64_t guids[4];
- char ans;
- int rv;
- int i;
-
- DPRINTF(DBG_INFO, ("fwflash_update_ib\n"));
- /* flash devices we're working on */
- state.ibhdl = fwflash_ib_open(device);
- if (state.ibhdl == NULL) {
- (void) fprintf(stderr, gettext("Failed to open device"));
- (void) fprintf(stderr, " (%s)\n", device);
- return (FWFLASH_FAILURE);
- }
-
- /* read in and verify the new firmware */
- DPRINTF(DBG_INFO, ("Verify new FW image\n"));
- rv = fwflash_ib_read_file(state.ibhdl, state.filename);
- if (rv != 0) {
- fwflash_usage();
- goto out;
- }
-
- /*
- * Ask the user if he would like to continue.
- */
- (void) fprintf(stdout, gettext("About to update firmware on"));
- (void) fprintf(stdout, ":\n\t%s\n", device);
-
- if (!(fwflash_arg_list & FWFLASH_YES_FLAG)) {
- (void) fprintf(stdout, gettext("Continue"));
- (void) fprintf(stdout, " (Y/N): ");
- ans = getchar();
- if (ans != 'Y' && ans != 'y') {
- DPRINTF(DBG_INFO, ("ans (%c)\n", ans));
- rv = FWFLASH_FAILURE;
- goto out;
- }
- }
-
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout, gettext("Updating"));
- (void) fprintf(stdout, " ");
- /* write both the primary and secondary images */
- fwflash_in_write = 1;
-
- /*
- * Try to read existing GUIDs from the device. We will use these, if
- * we are able to read them, when updating each image. We try the
- * primary first, and then the secondary. To the end user, there
- * should be no distinction between primary and secondary images, so
- * the GUID values are expected to be the same between both sets of
- * images.
- */
- DPRINTF(DBG_INFO, ("Using Existing GUIDs.\n"));
- rv = fwflash_ib_flash_read_guids(state.ibhdl, &guids[0], 1);
- if (rv != 0) {
- DPRINTF(DBG_ERR, ("Failed to read Primary GUIDs. Trying "
- "from secondary image.\n"));
- rv = fwflash_ib_flash_read_guids(state.ibhdl, &guids[0], 2);
- if (rv != 0) {
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout,
- gettext("Failed to read any valid GUIDs."));
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout,
- gettext("Using default GUIDs from file."));
- (void) fprintf(stdout, "\n");
- }
- }
-
- /*
- * If we were able to read some valid GUIDs from either primary or
- * secondary images, then we set them here to our local image. This
- * allows us to use the existing GUIDs in the firmware. However, if
- * both attempts to read GUIDs failed, then we do not set any of the
- * GUIDs in our local image, and will use the values that are in the
- * firmware file itself instead.
- */
- if (rv == 0) {
- state.ibhdl->state |=
- FWFLASH_IB_STATE_GUIDN |
- FWFLASH_IB_STATE_GUID1 |
- FWFLASH_IB_STATE_GUID2 |
- FWFLASH_IB_STATE_GUIDS;
- rv = fwflash_ib_set_guids(state.ibhdl, guids, 1);
- if (rv != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set GUIDs\n"));
- }
- rv = fwflash_ib_set_guids(state.ibhdl, guids, 2);
- if (rv != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set GUIDs\n"));
- }
- }
-
- /*
- * Update both Primary and Secondary images
- */
- for (i = FWFLASH_FLASH_IMAGES; i > 0; i--) {
- char *type = i == 1 ? "Primary" : "Secondary";
-
- DPRINTF(DBG_INFO, ("UPDATING %s IMAGE\n", type));
- rv = fwflash_ib_write_image(state.ibhdl, i);
- if (rv != 0) {
- (void) fprintf(stderr, gettext("Failed to update"));
- (void) fprintf(stderr, " %s ", type);
- (void) fprintf(stderr, gettext("image on device"));
- (void) fprintf(stderr, " %s\n", device);
- goto out;
- }
-
- DPRINTF(DBG_INFO, ("Verify %s image..\n", type));
- rv = fwflash_ib_verify_image(state.ibhdl, i);
- if (rv != 0) {
- (void) fprintf(stderr, gettext("Failed to verify"));
- (void) fprintf(stderr, " %s ", type);
- (void) fprintf(stderr, gettext("image for device"));
- (void) fprintf(stderr, " %s\n", state.device_name);
- goto out;
- }
- }
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout, gettext("Done."));
- (void) fprintf(stdout, " ");
- (void) fprintf(stdout,
- gettext("New image will be active after the system is rebooted."));
- (void) fprintf(stdout, "\n");
-out:
- fwflash_ib_close(state.ibhdl);
- fwflash_in_write = 0;
- return (rv);
-}
-
-static int
-fwflash_read_file_ib(char *device)
-{
- char ans;
- int rv;
- int i;
-
- DPRINTF(DBG_INFO, ("fwflash_read_file_ib\n"));
- /* flash devices we're working on */
- state.ibhdl = fwflash_ib_open(device);
- if (state.ibhdl == NULL) {
- (void) fprintf(stderr, gettext("Failed to open device"));
- (void) fprintf(stderr, " (%s)\n", device);
- return (FWFLASH_FAILURE);
- }
-
- /*
- * Ask the user if he would like to continue.
- */
- (void) fprintf(stdout, gettext("About to read firmware on"));
- (void) fprintf(stdout, ":\n\t%s\n", device);
- (void) fprintf(stdout, gettext("to filename"));
- (void) fprintf(stdout, ": %s\n", state.filename);
-
- if (!(fwflash_arg_list & FWFLASH_YES_FLAG)) {
- (void) fprintf(stdout, gettext("Continue"));
- (void) fprintf(stdout, " (Y/N): ");
- ans = getchar();
- if (ans != 'Y' && ans != 'y') {
- DPRINTF(DBG_INFO, ("ans (%c)\n", ans));
- rv = FWFLASH_FAILURE;
- goto out;
- }
- }
-
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout, gettext("Reading"));
-
- /* read both the primary and secondary images */
- for (i = FWFLASH_FLASH_IMAGES; i > 0; i--) {
- char *type = i == 1 ? "Primary" : "Secondary";
-
- DPRINTF(DBG_INFO, ("READING %s IMAGE\n", type));
- (void) printf(" .");
- (void) fflush((void *)NULL);
- rv = fwflash_ib_read_image(state.ibhdl, i);
- if (rv != 0) {
- (void) fprintf(stderr, gettext("Failed to read"));
- (void) fprintf(stderr, " %s ", type);
- (void) fprintf(stderr, gettext("image on device"));
- (void) fprintf(stderr, " (%s)\n", state.device_name);
- goto out;
- }
- }
- (void) printf(" .");
- (void) fflush((void *)NULL);
- rv = fwflash_ib_write_file(state.ibhdl, state.filename);
- (void) fprintf(stdout, "\n");
- (void) fprintf(stdout, gettext("Done."));
- (void) fprintf(stdout, "\n");
-out:
- fwflash_ib_close(state.ibhdl);
- fwflash_in_write = 0;
- return (rv);
-}
diff --git a/usr/src/cmd/fwflash/fwflash.h b/usr/src/cmd/fwflash/fwflash.h
deleted file mode 100644
index f09c48383e..0000000000
--- a/usr/src/cmd/fwflash/fwflash.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _FWFLASH_H
-#define _FWFLASH_H
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * fwflash.h
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "fwflash_ib.h"
-
-/*
- * Debugging output level:
- * DBG_NONE - no output
- * DBG_INFO - informative debugging
- * output
- * DBG_ERR - error output
- */
-#define DBG_NONE 0x00
-#define DBG_INFO 0x01
-#define DBG_ERR 0x02
-
-/*
- * XXX Let's define DEBUG for now. We can patch this binary if we need to,
- * changing 'fwflash_debug' in the field, if we really need to debug things.
- * By defining DEBUG, this enables us to do that on the fly. May change later.
- */
-#define DEBUG
-#ifdef DEBUG
-static int fwflash_debug = DBG_NONE;
-/* static int fwflash_debug = DBG_INFO | DBG_ERR; */
-#define DPRINTF(DBG_LEVEL, ARGLIST) \
- if (DBG_LEVEL & fwflash_debug) (void) printf ARGLIST;
-#else
-#define DPRINTF(DBG_LEVEL, ARGLIST)
-#endif /* DEBUG */
-
-#define FWFLASH_SUCCESS 0
-#define FWFLASH_FAILURE 1
-
-#define FWFLASH_FLASH_IMAGES 2
-#define FWFLASH_VERSION "1.2"
-#define FWFLASH_PGM_NAME "fwflash"
-
-typedef struct fwflash_device_info_s {
- char **device_list;
- int *device_class;
-} fwflash_device_info_t;
-
-typedef struct fwflash_state_s {
- fwflash_ib_hdl_t *ibhdl;
- fwflash_device_info_t *devices;
- int count;
- char *filename;
- char *device_name;
- int device_class;
-} fwflash_state_t;
-
-/* 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
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _FWFLASH_H */
diff --git a/usr/src/cmd/fwflash/fwflash_ib.c b/usr/src/cmd/fwflash/fwflash_ib.c
deleted file mode 100644
index e243f6c772..0000000000
--- a/usr/src/cmd/fwflash/fwflash_ib.c
+++ /dev/null
@@ -1,2352 +0,0 @@
-/*
- * 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 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * fwflash_ib.c
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <locale.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <errno.h>
-#include <libdevinfo.h>
-#include <netinet/in.h>
-#include <inttypes.h>
-#include <sys/ib/adapters/tavor/tavor_ioctl.h>
-#include "fwflash.h"
-#include "fwflash_ib.h"
-#include "fwflash_ib_impl.h"
-#include "fwflash_mlx.h"
-
-/*
- * Internal IB Flash update routines
- */
-static int fwflash_ib_i_check_handle(fwflash_ib_hdl_t *handle);
-static int fwflash_ib_i_num_sectors(fwflash_ib_hdl_t *handle, int size);
-static int fwflash_ib_i_read_file(FILE *fp, int len, void *buf);
-static int fwflash_ib_i_local_verify(fwflash_ib_hdl_t *handle, uint32_t offset);
-static int fwflash_ib_i_flash_verify_signature(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_local_verify_signature(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_local_verify_vsd(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_flash_zero_signature(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_local_verify_xps_crc(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static void fwflash_ib_i_local_set_xps_crc(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_flash_set_xps_crc(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static uint32_t fwflash_ib_i_flash_get_sect_size(fwflash_ib_hdl_t *handle);
-static uint32_t fwflash_ib_i_local_get_sect_size(fwflash_ib_hdl_t *handle);
-static int fwflash_ib_i_flash_verify_is(fwflash_ib_hdl_t *handle);
-static int fwflash_ib_i_flash_verify_flash_info(fwflash_ib_hdl_t *handle,
- uint32_t size);
-static void fwflash_ib_i_flash_verify_flash_match(fwflash_ib_hdl_t *handle,
- int offset, int type);
-static void fwflash_ib_i_flash_verify_flash_pn(fwflash_ib_hdl_t *handle,
- uchar_t *psid, int psid_size, int type);
-static void fwflash_ib_i_flash_verify_flash_fwpsid(fwflash_ib_hdl_t *handle,
- uchar_t *psid, int psid_size);
-static uchar_t *fwflash_ib_i_flash_get_psid(fwflash_ib_hdl_t *handle,
- int offset);
-static uint16_t fwflash_ib_i_check_hwver(fwflash_ib_hdl_t *handle);
-static void fwflash_ib_i_local_zero_crc(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_flash_zero_crc(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static uint32_t fwflash_ib_i_local_get_fw_size(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static uint32_t fwflash_ib_i_local_get_fw_addr(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static uint32_t fwflash_ib_i_flash_get_fw_addr(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_flash_set_fw_addr(fwflash_ib_hdl_t *handle,
- uint32_t offset, uint32_t addr);
-static int fwflash_ib_i_flash_set_signature(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static int fwflash_ib_i_flash_read_guids(fwflash_ib_hdl_t *handle, void *buf,
- int type);
-static void fwflash_ib_i_local_set_guid_crc(fwflash_ib_hdl_t *handle,
- uint32_t offset);
-static uint16_t crc16(uint8_t *image, uint32_t size);
-
-/* global arg list */
-extern int fwflash_arg_list;
-
-/*
- * Generate list of devices.
- */
-char **
-fwflash_ib_device_list(int *count)
-{
- di_node_t root_node;
- di_node_t node;
- char *phys_path;
- int phys_path_len;
- char **device_list = NULL;
- int i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_device_list\n"));
- if (count == NULL) {
- DPRINTF(DBG_ERR, ("\nNULL count\n"));
- goto out;
- }
-
- root_node = di_init("/", DINFOCPYALL);
- if (root_node == DI_NODE_NIL) {
- DPRINTF(DBG_ERR, ("\nNo root node\n"));
- goto out;
- }
-
- *count = 0;
- node = di_drv_first_node(FWFLASH_IB_DRIVER_NAME, root_node);
- while (node != DI_NODE_NIL) {
- node = di_drv_next_node(node);
- ++(*count);
- }
-
- if (*count <= 0) {
- DPRINTF(DBG_ERR, ("\nNo devices found\n"));
- di_fini(root_node);
- goto out;
- }
-
- /* Allocate device_list for number of devices */
- device_list = (char **)malloc(sizeof (char *) * (*count));
- if (device_list == NULL) {
- DPRINTF(DBG_ERR, ("\nCan't malloc device_list (0x%x)\n",
- errno));
- goto out;
- }
-
- i = 0;
- node = di_drv_first_node(FWFLASH_IB_DRIVER_NAME, root_node);
- while (node != DI_NODE_NIL) {
- phys_path = di_devfs_path(node);
-
- if (phys_path == NULL) {
- DPRINTF(DBG_ERR, ("\n%s phys_path is NULL \n",
- FWFLASH_IB_DRIVER_NAME));
- free(device_list);
- }
-
- /*
- * Set path length, plus enough spaces to add
- * /devices/etc. paths below.
- */
- phys_path_len = strlen(phys_path) + 25;
-
- device_list[i] = (char *)malloc(sizeof (char) *
- (phys_path_len + 2));
- if (device_list[i] == NULL) {
- DPRINTF(DBG_ERR, ("\nCan't malloc %s list[%d] (0x%x)\n",
- FWFLASH_IB_DRIVER_NAME, i, errno));
- free(device_list);
- device_list = (char **)NULL;
- goto out;
- }
- (void) snprintf(device_list[i], phys_path_len,
- "/devices%s:devctl", phys_path);
-
- i++;
- di_devfs_path_free(phys_path);
- node = di_drv_next_node(node);
- }
- di_fini(root_node);
-out:
- return (device_list);
-}
-
-fwflash_ib_hdl_t *
-fwflash_ib_open(char *dev_path)
-{
- tavor_flash_init_ioctl_t init_ioctl;
- fwflash_ib_hdl_t *handle;
- cfi_t cfi;
- int fd = 0;
- int id_size = 0;
- int ret;
- int i, j;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_open\n"));
- if (dev_path == NULL) {
- DPRINTF(DBG_ERR, ("\ndevpath is NULL\n"));
- goto bad;
- }
-
- fd = open(dev_path, O_RDWR);
- if (fd == -1) {
- perror("fwflash_ib_open");
- goto bad;
- }
-
- handle = (fwflash_ib_hdl_t *)malloc(sizeof (fwflash_ib_hdl_t));
- if (handle == NULL) {
- DPRINTF(DBG_ERR, ("\nhandle malloc failed (%d)\n", errno));
- goto bad;
- }
- bzero(handle, sizeof (fwflash_ib_hdl_t));
-
- handle->magic = FWFLASH_IB_MAGIC_NUMBER;
- handle->state = FWFLASH_IB_STATE_NONE;
-
- handle->fd = fd;
-
- /*
- * Inform driver: this cmd supports the Intel Extended CFI
- * command set.
- */
- cfi.cfi_char[0x10] = 'M';
- cfi.cfi_char[0x11] = 'X';
- cfi.cfi_char[0x12] = '2';
- init_ioctl.tf_cfi_info[0x4] = ntohl(cfi.cfi_int[0x4]);
-
- /* call flash init ioctl */
- ret = ioctl(handle->fd, TAVOR_IOCTL_FLASH_INIT, &init_ioctl);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nTAVOR_IOCTL_FLASH_INIT failed "
- "(0x%x)\n", errno));
- goto bad;
- }
- handle->hwrev = init_ioctl.tf_hwrev;
-
- /*
- * Determine if the attached driver doesn't support
- * the Intel Extended CFI command set. And if not,
- * verify it's the AMD command set. If not error out
- * as the Intel cmd set can't be used without support
- * in the driver.
- */
- for (i = 0; i < TAVOR_FLASH_CFI_SIZE_QUADLET; i++) {
- cfi.cfi_int[i] = ntohl(init_ioctl.tf_cfi_info[i]);
- }
-
- handle->cmd_set = cfi.cfi_char[0x13];
- if (cfi.cfi_char[0x10] == 'Q' &&
- cfi.cfi_char[0x11] == 'R' &&
- cfi.cfi_char[0x12] == 'Y') {
- /* make sure the cmd set is AMD */
- if (handle->cmd_set != TAVOR_FLASH_AMD_CMDSET) {
- (void) fprintf(stderr,
- gettext("Unsupported flash device command set"));
- (void) fprintf(stderr, "\n");
- goto bad;
- }
- /* set some defaults */
- handle->sector_sz = TAVOR_FLASH_SECTOR_SZ_DEFAULT;
- handle->device_sz = TAVOR_FLASH_DEVICE_SZ_DEFAULT;
- } else {
- if (handle->cmd_set != TAVOR_FLASH_AMD_CMDSET &&
- handle->cmd_set != TAVOR_FLASH_INTEL_CMDSET) {
- (void) fprintf(stderr,
- gettext("Uknown flash device command set"));
- (void) fprintf(stderr, "\n");
- goto bad;
- }
- /* read from the CFI data */
- handle->sector_sz = ((cfi.cfi_char[0x30] << 8) |
- cfi.cfi_char[0x2F]) << 8;
- handle->device_sz = 0x1 << cfi.cfi_char[0x27];
- }
-
- DPRINTF(DBG_INFO, ("sector_sz: 0x%08x\ndevice_sz: 0x%08x\n",
- handle->sector_sz, handle->device_sz));
-
- handle->dev_path = strdup(dev_path);
-
- handle->fw = (uint32_t *)malloc(handle->device_sz);
- if (handle->fw == NULL) {
- DPRINTF(DBG_ERR, ("\nfw malloc failed (%d)\n", errno));
- goto bad;
- }
-
- bzero(handle->fw, sizeof (handle->device_sz));
- handle->state |= FWFLASH_IB_STATE_MMAP;
-
- /* set firmware revision */
- handle->fw_rev.major = init_ioctl.tf_fwrev.tfi_maj;
- handle->fw_rev.minor = init_ioctl.tf_fwrev.tfi_min;
- handle->fw_rev.subminor = init_ioctl.tf_fwrev.tfi_sub;
-
- /* set hw part number, psid, and name in handle */
- if (init_ioctl.tf_pn_len != 0) {
- /* part number length */
- for (i = 0; i < init_ioctl.tf_pn_len; i++) {
- if (init_ioctl.tf_hwpn[i] == ' ') {
- handle->pn_len = i;
- break;
- }
- }
- if (i == init_ioctl.tf_pn_len) {
- handle->pn_len = init_ioctl.tf_pn_len;
- }
- } else {
- handle->pn_len = 0;
- }
-
- if (handle->pn_len != 0) {
- handle->info.mlx_pn = malloc(handle->pn_len);
- if (handle->info.mlx_pn == NULL) {
- DPRINTF(DBG_ERR, ("\nhandle PN malloc failed (%d)\n",
- errno));
- goto bad;
- }
- (void) memcpy(handle->info.mlx_pn, init_ioctl.tf_hwpn,
- handle->pn_len);
- DPRINTF(DBG_INFO, ("HCA PN (%s)\n", handle->info.mlx_pn));
-
- /* Find part number, set the rest */
- for (i = 0; i < FWFLASH_MAX_ID; i++) {
- if (strncmp((const char *)init_ioctl.tf_hwpn,
- mlx_mdr[i].mlx_pn, handle->pn_len) == 0) {
- /* Set PSID */
- handle->info.mlx_psid = malloc(FWFLASH_PSID_SZ);
- if (handle->info.mlx_psid == NULL) {
- DPRINTF(DBG_ERR,
- ("\nPSID malloc failed (%d)\n",
- errno));
- goto bad;
- }
- (void) memcpy(handle->info.mlx_psid,
- mlx_mdr[i].mlx_psid, FWFLASH_PSID_SZ);
- handle->info.mlx_psid[FWFLASH_PSID_SZ] = 0;
- DPRINTF(DBG_INFO, ("HCA PSID (%s)\n",
- handle->info.mlx_psid));
-
- /* determine name length */
- for (j = 0; j < FWFLASH_MAX_ID_SZ; j++) {
- int id_char = (int)mlx_mdr[i].mlx_id[j];
- if (!isalpha(id_char) &&
- !isspace(id_char)) {
- id_size = j + 1;
- break;
- }
- }
- if (j == FWFLASH_MAX_ID_SZ) {
- id_size = FWFLASH_MAX_ID_SZ;
- }
-
- /* Set string ID */
- handle->info.mlx_id = malloc(id_size);
- if (handle->info.mlx_psid == NULL) {
- DPRINTF(DBG_ERR,
- ("\nID malloc failed (%d)\n",
- errno));
- goto bad;
- }
- (void) memcpy(handle->info.mlx_id,
- mlx_mdr[i].mlx_id, id_size);
- handle->info.mlx_id[id_size] = 0;
- DPRINTF(DBG_INFO, ("HCA Name (%s)\n",
- handle->info.mlx_id));
-
- break;
- }
- }
- if (i == FWFLASH_MAX_ID) {
- DPRINTF(DBG_ERR, ("\nUnknown Part Number: (%s)\n",
- handle->info.mlx_pn));
- handle->pn_len = 0;
- }
- }
-
- return (handle);
-bad:
- /* cleanup */
- if (handle->info.mlx_id != NULL) {
- free(handle->info.mlx_id);
- }
- if (handle->info.mlx_psid != NULL) {
- free(handle->info.mlx_psid);
- }
- if (handle->info.mlx_pn != NULL) {
- free(handle->info.mlx_pn);
- }
- if (handle != NULL) {
- free(handle);
- }
- return (NULL);
-}
-
-/*
- * Close device by calling _FINI.
- */
-void
-fwflash_ib_close(fwflash_ib_hdl_t *handle)
-{
- int ret;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_close\n"));
- ret = fwflash_ib_i_check_handle(handle);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nInvalid handle\n"));
- return;
- }
-
- if (handle->fd > 0) {
- (void) ioctl(handle->fd, TAVOR_IOCTL_FLASH_FINI);
- ret = close(handle->fd);
- if (ret != 0) {
- perror("fwflash_ib_close");
- return;
- }
- }
-
- /* cleanup */
- if (handle->fw != NULL) {
- free(handle->fw);
- }
- if (handle->info.mlx_id != NULL) {
- free(handle->info.mlx_id);
- }
- if (handle->info.mlx_psid != NULL) {
- free(handle->info.mlx_psid);
- }
- if (handle->info.mlx_pn != NULL) {
- free(handle->info.mlx_pn);
- }
- free(handle);
- handle = NULL;
-}
-
-/*
- * Driver read/write ioctl calls.
- */
-int
-fwflash_read_ioctl(fwflash_ib_hdl_t *hdl, tavor_flash_ioctl_t *info)
-{
- int ret;
-
- DPRINTF(DBG_INFO, ("flash_read: fd(%d) tf_type(0x%x) tf_addr(0x%x)\n",
- hdl->fd, info->tf_type, info->tf_addr));
- ret = ioctl(hdl->fd, TAVOR_IOCTL_FLASH_READ, info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nTAVOR_IOCTL_FLASH_READ failed (0x%x)\n",
- errno));
- }
- return (ret);
-}
-
-int
-fwflash_write_ioctl(fwflash_ib_hdl_t *hdl, tavor_flash_ioctl_t *info)
-{
- int ret;
-
- DPRINTF(DBG_INFO, ("flash_write fd(%d) tf_type(0x%x) tf_addr(0x%x)\n",
- hdl->fd, info->tf_type, info->tf_addr));
- ret = ioctl(hdl->fd, TAVOR_IOCTL_FLASH_WRITE, info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nTAVOR_IOCTL_FLASH_WRITE failed (0x%x)\n",
- errno));
- }
- return (ret);
-}
-
-/*
- * Notes:
- * 1. flash read is done in 32 bit quantities, and the driver returns
- * data in host byteorder form.
- * 2. flash write is done in 8 bit quantities by the driver.
- * 3. data in the flash should be in network byteorder.
- * 4. data in image files is in network byteorder form.
- * 5. data in image structures in memory is kept in network byteorder.
- * 6. the functions in this file deal with data in host byteorder form.
- */
-
-int
-fwflash_ib_read_image(fwflash_ib_hdl_t *handle, int type)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t sector_size;
- int start_sector;
- int ps_offset;
- int ret, len, i;
-#ifdef _LITTLE_ENDIAN
- uint32_t *ptr;
- int j;
-#endif
-
- DPRINTF(DBG_INFO, ("fwflash_ib_read_image\n"));
- /* Get Sector Size */
- sector_size = fwflash_ib_i_flash_get_sect_size(handle);
- DPRINTF(DBG_INFO, ("sector_size: 0x%x\n", sector_size));
-
- /* Verify flash info */
- ret = fwflash_ib_i_flash_verify_flash_info(handle, sector_size);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to verify flash info\n"));
- goto out;
- }
-
- /* Read IS Sector */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- ioctl_info.tf_sector_num = 0;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(handle->fw, 0, sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read IS\n"));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (i = 0; i < (1 << sector_size)/4; i ++) {
- ptr[i] = htonl(ptr[i]);
- }
-#endif
-
- /* offset is the start of the xPS sector */
- /* 'type' is the sector number input as PPS or SPS */
- ps_offset = type << sector_size;
-
- DPRINTF(DBG_INFO, ("type: 0x%x\n", type));
- DPRINTF(DBG_INFO, ("ps_offset: 0x%x\n", ps_offset));
-
- /* Read in PS */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- ioctl_info.tf_sector_num = type;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(handle->fw, type,
- sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read PS\n"));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (i = 0; i < (1 << sector_size)/4; i ++) {
- ptr[i] = htonl(ptr[i]);
- }
-#endif
-
- /* Verify Valid signature */
- ret = fwflash_ib_i_local_verify_signature(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to verify signature for %s image\n",
- type == 0x1 ? "Primary" : "Secondary"));
- goto out;
- }
-
- /* Verify Valid CRC */
- ret = fwflash_ib_i_local_verify_xps_crc(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to verify crc for %s image\n",
- type == 0x1 ? "Primary" : "Secondary"));
- goto out;
- }
-
- /* Read Firmware Image Size */
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = ps_offset + FLASH_PS_FW_SIZE_OFFSET;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read FW image size\n"));
- goto out;
- }
- DPRINTF(DBG_INFO, ("fw_size: 0x%x\n", ioctl_info.tf_quadlet));
-
- /* Based on firmware size, see how many sectors it takes up */
- len = fwflash_ib_i_num_sectors(handle, ioctl_info.tf_quadlet);
- DPRINTF(DBG_INFO, ("num_sectors: 0x%x\n", len));
-
- /* Get Firmware Start Address */
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = ps_offset + FLASH_PS_FI_ADDR_OFFSET;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read FW start addr\n"));
- goto out;
- }
- DPRINTF(DBG_INFO, ("fw_addr: 0x%x\n", ioctl_info.tf_quadlet));
-
- /* Translate fw addr to sector offset */
- start_sector = ioctl_info.tf_quadlet >> sector_size;
- DPRINTF(DBG_INFO, ("start_sector: 0x%x\n", start_sector));
-
- /* Read one sector at a time */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- for (i = start_sector; i < (len + start_sector); i++) {
- ioctl_info.tf_sector_num = i;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(handle->fw, i,
- sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read sec %d\n", i));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (j = 0; j < (1 << sector_size)/4; j ++) {
- ptr[j] = htonl(ptr[j]);
- }
-#endif
-
- }
-
- handle->state |= type;
-out:
- return (ret);
-}
-
-/*
- * type is PRIMARY or SECONDARY
- */
-int
-fwflash_ib_write_image(fwflash_ib_hdl_t *handle, int type)
-{
- tavor_flash_ioctl_t ioctl_info;
- int ps_offset;
- int sector_size;
- int start_sector_local;
- int start_sector_flash;
- int local_addr, flash_addr;
- int addr, size;
- int save_addr;
- int len, ret, i;
- uint16_t ver;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_write_image\n"));
- ret = fwflash_ib_i_check_handle(handle);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nInvalid handle\n"));
- goto out;
- }
-
- if ((handle->state & type) == 0) {
- DPRINTF(DBG_ERR, ("\nMust read in image first\n"));
- ret = -1;
- goto out;
- }
-
- /* Check Hardware Rev */
- ver = fwflash_ib_i_check_hwver(handle);
- if (ver != 0) {
- DPRINTF(DBG_ERR, ("\nFirmware missmatch: ver(0x%X) "
- "hw_ver(0x%X)\n", (ver >> 8), ver & 0xFF));
- ret = -1;
- goto out;
- }
-
- ret = fwflash_ib_i_flash_verify_is(handle);
- if (ret != 0) {
- DPRINTF(DBG_INFO, ("Writing new Invariant Sector...\n"));
- ret = fwflash_ib_write_is(handle);
- if (ret != 0) {
- DPRINTF(DBG_ERR,
- ("\nFailed to write Invariant Sector\n"));
- goto out;
- }
- }
-
- /* Get Sector Size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
- DPRINTF(DBG_INFO, ("sector_size: 0x%x\n", sector_size));
-
- DPRINTF(DBG_INFO, ("type: 0x%x\n", type));
- ps_offset = type << sector_size;
- DPRINTF(DBG_INFO, ("ps_offset: 0x%x\n", ps_offset));
-
- /* Verify local PS */
- ret = fwflash_ib_i_local_verify(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to verify local %s image\n",
- type == 1 ? "Primary" : "Secondary"));
- goto out;
- }
-
- /* Invalidate FW Signature */
- DPRINTF(DBG_INFO, ("Invalidate flash sig\n"));
- ret = fwflash_ib_i_flash_zero_signature(handle, ps_offset);
- if (ret != 0) {
- goto out;
- }
-
- /* Invalidate FW CRC */
- DPRINTF(DBG_INFO, ("Invalidate flash crc\n"));
- (void) fwflash_ib_i_flash_zero_crc(handle, ps_offset);
-
- /* Read Image Size */
- size = fwflash_ib_i_local_get_fw_size(handle, ps_offset);
- DPRINTF(DBG_INFO, ("Local fw size: 0x%x\n", size));
-
- /* Based on size, calculate how many sectors we need */
- len = fwflash_ib_i_num_sectors(handle, size);
- DPRINTF(DBG_INFO, ("Number of sectors: 0x%x\n", len));
-
- /* Get Firmware Start Address on local */
- local_addr = fwflash_ib_i_local_get_fw_addr(handle, ps_offset);
- DPRINTF(DBG_INFO, ("Local FW start addr: 0x%x\n", local_addr));
-
- /* Get Firmware Start Address on flash */
- flash_addr = fwflash_ib_i_flash_get_fw_addr(handle, ps_offset);
- DPRINTF(DBG_INFO, ("Flash FW start addr: 0x%x\n", flash_addr));
-
- if (local_addr < flash_addr) {
- addr = flash_addr;
- } else {
- addr = local_addr;
- }
-
- /* Translate fw addr to sector offset */
- start_sector_local = local_addr >> sector_size;
- start_sector_flash = addr >> sector_size;
- DPRINTF(DBG_INFO, ("local start_sector: 0x%x\n", start_sector_local));
- DPRINTF(DBG_INFO, ("flash start_sector: 0x%x\n", start_sector_flash));
-
- /* Write one sector of fw image at a time */
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_SECTOR;
- for (i = 0; i < len; i++) {
- ioctl_info.tf_sector_num = start_sector_flash + i;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(handle->fw,
- start_sector_local + i, sector_size);
-
- /* give the user some progress output */
- (void) printf(" .");
- (void) fflush((void *)NULL);
-
- DPRINTF(DBG_INFO, ("Writing sector: 0x%x\n",
- ioctl_info.tf_sector_num));
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to write sector (0x%x)\n",
- ioctl_info.tf_sector_num));
- goto out;
- }
- }
-
- /* Invalidate local SIG and CRC */
- handle->fw[(ps_offset + FLASH_PS_SIGNATURE_OFFSET) / 4] = 0xFFFFFFFF;
- fwflash_ib_i_local_zero_crc(handle, ps_offset);
-
- /* Invalidate Firmware Image Address but save it to put back locally */
- save_addr = handle->fw[(ps_offset + FLASH_PS_FI_ADDR_OFFSET) / 4];
- handle->fw[(ps_offset + FLASH_PS_FI_ADDR_OFFSET) / 4] = 0xFFFFFFFF;
-
- /* Write fw PS */
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_SECTOR;
- ioctl_info.tf_sector_num = type;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(handle->fw, type,
- sector_size);
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to write PS\n"));
- goto out;
- }
-
- /* Make sure fw addr pointer is updated to be correct */
- DPRINTF(DBG_ERR, ("Updating fw addr pointer in PS: 0x%x\n", addr));
- ret = fwflash_ib_i_flash_set_fw_addr(handle, ps_offset, addr);
- if (ret != 0) {
- goto out;
- }
-
- /* Restore previous firmware address in local image */
- handle->fw[(ps_offset + FLASH_PS_FI_ADDR_OFFSET) / 4] = save_addr;
-
- /* Set local SIG */
- handle->fw[(ps_offset + FLASH_PS_SIGNATURE_OFFSET) / 4] =
- (uint32_t)htonl(FLASH_PS_SIGNATURE);
-
- /* calc local CRC */
- fwflash_ib_i_local_set_xps_crc(handle, ps_offset);
-
- /* Set CRC */
- ret = fwflash_ib_i_flash_set_xps_crc(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set crc\n"));
- goto out;
- }
-
- /* Set Signature */
- ret = fwflash_ib_i_flash_set_signature(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set signature\n"));
- goto out;
- }
-
- ret = fwflash_ib_i_flash_verify_signature(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to verify flash sig\n"));
- }
-out:
- return (ret);
-}
-
-int
-fwflash_ib_verify_image(fwflash_ib_hdl_t *handle, int type)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t *flash;
- uint32_t start_addr;
- uint32_t end_addr;
- int len, size;
- int sector_size;
- int start_sector_local;
- int start_sector_flash;
- int local_addr, flash_addr;
- int addr, ps_offset;
- int ret, i;
-#ifdef _LITTLE_ENDIAN
- uint32_t *ptr;
- int j;
-#endif
-
- DPRINTF(DBG_INFO, ("fwflash_ib_verify_image\n"));
- ret = fwflash_ib_i_check_handle(handle);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nInvalid handle\n"));
- goto out;
- }
-
- if ((handle->state & type) == 0) {
- DPRINTF(DBG_ERR, ("\nMust read in an image first\n"));
- ret = -1;
- goto out;
- }
-
- flash = (uint32_t *)malloc(handle->device_sz);
- if (flash == NULL) {
- DPRINTF(DBG_ERR, ("\nflash malloc failed (0x%x\n", errno));
- ret = -1;
- goto out;
- }
-
- /* Get Sector Size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
-
- /* Get offset to pointer sector based on type */
- ps_offset = type << sector_size;
-
- /* Get FW Size */
- size = fwflash_ib_i_local_get_fw_size(handle, ps_offset);
-
- /* Based on size, determine number of sectors needed */
- len = fwflash_ib_i_num_sectors(handle, size);
-
- /* First read IS sector */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- ioctl_info.tf_sector_num = 0;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(&flash[0], 0, sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read IS\n"));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (i = 0; i < (1 << sector_size)/4; i ++) {
- ptr[i] = htonl(ptr[i]);
- }
-#endif
-
- /* Compare IS */
- DPRINTF(DBG_INFO, ("Comparing IS..\n"));
- for (i = 0; i < (1 << sector_size) / 4; i++) {
- if (flash[i] != handle->fw[i]) {
- DPRINTF(DBG_ERR, ("\nIS Verify failed at offset: %d\n",
- i));
- DPRINTF(DBG_ERR, ("expected: 0x%X, actual: 0x%X\n",
- handle->fw[i], flash[i]));
- ret = -1;
- goto out;
- }
- }
-
- /* First read pointer sector */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- ioctl_info.tf_sector_num = type;
- ioctl_info.tf_sector =
- FLASH_SECTOR_OFFSET(&flash[0], type, sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read pointer (0x%x)\n", type));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (i = 0; i < (1 << sector_size)/4; i ++) {
- ptr[i] = htonl(ptr[i]);
- }
-#endif
- /* Get Firmware Start Address */
- local_addr = fwflash_ib_i_local_get_fw_addr(handle, ps_offset);
- DPRINTF(DBG_INFO, ("Local FW start addr: 0x%x\n", local_addr));
-
- /* Get Firmware Start Address on flash */
- flash_addr = fwflash_ib_i_flash_get_fw_addr(handle, ps_offset);
- DPRINTF(DBG_INFO, ("\nFlash FW start addr: 0x%x\n", flash_addr));
-
- /* Compare PS */
- DPRINTF(DBG_INFO, ("Comparing PS: start: 0x%x, end: 0x%x\n",
- ps_offset, ps_offset + (1 << sector_size)));
- for (i = ps_offset / 4; i < (ps_offset + (1 << sector_size)) / 4; i++) {
- if (flash[i] != handle->fw[i]) {
- /* Skip error, if firmware image addr is correct */
- if (i == (ps_offset / 4) &&
- ntohl(flash[i]) == flash_addr &&
- ntohl(handle->fw[i]) == local_addr) {
- continue;
- }
- DPRINTF(DBG_ERR, ("\nPS Verify failed at offset: %d\n",
- i));
- DPRINTF(DBG_ERR, ("expected: 0x%X, actual: 0x%X\n",
- handle->fw[i], flash[i]));
- ret = -1;
- goto out;
- }
- }
-
- /* Setup addr pointer based on firmware size differences */
- if (local_addr < flash_addr) {
- addr = flash_addr;
- } else {
- addr = local_addr;
- }
-
- /* Translate fw addr to sector offset */
- start_sector_local = local_addr >> sector_size;
- start_sector_flash = addr >> sector_size;
- DPRINTF(DBG_INFO, ("start_sector: 0x%x\n", start_sector_local));
- DPRINTF(DBG_INFO, ("start_sector: 0x%x\n", start_sector_flash));
-
- /* Read FW image */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- for (i = 0; i < len; i++) {
- ioctl_info.tf_sector_num = start_sector_flash + i;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(&flash[0],
- start_sector_local + i, sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read FW\n"));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (j = 0; j < (1 << sector_size)/4; j ++) {
- ptr[j] = htonl(ptr[j]);
- }
-#endif
- }
-
- /* Compare FW Image */
- start_addr = start_sector_local << sector_size;
- end_addr = start_addr + size;
- DPRINTF(DBG_INFO, ("FW Compare: start: 0x%x, end: 0x%x\n", start_addr,
- end_addr));
-
- for (i = start_addr / 4;
- i < end_addr / 4; i++) {
- if (flash[i] != handle->fw[i]) {
- DPRINTF(DBG_ERR, ("\nVerify failed at offset: 0x%x\n",
- i));
- DPRINTF(DBG_ERR, ("expected: 0x%X, actual: 0x%X\n",
- handle->fw[i], flash[i]));
- ret = -1;
- break;
- }
- }
-out:
- if (flash != NULL) {
- free(flash);
- }
- return (ret);
-}
-
-int
-fwflash_ib_write_is(fwflash_ib_hdl_t *handle)
-{
- tavor_flash_ioctl_t ioctl_info;
- int sector_size;
- int ret;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_write_is\n"));
- if ((handle->state & FWFLASH_IB_STATE_PFI_IMAGE) == 0 &&
- (handle->state & FWFLASH_IB_STATE_SFI_IMAGE) == 0) {
- DPRINTF(DBG_ERR, ("Must read in image first.\n"));
- return (-1);
- }
-
- /* Get sector size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
-
- /* Write one sector of IS */
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_SECTOR;
- ioctl_info.tf_sector_num = 0;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(handle->fw, 0, sector_size);
-
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to write IS\n"));
- return (-1);
- }
-
- return (0);
-}
-
-int
-fwflash_ib_read_file(fwflash_ib_hdl_t *handle, const char *filename)
-{
- FILE *fp;
- char ans;
- int sector_size;
- int ps_okay[2];
- int ps_offset;
- int len, ps;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_read_file: file %s\n", filename));
- fp = fopen(filename, "r");
- if (fp == NULL) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("Unknown filename"));
- (void) fprintf(stderr, ": %s\n", filename);
- ret = -1;
- goto out;
- }
-
- len = handle->device_sz;
- ret = fwflash_ib_i_read_file(fp, len, &handle->fw[0]);
- if (ret != 0) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("Error reading file"));
- (void) fprintf(stderr, ": %s\n", filename);
- goto out;
- }
-
- /* Get sector size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
-
- /* Verify flash info */
- ret = fwflash_ib_i_flash_verify_flash_info(handle, sector_size);
- if (ret != 0) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("Unknown file type"));
- (void) fprintf(stderr, ": %s\n", filename);
- goto out;
- }
-
- handle->hwfw_match = 0;
- for (i = 1; i < 3; i++) {
- /* set array pointer */
- ps = i - 1;
-
- /* Read PS */
- ps_offset = i << sector_size;
-
- ps_okay[ps] = fwflash_ib_i_local_verify_xps_crc(handle,
- ps_offset);
-
- if (ps_okay[ps] == 0) {
- /* set state field correctly */
- handle->state |= i;
- }
-
- /* verify fw matches the hardware */
- fwflash_ib_i_flash_verify_flash_match(handle, ps_offset, i);
- }
-
- if (handle->hwfw_match == 0) {
- (void) fprintf(stderr, "\n\t");
- if (handle->pn_len != 0) {
- /* HW VPD exist and a mismatch was found */
- (void) fprintf(stderr, gettext(
- "Please verify that the firmware image"
- "\n\tis intended for use with this hardware"));
- } else {
- (void) fprintf(stdout, gettext(
- "Unable to verify firmware is appropriate"
- "\n\tfor the hardware"));
- }
- (void) fprintf(stdout, "\n\t");
- (void) fprintf(stdout, gettext("Do you want to continue"));
- (void) fprintf(stdout, " (Y/N): ");
- ans = getchar();
- if (ans != 'Y' && ans != 'y') {
- ret = -1;
- } else {
- fwflash_arg_list |= FWFLASH_YES_FLAG;
- ret = 0;
- }
- }
-
-out:
- if (fp != NULL) {
- (void) fclose(fp);
- }
- return (ret);
-}
-
-int
-fwflash_ib_write_file(fwflash_ib_hdl_t *handle, const char *filename)
-{
- FILE *fp;
- uint32_t *fw;
- uint8_t *fwp;
- int ps_offset;
- int sector;
- int sector_size;
- int sector_size_val;
- int ps_okay[2];
- uint32_t fw_addr[2];
- uint32_t fw_size[2];
- uint32_t fw_new_addr[2];
- uint16_t crc;
- int addr;
- int len;
- int ret;
- int ps;
- int i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_write_file\n"));
- ret = fwflash_ib_i_check_handle(handle);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nInvalid handle\n"));
- goto out;
- }
-
- if ((handle->state & FWFLASH_IB_STATE_PFI_IMAGE) == 0 &&
- (handle->state & FWFLASH_IB_STATE_SFI_IMAGE) == 0) {
- DPRINTF(DBG_ERR, ("Must read in image first.\n"));
- return (-1);
- }
-
- fp = fopen(filename, "w");
- if (fp == NULL) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("Unknown filename"));
- (void) fprintf(stderr, ": %s\n", filename);
- ret = -1;
- goto out;
- }
-
- /* Get Sector Size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
- sector_size_val = 1 << sector_size;
- DPRINTF(DBG_INFO, ("sector_size: 0x%x\n", sector_size));
-
- for (i = 1; i < 3; i++) {
- /* set array pointer */
- ps = i - 1;
-
- /* Read PS */
- ps_offset = i << sector_size;
-
- ps_okay[ps] = fwflash_ib_i_local_verify(handle,
- ps_offset);
-
- if (ps_okay[ps] != 0) {
- continue;
- }
-
- /* Get FW addr */
- fw_addr[ps] = fwflash_ib_i_local_get_fw_addr(handle,
- ps_offset);
-
- /* Get length */
- fw_size[ps] = fwflash_ib_i_local_get_fw_size(handle,
- ps_offset);
- }
-
- if (ps_okay[0] != 0 && ps_okay[1] != 0) {
- (void) fprintf(stderr,
- gettext("ERROR: no valid Pointer Sector found"));
- (void) fprintf(stderr, "\n");
-
- (void) fclose(fp);
- return (-1);
- }
-
- /* Build image to write out */
- fw = (uint32_t *)malloc(handle->device_sz);
- fwp = (uint8_t *)&fw[0];
- addr = 3 << sector_size;
- len = 3 << sector_size; /* len is always at least 3 sectors */
-
- /* Copy IS */
- (void) memcpy(&fw[0], &handle->fw[0], sector_size_val);
-
- /* Setup PS */
- if (ps_okay[0] == 0) {
- ps_offset = 1 << sector_size;
- fw_new_addr[0] = addr;
-
- /* Copy in PS */
- (void) memcpy(&fw[ps_offset / 4], &handle->fw[ps_offset / 4],
- sector_size_val);
-
- /* Set new FW addr */
- fw[(ps_offset + FLASH_PS_FI_ADDR_OFFSET) / 4] =
- htonl(fw_new_addr[0]);
-
- /* Set new Crc16 */
- crc = crc16((uint8_t *)
- &fw[ps_offset / 4], FLASH_PS_CRC16_SIZE);
- crc = htons(crc);
- (void) memcpy(&fwp[ps_offset + FLASH_PS_CRC16_OFFSET], &crc, 2);
-
- /* Copy FW Image */
- (void) memcpy(&fw[fw_new_addr[0] / 4],
- &handle->fw[fw_addr[0] / 4],
- fw_size[0]);
-
- len += (fwflash_ib_i_num_sectors(handle,
- fw_size[0]) << sector_size);
-
- if (fw_addr[0] != fw_addr[1]) {
- sector = (fw_addr[0] + fw_size[0]) >> sector_size;
- addr = (sector + 1) << sector_size;
- }
- }
-
- if (ps_okay[1] == 0) {
- ps_offset = 2 << sector_size;
- fw_new_addr[1] = addr;
-
- /* Copy in PS */
- (void) memcpy(&fw[ps_offset / 4], &handle->fw[ps_offset / 4],
- sector_size_val);
-
- /* Set new FW addr */
- fw[(ps_offset + FLASH_PS_FI_ADDR_OFFSET) / 4] =
- htonl(fw_new_addr[1]);
-
- /* Set new Crc16 */
- crc = crc16((uint8_t *)&fw[ps_offset / 4],
- FLASH_PS_CRC16_SIZE);
- crc = htons(crc);
- (void) memcpy(&fwp[ps_offset + FLASH_PS_CRC16_OFFSET], &crc, 2);
-
- len += fw_size[1];
-
- /* Copy FW Image if needed */
- if (fw_addr[0] != fw_addr[1]) {
- (void) memcpy(&fw[fw_new_addr[1] / 4],
- &handle->fw[fw_addr[1] / 4],
- fw_size[1]);
- }
- }
-
- ret = fwrite(&fw[0], len, 1, fp);
- if (ret == 0) {
- (void) fprintf(stderr, "\n");
- (void) fprintf(stderr, gettext("ERROR: fwrite failed"));
- (void) fprintf(stderr, "\n");
- perror("fwrite");
- (void) fclose(fp);
- return (-1);
- }
-
- (void) fclose(fp);
-out:
- return (ret);
-}
-
-int
-fwflash_ib_set_guids(fwflash_ib_hdl_t *handle, void *arg, int type)
-{
- uint32_t addr;
- uint32_t *guids;
- uint32_t fw_addr;
- uint32_t guid_ptr;
- int sector_size;
- int ps_offset;
- int ret = 0;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_set_guids\n"));
- if (arg == NULL) {
- DPRINTF(DBG_ERR, ("\nNULL guids\n"));
- ret = -1;
- goto out;
- }
-
- if ((handle->state & FWFLASH_IB_STATE_MMAP) == 0) {
- DPRINTF(DBG_INFO, ("\nFWFLASH_IB_STATE_MMAP\n"));
- goto out;
- }
-
- if (type == 0x1 && (handle->state & FWFLASH_IB_STATE_PFI_IMAGE) == 0) {
- DPRINTF(DBG_INFO, ("Reading primary from flash\n"));
- ret = fwflash_ib_read_image(handle, type);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read PFI\n"));
- goto out;
- }
- }
-
- if (type == 0x2 && (handle->state & FWFLASH_IB_STATE_SFI_IMAGE) == 0) {
- DPRINTF(DBG_INFO, ("Reading secondary from flash\n"));
- ret = fwflash_ib_read_image(handle, type);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read SFI\n"));
- goto out;
- }
- }
-
- /* Read Sector Size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
- DPRINTF(DBG_INFO, ("sector_size: 0x%x\n", sector_size));
-
- /* ps_offset is the start of the xPS sector */
- /* 'type' is the sector number input as PPS or SPS */
- ps_offset = type << sector_size;
- DPRINTF(DBG_INFO, ("ps_offset: 0x%x\n", ps_offset));
-
- fw_addr = fwflash_ib_i_local_get_fw_addr(handle, ps_offset);
- DPRINTF(DBG_INFO, ("fw_addr: 0x%x\n", fw_addr));
-
- guid_ptr = ntohl(handle->fw[(fw_addr + FLASH_GUID_PTR) / 4]);
- DPRINTF(DBG_INFO, ("guid_ptr: 0x%x\n", guid_ptr));
-
- guids = (uint32_t *)arg;
- addr = (fw_addr + guid_ptr + FLASH_FI_NGUID_OFFSET) / 4;
- DPRINTF(DBG_INFO, ("guid_start_addr: 0x%x\n", addr * 4));
-
- /*
- * guids are supplied by callers as 64 bit values in host byteorder.
- * Storage is in network byteorder.
- */
-#ifdef _BIG_ENDIAN
- if (handle->state & FWFLASH_IB_STATE_GUIDN) {
- handle->fw[addr] = guids[0];
- handle->fw[addr + 1] = guids[1];
- }
-
- if (handle->state & FWFLASH_IB_STATE_GUID1) {
- handle->fw[addr + 2] = guids[2];
- handle->fw[addr + 3] = guids[3];
- }
-
- if (handle->state & FWFLASH_IB_STATE_GUID2) {
- handle->fw[addr + 4] = guids[4];
- handle->fw[addr + 5] = guids[5];
- }
-
- if (handle->state & FWFLASH_IB_STATE_GUIDS) {
- handle->fw[addr + 6] = guids[6];
- handle->fw[addr + 7] = guids[7];
- }
-#else
- if (handle->state & FWFLASH_IB_STATE_GUIDN) {
- handle->fw[addr] = htonl(guids[1]);
- handle->fw[addr + 1] = htonl(guids[0]);
- }
-
- if (handle->state & FWFLASH_IB_STATE_GUID1) {
- handle->fw[addr + 2] = htonl(guids[3]);
- handle->fw[addr + 3] = htonl(guids[2]);
- }
-
- if (handle->state & FWFLASH_IB_STATE_GUID2) {
- handle->fw[addr + 4] = htonl(guids[5]);
- handle->fw[addr + 5] = htonl(guids[4]);
- }
-
- if (handle->state & FWFLASH_IB_STATE_GUIDS) {
- handle->fw[addr + 6] = htonl(guids[7]);
- handle->fw[addr + 7] = htonl(guids[6]);
- }
-#endif
-
- fwflash_ib_i_local_set_guid_crc(handle, (addr * 4) - 0x10);
-out:
- return (ret);
-}
-
-int
-fwflash_ib_flash_read_guids(fwflash_ib_hdl_t *handle, void *guids, int type)
-{
- int ret;
-#ifdef _LITTLE_ENDIAN
- uint32_t *ptr, tmp;
-#endif
-
- DPRINTF(DBG_INFO, ("fwflash_ib_flash_read_guids\n"));
- ret = fwflash_ib_i_check_handle(handle);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nInvalid handle\n"));
- goto out;
- }
-
- if (guids == NULL) {
- DPRINTF(DBG_INFO, ("\nNULL guids\n"));
- ret = -1;
- goto out;
- }
-
- ret = fwflash_ib_i_flash_read_guids(handle, guids, type);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read GUIDs\n"));
- goto out;
- }
-
-#ifdef _LITTLE_ENDIAN
- /*
- * guids are read as pairs of 32 bit host byteorder values and treated
- * by callers as 64 bit values. So swap each pair of 32 bit values
- * to make them correct
- */
- ptr = (uint32_t *)guids;
- for (ret = 0; ret < 8; ret += 2) {
- tmp = ptr[ret];
- ptr[ret] = ptr[ret+1];
- ptr[ret+1] = tmp;
- }
-#endif
-
- handle->state |= FWFLASH_IB_STATE_GUIDN | FWFLASH_IB_STATE_GUID1 |
- FWFLASH_IB_STATE_GUID2 | FWFLASH_IB_STATE_GUIDS;
- ret = fwflash_ib_set_guids(handle, guids, type);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set GUIDs\n"));
- }
-out:
- return (ret);
-}
-
-/*
- * Notes:
- * 1. flash read is done in 32 bit quantities, and the driver returns
- * data in host byteorder form.
- * 2. flash write is done in 8 bit quantities by the driver.
- * 3. data in the flash should be in network byteorder.
- * 4. data in image files is in network byteorder form.
- * 5. data in image structures in memory is kept in network byteorder.
- * 6. the functions in this file only deal with 32 bit and smaller data
- * in host byteorder form.
- */
-
-static int
-fwflash_ib_i_check_handle(fwflash_ib_hdl_t *handle)
-{
- if ((handle == NULL) || (handle->magic != FWFLASH_IB_MAGIC_NUMBER)) {
- return (-1);
- }
- return (0);
-}
-
-static int
-fwflash_ib_i_num_sectors(fwflash_ib_hdl_t *handle, int size)
-{
- int num_sectors;
- int mod;
-
- num_sectors = size / handle->sector_sz;
- mod = size % handle->sector_sz;
-
- if (mod > 0) {
- num_sectors++;
- }
- return (num_sectors);
-}
-
-static int
-fwflash_ib_i_read_file(FILE *fp, int len, void *buf)
-{
- uint32_t *bg;
- int ret;
- int i;
-
- bg = (uint32_t *)buf;
-
- for (i = 0; i < len / 4; i++) {
- ret = fread(&bg[i], 4, 1, fp);
- if (ret == 0) {
- if (feof(fp) != 0) {
- break;
- } else {
- return (ferror(fp));
- }
- }
- }
- return (0);
-}
-
-static int
-fwflash_ib_i_local_verify(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- int ret;
-
- ret = fwflash_ib_i_local_verify_signature(handle, offset);
- if (ret != 0) {
- return (ret);
- }
-
- ret = fwflash_ib_i_local_verify_vsd(handle, offset);
- if (ret != 0) {
- return (ret);
- }
-
- ret = fwflash_ib_i_local_verify_xps_crc(handle, offset);
- return (ret);
-}
-
-static int
-fwflash_ib_i_flash_verify_signature(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- tavor_flash_ioctl_t ioctl_info;
- int ret;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_verify_signature\n"));
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = offset + FLASH_PS_SIGNATURE_OFFSET;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read sig\n"));
- goto out;
- }
-
- DPRINTF(DBG_INFO, ("local_quadlet: %08x, ps_signature: %08x\n",
- ioctl_info.tf_quadlet, FLASH_PS_SIGNATURE));
-
- if (ioctl_info.tf_quadlet != FLASH_PS_SIGNATURE) {
- DPRINTF(DBG_ERR, ("flash signature compare failed.\n"));
- ret = -1;
- }
-out:
- return (ret);
-}
-
-/*
- * We would not need this if it were not for Cisco's image using the
- * VSD to store boot options and flags for their PXE boot extension,
- * but not setting the proper default values for the extension in
- * their image. As it turns out, some of the data for the extension
- * is stored in the VSD in the firmware file, and the rest is set by
- * their firmware utility. That's not very nice for us, since it could
- * change at any time without our knowledge. Well, for the time being,
- * we can use this to examine and fix up anything in the VSD that we might
- * need to handle, for any vendor specific settings.
- */
-static int
-fwflash_ib_i_local_verify_vsd(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- vsd_t vsd;
- uint32_t addr;
- uint16_t vsd_sig1;
- uint16_t vsd_sig2;
- int i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_local_verify_vsd\n"));
- DPRINTF(DBG_INFO, ("verifying vsd in PS at offset 0x%x\n", offset));
- /* read the VSD into local storage */
- addr = offset + FLASH_PS_VSD_OFFSET;
- for (i = 0; i < FLASH_PS_VSD_LENGTH / 4; i++) {
- vsd.vsd_int[i] = (uint32_t)ntohl(handle->fw[(addr / 4) + i]);
- }
-
- /* check for the Cisco signature at the first and last 16b */
- vsd_sig1 = (uint16_t)(vsd.vsd_int[0] >> 16);
- vsd_sig2 = (uint16_t)vsd.vsd_int[(FLASH_PS_VSD_LENGTH / 4) - 1];
-
- if (vsd_sig1 == FLASH_VSD_CISCO_SIGNATURE &&
- vsd_sig2 == FLASH_VSD_CISCO_SIGNATURE) {
-
- DPRINTF(DBG_INFO, ("VSD contains Cisco signatures\n"));
-
- /*
- * Fix up this VSD so that it contains the proper
- * default values for the Cisco, nee Topspin, boot
- * extension(s)
- */
-
- /*
- * Set the Cisco VSD's "boot_version" to '2'. This value is
- * located in the 2nd byte of the last dword. Just or the bit
- * in and move on.
- */
- handle->fw[(addr / 4) + ((FLASH_PS_VSD_LENGTH - 1) / 4)] =
- htonl(vsd.vsd_int[(FLASH_PS_VSD_LENGTH / 4) - 1] |
- 0x00020000);
-
- /*
- * Set some defaults for the SRP boot extension. This is
- * currently the only extension we support. The boot options
- * flags are located in the second dword of the VSD.
- */
- DPRINTF(DBG_INFO, ("boot flags in Cisco image currently "
- "set to 0x%08x\n", vsd.vsd_int[1]));
-
- handle->fw[(addr / 4) + 1] = htonl(vsd.vsd_int[1] |
- FLASH_VSD_CISCO_FLAG_AUTOUPGRADE |
- FLASH_VSD_CISCO_BOOT_OPTIONS |
- FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_PORT_1 |
- FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_PORT_2 |
- FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_SCAN |
- FLASH_VSD_CISCO_FLAG_BOOT_TYPE_WELL_KNOWN |
- FLASH_VSD_CISCO_FLAG_BOOT_TRY_FOREVER);
-
- DPRINTF(DBG_INFO, ("boot flags now set to 0x%08x\n",
- ntohl(handle->fw[(addr / 4) + 1])));
-
- /* Set updated PS CRC */
- fwflash_ib_i_local_set_xps_crc(handle, offset);
- }
-
- return (0);
-}
-
-static int
-fwflash_ib_i_local_verify_signature(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint32_t addr;
-
- addr = offset + FLASH_PS_SIGNATURE_OFFSET;
-
- if (ntohl(handle->fw[addr / 4]) != FLASH_PS_SIGNATURE) {
- return (-1);
- }
- return (0);
-}
-
-static int
-fwflash_ib_i_flash_zero_signature(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- tavor_flash_ioctl_t ioctl_info;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_zero_signature\n"));
- for (i = 0; i < 4; i++) {
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_BYTE;
- ioctl_info.tf_addr = offset + FLASH_PS_SIGNATURE_OFFSET + i;
- ioctl_info.tf_byte = 0;
-
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to write sig\n"));
- return (ret);
- }
- }
- return (0);
-}
-
-/*
- * Due to calling convention, handle->fw is in network byte order.
- * CRC must be calculated on bytes in network byte order.
- *
- * Yet when compared, they are compared in host byteorder. Since the crc16
- * function returns host byteorder.
- */
-
-static int
-fwflash_ib_i_local_verify_xps_crc(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint16_t crc;
- uint16_t local_crc;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_local_verify_xps_crc\n"));
- crc = (crc16((uint8_t *)&handle->fw[offset / 4], FLASH_PS_CRC16_SIZE));
-
- local_crc = (uint16_t)(ntohl(handle->fw[(offset +
- FLASH_PS_CRC16_OFFSET) /4]));
-
- DPRINTF(DBG_INFO, ("local crc: 0x%x calc crc: 0x%x\n", local_crc, crc));
-
- if (crc != local_crc) {
- DPRINTF(DBG_ERR, ("\nFailed to verify crc\n"));
- return (-1);
- }
- return (0);
-}
-
-static void
-fwflash_ib_i_local_set_xps_crc(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint16_t crc;
- uint8_t *fw_p = (uint8_t *)&handle->fw[0];
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_local_set_xps_crc\n"));
- crc = htons(crc16((uint8_t *)&handle->fw[offset / 4],
- FLASH_PS_CRC16_SIZE));
-
- DPRINTF(DBG_INFO, ("set local xps crc: %x\n", ntohs(crc)));
- (void) memcpy(&fw_p[offset + FLASH_PS_CRC16_OFFSET], &crc, 2);
-}
-
-static int
-fwflash_ib_i_flash_set_xps_crc(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint16_t crc;
- uint8_t *crc_p = (uint8_t *)&crc;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_set_xps_crc\n"));
- crc = htons(crc16((uint8_t *)&handle->fw[offset / 4],
- FLASH_PS_CRC16_SIZE));
-
- DPRINTF(DBG_INFO, ("set flash xps crc: %x\n", ntohs(crc)));
- for (i = 0; i < 2; i++) {
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_BYTE;
- ioctl_info.tf_addr = offset + FLASH_PS_CRC16_OFFSET + i;
- ioctl_info.tf_byte = crc_p[i];
-
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to write crc (0x%x)\n", i));
- return (ret);
- }
- }
- return (0);
-}
-
-static uint32_t
-fwflash_ib_i_flash_get_sect_size(fwflash_ib_hdl_t *handle)
-{
- tavor_flash_ioctl_t ioctl_info;
- int ret;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_get_sect_size\n"));
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = FLASH_IS_SECT_SIZE_PTR;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read size\n"));
- return (ret);
- }
-
- DPRINTF(DBG_INFO, ("sect size ptr: 0x%x\n", ioctl_info.tf_quadlet));
-
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = ioctl_info.tf_quadlet +
- FLASH_IS_SECTOR_SIZE_OFFSET;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read size\n"));
- return (ret);
- }
-
-#ifdef DEBUG
- {
- uint8_t *byte;
- int i;
-
- byte = (uint8_t *)&ioctl_info.tf_quadlet;
- DPRINTF(DBG_INFO, ("sect size quadlet: %x\n", ioctl_info.tf_quadlet));
- for (i = 0; i < 4; i++)
- DPRINTF(DBG_INFO, ("sect size[%d]: %x\n", i, byte[i]));
- }
-#endif /* DEBUG */
- return (ioctl_info.tf_quadlet & FLASH_IS_SECTOR_SIZE_MASK);
-}
-
-static uint32_t
-fwflash_ib_i_local_get_sect_size(fwflash_ib_hdl_t *handle)
-{
- uint32_t size;
- int offset;
-
- offset = FLASH_IS_SECTOR_SIZE_OFFSET +
- ntohl(handle->fw[FLASH_IS_SECT_SIZE_PTR / 4]);
-
- if (offset > handle->device_sz) {
- DPRINTF(DBG_INFO, ("offset too large: %x\n", offset));
- return (0);
- }
- size = ntohl(handle->fw[offset / 4]);
-
- return (size & FLASH_IS_SECTOR_SIZE_MASK);
-}
-
-static int
-fwflash_ib_i_flash_verify_is(fwflash_ib_hdl_t *handle)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t *flash;
- int sector_size;
- int ps_offset;
- int ret, i;
-#ifdef _LITTLE_ENDIAN
- uint32_t *ptr;
-#endif
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_verify_is\n"));
- if ((handle->state & FWFLASH_IB_STATE_PFI_IMAGE) == 0 &&
- (handle->state & FWFLASH_IB_STATE_SFI_IMAGE) == 0) {
- DPRINTF(DBG_ERR, ("\nMust read in an image first\n"));
- ret = -1;
- goto out;
- }
-
- /* Get Sector Size */
- sector_size = fwflash_ib_i_local_get_sect_size(handle);
-
- /* Get offset to pointer sector based on type */
- ps_offset = 1 << sector_size;
-
- flash = (uint32_t *)malloc(handle->device_sz);
- if (flash == NULL) {
- DPRINTF(DBG_ERR, ("\nmalloc failed (0x%x)\n", errno));
- ret = -1;
- goto out;
- }
-
- /* Read IS sector */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- ioctl_info.tf_sector_num = 0;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(&flash[0], 0, sector_size);
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read IS\n"));
- goto out;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (i = 0; i < (1 << sector_size)/4; i ++) {
- ptr[i] = htonl(ptr[i]);
- }
-#endif
-
- /* Compare IS */
- for (i = 0; i < (ps_offset / 4); i++) {
- if (flash[i] != handle->fw[i]) {
- DPRINTF(DBG_ERR, ("\nVerify IS failed at offset: %d\n",
- i));
- DPRINTF(DBG_ERR, ("expected: 0x%X, actual: 0x%X\n",
- handle->fw[i], flash[i]));
- ret = -1;
- break;
- }
- }
-out:
- if (flash != NULL) {
- free(flash);
- }
- return (ret);
-}
-
-static int
-fwflash_ib_i_flash_verify_flash_info(fwflash_ib_hdl_t *handle, uint32_t size)
-{
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_verify_flash_info\n"));
- if (handle->sector_sz != (1 << size)) {
- DPRINTF(DBG_ERR, ("Sector size values didn't match. "
- "Expected: 0x%08x, actual: 0x%08x.\n",
- handle->sector_sz, 1 << size));
- return (1);
- }
- return (0);
-}
-
-static uchar_t *
-fwflash_ib_i_flash_get_psid(fwflash_ib_hdl_t *handle, int offset)
-{
- int i;
- uchar_t *psid_str;
-#ifndef _LITTLE_ENDIAN
- uint32_t data32;
-#endif /* _LITTLE_ENDIAN */
- union {
- uchar_t psid_char[FWFLASH_PSID_SZ];
- uint32_t psid_int[FWFLASH_PSID_SZ/4];
- } psid;
-
- for (i = 0; i < FWFLASH_PSID_SZ/4; i++) {
- psid.psid_int[i] = (uint32_t)ntohl(handle->fw[(offset +
- FLASH_PS_PSID_OFFSET) / 4 + i]);
-#ifndef _LITTLE_ENDIAN
- data32 = psid.psid_int[i];
- psid.psid_char[i << 2] =
- (uchar_t)(data32 & 0x000000ff);
- psid.psid_char[(i << 2) + 1] =
- (uchar_t)((data32 & 0x0000ff00) >> 8);
- psid.psid_char[(i << 2) + 2] =
- (uchar_t)((data32 & 0x00ff0000) >> 16);
- psid.psid_char[(i << 2) + 3] =
- (uchar_t)((data32 & 0xff000000) >> 24);
-#endif /* _LITTLE_ENDIAN */
- }
-
- psid_str = malloc(FWFLASH_PSID_SZ);
- if (psid_str == NULL) {
- DPRINTF(DBG_ERR, ("\nmalloc failed (0x%x)\n", errno));
- goto out;
- }
-
- (void) memcpy(psid_str, (const uchar_t *)psid.psid_char,
- FWFLASH_PSID_SZ);
-out:
- return (psid_str);
-}
-
-static void
-fwflash_ib_i_flash_verify_flash_match(fwflash_ib_hdl_t *handle, int offset,
- int type)
-{
- uchar_t *psid;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_verify_flash_match\n"));
- /* get PSID of firmware file */
- psid = fwflash_ib_i_flash_get_psid(handle, offset);
- if (psid == NULL) {
- handle->hwfw_match = 0;
- handle->pn_len = 0;
- return;
- }
- DPRINTF(DBG_INFO, ("FW PSID (%s)\n", psid));
-
- /*
- * Check the part number of the hardware against the part number
- * of the firmware file. If the hardware information is not
- * available, check the currently loaded firmware against the
- * firmware file to be uploaded.
- */
- if (handle->pn_len != 0) {
- fwflash_ib_i_flash_verify_flash_pn(handle, psid,
- FWFLASH_PSID_SZ, type);
- } else {
- DPRINTF(DBG_ERR, ("No VPD data available for HW\n"));
- fwflash_ib_i_flash_verify_flash_fwpsid(handle, psid,
- FWFLASH_PSID_SZ);
- }
- free(psid);
-}
-
-static void
-fwflash_ib_i_flash_verify_flash_pn(fwflash_ib_hdl_t *handle, uchar_t *psid,
- int psid_size, int type)
-{
- int i;
- int no_match = 0;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_verify_flash_pn\n"));
- /* verify fw matches the hardware */
- if (handle->hwfw_match == 1) {
- /* already been verified */
- return;
- }
-
- /* find the PSID from FW in the mlx table */
- for (i = 0; i < FWFLASH_MAX_ID; i++) {
- if (handle->hwfw_match == 1) {
- /*
- * Need this check here and the 'continue's below
- * becasue there are some cards that have a
- * 'new' part number but the same PSID value.
- */
- break;
- }
- DPRINTF(DBG_INFO, ("psid (%s) mlx_psid (%s)\n",
- psid, mlx_mdr[i].mlx_psid));
-
- /* match PSID */
- if (strncmp((const char *)psid, mlx_mdr[i].mlx_psid,
- psid_size) == 0) {
- DPRINTF(DBG_INFO, ("FW PSID (%s) MDR/HW PSID (%s) "
- "FW PN (%s) MDR/HW PN (%s)\n",
- psid, mlx_mdr[i].mlx_psid,
- handle->info.mlx_pn, mlx_mdr[i].mlx_pn));
-
- /* match part numbers */
- if (strncmp(handle->info.mlx_pn, mlx_mdr[i].mlx_pn,
- handle->pn_len) == 0) {
- handle->hwfw_match = 1;
- continue;
- } else {
- handle->hwfw_match = 0;
- no_match = i;
- continue;
- }
- }
- }
- if (i == FWFLASH_MAX_ID && no_match == 0) {
- /* no match found */
- handle->hwfw_match = 0;
- handle->pn_len = 0;
- DPRINTF(DBG_ERR, ("No PSID match found\n"));
- } else {
- if (handle->hwfw_match == 0) {
- (void) fprintf(stderr, "\t");
- (void) fprintf(stderr, gettext("WARNING"));
- (void) fprintf(stderr, ": %s",
- type == 1 ? " Primary " : " Secondary ");
- (void) fprintf(stderr, gettext(
- "firmware image is meant for"));
- (void) fprintf(stderr, " %s ",
- mlx_mdr[no_match].mlx_pn);
- (void) fprintf(stderr, "\n\t");
- (void) fprintf(stderr, gettext("but the harware is"));
- (void) fprintf(stderr, " %s\n",
- handle->info.mlx_pn);
- }
- }
-}
-
-static void
-fwflash_ib_i_flash_verify_flash_fwpsid(fwflash_ib_hdl_t *handle,
- uchar_t *psid, int psid_size)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t sector_size;
- uint32_t device_size;
- int ps_offset;
- int ret, i;
- fwflash_ib_hdl_t *hdl;
- uchar_t *hw_psid;
-#ifdef _LITTLE_ENDIAN
- int j;
- uint32_t *ptr;
-#endif
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_verify_flash_fwpsid\n"));
- /* Get Sector Size */
- sector_size = fwflash_ib_i_flash_get_sect_size(handle);
- DPRINTF(DBG_INFO, ("sector_size: 0x%x\n", sector_size));
-
- /* get device size */
- device_size = handle->device_sz;
- DPRINTF(DBG_INFO, ("device_size: 0x%x\n", device_size));
-
- /* allocate some space */
- hdl = malloc(sizeof (fwflash_ib_hdl_t));
- hdl->fw = malloc(device_size);
-
- /* Look for PSID in PPS first, then SPS if no match */
- for (i = 1; i < 3; i++) {
- ps_offset = i << sector_size;
-
- DPRINTF(DBG_INFO, ("type: 0x%x\n", i));
- DPRINTF(DBG_INFO, ("ps_offset: 0x%x\n", ps_offset));
-
- /* Read in xPS */
- ioctl_info.tf_type = TAVOR_FLASH_READ_SECTOR;
- ioctl_info.tf_sector_num = i;
- ioctl_info.tf_sector = FLASH_SECTOR_OFFSET(hdl->fw, i,
- sector_size);
- hdl->fd = handle->fd;
- ret = fwflash_read_ioctl(hdl, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read PS\n"));
- handle->hwfw_match = 0;
- return;
- }
-#ifdef _LITTLE_ENDIAN
- /* swap sector contents into network byte order form */
- ptr = (uint32_t *)(uintptr_t)ioctl_info.tf_sector;
- for (j = 0; j < (1 << sector_size)/4; j++) {
- ptr[j] = htonl(ptr[j]);
- }
-#endif
- /* grab PSID from xPS */
- hw_psid = fwflash_ib_i_flash_get_psid(hdl, ps_offset);
- if (hw_psid == NULL) {
- handle->hwfw_match = 0;
- handle->pn_len = 0;
- return;
- }
- DPRINTF(DBG_INFO, ("%s PSID (%s) file PSID (%s)\n",
- i == 1 ? "Primary" : "Secondary",
- hw_psid, psid));
-
- /* compare PSIDs */
- if (strncmp((const char *)psid, (const char *)hw_psid,
- psid_size) == 0) {
- handle->hwfw_match = 1;
- break;
- } else {
- handle->hwfw_match = 0;
- }
- }
- free(hdl->fw);
- free(hdl);
- free(hw_psid);
-}
-
-static uint16_t
-fwflash_ib_i_check_hwver(fwflash_ib_hdl_t *handle)
-{
- uint8_t hwver;
- uint8_t local_hwver;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_check_hwver\n"));
- if ((handle->state & FWFLASH_IB_STATE_PFI_IMAGE) == 0 &&
- (handle->state & FWFLASH_IB_STATE_SFI_IMAGE) == 0) {
- DPRINTF(DBG_ERR, ("\nMust read in image first\n"));
- return (1);
- }
-
- /* Read Flash HW Version */
- hwver = (uint8_t)handle->hwrev;
- local_hwver = (ntohl(handle->fw[FLASH_IS_HWVER_OFFSET / 4]) &
- FLASH_IS_HWVER_MASK) >> 24;
-
- DPRINTF(DBG_INFO, ("local_hwver: %x, hwver: %x\n", local_hwver, hwver));
-
- if ((hwver == 0xA0 || hwver == 0x00 || hwver == 0x20) &&
- (local_hwver == 0x00 || local_hwver == 0xA0 ||
- local_hwver == 0x20)) {
- DPRINTF(DBG_INFO, ("A0 board found.\r\n"));
- } else if (hwver == 0xA1 && local_hwver == 0xA1) {
- DPRINTF(DBG_INFO, ("A1 board found.\r\n"));
- } else if (hwver == 0xA2 && local_hwver == 0xA2) {
- DPRINTF(DBG_INFO, ("A2 board found.\r\n"));
- } else if (hwver == 0xA3 && local_hwver == 0xA3) {
- DPRINTF(DBG_INFO, ("A3 board found.\r\n"));
- } else {
- return ((uint16_t)(local_hwver << 8) | hwver);
- }
- return (0);
-}
-
-static void
-fwflash_ib_i_local_zero_crc(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint8_t *image = (uint8_t *)&handle->fw[0];
-
- image[offset + FLASH_PS_CRC16_OFFSET] = 0xFF;
- image[offset + FLASH_PS_CRC16_OFFSET + 1] = 0xFF;
-}
-
-static int
-fwflash_ib_i_flash_zero_crc(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- tavor_flash_ioctl_t ioctl_info;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_zero_crc\n"));
- for (i = 0; i < 2; i++) {
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_BYTE;
- ioctl_info.tf_addr = offset + FLASH_PS_CRC16_OFFSET + i;
- ioctl_info.tf_byte = 0;
-
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to zero crc (%d)\n", i));
- return (ret);
- }
- }
- return (0);
-}
-
-static uint32_t
-fwflash_ib_i_local_get_fw_size(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint32_t size;
-
- size = ntohl(handle->fw[(offset + FLASH_PS_FW_SIZE_OFFSET) / 4]);
- return (size);
-}
-
-static uint32_t
-fwflash_ib_i_local_get_fw_addr(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint32_t addr;
-
- addr = ntohl(handle->fw[(offset + FLASH_PS_FI_ADDR_OFFSET) / 4]);
- return (addr);
-}
-
-static uint32_t
-fwflash_ib_i_flash_get_fw_addr(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- tavor_flash_ioctl_t ioctl_info;
- int ret;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_get_fw_addr\n"));
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = offset + FLASH_PS_FI_ADDR_OFFSET;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read addr\n"));
- return (ret);
- }
- return (ioctl_info.tf_quadlet);
-}
-
-static int
-fwflash_ib_i_flash_set_fw_addr(fwflash_ib_hdl_t *handle, uint32_t offset,
- uint32_t addr)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t fw_addr = htonl(addr);
- uint8_t *fw_addrp = (uint8_t *)&fw_addr;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_set_fw_addr\n"));
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_BYTE;
- for (i = 0; i < 4; i++) {
- ioctl_info.tf_addr = offset + FLASH_PS_FI_ADDR_OFFSET + i;
- ioctl_info.tf_byte = fw_addrp[i];
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set fw addr\n"));
- return (ret);
- }
- }
- return (0);
-}
-
-static int
-fwflash_ib_i_flash_set_signature(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t signature = (uint32_t)htonl(FLASH_PS_SIGNATURE);
- uint8_t *signaturep = (uint8_t *)&signature;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_set_signature\n"));
- DPRINTF(DBG_INFO, ("flash set sig: %x\n", ntohl(signature)));
- ioctl_info.tf_type = TAVOR_FLASH_WRITE_BYTE;
- for (i = 0; i < 4; i++) {
- ioctl_info.tf_addr = offset + FLASH_PS_SIGNATURE_OFFSET + i;
- ioctl_info.tf_byte = signaturep[i];
- ret = fwflash_write_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to set sig\n"));
- return (ret);
- }
- }
- return (0);
-}
-
-static int
-fwflash_ib_i_flash_read_guids(fwflash_ib_hdl_t *handle, void *buf, int type)
-{
- tavor_flash_ioctl_t ioctl_info;
- uint32_t *guids;
- uint32_t fw_addr;
- uint32_t guid_ptr;
- int start_addr;
- int sector_size;
- int ps_offset;
- int ret, i;
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_flash_read_guids\n"));
- /* Read Sector Size */
- sector_size = fwflash_ib_i_flash_get_sect_size(handle);
-
- /* offset is the start of the xPS sector */
- /* 'type' is the sector number input as PPS or SPS */
- ps_offset = type << sector_size;
-
- ret = fwflash_ib_i_flash_verify_signature(handle, ps_offset);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to verify signature\n"));
- return (ret);
- }
-
- fw_addr = fwflash_ib_i_flash_get_fw_addr(handle, ps_offset);
-
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ioctl_info.tf_addr = fw_addr + FLASH_GUID_PTR;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read fw_addr\n"));
- return (ret);
- }
-
- guid_ptr = ioctl_info.tf_quadlet;
- guids = (uint32_t *)buf;
- start_addr = fw_addr + guid_ptr + FLASH_FI_NGUID_OFFSET;
-
- ioctl_info.tf_addr = start_addr;
- for (i = 0; i < 8; i++) {
- ioctl_info.tf_type = TAVOR_FLASH_READ_QUADLET;
- ret = fwflash_read_ioctl(handle, &ioctl_info);
- if (ret != 0) {
- DPRINTF(DBG_ERR, ("\nFailed to read guid (0x%x)\n", i));
- return (ret);
- }
-
- guids[i] = ioctl_info.tf_quadlet;
- ioctl_info.tf_addr += 4;
- }
-
- return (0);
-}
-
-static void
-fwflash_ib_i_local_set_guid_crc(fwflash_ib_hdl_t *handle, uint32_t offset)
-{
- uint16_t crc;
- uint8_t *fw_p = (uint8_t *)&handle->fw[0];
-
- DPRINTF(DBG_INFO, ("fwflash_ib_i_local_set_guid_crc\n"));
- crc = htons(crc16((uint8_t *)&handle->fw[offset / 4],
- FLASH_GUID_CRC16_SIZE));
-
- DPRINTF(DBG_INFO, ("local crc guid: %x\n", ntohs(crc)));
- (void) memcpy(&fw_p[offset + FLASH_GUID_CRC16_OFFSET], &crc, 2);
-}
-
-/*
- * crc16 - computes 16 bit crc of supplied buffer.
- * image should be in network byteorder
- * result is returned in host byteorder form
- */
-static uint16_t
-crc16(uint8_t *image, uint32_t size)
-{
- const uint16_t poly = 0x100b;
- uint32_t crc = 0xFFFF;
- uint32_t word;
- uint32_t i, j;
-
- for (i = 0; i < size / 4; i++) {
- word = (image[4 * i] << 24) |
- (image[4 * i + 1] << 16) |
- (image[4 * i + 2] << 8) |
- (image[4 * i + 3]);
-
- for (j = 0; j < 32; j++) {
- if (crc & 0x8000) {
- crc = (((crc << 1) |
- (word >> 31)) ^ poly) & 0xFFFF;
- } else {
- crc = ((crc << 1) | (word >> 31)) & 0xFFFF;
- }
- word = (word << 1) & 0xFFFFFFFF;
- }
- }
-
- for (i = 0; i < 16; i++) {
- if (crc & 0x8000) {
- crc = ((crc << 1) ^ poly) & 0xFFFF;
- } else {
- crc = (crc << 1) & 0xFFFF;
- }
- }
-
- crc = crc ^ 0xFFFF;
- return (crc & 0xFFFF);
-}
diff --git a/usr/src/cmd/fwflash/fwflash_ib.h b/usr/src/cmd/fwflash/fwflash_ib.h
deleted file mode 100644
index 963fa0ebbd..0000000000
--- a/usr/src/cmd/fwflash/fwflash_ib.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _FWFLASH_IB_H
-#define _FWFLASH_IB_H
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * fwflash_ib.h
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <sys/types.h>
-#include <sys/ib/adapters/tavor/tavor_ioctl.h>
-
-#define FWFLASH_IB_DRIVER_NAME "tavor"
-#define FWFLASH_IB_MAGIC_NUMBER 0xF00B0021
-
-#define NODE_GUID_OFFSET 0x0
-#define PORT1_GUID_OFFSET 0x08
-#define PORT2_GUID_OFFSET 0x10
-#define FLASH_SIZE_OFFSET 0x20
-#define FLASH_GUID_PTR 0x24
-
-#define FWFLASH_IB_STATE_NONE 0x00
-#define FWFLASH_IB_STATE_IMAGE 0x01
-#define FWFLASH_IB_STATE_MMAP 0x04
-#define FWFLASH_IB_STATE_GUIDN 0x10
-#define FWFLASH_IB_STATE_GUID1 0x20
-#define FWFLASH_IB_STATE_GUID2 0x40
-#define FWFLASH_IB_STATE_GUIDS 0x80
-
-#define FWFLASH_IB_STATE_PFI_IMAGE 0x1
-#define FWFLASH_IB_STATE_SFI_IMAGE 0x2
-#define FWFLASH_IB_PRIMARY_IMAGE FWFLASH_IB_STATE_PFI_IMAGE
-#define FWFLASH_IB_SECONDARY_IMAGE FWFLASH_IB_STATE_SFI_IMAGE
-
-
-/*
- * Structure to hold the part number, PSID, and string ID
- * for an HCA card.
- */
-typedef struct mlx_mdr_s {
- char *mlx_pn;
- char *mlx_psid;
- char *mlx_id;
-} mlx_mdr_t;
-
-typedef struct fw_rev_s {
- uint32_t major:16;
- uint32_t minor:16;
- uint32_t subminor:16;
- uint32_t holder:16;
-} fw_rev_t;
-
-typedef struct fwflash_ib_hdl_s {
- uint_t magic;
- int fd;
- fw_rev_t fw_rev;
- char *dev_path;
- uint32_t *fw;
- uint32_t hwrev;
- uint32_t sector_sz;
- uint32_t device_sz;
- uint32_t state;
- int cmd_set;
- mlx_mdr_t info;
- int pn_len;
- int hwfw_match;
-} fwflash_ib_hdl_t;
-
-/* IB Specific functions */
-char ** fwflash_ib_device_list(int *count);
-fwflash_ib_hdl_t *fwflash_ib_open(char *dev_path);
-void fwflash_ib_close(fwflash_ib_hdl_t *handle);
-int fwflash_ib_read_file(fwflash_ib_hdl_t *handle, const char *filename);
-
-int fwflash_read_ioctl(fwflash_ib_hdl_t *hdl, tavor_flash_ioctl_t *ioctl_info);
-int fwflash_write_ioctl(fwflash_ib_hdl_t *hdl, tavor_flash_ioctl_t *ioctl_info);
-
-int fwflash_ib_write_is(fwflash_ib_hdl_t *handle);
-int fwflash_ib_write_image(fwflash_ib_hdl_t *handle, int type);
-int fwflash_ib_verify_image(fwflash_ib_hdl_t *handle, int type);
-int fwflash_ib_read_image(fwflash_ib_hdl_t *handle, int type);
-int fwflash_ib_write_file(fwflash_ib_hdl_t *handle, const char *filename);
-int fwflash_ib_set_guids(fwflash_ib_hdl_t *handle, void *guids, int type);
-int fwflash_ib_flash_read_guids(fwflash_ib_hdl_t *handle, void *guids,
- int type);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _FWFLASH_IB_H */
diff --git a/usr/src/cmd/fwflash/fwflash_ib_impl.h b/usr/src/cmd/fwflash/fwflash_ib_impl.h
deleted file mode 100644
index e2a0196974..0000000000
--- a/usr/src/cmd/fwflash/fwflash_ib_impl.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _FWFLASH_IB_IMPL_H
-#define _FWFLASH_IB_IMPL_H
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * fwflash_ib_impl.h
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define FLASH_PS_SIGNATURE 0x5a445a44
-
-#define FLASH_IS_SECTOR_SIZE_OFFSET 0x30
-#define FLASH_IS_SECTOR_SIZE_MASK 0x0000FFFF
-#define FLASH_IS_HWVER_OFFSET 0x10
-#define FLASH_IS_HWVER_MASK 0xFF000000
-#define FLASH_IS_ISVER_MASK 0x00FF0000
-
-#define FLASH_IS_SECT_SIZE_PTR 0x16
-#define FLASH_IS_SECT_SIZE_PTR_MASK 0x0000FFFF
-
-#define FLASH_PS_FI_ADDR_OFFSET 0x00
-#define FLASH_PS_FW_SIZE_OFFSET 0x04
-#define FLASH_PS_SIGNATURE_OFFSET 0x08
-/* Vendor Specific Data (VSD) */
-#define FLASH_PS_VSD_OFFSET 0x20
-/* VSD length in bytes */
-#define FLASH_PS_VSD_LENGTH 0xe0
-/* PSID is the last 16B of VSD */
-#define FLASH_PS_PSID_OFFSET 0xf0
-
-/* For use with Cisco's VSD */
-#define FLASH_VSD_CISCO_SIGNATURE 0x05ad
-#define FLASH_VSD_CISCO_BOOT_OPTIONS 0x00000004
-#define FLASH_VSD_CISCO_FLAG_AUTOUPGRADE 0x01000000
-#define FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_PORT_1 0x00010000
-#define FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_PORT_2 0x00020000
-#define FLASH_VSD_CISCO_FLAG_BOOT_ENABLE_SCAN 0x00040000
-#define FLASH_VSD_CISCO_FLAG_BOOT_TYPE_WELL_KNOWN 0x00000000
-#define FLASH_VSD_CISCO_FLAG_BOOT_TRY_FOREVER 0x00001000
-#define FLASH_VSD_CISCO_BOOT_VERSION 2
-/* For use with Cisco's VSD */
-
-#define FLASH_PS_CRC16_SIZE 0x104
-#define FLASH_PS_CRC16_OFFSET 0x106
-
-#define FLASH_FI_NGUID_OFFSET 0x0
-#define FLASH_FI_P1GUID_OFFSET 0x08
-#define FLASH_FI_P2GUID_OFFSET 0x10
-#define FLASH_FI_SYSIMGUID_OFFSET 0x18
-#define FLASH_GUID_CRC16_SIZE 0x30
-#define FLASH_GUID_CRC16_OFFSET 0x32
-#define FLASH_GUID_SIZE 0x34
-
-/*
- * Used during read/write ioctl calls to setup the offset into the firmware
- * image memory for that particular sector.
- */
-#define FLASH_SECTOR_OFFSET(fw, sect, sz) \
- (caddr_t)((uintptr_t)fw + (sect << sz))
-
-/*
- * Vital System Data from PCI config space.
- */
-typedef union vsd_u {
- uchar_t vsd_char[FLASH_PS_VSD_LENGTH];
- uint32_t vsd_int[FLASH_PS_VSD_LENGTH / 4];
-} vsd_t;
-
-/*
- * Common Flash Interface data.
- */
-typedef union cfi_u {
- uchar_t cfi_char[TAVOR_FLASH_CFI_SIZE];
- uint32_t cfi_int[TAVOR_FLASH_CFI_SIZE_QUADLET];
-} cfi_t;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _FWFLASH_IB_IMPL_H */
diff --git a/usr/src/cmd/fwflash/fwflash_mlx.h b/usr/src/cmd/fwflash/fwflash_mlx.h
deleted file mode 100644
index ba4077378f..0000000000
--- a/usr/src/cmd/fwflash/fwflash_mlx.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _FWFLASH_MLX_H
-#define _FWFLASH_MLX_H
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * fwflash_mlx.h
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "fwflash_ib.h"
-
-/*
- * Magic decoder ring for matching HCA hardware/firmware.
- * Part Number / PSID / String ID
- */
-mlx_mdr_t mlx_mdr[] = {
- /* Part No PSID Card ID */
- { "MHEA28-XS", "MT_0250000001", "Lion mini" },
- { "MHEA28-XSC", "MT_0390110001", "Lion mini" },
- { "MHEA28-XT", "MT_0150000001", "Lion mini" },
- { "MHEA28-XTC", "MT_0370110001", "Lion mini" },
- { "MHGA28-XT", "MT_0150000002", "Lion mini" },
- { "MHGA28-XTC", "MT_0370110002", "Lion mini" },
- { "MHGA28-XTC", "MT_0370130002", "Lion mini" },
- { "MHGA28-XS", "MT_0250000002", "Lion mini" },
- { "MHGA28-XSC", "MT_0390110002", "Lion mini" },
- { "MHGA28-XSC", "MT_0390130002", "Lion mini" },
- { "MHEL-CF128", "MT_0190000001", "Lion cub" },
- { "MHEL-CF128-T", "MT_00A0000001", "Lion cub" },
- { "MTLP25208-CF128T", "MT_00A0000001", "Lion cub" },
- { "MHEL-CF128-TC", "MT_00A0010001", "Lion cub" },
- { "MHEL-CF128-TC", "MT_0140010001", "Lion cub" },
- { "MHEL-CF128-SC", "MT_0190010001", "Lion cub" },
- { "MHEA28-1TC", "MT_02F0110001", "Lion cub" },
- { "MHEA28-1SC", "MT_0330110001", "Lion cub" },
- { "MHGA28-1T", "MT_0200000001", "Lion cub" },
- { "MHGA28-1TC", "MT_02F0110002", "Lion cub" },
- { "MHGA28-1SC", "MT_0330110002", "Lion cub" },
- { "MHGA28-1S", "MT_0430000001", "Lion cub" },
- { "MHEL-CF256-T", "MT_00B0000001", "Lion cub" },
- { "MTLP25208-CF256T", "MT_00B0000001", "Lion cub" },
- { "MHEL-CF256-TC", "MT_00B0010001", "Lion cub" },
- { "MHEA28-2TC", "MT_0300110001", "Lion cub" },
- { "MHEA28-2SC", "MT_0340110001", "Lion cub" },
- { "MHGA28-2T", "MT_0210000001", "Lion cub" },
- { "MHGA28-2TC", "MT_0300110002", "Lion cub" },
- { "MHGA28-2SC", "MT_0340110002", "Lion cub" },
- { "MHEL-CF512-T", "MT_00C0000001", "Lion cub" },
- { "MTLP25208-CF512T", "MT_00C0000001", "Lion cub" },
- { "MHGA28-5T", "MT_0220000001", "Lion cub" },
- { "MHES14-XSC", "MT_0410110001", "Tiger" },
- { "MHES14-XT", "MT_01F0000001", "Tiger" },
- { "MHES14-XTC", "MT_03F0110001", "Tiger" },
- { "MHES18-XS", "MT_0260000001", "Cheetah" },
- { "MHES18-XS", "MT_0260010001", "Cheetah" },
- { "MHES18-XSC", "MT_03D0110001", "Cheetah" },
- { "MHES18-XSC", "MT_03D0120001", "Cheetah" },
- { "MHES18-XSC", "MT_03D0130001", "Cheetah" },
- { "MHES18-XT", "MT_0230000002", "Cheetah" },
- { "MHES18-XT", "MT_0230010002", "Cheetah" },
- { "MHES18-XTC", "MT_03B0110001", "Cheetah" },
- { "MHES18-XTC", "MT_03B0120001", "Cheetah" },
- { "MHES18-XTC", "MT_03B0140001", "Cheetah" },
- { "MHGS18-XS", "MT_0260000002", "Cheetah" },
- { "MHGS18-XSC", "MT_03D0110002", "Cheetah" },
- { "MHGS18-XSC", "MT_03D0120002", "Cheetah" },
- { "MHGS18-XSC", "MT_03D0130002", "Cheetah" },
- { "MHGS18-XT", "MT_0230000001", "Cheetah" },
- { "MHGS18-XTC", "MT_03B0110002", "Cheetah" },
- { "MHGS18-XTC", "MT_03B0120002", "Cheetah" },
- { "MHGS18-XTC", "MT_03B0140002", "Cheetah" },
- { "MHXL-CF128", "MT_0180000001", "Cougar cub" },
- { "MHXL-CF128-T", "MT_0030000001", "Cougar cub" },
- { "MTLP23108-CF128T", "MT_0030000001", "Cougar cub" },
- { "MHET2X-1SC", "MT_0280110001", "Cougar cub" },
- { "MHET2X-1SC", "MT_0280120001", "Cougar cub" },
- { "MHET2X-1TC", "MT_0270110001", "Cougar cub" },
- { "MHET2X-1TC", "MT_0270120001", "Cougar cub" },
- { "MHXL-CF256-T", "MT_0040000001", "Cougar cub" },
- { "MHET2X-2SC", "MT_02D0110001", "Cougar cub" },
- { "MHET2X-2SC", "MT_02D0120001", "Cougar cub" },
- { "MHET2X-2TC", "MT_02B0110001", "Cougar cub" },
- { "MHET2X-2TC", "MT_02B0120001", "Cougar cub" },
- { "MHX-CE128-T", "MT_0000000001", "Cougar" },
- { "MTPB23108-CE128", "MT_0000000001", "Cougar" },
- { "MHX-CE256-T", "MT_0010000001", "Cougar" },
- { "MTPB23108-CE256", "MT_0010000001", "Cougar" },
- { "MHX-CE512-T", "MT_0050000001", "Cougar" },
- { "MTPB23108-CE512", "MT_0050000001", "Cougar" }
-};
-
-#define FWFLASH_MAX_ID 72 /* available combinations */
-#define FWFLASH_PSID_SZ 16
-#define FWFLASH_MAX_ID_SZ 64
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _FWFLASH_MLX_H */