From owner-svn-src-all@freebsd.org Sat Jun 4 14:26:42 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6BFCCB6A1D1; Sat, 4 Jun 2016 14:26:42 +0000 (UTC) (envelope-from arybchik@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2EA8113C2; Sat, 4 Jun 2016 14:26:42 +0000 (UTC) (envelope-from arybchik@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u54EQfUE088292; Sat, 4 Jun 2016 14:26:41 GMT (envelope-from arybchik@FreeBSD.org) Received: (from arybchik@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u54EQej6088287; Sat, 4 Jun 2016 14:26:40 GMT (envelope-from arybchik@FreeBSD.org) Message-Id: <201606041426.u54EQej6088287@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: arybchik set sender to arybchik@FreeBSD.org using -f From: Andrew Rybchenko Date: Sat, 4 Jun 2016 14:26:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r301321 - stable/10/sys/dev/sfxge/common X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jun 2016 14:26:42 -0000 Author: arybchik Date: Sat Jun 4 14:26:40 2016 New Revision: 301321 URL: https://svnweb.freebsd.org/changeset/base/301321 Log: MFC r299318 sfxge(4): restructure TLV buffer validation Move TLV buffer validation into ef10-specific function and add accessor function which also converts the partition ID to the internal representation. Submitted by: Richard Houldsworth Sponsored by: Solarflare Communications, Inc. Modified: stable/10/sys/dev/sfxge/common/efx.h stable/10/sys/dev/sfxge/common/efx_impl.h stable/10/sys/dev/sfxge/common/efx_nvram.c stable/10/sys/dev/sfxge/common/hunt_impl.h stable/10/sys/dev/sfxge/common/hunt_nvram.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/sfxge/common/efx.h ============================================================================== --- stable/10/sys/dev/sfxge/common/efx.h Sat Jun 4 14:23:11 2016 (r301320) +++ stable/10/sys/dev/sfxge/common/efx.h Sat Jun 4 14:26:40 2016 (r301321) @@ -1370,11 +1370,10 @@ efx_nvram_set_version( __in efx_nvram_type_t type, __in_ecount(4) uint16_t version[4]); -/* Validate contents of TLV formatted partition */ extern __checkReturn efx_rc_t -efx_nvram_tlv_validate( +efx_nvram_validate( __in efx_nic_t *enp, - __in uint32_t partn, + __in efx_nvram_type_t type, __in_bcount(partn_size) caddr_t partn_data, __in size_t partn_size); Modified: stable/10/sys/dev/sfxge/common/efx_impl.h ============================================================================== --- stable/10/sys/dev/sfxge/common/efx_impl.h Sat Jun 4 14:23:11 2016 (r301320) +++ stable/10/sys/dev/sfxge/common/efx_impl.h Sat Jun 4 14:26:40 2016 (r301321) @@ -499,9 +499,19 @@ typedef struct efx_nvram_ops_s { uint32_t *, uint16_t *); efx_rc_t (*envo_partn_set_version)(efx_nic_t *, uint32_t, uint16_t *); + efx_rc_t (*envo_buffer_validate)(efx_nic_t *, uint32_t, + caddr_t, size_t); } efx_nvram_ops_t; #endif /* EFSYS_OPT_NVRAM */ +extern __checkReturn efx_rc_t +efx_nvram_tlv_validate( + __in efx_nic_t *enp, + __in uint32_t partn, + __in_bcount(partn_size) caddr_t partn_data, + __in size_t partn_size); + + #if EFSYS_OPT_VPD typedef struct efx_vpd_ops_s { efx_rc_t (*evpdo_init)(efx_nic_t *); Modified: stable/10/sys/dev/sfxge/common/efx_nvram.c ============================================================================== --- stable/10/sys/dev/sfxge/common/efx_nvram.c Sat Jun 4 14:23:11 2016 (r301320) +++ stable/10/sys/dev/sfxge/common/efx_nvram.c Sat Jun 4 14:26:40 2016 (r301321) @@ -51,6 +51,7 @@ static efx_nvram_ops_t __efx_nvram_falco falcon_nvram_partn_rw_finish, /* envo_partn_rw_finish */ falcon_nvram_partn_get_version, /* envo_partn_get_version */ falcon_nvram_partn_set_version, /* envo_partn_set_version */ + NULL, /* envo_partn_validate */ }; #endif /* EFSYS_OPT_FALCON */ @@ -70,6 +71,7 @@ static efx_nvram_ops_t __efx_nvram_siena siena_nvram_partn_rw_finish, /* envo_partn_rw_finish */ siena_nvram_partn_get_version, /* envo_partn_get_version */ siena_nvram_partn_set_version, /* envo_partn_set_version */ + NULL, /* envo_partn_validate */ }; #endif /* EFSYS_OPT_SIENA */ @@ -89,6 +91,7 @@ static efx_nvram_ops_t __efx_nvram_ef10_ ef10_nvram_partn_rw_finish, /* envo_partn_rw_finish */ ef10_nvram_partn_get_version, /* envo_partn_get_version */ ef10_nvram_partn_set_version, /* envo_partn_set_version */ + ef10_nvram_buffer_validate, /* envo_buffer_validate */ }; #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */ @@ -446,6 +449,44 @@ fail1: return (rc); } +/* Validate buffer contents (before writing to flash) */ + __checkReturn efx_rc_t +efx_nvram_validate( + __in efx_nic_t *enp, + __in efx_nvram_type_t type, + __in_bcount(partn_size) caddr_t partn_data, + __in size_t partn_size) +{ + efx_nvram_ops_t *envop = enp->en_envop; + uint32_t partn; + efx_rc_t rc; + + EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); + EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE); + EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NVRAM); + + EFSYS_ASSERT3U(type, <, EFX_NVRAM_NTYPES); + + + if ((rc = envop->envo_type_to_partn(enp, type, &partn)) != 0) + goto fail1; + + if (envop->envo_type_to_partn != NULL && + ((rc = envop->envo_buffer_validate(enp, partn, + partn_data, partn_size)) != 0)) + goto fail2; + + return (0); + +fail2: + EFSYS_PROBE(fail2); +fail1: + EFSYS_PROBE1(fail1, efx_rc_t, rc); + + return (rc); +} + + void efx_nvram_fini( __in efx_nic_t *enp) Modified: stable/10/sys/dev/sfxge/common/hunt_impl.h ============================================================================== --- stable/10/sys/dev/sfxge/common/hunt_impl.h Sat Jun 4 14:23:11 2016 (r301320) +++ stable/10/sys/dev/sfxge/common/hunt_impl.h Sat Jun 4 14:26:40 2016 (r301321) @@ -458,6 +458,14 @@ ef10_nvram_partn_set_version( __in uint32_t partn, __in_ecount(4) uint16_t version[4]); +extern __checkReturn efx_rc_t +ef10_nvram_buffer_validate( + __in efx_nic_t *enp, + __in uint32_t partn, + __in_bcount(buffer_size) + caddr_t bufferp, + __in size_t buffer_size); + #endif /* EFSYS_OPT_NVRAM */ Modified: stable/10/sys/dev/sfxge/common/hunt_nvram.c ============================================================================== --- stable/10/sys/dev/sfxge/common/hunt_nvram.c Sat Jun 4 14:23:11 2016 (r301320) +++ stable/10/sys/dev/sfxge/common/hunt_nvram.c Sat Jun 4 14:26:40 2016 (r301321) @@ -472,7 +472,7 @@ fail1: /* Validate TLV formatted partition contents (before writing to flash) */ __checkReturn efx_rc_t -efx_nvram_tlv_validate( +ef10_nvram_buffer_validate( __in efx_nic_t *enp, __in uint32_t partn, __in_bcount(partn_size) caddr_t partn_data,