Commit | Line | Data |
---|---|---|
800f879a AT |
1 | /* |
2 | * Copyright 2010-2017 Intel Corporation. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License, version 2, | |
6 | * as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * General Public License for more details. | |
12 | * | |
13 | * Disclaimer: The codes contained in these modules may be specific to | |
14 | * the Intel Software Development Platform codenamed Knights Ferry, | |
15 | * and the Intel product codenamed Knights Corner, and are not backward | |
16 | * compatible with other Intel products. Additionally, Intel will NOT | |
17 | * support the codes or instruction set in future products. | |
18 | * | |
19 | * Intel offers no warranty of any kind regarding the code. This code is | |
20 | * licensed on an "AS IS" basis and Intel is not obligated to provide | |
21 | * any support, assistance, installation, training, or other services | |
22 | * of any kind. Intel is also not obligated to provide any updates, | |
23 | * enhancements or extensions. Intel specifically disclaims any warranty | |
24 | * of merchantability, non-infringement, fitness for any particular | |
25 | * purpose, and any other warranty. | |
26 | * | |
27 | * Further, Intel disclaims all liability of any kind, including but | |
28 | * not limited to liability for infringement of any proprietary rights, | |
29 | * relating to the use of the code, even if Intel is notified of the | |
30 | * possibility of such liability. Except as expressly stated in an Intel | |
31 | * license agreement provided with this code and agreed upon with Intel, | |
32 | * no license, express or implied, by estoppel or otherwise, to any | |
33 | * intellectual property rights is granted herein. | |
34 | */ | |
35 | ||
36 | #ifndef __MIC_MACADDR_H__ | |
37 | #define __MIC_MACADDR_H__ | |
38 | ||
39 | #define MAC_RUN_SHIFT 1 | |
40 | #define MAC_DATE_SHIFT 16 | |
41 | ||
42 | /** | |
43 | * mic_get_mac_from_serial - Create MAC address from serial number string | |
44 | * \param serial string containing serial number | |
45 | * \param mac data space to place MAC address | |
46 | * \param host if true set least significant bit for hosts MAC | |
47 | * | |
48 | * mic_get_mac_from_serial() creates a MAC address from a MIC host's serial number. | |
49 | * | |
50 | * A MAC address contains 6 bytes of which the first 3 are either assigned by IEEE | |
51 | * or bit 2 of the first byte is set to indicate locally created. While awaiting | |
52 | * our assigned values, the first the bytes have been set to 'MIC' with the local | |
53 | * bit also being set and multicast not. The result is actually seeing "NIC". | |
54 | * | |
55 | * The last 3 bytes, or 24 bits are set in the pattern: | |
56 | * o 8 bits are created by subtracting 1 from the cards year character mulitplied | |
57 | * by the work week field. By subtracting 1 the year starts at 2012 and there | |
58 | * is enough room to accout for MIC cards build through 2017 | |
59 | * o 15 bits are the work week running number from the serail number. This allows | |
60 | * space for 32k of boards to be build in any one week. | |
61 | * o 1 bit is used to indicated whether it is the host or card end of the virtual | |
62 | * network connection. The bit being set is the card MAC address. | |
63 | * | |
64 | * Upon successful completion, mic_get_mac_from_serial returns zero. If the serial | |
65 | * number does not have "KC" (for Knights Corner) as the 3rd and 4th characters | |
66 | * then the serial number is invalid and a non zero value is returned. | |
67 | */ | |
68 | ||
69 | static int | |
70 | mic_get_mac_from_serial(char *serial, unsigned char *mac, int host) | |
71 | { | |
72 | unsigned long final; | |
73 | int y; | |
74 | int ww; | |
75 | ||
76 | if ((serial == NULL) || (serial[2] != 'K') || (serial[3] != 'C')) | |
77 | return 1; | |
78 | ||
79 | #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,39) | |
80 | y = kstrtoul(&serial[7], 10, &final); // y is to shutup Suse build | |
81 | #else | |
82 | final = simple_strtoul(&serial[7], NULL, 10); | |
83 | #endif | |
84 | ||
85 | final = final << MAC_RUN_SHIFT; /* Card side will add one */ | |
86 | ||
87 | y = (serial[4] - '1'); /* start year 2012 end year 2016 */ | |
88 | ww = ((serial[5] - '0') * 10) + (serial[6] - '0'); | |
89 | ||
90 | final += (y * ww) << MAC_DATE_SHIFT; | |
91 | ||
92 | if (host) /* least bit indicates host MAC */ | |
93 | final++; | |
94 | ||
95 | mac[0] = 0x4c; | |
96 | mac[1] = 0x79; | |
97 | mac[2] = 0xba; | |
98 | mac[3] = (final >> 16) & 0xff; | |
99 | mac[4] = (final >> 8) & 0xff; | |
100 | mac[5] = final & 0xff; | |
101 | return 0; | |
102 | } | |
103 | ||
104 | #endif /* __MIC_MACADDR_H__ */ |