Author: arybchik
Date: Tue May 10 06:51:20 2016
New Revision: 299318
URL: https://svnweb.freebsd.org/changeset/base/299318

Log:
  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 <rhouldsworth at solarflare.com>
  Sponsored by:   Solarflare Communications, Inc.
  MFC after:      1 week
  Differential Revision:  https://reviews.freebsd.org/D6263

Modified:
  head/sys/dev/sfxge/common/efx.h
  head/sys/dev/sfxge/common/efx_impl.h
  head/sys/dev/sfxge/common/efx_nvram.c
  head/sys/dev/sfxge/common/hunt_impl.h
  head/sys/dev/sfxge/common/hunt_nvram.c

Modified: head/sys/dev/sfxge/common/efx.h
==============================================================================
--- head/sys/dev/sfxge/common/efx.h     Tue May 10 05:47:25 2016        
(r299317)
+++ head/sys/dev/sfxge/common/efx.h     Tue May 10 06:51:20 2016        
(r299318)
@@ -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: head/sys/dev/sfxge/common/efx_impl.h
==============================================================================
--- head/sys/dev/sfxge/common/efx_impl.h        Tue May 10 05:47:25 2016        
(r299317)
+++ head/sys/dev/sfxge/common/efx_impl.h        Tue May 10 06:51:20 2016        
(r299318)
@@ -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: head/sys/dev/sfxge/common/efx_nvram.c
==============================================================================
--- head/sys/dev/sfxge/common/efx_nvram.c       Tue May 10 05:47:25 2016        
(r299317)
+++ head/sys/dev/sfxge/common/efx_nvram.c       Tue May 10 06:51:20 2016        
(r299318)
@@ -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: head/sys/dev/sfxge/common/hunt_impl.h
==============================================================================
--- head/sys/dev/sfxge/common/hunt_impl.h       Tue May 10 05:47:25 2016        
(r299317)
+++ head/sys/dev/sfxge/common/hunt_impl.h       Tue May 10 06:51:20 2016        
(r299318)
@@ -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: head/sys/dev/sfxge/common/hunt_nvram.c
==============================================================================
--- head/sys/dev/sfxge/common/hunt_nvram.c      Tue May 10 05:47:25 2016        
(r299317)
+++ head/sys/dev/sfxge/common/hunt_nvram.c      Tue May 10 06:51:20 2016        
(r299318)
@@ -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,
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to