1*9e39c5baSBill Taylor /* 2*9e39c5baSBill Taylor * CDDL HEADER START 3*9e39c5baSBill Taylor * 4*9e39c5baSBill Taylor * The contents of this file are subject to the terms of the 5*9e39c5baSBill Taylor * Common Development and Distribution License (the "License"). 6*9e39c5baSBill Taylor * You may not use this file except in compliance with the License. 7*9e39c5baSBill Taylor * 8*9e39c5baSBill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*9e39c5baSBill Taylor * or http://www.opensolaris.org/os/licensing. 10*9e39c5baSBill Taylor * See the License for the specific language governing permissions 11*9e39c5baSBill Taylor * and limitations under the License. 12*9e39c5baSBill Taylor * 13*9e39c5baSBill Taylor * When distributing Covered Code, include this CDDL HEADER in each 14*9e39c5baSBill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*9e39c5baSBill Taylor * If applicable, add the following below this CDDL HEADER, with the 16*9e39c5baSBill Taylor * fields enclosed by brackets "[]" replaced with your own identifying 17*9e39c5baSBill Taylor * information: Portions Copyright [yyyy] [name of copyright owner] 18*9e39c5baSBill Taylor * 19*9e39c5baSBill Taylor * CDDL HEADER END 20*9e39c5baSBill Taylor */ 21*9e39c5baSBill Taylor 22*9e39c5baSBill Taylor /* 23*9e39c5baSBill Taylor * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*9e39c5baSBill Taylor * Use is subject to license terms. 25*9e39c5baSBill Taylor */ 26*9e39c5baSBill Taylor 27*9e39c5baSBill Taylor #ifndef _HDRS_HERMON_IB_H 28*9e39c5baSBill Taylor #define _HDRS_HERMON_IB_H 29*9e39c5baSBill Taylor 30*9e39c5baSBill Taylor #ifdef __cplusplus 31*9e39c5baSBill Taylor extern "C" { 32*9e39c5baSBill Taylor #endif 33*9e39c5baSBill Taylor 34*9e39c5baSBill Taylor /* 35*9e39c5baSBill Taylor * ConnectX (hermon) specific definitions. 36*9e39c5baSBill Taylor */ 37*9e39c5baSBill Taylor 38*9e39c5baSBill Taylor /* 39*9e39c5baSBill Taylor * The reference for the definitions in this file is the 40*9e39c5baSBill Taylor * 41*9e39c5baSBill Taylor * Mellanox HCA Flash Programming Application Note 42*9e39c5baSBill Taylor * (Mellanox document number 2205AN) 43*9e39c5baSBill Taylor * rev 1.45, 2007. Chapter 4 in particular. 44*9e39c5baSBill Taylor */ 45*9e39c5baSBill Taylor 46*9e39c5baSBill Taylor #include <sys/types.h> 47*9e39c5baSBill Taylor #include <sys/ib/adapters/hermon/hermon_ioctl.h> 48*9e39c5baSBill Taylor #include "MELLANOX.h" 49*9e39c5baSBill Taylor 50*9e39c5baSBill Taylor #define FWFLASH_IB_HERMON_DRIVER "hermon" 51*9e39c5baSBill Taylor 52*9e39c5baSBill Taylor /* 53*9e39c5baSBill Taylor * Image Info section: Refer Mellanox App note 1.45, Section 4.4 54*9e39c5baSBill Taylor * 55*9e39c5baSBill Taylor * The Image Info section contains management information about the 56*9e39c5baSBill Taylor * firmware image. It consists of a series of consecutive data tags. 57*9e39c5baSBill Taylor * Each tag contains a 32-bit header, providing a TagID which indicates 58*9e39c5baSBill Taylor * the data type, and the size of the data in the tag. 59*9e39c5baSBill Taylor */ 60*9e39c5baSBill Taylor #define MLX_MASK_TAGID 0xff000000 61*9e39c5baSBill Taylor #define MLX_MASK_TAGSIZE 0x00ffffff 62*9e39c5baSBill Taylor 63*9e39c5baSBill Taylor enum tag_ids { 64*9e39c5baSBill Taylor CNX_IMAGE_INFO_REV = 0, /* IMAGE_INFO format revision */ 65*9e39c5baSBill Taylor CNX_FW_VER = 1, /* Firmware Version */ 66*9e39c5baSBill Taylor CNX_FW_BUILD_TIME = 2, /* Firmware Build Time */ 67*9e39c5baSBill Taylor CNX_DEV_TYPE = 3, /* Device Type */ 68*9e39c5baSBill Taylor CNX_PSID = 4, /* Parameter Set IDentification */ 69*9e39c5baSBill Taylor CNX_VSD = 5, /* Vendor Specific Data */ 70*9e39c5baSBill Taylor CNX_RES1 = 6, /* reserved */ 71*9e39c5baSBill Taylor CNX_RES2 = 7, /* reserved */ 72*9e39c5baSBill Taylor CNX_VSD_VENDOR_ID = 8, /* PCISIG vendor ID */ 73*9e39c5baSBill Taylor /* 0x9 - 0xFE are reserved */ 74*9e39c5baSBill Taylor CNX_END_TAG = 0xff /* END tag */ 75*9e39c5baSBill Taylor }; 76*9e39c5baSBill Taylor 77*9e39c5baSBill Taylor enum tag_sizes { 78*9e39c5baSBill Taylor CNX_IMAGE_INFO_REV_SZ = 4, 79*9e39c5baSBill Taylor CNX_FW_VER_SZ = 8, 80*9e39c5baSBill Taylor CNX_FW_BUILD_TIME_SZ = 8, 81*9e39c5baSBill Taylor CNX_DEV_TYPE_SZ = 4, 82*9e39c5baSBill Taylor CNX_PSID_SZ = 16, 83*9e39c5baSBill Taylor CNX_VSD_SZ = 208, 84*9e39c5baSBill Taylor CNX_VSD_VENDOR_ID_SZ = 4, 85*9e39c5baSBill Taylor CNX_END_TAG_SZ = 0 86*9e39c5baSBill Taylor }; 87*9e39c5baSBill Taylor 88*9e39c5baSBill Taylor /* 89*9e39c5baSBill Taylor * Image Info Format revision (TagID - CNX_IMAGE_INFO_REV). 90*9e39c5baSBill Taylor * Provides the format revision of the Image Info section. Currently it is 0x1 91*9e39c5baSBill Taylor */ 92*9e39c5baSBill Taylor #define CNX_IMAGE_INFO_VER 1 93*9e39c5baSBill Taylor 94*9e39c5baSBill Taylor /* 95*9e39c5baSBill Taylor * Firmware Version (TagID - CNX_FW_VER) 96*9e39c5baSBill Taylor * Provides the major, minor and sub-minor versions of the firmware image. 97*9e39c5baSBill Taylor */ 98*9e39c5baSBill Taylor #define CNX_MASK_FW_VER_MAJ 0xffff0000 99*9e39c5baSBill Taylor #define CNX_MASK_FW_VER_MIN CNX_MASK_FW_VER_MAJ 100*9e39c5baSBill Taylor #define CNX_MASK_FW_VER_SUBMIN 0x0000ffff 101*9e39c5baSBill Taylor 102*9e39c5baSBill Taylor typedef struct cnx_fw_rev_s { 103*9e39c5baSBill Taylor uint16_t major; 104*9e39c5baSBill Taylor uint16_t reserved; 105*9e39c5baSBill Taylor uint16_t minor; 106*9e39c5baSBill Taylor uint16_t subminor; 107*9e39c5baSBill Taylor } cnx_fw_rev_t; 108*9e39c5baSBill Taylor 109*9e39c5baSBill Taylor 110*9e39c5baSBill Taylor /* 111*9e39c5baSBill Taylor * Firmware Build Time (TagID - CNX_FW_BUILD_TIME) 112*9e39c5baSBill Taylor * Provides the data and time of the firmware image build. 113*9e39c5baSBill Taylor */ 114*9e39c5baSBill Taylor #define CNX_MASK_FW_BUILD_HOUR 0x00ff0000 115*9e39c5baSBill Taylor #define CNX_MASK_FW_BUILD_MIN 0x0000ff00 116*9e39c5baSBill Taylor #define CNX_MASK_FW_BUILD_SEC 0x000000ff 117*9e39c5baSBill Taylor #define CNX_MASK_FW_BUILD_YEAR 0xffff0000 118*9e39c5baSBill Taylor #define CNX_MASK_FW_BUILD_MON 0x0000ff00 119*9e39c5baSBill Taylor #define CNX_MASK_FW_BUILD_DAY 0x000000ff 120*9e39c5baSBill Taylor 121*9e39c5baSBill Taylor typedef struct cnx_fw_build_time_tag { 122*9e39c5baSBill Taylor uint8_t reserved; 123*9e39c5baSBill Taylor uint8_t hour; 124*9e39c5baSBill Taylor uint8_t minute; 125*9e39c5baSBill Taylor uint8_t second; 126*9e39c5baSBill Taylor uint16_t year; 127*9e39c5baSBill Taylor uint8_t month; 128*9e39c5baSBill Taylor uint8_t day; 129*9e39c5baSBill Taylor } cnx_fw_build_time_t; 130*9e39c5baSBill Taylor 131*9e39c5baSBill Taylor /* 132*9e39c5baSBill Taylor * Device Type (TagID - CNX_DEV_TYPE) 133*9e39c5baSBill Taylor * The device type tag is only 4 bytes long, so we don't bother to 134*9e39c5baSBill Taylor * declare a separate struct for it. 135*9e39c5baSBill Taylor * 136*9e39c5baSBill Taylor * The CNX_MASK_DEV_TYPE_REV provides the mask to extract the hardware 137*9e39c5baSBill Taylor * device's PCI Revision ID. 138*9e39c5baSBill Taylor * The CNX_MASK_DEV_TYPE_ID provides the mask to extract the hardware 139*9e39c5baSBill Taylor * device's PCI Device ID. 140*9e39c5baSBill Taylor */ 141*9e39c5baSBill Taylor #define CNX_MASK_DEV_TYPE_REV 0x00ff0000 142*9e39c5baSBill Taylor #define CNX_MASK_DEV_TYPE_ID 0x0000ffff 143*9e39c5baSBill Taylor 144*9e39c5baSBill Taylor /* 145*9e39c5baSBill Taylor * The PSID (TagID - CNX_PSID) and VSD (TagID - CNX_VSD) tag contents are 146*9e39c5baSBill Taylor * just bytes without any specific structure, so we'll declare their sizes 147*9e39c5baSBill Taylor * but nothing else. 148*9e39c5baSBill Taylor */ 149*9e39c5baSBill Taylor #define CNX_TAG_PSID_SIZE 0x10 150*9e39c5baSBill Taylor #define CNX_TAG_VSD_SIZE 0xD0 151*9e39c5baSBill Taylor 152*9e39c5baSBill Taylor /* 153*9e39c5baSBill Taylor * VSD Vendor ID (TagID - CNX_VSD_VENDOR_ID) 154*9e39c5baSBill Taylor * The VSD Vendor ID tag holds the PCISIG vendor ID of the vendor that 155*9e39c5baSBill Taylor * fills the VSD tag. 156*9e39c5baSBill Taylor */ 157*9e39c5baSBill Taylor #define CNX_MASK_VSD_VENDORID 0x00ff 158*9e39c5baSBill Taylor 159*9e39c5baSBill Taylor typedef struct cnx_img_info_s { 160*9e39c5baSBill Taylor cnx_fw_rev_t fw_rev; 161*9e39c5baSBill Taylor cnx_fw_build_time_t fw_buildtime; 162*9e39c5baSBill Taylor uint16_t dev_id; 163*9e39c5baSBill Taylor uint16_t vsd_vendor_id; 164*9e39c5baSBill Taylor uint8_t psid[CNX_PSID_SZ]; 165*9e39c5baSBill Taylor uint8_t vsd[CNX_VSD_SZ]; 166*9e39c5baSBill Taylor } cnx_img_info_t; 167*9e39c5baSBill Taylor 168*9e39c5baSBill Taylor /* 169*9e39c5baSBill Taylor * ConnectX Devices Firmware Image Format 170*9e39c5baSBill Taylor */ 171*9e39c5baSBill Taylor typedef struct mlx_cnx_xfi { /* Byte Offset */ 172*9e39c5baSBill Taylor uint32_t magic_pattern[4]; /* 0x00 - 0x0F */ 173*9e39c5baSBill Taylor uint8_t xfiresv1[24]; /* 0x10 - 0x27 */ 174*9e39c5baSBill Taylor uint32_t failsafechunkinfo; /* 0x28 - 0x2B */ 175*9e39c5baSBill Taylor uint32_t imageinfoptr; /* 0x2C - 0x2F */ 176*9e39c5baSBill Taylor uint32_t fwimagesz; /* 0x30 - 0x33 */ 177*9e39c5baSBill Taylor uint32_t nguidptr; /* 0x34 - 0x37 */ 178*9e39c5baSBill Taylor uint8_t *xfiremainder; 179*9e39c5baSBill Taylor } mlx_cnx_xfi_t; 180*9e39c5baSBill Taylor 181*9e39c5baSBill Taylor uint32_t cnx_magic_pattern[4] = { 182*9e39c5baSBill Taylor 0x4D544657, 183*9e39c5baSBill Taylor 0x8CDFD000, 184*9e39c5baSBill Taylor 0xDEAD9270, 185*9e39c5baSBill Taylor 0x4154BEEF }; 186*9e39c5baSBill Taylor 187*9e39c5baSBill Taylor #define CNX_XFI_IMGINFO_CKSUM_MASK 0xFF000000 188*9e39c5baSBill Taylor #define CNX_XFI_IMGINFO_PTR_MASK 0x00FFFFFF 189*9e39c5baSBill Taylor 190*9e39c5baSBill Taylor #define CNX_HWVER_OFFSET 0x20 191*9e39c5baSBill Taylor #define CNX_HWVER_MASK 0xFF000000 192*9e39c5baSBill Taylor 193*9e39c5baSBill Taylor #define CNX_CHUNK_SIZE_OFFSET 0x28 194*9e39c5baSBill Taylor #define CNX_IMG_INF_PTR_OFFSET 0x2C 195*9e39c5baSBill Taylor #define CNX_IMG_INF_SZ_OFFSET -0x0C 196*9e39c5baSBill Taylor #define CNX_IMG_SIZE_OFFSET 0x30 197*9e39c5baSBill Taylor #define CNX_NGUIDPTR_OFFSET 0x34 198*9e39c5baSBill Taylor 199*9e39c5baSBill Taylor /* 200*9e39c5baSBill Taylor * ConnectX Devices GUID Section Structure. 201*9e39c5baSBill Taylor * 202*9e39c5baSBill Taylor * Of all the structures we poke around with, we're packing 203*9e39c5baSBill Taylor * these because we frequently have to operate on them as 204*9e39c5baSBill Taylor * plain old byte arrays. If we don't pack it then the compiler 205*9e39c5baSBill Taylor * will "properly" align it for us - which results in a 206*9e39c5baSBill Taylor * structure that's a l l s p r e a d o u t. 207*9e39c5baSBill Taylor */ 208*9e39c5baSBill Taylor #pragma pack(1) 209*9e39c5baSBill Taylor typedef struct mlx_cnx_guid_sect { /* Byte Offset */ 210*9e39c5baSBill Taylor uint8_t guidresv[16]; /* 0x00 - 0x0F */ 211*9e39c5baSBill Taylor uint64_t nodeguid; /* 0x10 - 0x17 */ 212*9e39c5baSBill Taylor uint64_t port1guid; /* 0x18 - 0x1F */ 213*9e39c5baSBill Taylor uint64_t port2guid; /* 0x20 - 0x27 */ 214*9e39c5baSBill Taylor uint64_t sysimguid; /* 0x28 - 0x2F */ 215*9e39c5baSBill Taylor uint64_t port1_mac; /* 0x30 - 0x31 - rsvd - must be zero */ 216*9e39c5baSBill Taylor /* 0x32 - 0x37 - Port1 MAC [47:0] */ 217*9e39c5baSBill Taylor uint64_t port2_mac; /* 0x38 - 0x39 - rsvd - must be zero */ 218*9e39c5baSBill Taylor /* 0x3A - 0x3F - Port2 MAC [47:0] */ 219*9e39c5baSBill Taylor uint16_t guidresv2; /* 0x40 - 0x41 */ 220*9e39c5baSBill Taylor uint16_t guidcrc; /* 0x42 - 0x43 */ 221*9e39c5baSBill Taylor } mlx_cnx_guid_sect_t; 222*9e39c5baSBill Taylor #pragma pack() 223*9e39c5baSBill Taylor 224*9e39c5baSBill Taylor #define CNX_NGUID_OFFSET 0x10 225*9e39c5baSBill Taylor #define CNX_P1GUID_OFFSET 0x18 226*9e39c5baSBill Taylor #define CNX_P2GUID_OFFSET 0x20 227*9e39c5baSBill Taylor #define CNX_SYSIMGUID_OFFSET 0x28 228*9e39c5baSBill Taylor #define CNX_P1MAC_OFFSET 0x32 229*9e39c5baSBill Taylor #define CNX_P2MAC_OFFSET 0x3A 230*9e39c5baSBill Taylor #define CNX_GUID_CRC16_SIZE 0x40 /* 00-3F */ 231*9e39c5baSBill Taylor #define CNX_GUID_CRC16_OFFSET 0x42 232*9e39c5baSBill Taylor 233*9e39c5baSBill Taylor 234*9e39c5baSBill Taylor /* we hook this struct into vpr->encap_ident */ 235*9e39c5baSBill Taylor typedef struct ib_cnx_encap_ident_s { 236*9e39c5baSBill Taylor uint_t magic; /* FWFLASH_IB_MAGIC_NUMBER */ 237*9e39c5baSBill Taylor int fd; /* fd of hermon device */ 238*9e39c5baSBill Taylor int cmd_set; /* COMMAND SET */ 239*9e39c5baSBill Taylor int pn_len; /* Part# Length */ 240*9e39c5baSBill Taylor int hwfw_match; /* 1 = match, 0 - nomatch */ 241*9e39c5baSBill Taylor /* Used during write for validation */ 242*9e39c5baSBill Taylor cnx_img_info_t hwfw_img_info; /* HW Image Info Section */ 243*9e39c5baSBill Taylor cnx_img_info_t file_img_info; /* Image File's Image Info Section */ 244*9e39c5baSBill Taylor mlx_mdr_t info; /* Details of HW part#, name, */ 245*9e39c5baSBill Taylor uint32_t *fw; /* this where image is read to */ 246*9e39c5baSBill Taylor uint32_t hwrev; /* H/W revision. ex: A0, A1 */ 247*9e39c5baSBill Taylor uint32_t fw_sz; /* FW image size */ 248*9e39c5baSBill Taylor uint32_t sector_sz; /* FW sector size */ 249*9e39c5baSBill Taylor uint32_t device_sz; /* FW device size */ 250*9e39c5baSBill Taylor uint32_t state; 251*9e39c5baSBill Taylor uint64_t ibguids[4]; /* HW's GUIDs backup info */ 252*9e39c5baSBill Taylor uint64_t ib_mac[2]; /* HW's MAC backup info */ 253*9e39c5baSBill Taylor uint32_t log2_chunk_sz; /* FW chunk size */ 254*9e39c5baSBill Taylor uint32_t img2_start_addr; /* Boot Address, 0 - Pri */ 255*9e39c5baSBill Taylor } ib_cnx_encap_ident_t; 256*9e39c5baSBill Taylor 257*9e39c5baSBill Taylor /* 258*9e39c5baSBill Taylor * Common Flash Interface data. 259*9e39c5baSBill Taylor */ 260*9e39c5baSBill Taylor typedef union cfi_u { 261*9e39c5baSBill Taylor uchar_t cfi_char[HERMON_CFI_INFO_SIZE]; 262*9e39c5baSBill Taylor uint32_t cfi_int[HERMON_CFI_INFO_QSIZE]; 263*9e39c5baSBill Taylor } cfi_t; 264*9e39c5baSBill Taylor 265*9e39c5baSBill Taylor /* used by both identify and verifier plugin */ 266*9e39c5baSBill Taylor uint16_t cnx_crc16(uint8_t *image, uint32_t size, int is_image); 267*9e39c5baSBill Taylor int cnx_is_magic_pattern_present(int *data, int hwim_or_fwim); 268*9e39c5baSBill Taylor int cnx_parse_img_info(int *buf, uint32_t byte_size, cnx_img_info_t *img_info, 269*9e39c5baSBill Taylor int is_image); 270*9e39c5baSBill Taylor 271*9e39c5baSBill Taylor #define CNX_FILE_IMG 1 /* Processing File Image */ 272*9e39c5baSBill Taylor #define CNX_HW_IMG 2 /* Processing Hardware Image */ 273*9e39c5baSBill Taylor 274*9e39c5baSBill Taylor /* Validate the handle */ 275*9e39c5baSBill Taylor #define CNX_I_CHECK_HANDLE(s) \ 276*9e39c5baSBill Taylor ((s == NULL) || ((s)->magic != FWFLASH_IB_MAGIC_NUMBER)) 277*9e39c5baSBill Taylor 278*9e39c5baSBill Taylor #ifdef __cplusplus 279*9e39c5baSBill Taylor } 280*9e39c5baSBill Taylor #endif 281*9e39c5baSBill Taylor 282*9e39c5baSBill Taylor #endif /* _HDRS_HERMON_IB_H */ 283