1 /******************************************************************************* 2 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved. 3 * 4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided 5 *that the following conditions are met: 6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the 7 *following disclaimer. 8 *2. Redistributions in binary form must reproduce the above copyright notice, 9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided 10 *with the distribution. 11 * 12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED 13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 20 21 ********************************************************************************/ 22 /*******************************************************************************/ 23 /*! \file saframe.c 24 * \brief The file implements the functions to read frame content 25 */ 26 27 28 /******************************************************************************/ 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 #include <dev/pms/config.h> 32 33 #include <dev/pms/RefTisa/sallsdk/spc/saglobal.h> 34 #ifdef SA_ENABLE_TRACE_FUNCTIONS 35 #ifdef siTraceFileID 36 #undef siTraceFileID 37 #endif 38 #define siTraceFileID 'D' 39 #endif 40 41 /******************************************************************************/ 42 /*! \brief Read 32 bits from a frame 43 * 44 * Read 32 bits from a frame 45 * 46 * \param agRoot Handles for this instance of SAS/SATA LLL 47 * \param agFrame The frame handler 48 * \param frameOffset Offset in bytes from the beginning of valid frame bytes or IU 49 to the 32-bit value to read 50 * 51 * \return The read value 52 * 53 */ 54 /*******************************************************************************/ 55 GLOBAL bit32 saFrameReadBit32( 56 agsaRoot_t *agRoot, 57 agsaFrameHandle_t agFrame, 58 bit32 frameOffset 59 ) 60 { 61 bit8 *payloadAddr; 62 bit32 value = 0; 63 64 smTraceFuncEnter(hpDBG_VERY_LOUD, "zr"); 65 66 if ( agNULL != agFrame ) 67 { 68 /* Find the address of the payload */ 69 payloadAddr = (bit8 *)(agFrame) + frameOffset; 70 71 /* read one DW Data */ 72 value = *(bit32 *)payloadAddr; 73 } 74 75 76 /* (5) return value */ 77 smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "zr"); 78 return value; 79 } 80 81 /******************************************************************************/ 82 /*! \brief Read a block from a frame 83 * 84 * Read a block from a frame 85 * 86 * \param agRoot Handles for this instance of SAS/SATA LLL 87 * \param agFrame The frame handler 88 * \param frameOffset The offset of the frame to start read 89 * \param frameBuffer The pointer to the destination of data read from the frame 90 * \param frameBufLen Number of bytes to read from the frame 91 * 92 * \return -void- 93 * 94 */ 95 /*******************************************************************************/ 96 GLOBAL void saFrameReadBlock ( 97 agsaRoot_t *agRoot, 98 agsaFrameHandle_t agFrame, 99 bit32 frameOffset, 100 void *frameBuffer, 101 bit32 frameBufLen 102 ) 103 { 104 bit8 *payloadAddr; 105 bit32 i; 106 107 smTraceFuncEnter(hpDBG_VERY_LOUD, "zi"); 108 109 /* Sanity check */ 110 SA_ASSERT(frameBufLen < 4096, "saFrameReadBlock read more than 4k"); 111 112 if ( agNULL != agFrame ) 113 { 114 /* Find the address of the payload */ 115 payloadAddr = (bit8 *)(agFrame) + frameOffset; 116 /* Copy the frame data to the destination frame buffer */ 117 for ( i = 0; i < frameBufLen; i ++ ) 118 { 119 *(bit8 *)((bit8 *)frameBuffer + i) = *(bit8 *)(payloadAddr + i); 120 } 121 } 122 123 smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "zi"); 124 } 125 126