efx_vpd.c revision 49ef7e0638c8b771d8a136eae78b1c0f99acc8e0
/*
* Copyright (c) 2009-2015 Solarflare Communications Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the FreeBSD Project.
*/
#include "efx.h"
#include "efx_impl.h"
#if EFSYS_OPT_VPD
#define TAG_TYPE_LBN 7
#define TAG_TYPE_WIDTH 1
#define TAG_TYPE_LARGE_ITEM_DECODE 1
#define TAG_TYPE_SMALL_ITEM_DECODE 0
#define TAG_SMALL_ITEM_NAME_LBN 3
#define TAG_SMALL_ITEM_NAME_WIDTH 4
#define TAG_SMALL_ITEM_SIZE_LBN 0
#define TAG_SMALL_ITEM_SIZE_WIDTH 3
#define TAG_LARGE_ITEM_NAME_LBN 0
#define TAG_LARGE_ITEM_NAME_WIDTH 7
#define TAG_NAME_END_DECODE 0x0f
#define TAG_NAME_ID_STRING_DECODE 0x02
#define TAG_NAME_VPD_R_DECODE 0x10
#define TAG_NAME_VPD_W_DECODE 0x11
#if EFSYS_OPT_SIENA
static const efx_vpd_ops_t __efx_vpd_siena_ops = {
siena_vpd_init, /* evpdo_init */
siena_vpd_size, /* evpdo_size */
siena_vpd_read, /* evpdo_read */
siena_vpd_verify, /* evpdo_verify */
siena_vpd_reinit, /* evpdo_reinit */
siena_vpd_get, /* evpdo_get */
siena_vpd_set, /* evpdo_set */
siena_vpd_next, /* evpdo_next */
siena_vpd_write, /* evpdo_write */
siena_vpd_fini, /* evpdo_fini */
};
#endif /* EFSYS_OPT_SIENA */
static const efx_vpd_ops_t __efx_vpd_ef10_ops = {
ef10_vpd_init, /* evpdo_init */
ef10_vpd_size, /* evpdo_size */
ef10_vpd_read, /* evpdo_read */
ef10_vpd_verify, /* evpdo_verify */
ef10_vpd_reinit, /* evpdo_reinit */
ef10_vpd_get, /* evpdo_get */
ef10_vpd_set, /* evpdo_set */
ef10_vpd_next, /* evpdo_next */
ef10_vpd_write, /* evpdo_write */
ef10_vpd_fini, /* evpdo_fini */
};
#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
{
const efx_vpd_ops_t *evpdop;
#if EFSYS_OPT_SIENA
case EFX_FAMILY_SIENA:
break;
#endif /* EFSYS_OPT_SIENA */
case EFX_FAMILY_HUNTINGTON:
break;
#endif /* EFSYS_OPT_HUNTINGTON */
case EFX_FAMILY_MEDFORD:
break;
#endif /* EFSYS_OPT_MEDFORD */
default:
EFSYS_ASSERT(0);
goto fail1;
}
goto fail2;
}
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
{
goto fail1;
}
goto fail2;
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
{
goto fail1;
return (0);
return (rc);
}
static __checkReturn efx_rc_t
{
goto fail1;
}
headlen = 1;
break;
headlen = 3;
goto fail2;
}
break;
default:
goto fail2;
}
goto fail3;
}
name != EFX_VPD_RO) {
goto fail4;
}
return (0);
return (rc);
}
static __checkReturn efx_rc_t
{
goto fail1;
}
goto fail2;
}
return (0);
return (rc);
}
{
unsigned int offset;
offset = 0;
while (1) {
goto fail1;
if (tag == EFX_VPD_END)
break;
}
return (0);
return (rc);
}
{
unsigned int offset;
unsigned int pos;
unsigned int i;
/*
* Parse every tag,keyword in the existing VPD. If the csum is present,
* the assert it is correct, and is the final keyword in the RO block.
*/
offset = 0;
while (1) {
goto fail1;
if (tag == EFX_VPD_END)
break;
else if (tag == EFX_VPD_ID)
goto done;
/* RV keyword must be the last in the block */
if (cksummed) {
goto fail2;
}
goto fail3;
cksum = 0;
if (cksum != 0) {
goto fail4;
}
}
}
done:
}
if (!cksummed) {
goto fail5;
}
return (0);
return (rc);
}
static uint8_t __efx_vpd_blank_pid[] = {
/* Large resource type ID length 1 */
0x82, 0x01, 0x00,
/* Product name ' ' */
0x32,
};
static uint8_t __efx_vpd_blank_r[] = {
/* Large resource type VPD-R length 4 */
0x90, 0x04, 0x00,
/* RV keyword length 1 */
'R', 'V', 0x01,
/* RV payload checksum */
0x00,
};
{
unsigned int offset = 0;
unsigned int pos;
if (size < 0x100) {
goto fail1;
}
if (wantpid) {
sizeof (__efx_vpd_blank_pid));
offset += sizeof (__efx_vpd_blank_pid);
}
sizeof (__efx_vpd_blank_r));
offset += sizeof (__efx_vpd_blank_r);
/* Update checksum */
cksum = 0;
/* Append trailing tag */
TAG_SMALL_ITEM_SIZE, 0);
offset++;
return (0);
return (rc);
}
{
efx_vpd_keyword_t keyword = 0;
unsigned int offset;
unsigned int pos;
unsigned int index;
while (1) {
goto fail1;
if (tag == EFX_VPD_END) {
keyword = 0;
paylen = 0;
index = 0;
break;
}
if (tag == EFX_VPD_ID) {
keyword = 0;
goto done;
}
} else {
goto fail2;
goto done;
}
}
}
}
done:
return (0);
return (rc);
}
{
unsigned int offset;
unsigned int pos;
offset = 0;
while (1) {
goto fail1;
if (itag == EFX_VPD_END)
break;
if (itag == EFX_VPD_ID) {
return (0);
}
goto fail2;
return (0);
}
}
}
}
/* Not an error */
return (ENOENT);
return (rc);
}
{
unsigned int offset;
unsigned int pos;
unsigned int taghead;
unsigned int source;
unsigned int dest;
unsigned int i;
case EFX_VPD_ID:
if (evvp->evv_keyword != 0) {
goto fail1;
}
/* Can't delete the ID keyword */
if (evvp->evv_length == 0) {
goto fail1;
}
break;
case EFX_VPD_RO:
goto fail1;
}
break;
default:
goto fail1;
}
/* Determine total size of all current tags */
goto fail2;
offset = 0;
while (1) {
goto fail3;
if (tag == EFX_VPD_END)
break;
continue;
}
/* We only support modifying large resource tags */
goto fail4;
}
/*
* Work out the offset of the byte immediately after the
*/
pos = 0;
if (tag == EFX_VPD_ID) {
goto check_space;
}
goto fail5;
evvp->evv_length == 0) {
/* Deleting this keyword */
break;
/* Adjusting this keyword */
break;
/* The RV keyword must be at the end */
/*
* The keyword doesn't already exist. If the
* user deleting a non-existant keyword then
* this is a no-op.
*/
if (evvp->evv_length == 0)
return (0);
/* Insert this keyword before the RV keyword */
break;
}
}
goto fail6;
}
/* Move trailing data */
/* Copy contents */
evvp->evv_length);
/* Insert new keyword header if required */
evvp->evv_keyword);
}
/* Modify tag length (large resource type) */
goto checksum;
}
/* Unable to find the matching tag */
goto fail7;
/* Find the RV tag, and update the checksum */
offset = 0;
while (1) {
goto fail8;
if (tag == EFX_VPD_END)
break;
if (tag == EFX_VPD_RO) {
goto fail9;
cksum = 0;
break;
}
}
}
}
/* Zero out the unused portion */
return (0);
return (rc);
}
void
{
}
#endif /* EFSYS_OPT_VPD */