1 /* 2 * Copyright 2008-2012 Freescale Semiconductor Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution. 11 * * Neither the name of Freescale Semiconductor nor the 12 * names of its contributors may be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * 16 * ALTERNATIVELY, this software may be distributed under the terms of the 17 * GNU General Public License ("GPL") as published by the Free Software 18 * Foundation, either version 2 of that License or (at your option) any 19 * later version. 20 * 21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 34 /*------------------------------------------------------*/ 35 /* */ 36 /* File: crc_mac_addr_ext.h */ 37 /* */ 38 /* Description: */ 39 /* Define a macro that calculate the crc value of */ 40 /* an Ethernet MAC address (48 bitd address */ 41 /*------------------------------------------------------*/ 42 43 #ifndef __crc_mac_addr_ext_h 44 #define __crc_mac_addr_ext_h 45 46 #include "std_ext.h" 47 48 49 static uint32_t crc_table[256] = 50 { 51 0x00000000, 52 0x77073096, 53 0xee0e612c, 54 0x990951ba, 55 0x076dc419, 56 0x706af48f, 57 0xe963a535, 58 0x9e6495a3, 59 0x0edb8832, 60 0x79dcb8a4, 61 0xe0d5e91e, 62 0x97d2d988, 63 0x09b64c2b, 64 0x7eb17cbd, 65 0xe7b82d07, 66 0x90bf1d91, 67 0x1db71064, 68 0x6ab020f2, 69 0xf3b97148, 70 0x84be41de, 71 0x1adad47d, 72 0x6ddde4eb, 73 0xf4d4b551, 74 0x83d385c7, 75 0x136c9856, 76 0x646ba8c0, 77 0xfd62f97a, 78 0x8a65c9ec, 79 0x14015c4f, 80 0x63066cd9, 81 0xfa0f3d63, 82 0x8d080df5, 83 0x3b6e20c8, 84 0x4c69105e, 85 0xd56041e4, 86 0xa2677172, 87 0x3c03e4d1, 88 0x4b04d447, 89 0xd20d85fd, 90 0xa50ab56b, 91 0x35b5a8fa, 92 0x42b2986c, 93 0xdbbbc9d6, 94 0xacbcf940, 95 0x32d86ce3, 96 0x45df5c75, 97 0xdcd60dcf, 98 0xabd13d59, 99 0x26d930ac, 100 0x51de003a, 101 0xc8d75180, 102 0xbfd06116, 103 0x21b4f4b5, 104 0x56b3c423, 105 0xcfba9599, 106 0xb8bda50f, 107 0x2802b89e, 108 0x5f058808, 109 0xc60cd9b2, 110 0xb10be924, 111 0x2f6f7c87, 112 0x58684c11, 113 0xc1611dab, 114 0xb6662d3d, 115 0x76dc4190, 116 0x01db7106, 117 0x98d220bc, 118 0xefd5102a, 119 0x71b18589, 120 0x06b6b51f, 121 0x9fbfe4a5, 122 0xe8b8d433, 123 0x7807c9a2, 124 0x0f00f934, 125 0x9609a88e, 126 0xe10e9818, 127 0x7f6a0dbb, 128 0x086d3d2d, 129 0x91646c97, 130 0xe6635c01, 131 0x6b6b51f4, 132 0x1c6c6162, 133 0x856530d8, 134 0xf262004e, 135 0x6c0695ed, 136 0x1b01a57b, 137 0x8208f4c1, 138 0xf50fc457, 139 0x65b0d9c6, 140 0x12b7e950, 141 0x8bbeb8ea, 142 0xfcb9887c, 143 0x62dd1ddf, 144 0x15da2d49, 145 0x8cd37cf3, 146 0xfbd44c65, 147 0x4db26158, 148 0x3ab551ce, 149 0xa3bc0074, 150 0xd4bb30e2, 151 0x4adfa541, 152 0x3dd895d7, 153 0xa4d1c46d, 154 0xd3d6f4fb, 155 0x4369e96a, 156 0x346ed9fc, 157 0xad678846, 158 0xda60b8d0, 159 0x44042d73, 160 0x33031de5, 161 0xaa0a4c5f, 162 0xdd0d7cc9, 163 0x5005713c, 164 0x270241aa, 165 0xbe0b1010, 166 0xc90c2086, 167 0x5768b525, 168 0x206f85b3, 169 0xb966d409, 170 0xce61e49f, 171 0x5edef90e, 172 0x29d9c998, 173 0xb0d09822, 174 0xc7d7a8b4, 175 0x59b33d17, 176 0x2eb40d81, 177 0xb7bd5c3b, 178 0xc0ba6cad, 179 0xedb88320, 180 0x9abfb3b6, 181 0x03b6e20c, 182 0x74b1d29a, 183 0xead54739, 184 0x9dd277af, 185 0x04db2615, 186 0x73dc1683, 187 0xe3630b12, 188 0x94643b84, 189 0x0d6d6a3e, 190 0x7a6a5aa8, 191 0xe40ecf0b, 192 0x9309ff9d, 193 0x0a00ae27, 194 0x7d079eb1, 195 0xf00f9344, 196 0x8708a3d2, 197 0x1e01f268, 198 0x6906c2fe, 199 0xf762575d, 200 0x806567cb, 201 0x196c3671, 202 0x6e6b06e7, 203 0xfed41b76, 204 0x89d32be0, 205 0x10da7a5a, 206 0x67dd4acc, 207 0xf9b9df6f, 208 0x8ebeeff9, 209 0x17b7be43, 210 0x60b08ed5, 211 0xd6d6a3e8, 212 0xa1d1937e, 213 0x38d8c2c4, 214 0x4fdff252, 215 0xd1bb67f1, 216 0xa6bc5767, 217 0x3fb506dd, 218 0x48b2364b, 219 0xd80d2bda, 220 0xaf0a1b4c, 221 0x36034af6, 222 0x41047a60, 223 0xdf60efc3, 224 0xa867df55, 225 0x316e8eef, 226 0x4669be79, 227 0xcb61b38c, 228 0xbc66831a, 229 0x256fd2a0, 230 0x5268e236, 231 0xcc0c7795, 232 0xbb0b4703, 233 0x220216b9, 234 0x5505262f, 235 0xc5ba3bbe, 236 0xb2bd0b28, 237 0x2bb45a92, 238 0x5cb36a04, 239 0xc2d7ffa7, 240 0xb5d0cf31, 241 0x2cd99e8b, 242 0x5bdeae1d, 243 0x9b64c2b0, 244 0xec63f226, 245 0x756aa39c, 246 0x026d930a, 247 0x9c0906a9, 248 0xeb0e363f, 249 0x72076785, 250 0x05005713, 251 0x95bf4a82, 252 0xe2b87a14, 253 0x7bb12bae, 254 0x0cb61b38, 255 0x92d28e9b, 256 0xe5d5be0d, 257 0x7cdcefb7, 258 0x0bdbdf21, 259 0x86d3d2d4, 260 0xf1d4e242, 261 0x68ddb3f8, 262 0x1fda836e, 263 0x81be16cd, 264 0xf6b9265b, 265 0x6fb077e1, 266 0x18b74777, 267 0x88085ae6, 268 0xff0f6a70, 269 0x66063bca, 270 0x11010b5c, 271 0x8f659eff, 272 0xf862ae69, 273 0x616bffd3, 274 0x166ccf45, 275 0xa00ae278, 276 0xd70dd2ee, 277 0x4e048354, 278 0x3903b3c2, 279 0xa7672661, 280 0xd06016f7, 281 0x4969474d, 282 0x3e6e77db, 283 0xaed16a4a, 284 0xd9d65adc, 285 0x40df0b66, 286 0x37d83bf0, 287 0xa9bcae53, 288 0xdebb9ec5, 289 0x47b2cf7f, 290 0x30b5ffe9, 291 0xbdbdf21c, 292 0xcabac28a, 293 0x53b39330, 294 0x24b4a3a6, 295 0xbad03605, 296 0xcdd70693, 297 0x54de5729, 298 0x23d967bf, 299 0xb3667a2e, 300 0xc4614ab8, 301 0x5d681b02, 302 0x2a6f2b94, 303 0xb40bbe37, 304 0xc30c8ea1, 305 0x5a05df1b, 306 0x2d02ef8d 307 }; 308 309 310 #define GET_MAC_ADDR_CRC(addr, crc) \ 311 { \ 312 uint32_t i; \ 313 uint8_t data; \ 314 \ 315 /* CRC calculation */ \ 316 crc = 0xffffffff; \ 317 for (i=0; i < 6; i++) \ 318 { \ 319 data = (uint8_t)(addr >> ((5-i)*8)); \ 320 crc = crc^data; \ 321 crc = crc_table[crc&0xff] ^ (crc>>8); \ 322 } \ 323 } \ 324 325 /* Define a macro for getting the mirrored value of */ 326 /* a byte size number. (0x11010011 --> 0x11001011) */ 327 /* Sometimes the mirrored value of the CRC is required */ 328 static __inline__ uint8_t GetMirror(uint8_t n) 329 { 330 uint8_t mirror[16] = 331 { 332 0x00, 333 0x08, 334 0x04, 335 0x0c, 336 0x02, 337 0x0a, 338 0x06, 339 0x0e, 340 0x01, 341 0x09, 342 0x05, 343 0x0d, 344 0x03, 345 0x0b, 346 0x07, 347 0x0f 348 }; 349 return ((uint8_t)(((mirror[n & 0x0f] << 4) | (mirror[n >> 4])))); 350 } 351 352 static __inline__ uint32_t GetMirror32(uint32_t n) 353 { 354 return (((uint32_t)GetMirror((uint8_t)(n))<<24) | 355 ((uint32_t)GetMirror((uint8_t)(n>>8))<<16) | 356 ((uint32_t)GetMirror((uint8_t)(n>>16))<<8) | 357 ((uint32_t)GetMirror((uint8_t)(n>>24)))); 358 } 359 360 #define MIRROR GetMirror 361 #define MIRROR_32 GetMirror32 362 363 364 #endif /* __crc_mac_addr_ext_h */ 365