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  * The reference for the functions in this file is the
289e39c5baSBill Taylor  *
299e39c5baSBill Taylor  *	Mellanox HCA Flash Programming Application Note
309e39c5baSBill Taylor  * (Mellanox document number 2205AN) rev 1.45, 2007.
319e39c5baSBill Taylor  * Chapter 4 in particular.
329e39c5baSBill Taylor  */
339e39c5baSBill Taylor 
349e39c5baSBill Taylor #include <stdio.h>
359e39c5baSBill Taylor #include <stdlib.h>
369e39c5baSBill Taylor #include <unistd.h>
379e39c5baSBill Taylor #include <sys/types.h>
389e39c5baSBill Taylor #include <sys/stat.h>
399e39c5baSBill Taylor #include <sys/sysmacros.h>
409e39c5baSBill Taylor #include <sys/queue.h>
419e39c5baSBill Taylor #include <fcntl.h>
429e39c5baSBill Taylor #include <ctype.h>
439e39c5baSBill Taylor #include <string.h>
449e39c5baSBill Taylor #include <strings.h>
459e39c5baSBill Taylor 
469e39c5baSBill Taylor #include <sys/byteorder.h>
479e39c5baSBill Taylor 
489e39c5baSBill Taylor #include <libintl.h> /* for gettext(3c) */
499e39c5baSBill Taylor 
509e39c5baSBill Taylor #include <fwflash/fwflash.h>
519e39c5baSBill Taylor #include "../../hdrs/hermon_ib.h"
529e39c5baSBill Taylor 
539e39c5baSBill Taylor char *devprefix = "/devices";
549e39c5baSBill Taylor char drivername[] = "hermon\0";
559e39c5baSBill Taylor char *devsuffix = ":devctl";
569e39c5baSBill Taylor 
579e39c5baSBill Taylor extern di_node_t rootnode;
589e39c5baSBill Taylor extern int errno;
599e39c5baSBill Taylor extern struct fw_plugin *self;
609e39c5baSBill Taylor extern struct vrfyplugin *verifier;
619e39c5baSBill Taylor extern int fwflash_debug;
629e39c5baSBill Taylor 
639e39c5baSBill Taylor /* required functions for this plugin */
649e39c5baSBill Taylor int fw_readfw(struct devicelist *device, char *filename);
659e39c5baSBill Taylor int fw_writefw(struct devicelist *device);
669e39c5baSBill Taylor int fw_identify(int start);
679e39c5baSBill Taylor int fw_devinfo();
689e39c5baSBill Taylor 
699e39c5baSBill Taylor 
709e39c5baSBill Taylor /* helper functions */
719e39c5baSBill Taylor static int cnx_identify(struct devicelist *thisdev);
729e39c5baSBill Taylor static int cnx_get_guids(ib_cnx_encap_ident_t *handle);
739e39c5baSBill Taylor static int cnx_close(struct devicelist *flashdev);
749e39c5baSBill Taylor static int cnx_check_for_magic_pattern(ib_cnx_encap_ident_t *hdl, uint32_t adr);
759e39c5baSBill Taylor static uint32_t cnx_get_log2_chunk_size_f_hdl(ib_cnx_encap_ident_t *handle,
769e39c5baSBill Taylor     int type);
779e39c5baSBill Taylor static uint32_t cnx_get_log2_chunk_size(uint32_t chunk_size_word);
789e39c5baSBill Taylor static uint32_t cnx_cont2phys(uint32_t log2_chunk_sz, uint32_t cont_addr,
799e39c5baSBill Taylor     int type);
809e39c5baSBill Taylor static uint32_t cnx_get_image_size_f_hdl(ib_cnx_encap_ident_t *hdl, int type);
819e39c5baSBill Taylor static void cnx_local_set_guid_crc_img(uint32_t offset, uint32_t guid_crc_size,
829e39c5baSBill Taylor     uint32_t guid_crc_offset);
839e39c5baSBill Taylor static int cnx_read_image(ib_cnx_encap_ident_t *handle);
849e39c5baSBill Taylor static int cnx_write_file(ib_cnx_encap_ident_t *handle, const char *filename);
859e39c5baSBill Taylor static int cnx_verify_image(ib_cnx_encap_ident_t *handle, int type);
869e39c5baSBill Taylor static int cnx_read_guids(ib_cnx_encap_ident_t *handle, int type);
879e39c5baSBill Taylor static int cnx_set_guids(ib_cnx_encap_ident_t *handle, void *arg);
889e39c5baSBill Taylor static int cnx_write_image(ib_cnx_encap_ident_t *handle, int type);
899e39c5baSBill Taylor static int cnx_read_ioctl(ib_cnx_encap_ident_t *hdl,
909e39c5baSBill Taylor     hermon_flash_ioctl_t *info);
919e39c5baSBill Taylor static int cnx_write_ioctl(ib_cnx_encap_ident_t *hdl,
929e39c5baSBill Taylor     hermon_flash_ioctl_t *info);
939e39c5baSBill Taylor static int cnx_erase_sector_ioctl(ib_cnx_encap_ident_t *hdl,
949e39c5baSBill Taylor     hermon_flash_ioctl_t *info);
959e39c5baSBill Taylor static int cnx_find_magic_n_chnk_sz(ib_cnx_encap_ident_t *handle, int type);
969e39c5baSBill Taylor static int cnx_get_image_info(ib_cnx_encap_ident_t *handle);
979e39c5baSBill Taylor 
989e39c5baSBill Taylor 
999e39c5baSBill Taylor int
fw_readfw(struct devicelist * flashdev,char * filename)1009e39c5baSBill Taylor fw_readfw(struct devicelist *flashdev, char *filename)
1019e39c5baSBill Taylor {
1029e39c5baSBill Taylor 	ib_cnx_encap_ident_t	*manuf;
1039e39c5baSBill Taylor 	int 			rv = FWFLASH_SUCCESS;
1049e39c5baSBill Taylor 
1059e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_readfw: filename %s\n", filename);
1069e39c5baSBill Taylor 
1079e39c5baSBill Taylor 	manuf = (ib_cnx_encap_ident_t *)flashdev->ident->encap_ident;
1089e39c5baSBill Taylor 	if (CNX_I_CHECK_HANDLE(manuf)) {
1099e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Invalid Handle for "
1109e39c5baSBill Taylor 		    "device %s! \n"), flashdev->access_devname);
1119e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
1129e39c5baSBill Taylor 	}
1139e39c5baSBill Taylor 
1149e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_identify should have read the image. "
1159e39c5baSBill Taylor 	    "state 0x%x\n", manuf->state);
1169e39c5baSBill Taylor 
1179e39c5baSBill Taylor 	rv = cnx_read_image(manuf);
1189e39c5baSBill Taylor 	if (rv != FWFLASH_SUCCESS) {
1199e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Failed to read any valid "
1209e39c5baSBill Taylor 		    "image on device (%s)\n"), flashdev->access_devname);
1219e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("Aborting read.\n"));
1229e39c5baSBill Taylor 	} else {
1239e39c5baSBill Taylor 		rv = cnx_write_file(manuf, filename);
1249e39c5baSBill Taylor 	}
1259e39c5baSBill Taylor 
1269e39c5baSBill Taylor 	cnx_close(flashdev);
1279e39c5baSBill Taylor 	return (rv);
1289e39c5baSBill Taylor }
1299e39c5baSBill Taylor 
1309e39c5baSBill Taylor 
1319e39c5baSBill Taylor /*
1329e39c5baSBill Taylor  * If we're invoking fw_writefw, then flashdev is a valid,
1339e39c5baSBill Taylor  * flashable device as determined by fw_identify().
1349e39c5baSBill Taylor  *
1359e39c5baSBill Taylor  * If verifier is null, then we haven't been called following a firmware
1369e39c5baSBill Taylor  * image verification load operation.
1379e39c5baSBill Taylor  */
1389e39c5baSBill Taylor int
fw_writefw(struct devicelist * flashdev)1399e39c5baSBill Taylor fw_writefw(struct devicelist *flashdev)
1409e39c5baSBill Taylor {
1419e39c5baSBill Taylor 	ib_cnx_encap_ident_t	*manuf;
1429e39c5baSBill Taylor 	int			i, j, k;
1439e39c5baSBill Taylor 
1449e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_writefw\n");
1459e39c5baSBill Taylor 
1469e39c5baSBill Taylor 	manuf = (ib_cnx_encap_ident_t *)flashdev->ident->encap_ident;
1479e39c5baSBill Taylor 
1489e39c5baSBill Taylor 	if (CNX_I_CHECK_HANDLE(manuf)) {
1499e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Invalid Handle for "
1509e39c5baSBill Taylor 		    "device %s! \n"), flashdev->access_devname);
1519e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
1529e39c5baSBill Taylor 	}
1539e39c5baSBill Taylor 
1549e39c5baSBill Taylor 	/*
1559e39c5baSBill Taylor 	 * Try the primary first, then the secondary.
1569e39c5baSBill Taylor 	 * If we get here, then the verifier has _already_ checked that
1579e39c5baSBill Taylor 	 * the part number in the firmware image matches that in the HCA,
1589e39c5baSBill Taylor 	 * so we only need this check if there's no hardware info available
1599e39c5baSBill Taylor 	 * already after running through fw_identify().
1609e39c5baSBill Taylor 	 */
1619e39c5baSBill Taylor 	if (manuf->pn_len == 0) {
1629e39c5baSBill Taylor 		int resp;
1639e39c5baSBill Taylor 
1649e39c5baSBill Taylor 		(void) fprintf(stderr, gettext("Unable to completely verify "
1659e39c5baSBill Taylor 		    "that this firmware image (%s) is compatible with your "
1669e39c5baSBill Taylor 		    "HCA %s"), verifier->imgfile, flashdev->access_devname);
1679e39c5baSBill Taylor 		(void) fprintf(stderr, gettext("Do you really want to "
1689e39c5baSBill Taylor 		    "continue? (Y/N): "));
1699e39c5baSBill Taylor 		(void) fflush(stdin);
1709e39c5baSBill Taylor 		resp = getchar();
1719e39c5baSBill Taylor 		if (resp != 'Y' && resp != 'y') {
1729e39c5baSBill Taylor 			(void) fprintf(stderr, gettext("Not proceeding with "
1739e39c5baSBill Taylor 			    "flash operation of %s on %s"),
1749e39c5baSBill Taylor 			    verifier->imgfile, flashdev->access_devname);
1759e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
1769e39c5baSBill Taylor 		}
1779e39c5baSBill Taylor 	}
1789e39c5baSBill Taylor 
1799e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_writefw: Using Existing GUIDs.\n");
1809e39c5baSBill Taylor 	manuf->state |=
1819e39c5baSBill Taylor 	    FWFLASH_IB_STATE_GUIDN |
1829e39c5baSBill Taylor 	    FWFLASH_IB_STATE_GUID1 |
1839e39c5baSBill Taylor 	    FWFLASH_IB_STATE_GUID2 |
1849e39c5baSBill Taylor 	    FWFLASH_IB_STATE_GUIDS;
1859e39c5baSBill Taylor 	if (cnx_set_guids(manuf, manuf->ibguids) != FWFLASH_SUCCESS) {
1869e39c5baSBill Taylor 		logmsg(MSG_WARN, gettext("hermon: Failed to set GUIDs"));
1879e39c5baSBill Taylor 	}
1889e39c5baSBill Taylor 
1899e39c5baSBill Taylor 	/*
1909e39c5baSBill Taylor 	 * Update both Primary and Secondary images
1919e39c5baSBill Taylor 	 *
1929e39c5baSBill Taylor 	 * For Failsafe firmware image update, if the current image (i.e.
1939e39c5baSBill Taylor 	 * containing a magic pattern) on the Flash is stored on the Primary
1949e39c5baSBill Taylor 	 * location, burn the new image to the Secondary location first,
1959e39c5baSBill Taylor 	 * or vice versa.
1969e39c5baSBill Taylor 	 */
1979e39c5baSBill Taylor 
1989e39c5baSBill Taylor 	/* Note Current Image location. */
1999e39c5baSBill Taylor 	j = manuf->state &
2009e39c5baSBill Taylor 	    (FWFLASH_IB_STATE_IMAGE_PRI | FWFLASH_IB_STATE_IMAGE_SEC);
2019e39c5baSBill Taylor 
2029e39c5baSBill Taylor 	/*
2039e39c5baSBill Taylor 	 * If we find that current image location is not found, no worries
2049e39c5baSBill Taylor 	 * we shall default to PRIMARY, and proceed with burning anyway.
2059e39c5baSBill Taylor 	 */
2069e39c5baSBill Taylor 	if (j == 0)
2079e39c5baSBill Taylor 		j = FWFLASH_IB_STATE_IMAGE_PRI;
2089e39c5baSBill Taylor 
2099e39c5baSBill Taylor 	for (i = FWFLASH_FLASH_IMAGES; i > 0; i--) {
2109e39c5baSBill Taylor 		char *type;
2119e39c5baSBill Taylor 
2129e39c5baSBill Taylor 		if (i == 2) {
2139e39c5baSBill Taylor 			if (j == 2)
2149e39c5baSBill Taylor 				k = 1;	/* Burn PRI First */
2159e39c5baSBill Taylor 			else
2169e39c5baSBill Taylor 				k = 2;	/* Burn SEC First */
2179e39c5baSBill Taylor 		} else {
2189e39c5baSBill Taylor 			if (k == 2)
2199e39c5baSBill Taylor 				k = 1;	/* Burn PRI next */
2209e39c5baSBill Taylor 			else
2219e39c5baSBill Taylor 				k = 2;	/* Burn SEC next */
2229e39c5baSBill Taylor 		}
2239e39c5baSBill Taylor 		type = ((k == 1) ? "Primary" : "Secondary");
2249e39c5baSBill Taylor 
2259e39c5baSBill Taylor 		logmsg(MSG_INFO, "hermon: fw_write: UPDATING %s image\n", type);
2269e39c5baSBill Taylor 
2279e39c5baSBill Taylor 		if (cnx_write_image(manuf, k) != FWFLASH_SUCCESS) {
2289e39c5baSBill Taylor 			(void) fprintf(stderr,
2299e39c5baSBill Taylor 			    gettext("Failed to update %s image on device %s"),
2309e39c5baSBill Taylor 			    type, flashdev->access_devname);
2319e39c5baSBill Taylor 			goto out;
2329e39c5baSBill Taylor 		}
2339e39c5baSBill Taylor 
2349e39c5baSBill Taylor 		logmsg(MSG_INFO, "hermon: fw_write: Verify %s image..\n", type);
2359e39c5baSBill Taylor 		if (cnx_verify_image(manuf, k) != FWFLASH_SUCCESS) {
2369e39c5baSBill Taylor 			(void) fprintf(stderr,
2379e39c5baSBill Taylor 			    gettext("Failed to verify %s image for device %s"),
2389e39c5baSBill Taylor 			    type, flashdev->access_devname);
2399e39c5baSBill Taylor 			goto out;
2409e39c5baSBill Taylor 		}
2419e39c5baSBill Taylor 	}
2429e39c5baSBill Taylor out:
2439e39c5baSBill Taylor 	/* final update marker to the user */
2449e39c5baSBill Taylor 	(void) printf(" +\n");
2459e39c5baSBill Taylor 	return (cnx_close(flashdev));
2469e39c5baSBill Taylor }
2479e39c5baSBill Taylor 
2489e39c5baSBill Taylor 
2499e39c5baSBill Taylor /*
2509e39c5baSBill Taylor  * The fw_identify() function walks the device tree trying to find
2519e39c5baSBill Taylor  * devices which this plugin can work with.
2529e39c5baSBill Taylor  *
2539e39c5baSBill Taylor  * The parameter "start" gives us the starting index number
2549e39c5baSBill Taylor  * to give the device when we add it to the fw_devices list.
2559e39c5baSBill Taylor  *
2569e39c5baSBill Taylor  * firstdev is allocated by us and we add space as necessary
2579e39c5baSBill Taylor  */
2589e39c5baSBill Taylor int
fw_identify(int start)2599e39c5baSBill Taylor fw_identify(int start)
2609e39c5baSBill Taylor {
2619e39c5baSBill Taylor 	int		rv = FWFLASH_FAILURE;
2629e39c5baSBill Taylor 	di_node_t	thisnode;
2639e39c5baSBill Taylor 	struct devicelist *newdev;
2649e39c5baSBill Taylor 	char		*devpath;
2659e39c5baSBill Taylor 	int		idx = start;
2669e39c5baSBill Taylor 	int		devlength = 0;
2679e39c5baSBill Taylor 
2689e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_identify\n");
2699e39c5baSBill Taylor 	thisnode = di_drv_first_node(drivername, rootnode);
2709e39c5baSBill Taylor 
2719e39c5baSBill Taylor 	if (thisnode == DI_NODE_NIL) {
2729e39c5baSBill Taylor 		logmsg(MSG_INFO, gettext("No %s nodes in this system\n"),
2739e39c5baSBill Taylor 		    drivername);
2749e39c5baSBill Taylor 		return (rv);
2759e39c5baSBill Taylor 	}
2769e39c5baSBill Taylor 
2779e39c5baSBill Taylor 	/* we've found one, at least */
2789e39c5baSBill Taylor 	for (; thisnode != DI_NODE_NIL; thisnode = di_drv_next_node(thisnode)) {
2799e39c5baSBill Taylor 
2809e39c5baSBill Taylor 		devpath = di_devfs_path(thisnode);
2819e39c5baSBill Taylor 
2829e39c5baSBill Taylor 		if ((newdev = calloc(1, sizeof (struct devicelist))) == NULL) {
2839e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unable to allocate "
2849e39c5baSBill Taylor 			    "space for device entry\n"));
2859e39c5baSBill Taylor 			di_devfs_path_free(devpath);
2869e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
2879e39c5baSBill Taylor 		}
2889e39c5baSBill Taylor 
2899e39c5baSBill Taylor 		/* calloc enough for /devices + devpath + ":devctl" + '\0' */
2909e39c5baSBill Taylor 		devlength = strlen(devpath) + strlen(devprefix) +
2919e39c5baSBill Taylor 		    strlen(devsuffix) + 2;
2929e39c5baSBill Taylor 
2939e39c5baSBill Taylor 		if ((newdev->access_devname = calloc(1, devlength)) == NULL) {
2949e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unable to allocate "
2959e39c5baSBill Taylor 			    "space for a devfs name\n"));
2969e39c5baSBill Taylor 			(void) free(newdev);
2979e39c5baSBill Taylor 			di_devfs_path_free(devpath);
2989e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
2999e39c5baSBill Taylor 		}
3009e39c5baSBill Taylor 		snprintf(newdev->access_devname, devlength,
3019e39c5baSBill Taylor 		    "%s%s%s", devprefix, devpath, devsuffix);
3029e39c5baSBill Taylor 
3039e39c5baSBill Taylor 		if ((newdev->ident = calloc(1, sizeof (struct vpr))) == NULL) {
3049e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unable to allocate "
3059e39c5baSBill Taylor 			    "space for a device identification record\n"));
3069e39c5baSBill Taylor 			(void) free(newdev->access_devname);
3079e39c5baSBill Taylor 			(void) free(newdev);
3089e39c5baSBill Taylor 			di_devfs_path_free(devpath);
3099e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
3109e39c5baSBill Taylor 		}
3119e39c5baSBill Taylor 
3129e39c5baSBill Taylor 		/* CHECK VARIOUS IB THINGS HERE */
3139e39c5baSBill Taylor 		rv = cnx_identify(newdev);
3149e39c5baSBill Taylor 		if (rv == FWFLASH_FAILURE) {
3159e39c5baSBill Taylor 			(void) free(newdev->ident);
3169e39c5baSBill Taylor 			(void) free(newdev->access_devname);
3179e39c5baSBill Taylor 			(void) free(newdev);
3189e39c5baSBill Taylor 			di_devfs_path_free(devpath);
3199e39c5baSBill Taylor 			continue;
3209e39c5baSBill Taylor 		}
3219e39c5baSBill Taylor 
3229e39c5baSBill Taylor 		if ((newdev->drvname = calloc(1, strlen(drivername) + 1))
3239e39c5baSBill Taylor 		    == NULL) {
3249e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unable to allocate"
3259e39c5baSBill Taylor 			    " space for a driver name\n"));
3269e39c5baSBill Taylor 			(void) free(newdev->ident);
3279e39c5baSBill Taylor 			(void) free(newdev->access_devname);
3289e39c5baSBill Taylor 			(void) free(newdev);
3299e39c5baSBill Taylor 			di_devfs_path_free(devpath);
3309e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
3319e39c5baSBill Taylor 		}
3329e39c5baSBill Taylor 
3339e39c5baSBill Taylor 		(void) strlcpy(newdev->drvname, drivername,
3349e39c5baSBill Taylor 		    strlen(drivername) + 1);
3359e39c5baSBill Taylor 
3369e39c5baSBill Taylor 		/* this next bit is backwards compatibility - "IB\0" */
3379e39c5baSBill Taylor 		if ((newdev->classname = calloc(1, 3)) == NULL) {
3389e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unable to allocate "
3399e39c5baSBill Taylor 			    "space for a class name\n"));
3409e39c5baSBill Taylor 			(void) free(newdev->drvname);
3419e39c5baSBill Taylor 			(void) free(newdev->ident);
3429e39c5baSBill Taylor 			(void) free(newdev->access_devname);
3439e39c5baSBill Taylor 			(void) free(newdev);
3449e39c5baSBill Taylor 			di_devfs_path_free(devpath);
3459e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
3469e39c5baSBill Taylor 		}
3479e39c5baSBill Taylor 		(void) strlcpy(newdev->classname, "IB", 3);
3489e39c5baSBill Taylor 
3499e39c5baSBill Taylor 		newdev->index = idx;
3509e39c5baSBill Taylor 		++idx;
3519e39c5baSBill Taylor 		newdev->plugin = self;
3529e39c5baSBill Taylor 
3539e39c5baSBill Taylor 		di_devfs_path_free(devpath);
3549e39c5baSBill Taylor 
3559e39c5baSBill Taylor 		TAILQ_INSERT_TAIL(fw_devices, newdev, nextdev);
3569e39c5baSBill Taylor 	}
3579e39c5baSBill Taylor 
3589e39c5baSBill Taylor 	if (fwflash_debug != 0) {
3599e39c5baSBill Taylor 		struct devicelist *tempdev;
3609e39c5baSBill Taylor 
3619e39c5baSBill Taylor 		TAILQ_FOREACH(tempdev, fw_devices, nextdev) {
3629e39c5baSBill Taylor 			logmsg(MSG_INFO, "fw_identify: hermon:\n");
3639e39c5baSBill Taylor 			logmsg(MSG_INFO, "\ttempdev @ 0x%lx\n"
3649e39c5baSBill Taylor 			    "\t\taccess_devname: %s\n"
3659e39c5baSBill Taylor 			    "\t\tdrvname: %s\tclassname: %s\n"
3669e39c5baSBill Taylor 			    "\t\tident->vid:   %s\n"
3679e39c5baSBill Taylor 			    "\t\tident->pid:   %s\n"
3689e39c5baSBill Taylor 			    "\t\tident->revid: %s\n"
3699e39c5baSBill Taylor 			    "\t\tindex: %d\n"
3709e39c5baSBill Taylor 			    "\t\tguid0: %s\n"
3719e39c5baSBill Taylor 			    "\t\tguid1: %s\n"
3729e39c5baSBill Taylor 			    "\t\tguid2: %s\n"
3739e39c5baSBill Taylor 			    "\t\tguid3: %s\n"
3749e39c5baSBill Taylor 			    "\t\tplugin @ 0x%lx\n\n",
3759e39c5baSBill Taylor 			    &tempdev,
3769e39c5baSBill Taylor 			    tempdev->access_devname,
3779e39c5baSBill Taylor 			    tempdev->drvname, newdev->classname,
3789e39c5baSBill Taylor 			    tempdev->ident->vid,
3799e39c5baSBill Taylor 			    tempdev->ident->pid,
3809e39c5baSBill Taylor 			    tempdev->ident->revid,
3819e39c5baSBill Taylor 			    tempdev->index,
382*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[0] ? tempdev->addresses[0] :
383*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
384*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[1] ? tempdev->addresses[1] :
385*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
386*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[2] ? tempdev->addresses[2] :
387*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
388*b67a60d6SShantkumar Hiremath 			    (tempdev->addresses[3] ? tempdev->addresses[3] :
389*b67a60d6SShantkumar Hiremath 			    "(not supported)"),
3909e39c5baSBill Taylor 			    tempdev->plugin);
3919e39c5baSBill Taylor 		}
3929e39c5baSBill Taylor 	}
3939e39c5baSBill Taylor 
3949e39c5baSBill Taylor 	return (FWFLASH_SUCCESS);
3959e39c5baSBill Taylor }
3969e39c5baSBill Taylor 
3979e39c5baSBill Taylor 
3989e39c5baSBill Taylor int
fw_devinfo(struct devicelist * thisdev)3999e39c5baSBill Taylor fw_devinfo(struct devicelist *thisdev)
4009e39c5baSBill Taylor {
4019e39c5baSBill Taylor 	ib_cnx_encap_ident_t	*encap;
4029e39c5baSBill Taylor 
4039e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_devinfo\n");
4049e39c5baSBill Taylor 
4059e39c5baSBill Taylor 	encap = (ib_cnx_encap_ident_t *)thisdev->ident->encap_ident;
4069e39c5baSBill Taylor 	if (CNX_I_CHECK_HANDLE(encap)) {
4079e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: fw_devinfo: Invalid handle "
4089e39c5baSBill Taylor 		    "for device %s! \n"), thisdev->access_devname);
4099e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
4109e39c5baSBill Taylor 	}
4119e39c5baSBill Taylor 
4129e39c5baSBill Taylor 	/* Try the primary first, then the secondary */
4139e39c5baSBill Taylor 	fprintf(stdout, gettext("Device[%d] %s\n"),
4149e39c5baSBill Taylor 	    thisdev->index, thisdev->access_devname);
4159e39c5baSBill Taylor 	fprintf(stdout, gettext("Class [%s]\n"), thisdev->classname);
4169e39c5baSBill Taylor 
4179e39c5baSBill Taylor 	fprintf(stdout, "\t");
4189e39c5baSBill Taylor 
4199e39c5baSBill Taylor 	/* Mellanox HCA Flash app note, p40, #4.2.3 table 9 */
4209e39c5baSBill Taylor 	fprintf(stdout, gettext("GUID: System Image - %s\n"),
4219e39c5baSBill Taylor 	    thisdev->addresses[3]);
4229e39c5baSBill Taylor 	fprintf(stdout, gettext("\t\tNode Image - %s\n"),
4239e39c5baSBill Taylor 	    thisdev->addresses[0]);
4249e39c5baSBill Taylor 	fprintf(stdout, gettext("\t\tPort 1\t   - %s\n"),
4259e39c5baSBill Taylor 	    thisdev->addresses[1]);
4269e39c5baSBill Taylor 	fprintf(stdout, gettext("\t\tPort 2\t   - %s\n"),
4279e39c5baSBill Taylor 	    thisdev->addresses[2]);
4289e39c5baSBill Taylor 
4299e39c5baSBill Taylor 	fprintf(stdout, gettext("\tFirmware revision  : %s\n"),
4309e39c5baSBill Taylor 	    thisdev->ident->revid);
4319e39c5baSBill Taylor 
4329e39c5baSBill Taylor 	if (encap->pn_len != 0) {
4339e39c5baSBill Taylor 		if (strlen(encap->info.mlx_id))
434*b67a60d6SShantkumar Hiremath 			fprintf(stdout, gettext("\tProduct\t\t   : "
435*b67a60d6SShantkumar Hiremath 			    "%s %X (%s)\n"), encap->info.mlx_pn,
436*b67a60d6SShantkumar Hiremath 			    encap->hwrev, encap->info.mlx_id);
4379e39c5baSBill Taylor 		else
438*b67a60d6SShantkumar Hiremath 			fprintf(stdout, gettext("\tProduct\t\t   : %s %X\n"),
439*b67a60d6SShantkumar Hiremath 			    encap->info.mlx_pn, encap->hwrev);
4409e39c5baSBill Taylor 
4419e39c5baSBill Taylor 		if (strlen(encap->info.mlx_psid))
4429e39c5baSBill Taylor 			fprintf(stdout, gettext("\tPSID\t\t   : %s\n"),
4439e39c5baSBill Taylor 			    encap->info.mlx_psid);
4449e39c5baSBill Taylor 		else if (strlen(thisdev->ident->pid))
4459e39c5baSBill Taylor 			fprintf(stdout, gettext("\t%s\n"), thisdev->ident->pid);
4469e39c5baSBill Taylor 	} else {
4479e39c5baSBill Taylor 		fprintf(stdout, gettext("\t%s\n"), thisdev->ident->pid);
4489e39c5baSBill Taylor 	}
4499e39c5baSBill Taylor 	fprintf(stdout, "\n\n");
4509e39c5baSBill Taylor 
4519e39c5baSBill Taylor 	return (cnx_close(thisdev));
4529e39c5baSBill Taylor }
4539e39c5baSBill Taylor 
4549e39c5baSBill Taylor 
4559e39c5baSBill Taylor /*
4569e39c5baSBill Taylor  * Helper functions lurk beneath this point
4579e39c5baSBill Taylor  */
4589e39c5baSBill Taylor 
4599e39c5baSBill Taylor 
4609e39c5baSBill Taylor /*
4619e39c5baSBill Taylor  * Notes:
4629e39c5baSBill Taylor  * 1. flash read is done in 32 bit quantities, and the driver returns
4639e39c5baSBill Taylor  *    data in host byteorder form.
4649e39c5baSBill Taylor  * 2. flash write is done in 8 bit quantities by the driver.
4659e39c5baSBill Taylor  * 3. data in the flash should be in network byteorder.
4669e39c5baSBill Taylor  * 4. data in image files is in network byteorder form.
4679e39c5baSBill Taylor  * 5. data in image structures in memory is kept in network byteorder.
4689e39c5baSBill Taylor  * 6. the functions in this file deal with data in host byteorder form.
4699e39c5baSBill Taylor  */
4709e39c5baSBill Taylor 
4719e39c5baSBill Taylor static int
cnx_read_image(ib_cnx_encap_ident_t * handle)4729e39c5baSBill Taylor cnx_read_image(ib_cnx_encap_ident_t *handle)
4739e39c5baSBill Taylor {
4749e39c5baSBill Taylor 	hermon_flash_ioctl_t	ioctl_info;
4759e39c5baSBill Taylor 	uint32_t		phys_addr;
4769e39c5baSBill Taylor 	int			ret, i;
4779e39c5baSBill Taylor 	int			image_size;
4789e39c5baSBill Taylor 	int			type;
4799e39c5baSBill Taylor 
4809e39c5baSBill Taylor 	type = handle->state &
4819e39c5baSBill Taylor 	    (FWFLASH_IB_STATE_IMAGE_PRI | FWFLASH_IB_STATE_IMAGE_SEC);
4829e39c5baSBill Taylor 	logmsg(MSG_INFO, "cnx_read_image: type %lx\n", type);
4839e39c5baSBill Taylor 
4849e39c5baSBill Taylor 	if (type == 0) {
4859e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("cnx_read_image: Must read in "
4869e39c5baSBill Taylor 		    "image first\n"));
4879e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
4889e39c5baSBill Taylor 	}
4899e39c5baSBill Taylor 
4909e39c5baSBill Taylor 	image_size = handle->fw_sz;
4919e39c5baSBill Taylor 	if (image_size <= 0) {
4929e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("cnx_read_image: Invalid image size "
4939e39c5baSBill Taylor 		    "0x%x for %s image\n"),
4949e39c5baSBill Taylor 		    image_size, (type == 0x1 ? "Primary" : "Secondary"));
4959e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
4969e39c5baSBill Taylor 	}
4979e39c5baSBill Taylor 
4989e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: fw_size: 0x%x\n", image_size);
4999e39c5baSBill Taylor 
5009e39c5baSBill Taylor 	handle->fw = (uint32_t *)calloc(1, image_size);
5019e39c5baSBill Taylor 	if (handle->fw == NULL) {
5029e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("cnx_read_image: Unable to allocate "
5039e39c5baSBill Taylor 		    "memory for fw_img : (%s)\n"), strerror(errno));
5049e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5059e39c5baSBill Taylor 	}
5069e39c5baSBill Taylor 
5079e39c5baSBill Taylor 	ioctl_info.af_type = HERMON_FLASH_READ_QUADLET;
5089e39c5baSBill Taylor 	for (i = 0; i < image_size; i += 4) {
5099e39c5baSBill Taylor 		phys_addr = cnx_cont2phys(handle->log2_chunk_sz, i, type);
5109e39c5baSBill Taylor 		ioctl_info.af_addr = phys_addr;
5119e39c5baSBill Taylor 
5129e39c5baSBill Taylor 		ret = cnx_read_ioctl(handle, &ioctl_info);
5139e39c5baSBill Taylor 		if (ret != 0) {
5149e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("cnx_read_image: Failed to "
5159e39c5baSBill Taylor 			    "read sector %d\n"), i);
5169e39c5baSBill Taylor 			free(handle->fw);
5179e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
5189e39c5baSBill Taylor 		}
5199e39c5baSBill Taylor 		handle->fw[i / 4] = htonl(ioctl_info.af_quadlet);
5209e39c5baSBill Taylor 	}
5219e39c5baSBill Taylor 
5229e39c5baSBill Taylor 	for (i = 0; i < image_size; i += 4) {
5239e39c5baSBill Taylor 		logmsg(MSG_INFO, "cnx_read_image: addr[0x%x] = 0x%08x\n", i,
5249e39c5baSBill Taylor 		    ntohl(handle->fw[i / 4]));
5259e39c5baSBill Taylor 	}
5269e39c5baSBill Taylor 
5279e39c5baSBill Taylor 	return (FWFLASH_SUCCESS);
5289e39c5baSBill Taylor }
5299e39c5baSBill Taylor 
5309e39c5baSBill Taylor static int
cnx_write_file(ib_cnx_encap_ident_t * handle,const char * filename)5319e39c5baSBill Taylor cnx_write_file(ib_cnx_encap_ident_t *handle, const char *filename)
5329e39c5baSBill Taylor {
5339e39c5baSBill Taylor 	FILE		*fp;
5349e39c5baSBill Taylor 	int 		fd;
5359e39c5baSBill Taylor 	mode_t		mode = S_IRUSR | S_IWUSR;
5369e39c5baSBill Taylor 	int		len;
5379e39c5baSBill Taylor 
5389e39c5baSBill Taylor 	logmsg(MSG_INFO, "cnx_write_file\n");
5399e39c5baSBill Taylor 
5409e39c5baSBill Taylor 	errno = 0;
5419e39c5baSBill Taylor 	if ((fd = open(filename, O_RDWR|O_CREAT|O_DSYNC, mode)) < 0) {
5429e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Unable to open specified "
5439e39c5baSBill Taylor 		    "file (%s) for writing: %s\n"), filename, strerror(errno));
5449e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5459e39c5baSBill Taylor 	}
5469e39c5baSBill Taylor 
5479e39c5baSBill Taylor 	errno = 0;
5489e39c5baSBill Taylor 	fp = fdopen(fd, "w");
5499e39c5baSBill Taylor 	if (fp == NULL) {
5509e39c5baSBill Taylor 		(void) fprintf(stderr, gettext("hermon: Unknown filename %s : "
5519e39c5baSBill Taylor 		    "%s\n"), filename, strerror(errno));
5529e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5539e39c5baSBill Taylor 	}
5549e39c5baSBill Taylor 
5559e39c5baSBill Taylor 	len = ntohl(handle->fw[CNX_IMG_SIZE_OFFSET / 4]);
5569e39c5baSBill Taylor 	logmsg(MSG_INFO, "cnx_write_file: Writing to file. Length 0x%x\n", len);
5579e39c5baSBill Taylor 
5589e39c5baSBill Taylor 	if (fwrite(&handle->fw[0], len, 1, fp) == 0) {
5599e39c5baSBill Taylor 		(void) fprintf(stderr, gettext("hermon: fwrite failed"));
5609e39c5baSBill Taylor 		perror("fwrite");
5619e39c5baSBill Taylor 		(void) fclose(fp);
5629e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
5639e39c5baSBill Taylor 	}
5649e39c5baSBill Taylor 	(void) fclose(fp);
5659e39c5baSBill Taylor 	return (FWFLASH_SUCCESS);
5669e39c5baSBill Taylor }
5679e39c5baSBill Taylor 
5689e39c5baSBill Taylor static int
cnx_verify_image(ib_cnx_encap_ident_t * handle,int type)5699e39c5baSBill Taylor cnx_verify_image(ib_cnx_encap_ident_t *handle, int type)
5709e39c5baSBill Taylor {
5719e39c5baSBill Taylor 	uint32_t	new_start_addr;
5729e39c5baSBill Taylor 
5739e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: cnx_verify_image\n");
5749e39c5baSBill Taylor 
5759e39c5baSBill Taylor 	new_start_addr = cnx_cont2phys(handle->log2_chunk_sz, 0, type);
5769e39c5baSBill Taylor 
5779e39c5baSBill Taylor 	return (cnx_check_for_magic_pattern(handle, new_start_addr));
5789e39c5baSBill Taylor }
5799e39c5baSBill Taylor 
5809e39c5baSBill Taylor static int
cnx_set_guids(ib_cnx_encap_ident_t * handle,void * arg)5819e39c5baSBill Taylor cnx_set_guids(ib_cnx_encap_ident_t *handle, void *arg)
5829e39c5baSBill Taylor {
5839e39c5baSBill Taylor 	uint32_t	addr;
5849e39c5baSBill Taylor 	uint32_t	*guids;
5859e39c5baSBill Taylor 
5869e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: cnx_set_guids\n");
5879e39c5baSBill Taylor 
5889e39c5baSBill Taylor 	guids = (uint32_t *)arg;
5899e39c5baSBill Taylor 	addr = ntohl(verifier->fwimage[CNX_NGUIDPTR_OFFSET / 4]) / 4;
5909e39c5baSBill Taylor 	logmsg(MSG_INFO, "cnx_set_guids: guid_start_addr: 0x%x\n", addr * 4);
5919e39c5baSBill Taylor 
5929e39c5baSBill Taylor 	/*
5939e39c5baSBill Taylor 	 * guids are supplied by callers as 64 bit values in host byteorder.
5949e39c5baSBill Taylor 	 * Storage is in network byteorder.
5959e39c5baSBill Taylor 	 */
5969e39c5baSBill Taylor #ifdef _BIG_ENDIAN
5979e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUIDN) {
5989e39c5baSBill Taylor 		verifier->fwimage[addr] = guids[0];
5999e39c5baSBill Taylor 		verifier->fwimage[addr + 1] = guids[1];
6009e39c5baSBill Taylor 	}
6019e39c5baSBill Taylor 
6029e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUID1) {
6039e39c5baSBill Taylor 		verifier->fwimage[addr + 2] = guids[2];
6049e39c5baSBill Taylor 		verifier->fwimage[addr + 3] = guids[3];
6059e39c5baSBill Taylor 	}
6069e39c5baSBill Taylor 
6079e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUID2) {
6089e39c5baSBill Taylor 		verifier->fwimage[addr + 4] = guids[4];
6099e39c5baSBill Taylor 		verifier->fwimage[addr + 5] = guids[5];
6109e39c5baSBill Taylor 	}
6119e39c5baSBill Taylor 
6129e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUIDS) {
6139e39c5baSBill Taylor 		verifier->fwimage[addr + 6] = guids[6];
6149e39c5baSBill Taylor 		verifier->fwimage[addr + 7] = guids[7];
6159e39c5baSBill Taylor 	}
6169e39c5baSBill Taylor #else
6179e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUIDN) {
6189e39c5baSBill Taylor 		verifier->fwimage[addr] = htonl(guids[1]);
6199e39c5baSBill Taylor 		verifier->fwimage[addr + 1] = htonl(guids[0]);
6209e39c5baSBill Taylor 	}
6219e39c5baSBill Taylor 
6229e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUID1) {
6239e39c5baSBill Taylor 		verifier->fwimage[addr + 2] = htonl(guids[3]);
6249e39c5baSBill Taylor 		verifier->fwimage[addr + 3] = htonl(guids[2]);
6259e39c5baSBill Taylor 	}
6269e39c5baSBill Taylor 
6279e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUID2) {
6289e39c5baSBill Taylor 		verifier->fwimage[addr + 4] = htonl(guids[5]);
6299e39c5baSBill Taylor 		verifier->fwimage[addr + 5] = htonl(guids[4]);
6309e39c5baSBill Taylor 	}
6319e39c5baSBill Taylor 
6329e39c5baSBill Taylor 	if (handle->state & FWFLASH_IB_STATE_GUIDS) {
6339e39c5baSBill Taylor 		verifier->fwimage[addr + 6] = htonl(guids[7]);
6349e39c5baSBill Taylor 		verifier->fwimage[addr + 7] = htonl(guids[6]);
6359e39c5baSBill Taylor 	}
6369e39c5baSBill Taylor #endif
6379e39c5baSBill Taylor 
6389e39c5baSBill Taylor 	cnx_local_set_guid_crc_img((addr * 4) - 0x10, CNX_GUID_CRC16_SIZE,
6399e39c5baSBill Taylor 	    CNX_GUID_CRC16_OFFSET);
6409e39c5baSBill Taylor 
6419e39c5baSBill Taylor 	return (FWFLASH_SUCCESS);
6429e39c5baSBill Taylor }
6439e39c5baSBill Taylor 
6449e39c5baSBill Taylor /*
6459e39c5baSBill Taylor  * Notes: Burn the image
6469e39c5baSBill Taylor  *
6479e39c5baSBill Taylor  * 1. Erase the entire sector where the new image is to be burned.
6489e39c5baSBill Taylor  * 2. Burn the image WITHOUT the magic pattern. This marks the new image
6499e39c5baSBill Taylor  *    as invalid during the burn process. If the current image (i.e
6509e39c5baSBill Taylor  *    containing a magic pattern) on the Flash is stored on the even
6519e39c5baSBill Taylor  *    chunks (PRIMARY), burn the new image to the odd chunks (SECONDARY),
6529e39c5baSBill Taylor  *    or vice versa.
6539e39c5baSBill Taylor  * 3. Burn the magic pattern at the beginning of the new image on the Flash.
6549e39c5baSBill Taylor  *    This will validate the new image.
6559e39c5baSBill Taylor  * 4. Set the BootAddress register to its new location.
6569e39c5baSBill Taylor  */
6579e39c5baSBill Taylor static int
cnx_write_image(ib_cnx_encap_ident_t * handle,int type)6589e39c5baSBill Taylor cnx_write_image(ib_cnx_encap_ident_t *handle, int type)
6599e39c5baSBill Taylor {
6609e39c5baSBill Taylor 	hermon_flash_ioctl_t	ioctl_info;
6619e39c5baSBill Taylor 	int			sector_size;
6629e39c5baSBill Taylor 	int			size;
6639e39c5baSBill Taylor 	int			i;
6649e39c5baSBill Taylor 	uint32_t		new_start_addr;
6659e39c5baSBill Taylor 	uint32_t		log2_chunk_sz;
6669e39c5baSBill Taylor 	uint8_t			*fw;
6679e39c5baSBill Taylor 
6689e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: cnx_write_image\n");
6699e39c5baSBill Taylor 
6709e39c5baSBill Taylor 	if (type == 0) {
6719e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("cnx_write_image: Must inform us "
6729e39c5baSBill Taylor 		    " where to write.\n"));
6739e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
6749e39c5baSBill Taylor 	}
6759e39c5baSBill Taylor 
6769e39c5baSBill Taylor 	log2_chunk_sz = cnx_get_log2_chunk_size(
6779e39c5baSBill Taylor 	    ntohl(verifier->fwimage[CNX_CHUNK_SIZE_OFFSET / 4]));
6789e39c5baSBill Taylor 
6799e39c5baSBill Taylor 	sector_size = handle->sector_sz;
6809e39c5baSBill Taylor 	new_start_addr = ((type - 1) << handle->log2_chunk_sz);
6819e39c5baSBill Taylor 
6829e39c5baSBill Taylor 	/* Read Image Size */
6839e39c5baSBill Taylor 	size = ntohl(verifier->fwimage[CNX_IMG_SIZE_OFFSET / 4]);
6849e39c5baSBill Taylor 	logmsg(MSG_INFO, "cnx_write_image: fw image size: 0x%x\n", size);
6859e39c5baSBill Taylor 
6869e39c5baSBill Taylor 	/* Sectors must be erased before they can be written to. */
6879e39c5baSBill Taylor 	ioctl_info.af_type = HERMON_FLASH_ERASE_SECTOR;
6889e39c5baSBill Taylor 	for (i = 0; i < size; i += sector_size) {
6899e39c5baSBill Taylor 		ioctl_info.af_sector_num =
6909e39c5baSBill Taylor 		    cnx_cont2phys(log2_chunk_sz, i, type) / sector_size;
6919e39c5baSBill Taylor 		if (cnx_erase_sector_ioctl(handle, &ioctl_info) != 0) {
6929e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("cnx_write_image: Failed to "
6939e39c5baSBill Taylor 			    "erase sector 0x%x\n"), ioctl_info.af_sector_num);
6949e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
6959e39c5baSBill Taylor 		}
6969e39c5baSBill Taylor 	}
6979e39c5baSBill Taylor 
6989e39c5baSBill Taylor 	fw = (uint8_t *)verifier->fwimage;
6999e39c5baSBill Taylor 	ioctl_info.af_type = HERMON_FLASH_WRITE_BYTE;
7009e39c5baSBill Taylor 
7019e39c5baSBill Taylor 	/* Write the new image without the magic pattern */
7029e39c5baSBill Taylor 	for (i = 16; i < size; i++) {
7039e39c5baSBill Taylor 		ioctl_info.af_byte = fw[i];
7049e39c5baSBill Taylor 		ioctl_info.af_addr = cnx_cont2phys(log2_chunk_sz, i, type);
7059e39c5baSBill Taylor 		if (cnx_write_ioctl(handle, &ioctl_info) != 0) {
7069e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("cnx_write_image: Failed to "
7079e39c5baSBill Taylor 			    "write byte 0x%x\n"), ioctl_info.af_byte);
7089e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
7099e39c5baSBill Taylor 		}
7109e39c5baSBill Taylor 
7119e39c5baSBill Taylor 		if (i && !(i % handle->sector_sz)) {
7129e39c5baSBill Taylor 			(void) printf(" .");
7139e39c5baSBill Taylor 			(void) fflush((void *)NULL);
7149e39c5baSBill Taylor 		}
7159e39c5baSBill Taylor 	}
7169e39c5baSBill Taylor 
7179e39c5baSBill Taylor 	/* Validate the new image -- Write the magic pattern. */
7189e39c5baSBill Taylor 	for (i = 0; i < 16; i++) {
7199e39c5baSBill Taylor 		ioctl_info.af_byte = fw[i];
7209e39c5baSBill Taylor 		ioctl_info.af_addr = cnx_cont2phys(log2_chunk_sz, i, type);
7219e39c5baSBill Taylor 		if (cnx_write_ioctl(handle, &ioctl_info) != 0) {
7229e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("cnx_write_image: Failed to "
7239e39c5baSBill Taylor 			    "write magic pattern byte 0x%x\n"),
7249e39c5baSBill Taylor 			    ioctl_info.af_byte);
7259e39c5baSBill Taylor 			return (FWFLASH_FAILURE);
7269e39c5baSBill Taylor 		}
7279e39c5baSBill Taylor 	}
7289e39c5baSBill Taylor 
7299e39c5baSBill Taylor 	/* Write new image start address to CR space */
7309e39c5baSBill Taylor 	errno = 0;
7319e39c5baSBill Taylor 	ioctl_info.af_addr = new_start_addr;
7329e39c5baSBill Taylor 	if (ioctl(handle->fd, HERMON_IOCTL_WRITE_BOOT_ADDR, &ioctl_info) != 0) {
7339e39c5baSBill Taylor 		logmsg(MSG_WARN, gettext("cnx_write_image: Failed to "
7349e39c5baSBill Taylor 		    "update boot address register: %s\n"), strerror(errno));
7359e39c5baSBill Taylor 	}
7369e39c5baSBill Taylor 
7379e39c5baSBill Taylor 	return (FWFLASH_SUCCESS);
7389e39c5baSBill Taylor }
7399e39c5baSBill Taylor 
7409e39c5baSBill Taylor 
7419e39c5baSBill Taylor /*
7429e39c5baSBill Taylor  * cnx_identify performs the following actions:
7439e39c5baSBill Taylor  *
7449e39c5baSBill Taylor  *	allocates and assigns thisdev->vpr
7459e39c5baSBill Taylor  *
7469e39c5baSBill Taylor  *	allocates space for the 4 GUIDs which each IB device must have
7479e39c5baSBill Taylor  *	queries the hermon driver for this device's GUIDs
7489e39c5baSBill Taylor  *
7499e39c5baSBill Taylor  *	determines the hardware vendor, so that thisdev->vpr->vid
7509e39c5baSBill Taylor  *	can be set correctly
7519e39c5baSBill Taylor  */
7529e39c5baSBill Taylor static int
cnx_identify(struct devicelist * thisdev)7539e39c5baSBill Taylor cnx_identify(struct devicelist *thisdev)
7549e39c5baSBill Taylor {
7559e39c5baSBill Taylor 	int				fd, ret, i;
7569e39c5baSBill Taylor 	hermon_flash_init_ioctl_t	init_ioctl;
7579e39c5baSBill Taylor 	ib_cnx_encap_ident_t		*manuf;
7589e39c5baSBill Taylor 	cfi_t				cfi;
7599e39c5baSBill Taylor 	int				hw_psid_found = 0;
7609e39c5baSBill Taylor 
7619e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: cnx_identify\n");
7629e39c5baSBill Taylor 	/* open the device */
7639e39c5baSBill Taylor 	/* hook thisdev->ident->encap_ident to ib_cnx_encap_ident_t */
7649e39c5baSBill Taylor 	/* check that all the bits are sane */
7659e39c5baSBill Taylor 	/* return success, if warranted */
7669e39c5baSBill Taylor 
7679e39c5baSBill Taylor 	errno = 0;
7689e39c5baSBill Taylor 	if ((fd = open(thisdev->access_devname, O_RDONLY)) < 0) {
7699e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Unable to open a %s-"
7709e39c5baSBill Taylor 		    "attached device node: %s: %s\n"), drivername,
7719e39c5baSBill Taylor 		    thisdev->access_devname, strerror(errno));
7729e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
7739e39c5baSBill Taylor 	}
7749e39c5baSBill Taylor 
7759e39c5baSBill Taylor 	if ((manuf = calloc(1, sizeof (ib_cnx_encap_ident_t))) == NULL) {
7769e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Unable to allocate space "
7779e39c5baSBill Taylor 		    "for a %s-attached handle structure\n"), drivername);
7789e39c5baSBill Taylor 		close(fd);
7799e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
7809e39c5baSBill Taylor 	}
7819e39c5baSBill Taylor 	manuf->magic = FWFLASH_IB_MAGIC_NUMBER;
7829e39c5baSBill Taylor 	manuf->state = FWFLASH_IB_STATE_NONE;
7839e39c5baSBill Taylor 	manuf->fd = fd;
7849e39c5baSBill Taylor 	manuf->log2_chunk_sz = 0;
7859e39c5baSBill Taylor 
7869e39c5baSBill Taylor 	thisdev->ident->encap_ident = manuf;
7879e39c5baSBill Taylor 
7889e39c5baSBill Taylor 	/*
7899e39c5baSBill Taylor 	 * Inform driver that this command supports the Intel Extended
7909e39c5baSBill Taylor 	 * CFI command set.
7919e39c5baSBill Taylor 	 */
7929e39c5baSBill Taylor 	cfi.cfi_char[0x10] = 'M';
7939e39c5baSBill Taylor 	cfi.cfi_char[0x11] = 'X';
7949e39c5baSBill Taylor 	cfi.cfi_char[0x12] = '2';
7959e39c5baSBill Taylor 	init_ioctl.af_cfi_info[0x4] = ntohl(cfi.cfi_int[0x4]);
7969e39c5baSBill Taylor 
7979e39c5baSBill Taylor 	errno = 0;
7989e39c5baSBill Taylor 	ret = ioctl(fd, HERMON_IOCTL_FLASH_INIT, &init_ioctl);
7999e39c5baSBill Taylor 	if (ret < 0) {
8009e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: HERMON_IOCTL_FLASH_INIT "
8019e39c5baSBill Taylor 		    "failed: %s\n"), strerror(errno));
8029e39c5baSBill Taylor 		close(fd);
8039e39c5baSBill Taylor 		free(manuf);
8049e39c5baSBill Taylor 		return (FWFLASH_FAILURE);
8059e39c5baSBill Taylor 	}
8069e39c5baSBill Taylor 
8079e39c5baSBill Taylor 	manuf->hwrev = init_ioctl.af_hwrev;
8089e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: init_ioctl: hwrev: %x, fwver: %d.%d.%04d, "
8099e39c5baSBill Taylor 	    "PN# Len %d\n", init_ioctl.af_hwrev, init_ioctl.af_fwrev.afi_maj,
8109e39c5baSBill Taylor 	    init_ioctl.af_fwrev.afi_min, init_ioctl.af_fwrev.afi_sub,
8119e39c5baSBill Taylor 	    init_ioctl.af_pn_len);
8129e39c5baSBill Taylor 
8139e39c5baSBill Taylor 	/*
8149e39c5baSBill Taylor 	 * Determine whether the attached driver supports the Intel or
8159e39c5baSBill Taylor 	 * AMD Extended CFI command sets. If it doesn't support either,
8169e39c5baSBill Taylor 	 * then we're hosed, so error out.
8179e39c5baSBill Taylor 	 */
8189e39c5baSBill Taylor 	for (i = 0; i < HERMON_FLASH_CFI_SIZE_QUADLET; i++) {
8199e39c5baSBill Taylor 		cfi.cfi_int[i] = ntohl(init_ioctl.af_cfi_info[i]);
8209e39c5baSBill Taylor 	}
8219e39c5baSBill Taylor 	manuf->cmd_set = cfi.cfi_char[0x13];
8229e39c5baSBill Taylor 
8239e39c5baSBill Taylor 	if (cfi.cfi_char[0x10] == 'Q' &&
8249e39c5baSBill Taylor 	    cfi.cfi_char[0x11] == 'R' &&
8259e39c5baSBill Taylor 	    cfi.cfi_char[0x12] == 'Y') {
8269e39c5baSBill Taylor 		/* make sure the cmd set is SPI */
8279e39c5baSBill Taylor 		if (manuf->cmd_set != HERMON_FLASH_SPI_CMDSET) {
8289e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unsupported flash "
8299e39c5baSBill Taylor 			    "device command set\n"));
8309e39c5baSBill Taylor 			goto identify_end;
8319e39c5baSBill Taylor 		}
8329e39c5baSBill Taylor 		/* set some defaults */
8339e39c5baSBill Taylor 		manuf->sector_sz = HERMON_FLASH_SECTOR_SZ_DEFAULT;
8349e39c5baSBill Taylor 		manuf->device_sz = HERMON_FLASH_DEVICE_SZ_DEFAULT;
8359e39c5baSBill Taylor 	} else if (manuf->cmd_set == HERMON_FLASH_SPI_CMDSET) {
8369e39c5baSBill Taylor 		manuf->sector_sz = HERMON_FLASH_SPI_SECTOR_SIZE;
8379e39c5baSBill Taylor 		manuf->device_sz = HERMON_FLASH_SPI_DEVICE_SIZE;
8389e39c5baSBill Taylor 	} else {
8399e39c5baSBill Taylor 		if (manuf->cmd_set != HERMON_FLASH_AMD_CMDSET &&
8409e39c5baSBill Taylor 		    manuf->cmd_set != HERMON_FLASH_INTEL_CMDSET) {
8419e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: Unknown flash "
8429e39c5baSBill Taylor 			    "device command set %lx\n"), manuf->cmd_set);
8439e39c5baSBill Taylor 			goto identify_end;
8449e39c5baSBill Taylor 		}
8459e39c5baSBill Taylor 		/* read from the CFI data */
8469e39c5baSBill Taylor 		manuf->sector_sz = ((cfi.cfi_char[0x30] << 8) |
8479e39c5baSBill Taylor 		    cfi.cfi_char[0x2F]) << 8;
8489e39c5baSBill Taylor 		manuf->device_sz = 0x1 << cfi.cfi_char[0x27];
8499e39c5baSBill Taylor 	}
8509e39c5baSBill Taylor 
8519e39c5baSBill Taylor 	logmsg(MSG_INFO, "hermon: sector_sz: 0x%08x device_sz: 0x%08x\n",
8529e39c5baSBill Taylor 	    manuf->sector_sz, manuf->device_sz);
8539e39c5baSBill Taylor 
8549e39c5baSBill Taylor 	/* set firmware revision */
8559e39c5baSBill Taylor 	manuf->hwfw_img_info.fw_rev.major = init_ioctl.af_fwrev.afi_maj;
8569e39c5baSBill Taylor 	manuf->hwfw_img_info.fw_rev.minor = init_ioctl.af_fwrev.afi_min;
8579e39c5baSBill Taylor 	manuf->hwfw_img_info.fw_rev.subminor = init_ioctl.af_fwrev.afi_sub;
8589e39c5baSBill Taylor 
8599e39c5baSBill Taylor 	if (((thisdev->ident->vid = calloc(1, MLX_VPR_VIDLEN + 1)) == NULL) ||
8609e39c5baSBill Taylor 	    ((thisdev->ident->revid = calloc(1, MLX_VPR_REVLEN + 1)) == NULL)) {
8619e39c5baSBill Taylor 		logmsg(MSG_ERROR, gettext("hermon: Unable to allocate space "
8629e39c5baSBill Taylor 		    "for a VPR record.\n"));
8639e39c5baSBill Taylor 		goto identify_end;
8649e39c5baSBill Taylor 	}
8659e39c5baSBill Taylor 	(void) strlcpy(thisdev->ident->vid, "MELLANOX", MLX_VPR_VIDLEN);
8669e39c5baSBill Taylor 
8679e39c5baSBill Taylor 	/*
8689e39c5baSBill Taylor 	 * We actually want the hwrev field from the ioctl above.
8699e39c5baSBill Taylor 	 * Until we find out otherwise, add it onto the end of the
8709e39c5baSBill Taylor 	 * firmware version details.
8719e39c5baSBill Taylor 	 */
872ee5d8455SShantkumar Hiremath 	snprintf(thisdev->ident->revid, MLX_VPR_REVLEN, "%d.%d.%03d",
8739e39c5baSBill Taylor 	    manuf->hwfw_img_info.fw_rev.major,
8749e39c5baSBill Taylor 	    manuf->hwfw_img_info.fw_rev.minor,
8759e39c5baSBill Taylor 	    manuf->hwfw_img_info.fw_rev.subminor);
8769e39c5baSBill Taylor 
8779e39c5baSBill Taylor 	if ((ret = cnx_get_guids(manuf)) != FWFLASH_SUCCESS) {
8789e39c5baSBill Taylor 		logmsg(MSG_WARN, gettext("hermon: No GUIDs found for "
8799e39c5baSBill Taylor 		    "device %s!\n"), thisdev->access_devname);
8809e39c5baSBill Taylor 	}
8819e39c5baSBill Taylor 
8829e39c5baSBill Taylor 	/* set hw part number, psid, and name in handle */
8839e39c5baSBill Taylor 	/* now walk the magic decoder ring table */
8849e39c5baSBill Taylor 	manuf->info.mlx_pn = NULL;
8859e39c5baSBill Taylor 	manuf->info.mlx_psid = NULL;
8869e39c5baSBill Taylor 	manuf->info.mlx_id = NULL;
8879e39c5baSBill Taylor 
8889e39c5baSBill Taylor 	if (cnx_get_image_info(manuf) != FWFLASH_SUCCESS) {
8899e39c5baSBill Taylor 		logmsg(MSG_WARN, gettext("hermon: Failed to read Image Info "
8909e39c5baSBill Taylor 		    "for PSID\n"));
8919e39c5baSBill Taylor 		hw_psid_found = 0;
8929e39c5baSBill Taylor 	} else {
8939e39c5baSBill Taylor 		hw_psid_found = 1;
8949e39c5baSBill Taylor 	}
8959e39c5baSBill Taylor 
8969e39c5baSBill Taylor 	if (init_ioctl.af_pn_len != 0) {
8979e39c5baSBill Taylor 		/* part number length */
8989e39c5baSBill Taylor 		for (i = 0; i < init_ioctl.af_pn_len; i++) {
8999e39c5baSBill Taylor 			if (init_ioctl.af_hwpn[i] == ' ') {
9009e39c5baSBill Taylor 				manuf->pn_len = i;
9019e39c5baSBill Taylor 				break;
9029e39c5baSBill Taylor 			}
9039e39c5baSBill Taylor 		}
9049e39c5baSBill Taylor 		if (i == init_ioctl.af_pn_len) {
9059e39c5baSBill Taylor 			manuf->pn_len = init_ioctl.af_pn_len;
9069e39c5baSBill Taylor 		}
9079e39c5baSBill Taylor 	} else {
9089e39c5baSBill Taylor 		logmsg(MSG_INFO, "hermon: Failed to get Part# from hermon "
9099e39c5baSBill Taylor 		    "driver \n");
9109e39c5baSBill Taylor 		manuf->pn_len = 0;
9119e39c5baSBill Taylor 	}
9129e39c5baSBill Taylor 
9139e39c5baSBill Taylor 	if (manuf->pn_len != 0) {
9149e39c5baSBill Taylor 		errno = 0;
9159e39c5baSBill Taylor 		manuf->info.mlx_pn = calloc(1, manuf->pn_len);
9169e39c5baSBill Taylor 		if (manuf->info.mlx_pn == NULL) {
9179e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: no space available "
9189e39c5baSBill Taylor 			    "for the HCA PN record (%s)\n"), strerror(errno));
9199e39c5baSBill Taylor 			goto identify_end;
9209e39c5baSBill Taylor 		}
9219e39c5baSBill Taylor 		(void) memcpy(manuf->info.mlx_pn, init_ioctl.af_hwpn,
9229e39c5baSBill Taylor 		    manuf->pn_len);
9239e39c5baSBill Taylor 		manuf->info.mlx_pn[manuf->pn_len] = 0;
9249e39c5baSBill Taylor 
9259e39c5baSBill Taylor 		logmsg(MSG_INFO, "hermon: HCA PN (%s) PN-Len %d\n",
9269e39c5baSBill Taylor 		    manuf->info.mlx_pn, manuf->pn_len);
9279e39c5baSBill Taylor 
9289e39c5baSBill Taylor 		errno = 0;
9299e39c5baSBill Taylor 		manuf->info.mlx_psid = calloc(1, MLX_PSID_SZ);
9309e39c5baSBill Taylor 		if (manuf->info.mlx_psid == NULL) {
9319e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: PSID calloc "
9329e39c5baSBill Taylor 			    "failed :%s\n"), strerror(errno));
9339e39c5baSBill Taylor 			goto identify_end;
9349e39c5baSBill Taylor 		}
9359e39c5baSBill Taylor 
9369e39c5baSBill Taylor 		errno = 0;
9379e39c5baSBill Taylor 		if ((manuf->info.mlx_id = calloc(1, MLX_STR_ID_SZ)) == NULL) {
9389e39c5baSBill Taylor 			logmsg(MSG_ERROR, gettext("hermon: "
9399e39c5baSBill Taylor 			    "ID calloc failed (%s)\n"),
9409e39c5baSBill Taylor 			    strerror(errno));
9419e39c5baSBill Taylor 			goto identify_end;
9429e39c5baSBill Taylor 		}
9439e39c5baSBill Taylor 
9449e39c5baSBill Taylor 		/* Find part number, set the rest */
9459e39c5baSBill Taylor 		for (i = 0; i < MLX_MAX_ID; i++) {
9469e39c5baSBill Taylor 			if (strncmp((const char *)init_ioctl.af_hwpn,
9479e39c5baSBill Taylor 			    mlx_mdr[i].mlx_pn, manuf->pn_len) == 0) {
9489e39c5baSBill Taylor 
9499e39c5baSBill Taylor 				if (hw_psid_found) {
9509e39c5baSBill Taylor 					logmsg(MSG_INFO, "HW-PSID: %s "
9519e39c5baSBill Taylor 					    "MLX_MDR[%d]: %s\n",
9529e39c5baSBill Taylor 					    manuf->hwfw_img_info.psid, i,
9539e39c5baSBill Taylor 					    mlx_mdr[i].mlx_psid);
9549e39c5baSBill Taylor 					if (strncmp((const char *)
9559e39c5baSBill Taylor 					    manuf->hwfw_img_info.psid,
9569e39c5baSBill Taylor 					    mlx_mdr[i].mlx_psid,
9579e39c5baSBill Taylor 					    MLX_PSID_SZ) != 0)
9589e39c5baSBill Taylor 						continue;
9599e39c5baSBill Taylor 				}
9609e39c5baSBill Taylor 				/* Set PSID */
9619e39c5baSBill Taylor 				(void) memcpy(manuf->info.mlx_psid,
9629e39c5baSBill Taylor 				    mlx_mdr[i].mlx_psid, MLX_PSID_SZ);
9639e39c5baSBill Taylor 				manuf->info.mlx_psid[MLX_PSID_SZ - 1] = 0;
9649e39c5baSBill Taylor 
9659e39c5baSBill Taylor 				logmsg(MSG_INFO, "hermon: HCA PSID (%s)\n",
9669e39c5baSBill Taylor 				    manuf->info.mlx_psid);
9679e39c5baSBill Taylor 
9689e39c5baSBill Taylor 				(void) strlcpy(manuf->info.mlx_id,
9699e39c5baSBill Taylor 				    mlx_mdr[i].mlx_id,
9709e39c5baSBill Taylor 				    strlen(mlx_mdr[i].mlx_id) + 1);
9719e39c5baSBill Taylor 
9729e39c5baSBill Taylor 				logmsg(MSG_INFO, "hermon: HCA Name (%s)\n",
9739e39c5baSBill Taylor 				    manuf->info.mlx_id);
9749e39c5baSBill Taylor 
9759e39c5baSBill Taylor 				break;
9769e39c5baSBill Taylor 			}
9779e39c5baSBill Taylor 		}
9789e39c5baSBill Taylor 	}
9799e39c5baSBill Taylor 
9809e39c5baSBill Taylor 	if ((manuf->pn_len == 0) || (i == MLX_MAX_ID)) {
9819e39c5baSBill Taylor 		logmsg(MSG_INFO, "hermon: No hardware part number "
9829e39c5baSBill Taylor 		    "information available for this HCA\n");
9839e39c5baSBill Taylor 
9849e39c5baSBill Taylor 		i = strlen("No hardware information available for this device");
9859e39c5baSBill Taylor 
9869e39c5baSBill Taylor 		thisdev->ident->pid = calloc(1, i + 2);
9879e39c5baSBill Taylor 		sprintf(thisdev->ident->pid, "No additional hardware info "
9889e39c5baSBill Taylor 		    "available for this device");
9899e39c5baSBill Taylor 	} else {
9909e39c5baSBill Taylor 		errno = 0;
9919e39c5baSBill Taylor 		if ((thisdev->ident->pid = calloc(1,
9929e39c5baSBill Taylor 		    strlen(manuf->info.mlx_psid) + 1)) != NULL) {
9939e39c5baSBill Taylor 			(void) strlcpy(thisdev->ident->pid,
9949e39c5baSBill Taylor 			    manuf->info.mlx_psid,
9959e39c5baSBill Taylor 			    strlen(manuf->info.mlx_psid) + 1);
9969e39c5baSBill Taylor 		} else {
9979e39c5baSBill Taylor 			logmsg(MSG_ERROR,
9989e39c5baSBill Taylor 			    gettext("hermon: Unable to allocate space for a "
9999e39c5baSBill Taylor 			    "hardware identifier: %s\n"), strerror(errno));
10009e39c5baSBill Taylor 			goto identify_end;
10019e39c5baSBill Taylor 		}
10029e39c5baSBill Taylor 	}
10039e39c5ba