FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
sfp.c
Go to the documentation of this file.
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 #include <vnet/ethernet/sfp.h>
17 
18 static u8 *
19 format_space_terminated (u8 * s, va_list * args)
20 {
21  u32 l = va_arg (*args, u32);
22  u8 *v = va_arg (*args, u8 *);
23  u8 *p;
24 
25  for (p = v + l - 1; p >= v && p[0] == ' '; p--)
26  ;
27  vec_add (s, v, clib_min (p - v + 1, l));
28  return s;
29 }
30 
31 static u8 *
32 format_sfp_id (u8 * s, va_list * args)
33 {
34  u32 id = va_arg (*args, u32);
35  char *t = 0;
36  switch (id)
37  {
38 #define _(f) case SFP_ID_##f: t = #f; break;
40 #undef _
41  default:
42  return format (s, "unknown 0x%x", id);
43  }
44  return format (s, "%s", t);
45 }
46 
47 static u8 *
48 format_sfp_compatibility (u8 * s, va_list * args)
49 {
50  u32 c = va_arg (*args, u32);
51  char *t = 0;
52  switch (c)
53  {
54 #define _(a,b,f) case SFP_COMPATIBILITY_##f: t = #f; break;
56 #undef _
57  default:
58  return format (s, "unknown 0x%x", c);
59  }
60  return format (s, "%s", t);
61 }
62 
63 u32
65 {
66  static struct
67  {
68  u8 byte, bit;
69  } t[] =
70  {
71 #define _(a,b,f) { .byte = a, .bit = b, },
73 #undef _
74  };
75 
76  ASSERT (c < ARRAY_LEN (t));
77  return (e->compatibility[t[c].byte] & (1 << t[c].bit)) != 0;
78 }
79 
80 u8 *
81 format_sfp_eeprom (u8 * s, va_list * args)
82 {
83  sfp_eeprom_t *e = va_arg (*args, sfp_eeprom_t *);
84  uword indent = format_get_indent (s);
85  int i;
86 
87  if (e->id != SFP_ID_sfp)
88  s = format (s, "id %U, ", format_sfp_id, e->id);
89 
90  s = format (s, "compatibility:");
91  for (i = 0; i < SFP_N_COMPATIBILITY; i++)
92  if (sfp_is_comatible (e, i))
93  s = format (s, " %U", format_sfp_compatibility, i);
94 
95  s = format (s, "\n%Uvendor: %U, part %U",
96  format_white_space, indent,
99  sizeof (e->vendor_part_number), e->vendor_part_number);
100  s =
101  format (s, "\n%Urevision: %U, serial: %U, date code: %U",
103  sizeof (e->vendor_revision), e->vendor_revision,
106  sizeof (e->vendor_date_code), e->vendor_date_code);
107 
108  return s;
109 }
110 
111 /*
112  * fd.io coding-style-patch-verification: ON
113  *
114  * Local Variables:
115  * eval: (c-set-style "gnu")
116  * End:
117  */
static u8 * format_sfp_compatibility(u8 *s, va_list *args)
Definition: sfp.c:48
u8 vendor_date_code[8]
Definition: sfp.h:59
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
u8 vendor_name[16]
Definition: sfp.h:45
#define clib_min(x, y)
Definition: clib.h:332
#define foreach_sfp_compatibility
Definition: sfp.h:80
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
static u8 * format_space_terminated(u8 *s, va_list *args)
Definition: sfp.c:19
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:599
static uword format_get_indent(u8 *s)
Definition: format.h:72
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
u8 vendor_serial_number[16]
Definition: sfp.h:58
u8 id
Definition: sfp.h:36
#define v
Definition: acl.c:246
svmdb_client_t * c
u8 vendor_part_number[16]
Definition: sfp.h:48
#define ARRAY_LEN(x)
Definition: clib.h:59
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
static u8 * format_sfp_id(u8 *s, va_list *args)
Definition: sfp.c:32
u32 sfp_is_comatible(sfp_eeprom_t *e, sfp_compatibility_t c)
Definition: sfp.c:64
sfp_compatibility_t
Definition: sfp.h:97
u64 uword
Definition: types.h:112
unsigned char u8
Definition: types.h:56
u8 * format_sfp_eeprom(u8 *s, va_list *args)
Definition: sfp.c:81
u8 compatibility[8]
Definition: sfp.h:39
u8 vendor_revision[4]
Definition: sfp.h:49