xref: /onnv-gate/usr/src/cmd/fwflash/plugins/vendor/hermon-MELLANOX.c (revision 12472:c0d938f047b6)
19517SBill.Taylor@Sun.COM /*
29517SBill.Taylor@Sun.COM  * CDDL HEADER START
39517SBill.Taylor@Sun.COM  *
49517SBill.Taylor@Sun.COM  * The contents of this file are subject to the terms of the
59517SBill.Taylor@Sun.COM  * Common Development and Distribution License (the "License").
69517SBill.Taylor@Sun.COM  * You may not use this file except in compliance with the License.
79517SBill.Taylor@Sun.COM  *
89517SBill.Taylor@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99517SBill.Taylor@Sun.COM  * or http://www.opensolaris.org/os/licensing.
109517SBill.Taylor@Sun.COM  * See the License for the specific language governing permissions
119517SBill.Taylor@Sun.COM  * and limitations under the License.
129517SBill.Taylor@Sun.COM  *
139517SBill.Taylor@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
149517SBill.Taylor@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159517SBill.Taylor@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
169517SBill.Taylor@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
179517SBill.Taylor@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
189517SBill.Taylor@Sun.COM  *
199517SBill.Taylor@Sun.COM  * CDDL HEADER END
209517SBill.Taylor@Sun.COM  */
219517SBill.Taylor@Sun.COM 
229517SBill.Taylor@Sun.COM /*
23*12472SShantkumar.Hiremath@Sun.COM  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
249517SBill.Taylor@Sun.COM  */
259517SBill.Taylor@Sun.COM 
269517SBill.Taylor@Sun.COM /*
279517SBill.Taylor@Sun.COM  * ConnectX (hermon) firmware image verification plugin
289517SBill.Taylor@Sun.COM  */
299517SBill.Taylor@Sun.COM 
309517SBill.Taylor@Sun.COM #include <stdio.h>
319517SBill.Taylor@Sun.COM #include <stdlib.h>
329517SBill.Taylor@Sun.COM #include <unistd.h>
339517SBill.Taylor@Sun.COM #include <sys/types.h>
349517SBill.Taylor@Sun.COM #include <sys/stat.h>
359517SBill.Taylor@Sun.COM #include <sys/sysmacros.h>
369517SBill.Taylor@Sun.COM #include <fcntl.h>
379517SBill.Taylor@Sun.COM #include <sys/condvar.h>
389517SBill.Taylor@Sun.COM #include <string.h>
399517SBill.Taylor@Sun.COM #include <strings.h>
409517SBill.Taylor@Sun.COM 
419517SBill.Taylor@Sun.COM #include <sys/byteorder.h>
429517SBill.Taylor@Sun.COM 
439517SBill.Taylor@Sun.COM #include <libintl.h> /* for gettext(3c) */
449517SBill.Taylor@Sun.COM 
459517SBill.Taylor@Sun.COM #include <fwflash/fwflash.h>
469517SBill.Taylor@Sun.COM #include "../hdrs/hermon_ib.h"
479517SBill.Taylor@Sun.COM 
489517SBill.Taylor@Sun.COM char vendor[] = "MELLANOX\0";
499517SBill.Taylor@Sun.COM 
509517SBill.Taylor@Sun.COM extern struct vrfyplugin *verifier;
519517SBill.Taylor@Sun.COM 
529517SBill.Taylor@Sun.COM 
539517SBill.Taylor@Sun.COM /* required functions for this plugin */
549517SBill.Taylor@Sun.COM int vendorvrfy(struct devicelist *devicenode);
559517SBill.Taylor@Sun.COM 
569517SBill.Taylor@Sun.COM /* helper functions */
579517SBill.Taylor@Sun.COM static uint16_t cnx_check_hwver_img(ib_cnx_encap_ident_t *handle);
589517SBill.Taylor@Sun.COM static void cnx_flash_verify_flash_match_img(ib_cnx_encap_ident_t *handle);
599517SBill.Taylor@Sun.COM static void cnx_flash_verify_flash_pn_img(ib_cnx_encap_ident_t *handle,
609517SBill.Taylor@Sun.COM     uchar_t *psid, int psid_size);
619517SBill.Taylor@Sun.COM static uchar_t *cnx_flash_get_psid_img(ib_cnx_encap_ident_t *handle);
629517SBill.Taylor@Sun.COM static void cnx_display_fwver(ib_cnx_encap_ident_t *handle);
639517SBill.Taylor@Sun.COM static int cnx_check_guid_section();
649517SBill.Taylor@Sun.COM 
659517SBill.Taylor@Sun.COM 
669517SBill.Taylor@Sun.COM int
vendorvrfy(struct devicelist * devicenode)679517SBill.Taylor@Sun.COM vendorvrfy(struct devicelist *devicenode)
689517SBill.Taylor@Sun.COM {
699517SBill.Taylor@Sun.COM 	struct ib_cnx_encap_ident_s	*handle;
709517SBill.Taylor@Sun.COM 	uint16_t	ver;
719517SBill.Taylor@Sun.COM 
729517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "hermon: vendorvrfy \n");
739517SBill.Taylor@Sun.COM 
749517SBill.Taylor@Sun.COM 	handle = (struct ib_cnx_encap_ident_s *)devicenode->ident->encap_ident;
759517SBill.Taylor@Sun.COM 
769517SBill.Taylor@Sun.COM 	if (CNX_I_CHECK_HANDLE(handle)) {
779517SBill.Taylor@Sun.COM 		logmsg(MSG_ERROR, gettext("hermon: Invalid Handle for "
789517SBill.Taylor@Sun.COM 		    "device %s! \n"), devicenode->access_devname);
799517SBill.Taylor@Sun.COM 		return (FWFLASH_FAILURE);
809517SBill.Taylor@Sun.COM 	}
819517SBill.Taylor@Sun.COM 
829517SBill.Taylor@Sun.COM 	/*
839517SBill.Taylor@Sun.COM 	 * NOTE verifier->fwimage is where file is read to.
849517SBill.Taylor@Sun.COM 	 */
859517SBill.Taylor@Sun.COM 	if (cnx_is_magic_pattern_present(&verifier->fwimage[0], 1) !=
869517SBill.Taylor@Sun.COM 	    FWFLASH_SUCCESS) {
879517SBill.Taylor@Sun.COM 		logmsg(MSG_ERROR, gettext("%s firmware image verifier: "
889517SBill.Taylor@Sun.COM 		    "No magic pattern found in firmware file %s \n"),
899517SBill.Taylor@Sun.COM 		    verifier->vendor, verifier->imgfile);
909517SBill.Taylor@Sun.COM 		return (FWFLASH_FAILURE);
919517SBill.Taylor@Sun.COM 	}
929517SBill.Taylor@Sun.COM 
939517SBill.Taylor@Sun.COM 	if (cnx_check_guid_section() == FWFLASH_FAILURE) {
949517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, "%s firmware image verifier: "
959517SBill.Taylor@Sun.COM 		    "Firmware Image GUID section is invalid\n",
969517SBill.Taylor@Sun.COM 		    verifier->vendor);
979517SBill.Taylor@Sun.COM 	}
989517SBill.Taylor@Sun.COM 
999517SBill.Taylor@Sun.COM 	cnx_flash_verify_flash_match_img(handle);
1009517SBill.Taylor@Sun.COM 
1019517SBill.Taylor@Sun.COM 	/* Check Hardware Rev */
1029517SBill.Taylor@Sun.COM 	ver = cnx_check_hwver_img(handle);
1039517SBill.Taylor@Sun.COM 	if (ver != 0) {
1049517SBill.Taylor@Sun.COM 		logmsg(MSG_ERROR, gettext("hermon: Firmware mismatch: "
1059517SBill.Taylor@Sun.COM 		    "ver(0x%X) hw_ver(0x%X)\n"), (ver >> 8), ver & 0xFF);
1069517SBill.Taylor@Sun.COM 		return (FWFLASH_FAILURE);
1079517SBill.Taylor@Sun.COM 	}
1089517SBill.Taylor@Sun.COM 
1099517SBill.Taylor@Sun.COM 	if (handle->hwfw_match == 0) {
11010618SShantkumar.Hiremath@Sun.COM 		int resp;
11110618SShantkumar.Hiremath@Sun.COM 
1129517SBill.Taylor@Sun.COM 		if (handle->pn_len != 0) {
1139517SBill.Taylor@Sun.COM 			/* HW VPD exist and a mismatch was found */
1149517SBill.Taylor@Sun.COM 			logmsg(MSG_ERROR, gettext("hermon: Please verify that "
1159517SBill.Taylor@Sun.COM 			    "the firmware image is intended for use with this "
1169517SBill.Taylor@Sun.COM 			    "hardware\n"));
1179517SBill.Taylor@Sun.COM 		} else {
1189517SBill.Taylor@Sun.COM 			logmsg(MSG_ERROR, gettext("hermon: Unable to verify "
1199517SBill.Taylor@Sun.COM 			    "firmware is appropriate for the hardware\n"));
1209517SBill.Taylor@Sun.COM 		}
12110618SShantkumar.Hiremath@Sun.COM 		logmsg(MSG_ERROR, gettext("Do you want to continue? (Y/N): "));
12210618SShantkumar.Hiremath@Sun.COM 		(void) fflush(stdin);
12310618SShantkumar.Hiremath@Sun.COM 		resp = getchar();
12410618SShantkumar.Hiremath@Sun.COM 		if (resp != 'Y' && resp != 'y') {
12510618SShantkumar.Hiremath@Sun.COM 			logmsg(MSG_ERROR, gettext("Not proceeding with "
126*12472SShantkumar.Hiremath@Sun.COM 			    "flash operation of %s on %s \n"),
12710618SShantkumar.Hiremath@Sun.COM 			    verifier->imgfile, devicenode->drvname);
12810618SShantkumar.Hiremath@Sun.COM 			return (FWFLASH_FAILURE);
12910618SShantkumar.Hiremath@Sun.COM 		}
13010618SShantkumar.Hiremath@Sun.COM 	} else {
13110618SShantkumar.Hiremath@Sun.COM 		logmsg(MSG_INFO, "%s firmware image verifier: HCA PSID (%s) "
13210618SShantkumar.Hiremath@Sun.COM 		    "matches firmware image %s's PSID\n", verifier->vendor,
13310618SShantkumar.Hiremath@Sun.COM 		    handle->info.mlx_psid, verifier->imgfile);
13410618SShantkumar.Hiremath@Sun.COM 
13510618SShantkumar.Hiremath@Sun.COM 		cnx_display_fwver(handle);
1369517SBill.Taylor@Sun.COM 	}
1379517SBill.Taylor@Sun.COM 
1389517SBill.Taylor@Sun.COM 	return (FWFLASH_SUCCESS);
1399517SBill.Taylor@Sun.COM }
1409517SBill.Taylor@Sun.COM 
1419517SBill.Taylor@Sun.COM static uint16_t
cnx_check_hwver_img(ib_cnx_encap_ident_t * handle)1429517SBill.Taylor@Sun.COM cnx_check_hwver_img(ib_cnx_encap_ident_t *handle)
1439517SBill.Taylor@Sun.COM {
1449517SBill.Taylor@Sun.COM 	uint8_t	hwver;
1459517SBill.Taylor@Sun.COM 	uint8_t	local_hwver;
1469517SBill.Taylor@Sun.COM 
1479517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "hermon: verify: cnx_check_hwver_img\n");
1489517SBill.Taylor@Sun.COM 	if ((handle->state & FWFLASH_IB_STATE_IMAGE_PRI) == 0 &&
1499517SBill.Taylor@Sun.COM 	    (handle->state & FWFLASH_IB_STATE_IMAGE_SEC) == 0) {
1509517SBill.Taylor@Sun.COM 		logmsg(MSG_ERROR, gettext("hermon: Must read in image "
1519517SBill.Taylor@Sun.COM 		    "first\n"));
1529517SBill.Taylor@Sun.COM 		return (1);
1539517SBill.Taylor@Sun.COM 	}
1549517SBill.Taylor@Sun.COM 
1559517SBill.Taylor@Sun.COM 	/* Read Flash HW Version */
1569517SBill.Taylor@Sun.COM 	hwver = (uint8_t)handle->hwrev;
1579517SBill.Taylor@Sun.COM 	local_hwver = (ntohl(verifier->fwimage[CNX_HWVER_OFFSET / 4]) &
1589517SBill.Taylor@Sun.COM 	    CNX_HWVER_MASK) >> 24;
1599517SBill.Taylor@Sun.COM 
1609517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "local_hwver: %x, hwver: %x\n", local_hwver, hwver);
1619517SBill.Taylor@Sun.COM 
1629517SBill.Taylor@Sun.COM 	if ((hwver == 0xA0 || hwver == 0x00 || hwver == 0x20) &&
1639517SBill.Taylor@Sun.COM 	    (local_hwver == 0x00 || local_hwver == 0xA0 ||
1649517SBill.Taylor@Sun.COM 	    local_hwver == 0x20)) {
1659517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, ("A0 board found.\r\n"));
1669517SBill.Taylor@Sun.COM 	} else if (hwver == 0xA1 && local_hwver == 0xA1) {
1679517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, ("A1 board found.\r\n"));
1689517SBill.Taylor@Sun.COM 	} else if (hwver == 0xA2 && local_hwver == 0xA2) {
1699517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, ("A2 board found.\r\n"));
1709517SBill.Taylor@Sun.COM 	} else if (hwver == 0xA3 && local_hwver == 0xA3) {
1719517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, ("A3 board found.\r\n"));
172*12472SShantkumar.Hiremath@Sun.COM 	} else if (hwver == 0xB0 && local_hwver == 0xB0) {
173*12472SShantkumar.Hiremath@Sun.COM 		logmsg(MSG_INFO, ("B0 board found.\r\n"));
174*12472SShantkumar.Hiremath@Sun.COM 	} else if (hwver != local_hwver) {
1759517SBill.Taylor@Sun.COM 		return ((uint16_t)(local_hwver << 8) | hwver);
1769517SBill.Taylor@Sun.COM 	}
1779517SBill.Taylor@Sun.COM 	return (0);
1789517SBill.Taylor@Sun.COM }
1799517SBill.Taylor@Sun.COM 
1809517SBill.Taylor@Sun.COM static void
cnx_display_fwver(ib_cnx_encap_ident_t * handle)1819517SBill.Taylor@Sun.COM cnx_display_fwver(ib_cnx_encap_ident_t *handle)
1829517SBill.Taylor@Sun.COM {
1839517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "hermon: verify: cnx_display_fwver\n");
1849517SBill.Taylor@Sun.COM 
1859517SBill.Taylor@Sun.COM 	(void) fprintf(stdout, gettext("  The current HCA firmware version "
18610618SShantkumar.Hiremath@Sun.COM 	    "is    : %d.%d.%03d\n"),
1879517SBill.Taylor@Sun.COM 	    handle->hwfw_img_info.fw_rev.major,
1889517SBill.Taylor@Sun.COM 	    handle->hwfw_img_info.fw_rev.minor,
1899517SBill.Taylor@Sun.COM 	    handle->hwfw_img_info.fw_rev.subminor);
1909517SBill.Taylor@Sun.COM 	(void) fprintf(stdout, gettext("  Will be updated to HCA firmware "
19110618SShantkumar.Hiremath@Sun.COM 	    "ver of : %d.%d.%03d\n"),
1929517SBill.Taylor@Sun.COM 	    handle->file_img_info.fw_rev.major,
1939517SBill.Taylor@Sun.COM 	    handle->file_img_info.fw_rev.minor,
1949517SBill.Taylor@Sun.COM 	    handle->file_img_info.fw_rev.subminor);
1959517SBill.Taylor@Sun.COM }
1969517SBill.Taylor@Sun.COM 
1979517SBill.Taylor@Sun.COM static uchar_t *
cnx_flash_get_psid_img(ib_cnx_encap_ident_t * handle)1989517SBill.Taylor@Sun.COM cnx_flash_get_psid_img(ib_cnx_encap_ident_t *handle)
1999517SBill.Taylor@Sun.COM {
2009517SBill.Taylor@Sun.COM 	uint32_t	ii_ptr_addr;
2019517SBill.Taylor@Sun.COM 	uint32_t	ii_size;
2029517SBill.Taylor@Sun.COM 
2039517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "hermon: verify: cnx_flash_get_psid_img\n");
2049517SBill.Taylor@Sun.COM 
2059517SBill.Taylor@Sun.COM 	/* Get the image info pointer */
2069517SBill.Taylor@Sun.COM 	ii_ptr_addr = ntohl(verifier->fwimage[CNX_IMG_INF_PTR_OFFSET / 4]);
2079517SBill.Taylor@Sun.COM 	ii_ptr_addr &= 0xffffff; /* Bits 23:0 - Image Info Data Pointer */
2089517SBill.Taylor@Sun.COM 
2099517SBill.Taylor@Sun.COM 	/* Get the image info size, a negative offset from the image info ptr */
2109517SBill.Taylor@Sun.COM 	ii_size =
2119517SBill.Taylor@Sun.COM 	    ntohl(verifier->fwimage[(ii_ptr_addr + CNX_IMG_INF_SZ_OFFSET) / 4]);
2129517SBill.Taylor@Sun.COM 	/* size is in dwords--convert it to bytes */
2139517SBill.Taylor@Sun.COM 	ii_size *= 4;
2149517SBill.Taylor@Sun.COM 
2159517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "ImgInfo_ptr_addr: 0x%lx, ImgInfo_size: 0x%x\n",
2169517SBill.Taylor@Sun.COM 	    ii_ptr_addr, ii_size);
2179517SBill.Taylor@Sun.COM 
2189517SBill.Taylor@Sun.COM 	/* Parse the image info section */
2199517SBill.Taylor@Sun.COM 	if (cnx_parse_img_info(&verifier->fwimage[ii_ptr_addr / 4], ii_size,
2209517SBill.Taylor@Sun.COM 	    &handle->file_img_info, CNX_FILE_IMG) != FWFLASH_SUCCESS) {
2219517SBill.Taylor@Sun.COM 		logmsg(MSG_WARN, gettext("hermon: Failed to parse ImageInfo "
2229517SBill.Taylor@Sun.COM 		    "section\n"));
2239517SBill.Taylor@Sun.COM 		return (NULL);
2249517SBill.Taylor@Sun.COM 	}
2259517SBill.Taylor@Sun.COM 
2269517SBill.Taylor@Sun.COM 	return (handle->file_img_info.psid);
2279517SBill.Taylor@Sun.COM }
2289517SBill.Taylor@Sun.COM 
2299517SBill.Taylor@Sun.COM static void
cnx_flash_verify_flash_pn_img(ib_cnx_encap_ident_t * handle,uchar_t * psid,int psid_size)2309517SBill.Taylor@Sun.COM cnx_flash_verify_flash_pn_img(ib_cnx_encap_ident_t *handle, uchar_t *psid,
2319517SBill.Taylor@Sun.COM     int psid_size)
2329517SBill.Taylor@Sun.COM {
2339517SBill.Taylor@Sun.COM 	int	i;
2349517SBill.Taylor@Sun.COM 	int	no_match = 0;
2359517SBill.Taylor@Sun.COM 
2369517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "hermon: verify: cnx_flash_verify_flash_pn_img\n");
2379517SBill.Taylor@Sun.COM 	/* verify fw matches the hardware */
2389517SBill.Taylor@Sun.COM 	if (handle->hwfw_match == 1) {
2399517SBill.Taylor@Sun.COM 		/* already been verified */
2409517SBill.Taylor@Sun.COM 		return;
2419517SBill.Taylor@Sun.COM 	}
2429517SBill.Taylor@Sun.COM 
2439517SBill.Taylor@Sun.COM 	/* find the PSID from FW in the mlx table */
2449517SBill.Taylor@Sun.COM 	for (i = 0; i < MLX_MAX_ID; i++) {
2459517SBill.Taylor@Sun.COM 		if (handle->hwfw_match == 1) {
2469517SBill.Taylor@Sun.COM 			/*
2479517SBill.Taylor@Sun.COM 			 * Need this check here and the 'continue's below
2489517SBill.Taylor@Sun.COM 			 * because there are some cards that have a
2499517SBill.Taylor@Sun.COM 			 * 'new' part number but the same PSID value.
2509517SBill.Taylor@Sun.COM 			 */
2519517SBill.Taylor@Sun.COM 			break;
2529517SBill.Taylor@Sun.COM 		}
2539517SBill.Taylor@Sun.COM 
2549517SBill.Taylor@Sun.COM 		/* match PSID */
2559517SBill.Taylor@Sun.COM 		if (strncmp((const char *)psid, mlx_mdr[i].mlx_psid,
2569517SBill.Taylor@Sun.COM 		    psid_size) == 0) {
2579517SBill.Taylor@Sun.COM 			logmsg(MSG_INFO, "Found Matching firmware image's "
2589517SBill.Taylor@Sun.COM 			    "PSID (%s) entry in MDR Table\n", psid);
2599517SBill.Taylor@Sun.COM 
2609517SBill.Taylor@Sun.COM 			logmsg(MSG_INFO, "Search for firmware image's part# "
2619517SBill.Taylor@Sun.COM 			    "(%s), MDR/HW PN (%s) \n",
2629517SBill.Taylor@Sun.COM 			    handle->info.mlx_pn, mlx_mdr[i].mlx_pn);
2639517SBill.Taylor@Sun.COM 
2649517SBill.Taylor@Sun.COM 			/* match part numbers */
2659517SBill.Taylor@Sun.COM 			if (strncmp(handle->info.mlx_pn, mlx_mdr[i].mlx_pn,
2669517SBill.Taylor@Sun.COM 			    handle->pn_len) == 0) {
2679517SBill.Taylor@Sun.COM 				handle->hwfw_match = 1;
2689517SBill.Taylor@Sun.COM 				logmsg(MSG_INFO, "Match Found \n");
2699517SBill.Taylor@Sun.COM 				continue;
2709517SBill.Taylor@Sun.COM 			} else {
2719517SBill.Taylor@Sun.COM 				handle->hwfw_match = 0;
2729517SBill.Taylor@Sun.COM 				no_match = i;
2739517SBill.Taylor@Sun.COM 				logmsg(MSG_INFO, "Match NOT Found \n");
2749517SBill.Taylor@Sun.COM 				continue;
2759517SBill.Taylor@Sun.COM 			}
2769517SBill.Taylor@Sun.COM 		}
2779517SBill.Taylor@Sun.COM 	}
2789517SBill.Taylor@Sun.COM 	if (i == MLX_MAX_ID && no_match == 0) {
2799517SBill.Taylor@Sun.COM 		/* no match found */
2809517SBill.Taylor@Sun.COM 		handle->hwfw_match = 0;
2819517SBill.Taylor@Sun.COM 		handle->pn_len = 0;
2829517SBill.Taylor@Sun.COM 		logmsg(MSG_WARN, gettext("hermon: No PSID match found\n"));
2839517SBill.Taylor@Sun.COM 	} else {
2849517SBill.Taylor@Sun.COM 		if (handle->hwfw_match == 0) {
2859517SBill.Taylor@Sun.COM 			logmsg(MSG_WARN, gettext("WARNING: Firmware "
2869517SBill.Taylor@Sun.COM 			    "image is meant for %s but the hardware "
2879517SBill.Taylor@Sun.COM 			    "is %s\n"), mlx_mdr[no_match].mlx_pn,
2889517SBill.Taylor@Sun.COM 			    handle->info.mlx_pn);
2899517SBill.Taylor@Sun.COM 		}
2909517SBill.Taylor@Sun.COM 	}
2919517SBill.Taylor@Sun.COM }
2929517SBill.Taylor@Sun.COM 
2939517SBill.Taylor@Sun.COM static void
cnx_flash_verify_flash_match_img(ib_cnx_encap_ident_t * handle)2949517SBill.Taylor@Sun.COM cnx_flash_verify_flash_match_img(ib_cnx_encap_ident_t *handle)
2959517SBill.Taylor@Sun.COM {
2969517SBill.Taylor@Sun.COM 	uchar_t	*psid;
2979517SBill.Taylor@Sun.COM 
2989517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "hermon: verify: cnx_flash_verify_flash_match_img\n");
2999517SBill.Taylor@Sun.COM 	/* get PSID of firmware file */
3009517SBill.Taylor@Sun.COM 	psid = cnx_flash_get_psid_img(handle);
3019517SBill.Taylor@Sun.COM 	if (psid == NULL) {
3029517SBill.Taylor@Sun.COM 		handle->hwfw_match = 0;
3039517SBill.Taylor@Sun.COM 		handle->pn_len = 0;
3049517SBill.Taylor@Sun.COM 		return;
3059517SBill.Taylor@Sun.COM 	}
3069517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "FW PSID (%s)\n", psid);
3079517SBill.Taylor@Sun.COM 
3089517SBill.Taylor@Sun.COM 	/*
3099517SBill.Taylor@Sun.COM 	 * Check the part number of the hardware against the part number
3109517SBill.Taylor@Sun.COM 	 * of the firmware file. If the hardware information is not
3119517SBill.Taylor@Sun.COM 	 * available, check the currently loaded firmware against the
3129517SBill.Taylor@Sun.COM 	 * firmware file to be uploaded.
3139517SBill.Taylor@Sun.COM 	 */
3149517SBill.Taylor@Sun.COM 	if (handle->pn_len != 0) {
3159517SBill.Taylor@Sun.COM 		cnx_flash_verify_flash_pn_img(handle, psid, CNX_PSID_SZ);
3169517SBill.Taylor@Sun.COM 	}
3179517SBill.Taylor@Sun.COM }
3189517SBill.Taylor@Sun.COM 
3199517SBill.Taylor@Sun.COM 
3209517SBill.Taylor@Sun.COM static int
cnx_check_guid_section()3219517SBill.Taylor@Sun.COM cnx_check_guid_section()
3229517SBill.Taylor@Sun.COM {
3239517SBill.Taylor@Sun.COM 	struct mlx_cnx_xfi  		xfisect;
3249517SBill.Taylor@Sun.COM 	struct mlx_cnx_guid_sect	guidsect;
3259517SBill.Taylor@Sun.COM 	uint32_t			nguidptr_addr;
3269517SBill.Taylor@Sun.COM 	uint16_t			calculated_crc;
3279517SBill.Taylor@Sun.COM 
3289517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "cnx_check_guid_section: \n");
3299517SBill.Taylor@Sun.COM 
3309517SBill.Taylor@Sun.COM 	bcopy(&verifier->fwimage[0], &xfisect, sizeof (struct mlx_cnx_xfi));
3319517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "FailSafeChunkSz: 0x%08x, ImageInfoPtr: 0x%08x\n",
3329517SBill.Taylor@Sun.COM 	    MLXSWAPBITS32(xfisect.failsafechunkinfo),
3339517SBill.Taylor@Sun.COM 	    MLXSWAPBITS32(xfisect.imageinfoptr) & CNX_XFI_IMGINFO_PTR_MASK);
3349517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "FW Size: 0x%08x NGUIDPTR: 0x%08x\n",
3359517SBill.Taylor@Sun.COM 	    MLXSWAPBITS32(xfisect.fwimagesz), MLXSWAPBITS32(xfisect.nguidptr));
3369517SBill.Taylor@Sun.COM 
3379517SBill.Taylor@Sun.COM 	nguidptr_addr = (MLXSWAPBITS32(xfisect.nguidptr) - 0x10) / 4;
3389517SBill.Taylor@Sun.COM 	bcopy(&verifier->fwimage[nguidptr_addr], &guidsect,
3399517SBill.Taylor@Sun.COM 	    sizeof (struct mlx_cnx_guid_sect));
3409517SBill.Taylor@Sun.COM 
3419517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "Node GUID : 0x%016llx \n",
3429517SBill.Taylor@Sun.COM 	    MLXSWAPBITS64(guidsect.nodeguid));
3439517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "Port1 GUID: 0x%016llx \n",
3449517SBill.Taylor@Sun.COM 	    MLXSWAPBITS64(guidsect.port1guid));
3459517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "Port2 GUID: 0x%016llx \n",
3469517SBill.Taylor@Sun.COM 	    MLXSWAPBITS64(guidsect.port2guid));
3479517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "SysIm GUID: 0x%016llx \n",
3489517SBill.Taylor@Sun.COM 	    MLXSWAPBITS64(guidsect.sysimguid));
3499517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "Port 1 MAC: 0x%016llx \n",
3509517SBill.Taylor@Sun.COM 	    MLXSWAPBITS64(guidsect.port1_mac));
3519517SBill.Taylor@Sun.COM 	logmsg(MSG_INFO, "Port 2 MAC: 0x%016llx \n",
3529517SBill.Taylor@Sun.COM 	    MLXSWAPBITS64(guidsect.port2_mac));
3539517SBill.Taylor@Sun.COM 
3549517SBill.Taylor@Sun.COM 	calculated_crc = cnx_crc16((uint8_t *)&verifier->fwimage[nguidptr_addr],
3559517SBill.Taylor@Sun.COM 	    CNX_GUID_CRC16_SIZE, CNX_FILE_IMG);
3569517SBill.Taylor@Sun.COM 	if (calculated_crc != ntohs(guidsect.guidcrc)) {
3579517SBill.Taylor@Sun.COM 		logmsg(MSG_WARN, gettext("hermon: calculated crc value 0x%x "
3589517SBill.Taylor@Sun.COM 		    "differs from GUID section 0x%x\n"), calculated_crc,
3599517SBill.Taylor@Sun.COM 		    ntohs(guidsect.guidcrc));
3609517SBill.Taylor@Sun.COM 	} else {
3619517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, "hermon: calculated crc value 0x%x MATCHES "
3629517SBill.Taylor@Sun.COM 		    "with GUID section 0x%x\n", calculated_crc,
3639517SBill.Taylor@Sun.COM 		    ntohs(guidsect.guidcrc));
3649517SBill.Taylor@Sun.COM 	}
3659517SBill.Taylor@Sun.COM 
3669517SBill.Taylor@Sun.COM 	if ((MLXSWAPBITS64(guidsect.nodeguid) == MLX_DEFAULT_NODE_GUID) &&
3679517SBill.Taylor@Sun.COM 	    (MLXSWAPBITS64(guidsect.port1guid) == MLX_DEFAULT_P1_GUID) &&
3689517SBill.Taylor@Sun.COM 	    (MLXSWAPBITS64(guidsect.port2guid) == MLX_DEFAULT_P2_GUID) &&
3699517SBill.Taylor@Sun.COM 	    ((MLXSWAPBITS64(guidsect.sysimguid) == MLX_DEFAULT_SYSIMG_GUID) ||
3709517SBill.Taylor@Sun.COM 	    (MLXSWAPBITS64(guidsect.sysimguid) == MLX_DEFAULT_NODE_GUID)) ||
3719517SBill.Taylor@Sun.COM 	    ((((MLXSWAPBITS64(guidsect.nodeguid) & HIGHBITS64) >> 40) ==
3729517SBill.Taylor@Sun.COM 	    MLX_OUI) ||
3739517SBill.Taylor@Sun.COM 	    (((MLXSWAPBITS64(guidsect.port1guid) & HIGHBITS64) >> 40) ==
3749517SBill.Taylor@Sun.COM 	    MLX_OUI) ||
3759517SBill.Taylor@Sun.COM 	    (((MLXSWAPBITS64(guidsect.port2guid) & HIGHBITS64) >> 40) ==
3769517SBill.Taylor@Sun.COM 	    MLX_OUI) ||
3779517SBill.Taylor@Sun.COM 	    (((MLXSWAPBITS64(guidsect.sysimguid) & HIGHBITS64) >> 40) ==
3789517SBill.Taylor@Sun.COM 	    MLX_OUI)) ||
3799517SBill.Taylor@Sun.COM 	    ((((MLXSWAPBITS64(guidsect.nodeguid) & HIGHBITS64) >> 40) ==
3809517SBill.Taylor@Sun.COM 	    SUNW_OUI) ||
3819517SBill.Taylor@Sun.COM 	    (((MLXSWAPBITS64(guidsect.port1guid) & HIGHBITS64) >> 40) ==
3829517SBill.Taylor@Sun.COM 	    SUNW_OUI) ||
3839517SBill.Taylor@Sun.COM 	    (((MLXSWAPBITS64(guidsect.port2guid) & HIGHBITS64) >> 40) ==
3849517SBill.Taylor@Sun.COM 	    SUNW_OUI) ||
3859517SBill.Taylor@Sun.COM 	    (((MLXSWAPBITS64(guidsect.sysimguid) & HIGHBITS64) >> 40) ==
3869517SBill.Taylor@Sun.COM 	    SUNW_OUI))) {
3879517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, "%s firmware image verifier: GUID Prefix "
3889517SBill.Taylor@Sun.COM 		    "is as expected\n", verifier->vendor);
3899517SBill.Taylor@Sun.COM 		return (FWFLASH_SUCCESS);
3909517SBill.Taylor@Sun.COM 	} else {
3919517SBill.Taylor@Sun.COM 		logmsg(MSG_INFO, "%s firmware image verifier: GUID prefix "
3929517SBill.Taylor@Sun.COM 		    "is not as expected\n", verifier->vendor);
3939517SBill.Taylor@Sun.COM 		return (FWFLASH_FAILURE);
3949517SBill.Taylor@Sun.COM 	}
3959517SBill.Taylor@Sun.COM }
396