Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 1 | #ifndef BAL_OBJ |
| 2 | #define BAL_OBJ |
| 3 | |
| 4 | #include <bcmos_system.h> |
| 5 | #include <bcmos_errno.h> |
| 6 | #include "bal_model_ids.h" |
| 7 | #include "bal_buf.h" |
| 8 | #include "bal_msg_type.h" |
| 9 | |
| 10 | /* |
| 11 | * The current BAL header version |
| 12 | */ |
| 13 | #define BAL_HDR_VERSION_MAJOR (1) |
| 14 | #define BAL_HDR_VERSION_MINOR (1) |
| 15 | |
| 16 | /* |
| 17 | * The BAL common message header |
| 18 | */ |
| 19 | typedef struct bal_comm_msg_hdr |
| 20 | { |
| 21 | bcmos_msg m; /**< bcmos message header */ |
| 22 | uint16_t version_major; /**< Header Major version number */ |
| 23 | uint16_t version_minor; /**< Header Minor version number */ |
| 24 | bcmbal_msg_type msg_type; /**< Request / Response / Ack / Indication */ |
| 25 | uint32_t msg_id; /**< Message ID – the ID of the message (subID under the message type) */ |
| 26 | uint32_t ex_id; /**< Exchange ID for message tracking between endpoints */ |
| 27 | bal_subsystem sender; /**< Sender subsystem - used for additional validation */ |
| 28 | uint32_t timestamp; /**< Timestamp when the message was sent */ |
| 29 | bcmos_sem sem; /**< Semaphore used for inter-thread communication */ |
| 30 | void* scratchpad; /**< Scratchpad used for inter-thread communication */ |
| 31 | uint8_t payload[]; /**< Payload follows the header */ |
| 32 | } bal_comm_msg_hdr; |
| 33 | |
| 34 | /** Version of Object definitions */ |
| 35 | #define BCMBAL_OBJ_VERSION 2 /**< The current version number */ |
| 36 | typedef uint32_t bcmbal_object_ver; /**< The attribute type in the object info structure */ |
| 37 | |
| 38 | /** Bitmask of object attributes that are specified in an object (1 = specified, 0 = not specified) */ |
| 39 | typedef uint64_t bcmbal_presence_mask; |
| 40 | |
| 41 | /** Presence mask indicating all fields present */ |
| 42 | #define BCMBAL_PRESENCE_MASK_ALL ((bcmbal_presence_mask)0xFFFFFFFFFFFFFFFF) |
| 43 | |
| 44 | /** Helper type to determine what the data format of a message should look like */ |
| 45 | typedef enum bcmbal_mgt_group |
| 46 | { |
| 47 | BCMBAL_MGT_GROUP_KEY, /**< Key that uniquely identifies object instance */ |
| 48 | BCMBAL_MGT_GROUP_CFG, /**< Configuration (get/set/clear) */ |
| 49 | BCMBAL_MGT_GROUP_STAT, /**< Statistics */ |
| 50 | BCMBAL_MGT_GROUP_AUTO, /**< Autonomous indications */ |
| 51 | BCMBAL_MGT_GROUP_AUTO_CFG, /**< Autonomous indication configuration */ |
| 52 | BCMBAL_MGT_GROUP__NUM_OF |
| 53 | } bcmbal_mgt_group; |
| 54 | |
| 55 | /** Object message type. Can be a combination of flags. */ |
| 56 | typedef enum bcmbal_obj_msg_type |
| 57 | { |
| 58 | BCMBAL_OBJ_MSG_TYPE_GET = 0x01, /**< Get configuration parameters */ |
| 59 | BCMBAL_OBJ_MSG_TYPE_SET = 0x02, /**< Set configuration parameters */ |
| 60 | BCMBAL_OBJ_MSG_TYPE_CLEAR = 0x04, /**< Clear configuration parameters */ |
| 61 | } bcmbal_obj_msg_type; |
| 62 | |
| 63 | /** Object message direction - request or response. */ |
| 64 | typedef enum bcmbal_obj_msg_dir |
| 65 | { |
| 66 | BCMBAL_OBJ_MSG_DIR_REQUEST, |
| 67 | BCMBAL_OBJ_MSG_DIR_RESPONSE |
| 68 | } bcmbal_obj_msg_dir; |
| 69 | |
| 70 | #define BCMBAL_OBJ_INIT_VAL 0xdeadbeef /**< The value of the obj_init_val after macro initialization */ |
| 71 | |
| 72 | /** Information common to all BAL objects */ |
| 73 | typedef struct bcmbal_obj |
| 74 | { |
| 75 | bal_comm_msg_hdr comm_hdr; /**< Communication header */ |
| 76 | bcmbal_object_ver version; /**< Version of the Object definition/structure */ |
| 77 | bcmbal_obj_id obj_type; /**< An enumerated ID associated with the object being specified */ |
| 78 | bcmbal_mgt_group group; /**< Management group */ |
| 79 | uint16_t subgroup; /**< Subgroup for indications */ |
| 80 | bcmbal_obj_msg_type type; /**< Type (e.g. get / set / clear) */ |
| 81 | bcmbal_obj_msg_dir dir; /**< Direction - request / response */ |
| 82 | bcmos_errno status; /**< BAL status code (BCM_ERR_OK–success, error code otherwise) */ |
| 83 | bcmbal_presence_mask presence_mask; /**< Indicates which attribute parameters are present */ |
| 84 | |
| 85 | /* The following fields are internal. They are not sent on the line */ |
| 86 | bcmos_bool is_inprogress; /**< RO - When set to TRUE: Object is changing state internally */ |
| 87 | void *list_buf; /**< Memory buffer in which to store variable-sized lists when unpacking */ |
| 88 | uint32_t list_buf_size; /**< Number of bytes in the variable-sized list buffer */ |
| 89 | uint32_t obj_init_val; /**< An field that is set on INIT macro call, and checked by the API */ |
| 90 | } bcmbal_obj; |
| 91 | |
| 92 | /** Information structure for use with BAL configuration API (get/set/clear) */ |
| 93 | typedef struct bcmbal_cfg |
| 94 | { |
| 95 | bcmbal_obj hdr; |
| 96 | } bcmbal_cfg; |
| 97 | |
| 98 | /** Information structure for BAL statistics API */ |
| 99 | typedef struct bcmbal_stat |
| 100 | { |
| 101 | bcmbal_obj hdr; |
| 102 | } bcmbal_stat; |
| 103 | |
| 104 | /** Information structure for BAL indications */ |
| 105 | typedef struct bcmbal_auto |
| 106 | { |
| 107 | bcmbal_obj hdr; |
| 108 | } bcmbal_auto; |
| 109 | |
| 110 | /** Information structure for BAL indication configuration API */ |
| 111 | typedef struct bcmbal_auto_cfg |
| 112 | { |
| 113 | bcmbal_obj hdr; |
| 114 | } bcmbal_auto_cfg; |
| 115 | |
| 116 | /** Whether we pack the entire structure of a message */ |
| 117 | static inline bcmos_bool bcmbal_obj_msg_should_pack_data(const bcmbal_obj *msg) |
| 118 | { |
| 119 | switch (msg->group) |
| 120 | { |
| 121 | case BCMBAL_MGT_GROUP_CFG: |
| 122 | case BCMBAL_MGT_GROUP_STAT: |
| 123 | case BCMBAL_MGT_GROUP_AUTO_CFG: |
| 124 | if ((msg->type & BCMBAL_OBJ_MSG_TYPE_GET)) |
| 125 | { |
| 126 | return (msg->dir == BCMBAL_OBJ_MSG_DIR_RESPONSE); |
| 127 | } |
| 128 | else if ((msg->type & BCMBAL_OBJ_MSG_TYPE_SET)) |
| 129 | { |
| 130 | return (msg->dir == BCMBAL_OBJ_MSG_DIR_REQUEST); |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | return BCMOS_FALSE; |
| 135 | } |
| 136 | |
| 137 | default: |
| 138 | return BCMOS_TRUE; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /** Get the packed length of the header portion of an object message */ |
| 143 | static inline int32_t bcmbal_obj_msg_hdr_get_packed_length(void) |
| 144 | { |
| 145 | return 24; |
| 146 | } |
| 147 | |
| 148 | /** Pack a message header to a byte stream */ |
| 149 | static inline bcmos_errno bcmbal_obj_msg_hdr_pack(const bcmbal_obj *msg, bcmbal_buf *buf) |
| 150 | { |
| 151 | bcmos_bool ret; |
| 152 | |
| 153 | ret = bcmbal_buf_write_u32(buf, (uint32_t)msg->version); |
| 154 | ret = ret && bcmbal_buf_write_u8(buf, (uint32_t)msg->obj_type); |
| 155 | ret = ret && bcmbal_buf_write_u8(buf, (uint8_t)msg->group); |
| 156 | ret = ret && bcmbal_buf_write_u16(buf, msg->subgroup); |
| 157 | ret = ret && bcmbal_buf_write_u8(buf, (uint8_t)msg->type); |
| 158 | ret = ret && bcmbal_buf_write_u8(buf, (uint8_t)msg->dir); |
| 159 | ret = ret && bcmbal_buf_write_s16(buf, (int16_t)msg->status); |
| 160 | ret = ret && bcmbal_buf_write_u32(buf, (int32_t)msg->is_inprogress); |
| 161 | ret = ret && bcmbal_buf_write_u64(buf, (uint64_t)msg->presence_mask); |
| 162 | |
| 163 | return ret ? BCM_ERR_OK : BCM_ERR_OVERFLOW; |
| 164 | } |
| 165 | |
| 166 | /** Unpack a message header from a byte stream */ |
| 167 | static inline bcmos_errno bcmbal_obj_msg_hdr_unpack(bcmbal_obj *msg, bcmbal_buf *buf) |
| 168 | { |
| 169 | uint32_t version; |
| 170 | uint8_t obj_type; |
| 171 | uint8_t group; |
| 172 | uint16_t subgroup; |
| 173 | uint8_t type; |
| 174 | uint8_t dir; |
| 175 | int16_t status; |
| 176 | uint32_t is_inprogress; |
| 177 | uint64_t presence_mask; |
| 178 | bcmos_bool ret; |
| 179 | |
| 180 | ret = bcmbal_buf_read_u32(buf, &version); |
| 181 | ret = ret && bcmbal_buf_read_u8(buf, &obj_type); |
| 182 | ret = ret && bcmbal_buf_read_u8(buf, &group); |
| 183 | ret = ret && bcmbal_buf_read_u16(buf, &subgroup); |
| 184 | ret = ret && bcmbal_buf_read_u8(buf, &type); |
| 185 | ret = ret && bcmbal_buf_read_u8(buf, &dir); |
| 186 | ret = ret && bcmbal_buf_read_s16(buf, &status); |
| 187 | ret = ret && bcmbal_buf_read_u32(buf, &is_inprogress); |
| 188 | ret = ret && bcmbal_buf_read_u64(buf, &presence_mask); |
| 189 | if (ret) |
| 190 | { |
| 191 | msg->version = (bcmbal_object_ver)version; |
| 192 | msg->obj_type = (bcmbal_obj_id)obj_type; |
| 193 | msg->group = (bcmbal_mgt_group)group; |
| 194 | msg->subgroup = subgroup; |
| 195 | msg->type = (bcmbal_obj_msg_type)type; |
| 196 | msg->dir = (bcmbal_obj_msg_dir)dir; |
| 197 | msg->status = (bcmos_errno)status; |
| 198 | msg->is_inprogress = (bcmos_bool)is_inprogress; |
| 199 | msg->presence_mask = (bcmbal_presence_mask)presence_mask; |
| 200 | } |
| 201 | |
| 202 | return ret ? BCM_ERR_OK : BCM_ERR_OVERFLOW; |
| 203 | } |
| 204 | |
| 205 | #endif /* BAL_OBJ */ |