Prasanna Kumar | f6c94ae | 2013-04-11 20:05:21 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | *ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | *BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | *IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | *\ |
| 29 | #if !defined _WLAN_NV_TEMPLATE_INTERNAL_H |
| 30 | #define _WLAN_NV_TEMPLATE_INTERNAL_H |
| 31 | |
| 32 | /* |
| 33 | Template constructs |
| 34 | 1. TABLE_: struct |
| 35 | 2. INDEX_ENUM: enums, e.g. {RATE_OFDM_6M,RATE_OFDM_54M} |
| 36 | 3. INDEX_INT: int, e.g.{min, max, increment} |
| 37 | 3. Basic data types: tANI_U8, tANI_S8, tANI_U32, tANI_S32 |
| 38 | 4. Storage types: |
| 39 | 4.1 SINGULAR: one element of basic data type |
| 40 | 4.2 ARRAY_1: one dimensional array, x-axis |
| 41 | 4.3 ARRAY_2: two dimensional array, (x, y) |
| 42 | 4.4 ARRAY_3: three dimensional array, (x, y, z) |
| 43 | |
| 44 | Implementation notes |
| 45 | 1. Flow of changing NV data format: (TBD) Either change the template and |
| 46 | generate the header file, or |
| 47 | modify header file and auto-generate the template. |
| 48 | 2. Flow of writing NV data: encode the template in the data stream, so the |
| 49 | NV data is "self-sufficient". |
| 50 | No separate template, no compability issue, no need of version control. |
| 51 | 3. Flow of reading NV data: parse the binary NV data stream based on the |
| 52 | template info in the data stream. |
| 53 | 4. The above NV logic is decoupled from the actual data content, a |
| 54 | generic, content ergonostic parser (reading) and encoder (writing). |
| 55 | The NV logic is common code shared by tools, s/w |
| 56 | (both host and firmware), and off-line utilities. |
| 57 | 5. NV data parsing and "acceptanace" into an s/w moduel data structure can |
| 58 | be "configured" in several ways: |
| 59 | 5.1 only total matching of all fields, otherwise, reject the whole data |
| 60 | stream (a table). |
| 61 | 5.2 partial matching of fields allowed and the rest fields assume |
| 62 | reasonal default values, |
| 63 | The choice can be determined later, but the capability is provided. |
| 64 | 6. We could also design in this selection on an individua table base. |
| 65 | To design such capability, reserve some header bits in the data stream. |
| 66 | 7. The NV data streams can be modified, replaced, or intact with a new |
| 67 | data stream of the same table ID added to NV data. |
| 68 | The choice can be determined later, but the NV scheme provides such |
| 69 | capability. |
| 70 | 8. The template construct definitions can be common to all tables |
| 71 | (tbd: in a common section) or table specific, or updated |
| 72 | in a subsequent format section. |
| 73 | The use cases are: |
| 74 | - An index enum (e.g. RF channels) is common to all tables when the NV |
| 75 | data is created. Later new enums are added (e.g. |
| 76 | additional channels), one can choose to add the new index enum for new |
| 77 | tables appended to the NV data, or replace the |
| 78 | old table with new template info and data. |
| 79 | The template precedence is table specific then common, and later |
| 80 | "common" overwrites "earlier" commmon. |
| 81 | - A new field is added to the table, the user decides to replace the old |
| 82 | table data, he can simply encode the template |
| 83 | info in the data stream. |
| 84 | - In the same scenario (a new field is added), the user decides to |
| 85 | append a new table, he can encode the template |
| 86 | in the new data table and append it to NV data, or write a new common |
| 87 | template section and append the data. |
| 88 | |
| 89 | Key "ingredients", (re-iterate the most important features and capabilities) |
| 90 | 1. How to parse the data is embedded in the NV data itself. It removes the |
| 91 | dependency on header file matching, |
| 92 | version checking, compatibility among tools, host and firmware. |
| 93 | 2. Table field ID enables "partial" data acceptance in an s/w module data |
| 94 | structure. Whether full matching or reject the whole table, or "partial" |
| 95 | acceptance, the capabiilty is in place and further ensures the robust |
| 96 | NV data extensibility and compatibility. |
| 97 | 3. The table granularity, data stream based NV data has variable length |
| 98 | and flexibility of modifying an existing table data, replacing |
| 99 | the whole data,or leaving the existing data table intact and |
| 100 | appending a new table. |
| 101 | Misc notes: |
| 102 | 1. For endianness, support only 4 bytes integer or 4 1-byte |
| 103 | 2. String identifier needs to be shortened to save storage |
| 104 | 3. string_field_name, field type, field storage class, storage size |
| 105 | */ |
| 106 | |
| 107 | #include "wlan_nv_types.h" |
| 108 | |
| 109 | /* |
| 110 | * Stream header bitmap |
| 111 | * streamType |
| 112 | * bitmap[7] |
| 113 | * / \ |
| 114 | * 1: template 0: data |
| 115 | * bitmap[6] |
| 116 | * / \ |
| 117 | * 0: enum 1: table |
| 118 | * |
| 119 | */ |
| 120 | /* Stream header type[7], 0: data, 1: template */ |
| 121 | #define STREAM_HEADER_TYPE_MASK 0x80 |
| 122 | #define STREAM_HEADER_TYPE_LSB 7 |
| 123 | #define IsStreamTemplate(b) (((b) & (STREAM_HEADER_TYPE_MASK)) ? 1 : 0) |
| 124 | |
| 125 | /* Stream header template type [6], 0: enum; 1: table */ |
| 126 | #define STREAM_HEADER_TEMPLATE_TYPE_MASK 0x40 |
| 127 | #define STREAM_HEADER_TEMPLATE_TYPE_LSB 6 |
| 128 | #define IsTemplateStreamTable(b) (((b) & (STREAM_HEADER_TEMPLATE_TYPE_MASK)) ? 1 : 0) |
| 129 | |
| 130 | /* |
| 131 | * Field identifier bitmap |
| 132 | * |
| 133 | * field identifier |
| 134 | * bitmap[7] |
| 135 | * / \ |
| 136 | * 0: table/enum 1: basic data type |
| 137 | * bitmap[6:0] bitmap[6:0] |
| 138 | * | | |
| 139 | * tableIdx/ data types (U8, U32, etc.) |
| 140 | * enumIdx |
| 141 | */ |
| 142 | /* Field Identifier type [7] |
| 143 | * 0: table |
| 144 | * 1: basic data types |
| 145 | * Note that |
| 146 | * - bit[7] table value=0 makes the table ID following data header stream or |
| 147 | * template header stream identical to field ID |
| 148 | * - tableIdx 0 is the "table of all tables", a.k.a. table content of all |
| 149 | * table indexes |
| 150 | * - enumIdx 0 is the "enum of all enums", a.k.a. table content of all enum |
| 151 | * indexes |
| 152 | */ |
| 153 | |
| 154 | #define FIELD_ID_TYPE_MASK 0x80 |
| 155 | #define FIELD_ID_TYPE_LSB 7 |
| 156 | #define IsFieldTypeBasicData(b) (((b) & (FIELD_ID_TYPE_MASK)) ? 1 : 0) |
| 157 | |
| 158 | /* Field Identifier table index [6:0] */ |
| 159 | #define FIELD_ID_TABLE_OR_ENUM_IDX_MASK 0x7f |
| 160 | #define FIELD_ID_TABLE_OR_ENUM_IDX_LSB 0 |
| 161 | #define _TABLE_IDX(b) (((b) & ~FIELD_ID_TYPE_MASK) | ((b) & FIELD_ID_TABLE_OR_ENUM_IDX_MASK)) |
| 162 | #define IsIdxTableOfAllTables(b) (((b) & FIELD_ID_TABLE_OR_ENUM_IDX_MASK) ? 0 : 1) |
| 163 | #define IsIdxEnumOfAllEnums(b) (((b) & FIELD_ID_TABLE_OR_ENUM_IDX_MASK) ? 0 : 1) |
| 164 | |
| 165 | /* Field Identifier basic data types [6:0] |
| 166 | * 0: U8 |
| 167 | * 1: U32 |
| 168 | * 2: S8 |
| 169 | * 3: S32 |
| 170 | * 4: U16 |
| 171 | * 5: S16 |
| 172 | */ |
| 173 | |
| 174 | #define FIELD_ID_BASIC_DATA_TYPES_MASK 0x7F |
| 175 | #define FIELD_ID_BASIC_DATA_TYPES_LSB 0 |
| 176 | |
| 177 | typedef enum { |
| 178 | _FIELD_ID_DATA_TYPE_U8 = 0, |
| 179 | _FIELD_ID_DATA_TYPE_U32, |
| 180 | _FIELD_ID_DATA_TYPE_S8, |
| 181 | _FIELD_ID_DATA_TYPE_S32, |
| 182 | _FIELD_ID_DATA_TYPE_U16, |
| 183 | _FIELD_ID_DATA_TYPE_S16, |
| 184 | _FIELD_ID_DATA_TYPE_LAST, |
| 185 | } _FIELD_ID_BASIC_DATA_TYPE; |
| 186 | |
| 187 | #define TheBasicDataType(b) (((b) & (FIELD_ID_BASIC_DATA_TYPES_MASK)) >> FIELD_ID_BASIC_DATA_TYPES_LSB) |
| 188 | #define _ID_U8 ((FIELD_ID_TYPE_MASK) | (_FIELD_ID_DATA_TYPE_U8)) |
| 189 | #define _ID_U32 ((FIELD_ID_TYPE_MASK) | (_FIELD_ID_DATA_TYPE_U32)) |
| 190 | #define _ID_S8 ((FIELD_ID_TYPE_MASK) | (_FIELD_ID_DATA_TYPE_S8)) |
| 191 | #define _ID_S32 ((FIELD_ID_TYPE_MASK) | (_FIELD_ID_DATA_TYPE_S32)) |
| 192 | #define _ID_U16 ((FIELD_ID_TYPE_MASK) | (_FIELD_ID_DATA_TYPE_U16)) |
| 193 | #define _ID_S16 ((FIELD_ID_TYPE_MASK) | (_FIELD_ID_DATA_TYPE_S16)) |
| 194 | |
| 195 | /* |
| 196 | * field storage class |
| 197 | */ |
| 198 | typedef enum { |
| 199 | SINGULAR = 0, |
| 200 | ARRAY_1, |
| 201 | ARRAY_2, |
| 202 | ARRAY_3, |
| 203 | STORAGE_TYPE_LAST, |
| 204 | } _FIELD_ID_STORAGE_TYPE; |
| 205 | |
| 206 | #define _STORAGE_TYPE(b) ((b) & 0x3) |
| 207 | #define _STORAGE_SIZE1(byteLow, byteHigh) (((((byteHigh) >> 2) & 0x3) << 7) | (((byteLow) >> FIELD_SIZE_VALUE_LSB) & FIELD_SIZE_VALUE_MASK)) |
| 208 | #define _STORAGE_SIZE2(byteLow, byteHigh) (((((byteHigh) >> 4) & 0x3) << 7) | (((byteLow) >> FIELD_SIZE_VALUE_LSB) & FIELD_SIZE_VALUE_MASK)) |
| 209 | #define _STORAGE_SIZE3(byteLow, byteHigh) (((((byteHigh) >> 6) & 0x3) << 7) | (((byteLow) >> FIELD_SIZE_VALUE_LSB) & FIELD_SIZE_VALUE_MASK)) |
| 210 | |
| 211 | #define _ADD_SIZE1(b) ((((b) >> 7) & 0x3) << 2) |
| 212 | #define _ADD_SIZE2(b) ((((b) >> 7) & 0x3) << 4) |
| 213 | #define _ADD_SIZE3(b) ((((b) >> 7) & 0x3) << 6) |
| 214 | |
| 215 | /* |
| 216 | * Field storage size type [7] |
| 217 | * / \ |
| 218 | * 1: int 0: enum |
| 219 | * bitmap[6:0] bitmap[6:0] |
| 220 | * | | |
| 221 | * max int index enum index into enum tables |
| 222 | * |
| 223 | * Note that enum=0 makes the template enum ID following template stream byte |
| 224 | * identical to enum field storage size type |
| 225 | * |
| 226 | * Field storage size value [6:0] |
| 227 | */ |
| 228 | #define FIELD_SIZE_TYPE_MASK 0x80 |
| 229 | #define FIELD_SIZE_TYPE_LSB 7 |
| 230 | #define FIELD_SIZE_TYPE_BIT(t) (((t)<< (FIELD_SIZE_TYPE_LSB)) & (FIELD_SIZE_TYPE_MASK)) |
| 231 | #define IsFieldSizeInt(b) (((b) & (FIELD_SIZE_TYPE_MASK)) ? 1 : 0) |
| 232 | |
| 233 | typedef enum { |
| 234 | FIELD_SIZE_IDX_ENUM = 0, |
| 235 | FIELD_SIZE_IDX_INT = 1, |
| 236 | } FIELD_SIZE_TYPE; |
| 237 | |
| 238 | #define FIELD_SIZE_VALUE_MASK 0x7f |
| 239 | #define FIELD_SIZE_VALUE_LSB 0 |
| 240 | #define FIELD_SIZE_VALUE_BITS(val) (((val) << (FIELD_SIZE_VALUE_LSB)) & (FIELD_SIZE_VALUE_MASK)) |
| 241 | |
| 242 | /* |
| 243 | * NV table storage struct in an s/w module |
| 244 | */ |
| 245 | #define _TABLE_NAME_LEN 2 |
| 246 | #define _TABLE_FIELD_FULL_NAME_LEN 47 |
| 247 | |
| 248 | typedef struct _nvTemplateTableStructInternal { |
| 249 | tANI_U8 fieldName[_TABLE_NAME_LEN + 1]; |
| 250 | tANI_U8 fieldId; |
| 251 | tANI_U8 fieldStorageType; |
| 252 | tANI_U8 fieldStorageSize1; |
| 253 | tANI_U8 fieldStorageSize2; |
| 254 | tANI_U8 fieldStorageSize3; |
| 255 | tANI_U32 offset; //void *offset; |
| 256 | tANI_U8 fieldFullName[_TABLE_FIELD_FULL_NAME_LEN +1]; |
| 257 | } _NV_TEMPLATE_TABLE; |
| 258 | |
| 259 | #define _OFFSET_NOT_SET 0xFFFFFFFF |
| 260 | #define TABLE_PREDEFINED_MAX 50 |
| 261 | #define TABLE_ENTRIES_MAX 50 |
| 262 | #define _LIST_OF_TABLES_IDX 0 |
| 263 | #define _TABLE_FIELDS_POS 2 |
| 264 | #define _ENUM_START_POS 2 |
| 265 | #define _TABLE_FIELD_MIN_LEN 4 |
| 266 | #define _ENUM_MIN_LEN 3 |
| 267 | |
| 268 | #define _ENUM_NAME_LEN _TABLE_NAME_LEN |
| 269 | #define _ENUM_FULL_NAME_LEN 47 |
| 270 | typedef struct _nvTemplateEnumStruct { |
| 271 | tANI_U8 enumName[3]; // 2 char string |
| 272 | tANI_U8 enumValue; |
| 273 | tANI_U8 enumValuePeer; |
| 274 | tANI_U8 enumFullName[_ENUM_FULL_NAME_LEN +1]; |
| 275 | } _NV_TEMPLATE_ENUM; |
| 276 | #define INDEX_ENUM_PREDEFINED_MAX 20 |
| 277 | #define ENUM_ENTRIES_MAX 200 |
| 278 | |
| 279 | typedef enum { |
| 280 | _MIS_MATCH = 0, |
| 281 | _MATCH, |
| 282 | } _NV_TEMPLATE_PROCESS_RC; |
| 283 | |
| 284 | #define _NV_BIN_STREAM_HEADER_BYTE 0 |
| 285 | #define _NV_BIN_STREAM_TABLE_ID_BYTE 1 |
| 286 | #define _NV_BIN_STREAM_ENUM_ID_BYTE 1 |
| 287 | #define _NV_BIN_DATA_STREAM_TABLEID_BYTE 1 |
| 288 | #define _NV_BIN_ENUM_TEMPLATE_ENTRY_SIZE 3 |
| 289 | #define _NV_LIST_OF_TABLE_ID 0 |
| 290 | |
| 291 | /* |
| 292 | * Stream write |
| 293 | */ |
| 294 | #define _STREAM_HEADER_POS 0 |
| 295 | #define _ENUM_STREAM_HEADER_POS _STREAM_HEADER_POS |
| 296 | #define _TABLE_STREAM_HEADER_POS _STREAM_HEADER_POS |
| 297 | #define _TEMPLATE_INDEX_HEADER_POS 1 |
| 298 | #define _ENUM_INDEX_HEADER_POS _TEMPLATE_INDEX_HEADER_POS |
| 299 | #define _TABLE_INDEX_HEADER_POS _TEMPLATE_INDEX_HEADER_POS |
| 300 | |
| 301 | /* |
| 302 | * Additional typedef |
| 303 | */ |
| 304 | typedef struct _enumMetaData { |
| 305 | _NV_TEMPLATE_PROCESS_RC match; |
| 306 | } _ENUM_META_DATA; |
| 307 | |
| 308 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
| 309 | #define _NV_STREAM_LEN_MAX 35000 |
| 310 | |
| 311 | /* |
| 312 | * Error code should be expanded, this is the beginning set |
| 313 | */ |
| 314 | typedef enum { |
| 315 | _OK = 0, |
| 316 | _RESET_STREAM_FAILED, |
| 317 | _WRITE_STREAM_FAILED, |
| 318 | _STREAM_NOT_FIT_BUF, |
| 319 | _SW_BIN_MISMATCH, |
| 320 | _INSUFFICIENT_FOR_FIELD_PARSER_ERROR, |
| 321 | _TABLE_NON_EXIST_IN_TABLE_OF_ALL_TABLES, |
| 322 | _ENUM_NOT_FOUND_IN_BUILT_IN, |
| 323 | } _ErrorCode; |
| 324 | |
| 325 | /* |
| 326 | * Use the stream test stub |
| 327 | */ |
| 328 | //#define _USE_STREAM_STUB |
| 329 | #define RESET_STREAM(b) resetStream(b) |
| 330 | #define NEXT_STREAM(b,c) nextStream(b,c) |
| 331 | |
| 332 | #endif /*#if !defined(_WLAN_NV_TEMPLATE_INTERNAL_H)*/ |