Native VPP driver for Intel Niantic family of NICs
[vpp.git] / vnet / vnet / devices / nic / sfp.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_vnet_optics_sfp_h
17 #define included_vnet_optics_sfp_h
18
19 #include <vppinfra/format.h>
20
21 #define foreach_sfp_id                          \
22   _ (unknown)                                   \
23   _ (gbic)                                      \
24   _ (on_motherboard)                            \
25   _ (sfp)
26
27 typedef enum {
28 #define _(f) SFP_ID_##f,
29   foreach_sfp_id
30 #undef _
31 } sfp_id_t;
32
33 typedef struct {
34   u8 id;
35   u8 extended_id;
36   u8 connector_type;
37   u8 compatibility[8];
38   u8 encoding;
39   u8 nominal_bit_rate_100mbits_per_sec;
40   u8 reserved13;
41   u8 link_length[5];
42   u8 reserved19;
43   u8 vendor_name[16];
44   u8 reserved36;
45   u8 vendor_oui[3];
46   u8 vendor_part_number[16];
47   u8 vendor_revision[4];
48   /* 16 bit value network byte order. */
49   u8 laser_wavelength_in_nm[2];
50   u8 reserved62;
51   u8 checksum_0_to_62;
52
53   u8 options[2];
54   u8 max_bit_rate_margin_percent;
55   u8 min_bit_rate_margin_percent;
56   u8 vendor_serial_number[16];
57   u8 vendor_date_code[8];
58   u8 reserved92[3];
59   u8 checksum_63_to_94;
60   u8 vendor_specific[32];
61   u8 reserved128[384];
62
63   /* Vendor specific data follows. */
64   u8 vendor_specific1[0];
65 } sfp_eeprom_t;
66
67 always_inline uword
68 sfp_eeprom_is_valid (sfp_eeprom_t * e)
69 {
70   int i;
71   u8 sum = 0;
72   for (i = 0; i < 63; i++)
73     sum += ((u8 *) e)[i];
74   return sum == e->checksum_0_to_62;
75 }
76
77 /* _ (byte_index, bit_index, name) */
78 #define foreach_sfp_compatibility               \
79   _ (0, 4, 10g_base_sr)                         \
80   _ (0, 5, 10g_base_lr)                         \
81   _ (1, 2, oc48_long_reach)                     \
82   _ (1, 1, oc48_intermediate_reach)             \
83   _ (1, 0, oc48_short_reach)                    \
84   _ (2, 6, oc12_long_reach)                     \
85   _ (2, 5, oc12_intermediate_reach)             \
86   _ (2, 4, oc12_short_reach)                    \
87   _ (2, 2, oc3_long_reach)                      \
88   _ (2, 1, oc3_intermediate_reach)              \
89   _ (2, 0, oc3_short_reach)                     \
90   _ (3, 3, 1g_base_t)                           \
91   _ (3, 2, 1g_base_cx)                          \
92   _ (3, 1, 1g_base_lx)                          \
93   _ (3, 0, 1g_base_sx)
94
95 typedef enum {
96 #define _(a,b,f) SFP_COMPATIBILITY_##f,
97   foreach_sfp_compatibility
98 #undef _
99   SFP_N_COMPATIBILITY,
100 } sfp_compatibility_t;
101
102 u32 sfp_is_comatible (sfp_eeprom_t * e, sfp_compatibility_t c);
103
104 format_function_t format_sfp_eeprom;
105
106 #endif /* included_vnet_optics_sfp_h */