ONLP
Open Network Linux Platform APIs
sfp.h
Go to the documentation of this file.
1 /*************************************************************
2  * <bsn.cl fy=2014 v=onl>
3  *
4  * Copyright 2014, 2015 Big Switch Networks, Inc.
5  *
6  * Licensed under the Eclipse Public License, Version 1.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.eclipse.org/legal/epl-v10.html
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific
16  * language governing permissions and limitations under the
17  * License.
18  *
19  * </bsn.cl>
20  *********************************************************/
28 #ifndef __ONLP_SFP_H__
29 #define __ONLP_SFP_H__
30 
31 #include <onlp/onlp_config.h>
32 #include <onlp/onlp.h>
33 #include <onlp/oids.h>
34 #include <AIM/aim_bitmap.h>
35 #include <AIM/aim_pvs.h>
36 #include <sff/sff.h>
37 #include <sff/dom.h>
38 
39 /* <auto.start.enum(tag:sfp1).define> */
41 typedef enum onlp_sfp_control_e {
42  ONLP_SFP_CONTROL_RESET,
43  ONLP_SFP_CONTROL_RESET_STATE,
44  ONLP_SFP_CONTROL_RX_LOS,
45  ONLP_SFP_CONTROL_TX_FAULT,
46  ONLP_SFP_CONTROL_TX_DISABLE,
47  ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL,
48  ONLP_SFP_CONTROL_LP_MODE,
49  ONLP_SFP_CONTROL_POWER_OVERRIDE,
50  ONLP_SFP_CONTROL_LAST = ONLP_SFP_CONTROL_POWER_OVERRIDE,
51  ONLP_SFP_CONTROL_COUNT,
52  ONLP_SFP_CONTROL_INVALID = -1,
54 /* <auto.end.enum(tag:sfp1).define> */
55 
56 /* <auto.start.enum(tag:sfp2).define> */
59  ONLP_SFP_CONTROL_FLAG_RESET = (1 << 0),
60  ONLP_SFP_CONTROL_FLAG_RESET_STATE = (1 << 1),
61  ONLP_SFP_CONTROL_FLAG_RX_LOS = (1 << 2),
62  ONLP_SFP_CONTROL_FLAG_TX_FAULT = (1 << 3),
63  ONLP_SFP_CONTROL_FLAG_TX_DISABLE = (1 << 4),
64  ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL = (1 << 5),
65  ONLP_SFP_CONTROL_FLAG_LP_MODE = (1 << 6),
66  ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE = (1 << 7),
68 
70 typedef enum onlp_sfp_type_e {
71  ONLP_SFP_TYPE_SFP,
72  ONLP_SFP_TYPE_QSFP,
73  ONLP_SFP_TYPE_SFP28,
74  ONLP_SFP_TYPE_QSFP28,
75  ONLP_SFP_TYPE_LAST = ONLP_SFP_TYPE_QSFP28,
76  ONLP_SFP_TYPE_COUNT,
77  ONLP_SFP_TYPE_INVALID = -1,
79 /* <auto.end.enum(tag:sfp2).define> */
80 
81 
82 
86 #define ONLP_SFP_BLOCK_DATA_SIZE 256
87 
88 
92 typedef struct onlp_sfp_info_t {
95 
98 
100  uint32_t controls;
101 
102 
103  /*
104  * The following fields are only relevant
105  * if the SFP is present.
106  */
107 
108 
117  sff_info_t sff;
118 
122  sff_dom_info_t dom;
123 
125  struct {
128 
131  } bytes;
132 
134 
138 typedef aim_bitmap256_t onlp_sfp_bitmap_t;
139 
140 
144 int onlp_sfp_sw_init(void);
145 
150 int onlp_sfp_hw_init(uint32_t flags);
151 
158 int onlp_sfp_sw_denit(void);
159 
165 
171 
178 
185 
192 
198 
205 
214 
223 
224 
233 
243 int onlp_sfp_dev_read(onlp_oid_t port, int devaddr, int addr,
244  uint8_t* dst, int count);
245 
256  int devaddr, int addr, int count,
257  uint8_t** rv);
258 
267 int onlp_sfp_dev_write(onlp_oid_t port, int devaddr, int addr,
268  uint8_t* src, int count);
269 
277 int onlp_sfp_dev_readb(onlp_oid_t port, int devaddr, int addr);
278 
286 int onlp_sfp_dev_writeb(onlp_oid_t port, int devaddr, int addr,
287  uint8_t value);
288 
296 int onlp_sfp_dev_readw(onlp_oid_t port, int devaddr, int addr);
297 
305 int onlp_sfp_dev_writew(onlp_oid_t port, int devaddr, int addr,
306  uint16_t value);
307 
308 
309 
318 int onlp_sfp_post_insert(onlp_oid_t port, sff_info_t* info);
319 
326 int onlp_sfp_control_set(onlp_oid_t port, onlp_sfp_control_t control, int value);
327 
335  int* value);
336 
342 int onlp_sfp_control_flags_get(onlp_oid_t port, uint32_t* flags);
343 
344 
351 int onlp_sfp_info_to_user_json(onlp_sfp_info_t* info, cJSON** rv, uint32_t flags);
352 
359 int onlp_sfp_info_to_json(onlp_sfp_info_t* info, cJSON** rv, uint32_t flags);
360 
361 
367 int onlp_sfp_info_from_json(cJSON* cj, onlp_sfp_info_t* info);
368 
372 int onlp_sfp_sw_denit(void);
373 
377 int onlp_sfp_hw_denit(void);
378 
382 int onlp_sfp_inventory_show(aim_pvs_t* pvs);
383 
384 /******************************************************************************
385  *
386  * Enumeration Support Definitions.
387  *
388  * Please do not add additional code beyond this point.
389  *
390  *****************************************************************************/
391 /* <auto.start.enum(tag:sfp1).supportheader> */
393 #define ONLP_SFP_CONTROL_STRINGS \
394 {\
395  "RESET", \
396  "RESET_STATE", \
397  "RX_LOS", \
398  "TX_FAULT", \
399  "TX_DISABLE", \
400  "TX_DISABLE_CHANNEL", \
401  "LP_MODE", \
402  "POWER_OVERRIDE", \
403 }
404 
406 
408 int onlp_sfp_control_value(const char* str, onlp_sfp_control_t* e, int substr);
409 
412 
414 #define ONLP_SFP_CONTROL_VALID(_e) \
415  ( (0 <= (_e)) && ((_e) <= ONLP_SFP_CONTROL_POWER_OVERRIDE))
416 
418 extern aim_map_si_t onlp_sfp_control_map[];
420 extern aim_map_si_t onlp_sfp_control_desc_map[];
421 /* <auto.end.enum(tag:sfp1).supportheader> */
422 
423 /* <auto.start.enum(tag:sfp2).supportheader> */
426 
428 int onlp_sfp_control_flag_value(const char* str, onlp_sfp_control_flag_t* e, int substr);
429 
432 
435 
437 #define ONLP_SFP_CONTROL_FLAG_VALID(_e) \
438  (onlp_sfp_control_flag_valid((_e)))
439 
441 extern aim_map_si_t onlp_sfp_control_flag_map[];
443 extern aim_map_si_t onlp_sfp_control_flag_desc_map[];
444 
446 #define ONLP_SFP_TYPE_STRINGS \
447 {\
448  "SFP", \
449  "QSFP", \
450  "SFP28", \
451  "QSFP28", \
452 }
453 
454 const char* onlp_sfp_type_name(onlp_sfp_type_t e);
455 
457 int onlp_sfp_type_value(const char* str, onlp_sfp_type_t* e, int substr);
458 
460 const char* onlp_sfp_type_desc(onlp_sfp_type_t e);
461 
463 #define ONLP_SFP_TYPE_VALID(_e) \
464  ( (0 <= (_e)) && ((_e) <= ONLP_SFP_TYPE_QSFP28))
465 
467 extern aim_map_si_t onlp_sfp_type_map[];
469 extern aim_map_si_t onlp_sfp_type_desc_map[];
470 /* <auto.end.enum(tag:sfp2).supportheader> */
471 
472 #endif /* __ONLP_SFP_H__ */
473 /* @} */
uint8_t a0[ONLP_SFP_BLOCK_DATA_SIZE]
Definition: sfp.h:127
onlp Configuration Header
struct onlp_sfp_info_t::@0 bytes
aim_map_si_t onlp_sfp_control_flag_map[]
int onlp_sfp_dev_alloc_read(onlp_oid_t port, int devaddr, int addr, int count, uint8_t **rv)
Read bytes from the target device on the given SFP port.
aim_map_si_t onlp_sfp_control_map[]
int onlp_sfp_hw_denit(void)
Hardware deinitialize the SFP subsystem.
const char * onlp_sfp_type_name(onlp_sfp_type_t e)
int onlp_sfp_control_flags_get(onlp_oid_t port, uint32_t *flags)
Get the value of all SFP controls.
int onlp_sfp_presence_bitmap_get(onlp_sfp_bitmap_t *dst)
Return the presence bitmap for all ports.
int onlp_sfp_rx_los_bitmap_get(onlp_sfp_bitmap_t *dst)
Get the RX_LOS bitmap for all ports.
onlp_sfp_control_flag_e
Definition: sfp.h:58
const char * onlp_sfp_type_desc(onlp_sfp_type_t e)
int onlp_sfp_control_get(onlp_oid_t port, onlp_sfp_control_t control, int *value)
Get an SFP control.
aim_map_si_t onlp_sfp_type_map[]
Object Identifiers.
uint32_t onlp_oid_t
Definition: oids.h:52
uint8_t a2[ONLP_SFP_BLOCK_DATA_SIZE]
Definition: sfp.h:130
int onlp_sfp_type_get(onlp_oid_t port, onlp_sfp_type_t *rtype)
Determine the SFP Connector type.
int onlp_sfp_info_get(onlp_oid_t port, onlp_sfp_info_t *info)
Get the SFP information structure.
int onlp_sfp_post_insert(onlp_oid_t port, sff_info_t *info)
Perform any actions required after an SFP is inserted.
int onlp_sfp_control_flag_value(const char *str, onlp_sfp_control_flag_t *e, int substr)
int onlp_sfp_hw_init(uint32_t flags)
Hardware initialization of the SFP module.
void onlp_sfp_bitmap_t_init(onlp_sfp_bitmap_t *bmap)
int onlp_sfp_dev_writeb(onlp_oid_t port, int devaddr, int addr, uint8_t value)
Write a byte to the target device on the given SFP port.
int onlp_sfp_hdr_get(onlp_oid_t port, onlp_oid_hdr_t *rv)
Get the SFP&#39;s oid header.
int onlp_sfp_control_value(const char *str, onlp_sfp_control_t *e, int substr)
onlp_sfp_type_e
Definition: sfp.h:70
int onlp_sfp_type_value(const char *str, onlp_sfp_type_t *e, int substr)
aim_map_si_t onlp_sfp_control_desc_map[]
int onlp_sfp_control_flag_valid(onlp_sfp_control_flag_t e)
int onlp_sfp_dev_readw(onlp_oid_t port, int devaddr, int addr)
Read a word from the target device on the given SFP port.
const char * onlp_sfp_control_flag_name(onlp_sfp_control_flag_t e)
int onlp_sfp_bitmap_get(onlp_sfp_bitmap_t *bmap)
Get the set of valid SFP ports.
const char * onlp_sfp_control_flag_desc(onlp_sfp_control_flag_t e)
int onlp_sfp_dev_read(onlp_oid_t port, int devaddr, int addr, uint8_t *dst, int count)
Read bytes from the target device on the given SFP port.
int onlp_sfp_dev_write(onlp_oid_t port, int devaddr, int addr, uint8_t *src, int count)
Write bytes to the target device on the given SFP port.
int onlp_sfp_control_set(onlp_oid_t port, onlp_sfp_control_t control, int value)
Set an SFP control.
const char * onlp_sfp_control_desc(onlp_sfp_control_t e)
int onlp_sfp_info_to_user_json(onlp_sfp_info_t *info, cJSON **rv, uint32_t flags)
Convert an SFP info structure to user JSON.
int onlp_sfp_is_present(onlp_oid_t port)
Determine if an SFP is currently plugged in.
aim_bitmap256_t onlp_sfp_bitmap_t
Definition: sfp.h:138
int onlp_sfp_info_dom_get(onlp_oid_t port, onlp_sfp_info_t *info)
Get the SFP information structure (including DOM)
uint32_t controls
Definition: sfp.h:100
int onlp_sfp_inventory_show(aim_pvs_t *pvs)
Show the current SFP inventory.
Definition: sfp.h:92
sff_dom_info_t dom
Definition: sfp.h:122
int onlp_sfp_sw_init(void)
Software initialization of the SFP module.
enum onlp_sfp_control_flag_e onlp_sfp_control_flag_t
enum onlp_sfp_type_e onlp_sfp_type_t
const char * onlp_sfp_control_name(onlp_sfp_control_t e)
int onlp_sfp_info_to_json(onlp_sfp_info_t *info, cJSON **rv, uint32_t flags)
Convert an SFP info structure to JSON.
onlp_sfp_control_e
Definition: sfp.h:41
enum onlp_sfp_control_e onlp_sfp_control_t
int onlp_sfp_port_valid(onlp_oid_t port)
Determine if a given port number is a valid SFP port.
onlp_oid_hdr_t hdr
Definition: sfp.h:94
int onlp_sfp_sw_denit(void)
Deinitialize the sfp software module.
aim_map_si_t onlp_sfp_type_desc_map[]
sff_info_t sff
Definition: sfp.h:117
int onlp_sfp_dev_readb(onlp_oid_t port, int devaddr, int addr)
Read a byte from the target device on the given SFP port.
int onlp_sfp_info_from_json(cJSON *cj, onlp_sfp_info_t *info)
Convert a JSON object to an SFP info structure.
struct onlp_sfp_info_t onlp_sfp_info_t
Definition: oids.h:296
int onlp_sfp_dev_writew(onlp_oid_t port, int devaddr, int addr, uint16_t value)
Write a word to the target device on the given SFP port.
#define ONLP_SFP_BLOCK_DATA_SIZE
Definition: sfp.h:86
aim_map_si_t onlp_sfp_control_flag_desc_map[]
onlp_sfp_type_t type
Definition: sfp.h:97