19e39c5baSBill Taylor /*
29e39c5baSBill Taylor  * CDDL HEADER START
39e39c5baSBill Taylor  *
49e39c5baSBill Taylor  * The contents of this file are subject to the terms of the
59e39c5baSBill Taylor  * Common Development and Distribution License (the "License").
69e39c5baSBill Taylor  * You may not use this file except in compliance with the License.
79e39c5baSBill Taylor  *
89e39c5baSBill Taylor  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99e39c5baSBill Taylor  * or http://www.opensolaris.org/os/licensing.
109e39c5baSBill Taylor  * See the License for the specific language governing permissions
119e39c5baSBill Taylor  * and limitations under the License.
129e39c5baSBill Taylor  *
139e39c5baSBill Taylor  * When distributing Covered Code, include this CDDL HEADER in each
149e39c5baSBill Taylor  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159e39c5baSBill Taylor  * If applicable, add the following below this CDDL HEADER, with the
169e39c5baSBill Taylor  * fields enclosed by brackets "[]" replaced with your own identifying
179e39c5baSBill Taylor  * information: Portions Copyright [yyyy] [name of copyright owner]
189e39c5baSBill Taylor  *
199e39c5baSBill Taylor  * CDDL HEADER END
209e39c5baSBill Taylor  */
219e39c5baSBill Taylor 
229e39c5baSBill Taylor /*
23*b67a60d6SShantkumar Hiremath  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
249e39c5baSBill Taylor  */
259e39c5baSBill Taylor 
269e39c5baSBill Taylor /*
279e39c5baSBill Taylor  * IB (InfiniBand) specific functions.
289e39c5baSBill Taylor  */
299e39c5baSBill Taylor 
309e39c5baSBill Taylor /*
319e39c5baSBill Taylor  * The reference for the functions in this file is the
329e39c5baSBill Taylor  *
339e39c5baSBill Taylor  *	Mellanox HCA Flash Programming Application Note
349e39c5baSBill Taylor  * (Mellanox document number 2205AN)
359e39c5baSBill Taylor  * rev 1.44, 2007. Chapter 4 in particular.
369e39c5baSBill Taylor  *
379e39c5baSBill Taylor  * NOTE: this Mellanox document is labelled Confidential
389e39c5baSBill Taylor  * so DO NOT move this file out of usr/closed without
399e39c5baSBill Taylor  * explicit approval from Sun Legal.
409e39c5baSBill Taylor  */
419e39c5baSBill Taylor 
429e39c5baSBill Taylor /*
439e39c5baSBill Taylor  * IMPORTANT NOTE:
449e39c5baSBill Taylor  * 1. flash read is done in 32 bit quantities, and the driver returns
459e39c5baSBill Taylor  *    data in host byteorder form.
469e39c5baSBill Taylor  * 2. flash write is done in 8 bit quantities by the driver.
479e39c5baSBill Taylor  * 3. data in the flash should be in network byteorder (bigendian).
489e39c5baSBill Taylor  * 4. data in image files is in network byteorder form.
499e39c5baSBill Taylor  * 5. data in image structures in memory is kept in network byteorder.
509e39c5baSBill Taylor  * 6. the functions in this file deal with data in host byteorder form.
519e39c5baSBill Taylor  */
529e39c5baSBill Taylor 
539e39c5baSBill Taylor 
549e39c5baSBill Taylor #include <stdio.h>
559e39c5baSBill Taylor #include <stdlib.h>
569e39c5baSBill Taylor #include <unistd.h>
579e39c5baSBill Taylor #include <sys/types.h>
589e39c5baSBill Taylor #include <sys/stat.h>
599e39c5baSBill Taylor #include <sys/sysmacros.h>
609e39c5baSBill Taylor #include <sys/queue.h>
619e39c5baSBill Taylor #include <fcntl.h>
629e39c5baSBill Taylor #include <ctype.h>
639e39c5baSBill Taylor #include <string.h>
649e39c5baSBill Taylor #include <strings.h>
659e39c5baSBill Taylor 
669e39c5baSBill Taylor #include <sys/byteorder.h>
679e39c5baSBill Taylor 
689e39c5baSBill Taylor #include <libintl.h> /* for gettext(3c) */
699e39c5baSBill Taylor 
709e39c5baSBill Taylor #include <fwflash/fwflash.h>
719e39c5baSBill Taylor #include "../../hdrs/MELLANOX.h"
729e39c5baSBill Taylor #include "../../hdrs/tavor_ib.h"
739e39c5baSBill Taylor 
749e39c5baSBill Taylor 
759e39c5baSBill Taylor 
769e39c5baSBill Taylor char *devprefix = "/devices";
779e39c5baSBill Taylor char drivername[] = "tavor\0";
789e39c5baSBill Taylor char *devsuffix = ":devctl";
799e39c5baSBill Taylor 
809e39c5baSBill Taylor 
819e39c5baSBill Taylor extern di_node_t rootnode;
829e39c5baSBill Taylor extern int errno;
839e39c5baSBill Taylor extern struct fw_plugin *self;
849e39c5baSBill Taylor extern struct vrfyplugin *verifier;
859e39c5baSBill Taylor extern int fwflash_debug;
869e39c5baSBill Taylor 
879e39c5baSBill Taylor 
889e39c5baSBill Taylor /* required functions for this plugin */
899e39c5baSBill Taylor int fw_readfw(struct devicelist *device, char *filename);
909e39c5baSBill Taylor int fw_writefw(struct devicelist *device);
919e39c5baSBill Taylor int fw_identify(int start);
929e39c5baSBill Taylor int fw_devinfo();
939e39c5baSBill Taylor 
949e39c5baSBill Taylor 
959e39c5baSBill Taylor /* helper functions */
969e39c5baSBill Taylor 
979e39c5baSBill Taylor static int tavor_identify(struct devicelist *thisdev);
989e39c5baSBill Taylor static int tavor_get_guids(struct ib_encap_ident *handle);
999e39c5baSBill Taylor static int tavor_close(struct devicelist *flashdev);
1009e39c5baSBill Taylor static void tavor_cisco_extensions(mlx_xps_t *hcaxps, mlx_xps_t *diskxps);
1019e39c5baSBill Taylor static uint16_t crc16(uint8_t *image, uint32_t size);
1029e39c5baSBill Taylor static int tavor_write_sector(int fd, int sectnum, int32_t *data);
1039e39c5baSBill Taylor static int tavor_zero_sig_crc(int fd, uint32_t start);
1049e39c5baSBill Taylor static int tavor_write_xps_fia(int fd, uint32_t offset, uint32_t start);
1059e39c5baSBill Taylor static int tavor_write_xps_crc_sig(int fd, uint32_t offset, uint16_t newcrc);
1069e39c5baSBill Taylor static int tavor_blast_image(int fd, int prisec, uint32_t hcafia,
1079e39c5baSBill Taylor     uint32_t sectsz, struct mlx_xps *newxps);
1089e39c5baSBill Taylor static int tavor_readback(int infd, int whichsect, int sectsz);
1099e39c5baSBill Taylor 
1109e39c5baSBill Taylor 
1119e39c5baSBill Taylor 
1129e39c5baSBill Taylor int
fw_readfw(struct devicelist * flashdev,char * filename)1139e39c5baSBill Taylor fw_readfw(struct devicelist *flashdev, char *filename)
1149e39c5baSBill Taylor {
1159e39c5baSBill Taylor 
1169e39c5baSBill Taylor 	int 				rv = FWFLASH_SUCCESS;
1179e39c5baSBill Taylor 	int 				fd;
1189e39c5baSBill Taylor 	mode_t				mode = S_IRUSR | S_IWUSR;
1199e39c5baSBill Taylor 	uint8_t				pchunks;
1209e39c5baSBill Taylor 	uint8_t				*raw_pfi;
1219e39c5baSBill Taylor 	uint8_t				*raw_sfi;
1229e39c5baSBill Taylor 	uint32_t			j, offset;
1239e39c5baSBill Taylor 	uint32_t			pfia, sfia, psz, ssz;
1249e39c5baSBill Taylor 	tavor_flash_ioctl_t		tfi_data;
1259e39c5baSBill Taylor 	struct ib_encap_ident		*manuf;
1269e39c5baSBill Taylor 	struct mlx_xps			*lpps;
1279e39c5baSBill Taylor 	struct mlx_xps			*lsps;
1289e39c5baSBill Taylor #if defined(_LITTLE_ENDIAN)
1299e39c5baSBill Taylor 	uint32_t			*ptr;
1309e39c5baSBill Taylor #endif
1319e39c5baSBill Taylor 
1329e39c5baSBill Taylor 	errno = 0;
1339e39c5baSBill Taylor 	if ((fd = open(filename, O_RDWR|O_CREAT|O_DSYNC, mode)) < 0) {
1349e39c5baSBill Taylor 		logmsg(MSG_ERROR,
1359e39c5baSBill Taylor 		    gettext("tavor: Unable to open specified file "
1369e39c5baSBill Taylor 		    "(%s) for writing: %s\n"), filename, strerror(errno));
1379e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
1389e39c5baSBill Taylor 	}
1399e39c5baSBill Taylor 
1409e39c5baSBill Taylor 	manuf =
1419e39c5baSBill Taylor 	    (struct ib_encap_ident *)(uintptr_t)flashdev->ident->encap_ident;
1429e39c5baSBill Taylor 	lpps = (struct mlx_xps *)(uintptr_t)manuf->pps;
1439e39c5baSBill Taylor 	lsps = (struct mlx_xps *)(uintptr_t)manuf->sps;
1449e39c5baSBill Taylor 
1459e39c5baSBill Taylor 	/*
1469e39c5baSBill Taylor 	 * Now that we've got an open, init'd fd, we can read the
1479e39c5baSBill Taylor 	 * xFI from the device itself. We've already got the IS
1489e39c5baSBill Taylor 	 * and xPS stored in manuf.
1499e39c5baSBill Taylor 	 */
1509e39c5baSBill Taylor 
1519e39c5baSBill Taylor 	/* stash some values for later */
1529e39c5baSBill Taylor 	pfia = MLXSWAPBITS32(lpps->fia);
1539e39c5baSBill Taylor 	sfia = MLXSWAPBITS32(lsps->fia);
1549e39c5baSBill Taylor 	psz = MLXSWAPBITS32(lpps->fis);
1559e39c5baSBill Taylor 	ssz = MLXSWAPBITS32(lsps->fis);
1569e39c5baSBill Taylor 
1579e39c5baSBill Taylor 	/* Invariant Sector comes first */
1589e39c5baSBill Taylor 	if ((j = write(fd, manuf->inv, manuf->sector_sz)) !=
1599e39c5baSBill Taylor 	    manuf->sector_sz) {
1609e39c5baSBill Taylor 		logmsg(MSG_ERROR,
1619e39c5baSBill Taylor 		    gettext("tavor: Unable to write HCA Invariant Sector "
1629e39c5baSBill Taylor 		    "(%d of %d bytes)\n"),
1639e39c5baSBill Taylor 		    j, manuf->sector_sz);
1649e39c5baSBill Taylor 		(void) tavor_close(flashdev);
1659e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
1669e39c5baSBill Taylor 	} else {
1679e39c5baSBill Taylor 		fprintf(stdout, gettext("Writing ."));
1689e39c5baSBill Taylor 	}
1699e39c5baSBill Taylor 
1709e39c5baSBill Taylor 	/* followed by Primary Pointer Sector */
1719e39c5baSBill Taylor 	if ((j = write(fd, manuf->pps, manuf->sector_sz)) !=
1729e39c5baSBill Taylor 	    manuf->sector_sz) {
1739e39c5baSBill Taylor 		logmsg(MSG_ERROR,
1749e39c5baSBill Taylor 		    gettext("tavor: Unable to write HCA Primary Pointer "
1759e39c5baSBill Taylor 		    "Sector (%d of %d bytes)\n)"),
1769e39c5baSBill Taylor 		    j, manuf->sector_sz);
1779e39c5baSBill Taylor 		(void) tavor_close(flashdev);
1789e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
1799e39c5baSBill Taylor 	} else {
1809e39c5baSBill Taylor 		fprintf(stdout, " .");
1819e39c5baSBill Taylor 	}
1829e39c5baSBill Taylor 
1839e39c5baSBill Taylor 	/* followed by Secondary Pointer Sector */
1849e39c5baSBill Taylor 	if ((j = write(fd, manuf->sps, manuf->sector_sz)) !=
1859e39c5baSBill Taylor 	    manuf->sector_sz) {
1869e39c5baSBill Taylor 		logmsg(MSG_ERROR,
1879e39c5baSBill Taylor 		    gettext("tavor: Unable to write HCA Secondary Pointer "
1889e39c5baSBill Taylor 		    "Sector (%d of %d bytes)\n"),
1899e39c5baSBill Taylor 		    j, manuf->sector_sz);
1909e39c5baSBill Taylor 		(void) tavor_close(flashdev);
1919e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
1929e39c5baSBill Taylor 	} else {
1939e39c5baSBill Taylor 		fprintf(stdout, " .");
1949e39c5baSBill Taylor 	}
1959e39c5baSBill Taylor 
1969e39c5baSBill Taylor 	/* Now for the xFI sectors */
1979e39c5baSBill Taylor 	pchunks = psz / manuf->sector_sz;
1989e39c5baSBill Taylor 
1999e39c5baSBill Taylor 	if ((psz % manuf->sector_sz) != 0)
2009e39c5baSBill Taylor 		pchunks++;
2019e39c5baSBill Taylor 
2029e39c5baSBill Taylor 	/* Get the PFI, then the SFI */
2039e39c5baSBill Taylor 	if ((raw_pfi = calloc(1, pchunks * manuf->sector_sz)) == NULL) {
2049e39c5baSBill Taylor 		logmsg(MSG_ERROR,
2059e39c5baSBill Taylor 		    gettext("tavor: Unable to allocate space for "
2069e39c5baSBill Taylor 		    "device's Primary Firmware Image\n"));
2079e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
2089e39c5baSBill Taylor 	}
2099e39c5baSBill Taylor 	bzero(&tfi_data, sizeof (tavor_flash_ioctl_t));
2109e39c5baSBill Taylor 	tfi_data.tf_type = TAVOR_FLASH_READ_SECTOR;
2119e39c5baSBill Taylor 	j = pfia / manuf->sector_sz;
2129e39c5baSBill Taylor 
2139e39c5baSBill Taylor 	for (offset = 0; offset < psz; offset += manuf->sector_sz) {
2149e39c5baSBill Taylor 		tfi_data.tf_sector_num = j;
2159e39c5baSBill Taylor 		tfi_data.tf_sector = (caddr_t)&raw_pfi[offset];
2169e39c5baSBill Taylor 		rv = ioctl(manuf->fd, TAVOR_IOCTL_FLASH_READ, &tfi_data);
2179e39c5baSBill Taylor 		if (rv < 0) {
2189e39c5baSBill Taylor 			logmsg(MSG_ERROR,
2199e39c5baSBill Taylor 			    gettext("tavor: Unable to read sector %d of "
2209e39c5baSBill Taylor 			    "HCA Primary Firmware Image\n"), j);
2219e39c5baSBill Taylor 			free(raw_pfi);
2229e39c5baSBill Taylor 			(void) tavor_close(flashdev);
2239e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
2249e39c5baSBill Taylor 		}
2259e39c5baSBill Taylor 		++j;
2269e39c5baSBill Taylor 	}
2279e39c5baSBill Taylor 
2289e39c5baSBill Taylor 	/*
2299e39c5baSBill Taylor 	 * It appears that the tavor driver is returning a signed
2309e39c5baSBill Taylor 	 * -1 (0xffff) in unassigned quadlets if we read a sector
2319e39c5baSBill Taylor 	 * that isn't full, so for backwards compatibility with
2329e39c5baSBill Taylor 	 * earlier fwflash versions, we need to zero out what
2339e39c5baSBill Taylor 	 * remains in the sector.
2349e39c5baSBill Taylor 	 */
2359e39c5baSBill Taylor 	bzero(&raw_pfi[psz], (pchunks * manuf->sector_sz) - psz);
2369e39c5baSBill Taylor 
2379e39c5baSBill Taylor #if defined(_LITTLE_ENDIAN)
2389e39c5baSBill Taylor 	ptr = (uint32_t *)(uintptr_t)raw_pfi;
2399e39c5baSBill Taylor 	for (j = 0; j < (pchunks * manuf->sector_sz / 4); j++) {
2409e39c5baSBill Taylor 		ptr[j] = htonl(ptr[j]);
2419e39c5baSBill Taylor 		if (j > psz)
2429e39c5baSBill Taylor 			break;
2439e39c5baSBill Taylor 	}
2449e39c5baSBill Taylor #endif
2459e39c5baSBill Taylor 
2469e39c5baSBill Taylor 	if ((j = write(fd, raw_pfi, pchunks * manuf->sector_sz))
2479e39c5baSBill Taylor 	    != pchunks * manuf->sector_sz) {
2489e39c5baSBill Taylor 		logmsg(MSG_ERROR,
2499e39c5baSBill Taylor 		    gettext("tavor: Unable to write HCA Primary Firmware "
2509e39c5baSBill Taylor 		    "Image data (%d of %d bytes)\n"),
2519e39c5baSBill Taylor 		    j, pchunks * manuf->sector_sz);
2529e39c5baSBill Taylor 		free(raw_pfi);
2539e39c5baSBill Taylor 		(void) tavor_close(flashdev);
2549e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
2559e39c5baSBill Taylor 	} else {
2569e39c5baSBill Taylor 		fprintf(stdout, " .");
2579e39c5baSBill Taylor 	}
2589e39c5baSBill Taylor 
2599e39c5baSBill Taylor 	pchunks = ssz / manuf->sector_sz;
2609e39c5baSBill Taylor 
2619e39c5baSBill Taylor 	if ((ssz % manuf->sector_sz) != 0)
2629e39c5baSBill Taylor 		pchunks++;
2639e39c5baSBill Taylor 
2649e39c5baSBill Taylor 	/*
2659e39c5baSBill Taylor 	 * We allocate wholenum sectors, but only write out what we
2669e39c5baSBill Taylor 	 * really need (ssz bytes)
2679e39c5baSBill Taylor 	 */
2689e39c5baSBill Taylor 	if ((raw_sfi = calloc(1, pchunks * manuf->sector_sz)) == NULL) {
2699e39c5baSBill Taylor 		logmsg(MSG_ERROR,
2709e39c5baSBill Taylor 		    gettext("tavor: Unable to allocate space for "
2719e39c5baSBill Taylor 		    "device's Secondary Firmware Image\n"));
2729e39c5baSBill Taylor 		free(raw_pfi);
2739e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
2749e39c5baSBill Taylor 	}
2759e39c5baSBill Taylor 	bzero(&tfi_data, sizeof (tavor_flash_ioctl_t));
2769e39c5baSBill Taylor 	tfi_data.tf_type = TAVOR_FLASH_READ_SECTOR;
2779e39c5baSBill Taylor 
2789e39c5baSBill Taylor 	/* get our starting sector number */
2799e39c5baSBill Taylor 	j = sfia / manuf->sector_sz;
2809e39c5baSBill Taylor 
2819e39c5baSBill Taylor 	for (offset = 0; offset < ssz; offset += manuf->sector_sz) {
2829e39c5baSBill Taylor 		tfi_data.tf_sector_num = j;
2839e39c5baSBill Taylor 		tfi_data.tf_sector = (caddr_t)&raw_sfi[offset];
2849e39c5baSBill Taylor 		if ((rv = ioctl(manuf->fd, TAVOR_IOCTL_FLASH_READ,
2859e39c5baSBill Taylor 		    &tfi_data)) < 0) {
2869e39c5baSBill Taylor 			logmsg(MSG_ERROR,
2879e39c5baSBill Taylor 			    gettext("tavor: Unable to read sector %d of "
2889e39c5baSBill Taylor 			    "HCA Secondary Firmware Image\n"), j);
2899e39c5baSBill Taylor 			(void) tavor_close(flashdev);
2909e39c5baSBill Taylor 			free(raw_pfi);
2919e39c5baSBill Taylor 			free(raw_sfi);
2929e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
2939e39c5baSBill Taylor 		}
2949e39c5baSBill Taylor 		++j;
2959e39c5baSBill Taylor 	}
2969e39c5baSBill Taylor 
2979e39c5baSBill Taylor 	/*
2989e39c5baSBill Taylor 	 * It appears that the tavor driver is returning a signed
2999e39c5baSBill Taylor 	 * -1 (0xffff) in unassigned quadlets if we read a sector
3009e39c5baSBill Taylor 	 * that isn't full, so for backwards compatibility with
3019e39c5baSBill Taylor 	 * earlier fwflash versions, we need to zero out what
3029e39c5baSBill Taylor 	 * remains in the sector.
3039e39c5baSBill Taylor 	 */
3049e39c5baSBill Taylor 	bzero(&raw_sfi[ssz], (pchunks * manuf->sector_sz) - ssz);
3059e39c5baSBill Taylor 
3069e39c5baSBill Taylor #if defined(_LITTLE_ENDIAN)
3079e39c5baSBill Taylor 	ptr = (uint32_t *)(uintptr_t)raw_sfi;
3089e39c5baSBill Taylor 	for (j = 0; j < ssz / 4; j++) {
3099e39c5baSBill Taylor 		ptr[j] = htonl(ptr[j]);
3109e39c5baSBill Taylor 	}
3119e39c5baSBill Taylor #endif
3129e39c5baSBill Taylor 
3139e39c5baSBill Taylor 	/* only write out ssz bytes */
3149e39c5baSBill Taylor 	if ((j = write(fd, raw_sfi, ssz)) != ssz) {
3159e39c5baSBill Taylor 		logmsg(MSG_ERROR,
3169e39c5baSBill Taylor 		    gettext("tavor: Unable to write HCA Secondary Firmware "
3179e39c5baSBill Taylor 		    "Image data (%d of %d bytes)\n"),
3189e39c5baSBill Taylor 		    j, ssz);
3199e39c5baSBill Taylor 		(void) tavor_close(flashdev);
3209e39c5baSBill Taylor 		free(raw_pfi);
3219e39c5baSBill Taylor 		free(raw_sfi);
3229e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
3239e39c5baSBill Taylor 	} else {
3249e39c5baSBill Taylor 		fprintf(stdout, " .\n");
3259e39c5baSBill Taylor 	}
3269e39c5baSBill Taylor 
3279e39c5baSBill Taylor 	fprintf(stdout,
3289e39c5baSBill Taylor 	    gettext("Done.\n"));
3299e39c5baSBill Taylor 
3309e39c5baSBill Taylor 	free(raw_pfi);
3319e39c5baSBill Taylor 	free(raw_sfi);
3329e39c5baSBill Taylor 	/*
3339e39c5baSBill Taylor 	 * this should succeed, but we don't just blindly ignore
3349e39c5baSBill Taylor 	 * the return code cos that would be obnoxious.
3359e39c5baSBill Taylor 	 */
3369e39c5baSBill Taylor 	return (tavor_close(flashdev));
3379e39c5baSBill Taylor }
3389e39c5baSBill Taylor 
3399e39c5baSBill Taylor 
3409e39c5baSBill Taylor /*
3419e39c5baSBill Taylor  * If we're invoking fw_writefw, then flashdev is a valid,
3429e39c5baSBill Taylor  * flashable device as determined by fw_identify().
3439e39c5baSBill Taylor  *
3449e39c5baSBill Taylor  * If verifier is null, then we haven't been called following a firmware
3459e39c5baSBill Taylor  * image verification load operation.
3469e39c5baSBill Taylor  */
3479e39c5baSBill Taylor int
fw_writefw(struct devicelist * flashdev)3489e39c5baSBill Taylor fw_writefw(struct devicelist *flashdev)
3499e39c5baSBill Taylor {
3509e39c5baSBill Taylor 
3519e39c5baSBill Taylor 	int			rv;
3529e39c5baSBill Taylor 	uint32_t 		j, sectsz, hpfia, hsfia;
3539e39c5baSBill Taylor 	uint32_t		ipfia, isfia, ipfis, isfis;
3549e39c5baSBill Taylor 	struct ib_encap_ident	*manuf;
3559e39c5baSBill Taylor 	struct mlx_is		*iinv;
3569e39c5baSBill Taylor 	struct mlx_xps		*ipps, *lpps;
3579e39c5baSBill Taylor 	struct mlx_xps		*isps, *lsps;
3589e39c5baSBill Taylor 	struct mlx_xfi		*ipfi, *isfi;
3599e39c5baSBill Taylor 
3609e39c5baSBill Taylor 	/*
3619e39c5baSBill Taylor 	 * linv, lpps/lsps are from the HCA whereas
3629e39c5baSBill Taylor 	 * iinv/ipps/isps are in the on-disk firmware image that
3639e39c5baSBill Taylor 	 * we've read in to the verifier->fwimage field, and are
3649e39c5baSBill Taylor 	 * about to do some hand-waving with.
3659e39c5baSBill Taylor 	 */
3669e39c5baSBill Taylor 
3679e39c5baSBill Taylor 	/*
3689e39c5baSBill Taylor 	 * From the Mellanox HCA Flash programming app note,
3699e39c5baSBill Taylor 	 * start of ch4, page36:
3709e39c5baSBill Taylor 	 * ===========================================================
3719e39c5baSBill Taylor 	 * Failsafe firmware programming ensures that an HCA device
3729e39c5baSBill Taylor 	 * can boot up in a functional mode even if the burn process
3739e39c5baSBill Taylor 	 * was interrupted (because of a power failure, reboot, user
3749e39c5baSBill Taylor 	 * interrupt, etc.). This can be implemented by burning the
3759e39c5baSBill Taylor 	 * new image to a vacant region on the Flash, and erasing the
3769e39c5baSBill Taylor 	 * old image only after the new image is successfully burnt.
3779e39c5baSBill Taylor 	 * This method ensures that there is at least one valid firmware
3789e39c5baSBill Taylor 	 * image on the Flash at all times. Thus, in case a firmware
3799e39c5baSBill Taylor 	 * image programming process is aborted for any reason, the HCA
3809e39c5baSBill Taylor 	 * will still be able to boot up properly using the valid image
3819e39c5baSBill Taylor 	 * on the Flash.
3829e39c5baSBill Taylor 	 * ...
3839e39c5baSBill Taylor 	 *
3849e39c5baSBill Taylor 	 * 4.1 Notes on Image Programming of HCA Flashes
3859e39c5baSBill Taylor 	 * Following are some general notes regarding the Flash memory
3869e39c5baSBill Taylor 	 * in the context of Mellanox HCA devices:
3879e39c5baSBill Taylor 	 * > The Flash memory is divided into sectors, and each sector
3889e39c5baSBill Taylor 	 *   must be erased prior to its programming.
3899e39c5baSBill Taylor 	 * > The image to be burnt is byte packed and should be programmed
3909e39c5baSBill Taylor 	 *   into the Flash byte by byte, preserving the byte order, starting
3919e39c5baSBill Taylor 	 *   at offset zero. No amendments are needed for endianess.
3929e39c5baSBill Taylor 	 * > It is recommended to program the Flash while the device is idle.
3939e39c5baSBill Taylor 	 * ===========================================================
3949e39c5baSBill Taylor 	 *
3959e39c5baSBill Taylor 	 * The comment about endianness is particularly important for us
3969e39c5baSBill Taylor 	 * since we operate on both big- and litte-endian hosts - it means
3979e39c5baSBill Taylor 	 * we have to do some byte-swapping gymnastics
3989e39c5baSBill Taylor 	 */
3999e39c5baSBill Taylor 
4009e39c5baSBill Taylor 	/*
4019e39c5baSBill Taylor 	 * From the Mellanox HCA Flash programming app note,
4029e39c5baSBill Taylor 	 * section 4.2.5 on page 41/42:
4039e39c5baSBill Taylor 	 * ===========================================================
4049e39c5baSBill Taylor 	 * 4.2.5 Failsafe Programming Example
4059e39c5baSBill Taylor 	 * This section provides an example of a programming utility
4069e39c5baSBill Taylor 	 * that performs a Failsafe firmware image update. The flow
4079e39c5baSBill Taylor 	 * ensures that there is at least one valid firmware image on
4089e39c5baSBill Taylor 	 * the Flash at all times. Thus, in case a firmware image pro-
4099e39c5baSBill Taylor 	 * gramming process is aborted for any reason, the HCA will
4109e39c5baSBill Taylor 	 * still be able to boot up properly using the valid image on
4119e39c5baSBill Taylor 	 * the Flash. Any other flow that ensures the above is also
4129e39c5baSBill Taylor 	 * considered a Failsafe firmware update.
4139e39c5baSBill Taylor 	 *
4149e39c5baSBill Taylor 	 * Update Flow:
4159e39c5baSBill Taylor 	 * * Check the validity of the PPS and SPS:
4169e39c5baSBill Taylor 	 * > If both PSs are valid, arbitrarily invalidate one of them
4179e39c5baSBill Taylor 	 * > If both PSs are invalid, the image on flash is corrupted
4189e39c5baSBill Taylor 	 *   and cannot be updated in a Failsafe way. The user must
4199e39c5baSBill Taylor 	 *   burn a full image in a non-failsafe way.
4209e39c5baSBill Taylor 	 *
4219e39c5baSBill Taylor 	 * > If only the PPS is valid:
4229e39c5baSBill Taylor 	 *   i.Burn the secondary image (erase each sector first)
4239e39c5baSBill Taylor 	 *  ii.Burn the SPS with the correct image address (FIA field)
4249e39c5baSBill Taylor 	 * iii.Invalidate the PPS
4259e39c5baSBill Taylor 	 *
4269e39c5baSBill Taylor 	 * > If only the SPS is valid:
4279e39c5baSBill Taylor 	 *   i.Burn the primary image (erase each sector first)
4289e39c5baSBill Taylor 	 *  ii.Burn the PPS with the correct image address (FIA field)
4299e39c5baSBill Taylor 	 * iii.Invalidate the SPS
4309e39c5baSBill Taylor 	 * ===========================================================
4319e39c5baSBill Taylor 	 */
4329e39c5baSBill Taylor 
4339e39c5baSBill Taylor 	/*
4349e39c5baSBill Taylor 	 * Other required tasks called from this function:
4359e39c5baSBill Taylor 	 *
4369e39c5baSBill Taylor 	 * * check for CISCO boot extensions in the current xPS, and
4379e39c5baSBill Taylor 	 *   if found, set them in the new xPS
4389e39c5baSBill Taylor 	 *
4399e39c5baSBill Taylor 	 * * update the xPS CRC field
4409e39c5baSBill Taylor 	 *
4419e39c5baSBill Taylor 	 * _then_ you can setup the outbound transfer to the HCA flash.
4429e39c5baSBill Taylor 	 */
4439e39c5baSBill Taylor 
4449e39c5baSBill Taylor 	/*
4459e39c5baSBill Taylor 	 * VERY IMPORTANT NOTE:
4469e39c5baSBill Taylor 	 * The above text from the app note programming guide v1.44 does
4479e39c5baSBill Taylor 	 * NOT match reality. If you try to do exactly what the above
4489e39c5baSBill Taylor 	 * text specifies then you'll wind up with a warm, brick-like
4499e39c5baSBill Taylor 	 * HCA that if you're really lucky has booted up in maintenance
4509e39c5baSBill Taylor 	 * mode for you to re-flash.
4519e39c5baSBill Taylor 	 *
4529e39c5baSBill Taylor 	 * What you need to do is follow the example of the previous
4539e39c5baSBill Taylor 	 * (v1.2 etc) version from the ON gate - which is what happens
4549e39c5baSBill Taylor 	 * in this file. Basically - don't erase prior to writing a new
4559e39c5baSBill Taylor 	 * sector, and _read back_ each sector after writing it. Especially
4569e39c5baSBill Taylor 	 * the pointer sectors. Otherwise you'll get a warm brick.
4579e39c5baSBill Taylor 	 */
4589e39c5baSBill Taylor 
4599e39c5baSBill Taylor 	manuf =
4609e39c5baSBill Taylor 	    (struct ib_encap_ident *)(uintptr_t)flashdev->ident->encap_ident;
4619e39c5baSBill Taylor 	lpps = (struct mlx_xps *)(uintptr_t)manuf->pps;
4629e39c5baSBill Taylor 	lsps = (struct mlx_xps *)(uintptr_t)manuf->sps;
4639e39c5baSBill Taylor 	iinv = (struct mlx_is *)&verifier->fwimage[0];
4649e39c5baSBill Taylor 	sectsz = 1 << MLXSWAPBITS16(iinv->log2sectsz + iinv->log2sectszp);
4659e39c5baSBill Taylor 	ipps = (struct mlx_xps *)&verifier->fwimage[sectsz/4];
4669e39c5baSBill Taylor 	isps = (struct mlx_xps *)&verifier->fwimage[sectsz/2];
4679e39c5baSBill Taylor 
4689e39c5baSBill Taylor 	/*
4699e39c5baSBill Taylor 	 * If we get here, then the verifier has _already_ checked that
4709e39c5baSBill Taylor 	 * the part number in the firmware image matches that in the HCA,
4719e39c5baSBill Taylor 	 * so we only need this check if there's no hardware info available
4729e39c5baSBill Taylor 	 * already after running through fw_identify().
4739e39c5baSBill Taylor 	 */
4749e39c5baSBill Taylor 	if (manuf->pn_len == 0) {
4759e39c5baSBill Taylor 		int resp;
4769e39c5baSBill Taylor 
4779e39c5baSBill Taylor 		(void) printf("\nUnable to completely verify that this "
4789e39c5baSBill Taylor 		    "firmware image\n\t(%s)\nis compatible with your "
4799e39c5baSBill Taylor 		    "HCA\n\t%s\n",
4809e39c5baSBill Taylor 		    verifier->imgfile, flashdev->access_devname);
4819e39c5baSBill Taylor 		(void) printf("\n\tDo you really want to continue? (Y/N): ");
4829e39c5baSBill Taylor 
4839e39c5baSBill Taylor 		(void) fflush(stdin);
4849e39c5baSBill Taylor 		resp = getchar();
4859e39c5baSBill Taylor 		if (resp != 'Y' && resp != 'y') {
4869e39c5baSBill Taylor 			(void) printf("\nNot proceeding with flash "
4879e39c5baSBill Taylor 			    "operation of %s on %s\n",
4889e39c5baSBill Taylor 			    verifier->imgfile, flashdev->access_devname);
4899e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
4909e39c5baSBill Taylor 		}
4919e39c5baSBill Taylor 	}
4929e39c5baSBill Taylor 
4939e39c5baSBill Taylor 	/* stash these for later */
4949e39c5baSBill Taylor 	hpfia = MLXSWAPBITS32(lpps->fia);
4959e39c5baSBill Taylor 	hsfia = MLXSWAPBITS32(lsps->fia);
4969e39c5baSBill Taylor 
4979e39c5baSBill Taylor 	/* where does the on-disk image think everything is at? */
4989e39c5baSBill Taylor 	ipfia = MLXSWAPBITS32(ipps->fia);
4999e39c5baSBill Taylor 	isfia = MLXSWAPBITS32(isps->fia);
5009e39c5baSBill Taylor 	ipfis = MLXSWAPBITS32(ipps->fis);
5019e39c5baSBill Taylor 	isfis = MLXSWAPBITS32(isps->fis);
5029e39c5baSBill Taylor 
5039e39c5baSBill Taylor 	logmsg(MSG_INFO, "tavor: hpfia 0x%0x hsfia 0x%0x "
5049e39c5baSBill Taylor 	    "ipfia 0x%0x isfia 0x%0x ipfis 0x%0x isfis 0x%0x\n",
5059e39c5baSBill Taylor 	    hpfia, hsfia, ipfia, isfia, ipfis, isfis);
5069e39c5baSBill Taylor 
5079e39c5baSBill Taylor 	if ((ipfis + isfis) > manuf->device_sz) {
5089e39c5baSBill Taylor 		/*
5099e39c5baSBill Taylor 		 * This is bad - don't flash an image which is larger
5109e39c5baSBill Taylor 		 * than the size of the HCA's flash
5119e39c5baSBill Taylor 		 */
5129e39c5baSBill Taylor 		logmsg(MSG_ERROR,
5139e39c5baSBill Taylor 		    gettext("tavor: on-disk firmware image size (0x%lx bytes) "
5149e39c5baSBill Taylor 		    "exceeds HCA's flash memory size (0x%lx bytes)!\n"),
5159e39c5baSBill Taylor 		    ipfis + isfis, manuf->device_sz);
5169e39c5baSBill Taylor 		logmsg(MSG_ERROR,
5179e39c5baSBill Taylor 		    gettext("tavor: not flashing this image (%s)\n"),
5189e39c5baSBill Taylor 		    verifier->imgfile);
5199e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5209e39c5baSBill Taylor 	}
5219e39c5baSBill Taylor 
5229e39c5baSBill Taylor 	/*
5239e39c5baSBill Taylor 	 * The Mellanox HCA Flash app programming note does _not_
5249e39c5baSBill Taylor 	 * specify that you have to insert the HCA's guid section
5259e39c5baSBill Taylor 	 * into the flash image before burning it.
5269e39c5baSBill Taylor 	 *
5279e39c5baSBill Taylor 	 * HOWEVER it was determined during testing that this is
5289e39c5baSBill Taylor 	 * actually required (otherwise your HCA's GUIDs revert to
5299e39c5baSBill Taylor 	 * the manufacturer's defaults, ugh!), so we'll do it too.
5309e39c5baSBill Taylor 	 */
5319e39c5baSBill Taylor 
5329e39c5baSBill Taylor 	ipfi = (struct mlx_xfi *)&verifier->fwimage[ipfia/4];
5339e39c5baSBill Taylor 	isfi = (struct mlx_xfi *)&verifier->fwimage[isfia/4];
5349e39c5baSBill Taylor 
5359e39c5baSBill Taylor 	/*
5369e39c5baSBill Taylor 	 * Here we check against our stored, properly-bitwise-munged copy
5379e39c5baSBill Taylor 	 * of the HCA's GUIDS. If they're not set to default AND the OUI
5389e39c5baSBill Taylor 	 * is MLX_OUI, then they're ok so we copy the HCA's version into
5399e39c5baSBill Taylor 	 * our in-memory copy and blat it. If the GUIDs don't match this
5409e39c5baSBill Taylor 	 * condition, then we use the default GUIDs which are in the on-disk
5419e39c5baSBill Taylor 	 * firmware image instead.
5429e39c5baSBill Taylor 	 */
5439e39c5baSBill Taylor 	if (((manuf->ibguids[0] != MLX_DEFAULT_NODE_GUID) &&
5449e39c5baSBill Taylor 	    (manuf->ibguids[1] != MLX_DEFAULT_P1_GUID) &&
5459e39c5baSBill Taylor 	    (manuf->ibguids[2] != MLX_DEFAULT_P2_GUID) &&
5469e39c5baSBill Taylor 	    (manuf->ibguids[3] != MLX_DEFAULT_SYSIMG_GUID)) &&
5479e39c5baSBill Taylor 	    ((((manuf->ibguids[0] & HIGHBITS64) >> OUISHIFT) == MLX_OUI) ||
5489e39c5baSBill Taylor 	    (((manuf->ibguids[1] & HIGHBITS64) >> OUISHIFT) == MLX_OUI) ||
5499e39c5baSBill Taylor 	    (((manuf->ibguids[2] & HIGHBITS64) >> OUISHIFT) == MLX_OUI) ||
5509e39c5baSBill Taylor 	    (((manuf->ibguids[3] & HIGHBITS64) >> OUISHIFT) == MLX_OUI))) {
5519e39c5baSBill Taylor 		/* The GUIDs are ok, blat them into the in-memory image */
5529e39c5baSBill Taylor 		j = ((ipfia + MLXSWAPBITS32(ipfi->nguidptr)) / 4) - 4;
5539e39c5baSBill Taylor 		bcopy(manuf->pri_guid_section, &verifier->fwimage[j],
5549e39c5baSBill Taylor 		    sizeof (struct mlx_guid_sect));
5559e39c5baSBill Taylor 		j = ((isfia + MLXSWAPBITS32(isfi->nguidptr)) / 4) - 4;
5569e39c5baSBill Taylor 		bcopy(manuf->sec_guid_section, &verifier->fwimage[j],
5579e39c5baSBill Taylor 		    sizeof (struct mlx_guid_sect));
5589e39c5baSBill Taylor 	} else {
5599e39c5baSBill Taylor 		/*
5609e39c5baSBill Taylor 		 * The GUIDs are hosed, we'll have to use
5619e39c5baSBill Taylor 		 * the vendor defaults in the image instead
5629e39c5baSBill Taylor 		 */
5639e39c5baSBill Taylor 		logmsg(MSG_ERROR,
5649e39c5baSBill Taylor 		    gettext("tavor: HCA's GUID section is set to defaults or "
5659e39c5baSBill Taylor 		    " is invalid, using firmware image manufacturer's "
5669e39c5baSBill Taylor 		    "default GUID section instead\n"));
5679e39c5baSBill Taylor 	}
5689e39c5baSBill Taylor 
5699e39c5baSBill Taylor 	/* Just in case somebody is booting from this card... */
5709e39c5baSBill Taylor 	tavor_cisco_extensions(lpps, ipps);
5719e39c5baSBill Taylor 	tavor_cisco_extensions(lsps, isps);
5729e39c5baSBill Taylor 
5739e39c5baSBill Taylor 	/* first we write the secondary image and SPS, then the primary */
5749e39c5baSBill Taylor 	rv = tavor_blast_image(manuf->fd, 2, hsfia, manuf->sector_sz, isps);
5759e39c5baSBill Taylor 	if (rv != FWFLASH_SUCCESS) {
5769e39c5baSBill Taylor 		logmsg(MSG_INFO,
5779e39c5baSBill Taylor 		    "tavor: failed to update #2 firmware image\n");
5789e39c5baSBill Taylor 		(void) tavor_close(flashdev);
5799e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5809e39c5baSBill Taylor 	}
5819e39c5baSBill Taylor 
5829e39c5baSBill Taylor 	rv = tavor_blast_image(manuf->fd, 1, hpfia, manuf->sector_sz, ipps);
5839e39c5baSBill Taylor 	if (rv != FWFLASH_SUCCESS) {
5849e39c5baSBill Taylor 		logmsg(MSG_INFO,
5859e39c5baSBill Taylor 		    "tavor: failed to update #1 firmware image\n");
5869e39c5baSBill Taylor 		(void) tavor_close(flashdev);
5879e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5889e39c5baSBill Taylor 	}
5899e39c5baSBill Taylor 
5909e39c5baSBill Taylor 	/* final update marker to the user */
5919e39c5baSBill Taylor 	(void) printf(" +\n");
5929e39c5baSBill Taylor 	return (tavor_close(flashdev));
5939e39c5baSBill Taylor }
5949e39c5baSBill Taylor 
5959e39c5baSBill Taylor 
5969e39c5baSBill Taylor /*
5979e39c5baSBill Taylor  * The fw_identify() function walks the device
5989e39c5baSBill Taylor  * tree trying to find devices which this plugin
5999e39c5baSBill Taylor  * can work with.
6009e39c5baSBill Taylor  *
6019e39c5baSBill Taylor  * The parameter "start" gives us the starting index number
6029e39c5baSBill Taylor  * to give the device when we add it to the fw_devices list.
6039e39c5baSBill Taylor  *
6049e39c5baSBill Taylor  * firstdev is allocated by us and we add space as necessary
6059e39c5baSBill Taylor  *
6069e39c5baSBill Taylor  */
6079e39c5baSBill Taylor int
fw_identify(int start)6089e39c5baSBill Taylor fw_identify(int start)
6099e39c5baSBill Taylor {
6109e39c5baSBill Taylor 	int rv = FWFLASH_FAILURE;
6119e39c5baSBill Taylor 	di_node_t thisnode;
6129e39c5baSBill Taylor 	struct devicelist *newdev;
6139e39c5baSBill Taylor 	char *devpath;
6149e39c5baSBill Taylor 	int idx = start;
6159e39c5baSBill Taylor 	int devlength = 0;
6169e39c5baSBill Taylor 
6179e39c5baSBill Taylor 	thisnode = di_drv_first_node(drivername, rootnode);
6189e39c5baSBill Taylor 
6199e39c5baSBill Taylor 	if (thisnode == DI_NODE_NIL) {
6209e39c5baSBill Taylor 		logmsg(MSG_INFO, gettext("No %s nodes in this system\n"),
6219e39c5baSBill Taylor 		    drivername);
6229e39c5baSBill Taylor 		return (rv);
6239e39c5baSBill Taylor 	}
6249e39c5baSBill Taylor 
6259e39c5baSBill Taylor 	/* we've found one, at least */
6269e39c5baSBill Taylor 	for (; thisnode != DI_NODE_NIL; thisnode = di_drv_next_node(thisnode)) {
6279e39c5baSBill Taylor 
6289e39c5baSBill Taylor 		devpath = di_devfs_path(thisnode);
6299e39c5baSBill Taylor 
6309e39c5baSBill Taylor 		if ((newdev = calloc(1, sizeof (struct devicelist)))
6319e39c5baSBill Taylor 		    == NULL) {
6329e39c5baSBill Taylor 			logmsg(MSG_ERROR,
633ee5d8455SShantkumar Hiremath 			    gettext("tavor identification function: unable "
6349e39c5baSBill Taylor 			    "to allocate space for device entry\n"));
6359e39c5baSBill Taylor 			di_devfs_path_free(devpath);
6369e39c5baSBill Taylor 			return (rv);
6379e39c5baSBill Taylor 		}
6389e39c5baSBill Taylor 
6399e39c5baSBill Taylor 		/* calloc enough for /devices + devpath + ":devctl" + '\0' */
6409e39c5baSBill Taylor 		devlength = strlen(devpath) + strlen(devprefix) +
6419e39c5baSBill Taylor 		    strlen(devsuffix) + 2;
6429e39c5baSBill Taylor 
6439e39c5baSBill Taylor 		if ((newdev->access_devname = calloc(1, devlength)) == NULL) {
6449e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("Unable to calloc space "
6459e39c5baSBill Taylor 			    "for a devfs name\n"));
6469e39c5baSBill Taylor 			di_devfs_path_free(devpath);
6479e39c5baSBill Taylor 			(void) free(newdev);
6489e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
6499e39c5baSBill Taylor 		}
6509e39c5baSBill Taylor 		snprintf(newdev->access_devname, devlength,
6519e39c5baSBill Taylor 		    "%s%s%s", devprefix, devpath, devsuffix);
6529e39c5baSBill Taylor 
6539e39c5baSBill Taylor 		/* CHECK VARIOUS IB THINGS HERE */
6549e39c5baSBill Taylor 
6559e39c5baSBill Taylor 		if ((newdev->ident = calloc(1, sizeof (struct vpr))) == NULL) {
6569e39c5baSBill Taylor 			logmsg(MSG_ERROR,
6579e39c5baSBill Taylor 			    gettext("tavor: Unable to allocate space for a "
6589e39c5baSBill Taylor 			    "device identification record\n"));
6599e39c5baSBill Taylor 			(void) free(newdev->access_devname);
6609e39c5baSBill Taylor 			(void) free(newdev);
6619e39c5baSBill Taylor 			di_devfs_path_free(devpath);
6629e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
6639e39c5baSBill Taylor 		}
6649e39c5baSBill Taylor 
6659e39c5baSBill Taylor 		rv = tavor_identify(newdev);
6669e39c5baSBill Taylor 		if (rv == FWFLASH_FAILURE) {
6679e39c5baSBill Taylor 			(void) free(newdev->ident);
6689e39c5baSBill Taylor 			(void) free(newdev->access_devname);
6699e39c5baSBill Taylor 			(void) free(newdev);
6709e39c5baSBill Taylor 			di_devfs_path_free(devpath);
6719e39c5baSBill Taylor 			continue;
6729e39c5baSBill Taylor 		}
6739e39c5baSBill Taylor 
6749e39c5baSBill Taylor 		if ((newdev->drvname = calloc(1, strlen(drivername) + 1))
6759e39c5baSBill Taylor 		    == NULL) {
6769e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("Unable to allocate space "
6779e39c5baSBill Taylor 			    "for a driver name\n"));
6789e39c5baSBill Taylor 			(void) free(newdev->ident);
6799e39c5baSBill Taylor 			(void) free(newdev->access_devname);
6809e39c5baSBill Taylor 			(void) free(newdev);
6819e39c5baSBill Taylor 			di_devfs_path_free(devpath);
6829e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
6839e39c5baSBill Taylor 		}
6849e39c5baSBill Taylor 
6859e39c5baSBill Taylor 		(void) strlcpy(newdev->drvname, drivername,
6869e39c5baSBill Taylor 		    strlen(drivername) + 1);
6879e39c5baSBill Taylor 
6889e39c5baSBill Taylor 		/* this next bit is backwards compatibility - "IB\0" */
6899e39c5baSBill Taylor 		if ((newdev->classname = calloc(1, 3)) == NULL) {
6909e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("Unable to allocate space "
6919e39c5baSBill Taylor 			    "for a class name\n"));
6929e39c5baSBill Taylor 			(void) free(newdev->drvname);
6939e39c5baSBill Taylor 			(void) free(newdev->ident);
6949e39c5baSBill Taylor 			(void) free(newdev->access_devname);
6959e39c5baSBill Taylor 			(void) free(newdev);
6969e39c5baSBill Taylor 			di_devfs_path_free(devpath);
6979e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
6989e39c5baSBill Taylor 		}
6999e39c5baSBill Taylor 		(void) strlcpy(newdev->classname, "IB", 3);
7009e39c5baSBill Taylor 
7019e39c5baSBill Taylor 		newdev->index = idx;
7029e39c5baSBill Taylor 		++idx;
7039e39c5baSBill Taylor 		newdev->plugin = self;
7049e39c5baSBill Taylor 
7059e39c5baSBill Taylor 		di_devfs_path_free(devpath);
7069e39c5baSBill Taylor 		TAILQ_INSERT_TAIL(fw_devices, newdev, nextdev);
7079e39c5baSBill Taylor 	}
7089e39c5baSBill Taylor 
7099e39c5baSBill Taylor 	if (fwflash_debug != 0) {
7109e39c5baSBill Taylor 		struct devicelist *tempdev;
7119e39c5baSBill Taylor 
7129e39c5baSBill Taylor 		TAILQ_FOREACH(tempdev, fw_devices, nextdev) {
713*b67a60d6SShantkumar Hiremath 			logmsg(MSG_INFO, "fw_identify:\n");
7149e39c5baSBill Taylor 			logmsg(MSG_INFO, "\ttempdev @ 0x%lx\n"
7159e39c5baSBill Taylor 			    "\t\taccess_devname: %s\n"
7169e39c5baSBill Taylor 			    "\t\tdrvname: %s\tclassname: %s\n"
7179e39c5baSBill Taylor 			    "\t\tident->vid:   %s\n"
7189e39c5baSBill Taylor 			    "\t\tident->pid:   %s\n"
7199e39c5baSBill Taylor 			    "\t\tident->revid: %s\n"
7209e39c5baSBill Taylor 			    "\t\tindex: %d\n"
7219e39c5baSBill Taylor 			    "\t\tguid0: %s\n"
7229e39c5baSBill Taylor 			    "\t\tguid1: %s\n"
7239e39c5baSBill Taylor 			    "\t\tguid2: %s\n"
7249e39c5baSBill Taylor 			    "\t\tguid3: %s\n"
7259e39c5baSBill Taylor 			    "\t\tplugin @ 0x%lx\n\n",
7269e39c5baSBill Taylor 			    &tempdev,
7279e39c5baSBill Taylor 			    tempdev->access_devname,
7289e39c5baSBill Taylor 			    tempdev->drvname, newdev->classname,
7299e39c5baSBill Taylor 			    tempdev->ident->vid,
7309e39c5baSBill Taylor 			    tempdev->ident->pid,
7319e39c5baSBill Taylor 			    tempdev->ident->revid,
7329e39c5baSBill Taylor 			    tempdev->index,
733*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[0] ? tempdev->addresses[0] :
734*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
735*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[1] ? tempdev->addresses[1] :
736*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
737*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[2] ? tempdev->addresses[2] :
738*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
739*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[3] ? tempdev->addresses[3] :
740*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
7419e39c5baSBill Taylor 			    tempdev->plugin);
7429e39c5baSBill Taylor 		}
7439e39c5baSBill Taylor 	}
7449e39c5baSBill Taylor 
7459e39c5baSBill Taylor 	return (FWFLASH_SUCCESS);
7469e39c5baSBill Taylor }
7479e39c5baSBill Taylor 
7489e39c5baSBill Taylor 
7499e39c5baSBill Taylor 
7509e39c5baSBill Taylor int
fw_devinfo(struct devicelist * thisdev)7519e39c5baSBill Taylor fw_devinfo(struct devicelist *thisdev)
7529e39c5baSBill Taylor {
7539e39c5baSBill Taylor 
7549e39c5baSBill Taylor 	struct ib_encap_ident	*encap;
7559e39c5baSBill Taylor 
7569e39c5baSBill Taylor 
7579e39c5baSBill Taylor 	encap = (struct ib_encap_ident *)thisdev->ident->encap_ident;
7589e39c5baSBill Taylor 
7599e39c5baSBill Taylor 	fprintf(stdout, gettext("Device[%d] %s\n  Class [%s]\n"),
7609e39c5baSBill Taylor 	    thisdev->index, thisdev->access_devname, thisdev->classname);
7619e39c5baSBill Taylor 
7629e39c5baSBill Taylor 	fprintf(stdout, "\t");
7639e39c5baSBill Taylor 
7649e39c5baSBill Taylor 	/* Mellanox HCA Flash app note, p40, #4.2.3 table 9 */
7659e39c5baSBill Taylor 	fprintf(stdout,
7669e39c5baSBill Taylor 	    gettext("GUID: System Image - %s\n"),
7679e39c5baSBill Taylor 	    thisdev->addresses[3]);
7689e39c5baSBill Taylor 	fprintf(stdout,
7699e39c5baSBill Taylor 	    gettext("\t\tNode Image - %s\n"),
7709e39c5baSBill Taylor 	    thisdev->addresses[0]);
7719e39c5baSBill Taylor 	fprintf(stdout,
7729e39c5baSBill Taylor 	    gettext("\t\tPort 1\t   - %s\n"),
7739e39c5baSBill Taylor 	    thisdev->addresses[1]);
7749e39c5baSBill Taylor 	fprintf(stdout,
7759e39c5baSBill Taylor 	    gettext("\t\tPort 2\t   - %s\n"),
7769e39c5baSBill Taylor 	    thisdev->addresses[2]);
7779e39c5baSBill Taylor 
7789e39c5baSBill Taylor 	if (encap->pn_len != 0) {
7799e39c5baSBill Taylor 		fprintf(stdout,
7809e39c5baSBill Taylor 		    gettext("\tFirmware revision : %s\n"
781*b67a60d6SShantkumar Hiremath 		    "\tProduct\t\t: %s %X\n"
7829e39c5baSBill Taylor 		    "\tPSID\t\t: %s\n"),
7839e39c5baSBill Taylor 		    thisdev->ident->revid,
7849e39c5baSBill Taylor 		    encap->info.mlx_pn,
785*b67a60d6SShantkumar Hiremath 		    encap->hwrev,
7869e39c5baSBill Taylor 		    encap->info.mlx_psid);
787*b67a60d6SShantkumar Hiremath 	} else {
7889e39c5baSBill Taylor 		fprintf(stdout,
7899e39c5baSBill Taylor 		    gettext("\tFirmware revision : %s\n"
7909e39c5baSBill Taylor 		    "\tNo hardware information available for this "
7919e39c5baSBill Taylor 		    "device\n"), thisdev->ident->revid);
7929e39c5baSBill Taylor 	}
7939e39c5baSBill Taylor 	fprintf(stdout, "\n\n");
7949e39c5baSBill Taylor 
7959e39c5baSBill Taylor 	return (tavor_close(thisdev));
7969e39c5baSBill Taylor }
7979e39c5baSBill Taylor 
7989e39c5baSBill Taylor 
7999e39c5baSBill Taylor /*
8009e39c5baSBill Taylor  * Helper functions lurk beneath this point
8019e39c5baSBill Taylor  */
8029e39c5baSBill Taylor 
8039e39c5baSBill Taylor 
8049e39c5baSBill Taylor /*
8059e39c5baSBill Taylor  * tavor_identify performs the following actions:
8069e39c5baSBill Taylor  *
8079e39c5baSBill Taylor  *	allocates and assigns thisdev->vpr
8089e39c5baSBill Taylor  *
8099e39c5baSBill Taylor  *	allocates space for the 4 GUIDs which each IB device must have
8109e39c5baSBill Taylor  *	queries the tavor driver for this device's GUIDs
8119e39c5baSBill Taylor  *
8129e39c5baSBill Taylor  *	determines the hardware vendor, so that thisdev->vpr->vid
8139e39c5baSBill Taylor  *	can be set correctly
8149e39c5baSBill Taylor  */
8159e39c5baSBill Taylor static int
tavor_identify(struct devicelist * thisdev)8169e39c5baSBill Taylor tavor_identify(struct devicelist *thisdev)
8179e39c5baSBill Taylor {
8189e39c5baSBill Taylor 	int rv = FWFLASH_SUCCESS;
8199e39c5baSBill Taylor 	int fd, ret, i;
8209e39c5baSBill Taylor 
8219e39c5baSBill Taylor 	tavor_flash_init_ioctl_t	init_ioctl;
8229e39c5baSBill Taylor 	tavor_flash_ioctl_t		info;
8239e39c5baSBill Taylor 	struct ib_encap_ident		*manuf;
8249e39c5baSBill Taylor 	cfi_t				cfi;
8259e39c5baSBill Taylor 	char temppsid[17];
8269e39c5baSBill Taylor 	char rawpsid[16];
8279e39c5baSBill Taylor 
8289e39c5baSBill Taylor #if defined(_LITTLE_ENDIAN)
8299e39c5baSBill Taylor 	uint32_t			*ptr;
8309e39c5baSBill Taylor #endif
8319e39c5baSBill Taylor 
8329e39c5baSBill Taylor 	/* open the device */
8339e39c5baSBill Taylor 	/* hook thisdev->ident->encap_ident to ib_encap_ident */
8349e39c5baSBill Taylor 	/* check that all the bits are sane */
8359e39c5baSBill Taylor 	/* return success, if warranted */
8369e39c5baSBill Taylor 
8379e39c5baSBill Taylor 	errno = 0;
8389e39c5baSBill Taylor 	if ((fd = open(thisdev->access_devname, O_RDONLY)) < 0) {
8399e39c5baSBill Taylor 		logmsg(MSG_INFO,
8409e39c5baSBill Taylor 		    gettext("tavor: Unable to open a %s-attached "
8419e39c5baSBill Taylor 		    "device node: %s: %s\n"), drivername,
8429e39c5baSBill Taylor 		    thisdev->access_devname, strerror(errno));
8439e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
8449e39c5baSBill Taylor 	}
8459e39c5baSBill Taylor 
8469e39c5baSBill Taylor 	if ((manuf = calloc(1, sizeof (ib_encap_ident_t))) == NULL) {
8479e39c5baSBill Taylor 		logmsg(MSG_ERROR,
8489e39c5baSBill Taylor 		    gettext("tavor: Unable to calloc space for a "
8499e39c5baSBill Taylor 		    "%s-attached handle structure\n"),
8509e39c5baSBill Taylor 		    drivername);
8519e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
8529e39c5baSBill Taylor 	}
8539e39c5baSBill Taylor 	manuf->magic = FWFLASH_IB_MAGIC_NUMBER;
8549e39c5baSBill Taylor 	manuf->state = FWFLASH_IB_STATE_NONE;
8559e39c5baSBill Taylor 	manuf->fd = fd;
8569e39c5baSBill Taylor 
8579e39c5baSBill Taylor 	thisdev->ident->encap_ident = manuf;
8589e39c5baSBill Taylor 
859ee5d8455SShantkumar Hiremath 	bzero(&init_ioctl, sizeof (tavor_flash_init_ioctl_t));
860ee5d8455SShantkumar Hiremath 	bzero(&cfi, sizeof (cfi_t));
8619e39c5baSBill Taylor 	/*
8629e39c5baSBill Taylor 	 * Inform driver that this command supports the Intel Extended
8639e39c5baSBill Taylor 	 * CFI command set.
8649e39c5baSBill Taylor 	 */
8659e39c5baSBill Taylor 	cfi.cfi_char[0x10] = 'M';
8669e39c5baSBill Taylor 	cfi.cfi_char[0x11] = 'X';
8679e39c5baSBill Taylor 	cfi.cfi_char[0x12] = '2';
8689e39c5baSBill Taylor 	init_ioctl.tf_cfi_info[0x4] = MLXSWAPBITS32(cfi.cfi_int[0x4]);
8699e39c5baSBill Taylor 
8709e39c5baSBill Taylor 	errno = 0;
8719e39c5baSBill Taylor 	ret = ioctl(fd, TAVOR_IOCTL_FLASH_INIT, &init_ioctl);
8729e39c5baSBill Taylor 	if (ret < 0) {
8739e39c5baSBill Taylor 		logmsg(MSG_ERROR,
8749e39c5baSBill Taylor 		    gettext("ib: TAVOR_IOCTL_FLASH_INIT failed: %s\n"),
8759e39c5baSBill Taylor 		    strerror(errno));
8769e39c5baSBill Taylor 		free(manuf);
8779e39c5baSBill Taylor 		close(fd);
8789e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
8799e39c5baSBill Taylor 	}
8809e39c5baSBill Taylor 
8819e39c5baSBill Taylor 	manuf->hwrev = init_ioctl.tf_hwrev;
8829e39c5baSBill Taylor 
883*b67a60d6SShantkumar Hiremath 	logmsg(MSG_INFO, "tavor_identify: init_ioctl: hwrev: %X, "
884*b67a60d6SShantkumar Hiremath 	    "fwver: %d.%d.%04d\n", init_ioctl.tf_hwrev,
885*b67a60d6SShantkumar Hiremath 	    init_ioctl.tf_fwrev.tfi_maj, init_ioctl.tf_fwrev.tfi_min,
886*b67a60d6SShantkumar Hiremath 	    init_ioctl.tf_fwrev.tfi_sub);
887*b67a60d6SShantkumar Hiremath 
8889e39c5baSBill Taylor 	/*
8899e39c5baSBill Taylor 	 * Determine whether the attached driver supports the Intel or
8909e39c5baSBill Taylor 	 * AMD Extended CFI command sets. If it doesn't support either,
8919e39c5baSBill Taylor 	 * then we're hosed, so error out.
8929e39c5baSBill Taylor 	 */
8939e39c5baSBill Taylor 	for (i = 0; i < TAVOR_FLASH_CFI_SIZE_QUADLET; i++) {
8949e39c5baSBill Taylor 		cfi.cfi_int[i] = MLXSWAPBITS32(init_ioctl.tf_cfi_info[i]);
8959e39c5baSBill Taylor 	}
8969e39c5baSBill Taylor 	manuf->cmd_set = cfi.cfi_char[0x13];
8979e39c5baSBill Taylor 
8989e39c5baSBill Taylor 	if (cfi.cfi_char[0x10] == 'Q' &&
8999e39c5baSBill Taylor 	    cfi.cfi_char[0x11] == 'R' &&
9009e39c5baSBill Taylor 	    cfi.cfi_char[0x12] == 'Y') {
9019e39c5baSBill Taylor 		/* make sure the cmd set is AMD */
9029e39c5baSBill Taylor 		if (manuf->cmd_set != TAVOR_FLASH_AMD_CMDSET) {
9039e39c5baSBill Taylor 			logmsg(MSG_ERROR,
9049e39c5baSBill Taylor 			    gettext("tavor: Unsupported flash device "
9059e39c5baSBill Taylor 			    "command set\n"));
9069e39c5baSBill Taylor 			free(manuf);
9079e39c5baSBill Taylor 			close(fd);
9089e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
9099e39c5baSBill Taylor 		}
9109e39c5baSBill Taylor 		/* set some defaults */
911ee5d8455SShantkumar Hiremath 		manuf->sector_sz = TAVOR_FLASH_SECTOR_SZ_DEFAULT;
9129e39c5baSBill Taylor 		manuf->device_sz = TAVOR_FLASH_DEVICE_SZ_DEFAULT;
913ee5d8455SShantkumar Hiremath 		logmsg(MSG_INFO, "tavor_identify: CMDSET is AMD, SectorSz "
914ee5d8455SShantkumar Hiremath 		    "are default \n");
9159e39c5baSBill Taylor 	} else {
9169e39c5baSBill Taylor 		if (manuf->cmd_set != TAVOR_FLASH_AMD_CMDSET &&
9179e39c5baSBill Taylor 		    manuf->cmd_set != TAVOR_FLASH_INTEL_CMDSET) {
9189e39c5baSBill Taylor 			logmsg(MSG_ERROR,
9199e39c5baSBill Taylor 			    gettext("ib: Unknown flash device command set\n"));
9209e39c5baSBill Taylor 			free(manuf);
9219e39c5baSBill Taylor 			close(fd);
9229e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
9239e39c5baSBill Taylor 		}
9249e39c5baSBill Taylor 		/* read from the CFI data */
9259e39c5baSBill Taylor 		manuf->sector_sz = ((cfi.cfi_char[0x30] << 8) |
9269e39c5baSBill Taylor 		    cfi.cfi_char[0x2F]) << 8;
9279e39c5baSBill Taylor 		manuf->device_sz = 0x1 << cfi.cfi_char[0x27];
928ee5d8455SShantkumar Hiremath 		logmsg(MSG_INFO, "tavor_identify: SectorSz is from CFI Data\n");
9299e39c5baSBill Taylor 	}
9309e39c5baSBill Taylor 
931ee5d8455SShantkumar Hiremath 	logmsg(MSG_INFO, "tavor_identify: sector_sz: 0x%08x dev_sz: 0x%08x\n",
9329e39c5baSBill Taylor 	    manuf->sector_sz, manuf->device_sz);
9339e39c5baSBill Taylor 
9349e39c5baSBill Taylor 	manuf->state |= FWFLASH_IB_STATE_MMAP;
9359e39c5baSBill Taylor 
9369e39c5baSBill Taylor 	/* set firmware revision */
9379e39c5baSBill Taylor 	manuf->fw_rev.major = init_ioctl.tf_fwrev.tfi_maj;
9389e39c5baSBill Taylor 	manuf->fw_rev.minor = init_ioctl.tf_fwrev.tfi_min;
9399e39c5baSBill Taylor 	manuf->fw_rev.subminor = init_ioctl.tf_fwrev.tfi_sub;
9409e39c5baSBill Taylor 
941ee5d8455SShantkumar Hiremath 	logmsg(MSG_INFO, "tavor_identify: pn_len %d hwpn %s \n",
942ee5d8455SShantkumar Hiremath 	    init_ioctl.tf_pn_len,
943ee5d8455SShantkumar Hiremath 	    (init_ioctl.tf_pn_len != 0) ? init_ioctl.tf_hwpn : "(null)");
944ee5d8455SShantkumar Hiremath 
9459e39c5baSBill Taylor 	if (((thisdev->ident->vid = calloc(1, MLX_VPR_VIDLEN + 1)) == NULL) ||
9469e39c5baSBill Taylor 	    ((thisdev->ident->revid = calloc(1, MLX_VPR_REVLEN + 1)) == NULL)) {
9479e39c5baSBill Taylor 
9489e39c5baSBill Taylor 		logmsg(MSG_ERROR,
9499e39c5baSBill Taylor 		    gettext("ib: Unable to allocate space for a VPR "
9509e39c5baSBill Taylor 		    "record.\n"));
9519e39c5baSBill Taylor 		free(thisdev->ident);
9529e39c5baSBill Taylor 		free(manuf->info.mlx_pn);
9539e39c5baSBill Taylor 		free(manuf->info.mlx_psid);
9549e39c5baSBill Taylor 		free(manuf->info.mlx_id);
9559e39c5baSBill Taylor 		free(manuf);
9569e39c5baSBill Taylor 		close(fd);
9579e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
9589e39c5baSBill Taylor 	}
9599e39c5baSBill Taylor 	(void) strlcpy(thisdev->ident->vid, "MELLANOX", MLX_VPR_VIDLEN);
9609e39c5baSBill Taylor 	/*
9619e39c5baSBill Taylor 	 * We actually want the hwrev field from the ioctl above.
9629e39c5baSBill Taylor 	 * Until we find out otherwise, add it onto the end of the
9639e39c5baSBill Taylor 	 * firmware version details.
9649e39c5baSBill Taylor 	 */
9659e39c5baSBill Taylor 
966ee5d8455SShantkumar Hiremath 	snprintf(thisdev->ident->revid, MLX_VPR_REVLEN, "%d.%d.%03d",
9679e39c5baSBill Taylor 	    manuf->fw_rev.major, manuf->fw_rev.minor,
9689e39c5baSBill Taylor 	    manuf->fw_rev.subminor);
9699e39c5baSBill Taylor 
9709e39c5baSBill Taylor 	bzero(manuf->ibguids, sizeof (manuf->ibguids));
9719e39c5baSBill Taylor 
9729e39c5baSBill Taylor 	/*
9739e39c5baSBill Taylor 	 * For convenience we read in the Invariant Sector as
9749e39c5baSBill Taylor 	 * well as both the Primary and Secondary Pointer Sectors
9759e39c5baSBill Taylor 	 */
9769e39c5baSBill Taylor 
9779e39c5baSBill Taylor 	if ((manuf->inv = calloc(1, manuf->sector_sz)) == NULL) {
9789e39c5baSBill Taylor 		logmsg(MSG_ERROR,
9799e39c5baSBill Taylor 		    gettext("tavor: Unable to allocate space for storing "
9809e39c5baSBill Taylor 		    "the HCA's Invariant Sector\n"));
9819e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
9829e39c5baSBill Taylor 	}
9839e39c5baSBill Taylor 	bzero(&info, sizeof (tavor_flash_ioctl_t));
9849e39c5baSBill Taylor 
9859e39c5baSBill Taylor 	info.tf_type = TAVOR_FLASH_READ_SECTOR;
9869e39c5baSBill Taylor 	info.tf_sector = (caddr_t)manuf->inv;
9879e39c5baSBill Taylor 	info.tf_sector_num = 0;
9889e39c5baSBill Taylor 
9899e39c5baSBill Taylor 	errno = 0;
9909e39c5baSBill Taylor 
9919e39c5baSBill Taylor 	if ((rv = ioctl(manuf->fd, TAVOR_IOCTL_FLASH_READ, &info))
9929e39c5baSBill Taylor 	    < 0) {
9939e39c5baSBill Taylor 		logmsg(MSG_ERROR,
9949e39c5baSBill Taylor 		    gettext("tavor: Unable to read HCA Invariant Sector\n"));
9959e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
9969e39c5baSBill Taylor 	}
9979e39c5baSBill Taylor 
9989e39c5baSBill Taylor #if defined(_LITTLE_ENDIAN)
9999e39c5baSBill Taylor 	ptr = (uint32_t *)(uintptr_t)manuf->inv;
10009e39c5baSBill Taylor 	for (i = 0; i < (manuf->sector_sz / 4); i++) {
10019e39c5baSBill Taylor 		ptr[i] = htonl(ptr[i]);
10029e39c5baSBill Taylor 	}
10039e39c5baSBill Taylor #endif
10049e39c5baSBill Taylor 
10059e39c5baSBill Taylor 	if ((manuf->pps = calloc(1, manuf->sector_sz)) == NULL) {
10069e39c5baSBill Taylor 		logmsg(MSG_ERROR,
10079e39c5baSBill Taylor 		    gettext("tavor: Unable to allocate space for storing "
10089e39c5baSBill Taylor 		    "the HCA's Primary Pointer Sector\n"));
10099e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
10109e39c5baSBill Taylor 	}
10119e39c5baSBill Taylor 	bzero(&info, sizeof (tavor_flash_ioctl_t));
10129e39c5baSBill Taylor 
10139e39c5baSBill Taylor 	info.tf_type = TAVOR_FLASH_READ_SECTOR;
10149e39c5baSBill Taylor 	info.tf_sector = (caddr_t)manuf->pps;
10159e39c5baSBill Taylor 	info.tf_sector_num = 1;
10169e39c5baSBill Taylor 
10179e39c5baSBill Taylor 	errno = 0;
10189e39c5baSBill Taylor 
10199e39c5baSBill Taylor 	if ((rv = ioctl(manuf->fd, TAVOR_IOCTL_FLASH_READ, &info))
10209e39c5baSBill Taylor 	    < 0) {
10219e39c5baSBill Taylor 		logmsg(MSG_ERROR,
10229e39c5baSBill Taylor 		    gettext("tavor: Unable to read HCA Primary "
10239e39c5baSBill Taylor 		    "Pointer Sector\n"));
10249e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
10259e39c5baSBill Taylor 	}
10269e39c5baSBill Taylor 
10279e39c5baSBill Taylor #if defined(_LITTLE_ENDIAN)
10289e39c5baSBill Taylor 	ptr = (uint32_t *)(uintptr_t)manuf->pps;
10299e39c5baSBill Taylor 	for (i = 0; i < (manuf->sector_sz / 4); i++) {
10309e39c5baSBill Taylor 		ptr[i] = htonl(ptr[i]);
10319e39c5baSBill Taylor 	}
10329e39c5baSBill Taylor #endif
10339e39c5baSBill Taylor 
10349e39c5baSBill Taylor 	if ((manuf->sps = calloc(1, manuf->sector_sz)) == NULL) {
10359e39c5baSBill Taylor 		logmsg(MSG_ERROR,